Blame include/libssh/callbacks.h

Packit Service 31306d
/*
Packit Service 31306d
 * This file is part of the SSH Library
Packit Service 31306d
 *
Packit Service 31306d
 * Copyright (c) 2009 Aris Adamantiadis <aris@0xbadc0de.be>
Packit Service 31306d
 *
Packit Service 31306d
 * This library is free software; you can redistribute it and/or
Packit Service 31306d
 * modify it under the terms of the GNU Lesser General Public
Packit Service 31306d
 * License as published by the Free Software Foundation; either
Packit Service 31306d
 * version 2.1 of the License, or (at your option) any later version.
Packit Service 31306d
 *
Packit Service 31306d
 * This library is distributed in the hope that it will be useful,
Packit Service 31306d
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 31306d
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 31306d
 * Lesser General Public License for more details.
Packit Service 31306d
 *
Packit Service 31306d
 * You should have received a copy of the GNU Lesser General Public
Packit Service 31306d
 * License along with this library; if not, write to the Free Software
Packit Service 31306d
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Packit Service 31306d
 */
Packit Service 31306d
Packit Service 31306d
/* callback.h
Packit Service 31306d
 * This file includes the public declarations for the libssh callback mechanism
Packit Service 31306d
 */
Packit Service 31306d
Packit Service 31306d
#ifndef _SSH_CALLBACK_H
Packit Service 31306d
#define _SSH_CALLBACK_H
Packit Service 31306d
Packit Service 31306d
#include <libssh/libssh.h>
Packit Service 31306d
#include <string.h>
Packit Service 31306d
Packit Service 31306d
#ifdef __cplusplus
Packit Service 31306d
extern "C" {
Packit Service 31306d
#endif
Packit Service 31306d
Packit Service 31306d
/**
Packit Service 31306d
 * @defgroup libssh_callbacks The libssh callbacks
Packit Service 31306d
 * @ingroup libssh
Packit Service 31306d
 *
Packit Service 31306d
 * Callback which can be replaced in libssh.
Packit Service 31306d
 *
Packit Service 31306d
 * @{
Packit Service 31306d
 */
Packit Service 31306d
Packit Service 31306d
/** @internal
Packit Service 31306d
 * @brief callback to process simple codes
Packit Service 31306d
 * @param code value to transmit
Packit Service 31306d
 * @param user Userdata to pass in callback
Packit Service 31306d
 */
Packit Service 31306d
typedef void (*ssh_callback_int) (int code, void *user);
Packit Service 31306d
Packit Service 31306d
/** @internal
Packit Service 31306d
 * @brief callback for data received messages.
Packit Service 31306d
 * @param data data retrieved from the socket or stream
Packit Service 31306d
 * @param len number of bytes available from this stream
Packit Service 31306d
 * @param user user-supplied pointer sent along with all callback messages
Packit Service 31306d
 * @returns number of bytes processed by the callee. The remaining bytes will
Packit Service 31306d
 * be sent in the next callback message, when more data is available.
Packit Service 31306d
 */
Packit Service 31306d
typedef int (*ssh_callback_data) (const void *data, size_t len, void *user);
Packit Service 31306d
Packit Service 31306d
typedef void (*ssh_callback_int_int) (int code, int errno_code, void *user);
Packit Service 31306d
Packit Service 31306d
typedef int (*ssh_message_callback) (ssh_session, ssh_message message, void *user);
Packit Service 31306d
typedef int (*ssh_channel_callback_int) (ssh_channel channel, int code, void *user);
Packit Service 31306d
typedef int (*ssh_channel_callback_data) (ssh_channel channel, int code, void *data, size_t len, void *user);
Packit Service 31306d
Packit Service 31306d
/**
Packit Service 31306d
 * @brief SSH log callback. All logging messages will go through this callback
Packit Service 31306d
 * @param session Current session handler
Packit Service 31306d
 * @param priority Priority of the log, the smaller being the more important
Packit Service 31306d
 * @param message the actual message
Packit Service 31306d
 * @param userdata Userdata to be passed to the callback function.
Packit Service 31306d
 */
Packit Service 31306d
typedef void (*ssh_log_callback) (ssh_session session, int priority,
Packit Service 31306d
    const char *message, void *userdata);
Packit Service 31306d
Packit Service 31306d
/**
Packit Service 31306d
 * @brief SSH log callback.
Packit Service 31306d
 *
Packit Service 31306d
 * All logging messages will go through this callback.
Packit Service 31306d
 *
Packit Service 31306d
 * @param priority  Priority of the log, the smaller being the more important.
Packit Service 31306d
 *
Packit Service 31306d
 * @param function  The function name calling the the logging fucntions.
Packit Service 31306d
 *
Packit Service 31306d
 * @param message   The actual message
Packit Service 31306d
 *
Packit Service 31306d
 * @param userdata Userdata to be passed to the callback function.
Packit Service 31306d
 */
Packit Service 31306d
typedef void (*ssh_logging_callback) (int priority,
Packit Service 31306d
                                      const char *function,
Packit Service 31306d
                                      const char *buffer,
Packit Service 31306d
                                      void *userdata);
Packit Service 31306d
Packit Service 31306d
/**
Packit Service 31306d
 * @brief SSH Connection status callback.
Packit Service 31306d
 * @param session Current session handler
Packit Service 31306d
 * @param status Percentage of connection status, going from 0.0 to 1.0
Packit Service 31306d
 * once connection is done.
Packit Service 31306d
 * @param userdata Userdata to be passed to the callback function.
Packit Service 31306d
 */
Packit Service 31306d
typedef void (*ssh_status_callback) (ssh_session session, float status,
Packit Service 31306d
		void *userdata);
Packit Service 31306d
Packit Service 31306d
/**
Packit Service 31306d
 * @brief SSH global request callback. All global request will go through this
Packit Service 31306d
 * callback.
Packit Service 31306d
 * @param session Current session handler
Packit Service 31306d
 * @param message the actual message
Packit Service 31306d
 * @param userdata Userdata to be passed to the callback function.
Packit Service 31306d
 */
Packit Service 31306d
typedef void (*ssh_global_request_callback) (ssh_session session,
Packit Service 31306d
                                        ssh_message message, void *userdata);
Packit Service 31306d
Packit Service 31306d
/**
Packit Service 31306d
 * @brief Handles an SSH new channel open X11 request. This happens when the server
Packit Service 31306d
 * sends back an X11 connection attempt. This is a client-side API
Packit Service 31306d
 * @param session current session handler
Packit Service 31306d
 * @param userdata Userdata to be passed to the callback function.
Packit Service 31306d
 * @returns a valid ssh_channel handle if the request is to be allowed
Packit Service 31306d
 * @returns NULL if the request should not be allowed
Packit Service 31306d
 * @warning The channel pointer returned by this callback must be closed by the application.
Packit Service 31306d
 */
Packit Service 31306d
typedef ssh_channel (*ssh_channel_open_request_x11_callback) (ssh_session session,
Packit Service 31306d
      const char * originator_address, int originator_port, void *userdata);
Packit Service 31306d
Packit Service 31306d
/**
Packit Service 31306d
 * @brief Handles an SSH new channel open "auth-agent" request. This happens when the server
Packit Service 31306d
 * sends back an "auth-agent" connection attempt. This is a client-side API
Packit Service 31306d
 * @param session current session handler
Packit Service 31306d
 * @param userdata Userdata to be passed to the callback function.
Packit Service 31306d
 * @returns a valid ssh_channel handle if the request is to be allowed
Packit Service 31306d
 * @returns NULL if the request should not be allowed
Packit Service 31306d
 * @warning The channel pointer returned by this callback must be closed by the application.
Packit Service 31306d
 */
Packit Service 31306d
typedef ssh_channel (*ssh_channel_open_request_auth_agent_callback) (ssh_session session,
Packit Service 31306d
      void *userdata);
Packit Service 31306d
Packit Service 31306d
/**
Packit Service 31306d
 * The structure to replace libssh functions with appropriate callbacks.
Packit Service 31306d
 */
Packit Service 31306d
struct ssh_callbacks_struct {
Packit Service 31306d
  /** DON'T SET THIS use ssh_callbacks_init() instead. */
Packit Service 31306d
  size_t size;
Packit Service 31306d
  /**
Packit Service 31306d
   * User-provided data. User is free to set anything he wants here
Packit Service 31306d
   */
Packit Service 31306d
  void *userdata;
Packit Service 31306d
  /**
Packit Service 31306d
   * This functions will be called if e.g. a keyphrase is needed.
Packit Service 31306d
   */
Packit Service 31306d
  ssh_auth_callback auth_function;
Packit Service 31306d
  /**
Packit Service 31306d
   * This function will be called each time a loggable event happens.
Packit Service 31306d
   */
Packit Service 31306d
  ssh_log_callback log_function;
Packit Service 31306d
  /**
Packit Service 31306d
   * This function gets called during connection time to indicate the
Packit Service 31306d
   * percentage of connection steps completed.
Packit Service 31306d
   */
Packit Service 31306d
  void (*connect_status_function)(void *userdata, float status);
Packit Service 31306d
  /**
Packit Service 31306d
   * This function will be called each time a global request is received.
Packit Service 31306d
   */
Packit Service 31306d
  ssh_global_request_callback global_request_function;
Packit Service 31306d
  /** This function will be called when an incoming X11 request is received.
Packit Service 31306d
   */
Packit Service 31306d
  ssh_channel_open_request_x11_callback channel_open_request_x11_function;
Packit Service 31306d
  /** This function will be called when an incoming "auth-agent" request is received.
Packit Service 31306d
   */
Packit Service 31306d
  ssh_channel_open_request_auth_agent_callback channel_open_request_auth_agent_function;
Packit Service 31306d
};
Packit Service 31306d
typedef struct ssh_callbacks_struct *ssh_callbacks;
Packit Service 31306d
Packit Service 31306d
/** These are callbacks used specifically in SSH servers.
Packit Service 31306d
 */
Packit Service 31306d
Packit Service 31306d
/**
Packit Service 31306d
 * @brief SSH authentication callback.
Packit Service 31306d
 * @param session Current session handler
Packit Service 31306d
 * @param user User that wants to authenticate
Packit Service 31306d
 * @param password Password used for authentication
Packit Service 31306d
 * @param userdata Userdata to be passed to the callback function.
Packit Service 31306d
 * @returns SSH_AUTH_SUCCESS Authentication is accepted.
Packit Service 31306d
 * @returns SSH_AUTH_PARTIAL Partial authentication, more authentication means are needed.
Packit Service 31306d
 * @returns SSH_AUTH_DENIED Authentication failed.
Packit Service 31306d
 */
Packit Service 31306d
typedef int (*ssh_auth_password_callback) (ssh_session session, const char *user, const char *password,
Packit Service 31306d
		void *userdata);
Packit Service 31306d
Packit Service 31306d
/**
Packit Service 31306d
 * @brief SSH authentication callback. Tries to authenticates user with the "none" method
Packit Service 31306d
 * which is anonymous or passwordless.
Packit Service 31306d
 * @param session Current session handler
Packit Service 31306d
 * @param user User that wants to authenticate
Packit Service 31306d
 * @param userdata Userdata to be passed to the callback function.
Packit Service 31306d
 * @returns SSH_AUTH_SUCCESS Authentication is accepted.
Packit Service 31306d
 * @returns SSH_AUTH_PARTIAL Partial authentication, more authentication means are needed.
Packit Service 31306d
 * @returns SSH_AUTH_DENIED Authentication failed.
Packit Service 31306d
 */
Packit Service 31306d
typedef int (*ssh_auth_none_callback) (ssh_session session, const char *user, void *userdata);
Packit Service 31306d
Packit Service 31306d
/**
Packit Service 31306d
 * @brief SSH authentication callback. Tries to authenticates user with the "gssapi-with-mic" method
Packit Service 31306d
 * @param session Current session handler
Packit Service 31306d
 * @param user Username of the user (can be spoofed)
Packit Service 31306d
 * @param principal Authenticated principal of the user, including realm.
Packit Service 31306d
 * @param userdata Userdata to be passed to the callback function.
Packit Service 31306d
 * @returns SSH_AUTH_SUCCESS Authentication is accepted.
Packit Service 31306d
 * @returns SSH_AUTH_PARTIAL Partial authentication, more authentication means are needed.
Packit Service 31306d
 * @returns SSH_AUTH_DENIED Authentication failed.
Packit Service 31306d
 * @warning Implementations should verify that parameter user matches in some way the principal.
Packit Service 31306d
 * user and principal can be different. Only the latter is guaranteed to be safe.
Packit Service 31306d
 */
Packit Service 31306d
typedef int (*ssh_auth_gssapi_mic_callback) (ssh_session session, const char *user, const char *principal,
Packit Service 31306d
		void *userdata);
Packit Service 31306d
Packit Service 31306d
/**
Packit Service 31306d
 * @brief SSH authentication callback.
Packit Service 31306d
 * @param session Current session handler
Packit Service 31306d
 * @param user User that wants to authenticate
Packit Service 31306d
 * @param pubkey public key used for authentication
Packit Service 31306d
 * @param signature_state SSH_PUBLICKEY_STATE_NONE if the key is not signed (simple public key probe),
Packit Service 31306d
 * 							SSH_PUBLICKEY_STATE_VALID if the signature is valid. Others values should be
Packit Service 31306d
 * 							replied with a SSH_AUTH_DENIED.
Packit Service 31306d
 * @param userdata Userdata to be passed to the callback function.
Packit Service 31306d
 * @returns SSH_AUTH_SUCCESS Authentication is accepted.
Packit Service 31306d
 * @returns SSH_AUTH_PARTIAL Partial authentication, more authentication means are needed.
Packit Service 31306d
 * @returns SSH_AUTH_DENIED Authentication failed.
Packit Service 31306d
 */
Packit Service 31306d
typedef int (*ssh_auth_pubkey_callback) (ssh_session session, const char *user, struct ssh_key_struct *pubkey,
Packit Service 31306d
		char signature_state, void *userdata);
Packit Service 31306d
Packit Service 31306d
Packit Service 31306d
/**
Packit Service 31306d
 * @brief Handles an SSH service request
Packit Service 31306d
 * @param session current session handler
Packit Service 31306d
 * @param service name of the service (e.g. "ssh-userauth") requested
Packit Service 31306d
 * @param userdata Userdata to be passed to the callback function.
Packit Service 31306d
 * @returns 0 if the request is to be allowed
Packit Service 31306d
 * @returns -1 if the request should not be allowed
Packit Service 31306d
 */
Packit Service 31306d
Packit Service 31306d
typedef int (*ssh_service_request_callback) (ssh_session session, const char *service, void *userdata);
Packit Service 31306d
Packit Service 31306d
/**
Packit Service 31306d
 * @brief Handles an SSH new channel open session request
Packit Service 31306d
 * @param session current session handler
Packit Service 31306d
 * @param userdata Userdata to be passed to the callback function.
Packit Service 31306d
 * @returns a valid ssh_channel handle if the request is to be allowed
Packit Service 31306d
 * @returns NULL if the request should not be allowed
Packit Service 31306d
 * @warning The channel pointer returned by this callback must be closed by the application.
Packit Service 31306d
 */
Packit Service 31306d
typedef ssh_channel (*ssh_channel_open_request_session_callback) (ssh_session session, void *userdata);
Packit Service 31306d
Packit Service 31306d
/*
Packit Service 31306d
 * @brief handle the beginning of a GSSAPI authentication, server side.
Packit Service 31306d
 * @param session current session handler
Packit Service 31306d
 * @param user the username of the client
Packit Service 31306d
 * @param n_oid number of available oids
Packit Service 31306d
 * @param oids OIDs provided by the client
Packit Service 31306d
 * @returns an ssh_string containing the chosen OID, that's supported by both
Packit Service 31306d
 * client and server.
Packit Service 31306d
 * @warning It is not necessary to fill this callback in if libssh is linked
Packit Service 31306d
 * with libgssapi.
Packit Service 31306d
 */
Packit Service 31306d
typedef ssh_string (*ssh_gssapi_select_oid_callback) (ssh_session session, const char *user,
Packit Service 31306d
		int n_oid, ssh_string *oids, void *userdata);
Packit Service 31306d
Packit Service 31306d
/*
Packit Service 31306d
 * @brief handle the negociation of a security context, server side.
Packit Service 31306d
 * @param session current session handler
Packit Service 31306d
 * @param[in] input_token input token provided by client
Packit Service 31306d
 * @param[out] output_token output of the gssapi accept_sec_context method,
Packit Service 31306d
 * 				NULL after completion.
Packit Service 31306d
 * @returns SSH_OK if the token was generated correctly or accept_sec_context
Packit Service 31306d
 * returned GSS_S_COMPLETE
Packit Service 31306d
 * @returns SSH_ERROR in case of error
Packit Service 31306d
 * @warning It is not necessary to fill this callback in if libssh is linked
Packit Service 31306d
 * with libgssapi.
Packit Service 31306d
 */
Packit Service 31306d
typedef int (*ssh_gssapi_accept_sec_ctx_callback) (ssh_session session,
Packit Service 31306d
		ssh_string input_token, ssh_string *output_token, void *userdata);
Packit Service 31306d
Packit Service 31306d
/*
Packit Service 31306d
 * @brief Verify and authenticates a MIC, server side.
Packit Service 31306d
 * @param session current session handler
Packit Service 31306d
 * @param[in] mic input mic to be verified provided by client
Packit Service 31306d
 * @param[in] mic_buffer buffer of data to be signed.
Packit Service 31306d
 * @param[in] mic_buffer_size size of mic_buffer
Packit Service 31306d
 * @returns SSH_OK if the MIC was authenticated correctly
Packit Service 31306d
 * @returns SSH_ERROR in case of error
Packit Service 31306d
 * @warning It is not necessary to fill this callback in if libssh is linked
Packit Service 31306d
 * with libgssapi.
Packit Service 31306d
 */
Packit Service 31306d
typedef int (*ssh_gssapi_verify_mic_callback) (ssh_session session,
Packit Service 31306d
		ssh_string mic, void *mic_buffer, size_t mic_buffer_size, void *userdata);
Packit Service 31306d
Packit Service 31306d
Packit Service 31306d
/**
Packit Service 31306d
 * This structure can be used to implement a libssh server, with appropriate callbacks.
Packit Service 31306d
 */
Packit Service 31306d
Packit Service 31306d
struct ssh_server_callbacks_struct {
Packit Service 31306d
  /** DON'T SET THIS use ssh_callbacks_init() instead. */
Packit Service 31306d
  size_t size;
Packit Service 31306d
  /**
Packit Service 31306d
   * User-provided data. User is free to set anything he wants here
Packit Service 31306d
   */
Packit Service 31306d
  void *userdata;
Packit Service 31306d
  /** This function gets called when a client tries to authenticate through
Packit Service 31306d
   * password method.
Packit Service 31306d
   */
Packit Service 31306d
  ssh_auth_password_callback auth_password_function;
Packit Service 31306d
Packit Service 31306d
  /** This function gets called when a client tries to authenticate through
Packit Service 31306d
   * none method.
Packit Service 31306d
   */
Packit Service 31306d
  ssh_auth_none_callback auth_none_function;
Packit Service 31306d
Packit Service 31306d
  /** This function gets called when a client tries to authenticate through
Packit Service 31306d
   * gssapi-mic method.
Packit Service 31306d
   */
Packit Service 31306d
  ssh_auth_gssapi_mic_callback auth_gssapi_mic_function;
Packit Service 31306d
Packit Service 31306d
  /** this function gets called when a client tries to authenticate or offer
Packit Service 31306d
   * a public key.
Packit Service 31306d
   */
Packit Service 31306d
  ssh_auth_pubkey_callback auth_pubkey_function;
Packit Service 31306d
Packit Service 31306d
  /** This functions gets called when a service request is issued by the
Packit Service 31306d
   * client
Packit Service 31306d
   */
Packit Service 31306d
  ssh_service_request_callback service_request_function;
Packit Service 31306d
  /** This functions gets called when a new channel request is issued by
Packit Service 31306d
   * the client
Packit Service 31306d
   */
Packit Service 31306d
  ssh_channel_open_request_session_callback channel_open_request_session_function;
Packit Service 31306d
  /** This function will be called when a new gssapi authentication is attempted.
Packit Service 31306d
   */
Packit Service 31306d
  ssh_gssapi_select_oid_callback gssapi_select_oid_function;
Packit Service 31306d
  /** This function will be called when a gssapi token comes in.
Packit Service 31306d
   */
Packit Service 31306d
  ssh_gssapi_accept_sec_ctx_callback gssapi_accept_sec_ctx_function;
Packit Service 31306d
  /* This function will be called when a MIC needs to be verified.
Packit Service 31306d
   */
Packit Service 31306d
  ssh_gssapi_verify_mic_callback gssapi_verify_mic_function;
Packit Service 31306d
};
Packit Service 31306d
typedef struct ssh_server_callbacks_struct *ssh_server_callbacks;
Packit Service 31306d
Packit Service 31306d
/**
Packit Service 31306d
 * @brief Set the session server callback functions.
Packit Service 31306d
 *
Packit Service 31306d
 * This functions sets the callback structure to use your own callback
Packit Service 31306d
 * functions for user authentication, new channels and requests.
Packit Service 31306d
 *
Packit Service 31306d
 * @code
Packit Service 31306d
 * struct ssh_server_callbacks_struct cb = {
Packit Service 31306d
 *   .userdata = data,
Packit Service 31306d
 *   .auth_password_function = my_auth_function
Packit Service 31306d
 * };
Packit Service 31306d
 * ssh_callbacks_init(&cb;;
Packit Service 31306d
 * ssh_set_server_callbacks(session, &cb;;
Packit Service 31306d
 * @endcode
Packit Service 31306d
 *
Packit Service 31306d
 * @param  session      The session to set the callback structure.
Packit Service 31306d
 *
Packit Service 31306d
 * @param  cb           The callback structure itself.
Packit Service 31306d
 *
Packit Service 31306d
 * @return SSH_OK on success, SSH_ERROR on error.
Packit Service 31306d
 */
Packit Service 31306d
LIBSSH_API int ssh_set_server_callbacks(ssh_session session, ssh_server_callbacks cb);
Packit Service 31306d
Packit Service 31306d
/**
Packit Service 31306d
 * These are the callbacks exported by the socket structure
Packit Service 31306d
 * They are called by the socket module when a socket event appears
Packit Service 31306d
 */
Packit Service 31306d
struct ssh_socket_callbacks_struct {
Packit Service 31306d
  /**
Packit Service 31306d
   * User-provided data. User is free to set anything he wants here
Packit Service 31306d
   */
Packit Service 31306d
  void *userdata;
Packit Service 31306d
	/**
Packit Service 31306d
	 * This function will be called each time data appears on socket. The data
Packit Service 31306d
	 * not consumed will appear on the next data event.
Packit Service 31306d
	 */
Packit Service 31306d
  ssh_callback_data data;
Packit Service 31306d
  /** This function will be called each time a controlflow state changes, i.e.
Packit Service 31306d
   * the socket is available for reading or writing.
Packit Service 31306d
   */
Packit Service 31306d
  ssh_callback_int controlflow;
Packit Service 31306d
  /** This function will be called each time an exception appears on socket. An
Packit Service 31306d
   * exception can be a socket problem (timeout, ...) or an end-of-file.
Packit Service 31306d
   */
Packit Service 31306d
  ssh_callback_int_int exception;
Packit Service 31306d
  /** This function is called when the ssh_socket_connect was used on the socket
Packit Service 31306d
   * on nonblocking state, and the connection successed.
Packit Service 31306d
   */
Packit Service 31306d
  ssh_callback_int_int connected;
Packit Service 31306d
};
Packit Service 31306d
typedef struct ssh_socket_callbacks_struct *ssh_socket_callbacks;
Packit Service 31306d
Packit Service 31306d
#define SSH_SOCKET_FLOW_WRITEWILLBLOCK 1
Packit Service 31306d
#define SSH_SOCKET_FLOW_WRITEWONTBLOCK 2
Packit Service 31306d
Packit Service 31306d
#define SSH_SOCKET_EXCEPTION_EOF 	     1
Packit Service 31306d
#define SSH_SOCKET_EXCEPTION_ERROR     2
Packit Service 31306d
Packit Service 31306d
#define SSH_SOCKET_CONNECTED_OK 			1
Packit Service 31306d
#define SSH_SOCKET_CONNECTED_ERROR 		2
Packit Service 31306d
#define SSH_SOCKET_CONNECTED_TIMEOUT 	3
Packit Service 31306d
Packit Service 31306d
/**
Packit Service 31306d
 * @brief Initializes an ssh_callbacks_struct
Packit Service 31306d
 * A call to this macro is mandatory when you have set a new
Packit Service 31306d
 * ssh_callback_struct structure. Its goal is to maintain the binary
Packit Service 31306d
 * compatibility with future versions of libssh as the structure
Packit Service 31306d
 * evolves with time.
Packit Service 31306d
 */
Packit Service 31306d
#define ssh_callbacks_init(p) do {\
Packit Service 31306d
	(p)->size=sizeof(*(p)); \
Packit Service 31306d
} while(0);
Packit Service 31306d
Packit Service 31306d
/**
Packit Service 31306d
 * @internal
Packit Service 31306d
 * @brief tests if a callback can be called without crash
Packit Service 31306d
 *  verifies that the struct size if big enough
Packit Service 31306d
 *  verifies that the callback pointer exists
Packit Service 31306d
 * @param p callback pointer
Packit Service 31306d
 * @param c callback name
Packit Service 31306d
 * @returns nonzero if callback can be called
Packit Service 31306d
 */
Packit Service 31306d
#define ssh_callbacks_exists(p,c) (\
Packit Service 31306d
  (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
Packit Service 31306d
  ((p)-> c != NULL) \
Packit Service 31306d
  )
Packit Service 31306d
Packit Service 31306d
/**
Packit Service 31306d
 * @internal
Packit Service 31306d
 *
Packit Service 31306d
 * @brief Iterate through a list of callback structures
Packit Service 31306d
 *
Packit Service 31306d
 * This tests for their validity and executes them. The userdata argument is
Packit Service 31306d
 * automatically passed through.
Packit Service 31306d
 *
Packit Service 31306d
 * @param list     list of callbacks
Packit Service 31306d
 *
Packit Service 31306d
 * @param cbtype   type of the callback
Packit Service 31306d
 *
Packit Service 31306d
 * @param c        callback name
Packit Service 31306d
 *
Packit Service 31306d
 * @param va_args parameters to be passed
Packit Service 31306d
 */
Packit Service 31306d
#define ssh_callbacks_execute_list(list, cbtype, c, ...)      \
Packit Service 31306d
    do {                                                      \
Packit Service 31306d
        struct ssh_iterator *i = ssh_list_get_iterator(list); \
Packit Service 31306d
        cbtype cb;                                            \
Packit Service 31306d
        while (i != NULL){                                    \
Packit Service 31306d
            cb = ssh_iterator_value(cbtype, i);               \
Packit Service 31306d
            if (ssh_callbacks_exists(cb, c))                  \
Packit Service 31306d
                cb-> c (__VA_ARGS__, cb->userdata);           \
Packit Service 31306d
            i = i->next;                                      \
Packit Service 31306d
        }                                                     \
Packit Service 31306d
    } while(0)
Packit Service 31306d
Packit Service 31306d
/**
Packit Service 31306d
 * @internal
Packit Service 31306d
 *
Packit Service 31306d
 * @brief iterate through a list of callback structures.
Packit Service 31306d
 *
Packit Service 31306d
 * This tests for their validity and give control back to the calling code to
Packit Service 31306d
 * execute them. Caller can decide to break the loop or continue executing the
Packit Service 31306d
 * callbacks with different parameters
Packit Service 31306d
 *
Packit Service 31306d
 * @code
Packit Service 31306d
 * ssh_callbacks_iterate(channel->callbacks, ssh_channel_callbacks,
Packit Service 31306d
 *                     channel_eof_function){
Packit Service 31306d
 *     rc = ssh_callbacks_iterate_exec(session, channel);
Packit Service 31306d
 *     if (rc != SSH_OK){
Packit Service 31306d
 *         break;
Packit Service 31306d
 *     }
Packit Service 31306d
 * }
Packit Service 31306d
 * ssh_callbacks_iterate_end();
Packit Service 31306d
 * @endcode
Packit Service 31306d
 */
Packit Service 31306d
#define ssh_callbacks_iterate(_cb_list, _cb_type, _cb_name)           \
Packit Service 31306d
    do {                                                              \
Packit Service 31306d
        struct ssh_iterator *_cb_i = ssh_list_get_iterator(_cb_list); \
Packit Service 31306d
        _cb_type _cb;                                                 \
Packit Service 31306d
        for (; _cb_i != NULL; _cb_i = _cb_i->next) {                  \
Packit Service 31306d
            _cb = ssh_iterator_value(_cb_type, _cb_i);                \
Packit Service 31306d
            if (ssh_callbacks_exists(_cb, _cb_name))
Packit Service 31306d
Packit Service 31306d
#define ssh_callbacks_iterate_exec(_cb_name, ...) \
Packit Service 31306d
                _cb->_cb_name(__VA_ARGS__, _cb->userdata)
Packit Service 31306d
Packit Service 31306d
#define ssh_callbacks_iterate_end() \
Packit Service 31306d
        }                           \
Packit Service 31306d
    } while(0)
Packit Service 31306d
Packit Service 31306d
/** @brief Prototype for a packet callback, to be called when a new packet arrives
Packit Service 31306d
 * @param session The current session of the packet
Packit Service 31306d
 * @param type packet type (see ssh2.h)
Packit Service 31306d
 * @param packet buffer containing the packet, excluding size, type and padding fields
Packit Service 31306d
 * @param user user argument to the callback
Packit Service 31306d
 * and are called each time a packet shows up
Packit Service 31306d
 * @returns SSH_PACKET_USED Packet was parsed and used
Packit Service 31306d
 * @returns SSH_PACKET_NOT_USED Packet was not used or understood, processing must continue
Packit Service 31306d
 */
Packit Service 31306d
typedef int (*ssh_packet_callback) (ssh_session session, uint8_t type, ssh_buffer packet, void *user);
Packit Service 31306d
Packit Service 31306d
/** return values for a ssh_packet_callback */
Packit Service 31306d
/** Packet was used and should not be parsed by another callback */
Packit Service 31306d
#define SSH_PACKET_USED 1
Packit Service 31306d
/** Packet was not used and should be passed to any other callback
Packit Service 31306d
 * available */
Packit Service 31306d
#define SSH_PACKET_NOT_USED 2
Packit Service 31306d
Packit Service 31306d
Packit Service 31306d
/** @brief This macro declares a packet callback handler
Packit Service 31306d
 * @code
Packit Service 31306d
 * SSH_PACKET_CALLBACK(mycallback){
Packit Service 31306d
 * ...
Packit Service 31306d
 * }
Packit Service 31306d
 * @endcode
Packit Service 31306d
 */
Packit Service 31306d
#define SSH_PACKET_CALLBACK(name) \
Packit Service 31306d
	int name (ssh_session session, uint8_t type, ssh_buffer packet, void *user)
Packit Service 31306d
Packit Service 31306d
struct ssh_packet_callbacks_struct {
Packit Service 31306d
	/** Index of the first packet type being handled */
Packit Service 31306d
	uint8_t start;
Packit Service 31306d
	/** Number of packets being handled by this callback struct */
Packit Service 31306d
	uint8_t n_callbacks;
Packit Service 31306d
	/** A pointer to n_callbacks packet callbacks */
Packit Service 31306d
	ssh_packet_callback *callbacks;
Packit Service 31306d
  /**
Packit Service 31306d
   * User-provided data. User is free to set anything he wants here
Packit Service 31306d
   */
Packit Service 31306d
	void *user;
Packit Service 31306d
};
Packit Service 31306d
Packit Service 31306d
typedef struct ssh_packet_callbacks_struct *ssh_packet_callbacks;
Packit Service 31306d
Packit Service 31306d
/**
Packit Service 31306d
 * @brief Set the session callback functions.
Packit Service 31306d
 *
Packit Service 31306d
 * This functions sets the callback structure to use your own callback
Packit Service 31306d
 * functions for auth, logging and status.
Packit Service 31306d
 *
Packit Service 31306d
 * @code
Packit Service 31306d
 * struct ssh_callbacks_struct cb = {
Packit Service 31306d
 *   .userdata = data,
Packit Service 31306d
 *   .auth_function = my_auth_function
Packit Service 31306d
 * };
Packit Service 31306d
 * ssh_callbacks_init(&cb;;
Packit Service 31306d
 * ssh_set_callbacks(session, &cb;;
Packit Service 31306d
 * @endcode
Packit Service 31306d
 *
Packit Service 31306d
 * @param  session      The session to set the callback structure.
Packit Service 31306d
 *
Packit Service 31306d
 * @param  cb           The callback structure itself.
Packit Service 31306d
 *
Packit Service 31306d
 * @return SSH_OK on success, SSH_ERROR on error.
Packit Service 31306d
 */
Packit Service 31306d
LIBSSH_API int ssh_set_callbacks(ssh_session session, ssh_callbacks cb);
Packit Service 31306d
Packit Service 31306d
/**
Packit Service 31306d
 * @brief SSH channel data callback. Called when data is available on a channel
Packit Service 31306d
 * @param session Current session handler
Packit Service 31306d
 * @param channel the actual channel
Packit Service 31306d
 * @param data the data that has been read on the channel
Packit Service 31306d
 * @param len the length of the data
Packit Service 31306d
 * @param is_stderr is 0 for stdout or 1 for stderr
Packit Service 31306d
 * @param userdata Userdata to be passed to the callback function.
Packit Service 31306d
 * @returns number of bytes processed by the callee. The remaining bytes will
Packit Service 31306d
 * be sent in the next callback message, when more data is available.
Packit Service 31306d
 */
Packit Service 31306d
typedef int (*ssh_channel_data_callback) (ssh_session session,
Packit Service 31306d
                                           ssh_channel channel,
Packit Service 31306d
                                           void *data,
Packit Service 31306d
                                           uint32_t len,
Packit Service 31306d
                                           int is_stderr,
Packit Service 31306d
                                           void *userdata);
Packit Service 31306d
Packit Service 31306d
/**
Packit Service 31306d
 * @brief SSH channel eof callback. Called when a channel receives EOF
Packit Service 31306d
 * @param session Current session handler
Packit Service 31306d
 * @param channel the actual channel
Packit Service 31306d
 * @param userdata Userdata to be passed to the callback function.
Packit Service 31306d
 */
Packit Service 31306d
typedef void (*ssh_channel_eof_callback) (ssh_session session,
Packit Service 31306d
                                           ssh_channel channel,
Packit Service 31306d
                                           void *userdata);
Packit Service 31306d
Packit Service 31306d
/**
Packit Service 31306d
 * @brief SSH channel close callback. Called when a channel is closed by remote peer
Packit Service 31306d
 * @param session Current session handler
Packit Service 31306d
 * @param channel the actual channel
Packit Service 31306d
 * @param userdata Userdata to be passed to the callback function.
Packit Service 31306d
 */
Packit Service 31306d
typedef void (*ssh_channel_close_callback) (ssh_session session,
Packit Service 31306d
                                            ssh_channel channel,
Packit Service 31306d
                                            void *userdata);
Packit Service 31306d
Packit Service 31306d
/**
Packit Service 31306d
 * @brief SSH channel signal callback. Called when a channel has received a signal
Packit Service 31306d
 * @param session Current session handler
Packit Service 31306d
 * @param channel the actual channel
Packit Service 31306d
 * @param signal the signal name (without the SIG prefix)
Packit Service 31306d
 * @param userdata Userdata to be passed to the callback function.
Packit Service 31306d
 */
Packit Service 31306d
typedef void (*ssh_channel_signal_callback) (ssh_session session,
Packit Service 31306d
                                            ssh_channel channel,
Packit Service 31306d
                                            const char *signal,
Packit Service 31306d
                                            void *userdata);
Packit Service 31306d
Packit Service 31306d
/**
Packit Service 31306d
 * @brief SSH channel exit status callback. Called when a channel has received an exit status
Packit Service 31306d
 * @param session Current session handler
Packit Service 31306d
 * @param channel the actual channel
Packit Service 31306d
 * @param userdata Userdata to be passed to the callback function.
Packit Service 31306d
 */
Packit Service 31306d
typedef void (*ssh_channel_exit_status_callback) (ssh_session session,
Packit Service 31306d
                                            ssh_channel channel,
Packit Service 31306d
                                            int exit_status,
Packit Service 31306d
                                            void *userdata);
Packit Service 31306d
Packit Service 31306d
/**
Packit Service 31306d
 * @brief SSH channel exit signal callback. Called when a channel has received an exit signal
Packit Service 31306d
 * @param session Current session handler
Packit Service 31306d
 * @param channel the actual channel
Packit Service 31306d
 * @param signal the signal name (without the SIG prefix)
Packit Service 31306d
 * @param core a boolean telling wether a core has been dumped or not
Packit Service 31306d
 * @param errmsg the description of the exception
Packit Service 31306d
 * @param lang the language of the description (format: RFC 3066)
Packit Service 31306d
 * @param userdata Userdata to be passed to the callback function.
Packit Service 31306d
 */
Packit Service 31306d
typedef void (*ssh_channel_exit_signal_callback) (ssh_session session,
Packit Service 31306d
                                            ssh_channel channel,
Packit Service 31306d
                                            const char *signal,
Packit Service 31306d
                                            int core,
Packit Service 31306d
                                            const char *errmsg,
Packit Service 31306d
                                            const char *lang,
Packit Service 31306d
                                            void *userdata);
Packit Service 31306d
Packit Service 31306d
/**
Packit Service 31306d
 * @brief SSH channel PTY request from a client.
Packit Service 31306d
 * @param channel the channel
Packit Service 31306d
 * @param term The type of terminal emulation
Packit Service 31306d
 * @param width width of the terminal, in characters
Packit Service 31306d
 * @param height height of the terminal, in characters
Packit Service 31306d
 * @param pxwidth width of the terminal, in pixels
Packit Service 31306d
 * @param pxheight height of the terminal, in pixels
Packit Service 31306d
 * @param userdata Userdata to be passed to the callback function.
Packit Service 31306d
 * @returns 0 if the pty request is accepted
Packit Service 31306d
 * @returns -1 if the request is denied
Packit Service 31306d
 */
Packit Service 31306d
typedef int (*ssh_channel_pty_request_callback) (ssh_session session,
Packit Service 31306d
                                            ssh_channel channel,
Packit Service 31306d
                                            const char *term,
Packit Service 31306d
                                            int width, int height,
Packit Service 31306d
                                            int pxwidth, int pwheight,
Packit Service 31306d
                                            void *userdata);
Packit Service 31306d
Packit Service 31306d
/**
Packit Service 31306d
 * @brief SSH channel Shell request from a client.
Packit Service 31306d
 * @param channel the channel
Packit Service 31306d
 * @param userdata Userdata to be passed to the callback function.
Packit Service 31306d
 * @returns 0 if the shell request is accepted
Packit Service 31306d
 * @returns 1 if the request is denied
Packit Service 31306d
 */
Packit Service 31306d
typedef int (*ssh_channel_shell_request_callback) (ssh_session session,
Packit Service 31306d
                                            ssh_channel channel,
Packit Service 31306d
                                            void *userdata);
Packit Service 31306d
/**
Packit Service 31306d
 * @brief SSH auth-agent-request from the client. This request is
Packit Service 31306d
 * sent by a client when agent forwarding is available.
Packit Service 31306d
 * Server is free to ignore this callback, no answer is expected.
Packit Service 31306d
 * @param channel the channel
Packit Service 31306d
 * @param userdata Userdata to be passed to the callback function.
Packit Service 31306d
 */
Packit Service 31306d
typedef void (*ssh_channel_auth_agent_req_callback) (ssh_session session,
Packit Service 31306d
                                            ssh_channel channel,
Packit Service 31306d
                                            void *userdata);
Packit Service 31306d
Packit Service 31306d
/**
Packit Service 31306d
 * @brief SSH X11 request from the client. This request is
Packit Service 31306d
 * sent by a client when X11 forwarding is requested(and available).
Packit Service 31306d
 * Server is free to ignore this callback, no answer is expected.
Packit Service 31306d
 * @param channel the channel
Packit Service 31306d
 * @param userdata Userdata to be passed to the callback function.
Packit Service 31306d
 */
Packit Service 31306d
typedef void (*ssh_channel_x11_req_callback) (ssh_session session,
Packit Service 31306d
                                            ssh_channel channel,
Packit Service 31306d
                                            int single_connection,
Packit Service 31306d
                                            const char *auth_protocol,
Packit Service 31306d
                                            const char *auth_cookie,
Packit Service 31306d
                                            uint32_t screen_number,
Packit Service 31306d
                                            void *userdata);
Packit Service 31306d
/**
Packit Service 31306d
 * @brief SSH channel PTY windows change (terminal size) from a client.
Packit Service 31306d
 * @param channel the channel
Packit Service 31306d
 * @param width width of the terminal, in characters
Packit Service 31306d
 * @param height height of the terminal, in characters
Packit Service 31306d
 * @param pxwidth width of the terminal, in pixels
Packit Service 31306d
 * @param pxheight height of the terminal, in pixels
Packit Service 31306d
 * @param userdata Userdata to be passed to the callback function.
Packit Service 31306d
 * @returns 0 if the pty request is accepted
Packit Service 31306d
 * @returns -1 if the request is denied
Packit Service 31306d
 */
Packit Service 31306d
typedef int (*ssh_channel_pty_window_change_callback) (ssh_session session,
Packit Service 31306d
                                            ssh_channel channel,
Packit Service 31306d
                                            int width, int height,
Packit Service 31306d
                                            int pxwidth, int pwheight,
Packit Service 31306d
                                            void *userdata);
Packit Service 31306d
Packit Service 31306d
/**
Packit Service 31306d
 * @brief SSH channel Exec request from a client.
Packit Service 31306d
 * @param channel the channel
Packit Service 31306d
 * @param command the shell command to be executed
Packit Service 31306d
 * @param userdata Userdata to be passed to the callback function.
Packit Service 31306d
 * @returns 0 if the exec request is accepted
Packit Service 31306d
 * @returns 1 if the request is denied
Packit Service 31306d
 */
Packit Service 31306d
typedef int (*ssh_channel_exec_request_callback) (ssh_session session,
Packit Service 31306d
                                            ssh_channel channel,
Packit Service 31306d
                                            const char *command,
Packit Service 31306d
                                            void *userdata);
Packit Service 31306d
Packit Service 31306d
/**
Packit Service 31306d
 * @brief SSH channel environment request from a client.
Packit Service 31306d
 * @param channel the channel
Packit Service 31306d
 * @param env_name name of the environment value to be set
Packit Service 31306d
 * @param env_value value of the environment value to be set
Packit Service 31306d
 * @param userdata Userdata to be passed to the callback function.
Packit Service 31306d
 * @returns 0 if the env request is accepted
Packit Service 31306d
 * @returns 1 if the request is denied
Packit Service 31306d
 * @warning some environment variables can be dangerous if changed (e.g.
Packit Service 31306d
 * 			LD_PRELOAD) and should not be fulfilled.
Packit Service 31306d
 */
Packit Service 31306d
typedef int (*ssh_channel_env_request_callback) (ssh_session session,
Packit Service 31306d
                                            ssh_channel channel,
Packit Service 31306d
                                            const char *env_name,
Packit Service 31306d
                                            const char *env_value,
Packit Service 31306d
                                            void *userdata);
Packit Service 31306d
/**
Packit Service 31306d
 * @brief SSH channel subsystem request from a client.
Packit Service 31306d
 * @param channel the channel
Packit Service 31306d
 * @param subsystem the subsystem required
Packit Service 31306d
 * @param userdata Userdata to be passed to the callback function.
Packit Service 31306d
 * @returns 0 if the subsystem request is accepted
Packit Service 31306d
 * @returns 1 if the request is denied
Packit Service 31306d
 */
Packit Service 31306d
typedef int (*ssh_channel_subsystem_request_callback) (ssh_session session,
Packit Service 31306d
                                            ssh_channel channel,
Packit Service 31306d
                                            const char *subsystem,
Packit Service 31306d
                                            void *userdata);
Packit Service 31306d
Packit Service 31306d
/**
Packit Service 31306d
 * @brief SSH channel write will not block (flow control).
Packit Service 31306d
 *
Packit Service 31306d
 * @param channel the channel
Packit Service 31306d
 *
Packit Service 31306d
 * @param[in] bytes size of the remote window in bytes. Writing as much data
Packit Service 31306d
 *            will not block.
Packit Service 31306d
 *
Packit Service 31306d
 * @param[in] userdata Userdata to be passed to the callback function.
Packit Service 31306d
 *
Packit Service 31306d
 * @returns 0 default return value (other return codes may be added in future).
Packit Service 31306d
 */
Packit Service 31306d
typedef int (*ssh_channel_write_wontblock_callback) (ssh_session session,
Packit Service 31306d
                                                     ssh_channel channel,
Packit Service 31306d
                                                     size_t bytes,
Packit Service 31306d
                                                     void *userdata);
Packit Service 31306d
Packit Service 31306d
struct ssh_channel_callbacks_struct {
Packit Service 31306d
  /** DON'T SET THIS use ssh_callbacks_init() instead. */
Packit Service 31306d
  size_t size;
Packit Service 31306d
  /**
Packit Service 31306d
   * User-provided data. User is free to set anything he wants here
Packit Service 31306d
   */
Packit Service 31306d
  void *userdata;
Packit Service 31306d
  /**
Packit Service 31306d
   * This functions will be called when there is data available.
Packit Service 31306d
   */
Packit Service 31306d
  ssh_channel_data_callback channel_data_function;
Packit Service 31306d
  /**
Packit Service 31306d
   * This functions will be called when the channel has received an EOF.
Packit Service 31306d
   */
Packit Service 31306d
  ssh_channel_eof_callback channel_eof_function;
Packit Service 31306d
  /**
Packit Service 31306d
   * This functions will be called when the channel has been closed by remote
Packit Service 31306d
   */
Packit Service 31306d
  ssh_channel_close_callback channel_close_function;
Packit Service 31306d
  /**
Packit Service 31306d
   * This functions will be called when a signal has been received
Packit Service 31306d
   */
Packit Service 31306d
  ssh_channel_signal_callback channel_signal_function;
Packit Service 31306d
  /**
Packit Service 31306d
   * This functions will be called when an exit status has been received
Packit Service 31306d
   */
Packit Service 31306d
  ssh_channel_exit_status_callback channel_exit_status_function;
Packit Service 31306d
  /**
Packit Service 31306d
   * This functions will be called when an exit signal has been received
Packit Service 31306d
   */
Packit Service 31306d
  ssh_channel_exit_signal_callback channel_exit_signal_function;
Packit Service 31306d
  /**
Packit Service 31306d
   * This function will be called when a client requests a PTY
Packit Service 31306d
   */
Packit Service 31306d
  ssh_channel_pty_request_callback channel_pty_request_function;
Packit Service 31306d
  /**
Packit Service 31306d
   * This function will be called when a client requests a shell
Packit Service 31306d
   */
Packit Service 31306d
  ssh_channel_shell_request_callback channel_shell_request_function;
Packit Service 31306d
  /** This function will be called when a client requests agent
Packit Service 31306d
   * authentication forwarding.
Packit Service 31306d
   */
Packit Service 31306d
  ssh_channel_auth_agent_req_callback channel_auth_agent_req_function;
Packit Service 31306d
  /** This function will be called when a client requests X11
Packit Service 31306d
   * forwarding.
Packit Service 31306d
   */
Packit Service 31306d
  ssh_channel_x11_req_callback channel_x11_req_function;
Packit Service 31306d
  /** This function will be called when a client requests a
Packit Service 31306d
   * window change.
Packit Service 31306d
   */
Packit Service 31306d
  ssh_channel_pty_window_change_callback channel_pty_window_change_function;
Packit Service 31306d
  /** This function will be called when a client requests a
Packit Service 31306d
   * command execution.
Packit Service 31306d
   */
Packit Service 31306d
  ssh_channel_exec_request_callback channel_exec_request_function;
Packit Service 31306d
  /** This function will be called when a client requests an environment
Packit Service 31306d
   * variable to be set.
Packit Service 31306d
   */
Packit Service 31306d
  ssh_channel_env_request_callback channel_env_request_function;
Packit Service 31306d
  /** This function will be called when a client requests a subsystem
Packit Service 31306d
   * (like sftp).
Packit Service 31306d
   */
Packit Service 31306d
  ssh_channel_subsystem_request_callback channel_subsystem_request_function;
Packit Service 31306d
  /** This function will be called when the channel write is guaranteed
Packit Service 31306d
   * not to block.
Packit Service 31306d
   */
Packit Service 31306d
  ssh_channel_write_wontblock_callback channel_write_wontblock_function;
Packit Service 31306d
};
Packit Service 31306d
Packit Service 31306d
typedef struct ssh_channel_callbacks_struct *ssh_channel_callbacks;
Packit Service 31306d
Packit Service 31306d
/**
Packit Service 31306d
 * @brief Set the channel callback functions.
Packit Service 31306d
 *
Packit Service 31306d
 * This functions sets the callback structure to use your own callback
Packit Service 31306d
 * functions for channel data and exceptions
Packit Service 31306d
 *
Packit Service 31306d
 * @code
Packit Service 31306d
 * struct ssh_channel_callbacks_struct cb = {
Packit Service 31306d
 *   .userdata = data,
Packit Service 31306d
 *   .channel_data_function = my_channel_data_function
Packit Service 31306d
 * };
Packit Service 31306d
 * ssh_callbacks_init(&cb;;
Packit Service 31306d
 * ssh_set_channel_callbacks(channel, &cb;;
Packit Service 31306d
 * @endcode
Packit Service 31306d
 *
Packit Service 31306d
 * @param  channel      The channel to set the callback structure.
Packit Service 31306d
 *
Packit Service 31306d
 * @param  cb           The callback structure itself.
Packit Service 31306d
 *
Packit Service 31306d
 * @return SSH_OK on success, SSH_ERROR on error.
Packit Service 31306d
 * @warning this function will not replace existing callbacks but set the
Packit Service 31306d
 *          new one atop of them.
Packit Service 31306d
 */
Packit Service 31306d
LIBSSH_API int ssh_set_channel_callbacks(ssh_channel channel,
Packit Service 31306d
                                         ssh_channel_callbacks cb);
Packit Service 31306d
Packit Service 31306d
/**
Packit Service 31306d
 * @brief Add channel callback functions
Packit Service 31306d
 *
Packit Service 31306d
 * This function will add channel callback functions to the channel callback
Packit Service 31306d
 * list.
Packit Service 31306d
 * Callbacks missing from a callback structure will be probed in the next
Packit Service 31306d
 * on the list.
Packit Service 31306d
 *
Packit Service 31306d
 * @param  channel      The channel to set the callback structure.
Packit Service 31306d
 *
Packit Service 31306d
 * @param  cb           The callback structure itself.
Packit Service 31306d
 *
Packit Service 31306d
 * @return SSH_OK on success, SSH_ERROR on error.
Packit Service 31306d
 *
Packit Service 31306d
 * @see ssh_set_channel_callbacks
Packit Service 31306d
 */
Packit Service 31306d
LIBSSH_API int ssh_add_channel_callbacks(ssh_channel channel,
Packit Service 31306d
                                         ssh_channel_callbacks cb);
Packit Service 31306d
Packit Service 31306d
/**
Packit Service 31306d
 * @brief Remove a channel callback.
Packit Service 31306d
 *
Packit Service 31306d
 * The channel has been added with ssh_add_channel_callbacks or
Packit Service 31306d
 * ssh_set_channel_callbacks in this case.
Packit Service 31306d
 *
Packit Service 31306d
 * @param channel  The channel to remove the callback structure from.
Packit Service 31306d
 *
Packit Service 31306d
 * @param cb       The callback structure to remove
Packit Service 31306d
 *
Packit Service 31306d
 * @returns SSH_OK on success, SSH_ERROR on error.
Packit Service 31306d
 */
Packit Service 31306d
LIBSSH_API int ssh_remove_channel_callbacks(ssh_channel channel,
Packit Service 31306d
                                            ssh_channel_callbacks cb);
Packit Service 31306d
Packit Service 31306d
/** @} */
Packit Service 31306d
Packit Service 31306d
/** @group libssh_threads
Packit Service 31306d
 * @{
Packit Service 31306d
 */
Packit Service 31306d
Packit Service 31306d
typedef int (*ssh_thread_callback) (void **lock);
Packit Service 31306d
Packit Service 31306d
typedef unsigned long (*ssh_thread_id_callback) (void);
Packit Service 31306d
struct ssh_threads_callbacks_struct {
Packit Service 31306d
	const char *type;
Packit Service 31306d
  ssh_thread_callback mutex_init;
Packit Service 31306d
  ssh_thread_callback mutex_destroy;
Packit Service 31306d
  ssh_thread_callback mutex_lock;
Packit Service 31306d
  ssh_thread_callback mutex_unlock;
Packit Service 31306d
  ssh_thread_id_callback thread_id;
Packit Service 31306d
};
Packit Service 31306d
Packit Service 31306d
/**
Packit Service 31306d
 * @brief Set the thread callbacks structure.
Packit Service 31306d
 *
Packit Service 31306d
 * This is necessary if your program is using libssh in a multithreaded fashion.
Packit Service 31306d
 * This function must be called first, outside of any threading context (in your
Packit Service 31306d
 * main() function for instance), before you call ssh_init().
Packit Service 31306d
 *
Packit Service 31306d
 * @param[in] cb   A pointer to a ssh_threads_callbacks_struct structure, which
Packit Service 31306d
 *                 contains the different callbacks to be set.
Packit Service 31306d
 *
Packit Service 31306d
 * @returns        Always returns SSH_OK.
Packit Service 31306d
 *
Packit Service 31306d
 * @see ssh_threads_callbacks_struct
Packit Service 31306d
 * @see SSH_THREADS_PTHREAD
Packit Service 31306d
 * @bug libgcrypt 1.6 and bigger backend does not support custom callback.
Packit Service 31306d
 *      Using anything else than pthreads here will fail.
Packit Service 31306d
 */
Packit Service 31306d
LIBSSH_API int ssh_threads_set_callbacks(struct ssh_threads_callbacks_struct
Packit Service 31306d
    *cb);
Packit Service 31306d
Packit Service 31306d
/**
Packit Service 31306d
 * @brief Returns a pointer to the appropriate callbacks structure for the
Packit Service 31306d
 * environment, to be used with ssh_threads_set_callbacks.
Packit Service 31306d
 *
Packit Service 31306d
 * @returns A pointer to a ssh_threads_callbacks_struct to be used with
Packit Service 31306d
 * ssh_threads_set_callbacks.
Packit Service 31306d
 *
Packit Service 31306d
 * @see ssh_threads_set_callbacks
Packit Service 31306d
 */
Packit Service 31306d
LIBSSH_API struct ssh_threads_callbacks_struct *ssh_threads_get_default(void);
Packit Service 31306d
Packit Service 31306d
/**
Packit Service 31306d
 * @brief Returns a pointer on the pthread threads callbacks, to be used with
Packit Service 31306d
 * ssh_threads_set_callbacks.
Packit Service 31306d
 *
Packit Service 31306d
 * @see ssh_threads_set_callbacks
Packit Service 31306d
 */
Packit Service 31306d
LIBSSH_API struct ssh_threads_callbacks_struct *ssh_threads_get_pthread(void);
Packit Service 31306d
Packit Service 31306d
/**
Packit Service 31306d
 * @brief Get the noop threads callbacks structure
Packit Service 31306d
 *
Packit Service 31306d
 * This can be used with ssh_threads_set_callbacks. These callbacks do nothing
Packit Service 31306d
 * and are being used by default.
Packit Service 31306d
 *
Packit Service 31306d
 * @return Always returns a valid pointer to the noop callbacks structure.
Packit Service 31306d
 *
Packit Service 31306d
 * @see ssh_threads_set_callbacks
Packit Service 31306d
 */
Packit Service 31306d
LIBSSH_API struct ssh_threads_callbacks_struct *ssh_threads_get_noop(void);
Packit Service 31306d
Packit Service 31306d
/**
Packit Service 31306d
 * @brief Set the logging callback function.
Packit Service 31306d
 *
Packit Service 31306d
 * @param[in]  cb  The callback to set.
Packit Service 31306d
 *
Packit Service 31306d
 * @return         0 on success, < 0 on errror.
Packit Service 31306d
 */
Packit Service 31306d
LIBSSH_API int ssh_set_log_callback(ssh_logging_callback cb);
Packit Service 31306d
Packit Service 31306d
/**
Packit Service 31306d
 * @brief Get the pointer to the logging callback function.
Packit Service 31306d
 *
Packit Service 31306d
 * @return The pointer the the callback or NULL if none set.
Packit Service 31306d
 */
Packit Service 31306d
LIBSSH_API ssh_logging_callback ssh_get_log_callback(void);
Packit Service 31306d
Packit Service 31306d
/** @} */
Packit Service 31306d
#ifdef __cplusplus
Packit Service 31306d
}
Packit Service 31306d
#endif
Packit Service 31306d
Packit Service 31306d
#endif /*_SSH_CALLBACK_H */
Packit Service 31306d
Packit Service 31306d
/* @} */