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 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 ***************************************************************************/ 35typedef 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_INIT, /* First state in SSH-CONNECT */ 40 SSH_S_STARTUP, /* Session startup */ 41 SSH_HOSTKEY, /* verify hostkey */ 42 SSH_AUTHLIST, 43 SSH_AUTH_PKEY_INIT, 44 SSH_AUTH_PKEY, 45 SSH_AUTH_PASS_INIT, 46 SSH_AUTH_PASS, 47 SSH_AUTH_HOST_INIT, 48 SSH_AUTH_HOST, 49 SSH_AUTH_KEY_INIT, 50 SSH_AUTH_KEY, 51 SSH_AUTH_DONE, 52 SSH_SFTP_INIT, 53 SSH_SFTP_REALPATH, /* Last state in SSH-CONNECT */ 54 55 SSH_SFTP_QUOTE_INIT, /* First state in SFTP-DO */ 56 SSH_SFTP_POSTQUOTE_INIT, /* (Possibly) First state in SFTP-DONE */ 57 SSH_SFTP_QUOTE, 58 SSH_SFTP_NEXT_QUOTE, 59 SSH_SFTP_QUOTE_STAT, 60 SSH_SFTP_QUOTE_SETSTAT, 61 SSH_SFTP_QUOTE_SYMLINK, 62 SSH_SFTP_QUOTE_MKDIR, 63 SSH_SFTP_QUOTE_RENAME, 64 SSH_SFTP_QUOTE_RMDIR, 65 SSH_SFTP_QUOTE_UNLINK, 66 SSH_SFTP_TRANS_INIT, 67 SSH_SFTP_UPLOAD_INIT, 68 SSH_SFTP_CREATE_DIRS_INIT, 69 SSH_SFTP_CREATE_DIRS, 70 SSH_SFTP_CREATE_DIRS_MKDIR, 71 SSH_SFTP_READDIR_INIT, 72 SSH_SFTP_READDIR, 73 SSH_SFTP_READDIR_LINK, 74 SSH_SFTP_READDIR_BOTTOM, 75 SSH_SFTP_READDIR_DONE, 76 SSH_SFTP_DOWNLOAD_INIT, 77 SSH_SFTP_DOWNLOAD_STAT, /* Last state in SFTP-DO */ 78 SSH_SFTP_CLOSE, /* Last state in SFTP-DONE */ 79 SSH_SFTP_SHUTDOWN, /* First state in SFTP-DISCONNECT */ 80 SSH_SCP_TRANS_INIT, /* First state in SCP-DO */ 81 SSH_SCP_UPLOAD_INIT, 82 SSH_SCP_DOWNLOAD_INIT, 83 SSH_SCP_DONE, 84 SSH_SCP_SEND_EOF, 85 SSH_SCP_WAIT_EOF, 86 SSH_SCP_WAIT_CLOSE, 87 SSH_SCP_CHANNEL_FREE, /* Last state in SCP-DONE */ 88 SSH_SESSION_DISCONNECT, /* First state in SCP-DISCONNECT */ 89 SSH_SESSION_FREE, /* Last state in SCP/SFTP-DISCONNECT */ 90 SSH_QUIT, 91 SSH_LAST /* never used */ 92} sshstate; 93 94/* this struct is used in the HandleData struct which is part of the 95 SessionHandle, which means this is used on a per-easy handle basis. 96 Everything that is strictly related to a connection is banned from this 97 struct. */ 98struct SSHPROTO { 99 char *path; /* the path we operate on */ 100}; 101 102/* ssh_conn is used for struct connection-oriented data in the connectdata 103 struct */ 104struct ssh_conn { 105 const char *authlist; /* List of auth. methods, managed by libssh2 */ 106#ifdef USE_LIBSSH2 107 const char *passphrase; /* pass-phrase to use */ 108 char *rsa_pub; /* path name */ 109 char *rsa; /* path name */ 110 bool authed; /* the connection has been authenticated fine */ 111 sshstate state; /* always use ssh.c:state() to change state! */ 112 sshstate nextstate; /* the state to goto after stopping */ 113 CURLcode actualcode; /* the actual error code */ 114 struct curl_slist *quote_item; /* for the quote option */ 115 char *quote_path1; /* two generic pointers for the QUOTE stuff */ 116 char *quote_path2; 117 LIBSSH2_SFTP_ATTRIBUTES quote_attrs; /* used by the SFTP_QUOTE state */ 118 char *homedir; /* when doing SFTP we figure out home dir in the 119 connect phase */ 120 121 /* Here's a set of struct members used by the SFTP_READDIR state */ 122 LIBSSH2_SFTP_ATTRIBUTES readdir_attrs; 123 char *readdir_filename; 124 char *readdir_longentry; 125 int readdir_len, readdir_totalLen, readdir_currLen; 126 char *readdir_line; 127 char *readdir_linkPath; 128 /* end of READDIR stuff */ 129 130 int secondCreateDirs; /* counter use by the code to see if the 131 second attempt has been made to change 132 to/create a directory */ 133 char *slash_pos; /* used by the SFTP_CREATE_DIRS state */ 134 LIBSSH2_SESSION *ssh_session; /* Secure Shell session */ 135 LIBSSH2_CHANNEL *ssh_channel; /* Secure Shell channel handle */ 136 LIBSSH2_SFTP *sftp_session; /* SFTP handle */ 137 LIBSSH2_SFTP_HANDLE *sftp_handle; 138 int orig_waitfor; /* default READ/WRITE bits wait for */ 139 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 148#ifdef USE_LIBSSH2 149 150#if !defined(LIBSSH2_VERSION_NUM) || (LIBSSH2_VERSION_NUM < 0x001000) 151# error "SCP/SFTP protocols require libssh2 0.16 or later" 152#endif 153 154#if defined(LIBSSH2_VERSION_NUM) && (LIBSSH2_VERSION_NUM >= 0x010000) 155# define HAVE_LIBSSH2_SFTP_SEEK64 1 156#else 157# undef HAVE_LIBSSH2_SFTP_SEEK64 158#endif 159 160#if defined(LIBSSH2_VERSION_NUM) && (LIBSSH2_VERSION_NUM >= 0x010206) 161# define HAVE_LIBSSH2_SCP_SEND64 1 162#else 163# undef HAVE_LIBSSH2_SCP_SEND64 164#endif 165 166 167extern const struct Curl_handler Curl_handler_scp; 168extern const struct Curl_handler Curl_handler_sftp; 169 170#endif /* USE_LIBSSH2 */ 171 172#endif /* HEADER_CURL_SSH_H */ 173