00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef _LIBSSH_PRIV_H
00031 #define _LIBSSH_PRIV_H
00032
00033 #include "config.h"
00034
00035 #ifdef _MSC_VER
00036 #define snprintf _snprintf
00037
00038 #define PRIdS "Id"
00039 #define strcasecmp _stricmp
00040 #define strncasecmp _strnicmp
00041 #define strtoull _strtoui64
00042 #define isblank(ch) ((ch) == ' ' || (ch) == '\t' || (ch) == '\n' || (ch) == '\r')
00043 #else
00044 #include <unistd.h>
00045 #define PRIdS "zd"
00046 #endif
00047
00048 #include "libssh/libssh.h"
00049 #include "libssh/callbacks.h"
00050 #include "libssh/crypto.h"
00051
00052 #define MAX_PACKET_LEN 262144
00053 #define ERROR_BUFFERLEN 1024
00054 #define CLIENTBANNER1 "SSH-1.5-libssh-" SSH_STRINGIFY(LIBSSH_VERSION)
00055 #define CLIENTBANNER2 "SSH-2.0-libssh-" SSH_STRINGIFY(LIBSSH_VERSION)
00056 #define KBDINT_MAX_PROMPT 256
00057
00058 enum public_key_types_e{
00059 TYPE_DSS=1,
00060 TYPE_RSA,
00061 TYPE_RSA1
00062 };
00063
00064 #ifdef __cplusplus
00065 extern "C" {
00066 #endif
00067
00068
00069 #ifdef HAVE_SYS_TIME_H
00070 #include <sys/time.h>
00071 #endif
00072
00073 typedef struct kex_struct {
00074 unsigned char cookie[16];
00075 char **methods;
00076 } KEX;
00077
00078 struct error_struct {
00079
00080 unsigned int error_code;
00081 char error_buffer[ERROR_BUFFERLEN];
00082 };
00083
00084
00085 #include "libssh/wrapper.h"
00086
00087 struct ssh_keys_struct {
00088 const char *privatekey;
00089 const char *publickey;
00090 };
00091
00092 struct ssh_message_struct;
00093
00094
00095
00096
00097 struct ssh_bind_struct {
00098 struct error_struct error;
00099
00100 ssh_callbacks callbacks;
00101
00102
00103 char *wanted_methods[10];
00104 char *banner;
00105 char *dsakey;
00106 char *rsakey;
00107 char *bindaddr;
00108 socket_t bindfd;
00109 unsigned int bindport;
00110 unsigned int log_verbosity;
00111
00112 int blocking;
00113 int toaccept;
00114 };
00115
00116
00117
00118
00119 int ssh_send_banner(ssh_session session, int is_server);
00120 char *ssh_get_banner(ssh_session session);
00121
00122
00123 int ssh_config_parse_file(ssh_session session, const char *filename);
00124
00125
00126 void ssh_set_error(void *error, int code, const char *descr, ...) PRINTF_ATTRIBUTE(3, 4);
00127 void ssh_set_error_oom(void *);
00128 void ssh_set_error_invalid(void *, const char *);
00129
00130
00131 uint32_t packet_decrypt_len(ssh_session session,char *crypted);
00132 int packet_decrypt(ssh_session session, void *packet,unsigned int len);
00133 unsigned char *packet_encrypt(ssh_session session,void *packet,unsigned int len);
00134
00135 int packet_hmac_verify(ssh_session session,ssh_buffer buffer,unsigned char *mac);
00136
00137
00138 int ssh_regex_init(void);
00139 void ssh_regex_finalize(void);
00140 ssh_session ssh_session_new(void);
00141 socket_t ssh_connect_host(ssh_session session, const char *host,const char
00142 *bind_addr, int port, long timeout, long usec);
00143
00144
00145 extern const char *ssh_kex_nums[];
00146 int ssh_send_kex(ssh_session session, int server_kex);
00147 void ssh_list_kex(ssh_session session, KEX *kex);
00148 int set_kex(ssh_session session);
00149 int ssh_get_kex(ssh_session session, int server_kex);
00150 int verify_existing_algo(int algo, const char *name);
00151 char **space_tokenize(const char *chain);
00152 int ssh_get_kex1(ssh_session session);
00153 char *ssh_find_matching(const char *in_d, const char *what_d);
00154
00155
00156 ssh_buffer base64_to_bin(const char *source);
00157 unsigned char *bin_to_base64(const unsigned char *source, int len);
00158
00159
00160 int compress_buffer(ssh_session session,ssh_buffer buf);
00161 int decompress_buffer(ssh_session session,ssh_buffer buf, size_t maxlen);
00162
00163
00164 uint32_t ssh_crc32(const char *buf, uint32_t len);
00165
00166
00167 int ssh_userauth1_none(ssh_session session, const char *username);
00168 int ssh_userauth1_offer_pubkey(ssh_session session, const char *username,
00169 int type, ssh_string pubkey);
00170 int ssh_userauth1_password(ssh_session session, const char *username,
00171 const char *password);
00172
00173
00174 int channel_open_session1(ssh_channel channel);
00175 int channel_request_pty_size1(ssh_channel channel, const char *terminal,
00176 int cols, int rows);
00177 int channel_change_pty_size1(ssh_channel channel, int cols, int rows);
00178 int channel_request_shell1(ssh_channel channel);
00179 int channel_request_exec1(ssh_channel channel, const char *cmd);
00180 int channel_handle1(ssh_session session, int type);
00181 int channel_write1(ssh_channel channel, const void *data, int len);
00182
00183
00184 int match_hostname(const char *host, const char *pattern, unsigned int len);
00185
00186
00187
00188
00189 #ifdef _WIN32
00190 int gettimeofday(struct timeval *__p, void *__t);
00191 #endif
00192
00193 #ifndef __FUNCTION__
00194 #if defined(__SUNPRO_C)
00195 #define __FUNCTION__ __func__
00196 #endif
00197 #endif
00198
00199 #define _enter_function(sess) \
00200 do {\
00201 if((sess)->log_verbosity >= SSH_LOG_FUNCTIONS){ \
00202 ssh_log((sess),SSH_LOG_FUNCTIONS,"entering function %s line %d in " __FILE__ , __FUNCTION__,__LINE__);\
00203 (sess)->log_indent++; \
00204 } \
00205 } while(0)
00206
00207 #define _leave_function(sess) \
00208 do { \
00209 if((sess)->log_verbosity >= SSH_LOG_FUNCTIONS){ \
00210 (sess)->log_indent--; \
00211 ssh_log((sess),SSH_LOG_FUNCTIONS,"leaving function %s line %d in " __FILE__ , __FUNCTION__,__LINE__);\
00212 }\
00213 } while(0)
00214
00215 #ifdef DEBUG_CALLTRACE
00216 #define enter_function() _enter_function(session)
00217 #define leave_function() _leave_function(session)
00218 #else
00219 #define enter_function() (void)session
00220 #define leave_function() (void)session
00221 #endif
00222
00223
00224
00225 char *dir_expand_dup(ssh_session session, const char *value, int allowsshdir);
00226 int ssh_options_set_algo(ssh_session session, int algo, const char *list);
00227
00229 #define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
00230
00232 #define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x))
00233
00235 #define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((char *)(x), 0, sizeof(*(x))); } while(0)
00236
00238 #define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
00239
00241 #define BURN_STRING(x) do { if ((x) != NULL) memset((x), 'X', strlen((x))); } while(0)
00242
00243 #ifdef HAVE_LIBGCRYPT
00244
00245 int my_gcry_dec2bn(bignum *bn, const char *data);
00246 char *my_gcry_bn2dec(bignum bn);
00247 #endif
00248
00249 #ifdef __cplusplus
00250 }
00251 #endif
00252
00253 #endif
00254