38#if !defined(HAVE_STRTOULL)
39# if defined(HAVE___STRTOULL)
40# define strtoull __strtoull
41# elif defined(HAVE__STRTOUI64)
42# define strtoull _strtoui64
43# elif defined(__hpux) && defined(__LP64__)
44# define strtoull strtoul
46# error "no strtoull function found"
58#if !defined(HAVE_STRNDUP)
59char *strndup(
const char *s,
size_t n);
66#ifdef HAVE_ARPA_INET_H
72 ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
73 (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
108# define inline __inline
111# define va_copy(dest, src) (dest = src)
114# define strcasecmp _stricmp
115# define strncasecmp _strnicmp
116# if ! defined(HAVE_ISBLANK)
117# define isblank(ch) ((ch) == ' ' || (ch) == '\t' || (ch) == '\n' || (ch) == '\r')
120# define usleep(X) Sleep(((X)+1000)/1000)
123# define strtok_r strtok_s
125# if defined(HAVE__SNPRINTF_S)
127# define snprintf(d, n, ...) _snprintf_s((d), (n), _TRUNCATE, __VA_ARGS__)
129# if defined(HAVE__SNPRINTF)
131# define snprintf _snprintf
133# if !defined(HAVE_SNPRINTF)
134# error "no snprintf compatible function found"
139# if defined(HAVE__VSNPRINTF_S)
141# define vsnprintf(s, n, f, v) _vsnprintf_s((s), (n), _TRUNCATE, (f), (v))
143# if defined(HAVE__VSNPRINTF)
145# define vsnprintf _vsnprintf
147# if !defined(HAVE_VSNPRINTF)
148# error "No vsnprintf compatible function found"
153# ifndef _SSIZE_T_DEFINED
156 typedef _W64 SSIZE_T ssize_t;
157# define _SSIZE_T_DEFINED
163int ssh_gettimeofday(
struct timeval *__p,
void *__t);
165#define gettimeofday ssh_gettimeofday
167#define _XCLOSESOCKET closesocket
180# define unlink _unlink
187#define _XCLOSESOCKET close
191#include "libssh/libssh.h"
192#include "libssh/callbacks.h"
197#define PATH_MAX MAX_PATH
203#ifndef MAX_PACKET_LEN
204#define MAX_PACKET_LEN 262144
206#ifndef ERROR_BUFFERLEN
207#define ERROR_BUFFERLEN 1024
210#ifndef CLIENT_BANNER_SSH2
211#define CLIENT_BANNER_SSH2 "SSH-2.0-libssh_" SSH_STRINGIFY(LIBSSH_VERSION)
214#ifndef KBDINT_MAX_PROMPT
215#define KBDINT_MAX_PROMPT 256
218#define MAX_BUF_SIZE 4096
221#ifndef HAVE_COMPILER__FUNC__
222# ifdef HAVE_COMPILER__FUNCTION__
223# define __func__ __FUNCTION__
225# error "Your system must provide a __func__ macro"
229#if defined(HAVE_GCC_THREAD_LOCAL_STORAGE)
230# define LIBSSH_THREAD __thread
231#elif defined(HAVE_MSC_THREAD_LOCAL_STORAGE)
232# define LIBSSH_THREAD __declspec(thread)
234# define LIBSSH_THREAD
242#if defined(HAVE_GCC_VOLATILE_MEMORY_PROTECTION)
243# define LIBSSH_MEM_PROTECTION __asm__ volatile("" : : "r"(&(x)) : "memory")
245# define LIBSSH_MEM_PROTECTION
248#define SSH_DANGEROUS_SHELL_CHARS "'`\";&<>|(){}$\\,"
251struct ssh_common_struct;
252struct ssh_kex_struct;
262int ssh_get_key_params(ssh_session session,
264 enum ssh_digest_e *digest);
267void ssh_log_function(
int verbosity,
268 const char *function,
270#define SSH_LOG(priority, ...) \
271 _ssh_log(priority, __func__, __VA_ARGS__)
274void ssh_log_common(
struct ssh_common_struct *common,
276 const char *function,
277 const char *format, ...) PRINTF_ATTRIBUTE(4, 5);
279void _ssh_remove_legacy_log_cb(
void);
282void _ssh_reset_log_cb(
void);
289 char error_buffer[ERROR_BUFFERLEN];
292#define ssh_set_error(error, code, ...) \
293 _ssh_set_error(error, code, __func__, __VA_ARGS__)
294void _ssh_set_error(
void *error,
296 const char *function,
297 const char *descr, ...) PRINTF_ATTRIBUTE(4, 5);
299#define ssh_set_error_oom(error) \
300 _ssh_set_error_oom(error, __func__)
301void _ssh_set_error_oom(
void *error,
const char *function);
303#define ssh_set_error_invalid(error) \
304 _ssh_set_error_invalid(error, __func__)
305void _ssh_set_error_invalid(
void *error,
const char *function);
307void ssh_reset_error(
void *error);
311int ssh_auth_reply_default(ssh_session session,
int partial);
316int ssh_send_banner(ssh_session session,
int is_server);
317void ssh_session_socket_close(ssh_session session);
320socket_t ssh_connect_host_nonblocking(ssh_session session,
const char *host,
321 const char *bind_addr,
int port);
324ssh_buffer base64_to_bin(
const char *source);
325uint8_t *bin_to_base64(
const uint8_t *source,
size_t len);
328int compress_buffer(ssh_session session,ssh_buffer buf);
329int decompress_buffer(ssh_session session,ssh_buffer buf,
size_t maxlen);
332int match_pattern_list(
const char *
string,
const char *pattern,
333 size_t len,
int dolower);
334int match_hostname(
const char *host,
const char *pattern,
unsigned int len);
336int match_cidr_address_list(
const char *address,
337 const char *addrlist,
340int match_group(
const char *group,
const char *
object);
343int ssh_connector_set_event(ssh_connector connector, ssh_event event);
344int ssh_connector_remove_event(ssh_connector connector);
347#define MIN(a,b) ((a) < (b) ? (a) : (b))
351#define MAX(a,b) ((a) > (b) ? (a) : (b))
355#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
358#define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x))
361#define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((char *)(x), 0, sizeof(*(x))); } while(0)
364#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
366#ifndef HAVE_EXPLICIT_BZERO
367void explicit_bzero(
void *s,
size_t n);
382#define discard_const(ptr) ((void *)((uintptr_t)(ptr)))
387#define discard_const_p(type, ptr) ((type *)discard_const(ptr))
399#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
401#define __VA_NARG__(...) \
402 (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
403#define __VA_NARG_(...) \
404 VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
406 _1, _2, _3, _4, _5, _6, _7, _8, _9,_10, \
407 _11,_12,_13,_14,_15,_16,_17,_18,_19,_20, \
408 _21,_22,_23,_24,_25,_26,_27,_28,_29,_30, \
409 _31,_32,_33,_34,_35,_36,_37,_38,_39,_40, \
410 _41,_42,_43,_44,_45,_46,_47,_48,_49,_50, \
411 _51,_52,_53,_54,_55,_56,_57,_58,_59,_60, \
415 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, \
416 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, \
417 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, \
418 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, \
419 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, \
420 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
423#define CLOSE_SOCKET(s) do { if ((s) != SSH_INVALID_SOCKET) { _XCLOSESOCKET(s); (s) = SSH_INVALID_SOCKET;} } while(0)
426# ifdef WORDS_BIGENDIAN
427# define htonll(x) (x)
430 (((uint64_t)htonl((x) & 0xFFFFFFFF) << 32) | htonl((x) >> 32))
435# ifdef WORDS_BIGENDIAN
436# define ntohll(x) (x)
439 (((uint64_t)ntohl((x) & 0xFFFFFFFF) << 32) | ntohl((x) >> 32))
444# ifdef HAVE_FALLTHROUGH_ATTRIBUTE
445# define FALL_THROUGH __attribute__ ((fallthrough))
451#ifndef __attr_unused__
452# ifdef HAVE_UNUSED_ATTRIBUTE
453# define __attr_unused__ __attribute__((unused))
455# define __attr_unused__
460#define UNUSED_PARAM(param) param __attr_unused__
464#define UNUSED_VAR(var) __attr_unused__ var
467void ssh_agent_state_free(
void *data);
469bool is_ssh_initialized(
void);
471#define SSH_ERRNO_MSG_MAX 1024
472char *ssh_strerror(
int err_num,
char *buf,
size_t buflen);
475#define SSH_TTY_MODES_MAX_BUFSIZE (55 * 5 + 1)
479#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:436
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:1052