mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-04 20:30:38 +09:00
server: Introduce ssh_send_disconnect()
This will only send the disconnect message and close the socket. We should not free any memory here. This should be done by the server implementation. Pair-Programmed-With: Jakub Jelen <jjelen@redhat.com> Signed-off-by: Andreas Schneider <asn@cryptomilk.org> Signed-off-by: Jakub Jelen <jjelen@redhat.com>
This commit is contained in:
@@ -40,8 +40,8 @@
|
||||
#include "libssh/session.h"
|
||||
#include "libssh/misc.h"
|
||||
#include "libssh/pki.h"
|
||||
#include "libssh/dh.h"
|
||||
#include "libssh/messages.h"
|
||||
#include "libssh/socket.h"
|
||||
#ifdef WITH_SERVER
|
||||
#include "libssh/server.h"
|
||||
#include "libssh/gssapi.h"
|
||||
@@ -97,6 +97,41 @@ static int ssh_message_reply_default(ssh_message msg) {
|
||||
|
||||
#endif
|
||||
|
||||
static int ssh_send_disconnect(ssh_session session)
|
||||
{
|
||||
int rc = SSH_ERROR;
|
||||
|
||||
if (session == NULL) {
|
||||
return SSH_ERROR;
|
||||
}
|
||||
|
||||
if (session->disconnect_message == NULL) {
|
||||
session->disconnect_message = strdup("Bye Bye");
|
||||
if (session->disconnect_message == NULL) {
|
||||
ssh_set_error_oom(session);
|
||||
return SSH_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
if (session->socket != NULL && ssh_socket_is_open(session->socket)) {
|
||||
rc = ssh_buffer_pack(session->out_buffer,
|
||||
"bdss",
|
||||
SSH2_MSG_DISCONNECT,
|
||||
SSH2_DISCONNECT_BY_APPLICATION,
|
||||
session->disconnect_message,
|
||||
""); /* language tag */
|
||||
if (rc != SSH_OK) {
|
||||
ssh_set_error_oom(session);
|
||||
return SSH_ERROR;
|
||||
}
|
||||
|
||||
rc = ssh_packet_send(session);
|
||||
ssh_session_socket_close(session);
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
#ifdef WITH_SERVER
|
||||
|
||||
static int ssh_execute_server_request(ssh_session session, ssh_message msg)
|
||||
@@ -303,7 +338,7 @@ static int ssh_execute_server_request(ssh_session session, ssh_message msg)
|
||||
if (rc == 0) {
|
||||
ssh_message_reply_default(msg);
|
||||
} else {
|
||||
ssh_disconnect(session);
|
||||
ssh_send_disconnect(session);
|
||||
}
|
||||
|
||||
return SSH_OK;
|
||||
@@ -1182,7 +1217,7 @@ SSH_PACKET_CALLBACK(ssh_packet_channel_open){
|
||||
ssh_session_set_disconnect_message(session, "No more sessions allowed!");
|
||||
ssh_set_error(session, SSH_FATAL, "No more sessions allowed!");
|
||||
session->session_state = SSH_SESSION_STATE_ERROR;
|
||||
ssh_disconnect(session);
|
||||
ssh_send_disconnect(session);
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user