~ubuntu-branches/ubuntu/natty/curl/natty-security

« back to all changes in this revision

Viewing changes to lib/ssh.h

  • Committer: Bazaar Package Importer
  • Author(s): Bhavani Shankar
  • Date: 2010-06-20 13:56:28 UTC
  • mfrom: (3.4.7 sid)
  • Revision ID: james.westby@ubuntu.com-20100620135628-e30tp9jldq6hq985
Tags: 7.21.0-1ubuntu1
* Merge from debian unstable.  Remaining changes: LP: #596334
  - Keep build deps in main:
    - Drop build dependencies: stunnel, libssh2-1-dev
    - Add build-dependency on openssh-server
    - Drop libssh2-1-dev from libcurl4-openssl-dev's Depends.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21
21
 * KIND, either express or implied.
22
22
 *
23
 
 * $Id: ssh.h,v 1.19 2009-05-19 23:21:25 gknauf Exp $
24
 
 ***************************************************************************/
 
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
};
25
146
 
26
147
#ifdef USE_LIBSSH2
27
148
 
41
162
extern const struct Curl_handler Curl_handler_scp;
42
163
extern const struct Curl_handler Curl_handler_sftp;
43
164
 
44
 
ssize_t Curl_scp_send(struct connectdata *conn, int sockindex,
45
 
                      const void *mem, size_t len);
46
 
ssize_t Curl_scp_recv(struct connectdata *conn, int sockindex,
47
 
                      char *mem, size_t len);
48
 
 
49
 
ssize_t Curl_sftp_send(struct connectdata *conn, int sockindex,
50
 
                       const void *mem, size_t len);
51
 
ssize_t Curl_sftp_recv(struct connectdata *conn, int sockindex,
52
 
                       char *mem, size_t len);
53
 
 
54
 
#define Curl_ssh_enabled(conn,prot) (conn->protocol & prot)
55
 
 
56
 
#else /* USE_LIBSSH2 */
57
 
 
58
 
#define Curl_ssh_enabled(x,y) 0
59
 
#define Curl_scp_send(a,b,c,d) 0
60
 
#define Curl_sftp_send(a,b,c,d) 0
61
 
#define Curl_scp_recv(a,b,c,d) 0
62
 
#define Curl_sftp_recv(a,b,c,d) 0
63
 
 
64
165
#endif /* USE_LIBSSH2 */
65
166
 
66
167
#endif /* HEADER_CURL_SSH_H */