libssh 0.4.8
|
00001 /* 00002 * This file is part of the SSH Library 00003 * 00004 * Copyright (c) 2003-2009 by Aris Adamantiadis 00005 * 00006 * The SSH Library is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU Lesser General Public License as published by 00008 * the Free Software Foundation; either version 2.1 of the License, or (at your 00009 * option) any later version. 00010 * 00011 * The SSH Library is distributed in the hope that it will be useful, but 00012 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 00013 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 00014 * License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public License 00017 * along with the SSH Library; see the file COPYING. If not, write to 00018 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, 00019 * MA 02111-1307, USA. 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 && !defined(__OS2__) 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 /* Visual Studio hasn't inttypes.h so it doesn't know uint32_t */ 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 /* _MSC_VER */ 00060 #include <unistd.h> 00061 #include <inttypes.h> 00062 #endif /* _MSC_VER */ 00063 00064 #ifdef _WIN32 00065 #include <winsock2.h> 00066 #else /* _WIN32 */ 00067 #include <sys/select.h> /* for fd_set * */ 00068 #include <netdb.h> 00069 #endif /* _WIN32 */ 00070 00071 #define SSH_STRINGIFY(s) SSH_TOSTRING(s) 00072 #define SSH_TOSTRING(s) #s 00073 00074 /* libssh version macros */ 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 /* libssh version */ 00080 #define LIBSSH_VERSION_MAJOR 0 00081 #define LIBSSH_VERSION_MINOR 4 00082 #define LIBSSH_VERSION_MICRO 8 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 /* GCC have printf type attribute check. */ 00092 #ifdef __GNUC__ 00093 #define PRINTF_ATTRIBUTE(a,b) __attribute__ ((__format__ (__printf__, a, b))) 00094 #else 00095 #define PRINTF_ATTRIBUTE(a,b) 00096 #endif /* __GNUC__ */ 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 /* Socket type */ 00121 #ifdef _WIN32 00122 #ifndef socket_t 00123 typedef SOCKET socket_t; 00124 #endif /* socket_t */ 00125 #else /* _WIN32 */ 00126 #ifndef socket_t 00127 typedef int socket_t; 00128 #endif 00129 #endif /* _WIN32 */ 00130 00131 #define SSH_INVALID_SOCKET ((socket_t) -1) 00132 00133 /* the offsets of methods */ 00134 enum ssh_kex_types_e { 00135 SSH_KEX=0, 00136 SSH_HOSTKEYS, 00137 SSH_CRYPT_C_S, 00138 SSH_CRYPT_S_C, 00139 SSH_MAC_C_S, 00140 SSH_MAC_S_C, 00141 SSH_COMP_C_S, 00142 SSH_COMP_S_C, 00143 SSH_LANG_C_S, 00144 SSH_LANG_S_C 00145 }; 00146 00147 #define SSH_CRYPT 2 00148 #define SSH_MAC 3 00149 #define SSH_COMP 4 00150 #define SSH_LANG 5 00151 00152 enum ssh_auth_e { 00153 SSH_AUTH_SUCCESS=0, 00154 SSH_AUTH_DENIED, 00155 SSH_AUTH_PARTIAL, 00156 SSH_AUTH_INFO, 00157 SSH_AUTH_ERROR=-1 00158 }; 00159 00160 /* auth flags */ 00161 #define SSH_AUTH_METHOD_UNKNOWN 0 00162 #define SSH_AUTH_METHOD_NONE 0x0001 00163 #define SSH_AUTH_METHOD_PASSWORD 0x0002 00164 #define SSH_AUTH_METHOD_PUBLICKEY 0x0004 00165 #define SSH_AUTH_METHOD_HOSTBASED 0x0008 00166 #define SSH_AUTH_METHOD_INTERACTIVE 0x0010 00167 00168 /* messages */ 00169 enum ssh_requests_e { 00170 SSH_REQUEST_AUTH=1, 00171 SSH_REQUEST_CHANNEL_OPEN, 00172 SSH_REQUEST_CHANNEL, 00173 SSH_REQUEST_SERVICE, 00174 SSH_REQUEST_GLOBAL 00175 }; 00176 00177 enum ssh_channel_type_e { 00178 SSH_CHANNEL_UNKNOWN=0, 00179 SSH_CHANNEL_SESSION, 00180 SSH_CHANNEL_DIRECT_TCPIP, 00181 SSH_CHANNEL_FORWARDED_TCPIP, 00182 SSH_CHANNEL_X11 00183 }; 00184 00185 enum ssh_channel_requests_e { 00186 SSH_CHANNEL_REQUEST_UNKNOWN=0, 00187 SSH_CHANNEL_REQUEST_PTY, 00188 SSH_CHANNEL_REQUEST_EXEC, 00189 SSH_CHANNEL_REQUEST_SHELL, 00190 SSH_CHANNEL_REQUEST_ENV, 00191 SSH_CHANNEL_REQUEST_SUBSYSTEM, 00192 SSH_CHANNEL_REQUEST_WINDOW_CHANGE 00193 }; 00194 00195 /* status flags */ 00196 #define SSH_CLOSED 0x01 00197 #define SSH_READ_PENDING 0x02 00198 #define SSH_CLOSED_ERROR 0x04 00199 00200 enum ssh_server_known_e { 00201 SSH_SERVER_ERROR=-1, 00202 SSH_SERVER_NOT_KNOWN=0, 00203 SSH_SERVER_KNOWN_OK, 00204 SSH_SERVER_KNOWN_CHANGED, 00205 SSH_SERVER_FOUND_OTHER, 00206 SSH_SERVER_FILE_NOT_FOUND 00207 }; 00208 00209 #ifndef MD5_DIGEST_LEN 00210 #define MD5_DIGEST_LEN 16 00211 #endif 00212 /* errors */ 00213 00214 enum ssh_error_types_e { 00215 SSH_NO_ERROR=0, 00216 SSH_REQUEST_DENIED, 00217 SSH_FATAL, 00218 SSH_EINTR 00219 }; 00220 00221 /* Error return codes */ 00222 #define SSH_OK 0 /* No error */ 00223 #define SSH_ERROR -1 /* Error of some kind */ 00224 #define SSH_AGAIN -2 /* The nonblocking call must be repeated */ 00225 #define SSH_EOF -127 /* We have already a eof */ 00226 00233 enum { 00236 SSH_LOG_NOLOG=0, 00239 SSH_LOG_RARE, 00242 SSH_LOG_PROTOCOL, 00245 SSH_LOG_PACKET, 00248 SSH_LOG_FUNCTIONS 00249 }; 00253 enum ssh_options_e { 00254 SSH_OPTIONS_HOST, 00255 SSH_OPTIONS_PORT, 00256 SSH_OPTIONS_PORT_STR, 00257 SSH_OPTIONS_FD, 00258 SSH_OPTIONS_USER, 00259 SSH_OPTIONS_SSH_DIR, 00260 SSH_OPTIONS_IDENTITY, 00261 SSH_OPTIONS_ADD_IDENTITY, 00262 SSH_OPTIONS_KNOWNHOSTS, 00263 SSH_OPTIONS_TIMEOUT, 00264 SSH_OPTIONS_TIMEOUT_USEC, 00265 SSH_OPTIONS_SSH1, 00266 SSH_OPTIONS_SSH2, 00267 SSH_OPTIONS_LOG_VERBOSITY, 00268 SSH_OPTIONS_LOG_VERBOSITY_STR, 00269 00270 SSH_OPTIONS_CIPHERS_C_S, 00271 SSH_OPTIONS_CIPHERS_S_C, 00272 SSH_OPTIONS_COMPRESSION_C_S, 00273 SSH_OPTIONS_COMPRESSION_S_C, 00274 SSH_OPTIONS_PROXYCOMMAND, 00275 SSH_OPTIONS_BINDADDR 00276 }; 00277 00278 enum { 00280 SSH_SCP_WRITE, 00282 SSH_SCP_READ, 00283 SSH_SCP_RECURSIVE=0x10 00284 }; 00285 00286 enum ssh_scp_request_types { 00288 SSH_SCP_REQUEST_NEWDIR=1, 00290 SSH_SCP_REQUEST_NEWFILE, 00292 SSH_SCP_REQUEST_EOF, 00294 SSH_SCP_REQUEST_ENDDIR, 00296 SSH_SCP_REQUEST_WARNING 00297 }; 00298 00299 LIBSSH_API void buffer_free(ssh_buffer buffer); 00300 LIBSSH_API void *buffer_get(ssh_buffer buffer); 00301 LIBSSH_API uint32_t buffer_get_len(ssh_buffer buffer); 00302 LIBSSH_API ssh_buffer buffer_new(void); 00303 00304 LIBSSH_API ssh_channel channel_accept_x11(ssh_channel channel, int timeout_ms); 00305 LIBSSH_API int channel_change_pty_size(ssh_channel channel,int cols,int rows); 00306 LIBSSH_API ssh_channel channel_forward_accept(ssh_session session, int timeout_ms); 00307 LIBSSH_API int channel_close(ssh_channel channel); 00308 LIBSSH_API int channel_forward_cancel(ssh_session session, const char *address, int port); 00309 LIBSSH_API int channel_forward_listen(ssh_session session, const char *address, int port, int *bound_port); 00310 LIBSSH_API void channel_free(ssh_channel channel); 00311 LIBSSH_API int channel_get_exit_status(ssh_channel channel); 00312 LIBSSH_API ssh_session channel_get_session(ssh_channel channel); 00313 LIBSSH_API int channel_is_closed(ssh_channel channel); 00314 LIBSSH_API int channel_is_eof(ssh_channel channel); 00315 LIBSSH_API int channel_is_open(ssh_channel channel); 00316 LIBSSH_API ssh_channel channel_new(ssh_session session); 00317 LIBSSH_API int channel_open_forward(ssh_channel channel, const char *remotehost, 00318 int remoteport, const char *sourcehost, int localport); 00319 LIBSSH_API int channel_open_session(ssh_channel channel); 00320 LIBSSH_API int channel_poll(ssh_channel channel, int is_stderr); 00321 LIBSSH_API int channel_read(ssh_channel channel, void *dest, uint32_t count, int is_stderr); 00322 LIBSSH_API int channel_read_buffer(ssh_channel channel, ssh_buffer buffer, uint32_t count, 00323 int is_stderr); 00324 LIBSSH_API int channel_read_nonblocking(ssh_channel channel, void *dest, uint32_t count, 00325 int is_stderr); 00326 LIBSSH_API int channel_request_env(ssh_channel channel, const char *name, const char *value); 00327 LIBSSH_API int channel_request_exec(ssh_channel channel, const char *cmd); 00328 LIBSSH_API int channel_request_pty(ssh_channel channel); 00329 LIBSSH_API int channel_request_pty_size(ssh_channel channel, const char *term, 00330 int cols, int rows); 00331 LIBSSH_API int channel_request_shell(ssh_channel channel); 00332 LIBSSH_API int channel_request_send_signal(ssh_channel channel, const char *signum); 00333 LIBSSH_API int channel_request_sftp(ssh_channel channel); 00334 LIBSSH_API int channel_request_subsystem(ssh_channel channel, const char *subsystem); 00335 LIBSSH_API int channel_request_x11(ssh_channel channel, int single_connection, const char *protocol, 00336 const char *cookie, int screen_number); 00337 LIBSSH_API int channel_send_eof(ssh_channel channel); 00338 LIBSSH_API int channel_select(ssh_channel *readchans, ssh_channel *writechans, ssh_channel *exceptchans, struct 00339 timeval * timeout); 00340 LIBSSH_API void channel_set_blocking(ssh_channel channel, int blocking); 00341 LIBSSH_API int channel_write(ssh_channel channel, const void *data, uint32_t len); 00342 00343 LIBSSH_API void privatekey_free(ssh_private_key prv); 00344 LIBSSH_API ssh_private_key privatekey_from_file(ssh_session session, const char *filename, 00345 int type, const char *passphrase); 00346 LIBSSH_API void publickey_free(ssh_public_key key); 00347 LIBSSH_API int ssh_publickey_to_file(ssh_session session, const char *file, 00348 ssh_string pubkey, int type); 00349 LIBSSH_API ssh_string publickey_from_file(ssh_session session, const char *filename, 00350 int *type); 00351 LIBSSH_API ssh_public_key publickey_from_privatekey(ssh_private_key prv); 00352 LIBSSH_API ssh_string publickey_to_string(ssh_public_key key); 00353 LIBSSH_API int ssh_try_publickey_from_file(ssh_session session, const char *keyfile, 00354 ssh_string *publickey, int *type); 00355 00356 LIBSSH_API int ssh_auth_list(ssh_session session); 00357 LIBSSH_API char *ssh_basename (const char *path); 00358 LIBSSH_API void ssh_clean_pubkey_hash(unsigned char **hash); 00359 LIBSSH_API int ssh_connect(ssh_session session); 00360 LIBSSH_API const char *ssh_copyright(void); 00361 LIBSSH_API void ssh_disconnect(ssh_session session); 00362 LIBSSH_API char *ssh_dirname (const char *path); 00363 LIBSSH_API int ssh_finalize(void); 00364 LIBSSH_API void ssh_free(ssh_session session); 00365 LIBSSH_API const char *ssh_get_disconnect_message(ssh_session session); 00366 LIBSSH_API const char *ssh_get_error(void *error); 00367 LIBSSH_API int ssh_get_error_code(void *error); 00368 LIBSSH_API socket_t ssh_get_fd(ssh_session session); 00369 LIBSSH_API char *ssh_get_hexa(const unsigned char *what, size_t len); 00370 LIBSSH_API char *ssh_get_issue_banner(ssh_session session); 00371 LIBSSH_API int ssh_get_openssh_version(ssh_session session); 00372 LIBSSH_API ssh_string ssh_get_pubkey(ssh_session session); 00373 LIBSSH_API int ssh_get_pubkey_hash(ssh_session session, unsigned char **hash); 00374 LIBSSH_API int ssh_get_random(void *where,int len,int strong); 00375 LIBSSH_API int ssh_get_version(ssh_session session); 00376 LIBSSH_API int ssh_get_status(ssh_session session); 00377 LIBSSH_API int ssh_init(void); 00378 LIBSSH_API int ssh_is_server_known(ssh_session session); 00379 LIBSSH_API void ssh_log(ssh_session session, int prioriry, const char *format, ...) PRINTF_ATTRIBUTE(3, 4); 00380 LIBSSH_API ssh_channel ssh_message_channel_request_open_reply_accept(ssh_message msg); 00381 LIBSSH_API int ssh_message_channel_request_reply_success(ssh_message msg); 00382 LIBSSH_API void ssh_message_free(ssh_message msg); 00383 LIBSSH_API ssh_message ssh_message_get(ssh_session session); 00384 LIBSSH_API ssh_message ssh_message_retrieve(ssh_session session, uint32_t packettype); 00385 LIBSSH_API int ssh_message_subtype(ssh_message msg); 00386 LIBSSH_API int ssh_message_type(ssh_message msg); 00387 LIBSSH_API int ssh_mkdir (const char *pathname, mode_t mode); 00388 LIBSSH_API ssh_session ssh_new(void); 00389 00390 LIBSSH_API int ssh_options_copy(ssh_session src, ssh_session *dest); 00391 LIBSSH_API int ssh_options_getopt(ssh_session session, int *argcptr, char **argv); 00392 LIBSSH_API int ssh_options_parse_config(ssh_session session, const char *filename); 00393 LIBSSH_API int ssh_options_set(ssh_session session, enum ssh_options_e type, 00394 const void *value); 00395 LIBSSH_API int ssh_pcap_file_close(ssh_pcap_file pcap); 00396 LIBSSH_API void ssh_pcap_file_free(ssh_pcap_file pcap); 00397 LIBSSH_API ssh_pcap_file ssh_pcap_file_new(void); 00398 LIBSSH_API int ssh_pcap_file_open(ssh_pcap_file pcap, const char *filename); 00399 00400 LIBSSH_API int ssh_privatekey_type(ssh_private_key privatekey); 00401 00402 LIBSSH_API void ssh_print_hexa(const char *descr, const unsigned char *what, size_t len); 00403 LIBSSH_API int ssh_scp_accept_request(ssh_scp scp); 00404 LIBSSH_API int ssh_scp_close(ssh_scp scp); 00405 LIBSSH_API int ssh_scp_deny_request(ssh_scp scp, const char *reason); 00406 LIBSSH_API void ssh_scp_free(ssh_scp scp); 00407 LIBSSH_API int ssh_scp_init(ssh_scp scp); 00408 LIBSSH_API int ssh_scp_leave_directory(ssh_scp scp); 00409 LIBSSH_API ssh_scp ssh_scp_new(ssh_session session, int mode, const char *location); 00410 LIBSSH_API int ssh_scp_pull_request(ssh_scp scp); 00411 LIBSSH_API int ssh_scp_push_directory(ssh_scp scp, const char *dirname, int mode); 00412 LIBSSH_API int ssh_scp_push_file(ssh_scp scp, const char *filename, size_t size, int perms); 00413 LIBSSH_API int ssh_scp_read(ssh_scp scp, void *buffer, size_t size); 00414 LIBSSH_API const char *ssh_scp_request_get_filename(ssh_scp scp); 00415 LIBSSH_API int ssh_scp_request_get_permissions(ssh_scp scp); 00416 LIBSSH_API size_t ssh_scp_request_get_size(ssh_scp scp); 00417 LIBSSH_API const char *ssh_scp_request_get_warning(ssh_scp scp); 00418 LIBSSH_API int ssh_scp_write(ssh_scp scp, const void *buffer, size_t len); 00419 LIBSSH_API int ssh_select(ssh_channel *channels, ssh_channel *outchannels, socket_t maxfd, 00420 fd_set *readfds, struct timeval *timeout); 00421 LIBSSH_API int ssh_service_request(ssh_session session, const char *service); 00422 LIBSSH_API void ssh_set_blocking(ssh_session session, int blocking); 00423 LIBSSH_API void ssh_set_fd_except(ssh_session session); 00424 LIBSSH_API void ssh_set_fd_toread(ssh_session session); 00425 LIBSSH_API void ssh_set_fd_towrite(ssh_session session); 00426 LIBSSH_API void ssh_silent_disconnect(ssh_session session); 00427 LIBSSH_API int ssh_set_pcap_file(ssh_session session, ssh_pcap_file pcapfile); 00428 #ifndef _WIN32 00429 LIBSSH_API int ssh_userauth_agent_pubkey(ssh_session session, const char *username, 00430 ssh_public_key publickey); 00431 #endif 00432 LIBSSH_API int ssh_userauth_autopubkey(ssh_session session, const char *passphrase); 00433 LIBSSH_API int ssh_userauth_kbdint(ssh_session session, const char *user, const char *submethods); 00434 LIBSSH_API const char *ssh_userauth_kbdint_getinstruction(ssh_session session); 00435 LIBSSH_API const char *ssh_userauth_kbdint_getname(ssh_session session); 00436 LIBSSH_API int ssh_userauth_kbdint_getnprompts(ssh_session session); 00437 LIBSSH_API const char *ssh_userauth_kbdint_getprompt(ssh_session session, unsigned int i, char *echo); 00438 LIBSSH_API int ssh_userauth_kbdint_setanswer(ssh_session session, unsigned int i, 00439 const char *answer); 00440 LIBSSH_API int ssh_userauth_list(ssh_session session, const char *username); 00441 LIBSSH_API int ssh_userauth_none(ssh_session session, const char *username); 00442 LIBSSH_API int ssh_userauth_offer_pubkey(ssh_session session, const char *username, int type, ssh_string publickey); 00443 LIBSSH_API int ssh_userauth_password(ssh_session session, const char *username, const char *password); 00444 LIBSSH_API int ssh_userauth_pubkey(ssh_session session, const char *username, ssh_string publickey, ssh_private_key privatekey); 00445 LIBSSH_API const char *ssh_version(int req_version); 00446 LIBSSH_API int ssh_write_knownhost(ssh_session session); 00447 00448 LIBSSH_API void string_burn(ssh_string str); 00449 LIBSSH_API ssh_string string_copy(ssh_string str); 00450 LIBSSH_API void *string_data(ssh_string str); 00451 LIBSSH_API int string_fill(ssh_string str, const void *data, size_t len); 00452 LIBSSH_API void string_free(ssh_string str); 00453 LIBSSH_API ssh_string string_from_char(const char *what); 00454 LIBSSH_API size_t string_len(ssh_string str); 00455 LIBSSH_API ssh_string string_new(size_t size); 00456 LIBSSH_API char *string_to_char(ssh_string str); 00457 00458 00459 #ifdef __cplusplus 00460 } 00461 #endif 00462 #endif /* _LIBSSH_H */ 00463 /* vim: set ts=2 sw=2 et cindent: */