client: Reformat ssh_disconnect()

Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
This commit is contained in:
Jakub Jelen
2020-10-02 12:36:16 +02:00
parent 693383d1ef
commit ccb5d6e0ac

View File

@@ -689,84 +689,88 @@ int ssh_get_openssh_version(ssh_session session) {
* *
* @param[in] session The SSH session to use. * @param[in] session The SSH session to use.
*/ */
void ssh_disconnect(ssh_session session) { void
struct ssh_iterator *it; ssh_disconnect(ssh_session session)
int rc; {
struct ssh_iterator *it;
int rc;
if (session == NULL) { if (session == NULL) {
return; return;
} }
if (session->socket != NULL && ssh_socket_is_open(session->socket)) { if (session->socket != NULL && ssh_socket_is_open(session->socket)) {
rc = ssh_buffer_pack(session->out_buffer, rc = ssh_buffer_pack(session->out_buffer,
"bdss", "bdss",
SSH2_MSG_DISCONNECT, SSH2_MSG_DISCONNECT,
SSH2_DISCONNECT_BY_APPLICATION, SSH2_DISCONNECT_BY_APPLICATION,
"Bye Bye", "Bye Bye",
""); /* language tag */ ""); /* language tag */
if (rc != SSH_OK){ if (rc != SSH_OK) {
ssh_set_error_oom(session); ssh_set_error_oom(session);
goto error; goto error;
}
ssh_packet_send(session);
ssh_socket_close(session->socket);
} }
ssh_packet_send(session);
ssh_socket_close(session->socket);
}
error: error:
session->recv_seq = 0; session->recv_seq = 0;
session->send_seq = 0; session->send_seq = 0;
session->alive = 0; session->alive = 0;
if (session->socket != NULL){ if (session->socket != NULL){
ssh_socket_reset(session->socket); ssh_socket_reset(session->socket);
}
session->opts.fd = SSH_INVALID_SOCKET;
session->session_state=SSH_SESSION_STATE_DISCONNECTED;
while ((it=ssh_list_get_iterator(session->channels)) != NULL) {
ssh_channel_do_free(ssh_iterator_value(ssh_channel,it));
ssh_list_remove(session->channels, it);
}
if(session->current_crypto){
crypto_free(session->current_crypto);
session->current_crypto=NULL;
}
if (session->next_crypto) {
crypto_free(session->next_crypto);
session->next_crypto = crypto_new();
if (session->next_crypto == NULL) {
ssh_set_error_oom(session);
} }
} session->opts.fd = SSH_INVALID_SOCKET;
if (session->in_buffer) { session->session_state = SSH_SESSION_STATE_DISCONNECTED;
ssh_buffer_reinit(session->in_buffer);
}
if (session->out_buffer) {
ssh_buffer_reinit(session->out_buffer);
}
if (session->in_hashbuf) {
ssh_buffer_reinit(session->in_hashbuf);
}
if (session->out_hashbuf) {
ssh_buffer_reinit(session->out_hashbuf);
}
session->auth.supported_methods = 0;
SAFE_FREE(session->serverbanner);
SAFE_FREE(session->clientbanner);
if(session->ssh_message_list){ while ((it = ssh_list_get_iterator(session->channels)) != NULL) {
ssh_message msg; ssh_channel_do_free(ssh_iterator_value(ssh_channel, it));
while((msg=ssh_list_pop_head(ssh_message ,session->ssh_message_list)) ssh_list_remove(session->channels, it);
!= NULL){
ssh_message_free(msg);
} }
ssh_list_free(session->ssh_message_list); if (session->current_crypto) {
session->ssh_message_list=NULL; crypto_free(session->current_crypto);
} session->current_crypto = NULL;
}
if (session->next_crypto) {
crypto_free(session->next_crypto);
session->next_crypto = crypto_new();
if (session->next_crypto == NULL) {
ssh_set_error_oom(session);
}
}
if (session->in_buffer) {
ssh_buffer_reinit(session->in_buffer);
}
if (session->out_buffer) {
ssh_buffer_reinit(session->out_buffer);
}
if (session->in_hashbuf) {
ssh_buffer_reinit(session->in_hashbuf);
}
if (session->out_hashbuf) {
ssh_buffer_reinit(session->out_hashbuf);
}
session->auth.supported_methods = 0;
SAFE_FREE(session->serverbanner);
SAFE_FREE(session->clientbanner);
if (session->packet_callbacks){ if (session->ssh_message_list) {
ssh_list_free(session->packet_callbacks); ssh_message msg = NULL;
session->packet_callbacks=NULL;
} while ((msg = ssh_list_pop_head(ssh_message,
session->ssh_message_list)) != NULL) {
ssh_message_free(msg);
}
ssh_list_free(session->ssh_message_list);
session->ssh_message_list = NULL;
}
if (session->packet_callbacks) {
ssh_list_free(session->packet_callbacks);
session->packet_callbacks = NULL;
}
} }
const char *ssh_copyright(void) { const char *ssh_copyright(void) {