libssh 0.8.5 The SSH library

libssh.h
1 /*
2 * This file is part of the SSH Library
3 *
4 * Copyright (c) 2003-2009 by Aris Adamantiadis
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #ifndef _LIBSSH_H
22 #define _LIBSSH_H
23
24 #if defined _WIN32 || defined __CYGWIN__
25 #ifdef LIBSSH_STATIC
26 #define LIBSSH_API
27 #else
28 #ifdef LIBSSH_EXPORTS
29 #ifdef __GNUC__
30 #define LIBSSH_API __attribute__((dllexport))
31 #else
32 #define LIBSSH_API __declspec(dllexport)
33 #endif
34 #else
35 #ifdef __GNUC__
36 #define LIBSSH_API __attribute__((dllimport))
37 #else
38 #define LIBSSH_API __declspec(dllimport)
39 #endif
40 #endif
41 #endif
42 #else
43 #if __GNUC__ >= 4 && !defined(__OS2__)
44 #define LIBSSH_API __attribute__((visibility("default")))
45 #else
46 #define LIBSSH_API
47 #endif
48 #endif
49
50 #ifdef _MSC_VER
51 /* Visual Studio hasn't inttypes.h so it doesn't know uint32_t */
52 typedef int int32_t;
53 typedef unsigned int uint32_t;
54 typedef unsigned short uint16_t;
55 typedef unsigned char uint8_t;
56 typedef unsigned long long uint64_t;
57 typedef int mode_t;
58 #else /* _MSC_VER */
59 #include <unistd.h>
60 #include <inttypes.h>
61 #include <sys/types.h>
62 #endif /* _MSC_VER */
63
64 #ifdef _WIN32
65 #include <winsock2.h>
66 #else /* _WIN32 */
67 #include <sys/select.h> /* for fd_set * */
68 #include <netdb.h>
69 #endif /* _WIN32 */
70
71 #define SSH_STRINGIFY(s) SSH_TOSTRING(s)
72 #define SSH_TOSTRING(s) #s
73
74 /* libssh version macros */
75 #define SSH_VERSION_INT(a, b, c) ((a) << 16 | (b) << 8 | (c))
76 #define SSH_VERSION_DOT(a, b, c) a ##.## b ##.## c
77 #define SSH_VERSION(a, b, c) SSH_VERSION_DOT(a, b, c)
78
79 /* libssh version */
80 #define LIBSSH_VERSION_MAJOR 0
81 #define LIBSSH_VERSION_MINOR 8
82 #define LIBSSH_VERSION_MICRO 5
83
84 #define LIBSSH_VERSION_INT SSH_VERSION_INT(LIBSSH_VERSION_MAJOR, \
85 LIBSSH_VERSION_MINOR, \
86 LIBSSH_VERSION_MICRO)
87 #define LIBSSH_VERSION SSH_VERSION(LIBSSH_VERSION_MAJOR, \
88 LIBSSH_VERSION_MINOR, \
89 LIBSSH_VERSION_MICRO)
90
91 /* GCC have printf type attribute check. */
92 #ifdef __GNUC__
93 #define PRINTF_ATTRIBUTE(a,b) __attribute__ ((__format__ (__printf__, a, b)))
94 #else
95 #define PRINTF_ATTRIBUTE(a,b)
96 #endif /* __GNUC__ */
97
98 #ifdef __GNUC__
99 #define SSH_DEPRECATED __attribute__ ((deprecated))
100 #else
101 #define SSH_DEPRECATED
102 #endif
103
104 #ifdef __cplusplus
105 extern "C" {
106 #endif
107
108 struct ssh_counter_struct {
109 uint64_t in_bytes;
110 uint64_t out_bytes;
111 uint64_t in_packets;
112 uint64_t out_packets;
113 };
114 typedef struct ssh_counter_struct *ssh_counter;
115
116 typedef struct ssh_agent_struct* ssh_agent;
117 typedef struct ssh_buffer_struct* ssh_buffer;
118 typedef struct ssh_channel_struct* ssh_channel;
119 typedef struct ssh_message_struct* ssh_message;
120 typedef struct ssh_pcap_file_struct* ssh_pcap_file;
121 typedef struct ssh_key_struct* ssh_key;
122 typedef struct ssh_scp_struct* ssh_scp;
123 typedef struct ssh_session_struct* ssh_session;
124 typedef struct ssh_string_struct* ssh_string;
125 typedef struct ssh_event_struct* ssh_event;
126 typedef struct ssh_connector_struct * ssh_connector;
127 typedef void* ssh_gssapi_creds;
128
129 /* Socket type */
130 #ifdef _WIN32
131 #ifndef socket_t
132 typedef SOCKET socket_t;
133 #endif /* socket_t */
134 #else /* _WIN32 */
135 #ifndef socket_t
136 typedef int socket_t;
137 #endif
138 #endif /* _WIN32 */
139
140 #define SSH_INVALID_SOCKET ((socket_t) -1)
141
142 /* the offsets of methods */
143 enum ssh_kex_types_e {
144 SSH_KEX=0,
145 SSH_HOSTKEYS,
146 SSH_CRYPT_C_S,
147 SSH_CRYPT_S_C,
148 SSH_MAC_C_S,
149 SSH_MAC_S_C,
150 SSH_COMP_C_S,
151 SSH_COMP_S_C,
152 SSH_LANG_C_S,
153 SSH_LANG_S_C
154 };
155
156 #define SSH_CRYPT 2
157 #define SSH_MAC 3
158 #define SSH_COMP 4
159 #define SSH_LANG 5
160
161 enum ssh_auth_e {
162 SSH_AUTH_SUCCESS=0,
163 SSH_AUTH_DENIED,
164 SSH_AUTH_PARTIAL,
165 SSH_AUTH_INFO,
166 SSH_AUTH_AGAIN,
167 SSH_AUTH_ERROR=-1
168 };
169
170 /* auth flags */
171 #define SSH_AUTH_METHOD_UNKNOWN 0
172 #define SSH_AUTH_METHOD_NONE 0x0001
173 #define SSH_AUTH_METHOD_PASSWORD 0x0002
174 #define SSH_AUTH_METHOD_PUBLICKEY 0x0004
175 #define SSH_AUTH_METHOD_HOSTBASED 0x0008
176 #define SSH_AUTH_METHOD_INTERACTIVE 0x0010
177 #define SSH_AUTH_METHOD_GSSAPI_MIC 0x0020
178
179 /* messages */
180 enum ssh_requests_e {
181 SSH_REQUEST_AUTH=1,
182 SSH_REQUEST_CHANNEL_OPEN,
183 SSH_REQUEST_CHANNEL,
184 SSH_REQUEST_SERVICE,
185 SSH_REQUEST_GLOBAL
186 };
187
188 enum ssh_channel_type_e {
189 SSH_CHANNEL_UNKNOWN=0,
190 SSH_CHANNEL_SESSION,
191 SSH_CHANNEL_DIRECT_TCPIP,
192 SSH_CHANNEL_FORWARDED_TCPIP,
193 SSH_CHANNEL_X11,
194 SSH_CHANNEL_AUTH_AGENT
195 };
196
197 enum ssh_channel_requests_e {
198 SSH_CHANNEL_REQUEST_UNKNOWN=0,
199 SSH_CHANNEL_REQUEST_PTY,
200 SSH_CHANNEL_REQUEST_EXEC,
201 SSH_CHANNEL_REQUEST_SHELL,
202 SSH_CHANNEL_REQUEST_ENV,
203 SSH_CHANNEL_REQUEST_SUBSYSTEM,
204 SSH_CHANNEL_REQUEST_WINDOW_CHANGE,
205 SSH_CHANNEL_REQUEST_X11
206 };
207
208 enum ssh_global_requests_e {
209 SSH_GLOBAL_REQUEST_UNKNOWN=0,
210 SSH_GLOBAL_REQUEST_TCPIP_FORWARD,
211 SSH_GLOBAL_REQUEST_CANCEL_TCPIP_FORWARD,
212 SSH_GLOBAL_REQUEST_KEEPALIVE
213 };
214
215 enum ssh_publickey_state_e {
216 SSH_PUBLICKEY_STATE_ERROR=-1,
217 SSH_PUBLICKEY_STATE_NONE=0,
218 SSH_PUBLICKEY_STATE_VALID=1,
219 SSH_PUBLICKEY_STATE_WRONG=2
220 };
221
222 /* Status flags */
224 #define SSH_CLOSED 0x01
225
226 #define SSH_READ_PENDING 0x02
227
228 #define SSH_CLOSED_ERROR 0x04
229
230 #define SSH_WRITE_PENDING 0x08
231
232 enum ssh_server_known_e {
233 SSH_SERVER_ERROR=-1,
234 SSH_SERVER_NOT_KNOWN=0,
235 SSH_SERVER_KNOWN_OK,
236 SSH_SERVER_KNOWN_CHANGED,
237 SSH_SERVER_FOUND_OTHER,
238 SSH_SERVER_FILE_NOT_FOUND
239 };
240
241 enum ssh_known_hosts_e {
245 SSH_KNOWN_HOSTS_ERROR = -2,
246
251 SSH_KNOWN_HOSTS_NOT_FOUND = -1,
252
257 SSH_KNOWN_HOSTS_UNKNOWN = 0,
258
262 SSH_KNOWN_HOSTS_OK,
263
269 SSH_KNOWN_HOSTS_CHANGED,
270
275 SSH_KNOWN_HOSTS_OTHER,
276 };
277
278 #ifndef MD5_DIGEST_LEN
279 #define MD5_DIGEST_LEN 16
280 #endif
281 /* errors */
282
283 enum ssh_error_types_e {
284 SSH_NO_ERROR=0,
285 SSH_REQUEST_DENIED,
286 SSH_FATAL,
287 SSH_EINTR
288 };
289
290 /* some types for keys */
291 enum ssh_keytypes_e{
292 SSH_KEYTYPE_UNKNOWN=0,
293 SSH_KEYTYPE_DSS=1,
294 SSH_KEYTYPE_RSA,
295 SSH_KEYTYPE_RSA1,
296 SSH_KEYTYPE_ECDSA,
297 SSH_KEYTYPE_ED25519,
298 SSH_KEYTYPE_DSS_CERT01,
299 SSH_KEYTYPE_RSA_CERT01
300 };
301
302 enum ssh_keycmp_e {
303 SSH_KEY_CMP_PUBLIC = 0,
304 SSH_KEY_CMP_PRIVATE
305 };
306
307 #define SSH_ADDRSTRLEN 46
308
309 struct ssh_knownhosts_entry {
310 char *hostname;
311 char *unparsed;
312 ssh_key publickey;
313 char *comment;
314 };
315
316
317 /* Error return codes */
318 #define SSH_OK 0 /* No error */
319 #define SSH_ERROR -1 /* Error of some kind */
320 #define SSH_AGAIN -2 /* The nonblocking call must be repeated */
321 #define SSH_EOF -127 /* We have already a eof */
322
329 enum {
332 SSH_LOG_NOLOG=0,
335 SSH_LOG_WARNING,
338 SSH_LOG_PROTOCOL,
341 SSH_LOG_PACKET,
344 SSH_LOG_FUNCTIONS
345 };
347 #define SSH_LOG_RARE SSH_LOG_WARNING
348
357 #define SSH_LOG_NONE 0
358
359 #define SSH_LOG_WARN 1
360
361 #define SSH_LOG_INFO 2
362
363 #define SSH_LOG_DEBUG 3
364
365 #define SSH_LOG_TRACE 4
366
369 enum ssh_options_e {
370 SSH_OPTIONS_HOST,
371 SSH_OPTIONS_PORT,
372 SSH_OPTIONS_PORT_STR,
373 SSH_OPTIONS_FD,
374 SSH_OPTIONS_USER,
375 SSH_OPTIONS_SSH_DIR,
376 SSH_OPTIONS_IDENTITY,
377 SSH_OPTIONS_ADD_IDENTITY,
378 SSH_OPTIONS_KNOWNHOSTS,
379 SSH_OPTIONS_TIMEOUT,
380 SSH_OPTIONS_TIMEOUT_USEC,
381 SSH_OPTIONS_SSH1,
382 SSH_OPTIONS_SSH2,
383 SSH_OPTIONS_LOG_VERBOSITY,
384 SSH_OPTIONS_LOG_VERBOSITY_STR,
385 SSH_OPTIONS_CIPHERS_C_S,
386 SSH_OPTIONS_CIPHERS_S_C,
387 SSH_OPTIONS_COMPRESSION_C_S,
388 SSH_OPTIONS_COMPRESSION_S_C,
389 SSH_OPTIONS_PROXYCOMMAND,
390 SSH_OPTIONS_BINDADDR,
391 SSH_OPTIONS_STRICTHOSTKEYCHECK,
392 SSH_OPTIONS_COMPRESSION,
393 SSH_OPTIONS_COMPRESSION_LEVEL,
394 SSH_OPTIONS_KEY_EXCHANGE,
395 SSH_OPTIONS_HOSTKEYS,
396 SSH_OPTIONS_GSSAPI_SERVER_IDENTITY,
397 SSH_OPTIONS_GSSAPI_CLIENT_IDENTITY,
398 SSH_OPTIONS_GSSAPI_DELEGATE_CREDENTIALS,
399 SSH_OPTIONS_HMAC_C_S,
400 SSH_OPTIONS_HMAC_S_C,
401 SSH_OPTIONS_PASSWORD_AUTH,
402 SSH_OPTIONS_PUBKEY_AUTH,
403 SSH_OPTIONS_KBDINT_AUTH,
404 SSH_OPTIONS_GSSAPI_AUTH,
405 SSH_OPTIONS_GLOBAL_KNOWNHOSTS,
406 SSH_OPTIONS_NODELAY,
407 SSH_OPTIONS_PUBLICKEY_ACCEPTED_TYPES,
408 };
409
410 enum {
412 SSH_SCP_WRITE,
414 SSH_SCP_READ,
415 SSH_SCP_RECURSIVE=0x10
416 };
417
418 enum ssh_scp_request_types {
420 SSH_SCP_REQUEST_NEWDIR=1,
422 SSH_SCP_REQUEST_NEWFILE,
424 SSH_SCP_REQUEST_EOF,
426 SSH_SCP_REQUEST_ENDDIR,
428 SSH_SCP_REQUEST_WARNING
429 };
430
431 enum ssh_connector_flags_e {
433 SSH_CONNECTOR_STDOUT = 1,
435 SSH_CONNECTOR_STDERR = 2,
437 SSH_CONNECTOR_BOTH = 3
438 };
439
440 LIBSSH_API int ssh_blocking_flush(ssh_session session, int timeout);
441 LIBSSH_API ssh_channel ssh_channel_accept_x11(ssh_channel channel, int timeout_ms);
442 LIBSSH_API int ssh_channel_change_pty_size(ssh_channel channel,int cols,int rows);
443 LIBSSH_API int ssh_channel_close(ssh_channel channel);
444 LIBSSH_API void ssh_channel_free(ssh_channel channel);
445 LIBSSH_API int ssh_channel_get_exit_status(ssh_channel channel);
446 LIBSSH_API ssh_session ssh_channel_get_session(ssh_channel channel);
447 LIBSSH_API int ssh_channel_is_closed(ssh_channel channel);
448 LIBSSH_API int ssh_channel_is_eof(ssh_channel channel);
449 LIBSSH_API int ssh_channel_is_open(ssh_channel channel);
450 LIBSSH_API ssh_channel ssh_channel_new(ssh_session session);
451 LIBSSH_API int ssh_channel_open_auth_agent(ssh_channel channel);
452 LIBSSH_API int ssh_channel_open_forward(ssh_channel channel, const char *remotehost,
453 int remoteport, const char *sourcehost, int localport);
454 LIBSSH_API int ssh_channel_open_session(ssh_channel channel);
455 LIBSSH_API int ssh_channel_open_x11(ssh_channel channel, const char *orig_addr, int orig_port);
456 LIBSSH_API int ssh_channel_poll(ssh_channel channel, int is_stderr);
457 LIBSSH_API int ssh_channel_poll_timeout(ssh_channel channel, int timeout, int is_stderr);
458 LIBSSH_API int ssh_channel_read(ssh_channel channel, void *dest, uint32_t count, int is_stderr);
459 LIBSSH_API int ssh_channel_read_timeout(ssh_channel channel, void *dest, uint32_t count, int is_stderr, int timeout_ms);
460 LIBSSH_API int ssh_channel_read_nonblocking(ssh_channel channel, void *dest, uint32_t count,
461 int is_stderr);
462 LIBSSH_API int ssh_channel_request_env(ssh_channel channel, const char *name, const char *value);
463 LIBSSH_API int ssh_channel_request_exec(ssh_channel channel, const char *cmd);
464 LIBSSH_API int ssh_channel_request_pty(ssh_channel channel);
465 LIBSSH_API int ssh_channel_request_pty_size(ssh_channel channel, const char *term,
466 int cols, int rows);
467 LIBSSH_API int ssh_channel_request_shell(ssh_channel channel);
468 LIBSSH_API int ssh_channel_request_send_signal(ssh_channel channel, const char *signum);
469 LIBSSH_API int ssh_channel_request_send_break(ssh_channel channel, uint32_t length);
470 LIBSSH_API int ssh_channel_request_sftp(ssh_channel channel);
471 LIBSSH_API int ssh_channel_request_subsystem(ssh_channel channel, const char *subsystem);
472 LIBSSH_API int ssh_channel_request_x11(ssh_channel channel, int single_connection, const char *protocol,
473 const char *cookie, int screen_number);
474 LIBSSH_API int ssh_channel_request_auth_agent(ssh_channel channel);
475 LIBSSH_API int ssh_channel_send_eof(ssh_channel channel);
476 LIBSSH_API int ssh_channel_select(ssh_channel *readchans, ssh_channel *writechans, ssh_channel *exceptchans, struct
477 timeval * timeout);
478 LIBSSH_API void ssh_channel_set_blocking(ssh_channel channel, int blocking);
479 LIBSSH_API void ssh_channel_set_counter(ssh_channel channel,
480 ssh_counter counter);
481 LIBSSH_API int ssh_channel_write(ssh_channel channel, const void *data, uint32_t len);
482 LIBSSH_API int ssh_channel_write_stderr(ssh_channel channel,
483 const void *data,
484 uint32_t len);
485 LIBSSH_API uint32_t ssh_channel_window_size(ssh_channel channel);
486
487 LIBSSH_API char *ssh_basename (const char *path);
488 LIBSSH_API void ssh_clean_pubkey_hash(unsigned char **hash);
489 LIBSSH_API int ssh_connect(ssh_session session);
490
491 LIBSSH_API ssh_connector ssh_connector_new(ssh_session session);
492 LIBSSH_API void ssh_connector_free(ssh_connector connector);
493 LIBSSH_API int ssh_connector_set_in_channel(ssh_connector connector,
494 ssh_channel channel,
495 enum ssh_connector_flags_e flags);
496 LIBSSH_API int ssh_connector_set_out_channel(ssh_connector connector,
497 ssh_channel channel,
498 enum ssh_connector_flags_e flags);
499 LIBSSH_API void ssh_connector_set_in_fd(ssh_connector connector, socket_t fd);
500 LIBSSH_API void ssh_connector_set_out_fd(ssh_connector connector, socket_t fd);
501
502 LIBSSH_API const char *ssh_copyright(void);
503 LIBSSH_API void ssh_disconnect(ssh_session session);
504 LIBSSH_API char *ssh_dirname (const char *path);
505 LIBSSH_API int ssh_finalize(void);
506
507 /* REVERSE PORT FORWARDING */
508 LIBSSH_API ssh_channel ssh_channel_accept_forward(ssh_session session,
509 int timeout_ms,
510 int *destination_port);
511 LIBSSH_API int ssh_channel_cancel_forward(ssh_session session,
512 const char *address,
513 int port);
514 LIBSSH_API int ssh_channel_listen_forward(ssh_session session,
515 const char *address,
516 int port,
517 int *bound_port);
518
519 LIBSSH_API void ssh_free(ssh_session session);
520 LIBSSH_API const char *ssh_get_disconnect_message(ssh_session session);
521 LIBSSH_API const char *ssh_get_error(void *error);
522 LIBSSH_API int ssh_get_error_code(void *error);
523 LIBSSH_API socket_t ssh_get_fd(ssh_session session);
524 LIBSSH_API char *ssh_get_hexa(const unsigned char *what, size_t len);
525 LIBSSH_API char *ssh_get_issue_banner(ssh_session session);
526 LIBSSH_API int ssh_get_openssh_version(ssh_session session);
527
528 LIBSSH_API int ssh_get_server_publickey(ssh_session session, ssh_key *key);
529
530 enum ssh_publickey_hash_type {
531 SSH_PUBLICKEY_HASH_SHA1,
532 SSH_PUBLICKEY_HASH_MD5,
533 SSH_PUBLICKEY_HASH_SHA256
534 };
535 LIBSSH_API int ssh_get_publickey_hash(const ssh_key key,
536 enum ssh_publickey_hash_type type,
537 unsigned char **hash,
538 size_t *hlen);
539
540 /* DEPRECATED FUNCTIONS */
541 SSH_DEPRECATED LIBSSH_API int ssh_get_pubkey_hash(ssh_session session, unsigned char **hash);
542 SSH_DEPRECATED LIBSSH_API ssh_channel ssh_forward_accept(ssh_session session, int timeout_ms);
543 SSH_DEPRECATED LIBSSH_API int ssh_forward_cancel(ssh_session session, const char *address, int port);
544 SSH_DEPRECATED LIBSSH_API int ssh_forward_listen(ssh_session session, const char *address, int port, int *bound_port);
545 SSH_DEPRECATED LIBSSH_API int ssh_get_publickey(ssh_session session, ssh_key *key);
546
547
548 LIBSSH_API int ssh_get_random(void *where,int len,int strong);
549 LIBSSH_API int ssh_get_version(ssh_session session);
550 LIBSSH_API int ssh_get_status(ssh_session session);
551 LIBSSH_API int ssh_get_poll_flags(ssh_session session);
552 LIBSSH_API int ssh_init(void);
553 LIBSSH_API int ssh_is_blocking(ssh_session session);
554 LIBSSH_API int ssh_is_connected(ssh_session session);
555 LIBSSH_API int ssh_is_server_known(ssh_session session);
556
557 /* KNOWN HOSTS */
558 LIBSSH_API void ssh_knownhosts_entry_free(struct ssh_knownhosts_entry *entry);
559 #define SSH_KNOWNHOSTS_ENTRY_FREE(e) do { \
560 if ((e) != NULL) { \
561 ssh_knownhosts_entry_free(e); \
562 e = NULL; \
563 } \
564 } while(0)
565
566 LIBSSH_API int ssh_known_hosts_parse_line(const char *host,
567 const char *line,
568 struct ssh_knownhosts_entry **entry);
569 LIBSSH_API enum ssh_known_hosts_e ssh_session_has_known_hosts_entry(ssh_session session);
570
571 LIBSSH_API int ssh_session_export_known_hosts_entry(ssh_session session,
572 char **pentry_string);
573 LIBSSH_API int ssh_session_update_known_hosts(ssh_session session);
574
575 LIBSSH_API enum ssh_known_hosts_e
576 ssh_session_get_known_hosts_entry(ssh_session session,
577 struct ssh_knownhosts_entry **pentry);
578 LIBSSH_API enum ssh_known_hosts_e ssh_session_is_known_server(ssh_session session);
579
580 /* LOGGING */
581 LIBSSH_API int ssh_set_log_level(int level);
582 LIBSSH_API int ssh_get_log_level(void);
583 LIBSSH_API void *ssh_get_log_userdata(void);
584 LIBSSH_API int ssh_set_log_userdata(void *data);
585 LIBSSH_API void _ssh_log(int verbosity,
586 const char *function,
587 const char *format, ...) PRINTF_ATTRIBUTE(3, 4);
588
589 /* legacy */
590 SSH_DEPRECATED LIBSSH_API void ssh_log(ssh_session session,
591 int prioriry,
592 const char *format, ...) PRINTF_ATTRIBUTE(3, 4);
593
594 LIBSSH_API ssh_channel ssh_message_channel_request_open_reply_accept(ssh_message msg);
595 LIBSSH_API int ssh_message_channel_request_reply_success(ssh_message msg);
596 LIBSSH_API void ssh_message_free(ssh_message msg);
597 LIBSSH_API ssh_message ssh_message_get(ssh_session session);
598 LIBSSH_API int ssh_message_subtype(ssh_message msg);
599 LIBSSH_API int ssh_message_type(ssh_message msg);
600 LIBSSH_API int ssh_mkdir (const char *pathname, mode_t mode);
601 LIBSSH_API ssh_session ssh_new(void);
602
603 LIBSSH_API int ssh_options_copy(ssh_session src, ssh_session *dest);
604 LIBSSH_API int ssh_options_getopt(ssh_session session, int *argcptr, char **argv);
605 LIBSSH_API int ssh_options_parse_config(ssh_session session, const char *filename);
606 LIBSSH_API int ssh_options_set(ssh_session session, enum ssh_options_e type,
607 const void *value);
608 LIBSSH_API int ssh_options_get(ssh_session session, enum ssh_options_e type,
609 char **value);
610 LIBSSH_API int ssh_options_get_port(ssh_session session, unsigned int * port_target);
611 LIBSSH_API int ssh_pcap_file_close(ssh_pcap_file pcap);
612 LIBSSH_API void ssh_pcap_file_free(ssh_pcap_file pcap);
613 LIBSSH_API ssh_pcap_file ssh_pcap_file_new(void);
614 LIBSSH_API int ssh_pcap_file_open(ssh_pcap_file pcap, const char *filename);
615
629 typedef int (*ssh_auth_callback) (const char *prompt, char *buf, size_t len,
630 int echo, int verify, void *userdata);
631
632 LIBSSH_API ssh_key ssh_key_new(void);
633 #define SSH_KEY_FREE(x) \
634 do { if ((x) != NULL) { ssh_key_free(x); x = NULL; } } while(0)
635 LIBSSH_API void ssh_key_free (ssh_key key);
636 LIBSSH_API enum ssh_keytypes_e ssh_key_type(const ssh_key key);
637 LIBSSH_API const char *ssh_key_type_to_char(enum ssh_keytypes_e type);
638 LIBSSH_API enum ssh_keytypes_e ssh_key_type_from_name(const char *name);
639 LIBSSH_API int ssh_key_is_public(const ssh_key k);
640 LIBSSH_API int ssh_key_is_private(const ssh_key k);
641 LIBSSH_API int ssh_key_cmp(const ssh_key k1,
642 const ssh_key k2,
643 enum ssh_keycmp_e what);
644
645 LIBSSH_API int ssh_pki_generate(enum ssh_keytypes_e type, int parameter,
646 ssh_key *pkey);
647 LIBSSH_API int ssh_pki_import_privkey_base64(const char *b64_key,
648 const char *passphrase,
649 ssh_auth_callback auth_fn,
650 void *auth_data,
651 ssh_key *pkey);
652 LIBSSH_API int ssh_pki_export_privkey_base64(const ssh_key privkey,
653 const char *passphrase,
654 ssh_auth_callback auth_fn,
655 void *auth_data,
656 char **b64_key);
657 LIBSSH_API int ssh_pki_import_privkey_file(const char *filename,
658 const char *passphrase,
659 ssh_auth_callback auth_fn,
660 void *auth_data,
661 ssh_key *pkey);
662 LIBSSH_API int ssh_pki_export_privkey_file(const ssh_key privkey,
663 const char *passphrase,
664 ssh_auth_callback auth_fn,
665 void *auth_data,
666 const char *filename);
667
668 LIBSSH_API int ssh_pki_copy_cert_to_privkey(const ssh_key cert_key,
669 ssh_key privkey);
670
671 LIBSSH_API int ssh_pki_import_pubkey_base64(const char *b64_key,
672 enum ssh_keytypes_e type,
673 ssh_key *pkey);
674 LIBSSH_API int ssh_pki_import_pubkey_file(const char *filename,
675 ssh_key *pkey);
676
677 LIBSSH_API int ssh_pki_import_cert_base64(const char *b64_cert,
678 enum ssh_keytypes_e type,
679 ssh_key *pkey);
680 LIBSSH_API int ssh_pki_import_cert_file(const char *filename,
681 ssh_key *pkey);
682
683 LIBSSH_API int ssh_pki_export_privkey_to_pubkey(const ssh_key privkey,
684 ssh_key *pkey);
685 LIBSSH_API int ssh_pki_export_pubkey_base64(const ssh_key key,
686 char **b64_key);
687 LIBSSH_API int ssh_pki_export_pubkey_file(const ssh_key key,
688 const char *filename);
689
690 LIBSSH_API const char *ssh_pki_key_ecdsa_name(const ssh_key key);
691
692 LIBSSH_API char *ssh_get_fingerprint_hash(enum ssh_publickey_hash_type type,
693 unsigned char *hash,
694 size_t len);
695 LIBSSH_API void ssh_print_hash(enum ssh_publickey_hash_type type, unsigned char *hash, size_t len);
696 LIBSSH_API void ssh_print_hexa(const char *descr, const unsigned char *what, size_t len);
697 LIBSSH_API int ssh_send_ignore (ssh_session session, const char *data);
698 LIBSSH_API int ssh_send_debug (ssh_session session, const char *message, int always_display);
699 LIBSSH_API void ssh_gssapi_set_creds(ssh_session session, const ssh_gssapi_creds creds);
700 LIBSSH_API int ssh_scp_accept_request(ssh_scp scp);
701 LIBSSH_API int ssh_scp_close(ssh_scp scp);
702 LIBSSH_API int ssh_scp_deny_request(ssh_scp scp, const char *reason);
703 LIBSSH_API void ssh_scp_free(ssh_scp scp);
704 LIBSSH_API int ssh_scp_init(ssh_scp scp);
705 LIBSSH_API int ssh_scp_leave_directory(ssh_scp scp);
706 LIBSSH_API ssh_scp ssh_scp_new(ssh_session session, int mode, const char *location);
707 LIBSSH_API int ssh_scp_pull_request(ssh_scp scp);
708 LIBSSH_API int ssh_scp_push_directory(ssh_scp scp, const char *dirname, int mode);
709 LIBSSH_API int ssh_scp_push_file(ssh_scp scp, const char *filename, size_t size, int perms);
710 LIBSSH_API int ssh_scp_push_file64(ssh_scp scp, const char *filename, uint64_t size, int perms);
711 LIBSSH_API int ssh_scp_read(ssh_scp scp, void *buffer, size_t size);
712 LIBSSH_API const char *ssh_scp_request_get_filename(ssh_scp scp);
713 LIBSSH_API int ssh_scp_request_get_permissions(ssh_scp scp);
714 LIBSSH_API size_t ssh_scp_request_get_size(ssh_scp scp);
715 LIBSSH_API uint64_t ssh_scp_request_get_size64(ssh_scp scp);
716 LIBSSH_API const char *ssh_scp_request_get_warning(ssh_scp scp);
717 LIBSSH_API int ssh_scp_write(ssh_scp scp, const void *buffer, size_t len);
718 LIBSSH_API int ssh_select(ssh_channel *channels, ssh_channel *outchannels, socket_t maxfd,
719 fd_set *readfds, struct timeval *timeout);
720 LIBSSH_API int ssh_service_request(ssh_session session, const char *service);
721 LIBSSH_API int ssh_set_agent_channel(ssh_session session, ssh_channel channel);
722 LIBSSH_API int ssh_set_agent_socket(ssh_session session, socket_t fd);
723 LIBSSH_API void ssh_set_blocking(ssh_session session, int blocking);
724 LIBSSH_API void ssh_set_counters(ssh_session session, ssh_counter scounter,
725 ssh_counter rcounter);
726 LIBSSH_API void ssh_set_fd_except(ssh_session session);
727 LIBSSH_API void ssh_set_fd_toread(ssh_session session);
728 LIBSSH_API void ssh_set_fd_towrite(ssh_session session);
729 LIBSSH_API void ssh_silent_disconnect(ssh_session session);
730 LIBSSH_API int ssh_set_pcap_file(ssh_session session, ssh_pcap_file pcapfile);
731
732 /* USERAUTH */
733 LIBSSH_API int ssh_userauth_none(ssh_session session, const char *username);
734 LIBSSH_API int ssh_userauth_list(ssh_session session, const char *username);
735 LIBSSH_API int ssh_userauth_try_publickey(ssh_session session,
736 const char *username,
737 const ssh_key pubkey);
738 LIBSSH_API int ssh_userauth_publickey(ssh_session session,
739 const char *username,
740 const ssh_key privkey);
741 #ifndef _WIN32
742 LIBSSH_API int ssh_userauth_agent(ssh_session session,
743 const char *username);
744 #endif
745 LIBSSH_API int ssh_userauth_publickey_auto(ssh_session session,
746 const char *username,
747 const char *passphrase);
748 LIBSSH_API int ssh_userauth_password(ssh_session session,
749 const char *username,
750 const char *password);
751
752 LIBSSH_API int ssh_userauth_kbdint(ssh_session session, const char *user, const char *submethods);
753 LIBSSH_API const char *ssh_userauth_kbdint_getinstruction(ssh_session session);
754 LIBSSH_API const char *ssh_userauth_kbdint_getname(ssh_session session);
755 LIBSSH_API int ssh_userauth_kbdint_getnprompts(ssh_session session);
756 LIBSSH_API const char *ssh_userauth_kbdint_getprompt(ssh_session session, unsigned int i, char *echo);
757 LIBSSH_API int ssh_userauth_kbdint_getnanswers(ssh_session session);
758 LIBSSH_API const char *ssh_userauth_kbdint_getanswer(ssh_session session, unsigned int i);
759 LIBSSH_API int ssh_userauth_kbdint_setanswer(ssh_session session, unsigned int i,
760 const char *answer);
761 LIBSSH_API int ssh_userauth_gssapi(ssh_session session);
762 LIBSSH_API const char *ssh_version(int req_version);
763 LIBSSH_API int ssh_write_knownhost(ssh_session session);
764 LIBSSH_API char *ssh_dump_knownhost(ssh_session session);
765
766 LIBSSH_API void ssh_string_burn(ssh_string str);
767 LIBSSH_API ssh_string ssh_string_copy(ssh_string str);
768 LIBSSH_API void *ssh_string_data(ssh_string str);
769 LIBSSH_API int ssh_string_fill(ssh_string str, const void *data, size_t len);
770 #define SSH_STRING_FREE(x) \
771 do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
772 LIBSSH_API void ssh_string_free(ssh_string str);
773 LIBSSH_API ssh_string ssh_string_from_char(const char *what);
774 LIBSSH_API size_t ssh_string_len(ssh_string str);
775 LIBSSH_API ssh_string ssh_string_new(size_t size);
776 LIBSSH_API const char *ssh_string_get_char(ssh_string str);
777 LIBSSH_API char *ssh_string_to_char(ssh_string str);
778 #define SSH_STRING_FREE_CHAR(x) \
779 do { if ((x) != NULL) { ssh_string_free_char(x); x = NULL; } } while(0)
780 LIBSSH_API void ssh_string_free_char(char *s);
781
782 LIBSSH_API int ssh_getpass(const char *prompt, char *buf, size_t len, int echo,
783 int verify);
784
785
786 typedef int (*ssh_event_callback)(socket_t fd, int revents, void *userdata);
787
788 LIBSSH_API ssh_event ssh_event_new(void);
789 LIBSSH_API int ssh_event_add_fd(ssh_event event, socket_t fd, short events,
790 ssh_event_callback cb, void *userdata);
791 LIBSSH_API int ssh_event_add_session(ssh_event event, ssh_session session);
792 LIBSSH_API int ssh_event_add_connector(ssh_event event, ssh_connector connector);
793 LIBSSH_API int ssh_event_dopoll(ssh_event event, int timeout);
794 LIBSSH_API int ssh_event_remove_fd(ssh_event event, socket_t fd);
795 LIBSSH_API int ssh_event_remove_session(ssh_event event, ssh_session session);
796 LIBSSH_API int ssh_event_remove_connector(ssh_event event, ssh_connector connector);
797 LIBSSH_API void ssh_event_free(ssh_event event);
798 LIBSSH_API const char* ssh_get_clientbanner(ssh_session session);
799 LIBSSH_API const char* ssh_get_serverbanner(ssh_session session);
800 LIBSSH_API const char* ssh_get_kex_algo(ssh_session session);
801 LIBSSH_API const char* ssh_get_cipher_in(ssh_session session);
802 LIBSSH_API const char* ssh_get_cipher_out(ssh_session session);
803 LIBSSH_API const char* ssh_get_hmac_in(ssh_session session);
804 LIBSSH_API const char* ssh_get_hmac_out(ssh_session session);
805
806 LIBSSH_API ssh_buffer ssh_buffer_new(void);
807 LIBSSH_API void ssh_buffer_free(ssh_buffer buffer);
808 #define SSH_BUFFER_FREE(x) \
809 do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
810 LIBSSH_API int ssh_buffer_reinit(ssh_buffer buffer);
811 LIBSSH_API int ssh_buffer_add_data(ssh_buffer buffer, const void *data, uint32_t len);
812 LIBSSH_API uint32_t ssh_buffer_get_data(ssh_buffer buffer, void *data, uint32_t requestedlen);
813 LIBSSH_API void *ssh_buffer_get(ssh_buffer buffer);
814 LIBSSH_API uint32_t ssh_buffer_get_len(ssh_buffer buffer);
815
816 #ifndef LIBSSH_LEGACY_0_4
817 #include "libssh/legacy.h"
818 #endif
819
820 #ifdef __cplusplus
821 }
822 #endif
823 #endif /* _LIBSSH_H */
ssh_knownhosts_entry_free
LIBSSH_API void ssh_knownhosts_entry_free(struct ssh_knownhosts_entry *entry)
Free an allocated ssh_knownhosts_entry.
Definition: knownhosts.c:144
ssh_set_log_userdata
LIBSSH_API int ssh_set_log_userdata(void *data)
Set the userdata for the logging function.
Definition: log.c:235
ssh_service_request
Definition: messages.h:46
ssh_get_fingerprint_hash
LIBSSH_API char * ssh_get_fingerprint_hash(enum ssh_publickey_hash_type type, unsigned char *hash, size_t len)
Get a hash as a human-readable hex- or base64-string.
Definition: dh.c:1521
ssh_get_log_userdata
LIBSSH_API void * ssh_get_log_userdata(void)
Get the userdata of the logging function.
Definition: log.c:219
ssh_pki_export_privkey_to_pubkey
LIBSSH_API int ssh_pki_export_privkey_to_pubkey(const ssh_key privkey, ssh_key *pkey)
Create a public key from a private key.
Definition: pki.c:1613
ssh_key_struct
Definition: pki.h:42
ssh_userauth_kbdint
LIBSSH_API int ssh_userauth_kbdint(ssh_session session, const char *user, const char *submethods)
Try to authenticate through the "keyboard-interactive" method.
Definition: auth.c:1651
ssh_scp_init
LIBSSH_API int ssh_scp_init(ssh_scp scp)
Initialize the scp channel.
Definition: scp.c:95
ssh_session_get_known_hosts_entry
LIBSSH_API enum ssh_known_hosts_e ssh_session_get_known_hosts_entry(ssh_session session, struct ssh_knownhosts_entry **pentry)
Get the known_hosts entry for the current connected session.
Definition: knownhosts.c:855
ssh_agent_struct
Definition: agent.h:73
ssh_options_get
LIBSSH_API int ssh_options_get(ssh_session session, enum ssh_options_e type, char **value)
This function can get ssh options, it does not support all options provided for ssh options set...
Definition: options.c:1038
ssh_get_pubkey_hash
SSH_DEPRECATED LIBSSH_API int ssh_get_pubkey_hash(ssh_session session, unsigned char **hash)
Definition: dh.c:1177
ssh_string_to_char
char * ssh_string_to_char(struct ssh_string_struct *s)
Convert a SSH string to a C nul-terminated string.
Definition: string.c:181
ssh_channel_select
LIBSSH_API int ssh_channel_select(ssh_channel *readchans, ssh_channel *writechans, ssh_channel *exceptchans, struct timeval *timeout)
Act like the standard select(2) on channels.
Definition: channels.c:3088
ssh_options_parse_config
LIBSSH_API int ssh_options_parse_config(ssh_session session, const char *filename)
Parse the ssh config file.
Definition: options.c:1300
ssh_channel_request_x11
LIBSSH_API int ssh_channel_request_x11(ssh_channel channel, int single_connection, const char *protocol, const char *cookie, int screen_number)
Sends the "x11-req" channel request over an existing session channel.
Definition: channels.c:1871
ssh_key_type_to_char
LIBSSH_API const char * ssh_key_type_to_char(enum ssh_keytypes_e type)
Convert a key type to a string.
Definition: pki.c:233
ssh_channel_request_shell
LIBSSH_API int ssh_channel_request_shell(ssh_channel channel)
Request a shell.
Definition: channels.c:1760
ssh_init
LIBSSH_API int ssh_init(void)
Initialize global cryptographic data structures.
Definition: init.c:148
ssh_message_type
LIBSSH_API int ssh_message_type(ssh_message msg)
Get the type of the message.
Definition: messages.c:516
ssh_send_debug
LIBSSH_API int ssh_send_debug(ssh_session session, const char *message, int always_display)
Send a debug message.
Definition: session.c:867
ssh_get_cipher_in
LIBSSH_API const char * ssh_get_cipher_in(ssh_session session)
get the name of the input cipher for the given session.
Definition: session.c:373
ssh_channel_open_forward
LIBSSH_API int ssh_channel_open_forward(ssh_channel channel, const char *remotehost, int remoteport, const char *sourcehost, int localport)
Open a TCP/IP forwarding channel.
Definition: channels.c:946
ssh_channel_request_send_break
LIBSSH_API int ssh_channel_request_send_break(ssh_channel channel, uint32_t length)
Send a break signal to the server (as described in RFC 4335).
Definition: channels.c:2510
ssh_message_struct
Definition: messages.h:84
ssh_channel_is_eof
LIBSSH_API int ssh_channel_is_eof(ssh_channel channel)
Check if remote has sent an EOF.
Definition: channels.c:1437
ssh_known_hosts_parse_line
LIBSSH_API int ssh_known_hosts_parse_line(const char *host, const char *line, struct ssh_knownhosts_entry **entry)
Parse a line from a known_hosts entry into a structure.
Definition: knownhosts.c:406
ssh_channel_read_timeout
LIBSSH_API int ssh_channel_read_timeout(ssh_channel channel, void *dest, uint32_t count, int is_stderr, int timeout_ms)
Reads data from a channel.
Definition: channels.c:2689
ssh_set_log_level
LIBSSH_API int ssh_set_log_level(int level)
Set the log level of the library.
Definition: log.c:181
ssh_channel_send_eof
LIBSSH_API int ssh_channel_send_eof(ssh_channel channel)
Send an end of file on the channel.
Definition: channels.c:1079
ssh_channel_struct
Definition: channels.h:57
ssh_buffer_free
void ssh_buffer_free(struct ssh_buffer_struct *buffer)
Deallocate a SSH buffer.
Definition: buffer.c:149
ssh_scp_free
LIBSSH_API void ssh_scp_free(ssh_scp scp)
Free a scp context.
Definition: scp.c:199
ssh_clean_pubkey_hash
LIBSSH_API void ssh_clean_pubkey_hash(unsigned char **hash)
Deallocate the hash obtained by ssh_get_pubkey_hash.
Definition: dh.c:1239
ssh_channel_close
LIBSSH_API int ssh_channel_close(ssh_channel channel)
Close a channel.
Definition: channels.c:1131
ssh_pki_export_privkey_file
LIBSSH_API int ssh_pki_export_privkey_file(const ssh_key privkey, const char *passphrase, ssh_auth_callback auth_fn, void *auth_data, const char *filename)
Export a private key to a pem file on disk, or OpenSSH format for keytype ssh-ed25519.
Definition: pki.c:770
ssh_set_fd_toread
LIBSSH_API void ssh_set_fd_toread(ssh_session session)
Tell the session it has data to read on the file descriptor without blocking.
Definition: session.c:548
ssh_session_export_known_hosts_entry
LIBSSH_API int ssh_session_export_known_hosts_entry(ssh_session session, char **pentry_string)
Export the current session information to a known_hosts string.
Definition: knownhosts.c:626
ssh_key_is_public
LIBSSH_API int ssh_key_is_public(const ssh_key k)
Check if the key has/is a public key.
Definition: pki.c:418
ssh_channel_window_size
LIBSSH_API uint32_t ssh_channel_window_size(ssh_channel channel)
Get the remote window size.
Definition: channels.c:1377
ssh_scp_leave_directory
LIBSSH_API int ssh_scp_leave_directory(ssh_scp scp)
Leave a directory.
Definition: scp.c:271
ssh_event_remove_connector
LIBSSH_API int ssh_event_remove_connector(ssh_event event, ssh_connector connector)
Remove a connector from an event context.
Definition: poll.c:1001
ssh_string_new
LIBSSH_API ssh_string ssh_string_new(size_t size)
Create a new SSH String object.
Definition: string.c:56
ssh_scp_deny_request
LIBSSH_API int ssh_scp_deny_request(ssh_scp scp, const char *reason)
Deny the transfer of a file or creation of a directory coming from the remote party.
Definition: scp.c:644
ssh_key_is_private
LIBSSH_API int ssh_key_is_private(const ssh_key k)
Check if the key is a private key.
Definition: pki.c:433
ssh_event_struct
Definition: poll.c:671
ssh_get_openssh_version
LIBSSH_API int ssh_get_openssh_version(ssh_session session)
Get the version of the OpenSSH server, if it is not an OpenSSH server then 0 will be returned...
Definition: client.c:644
ssh_channel_open_auth_agent
LIBSSH_API int ssh_channel_open_auth_agent(ssh_channel channel)
Open an agent authentication forwarding channel. This type of channel can be opened by a server towar...
Definition: channels.c:908
ssh_version
LIBSSH_API const char * ssh_version(int req_version)
Check if libssh is the required version or get the version string.
Definition: misc.c:355
ssh_message_get
LIBSSH_API ssh_message ssh_message_get(ssh_session session)
Retrieve a SSH message from a SSH session.
Definition: messages.c:489
ssh_userauth_list
LIBSSH_API int ssh_userauth_list(ssh_session session, const char *username)
Get available authentication methods from the server.
Definition: auth.c:369
ssh_print_hash
LIBSSH_API void ssh_print_hash(enum ssh_publickey_hash_type type, unsigned char *hash, size_t len)
Print a hash as a human-readable hex- or base64-string.
Definition: dh.c:1590
ssh_get_error
LIBSSH_API const char * ssh_get_error(void *error)
Retrieve the error text message from the last error.
Definition: error.c:128
SSH_LOG_PACKET
Definition: libssh.h:341
ssh_channel_write
LIBSSH_API int ssh_channel_write(ssh_channel channel, const void *data, uint32_t len)
Blocking write on a channel.
Definition: channels.c:1394
ssh_session_struct
Definition: session.h:102
ssh_scp_accept_request
LIBSSH_API int ssh_scp_accept_request(ssh_scp scp)
Accepts transfer of a file or creation of a directory coming from the remote party.
Definition: scp.c:673
ssh_event_add_session
LIBSSH_API int ssh_event_add_session(ssh_event event, ssh_session session)
remove the poll handle from session and assign them to a event, when used in blocking mode...
Definition: poll.c:810
ssh_pki_export_pubkey_base64
LIBSSH_API int ssh_pki_export_pubkey_base64(const ssh_key key, char **b64_key)
Convert a public key to a base64 encoded key.
Definition: pki.c:1681
ssh_channel_request_pty_size
LIBSSH_API int ssh_channel_request_pty_size(ssh_channel channel, const char *term, int cols, int rows)
Request a pty with a specific type and size.
Definition: channels.c:1639
ssh_channel_request_subsystem
LIBSSH_API int ssh_channel_request_subsystem(ssh_channel channel, const char *subsystem)
Request a subsystem (for example "sftp").
Definition: channels.c:1782
ssh_pki_generate
LIBSSH_API int ssh_pki_generate(enum ssh_keytypes_e type, int parameter, ssh_key *pkey)
Generates a keypair.
Definition: pki.c:1545
ssh_connector_struct
Definition: connector.c:52
ssh_string_from_char
LIBSSH_API ssh_string ssh_string_from_char(const char *what)
Create a ssh string using a C string.
Definition: string.c:108
ssh_getpass
LIBSSH_API int ssh_getpass(const char *prompt, char *buf, size_t len, int echo, int verify)
Get a password from the console.
Definition: getpass.c:212
ssh_event_dopoll
LIBSSH_API int ssh_event_dopoll(ssh_event event, int timeout)
Poll all the sockets and sessions associated through an event object.i.
Definition: poll.c:882
ssh_get_version
LIBSSH_API int ssh_get_version(ssh_session session)
Get the protocol version of the session.
Definition: session.c:797
ssh_channel_request_env
LIBSSH_API int ssh_channel_request_env(ssh_channel channel, const char *name, const char *value)
Set environment variables.
Definition: channels.c:2324
ssh_set_fd_except
LIBSSH_API void ssh_set_fd_except(ssh_session session)
Tell the session it has an exception to catch on the file descriptor.
Definition: session.c:574
ssh_buffer_get_len
uint32_t ssh_buffer_get_len(struct ssh_buffer_struct *buffer)
Get the length of the buffer from the current position.
Definition: buffer.c:602
ssh_get_issue_banner
LIBSSH_API char * ssh_get_issue_banner(ssh_session session)
Get the issue banner from the server.
Definition: client.c:618
ssh_buffer_reinit
int ssh_buffer_reinit(struct ssh_buffer_struct *buffer)
Reinitialize a SSH buffer.
Definition: buffer.c:259
ssh_session_has_known_hosts_entry
LIBSSH_API enum ssh_known_hosts_e ssh_session_has_known_hosts_entry(ssh_session session)
Check if the set hostname and port matches an entry in known_hosts.
Definition: knownhosts.c:554
ssh_pki_copy_cert_to_privkey
LIBSSH_API int ssh_pki_copy_cert_to_privkey(const ssh_key cert_key, ssh_key privkey)
Copy the certificate part of a public key into a private key.
Definition: pki.c:1774
ssh_string_fill
int ssh_string_fill(struct ssh_string_struct *s, const void *data, size_t len)
Fill a string with given data. The string should be big enough.
Definition: string.c:87
ssh_userauth_kbdint_getnprompts
LIBSSH_API int ssh_userauth_kbdint_getnprompts(ssh_session session)
Get the number of prompts (questions) the server has given.
Definition: auth.c:1694
ssh_event_add_fd
LIBSSH_API int ssh_event_add_fd(ssh_event event, socket_t fd, short events, ssh_event_callback cb, void *userdata)
Add a fd to the event and assign it a callback, when used in blocking mode.
Definition: poll.c:741
ssh_set_counters
LIBSSH_API void ssh_set_counters(ssh_session session, ssh_counter scounter, ssh_counter rcounter)
Set the session data counters.
Definition: session.c:923
ssh_options_copy
LIBSSH_API int ssh_options_copy(ssh_session src, ssh_session *dest)
Duplicate the options of a session structure.
Definition: options.c:64
ssh_userauth_kbdint_getinstruction
LIBSSH_API const char * ssh_userauth_kbdint_getinstruction(ssh_session session)
Get the "instruction" of the message block.
Definition: auth.c:1739
ssh_channel_open_session
LIBSSH_API int ssh_channel_open_session(ssh_channel channel)
Open a session channel (suited for a shell, not TCP forwarding).
Definition: channels.c:881
ssh_scp_request_get_size64
LIBSSH_API uint64_t ssh_scp_request_get_size64(ssh_scp scp)
Get the size of the file being pushed from the other party.
Definition: scp.c:789
ssh_string_copy
struct ssh_string_struct * ssh_string_copy(struct ssh_string_struct *s)
Copy a string, return a newly allocated string. The caller has to free the string.
Definition: string.c:221
ssh_string_get_char
const char * ssh_string_get_char(struct ssh_string_struct *s)
Get the the string as a C nul-terminated string.
Definition: string.c:160
ssh_buffer_get
void * ssh_buffer_get(struct ssh_buffer_struct *buffer)
Get a pointer to the head of a buffer at the current position.
Definition: buffer.c:589
ssh_set_blocking
LIBSSH_API void ssh_set_blocking(ssh_session session, int blocking)
Set the session in blocking/nonblocking mode.
Definition: session.c:452
ssh_channel_is_open
LIBSSH_API int ssh_channel_is_open(ssh_channel channel)
Check if the channel is open or not.
Definition: channels.c:1407
ssh_event_add_connector
LIBSSH_API int ssh_event_add_connector(ssh_event event, ssh_connector connector)
Add a connector to the SSH event loop.
Definition: poll.c:862
ssh_key_type_from_name
LIBSSH_API enum ssh_keytypes_e ssh_key_type_from_name(const char *name)
Convert a ssh key name to a ssh key type.
Definition: pki.c:381
ssh_write_knownhost
LIBSSH_API int ssh_write_knownhost(ssh_session session)
This function is deprecated.
Definition: known_hosts.c:515
ssh_channel_is_closed
LIBSSH_API int ssh_channel_is_closed(ssh_channel channel)
Check if the channel is closed or not.
Definition: channels.c:1423
ssh_key_free
LIBSSH_API void ssh_key_free(ssh_key key)
deallocate a SSH key
Definition: pki.c:174
SSH_LOG_WARNING
Definition: libssh.h:335
SSH_LOG_FUNCTIONS
Definition: libssh.h:344
ssh_channel_get_session
LIBSSH_API ssh_session ssh_channel_get_session(ssh_channel channel)
Recover the session in which belongs a channel.
Definition: channels.c:2949
ssh_channel_poll_timeout
LIBSSH_API int ssh_channel_poll_timeout(ssh_channel channel, int timeout, int is_stderr)
Polls a channel for data to read, waiting for a certain timeout.
Definition: channels.c:2908
ssh_pki_key_ecdsa_name
LIBSSH_API const char * ssh_pki_key_ecdsa_name(const ssh_key key)
returns the ECDSA key name ("ecdsa-sha2-nistp256" for example)
Definition: pki.c:92
ssh_scp_new
LIBSSH_API ssh_scp ssh_scp_new(ssh_session session, int mode, const char *location)
Create a new scp session.
Definition: scp.c:60
ssh_buffer_new
LIBSSH_API ssh_buffer ssh_buffer_new(void)
Create a new SSH buffer.
Definition: buffer.c:119
ssh_scp_request_get_filename
LIBSSH_API const char * ssh_scp_request_get_filename(ssh_scp scp)
Get the name of the directory or file being pushed from the other party.
Definition: scp.c:754
ssh_scp_write
LIBSSH_API int ssh_scp_write(ssh_scp scp, const void *buffer, size_t len)
Write into a remote scp file.
Definition: scp.c:437
ssh_event_new
LIBSSH_API ssh_event ssh_event_new(void)
Create a new event context. It could be associated with many ssh_session objects and socket fd which ...
Definition: poll.c:686
ssh_channel_poll
LIBSSH_API int ssh_channel_poll(ssh_channel channel, int is_stderr)
Polls a channel for data to read.
Definition: channels.c:2856
ssh_is_connected
LIBSSH_API int ssh_is_connected(ssh_session session)
Check if we are connected.
Definition: session.c:516
ssh_get_log_level
LIBSSH_API int ssh_get_log_level(void)
Get the log level of the library.
Definition: log.c:196
ssh_get_poll_flags
LIBSSH_API int ssh_get_poll_flags(ssh_session session)
Get poll flags for an external mainloop.
Definition: session.c:752
ssh_knownhosts_entry
Definition: libssh.h:309
ssh_string_struct
Definition: string.h:29
ssh_userauth_gssapi
LIBSSH_API int ssh_userauth_gssapi(ssh_session session)
Try to authenticate through the "gssapi-with-mic" method.
Definition: auth.c:1896
SSH_LOG_NOLOG
Definition: libssh.h:332
ssh_channel_new
LIBSSH_API ssh_channel ssh_channel_new(ssh_session session)
Allocate a new channel.
Definition: channels.c:79
ssh_options_set
LIBSSH_API int ssh_options_set(ssh_session session, enum ssh_options_e type, const void *value)
This function can set all possible ssh options.
Definition: options.c:430
ssh_options_getopt
LIBSSH_API int ssh_options_getopt(ssh_session session, int *argcptr, char **argv)
Parse command line arguments.
Definition: options.c:1118
ssh_userauth_kbdint_getprompt
LIBSSH_API const char * ssh_userauth_kbdint_getprompt(ssh_session session, unsigned int i, char *echo)
Get a prompt from a message block.
Definition: auth.c:1774
ssh_userauth_kbdint_getname
LIBSSH_API const char * ssh_userauth_kbdint_getname(ssh_session session)
Get the "name" of the message block.
Definition: auth.c:1716
ssh_get_clientbanner
LIBSSH_API const char * ssh_get_clientbanner(ssh_session session)
get the client banner
Definition: session.c:305
ssh_event_remove_session
LIBSSH_API int ssh_event_remove_session(ssh_event event, ssh_session session)
Remove a session object from an event context.
Definition: poll.c:947
ssh_key_new
LIBSSH_API ssh_key ssh_key_new(void)
creates a new empty SSH key
Definition: pki.c:106
ssh_get_server_publickey
LIBSSH_API int ssh_get_server_publickey(ssh_session session, ssh_key *key)
Get the server public key from a session.
Definition: dh.c:1256
ssh_userauth_password
LIBSSH_API int ssh_userauth_password(ssh_session session, const char *username, const char *password)
Try to authenticate by password.
Definition: auth.c:1236
ssh_userauth_publickey_auto
LIBSSH_API int ssh_userauth_publickey_auto(ssh_session session, const char *username, const char *passphrase)
Tries to automatically authenticate with public key and "none".
Definition: auth.c:1016
ssh_userauth_kbdint_setanswer
LIBSSH_API int ssh_userauth_kbdint_setanswer(ssh_session session, unsigned int i, const char *answer)
Set the answer for a question from a message block.
Definition: auth.c:1849
ssh_userauth_publickey
LIBSSH_API int ssh_userauth_publickey(ssh_session session, const char *username, const ssh_key privkey)
Authenticate with public/private key or certificate.
Definition: auth.c:615
ssh_pki_import_cert_base64
LIBSSH_API int ssh_pki_import_cert_base64(const char *b64_cert, enum ssh_keytypes_e type, ssh_key *pkey)
Import a base64 formated certificate from a memory c-string.
Definition: pki.c:1485
ssh_get_cipher_out
LIBSSH_API const char * ssh_get_cipher_out(ssh_session session)
get the name of the output cipher for the given session.
Definition: session.c:389
ssh_select
LIBSSH_API int ssh_select(ssh_channel *channels, ssh_channel *outchannels, socket_t maxfd, fd_set *readfds, struct timeval *timeout)
A wrapper for the select syscall.
Definition: connect.c:475
ssh_get_fd
LIBSSH_API socket_t ssh_get_fd(ssh_session session)
Get the fd of a connection.
Definition: session.c:534
ssh_channel_change_pty_size
LIBSSH_API int ssh_channel_change_pty_size(ssh_channel channel, int cols, int rows)
Change the size of the terminal associated to a channel.
Definition: channels.c:1721
ssh_connect
LIBSSH_API int ssh_connect(ssh_session session)
Connect to the ssh server.
Definition: client.c:503
ssh_key_type
LIBSSH_API enum ssh_keytypes_e ssh_key_type(const ssh_key key)
returns the type of a ssh key
Definition: pki.c:189
ssh_disconnect
LIBSSH_API void ssh_disconnect(ssh_session session)
Disconnect from a session (client or server). The session can then be reused to open a new session...
Definition: client.c:658
ssh_userauth_none
LIBSSH_API int ssh_userauth_none(ssh_session session, const char *username)
Try to authenticate through the "none" method.
Definition: auth.c:399
ssh_string_free
void ssh_string_free(struct ssh_string_struct *s)
Deallocate a SSH string object.
Definition: string.c:277
ssh_channel_listen_forward
LIBSSH_API int ssh_channel_listen_forward(ssh_session session, const char *address, int port, int *bound_port)
Sends the "tcpip-forward" global request to ask the server to begin listening for inbound connections...
Definition: channels.c:2191
ssh_channel_accept_x11
LIBSSH_API ssh_channel ssh_channel_accept_x11(ssh_channel channel, int timeout_ms)
Accept an X11 forwarding channel.
Definition: channels.c:1987
ssh_mkdir
LIBSSH_API int ssh_mkdir(const char *pathname, mode_t mode)
Attempts to create a directory with the given pathname.
Definition: misc.c:631
ssh_blocking_flush
LIBSSH_API int ssh_blocking_flush(ssh_session session, int timeout)
Blocking flush of the outgoing buffer.
Definition: session.c:491
ssh_key_cmp
LIBSSH_API int ssh_key_cmp(const ssh_key k1, const ssh_key k2, enum ssh_keycmp_e what)
Compare keys if they are equal.
Definition: pki.c:452
ssh_channel_request_send_signal
LIBSSH_API int ssh_channel_request_send_signal(ssh_channel channel, const char *signum)
Send a signal to remote process (as described in RFC 4254, section 6.9).
Definition: channels.c:2464
ssh_set_fd_towrite
LIBSSH_API void ssh_set_fd_towrite(ssh_session session)
Tell the session it may write to the file descriptor without blocking.
Definition: session.c:561
ssh_event_free
LIBSSH_API void ssh_event_free(ssh_event event)
Free an event context.
Definition: poll.c:1014
SSH_LOG_PROTOCOL
Definition: libssh.h:338
ssh_dump_knownhost
LIBSSH_API char * ssh_dump_knownhost(ssh_session session)
This function is deprecated.
Definition: known_hosts.c:446
ssh_channel_accept_forward
LIBSSH_API ssh_channel ssh_channel_accept_forward(ssh_session session, int timeout_ms, int *destination_port)
Accept an incoming TCP/IP forwarding channel and get information about incomming connection.
Definition: channels.c:2254
ssh_print_hexa
LIBSSH_API void ssh_print_hexa(const char *descr, const unsigned char *what, size_t len)
Print a buffer as colon separated hex string.
Definition: dh.c:1617
ssh_scp_request_get_warning
LIBSSH_API const char * ssh_scp_request_get_warning(ssh_scp scp)
Get the warning string from a scp handle.
Definition: scp.c:829
ssh_options_get_port
LIBSSH_API int ssh_options_get_port(ssh_session session, unsigned int *port_target)
This function can get ssh the ssh port. It must only be used on a valid ssh session. This function is useful when the session options have been automatically inferred from the environment or configuration files and one.
Definition: options.c:980
ssh_pki_import_cert_file
LIBSSH_API int ssh_pki_import_cert_file(const char *filename, ssh_key *pkey)
Import a certificate from the given filename.
Definition: pki.c:1524
ssh_scp_request_get_permissions
LIBSSH_API int ssh_scp_request_get_permissions(ssh_scp scp)
Get the permissions of the directory or file being pushed from the other party.
Definition: scp.c:766
ssh_scp_request_get_size
LIBSSH_API size_t ssh_scp_request_get_size(ssh_scp scp)
Get the size of the file being pushed from the other party.
Definition: scp.c:779
ssh_string_data
void * ssh_string_data(struct ssh_string_struct *s)
Get the payload of the string.
Definition: string.c:264
ssh_buffer_get_data
uint32_t ssh_buffer_get_data(struct ssh_buffer_struct *buffer, void *data, uint32_t len)
Get the remaining data out of the buffer and adjust the read pointer.
Definition: buffer.c:671
ssh_scp_read
LIBSSH_API int ssh_scp_read(ssh_scp scp, void *buffer, size_t size)
Read from a remote scp file.
Definition: scp.c:703
ssh_basename
LIBSSH_API char * ssh_basename(const char *path)
basename - parse filename component.
Definition: misc.c:580
ssh_finalize
LIBSSH_API int ssh_finalize(void)
Finalize and cleanup all libssh and cryptographic data structures.
Definition: init.c:221
ssh_pki_export_privkey_base64
LIBSSH_API int ssh_pki_export_privkey_base64(const ssh_key privkey, const char *passphrase, ssh_auth_callback auth_fn, void *auth_data, char **b64_key)
Convert a private key to a pem base64 encoded key, or OpenSSH format for keytype ssh-ed25519.
Definition: pki.c:617
ssh_string_burn
void ssh_string_burn(struct ssh_string_struct *s)
Destroy the data in a string so it couldn&#39;t appear in a core dump.
Definition: string.c:249
ssh_channel_request_exec
LIBSSH_API int ssh_channel_request_exec(ssh_channel channel, const char *cmd)
Run a shell command without an interactive shell.
Definition: channels.c:2394
ssh_get_hmac_out
LIBSSH_API const char * ssh_get_hmac_out(ssh_session session)
get the name of the output HMAC algorithm for the given session.
Definition: session.c:420
ssh_channel_request_pty
LIBSSH_API int ssh_channel_request_pty(ssh_channel channel)
Request a PTY.
Definition: channels.c:1702
ssh_get_serverbanner
LIBSSH_API const char * ssh_get_serverbanner(ssh_session session)
get the server banner
Definition: session.c:320
ssh_session_is_known_server
LIBSSH_API enum ssh_known_hosts_e ssh_session_is_known_server(ssh_session session)
Check if the servers public key for the connected session is known.
Definition: knownhosts.c:977
ssh_session_update_known_hosts
LIBSSH_API int ssh_session_update_known_hosts(ssh_session session)
Add the current connected server to the user known_hosts file.
Definition: knownhosts.c:699
ssh_silent_disconnect
LIBSSH_API void ssh_silent_disconnect(ssh_session session)
Disconnect impolitely from a remote host by closing the socket.
Definition: session.c:435
ssh_get_disconnect_message
LIBSSH_API const char * ssh_get_disconnect_message(ssh_session session)
Get the disconnect message from the server.
Definition: session.c:772
ssh_scp_struct
Definition: scp.h:35
ssh_string_len
size_t ssh_string_len(struct ssh_string_struct *s)
Return the size of a SSH string.
Definition: string.c:136
ssh_channel_set_blocking
LIBSSH_API void ssh_channel_set_blocking(ssh_channel channel, int blocking)
Put the channel into blocking or nonblocking mode.
Definition: channels.c:1462
ssh_get_kex_algo
LIBSSH_API const char * ssh_get_kex_algo(ssh_session session)
get the name of the current key exchange algorithm.
Definition: session.c:334
ssh_message_free
LIBSSH_API void ssh_message_free(ssh_message msg)
Free a SSH message.
Definition: messages.c:555
ssh_message_subtype
LIBSSH_API int ssh_message_subtype(ssh_message msg)
Get the subtype of the message.
Definition: messages.c:531
ssh_new
LIBSSH_API ssh_session ssh_new(void)
Create a new ssh session.
Definition: session.c:58
ssh_get_publickey
SSH_DEPRECATED LIBSSH_API int ssh_get_publickey(ssh_session session, ssh_key *key)
Definition: dh.c:1306
ssh_get_status
LIBSSH_API int ssh_get_status(ssh_session session)
Get session status.
Definition: session.c:714
ssh_channel_set_counter
LIBSSH_API void ssh_channel_set_counter(ssh_channel channel, ssh_counter counter)
Set the channel data counter.
Definition: channels.c:3222
ssh_channel_free
LIBSSH_API void ssh_channel_free(ssh_channel channel)
Close and free a channel.
Definition: channels.c:1002
ssh_userauth_try_publickey
LIBSSH_API int ssh_userauth_try_publickey(ssh_session session, const char *username, const ssh_key pubkey)
Try to authenticate with the given public key.
Definition: auth.c:482
ssh_event_remove_fd
LIBSSH_API int ssh_event_remove_fd(ssh_event event, socket_t fd)
Remove a socket fd from an event context.
Definition: poll.c:901
ssh_scp_push_file64
LIBSSH_API int ssh_scp_push_file64(ssh_scp scp, const char *filename, uint64_t size, int perms)
Initialize the sending of a file to a scp in sink mode, using a 64-bit size.
Definition: scp.c:317
ssh_scp_pull_request
LIBSSH_API int ssh_scp_pull_request(ssh_scp scp)
Wait for a scp request (file, directory).
Definition: scp.c:547
ssh_string_free_char
LIBSSH_API void ssh_string_free_char(char *s)
Deallocate a char string object.
Definition: string.c:209
ssh_is_server_known
LIBSSH_API int ssh_is_server_known(ssh_session session)
This function is depcrecated.
Definition: known_hosts.c:308
ssh_send_ignore
LIBSSH_API int ssh_send_ignore(ssh_session session, const char *data)
Send a message that should be ignored.
Definition: session.c:832
ssh_is_blocking
LIBSSH_API int ssh_is_blocking(ssh_session session)
Return the blocking mode of libssh.
Definition: session.c:466
ssh_get_hexa
LIBSSH_API char * ssh_get_hexa(const unsigned char *what, size_t len)
Convert a buffer into a colon separated hex string. The caller has to free the memory.
Definition: dh.c:1479
ssh_get_publickey_hash
LIBSSH_API int ssh_get_publickey_hash(const ssh_key key, enum ssh_publickey_hash_type type, unsigned char **hash, size_t *hlen)
Allocates a buffer with the hash of the public key.
Definition: dh.c:1339
ssh_channel_get_exit_status
LIBSSH_API int ssh_channel_get_exit_status(ssh_channel channel)
Get the exit status of the channel (error code from the executed instruction).
Definition: channels.c:2985
ssh_pki_import_pubkey_file
LIBSSH_API int ssh_pki_import_pubkey_file(const char *filename, ssh_key *pkey)
Import a public key from the given filename.
Definition: pki.c:1370
ssh_channel_cancel_forward
LIBSSH_API int ssh_channel_cancel_forward(ssh_session session, const char *address, int port)
Sends the "cancel-tcpip-forward" global request to ask the server to cancel the tcpip-forward request...
Definition: channels.c:2273
ssh_channel_request_auth_agent
LIBSSH_API int ssh_channel_request_auth_agent(ssh_channel channel)
Send an "auth-agent-req" channel request over an existing session channel.
Definition: channels.c:2002
ssh_channel_write_stderr
LIBSSH_API int ssh_channel_write_stderr(ssh_channel channel, const void *data, uint32_t len)
Blocking write on a channel stderr.
Definition: channels.c:3242
ssh_userauth_agent
LIBSSH_API int ssh_userauth_agent(ssh_session session, const char *username)
Try to do public key authentication with ssh agent.
Definition: auth.c:881
ssh_get_hmac_in
LIBSSH_API const char * ssh_get_hmac_in(ssh_session session)
get the name of the input HMAC algorithm for the given session.
Definition: session.c:405
ssh_scp_push_file
LIBSSH_API int ssh_scp_push_file(ssh_scp scp, const char *filename, size_t size, int perms)
Initialize the sending of a file to a scp in sink mode.
Definition: scp.c:372
ssh_pki_import_pubkey_base64
LIBSSH_API int ssh_pki_import_pubkey_base64(const char *b64_key, enum ssh_keytypes_e type, ssh_key *pkey)
Import a base64 formated public key from a memory c-string.
Definition: pki.c:1254
ssh_scp_push_directory
LIBSSH_API int ssh_scp_push_directory(ssh_scp scp, const char *dirname, int mode)
Create a directory in a scp in sink mode.
Definition: scp.c:227
ssh_channel_read
LIBSSH_API int ssh_channel_read(ssh_channel channel, void *dest, uint32_t count, int is_stderr)
Reads data from a channel.
Definition: channels.c:2657
ssh_pki_import_privkey_base64
LIBSSH_API int ssh_pki_import_privkey_base64(const char *b64_key, const char *passphrase, ssh_auth_callback auth_fn, void *auth_data, ssh_key *pkey)
import a base64 formated key from a memory c-string
Definition: pki.c:556
ssh_free
LIBSSH_API void ssh_free(ssh_session session)
Deallocate a SSH session handle.
Definition: session.c:169
ssh_scp_close
LIBSSH_API int ssh_scp_close(ssh_scp scp)
Close the scp channel.
Definition: scp.c:161
ssh_channel_read_nonblocking
LIBSSH_API int ssh_channel_read_nonblocking(ssh_channel channel, void *dest, uint32_t count, int is_stderr)
Do a nonblocking read on the channel.
Definition: channels.c:2804
ssh_buffer_add_data
int ssh_buffer_add_data(struct ssh_buffer_struct *buffer, const void *data, uint32_t len)
Add data at the tail of a buffer.
Definition: buffer.c:300
ssh_dirname
LIBSSH_API char * ssh_dirname(const char *path)
Parse directory component.
Definition: misc.c:525
ssh_get_error_code
LIBSSH_API int ssh_get_error_code(void *error)
Retrieve the error code from the last error.
Definition: error.c:148
ssh_pki_import_privkey_file
LIBSSH_API int ssh_pki_import_privkey_file(const char *filename, const char *passphrase, ssh_auth_callback auth_fn, void *auth_data, ssh_key *pkey)
Import a key from a file.
Definition: pki.c:676
ssh_buffer_struct
Definition: buffer.c:47
ssh_counter_struct
Definition: libssh.h:108