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);
119 #include "libssh/libssh.h"
120 #include "libssh/callbacks.h"
123 #ifndef MAX_PACKAT_LEN
124 #define MAX_PACKET_LEN 262144
126 #ifndef ERROR_BUFFERLEN
127 #define ERROR_BUFFERLEN 1024
129 #ifndef CLIENTBANNER1
130 #define CLIENTBANNER1 "SSH-1.5-libssh-" SSH_STRINGIFY(LIBSSH_VERSION)
132 #ifndef CLIENTBANNER2
133 #define CLIENTBANNER2 "SSH-2.0-libssh-" SSH_STRINGIFY(LIBSSH_VERSION)
135 #ifndef KBDINT_MAX_PROMPT
136 #define KBDINT_MAX_PROMPT 256
139 #define MAX_BUF_SIZE 4096
143 #if defined(__SUNPRO_C)
144 #define __FUNCTION__ __func__
148 #if defined(HAVE_GCC_THREAD_LOCAL_STORAGE)
149 # define LIBSSH_THREAD __thread
150 #elif defined(HAVE_MSC_THREAD_LOCAL_STORAGE)
151 # define LIBSSH_THREAD __declspec(thread)
153 # define LIBSSH_THREAD
161 #if defined(HAVE_GCC_VOLATILE_MEMORY_PROTECTION)
162 # define LIBSSH_MEM_PROTECTION __asm__ volatile("" : : "r"(&(x)) : "memory")
164 # define LIBSSH_MEM_PROTECTION
167 #ifdef HAVE_SYS_TIME_H
168 #include <sys/time.h>
172 struct ssh_common_struct;
173 struct ssh_kex_struct;
175 int ssh_get_key_params(ssh_session session, ssh_key *privkey);
178 void ssh_log_function(
int verbosity,
179 const char *
function,
181 #define SSH_LOG(priority, ...) \
182 _ssh_log(priority, __FUNCTION__, __VA_ARGS__)
185 void ssh_log_common(
struct ssh_common_struct *common,
187 const char *
function,
188 const char *format, ...) PRINTF_ATTRIBUTE(4, 5);
194 struct error_struct {
196 char error_buffer[ERROR_BUFFERLEN];
199 #define ssh_set_error(error, code, ...) \
200 _ssh_set_error(error, code, __FUNCTION__, __VA_ARGS__)
201 void _ssh_set_error(
void *error,
203 const char *
function,
204 const char *descr, ...) PRINTF_ATTRIBUTE(4, 5);
206 #define ssh_set_error_oom(error) \
207 _ssh_set_error_oom(error, __FUNCTION__)
208 void _ssh_set_error_oom(
void *error,
const char *
function);
210 #define ssh_set_error_invalid(error) \
211 _ssh_set_error_invalid(error, __FUNCTION__)
212 void _ssh_set_error_invalid(
void *error,
const char *
function);
217 int ssh_auth_reply_default(ssh_session session,
int partial);
218 int ssh_auth_reply_success(ssh_session session,
int partial);
222 int ssh_send_banner(ssh_session session,
int is_server);
225 socket_t ssh_connect_host(ssh_session session,
const char *host,
const char
226 *bind_addr,
int port,
long timeout,
long usec);
227 socket_t ssh_connect_host_nonblocking(ssh_session session,
const char *host,
228 const char *bind_addr,
int port);
231 ssh_buffer base64_to_bin(
const char *source);
232 unsigned char *bin_to_base64(
const unsigned char *source,
int len);
235 int compress_buffer(ssh_session session,ssh_buffer buf);
236 int decompress_buffer(ssh_session session,ssh_buffer buf,
size_t maxlen);
239 int match_hostname(
const char *host,
const char *pattern,
unsigned int len);
245 #define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
248 #define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x))
251 #define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((char *)(x), 0, sizeof(*(x))); } while(0)
254 #define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
259 #if defined(HAVE_GCC_VOLATILE_MEMORY_PROTECTION)
261 # define BURN_STRING(x) do { \
263 memset((x), '\0', strlen((x))); __asm__ volatile("" : : "r"(&(x)) : "memory"); \
267 # define BURN_BUFFER(x, size) do { \
269 memset((x), '\0', (size)); __asm__ volatile("" : : "r"(&(x)) : "memory"); \
273 # define BURN_STRING(x) do { \
274 if ((x) != NULL) memset((x), '\0', strlen((x))); \
278 # define BURN_BUFFER(x, size) do { \
280 memset((x), '\0', (size)); \
296 #define discard_const(ptr) ((void *)((uintptr_t)(ptr)))
301 #define discard_const_p(type, ptr) ((type *)discard_const(ptr))