mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-12-02 01:17:52 +03:00
Converted message handlers to new system
This commit is contained in:
@@ -77,6 +77,8 @@ struct ssh_message_struct {
|
|||||||
struct ssh_service_request service_request;
|
struct ssh_service_request service_request;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
SSH_PACKET_CALLBACK(ssh_packet_channel_open);
|
||||||
|
SSH_PACKET_CALLBACK(ssh_packet_service_request);
|
||||||
|
|
||||||
//void message_handle(ssh_session session, uint32_t type);
|
//void message_handle(ssh_session session, uint32_t type);
|
||||||
int ssh_execute_message_callbacks(ssh_session session);
|
int ssh_execute_message_callbacks(ssh_session session);
|
||||||
|
|||||||
@@ -61,14 +61,15 @@ static ssh_message message_new(ssh_session session){
|
|||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssh_message handle_service_request(ssh_session session) {
|
SSH_PACKET_CALLBACK(ssh_packet_service_request){
|
||||||
ssh_string service = NULL;
|
ssh_string service = NULL;
|
||||||
char *service_c = NULL;
|
char *service_c = NULL;
|
||||||
ssh_message msg=NULL;
|
ssh_message msg=NULL;
|
||||||
|
|
||||||
enter_function();
|
enter_function();
|
||||||
|
(void)type;
|
||||||
service = buffer_get_ssh_string(session->in_buffer);
|
(void)user;
|
||||||
|
service = buffer_get_ssh_string(packet);
|
||||||
if (service == NULL) {
|
if (service == NULL) {
|
||||||
ssh_set_error(session, SSH_FATAL, "Invalid SSH_MSG_SERVICE_REQUEST packet");
|
ssh_set_error(session, SSH_FATAL, "Invalid SSH_MSG_SERVICE_REQUEST packet");
|
||||||
goto error;
|
goto error;
|
||||||
@@ -87,10 +88,12 @@ static ssh_message handle_service_request(ssh_session session) {
|
|||||||
}
|
}
|
||||||
msg->type=SSH_REQUEST_SERVICE;
|
msg->type=SSH_REQUEST_SERVICE;
|
||||||
msg->service_request.service=service_c;
|
msg->service_request.service=service_c;
|
||||||
error:
|
error:
|
||||||
string_free(service);
|
string_free(service);
|
||||||
|
if(msg != NULL)
|
||||||
|
message_queue(session,msg);
|
||||||
leave_function();
|
leave_function();
|
||||||
return msg;
|
return SSH_PACKET_USED;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int handle_unimplemented(ssh_session session) {
|
static int handle_unimplemented(ssh_session session) {
|
||||||
@@ -289,29 +292,29 @@ error:
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssh_message handle_channel_request_open(ssh_session session) {
|
SSH_PACKET_CALLBACK(ssh_packet_channel_open){
|
||||||
ssh_message msg = NULL;
|
ssh_message msg = NULL;
|
||||||
ssh_string type = NULL, originator = NULL, destination = NULL;
|
ssh_string type_s = NULL, originator = NULL, destination = NULL;
|
||||||
char *type_c = NULL;
|
char *type_c = NULL;
|
||||||
uint32_t sender, window, packet, originator_port, destination_port;
|
uint32_t sender, window, packet_size, originator_port, destination_port;
|
||||||
|
|
||||||
enter_function();
|
enter_function();
|
||||||
|
(void)type;
|
||||||
|
(void)user;
|
||||||
msg = message_new(session);
|
msg = message_new(session);
|
||||||
if (msg == NULL) {
|
if (msg == NULL) {
|
||||||
ssh_set_error_oom(session);
|
ssh_set_error_oom(session);
|
||||||
leave_function();
|
goto error;
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
msg->type = SSH_REQUEST_CHANNEL_OPEN;
|
msg->type = SSH_REQUEST_CHANNEL_OPEN;
|
||||||
|
|
||||||
type = buffer_get_ssh_string(session->in_buffer);
|
type_s = buffer_get_ssh_string(packet);
|
||||||
if (type == NULL) {
|
if (type_s == NULL) {
|
||||||
ssh_set_error_oom(session);
|
ssh_set_error_oom(session);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
type_c = string_to_char(type);
|
type_c = string_to_char(type_s);
|
||||||
if (type_c == NULL) {
|
if (type_c == NULL) {
|
||||||
ssh_set_error_oom(session);
|
ssh_set_error_oom(session);
|
||||||
goto error;
|
goto error;
|
||||||
@@ -319,21 +322,21 @@ static ssh_message handle_channel_request_open(ssh_session session) {
|
|||||||
|
|
||||||
ssh_log(session, SSH_LOG_PACKET,
|
ssh_log(session, SSH_LOG_PACKET,
|
||||||
"Clients wants to open a %s channel", type_c);
|
"Clients wants to open a %s channel", type_c);
|
||||||
string_free(type);
|
string_free(type_s);
|
||||||
|
type_s=NULL;
|
||||||
|
|
||||||
buffer_get_u32(session->in_buffer, &sender);
|
buffer_get_u32(packet, &sender);
|
||||||
buffer_get_u32(session->in_buffer, &window);
|
buffer_get_u32(packet, &window);
|
||||||
buffer_get_u32(session->in_buffer, &packet);
|
buffer_get_u32(packet, &packet_size);
|
||||||
|
|
||||||
msg->channel_request_open.sender = ntohl(sender);
|
msg->channel_request_open.sender = ntohl(sender);
|
||||||
msg->channel_request_open.window = ntohl(window);
|
msg->channel_request_open.window = ntohl(window);
|
||||||
msg->channel_request_open.packet_size = ntohl(packet);
|
msg->channel_request_open.packet_size = ntohl(packet_size);
|
||||||
|
|
||||||
if (strcmp(type_c,"session") == 0) {
|
if (strcmp(type_c,"session") == 0) {
|
||||||
msg->channel_request_open.type = SSH_CHANNEL_SESSION;
|
msg->channel_request_open.type = SSH_CHANNEL_SESSION;
|
||||||
SAFE_FREE(type_c);
|
SAFE_FREE(type_c);
|
||||||
leave_function();
|
goto end;
|
||||||
return msg;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp(type_c,"direct-tcpip") == 0) {
|
if (strcmp(type_c,"direct-tcpip") == 0) {
|
||||||
@@ -342,7 +345,7 @@ static ssh_message handle_channel_request_open(ssh_session session) {
|
|||||||
ssh_set_error_oom(session);
|
ssh_set_error_oom(session);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
msg->channel_request_open.destination = string_to_char(type);
|
msg->channel_request_open.destination = string_to_char(type_s);
|
||||||
if (msg->channel_request_open.destination == NULL) {
|
if (msg->channel_request_open.destination == NULL) {
|
||||||
ssh_set_error_oom(session);
|
ssh_set_error_oom(session);
|
||||||
string_free(destination);
|
string_free(destination);
|
||||||
@@ -358,7 +361,7 @@ static ssh_message handle_channel_request_open(ssh_session session) {
|
|||||||
ssh_set_error_oom(session);
|
ssh_set_error_oom(session);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
msg->channel_request_open.originator = string_to_char(type);
|
msg->channel_request_open.originator = string_to_char(type_s);
|
||||||
if (msg->channel_request_open.originator == NULL) {
|
if (msg->channel_request_open.originator == NULL) {
|
||||||
ssh_set_error_oom(session);
|
ssh_set_error_oom(session);
|
||||||
string_free(originator);
|
string_free(originator);
|
||||||
@@ -366,22 +369,20 @@ static ssh_message handle_channel_request_open(ssh_session session) {
|
|||||||
}
|
}
|
||||||
string_free(originator);
|
string_free(originator);
|
||||||
|
|
||||||
buffer_get_u32(session->in_buffer, &originator_port);
|
buffer_get_u32(packet, &originator_port);
|
||||||
msg->channel_request_open.originator_port = ntohl(originator_port);
|
msg->channel_request_open.originator_port = ntohl(originator_port);
|
||||||
|
|
||||||
msg->channel_request_open.type = SSH_CHANNEL_DIRECT_TCPIP;
|
msg->channel_request_open.type = SSH_CHANNEL_DIRECT_TCPIP;
|
||||||
SAFE_FREE(type_c);
|
goto end;
|
||||||
leave_function();
|
|
||||||
return msg;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp(type_c,"forwarded-tcpip") == 0) {
|
if (strcmp(type_c,"forwarded-tcpip") == 0) {
|
||||||
destination = buffer_get_ssh_string(session->in_buffer);
|
destination = buffer_get_ssh_string(packet);
|
||||||
if (destination == NULL) {
|
if (destination == NULL) {
|
||||||
ssh_set_error_oom(session);
|
ssh_set_error_oom(session);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
msg->channel_request_open.destination = string_to_char(type);
|
msg->channel_request_open.destination = string_to_char(type_s);
|
||||||
if (msg->channel_request_open.destination == NULL) {
|
if (msg->channel_request_open.destination == NULL) {
|
||||||
ssh_set_error_oom(session);
|
ssh_set_error_oom(session);
|
||||||
string_free(destination);
|
string_free(destination);
|
||||||
@@ -389,15 +390,15 @@ static ssh_message handle_channel_request_open(ssh_session session) {
|
|||||||
}
|
}
|
||||||
string_free(destination);
|
string_free(destination);
|
||||||
|
|
||||||
buffer_get_u32(session->in_buffer, &destination_port);
|
buffer_get_u32(packet, &destination_port);
|
||||||
msg->channel_request_open.destination_port = ntohl(destination_port);
|
msg->channel_request_open.destination_port = ntohl(destination_port);
|
||||||
|
|
||||||
originator = buffer_get_ssh_string(session->in_buffer);
|
originator = buffer_get_ssh_string(packet);
|
||||||
if (originator == NULL) {
|
if (originator == NULL) {
|
||||||
ssh_set_error_oom(session);
|
ssh_set_error_oom(session);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
msg->channel_request_open.originator = string_to_char(type);
|
msg->channel_request_open.originator = string_to_char(type_s);
|
||||||
if (msg->channel_request_open.originator == NULL) {
|
if (msg->channel_request_open.originator == NULL) {
|
||||||
ssh_set_error_oom(session);
|
ssh_set_error_oom(session);
|
||||||
string_free(originator);
|
string_free(originator);
|
||||||
@@ -405,22 +406,20 @@ static ssh_message handle_channel_request_open(ssh_session session) {
|
|||||||
}
|
}
|
||||||
string_free(originator);
|
string_free(originator);
|
||||||
|
|
||||||
buffer_get_u32(session->in_buffer, &originator_port);
|
buffer_get_u32(packet, &originator_port);
|
||||||
msg->channel_request_open.originator_port = ntohl(originator_port);
|
msg->channel_request_open.originator_port = ntohl(originator_port);
|
||||||
|
|
||||||
msg->channel_request_open.type = SSH_CHANNEL_FORWARDED_TCPIP;
|
msg->channel_request_open.type = SSH_CHANNEL_FORWARDED_TCPIP;
|
||||||
SAFE_FREE(type_c);
|
goto end;
|
||||||
leave_function();
|
|
||||||
return msg;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp(type_c,"x11") == 0) {
|
if (strcmp(type_c,"x11") == 0) {
|
||||||
originator = buffer_get_ssh_string(session->in_buffer);
|
originator = buffer_get_ssh_string(packet);
|
||||||
if (originator == NULL) {
|
if (originator == NULL) {
|
||||||
ssh_set_error_oom(session);
|
ssh_set_error_oom(session);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
msg->channel_request_open.originator = string_to_char(type);
|
msg->channel_request_open.originator = string_to_char(type_s);
|
||||||
if (msg->channel_request_open.originator == NULL) {
|
if (msg->channel_request_open.originator == NULL) {
|
||||||
ssh_set_error_oom(session);
|
ssh_set_error_oom(session);
|
||||||
string_free(originator);
|
string_free(originator);
|
||||||
@@ -428,27 +427,27 @@ static ssh_message handle_channel_request_open(ssh_session session) {
|
|||||||
}
|
}
|
||||||
string_free(originator);
|
string_free(originator);
|
||||||
|
|
||||||
buffer_get_u32(session->in_buffer, &originator_port);
|
buffer_get_u32(packet, &originator_port);
|
||||||
msg->channel_request_open.originator_port = ntohl(originator_port);
|
msg->channel_request_open.originator_port = ntohl(originator_port);
|
||||||
|
|
||||||
msg->channel_request_open.type = SSH_CHANNEL_X11;
|
msg->channel_request_open.type = SSH_CHANNEL_X11;
|
||||||
SAFE_FREE(type_c);
|
goto end;
|
||||||
leave_function();
|
|
||||||
return msg;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
msg->channel_request_open.type = SSH_CHANNEL_UNKNOWN;
|
msg->channel_request_open.type = SSH_CHANNEL_UNKNOWN;
|
||||||
SAFE_FREE(type_c);
|
goto end;
|
||||||
|
|
||||||
leave_function();
|
|
||||||
return msg;
|
|
||||||
error:
|
error:
|
||||||
string_free(type);
|
|
||||||
SAFE_FREE(type_c);
|
|
||||||
ssh_message_free(msg);
|
ssh_message_free(msg);
|
||||||
|
msg=NULL;
|
||||||
|
end:
|
||||||
|
if(type_s != NULL)
|
||||||
|
string_free(type_s);
|
||||||
|
SAFE_FREE(type_c);
|
||||||
|
if(msg != NULL)
|
||||||
|
message_queue(session,msg);
|
||||||
leave_function();
|
leave_function();
|
||||||
return NULL;
|
return SSH_PACKET_USED;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssh_channel ssh_message_channel_request_open_reply_accept(ssh_message msg) {
|
ssh_channel ssh_message_channel_request_open_reply_accept(ssh_message msg) {
|
||||||
@@ -746,18 +745,19 @@ int ssh_message_channel_request_reply_success(ssh_message msg) {
|
|||||||
return SSH_OK;
|
return SSH_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* TODO this function should disapear in favor of SSH_PACKET handlers */
|
||||||
ssh_message ssh_message_retrieve(ssh_session session, uint32_t packettype){
|
ssh_message ssh_message_retrieve(ssh_session session, uint32_t packettype){
|
||||||
ssh_message msg=NULL;
|
ssh_message msg=NULL;
|
||||||
enter_function();
|
enter_function();
|
||||||
switch(packettype) {
|
switch(packettype) {
|
||||||
case SSH2_MSG_SERVICE_REQUEST:
|
case SSH2_MSG_SERVICE_REQUEST:
|
||||||
msg=handle_service_request(session);
|
// msg=handle_service_request(session);
|
||||||
break;
|
break;
|
||||||
case SSH2_MSG_USERAUTH_REQUEST:
|
case SSH2_MSG_USERAUTH_REQUEST:
|
||||||
msg = handle_userauth_request(session);
|
msg = handle_userauth_request(session);
|
||||||
break;
|
break;
|
||||||
case SSH2_MSG_CHANNEL_OPEN:
|
case SSH2_MSG_CHANNEL_OPEN:
|
||||||
msg = handle_channel_request_open(session);
|
// msg = handle_channel_request_open(session);
|
||||||
break;
|
break;
|
||||||
case SSH2_MSG_CHANNEL_REQUEST:
|
case SSH2_MSG_CHANNEL_REQUEST:
|
||||||
msg = handle_channel_request(session);
|
msg = handle_channel_request(session);
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ ssh_packet_callback default_packet_handlers[]= {
|
|||||||
ssh_packet_ignore_callback, //#define SSH2_MSG_IGNORE 2
|
ssh_packet_ignore_callback, //#define SSH2_MSG_IGNORE 2
|
||||||
NULL, //#define SSH2_MSG_UNIMPLEMENTED 3
|
NULL, //#define SSH2_MSG_UNIMPLEMENTED 3
|
||||||
ssh_packet_ignore_callback, //#define SSH2_MSG_DEBUG 4
|
ssh_packet_ignore_callback, //#define SSH2_MSG_DEBUG 4
|
||||||
NULL, //#define SSH2_MSG_SERVICE_REQUEST 5
|
ssh_packet_service_request, //#define SSH2_MSG_SERVICE_REQUEST 5
|
||||||
ssh_packet_service_accept, //#define SSH2_MSG_SERVICE_ACCEPT 6
|
ssh_packet_service_accept, //#define SSH2_MSG_SERVICE_ACCEPT 6
|
||||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
|
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
|
||||||
NULL, NULL, NULL, // 7-19
|
NULL, NULL, NULL, // 7-19
|
||||||
@@ -81,7 +81,7 @@ ssh_packet_callback default_packet_handlers[]= {
|
|||||||
ssh_request_success, //#define SSH2_MSG_REQUEST_SUCCESS 81
|
ssh_request_success, //#define SSH2_MSG_REQUEST_SUCCESS 81
|
||||||
ssh_request_denied, //#define SSH2_MSG_REQUEST_FAILURE 82
|
ssh_request_denied, //#define SSH2_MSG_REQUEST_FAILURE 82
|
||||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, // 83-89
|
NULL, NULL, NULL, NULL, NULL, NULL, NULL, // 83-89
|
||||||
NULL, //#define SSH2_MSG_CHANNEL_OPEN 90
|
ssh_packet_channel_open, //#define SSH2_MSG_CHANNEL_OPEN 90
|
||||||
ssh_packet_channel_open_conf, //#define SSH2_MSG_CHANNEL_OPEN_CONFIRMATION 91
|
ssh_packet_channel_open_conf, //#define SSH2_MSG_CHANNEL_OPEN_CONFIRMATION 91
|
||||||
ssh_packet_channel_open_fail, //#define SSH2_MSG_CHANNEL_OPEN_FAILURE 92
|
ssh_packet_channel_open_fail, //#define SSH2_MSG_CHANNEL_OPEN_FAILURE 92
|
||||||
channel_rcv_change_window, //#define SSH2_MSG_CHANNEL_WINDOW_ADJUST 93
|
channel_rcv_change_window, //#define SSH2_MSG_CHANNEL_WINDOW_ADJUST 93
|
||||||
|
|||||||
Reference in New Issue
Block a user