00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef _LIBSSH_H
00023 #define _LIBSSH_H
00024
00025 #ifdef LIBSSH_STATIC
00026 #define LIBSSH_API
00027 #else
00028 #if defined _WIN32 || defined __CYGWIN__
00029 #ifdef LIBSSH_EXPORTS
00030 #ifdef __GNUC__
00031 #define LIBSSH_API __attribute__((dllexport))
00032 #else
00033 #define LIBSSH_API __declspec(dllexport)
00034 #endif
00035 #else
00036 #ifdef __GNUC__
00037 #define LIBSSH_API __attribute__((dllimport))
00038 #else
00039 #define LIBSSH_API __declspec(dllimport)
00040 #endif
00041 #endif
00042 #else
00043 #if __GNUC__ >= 4
00044 #define LIBSSH_API __attribute__((visibility("default")))
00045 #else
00046 #define LIBSSH_API
00047 #endif
00048 #endif
00049 #endif
00050
00051 #ifdef _MSC_VER
00052
00053 typedef int int32_t;
00054 typedef unsigned int uint32_t;
00055 typedef unsigned short uint16_t;
00056 typedef unsigned char uint8_t;
00057 typedef unsigned long long uint64_t;
00058 typedef int mode_t;
00059 #else
00060 #include <unistd.h>
00061 #include <inttypes.h>
00062 #endif
00063
00064 #ifdef _WIN32
00065 #include <winsock2.h>
00066 #else
00067 #include <sys/select.h>
00068 #include <netdb.h>
00069 #endif
00070
00071 #define SSH_STRINGIFY(s) SSH_TOSTRING(s)
00072 #define SSH_TOSTRING(s) #s
00073
00074
00075 #define SSH_VERSION_INT(a, b, c) ((a) << 16 | (b) << 8 | (c))
00076 #define SSH_VERSION_DOT(a, b, c) a ##.## b ##.## c
00077 #define SSH_VERSION(a, b, c) SSH_VERSION_DOT(a, b, c)
00078
00079
00080 #define LIBSSH_VERSION_MAJOR 0
00081 #define LIBSSH_VERSION_MINOR 4
00082 #define LIBSSH_VERSION_MICRO 2
00083
00084 #define LIBSSH_VERSION_INT SSH_VERSION_INT(LIBSSH_VERSION_MAJOR, \
00085 LIBSSH_VERSION_MINOR, \
00086 LIBSSH_VERSION_MICRO)
00087 #define LIBSSH_VERSION SSH_VERSION(LIBSSH_VERSION_MAJOR, \
00088 LIBSSH_VERSION_MINOR, \
00089 LIBSSH_VERSION_MICRO)
00090
00091
00092 #ifdef __GNUC__
00093 #define PRINTF_ATTRIBUTE(a,b) __attribute__ ((__format__ (__printf__, a, b)))
00094 #else
00095 #define PRINTF_ATTRIBUTE(a,b)
00096 #endif
00097
00098 #ifdef __GNUC__
00099 #define SSH_DEPRECATED __attribute__ ((deprecated))
00100 #else
00101 #define SSH_DEPRECATED
00102 #endif
00103
00104 #ifdef __cplusplus
00105 extern "C" {
00106 #endif
00107
00108
00109 typedef struct ssh_agent_struct* ssh_agent;
00110 typedef struct ssh_buffer_struct* ssh_buffer;
00111 typedef struct ssh_channel_struct* ssh_channel;
00112 typedef struct ssh_message_struct* ssh_message;
00113 typedef struct ssh_pcap_file_struct* ssh_pcap_file;
00114 typedef struct ssh_private_key_struct* ssh_private_key;
00115 typedef struct ssh_public_key_struct* ssh_public_key;
00116 typedef struct ssh_scp_struct* ssh_scp;
00117 typedef struct ssh_session_struct* ssh_session;
00118 typedef struct ssh_string_struct* ssh_string;
00119
00120
00121 #ifdef _WIN32
00122 #define socket_t SOCKET
00123 #else
00124 typedef int socket_t;
00125 #endif
00126
00127
00128 enum ssh_kex_types_e {
00129 SSH_KEX=0,
00130 SSH_HOSTKEYS,
00131 SSH_CRYPT_C_S,
00132 SSH_CRYPT_S_C,
00133 SSH_MAC_C_S,
00134 SSH_MAC_S_C,
00135 SSH_COMP_C_S,
00136 SSH_COMP_S_C,
00137 SSH_LANG_C_S,
00138 SSH_LANG_S_C
00139 };
00140
00141 #define SSH_CRYPT 2
00142 #define SSH_MAC 3
00143 #define SSH_COMP 4
00144 #define SSH_LANG 5
00145
00146 enum ssh_auth_e {
00147 SSH_AUTH_SUCCESS=0,
00148 SSH_AUTH_DENIED,
00149 SSH_AUTH_PARTIAL,
00150 SSH_AUTH_INFO,
00151 SSH_AUTH_ERROR=-1
00152 };
00153
00154
00155 #define SSH_AUTH_METHOD_UNKNOWN 0
00156 #define SSH_AUTH_METHOD_NONE 0x0001
00157 #define SSH_AUTH_METHOD_PASSWORD 0x0002
00158 #define SSH_AUTH_METHOD_PUBLICKEY 0x0004
00159 #define SSH_AUTH_METHOD_HOSTBASED 0x0008
00160 #define SSH_AUTH_METHOD_INTERACTIVE 0x0010
00161
00162
00163 enum ssh_requests_e {
00164 SSH_REQUEST_AUTH=1,
00165 SSH_REQUEST_CHANNEL_OPEN,
00166 SSH_REQUEST_CHANNEL,
00167 SSH_REQUEST_SERVICE,
00168 SSH_REQUEST_GLOBAL,
00169 };
00170
00171 enum ssh_channel_type_e {
00172 SSH_CHANNEL_UNKNOWN=0,
00173 SSH_CHANNEL_SESSION,
00174 SSH_CHANNEL_DIRECT_TCPIP,
00175 SSH_CHANNEL_FORWARDED_TCPIP,
00176 SSH_CHANNEL_X11
00177 };
00178
00179 enum ssh_channel_requests_e {
00180 SSH_CHANNEL_REQUEST_UNKNOWN=0,
00181 SSH_CHANNEL_REQUEST_PTY,
00182 SSH_CHANNEL_REQUEST_EXEC,
00183 SSH_CHANNEL_REQUEST_SHELL,
00184 SSH_CHANNEL_REQUEST_ENV,
00185 SSH_CHANNEL_REQUEST_SUBSYSTEM,
00186 SSH_CHANNEL_REQUEST_WINDOW_CHANGE,
00187 };
00188
00189
00190 #define SSH_CLOSED 0x01
00191 #define SSH_READ_PENDING 0x02
00192 #define SSH_CLOSED_ERROR 0x04
00193
00194 enum ssh_server_known_e {
00195 SSH_SERVER_ERROR=-1,
00196 SSH_SERVER_NOT_KNOWN=0,
00197 SSH_SERVER_KNOWN_OK,
00198 SSH_SERVER_KNOWN_CHANGED,
00199 SSH_SERVER_FOUND_OTHER,
00200 SSH_SERVER_FILE_NOT_FOUND,
00201 };
00202
00203 #ifndef MD5_DIGEST_LEN
00204 #define MD5_DIGEST_LEN 16
00205 #endif
00206
00207
00208 enum ssh_error_types_e {
00209 SSH_NO_ERROR=0,
00210 SSH_REQUEST_DENIED,
00211 SSH_FATAL,
00212 SSH_EINTR
00213 };
00214
00215
00216 #define SSH_OK 0
00217 #define SSH_ERROR -1
00218 #define SSH_AGAIN -2
00219 #define SSH_EOF -127
00220
00227 enum {
00230 SSH_LOG_NOLOG=0,
00233 SSH_LOG_RARE,
00236 SSH_LOG_PROTOCOL,
00239 SSH_LOG_PACKET,
00242 SSH_LOG_FUNCTIONS
00243 };
00247 enum ssh_options_e {
00248 SSH_OPTIONS_HOST,
00249 SSH_OPTIONS_PORT,
00250 SSH_OPTIONS_PORT_STR,
00251 SSH_OPTIONS_FD,
00252 SSH_OPTIONS_USER,
00253 SSH_OPTIONS_SSH_DIR,
00254 SSH_OPTIONS_IDENTITY,
00255 SSH_OPTIONS_ADD_IDENTITY,
00256 SSH_OPTIONS_KNOWNHOSTS,
00257 SSH_OPTIONS_TIMEOUT,
00258 SSH_OPTIONS_TIMEOUT_USEC,
00259 SSH_OPTIONS_SSH1,
00260 SSH_OPTIONS_SSH2,
00261 SSH_OPTIONS_LOG_VERBOSITY,
00262 SSH_OPTIONS_LOG_VERBOSITY_STR,
00263
00264 SSH_OPTIONS_CIPHERS_C_S,
00265 SSH_OPTIONS_CIPHERS_S_C,
00266 SSH_OPTIONS_COMPRESSION_C_S,
00267 SSH_OPTIONS_COMPRESSION_S_C
00268 };
00269
00270 enum {
00272 SSH_SCP_WRITE,
00274 SSH_SCP_READ,
00275 SSH_SCP_RECURSIVE=0x10
00276 };
00277
00278 enum ssh_scp_request_types {
00280 SSH_SCP_REQUEST_NEWDIR=1,
00282 SSH_SCP_REQUEST_NEWFILE,
00284 SSH_SCP_REQUEST_EOF,
00286 SSH_SCP_REQUEST_ENDDIR,
00288 SSH_SCP_REQUEST_WARNING
00289 };
00290
00291 LIBSSH_API void buffer_free(ssh_buffer buffer);
00292 LIBSSH_API void *buffer_get(ssh_buffer buffer);
00293 LIBSSH_API uint32_t buffer_get_len(ssh_buffer buffer);
00294 LIBSSH_API ssh_buffer buffer_new(void);
00295
00296 LIBSSH_API ssh_channel channel_accept_x11(ssh_channel channel, int timeout_ms);
00297 LIBSSH_API int channel_change_pty_size(ssh_channel channel,int cols,int rows);
00298 LIBSSH_API ssh_channel channel_forward_accept(ssh_session session, int timeout_ms);
00299 LIBSSH_API int channel_close(ssh_channel channel);
00300 LIBSSH_API int channel_forward_cancel(ssh_session session, const char *address, int port);
00301 LIBSSH_API int channel_forward_listen(ssh_session session, const char *address, int port, int *bound_port);
00302 LIBSSH_API void channel_free(ssh_channel channel);
00303 LIBSSH_API int channel_get_exit_status(ssh_channel channel);
00304 LIBSSH_API ssh_session channel_get_session(ssh_channel channel);
00305 LIBSSH_API int channel_is_closed(ssh_channel channel);
00306 LIBSSH_API int channel_is_eof(ssh_channel channel);
00307 LIBSSH_API int channel_is_open(ssh_channel channel);
00308 LIBSSH_API ssh_channel channel_new(ssh_session session);
00309 LIBSSH_API int channel_open_forward(ssh_channel channel, const char *remotehost,
00310 int remoteport, const char *sourcehost, int localport);
00311 LIBSSH_API int channel_open_session(ssh_channel channel);
00312 LIBSSH_API int channel_poll(ssh_channel channel, int is_stderr);
00313 LIBSSH_API int channel_read(ssh_channel channel, void *dest, uint32_t count, int is_stderr);
00314 LIBSSH_API int channel_read_buffer(ssh_channel channel, ssh_buffer buffer, uint32_t count,
00315 int is_stderr);
00316 LIBSSH_API int channel_read_nonblocking(ssh_channel channel, void *dest, uint32_t count,
00317 int is_stderr);
00318 LIBSSH_API int channel_request_env(ssh_channel channel, const char *name, const char *value);
00319 LIBSSH_API int channel_request_exec(ssh_channel channel, const char *cmd);
00320 LIBSSH_API int channel_request_pty(ssh_channel channel);
00321 LIBSSH_API int channel_request_pty_size(ssh_channel channel, const char *term,
00322 int cols, int rows);
00323 LIBSSH_API int channel_request_shell(ssh_channel channel);
00324 LIBSSH_API int channel_request_send_signal(ssh_channel channel, const char *signum);
00325 LIBSSH_API int channel_request_sftp(ssh_channel channel);
00326 LIBSSH_API int channel_request_subsystem(ssh_channel channel, const char *subsystem);
00327 LIBSSH_API int channel_request_x11(ssh_channel channel, int single_connection, const char *protocol,
00328 const char *cookie, int screen_number);
00329 LIBSSH_API int channel_send_eof(ssh_channel channel);
00330 LIBSSH_API int channel_select(ssh_channel *readchans, ssh_channel *writechans, ssh_channel *exceptchans, struct
00331 timeval * timeout);
00332 LIBSSH_API void channel_set_blocking(ssh_channel channel, int blocking);
00333 LIBSSH_API int channel_write(ssh_channel channel, const void *data, uint32_t len);
00334
00335 LIBSSH_API void privatekey_free(ssh_private_key prv);
00336 LIBSSH_API ssh_private_key privatekey_from_file(ssh_session session, const char *filename,
00337 int type, const char *passphrase);
00338 LIBSSH_API void publickey_free(ssh_public_key key);
00339 LIBSSH_API int ssh_publickey_to_file(ssh_session session, const char *file,
00340 ssh_string pubkey, int type);
00341 LIBSSH_API ssh_string publickey_from_file(ssh_session session, const char *filename,
00342 int *type);
00343 LIBSSH_API ssh_public_key publickey_from_privatekey(ssh_private_key prv);
00344 LIBSSH_API ssh_string publickey_to_string(ssh_public_key key);
00345 LIBSSH_API int ssh_try_publickey_from_file(ssh_session session, const char *keyfile,
00346 ssh_string *publickey, int *type);
00347
00348 LIBSSH_API int ssh_auth_list(ssh_session session);
00349 LIBSSH_API char *ssh_basename (const char *path);
00350 LIBSSH_API void ssh_clean_pubkey_hash(unsigned char **hash);
00351 LIBSSH_API int ssh_connect(ssh_session session);
00352 LIBSSH_API const char *ssh_copyright(void);
00353 LIBSSH_API void ssh_disconnect(ssh_session session);
00354 LIBSSH_API char *ssh_dirname (const char *path);
00355 LIBSSH_API int ssh_finalize(void);
00356 LIBSSH_API void ssh_free(ssh_session session);
00357 LIBSSH_API const char *ssh_get_disconnect_message(ssh_session session);
00358 LIBSSH_API const char *ssh_get_error(void *error);
00359 LIBSSH_API int ssh_get_error_code(void *error);
00360 LIBSSH_API socket_t ssh_get_fd(ssh_session session);
00361 LIBSSH_API char *ssh_get_hexa(const unsigned char *what, size_t len);
00362 LIBSSH_API char *ssh_get_issue_banner(ssh_session session);
00363 LIBSSH_API int ssh_get_openssh_version(ssh_session session);
00364 LIBSSH_API ssh_string ssh_get_pubkey(ssh_session session);
00365 LIBSSH_API int ssh_get_pubkey_hash(ssh_session session, unsigned char **hash);
00366 LIBSSH_API int ssh_get_random(void *where,int len,int strong);
00367 LIBSSH_API int ssh_get_version(ssh_session session);
00368 LIBSSH_API int ssh_get_status(ssh_session session);
00369 LIBSSH_API int ssh_init(void);
00370 LIBSSH_API int ssh_is_server_known(ssh_session session);
00371 LIBSSH_API void ssh_log(ssh_session session, int prioriry, const char *format, ...) PRINTF_ATTRIBUTE(3, 4);
00372 LIBSSH_API ssh_channel ssh_message_channel_request_open_reply_accept(ssh_message msg);
00373 LIBSSH_API int ssh_message_channel_request_reply_success(ssh_message msg);
00374 LIBSSH_API void ssh_message_free(ssh_message msg);
00375 LIBSSH_API ssh_message ssh_message_get(ssh_session session);
00376 LIBSSH_API ssh_message ssh_message_retrieve(ssh_session session, uint32_t packettype);
00377 LIBSSH_API int ssh_message_subtype(ssh_message msg);
00378 LIBSSH_API int ssh_message_type(ssh_message msg);
00379 LIBSSH_API int ssh_mkdir (const char *pathname, mode_t mode);
00380 LIBSSH_API ssh_session ssh_new(void);
00381
00382 LIBSSH_API int ssh_options_copy(ssh_session src, ssh_session *dest);
00383 LIBSSH_API int ssh_options_getopt(ssh_session session, int *argcptr, char **argv);
00384 LIBSSH_API int ssh_options_parse_config(ssh_session session, const char *filename);
00385 LIBSSH_API int ssh_options_set(ssh_session session, enum ssh_options_e type,
00386 const void *value);
00387 LIBSSH_API int ssh_pcap_file_close(ssh_pcap_file pcap);
00388 LIBSSH_API void ssh_pcap_file_free(ssh_pcap_file pcap);
00389 LIBSSH_API ssh_pcap_file ssh_pcap_file_new(void);
00390 LIBSSH_API int ssh_pcap_file_open(ssh_pcap_file pcap, const char *filename);
00391 LIBSSH_API void ssh_print_hexa(const char *descr, const unsigned char *what, size_t len);
00392 LIBSSH_API int ssh_scp_accept_request(ssh_scp scp);
00393 LIBSSH_API int ssh_scp_close(ssh_scp scp);
00394 LIBSSH_API int ssh_scp_deny_request(ssh_scp scp, const char *reason);
00395 LIBSSH_API void ssh_scp_free(ssh_scp scp);
00396 LIBSSH_API int ssh_scp_init(ssh_scp scp);
00397 LIBSSH_API int ssh_scp_leave_directory(ssh_scp scp);
00398 LIBSSH_API ssh_scp ssh_scp_new(ssh_session session, int mode, const char *location);
00399 LIBSSH_API int ssh_scp_pull_request(ssh_scp scp);
00400 LIBSSH_API int ssh_scp_push_directory(ssh_scp scp, const char *dirname, int mode);
00401 LIBSSH_API int ssh_scp_push_file(ssh_scp scp, const char *filename, size_t size, int perms);
00402 LIBSSH_API int ssh_scp_read(ssh_scp scp, void *buffer, size_t size);
00403 LIBSSH_API const char *ssh_scp_request_get_filename(ssh_scp scp);
00404 LIBSSH_API int ssh_scp_request_get_permissions(ssh_scp scp);
00405 LIBSSH_API size_t ssh_scp_request_get_size(ssh_scp scp);
00406 LIBSSH_API const char *ssh_scp_request_get_warning(ssh_scp scp);
00407 LIBSSH_API int ssh_scp_write(ssh_scp scp, const void *buffer, size_t len);
00408 LIBSSH_API int ssh_select(ssh_channel *channels, ssh_channel *outchannels, socket_t maxfd,
00409 fd_set *readfds, struct timeval *timeout);
00410 LIBSSH_API int ssh_service_request(ssh_session session, const char *service);
00411 LIBSSH_API void ssh_set_blocking(ssh_session session, int blocking);
00412 LIBSSH_API void ssh_set_fd_except(ssh_session session);
00413 LIBSSH_API void ssh_set_fd_toread(ssh_session session);
00414 LIBSSH_API void ssh_set_fd_towrite(ssh_session session);
00415 LIBSSH_API void ssh_silent_disconnect(ssh_session session);
00416 LIBSSH_API int ssh_set_pcap_file(ssh_session session, ssh_pcap_file pcapfile);
00417 #ifndef _WIN32
00418 LIBSSH_API int ssh_userauth_agent_pubkey(ssh_session session, const char *username,
00419 ssh_public_key publickey);
00420 #endif
00421 LIBSSH_API int ssh_userauth_autopubkey(ssh_session session, const char *passphrase);
00422 LIBSSH_API int ssh_userauth_kbdint(ssh_session session, const char *user, const char *submethods);
00423 LIBSSH_API const char *ssh_userauth_kbdint_getinstruction(ssh_session session);
00424 LIBSSH_API const char *ssh_userauth_kbdint_getname(ssh_session session);
00425 LIBSSH_API int ssh_userauth_kbdint_getnprompts(ssh_session session);
00426 LIBSSH_API const char *ssh_userauth_kbdint_getprompt(ssh_session session, unsigned int i, char *echo);
00427 LIBSSH_API int ssh_userauth_kbdint_setanswer(ssh_session session, unsigned int i,
00428 const char *answer);
00429 LIBSSH_API int ssh_userauth_list(ssh_session session, const char *username);
00430 LIBSSH_API int ssh_userauth_none(ssh_session session, const char *username);
00431 LIBSSH_API int ssh_userauth_offer_pubkey(ssh_session session, const char *username, int type, ssh_string publickey);
00432 LIBSSH_API int ssh_userauth_password(ssh_session session, const char *username, const char *password);
00433 LIBSSH_API int ssh_userauth_pubkey(ssh_session session, const char *username, ssh_string publickey, ssh_private_key privatekey);
00434 LIBSSH_API const char *ssh_version(int req_version);
00435 LIBSSH_API int ssh_write_knownhost(ssh_session session);
00436
00437 LIBSSH_API void string_burn(ssh_string str);
00438 LIBSSH_API ssh_string string_copy(ssh_string str);
00439 LIBSSH_API void *string_data(ssh_string str);
00440 LIBSSH_API int string_fill(ssh_string str, const void *data, size_t len);
00441 LIBSSH_API void string_free(ssh_string str);
00442 LIBSSH_API ssh_string string_from_char(const char *what);
00443 LIBSSH_API size_t string_len(ssh_string str);
00444 LIBSSH_API ssh_string string_new(size_t size);
00445 LIBSSH_API char *string_to_char(ssh_string str);
00446
00447
00448 #ifdef __cplusplus
00449 }
00450 #endif
00451 #endif
00452