29 #ifndef _LIBSSH_PRIV_H
30 #define _LIBSSH_PRIV_H
34 #if !defined(HAVE_STRTOULL)
35 # if defined(HAVE___STRTOULL)
36 # define strtoull __strtoull
37 # elif defined(HAVE__STRTOUI64)
38 # define strtoull _strtoui64
39 # elif defined(__hpux) && defined(__LP64__)
40 # define strtoull strtoul
42 # error "no strtoull function found"
66 # define inline __inline
68 # define strcasecmp _stricmp
69 # define strncasecmp _strnicmp
70 # if ! defined(HAVE_ISBLANK)
71 # define isblank(ch) ((ch) == ' ' || (ch) == '\t' || (ch) == '\n' || (ch) == '\r')
74 # define usleep(X) Sleep(((X)+1000)/1000)
77 # define strtok_r strtok_s
79 # if defined(HAVE__SNPRINTF_S)
81 # define snprintf(d, n, ...) _snprintf_s((d), (n), _TRUNCATE, __VA_ARGS__)
83 # if defined(HAVE__SNPRINTF)
85 # define snprintf _snprintf
87 # if !defined(HAVE_SNPRINTF)
88 # error "no snprintf compatible function found"
93 # if defined(HAVE__VSNPRINTF_S)
95 # define vsnprintf(s, n, f, v) _vsnprintf_s((s), (n), _TRUNCATE, (f), (v))
97 # if defined(HAVE__VSNPRINTF)
99 # define vsnprintf _vsnprintf
101 # if !defined(HAVE_VSNPRINTF)
102 # error "No vsnprintf compatible function found"
110 int gettimeofday(
struct timeval *__p,
void *__t);
112 #define _XCLOSESOCKET closesocket
119 #define _XCLOSESOCKET close
123 #include "libssh/libssh.h"
124 #include "libssh/callbacks.h"
127 #ifndef MAX_PACKAT_LEN
128 #define MAX_PACKET_LEN 262144
130 #ifndef ERROR_BUFFERLEN
131 #define ERROR_BUFFERLEN 1024
133 #ifndef CLIENTBANNER1
134 #define CLIENTBANNER1 "SSH-1.5-libssh-" SSH_STRINGIFY(LIBSSH_VERSION)
136 #ifndef CLIENTBANNER2
137 #define CLIENTBANNER2 "SSH-2.0-libssh-" SSH_STRINGIFY(LIBSSH_VERSION)
139 #ifndef KBDINT_MAX_PROMPT
140 #define KBDINT_MAX_PROMPT 256
143 #define MAX_BUF_SIZE 4096
146 #ifndef HAVE_COMPILER__FUNC__
147 # ifdef HAVE_COMPILER__FUNCTION__
148 # define __func__ __FUNCTION__
150 # error "Your system must provide a __func__ macro"
154 #if defined(HAVE_GCC_THREAD_LOCAL_STORAGE)
155 # define LIBSSH_THREAD __thread
156 #elif defined(HAVE_MSC_THREAD_LOCAL_STORAGE)
157 # define LIBSSH_THREAD __declspec(thread)
159 # define LIBSSH_THREAD
167 #if defined(HAVE_GCC_VOLATILE_MEMORY_PROTECTION)
168 # define LIBSSH_MEM_PROTECTION __asm__ volatile("" : : "r"(&(x)) : "memory")
170 # define LIBSSH_MEM_PROTECTION
173 #ifdef HAVE_SYS_TIME_H
174 #include <sys/time.h>
178 struct ssh_common_struct;
179 struct ssh_kex_struct;
181 int ssh_get_key_params(ssh_session session, ssh_key *privkey);
184 void ssh_log_function(
int verbosity,
185 const char *
function,
187 #define SSH_LOG(priority, ...) \
188 _ssh_log(priority, __func__, __VA_ARGS__)
191 void ssh_log_common(
struct ssh_common_struct *common,
193 const char *
function,
194 const char *format, ...) PRINTF_ATTRIBUTE(4, 5);
200 struct error_struct {
202 char error_buffer[ERROR_BUFFERLEN];
205 #define ssh_set_error(error, code, ...) \
206 _ssh_set_error(error, code, __func__, __VA_ARGS__)
207 void _ssh_set_error(
void *error,
209 const char *
function,
210 const char *descr, ...) PRINTF_ATTRIBUTE(4, 5);
212 #define ssh_set_error_oom(error) \
213 _ssh_set_error_oom(error, __func__)
214 void _ssh_set_error_oom(
void *error,
const char *
function);
216 #define ssh_set_error_invalid(error) \
217 _ssh_set_error_invalid(error, __func__)
218 void _ssh_set_error_invalid(
void *error,
const char *
function);
223 int ssh_auth_reply_default(ssh_session session,
int partial);
224 int ssh_auth_reply_success(ssh_session session,
int partial);
228 int ssh_send_banner(ssh_session session,
int is_server);
231 socket_t ssh_connect_host(ssh_session session,
const char *host,
const char
232 *bind_addr,
int port,
long timeout,
long usec);
233 socket_t ssh_connect_host_nonblocking(ssh_session session,
const char *host,
234 const char *bind_addr,
int port);
237 ssh_buffer base64_to_bin(
const char *source);
238 unsigned char *bin_to_base64(
const unsigned char *source,
int len);
241 int compress_buffer(ssh_session session,ssh_buffer buf);
242 int decompress_buffer(ssh_session session,ssh_buffer buf,
size_t maxlen);
245 int match_hostname(
const char *host,
const char *pattern,
unsigned int len);
248 #define MIN(a,b) ((a) < (b) ? (a) : (b))
252 #define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
255 #define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x))
258 #define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((char *)(x), 0, sizeof(*(x))); } while(0)
261 #define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
266 #if defined(HAVE_GCC_VOLATILE_MEMORY_PROTECTION)
268 # define BURN_STRING(x) do { \
270 memset((x), '\0', strlen((x))); __asm__ volatile("" : : "r"(&(x)) : "memory"); \
274 # define BURN_BUFFER(x, size) do { \
276 memset((x), '\0', (size)); __asm__ volatile("" : : "r"(&(x)) : "memory"); \
280 # define BURN_STRING(x) do { \
281 if ((x) != NULL) memset((x), '\0', strlen((x))); \
285 # define BURN_BUFFER(x, size) do { \
287 memset((x), '\0', (size)); \
303 #define discard_const(ptr) ((void *)((uintptr_t)(ptr)))
308 #define discard_const_p(type, ptr) ((type *)discard_const(ptr))
313 #ifdef HAVE_GCC_NARG_MACRO
320 #define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
322 #define __VA_NARG__(...) \
323 (__VA_NARG_(_0, ## __VA_ARGS__, __RSEQ_N()) - 1)
324 #define __VA_NARG_(...) \
325 VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
326 #define __VA_ARG_N( \
327 _1, _2, _3, _4, _5, _6, _7, _8, _9,_10, \
328 _11,_12,_13,_14,_15,_16,_17,_18,_19,_20, \
329 _21,_22,_23,_24,_25,_26,_27,_28,_29,_30, \
330 _31,_32,_33,_34,_35,_36,_37,_38,_39,_40, \
331 _41,_42,_43,_44,_45,_46,_47,_48,_49,_50, \
332 _51,_52,_53,_54,_55,_56,_57,_58,_59,_60, \
336 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, \
337 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, \
338 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, \
339 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, \
340 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, \
341 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
344 #define __VA_NARG__(...) (-1)
347 #define CLOSE_SOCKET(s) do { if ((s) != SSH_INVALID_SOCKET) { _XCLOSESOCKET(s); (s) = SSH_INVALID_SOCKET;} } while(0)