libssh
0.5.2
|
00001 /* 00002 * This file is part of the SSH Library 00003 * 00004 * Copyright (c) 2003-2009 by Aris Adamantiadis 00005 * 00006 * The SSH Library is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU Lesser General Public License as published by 00008 * the Free Software Foundation; either version 2.1 of the License, or (at your 00009 * option) any later version. 00010 * 00011 * The SSH Library is distributed in the hope that it will be useful, but 00012 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 00013 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 00014 * License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public License 00017 * along with the SSH Library; see the file COPYING. If not, write to 00018 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, 00019 * MA 02111-1307, USA. 00020 */ 00021 00022 /* 00023 * priv.h file 00024 * This include file contains everything you shouldn't deal with in 00025 * user programs. Consider that anything in this file might change 00026 * without notice; libssh.h file will keep backward compatibility 00027 * on binary & source 00028 */ 00029 00030 #ifndef _LIBSSH_PRIV_H 00031 #define _LIBSSH_PRIV_H 00032 00033 #include "config.h" 00034 00035 #ifdef _WIN32 00036 00037 /* Imitate define of inttypes.h */ 00038 # ifndef PRIdS 00039 # define PRIdS "Id" 00040 # endif 00041 00042 # ifdef _MSC_VER 00043 # include <stdio.h> 00044 00045 /* On Microsoft compilers define inline to __inline on all others use inline */ 00046 # undef inline 00047 # define inline __inline 00048 00049 # define strcasecmp _stricmp 00050 # define strncasecmp _strnicmp 00051 # define strtoull _strtoui64 00052 # define isblank(ch) ((ch) == ' ' || (ch) == '\t' || (ch) == '\n' || (ch) == '\r') 00053 00054 # define usleep(X) Sleep(((X)+1000)/1000) 00055 00056 # undef strtok_r 00057 # define strtok_r strtok_s 00058 00059 # if defined(HAVE__SNPRINTF_S) 00060 # undef snprintf 00061 # define snprintf(d, n, ...) _snprintf_s((d), (n), _TRUNCATE, __VA_ARGS__) 00062 # else /* HAVE__SNPRINTF_S */ 00063 # if defined(HAVE__SNPRINTF) 00064 # undef snprintf 00065 # define snprintf _snprintf 00066 # else /* HAVE__SNPRINTF */ 00067 # if !defined(HAVE_SNPRINTF) 00068 # error "no snprintf compatible function found" 00069 # endif /* HAVE_SNPRINTF */ 00070 # endif /* HAVE__SNPRINTF */ 00071 # endif /* HAVE__SNPRINTF_S */ 00072 00073 # if defined(HAVE__VSNPRINTF_S) 00074 # undef vsnprintf 00075 # define vsnprintf(s, n, f, v) _vsnprintf_s((s), (n), _TRUNCATE, (f), (v)) 00076 # else /* HAVE__VSNPRINTF_S */ 00077 # if defined(HAVE__VSNPRINTF) 00078 # undef vsnprintf 00079 # define vsnprintf _vsnprintf 00080 # else 00081 # if !defined(HAVE_VSNPRINTF) 00082 # error "No vsnprintf compatible function found" 00083 # endif /* HAVE_VSNPRINTF */ 00084 # endif /* HAVE__VSNPRINTF */ 00085 # endif /* HAVE__VSNPRINTF_S */ 00086 00087 # endif /* _MSC_VER */ 00088 00089 #else /* _WIN32 */ 00090 00091 #include <unistd.h> 00092 #define PRIdS "zd" 00093 00094 #endif /* _WIN32 */ 00095 00096 #include "libssh/libssh.h" 00097 #include "libssh/callbacks.h" 00098 #include "libssh/crypto.h" 00099 00100 /* some constants */ 00101 #define MAX_PACKET_LEN 262144 00102 #define ERROR_BUFFERLEN 1024 00103 #define CLIENTBANNER1 "SSH-1.5-libssh-" SSH_STRINGIFY(LIBSSH_VERSION) 00104 #define CLIENTBANNER2 "SSH-2.0-libssh-" SSH_STRINGIFY(LIBSSH_VERSION) 00105 #define KBDINT_MAX_PROMPT 256 /* more than openssh's :) */ 00106 00107 #ifdef __cplusplus 00108 extern "C" { 00109 #endif 00110 00111 00112 #ifdef HAVE_SYS_TIME_H 00113 #include <sys/time.h> 00114 #endif 00115 00116 typedef struct kex_struct { 00117 unsigned char cookie[16]; 00118 char **methods; 00119 } KEX; 00120 00121 struct error_struct { 00122 /* error handling */ 00123 int error_code; 00124 char error_buffer[ERROR_BUFFERLEN]; 00125 }; 00126 00127 /* TODO: remove that include */ 00128 #include "libssh/wrapper.h" 00129 00130 struct ssh_keys_struct { 00131 const char *privatekey; 00132 const char *publickey; 00133 }; 00134 00135 struct ssh_message_struct; 00136 00137 /* server data */ 00138 00139 00140 SSH_PACKET_CALLBACK(ssh_packet_disconnect_callback); 00141 SSH_PACKET_CALLBACK(ssh_packet_ignore_callback); 00142 00143 /* client.c */ 00144 00145 int ssh_send_banner(ssh_session session, int is_server); 00146 SSH_PACKET_CALLBACK(ssh_packet_dh_reply); 00147 SSH_PACKET_CALLBACK(ssh_packet_newkeys); 00148 SSH_PACKET_CALLBACK(ssh_packet_service_accept); 00149 00150 /* config.c */ 00151 int ssh_config_parse_file(ssh_session session, const char *filename); 00152 00153 /* errors.c */ 00154 void ssh_set_error(void *error, int code, const char *descr, ...) PRINTF_ATTRIBUTE(3, 4); 00155 void ssh_set_error_oom(void *); 00156 void ssh_set_error_invalid(void *, const char *); 00157 00158 /* in crypt.c */ 00159 uint32_t packet_decrypt_len(ssh_session session,char *crypted); 00160 int packet_decrypt(ssh_session session, void *packet,unsigned int len); 00161 unsigned char *packet_encrypt(ssh_session session,void *packet,unsigned int len); 00162 /* it returns the hmac buffer if exists*/ 00163 struct ssh_poll_handle_struct; 00164 00165 int packet_hmac_verify(ssh_session session,ssh_buffer buffer,unsigned char *mac); 00166 00167 struct ssh_socket_struct; 00168 00169 int ssh_packet_socket_callback(const void *data, size_t len, void *user); 00170 void ssh_packet_register_socket_callback(ssh_session session, struct ssh_socket_struct *s); 00171 void ssh_packet_set_callbacks(ssh_session session, ssh_packet_callbacks callbacks); 00172 void ssh_packet_set_default_callbacks(ssh_session session); 00173 void ssh_packet_process(ssh_session session, uint8_t type); 00174 /* connect.c */ 00175 socket_t ssh_connect_host(ssh_session session, const char *host,const char 00176 *bind_addr, int port, long timeout, long usec); 00177 socket_t ssh_connect_host_nonblocking(ssh_session session, const char *host, 00178 const char *bind_addr, int port); 00179 void ssh_sock_set_nonblocking(socket_t sock); 00180 void ssh_sock_set_blocking(socket_t sock); 00181 00182 /* in kex.c */ 00183 extern const char *ssh_kex_nums[]; 00184 int ssh_send_kex(ssh_session session, int server_kex); 00185 void ssh_list_kex(ssh_session session, KEX *kex); 00186 int set_kex(ssh_session session); 00187 int verify_existing_algo(int algo, const char *name); 00188 char **space_tokenize(const char *chain); 00189 int ssh_get_kex1(ssh_session session); 00190 char *ssh_find_matching(const char *in_d, const char *what_d); 00191 00192 00193 /* in base64.c */ 00194 ssh_buffer base64_to_bin(const char *source); 00195 unsigned char *bin_to_base64(const unsigned char *source, int len); 00196 00197 /* gzip.c */ 00198 int compress_buffer(ssh_session session,ssh_buffer buf); 00199 int decompress_buffer(ssh_session session,ssh_buffer buf, size_t maxlen); 00200 00201 /* crc32.c */ 00202 uint32_t ssh_crc32(const char *buf, uint32_t len); 00203 00204 00205 /* match.c */ 00206 int match_hostname(const char *host, const char *pattern, unsigned int len); 00207 00208 int message_handle(ssh_session session, void *user, uint8_t type, ssh_buffer packet); 00209 /* log.c */ 00210 00211 /* misc.c */ 00212 #ifdef _WIN32 00213 int gettimeofday(struct timeval *__p, void *__t); 00214 #endif /* _WIN32 */ 00215 00216 #ifndef __FUNCTION__ 00217 #if defined(__SUNPRO_C) 00218 #define __FUNCTION__ __func__ 00219 #endif 00220 #endif 00221 00222 #define _enter_function(sess) \ 00223 do {\ 00224 if((sess)->log_verbosity >= SSH_LOG_FUNCTIONS){ \ 00225 ssh_log((sess),SSH_LOG_FUNCTIONS,"entering function %s line %d in " __FILE__ , __FUNCTION__,__LINE__);\ 00226 (sess)->log_indent++; \ 00227 } \ 00228 } while(0) 00229 00230 #define _leave_function(sess) \ 00231 do { \ 00232 if((sess)->log_verbosity >= SSH_LOG_FUNCTIONS){ \ 00233 (sess)->log_indent--; \ 00234 ssh_log((sess),SSH_LOG_FUNCTIONS,"leaving function %s line %d in " __FILE__ , __FUNCTION__,__LINE__);\ 00235 }\ 00236 } while(0) 00237 00238 #ifdef DEBUG_CALLTRACE 00239 #define enter_function() _enter_function(session) 00240 #define leave_function() _leave_function(session) 00241 #else 00242 #define enter_function() (void)session 00243 #define leave_function() (void)session 00244 #endif 00245 00246 /* options.c */ 00247 00248 int ssh_options_set_algo(ssh_session session, int algo, const char *list); 00249 int ssh_options_apply(ssh_session session); 00250 00251 /* server.c */ 00252 SSH_PACKET_CALLBACK(ssh_packet_kexdh_init); 00253 00255 #define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0) 00256 00258 #define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x)) 00259 00261 #define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((char *)(x), 0, sizeof(*(x))); } while(0) 00262 00264 #define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0])) 00265 00267 #define BURN_STRING(x) do { if ((x) != NULL) memset((x), 'X', strlen((x))); } while(0) 00268 00269 #ifdef HAVE_LIBGCRYPT 00270 /* gcrypt_missing.c */ 00271 int my_gcry_dec2bn(bignum *bn, const char *data); 00272 char *my_gcry_bn2dec(bignum bn); 00273 #endif /* !HAVE_LIBGCRYPT */ 00274 00275 #ifdef __cplusplus 00276 } 00277 #endif 00278 00279 #endif /* _LIBSSH_PRIV_H */ 00280 /* vim: set ts=2 sw=2 et cindent: */