|
libssh
0.7.2
|
00001 /* 00002 * This file is part of the SSH Library 00003 * 00004 * Copyright (c) 2009 Aris Adamantiadis <aris@0xbadc0de.be> 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2.1 of the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with this library; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00019 */ 00020 00021 /* callback.h 00022 * This file includes the public declarations for the libssh callback mechanism 00023 */ 00024 00025 #ifndef _SSH_CALLBACK_H 00026 #define _SSH_CALLBACK_H 00027 00028 #include <libssh/libssh.h> 00029 #include <string.h> 00030 00031 #ifdef __cplusplus 00032 extern "C" { 00033 #endif 00034 00049 typedef void (*ssh_callback_int) (int code, void *user); 00050 00059 typedef int (*ssh_callback_data) (const void *data, size_t len, void *user); 00060 00061 typedef void (*ssh_callback_int_int) (int code, int errno_code, void *user); 00062 00063 typedef int (*ssh_message_callback) (ssh_session, ssh_message message, void *user); 00064 typedef int (*ssh_channel_callback_int) (ssh_channel channel, int code, void *user); 00065 typedef int (*ssh_channel_callback_data) (ssh_channel channel, int code, void *data, size_t len, void *user); 00066 00074 typedef void (*ssh_log_callback) (ssh_session session, int priority, 00075 const char *message, void *userdata); 00076 00090 typedef void (*ssh_logging_callback) (int priority, 00091 const char *function, 00092 const char *buffer, 00093 void *userdata); 00094 00102 typedef void (*ssh_status_callback) (ssh_session session, float status, 00103 void *userdata); 00104 00112 typedef void (*ssh_global_request_callback) (ssh_session session, 00113 ssh_message message, void *userdata); 00114 00124 typedef ssh_channel (*ssh_channel_open_request_x11_callback) (ssh_session session, 00125 const char * originator_address, int originator_port, void *userdata); 00126 00130 struct ssh_callbacks_struct { 00132 size_t size; 00136 void *userdata; 00140 ssh_auth_callback auth_function; 00144 ssh_log_callback log_function; 00149 void (*connect_status_function)(void *userdata, float status); 00153 ssh_global_request_callback global_request_function; 00156 ssh_channel_open_request_x11_callback channel_open_request_x11_function; 00157 }; 00158 typedef struct ssh_callbacks_struct *ssh_callbacks; 00159 00173 typedef int (*ssh_auth_password_callback) (ssh_session session, const char *user, const char *password, 00174 void *userdata); 00175 00186 typedef int (*ssh_auth_none_callback) (ssh_session session, const char *user, void *userdata); 00187 00200 typedef int (*ssh_auth_gssapi_mic_callback) (ssh_session session, const char *user, const char *principal, 00201 void *userdata); 00202 00216 typedef int (*ssh_auth_pubkey_callback) (ssh_session session, const char *user, struct ssh_key_struct *pubkey, 00217 char signature_state, void *userdata); 00218 00219 00229 typedef int (*ssh_service_request_callback) (ssh_session session, const char *service, void *userdata); 00230 00239 typedef ssh_channel (*ssh_channel_open_request_session_callback) (ssh_session session, void *userdata); 00240 00241 /* 00242 * @brief handle the beginning of a GSSAPI authentication, server side. 00243 * @param session current session handler 00244 * @param user the username of the client 00245 * @param n_oid number of available oids 00246 * @param oids OIDs provided by the client 00247 * @returns an ssh_string containing the chosen OID, that's supported by both 00248 * client and server. 00249 * @warning It is not necessary to fill this callback in if libssh is linked 00250 * with libgssapi. 00251 */ 00252 typedef ssh_string (*ssh_gssapi_select_oid_callback) (ssh_session session, const char *user, 00253 int n_oid, ssh_string *oids, void *userdata); 00254 00255 /* 00256 * @brief handle the negociation of a security context, server side. 00257 * @param session current session handler 00258 * @param[in] input_token input token provided by client 00259 * @param[out] output_token output of the gssapi accept_sec_context method, 00260 * NULL after completion. 00261 * @returns SSH_OK if the token was generated correctly or accept_sec_context 00262 * returned GSS_S_COMPLETE 00263 * @returns SSH_ERROR in case of error 00264 * @warning It is not necessary to fill this callback in if libssh is linked 00265 * with libgssapi. 00266 */ 00267 typedef int (*ssh_gssapi_accept_sec_ctx_callback) (ssh_session session, 00268 ssh_string input_token, ssh_string *output_token, void *userdata); 00269 00270 /* 00271 * @brief Verify and authenticates a MIC, server side. 00272 * @param session current session handler 00273 * @param[in] mic input mic to be verified provided by client 00274 * @param[in] mic_buffer buffer of data to be signed. 00275 * @param[in] mic_buffer_size size of mic_buffer 00276 * @returns SSH_OK if the MIC was authenticated correctly 00277 * @returns SSH_ERROR in case of error 00278 * @warning It is not necessary to fill this callback in if libssh is linked 00279 * with libgssapi. 00280 */ 00281 typedef int (*ssh_gssapi_verify_mic_callback) (ssh_session session, 00282 ssh_string mic, void *mic_buffer, size_t mic_buffer_size, void *userdata); 00283 00284 00289 struct ssh_server_callbacks_struct { 00291 size_t size; 00295 void *userdata; 00299 ssh_auth_password_callback auth_password_function; 00300 00304 ssh_auth_none_callback auth_none_function; 00305 00309 ssh_auth_gssapi_mic_callback auth_gssapi_mic_function; 00310 00314 ssh_auth_pubkey_callback auth_pubkey_function; 00315 00319 ssh_service_request_callback service_request_function; 00323 ssh_channel_open_request_session_callback channel_open_request_session_function; 00326 ssh_gssapi_select_oid_callback gssapi_select_oid_function; 00329 ssh_gssapi_accept_sec_ctx_callback gssapi_accept_sec_ctx_function; 00330 /* This function will be called when a MIC needs to be verified. 00331 */ 00332 ssh_gssapi_verify_mic_callback gssapi_verify_mic_function; 00333 }; 00334 typedef struct ssh_server_callbacks_struct *ssh_server_callbacks; 00335 00357 LIBSSH_API int ssh_set_server_callbacks(ssh_session session, ssh_server_callbacks cb); 00358 00363 struct ssh_socket_callbacks_struct { 00367 void *userdata; 00372 ssh_callback_data data; 00376 ssh_callback_int controlflow; 00380 ssh_callback_int_int exception; 00384 ssh_callback_int_int connected; 00385 }; 00386 typedef struct ssh_socket_callbacks_struct *ssh_socket_callbacks; 00387 00388 #define SSH_SOCKET_FLOW_WRITEWILLBLOCK 1 00389 #define SSH_SOCKET_FLOW_WRITEWONTBLOCK 2 00390 00391 #define SSH_SOCKET_EXCEPTION_EOF 1 00392 #define SSH_SOCKET_EXCEPTION_ERROR 2 00393 00394 #define SSH_SOCKET_CONNECTED_OK 1 00395 #define SSH_SOCKET_CONNECTED_ERROR 2 00396 #define SSH_SOCKET_CONNECTED_TIMEOUT 3 00397 00405 #define ssh_callbacks_init(p) do {\ 00406 (p)->size=sizeof(*(p)); \ 00407 } while(0); 00408 00418 #define ssh_callbacks_exists(p,c) (\ 00419 (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \ 00420 ((p)-> c != NULL) \ 00421 ) 00422 00432 typedef int (*ssh_packet_callback) (ssh_session session, uint8_t type, ssh_buffer packet, void *user); 00433 00436 #define SSH_PACKET_USED 1 00437 00439 #define SSH_PACKET_NOT_USED 2 00440 00441 00449 #define SSH_PACKET_CALLBACK(name) \ 00450 int name (ssh_session session, uint8_t type, ssh_buffer packet, void *user) 00451 00452 struct ssh_packet_callbacks_struct { 00454 uint8_t start; 00456 uint8_t n_callbacks; 00458 ssh_packet_callback *callbacks; 00462 void *user; 00463 }; 00464 00465 typedef struct ssh_packet_callbacks_struct *ssh_packet_callbacks; 00466 00488 LIBSSH_API int ssh_set_callbacks(ssh_session session, ssh_callbacks cb); 00489 00501 typedef int (*ssh_channel_data_callback) (ssh_session session, 00502 ssh_channel channel, 00503 void *data, 00504 uint32_t len, 00505 int is_stderr, 00506 void *userdata); 00507 00514 typedef void (*ssh_channel_eof_callback) (ssh_session session, 00515 ssh_channel channel, 00516 void *userdata); 00517 00524 typedef void (*ssh_channel_close_callback) (ssh_session session, 00525 ssh_channel channel, 00526 void *userdata); 00527 00535 typedef void (*ssh_channel_signal_callback) (ssh_session session, 00536 ssh_channel channel, 00537 const char *signal, 00538 void *userdata); 00539 00546 typedef void (*ssh_channel_exit_status_callback) (ssh_session session, 00547 ssh_channel channel, 00548 int exit_status, 00549 void *userdata); 00550 00561 typedef void (*ssh_channel_exit_signal_callback) (ssh_session session, 00562 ssh_channel channel, 00563 const char *signal, 00564 int core, 00565 const char *errmsg, 00566 const char *lang, 00567 void *userdata); 00568 00581 typedef int (*ssh_channel_pty_request_callback) (ssh_session session, 00582 ssh_channel channel, 00583 const char *term, 00584 int width, int height, 00585 int pxwidth, int pwheight, 00586 void *userdata); 00587 00595 typedef int (*ssh_channel_shell_request_callback) (ssh_session session, 00596 ssh_channel channel, 00597 void *userdata); 00605 typedef void (*ssh_channel_auth_agent_req_callback) (ssh_session session, 00606 ssh_channel channel, 00607 void *userdata); 00608 00616 typedef void (*ssh_channel_x11_req_callback) (ssh_session session, 00617 ssh_channel channel, 00618 int single_connection, 00619 const char *auth_protocol, 00620 const char *auth_cookie, 00621 uint32_t screen_number, 00622 void *userdata); 00634 typedef int (*ssh_channel_pty_window_change_callback) (ssh_session session, 00635 ssh_channel channel, 00636 int width, int height, 00637 int pxwidth, int pwheight, 00638 void *userdata); 00639 00648 typedef int (*ssh_channel_exec_request_callback) (ssh_session session, 00649 ssh_channel channel, 00650 const char *command, 00651 void *userdata); 00652 00664 typedef int (*ssh_channel_env_request_callback) (ssh_session session, 00665 ssh_channel channel, 00666 const char *env_name, 00667 const char *env_value, 00668 void *userdata); 00677 typedef int (*ssh_channel_subsystem_request_callback) (ssh_session session, 00678 ssh_channel channel, 00679 const char *subsystem, 00680 void *userdata); 00681 00682 00683 struct ssh_channel_callbacks_struct { 00685 size_t size; 00689 void *userdata; 00693 ssh_channel_data_callback channel_data_function; 00697 ssh_channel_eof_callback channel_eof_function; 00701 ssh_channel_close_callback channel_close_function; 00705 ssh_channel_signal_callback channel_signal_function; 00709 ssh_channel_exit_status_callback channel_exit_status_function; 00713 ssh_channel_exit_signal_callback channel_exit_signal_function; 00717 ssh_channel_pty_request_callback channel_pty_request_function; 00721 ssh_channel_shell_request_callback channel_shell_request_function; 00725 ssh_channel_auth_agent_req_callback channel_auth_agent_req_function; 00729 ssh_channel_x11_req_callback channel_x11_req_function; 00733 ssh_channel_pty_window_change_callback channel_pty_window_change_function; 00737 ssh_channel_exec_request_callback channel_exec_request_function; 00741 ssh_channel_env_request_callback channel_env_request_function; 00745 ssh_channel_subsystem_request_callback channel_subsystem_request_function; 00746 }; 00747 00748 typedef struct ssh_channel_callbacks_struct *ssh_channel_callbacks; 00749 00771 LIBSSH_API int ssh_set_channel_callbacks(ssh_channel channel, 00772 ssh_channel_callbacks cb); 00773 00780 typedef int (*ssh_thread_callback) (void **lock); 00781 00782 typedef unsigned long (*ssh_thread_id_callback) (void); 00783 struct ssh_threads_callbacks_struct { 00784 const char *type; 00785 ssh_thread_callback mutex_init; 00786 ssh_thread_callback mutex_destroy; 00787 ssh_thread_callback mutex_lock; 00788 ssh_thread_callback mutex_unlock; 00789 ssh_thread_id_callback thread_id; 00790 }; 00791 00809 LIBSSH_API int ssh_threads_set_callbacks(struct ssh_threads_callbacks_struct 00810 *cb); 00811 00818 LIBSSH_API struct ssh_threads_callbacks_struct *ssh_threads_get_pthread(void); 00819 00830 LIBSSH_API struct ssh_threads_callbacks_struct *ssh_threads_get_noop(void); 00831 00839 LIBSSH_API int ssh_set_log_callback(ssh_logging_callback cb); 00840 00846 LIBSSH_API ssh_logging_callback ssh_get_log_callback(void); 00847 00849 #ifdef __cplusplus 00850 } 00851 #endif 00852 00853 #endif /*_SSH_CALLBACK_H */ 00854 00855 /* @} */
1.7.5.1