mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-11 18:50:28 +09:00
Add callback to accept forwarded-tcpip requests
Signed-off-by: Adley Phu <aphu@janestreet.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
This commit is contained in:
@@ -139,6 +139,26 @@ typedef ssh_channel (*ssh_channel_open_request_x11_callback) (ssh_session sessio
|
|||||||
typedef ssh_channel (*ssh_channel_open_request_auth_agent_callback) (ssh_session session,
|
typedef ssh_channel (*ssh_channel_open_request_auth_agent_callback) (ssh_session session,
|
||||||
void *userdata);
|
void *userdata);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Handles an SSH new channel open "forwarded-tcpip" request. This
|
||||||
|
* happens when the server forwards an incoming TCP connection on a port it was
|
||||||
|
* previously requested to listen on. This is a client-side API
|
||||||
|
* @param session current session handler
|
||||||
|
* @param destination_address the address that the TCP connection connected to
|
||||||
|
* @param destination_port the port that the TCP connection connected to
|
||||||
|
* @param originator_address the originator IP address
|
||||||
|
* @param originator_port the originator port
|
||||||
|
* @param userdata Userdata to be passed to the callback function.
|
||||||
|
* @returns a valid ssh_channel handle if the request is to be allowed
|
||||||
|
* @returns NULL if the request should not be allowed
|
||||||
|
* @warning The channel pointer returned by this callback must be closed by the
|
||||||
|
* application.
|
||||||
|
*/
|
||||||
|
typedef 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);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The structure to replace libssh functions with appropriate callbacks.
|
* The structure to replace libssh functions with appropriate callbacks.
|
||||||
*/
|
*/
|
||||||
@@ -172,6 +192,11 @@ struct ssh_callbacks_struct {
|
|||||||
/** This function will be called when an incoming "auth-agent" request is received.
|
/** This function will be called when an incoming "auth-agent" request is received.
|
||||||
*/
|
*/
|
||||||
ssh_channel_open_request_auth_agent_callback channel_open_request_auth_agent_function;
|
ssh_channel_open_request_auth_agent_callback channel_open_request_auth_agent_function;
|
||||||
|
/**
|
||||||
|
* This function will be called when an incoming "forwarded-tcpip"
|
||||||
|
* request is received.
|
||||||
|
*/
|
||||||
|
ssh_channel_open_request_forwarded_tcpip_callback channel_open_request_forwarded_tcpip_function;
|
||||||
};
|
};
|
||||||
typedef struct ssh_callbacks_struct *ssh_callbacks;
|
typedef struct ssh_callbacks_struct *ssh_callbacks;
|
||||||
|
|
||||||
|
|||||||
@@ -317,6 +317,17 @@ static int ssh_execute_server_request(ssh_session session, ssh_message msg)
|
|||||||
return SSH_AGAIN;
|
return SSH_AGAIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int ssh_reply_channel_open_request(ssh_message msg, ssh_channel channel)
|
||||||
|
{
|
||||||
|
if (channel != NULL) {
|
||||||
|
return ssh_message_channel_request_open_reply_accept_channel(msg, channel);
|
||||||
|
}
|
||||||
|
|
||||||
|
ssh_message_reply_default(msg);
|
||||||
|
|
||||||
|
return SSH_OK;
|
||||||
|
}
|
||||||
|
|
||||||
static int ssh_execute_client_request(ssh_session session, ssh_message msg)
|
static int ssh_execute_client_request(ssh_session session, ssh_message msg)
|
||||||
{
|
{
|
||||||
ssh_channel channel = NULL;
|
ssh_channel channel = NULL;
|
||||||
@@ -329,30 +340,26 @@ static int ssh_execute_client_request(ssh_session session, ssh_message msg)
|
|||||||
msg->channel_request_open.originator,
|
msg->channel_request_open.originator,
|
||||||
msg->channel_request_open.originator_port,
|
msg->channel_request_open.originator_port,
|
||||||
session->common.callbacks->userdata);
|
session->common.callbacks->userdata);
|
||||||
if (channel != NULL) {
|
|
||||||
rc = ssh_message_channel_request_open_reply_accept_channel(msg, channel);
|
|
||||||
|
|
||||||
return rc;
|
return ssh_reply_channel_open_request(msg, channel);
|
||||||
} else {
|
|
||||||
ssh_message_reply_default(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
return SSH_OK;
|
|
||||||
} else if (msg->type == SSH_REQUEST_CHANNEL_OPEN
|
} else if (msg->type == SSH_REQUEST_CHANNEL_OPEN
|
||||||
&& msg->channel_request_open.type == SSH_CHANNEL_AUTH_AGENT
|
&& msg->channel_request_open.type == SSH_CHANNEL_AUTH_AGENT
|
||||||
&& ssh_callbacks_exists(session->common.callbacks, channel_open_request_auth_agent_function)) {
|
&& ssh_callbacks_exists(session->common.callbacks, channel_open_request_auth_agent_function)) {
|
||||||
channel = session->common.callbacks->channel_open_request_auth_agent_function (session,
|
channel = session->common.callbacks->channel_open_request_auth_agent_function (session,
|
||||||
session->common.callbacks->userdata);
|
session->common.callbacks->userdata);
|
||||||
|
|
||||||
if (channel != NULL) {
|
return ssh_reply_channel_open_request(msg, channel);
|
||||||
rc = ssh_message_channel_request_open_reply_accept_channel(msg, channel);
|
} else if (msg->type == SSH_REQUEST_CHANNEL_OPEN
|
||||||
|
&& msg->channel_request_open.type == SSH_CHANNEL_FORWARDED_TCPIP
|
||||||
|
&& ssh_callbacks_exists(session->common.callbacks, channel_open_request_forwarded_tcpip_function)) {
|
||||||
|
channel = session->common.callbacks->channel_open_request_forwarded_tcpip_function(session,
|
||||||
|
msg->channel_request_open.destination,
|
||||||
|
msg->channel_request_open.destination_port,
|
||||||
|
msg->channel_request_open.originator,
|
||||||
|
msg->channel_request_open.originator_port,
|
||||||
|
session->common.callbacks->userdata);
|
||||||
|
|
||||||
return rc;
|
return ssh_reply_channel_open_request(msg, channel);
|
||||||
} else {
|
|
||||||
ssh_message_reply_default(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
return SSH_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
|
|||||||
Reference in New Issue
Block a user