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 _WIN32
00036
00037
00038 # ifndef PRIdS
00039 # define PRIdS "Id"
00040 # endif
00041
00042 # ifdef _MSC_VER
00043 # include <stdio.h>
00044
00045
00046 # undef inline
00047 # define inline __inline
00048
00049 # define strcasecmp _stricmp
00050 # define strncasecmp _strnicmp
00051 # define strtoull _strtoui64
00052 # define isblank(ch) ((ch) == ' ' || (ch) == '\t' || (ch) == '\n' || (ch) == '\r')
00053
00054 # define usleep(X) Sleep(((X)+1000)/1000)
00055
00056 # undef strtok_r
00057 # define strtok_r strtok_s
00058
00059 # if defined(HAVE__SNPRINTF_S)
00060 # undef snprintf
00061 # define snprintf(d, n, ...) _snprintf_s((d), (n), _TRUNCATE, __VA_ARGS__)
00062 # else
00063 # if defined(HAVE__SNPRINTF)
00064 # undef snprintf
00065 # define snprintf _snprintf
00066 # else
00067 # if !defined(HAVE_SNPRINTF)
00068 # error "no snprintf compatible function found"
00069 # endif
00070 # endif
00071 # endif
00072
00073 # if defined(HAVE__VSNPRINTF_S)
00074 # undef vsnprintf
00075 # define vsnprintf(s, n, f, v) _vsnprintf_s((s), (n), _TRUNCATE, (f), (v))
00076 # else
00077 # if defined(HAVE__VSNPRINTF)
00078 # undef vsnprintf
00079 # define vsnprintf _vsnprintf
00080 # else
00081 # if !defined(HAVE_VSNPRINTF)
00082 # error "No vsnprintf compatible function found"
00083 # endif
00084 # endif
00085 # endif
00086
00087 # endif
00088
00089 #else
00090
00091 #include <unistd.h>
00092 #define PRIdS "zd"
00093
00094 #endif
00095
00096 #include "libssh/libssh.h"
00097 #include "libssh/callbacks.h"
00098 #include "libssh/crypto.h"
00099
00100
00101 #define MAX_PACKET_LEN 262144
00102 #define ERROR_BUFFERLEN 1024
00103 #define CLIENTBANNER1 "SSH-1.5-libssh-" SSH_STRINGIFY(LIBSSH_VERSION)
00104 #define CLIENTBANNER2 "SSH-2.0-libssh-" SSH_STRINGIFY(LIBSSH_VERSION)
00105 #define KBDINT_MAX_PROMPT 256
00106
00107 #ifdef __cplusplus
00108 extern "C" {
00109 #endif
00110
00111
00112 #ifdef HAVE_SYS_TIME_H
00113 #include <sys/time.h>
00114 #endif
00115
00116 typedef struct kex_struct {
00117 unsigned char cookie[16];
00118 char **methods;
00119 } KEX;
00120
00121 struct error_struct {
00122
00123 int error_code;
00124 char error_buffer[ERROR_BUFFERLEN];
00125 };
00126
00127
00128 #include "libssh/wrapper.h"
00129
00130 struct ssh_keys_struct {
00131 const char *privatekey;
00132 const char *publickey;
00133 };
00134
00135 struct ssh_message_struct;
00136 struct ssh_common_struct;
00137
00138
00139
00140
00141 SSH_PACKET_CALLBACK(ssh_packet_disconnect_callback);
00142 SSH_PACKET_CALLBACK(ssh_packet_ignore_callback);
00143
00144
00145
00146 int ssh_send_banner(ssh_session session, int is_server);
00147 SSH_PACKET_CALLBACK(ssh_packet_dh_reply);
00148 SSH_PACKET_CALLBACK(ssh_packet_newkeys);
00149 SSH_PACKET_CALLBACK(ssh_packet_service_accept);
00150
00151
00152 int ssh_config_parse_file(ssh_session session, const char *filename);
00153
00154
00155 void ssh_set_error(void *error, int code, const char *descr, ...) PRINTF_ATTRIBUTE(3, 4);
00156 void ssh_set_error_oom(void *);
00157 void ssh_set_error_invalid(void *, const char *);
00158
00159
00160 uint32_t packet_decrypt_len(ssh_session session,char *crypted);
00161 int packet_decrypt(ssh_session session, void *packet,unsigned int len);
00162 unsigned char *packet_encrypt(ssh_session session,void *packet,unsigned int len);
00163
00164 struct ssh_poll_handle_struct;
00165
00166 int packet_hmac_verify(ssh_session session,ssh_buffer buffer,unsigned char *mac);
00167
00168 struct ssh_socket_struct;
00169
00170 int ssh_packet_socket_callback(const void *data, size_t len, void *user);
00171 void ssh_packet_register_socket_callback(ssh_session session, struct ssh_socket_struct *s);
00172 void ssh_packet_set_callbacks(ssh_session session, ssh_packet_callbacks callbacks);
00173 void ssh_packet_set_default_callbacks(ssh_session session);
00174 void ssh_packet_process(ssh_session session, uint8_t type);
00175
00176 socket_t ssh_connect_host(ssh_session session, const char *host,const char
00177 *bind_addr, int port, long timeout, long usec);
00178 socket_t ssh_connect_host_nonblocking(ssh_session session, const char *host,
00179 const char *bind_addr, int port);
00180 void ssh_sock_set_nonblocking(socket_t sock);
00181 void ssh_sock_set_blocking(socket_t sock);
00182
00183
00184 extern const char *ssh_kex_nums[];
00185 int ssh_send_kex(ssh_session session, int server_kex);
00186 void ssh_list_kex(ssh_session session, KEX *kex);
00187 int set_kex(ssh_session session);
00188 int verify_existing_algo(int algo, const char *name);
00189 char **space_tokenize(const char *chain);
00190 int ssh_get_kex1(ssh_session session);
00191 char *ssh_find_matching(const char *in_d, const char *what_d);
00192
00193
00194
00195 ssh_buffer base64_to_bin(const char *source);
00196 unsigned char *bin_to_base64(const unsigned char *source, int len);
00197
00198
00199 int compress_buffer(ssh_session session,ssh_buffer buf);
00200 int decompress_buffer(ssh_session session,ssh_buffer buf, size_t maxlen);
00201
00202
00203 uint32_t ssh_crc32(const char *buf, uint32_t len);
00204
00205
00206
00207 int match_hostname(const char *host, const char *pattern, unsigned int len);
00208
00209 int message_handle(ssh_session session, void *user, uint8_t type, ssh_buffer packet);
00210
00211
00212 void ssh_log_common(struct ssh_common_struct *common, int verbosity,
00213 const char *format, ...) PRINTF_ATTRIBUTE(3, 4);
00214
00215
00216 #ifdef _WIN32
00217 int gettimeofday(struct timeval *__p, void *__t);
00218 #endif
00219
00220 #ifndef __FUNCTION__
00221 #if defined(__SUNPRO_C)
00222 #define __FUNCTION__ __func__
00223 #endif
00224 #endif
00225
00226 #define _enter_function(sess) \
00227 do {\
00228 if((sess)->common.log_verbosity >= SSH_LOG_FUNCTIONS){ \
00229 ssh_log((sess),SSH_LOG_FUNCTIONS,"entering function %s line %d in " __FILE__ , __FUNCTION__,__LINE__);\
00230 (sess)->common.log_indent++; \
00231 } \
00232 } while(0)
00233
00234 #define _leave_function(sess) \
00235 do { \
00236 if((sess)->common.log_verbosity >= SSH_LOG_FUNCTIONS){ \
00237 (sess)->common.log_indent--; \
00238 ssh_log((sess),SSH_LOG_FUNCTIONS,"leaving function %s line %d in " __FILE__ , __FUNCTION__,__LINE__);\
00239 }\
00240 } while(0)
00241
00242 #ifdef DEBUG_CALLTRACE
00243 #define enter_function() _enter_function(session)
00244 #define leave_function() _leave_function(session)
00245 #else
00246 #define enter_function() (void)session
00247 #define leave_function() (void)session
00248 #endif
00249
00250
00251
00252 int ssh_options_set_algo(ssh_session session, int algo, const char *list);
00253 int ssh_options_apply(ssh_session session);
00254
00255
00256 SSH_PACKET_CALLBACK(ssh_packet_kexdh_init);
00257
00259 #define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
00260
00262 #define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x))
00263
00265 #define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((char *)(x), 0, sizeof(*(x))); } while(0)
00266
00268 #define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
00269
00271 #define BURN_STRING(x) do { if ((x) != NULL) memset((x), 'X', strlen((x))); } while(0)
00272
00273 #ifdef HAVE_LIBGCRYPT
00274
00275 int my_gcry_dec2bn(bignum *bn, const char *data);
00276 char *my_gcry_bn2dec(bignum bn);
00277 #endif
00278
00279 #ifdef __cplusplus
00280 }
00281 #endif
00282
00283 #endif
00284