libssh  0.10.4
The SSH library
libssh.h
1 /*
2  * This file is part of the SSH Library
3  *
4  * Copyright (c) 2003-2022 by Aris Adamantiadis and the libssh team
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 #include <libssh/libssh_version.h>
25 
26 #if defined _WIN32 || defined __CYGWIN__
27  #ifdef LIBSSH_STATIC
28  #define LIBSSH_API
29  #else
30  #ifdef LIBSSH_EXPORTS
31  #ifdef __GNUC__
32  #define LIBSSH_API __attribute__((dllexport))
33  #else
34  #define LIBSSH_API __declspec(dllexport)
35  #endif
36  #else
37  #ifdef __GNUC__
38  #define LIBSSH_API __attribute__((dllimport))
39  #else
40  #define LIBSSH_API __declspec(dllimport)
41  #endif
42  #endif
43  #endif
44 #else
45  #if __GNUC__ >= 4 && !defined(__OS2__)
46  #define LIBSSH_API __attribute__((visibility("default")))
47  #else
48  #define LIBSSH_API
49  #endif
50 #endif
51 
52 #include <stdarg.h>
53 
54 #ifdef _MSC_VER
55  /* Visual Studio hasn't inttypes.h so it doesn't know uint32_t */
56  typedef int int32_t;
57  typedef unsigned int uint32_t;
58  typedef unsigned short uint16_t;
59  typedef unsigned char uint8_t;
60  typedef unsigned long long uint64_t;
61  typedef int mode_t;
62 #else /* _MSC_VER */
63  #include <unistd.h>
64  #include <inttypes.h>
65  #include <sys/types.h>
66 #endif /* _MSC_VER */
67 
68 #ifdef _WIN32
69  #include <winsock2.h>
70 #else /* _WIN32 */
71  #include <sys/select.h> /* for fd_set * */
72  #include <netdb.h>
73 #endif /* _WIN32 */
74 
75 #define SSH_STRINGIFY(s) SSH_TOSTRING(s)
76 #define SSH_TOSTRING(s) #s
77 
78 /* GCC have printf type attribute check. */
79 #ifdef __GNUC__
80 #define PRINTF_ATTRIBUTE(a,b) __attribute__ ((__format__ (__printf__, a, b)))
81 #else
82 #define PRINTF_ATTRIBUTE(a,b)
83 #endif /* __GNUC__ */
84 
85 #ifdef __GNUC__
86 #define SSH_DEPRECATED __attribute__ ((deprecated))
87 #else
88 #define SSH_DEPRECATED
89 #endif
90 
91 #ifdef __cplusplus
92 extern "C" {
93 #endif
94 
96  uint64_t in_bytes;
97  uint64_t out_bytes;
98  uint64_t in_packets;
99  uint64_t out_packets;
100 };
101 typedef struct ssh_counter_struct *ssh_counter;
102 
103 typedef struct ssh_agent_struct* ssh_agent;
104 typedef struct ssh_buffer_struct* ssh_buffer;
105 typedef struct ssh_channel_struct* ssh_channel;
106 typedef struct ssh_message_struct* ssh_message;
107 typedef struct ssh_pcap_file_struct* ssh_pcap_file;
108 typedef struct ssh_key_struct* ssh_key;
109 typedef struct ssh_scp_struct* ssh_scp;
110 typedef struct ssh_session_struct* ssh_session;
111 typedef struct ssh_string_struct* ssh_string;
112 typedef struct ssh_event_struct* ssh_event;
113 typedef struct ssh_connector_struct * ssh_connector;
114 typedef void* ssh_gssapi_creds;
115 
116 /* Socket type */
117 #ifdef _WIN32
118 #ifndef socket_t
119 typedef SOCKET socket_t;
120 #endif /* socket_t */
121 #else /* _WIN32 */
122 #ifndef socket_t
123 typedef int socket_t;
124 #endif
125 #endif /* _WIN32 */
126 
127 #define SSH_INVALID_SOCKET ((socket_t) -1)
128 
129 /* the offsets of methods */
130 enum ssh_kex_types_e {
131  SSH_KEX=0,
132  SSH_HOSTKEYS,
133  SSH_CRYPT_C_S,
134  SSH_CRYPT_S_C,
135  SSH_MAC_C_S,
136  SSH_MAC_S_C,
137  SSH_COMP_C_S,
138  SSH_COMP_S_C,
139  SSH_LANG_C_S,
140  SSH_LANG_S_C
141 };
142 
143 #define SSH_CRYPT 2
144 #define SSH_MAC 3
145 #define SSH_COMP 4
146 #define SSH_LANG 5
147 
148 enum ssh_auth_e {
149  SSH_AUTH_SUCCESS=0,
150  SSH_AUTH_DENIED,
151  SSH_AUTH_PARTIAL,
152  SSH_AUTH_INFO,
153  SSH_AUTH_AGAIN,
154  SSH_AUTH_ERROR=-1
155 };
156 
157 /* auth flags */
158 #define SSH_AUTH_METHOD_UNKNOWN 0x0000u
159 #define SSH_AUTH_METHOD_NONE 0x0001u
160 #define SSH_AUTH_METHOD_PASSWORD 0x0002u
161 #define SSH_AUTH_METHOD_PUBLICKEY 0x0004u
162 #define SSH_AUTH_METHOD_HOSTBASED 0x0008u
163 #define SSH_AUTH_METHOD_INTERACTIVE 0x0010u
164 #define SSH_AUTH_METHOD_GSSAPI_MIC 0x0020u
165 
166 /* messages */
167 enum ssh_requests_e {
168  SSH_REQUEST_AUTH=1,
169  SSH_REQUEST_CHANNEL_OPEN,
170  SSH_REQUEST_CHANNEL,
171  SSH_REQUEST_SERVICE,
172  SSH_REQUEST_GLOBAL
173 };
174 
175 enum ssh_channel_type_e {
176  SSH_CHANNEL_UNKNOWN=0,
177  SSH_CHANNEL_SESSION,
178  SSH_CHANNEL_DIRECT_TCPIP,
179  SSH_CHANNEL_FORWARDED_TCPIP,
180  SSH_CHANNEL_X11,
181  SSH_CHANNEL_AUTH_AGENT
182 };
183 
184 enum ssh_channel_requests_e {
185  SSH_CHANNEL_REQUEST_UNKNOWN=0,
186  SSH_CHANNEL_REQUEST_PTY,
187  SSH_CHANNEL_REQUEST_EXEC,
188  SSH_CHANNEL_REQUEST_SHELL,
189  SSH_CHANNEL_REQUEST_ENV,
190  SSH_CHANNEL_REQUEST_SUBSYSTEM,
191  SSH_CHANNEL_REQUEST_WINDOW_CHANGE,
192  SSH_CHANNEL_REQUEST_X11
193 };
194 
195 enum ssh_global_requests_e {
196  SSH_GLOBAL_REQUEST_UNKNOWN=0,
197  SSH_GLOBAL_REQUEST_TCPIP_FORWARD,
198  SSH_GLOBAL_REQUEST_CANCEL_TCPIP_FORWARD,
199  SSH_GLOBAL_REQUEST_KEEPALIVE
200 };
201 
202 enum ssh_publickey_state_e {
203  SSH_PUBLICKEY_STATE_ERROR=-1,
204  SSH_PUBLICKEY_STATE_NONE=0,
205  SSH_PUBLICKEY_STATE_VALID=1,
206  SSH_PUBLICKEY_STATE_WRONG=2
207 };
208 
209 /* Status flags */
211 #define SSH_CLOSED 0x01
213 #define SSH_READ_PENDING 0x02
215 #define SSH_CLOSED_ERROR 0x04
217 #define SSH_WRITE_PENDING 0x08
218 
219 enum ssh_server_known_e {
220  SSH_SERVER_ERROR=-1,
221  SSH_SERVER_NOT_KNOWN=0,
222  SSH_SERVER_KNOWN_OK,
223  SSH_SERVER_KNOWN_CHANGED,
224  SSH_SERVER_FOUND_OTHER,
225  SSH_SERVER_FILE_NOT_FOUND
226 };
227 
228 enum ssh_known_hosts_e {
232  SSH_KNOWN_HOSTS_ERROR = -2,
233 
238  SSH_KNOWN_HOSTS_NOT_FOUND = -1,
239 
244  SSH_KNOWN_HOSTS_UNKNOWN = 0,
245 
249  SSH_KNOWN_HOSTS_OK,
250 
256  SSH_KNOWN_HOSTS_CHANGED,
257 
262  SSH_KNOWN_HOSTS_OTHER,
263 };
264 
265 #ifndef MD5_DIGEST_LEN
266  #define MD5_DIGEST_LEN 16
267 #endif
268 /* errors */
269 
270 enum ssh_error_types_e {
271  SSH_NO_ERROR=0,
272  SSH_REQUEST_DENIED,
273  SSH_FATAL,
274  SSH_EINTR
275 };
276 
277 /* some types for keys */
278 enum ssh_keytypes_e{
279  SSH_KEYTYPE_UNKNOWN=0,
280  SSH_KEYTYPE_DSS=1,
281  SSH_KEYTYPE_RSA,
282  SSH_KEYTYPE_RSA1,
283  SSH_KEYTYPE_ECDSA, /* deprecated */
284  SSH_KEYTYPE_ED25519,
285  SSH_KEYTYPE_DSS_CERT01,
286  SSH_KEYTYPE_RSA_CERT01,
287  SSH_KEYTYPE_ECDSA_P256,
288  SSH_KEYTYPE_ECDSA_P384,
289  SSH_KEYTYPE_ECDSA_P521,
290  SSH_KEYTYPE_ECDSA_P256_CERT01,
291  SSH_KEYTYPE_ECDSA_P384_CERT01,
292  SSH_KEYTYPE_ECDSA_P521_CERT01,
293  SSH_KEYTYPE_ED25519_CERT01,
294  SSH_KEYTYPE_SK_ECDSA,
295  SSH_KEYTYPE_SK_ECDSA_CERT01,
296  SSH_KEYTYPE_SK_ED25519,
297  SSH_KEYTYPE_SK_ED25519_CERT01,
298 };
299 
300 enum ssh_keycmp_e {
301  SSH_KEY_CMP_PUBLIC = 0,
302  SSH_KEY_CMP_PRIVATE
303 };
304 
305 #define SSH_ADDRSTRLEN 46
306 
308  char *hostname;
309  char *unparsed;
310  ssh_key publickey;
311  char *comment;
312 };
313 
314 
315 /* Error return codes */
316 #define SSH_OK 0 /* No error */
317 #define SSH_ERROR -1 /* Error of some kind */
318 #define SSH_AGAIN -2 /* The nonblocking call must be repeated */
319 #define SSH_EOF -127 /* We have already a eof */
320 
327 enum {
343 };
345 #define SSH_LOG_RARE SSH_LOG_WARNING
346 
355 #define SSH_LOG_NONE 0
357 #define SSH_LOG_WARN 1
359 #define SSH_LOG_INFO 2
361 #define SSH_LOG_DEBUG 3
363 #define SSH_LOG_TRACE 4
364 
367 enum ssh_options_e {
368  SSH_OPTIONS_HOST,
369  SSH_OPTIONS_PORT,
370  SSH_OPTIONS_PORT_STR,
371  SSH_OPTIONS_FD,
372  SSH_OPTIONS_USER,
373  SSH_OPTIONS_SSH_DIR,
374  SSH_OPTIONS_IDENTITY,
375  SSH_OPTIONS_ADD_IDENTITY,
376  SSH_OPTIONS_KNOWNHOSTS,
377  SSH_OPTIONS_TIMEOUT,
378  SSH_OPTIONS_TIMEOUT_USEC,
379  SSH_OPTIONS_SSH1,
380  SSH_OPTIONS_SSH2,
381  SSH_OPTIONS_LOG_VERBOSITY,
382  SSH_OPTIONS_LOG_VERBOSITY_STR,
383  SSH_OPTIONS_CIPHERS_C_S,
384  SSH_OPTIONS_CIPHERS_S_C,
385  SSH_OPTIONS_COMPRESSION_C_S,
386  SSH_OPTIONS_COMPRESSION_S_C,
387  SSH_OPTIONS_PROXYCOMMAND,
388  SSH_OPTIONS_BINDADDR,
389  SSH_OPTIONS_STRICTHOSTKEYCHECK,
390  SSH_OPTIONS_COMPRESSION,
391  SSH_OPTIONS_COMPRESSION_LEVEL,
392  SSH_OPTIONS_KEY_EXCHANGE,
393  SSH_OPTIONS_HOSTKEYS,
394  SSH_OPTIONS_GSSAPI_SERVER_IDENTITY,
395  SSH_OPTIONS_GSSAPI_CLIENT_IDENTITY,
396  SSH_OPTIONS_GSSAPI_DELEGATE_CREDENTIALS,
397  SSH_OPTIONS_HMAC_C_S,
398  SSH_OPTIONS_HMAC_S_C,
399  SSH_OPTIONS_PASSWORD_AUTH,
400  SSH_OPTIONS_PUBKEY_AUTH,
401  SSH_OPTIONS_KBDINT_AUTH,
402  SSH_OPTIONS_GSSAPI_AUTH,
403  SSH_OPTIONS_GLOBAL_KNOWNHOSTS,
404  SSH_OPTIONS_NODELAY,
405  SSH_OPTIONS_PUBLICKEY_ACCEPTED_TYPES,
406  SSH_OPTIONS_PROCESS_CONFIG,
407  SSH_OPTIONS_REKEY_DATA,
408  SSH_OPTIONS_REKEY_TIME,
409  SSH_OPTIONS_RSA_MIN_SIZE,
410  SSH_OPTIONS_IDENTITY_AGENT,
411 };
412 
413 enum {
415  SSH_SCP_WRITE,
417  SSH_SCP_READ,
418  SSH_SCP_RECURSIVE=0x10
419 };
420 
421 enum ssh_scp_request_types {
423  SSH_SCP_REQUEST_NEWDIR=1,
425  SSH_SCP_REQUEST_NEWFILE,
427  SSH_SCP_REQUEST_EOF,
429  SSH_SCP_REQUEST_ENDDIR,
431  SSH_SCP_REQUEST_WARNING
432 };
433 
434 enum ssh_connector_flags_e {
436  SSH_CONNECTOR_STDOUT = 1,
437  SSH_CONNECTOR_STDINOUT = 1,
439  SSH_CONNECTOR_STDERR = 2,
441  SSH_CONNECTOR_BOTH = 3
442 };
443 
444 LIBSSH_API int ssh_blocking_flush(ssh_session session, int timeout);
445 LIBSSH_API ssh_channel ssh_channel_accept_x11(ssh_channel channel, int timeout_ms);
446 LIBSSH_API int ssh_channel_change_pty_size(ssh_channel channel,int cols,int rows);
447 LIBSSH_API int ssh_channel_close(ssh_channel channel);
448 LIBSSH_API void ssh_channel_free(ssh_channel channel);
449 LIBSSH_API int ssh_channel_get_exit_status(ssh_channel channel);
451 LIBSSH_API int ssh_channel_is_closed(ssh_channel channel);
452 LIBSSH_API int ssh_channel_is_eof(ssh_channel channel);
453 LIBSSH_API int ssh_channel_is_open(ssh_channel channel);
454 LIBSSH_API ssh_channel ssh_channel_new(ssh_session session);
455 LIBSSH_API int ssh_channel_open_auth_agent(ssh_channel channel);
456 LIBSSH_API int ssh_channel_open_forward(ssh_channel channel, const char *remotehost,
457  int remoteport, const char *sourcehost, int localport);
458 LIBSSH_API int ssh_channel_open_forward_unix(ssh_channel channel, const char *remotepath,
459  const char *sourcehost, int localport);
460 LIBSSH_API int ssh_channel_open_session(ssh_channel channel);
461 LIBSSH_API int ssh_channel_open_x11(ssh_channel channel, const char *orig_addr, int orig_port);
462 LIBSSH_API int ssh_channel_poll(ssh_channel channel, int is_stderr);
463 LIBSSH_API int ssh_channel_poll_timeout(ssh_channel channel, int timeout, int is_stderr);
464 LIBSSH_API int ssh_channel_read(ssh_channel channel, void *dest, uint32_t count, int is_stderr);
465 LIBSSH_API int ssh_channel_read_timeout(ssh_channel channel, void *dest, uint32_t count, int is_stderr, int timeout_ms);
466 LIBSSH_API int ssh_channel_read_nonblocking(ssh_channel channel, void *dest, uint32_t count,
467  int is_stderr);
468 LIBSSH_API int ssh_channel_request_env(ssh_channel channel, const char *name, const char *value);
469 LIBSSH_API int ssh_channel_request_exec(ssh_channel channel, const char *cmd);
470 LIBSSH_API int ssh_channel_request_pty(ssh_channel channel);
471 LIBSSH_API int ssh_channel_request_pty_size(ssh_channel channel, const char *term,
472  int cols, int rows);
473 LIBSSH_API int ssh_channel_request_shell(ssh_channel channel);
474 LIBSSH_API int ssh_channel_request_send_signal(ssh_channel channel, const char *signum);
475 LIBSSH_API int ssh_channel_request_send_break(ssh_channel channel, uint32_t length);
476 LIBSSH_API int ssh_channel_request_sftp(ssh_channel channel);
477 LIBSSH_API int ssh_channel_request_subsystem(ssh_channel channel, const char *subsystem);
478 LIBSSH_API int ssh_channel_request_x11(ssh_channel channel, int single_connection, const char *protocol,
479  const char *cookie, int screen_number);
480 LIBSSH_API int ssh_channel_request_auth_agent(ssh_channel channel);
481 LIBSSH_API int ssh_channel_send_eof(ssh_channel channel);
482 LIBSSH_API void ssh_channel_set_blocking(ssh_channel channel, int blocking);
483 LIBSSH_API void ssh_channel_set_counter(ssh_channel channel,
484  ssh_counter counter);
485 LIBSSH_API int ssh_channel_write(ssh_channel channel, const void *data, uint32_t len);
486 LIBSSH_API int ssh_channel_write_stderr(ssh_channel channel,
487  const void *data,
488  uint32_t len);
489 LIBSSH_API uint32_t ssh_channel_window_size(ssh_channel channel);
490 
491 LIBSSH_API char *ssh_basename (const char *path);
492 LIBSSH_API void ssh_clean_pubkey_hash(unsigned char **hash);
493 LIBSSH_API int ssh_connect(ssh_session session);
494 
495 LIBSSH_API ssh_connector ssh_connector_new(ssh_session session);
496 LIBSSH_API void ssh_connector_free(ssh_connector connector);
497 LIBSSH_API int ssh_connector_set_in_channel(ssh_connector connector,
498  ssh_channel channel,
499  enum ssh_connector_flags_e flags);
500 LIBSSH_API int ssh_connector_set_out_channel(ssh_connector connector,
501  ssh_channel channel,
502  enum ssh_connector_flags_e flags);
503 LIBSSH_API void ssh_connector_set_in_fd(ssh_connector connector, socket_t fd);
504 LIBSSH_API void ssh_connector_set_out_fd(ssh_connector connector, socket_t fd);
505 
506 LIBSSH_API const char *ssh_copyright(void);
507 LIBSSH_API void ssh_disconnect(ssh_session session);
508 LIBSSH_API char *ssh_dirname (const char *path);
509 LIBSSH_API int ssh_finalize(void);
510 
511 /* REVERSE PORT FORWARDING */
513  int timeout_ms,
514  int *destination_port,
515  char **originator,
516  int *originator_port);
517 SSH_DEPRECATED LIBSSH_API ssh_channel ssh_channel_accept_forward(ssh_session session,
518  int timeout_ms,
519  int *destination_port);
520 LIBSSH_API int ssh_channel_cancel_forward(ssh_session session,
521  const char *address,
522  int port);
523 LIBSSH_API int ssh_channel_listen_forward(ssh_session session,
524  const char *address,
525  int port,
526  int *bound_port);
527 
528 LIBSSH_API void ssh_free(ssh_session session);
529 LIBSSH_API const char *ssh_get_disconnect_message(ssh_session session);
530 LIBSSH_API const char *ssh_get_error(void *error);
531 LIBSSH_API int ssh_get_error_code(void *error);
532 LIBSSH_API socket_t ssh_get_fd(ssh_session session);
533 LIBSSH_API char *ssh_get_hexa(const unsigned char *what, size_t len);
534 LIBSSH_API char *ssh_get_issue_banner(ssh_session session);
535 LIBSSH_API int ssh_get_openssh_version(ssh_session session);
536 
537 LIBSSH_API int ssh_get_server_publickey(ssh_session session, ssh_key *key);
538 
539 enum ssh_publickey_hash_type {
540  SSH_PUBLICKEY_HASH_SHA1,
541  SSH_PUBLICKEY_HASH_MD5,
542  SSH_PUBLICKEY_HASH_SHA256
543 };
544 LIBSSH_API int ssh_get_publickey_hash(const ssh_key key,
545  enum ssh_publickey_hash_type type,
546  unsigned char **hash,
547  size_t *hlen);
548 
549 /* DEPRECATED FUNCTIONS */
550 SSH_DEPRECATED LIBSSH_API int ssh_get_pubkey_hash(ssh_session session, unsigned char **hash);
551 SSH_DEPRECATED LIBSSH_API ssh_channel ssh_forward_accept(ssh_session session, int timeout_ms);
552 SSH_DEPRECATED LIBSSH_API int ssh_forward_cancel(ssh_session session, const char *address, int port);
553 SSH_DEPRECATED LIBSSH_API int ssh_forward_listen(ssh_session session, const char *address, int port, int *bound_port);
554 SSH_DEPRECATED LIBSSH_API int ssh_get_publickey(ssh_session session, ssh_key *key);
555 SSH_DEPRECATED LIBSSH_API int ssh_write_knownhost(ssh_session session);
556 SSH_DEPRECATED LIBSSH_API char *ssh_dump_knownhost(ssh_session session);
557 SSH_DEPRECATED LIBSSH_API int ssh_is_server_known(ssh_session session);
558 SSH_DEPRECATED LIBSSH_API void ssh_print_hexa(const char *descr, const unsigned char *what, size_t len);
559 SSH_DEPRECATED LIBSSH_API int ssh_channel_select(ssh_channel *readchans, ssh_channel *writechans, ssh_channel *exceptchans, struct
560  timeval * timeout);
561 
562 SSH_DEPRECATED LIBSSH_API int ssh_scp_accept_request(ssh_scp scp);
563 SSH_DEPRECATED LIBSSH_API int ssh_scp_close(ssh_scp scp);
564 SSH_DEPRECATED LIBSSH_API int ssh_scp_deny_request(ssh_scp scp, const char *reason);
565 SSH_DEPRECATED LIBSSH_API void ssh_scp_free(ssh_scp scp);
566 SSH_DEPRECATED LIBSSH_API int ssh_scp_init(ssh_scp scp);
567 SSH_DEPRECATED LIBSSH_API int ssh_scp_leave_directory(ssh_scp scp);
568 SSH_DEPRECATED LIBSSH_API ssh_scp ssh_scp_new(ssh_session session, int mode, const char *location);
569 SSH_DEPRECATED LIBSSH_API int ssh_scp_pull_request(ssh_scp scp);
570 SSH_DEPRECATED LIBSSH_API int ssh_scp_push_directory(ssh_scp scp, const char *dirname, int mode);
571 SSH_DEPRECATED LIBSSH_API int ssh_scp_push_file(ssh_scp scp, const char *filename, size_t size, int perms);
572 SSH_DEPRECATED LIBSSH_API int ssh_scp_push_file64(ssh_scp scp, const char *filename, uint64_t size, int perms);
573 SSH_DEPRECATED LIBSSH_API int ssh_scp_read(ssh_scp scp, void *buffer, size_t size);
574 SSH_DEPRECATED LIBSSH_API const char *ssh_scp_request_get_filename(ssh_scp scp);
575 SSH_DEPRECATED LIBSSH_API int ssh_scp_request_get_permissions(ssh_scp scp);
576 SSH_DEPRECATED LIBSSH_API size_t ssh_scp_request_get_size(ssh_scp scp);
577 SSH_DEPRECATED LIBSSH_API uint64_t ssh_scp_request_get_size64(ssh_scp scp);
578 SSH_DEPRECATED LIBSSH_API const char *ssh_scp_request_get_warning(ssh_scp scp);
579 SSH_DEPRECATED LIBSSH_API int ssh_scp_write(ssh_scp scp, const void *buffer, size_t len);
580 
581 
582 LIBSSH_API int ssh_get_random(void *where,int len,int strong);
583 LIBSSH_API int ssh_get_version(ssh_session session);
584 LIBSSH_API int ssh_get_status(ssh_session session);
585 LIBSSH_API int ssh_get_poll_flags(ssh_session session);
586 LIBSSH_API int ssh_init(void);
587 LIBSSH_API int ssh_is_blocking(ssh_session session);
588 LIBSSH_API int ssh_is_connected(ssh_session session);
589 
590 /* KNOWN HOSTS */
591 LIBSSH_API void ssh_knownhosts_entry_free(struct ssh_knownhosts_entry *entry);
592 #define SSH_KNOWNHOSTS_ENTRY_FREE(e) do { \
593  if ((e) != NULL) { \
594  ssh_knownhosts_entry_free(e); \
595  e = NULL; \
596  } \
597 } while(0)
598 
599 LIBSSH_API int ssh_known_hosts_parse_line(const char *host,
600  const char *line,
601  struct ssh_knownhosts_entry **entry);
602 LIBSSH_API enum ssh_known_hosts_e ssh_session_has_known_hosts_entry(ssh_session session);
603 
605  char **pentry_string);
606 LIBSSH_API int ssh_session_update_known_hosts(ssh_session session);
607 
608 LIBSSH_API enum ssh_known_hosts_e ssh_session_get_known_hosts_entry(ssh_session session,
609  struct ssh_knownhosts_entry **pentry);
610 LIBSSH_API enum ssh_known_hosts_e ssh_session_is_known_server(ssh_session session);
611 
612 /* LOGGING */
613 LIBSSH_API int ssh_set_log_level(int level);
614 LIBSSH_API int ssh_get_log_level(void);
615 LIBSSH_API void *ssh_get_log_userdata(void);
616 LIBSSH_API int ssh_set_log_userdata(void *data);
617 LIBSSH_API void ssh_vlog(int verbosity,
618  const char *function,
619  const char *format,
620  va_list *va) PRINTF_ATTRIBUTE(3, 0);
621 LIBSSH_API void _ssh_log(int verbosity,
622  const char *function,
623  const char *format, ...) PRINTF_ATTRIBUTE(3, 4);
624 
625 /* legacy */
626 SSH_DEPRECATED LIBSSH_API void ssh_log(ssh_session session,
627  int prioriry,
628  const char *format, ...) PRINTF_ATTRIBUTE(3, 4);
629 
630 LIBSSH_API ssh_channel ssh_message_channel_request_open_reply_accept(ssh_message msg);
631 LIBSSH_API int ssh_message_channel_request_open_reply_accept_channel(ssh_message msg, ssh_channel chan);
632 LIBSSH_API int ssh_message_channel_request_reply_success(ssh_message msg);
633 #define SSH_MESSAGE_FREE(x) \
634  do { if ((x) != NULL) { ssh_message_free(x); (x) = NULL; } } while(0)
635 LIBSSH_API void ssh_message_free(ssh_message msg);
636 LIBSSH_API ssh_message ssh_message_get(ssh_session session);
637 LIBSSH_API int ssh_message_subtype(ssh_message msg);
638 LIBSSH_API int ssh_message_type(ssh_message msg);
639 LIBSSH_API int ssh_mkdir (const char *pathname, mode_t mode);
640 LIBSSH_API ssh_session ssh_new(void);
641 
642 LIBSSH_API int ssh_options_copy(ssh_session src, ssh_session *dest);
643 LIBSSH_API int ssh_options_getopt(ssh_session session, int *argcptr, char **argv);
644 LIBSSH_API int ssh_options_parse_config(ssh_session session, const char *filename);
645 LIBSSH_API int ssh_options_set(ssh_session session, enum ssh_options_e type,
646  const void *value);
647 LIBSSH_API int ssh_options_get(ssh_session session, enum ssh_options_e type,
648  char **value);
649 LIBSSH_API int ssh_options_get_port(ssh_session session, unsigned int * port_target);
650 LIBSSH_API int ssh_pcap_file_close(ssh_pcap_file pcap);
651 LIBSSH_API void ssh_pcap_file_free(ssh_pcap_file pcap);
652 LIBSSH_API ssh_pcap_file ssh_pcap_file_new(void);
653 LIBSSH_API int ssh_pcap_file_open(ssh_pcap_file pcap, const char *filename);
654 
674 typedef int (*ssh_auth_callback) (const char *prompt, char *buf, size_t len,
675  int echo, int verify, void *userdata);
676 
679 LIBSSH_API ssh_key ssh_key_new(void);
680 #define SSH_KEY_FREE(x) \
681  do { if ((x) != NULL) { ssh_key_free(x); x = NULL; } } while(0)
682 LIBSSH_API void ssh_key_free (ssh_key key);
683 LIBSSH_API enum ssh_keytypes_e ssh_key_type(const ssh_key key);
684 LIBSSH_API const char *ssh_key_type_to_char(enum ssh_keytypes_e type);
685 LIBSSH_API enum ssh_keytypes_e ssh_key_type_from_name(const char *name);
686 LIBSSH_API int ssh_key_is_public(const ssh_key k);
687 LIBSSH_API int ssh_key_is_private(const ssh_key k);
688 LIBSSH_API int ssh_key_cmp(const ssh_key k1,
689  const ssh_key k2,
690  enum ssh_keycmp_e what);
691 LIBSSH_API ssh_key ssh_key_dup(const ssh_key key);
692 
693 LIBSSH_API int ssh_pki_generate(enum ssh_keytypes_e type, int parameter,
694  ssh_key *pkey);
695 LIBSSH_API int ssh_pki_import_privkey_base64(const char *b64_key,
696  const char *passphrase,
697  ssh_auth_callback auth_fn,
698  void *auth_data,
699  ssh_key *pkey);
700 LIBSSH_API int ssh_pki_export_privkey_base64(const ssh_key privkey,
701  const char *passphrase,
702  ssh_auth_callback auth_fn,
703  void *auth_data,
704  char **b64_key);
705 LIBSSH_API int ssh_pki_import_privkey_file(const char *filename,
706  const char *passphrase,
707  ssh_auth_callback auth_fn,
708  void *auth_data,
709  ssh_key *pkey);
710 LIBSSH_API int ssh_pki_export_privkey_file(const ssh_key privkey,
711  const char *passphrase,
712  ssh_auth_callback auth_fn,
713  void *auth_data,
714  const char *filename);
715 
716 LIBSSH_API int ssh_pki_copy_cert_to_privkey(const ssh_key cert_key,
717  ssh_key privkey);
718 
719 LIBSSH_API int ssh_pki_import_pubkey_base64(const char *b64_key,
720  enum ssh_keytypes_e type,
721  ssh_key *pkey);
722 LIBSSH_API int ssh_pki_import_pubkey_file(const char *filename,
723  ssh_key *pkey);
724 
725 LIBSSH_API int ssh_pki_import_cert_base64(const char *b64_cert,
726  enum ssh_keytypes_e type,
727  ssh_key *pkey);
728 LIBSSH_API int ssh_pki_import_cert_file(const char *filename,
729  ssh_key *pkey);
730 
731 LIBSSH_API int ssh_pki_export_privkey_to_pubkey(const ssh_key privkey,
732  ssh_key *pkey);
733 LIBSSH_API int ssh_pki_export_pubkey_base64(const ssh_key key,
734  char **b64_key);
735 LIBSSH_API int ssh_pki_export_pubkey_file(const ssh_key key,
736  const char *filename);
737 
738 LIBSSH_API const char *ssh_pki_key_ecdsa_name(const ssh_key key);
739 
740 LIBSSH_API char *ssh_get_fingerprint_hash(enum ssh_publickey_hash_type type,
741  unsigned char *hash,
742  size_t len);
743 LIBSSH_API void ssh_print_hash(enum ssh_publickey_hash_type type, unsigned char *hash, size_t len);
744 LIBSSH_API int ssh_send_ignore (ssh_session session, const char *data);
745 LIBSSH_API int ssh_send_debug (ssh_session session, const char *message, int always_display);
746 LIBSSH_API void ssh_gssapi_set_creds(ssh_session session, const ssh_gssapi_creds creds);
747 LIBSSH_API int ssh_select(ssh_channel *channels, ssh_channel *outchannels, socket_t maxfd,
748  fd_set *readfds, struct timeval *timeout);
749 LIBSSH_API int ssh_service_request(ssh_session session, const char *service);
750 LIBSSH_API int ssh_set_agent_channel(ssh_session session, ssh_channel channel);
751 LIBSSH_API int ssh_set_agent_socket(ssh_session session, socket_t fd);
752 LIBSSH_API void ssh_set_blocking(ssh_session session, int blocking);
753 LIBSSH_API void ssh_set_counters(ssh_session session, ssh_counter scounter,
754  ssh_counter rcounter);
755 LIBSSH_API void ssh_set_fd_except(ssh_session session);
756 LIBSSH_API void ssh_set_fd_toread(ssh_session session);
757 LIBSSH_API void ssh_set_fd_towrite(ssh_session session);
758 LIBSSH_API void ssh_silent_disconnect(ssh_session session);
759 LIBSSH_API int ssh_set_pcap_file(ssh_session session, ssh_pcap_file pcapfile);
760 
761 /* USERAUTH */
762 LIBSSH_API int ssh_userauth_none(ssh_session session, const char *username);
763 LIBSSH_API int ssh_userauth_list(ssh_session session, const char *username);
764 LIBSSH_API int ssh_userauth_try_publickey(ssh_session session,
765  const char *username,
766  const ssh_key pubkey);
767 LIBSSH_API int ssh_userauth_publickey(ssh_session session,
768  const char *username,
769  const ssh_key privkey);
770 #ifndef _WIN32
771 LIBSSH_API int ssh_userauth_agent(ssh_session session,
772  const char *username);
773 #endif
775  char** value);
776 LIBSSH_API int ssh_userauth_publickey_auto(ssh_session session,
777  const char *username,
778  const char *passphrase);
779 LIBSSH_API int ssh_userauth_password(ssh_session session,
780  const char *username,
781  const char *password);
782 
783 LIBSSH_API int ssh_userauth_kbdint(ssh_session session, const char *user, const char *submethods);
784 LIBSSH_API const char *ssh_userauth_kbdint_getinstruction(ssh_session session);
785 LIBSSH_API const char *ssh_userauth_kbdint_getname(ssh_session session);
786 LIBSSH_API int ssh_userauth_kbdint_getnprompts(ssh_session session);
787 LIBSSH_API const char *ssh_userauth_kbdint_getprompt(ssh_session session, unsigned int i, char *echo);
788 LIBSSH_API int ssh_userauth_kbdint_getnanswers(ssh_session session);
789 LIBSSH_API const char *ssh_userauth_kbdint_getanswer(ssh_session session, unsigned int i);
790 LIBSSH_API int ssh_userauth_kbdint_setanswer(ssh_session session, unsigned int i,
791  const char *answer);
792 LIBSSH_API int ssh_userauth_gssapi(ssh_session session);
793 LIBSSH_API const char *ssh_version(int req_version);
794 
795 LIBSSH_API void ssh_string_burn(ssh_string str);
796 LIBSSH_API ssh_string ssh_string_copy(ssh_string str);
797 LIBSSH_API void *ssh_string_data(ssh_string str);
798 LIBSSH_API int ssh_string_fill(ssh_string str, const void *data, size_t len);
799 #define SSH_STRING_FREE(x) \
800  do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
801 LIBSSH_API void ssh_string_free(ssh_string str);
802 LIBSSH_API ssh_string ssh_string_from_char(const char *what);
803 LIBSSH_API size_t ssh_string_len(ssh_string str);
804 LIBSSH_API ssh_string ssh_string_new(size_t size);
805 LIBSSH_API const char *ssh_string_get_char(ssh_string str);
806 LIBSSH_API char *ssh_string_to_char(ssh_string str);
807 #define SSH_STRING_FREE_CHAR(x) \
808  do { if ((x) != NULL) { ssh_string_free_char(x); x = NULL; } } while(0)
809 LIBSSH_API void ssh_string_free_char(char *s);
810 
811 LIBSSH_API int ssh_getpass(const char *prompt, char *buf, size_t len, int echo,
812  int verify);
813 
814 
815 typedef int (*ssh_event_callback)(socket_t fd, int revents, void *userdata);
816 
817 LIBSSH_API ssh_event ssh_event_new(void);
818 LIBSSH_API int ssh_event_add_fd(ssh_event event, socket_t fd, short events,
819  ssh_event_callback cb, void *userdata);
820 LIBSSH_API int ssh_event_add_session(ssh_event event, ssh_session session);
821 LIBSSH_API int ssh_event_add_connector(ssh_event event, ssh_connector connector);
822 LIBSSH_API int ssh_event_dopoll(ssh_event event, int timeout);
823 LIBSSH_API int ssh_event_remove_fd(ssh_event event, socket_t fd);
824 LIBSSH_API int ssh_event_remove_session(ssh_event event, ssh_session session);
825 LIBSSH_API int ssh_event_remove_connector(ssh_event event, ssh_connector connector);
826 LIBSSH_API void ssh_event_free(ssh_event event);
827 LIBSSH_API const char* ssh_get_clientbanner(ssh_session session);
828 LIBSSH_API const char* ssh_get_serverbanner(ssh_session session);
829 LIBSSH_API const char* ssh_get_kex_algo(ssh_session session);
830 LIBSSH_API const char* ssh_get_cipher_in(ssh_session session);
831 LIBSSH_API const char* ssh_get_cipher_out(ssh_session session);
832 LIBSSH_API const char* ssh_get_hmac_in(ssh_session session);
833 LIBSSH_API const char* ssh_get_hmac_out(ssh_session session);
834 
835 LIBSSH_API ssh_buffer ssh_buffer_new(void);
836 LIBSSH_API void ssh_buffer_free(ssh_buffer buffer);
837 #define SSH_BUFFER_FREE(x) \
838  do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
839 LIBSSH_API int ssh_buffer_reinit(ssh_buffer buffer);
840 LIBSSH_API int ssh_buffer_add_data(ssh_buffer buffer, const void *data, uint32_t len);
841 LIBSSH_API uint32_t ssh_buffer_get_data(ssh_buffer buffer, void *data, uint32_t requestedlen);
842 LIBSSH_API void *ssh_buffer_get(ssh_buffer buffer);
843 LIBSSH_API uint32_t ssh_buffer_get_len(ssh_buffer buffer);
844 LIBSSH_API int ssh_session_set_disconnect_message(ssh_session session, const char *message);
845 
846 #ifndef LIBSSH_LEGACY_0_4
847 #include "libssh/legacy.h"
848 #endif
849 
850 #ifdef __cplusplus
851 }
852 #endif
853 #endif /* _LIBSSH_H */
LIBSSH_API int ssh_userauth_gssapi(ssh_session session)
Try to authenticate through the "gssapi-with-mic" method.
Definition: auth.c:2011
LIBSSH_API int ssh_userauth_list(ssh_session session, const char *username)
Get available authentication methods from the server.
Definition: auth.c:379
LIBSSH_API int ssh_userauth_kbdint_getnanswers(ssh_session session)
Get the number of answers the client has given.
Definition: auth.c:1913
int(* ssh_auth_callback)(const char *prompt, char *buf, size_t len, int echo, int verify, void *userdata)
SSH authentication callback for password and publickey auth.
Definition: libssh.h:674
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:1885
LIBSSH_API int ssh_userauth_password(ssh_session session, const char *username, const char *password)
Try to authenticate by password.
Definition: auth.c:1329
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:1087
LIBSSH_API int ssh_userauth_none(ssh_session session, const char *username)
Try to authenticate through the "none" method.
Definition: auth.c:409
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:493
LIBSSH_API const char * ssh_userauth_kbdint_getanswer(ssh_session session, unsigned int i)
Get the answer to a question from a message block.
Definition: auth.c:1930
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:1757
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:1963
LIBSSH_API int ssh_userauth_agent(ssh_session session, const char *username)
Try to do public key authentication with ssh agent.
Definition: auth.c:904
LIBSSH_API int ssh_userauth_publickey_auto_get_current_identity(ssh_session session, char **value)
Get the identity that is currently being processed by ssh_userauth_publickey_auto()
Definition: auth.c:1028
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:622
LIBSSH_API const char * ssh_userauth_kbdint_getinstruction(ssh_session session)
Get the "instruction" of the message block.
Definition: auth.c:1848
LIBSSH_API int ssh_userauth_kbdint_getnprompts(ssh_session session)
Get the number of prompts (questions) the server has given.
Definition: auth.c:1801
LIBSSH_API const char * ssh_userauth_kbdint_getname(ssh_session session)
Get the "name" of the message block.
Definition: auth.c:1824
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:676
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:594
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
void ssh_buffer_free(struct ssh_buffer_struct *buffer)
Deallocate a SSH buffer.
Definition: buffer.c:149
LIBSSH_API ssh_buffer ssh_buffer_new(void)
Create a new SSH buffer.
Definition: buffer.c:119
uint32_t ssh_buffer_get_len(struct ssh_buffer_struct *buffer)
Get the length of the buffer from the current position.
Definition: buffer.c:607
int ssh_buffer_reinit(struct ssh_buffer_struct *buffer)
Reinitialize a SSH buffer.
Definition: buffer.c:259
LIBSSH_API int ssh_channel_request_subsystem(ssh_channel channel, const char *subsystem)
Request a subsystem (for example "sftp").
Definition: channels.c:2010
LIBSSH_API int ssh_channel_send_eof(ssh_channel channel)
Send an end of file on the channel.
Definition: channels.c:1281
SSH_DEPRECATED 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:3420
LIBSSH_API int ssh_channel_poll(ssh_channel channel, int is_stderr)
Polls a channel for data to read.
Definition: channels.c:3158
LIBSSH_API void ssh_channel_set_blocking(ssh_channel channel, int blocking)
Put the channel into blocking or nonblocking mode.
Definition: channels.c:1683
LIBSSH_API int ssh_channel_close(ssh_channel channel)
Close a channel.
Definition: channels.c:1342
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:2974
LIBSSH_API int ssh_channel_request_pty(ssh_channel channel)
Request a PTY.
Definition: channels.c:1927
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:2554
LIBSSH_API int ssh_channel_request_sftp(ssh_channel channel)
Request sftp subsystem on the channel.
Definition: channels.c:2060
SSH_DEPRECATED 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 some information about incomming connection.
Definition: channels.c:2512
LIBSSH_API ssh_channel ssh_channel_open_forward_port(ssh_session session, int timeout_ms, int *destination_port, char **originator, int *originator_port)
Accept an incoming TCP/IP forwarding channel and get information about incomming connection.
Definition: channels.c:2535
LIBSSH_API ssh_channel ssh_channel_accept_x11(ssh_channel channel, int timeout_ms)
Accept an X11 forwarding channel.
Definition: channels.c:2238
LIBSSH_API int ssh_channel_request_exec(ssh_channel channel, const char *cmd)
Run a shell command without an interactive shell.
Definition: channels.c:2677
LIBSSH_API int ssh_channel_write(ssh_channel channel, const void *data, uint32_t len)
Blocking write on a channel.
Definition: channels.c:1614
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:1002
LIBSSH_API ssh_session ssh_channel_get_session(ssh_channel channel)
Recover the session in which belongs a channel.
Definition: channels.c:3272
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:2447
LIBSSH_API int ssh_channel_request_env(ssh_channel channel, const char *name, const char *value)
Set environment variables.
Definition: channels.c:2606
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:3576
LIBSSH_API int ssh_channel_open_forward_unix(ssh_channel channel, const char *remotepath, const char *sourcehost, int localport)
Open a TCP/IP - UNIX domain socket forwarding channel.
Definition: channels.c:1114
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:3312
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:2743
LIBSSH_API int ssh_channel_is_open(ssh_channel channel)
Check if the channel is open or not.
Definition: channels.c:1628
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:3099
LIBSSH_API void ssh_channel_set_counter(ssh_channel channel, ssh_counter counter)
Set the channel data counter.
Definition: channels.c:3555
LIBSSH_API int ssh_channel_is_closed(ssh_channel channel)
Check if the channel is closed or not.
Definition: channels.c:1645
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:2254
LIBSSH_API int ssh_channel_is_eof(ssh_channel channel)
Check if remote has sent an EOF.
Definition: channels.c:1660
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:3212
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:1863
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:2944
LIBSSH_API void ssh_channel_free(ssh_channel channel)
Close and free a channel.
Definition: channels.c:1180
LIBSSH_API ssh_channel ssh_channel_new(ssh_session session)
Allocate a new channel.
Definition: channels.c:87
LIBSSH_API uint32_t ssh_channel_window_size(ssh_channel channel)
Get the remote window size.
Definition: channels.c:1596
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:2114
LIBSSH_API int ssh_channel_open_x11(ssh_channel channel, const char *orig_addr, int orig_port)
Open a X11 channel.
Definition: channels.c:3671
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:1041
LIBSSH_API int ssh_channel_request_shell(ssh_channel channel)
Request a shell.
Definition: channels.c:1987
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:2788
LIBSSH_API int ssh_channel_open_session(ssh_channel channel)
Open a session channel (suited for a shell, not TCP forwarding).
Definition: channels.c:974
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:1947
LIBSSH_API int ssh_get_error_code(void *error)
Retrieve the error code from the last error.
Definition: error.c:148
LIBSSH_API const char * ssh_get_error(void *error)
Retrieve the error text message from the last error.
Definition: error.c:128
LIBSSH_API int ssh_set_log_userdata(void *data)
Set the userdata for the logging function.
Definition: log.c:249
LIBSSH_API void * ssh_get_log_userdata(void)
Get the userdata of the logging function.
Definition: log.c:233
LIBSSH_API int ssh_set_log_level(int level)
Set the log level of the library.
Definition: log.c:195
LIBSSH_API int ssh_get_log_level(void)
Get the log level of the library.
Definition: log.c:210
@ SSH_LOG_WARNING
Definition: libssh.h:333
@ SSH_LOG_PACKET
Definition: libssh.h:339
@ SSH_LOG_PROTOCOL
Definition: libssh.h:336
@ SSH_LOG_FUNCTIONS
Definition: libssh.h:342
@ SSH_LOG_NOLOG
Definition: libssh.h:330
LIBSSH_API int ssh_message_type(ssh_message msg)
Get the type of the message.
Definition: messages.c:549
LIBSSH_API int ssh_message_subtype(ssh_message msg)
Get the subtype of the message.
Definition: messages.c:564
LIBSSH_API ssh_message ssh_message_get(ssh_session session)
Retrieve a SSH message from a SSH session.
Definition: messages.c:516
LIBSSH_API void ssh_message_free(ssh_message msg)
Free a SSH message.
Definition: messages.c:588
SSH_DEPRECATED LIBSSH_API void ssh_print_hexa(const char *descr, const unsigned char *what, size_t len)
Definition: misc.c:442
LIBSSH_API int ssh_mkdir(const char *pathname, mode_t mode)
Attempts to create a directory with the given pathname.
Definition: misc.c:985
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: misc.c:413
LIBSSH_API char * ssh_basename(const char *path)
basename - parse filename component.
Definition: misc.c:933
LIBSSH_API char * ssh_dirname(const char *path)
Parse directory component.
Definition: misc.c:874
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:214
LIBSSH_API const char * ssh_version(int req_version)
Check if libssh is the required version or get the version string.
Definition: misc.c:664
LIBSSH_API void ssh_key_free(ssh_key key)
deallocate a SSH key
Definition: pki.c:193
LIBSSH_API int ssh_key_is_private(const ssh_key k)
Check if the key is a private key.
Definition: pki.c:665
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 private key from a file or a PKCS #11 device.
Definition: pki.c:932
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:2124
LIBSSH_API const char * ssh_key_type_to_char(enum ssh_keytypes_e type)
Convert a key type to a string.
Definition: pki.c:273
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:872
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:1034
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:562
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:684
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:2056
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 formatted key from a memory c-string
Definition: pki.c:809
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:2217
LIBSSH_API int ssh_pki_import_cert_base64(const char *b64_cert, enum ssh_keytypes_e type, ssh_key *pkey)
Import a base64 formatted certificate from a memory c-string.
Definition: pki.c:1898
LIBSSH_API int ssh_pki_import_cert_file(const char *filename, ssh_key *pkey)
Import a certificate from the given filename.
Definition: pki.c:1939
LIBSSH_API int ssh_key_is_public(const ssh_key k)
Check if the key has/is a public key.
Definition: pki.c:649
LIBSSH_API enum ssh_keytypes_e ssh_key_type(const ssh_key key)
returns the type of a ssh key
Definition: pki.c:212
LIBSSH_API ssh_key ssh_key_new(void)
creates a new empty SSH key
Definition: pki.c:130
LIBSSH_API int ssh_pki_import_pubkey_base64(const char *b64_key, enum ssh_keytypes_e type, ssh_key *pkey)
Import a base64 formatted public key from a memory c-string.
Definition: pki.c:1614
LIBSSH_API int ssh_pki_generate(enum ssh_keytypes_e type, int parameter, ssh_key *pkey)
Generates a keypair.
Definition: pki.c:1961
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:112
LIBSSH_API int ssh_pki_import_pubkey_file(const char *filename, ssh_key *pkey)
Import a public key from a file or a PKCS #11 device.
Definition: pki.c:1775
LIBSSH_API void ssh_event_free(ssh_event event)
Free an event context.
Definition: poll.c:1122
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:779
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:838
LIBSSH_API int ssh_event_add_session(ssh_event event, ssh_session session)
remove the poll handle from session and assign them to an event, when used in blocking mode.
Definition: poll.c:908
LIBSSH_API int ssh_event_remove_session(ssh_event event, ssh_session session)
Remove a session object from an event context.
Definition: poll.c:1053
LIBSSH_API int ssh_event_dopoll(ssh_event event, int timeout)
Poll all the sockets and sessions associated through an event object.
Definition: poll.c:986
LIBSSH_API int ssh_event_remove_connector(ssh_event event, ssh_connector connector)
Remove a connector from an event context.
Definition: poll.c:1108
LIBSSH_API int ssh_event_add_connector(ssh_event event, ssh_connector connector)
Add a connector to the SSH event loop.
Definition: poll.c:961
LIBSSH_API int ssh_event_remove_fd(ssh_event event, socket_t fd)
Remove a socket fd from an event context.
Definition: poll.c:1006
SSH_DEPRECATED LIBSSH_API int ssh_scp_read(ssh_scp scp, void *buffer, size_t size)
Read from a remote scp file.
Definition: scp.c:997
SSH_DEPRECATED LIBSSH_API int ssh_scp_write(ssh_scp scp, const void *buffer, size_t len)
Write into a remote scp file.
Definition: scp.c:664
SSH_DEPRECATED LIBSSH_API int ssh_scp_close(ssh_scp scp)
Close the scp channel.
Definition: scp.c:249
SSH_DEPRECATED LIBSSH_API int ssh_scp_init(ssh_scp scp)
Initialize the scp channel.
Definition: scp.c:125
SSH_DEPRECATED LIBSSH_API int ssh_scp_leave_directory(ssh_scp scp)
Leave a directory.
Definition: scp.c:423
SSH_DEPRECATED 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:1083
SSH_DEPRECATED 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:472
SSH_DEPRECATED 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:575
SSH_DEPRECATED 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:1102
SSH_DEPRECATED LIBSSH_API ssh_scp ssh_scp_new(ssh_session session, int mode, const char *location)
Create a new scp session.
Definition: scp.c:65
SSH_DEPRECATED 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:332
SSH_DEPRECATED 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:1066
SSH_DEPRECATED LIBSSH_API int ssh_scp_pull_request(ssh_scp scp)
Wait for a scp request (file, directory).
Definition: scp.c:795
SSH_DEPRECATED LIBSSH_API void ssh_scp_free(ssh_scp scp)
Free a scp context.
Definition: scp.c:296
SSH_DEPRECATED 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:909
SSH_DEPRECATED 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:955
SSH_DEPRECATED 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:1117
SSH_DEPRECATED LIBSSH_API const char * ssh_scp_request_get_warning(ssh_scp scp)
Get the warning string from a scp handle.
Definition: scp.c:1167
LIBSSH_API int ssh_connect(ssh_session session)
Connect to the ssh server.
Definition: client.c:516
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:609
LIBSSH_API void ssh_clean_pubkey_hash(unsigned char **hash)
Deallocate the hash obtained by ssh_get_pubkey_hash.
Definition: session.c:1052
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:422
LIBSSH_API int ssh_is_blocking(ssh_session session)
Return the blocking mode of libssh.
Definition: session.c:500
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:583
LIBSSH_API void ssh_disconnect(ssh_session session)
Disconnect from a session (client or server).
Definition: client.c:741
SSH_DEPRECATED LIBSSH_API char * ssh_dump_knownhost(ssh_session session)
This function is deprecated.
Definition: known_hosts.c:446
LIBSSH_API const char * ssh_get_clientbanner(ssh_session session)
get the client banner
Definition: session.c:336
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:438
LIBSSH_API void ssh_set_blocking(ssh_session session, int blocking)
Set the session in blocking/nonblocking mode.
Definition: session.c:485
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:453
LIBSSH_API const char * ssh_get_kex_algo(ssh_session session)
get the name of the current key exchange algorithm.
Definition: session.c:365
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:596
LIBSSH_API int ssh_is_connected(ssh_session session)
Check if we are connected.
Definition: session.c:551
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:923
LIBSSH_API int ssh_get_server_publickey(ssh_session session, ssh_key *key)
Get the server public key from a session.
Definition: session.c:1069
LIBSSH_API int ssh_send_debug(ssh_session session, const char *message, int always_display)
Send a debug message.
Definition: session.c:911
LIBSSH_API int ssh_blocking_flush(ssh_session session, int timeout)
Blocking flush of the outgoing buffer.
Definition: session.c:526
SSH_DEPRECATED LIBSSH_API int ssh_is_server_known(ssh_session session)
This function is deprecated.
Definition: known_hosts.c:304
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:739
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: session.c:1124
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:491
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:406
LIBSSH_API int ssh_options_parse_config(ssh_session session, const char *filename)
Parse the ssh config file.
Definition: options.c:1432
SSH_DEPRECATED LIBSSH_API int ssh_get_publickey(ssh_session session, ssh_key *key)
Definition: session.c:1091
LIBSSH_API int ssh_get_version(ssh_session session)
Get the protocol version of the session.
Definition: session.c:839
LIBSSH_API void ssh_set_counters(ssh_session session, ssh_counter scounter, ssh_counter rcounter)
Set the session data counters.
Definition: session.c:967
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:323
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 currently connected session.
Definition: knownhosts.c:1166
LIBSSH_API char * ssh_get_issue_banner(ssh_session session)
Get the issue banner from the server.
Definition: client.c:660
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:811
LIBSSH_API int ssh_options_getopt(ssh_session session, int *argcptr, char **argv)
Parse command line arguments.
Definition: options.c:1241
LIBSSH_API int ssh_session_update_known_hosts(ssh_session session)
Adds the currently connected server to the user known_hosts file.
Definition: knownhosts.c:996
LIBSSH_API void ssh_knownhosts_entry_free(struct ssh_knownhosts_entry *entry)
Free an allocated ssh_knownhosts_entry.
Definition: knownhosts.c:155
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....
Definition: options.c:1103
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:638
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:1161
LIBSSH_API ssh_session ssh_new(void)
Create a new ssh session.
Definition: session.c:59
LIBSSH_API int ssh_send_ignore(ssh_session session, const char *data)
Send a message that should be ignored.
Definition: session.c:876
LIBSSH_API int ssh_session_set_disconnect_message(ssh_session session, const char *message)
Add disconnect message when ssh_session is disconnected To add a disconnect message to give peer a be...
Definition: client.c:704
LIBSSH_API int ssh_get_status(ssh_session session)
Get session status.
Definition: session.c:756
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:687
LIBSSH_API const char * ssh_get_serverbanner(ssh_session session)
get the server banner
Definition: session.c:351
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:1291
LIBSSH_API const char * ssh_get_disconnect_message(ssh_session session)
Get the disconnect message from the server.
Definition: session.c:814
LIBSSH_API void ssh_silent_disconnect(ssh_session session)
Disconnect impolitely from a remote host by closing the socket.
Definition: session.c:468
LIBSSH_API void ssh_free(ssh_session session)
Deallocate a SSH session handle.
Definition: session.c:189
LIBSSH_API int ssh_get_poll_flags(ssh_session session)
Get poll flags for an external mainloop.
Definition: session.c:794
LIBSSH_API int ssh_options_copy(ssh_session src, ssh_session *dest)
Duplicate the options of a session structure.
Definition: options.c:67
SSH_DEPRECATED LIBSSH_API int ssh_write_knownhost(ssh_session session)
This function is deprecated.
Definition: known_hosts.c:514
SSH_DEPRECATED LIBSSH_API int ssh_get_pubkey_hash(ssh_session session, unsigned char **hash)
Definition: session.c:978
LIBSSH_API socket_t ssh_get_fd(ssh_session session)
Get the fd of a connection.
Definition: session.c:569
LIBSSH_API enum ssh_known_hosts_e ssh_session_has_known_hosts_entry(ssh_session session)
Check if the set hostname and port match an entry in known_hosts.
Definition: knownhosts.c:808
size_t ssh_string_len(struct ssh_string_struct *s)
Return the size of a SSH string.
Definition: string.c:136
LIBSSH_API ssh_string ssh_string_from_char(const char *what)
Create a ssh string using a C string.
Definition: string.c:108
char * ssh_string_to_char(struct ssh_string_struct *s)
Convert a SSH string to a C null-terminated string.
Definition: string.c:181
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
void ssh_string_burn(struct ssh_string_struct *s)
Destroy the data in a string so it couldn't appear in a core dump.
Definition: string.c:249
void ssh_string_free(struct ssh_string_struct *s)
Deallocate a SSH string object.
Definition: string.c:277
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
LIBSSH_API ssh_string ssh_string_new(size_t size)
Create a new SSH String object.
Definition: string.c:56
void * ssh_string_data(struct ssh_string_struct *s)
Get the payload of the string.
Definition: string.c:264
const char * ssh_string_get_char(struct ssh_string_struct *s)
Get the string as a C null-terminated string.
Definition: string.c:160
LIBSSH_API void ssh_string_free_char(char *s)
Deallocate a char string object.
Definition: string.c:209
LIBSSH_API int ssh_init(void)
Initialize global cryptographic data structures.
Definition: init.c:153
LIBSSH_API int ssh_finalize(void)
Finalize and clean up all libssh and cryptographic data structures.
Definition: init.c:238
Definition: agent.h:73
Definition: buffer.c:47
Definition: channels.h:62
Definition: connector.c:54
Definition: libssh.h:95
Definition: poll.c:764
Definition: pki.h:54
Definition: libssh.h:307
Definition: messages.h:85
Definition: scp.h:35
Definition: messages.h:47
Definition: session.h:110
Definition: string.h:29