geom_gate userland utility improvements
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

1349 lines
53 KiB

  1. /* Copyright (c) 2004-2009, Sara Golemon <sarag@libssh2.org>
  2. * Copyright (c) 2009-2015 Daniel Stenberg
  3. * Copyright (c) 2010 Simon Josefsson <simon@josefsson.org>
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms,
  7. * with or without modification, are permitted provided
  8. * that the following conditions are met:
  9. *
  10. * Redistributions of source code must retain the above
  11. * copyright notice, this list of conditions and the
  12. * following disclaimer.
  13. *
  14. * Redistributions in binary form must reproduce the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer in the documentation and/or other materials
  17. * provided with the distribution.
  18. *
  19. * Neither the name of the copyright holder nor the names
  20. * of any other contributors may be used to endorse or
  21. * promote products derived from this software without
  22. * specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  25. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  26. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  27. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  28. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  29. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  30. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  31. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  32. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  33. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  34. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  35. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  36. * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  37. * OF SUCH DAMAGE.
  38. */
  39. #ifndef LIBSSH2_H
  40. #define LIBSSH2_H 1
  41. #define LIBSSH2_COPYRIGHT "2004-2019 The libssh2 project and its contributors."
  42. /* We use underscore instead of dash when appending DEV in dev versions just
  43. to make the BANNER define (used by src/session.c) be a valid SSH
  44. banner. Release versions have no appended strings and may of course not
  45. have dashes either. */
  46. #define LIBSSH2_VERSION "1.9.0_DEV"
  47. /* The numeric version number is also available "in parts" by using these
  48. defines: */
  49. #define LIBSSH2_VERSION_MAJOR 1
  50. #define LIBSSH2_VERSION_MINOR 9
  51. #define LIBSSH2_VERSION_PATCH 0
  52. /* This is the numeric version of the libssh2 version number, meant for easier
  53. parsing and comparions by programs. The LIBSSH2_VERSION_NUM define will
  54. always follow this syntax:
  55. 0xXXYYZZ
  56. Where XX, YY and ZZ are the main version, release and patch numbers in
  57. hexadecimal (using 8 bits each). All three numbers are always represented
  58. using two digits. 1.2 would appear as "0x010200" while version 9.11.7
  59. appears as "0x090b07".
  60. This 6-digit (24 bits) hexadecimal number does not show pre-release number,
  61. and it is always a greater number in a more recent release. It makes
  62. comparisons with greater than and less than work.
  63. */
  64. #define LIBSSH2_VERSION_NUM 0x010900
  65. /*
  66. * This is the date and time when the full source package was created. The
  67. * timestamp is not stored in the source code repo, as the timestamp is
  68. * properly set in the tarballs by the maketgz script.
  69. *
  70. * The format of the date should follow this template:
  71. *
  72. * "Mon Feb 12 11:35:33 UTC 2007"
  73. */
  74. #define LIBSSH2_TIMESTAMP "DEV"
  75. #ifndef RC_INVOKED
  76. #ifdef __cplusplus
  77. extern "C" {
  78. #endif
  79. #ifdef _WIN32
  80. # include <basetsd.h>
  81. # include <winsock2.h>
  82. #endif
  83. #include <stddef.h>
  84. #include <string.h>
  85. #include <sys/stat.h>
  86. #include <sys/types.h>
  87. /* Allow alternate API prefix from CFLAGS or calling app */
  88. #ifndef LIBSSH2_API
  89. # ifdef LIBSSH2_WIN32
  90. # ifdef _WINDLL
  91. # ifdef LIBSSH2_LIBRARY
  92. # define LIBSSH2_API __declspec(dllexport)
  93. # else
  94. # define LIBSSH2_API __declspec(dllimport)
  95. # endif /* LIBSSH2_LIBRARY */
  96. # else
  97. # define LIBSSH2_API
  98. # endif
  99. # else /* !LIBSSH2_WIN32 */
  100. # define LIBSSH2_API
  101. # endif /* LIBSSH2_WIN32 */
  102. #endif /* LIBSSH2_API */
  103. #ifdef HAVE_SYS_UIO_H
  104. # include <sys/uio.h>
  105. #endif
  106. #if (defined(NETWARE) && !defined(__NOVELL_LIBC__))
  107. # include <sys/bsdskt.h>
  108. typedef unsigned char uint8_t;
  109. typedef unsigned short int uint16_t;
  110. typedef unsigned int uint32_t;
  111. typedef int int32_t;
  112. typedef unsigned long long uint64_t;
  113. typedef long long int64_t;
  114. #endif
  115. #ifdef _MSC_VER
  116. typedef unsigned char uint8_t;
  117. typedef unsigned short int uint16_t;
  118. typedef unsigned int uint32_t;
  119. typedef __int32 int32_t;
  120. typedef __int64 int64_t;
  121. typedef unsigned __int64 uint64_t;
  122. typedef unsigned __int64 libssh2_uint64_t;
  123. typedef __int64 libssh2_int64_t;
  124. #if (!defined(HAVE_SSIZE_T) && !defined(ssize_t))
  125. typedef SSIZE_T ssize_t;
  126. #define HAVE_SSIZE_T
  127. #endif
  128. #else
  129. #include <stdint.h>
  130. typedef unsigned long long libssh2_uint64_t;
  131. typedef long long libssh2_int64_t;
  132. #endif
  133. #ifdef WIN32
  134. typedef SOCKET libssh2_socket_t;
  135. #define LIBSSH2_INVALID_SOCKET INVALID_SOCKET
  136. #else /* !WIN32 */
  137. typedef int libssh2_socket_t;
  138. #define LIBSSH2_INVALID_SOCKET -1
  139. #endif /* WIN32 */
  140. /*
  141. * Determine whether there is small or large file support on windows.
  142. */
  143. #if defined(_MSC_VER) && !defined(_WIN32_WCE)
  144. # if (_MSC_VER >= 900) && (_INTEGRAL_MAX_BITS >= 64)
  145. # define LIBSSH2_USE_WIN32_LARGE_FILES
  146. # else
  147. # define LIBSSH2_USE_WIN32_SMALL_FILES
  148. # endif
  149. #endif
  150. #if defined(__MINGW32__) && !defined(LIBSSH2_USE_WIN32_LARGE_FILES)
  151. # define LIBSSH2_USE_WIN32_LARGE_FILES
  152. #endif
  153. #if defined(__WATCOMC__) && !defined(LIBSSH2_USE_WIN32_LARGE_FILES)
  154. # define LIBSSH2_USE_WIN32_LARGE_FILES
  155. #endif
  156. #if defined(__POCC__)
  157. # undef LIBSSH2_USE_WIN32_LARGE_FILES
  158. #endif
  159. #if defined(_WIN32) && !defined(LIBSSH2_USE_WIN32_LARGE_FILES) && \
  160. !defined(LIBSSH2_USE_WIN32_SMALL_FILES)
  161. # define LIBSSH2_USE_WIN32_SMALL_FILES
  162. #endif
  163. /*
  164. * Large file (>2Gb) support using WIN32 functions.
  165. */
  166. #ifdef LIBSSH2_USE_WIN32_LARGE_FILES
  167. # include <io.h>
  168. # include <sys/types.h>
  169. # include <sys/stat.h>
  170. # define LIBSSH2_STRUCT_STAT_SIZE_FORMAT "%I64d"
  171. typedef struct _stati64 libssh2_struct_stat;
  172. typedef __int64 libssh2_struct_stat_size;
  173. #endif
  174. /*
  175. * Small file (<2Gb) support using WIN32 functions.
  176. */
  177. #ifdef LIBSSH2_USE_WIN32_SMALL_FILES
  178. # include <sys/types.h>
  179. # include <sys/stat.h>
  180. # ifndef _WIN32_WCE
  181. # define LIBSSH2_STRUCT_STAT_SIZE_FORMAT "%d"
  182. typedef struct _stat libssh2_struct_stat;
  183. typedef off_t libssh2_struct_stat_size;
  184. # endif
  185. #endif
  186. #ifndef LIBSSH2_STRUCT_STAT_SIZE_FORMAT
  187. # ifdef __VMS
  188. /* We have to roll our own format here because %z is a C99-ism we don't
  189. have. */
  190. # if __USE_OFF64_T || __USING_STD_STAT
  191. # define LIBSSH2_STRUCT_STAT_SIZE_FORMAT "%Ld"
  192. # else
  193. # define LIBSSH2_STRUCT_STAT_SIZE_FORMAT "%d"
  194. # endif
  195. # else
  196. # define LIBSSH2_STRUCT_STAT_SIZE_FORMAT "%zd"
  197. # endif
  198. typedef struct stat libssh2_struct_stat;
  199. typedef off_t libssh2_struct_stat_size;
  200. #endif
  201. /* Part of every banner, user specified or not */
  202. #define LIBSSH2_SSH_BANNER "SSH-2.0-libssh2_" LIBSSH2_VERSION
  203. #define LIBSSH2_SSH_DEFAULT_BANNER LIBSSH2_SSH_BANNER
  204. #define LIBSSH2_SSH_DEFAULT_BANNER_WITH_CRLF LIBSSH2_SSH_DEFAULT_BANNER "\r\n"
  205. /* Default generate and safe prime sizes for
  206. diffie-hellman-group-exchange-sha1 */
  207. #define LIBSSH2_DH_GEX_MINGROUP 2048
  208. #define LIBSSH2_DH_GEX_OPTGROUP 4096
  209. #define LIBSSH2_DH_GEX_MAXGROUP 8192
  210. #define LIBSSH2_DH_MAX_MODULUS_BITS 16384
  211. /* Defaults for pty requests */
  212. #define LIBSSH2_TERM_WIDTH 80
  213. #define LIBSSH2_TERM_HEIGHT 24
  214. #define LIBSSH2_TERM_WIDTH_PX 0
  215. #define LIBSSH2_TERM_HEIGHT_PX 0
  216. /* 1/4 second */
  217. #define LIBSSH2_SOCKET_POLL_UDELAY 250000
  218. /* 0.25 * 120 == 30 seconds */
  219. #define LIBSSH2_SOCKET_POLL_MAXLOOPS 120
  220. /* Maximum size to allow a payload to compress to, plays it safe by falling
  221. short of spec limits */
  222. #define LIBSSH2_PACKET_MAXCOMP 32000
  223. /* Maximum size to allow a payload to deccompress to, plays it safe by
  224. allowing more than spec requires */
  225. #define LIBSSH2_PACKET_MAXDECOMP 40000
  226. /* Maximum size for an inbound compressed payload, plays it safe by
  227. overshooting spec limits */
  228. #define LIBSSH2_PACKET_MAXPAYLOAD 40000
  229. /* Malloc callbacks */
  230. #define LIBSSH2_ALLOC_FUNC(name) void *name(size_t count, void **abstract)
  231. #define LIBSSH2_REALLOC_FUNC(name) void *name(void *ptr, size_t count, \
  232. void **abstract)
  233. #define LIBSSH2_FREE_FUNC(name) void name(void *ptr, void **abstract)
  234. typedef struct _LIBSSH2_USERAUTH_KBDINT_PROMPT
  235. {
  236. char *text;
  237. unsigned int length;
  238. unsigned char echo;
  239. } LIBSSH2_USERAUTH_KBDINT_PROMPT;
  240. typedef struct _LIBSSH2_USERAUTH_KBDINT_RESPONSE
  241. {
  242. char *text;
  243. unsigned int length;
  244. } LIBSSH2_USERAUTH_KBDINT_RESPONSE;
  245. /* 'publickey' authentication callback */
  246. #define LIBSSH2_USERAUTH_PUBLICKEY_SIGN_FUNC(name) \
  247. int name(LIBSSH2_SESSION *session, unsigned char **sig, size_t *sig_len, \
  248. const unsigned char *data, size_t data_len, void **abstract)
  249. /* 'keyboard-interactive' authentication callback */
  250. #define LIBSSH2_USERAUTH_KBDINT_RESPONSE_FUNC(name_) \
  251. void name_(const char *name, int name_len, const char *instruction, \
  252. int instruction_len, int num_prompts, \
  253. const LIBSSH2_USERAUTH_KBDINT_PROMPT *prompts, \
  254. LIBSSH2_USERAUTH_KBDINT_RESPONSE *responses, void **abstract)
  255. /* Callbacks for special SSH packets */
  256. #define LIBSSH2_IGNORE_FUNC(name) \
  257. void name(LIBSSH2_SESSION *session, const char *message, int message_len, \
  258. void **abstract)
  259. #define LIBSSH2_DEBUG_FUNC(name) \
  260. void name(LIBSSH2_SESSION *session, int always_display, const char *message, \
  261. int message_len, const char *language, int language_len, \
  262. void **abstract)
  263. #define LIBSSH2_DISCONNECT_FUNC(name) \
  264. void name(LIBSSH2_SESSION *session, int reason, const char *message, \
  265. int message_len, const char *language, int language_len, \
  266. void **abstract)
  267. #define LIBSSH2_PASSWD_CHANGEREQ_FUNC(name) \
  268. void name(LIBSSH2_SESSION *session, char **newpw, int *newpw_len, \
  269. void **abstract)
  270. #define LIBSSH2_MACERROR_FUNC(name) \
  271. int name(LIBSSH2_SESSION *session, const char *packet, int packet_len, \
  272. void **abstract)
  273. #define LIBSSH2_X11_OPEN_FUNC(name) \
  274. void name(LIBSSH2_SESSION *session, LIBSSH2_CHANNEL *channel, \
  275. const char *shost, int sport, void **abstract)
  276. #define LIBSSH2_CHANNEL_CLOSE_FUNC(name) \
  277. void name(LIBSSH2_SESSION *session, void **session_abstract, \
  278. LIBSSH2_CHANNEL *channel, void **channel_abstract)
  279. /* I/O callbacks */
  280. #define LIBSSH2_RECV_FUNC(name) \
  281. ssize_t name(libssh2_socket_t socket, \
  282. void *buffer, size_t length, \
  283. int flags, void **abstract)
  284. #define LIBSSH2_SEND_FUNC(name) \
  285. ssize_t name(libssh2_socket_t socket, \
  286. const void *buffer, size_t length, \
  287. int flags, void **abstract)
  288. /* libssh2_session_callback_set() constants */
  289. #define LIBSSH2_CALLBACK_IGNORE 0
  290. #define LIBSSH2_CALLBACK_DEBUG 1
  291. #define LIBSSH2_CALLBACK_DISCONNECT 2
  292. #define LIBSSH2_CALLBACK_MACERROR 3
  293. #define LIBSSH2_CALLBACK_X11 4
  294. #define LIBSSH2_CALLBACK_SEND 5
  295. #define LIBSSH2_CALLBACK_RECV 6
  296. /* libssh2_session_method_pref() constants */
  297. #define LIBSSH2_METHOD_KEX 0
  298. #define LIBSSH2_METHOD_HOSTKEY 1
  299. #define LIBSSH2_METHOD_CRYPT_CS 2
  300. #define LIBSSH2_METHOD_CRYPT_SC 3
  301. #define LIBSSH2_METHOD_MAC_CS 4
  302. #define LIBSSH2_METHOD_MAC_SC 5
  303. #define LIBSSH2_METHOD_COMP_CS 6
  304. #define LIBSSH2_METHOD_COMP_SC 7
  305. #define LIBSSH2_METHOD_LANG_CS 8
  306. #define LIBSSH2_METHOD_LANG_SC 9
  307. /* flags */
  308. #define LIBSSH2_FLAG_SIGPIPE 1
  309. #define LIBSSH2_FLAG_COMPRESS 2
  310. typedef struct _LIBSSH2_SESSION LIBSSH2_SESSION;
  311. typedef struct _LIBSSH2_CHANNEL LIBSSH2_CHANNEL;
  312. typedef struct _LIBSSH2_LISTENER LIBSSH2_LISTENER;
  313. typedef struct _LIBSSH2_KNOWNHOSTS LIBSSH2_KNOWNHOSTS;
  314. typedef struct _LIBSSH2_AGENT LIBSSH2_AGENT;
  315. typedef struct _LIBSSH2_POLLFD {
  316. unsigned char type; /* LIBSSH2_POLLFD_* below */
  317. union {
  318. libssh2_socket_t socket; /* File descriptors -- examined with
  319. system select() call */
  320. LIBSSH2_CHANNEL *channel; /* Examined by checking internal state */
  321. LIBSSH2_LISTENER *listener; /* Read polls only -- are inbound
  322. connections waiting to be accepted? */
  323. } fd;
  324. unsigned long events; /* Requested Events */
  325. unsigned long revents; /* Returned Events */
  326. } LIBSSH2_POLLFD;
  327. /* Poll FD Descriptor Types */
  328. #define LIBSSH2_POLLFD_SOCKET 1
  329. #define LIBSSH2_POLLFD_CHANNEL 2
  330. #define LIBSSH2_POLLFD_LISTENER 3
  331. /* Note: Win32 Doesn't actually have a poll() implementation, so some of these
  332. values are faked with select() data */
  333. /* Poll FD events/revents -- Match sys/poll.h where possible */
  334. #define LIBSSH2_POLLFD_POLLIN 0x0001 /* Data available to be read or
  335. connection available --
  336. All */
  337. #define LIBSSH2_POLLFD_POLLPRI 0x0002 /* Priority data available to
  338. be read -- Socket only */
  339. #define LIBSSH2_POLLFD_POLLEXT 0x0002 /* Extended data available to
  340. be read -- Channel only */
  341. #define LIBSSH2_POLLFD_POLLOUT 0x0004 /* Can may be written --
  342. Socket/Channel */
  343. /* revents only */
  344. #define LIBSSH2_POLLFD_POLLERR 0x0008 /* Error Condition -- Socket */
  345. #define LIBSSH2_POLLFD_POLLHUP 0x0010 /* HangUp/EOF -- Socket */
  346. #define LIBSSH2_POLLFD_SESSION_CLOSED 0x0010 /* Session Disconnect */
  347. #define LIBSSH2_POLLFD_POLLNVAL 0x0020 /* Invalid request -- Socket
  348. Only */
  349. #define LIBSSH2_POLLFD_POLLEX 0x0040 /* Exception Condition --
  350. Socket/Win32 */
  351. #define LIBSSH2_POLLFD_CHANNEL_CLOSED 0x0080 /* Channel Disconnect */
  352. #define LIBSSH2_POLLFD_LISTENER_CLOSED 0x0080 /* Listener Disconnect */
  353. #define HAVE_LIBSSH2_SESSION_BLOCK_DIRECTION
  354. /* Block Direction Types */
  355. #define LIBSSH2_SESSION_BLOCK_INBOUND 0x0001
  356. #define LIBSSH2_SESSION_BLOCK_OUTBOUND 0x0002
  357. /* Hash Types */
  358. #define LIBSSH2_HOSTKEY_HASH_MD5 1
  359. #define LIBSSH2_HOSTKEY_HASH_SHA1 2
  360. #define LIBSSH2_HOSTKEY_HASH_SHA256 3
  361. /* Hostkey Types */
  362. #define LIBSSH2_HOSTKEY_TYPE_UNKNOWN 0
  363. #define LIBSSH2_HOSTKEY_TYPE_RSA 1
  364. #define LIBSSH2_HOSTKEY_TYPE_DSS 2
  365. #define LIBSSH2_HOSTKEY_TYPE_ECDSA_256 3
  366. #define LIBSSH2_HOSTKEY_TYPE_ECDSA_384 4
  367. #define LIBSSH2_HOSTKEY_TYPE_ECDSA_521 5
  368. #define LIBSSH2_HOSTKEY_TYPE_ED25519 6
  369. /* Disconnect Codes (defined by SSH protocol) */
  370. #define SSH_DISCONNECT_HOST_NOT_ALLOWED_TO_CONNECT 1
  371. #define SSH_DISCONNECT_PROTOCOL_ERROR 2
  372. #define SSH_DISCONNECT_KEY_EXCHANGE_FAILED 3
  373. #define SSH_DISCONNECT_RESERVED 4
  374. #define SSH_DISCONNECT_MAC_ERROR 5
  375. #define SSH_DISCONNECT_COMPRESSION_ERROR 6
  376. #define SSH_DISCONNECT_SERVICE_NOT_AVAILABLE 7
  377. #define SSH_DISCONNECT_PROTOCOL_VERSION_NOT_SUPPORTED 8
  378. #define SSH_DISCONNECT_HOST_KEY_NOT_VERIFIABLE 9
  379. #define SSH_DISCONNECT_CONNECTION_LOST 10
  380. #define SSH_DISCONNECT_BY_APPLICATION 11
  381. #define SSH_DISCONNECT_TOO_MANY_CONNECTIONS 12
  382. #define SSH_DISCONNECT_AUTH_CANCELLED_BY_USER 13
  383. #define SSH_DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLE 14
  384. #define SSH_DISCONNECT_ILLEGAL_USER_NAME 15
  385. /* Error Codes (defined by libssh2) */
  386. #define LIBSSH2_ERROR_NONE 0
  387. /* The library once used -1 as a generic error return value on numerous places
  388. through the code, which subsequently was converted to
  389. LIBSSH2_ERROR_SOCKET_NONE uses over time. As this is a generic error code,
  390. the goal is to never ever return this code but instead make sure that a
  391. more accurate and descriptive error code is used. */
  392. #define LIBSSH2_ERROR_SOCKET_NONE -1
  393. #define LIBSSH2_ERROR_BANNER_RECV -2
  394. #define LIBSSH2_ERROR_BANNER_SEND -3
  395. #define LIBSSH2_ERROR_INVALID_MAC -4
  396. #define LIBSSH2_ERROR_KEX_FAILURE -5
  397. #define LIBSSH2_ERROR_ALLOC -6
  398. #define LIBSSH2_ERROR_SOCKET_SEND -7
  399. #define LIBSSH2_ERROR_KEY_EXCHANGE_FAILURE -8
  400. #define LIBSSH2_ERROR_TIMEOUT -9
  401. #define LIBSSH2_ERROR_HOSTKEY_INIT -10
  402. #define LIBSSH2_ERROR_HOSTKEY_SIGN -11
  403. #define LIBSSH2_ERROR_DECRYPT -12
  404. #define LIBSSH2_ERROR_SOCKET_DISCONNECT -13
  405. #define LIBSSH2_ERROR_PROTO -14
  406. #define LIBSSH2_ERROR_PASSWORD_EXPIRED -15
  407. #define LIBSSH2_ERROR_FILE -16
  408. #define LIBSSH2_ERROR_METHOD_NONE -17
  409. #define LIBSSH2_ERROR_AUTHENTICATION_FAILED -18
  410. #define LIBSSH2_ERROR_PUBLICKEY_UNRECOGNIZED \
  411. LIBSSH2_ERROR_AUTHENTICATION_FAILED
  412. #define LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED -19
  413. #define LIBSSH2_ERROR_CHANNEL_OUTOFORDER -20
  414. #define LIBSSH2_ERROR_CHANNEL_FAILURE -21
  415. #define LIBSSH2_ERROR_CHANNEL_REQUEST_DENIED -22
  416. #define LIBSSH2_ERROR_CHANNEL_UNKNOWN -23
  417. #define LIBSSH2_ERROR_CHANNEL_WINDOW_EXCEEDED -24
  418. #define LIBSSH2_ERROR_CHANNEL_PACKET_EXCEEDED -25
  419. #define LIBSSH2_ERROR_CHANNEL_CLOSED -26
  420. #define LIBSSH2_ERROR_CHANNEL_EOF_SENT -27
  421. #define LIBSSH2_ERROR_SCP_PROTOCOL -28
  422. #define LIBSSH2_ERROR_ZLIB -29
  423. #define LIBSSH2_ERROR_SOCKET_TIMEOUT -30
  424. #define LIBSSH2_ERROR_SFTP_PROTOCOL -31
  425. #define LIBSSH2_ERROR_REQUEST_DENIED -32
  426. #define LIBSSH2_ERROR_METHOD_NOT_SUPPORTED -33
  427. #define LIBSSH2_ERROR_INVAL -34
  428. #define LIBSSH2_ERROR_INVALID_POLL_TYPE -35
  429. #define LIBSSH2_ERROR_PUBLICKEY_PROTOCOL -36
  430. #define LIBSSH2_ERROR_EAGAIN -37
  431. #define LIBSSH2_ERROR_BUFFER_TOO_SMALL -38
  432. #define LIBSSH2_ERROR_BAD_USE -39
  433. #define LIBSSH2_ERROR_COMPRESS -40
  434. #define LIBSSH2_ERROR_OUT_OF_BOUNDARY -41
  435. #define LIBSSH2_ERROR_AGENT_PROTOCOL -42
  436. #define LIBSSH2_ERROR_SOCKET_RECV -43
  437. #define LIBSSH2_ERROR_ENCRYPT -44
  438. #define LIBSSH2_ERROR_BAD_SOCKET -45
  439. #define LIBSSH2_ERROR_KNOWN_HOSTS -46
  440. #define LIBSSH2_ERROR_CHANNEL_WINDOW_FULL -47
  441. #define LIBSSH2_ERROR_KEYFILE_AUTH_FAILED -48
  442. /* this is a define to provide the old (<= 1.2.7) name */
  443. #define LIBSSH2_ERROR_BANNER_NONE LIBSSH2_ERROR_BANNER_RECV
  444. /* Global API */
  445. #define LIBSSH2_INIT_NO_CRYPTO 0x0001
  446. /*
  447. * libssh2_init()
  448. *
  449. * Initialize the libssh2 functions. This typically initialize the
  450. * crypto library. It uses a global state, and is not thread safe --
  451. * you must make sure this function is not called concurrently.
  452. *
  453. * Flags can be:
  454. * 0: Normal initialize
  455. * LIBSSH2_INIT_NO_CRYPTO: Do not initialize the crypto library (ie.
  456. * OPENSSL_add_cipher_algoritms() for OpenSSL
  457. *
  458. * Returns 0 if succeeded, or a negative value for error.
  459. */
  460. LIBSSH2_API int libssh2_init(int flags);
  461. /*
  462. * libssh2_exit()
  463. *
  464. * Exit the libssh2 functions and free's all memory used internal.
  465. */
  466. LIBSSH2_API void libssh2_exit(void);
  467. /*
  468. * libssh2_free()
  469. *
  470. * Deallocate memory allocated by earlier call to libssh2 functions.
  471. */
  472. LIBSSH2_API void libssh2_free(LIBSSH2_SESSION *session, void *ptr);
  473. /*
  474. * libssh2_session_supported_algs()
  475. *
  476. * Fills algs with a list of supported acryptographic algorithms. Returns a
  477. * non-negative number (number of supported algorithms) on success or a
  478. * negative number (an error code) on failure.
  479. *
  480. * NOTE: on success, algs must be deallocated (by calling libssh2_free) when
  481. * not needed anymore
  482. */
  483. LIBSSH2_API int libssh2_session_supported_algs(LIBSSH2_SESSION* session,
  484. int method_type,
  485. const char ***algs);
  486. /* Session API */
  487. LIBSSH2_API LIBSSH2_SESSION *
  488. libssh2_session_init_ex(LIBSSH2_ALLOC_FUNC((*my_alloc)),
  489. LIBSSH2_FREE_FUNC((*my_free)),
  490. LIBSSH2_REALLOC_FUNC((*my_realloc)), void *abstract);
  491. #define libssh2_session_init() libssh2_session_init_ex(NULL, NULL, NULL, NULL)
  492. LIBSSH2_API void **libssh2_session_abstract(LIBSSH2_SESSION *session);
  493. LIBSSH2_API void *libssh2_session_callback_set(LIBSSH2_SESSION *session,
  494. int cbtype, void *callback);
  495. LIBSSH2_API int libssh2_session_banner_set(LIBSSH2_SESSION *session,
  496. const char *banner);
  497. LIBSSH2_API int libssh2_banner_set(LIBSSH2_SESSION *session,
  498. const char *banner);
  499. LIBSSH2_API int libssh2_session_startup(LIBSSH2_SESSION *session, int sock);
  500. LIBSSH2_API int libssh2_session_handshake(LIBSSH2_SESSION *session,
  501. libssh2_socket_t sock);
  502. LIBSSH2_API int libssh2_session_disconnect_ex(LIBSSH2_SESSION *session,
  503. int reason,
  504. const char *description,
  505. const char *lang);
  506. #define libssh2_session_disconnect(session, description) \
  507. libssh2_session_disconnect_ex((session), SSH_DISCONNECT_BY_APPLICATION, \
  508. (description), "")
  509. LIBSSH2_API int libssh2_session_free(LIBSSH2_SESSION *session);
  510. LIBSSH2_API const char *libssh2_hostkey_hash(LIBSSH2_SESSION *session,
  511. int hash_type);
  512. LIBSSH2_API const char *libssh2_session_hostkey(LIBSSH2_SESSION *session,
  513. size_t *len, int *type);
  514. LIBSSH2_API int libssh2_session_method_pref(LIBSSH2_SESSION *session,
  515. int method_type,
  516. const char *prefs);
  517. LIBSSH2_API const char *libssh2_session_methods(LIBSSH2_SESSION *session,
  518. int method_type);
  519. LIBSSH2_API int libssh2_session_last_error(LIBSSH2_SESSION *session,
  520. char **errmsg,
  521. int *errmsg_len, int want_buf);
  522. LIBSSH2_API int libssh2_session_last_errno(LIBSSH2_SESSION *session);
  523. LIBSSH2_API int libssh2_session_set_last_error(LIBSSH2_SESSION* session,
  524. int errcode,
  525. const char *errmsg);
  526. LIBSSH2_API int libssh2_session_block_directions(LIBSSH2_SESSION *session);
  527. LIBSSH2_API int libssh2_session_flag(LIBSSH2_SESSION *session, int flag,
  528. int value);
  529. LIBSSH2_API const char *libssh2_session_banner_get(LIBSSH2_SESSION *session);
  530. /* Userauth API */
  531. LIBSSH2_API char *libssh2_userauth_list(LIBSSH2_SESSION *session,
  532. const char *username,
  533. unsigned int username_len);
  534. LIBSSH2_API int libssh2_userauth_authenticated(LIBSSH2_SESSION *session);
  535. LIBSSH2_API int
  536. libssh2_userauth_password_ex(LIBSSH2_SESSION *session,
  537. const char *username,
  538. unsigned int username_len,
  539. const char *password,
  540. unsigned int password_len,
  541. LIBSSH2_PASSWD_CHANGEREQ_FUNC
  542. ((*passwd_change_cb)));
  543. #define libssh2_userauth_password(session, username, password) \
  544. libssh2_userauth_password_ex((session), (username), \
  545. (unsigned int)strlen(username), \
  546. (password), (unsigned int)strlen(password), NULL)
  547. LIBSSH2_API int
  548. libssh2_userauth_publickey_fromfile_ex(LIBSSH2_SESSION *session,
  549. const char *username,
  550. unsigned int username_len,
  551. const char *publickey,
  552. const char *privatekey,
  553. const char *passphrase);
  554. #define libssh2_userauth_publickey_fromfile(session, username, publickey, \
  555. privatekey, passphrase) \
  556. libssh2_userauth_publickey_fromfile_ex((session), (username), \
  557. (unsigned int)strlen(username), \
  558. (publickey), \
  559. (privatekey), (passphrase))
  560. LIBSSH2_API int
  561. libssh2_userauth_publickey(LIBSSH2_SESSION *session,
  562. const char *username,
  563. const unsigned char *pubkeydata,
  564. size_t pubkeydata_len,
  565. LIBSSH2_USERAUTH_PUBLICKEY_SIGN_FUNC
  566. ((*sign_callback)),
  567. void **abstract);
  568. LIBSSH2_API int
  569. libssh2_userauth_hostbased_fromfile_ex(LIBSSH2_SESSION *session,
  570. const char *username,
  571. unsigned int username_len,
  572. const char *publickey,
  573. const char *privatekey,
  574. const char *passphrase,
  575. const char *hostname,
  576. unsigned int hostname_len,
  577. const char *local_username,
  578. unsigned int local_username_len);
  579. #define libssh2_userauth_hostbased_fromfile(session, username, publickey, \
  580. privatekey, passphrase, hostname) \
  581. libssh2_userauth_hostbased_fromfile_ex((session), (username), \
  582. (unsigned int)strlen(username), \
  583. (publickey), \
  584. (privatekey), (passphrase), \
  585. (hostname), \
  586. (unsigned int)strlen(hostname), \
  587. (username), \
  588. (unsigned int)strlen(username))
  589. LIBSSH2_API int
  590. libssh2_userauth_publickey_frommemory(LIBSSH2_SESSION *session,
  591. const char *username,
  592. size_t username_len,
  593. const char *publickeyfiledata,
  594. size_t publickeyfiledata_len,
  595. const char *privatekeyfiledata,
  596. size_t privatekeyfiledata_len,
  597. const char *passphrase);
  598. /*
  599. * response_callback is provided with filled by library prompts array,
  600. * but client must allocate and fill individual responses. Responses
  601. * array is already allocated. Responses data will be freed by libssh2
  602. * after callback return, but before subsequent callback invocation.
  603. */
  604. LIBSSH2_API int
  605. libssh2_userauth_keyboard_interactive_ex(LIBSSH2_SESSION* session,
  606. const char *username,
  607. unsigned int username_len,
  608. LIBSSH2_USERAUTH_KBDINT_RESPONSE_FUNC(
  609. (*response_callback)));
  610. #define libssh2_userauth_keyboard_interactive(session, username, \
  611. response_callback) \
  612. libssh2_userauth_keyboard_interactive_ex((session), (username), \
  613. (unsigned int)strlen(username), \
  614. (response_callback))
  615. LIBSSH2_API int libssh2_poll(LIBSSH2_POLLFD *fds, unsigned int nfds,
  616. long timeout);
  617. /* Channel API */
  618. #define LIBSSH2_CHANNEL_WINDOW_DEFAULT (2*1024*1024)
  619. #define LIBSSH2_CHANNEL_PACKET_DEFAULT 32768
  620. #define LIBSSH2_CHANNEL_MINADJUST 1024
  621. /* Extended Data Handling */
  622. #define LIBSSH2_CHANNEL_EXTENDED_DATA_NORMAL 0
  623. #define LIBSSH2_CHANNEL_EXTENDED_DATA_IGNORE 1
  624. #define LIBSSH2_CHANNEL_EXTENDED_DATA_MERGE 2
  625. #define SSH_EXTENDED_DATA_STDERR 1
  626. /* Returned by any function that would block during a read/write operation */
  627. #define LIBSSH2CHANNEL_EAGAIN LIBSSH2_ERROR_EAGAIN
  628. LIBSSH2_API LIBSSH2_CHANNEL *
  629. libssh2_channel_open_ex(LIBSSH2_SESSION *session, const char *channel_type,
  630. unsigned int channel_type_len,
  631. unsigned int window_size, unsigned int packet_size,
  632. const char *message, unsigned int message_len);
  633. #define libssh2_channel_open_session(session) \
  634. libssh2_channel_open_ex((session), "session", sizeof("session") - 1, \
  635. LIBSSH2_CHANNEL_WINDOW_DEFAULT, \
  636. LIBSSH2_CHANNEL_PACKET_DEFAULT, NULL, 0)
  637. LIBSSH2_API LIBSSH2_CHANNEL *
  638. libssh2_channel_direct_tcpip_ex(LIBSSH2_SESSION *session, const char *host,
  639. int port, const char *shost, int sport);
  640. #define libssh2_channel_direct_tcpip(session, host, port) \
  641. libssh2_channel_direct_tcpip_ex((session), (host), (port), "127.0.0.1", 22)
  642. LIBSSH2_API LIBSSH2_LISTENER *
  643. libssh2_channel_forward_listen_ex(LIBSSH2_SESSION *session, const char *host,
  644. int port, int *bound_port,
  645. int queue_maxsize);
  646. #define libssh2_channel_forward_listen(session, port) \
  647. libssh2_channel_forward_listen_ex((session), NULL, (port), NULL, 16)
  648. LIBSSH2_API int libssh2_channel_forward_cancel(LIBSSH2_LISTENER *listener);
  649. LIBSSH2_API LIBSSH2_CHANNEL *
  650. libssh2_channel_forward_accept(LIBSSH2_LISTENER *listener);
  651. LIBSSH2_API int libssh2_channel_setenv_ex(LIBSSH2_CHANNEL *channel,
  652. const char *varname,
  653. unsigned int varname_len,
  654. const char *value,
  655. unsigned int value_len);
  656. #define libssh2_channel_setenv(channel, varname, value) \
  657. libssh2_channel_setenv_ex((channel), (varname), \
  658. (unsigned int)strlen(varname), (value), \
  659. (unsigned int)strlen(value))
  660. LIBSSH2_API int libssh2_channel_request_auth_agent(LIBSSH2_CHANNEL *channel);
  661. LIBSSH2_API int libssh2_channel_request_pty_ex(LIBSSH2_CHANNEL *channel,
  662. const char *term,
  663. unsigned int term_len,
  664. const char *modes,
  665. unsigned int modes_len,
  666. int width, int height,
  667. int width_px, int height_px);
  668. #define libssh2_channel_request_pty(channel, term) \
  669. libssh2_channel_request_pty_ex((channel), (term), \
  670. (unsigned int)strlen(term), \
  671. NULL, 0, \
  672. LIBSSH2_TERM_WIDTH, \
  673. LIBSSH2_TERM_HEIGHT, \
  674. LIBSSH2_TERM_WIDTH_PX, \
  675. LIBSSH2_TERM_HEIGHT_PX)
  676. LIBSSH2_API int libssh2_channel_request_pty_size_ex(LIBSSH2_CHANNEL *channel,
  677. int width, int height,
  678. int width_px,
  679. int height_px);
  680. #define libssh2_channel_request_pty_size(channel, width, height) \
  681. libssh2_channel_request_pty_size_ex((channel), (width), (height), 0, 0)
  682. LIBSSH2_API int libssh2_channel_x11_req_ex(LIBSSH2_CHANNEL *channel,
  683. int single_connection,
  684. const char *auth_proto,
  685. const char *auth_cookie,
  686. int screen_number);
  687. #define libssh2_channel_x11_req(channel, screen_number) \
  688. libssh2_channel_x11_req_ex((channel), 0, NULL, NULL, (screen_number))
  689. LIBSSH2_API int libssh2_channel_process_startup(LIBSSH2_CHANNEL *channel,
  690. const char *request,
  691. unsigned int request_len,
  692. const char *message,
  693. unsigned int message_len);
  694. #define libssh2_channel_shell(channel) \
  695. libssh2_channel_process_startup((channel), "shell", sizeof("shell") - 1, \
  696. NULL, 0)
  697. #define libssh2_channel_exec(channel, command) \
  698. libssh2_channel_process_startup((channel), "exec", sizeof("exec") - 1, \
  699. (command), (unsigned int)strlen(command))
  700. #define libssh2_channel_subsystem(channel, subsystem) \
  701. libssh2_channel_process_startup((channel), "subsystem", \
  702. sizeof("subsystem") - 1, (subsystem), \
  703. (unsigned int)strlen(subsystem))
  704. LIBSSH2_API ssize_t libssh2_channel_read_ex(LIBSSH2_CHANNEL *channel,
  705. int stream_id, char *buf,
  706. size_t buflen);
  707. #define libssh2_channel_read(channel, buf, buflen) \
  708. libssh2_channel_read_ex((channel), 0, (buf), (buflen))
  709. #define libssh2_channel_read_stderr(channel, buf, buflen) \
  710. libssh2_channel_read_ex((channel), SSH_EXTENDED_DATA_STDERR, (buf), (buflen))
  711. LIBSSH2_API int libssh2_poll_channel_read(LIBSSH2_CHANNEL *channel,
  712. int extended);
  713. LIBSSH2_API unsigned long
  714. libssh2_channel_window_read_ex(LIBSSH2_CHANNEL *channel,
  715. unsigned long *read_avail,
  716. unsigned long *window_size_initial);
  717. #define libssh2_channel_window_read(channel) \
  718. libssh2_channel_window_read_ex((channel), NULL, NULL)
  719. /* libssh2_channel_receive_window_adjust is DEPRECATED, do not use! */
  720. LIBSSH2_API unsigned long
  721. libssh2_channel_receive_window_adjust(LIBSSH2_CHANNEL *channel,
  722. unsigned long adjustment,
  723. unsigned char force);
  724. LIBSSH2_API int
  725. libssh2_channel_receive_window_adjust2(LIBSSH2_CHANNEL *channel,
  726. unsigned long adjustment,
  727. unsigned char force,
  728. unsigned int *storewindow);
  729. LIBSSH2_API ssize_t libssh2_channel_write_ex(LIBSSH2_CHANNEL *channel,
  730. int stream_id, const char *buf,
  731. size_t buflen);
  732. #define libssh2_channel_write(channel, buf, buflen) \
  733. libssh2_channel_write_ex((channel), 0, (buf), (buflen))
  734. #define libssh2_channel_write_stderr(channel, buf, buflen) \
  735. libssh2_channel_write_ex((channel), SSH_EXTENDED_DATA_STDERR, \
  736. (buf), (buflen))
  737. LIBSSH2_API unsigned long
  738. libssh2_channel_window_write_ex(LIBSSH2_CHANNEL *channel,
  739. unsigned long *window_size_initial);
  740. #define libssh2_channel_window_write(channel) \
  741. libssh2_channel_window_write_ex((channel), NULL)
  742. LIBSSH2_API void libssh2_session_set_blocking(LIBSSH2_SESSION* session,
  743. int blocking);
  744. LIBSSH2_API int libssh2_session_get_blocking(LIBSSH2_SESSION* session);
  745. LIBSSH2_API void libssh2_channel_set_blocking(LIBSSH2_CHANNEL *channel,
  746. int blocking);
  747. LIBSSH2_API void libssh2_session_set_timeout(LIBSSH2_SESSION* session,
  748. long timeout);
  749. LIBSSH2_API long libssh2_session_get_timeout(LIBSSH2_SESSION* session);
  750. /* libssh2_channel_handle_extended_data is DEPRECATED, do not use! */
  751. LIBSSH2_API void libssh2_channel_handle_extended_data(LIBSSH2_CHANNEL *channel,
  752. int ignore_mode);
  753. LIBSSH2_API int libssh2_channel_handle_extended_data2(LIBSSH2_CHANNEL *channel,
  754. int ignore_mode);
  755. /* libssh2_channel_ignore_extended_data() is defined below for BC with version
  756. * 0.1
  757. *
  758. * Future uses should use libssh2_channel_handle_extended_data() directly if
  759. * LIBSSH2_CHANNEL_EXTENDED_DATA_MERGE is passed, extended data will be read
  760. * (FIFO) from the standard data channel
  761. */
  762. /* DEPRECATED */
  763. #define libssh2_channel_ignore_extended_data(channel, ignore) \
  764. libssh2_channel_handle_extended_data((channel), \
  765. (ignore) ? \
  766. LIBSSH2_CHANNEL_EXTENDED_DATA_IGNORE : \
  767. LIBSSH2_CHANNEL_EXTENDED_DATA_NORMAL)
  768. #define LIBSSH2_CHANNEL_FLUSH_EXTENDED_DATA -1
  769. #define LIBSSH2_CHANNEL_FLUSH_ALL -2
  770. LIBSSH2_API int libssh2_channel_flush_ex(LIBSSH2_CHANNEL *channel,
  771. int streamid);
  772. #define libssh2_channel_flush(channel) libssh2_channel_flush_ex((channel), 0)
  773. #define libssh2_channel_flush_stderr(channel) \
  774. libssh2_channel_flush_ex((channel), SSH_EXTENDED_DATA_STDERR)
  775. LIBSSH2_API int libssh2_channel_get_exit_status(LIBSSH2_CHANNEL* channel);
  776. LIBSSH2_API int libssh2_channel_get_exit_signal(LIBSSH2_CHANNEL* channel,
  777. char **exitsignal,
  778. size_t *exitsignal_len,
  779. char **errmsg,
  780. size_t *errmsg_len,
  781. char **langtag,
  782. size_t *langtag_len);
  783. LIBSSH2_API int libssh2_channel_send_eof(LIBSSH2_CHANNEL *channel);
  784. LIBSSH2_API int libssh2_channel_eof(LIBSSH2_CHANNEL *channel);
  785. LIBSSH2_API int libssh2_channel_wait_eof(LIBSSH2_CHANNEL *channel);
  786. LIBSSH2_API int libssh2_channel_close(LIBSSH2_CHANNEL *channel);
  787. LIBSSH2_API int libssh2_channel_wait_closed(LIBSSH2_CHANNEL *channel);
  788. LIBSSH2_API int libssh2_channel_free(LIBSSH2_CHANNEL *channel);
  789. /* libssh2_scp_recv is DEPRECATED, do not use! */
  790. LIBSSH2_API LIBSSH2_CHANNEL *libssh2_scp_recv(LIBSSH2_SESSION *session,
  791. const char *path,
  792. struct stat *sb);
  793. /* Use libssh2_scp_recv2 for large (> 2GB) file support on windows */
  794. LIBSSH2_API LIBSSH2_CHANNEL *libssh2_scp_recv2(LIBSSH2_SESSION *session,
  795. const char *path,
  796. libssh2_struct_stat *sb);
  797. LIBSSH2_API LIBSSH2_CHANNEL *libssh2_scp_send_ex(LIBSSH2_SESSION *session,
  798. const char *path, int mode,
  799. size_t size, long mtime,
  800. long atime);
  801. LIBSSH2_API LIBSSH2_CHANNEL *
  802. libssh2_scp_send64(LIBSSH2_SESSION *session, const char *path, int mode,
  803. libssh2_int64_t size, time_t mtime, time_t atime);
  804. #define libssh2_scp_send(session, path, mode, size) \
  805. libssh2_scp_send_ex((session), (path), (mode), (size), 0, 0)
  806. LIBSSH2_API int libssh2_base64_decode(LIBSSH2_SESSION *session, char **dest,
  807. unsigned int *dest_len,
  808. const char *src, unsigned int src_len);
  809. LIBSSH2_API
  810. const char *libssh2_version(int req_version_num);
  811. #define HAVE_LIBSSH2_KNOWNHOST_API 0x010101 /* since 1.1.1 */
  812. #define HAVE_LIBSSH2_VERSION_API 0x010100 /* libssh2_version since 1.1 */
  813. struct libssh2_knownhost {
  814. unsigned int magic; /* magic stored by the library */
  815. void *node; /* handle to the internal representation of this host */
  816. char *name; /* this is NULL if no plain text host name exists */
  817. char *key; /* key in base64/printable format */
  818. int typemask;
  819. };
  820. /*
  821. * libssh2_knownhost_init
  822. *
  823. * Init a collection of known hosts. Returns the pointer to a collection.
  824. *
  825. */
  826. LIBSSH2_API LIBSSH2_KNOWNHOSTS *
  827. libssh2_knownhost_init(LIBSSH2_SESSION *session);
  828. /*
  829. * libssh2_knownhost_add
  830. *
  831. * Add a host and its associated key to the collection of known hosts.
  832. *
  833. * The 'type' argument specifies on what format the given host and keys are:
  834. *
  835. * plain - ascii "hostname.domain.tld"
  836. * sha1 - SHA1(<salt> <host>) base64-encoded!
  837. * custom - another hash
  838. *
  839. * If 'sha1' is selected as type, the salt must be provided to the salt
  840. * argument. This too base64 encoded.
  841. *
  842. * The SHA-1 hash is what OpenSSH can be told to use in known_hosts files. If
  843. * a custom type is used, salt is ignored and you must provide the host
  844. * pre-hashed when checking for it in the libssh2_knownhost_check() function.
  845. *
  846. * The keylen parameter may be omitted (zero) if the key is provided as a
  847. * NULL-terminated base64-encoded string.
  848. */
  849. /* host format (2 bits) */
  850. #define LIBSSH2_KNOWNHOST_TYPE_MASK 0xffff
  851. #define LIBSSH2_KNOWNHOST_TYPE_PLAIN 1
  852. #define LIBSSH2_KNOWNHOST_TYPE_SHA1 2 /* always base64 encoded */
  853. #define LIBSSH2_KNOWNHOST_TYPE_CUSTOM 3
  854. /* key format (2 bits) */
  855. #define LIBSSH2_KNOWNHOST_KEYENC_MASK (3<<16)
  856. #define LIBSSH2_KNOWNHOST_KEYENC_RAW (1<<16)
  857. #define LIBSSH2_KNOWNHOST_KEYENC_BASE64 (2<<16)
  858. /* type of key (4 bits) */
  859. #define LIBSSH2_KNOWNHOST_KEY_MASK (15<<18)
  860. #define LIBSSH2_KNOWNHOST_KEY_SHIFT 18
  861. #define LIBSSH2_KNOWNHOST_KEY_RSA1 (1<<18)
  862. #define LIBSSH2_KNOWNHOST_KEY_SSHRSA (2<<18)
  863. #define LIBSSH2_KNOWNHOST_KEY_SSHDSS (3<<18)
  864. #define LIBSSH2_KNOWNHOST_KEY_ECDSA_256 (4<<18)
  865. #define LIBSSH2_KNOWNHOST_KEY_ECDSA_384 (5<<18)
  866. #define LIBSSH2_KNOWNHOST_KEY_ECDSA_521 (6<<18)
  867. #define LIBSSH2_KNOWNHOST_KEY_ED25519 (7<<18)
  868. #define LIBSSH2_KNOWNHOST_KEY_UNKNOWN (15<<18)
  869. LIBSSH2_API int
  870. libssh2_knownhost_add(LIBSSH2_KNOWNHOSTS *hosts,
  871. const char *host,
  872. const char *salt,
  873. const char *key, size_t keylen, int typemask,
  874. struct libssh2_knownhost **store);
  875. /*
  876. * libssh2_knownhost_addc
  877. *
  878. * Add a host and its associated key to the collection of known hosts.
  879. *
  880. * Takes a comment argument that may be NULL. A NULL comment indicates
  881. * there is no comment and the entry will end directly after the key
  882. * when written out to a file. An empty string "" comment will indicate an
  883. * empty comment which will cause a single space to be written after the key.
  884. *
  885. * The 'type' argument specifies on what format the given host and keys are:
  886. *
  887. * plain - ascii "hostname.domain.tld"
  888. * sha1 - SHA1(<salt> <host>) base64-encoded!
  889. * custom - another hash
  890. *
  891. * If 'sha1' is selected as type, the salt must be provided to the salt
  892. * argument. This too base64 encoded.
  893. *
  894. * The SHA-1 hash is what OpenSSH can be told to use in known_hosts files. If
  895. * a custom type is used, salt is ignored and you must provide the host
  896. * pre-hashed when checking for it in the libssh2_knownhost_check() function.
  897. *
  898. * The keylen parameter may be omitted (zero) if the key is provided as a
  899. * NULL-terminated base64-encoded string.
  900. */
  901. LIBSSH2_API int
  902. libssh2_knownhost_addc(LIBSSH2_KNOWNHOSTS *hosts,
  903. const char *host,
  904. const char *salt,
  905. const char *key, size_t keylen,
  906. const char *comment, size_t commentlen, int typemask,
  907. struct libssh2_knownhost **store);
  908. /*
  909. * libssh2_knownhost_check
  910. *
  911. * Check a host and its associated key against the collection of known hosts.
  912. *
  913. * The type is the type/format of the given host name.
  914. *
  915. * plain - ascii "hostname.domain.tld"
  916. * custom - prehashed base64 encoded. Note that this cannot use any salts.
  917. *
  918. *
  919. * 'knownhost' may be set to NULL if you don't care about that info.
  920. *
  921. * Returns:
  922. *
  923. * LIBSSH2_KNOWNHOST_CHECK_* values, see below
  924. *
  925. */
  926. #define LIBSSH2_KNOWNHOST_CHECK_MATCH 0
  927. #define LIBSSH2_KNOWNHOST_CHECK_MISMATCH 1
  928. #define LIBSSH2_KNOWNHOST_CHECK_NOTFOUND 2
  929. #define LIBSSH2_KNOWNHOST_CHECK_FAILURE 3
  930. LIBSSH2_API int
  931. libssh2_knownhost_check(LIBSSH2_KNOWNHOSTS *hosts,
  932. const char *host, const char *key, size_t keylen,
  933. int typemask,
  934. struct libssh2_knownhost **knownhost);
  935. /* this function is identital to the above one, but also takes a port
  936. argument that allows libssh2 to do a better check */
  937. LIBSSH2_API int
  938. libssh2_knownhost_checkp(LIBSSH2_KNOWNHOSTS *hosts,
  939. const char *host, int port,
  940. const char *key, size_t keylen,
  941. int typemask,
  942. struct libssh2_knownhost **knownhost);
  943. /*
  944. * libssh2_knownhost_del
  945. *
  946. * Remove a host from the collection of known hosts. The 'entry' struct is
  947. * retrieved by a call to libssh2_knownhost_check().
  948. *
  949. */
  950. LIBSSH2_API int
  951. libssh2_knownhost_del(LIBSSH2_KNOWNHOSTS *hosts,
  952. struct libssh2_knownhost *entry);
  953. /*
  954. * libssh2_knownhost_free
  955. *
  956. * Free an entire collection of known hosts.
  957. *
  958. */
  959. LIBSSH2_API void
  960. libssh2_knownhost_free(LIBSSH2_KNOWNHOSTS *hosts);
  961. /*
  962. * libssh2_knownhost_readline()
  963. *
  964. * Pass in a line of a file of 'type'. It makes libssh2 read this line.
  965. *
  966. * LIBSSH2_KNOWNHOST_FILE_OPENSSH is the only supported type.
  967. *
  968. */
  969. LIBSSH2_API int
  970. libssh2_knownhost_readline(LIBSSH2_KNOWNHOSTS *hosts,
  971. const char *line, size_t len, int type);
  972. /*
  973. * libssh2_knownhost_readfile
  974. *
  975. * Add hosts+key pairs from a given file.
  976. *
  977. * Returns a negative value for error or number of successfully added hosts.
  978. *
  979. * This implementation currently only knows one 'type' (openssh), all others
  980. * are reserved for future use.
  981. */
  982. #define LIBSSH2_KNOWNHOST_FILE_OPENSSH 1
  983. LIBSSH2_API int
  984. libssh2_knownhost_readfile(LIBSSH2_KNOWNHOSTS *hosts,
  985. const char *filename, int type);
  986. /*
  987. * libssh2_knownhost_writeline()
  988. *
  989. * Ask libssh2 to convert a known host to an output line for storage.
  990. *
  991. * Note that this function returns LIBSSH2_ERROR_BUFFER_TOO_SMALL if the given
  992. * output buffer is too small to hold the desired output.
  993. *
  994. * This implementation currently only knows one 'type' (openssh), all others
  995. * are reserved for future use.
  996. *
  997. */
  998. LIBSSH2_API int
  999. libssh2_knownhost_writeline(LIBSSH2_KNOWNHOSTS *hosts,
  1000. struct libssh2_knownhost *known,
  1001. char *buffer, size_t buflen,
  1002. size_t *outlen, /* the amount of written data */
  1003. int type);
  1004. /*
  1005. * libssh2_knownhost_writefile
  1006. *
  1007. * Write hosts+key pairs to a given file.
  1008. *
  1009. * This implementation currently only knows one 'type' (openssh), all others
  1010. * are reserved for future use.
  1011. */
  1012. LIBSSH2_API int
  1013. libssh2_knownhost_writefile(LIBSSH2_KNOWNHOSTS *hosts,
  1014. const char *filename, int type);
  1015. /*
  1016. * libssh2_knownhost_get()
  1017. *
  1018. * Traverse the internal list of known hosts. Pass NULL to 'prev' to get
  1019. * the first one. Or pass a pointer to the previously returned one to get the
  1020. * next.
  1021. *
  1022. * Returns:
  1023. * 0 if a fine host was stored in 'store'
  1024. * 1 if end of hosts
  1025. * [negative] on errors
  1026. */
  1027. LIBSSH2_API int
  1028. libssh2_knownhost_get(LIBSSH2_KNOWNHOSTS *hosts,
  1029. struct libssh2_knownhost **store,
  1030. struct libssh2_knownhost *prev);
  1031. #define HAVE_LIBSSH2_AGENT_API 0x010202 /* since 1.2.2 */
  1032. struct libssh2_agent_publickey {
  1033. unsigned int magic; /* magic stored by the library */
  1034. void *node; /* handle to the internal representation of key */
  1035. unsigned char *blob; /* public key blob */
  1036. size_t blob_len; /* length of the public key blob */
  1037. char *comment; /* comment in printable format */
  1038. };
  1039. /*
  1040. * libssh2_agent_init
  1041. *
  1042. * Init an ssh-agent handle. Returns the pointer to the handle.
  1043. *
  1044. */
  1045. LIBSSH2_API LIBSSH2_AGENT *
  1046. libssh2_agent_init(LIBSSH2_SESSION *session);
  1047. /*
  1048. * libssh2_agent_connect()
  1049. *
  1050. * Connect to an ssh-agent.
  1051. *
  1052. * Returns 0 if succeeded, or a negative value for error.
  1053. */
  1054. LIBSSH2_API int
  1055. libssh2_agent_connect(LIBSSH2_AGENT *agent);
  1056. /*
  1057. * libssh2_agent_list_identities()
  1058. *
  1059. * Request an ssh-agent to list identities.
  1060. *
  1061. * Returns 0 if succeeded, or a negative value for error.
  1062. */
  1063. LIBSSH2_API int
  1064. libssh2_agent_list_identities(LIBSSH2_AGENT *agent);
  1065. /*
  1066. * libssh2_agent_get_identity()
  1067. *
  1068. * Traverse the internal list of public keys. Pass NULL to 'prev' to get
  1069. * the first one. Or pass a pointer to the previously returned one to get the
  1070. * next.
  1071. *
  1072. * Returns:
  1073. * 0 if a fine public key was stored in 'store'
  1074. * 1 if end of public keys
  1075. * [negative] on errors
  1076. */
  1077. LIBSSH2_API int
  1078. libssh2_agent_get_identity(LIBSSH2_AGENT *agent,
  1079. struct libssh2_agent_publickey **store,
  1080. struct libssh2_agent_publickey *prev);
  1081. /*
  1082. * libssh2_agent_userauth()
  1083. *
  1084. * Do publickey user authentication with the help of ssh-agent.
  1085. *
  1086. * Returns 0 if succeeded, or a negative value for error.
  1087. */
  1088. LIBSSH2_API int
  1089. libssh2_agent_userauth(LIBSSH2_AGENT *agent,
  1090. const char *username,
  1091. struct libssh2_agent_publickey *identity);
  1092. /*
  1093. * libssh2_agent_disconnect()
  1094. *
  1095. * Close a connection to an ssh-agent.
  1096. *
  1097. * Returns 0 if succeeded, or a negative value for error.
  1098. */
  1099. LIBSSH2_API int
  1100. libssh2_agent_disconnect(LIBSSH2_AGENT *agent);
  1101. /*
  1102. * libssh2_agent_free()
  1103. *
  1104. * Free an ssh-agent handle. This function also frees the internal
  1105. * collection of public keys.
  1106. */
  1107. LIBSSH2_API void
  1108. libssh2_agent_free(LIBSSH2_AGENT *agent);
  1109. /*
  1110. * libssh2_agent_set_identity_path()
  1111. *
  1112. * Allows a custom agent identity socket path beyond SSH_AUTH_SOCK env
  1113. *
  1114. */
  1115. LIBSSH2_API void
  1116. libssh2_agent_set_identity_path(LIBSSH2_AGENT *agent,
  1117. const char *path);
  1118. /*
  1119. * libssh2_agent_get_identity_path()
  1120. *
  1121. * Returns the custom agent identity socket path if set
  1122. *
  1123. */
  1124. LIBSSH2_API const char *
  1125. libssh2_agent_get_identity_path(LIBSSH2_AGENT *agent);
  1126. /*
  1127. * libssh2_keepalive_config()
  1128. *
  1129. * Set how often keepalive messages should be sent. WANT_REPLY
  1130. * indicates whether the keepalive messages should request a response
  1131. * from the server. INTERVAL is number of seconds that can pass
  1132. * without any I/O, use 0 (the default) to disable keepalives. To
  1133. * avoid some busy-loop corner-cases, if you specify an interval of 1
  1134. * it will be treated as 2.
  1135. *
  1136. * Note that non-blocking applications are responsible for sending the
  1137. * keepalive messages using libssh2_keepalive_send().
  1138. */
  1139. LIBSSH2_API void libssh2_keepalive_config(LIBSSH2_SESSION *session,
  1140. int want_reply,
  1141. unsigned interval);
  1142. /*
  1143. * libssh2_keepalive_send()
  1144. *
  1145. * Send a keepalive message if needed. SECONDS_TO_NEXT indicates how
  1146. * many seconds you can sleep after this call before you need to call
  1147. * it again. Returns 0 on success, or LIBSSH2_ERROR_SOCKET_SEND on
  1148. * I/O errors.
  1149. */
  1150. LIBSSH2_API int libssh2_keepalive_send(LIBSSH2_SESSION *session,
  1151. int *seconds_to_next);
  1152. /* NOTE NOTE NOTE
  1153. libssh2_trace() has no function in builds that aren't built with debug
  1154. enabled
  1155. */
  1156. LIBSSH2_API int libssh2_trace(LIBSSH2_SESSION *session, int bitmask);
  1157. #define LIBSSH2_TRACE_TRANS (1<<1)
  1158. #define LIBSSH2_TRACE_KEX (1<<2)
  1159. #define LIBSSH2_TRACE_AUTH (1<<3)
  1160. #define LIBSSH2_TRACE_CONN (1<<4)
  1161. #define LIBSSH2_TRACE_SCP (1<<5)
  1162. #define LIBSSH2_TRACE_SFTP (1<<6)
  1163. #define LIBSSH2_TRACE_ERROR (1<<7)
  1164. #define LIBSSH2_TRACE_PUBLICKEY (1<<8)
  1165. #define LIBSSH2_TRACE_SOCKET (1<<9)
  1166. typedef void (*libssh2_trace_handler_func)(LIBSSH2_SESSION*,
  1167. void *,
  1168. const char *,
  1169. size_t);
  1170. LIBSSH2_API int libssh2_trace_sethandler(LIBSSH2_SESSION *session,
  1171. void *context,
  1172. libssh2_trace_handler_func callback);
  1173. #ifdef __cplusplus
  1174. } /* extern "C" */
  1175. #endif
  1176. #endif /* !RC_INVOKED */
  1177. #endif /* LIBSSH2_H */