39#if !defined(HAVE_STRTOULL)
40# if defined(HAVE___STRTOULL)
41# define strtoull __strtoull
42# elif defined(HAVE__STRTOUI64)
43# define strtoull _strtoui64
44# elif defined(__hpux) && defined(__LP64__)
45# define strtoull strtoul
47# error "no strtoull function found"
59#if !defined(HAVE_STRNDUP)
60char *strndup(
const char *s,
size_t n);
67#ifdef HAVE_ARPA_INET_H
73 ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
74 (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
109# define inline __inline
112# define va_copy(dest, src) (dest = src)
115# define strcasecmp _stricmp
116# define strncasecmp _strnicmp
117# if ! defined(HAVE_ISBLANK)
118# define isblank(ch) ((ch) == ' ' || (ch) == '\t' || (ch) == '\n' || (ch) == '\r')
121# define usleep(X) Sleep(((X)+1000)/1000)
124# define strtok_r strtok_s
126# if defined(HAVE__SNPRINTF_S)
128# define snprintf(d, n, ...) _snprintf_s((d), (n), _TRUNCATE, __VA_ARGS__)
130# if defined(HAVE__SNPRINTF)
132# define snprintf _snprintf
134# if !defined(HAVE_SNPRINTF)
135# error "no snprintf compatible function found"
140# if defined(HAVE__VSNPRINTF_S)
142# define vsnprintf(s, n, f, v) _vsnprintf_s((s), (n), _TRUNCATE, (f), (v))
144# if defined(HAVE__VSNPRINTF)
146# define vsnprintf _vsnprintf
148# if !defined(HAVE_VSNPRINTF)
149# error "No vsnprintf compatible function found"
154# ifndef _SSIZE_T_DEFINED
157 typedef _W64 SSIZE_T ssize_t;
158# define _SSIZE_T_DEFINED
164int ssh_gettimeofday(
struct timeval *__p,
void *__t);
166#define gettimeofday ssh_gettimeofday
168struct tm *ssh_localtime(
const time_t *timer,
struct tm *result);
169# define localtime_r ssh_localtime
171#define _XCLOSESOCKET closesocket
184# define unlink _unlink
191#define _XCLOSESOCKET close
195#include "libssh/libssh.h"
196#include "libssh/callbacks.h"
201#define PATH_MAX MAX_PATH
207#ifndef MAX_PACKET_LEN
208#define MAX_PACKET_LEN 262144
210#ifndef ERROR_BUFFERLEN
211#define ERROR_BUFFERLEN 1024
214#ifndef CLIENT_BANNER_SSH2
215#define CLIENT_BANNER_SSH2 "SSH-2.0-libssh_" SSH_STRINGIFY(LIBSSH_VERSION)
218#ifndef KBDINT_MAX_PROMPT
219#define KBDINT_MAX_PROMPT 256
222#define MAX_BUF_SIZE 4096
225#ifndef HAVE_COMPILER__FUNC__
226# ifdef HAVE_COMPILER__FUNCTION__
227# define __func__ __FUNCTION__
229# error "Your system must provide a __func__ macro"
233#if defined(HAVE_GCC_THREAD_LOCAL_STORAGE)
234# define LIBSSH_THREAD __thread
235#elif defined(HAVE_MSC_THREAD_LOCAL_STORAGE)
236# define LIBSSH_THREAD __declspec(thread)
238# define LIBSSH_THREAD
246#if defined(HAVE_GCC_VOLATILE_MEMORY_PROTECTION)
247# define LIBSSH_MEM_PROTECTION __asm__ volatile("" : : "r"(&(x)) : "memory")
249# define LIBSSH_MEM_PROTECTION
252#define SSH_DANGEROUS_SHELL_CHARS "'`\";&<>|(){}$\\,"
255struct ssh_common_struct;
256struct ssh_kex_struct;
268 enum ssh_digest_e *digest);
271void ssh_log_function(
int verbosity,
272 const char *function,
274#define SSH_LOG(priority, ...) \
275 _ssh_log(priority, __func__, __VA_ARGS__)
278void ssh_log_common(
struct ssh_common_struct *common,
280 const char *function,
281 const char *format, ...) PRINTF_ATTRIBUTE(4, 5);
283void _ssh_remove_legacy_log_cb(
void);
286void _ssh_reset_log_cb(
void);
293 char error_buffer[ERROR_BUFFERLEN];
296#define ssh_set_error(error, code, ...) \
297 _ssh_set_error(error, code, __func__, __VA_ARGS__)
298void _ssh_set_error(
void *error,
300 const char *function,
301 const char *descr, ...) PRINTF_ATTRIBUTE(4, 5);
303#define ssh_set_error_oom(error) \
304 _ssh_set_error_oom(error, __func__)
305void _ssh_set_error_oom(
void *error,
const char *function);
307#define ssh_set_error_invalid(error) \
308 _ssh_set_error_invalid(error, __func__)
309void _ssh_set_error_invalid(
void *error,
const char *function);
311void ssh_reset_error(
void *error);
315int ssh_auth_reply_default(ssh_session session,
int partial);
320int ssh_send_banner(ssh_session session,
int is_server);
321void ssh_session_socket_close(ssh_session session);
324socket_t ssh_connect_host_nonblocking(ssh_session session,
const char *host,
325 const char *bind_addr,
int port);
328ssh_buffer base64_to_bin(
const char *source);
329uint8_t *bin_to_base64(
const uint8_t *source,
size_t len);
332int compress_buffer(ssh_session session,ssh_buffer buf);
333int decompress_buffer(ssh_session session,ssh_buffer buf,
size_t maxlen);
336int match_pattern_list(
const char *
string,
const char *pattern,
337 size_t len,
int dolower);
338int match_hostname(
const char *host,
const char *pattern,
size_t len);
340int match_cidr_address_list(
const char *address,
341 const char *addrlist,
344int match_group(
const char *group,
const char *
object);
347int ssh_connector_set_event(ssh_connector connector, ssh_event event);
348int ssh_connector_remove_event(ssh_connector connector);
351#define MIN(a,b) ((a) < (b) ? (a) : (b))
355#define MAX(a,b) ((a) > (b) ? (a) : (b))
359#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
362#define ZERO_STRUCT(x) memset(&(x), 0, sizeof(x))
365#define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((x), 0, sizeof(*(x))); } while(0)
368#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
371#if defined(HAVE_MEMSET_EXPLICIT)
372#define ssh_burn(ptr, len) memset_explicit((ptr), '\0', (len))
373#elif defined(HAVE_EXPLICIT_BZERO)
374#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
375#elif defined(HAVE_MEMSET_S)
376#define ssh_burn(ptr, len) memset_s((ptr), (len), '\0', (len))
377#elif defined(HAVE_SECURE_ZERO_MEMORY)
378#define ssh_burn(ptr, len) SecureZeroMemory((ptr), (len))
380#if defined(HAVE_GCC_VOLATILE_MEMORY_PROTECTION)
381#define ssh_burn(ptr, len) \
383 memset((ptr), '\0', (len)); \
384 __asm__ volatile("" : : "g"(ptr) : "memory"); \
387#define ssh_burn(ptr, len) \
389 memset((ptr), '\0', (len)); \
397#define BURN_FREE(x, len) \
400 burn_free((x), (len)); \
417#define discard_const(ptr) ((void *)((uintptr_t)(ptr)))
422#define discard_const_p(type, ptr) ((type *)discard_const(ptr))
434#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
436#define __VA_NARG__(...) \
437 (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
438#define __VA_NARG_(...) \
439 VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
441 _1, _2, _3, _4, _5, _6, _7, _8, _9,_10, \
442 _11,_12,_13,_14,_15,_16,_17,_18,_19,_20, \
443 _21,_22,_23,_24,_25,_26,_27,_28,_29,_30, \
444 _31,_32,_33,_34,_35,_36,_37,_38,_39,_40, \
445 _41,_42,_43,_44,_45,_46,_47,_48,_49,_50, \
446 _51,_52,_53,_54,_55,_56,_57,_58,_59,_60, \
450 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, \
451 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, \
452 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, \
453 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, \
454 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, \
455 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
458#define CLOSE_SOCKET(s) do { if ((s) != SSH_INVALID_SOCKET) { _XCLOSESOCKET(s); (s) = SSH_INVALID_SOCKET;} } while(0)
461# ifdef WORDS_BIGENDIAN
462# define htonll(x) (x)
465 (((uint64_t)htonl((x) & 0xFFFFFFFF) << 32) | htonl((x) >> 32))
470# ifdef WORDS_BIGENDIAN
471# define ntohll(x) (x)
474 (((uint64_t)ntohl((x) & 0xFFFFFFFF) << 32) | ntohl((x) >> 32))
479# ifdef HAVE_FALLTHROUGH_ATTRIBUTE
480# define FALL_THROUGH __attribute__ ((fallthrough))
486#ifndef __attr_unused__
487# ifdef HAVE_UNUSED_ATTRIBUTE
488# define __attr_unused__ __attribute__((unused))
490# define __attr_unused__
495#define UNUSED_PARAM(param) param __attr_unused__
499#define UNUSED_VAR(var) __attr_unused__ var
502void ssh_agent_state_free(
void *data);
504bool is_ssh_initialized(
void);
506#define SSH_ERRNO_MSG_MAX 1024
507char *ssh_strerror(
int err_num,
char *buf,
size_t buflen);
510#define SSH_TTY_MODES_MAX_BUFSIZE (55 * 5 + 1)
514#define SSH_MAX_CONFIG_FILE_SIZE 16 * 1024 * 1024
int encode_current_tty_opts(unsigned char *buf, size_t buflen)
Encode the current TTY options as SSH modes.
Definition ttyopts.c:458
void burn_free(void *ptr, size_t len)
Securely free memory by overwriting it before deallocation.
Definition misc.c:1769
int ssh_auth_reply_success(ssh_session session, int partial)
Sends SSH2_MSG_USERAUTH_SUCCESS or SSH2_MSG_USERAUTH_FAILURE message depending on the success of the ...
Definition server.c:1196
int ssh_get_key_params(ssh_session session, ssh_key *privkey, enum ssh_digest_e *digest)
Prepares server host key parameters for the key exchange process.
Definition server.c:349