libssh2.h 59 KB

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