libssh 0.5.4
|
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 struct ssh_common_struct; 00137 00138 /* server data */ 00139 00140 00141 SSH_PACKET_CALLBACK(ssh_packet_disconnect_callback); 00142 SSH_PACKET_CALLBACK(ssh_packet_ignore_callback); 00143 00144 /* client.c */ 00145 00146 int ssh_send_banner(ssh_session session, int is_server); 00147 SSH_PACKET_CALLBACK(ssh_packet_dh_reply); 00148 SSH_PACKET_CALLBACK(ssh_packet_newkeys); 00149 SSH_PACKET_CALLBACK(ssh_packet_service_accept); 00150 00151 /* config.c */ 00152 int ssh_config_parse_file(ssh_session session, const char *filename); 00153 00154 /* errors.c */ 00155 void ssh_set_error(void *error, int code, const char *descr, ...) PRINTF_ATTRIBUTE(3, 4); 00156 void ssh_set_error_oom(void *); 00157 void ssh_set_error_invalid(void *, const char *); 00158 00159 /* in crypt.c */ 00160 uint32_t packet_decrypt_len(ssh_session session,char *crypted); 00161 int packet_decrypt(ssh_session session, void *packet,unsigned int len); 00162 unsigned char *packet_encrypt(ssh_session session,void *packet,unsigned int len); 00163 /* it returns the hmac buffer if exists*/ 00164 struct ssh_poll_handle_struct; 00165 00166 int packet_hmac_verify(ssh_session session,ssh_buffer buffer,unsigned char *mac); 00167 00168 struct ssh_socket_struct; 00169 00170 int ssh_packet_socket_callback(const void *data, size_t len, void *user); 00171 void ssh_packet_register_socket_callback(ssh_session session, struct ssh_socket_struct *s); 00172 void ssh_packet_set_callbacks(ssh_session session, ssh_packet_callbacks callbacks); 00173 void ssh_packet_set_default_callbacks(ssh_session session); 00174 void ssh_packet_process(ssh_session session, uint8_t type); 00175 /* connect.c */ 00176 socket_t ssh_connect_host(ssh_session session, const char *host,const char 00177 *bind_addr, int port, long timeout, long usec); 00178 socket_t ssh_connect_host_nonblocking(ssh_session session, const char *host, 00179 const char *bind_addr, int port); 00180 void ssh_sock_set_nonblocking(socket_t sock); 00181 void ssh_sock_set_blocking(socket_t sock); 00182 00183 /* in kex.c */ 00184 extern const char *ssh_kex_nums[]; 00185 int ssh_send_kex(ssh_session session, int server_kex); 00186 void ssh_list_kex(ssh_session session, KEX *kex); 00187 int set_kex(ssh_session session); 00188 int verify_existing_algo(int algo, const char *name); 00189 char **space_tokenize(const char *chain); 00190 int ssh_get_kex1(ssh_session session); 00191 char *ssh_find_matching(const char *in_d, const char *what_d); 00192 00193 00194 /* in base64.c */ 00195 ssh_buffer base64_to_bin(const char *source); 00196 unsigned char *bin_to_base64(const unsigned char *source, int len); 00197 00198 /* gzip.c */ 00199 int compress_buffer(ssh_session session,ssh_buffer buf); 00200 int decompress_buffer(ssh_session session,ssh_buffer buf, size_t maxlen); 00201 00202 /* crc32.c */ 00203 uint32_t ssh_crc32(const char *buf, uint32_t len); 00204 00205 00206 /* match.c */ 00207 int match_hostname(const char *host, const char *pattern, unsigned int len); 00208 00209 int message_handle(ssh_session session, void *user, uint8_t type, ssh_buffer packet); 00210 /* log.c */ 00211 00212 void ssh_log_common(struct ssh_common_struct *common, int verbosity, 00213 const char *format, ...) PRINTF_ATTRIBUTE(3, 4); 00214 00215 /* misc.c */ 00216 #ifdef _WIN32 00217 int gettimeofday(struct timeval *__p, void *__t); 00218 #endif /* _WIN32 */ 00219 00220 #ifndef __FUNCTION__ 00221 #if defined(__SUNPRO_C) 00222 #define __FUNCTION__ __func__ 00223 #endif 00224 #endif 00225 00226 #define _enter_function(sess) \ 00227 do {\ 00228 if((sess)->common.log_verbosity >= SSH_LOG_FUNCTIONS){ \ 00229 ssh_log((sess),SSH_LOG_FUNCTIONS,"entering function %s line %d in " __FILE__ , __FUNCTION__,__LINE__);\ 00230 (sess)->common.log_indent++; \ 00231 } \ 00232 } while(0) 00233 00234 #define _leave_function(sess) \ 00235 do { \ 00236 if((sess)->common.log_verbosity >= SSH_LOG_FUNCTIONS){ \ 00237 (sess)->common.log_indent--; \ 00238 ssh_log((sess),SSH_LOG_FUNCTIONS,"leaving function %s line %d in " __FILE__ , __FUNCTION__,__LINE__);\ 00239 }\ 00240 } while(0) 00241 00242 #ifdef DEBUG_CALLTRACE 00243 #define enter_function() _enter_function(session) 00244 #define leave_function() _leave_function(session) 00245 #else 00246 #define enter_function() (void)session 00247 #define leave_function() (void)session 00248 #endif 00249 00250 /* options.c */ 00251 00252 int ssh_options_set_algo(ssh_session session, int algo, const char *list); 00253 int ssh_options_apply(ssh_session session); 00254 00255 /* server.c */ 00256 SSH_PACKET_CALLBACK(ssh_packet_kexdh_init); 00257 00259 #define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0) 00260 00262 #define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x)) 00263 00265 #define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((char *)(x), 0, sizeof(*(x))); } while(0) 00266 00268 #define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0])) 00269 00271 #define BURN_STRING(x) do { if ((x) != NULL) memset((x), 'X', strlen((x))); } while(0) 00272 00273 #ifdef HAVE_LIBGCRYPT 00274 /* gcrypt_missing.c */ 00275 int my_gcry_dec2bn(bignum *bn, const char *data); 00276 char *my_gcry_bn2dec(bignum bn); 00277 #endif /* !HAVE_LIBGCRYPT */ 00278 00279 #ifdef __cplusplus 00280 } 00281 #endif 00282 00283 #endif /* _LIBSSH_PRIV_H */ 00284 /* vim: set ts=2 sw=2 et cindent: */