30 #ifndef _LIBSSH_PRIV_H
31 #define _LIBSSH_PRIV_H
47 # define inline __inline
49 # define strcasecmp _stricmp
50 # define strncasecmp _strnicmp
51 # define strtoull _strtoui64
52 # define isblank(ch) ((ch) == ' ' || (ch) == '\t' || (ch) == '\n' || (ch) == '\r')
54 # define usleep(X) Sleep(((X)+1000)/1000)
57 # define strtok_r strtok_s
59 # if defined(HAVE__SNPRINTF_S)
61 # define snprintf(d, n, ...) _snprintf_s((d), (n), _TRUNCATE, __VA_ARGS__)
63 # if defined(HAVE__SNPRINTF)
65 # define snprintf _snprintf
67 # if !defined(HAVE_SNPRINTF)
68 # error "no snprintf compatible function found"
73 # if defined(HAVE__VSNPRINTF_S)
75 # define vsnprintf(s, n, f, v) _vsnprintf_s((s), (n), _TRUNCATE, (f), (v))
77 # if defined(HAVE__VSNPRINTF)
79 # define vsnprintf _vsnprintf
81 # if !defined(HAVE_VSNPRINTF)
82 # error "No vsnprintf compatible function found"
96 #include "libssh/libssh.h"
97 #include "libssh/callbacks.h"
98 #include "libssh/crypto.h"
101 #define MAX_PACKET_LEN 262144
102 #define ERROR_BUFFERLEN 1024
103 #define CLIENTBANNER1 "SSH-1.5-libssh-" SSH_STRINGIFY(LIBSSH_VERSION)
104 #define CLIENTBANNER2 "SSH-2.0-libssh-" SSH_STRINGIFY(LIBSSH_VERSION)
105 #define KBDINT_MAX_PROMPT 256
112 #ifdef HAVE_SYS_TIME_H
113 #include <sys/time.h>
116 typedef struct kex_struct {
117 unsigned char cookie[16];
121 struct error_struct {
124 char error_buffer[ERROR_BUFFERLEN];
128 #include "libssh/wrapper.h"
130 struct ssh_keys_struct {
131 const char *privatekey;
132 const char *publickey;
135 struct ssh_message_struct;
136 struct ssh_common_struct;
146 int ssh_send_banner(ssh_session session,
int is_server);
152 int ssh_config_parse_file(ssh_session session,
const char *filename);
155 void ssh_set_error(
void *error,
int code,
const char *descr, ...) PRINTF_ATTRIBUTE(3, 4);
156 void ssh_set_error_oom(
void *);
157 void ssh_set_error_invalid(
void *, const
char *);
160 uint32_t packet_decrypt_len(ssh_session session,
char *crypted);
161 int packet_decrypt(ssh_session session,
void *packet,
unsigned int len);
162 unsigned char *packet_encrypt(ssh_session session,
void *packet,
unsigned int len);
164 struct ssh_poll_handle_struct;
166 int packet_hmac_verify(ssh_session session,ssh_buffer buffer,
unsigned char *mac);
168 struct ssh_socket_struct;
170 int ssh_packet_socket_callback(const
void *data,
size_t len,
void *user);
171 void ssh_packet_register_socket_callback(ssh_session session, struct ssh_socket_struct *s);
172 void ssh_packet_set_callbacks(ssh_session session, ssh_packet_callbacks callbacks);
173 void ssh_packet_set_default_callbacks(ssh_session session);
174 void ssh_packet_process(ssh_session session, uint8_t type);
176 socket_t ssh_connect_host(ssh_session session, const
char *host,const
char
177 *bind_addr,
int port,
long timeout,
long usec);
178 socket_t ssh_connect_host_nonblocking(ssh_session session, const
char *host,
179 const
char *bind_addr,
int port);
180 void ssh_sock_set_nonblocking(socket_t sock);
181 void ssh_sock_set_blocking(socket_t sock);
184 extern const
char *ssh_kex_nums[];
185 int ssh_send_kex(ssh_session session,
int server_kex);
186 void ssh_list_kex(ssh_session session, KEX *kex);
187 int set_kex(ssh_session session);
188 int verify_existing_algo(
int algo, const
char *name);
189 char **space_tokenize(const
char *chain);
190 int ssh_get_kex1(ssh_session session);
191 char *ssh_find_matching(const
char *in_d, const
char *what_d);
195 ssh_buffer base64_to_bin(const
char *source);
196 unsigned char *bin_to_base64(const
unsigned char *source,
int len);
199 int compress_buffer(ssh_session session,ssh_buffer buf);
200 int decompress_buffer(ssh_session session,ssh_buffer buf,
size_t maxlen);
203 uint32_t ssh_crc32(const
char *buf, uint32_t len);
207 int match_hostname(const
char *host, const
char *pattern,
unsigned int len);
209 int message_handle(ssh_session session,
void *user, uint8_t type, ssh_buffer packet);
212 void ssh_log_common(struct ssh_common_struct *common,
int verbosity,
213 const
char *format, ...) PRINTF_ATTRIBUTE(3, 4);
217 int gettimeofday(
struct timeval *__p,
void *__t);
221 #if defined(__SUNPRO_C)
222 #define __FUNCTION__ __func__
226 #define _enter_function(sess) \
228 if((sess)->common.log_verbosity >= SSH_LOG_FUNCTIONS){ \
229 ssh_log((sess),SSH_LOG_FUNCTIONS,"entering function %s line %d in " __FILE__ , __FUNCTION__,__LINE__);\
230 (sess)->common.log_indent++; \
234 #define _leave_function(sess) \
236 if((sess)->common.log_verbosity >= SSH_LOG_FUNCTIONS){ \
237 (sess)->common.log_indent--; \
238 ssh_log((sess),SSH_LOG_FUNCTIONS,"leaving function %s line %d in " __FILE__ , __FUNCTION__,__LINE__);\
242 #ifdef DEBUG_CALLTRACE
243 #define enter_function() _enter_function(session)
244 #define leave_function() _leave_function(session)
246 #define enter_function() (void)session
247 #define leave_function() (void)session
252 int ssh_options_set_algo(ssh_session session,
int algo,
const char *list);
253 int ssh_options_apply(ssh_session session);
259 #define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
262 #define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x))
265 #define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((char *)(x), 0, sizeof(*(x))); } while(0)
268 #define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
271 #define BURN_STRING(x) do { if ((x) != NULL) memset((x), 'X', strlen((x))); } while(0)
273 #ifdef HAVE_LIBGCRYPT
275 int my_gcry_dec2bn(bignum *bn,
const char *data);
276 char *my_gcry_bn2dec(bignum bn);