Git init
[external/curl.git] / lib / ssh.h
1 #ifndef HEADER_CURL_SSH_H
2 #define HEADER_CURL_SSH_H
3 /***************************************************************************
4  *                                  _   _ ____  _
5  *  Project                     ___| | | |  _ \| |
6  *                             / __| | | | |_) | |
7  *                            | (__| |_| |  _ <| |___
8  *                             \___|\___/|_| \_\_____|
9  *
10  * Copyright (C) 1998 - 2010, 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
25 #include "setup.h"
26
27 #ifdef HAVE_LIBSSH2_H
28 #include <libssh2.h>
29 #include <libssh2_sftp.h>
30 #endif /* HAVE_LIBSSH2_H */
31
32 /****************************************************************************
33  * SSH unique setup
34  ***************************************************************************/
35 typedef enum {
36   SSH_NO_STATE = -1,  /* Used for "nextState" so say there is none */
37   SSH_STOP = 0,       /* do nothing state, stops the state machine */
38
39   SSH_S_STARTUP,      /* Session startup, First state in SSH-CONNECT */
40   SSH_HOSTKEY,        /* verify hostkey */
41   SSH_AUTHLIST,
42   SSH_AUTH_PKEY_INIT,
43   SSH_AUTH_PKEY,
44   SSH_AUTH_PASS_INIT,
45   SSH_AUTH_PASS,
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
54   SSH_SFTP_QUOTE_INIT, /* First state in SFTP-DO */
55   SSH_SFTP_POSTQUOTE_INIT, /* (Possibly) First state in SFTP-DONE */
56   SSH_SFTP_QUOTE,
57   SSH_SFTP_NEXT_QUOTE,
58   SSH_SFTP_QUOTE_STAT,
59   SSH_SFTP_QUOTE_SETSTAT,
60   SSH_SFTP_QUOTE_SYMLINK,
61   SSH_SFTP_QUOTE_MKDIR,
62   SSH_SFTP_QUOTE_RENAME,
63   SSH_SFTP_QUOTE_RMDIR,
64   SSH_SFTP_QUOTE_UNLINK,
65   SSH_SFTP_TRANS_INIT,
66   SSH_SFTP_UPLOAD_INIT,
67   SSH_SFTP_CREATE_DIRS_INIT,
68   SSH_SFTP_CREATE_DIRS,
69   SSH_SFTP_CREATE_DIRS_MKDIR,
70   SSH_SFTP_READDIR_INIT,
71   SSH_SFTP_READDIR,
72   SSH_SFTP_READDIR_LINK,
73   SSH_SFTP_READDIR_BOTTOM,
74   SSH_SFTP_READDIR_DONE,
75   SSH_SFTP_DOWNLOAD_INIT,
76   SSH_SFTP_DOWNLOAD_STAT, /* Last state in SFTP-DO */
77   SSH_SFTP_CLOSE,    /* Last state in SFTP-DONE */
78   SSH_SFTP_SHUTDOWN, /* First state in SFTP-DISCONNECT */
79   SSH_SCP_TRANS_INIT, /* First state in SCP-DO */
80   SSH_SCP_UPLOAD_INIT,
81   SSH_SCP_DOWNLOAD_INIT,
82   SSH_SCP_DONE,
83   SSH_SCP_SEND_EOF,
84   SSH_SCP_WAIT_EOF,
85   SSH_SCP_WAIT_CLOSE,
86   SSH_SCP_CHANNEL_FREE,   /* Last state in SCP-DONE */
87   SSH_SESSION_DISCONNECT, /* First state in SCP-DISCONNECT */
88   SSH_SESSION_FREE,       /* Last state in SCP/SFTP-DISCONNECT */
89   SSH_QUIT,
90   SSH_LAST  /* never used */
91 } sshstate;
92
93 /* this struct is used in the HandleData struct which is part of the
94    SessionHandle, which means this is used on a per-easy handle basis.
95    Everything that is strictly related to a connection is banned from this
96    struct. */
97 struct SSHPROTO {
98   char *path;                  /* the path we operate on */
99 };
100
101 /* ssh_conn is used for struct connection-oriented data in the connectdata
102    struct */
103 struct ssh_conn {
104   const char *authlist;       /* List of auth. methods, managed by libssh2 */
105 #ifdef USE_LIBSSH2
106   const char *passphrase;     /* pass-phrase to use */
107   char *rsa_pub;              /* path name */
108   char *rsa;                  /* path name */
109   bool authed;                /* the connection has been authenticated fine */
110   sshstate state;             /* always use ssh.c:state() to change state! */
111   sshstate nextstate;         /* the state to goto after stopping */
112   CURLcode actualcode;        /* the actual error code */
113   struct curl_slist *quote_item; /* for the quote option */
114   char *quote_path1;          /* two generic pointers for the QUOTE stuff */
115   char *quote_path2;
116   LIBSSH2_SFTP_ATTRIBUTES quote_attrs; /* used by the SFTP_QUOTE state */
117   char *homedir;              /* when doing SFTP we figure out home dir in the
118                                  connect phase */
119
120   /* Here's a set of struct members used by the SFTP_READDIR state */
121   LIBSSH2_SFTP_ATTRIBUTES readdir_attrs;
122   char *readdir_filename;
123   char *readdir_longentry;
124   int readdir_len, readdir_totalLen, readdir_currLen;
125   char *readdir_line;
126   char *readdir_linkPath;
127   /* end of READDIR stuff */
128
129   int secondCreateDirs;         /* counter use by the code to see if the
130                                    second attempt has been made to change
131                                    to/create a directory */
132   char *slash_pos;              /* used by the SFTP_CREATE_DIRS state */
133   LIBSSH2_SESSION *ssh_session; /* Secure Shell session */
134   LIBSSH2_CHANNEL *ssh_channel; /* Secure Shell channel handle */
135   LIBSSH2_SFTP *sftp_session;   /* SFTP handle */
136   LIBSSH2_SFTP_HANDLE *sftp_handle;
137   int orig_waitfor;             /* default READ/WRITE bits wait for */
138
139   /* note that HAVE_LIBSSH2_KNOWNHOST_API is a define set in the libssh2.h
140      header */
141 #ifdef HAVE_LIBSSH2_KNOWNHOST_API
142   LIBSSH2_KNOWNHOSTS *kh;
143 #endif
144 #endif /* USE_LIBSSH2 */
145 };
146
147 #ifdef USE_LIBSSH2
148
149 #if !defined(LIBSSH2_VERSION_NUM) || (LIBSSH2_VERSION_NUM < 0x001000)
150 #  error "SCP/SFTP protocols require libssh2 0.16 or later"
151 #endif
152
153 #if defined(LIBSSH2_VERSION_NUM) && (LIBSSH2_VERSION_NUM >= 0x010000)
154 #  define HAVE_LIBSSH2_SFTP_SEEK64 1
155 #else
156 #  undef HAVE_LIBSSH2_SFTP_SEEK64
157 #endif
158
159 #if defined(LIBSSH2_VERSION_NUM) && (LIBSSH2_VERSION_NUM >= 0x010206)
160 #  define HAVE_LIBSSH2_SCP_SEND64 1
161 #else
162 #  undef HAVE_LIBSSH2_SCP_SEND64
163 #endif
164
165
166 extern const struct Curl_handler Curl_handler_scp;
167 extern const struct Curl_handler Curl_handler_sftp;
168
169 #endif /* USE_LIBSSH2 */
170
171 #endif /* HEADER_CURL_SSH_H */