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 #ifndef _LIBSSH_PRIV_H
00030 #define _LIBSSH_PRIV_H
00031
00032 #include "config.h"
00033
00034 #if !defined(HAVE_STRTOULL)
00035 # if defined(HAVE___STRTOULL)
00036 # define strtoull __strtoull
00037 # elif defined(HAVE__STRTOUI64)
00038 # define strtoull _strtoui64
00039 # elif defined(__hpux) && defined(__LP64__)
00040 # define strtoull strtoul
00041 # else
00042 # error "no strtoull function found"
00043 # endif
00044 #endif
00045
00046 #ifdef _WIN32
00047
00048
00049 # ifndef PRIdS
00050 # define PRIdS "Id"
00051 # endif
00052
00053 # ifndef PRIu64
00054 # if __WORDSIZE == 64
00055 # define PRIu64 "lu"
00056 # else
00057 # define PRIu64 "llu"
00058 # endif
00059 # endif
00060
00061 # ifdef _MSC_VER
00062 # include <stdio.h>
00063
00064
00065 # undef inline
00066 # define inline __inline
00067
00068 # define strcasecmp _stricmp
00069 # define strncasecmp _strnicmp
00070 # if ! defined(HAVE_ISBLANK)
00071 # define isblank(ch) ((ch) == ' ' || (ch) == '\t' || (ch) == '\n' || (ch) == '\r')
00072 # endif
00073
00074 # define usleep(X) Sleep(((X)+1000)/1000)
00075
00076 # undef strtok_r
00077 # define strtok_r strtok_s
00078
00079 # if defined(HAVE__SNPRINTF_S)
00080 # undef snprintf
00081 # define snprintf(d, n, ...) _snprintf_s((d), (n), _TRUNCATE, __VA_ARGS__)
00082 # else
00083 # if defined(HAVE__SNPRINTF)
00084 # undef snprintf
00085 # define snprintf _snprintf
00086 # else
00087 # if !defined(HAVE_SNPRINTF)
00088 # error "no snprintf compatible function found"
00089 # endif
00090 # endif
00091 # endif
00092
00093 # if defined(HAVE__VSNPRINTF_S)
00094 # undef vsnprintf
00095 # define vsnprintf(s, n, f, v) _vsnprintf_s((s), (n), _TRUNCATE, (f), (v))
00096 # else
00097 # if defined(HAVE__VSNPRINTF)
00098 # undef vsnprintf
00099 # define vsnprintf _vsnprintf
00100 # else
00101 # if !defined(HAVE_VSNPRINTF)
00102 # error "No vsnprintf compatible function found"
00103 # endif
00104 # endif
00105 # endif
00106
00107 # endif
00108
00109 struct timeval;
00110 int gettimeofday(struct timeval *__p, void *__t);
00111
00112 #else
00113
00114 #include <unistd.h>
00115 #define PRIdS "zd"
00116
00117 #endif
00118
00119 #include "libssh/libssh.h"
00120 #include "libssh/callbacks.h"
00121
00122
00123 #ifndef MAX_PACKAT_LEN
00124 #define MAX_PACKET_LEN 262144
00125 #endif
00126 #ifndef ERROR_BUFFERLEN
00127 #define ERROR_BUFFERLEN 1024
00128 #endif
00129 #ifndef CLIENTBANNER1
00130 #define CLIENTBANNER1 "SSH-1.5-libssh-" SSH_STRINGIFY(LIBSSH_VERSION)
00131 #endif
00132 #ifndef CLIENTBANNER2
00133 #define CLIENTBANNER2 "SSH-2.0-libssh-" SSH_STRINGIFY(LIBSSH_VERSION)
00134 #endif
00135 #ifndef KBDINT_MAX_PROMPT
00136 #define KBDINT_MAX_PROMPT 256
00137 #endif
00138 #ifndef MAX_BUF_SIZE
00139 #define MAX_BUF_SIZE 4096
00140 #endif
00141
00142 #ifndef HAVE_COMPILER__FUNC__
00143 # ifdef HAVE_COMPILER__FUNCTION__
00144 # define __func__ __FUNCTION__
00145 # else
00146 # error "Your system must provide a __func__ macro"
00147 # endif
00148 #endif
00149
00150 #if defined(HAVE_GCC_THREAD_LOCAL_STORAGE)
00151 # define LIBSSH_THREAD __thread
00152 #elif defined(HAVE_MSC_THREAD_LOCAL_STORAGE)
00153 # define LIBSSH_THREAD __declspec(thread)
00154 #else
00155 # define LIBSSH_THREAD
00156 #endif
00157
00158
00159
00160
00161
00162
00163 #if defined(HAVE_GCC_VOLATILE_MEMORY_PROTECTION)
00164 # define LIBSSH_MEM_PROTECTION __asm__ volatile("" : : "r"(&(x)) : "memory")
00165 #else
00166 # define LIBSSH_MEM_PROTECTION
00167 #endif
00168
00169 #ifdef HAVE_SYS_TIME_H
00170 #include <sys/time.h>
00171 #endif
00172
00173
00174 struct ssh_common_struct;
00175 struct ssh_kex_struct;
00176
00177 int ssh_get_key_params(ssh_session session, ssh_key *privkey);
00178
00179
00180 void ssh_log_function(int verbosity,
00181 const char *function,
00182 const char *buffer);
00183 #define SSH_LOG(priority, ...) \
00184 _ssh_log(priority, __func__, __VA_ARGS__)
00185
00186
00187 void ssh_log_common(struct ssh_common_struct *common,
00188 int verbosity,
00189 const char *function,
00190 const char *format, ...) PRINTF_ATTRIBUTE(4, 5);
00191
00192
00193
00194
00195
00196 struct error_struct {
00197 int error_code;
00198 char error_buffer[ERROR_BUFFERLEN];
00199 };
00200
00201 #define ssh_set_error(error, code, ...) \
00202 _ssh_set_error(error, code, __func__, __VA_ARGS__)
00203 void _ssh_set_error(void *error,
00204 int code,
00205 const char *function,
00206 const char *descr, ...) PRINTF_ATTRIBUTE(4, 5);
00207
00208 #define ssh_set_error_oom(error) \
00209 _ssh_set_error_oom(error, __func__)
00210 void _ssh_set_error_oom(void *error, const char *function);
00211
00212 #define ssh_set_error_invalid(error) \
00213 _ssh_set_error_invalid(error, __func__)
00214 void _ssh_set_error_invalid(void *error, const char *function);
00215
00216
00217
00218 #ifdef WITH_SERVER
00219 int ssh_auth_reply_default(ssh_session session,int partial);
00220 int ssh_auth_reply_success(ssh_session session, int partial);
00221 #endif
00222
00223
00224 int ssh_send_banner(ssh_session session, int is_server);
00225
00226
00227 socket_t ssh_connect_host(ssh_session session, const char *host,const char
00228 *bind_addr, int port, long timeout, long usec);
00229 socket_t ssh_connect_host_nonblocking(ssh_session session, const char *host,
00230 const char *bind_addr, int port);
00231
00232
00233 ssh_buffer base64_to_bin(const char *source);
00234 unsigned char *bin_to_base64(const unsigned char *source, int len);
00235
00236
00237 int compress_buffer(ssh_session session,ssh_buffer buf);
00238 int decompress_buffer(ssh_session session,ssh_buffer buf, size_t maxlen);
00239
00240
00241 int match_hostname(const char *host, const char *pattern, unsigned int len);
00242
00243
00244
00245
00247 #define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
00248
00250 #define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x))
00251
00253 #define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((char *)(x), 0, sizeof(*(x))); } while(0)
00254
00256 #define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
00257
00258
00259
00260
00261 #if defined(HAVE_GCC_VOLATILE_MEMORY_PROTECTION)
00262
00263 # define BURN_STRING(x) do { \
00264 if ((x) != NULL) \
00265 memset((x), '\0', strlen((x))); __asm__ volatile("" : : "r"(&(x)) : "memory"); \
00266 } while(0)
00267
00269 # define BURN_BUFFER(x, size) do { \
00270 if ((x) != NULL) \
00271 memset((x), '\0', (size)); __asm__ volatile("" : : "r"(&(x)) : "memory"); \
00272 } while(0)
00273 #else
00274
00275 # define BURN_STRING(x) do { \
00276 if ((x) != NULL) memset((x), '\0', strlen((x))); \
00277 } while(0)
00278
00280 # define BURN_BUFFER(x, size) do { \
00281 if ((x) != NULL) \
00282 memset((x), '\0', (size)); \
00283 } while(0)
00284 #endif
00285
00298 #define discard_const(ptr) ((void *)((uintptr_t)(ptr)))
00299
00303 #define discard_const_p(type, ptr) ((type *)discard_const(ptr))
00304
00305 #endif
00306