mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-11-30 13:01:23 +03:00
Improve channel_rcv_request().
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@681 7dcaeef0-15fb-0310-b436-a5af3365683c
This commit is contained in:
@@ -465,64 +465,83 @@ static void channel_rcv_close(SSH_SESSION *session) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void channel_rcv_request(SSH_SESSION *session) {
|
static void channel_rcv_request(SSH_SESSION *session) {
|
||||||
|
CHANNEL *channel;
|
||||||
STRING *request_s;
|
STRING *request_s;
|
||||||
char *request;
|
char *request;
|
||||||
u32 status;
|
u32 status;
|
||||||
CHANNEL *channel=channel_from_msg(session);
|
|
||||||
enter_function();
|
enter_function();
|
||||||
if(!channel){
|
|
||||||
ssh_log(session, SSH_LOG_FUNCTIONS, "%s", ssh_get_error(session));
|
channel = channel_from_msg(session);
|
||||||
|
if (channel == NULL) {
|
||||||
|
ssh_log(session, SSH_LOG_FUNCTIONS, ssh_get_error(session));
|
||||||
leave_function();
|
leave_function();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
request_s = buffer_get_ssh_string(session->in_buffer);
|
request_s = buffer_get_ssh_string(session->in_buffer);
|
||||||
if(!request_s){
|
if (request_s == NULL) {
|
||||||
ssh_log(session, SSH_LOG_PACKET, "Invalid MSG_CHANNEL_REQUEST");
|
ssh_log(session, SSH_LOG_PACKET, "Invalid MSG_CHANNEL_REQUEST");
|
||||||
leave_function();
|
leave_function();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
buffer_get_u8(session->in_buffer,(u8 *)&status);
|
|
||||||
request = string_to_char(request_s);
|
request = string_to_char(request_s);
|
||||||
if(!strcmp(request,"exit-status")){
|
string_free(request_s);
|
||||||
|
if (request == NULL) {
|
||||||
|
leave_function();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer_get_u8(session->in_buffer, (u8 *) &status);
|
||||||
|
|
||||||
|
if (strcmp(request,"exit-status") == 0) {
|
||||||
|
SAFE_FREE(request);
|
||||||
ssh_log(session, SSH_LOG_PACKET, "received exit-status");
|
ssh_log(session, SSH_LOG_PACKET, "received exit-status");
|
||||||
buffer_get_u32(session->in_buffer, &status);
|
buffer_get_u32(session->in_buffer, &status);
|
||||||
status=ntohl(status);
|
channel->exit_status = ntohl(status);
|
||||||
channel->exit_status=status;
|
|
||||||
/* TODO do something with status, we might need it */
|
|
||||||
free(request_s);
|
|
||||||
free(request);
|
|
||||||
leave_function();
|
leave_function();
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
if(!strcmp(request,"exit-signal")){
|
|
||||||
|
if (strcmp(request, "exit-signal") == 0) {
|
||||||
|
const char *core = "(core dumped)";
|
||||||
STRING *signal_s;
|
STRING *signal_s;
|
||||||
char *signal;
|
char *signal;
|
||||||
const char *core = "(core dumped)";
|
|
||||||
u8 i;
|
u8 i;
|
||||||
|
|
||||||
|
SAFE_FREE(request);
|
||||||
|
|
||||||
signal_s = buffer_get_ssh_string(session->in_buffer);
|
signal_s = buffer_get_ssh_string(session->in_buffer);
|
||||||
if(!signal_s){
|
if (signal_s == NULL) {
|
||||||
ssh_log(session, SSH_LOG_PACKET, "Invalid MSG_CHANNEL_REQUEST");
|
ssh_log(session, SSH_LOG_PACKET, "Invalid MSG_CHANNEL_REQUEST");
|
||||||
free(request_s);
|
|
||||||
free(request);
|
|
||||||
leave_function();
|
leave_function();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
signal = string_to_char(signal_s);
|
signal = string_to_char(signal_s);
|
||||||
|
string_free(signal_s);
|
||||||
|
if (signal == NULL) {
|
||||||
|
leave_function();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
buffer_get_u8(session->in_buffer, &i);
|
buffer_get_u8(session->in_buffer, &i);
|
||||||
if(!i)
|
if (i == 0) {
|
||||||
core = "";
|
core = "";
|
||||||
|
}
|
||||||
|
|
||||||
ssh_log(session, SSH_LOG_PACKET,
|
ssh_log(session, SSH_LOG_PACKET,
|
||||||
"Remote connection closed by signal SIG %s %s", signal, core);
|
"Remote connection closed by signal SIG %s %s", signal, core);
|
||||||
free(signal_s);
|
SAFE_FREE(signal);
|
||||||
free(signal);
|
|
||||||
free(request_s);
|
|
||||||
free(request);
|
|
||||||
leave_function();
|
leave_function();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ssh_log(session, SSH_LOG_PACKET, "Unknown request %s", request);
|
ssh_log(session, SSH_LOG_PACKET, "Unknown request %s", request);
|
||||||
free(request_s);
|
SAFE_FREE(request);
|
||||||
free(request);
|
|
||||||
leave_function();
|
leave_function();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user