1 #ifndef HEADER_CURL_SSH_H
2 #define HEADER_CURL_SSH_H
3 /***************************************************************************
5 * Project ___| | | | _ \| |
7 * | (__| |_| | _ <| |___
8 * \___|\___/|_| \_\_____|
10 * Copyright (C) 1998 - 2015, 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 https://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,
69 SSH_SFTP_QUOTE_STATVFS,
74 SSH_SFTP_CREATE_DIRS_INIT,
76 SSH_SFTP_CREATE_DIRS_MKDIR,
77 SSH_SFTP_READDIR_INIT,
79 SSH_SFTP_READDIR_LINK,
80 SSH_SFTP_READDIR_BOTTOM,
81 SSH_SFTP_READDIR_DONE,
82 SSH_SFTP_DOWNLOAD_INIT,
83 SSH_SFTP_DOWNLOAD_STAT, /* Last state in SFTP-DO */
84 SSH_SFTP_CLOSE, /* Last state in SFTP-DONE */
85 SSH_SFTP_SHUTDOWN, /* First state in SFTP-DISCONNECT */
86 SSH_SCP_TRANS_INIT, /* First state in SCP-DO */
88 SSH_SCP_DOWNLOAD_INIT,
93 SSH_SCP_CHANNEL_FREE, /* Last state in SCP-DONE */
94 SSH_SESSION_DISCONNECT, /* First state in SCP-DISCONNECT */
95 SSH_SESSION_FREE, /* Last state in SCP/SFTP-DISCONNECT */
97 SSH_LAST /* never used */
100 /* this struct is used in the HandleData struct which is part of the
101 Curl_easy, which means this is used on a per-easy handle basis.
102 Everything that is strictly related to a connection is banned from this
105 char *path; /* the path we operate on */
108 /* ssh_conn is used for struct connection-oriented data in the connectdata
111 const char *authlist; /* List of auth. methods, managed by libssh2 */
113 const char *passphrase; /* pass-phrase to use */
114 char *rsa_pub; /* path name */
115 char *rsa; /* path name */
116 bool authed; /* the connection has been authenticated fine */
117 sshstate state; /* always use ssh.c:state() to change state! */
118 sshstate nextstate; /* the state to goto after stopping */
119 CURLcode actualcode; /* the actual error code */
120 struct curl_slist *quote_item; /* for the quote option */
121 char *quote_path1; /* two generic pointers for the QUOTE stuff */
123 LIBSSH2_SFTP_ATTRIBUTES quote_attrs; /* used by the SFTP_QUOTE state */
124 bool acceptfail; /* used by the SFTP_QUOTE (continue if
125 quote command fails) */
126 char *homedir; /* when doing SFTP we figure out home dir in the
129 /* Here's a set of struct members used by the SFTP_READDIR state */
130 LIBSSH2_SFTP_ATTRIBUTES readdir_attrs;
131 char *readdir_filename;
132 char *readdir_longentry;
133 int readdir_len, readdir_totalLen, readdir_currLen;
135 char *readdir_linkPath;
136 /* end of READDIR stuff */
138 int secondCreateDirs; /* counter use by the code to see if the
139 second attempt has been made to change
140 to/create a directory */
141 char *slash_pos; /* used by the SFTP_CREATE_DIRS state */
142 LIBSSH2_SESSION *ssh_session; /* Secure Shell session */
143 LIBSSH2_CHANNEL *ssh_channel; /* Secure Shell channel handle */
144 LIBSSH2_SFTP *sftp_session; /* SFTP handle */
145 LIBSSH2_SFTP_HANDLE *sftp_handle;
146 int orig_waitfor; /* default READ/WRITE bits wait for */
148 #ifdef HAVE_LIBSSH2_AGENT_API
149 LIBSSH2_AGENT *ssh_agent; /* proxy to ssh-agent/pageant */
150 struct libssh2_agent_publickey *sshagent_identity,
151 *sshagent_prev_identity;
154 /* note that HAVE_LIBSSH2_KNOWNHOST_API is a define set in the libssh2.h
156 #ifdef HAVE_LIBSSH2_KNOWNHOST_API
157 LIBSSH2_KNOWNHOSTS *kh;
159 #endif /* USE_LIBSSH2 */
164 /* Feature detection based on version numbers to better work with
165 non-configure platforms */
167 #if !defined(LIBSSH2_VERSION_NUM) || (LIBSSH2_VERSION_NUM < 0x001000)
168 # error "SCP/SFTP protocols require libssh2 0.16 or later"
171 #if LIBSSH2_VERSION_NUM >= 0x010000
172 #define HAVE_LIBSSH2_SFTP_SEEK64 1
175 #if LIBSSH2_VERSION_NUM >= 0x010100
176 #define HAVE_LIBSSH2_VERSION 1
179 #if LIBSSH2_VERSION_NUM >= 0x010205
180 #define HAVE_LIBSSH2_INIT 1
181 #define HAVE_LIBSSH2_EXIT 1
184 #if LIBSSH2_VERSION_NUM >= 0x010206
185 #define HAVE_LIBSSH2_KNOWNHOST_CHECKP 1
186 #define HAVE_LIBSSH2_SCP_SEND64 1
189 #if LIBSSH2_VERSION_NUM >= 0x010208
190 #define HAVE_LIBSSH2_SESSION_HANDSHAKE 1
193 extern const struct Curl_handler Curl_handler_scp;
194 extern const struct Curl_handler Curl_handler_sftp;
196 #endif /* USE_LIBSSH2 */
198 #endif /* HEADER_CURL_SSH_H */