libssh2.h 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118
  1. /* Copyright (c) 2004-2009, Sara Golemon <sarag@libssh2.org>
  2. * Copyright (c) 2009 by 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-2010 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.2.7"
  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 2
  51. #define LIBSSH2_VERSION_PATCH 7
  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 0x010207
  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 "Tue Aug 17 21:11:33 UTC 2010"
  75. #ifndef LIBSSH2_VERSION_ONLY
  76. #ifdef __cplusplus
  77. extern "C" {
  78. #endif
  79. #include <stddef.h>
  80. #include <string.h>
  81. #include <sys/stat.h>
  82. #include <sys/types.h>
  83. /* Allow alternate API prefix from CFLAGS or calling app */
  84. #ifndef LIBSSH2_API
  85. # ifdef LIBSSH2_WIN32
  86. # ifdef LIBSSH2_LIBRARY
  87. # define LIBSSH2_API __declspec(dllexport)
  88. # else
  89. # define LIBSSH2_API __declspec(dllimport)
  90. # endif /* LIBSSH2_LIBRARY */
  91. # else /* !LIBSSH2_WIN32 */
  92. # define LIBSSH2_API
  93. # endif /* LIBSSH2_WIN32 */
  94. #endif /* LIBSSH2_API */
  95. #if defined(LIBSSH2_DARWIN) || (defined(LIBSSH2_WIN32) && \
  96. !defined(_MSC_VER) && !defined(__MINGW32__))
  97. # include <sys/uio.h>
  98. #endif
  99. #if (defined(NETWARE) && !defined(__NOVELL_LIBC__))
  100. # include <sys/bsdskt.h>
  101. typedef unsigned char uint8_t;
  102. typedef unsigned int uint32_t;
  103. #endif
  104. #ifdef _MSC_VER
  105. typedef unsigned char uint8_t;
  106. typedef unsigned int uint32_t;
  107. typedef unsigned __int64 libssh2_uint64_t;
  108. typedef __int64 libssh2_int64_t;
  109. # ifndef _SSIZE_T_DEFINED
  110. typedef int ssize_t;
  111. # define _SSIZE_T_DEFINED
  112. #endif
  113. #else
  114. typedef unsigned long long libssh2_uint64_t;
  115. typedef long long libssh2_int64_t;
  116. #endif
  117. /* Part of every banner, user specified or not */
  118. #define LIBSSH2_SSH_BANNER "SSH-2.0-libssh2_" LIBSSH2_VERSION
  119. /* We *could* add a comment here if we so chose */
  120. #define LIBSSH2_SSH_DEFAULT_BANNER LIBSSH2_SSH_BANNER
  121. #define LIBSSH2_SSH_DEFAULT_BANNER_WITH_CRLF LIBSSH2_SSH_DEFAULT_BANNER "\r\n"
  122. /* Default generate and safe prime sizes for diffie-hellman-group-exchange-sha1 */
  123. #define LIBSSH2_DH_GEX_MINGROUP 1024
  124. #define LIBSSH2_DH_GEX_OPTGROUP 1536
  125. #define LIBSSH2_DH_GEX_MAXGROUP 2048
  126. /* Defaults for pty requests */
  127. #define LIBSSH2_TERM_WIDTH 80
  128. #define LIBSSH2_TERM_HEIGHT 24
  129. #define LIBSSH2_TERM_WIDTH_PX 0
  130. #define LIBSSH2_TERM_HEIGHT_PX 0
  131. /* 1/4 second */
  132. #define LIBSSH2_SOCKET_POLL_UDELAY 250000
  133. /* 0.25 * 120 == 30 seconds */
  134. #define LIBSSH2_SOCKET_POLL_MAXLOOPS 120
  135. /* Maximum size to allow a payload to compress to, plays it safe by falling
  136. short of spec limits */
  137. #define LIBSSH2_PACKET_MAXCOMP 32000
  138. /* Maximum size to allow a payload to deccompress to, plays it safe by
  139. allowing more than spec requires */
  140. #define LIBSSH2_PACKET_MAXDECOMP 40000
  141. /* Maximum size for an inbound compressed payload, plays it safe by
  142. overshooting spec limits */
  143. #define LIBSSH2_PACKET_MAXPAYLOAD 40000
  144. /* Malloc callbacks */
  145. #define LIBSSH2_ALLOC_FUNC(name) void *name(size_t count, void **abstract)
  146. #define LIBSSH2_REALLOC_FUNC(name) void *name(void *ptr, size_t count, \
  147. void **abstract)
  148. #define LIBSSH2_FREE_FUNC(name) void name(void *ptr, void **abstract)
  149. typedef struct _LIBSSH2_USERAUTH_KBDINT_PROMPT
  150. {
  151. char* text;
  152. unsigned int length;
  153. unsigned char echo;
  154. } LIBSSH2_USERAUTH_KBDINT_PROMPT;
  155. typedef struct _LIBSSH2_USERAUTH_KBDINT_RESPONSE
  156. {
  157. char* text;
  158. unsigned int length;
  159. } LIBSSH2_USERAUTH_KBDINT_RESPONSE;
  160. /* 'publickey' authentication callback */
  161. #define LIBSSH2_USERAUTH_PUBLICKEY_SIGN_FUNC(name) \
  162. int name(LIBSSH2_SESSION *session, unsigned char **sig, size_t *sig_len, \
  163. const unsigned char *data, size_t data_len, void **abstract)
  164. /* 'keyboard-interactive' authentication callback */
  165. #define LIBSSH2_USERAUTH_KBDINT_RESPONSE_FUNC(name_) \
  166. void name_(const char* name, int name_len, const char* instruction, \
  167. int instruction_len, int num_prompts, \
  168. const LIBSSH2_USERAUTH_KBDINT_PROMPT* prompts, \
  169. LIBSSH2_USERAUTH_KBDINT_RESPONSE* responses, void **abstract)
  170. /* Callbacks for special SSH packets */
  171. #define LIBSSH2_IGNORE_FUNC(name) \
  172. void name(LIBSSH2_SESSION *session, const char *message, int message_len, \
  173. void **abstract)
  174. #define LIBSSH2_DEBUG_FUNC(name) \
  175. void name(LIBSSH2_SESSION *session, int always_display, const char *message, \
  176. int message_len, const char *language, int language_len, \
  177. void **abstract)
  178. #define LIBSSH2_DISCONNECT_FUNC(name) \
  179. void name(LIBSSH2_SESSION *session, int reason, const char *message, \
  180. int message_len, const char *language, int language_len, \
  181. void **abstract)
  182. #define LIBSSH2_PASSWD_CHANGEREQ_FUNC(name) \
  183. void name(LIBSSH2_SESSION *session, char **newpw, int *newpw_len, \
  184. void **abstract)
  185. #define LIBSSH2_MACERROR_FUNC(name) \
  186. int name(LIBSSH2_SESSION *session, const char *packet, int packet_len, \
  187. void **abstract)
  188. #define LIBSSH2_X11_OPEN_FUNC(name) \
  189. void name(LIBSSH2_SESSION *session, LIBSSH2_CHANNEL *channel, \
  190. const char *shost, int sport, void **abstract)
  191. #define LIBSSH2_CHANNEL_CLOSE_FUNC(name) \
  192. void name(LIBSSH2_SESSION *session, void **session_abstract, \
  193. LIBSSH2_CHANNEL *channel, void **channel_abstract)
  194. /* libssh2_session_callback_set() constants */
  195. #define LIBSSH2_CALLBACK_IGNORE 0
  196. #define LIBSSH2_CALLBACK_DEBUG 1
  197. #define LIBSSH2_CALLBACK_DISCONNECT 2
  198. #define LIBSSH2_CALLBACK_MACERROR 3
  199. #define LIBSSH2_CALLBACK_X11 4
  200. /* libssh2_session_method_pref() constants */
  201. #define LIBSSH2_METHOD_KEX 0
  202. #define LIBSSH2_METHOD_HOSTKEY 1
  203. #define LIBSSH2_METHOD_CRYPT_CS 2
  204. #define LIBSSH2_METHOD_CRYPT_SC 3
  205. #define LIBSSH2_METHOD_MAC_CS 4
  206. #define LIBSSH2_METHOD_MAC_SC 5
  207. #define LIBSSH2_METHOD_COMP_CS 6
  208. #define LIBSSH2_METHOD_COMP_SC 7
  209. #define LIBSSH2_METHOD_LANG_CS 8
  210. #define LIBSSH2_METHOD_LANG_SC 9
  211. /* session.flags bits */
  212. #define LIBSSH2_FLAG_SIGPIPE 0x00000001
  213. typedef struct _LIBSSH2_SESSION LIBSSH2_SESSION;
  214. typedef struct _LIBSSH2_CHANNEL LIBSSH2_CHANNEL;
  215. typedef struct _LIBSSH2_LISTENER LIBSSH2_LISTENER;
  216. typedef struct _LIBSSH2_KNOWNHOSTS LIBSSH2_KNOWNHOSTS;
  217. typedef struct _LIBSSH2_AGENT LIBSSH2_AGENT;
  218. typedef struct _LIBSSH2_POLLFD {
  219. unsigned char type; /* LIBSSH2_POLLFD_* below */
  220. union {
  221. int socket; /* File descriptors -- examined with system select() call */
  222. LIBSSH2_CHANNEL *channel; /* Examined by checking internal state */
  223. LIBSSH2_LISTENER *listener; /* Read polls only -- are inbound
  224. connections waiting to be accepted? */
  225. } fd;
  226. unsigned long events; /* Requested Events */
  227. unsigned long revents; /* Returned Events */
  228. } LIBSSH2_POLLFD;
  229. /* Poll FD Descriptor Types */
  230. #define LIBSSH2_POLLFD_SOCKET 1
  231. #define LIBSSH2_POLLFD_CHANNEL 2
  232. #define LIBSSH2_POLLFD_LISTENER 3
  233. /* Note: Win32 Doesn't actually have a poll() implementation, so some of these
  234. values are faked with select() data */
  235. /* Poll FD events/revents -- Match sys/poll.h where possible */
  236. #define LIBSSH2_POLLFD_POLLIN 0x0001 /* Data available to be read or
  237. connection available --
  238. All */
  239. #define LIBSSH2_POLLFD_POLLPRI 0x0002 /* Priority data available to
  240. be read -- Socket only */
  241. #define LIBSSH2_POLLFD_POLLEXT 0x0002 /* Extended data available to
  242. be read -- Channel only */
  243. #define LIBSSH2_POLLFD_POLLOUT 0x0004 /* Can may be written --
  244. Socket/Channel */
  245. /* revents only */
  246. #define LIBSSH2_POLLFD_POLLERR 0x0008 /* Error Condition -- Socket */
  247. #define LIBSSH2_POLLFD_POLLHUP 0x0010 /* HangUp/EOF -- Socket */
  248. #define LIBSSH2_POLLFD_SESSION_CLOSED 0x0010 /* Session Disconnect */
  249. #define LIBSSH2_POLLFD_POLLNVAL 0x0020 /* Invalid request -- Socket
  250. Only */
  251. #define LIBSSH2_POLLFD_POLLEX 0x0040 /* Exception Condition --
  252. Socket/Win32 */
  253. #define LIBSSH2_POLLFD_CHANNEL_CLOSED 0x0080 /* Channel Disconnect */
  254. #define LIBSSH2_POLLFD_LISTENER_CLOSED 0x0080 /* Listener Disconnect */
  255. #define HAVE_LIBSSH2_SESSION_BLOCK_DIRECTION
  256. /* Block Direction Types */
  257. #define LIBSSH2_SESSION_BLOCK_INBOUND 0x0001
  258. #define LIBSSH2_SESSION_BLOCK_OUTBOUND 0x0002
  259. /* Hash Types */
  260. #define LIBSSH2_HOSTKEY_HASH_MD5 1
  261. #define LIBSSH2_HOSTKEY_HASH_SHA1 2
  262. /* Hostkey Types */
  263. #define LIBSSH2_HOSTKEY_TYPE_UNKNOWN 0
  264. #define LIBSSH2_HOSTKEY_TYPE_RSA 1
  265. #define LIBSSH2_HOSTKEY_TYPE_DSS 2
  266. /* Disconnect Codes (defined by SSH protocol) */
  267. #define SSH_DISCONNECT_HOST_NOT_ALLOWED_TO_CONNECT 1
  268. #define SSH_DISCONNECT_PROTOCOL_ERROR 2
  269. #define SSH_DISCONNECT_KEY_EXCHANGE_FAILED 3
  270. #define SSH_DISCONNECT_RESERVED 4
  271. #define SSH_DISCONNECT_MAC_ERROR 5
  272. #define SSH_DISCONNECT_COMPRESSION_ERROR 6
  273. #define SSH_DISCONNECT_SERVICE_NOT_AVAILABLE 7
  274. #define SSH_DISCONNECT_PROTOCOL_VERSION_NOT_SUPPORTED 8
  275. #define SSH_DISCONNECT_HOST_KEY_NOT_VERIFIABLE 9
  276. #define SSH_DISCONNECT_CONNECTION_LOST 10
  277. #define SSH_DISCONNECT_BY_APPLICATION 11
  278. #define SSH_DISCONNECT_TOO_MANY_CONNECTIONS 12
  279. #define SSH_DISCONNECT_AUTH_CANCELLED_BY_USER 13
  280. #define SSH_DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLE 14
  281. #define SSH_DISCONNECT_ILLEGAL_USER_NAME 15
  282. /* Error Codes (defined by libssh2) */
  283. #define LIBSSH2_ERROR_NONE 0
  284. #define LIBSSH2_ERROR_SOCKET_NONE -1
  285. #define LIBSSH2_ERROR_BANNER_NONE -2
  286. #define LIBSSH2_ERROR_BANNER_SEND -3
  287. #define LIBSSH2_ERROR_INVALID_MAC -4
  288. #define LIBSSH2_ERROR_KEX_FAILURE -5
  289. #define LIBSSH2_ERROR_ALLOC -6
  290. #define LIBSSH2_ERROR_SOCKET_SEND -7
  291. #define LIBSSH2_ERROR_KEY_EXCHANGE_FAILURE -8
  292. #define LIBSSH2_ERROR_TIMEOUT -9
  293. #define LIBSSH2_ERROR_HOSTKEY_INIT -10
  294. #define LIBSSH2_ERROR_HOSTKEY_SIGN -11
  295. #define LIBSSH2_ERROR_DECRYPT -12
  296. #define LIBSSH2_ERROR_SOCKET_DISCONNECT -13
  297. #define LIBSSH2_ERROR_PROTO -14
  298. #define LIBSSH2_ERROR_PASSWORD_EXPIRED -15
  299. #define LIBSSH2_ERROR_FILE -16
  300. #define LIBSSH2_ERROR_METHOD_NONE -17
  301. #define LIBSSH2_ERROR_AUTHENTICATION_FAILED -18
  302. #define LIBSSH2_ERROR_PUBLICKEY_UNRECOGNIZED LIBSSH2_ERROR_AUTHENTICATION_FAILED
  303. #define LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED -19
  304. #define LIBSSH2_ERROR_CHANNEL_OUTOFORDER -20
  305. #define LIBSSH2_ERROR_CHANNEL_FAILURE -21
  306. #define LIBSSH2_ERROR_CHANNEL_REQUEST_DENIED -22
  307. #define LIBSSH2_ERROR_CHANNEL_UNKNOWN -23
  308. #define LIBSSH2_ERROR_CHANNEL_WINDOW_EXCEEDED -24
  309. #define LIBSSH2_ERROR_CHANNEL_PACKET_EXCEEDED -25
  310. #define LIBSSH2_ERROR_CHANNEL_CLOSED -26
  311. #define LIBSSH2_ERROR_CHANNEL_EOF_SENT -27
  312. #define LIBSSH2_ERROR_SCP_PROTOCOL -28
  313. #define LIBSSH2_ERROR_ZLIB -29
  314. #define LIBSSH2_ERROR_SOCKET_TIMEOUT -30
  315. #define LIBSSH2_ERROR_SFTP_PROTOCOL -31
  316. #define LIBSSH2_ERROR_REQUEST_DENIED -32
  317. #define LIBSSH2_ERROR_METHOD_NOT_SUPPORTED -33
  318. #define LIBSSH2_ERROR_INVAL -34
  319. #define LIBSSH2_ERROR_INVALID_POLL_TYPE -35
  320. #define LIBSSH2_ERROR_PUBLICKEY_PROTOCOL -36
  321. #define LIBSSH2_ERROR_EAGAIN -37
  322. #define LIBSSH2_ERROR_BUFFER_TOO_SMALL -38
  323. #define LIBSSH2_ERROR_BAD_USE -39
  324. #define LIBSSH2_ERROR_COMPRESS -40
  325. #define LIBSSH2_ERROR_OUT_OF_BOUNDARY -41
  326. #define LIBSSH2_ERROR_AGENT_PROTOCOL -42
  327. /* Global API */
  328. #define LIBSSH2_INIT_NO_CRYPTO 0x0001
  329. /*
  330. * libssh2_init()
  331. *
  332. * Initialize the libssh2 functions. This typically initialize the
  333. * crypto library. It uses a global state, and is not thread safe --
  334. * you must make sure this function is not called concurrently.
  335. *
  336. * Flags can be:
  337. * 0: Normal initialize
  338. * LIBSSH2_INIT_NO_CRYPTO: Do not initialize the crypto library (ie.
  339. * OPENSSL_add_cipher_algoritms() for OpenSSL
  340. *
  341. * Returns 0 if succeeded, or a negative value for error.
  342. */
  343. LIBSSH2_API int libssh2_init(int flags);
  344. /*
  345. * libssh2_exit()
  346. *
  347. * Exit the libssh2 functions and free's all memory used internal.
  348. */
  349. LIBSSH2_API void libssh2_exit(void);
  350. /* Session API */
  351. LIBSSH2_API LIBSSH2_SESSION *
  352. libssh2_session_init_ex(LIBSSH2_ALLOC_FUNC((*my_alloc)),
  353. LIBSSH2_FREE_FUNC((*my_free)),
  354. LIBSSH2_REALLOC_FUNC((*my_realloc)), void *abstract);
  355. #define libssh2_session_init() libssh2_session_init_ex(NULL, NULL, NULL, NULL)
  356. LIBSSH2_API void **libssh2_session_abstract(LIBSSH2_SESSION *session);
  357. LIBSSH2_API void *libssh2_session_callback_set(LIBSSH2_SESSION *session,
  358. int cbtype, void *callback);
  359. LIBSSH2_API int libssh2_banner_set(LIBSSH2_SESSION *session,
  360. const char *banner);
  361. LIBSSH2_API int libssh2_session_startup(LIBSSH2_SESSION *session, int sock);
  362. LIBSSH2_API int libssh2_session_disconnect_ex(LIBSSH2_SESSION *session,
  363. int reason,
  364. const char *description,
  365. const char *lang);
  366. #define libssh2_session_disconnect(session, description) \
  367. libssh2_session_disconnect_ex((session), SSH_DISCONNECT_BY_APPLICATION, \
  368. (description), "")
  369. LIBSSH2_API int libssh2_session_free(LIBSSH2_SESSION *session);
  370. LIBSSH2_API const char *libssh2_hostkey_hash(LIBSSH2_SESSION *session,
  371. int hash_type);
  372. LIBSSH2_API const char *libssh2_session_hostkey(LIBSSH2_SESSION *session,
  373. size_t *len, int *type);
  374. LIBSSH2_API int libssh2_session_method_pref(LIBSSH2_SESSION *session,
  375. int method_type,
  376. const char *prefs);
  377. LIBSSH2_API const char *libssh2_session_methods(LIBSSH2_SESSION *session,
  378. int method_type);
  379. LIBSSH2_API int libssh2_session_last_error(LIBSSH2_SESSION *session,
  380. char **errmsg,
  381. int *errmsg_len, int want_buf);
  382. LIBSSH2_API int libssh2_session_last_errno(LIBSSH2_SESSION *session);
  383. LIBSSH2_API int libssh2_session_block_directions(LIBSSH2_SESSION *session);
  384. LIBSSH2_API int libssh2_session_flag(LIBSSH2_SESSION *session, int flag,
  385. int value);
  386. /* Userauth API */
  387. LIBSSH2_API char *libssh2_userauth_list(LIBSSH2_SESSION *session,
  388. const char *username,
  389. unsigned int username_len);
  390. LIBSSH2_API int libssh2_userauth_authenticated(LIBSSH2_SESSION *session);
  391. LIBSSH2_API int libssh2_userauth_password_ex(LIBSSH2_SESSION *session,
  392. const char *username,
  393. unsigned int username_len,
  394. const char *password,
  395. unsigned int password_len,
  396. LIBSSH2_PASSWD_CHANGEREQ_FUNC((*passwd_change_cb)));
  397. #define libssh2_userauth_password(session, username, password) \
  398. libssh2_userauth_password_ex((session), (username), strlen(username), \
  399. (password), strlen(password), NULL)
  400. LIBSSH2_API int
  401. libssh2_userauth_publickey_fromfile_ex(LIBSSH2_SESSION *session,
  402. const char *username,
  403. unsigned int username_len,
  404. const char *publickey,
  405. const char *privatekey,
  406. const char *passphrase);
  407. #define libssh2_userauth_publickey_fromfile(session, username, publickey, \
  408. privatekey, passphrase) \
  409. libssh2_userauth_publickey_fromfile_ex((session), (username), \
  410. strlen(username), (publickey), \
  411. (privatekey), (passphrase))
  412. LIBSSH2_API int
  413. libssh2_userauth_publickey(LIBSSH2_SESSION *session,
  414. const char *username,
  415. const unsigned char *pubkeydata,
  416. size_t pubkeydata_len,
  417. LIBSSH2_USERAUTH_PUBLICKEY_SIGN_FUNC((*sign_callback)),
  418. void **abstract);
  419. LIBSSH2_API int
  420. libssh2_userauth_hostbased_fromfile_ex(LIBSSH2_SESSION *session,
  421. const char *username,
  422. unsigned int username_len,
  423. const char *publickey,
  424. const char *privatekey,
  425. const char *passphrase,
  426. const char *hostname,
  427. unsigned int hostname_len,
  428. const char *local_username,
  429. unsigned int local_username_len);
  430. #define libssh2_userauth_hostbased_fromfile(session, username, publickey, \
  431. privatekey, passphrase, hostname) \
  432. libssh2_userauth_hostbased_fromfile_ex((session), (username), \
  433. strlen(username), (publickey), \
  434. (privatekey), (passphrase), \
  435. (hostname), strlen(hostname), \
  436. (username), strlen(username))
  437. /*
  438. * response_callback is provided with filled by library prompts array,
  439. * but client must allocate and fill individual responses. Responses
  440. * array is already allocated. Responses data will be freed by libssh2
  441. * after callback return, but before subsequent callback invokation.
  442. */
  443. LIBSSH2_API int
  444. libssh2_userauth_keyboard_interactive_ex(LIBSSH2_SESSION* session,
  445. const char *username,
  446. unsigned int username_len,
  447. LIBSSH2_USERAUTH_KBDINT_RESPONSE_FUNC((*response_callback)));
  448. #define libssh2_userauth_keyboard_interactive(session, username, \
  449. response_callback) \
  450. libssh2_userauth_keyboard_interactive_ex((session), (username), \
  451. strlen(username), (response_callback))
  452. LIBSSH2_API int libssh2_poll(LIBSSH2_POLLFD *fds, unsigned int nfds,
  453. long timeout);
  454. /* Channel API */
  455. #define LIBSSH2_CHANNEL_WINDOW_DEFAULT 65536
  456. #define LIBSSH2_CHANNEL_PACKET_DEFAULT 32768
  457. #define LIBSSH2_CHANNEL_MINADJUST 1024
  458. /* Extended Data Handling */
  459. #define LIBSSH2_CHANNEL_EXTENDED_DATA_NORMAL 0
  460. #define LIBSSH2_CHANNEL_EXTENDED_DATA_IGNORE 1
  461. #define LIBSSH2_CHANNEL_EXTENDED_DATA_MERGE 2
  462. #define SSH_EXTENDED_DATA_STDERR 1
  463. /* Returned by any function that would block during a read/write opperation */
  464. #define LIBSSH2CHANNEL_EAGAIN LIBSSH2_ERROR_EAGAIN
  465. LIBSSH2_API LIBSSH2_CHANNEL *
  466. libssh2_channel_open_ex(LIBSSH2_SESSION *session, const char *channel_type,
  467. unsigned int channel_type_len,
  468. unsigned int window_size, unsigned int packet_size,
  469. const char *message, unsigned int message_len);
  470. #define libssh2_channel_open_session(session) \
  471. libssh2_channel_open_ex((session), "session", sizeof("session") - 1, \
  472. LIBSSH2_CHANNEL_WINDOW_DEFAULT, \
  473. LIBSSH2_CHANNEL_PACKET_DEFAULT, NULL, 0)
  474. LIBSSH2_API LIBSSH2_CHANNEL *
  475. libssh2_channel_direct_tcpip_ex(LIBSSH2_SESSION *session, const char *host,
  476. int port, const char *shost, int sport);
  477. #define libssh2_channel_direct_tcpip(session, host, port) \
  478. libssh2_channel_direct_tcpip_ex((session), (host), (port), "127.0.0.1", 22)
  479. LIBSSH2_API LIBSSH2_LISTENER *
  480. libssh2_channel_forward_listen_ex(LIBSSH2_SESSION *session, const char *host,
  481. int port, int *bound_port, int queue_maxsize);
  482. #define libssh2_channel_forward_listen(session, port) \
  483. libssh2_channel_forward_listen_ex((session), NULL, (port), NULL, 16)
  484. LIBSSH2_API int libssh2_channel_forward_cancel(LIBSSH2_LISTENER *listener);
  485. LIBSSH2_API LIBSSH2_CHANNEL *
  486. libssh2_channel_forward_accept(LIBSSH2_LISTENER *listener);
  487. LIBSSH2_API int libssh2_channel_setenv_ex(LIBSSH2_CHANNEL *channel,
  488. const char *varname,
  489. unsigned int varname_len,
  490. const char *value,
  491. unsigned int value_len);
  492. #define libssh2_channel_setenv(channel, varname, value) \
  493. libssh2_channel_setenv_ex((channel), (varname), strlen(varname), (value), \
  494. strlen(value))
  495. LIBSSH2_API int libssh2_channel_request_pty_ex(LIBSSH2_CHANNEL *channel,
  496. const char *term,
  497. unsigned int term_len,
  498. const char *modes,
  499. unsigned int modes_len,
  500. int width, int height,
  501. int width_px, int height_px);
  502. #define libssh2_channel_request_pty(channel, term) \
  503. libssh2_channel_request_pty_ex((channel), (term), strlen(term), NULL, 0, \
  504. LIBSSH2_TERM_WIDTH, LIBSSH2_TERM_HEIGHT, \
  505. LIBSSH2_TERM_WIDTH_PX, LIBSSH2_TERM_HEIGHT_PX)
  506. LIBSSH2_API int libssh2_channel_request_pty_size_ex(LIBSSH2_CHANNEL *channel,
  507. int width, int height,
  508. int width_px,
  509. int height_px);
  510. #define libssh2_channel_request_pty_size(channel, width, height) \
  511. libssh2_channel_request_pty_size_ex( (channel), (width), (height), 0, 0)
  512. LIBSSH2_API int libssh2_channel_x11_req_ex(LIBSSH2_CHANNEL *channel,
  513. int single_connection,
  514. const char *auth_proto,
  515. const char *auth_cookie,
  516. int screen_number);
  517. #define libssh2_channel_x11_req(channel, screen_number) \
  518. libssh2_channel_x11_req_ex((channel), 0, NULL, NULL, (screen_number))
  519. LIBSSH2_API int libssh2_channel_process_startup(LIBSSH2_CHANNEL *channel,
  520. const char *request,
  521. unsigned int request_len,
  522. const char *message,
  523. unsigned int message_len);
  524. #define libssh2_channel_shell(channel) \
  525. libssh2_channel_process_startup((channel), "shell", sizeof("shell") - 1, \
  526. NULL, 0)
  527. #define libssh2_channel_exec(channel, command) \
  528. libssh2_channel_process_startup((channel), "exec", sizeof("exec") - 1, \
  529. (command), strlen(command))
  530. #define libssh2_channel_subsystem(channel, subsystem) \
  531. libssh2_channel_process_startup((channel), "subsystem", \
  532. sizeof("subsystem") - 1, (subsystem), \
  533. strlen(subsystem))
  534. LIBSSH2_API ssize_t libssh2_channel_read_ex(LIBSSH2_CHANNEL *channel,
  535. int stream_id, char *buf,
  536. size_t buflen);
  537. #define libssh2_channel_read(channel, buf, buflen) \
  538. libssh2_channel_read_ex((channel), 0, (buf), (buflen))
  539. #define libssh2_channel_read_stderr(channel, buf, buflen) \
  540. libssh2_channel_read_ex((channel), SSH_EXTENDED_DATA_STDERR, (buf), (buflen))
  541. LIBSSH2_API int libssh2_poll_channel_read(LIBSSH2_CHANNEL *channel,
  542. int extended);
  543. LIBSSH2_API unsigned long
  544. libssh2_channel_window_read_ex(LIBSSH2_CHANNEL *channel,
  545. unsigned long *read_avail,
  546. unsigned long *window_size_initial);
  547. #define libssh2_channel_window_read(channel) \
  548. libssh2_channel_window_read_ex((channel), NULL, NULL)
  549. /* libssh2_channel_receive_window_adjust is DEPRECATED, do not use! */
  550. LIBSSH2_API unsigned long
  551. libssh2_channel_receive_window_adjust(LIBSSH2_CHANNEL *channel,
  552. unsigned long adjustment,
  553. unsigned char force);
  554. LIBSSH2_API int
  555. libssh2_channel_receive_window_adjust2(LIBSSH2_CHANNEL *channel,
  556. unsigned long adjustment,
  557. unsigned char force,
  558. unsigned int *storewindow);
  559. LIBSSH2_API ssize_t libssh2_channel_write_ex(LIBSSH2_CHANNEL *channel,
  560. int stream_id, const char *buf,
  561. size_t buflen);
  562. #define libssh2_channel_write(channel, buf, buflen) \
  563. libssh2_channel_write_ex((channel), 0, (buf), (buflen))
  564. #define libssh2_channel_write_stderr(channel, buf, buflen) \
  565. libssh2_channel_write_ex((channel), SSH_EXTENDED_DATA_STDERR, (buf), (buflen))
  566. LIBSSH2_API unsigned long
  567. libssh2_channel_window_write_ex(LIBSSH2_CHANNEL *channel,
  568. unsigned long *window_size_initial);
  569. #define libssh2_channel_window_write(channel) \
  570. libssh2_channel_window_write_ex((channel), NULL)
  571. LIBSSH2_API void libssh2_session_set_blocking(LIBSSH2_SESSION* session,
  572. int blocking);
  573. LIBSSH2_API int libssh2_session_get_blocking(LIBSSH2_SESSION* session);
  574. LIBSSH2_API void libssh2_channel_set_blocking(LIBSSH2_CHANNEL *channel,
  575. int blocking);
  576. /* libssh2_channel_handle_extended_data is DEPRECATED, do not use! */
  577. LIBSSH2_API void libssh2_channel_handle_extended_data(LIBSSH2_CHANNEL *channel,
  578. int ignore_mode);
  579. LIBSSH2_API int libssh2_channel_handle_extended_data2(LIBSSH2_CHANNEL *channel,
  580. int ignore_mode);
  581. /* libssh2_channel_ignore_extended_data() is defined below for BC with version
  582. * 0.1
  583. *
  584. * Future uses should use libssh2_channel_handle_extended_data() directly if
  585. * LIBSSH2_CHANNEL_EXTENDED_DATA_MERGE is passed, extended data will be read
  586. * (FIFO) from the standard data channel
  587. */
  588. /* DEPRECATED */
  589. #define libssh2_channel_ignore_extended_data(channel, ignore) \
  590. libssh2_channel_handle_extended_data((channel), \
  591. (ignore) ? \
  592. LIBSSH2_CHANNEL_EXTENDED_DATA_IGNORE : \
  593. LIBSSH2_CHANNEL_EXTENDED_DATA_NORMAL )
  594. #define LIBSSH2_CHANNEL_FLUSH_EXTENDED_DATA -1
  595. #define LIBSSH2_CHANNEL_FLUSH_ALL -2
  596. LIBSSH2_API int libssh2_channel_flush_ex(LIBSSH2_CHANNEL *channel,
  597. int streamid);
  598. #define libssh2_channel_flush(channel) libssh2_channel_flush_ex((channel), 0)
  599. #define libssh2_channel_flush_stderr(channel) \
  600. libssh2_channel_flush_ex((channel), SSH_EXTENDED_DATA_STDERR)
  601. LIBSSH2_API int libssh2_channel_get_exit_status(LIBSSH2_CHANNEL* channel);
  602. LIBSSH2_API int libssh2_channel_send_eof(LIBSSH2_CHANNEL *channel);
  603. LIBSSH2_API int libssh2_channel_eof(LIBSSH2_CHANNEL *channel);
  604. LIBSSH2_API int libssh2_channel_wait_eof(LIBSSH2_CHANNEL *channel);
  605. LIBSSH2_API int libssh2_channel_close(LIBSSH2_CHANNEL *channel);
  606. LIBSSH2_API int libssh2_channel_wait_closed(LIBSSH2_CHANNEL *channel);
  607. LIBSSH2_API int libssh2_channel_free(LIBSSH2_CHANNEL *channel);
  608. LIBSSH2_API LIBSSH2_CHANNEL *libssh2_scp_recv(LIBSSH2_SESSION *session,
  609. const char *path,
  610. struct stat *sb);
  611. LIBSSH2_API LIBSSH2_CHANNEL *libssh2_scp_send_ex(LIBSSH2_SESSION *session,
  612. const char *path, int mode,
  613. size_t size, long mtime,
  614. long atime);
  615. LIBSSH2_API LIBSSH2_CHANNEL *
  616. libssh2_scp_send64(LIBSSH2_SESSION *session, const char *path, int mode,
  617. libssh2_int64_t size, time_t mtime, time_t atime);
  618. #define libssh2_scp_send(session, path, mode, size) \
  619. libssh2_scp_send_ex((session), (path), (mode), (size), 0, 0)
  620. LIBSSH2_API int libssh2_base64_decode(LIBSSH2_SESSION *session, char **dest,
  621. unsigned int *dest_len,
  622. const char *src, unsigned int src_len);
  623. LIBSSH2_API
  624. const char *libssh2_version(int req_version_num);
  625. #define HAVE_LIBSSH2_KNOWNHOST_API 0x010101 /* since 1.1.1 */
  626. #define HAVE_LIBSSH2_VERSION_API 0x010100 /* libssh2_version since 1.1 */
  627. struct libssh2_knownhost {
  628. unsigned int magic; /* magic stored by the library */
  629. void *node; /* handle to the internal representation of this host */
  630. char *name; /* this is NULL if no plain text host name exists */
  631. char *key; /* key in base64/printable format */
  632. int typemask;
  633. };
  634. /*
  635. * libssh2_knownhost_init
  636. *
  637. * Init a collection of known hosts. Returns the pointer to a collection.
  638. *
  639. */
  640. LIBSSH2_API LIBSSH2_KNOWNHOSTS *
  641. libssh2_knownhost_init(LIBSSH2_SESSION *session);
  642. /*
  643. * libssh2_knownhost_add
  644. *
  645. * Add a host and its associated key to the collection of known hosts.
  646. *
  647. * The 'type' argument specifies on what format the given host and keys are:
  648. *
  649. * plain - ascii "hostname.domain.tld"
  650. * sha1 - SHA1(<salt> <host>) base64-encoded!
  651. * custom - another hash
  652. *
  653. * If 'sha1' is selected as type, the salt must be provided to the salt
  654. * argument. This too base64 encoded.
  655. *
  656. * The SHA-1 hash is what OpenSSH can be told to use in known_hosts files. If
  657. * a custom type is used, salt is ignored and you must provide the host
  658. * pre-hashed when checking for it in the libssh2_knownhost_check() function.
  659. *
  660. * The keylen parameter may be omitted (zero) if the key is provided as a
  661. * NULL-terminated base64-encoded string.
  662. */
  663. /* host format (2 bits) */
  664. #define LIBSSH2_KNOWNHOST_TYPE_MASK 0xffff
  665. #define LIBSSH2_KNOWNHOST_TYPE_PLAIN 1
  666. #define LIBSSH2_KNOWNHOST_TYPE_SHA1 2 /* always base64 encoded */
  667. #define LIBSSH2_KNOWNHOST_TYPE_CUSTOM 3
  668. /* key format (2 bits) */
  669. #define LIBSSH2_KNOWNHOST_KEYENC_MASK (3<<16)
  670. #define LIBSSH2_KNOWNHOST_KEYENC_RAW (1<<16)
  671. #define LIBSSH2_KNOWNHOST_KEYENC_BASE64 (2<<16)
  672. /* type of key (2 bits) */
  673. #define LIBSSH2_KNOWNHOST_KEY_MASK (3<<18)
  674. #define LIBSSH2_KNOWNHOST_KEY_SHIFT 18
  675. #define LIBSSH2_KNOWNHOST_KEY_RSA1 (1<<18)
  676. #define LIBSSH2_KNOWNHOST_KEY_SSHRSA (2<<18)
  677. #define LIBSSH2_KNOWNHOST_KEY_SSHDSS (3<<18)
  678. LIBSSH2_API int
  679. libssh2_knownhost_add(LIBSSH2_KNOWNHOSTS *hosts,
  680. const char *host,
  681. const char *salt,
  682. const char *key, size_t keylen, int typemask,
  683. struct libssh2_knownhost **store);
  684. /*
  685. * libssh2_knownhost_addc
  686. *
  687. * Add a host and its associated key to the collection of known hosts.
  688. *
  689. * Takes a comment argument that may be NULL. A NULL comment indicates
  690. * there is no comment and the entry will end directly after the key
  691. * when written out to a file. An empty string "" comment will indicate an
  692. * empty comment which will cause a single space to be written after the key.
  693. *
  694. * The 'type' argument specifies on what format the given host and keys are:
  695. *
  696. * plain - ascii "hostname.domain.tld"
  697. * sha1 - SHA1(<salt> <host>) base64-encoded!
  698. * custom - another hash
  699. *
  700. * If 'sha1' is selected as type, the salt must be provided to the salt
  701. * argument. This too base64 encoded.
  702. *
  703. * The SHA-1 hash is what OpenSSH can be told to use in known_hosts files. If
  704. * a custom type is used, salt is ignored and you must provide the host
  705. * pre-hashed when checking for it in the libssh2_knownhost_check() function.
  706. *
  707. * The keylen parameter may be omitted (zero) if the key is provided as a
  708. * NULL-terminated base64-encoded string.
  709. */
  710. LIBSSH2_API int
  711. libssh2_knownhost_addc(LIBSSH2_KNOWNHOSTS *hosts,
  712. const char *host,
  713. const char *salt,
  714. const char *key, size_t keylen,
  715. const char *comment, size_t commentlen, int typemask,
  716. struct libssh2_knownhost **store);
  717. /*
  718. * libssh2_knownhost_check
  719. *
  720. * Check a host and its associated key against the collection of known hosts.
  721. *
  722. * The type is the type/format of the given host name.
  723. *
  724. * plain - ascii "hostname.domain.tld"
  725. * custom - prehashed base64 encoded. Note that this cannot use any salts.
  726. *
  727. *
  728. * 'knownhost' may be set to NULL if you don't care about that info.
  729. *
  730. * Returns:
  731. *
  732. * LIBSSH2_KNOWNHOST_CHECK_* values, see below
  733. *
  734. */
  735. #define LIBSSH2_KNOWNHOST_CHECK_MATCH 0
  736. #define LIBSSH2_KNOWNHOST_CHECK_MISMATCH 1
  737. #define LIBSSH2_KNOWNHOST_CHECK_NOTFOUND 2
  738. #define LIBSSH2_KNOWNHOST_CHECK_FAILURE 3
  739. LIBSSH2_API int
  740. libssh2_knownhost_check(LIBSSH2_KNOWNHOSTS *hosts,
  741. const char *host, const char *key, size_t keylen,
  742. int typemask,
  743. struct libssh2_knownhost **knownhost);
  744. /* this function is identital to the above one, but also takes a port
  745. argument that allows libssh2 to do a better check */
  746. LIBSSH2_API int
  747. libssh2_knownhost_checkp(LIBSSH2_KNOWNHOSTS *hosts,
  748. const char *host, int port,
  749. const char *key, size_t keylen,
  750. int typemask,
  751. struct libssh2_knownhost **knownhost);
  752. /*
  753. * libssh2_knownhost_del
  754. *
  755. * Remove a host from the collection of known hosts. The 'entry' struct is
  756. * retrieved by a call to libssh2_knownhost_check().
  757. *
  758. */
  759. LIBSSH2_API int
  760. libssh2_knownhost_del(LIBSSH2_KNOWNHOSTS *hosts,
  761. struct libssh2_knownhost *entry);
  762. /*
  763. * libssh2_knownhost_free
  764. *
  765. * Free an entire collection of known hosts.
  766. *
  767. */
  768. LIBSSH2_API void
  769. libssh2_knownhost_free(LIBSSH2_KNOWNHOSTS *hosts);
  770. /*
  771. * libssh2_knownhost_readline()
  772. *
  773. * Pass in a line of a file of 'type'. It makes libssh2 read this line.
  774. *
  775. * LIBSSH2_KNOWNHOST_FILE_OPENSSH is the only supported type.
  776. *
  777. */
  778. LIBSSH2_API int
  779. libssh2_knownhost_readline(LIBSSH2_KNOWNHOSTS *hosts,
  780. const char *line, size_t len, int type);
  781. /*
  782. * libssh2_knownhost_readfile
  783. *
  784. * Add hosts+key pairs from a given file.
  785. *
  786. * Returns a negative value for error or number of successfully added hosts.
  787. *
  788. * This implementation currently only knows one 'type' (openssh), all others
  789. * are reserved for future use.
  790. */
  791. #define LIBSSH2_KNOWNHOST_FILE_OPENSSH 1
  792. LIBSSH2_API int
  793. libssh2_knownhost_readfile(LIBSSH2_KNOWNHOSTS *hosts,
  794. const char *filename, int type);
  795. /*
  796. * libssh2_knownhost_writeline()
  797. *
  798. * Ask libssh2 to convert a known host to an output line for storage.
  799. *
  800. * Note that this function returns LIBSSH2_ERROR_BUFFER_TOO_SMALL if the given
  801. * output buffer is too small to hold the desired output.
  802. *
  803. * This implementation currently only knows one 'type' (openssh), all others
  804. * are reserved for future use.
  805. *
  806. */
  807. LIBSSH2_API int
  808. libssh2_knownhost_writeline(LIBSSH2_KNOWNHOSTS *hosts,
  809. struct libssh2_knownhost *known,
  810. char *buffer, size_t buflen,
  811. size_t *outlen, /* the amount of written data */
  812. int type);
  813. /*
  814. * libssh2_knownhost_writefile
  815. *
  816. * Write hosts+key pairs to a given file.
  817. *
  818. * This implementation currently only knows one 'type' (openssh), all others
  819. * are reserved for future use.
  820. */
  821. LIBSSH2_API int
  822. libssh2_knownhost_writefile(LIBSSH2_KNOWNHOSTS *hosts,
  823. const char *filename, int type);
  824. /*
  825. * libssh2_knownhost_get()
  826. *
  827. * Traverse the internal list of known hosts. Pass NULL to 'prev' to get
  828. * the first one. Or pass a poiner to the previously returned one to get the
  829. * next.
  830. *
  831. * Returns:
  832. * 0 if a fine host was stored in 'store'
  833. * 1 if end of hosts
  834. * [negative] on errors
  835. */
  836. LIBSSH2_API int
  837. libssh2_knownhost_get(LIBSSH2_KNOWNHOSTS *hosts,
  838. struct libssh2_knownhost **store,
  839. struct libssh2_knownhost *prev);
  840. #define HAVE_LIBSSH2_AGENT_API 0x010202 /* since 1.2.2 */
  841. struct libssh2_agent_publickey {
  842. unsigned int magic; /* magic stored by the library */
  843. void *node; /* handle to the internal representation of key */
  844. unsigned char *blob; /* public key blob */
  845. size_t blob_len; /* length of the public key blob */
  846. char *comment; /* comment in printable format */
  847. };
  848. /*
  849. * libssh2_agent_init
  850. *
  851. * Init an ssh-agent handle. Returns the pointer to the handle.
  852. *
  853. */
  854. LIBSSH2_API LIBSSH2_AGENT *
  855. libssh2_agent_init(LIBSSH2_SESSION *session);
  856. /*
  857. * libssh2_agent_connect()
  858. *
  859. * Connect to an ssh-agent.
  860. *
  861. * Returns 0 if succeeded, or a negative value for error.
  862. */
  863. LIBSSH2_API int
  864. libssh2_agent_connect(LIBSSH2_AGENT *agent);
  865. /*
  866. * libssh2_agent_list_identities()
  867. *
  868. * Request an ssh-agent to list identities.
  869. *
  870. * Returns 0 if succeeded, or a negative value for error.
  871. */
  872. LIBSSH2_API int
  873. libssh2_agent_list_identities(LIBSSH2_AGENT *agent);
  874. /*
  875. * libssh2_agent_get_identity()
  876. *
  877. * Traverse the internal list of public keys. Pass NULL to 'prev' to get
  878. * the first one. Or pass a poiner to the previously returned one to get the
  879. * next.
  880. *
  881. * Returns:
  882. * 0 if a fine public key was stored in 'store'
  883. * 1 if end of public keys
  884. * [negative] on errors
  885. */
  886. LIBSSH2_API int
  887. libssh2_agent_get_identity(LIBSSH2_AGENT *agent,
  888. struct libssh2_agent_publickey **store,
  889. struct libssh2_agent_publickey *prev);
  890. /*
  891. * libssh2_agent_userauth()
  892. *
  893. * Do publickey user authentication with the help of ssh-agent.
  894. *
  895. * Returns 0 if succeeded, or a negative value for error.
  896. */
  897. LIBSSH2_API int
  898. libssh2_agent_userauth(LIBSSH2_AGENT *agent,
  899. const char *username,
  900. struct libssh2_agent_publickey *identity);
  901. /*
  902. * libssh2_agent_disconnect()
  903. *
  904. * Close a connection to an ssh-agent.
  905. *
  906. * Returns 0 if succeeded, or a negative value for error.
  907. */
  908. LIBSSH2_API int
  909. libssh2_agent_disconnect(LIBSSH2_AGENT *agent);
  910. /*
  911. * libssh2_agent_free()
  912. *
  913. * Free an ssh-agent handle. This function also frees the internal
  914. * collection of public keys.
  915. */
  916. LIBSSH2_API void
  917. libssh2_agent_free(LIBSSH2_AGENT *agent);
  918. /*
  919. * libssh2_keepalive_config()
  920. *
  921. * Set how often keepalive messages should be sent. WANT_REPLY
  922. * indicates whether the keepalive messages should request a response
  923. * from the server. INTERVAL is number of seconds that can pass
  924. * without any I/O, use 0 (the default) to disable keepalives. To
  925. * avoid some busy-loop corner-cases, if you specify an interval of 1
  926. * it will be treated as 2.
  927. *
  928. * Note that non-blocking applications are responsible for sending the
  929. * keepalive messages using libssh2_keepalive_send().
  930. */
  931. LIBSSH2_API void libssh2_keepalive_config (LIBSSH2_SESSION *session,
  932. int want_reply,
  933. unsigned interval);
  934. /*
  935. * libssh2_keepalive_send()
  936. *
  937. * Send a keepalive message if needed. SECONDS_TO_NEXT indicates how
  938. * many seconds you can sleep after this call before you need to call
  939. * it again. Returns 0 on success, or LIBSSH2_ERROR_SOCKET_SEND on
  940. * I/O errors.
  941. */
  942. LIBSSH2_API int libssh2_keepalive_send (LIBSSH2_SESSION *session,
  943. int *seconds_to_next);
  944. /* NOTE NOTE NOTE
  945. libssh2_trace() has no function in builds that aren't built with debug
  946. enabled
  947. */
  948. LIBSSH2_API int libssh2_trace(LIBSSH2_SESSION *session, int bitmask);
  949. #define LIBSSH2_TRACE_TRANS (1<<1)
  950. #define LIBSSH2_TRACE_KEX (1<<2)
  951. #define LIBSSH2_TRACE_AUTH (1<<3)
  952. #define LIBSSH2_TRACE_CONN (1<<4)
  953. #define LIBSSH2_TRACE_SCP (1<<5)
  954. #define LIBSSH2_TRACE_SFTP (1<<6)
  955. #define LIBSSH2_TRACE_ERROR (1<<7)
  956. #define LIBSSH2_TRACE_PUBLICKEY (1<<8)
  957. #define LIBSSH2_TRACE_SOCKET (1<<9)
  958. typedef void (*libssh2_trace_handler_func)(LIBSSH2_SESSION*,
  959. void*,
  960. const char *,
  961. size_t);
  962. LIBSSH2_API int libssh2_trace_sethandler(LIBSSH2_SESSION *session,
  963. void* context,
  964. libssh2_trace_handler_func callback);
  965. #ifdef __cplusplus
  966. } /* extern "C" */
  967. #endif
  968. #endif /* LIBSSH2_VERSION_ONLY */
  969. #endif /* LIBSSH2_H */