aboutsummaryrefslogtreecommitdiff
path: root/include/libssh
diff options
context:
space:
mode:
authorAris Adamantiadis <aris@0xbadc0de.be>2013-02-11 21:31:11 +0100
committerAndreas Schneider <asn@cryptomilk.org>2013-07-13 13:59:58 +0200
commitab2e641b4a68e31390510f020d939107bef53b37 (patch)
tree6c85b2d683af3998c46553c5480da18ed90d8164 /include/libssh
parent48b715cce0d74c6695df5f085ed79de065ec072f (diff)
downloadlibssh-ab2e641b4a68e31390510f020d939107bef53b37.tar.gz
libssh-ab2e641b4a68e31390510f020d939107bef53b37.tar.xz
libssh-ab2e641b4a68e31390510f020d939107bef53b37.zip
Defined SSH server callbacks interface
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
Diffstat (limited to 'include/libssh')
-rw-r--r--include/libssh/callbacks.h107
-rw-r--r--include/libssh/session.h2
2 files changed, 108 insertions, 1 deletions
diff --git a/include/libssh/callbacks.h b/include/libssh/callbacks.h
index e15a0bd8..6dd90a85 100644
--- a/include/libssh/callbacks.h
+++ b/include/libssh/callbacks.h
@@ -124,6 +124,113 @@ struct ssh_callbacks_struct {
};
typedef struct ssh_callbacks_struct *ssh_callbacks;
+/** These are callbacks used specifically in SSH servers.
+ */
+
+/**
+ * @brief SSH authentication callback.
+ * @param session Current session handler
+ * @param user User that wants to authenticate
+ * @param password Password used for authentication
+ * @param userdata Userdata to be passed to the callback function.
+ * @returns SSH_AUTH_OK Authentication is accepted.
+ * @returns SSH_AUTH_PARTIAL Partial authentication, more authentication means are needed.
+ * @returns SSH_AUTH_DENIED Authentication failed.
+ */
+typedef int (*ssh_auth_password_callback) (ssh_session session, const char *user, const char *password,
+ void *userdata);
+
+/**
+ * @brief SSH Connection status callback. Tries to authenticates user with the "none" method
+ * which is anonymous or passwordless.
+ * @param session Current session handler
+ * @param user User that wants to authenticate
+ * @param userdata Userdata to be passed to the callback function.
+ * @returns SSH_AUTH_OK Authentication is accepted.
+ * @returns SSH_AUTH_PARTIAL Partial authentication, more authentication means are needed.
+ * @returns SSH_AUTH_DENIED Authentication failed.
+ */
+typedef int (*ssh_auth_none_callback) (ssh_session session, const char *user, void *userdata);
+
+
+/**
+ * @brief Handles an SSH service request
+ * @param session current session handler
+ * @param service name of the service (e.g. "ssh-userauth") requested
+ * @param userdata Userdata to be passed to the callback function.
+ * @returns 0 if the request is to be allowed
+ * @returns -1 if the request should not be allowed
+ */
+
+typedef int (*ssh_service_request_callback) (ssh_session session, const char *service, void *userdata);
+
+/**
+ * @brief Handles an SSH new channel open session request
+ * @param session current session handler
+ * @param channel Channel that will be allocated to this channel
+ * @param userdata Userdata to be passed to the callback function.
+ * @returns 0 if the request is to be allowed
+ * @returns -1 if the request should not be allowed
+ * @warning if the request is denied by the callback, the channel will be deallocated.
+ */
+typedef int (*ssh_channel_open_request_session_callback) (ssh_session session, ssh_channel channel, void *userdata);
+
+
+/**
+ * This structure can be used to implement a libssh server, with appropriate callbacks.
+ */
+
+struct ssh_server_callbacks_struct {
+ /** DON'T SET THIS use ssh_callbacks_init() instead. */
+ size_t size;
+ /**
+ * User-provided data. User is free to set anything he wants here
+ */
+ void *userdata;
+ /** This function gets called when a client tries to authenticate through
+ * password method.
+ */
+ ssh_auth_password_callback auth_password_function;
+
+ /** This function gets called when a client tries to authenticate through
+ * none method.
+ */
+ ssh_auth_none_callback auth_none_function;
+
+ /** This functions gets called when a service request is issued by the
+ * client
+ */
+ ssh_service_request_callback service_request_function;
+ /** This functions gets called when a new channel request is issued by
+ * the client
+ */
+ ssh_channel_open_request_session_callback channel_open_request_session_function;
+};
+typedef struct ssh_server_callbacks_struct *ssh_server_callbacks;
+
+/**
+ * @brief Set the session server callback functions.
+ *
+ * This functions sets the callback structure to use your own callback
+ * functions for user authentication, new channels and requests.
+ *
+ * @code
+ * struct ssh_server_callbacks_struct cb = {
+ * .userdata = data,
+ * .auth_password_function = my_auth_function
+ * };
+ * ssh_callbacks_init(&cb);
+ * ssh_set_server_callbacks(session, &cb);
+ * @endcode
+ *
+ * @param session The session to set the callback structure.
+ *
+ * @param cb The callback structure itself.
+ *
+ * @return SSH_OK on success, SSH_ERROR on error.
+ */
+LIBSSH_API int ssh_set_server_callbacks(ssh_session session, ssh_server_callbacks cb);
+
/**
* These are the callbacks exported by the socket structure
* They are called by the socket module when a socket event appears
diff --git a/include/libssh/session.h b/include/libssh/session.h
index 6edf9e51..18bc41f8 100644
--- a/include/libssh/session.h
+++ b/include/libssh/session.h
@@ -153,7 +153,7 @@ struct ssh_session_struct {
struct ssh_list *ssh_message_list; /* list of delayed SSH messages */
int (*ssh_message_callback)( struct ssh_session_struct *session, ssh_message msg, void *userdata);
void *ssh_message_callback_data;
-
+ ssh_server_callbacks server_callbacks;
void (*ssh_connection_callback)( struct ssh_session_struct *session);
struct ssh_packet_callbacks_struct default_packet_callbacks;
struct ssh_list *packet_callbacks;