ssh.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. #ifndef HEADER_CURL_SSH_H
  2. #define HEADER_CURL_SSH_H
  3. /***************************************************************************
  4. * _ _ ____ _
  5. * Project ___| | | | _ \| |
  6. * / __| | | | |_) | |
  7. * | (__| |_| | _ <| |___
  8. * \___|\___/|_| \_\_____|
  9. *
  10. * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
  11. *
  12. * This software is licensed as described in the file COPYING, which
  13. * you should have received as part of this distribution. The terms
  14. * are also available at http://curl.haxx.se/docs/copyright.html.
  15. *
  16. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  17. * copies of the Software, and permit persons to whom the Software is
  18. * furnished to do so, under the terms of the COPYING file.
  19. *
  20. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  21. * KIND, either express or implied.
  22. *
  23. ***************************************************************************/
  24. #include "curl_setup.h"
  25. #ifdef HAVE_LIBSSH2_H
  26. #include <libssh2.h>
  27. #include <libssh2_sftp.h>
  28. #endif /* HAVE_LIBSSH2_H */
  29. /****************************************************************************
  30. * SSH unique setup
  31. ***************************************************************************/
  32. typedef enum {
  33. SSH_NO_STATE = -1, /* Used for "nextState" so say there is none */
  34. SSH_STOP = 0, /* do nothing state, stops the state machine */
  35. SSH_INIT, /* First state in SSH-CONNECT */
  36. SSH_S_STARTUP, /* Session startup */
  37. SSH_HOSTKEY, /* verify hostkey */
  38. SSH_AUTHLIST,
  39. SSH_AUTH_PKEY_INIT,
  40. SSH_AUTH_PKEY,
  41. SSH_AUTH_PASS_INIT,
  42. SSH_AUTH_PASS,
  43. SSH_AUTH_AGENT_INIT,/* initialize then wait for connection to agent */
  44. SSH_AUTH_AGENT_LIST,/* ask for list then wait for entire list to come */
  45. SSH_AUTH_AGENT, /* attempt one key at a time */
  46. SSH_AUTH_HOST_INIT,
  47. SSH_AUTH_HOST,
  48. SSH_AUTH_KEY_INIT,
  49. SSH_AUTH_KEY,
  50. SSH_AUTH_DONE,
  51. SSH_SFTP_INIT,
  52. SSH_SFTP_REALPATH, /* Last state in SSH-CONNECT */
  53. SSH_SFTP_QUOTE_INIT, /* First state in SFTP-DO */
  54. SSH_SFTP_POSTQUOTE_INIT, /* (Possibly) First state in SFTP-DONE */
  55. SSH_SFTP_QUOTE,
  56. SSH_SFTP_NEXT_QUOTE,
  57. SSH_SFTP_QUOTE_STAT,
  58. SSH_SFTP_QUOTE_SETSTAT,
  59. SSH_SFTP_QUOTE_SYMLINK,
  60. SSH_SFTP_QUOTE_MKDIR,
  61. SSH_SFTP_QUOTE_RENAME,
  62. SSH_SFTP_QUOTE_RMDIR,
  63. SSH_SFTP_QUOTE_UNLINK,
  64. SSH_SFTP_TRANS_INIT,
  65. SSH_SFTP_UPLOAD_INIT,
  66. SSH_SFTP_CREATE_DIRS_INIT,
  67. SSH_SFTP_CREATE_DIRS,
  68. SSH_SFTP_CREATE_DIRS_MKDIR,
  69. SSH_SFTP_READDIR_INIT,
  70. SSH_SFTP_READDIR,
  71. SSH_SFTP_READDIR_LINK,
  72. SSH_SFTP_READDIR_BOTTOM,
  73. SSH_SFTP_READDIR_DONE,
  74. SSH_SFTP_DOWNLOAD_INIT,
  75. SSH_SFTP_DOWNLOAD_STAT, /* Last state in SFTP-DO */
  76. SSH_SFTP_CLOSE, /* Last state in SFTP-DONE */
  77. SSH_SFTP_SHUTDOWN, /* First state in SFTP-DISCONNECT */
  78. SSH_SCP_TRANS_INIT, /* First state in SCP-DO */
  79. SSH_SCP_UPLOAD_INIT,
  80. SSH_SCP_DOWNLOAD_INIT,
  81. SSH_SCP_DONE,
  82. SSH_SCP_SEND_EOF,
  83. SSH_SCP_WAIT_EOF,
  84. SSH_SCP_WAIT_CLOSE,
  85. SSH_SCP_CHANNEL_FREE, /* Last state in SCP-DONE */
  86. SSH_SESSION_DISCONNECT, /* First state in SCP-DISCONNECT */
  87. SSH_SESSION_FREE, /* Last state in SCP/SFTP-DISCONNECT */
  88. SSH_QUIT,
  89. SSH_LAST /* never used */
  90. } sshstate;
  91. /* this struct is used in the HandleData struct which is part of the
  92. SessionHandle, which means this is used on a per-easy handle basis.
  93. Everything that is strictly related to a connection is banned from this
  94. struct. */
  95. struct SSHPROTO {
  96. char *path; /* the path we operate on */
  97. };
  98. /* ssh_conn is used for struct connection-oriented data in the connectdata
  99. struct */
  100. struct ssh_conn {
  101. const char *authlist; /* List of auth. methods, managed by libssh2 */
  102. #ifdef USE_LIBSSH2
  103. const char *passphrase; /* pass-phrase to use */
  104. char *rsa_pub; /* path name */
  105. char *rsa; /* path name */
  106. bool authed; /* the connection has been authenticated fine */
  107. sshstate state; /* always use ssh.c:state() to change state! */
  108. sshstate nextstate; /* the state to goto after stopping */
  109. CURLcode actualcode; /* the actual error code */
  110. struct curl_slist *quote_item; /* for the quote option */
  111. char *quote_path1; /* two generic pointers for the QUOTE stuff */
  112. char *quote_path2;
  113. LIBSSH2_SFTP_ATTRIBUTES quote_attrs; /* used by the SFTP_QUOTE state */
  114. bool acceptfail; /* used by the SFTP_QUOTE (continue if
  115. quote command fails) */
  116. char *homedir; /* when doing SFTP we figure out home dir in the
  117. connect phase */
  118. /* Here's a set of struct members used by the SFTP_READDIR state */
  119. LIBSSH2_SFTP_ATTRIBUTES readdir_attrs;
  120. char *readdir_filename;
  121. char *readdir_longentry;
  122. int readdir_len, readdir_totalLen, readdir_currLen;
  123. char *readdir_line;
  124. char *readdir_linkPath;
  125. /* end of READDIR stuff */
  126. int secondCreateDirs; /* counter use by the code to see if the
  127. second attempt has been made to change
  128. to/create a directory */
  129. char *slash_pos; /* used by the SFTP_CREATE_DIRS state */
  130. LIBSSH2_SESSION *ssh_session; /* Secure Shell session */
  131. LIBSSH2_CHANNEL *ssh_channel; /* Secure Shell channel handle */
  132. LIBSSH2_SFTP *sftp_session; /* SFTP handle */
  133. LIBSSH2_SFTP_HANDLE *sftp_handle;
  134. int orig_waitfor; /* default READ/WRITE bits wait for */
  135. #ifdef HAVE_LIBSSH2_AGENT_API
  136. LIBSSH2_AGENT *ssh_agent; /* proxy to ssh-agent/pageant */
  137. struct libssh2_agent_publickey *sshagent_identity,
  138. *sshagent_prev_identity;
  139. #endif
  140. /* note that HAVE_LIBSSH2_KNOWNHOST_API is a define set in the libssh2.h
  141. header */
  142. #ifdef HAVE_LIBSSH2_KNOWNHOST_API
  143. LIBSSH2_KNOWNHOSTS *kh;
  144. #endif
  145. #endif /* USE_LIBSSH2 */
  146. };
  147. #ifdef USE_LIBSSH2
  148. #if !defined(LIBSSH2_VERSION_NUM) || (LIBSSH2_VERSION_NUM < 0x001000)
  149. # error "SCP/SFTP protocols require libssh2 0.16 or later"
  150. #endif
  151. #if defined(LIBSSH2_VERSION_NUM) && (LIBSSH2_VERSION_NUM >= 0x010000)
  152. # define HAVE_LIBSSH2_SFTP_SEEK64 1
  153. #else
  154. # undef HAVE_LIBSSH2_SFTP_SEEK64
  155. #endif
  156. #if defined(LIBSSH2_VERSION_NUM) && (LIBSSH2_VERSION_NUM >= 0x010206)
  157. # define HAVE_LIBSSH2_SCP_SEND64 1
  158. #else
  159. # undef HAVE_LIBSSH2_SCP_SEND64
  160. #endif
  161. extern const struct Curl_handler Curl_handler_scp;
  162. extern const struct Curl_handler Curl_handler_sftp;
  163. #endif /* USE_LIBSSH2 */
  164. #endif /* HEADER_CURL_SSH_H */