1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-12-08 03:42:12 +03:00

messages: Reformat the surrounding code

Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Sahana Prasad <sahana@redhat.com>
Reviewed-by: Eshan Kelkar <eshankelkar@galorithm.com>
This commit is contained in:
Jakub Jelen
2024-07-17 12:56:52 +02:00
committed by Sahana Prasad
parent f6e2d18da1
commit 716950fc9e

View File

@@ -1391,120 +1391,126 @@ ssh_channel ssh_message_channel_request_open_reply_accept(ssh_message msg) {
* *
* @returns SSH_OK on success, SSH_ERROR if an error occurred. * @returns SSH_OK on success, SSH_ERROR if an error occurred.
*/ */
int ssh_message_handle_channel_request(ssh_session session, ssh_channel channel, ssh_buffer packet, int
const char *request, uint8_t want_reply) { ssh_message_handle_channel_request(ssh_session session,
ssh_message msg = NULL; ssh_channel channel,
int rc; ssh_buffer packet,
const char *request,
uint8_t want_reply)
{
ssh_message msg = NULL;
int rc;
msg = ssh_message_new(session); msg = ssh_message_new(session);
if (msg == NULL) { if (msg == NULL) {
ssh_set_error_oom(session); ssh_set_error_oom(session);
goto error;
}
SSH_LOG(SSH_LOG_PACKET,
"Received a %s channel_request for channel (%" PRIu32 ":%" PRIu32
") (want_reply=%hhu)",
request,
channel->local_channel,
channel->remote_channel,
want_reply);
msg->type = SSH_REQUEST_CHANNEL;
msg->channel_request.channel = channel;
msg->channel_request.want_reply = want_reply;
if (strcmp(request, "pty-req") == 0) {
rc = ssh_buffer_unpack(packet, "sddddS",
&msg->channel_request.TERM,
&msg->channel_request.width,
&msg->channel_request.height,
&msg->channel_request.pxwidth,
&msg->channel_request.pxheight,
&msg->channel_request.modes
);
msg->channel_request.type = SSH_CHANNEL_REQUEST_PTY;
if (rc != SSH_OK) {
goto error;
}
goto end;
}
if (strcmp(request, "window-change") == 0) {
msg->channel_request.type = SSH_CHANNEL_REQUEST_WINDOW_CHANGE;
rc = ssh_buffer_unpack(packet, "dddd",
&msg->channel_request.width,
&msg->channel_request.height,
&msg->channel_request.pxwidth,
&msg->channel_request.pxheight);
if (rc != SSH_OK){
goto error; goto error;
} }
goto end;
}
if (strcmp(request, "subsystem") == 0) { SSH_LOG(SSH_LOG_PACKET,
rc = ssh_buffer_unpack(packet, "s", "Received a %s channel_request for channel (%" PRIu32 ":%" PRIu32
&msg->channel_request.subsystem); ") (want_reply=%hhu)",
msg->channel_request.type = SSH_CHANNEL_REQUEST_SUBSYSTEM; request,
if (rc != SSH_OK){ channel->local_channel,
goto error; channel->remote_channel,
} want_reply);
goto end;
}
if (strcmp(request, "shell") == 0) { msg->type = SSH_REQUEST_CHANNEL;
msg->channel_request.type = SSH_CHANNEL_REQUEST_SHELL; msg->channel_request.channel = channel;
goto end; msg->channel_request.want_reply = want_reply;
}
if (strcmp(request, "exec") == 0) { if (strcmp(request, "pty-req") == 0) {
rc = ssh_buffer_unpack(packet, "s", rc = ssh_buffer_unpack(packet,
&msg->channel_request.command); "sddddS",
msg->channel_request.type = SSH_CHANNEL_REQUEST_EXEC; &msg->channel_request.TERM,
if (rc != SSH_OK) { &msg->channel_request.width,
goto error; &msg->channel_request.height,
} &msg->channel_request.pxwidth,
goto end; &msg->channel_request.pxheight,
} &msg->channel_request.modes);
if (strcmp(request, "env") == 0) { msg->channel_request.type = SSH_CHANNEL_REQUEST_PTY;
rc = ssh_buffer_unpack(packet, "ss",
&msg->channel_request.var_name,
&msg->channel_request.var_value);
msg->channel_request.type = SSH_CHANNEL_REQUEST_ENV;
if (rc != SSH_OK) {
goto error;
}
goto end;
}
if (strcmp(request, "x11-req") == 0) { if (rc != SSH_OK) {
rc = ssh_buffer_unpack(packet, "bssd", goto error;
&msg->channel_request.x11_single_connection, }
&msg->channel_request.x11_auth_protocol, goto end;
&msg->channel_request.x11_auth_cookie,
&msg->channel_request.x11_screen_number);
msg->channel_request.type = SSH_CHANNEL_REQUEST_X11;
if (rc != SSH_OK) {
goto error;
} }
goto end; if (strcmp(request, "window-change") == 0) {
} msg->channel_request.type = SSH_CHANNEL_REQUEST_WINDOW_CHANGE;
rc = ssh_buffer_unpack(packet,
"dddd",
&msg->channel_request.width,
&msg->channel_request.height,
&msg->channel_request.pxwidth,
&msg->channel_request.pxheight);
if (rc != SSH_OK) {
goto error;
}
goto end;
}
msg->channel_request.type = SSH_CHANNEL_REQUEST_UNKNOWN; if (strcmp(request, "subsystem") == 0) {
rc = ssh_buffer_unpack(packet, "s", &msg->channel_request.subsystem);
msg->channel_request.type = SSH_CHANNEL_REQUEST_SUBSYSTEM;
if (rc != SSH_OK) {
goto error;
}
goto end;
}
if (strcmp(request, "shell") == 0) {
msg->channel_request.type = SSH_CHANNEL_REQUEST_SHELL;
goto end;
}
if (strcmp(request, "exec") == 0) {
rc = ssh_buffer_unpack(packet, "s", &msg->channel_request.command);
msg->channel_request.type = SSH_CHANNEL_REQUEST_EXEC;
if (rc != SSH_OK) {
goto error;
}
goto end;
}
if (strcmp(request, "env") == 0) {
rc = ssh_buffer_unpack(packet,
"ss",
&msg->channel_request.var_name,
&msg->channel_request.var_value);
msg->channel_request.type = SSH_CHANNEL_REQUEST_ENV;
if (rc != SSH_OK) {
goto error;
}
goto end;
}
if (strcmp(request, "x11-req") == 0) {
rc = ssh_buffer_unpack(packet,
"bssd",
&msg->channel_request.x11_single_connection,
&msg->channel_request.x11_auth_protocol,
&msg->channel_request.x11_auth_cookie,
&msg->channel_request.x11_screen_number);
msg->channel_request.type = SSH_CHANNEL_REQUEST_X11;
if (rc != SSH_OK) {
goto error;
}
goto end;
}
msg->channel_request.type = SSH_CHANNEL_REQUEST_UNKNOWN;
end: end:
ssh_message_queue(session,msg); ssh_message_queue(session, msg);
return SSH_OK; return SSH_OK;
error: error:
SSH_MESSAGE_FREE(msg); SSH_MESSAGE_FREE(msg);
return SSH_ERROR; return SSH_ERROR;
} }
/** @internal /** @internal
@@ -1515,53 +1521,55 @@ error:
* *
* @returns SSH_OK on success, SSH_ERROR if an error occurred. * @returns SSH_OK on success, SSH_ERROR if an error occurred.
*/ */
int ssh_message_channel_request_reply_success(ssh_message msg) { int ssh_message_channel_request_reply_success(ssh_message msg)
uint32_t channel; {
int rc; uint32_t channel;
int rc;
if (msg == NULL) { if (msg == NULL) {
return SSH_ERROR; return SSH_ERROR;
}
if (msg->channel_request.want_reply) {
channel = msg->channel_request.channel->remote_channel;
SSH_LOG(SSH_LOG_PACKET,
"Sending a channel_request success to channel %" PRIu32, channel);
rc = ssh_buffer_pack(msg->session->out_buffer,
"bd",
SSH2_MSG_CHANNEL_SUCCESS,
channel);
if (rc != SSH_OK){
ssh_set_error_oom(msg->session);
return SSH_ERROR;
} }
return ssh_packet_send(msg->session); if (msg->channel_request.want_reply) {
} channel = msg->channel_request.channel->remote_channel;
SSH_LOG(SSH_LOG_PACKET, SSH_LOG(SSH_LOG_PACKET,
"The client doesn't want to know the request succeeded"); "Sending a channel_request success to channel %" PRIu32,
channel);
return SSH_OK; rc = ssh_buffer_pack(msg->session->out_buffer,
"bd",
SSH2_MSG_CHANNEL_SUCCESS,
channel);
if (rc != SSH_OK) {
ssh_set_error_oom(msg->session);
return SSH_ERROR;
}
return ssh_packet_send(msg->session);
}
SSH_LOG(SSH_LOG_PACKET,
"The client doesn't want to know the request succeeded");
return SSH_OK;
} }
#ifdef WITH_SERVER #ifdef WITH_SERVER
SSH_PACKET_CALLBACK(ssh_packet_global_request){ SSH_PACKET_CALLBACK(ssh_packet_global_request)
{
ssh_message msg = NULL; ssh_message msg = NULL;
char *request=NULL; char *request = NULL;
uint8_t want_reply; uint8_t want_reply;
int rc = SSH_PACKET_USED; int rc = SSH_PACKET_USED;
int r; int r;
(void)user; (void)user;
(void)type; (void)type;
(void)packet; (void)packet;
SSH_LOG(SSH_LOG_DEBUG,"Received SSH_MSG_GLOBAL_REQUEST packet"); SSH_LOG(SSH_LOG_DEBUG,"Received SSH_MSG_GLOBAL_REQUEST packet");
r = ssh_buffer_unpack(packet, "sb", r = ssh_buffer_unpack(packet, "sb", &request, &want_reply);
&request,
&want_reply);
if (r != SSH_OK){ if (r != SSH_OK){
goto error; goto error;
} }
@@ -1580,10 +1588,10 @@ SSH_PACKET_CALLBACK(ssh_packet_global_request){
goto reply_with_failure; goto reply_with_failure;
} }
r = ssh_buffer_unpack(packet, "sd", r = ssh_buffer_unpack(packet,
&msg->global_request.bind_address, "sd",
&msg->global_request.bind_port &msg->global_request.bind_address,
); &msg->global_request.bind_port);
if (r != SSH_OK){ if (r != SSH_OK){
goto reply_with_failure; goto reply_with_failure;
} }
@@ -1597,14 +1605,18 @@ SSH_PACKET_CALLBACK(ssh_packet_global_request){
msg->global_request.bind_address, msg->global_request.bind_address,
msg->global_request.bind_port); msg->global_request.bind_port);
if(ssh_callbacks_exists(session->common.callbacks, global_request_function)) { if (ssh_callbacks_exists(session->common.callbacks,
global_request_function)) {
SSH_LOG(SSH_LOG_DEBUG, SSH_LOG(SSH_LOG_DEBUG,
"Calling callback for SSH_MSG_GLOBAL_REQUEST %s %hhu %s:%d", "Calling callback for SSH_MSG_GLOBAL_REQUEST %s %hhu %s:%d",
request, request,
want_reply, want_reply,
msg->global_request.bind_address, msg->global_request.bind_address,
msg->global_request.bind_port); msg->global_request.bind_port);
session->common.callbacks->global_request_function(session, msg, session->common.callbacks->userdata); session->common.callbacks->global_request_function(
session,
msg,
session->common.callbacks->userdata);
} else { } else {
SAFE_FREE(request); SAFE_FREE(request);
ssh_message_queue(session, msg); ssh_message_queue(session, msg);
@@ -1617,9 +1629,10 @@ SSH_PACKET_CALLBACK(ssh_packet_global_request){
goto reply_with_failure; goto reply_with_failure;
} }
r = ssh_buffer_unpack(packet, "sd", r = ssh_buffer_unpack(packet,
&msg->global_request.bind_address, "sd",
&msg->global_request.bind_port); &msg->global_request.bind_address,
&msg->global_request.bind_port);
if (r != SSH_OK){ if (r != SSH_OK){
goto reply_with_failure; goto reply_with_failure;
} }
@@ -1633,8 +1646,12 @@ SSH_PACKET_CALLBACK(ssh_packet_global_request){
msg->global_request.bind_address, msg->global_request.bind_address,
msg->global_request.bind_port); msg->global_request.bind_port);
if(ssh_callbacks_exists(session->common.callbacks, global_request_function)) { if (ssh_callbacks_exists(session->common.callbacks,
session->common.callbacks->global_request_function(session, msg, session->common.callbacks->userdata); global_request_function)) {
session->common.callbacks->global_request_function(
session,
msg,
session->common.callbacks->userdata);
} else { } else {
SAFE_FREE(request); SAFE_FREE(request);
ssh_message_queue(session, msg); ssh_message_queue(session, msg);
@@ -1646,8 +1663,12 @@ SSH_PACKET_CALLBACK(ssh_packet_global_request){
SSH_LOG(SSH_LOG_DEBUG, SSH_LOG(SSH_LOG_DEBUG,
"Received keepalive@openssh.com %hhu", "Received keepalive@openssh.com %hhu",
want_reply); want_reply);
if(ssh_callbacks_exists(session->common.callbacks, global_request_function)) { if (ssh_callbacks_exists(session->common.callbacks,
session->common.callbacks->global_request_function(session, msg, session->common.callbacks->userdata); global_request_function)) {
session->common.callbacks->global_request_function(
session,
msg,
session->common.callbacks->userdata);
} else { } else {
ssh_message_global_request_reply_success(msg, 0); ssh_message_global_request_reply_success(msg, 0);
} }
@@ -1666,7 +1687,7 @@ SSH_PACKET_CALLBACK(ssh_packet_global_request){
session->flags |= SSH_SESSION_FLAG_NO_MORE_SESSIONS; session->flags |= SSH_SESSION_FLAG_NO_MORE_SESSIONS;
} else { } else {
SSH_LOG(SSH_LOG_DEBUG, SSH_LOG(SSH_LOG_DEBUG,
"UNKNOWN SSH_MSG_GLOBAL_REQUEST %s,xwant_reply = %hhu", "UNKNOWN SSH_MSG_GLOBAL_REQUEST %s, want_reply = %hhu",
request, request,
want_reply); want_reply);
goto reply_with_failure; goto reply_with_failure;
@@ -1679,8 +1700,7 @@ SSH_PACKET_CALLBACK(ssh_packet_global_request){
reply_with_failure: reply_with_failure:
/* Only report the failure if requested */ /* Only report the failure if requested */
if (want_reply) { if (want_reply) {
r = ssh_buffer_add_u8(session->out_buffer, r = ssh_buffer_add_u8(session->out_buffer, SSH2_MSG_REQUEST_FAILURE);
SSH2_MSG_REQUEST_FAILURE);
if (r < 0) { if (r < 0) {
ssh_set_error_oom(session); ssh_set_error_oom(session);
goto error; goto error;