1 #ifndef HEADER_CURL_SSH_H
2 #define HEADER_CURL_SSH_H
3 /***************************************************************************
5 * Project ___| | | | _ \| |
7 * | (__| |_| | _ <| |___
8 * \___|\___/|_| \_\_____|
10 * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.
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.
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.
20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21 * KIND, either express or implied.
23 ***************************************************************************/
25 #include "curl_setup.h"
29 #include <libssh2_sftp.h>
30 #endif /* HAVE_LIBSSH2_H */
32 /****************************************************************************
34 ***************************************************************************/
36 SSH_NO_STATE = -1, /* Used for "nextState" so say there is none */
37 SSH_STOP = 0, /* do nothing state, stops the state machine */
39 SSH_INIT, /* First state in SSH-CONNECT */
40 SSH_S_STARTUP, /* Session startup */
41 SSH_HOSTKEY, /* verify hostkey */
47 SSH_AUTH_AGENT_INIT,/* initialize then wait for connection to agent */
48 SSH_AUTH_AGENT_LIST,/* ask for list then wait for entire list to come */
49 SSH_AUTH_AGENT, /* attempt one key at a time */
56 SSH_SFTP_REALPATH, /* Last state in SSH-CONNECT */
58 SSH_SFTP_QUOTE_INIT, /* First state in SFTP-DO */
59 SSH_SFTP_POSTQUOTE_INIT, /* (Possibly) First state in SFTP-DONE */
63 SSH_SFTP_QUOTE_SETSTAT,
64 SSH_SFTP_QUOTE_SYMLINK,
66 SSH_SFTP_QUOTE_RENAME,
68 SSH_SFTP_QUOTE_UNLINK,
71 SSH_SFTP_CREATE_DIRS_INIT,
73 SSH_SFTP_CREATE_DIRS_MKDIR,
74 SSH_SFTP_READDIR_INIT,
76 SSH_SFTP_READDIR_LINK,
77 SSH_SFTP_READDIR_BOTTOM,
78 SSH_SFTP_READDIR_DONE,
79 SSH_SFTP_DOWNLOAD_INIT,
80 SSH_SFTP_DOWNLOAD_STAT, /* Last state in SFTP-DO */
81 SSH_SFTP_CLOSE, /* Last state in SFTP-DONE */
82 SSH_SFTP_SHUTDOWN, /* First state in SFTP-DISCONNECT */
83 SSH_SCP_TRANS_INIT, /* First state in SCP-DO */
85 SSH_SCP_DOWNLOAD_INIT,
90 SSH_SCP_CHANNEL_FREE, /* Last state in SCP-DONE */
91 SSH_SESSION_DISCONNECT, /* First state in SCP-DISCONNECT */
92 SSH_SESSION_FREE, /* Last state in SCP/SFTP-DISCONNECT */
94 SSH_LAST /* never used */
97 /* this struct is used in the HandleData struct which is part of the
98 SessionHandle, which means this is used on a per-easy handle basis.
99 Everything that is strictly related to a connection is banned from this
102 char *path; /* the path we operate on */
105 /* ssh_conn is used for struct connection-oriented data in the connectdata
108 const char *authlist; /* List of auth. methods, managed by libssh2 */
110 const char *passphrase; /* pass-phrase to use */
111 char *rsa_pub; /* path name */
112 char *rsa; /* path name */
113 bool authed; /* the connection has been authenticated fine */
114 sshstate state; /* always use ssh.c:state() to change state! */
115 sshstate nextstate; /* the state to goto after stopping */
116 CURLcode actualcode; /* the actual error code */
117 struct curl_slist *quote_item; /* for the quote option */
118 char *quote_path1; /* two generic pointers for the QUOTE stuff */
120 LIBSSH2_SFTP_ATTRIBUTES quote_attrs; /* used by the SFTP_QUOTE state */
121 bool acceptfail; /* used by the SFTP_QUOTE (continue if
122 quote command fails) */
123 char *homedir; /* when doing SFTP we figure out home dir in the
126 /* Here's a set of struct members used by the SFTP_READDIR state */
127 LIBSSH2_SFTP_ATTRIBUTES readdir_attrs;
128 char *readdir_filename;
129 char *readdir_longentry;
130 int readdir_len, readdir_totalLen, readdir_currLen;
132 char *readdir_linkPath;
133 /* end of READDIR stuff */
135 int secondCreateDirs; /* counter use by the code to see if the
136 second attempt has been made to change
137 to/create a directory */
138 char *slash_pos; /* used by the SFTP_CREATE_DIRS state */
139 LIBSSH2_SESSION *ssh_session; /* Secure Shell session */
140 LIBSSH2_CHANNEL *ssh_channel; /* Secure Shell channel handle */
141 LIBSSH2_SFTP *sftp_session; /* SFTP handle */
142 LIBSSH2_SFTP_HANDLE *sftp_handle;
143 int orig_waitfor; /* default READ/WRITE bits wait for */
145 #ifdef HAVE_LIBSSH2_AGENT_API
146 LIBSSH2_AGENT *ssh_agent; /* proxy to ssh-agent/pageant */
147 struct libssh2_agent_publickey *sshagent_identity,
148 *sshagent_prev_identity;
151 /* note that HAVE_LIBSSH2_KNOWNHOST_API is a define set in the libssh2.h
153 #ifdef HAVE_LIBSSH2_KNOWNHOST_API
154 LIBSSH2_KNOWNHOSTS *kh;
156 #endif /* USE_LIBSSH2 */
161 /* Feature detection based on version numbers to better work with
162 non-configure platforms */
164 #if !defined(LIBSSH2_VERSION_NUM) || (LIBSSH2_VERSION_NUM < 0x001000)
165 # error "SCP/SFTP protocols require libssh2 0.16 or later"
168 #if LIBSSH2_VERSION_NUM >= 0x010000
169 #define HAVE_LIBSSH2_SFTP_SEEK64 1
172 #if LIBSSH2_VERSION_NUM >= 0x010100
173 #define HAVE_LIBSSH2_VERSION 1
176 #if LIBSSH2_VERSION_NUM >= 0x010205
177 #define HAVE_LIBSSH2_INIT 1
178 #define HAVE_LIBSSH2_EXIT 1
181 #if LIBSSH2_VERSION_NUM >= 0x010206
182 #define HAVE_LIBSSH2_KNOWNHOST_CHECKP 1
183 #define HAVE_LIBSSH2_SCP_SEND64 1
186 #if LIBSSH2_VERSION_NUM >= 0x010208
187 #define HAVE_LIBSSH2_SESSION_HANDSHAKE 1
190 extern const struct Curl_handler Curl_handler_scp;
191 extern const struct Curl_handler Curl_handler_sftp;
193 #endif /* USE_LIBSSH2 */
195 #endif /* HEADER_CURL_SSH_H */