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
142 #ifndef HAVE_COMPILER__FUNC__
143 # ifdef HAVE_COMPILER__FUNCTION__
144 # define __func__ __FUNCTION__
146 # error "Your system must provide a __func__ macro"
150 #if defined(HAVE_GCC_THREAD_LOCAL_STORAGE)
151 # define LIBSSH_THREAD __thread
152 #elif defined(HAVE_MSC_THREAD_LOCAL_STORAGE)
153 # define LIBSSH_THREAD __declspec(thread)
155 # define LIBSSH_THREAD
163 #if defined(HAVE_GCC_VOLATILE_MEMORY_PROTECTION)
164 # define LIBSSH_MEM_PROTECTION __asm__ volatile("" : : "r"(&(x)) : "memory")
166 # define LIBSSH_MEM_PROTECTION
169 #ifdef HAVE_SYS_TIME_H
170 #include <sys/time.h>
174 struct ssh_common_struct;
175 struct ssh_kex_struct;
177 int ssh_get_key_params(ssh_session session, ssh_key *privkey);
180 void ssh_log_function(
int verbosity,
181 const char *
function,
183 #define SSH_LOG(priority, ...) \
184 _ssh_log(priority, __func__, __VA_ARGS__)
187 void ssh_log_common(
struct ssh_common_struct *common,
189 const char *
function,
190 const char *format, ...) PRINTF_ATTRIBUTE(4, 5);
196 struct error_struct {
198 char error_buffer[ERROR_BUFFERLEN];
201 #define ssh_set_error(error, code, ...) \
202 _ssh_set_error(error, code, __func__, __VA_ARGS__)
203 void _ssh_set_error(
void *error,
205 const char *
function,
206 const char *descr, ...) PRINTF_ATTRIBUTE(4, 5);
208 #define ssh_set_error_oom(error) \
209 _ssh_set_error_oom(error, __func__)
210 void _ssh_set_error_oom(
void *error,
const char *
function);
212 #define ssh_set_error_invalid(error) \
213 _ssh_set_error_invalid(error, __func__)
214 void _ssh_set_error_invalid(
void *error,
const char *
function);
219 int ssh_auth_reply_default(ssh_session session,
int partial);
220 int ssh_auth_reply_success(ssh_session session,
int partial);
224 int ssh_send_banner(ssh_session session,
int is_server);
227 socket_t ssh_connect_host(ssh_session session,
const char *host,
const char
228 *bind_addr,
int port,
long timeout,
long usec);
229 socket_t ssh_connect_host_nonblocking(ssh_session session,
const char *host,
230 const char *bind_addr,
int port);
233 ssh_buffer base64_to_bin(
const char *source);
234 unsigned char *bin_to_base64(
const unsigned char *source,
int len);
237 int compress_buffer(ssh_session session,ssh_buffer buf);
238 int decompress_buffer(ssh_session session,ssh_buffer buf,
size_t maxlen);
241 int match_hostname(
const char *host,
const char *pattern,
unsigned int len);
247 #define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
250 #define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x))
253 #define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((char *)(x), 0, sizeof(*(x))); } while(0)
256 #define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
261 #if defined(HAVE_GCC_VOLATILE_MEMORY_PROTECTION)
263 # define BURN_STRING(x) do { \
265 memset((x), '\0', strlen((x))); __asm__ volatile("" : : "r"(&(x)) : "memory"); \
269 # define BURN_BUFFER(x, size) do { \
271 memset((x), '\0', (size)); __asm__ volatile("" : : "r"(&(x)) : "memory"); \
275 # define BURN_STRING(x) do { \
276 if ((x) != NULL) memset((x), '\0', strlen((x))); \
280 # define BURN_BUFFER(x, size) do { \
282 memset((x), '\0', (size)); \
298 #define discard_const(ptr) ((void *)((uintptr_t)(ptr)))
303 #define discard_const_p(type, ptr) ((type *)discard_const(ptr))