1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-11-29 01:03:57 +03:00

callbacks: make the channel accept callback more logical

Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
Aris Adamantiadis
2013-03-13 20:44:55 +01:00
committed by Andreas Schneider
parent e76442b650
commit e933d1e1b1
2 changed files with 7 additions and 12 deletions

View File

@@ -178,13 +178,12 @@ typedef int (*ssh_service_request_callback) (ssh_session session, const char *se
/** /**
* @brief Handles an SSH new channel open session request * @brief Handles an SSH new channel open session request
* @param session current session handler * @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. * @param userdata Userdata to be passed to the callback function.
* @returns 0 if the request is to be allowed * @returns a valid ssh_channel handle if the request is to be allowed
* @returns -1 if the request should not be allowed * @returns NULL if the request should not be allowed
* @warning if the request is denied by the callback, the channel will be deallocated. * @warning The channel pointer returned by this callback must be closed by the application.
*/ */
typedef int (*ssh_channel_open_request_session_callback) (ssh_session session, ssh_channel channel, void *userdata); typedef ssh_channel (*ssh_channel_open_request_session_callback) (ssh_session session, void *userdata);
/** /**
@@ -476,7 +475,7 @@ typedef int (*ssh_channel_pty_request_callback) (ssh_session session,
* @brief SSH channel Shell request from a client. * @brief SSH channel Shell request from a client.
* @param channel the channel * @param channel the channel
* @param userdata Userdata to be passed to the callback function. * @param userdata Userdata to be passed to the callback function.
* @returns 0 if the pty request is accepted * @returns 0 if the shell request is accepted
* @returns 1 if the request is denied * @returns 1 if the request is denied
*/ */
typedef int (*ssh_channel_shell_request_callback) (ssh_session session, typedef int (*ssh_channel_shell_request_callback) (ssh_session session,

View File

@@ -121,16 +121,12 @@ static int ssh_execute_server_callbacks(ssh_session session, ssh_message msg){
case SSH_REQUEST_CHANNEL_OPEN: case SSH_REQUEST_CHANNEL_OPEN:
if (msg->channel_request_open.type == SSH_CHANNEL_SESSION){ if (msg->channel_request_open.type == SSH_CHANNEL_SESSION){
if(ssh_callbacks_exists(session->server_callbacks, channel_open_request_session_function)){ if(ssh_callbacks_exists(session->server_callbacks, channel_open_request_session_function)){
channel = ssh_channel_new(session); channel = session->server_callbacks->channel_open_request_session_function(session,
rc = session->server_callbacks->channel_open_request_session_function(session, channel,
session->server_callbacks->userdata); session->server_callbacks->userdata);
if(rc==0) { if(channel != NULL) {
rc = ssh_message_channel_request_open_reply_accept_channel(msg, channel); rc = ssh_message_channel_request_open_reply_accept_channel(msg, channel);
if (rc == SSH_ERROR)
ssh_channel_free(channel);
return SSH_OK; return SSH_OK;
} else { } else {
ssh_channel_free(channel);
ssh_message_reply_default(msg); ssh_message_reply_default(msg);
} }
return SSH_OK; return SSH_OK;