libssh  0.10.90
The SSH library
Loading...
Searching...
No Matches
callbacks.h
1/*
2 * This file is part of the SSH Library
3 *
4 * Copyright (c) 2009 Aris Adamantiadis <aris@0xbadc0de.be>
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/* callback.h
22 * This file includes the public declarations for the libssh callback mechanism
23 */
24
25#ifndef _SSH_CALLBACK_H
26#define _SSH_CALLBACK_H
27
28#include <libssh/libssh.h>
29#include <string.h>
30#include <stdbool.h>
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
50typedef void (*ssh_callback_int) (int code, void *user);
51
60typedef size_t (*ssh_callback_data) (const void *data, size_t len, void *user);
61
62typedef void (*ssh_callback_int_int) (int code, int errno_code, void *user);
63
64typedef int (*ssh_message_callback) (ssh_session, ssh_message message, void *user);
65typedef int (*ssh_channel_callback_int) (ssh_channel channel, int code, void *user);
66typedef int (*ssh_channel_callback_data) (ssh_channel channel, int code, void *data, size_t len, void *user);
67
75typedef void (*ssh_log_callback) (ssh_session session, int priority,
76 const char *message, void *userdata);
77
91typedef void (*ssh_logging_callback) (int priority,
92 const char *function,
93 const char *buffer,
94 void *userdata);
95
103typedef void (*ssh_status_callback) (ssh_session session, float status,
104 void *userdata);
105
113typedef void (*ssh_global_request_callback) (ssh_session session,
114 ssh_message message, void *userdata);
115
127typedef ssh_channel (*ssh_channel_open_request_x11_callback) (ssh_session session,
128 const char * originator_address, int originator_port, void *userdata);
129
139typedef ssh_channel (*ssh_channel_open_request_auth_agent_callback) (ssh_session session,
140 void *userdata);
141
157typedef ssh_channel (*ssh_channel_open_request_forwarded_tcpip_callback) (ssh_session session,
158 const char *destination_address, int destination_port,
159 const char *originator_address, int originator_port,
160 void *userdata);
161
201typedef struct ssh_callbacks_struct *ssh_callbacks;
202
216typedef int (*ssh_auth_password_callback) (ssh_session session, const char *user, const char *password,
217 void *userdata);
218
229typedef int (*ssh_auth_none_callback) (ssh_session session, const char *user, void *userdata);
230
243typedef int (*ssh_auth_gssapi_mic_callback) (ssh_session session, const char *user, const char *principal,
244 void *userdata);
245
259typedef int (*ssh_auth_pubkey_callback) (ssh_session session, const char *user, struct ssh_key_struct *pubkey,
260 char signature_state, void *userdata);
261
262
272typedef int (*ssh_service_request_callback) (ssh_session session, const char *service, void *userdata);
273
282typedef ssh_channel (*ssh_channel_open_request_session_callback) (ssh_session session, void *userdata);
283
284/*
285 * @brief handle the beginning of a GSSAPI authentication, server side.
286 * @param session current session handler
287 * @param user the username of the client
288 * @param n_oid number of available oids
289 * @param oids OIDs provided by the client
290 * @returns an ssh_string containing the chosen OID, that's supported by both
291 * client and server.
292 * @warning It is not necessary to fill this callback in if libssh is linked
293 * with libgssapi.
294 */
295typedef ssh_string (*ssh_gssapi_select_oid_callback) (ssh_session session, const char *user,
296 int n_oid, ssh_string *oids, void *userdata);
297
298/*
299 * @brief handle the negotiation of a security context, server side.
300 * @param session current session handler
301 * @param[in] input_token input token provided by client
302 * @param[out] output_token output of the gssapi accept_sec_context method,
303 * NULL after completion.
304 * @returns SSH_OK if the token was generated correctly or accept_sec_context
305 * returned GSS_S_COMPLETE
306 * @returns SSH_ERROR in case of error
307 * @warning It is not necessary to fill this callback in if libssh is linked
308 * with libgssapi.
309 */
310typedef int (*ssh_gssapi_accept_sec_ctx_callback) (ssh_session session,
311 ssh_string input_token, ssh_string *output_token, void *userdata);
312
313/*
314 * @brief Verify and authenticates a MIC, server side.
315 * @param session current session handler
316 * @param[in] mic input mic to be verified provided by client
317 * @param[in] mic_buffer buffer of data to be signed.
318 * @param[in] mic_buffer_size size of mic_buffer
319 * @returns SSH_OK if the MIC was authenticated correctly
320 * @returns SSH_ERROR in case of error
321 * @warning It is not necessary to fill this callback in if libssh is linked
322 * with libgssapi.
323 */
324typedef int (*ssh_gssapi_verify_mic_callback) (ssh_session session,
325 ssh_string mic, void *mic_buffer, size_t mic_buffer_size, void *userdata);
326
327
378
403LIBSSH_API int ssh_set_server_callbacks(ssh_session session, ssh_server_callbacks cb);
404
413 void *userdata;
418 ssh_callback_data data;
422 ssh_callback_int controlflow;
426 ssh_callback_int_int exception;
430 ssh_callback_int_int connected;
431};
433
434#define SSH_SOCKET_FLOW_WRITEWILLBLOCK 1
435#define SSH_SOCKET_FLOW_WRITEWONTBLOCK 2
436
437#define SSH_SOCKET_EXCEPTION_EOF 1
438#define SSH_SOCKET_EXCEPTION_ERROR 2
439
440#define SSH_SOCKET_CONNECTED_OK 1
441#define SSH_SOCKET_CONNECTED_ERROR 2
442#define SSH_SOCKET_CONNECTED_TIMEOUT 3
443
451#define ssh_callbacks_init(p) do {\
452 (p)->size=sizeof(*(p)); \
453} while(0);
454
464#define ssh_callbacks_exists(p,c) (\
465 (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
466 ((p)-> c != NULL) \
467 )
468
485#define ssh_callbacks_execute_list(list, cbtype, c, ...) \
486 do { \
487 struct ssh_iterator *i = ssh_list_get_iterator(list); \
488 cbtype cb; \
489 while (i != NULL){ \
490 cb = ssh_iterator_value(cbtype, i); \
491 if (ssh_callbacks_exists(cb, c)) \
492 cb-> c (__VA_ARGS__, cb->userdata); \
493 i = i->next; \
494 } \
495 } while(0)
496
517#define ssh_callbacks_iterate(_cb_list, _cb_type, _cb_name) \
518 do { \
519 struct ssh_iterator *_cb_i = ssh_list_get_iterator(_cb_list); \
520 _cb_type _cb; \
521 for (; _cb_i != NULL; _cb_i = _cb_i->next) { \
522 _cb = ssh_iterator_value(_cb_type, _cb_i); \
523 if (ssh_callbacks_exists(_cb, _cb_name))
524
525#define ssh_callbacks_iterate_exec(_cb_name, ...) \
526 _cb->_cb_name(__VA_ARGS__, _cb->userdata)
527
528#define ssh_callbacks_iterate_end() \
529 } \
530 } while(0)
531
541typedef int (*ssh_packet_callback) (ssh_session session, uint8_t type, ssh_buffer packet, void *user);
542
545#define SSH_PACKET_USED 1
548#define SSH_PACKET_NOT_USED 2
549
550
558#define SSH_PACKET_CALLBACK(name) \
559 int name (ssh_session session, uint8_t type, ssh_buffer packet, void *user)
560
561struct ssh_packet_callbacks_struct {
563 uint8_t start;
565 uint8_t n_callbacks;
567 ssh_packet_callback *callbacks;
571 void *user;
572};
573
574typedef struct ssh_packet_callbacks_struct *ssh_packet_callbacks;
575
600LIBSSH_API int ssh_set_callbacks(ssh_session session, ssh_callbacks cb);
601
613typedef int (*ssh_channel_data_callback) (ssh_session session,
614 ssh_channel channel,
615 void *data,
616 uint32_t len,
617 int is_stderr,
618 void *userdata);
619
626typedef void (*ssh_channel_eof_callback) (ssh_session session,
627 ssh_channel channel,
628 void *userdata);
629
636typedef void (*ssh_channel_close_callback) (ssh_session session,
637 ssh_channel channel,
638 void *userdata);
639
647typedef void (*ssh_channel_signal_callback) (ssh_session session,
648 ssh_channel channel,
649 const char *signal,
650 void *userdata);
651
659typedef void (*ssh_channel_exit_status_callback) (ssh_session session,
660 ssh_channel channel,
661 int exit_status,
662 void *userdata);
663
674typedef void (*ssh_channel_exit_signal_callback) (ssh_session session,
675 ssh_channel channel,
676 const char *signal,
677 int core,
678 const char *errmsg,
679 const char *lang,
680 void *userdata);
681
695typedef int (*ssh_channel_pty_request_callback) (ssh_session session,
696 ssh_channel channel,
697 const char *term,
698 int width, int height,
699 int pxwidth, int pwheight,
700 void *userdata);
701
710typedef int (*ssh_channel_shell_request_callback) (ssh_session session,
711 ssh_channel channel,
712 void *userdata);
721typedef void (*ssh_channel_auth_agent_req_callback) (ssh_session session,
722 ssh_channel channel,
723 void *userdata);
724
737typedef void (*ssh_channel_x11_req_callback) (ssh_session session,
738 ssh_channel channel,
739 int single_connection,
740 const char *auth_protocol,
741 const char *auth_cookie,
742 uint32_t screen_number,
743 void *userdata);
756typedef int (*ssh_channel_pty_window_change_callback) (ssh_session session,
757 ssh_channel channel,
758 int width, int height,
759 int pxwidth, int pwheight,
760 void *userdata);
761
771typedef int (*ssh_channel_exec_request_callback) (ssh_session session,
772 ssh_channel channel,
773 const char *command,
774 void *userdata);
775
788typedef int (*ssh_channel_env_request_callback) (ssh_session session,
789 ssh_channel channel,
790 const char *env_name,
791 const char *env_value,
792 void *userdata);
802typedef int (*ssh_channel_subsystem_request_callback) (ssh_session session,
803 ssh_channel channel,
804 const char *subsystem,
805 void *userdata);
806
821typedef int (*ssh_channel_write_wontblock_callback) (ssh_session session,
822 ssh_channel channel,
823 uint32_t bytes,
824 void *userdata);
825
833typedef void (*ssh_channel_open_resp_callback) (ssh_session session,
834 ssh_channel channel,
835 bool is_success,
836 void *userdata);
837
844typedef void (*ssh_channel_request_resp_callback) (ssh_session session,
845 ssh_channel channel,
846 void *userdata);
847
848struct ssh_channel_callbacks_struct {
850 size_t size;
854 void *userdata;
858 ssh_channel_data_callback channel_data_function;
862 ssh_channel_eof_callback channel_eof_function;
866 ssh_channel_close_callback channel_close_function;
870 ssh_channel_signal_callback channel_signal_function;
874 ssh_channel_exit_status_callback channel_exit_status_function;
878 ssh_channel_exit_signal_callback channel_exit_signal_function;
882 ssh_channel_pty_request_callback channel_pty_request_function;
886 ssh_channel_shell_request_callback channel_shell_request_function;
890 ssh_channel_auth_agent_req_callback channel_auth_agent_req_function;
894 ssh_channel_x11_req_callback channel_x11_req_function;
898 ssh_channel_pty_window_change_callback channel_pty_window_change_function;
902 ssh_channel_exec_request_callback channel_exec_request_function;
906 ssh_channel_env_request_callback channel_env_request_function;
910 ssh_channel_subsystem_request_callback channel_subsystem_request_function;
914 ssh_channel_write_wontblock_callback channel_write_wontblock_function;
918 ssh_channel_open_resp_callback channel_open_response_function;
922 ssh_channel_request_resp_callback channel_request_response_function;
923};
924
925typedef struct ssh_channel_callbacks_struct *ssh_channel_callbacks;
926
954LIBSSH_API int ssh_set_channel_callbacks(ssh_channel channel,
955 ssh_channel_callbacks cb);
956
973LIBSSH_API int ssh_add_channel_callbacks(ssh_channel channel,
974 ssh_channel_callbacks cb);
975
988LIBSSH_API int ssh_remove_channel_callbacks(ssh_channel channel,
989 ssh_channel_callbacks cb);
990
997typedef int (*ssh_thread_callback) (void **lock);
998
999typedef unsigned long (*ssh_thread_id_callback) (void);
1000struct ssh_threads_callbacks_struct {
1001 const char *type;
1002 ssh_thread_callback mutex_init;
1003 ssh_thread_callback mutex_destroy;
1004 ssh_thread_callback mutex_lock;
1005 ssh_thread_callback mutex_unlock;
1006 ssh_thread_id_callback thread_id;
1007};
1008
1026LIBSSH_API int ssh_threads_set_callbacks(struct ssh_threads_callbacks_struct
1027 *cb);
1028
1038LIBSSH_API struct ssh_threads_callbacks_struct *ssh_threads_get_default(void);
1039
1046LIBSSH_API struct ssh_threads_callbacks_struct *ssh_threads_get_pthread(void);
1047
1058LIBSSH_API struct ssh_threads_callbacks_struct *ssh_threads_get_noop(void);
1069
1076
1077#ifdef __cplusplus
1078}
1079#endif
1080
1081#endif /*_SSH_CALLBACK_H */
1082
1083/* @} */
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:684
void(* ssh_channel_request_resp_callback)(ssh_session session, ssh_channel channel, void *userdata)
SSH channel request response callback. Called when a response to the pending request is received.
Definition callbacks.h:844
int(* ssh_channel_pty_request_callback)(ssh_session session, ssh_channel channel, const char *term, int width, int height, int pxwidth, int pwheight, void *userdata)
SSH channel PTY request from a client.
Definition callbacks.h:695
LIBSSH_API int ssh_set_callbacks(ssh_session session, ssh_callbacks cb)
Set the session callback functions.
Definition callbacks.c:48
LIBSSH_API int ssh_add_channel_callbacks(ssh_channel channel, ssh_channel_callbacks cb)
Add channel callback functions.
Definition callbacks.c:109
int(* ssh_channel_pty_window_change_callback)(ssh_session session, ssh_channel channel, int width, int height, int pxwidth, int pwheight, void *userdata)
SSH channel PTY windows change (terminal size) from a client.
Definition callbacks.h:756
int(* ssh_channel_exec_request_callback)(ssh_session session, ssh_channel channel, const char *command, void *userdata)
SSH channel Exec request from a client.
Definition callbacks.h:771
void(* ssh_channel_x11_req_callback)(ssh_session session, ssh_channel channel, int single_connection, const char *auth_protocol, const char *auth_cookie, uint32_t screen_number, void *userdata)
SSH X11 request from the client. This request is sent by a client when X11 forwarding is requested(an...
Definition callbacks.h:737
int(* ssh_channel_shell_request_callback)(ssh_session session, ssh_channel channel, void *userdata)
SSH channel Shell request from a client.
Definition callbacks.h:710
int(* ssh_channel_data_callback)(ssh_session session, ssh_channel channel, void *data, uint32_t len, int is_stderr, void *userdata)
SSH channel data callback. Called when data is available on a channel.
Definition callbacks.h:613
void(* ssh_channel_eof_callback)(ssh_session session, ssh_channel channel, void *userdata)
SSH channel eof callback. Called when a channel receives EOF.
Definition callbacks.h:626
void(* ssh_channel_close_callback)(ssh_session session, ssh_channel channel, void *userdata)
SSH channel close callback. Called when a channel is closed by remote peer.
Definition callbacks.h:636
void(* ssh_channel_signal_callback)(ssh_session session, ssh_channel channel, const char *signal, void *userdata)
SSH channel signal callback. Called when a channel has received a signal.
Definition callbacks.h:647
int(* ssh_auth_pubkey_callback)(ssh_session session, const char *user, struct ssh_key_struct *pubkey, char signature_state, void *userdata)
SSH authentication callback.
Definition callbacks.h:259
int(* ssh_packet_callback)(ssh_session session, uint8_t type, ssh_buffer packet, void *user)
Prototype for a packet callback, to be called when a new packet arrives.
Definition callbacks.h:541
void(* ssh_channel_exit_status_callback)(ssh_session session, ssh_channel channel, int exit_status, void *userdata)
SSH channel exit status callback. Called when a channel has received an exit status.
Definition callbacks.h:659
ssh_channel(* ssh_channel_open_request_x11_callback)(ssh_session session, const char *originator_address, int originator_port, void *userdata)
Handles an SSH new channel open X11 request. This happens when the server sends back an X11 connectio...
Definition callbacks.h:127
int(* ssh_auth_none_callback)(ssh_session session, const char *user, void *userdata)
SSH authentication callback. Tries to authenticates user with the "none" method which is anonymous or...
Definition callbacks.h:229
void(* ssh_channel_open_resp_callback)(ssh_session session, ssh_channel channel, bool is_success, void *userdata)
SSH channel open callback. Called when a channel open succeeds or fails.
Definition callbacks.h:833
void(* ssh_log_callback)(ssh_session session, int priority, const char *message, void *userdata)
SSH log callback. All logging messages will go through this callback.
Definition callbacks.h:75
int(* ssh_service_request_callback)(ssh_session session, const char *service, void *userdata)
Handles an SSH service request.
Definition callbacks.h:272
ssh_channel(* ssh_channel_open_request_forwarded_tcpip_callback)(ssh_session session, const char *destination_address, int destination_port, const char *originator_address, int originator_port, void *userdata)
Handles an SSH new channel open "forwarded-tcpip" request. This happens when the server forwards an i...
Definition callbacks.h:157
LIBSSH_API int ssh_set_server_callbacks(ssh_session session, ssh_server_callbacks cb)
Set the session server callback functions.
Definition callbacks.c:133
ssh_channel(* ssh_channel_open_request_auth_agent_callback)(ssh_session session, void *userdata)
Handles an SSH new channel open "auth-agent" request. This happens when the server sends back an "aut...
Definition callbacks.h:139
int(* ssh_channel_write_wontblock_callback)(ssh_session session, ssh_channel channel, uint32_t bytes, void *userdata)
SSH channel write will not block (flow control).
Definition callbacks.h:821
int(* ssh_auth_gssapi_mic_callback)(ssh_session session, const char *user, const char *principal, void *userdata)
SSH authentication callback. Tries to authenticates user with the "gssapi-with-mic" method.
Definition callbacks.h:243
void(* ssh_logging_callback)(int priority, const char *function, const char *buffer, void *userdata)
SSH log callback.
Definition callbacks.h:91
void(* ssh_status_callback)(ssh_session session, float status, void *userdata)
SSH Connection status callback.
Definition callbacks.h:103
ssh_channel(* ssh_channel_open_request_session_callback)(ssh_session session, void *userdata)
Handles an SSH new channel open session request.
Definition callbacks.h:282
void(* ssh_channel_exit_signal_callback)(ssh_session session, ssh_channel channel, const char *signal, int core, const char *errmsg, const char *lang, void *userdata)
SSH channel exit signal callback. Called when a channel has received an exit signal.
Definition callbacks.h:674
LIBSSH_API int ssh_set_channel_callbacks(ssh_channel channel, ssh_channel_callbacks cb)
Set the channel callback functions.
Definition callbacks.c:104
int(* ssh_auth_password_callback)(ssh_session session, const char *user, const char *password, void *userdata)
SSH authentication callback.
Definition callbacks.h:216
LIBSSH_API int ssh_remove_channel_callbacks(ssh_channel channel, ssh_channel_callbacks cb)
Remove a channel callback.
Definition callbacks.c:114
int(* ssh_channel_env_request_callback)(ssh_session session, ssh_channel channel, const char *env_name, const char *env_value, void *userdata)
SSH channel environment request from a client.
Definition callbacks.h:788
void(* ssh_global_request_callback)(ssh_session session, ssh_message message, void *userdata)
SSH global request callback. All global request will go through this callback.
Definition callbacks.h:113
void(* ssh_channel_auth_agent_req_callback)(ssh_session session, ssh_channel channel, void *userdata)
SSH auth-agent-request from the client. This request is sent by a client when agent forwarding is ava...
Definition callbacks.h:721
int(* ssh_channel_subsystem_request_callback)(ssh_session session, ssh_channel channel, const char *subsystem, void *userdata)
SSH channel subsystem request from a client.
Definition callbacks.h:802
LIBSSH_API ssh_logging_callback ssh_get_log_callback(void)
Get the pointer to the logging callback function.
Definition log.c:224
LIBSSH_API int ssh_set_log_callback(ssh_logging_callback cb)
Set the logging callback function.
Definition log.c:214
LIBSSH_API struct ssh_threads_callbacks_struct * ssh_threads_get_pthread(void)
Returns a pointer on the pthread threads callbacks, to be used with ssh_threads_set_callbacks.
Definition pthread.c:137
LIBSSH_API struct ssh_threads_callbacks_struct * ssh_threads_get_default(void)
Returns a pointer to the appropriate callbacks structure for the environment, to be used with ssh_thr...
Definition noop.c:65
LIBSSH_API struct ssh_threads_callbacks_struct * ssh_threads_get_noop(void)
Get the noop threads callbacks structure.
Definition noop.c:71
LIBSSH_API int ssh_threads_set_callbacks(struct ssh_threads_callbacks_struct *cb)
Set the thread callbacks structure.
Definition threads.c:71
Definition callbacks.h:165
ssh_channel_open_request_auth_agent_callback channel_open_request_auth_agent_function
Definition callbacks.h:194
ssh_log_callback log_function
Definition callbacks.h:179
ssh_auth_callback auth_function
Definition callbacks.h:175
ssh_channel_open_request_x11_callback channel_open_request_x11_function
Definition callbacks.h:191
void * userdata
Definition callbacks.h:171
ssh_channel_open_request_forwarded_tcpip_callback channel_open_request_forwarded_tcpip_function
Definition callbacks.h:199
size_t size
Definition callbacks.h:167
void(* connect_status_function)(void *userdata, float status)
Definition callbacks.h:184
ssh_global_request_callback global_request_function
Definition callbacks.h:188
Definition callbacks.h:332
ssh_gssapi_accept_sec_ctx_callback gssapi_accept_sec_ctx_function
Definition callbacks.h:372
ssh_service_request_callback service_request_function
Definition callbacks.h:362
size_t size
Definition callbacks.h:334
ssh_auth_none_callback auth_none_function
Definition callbacks.h:347
ssh_auth_gssapi_mic_callback auth_gssapi_mic_function
Definition callbacks.h:352
ssh_channel_open_request_session_callback channel_open_request_session_function
Definition callbacks.h:366
ssh_auth_password_callback auth_password_function
Definition callbacks.h:342
ssh_auth_pubkey_callback auth_pubkey_function
Definition callbacks.h:357
void * userdata
Definition callbacks.h:338
ssh_gssapi_select_oid_callback gssapi_select_oid_function
Definition callbacks.h:369
Definition callbacks.h:409
void * userdata
Definition callbacks.h:413
ssh_callback_data data
Definition callbacks.h:418
ssh_callback_int_int connected
Definition callbacks.h:430
ssh_callback_int controlflow
Definition callbacks.h:422
ssh_callback_int_int exception
Definition callbacks.h:426