mirror of
https://github.com/clearml/dropbear
synced 2025-01-31 10:57:01 +00:00
Run the cleanup handler also when we close due to TCP connection being closed
This commit is contained in:
parent
5af0d33164
commit
90b5691183
@ -98,8 +98,7 @@ static void cli_dropbear_exit(int exitcode, const char* format, va_list param) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Do the cleanup first, since then the terminal will be reset */
|
/* Do the cleanup first, since then the terminal will be reset */
|
||||||
cli_session_cleanup();
|
session_cleanup();
|
||||||
common_session_cleanup();
|
|
||||||
|
|
||||||
_dropbear_log(LOG_INFO, fmtbuf, param);
|
_dropbear_log(LOG_INFO, fmtbuf, param);
|
||||||
|
|
||||||
|
@ -42,6 +42,7 @@ static void cli_sessionloop();
|
|||||||
static void cli_session_init();
|
static void cli_session_init();
|
||||||
static void cli_finished();
|
static void cli_finished();
|
||||||
static void recv_msg_service_accept(void);
|
static void recv_msg_service_accept(void);
|
||||||
|
static void cli_session_cleanup(void);
|
||||||
|
|
||||||
struct clientsession cli_ses; /* GLOBAL */
|
struct clientsession cli_ses; /* GLOBAL */
|
||||||
|
|
||||||
@ -143,6 +144,7 @@ static void cli_session_init() {
|
|||||||
|
|
||||||
/* For printing "remote host closed" for the user */
|
/* For printing "remote host closed" for the user */
|
||||||
ses.remoteclosed = cli_remoteclosed;
|
ses.remoteclosed = cli_remoteclosed;
|
||||||
|
ses.extra_session_cleanup = cli_session_cleanup;
|
||||||
ses.buf_match_algo = cli_buf_match_algo;
|
ses.buf_match_algo = cli_buf_match_algo;
|
||||||
|
|
||||||
/* packet handlers */
|
/* packet handlers */
|
||||||
@ -290,7 +292,7 @@ static void cli_sessionloop() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void cli_session_cleanup() {
|
static void cli_session_cleanup(void) {
|
||||||
|
|
||||||
if (!sessinitdone) {
|
if (!sessinitdone) {
|
||||||
return;
|
return;
|
||||||
@ -308,8 +310,7 @@ void cli_session_cleanup() {
|
|||||||
|
|
||||||
static void cli_finished() {
|
static void cli_finished() {
|
||||||
|
|
||||||
cli_session_cleanup();
|
session_cleanup();
|
||||||
common_session_cleanup();
|
|
||||||
fprintf(stderr, "Connection to %s@%s:%s closed.\n", cli_opts.username,
|
fprintf(stderr, "Connection to %s@%s:%s closed.\n", cli_opts.username,
|
||||||
cli_opts.remotehost, cli_opts.remoteport);
|
cli_opts.remotehost, cli_opts.remoteport);
|
||||||
exit(cli_ses.retval);
|
exit(cli_ses.retval);
|
||||||
|
@ -234,7 +234,7 @@ void session_loop(void(*loophandler)()) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* clean up a session on exit */
|
/* clean up a session on exit */
|
||||||
void common_session_cleanup() {
|
void session_cleanup() {
|
||||||
|
|
||||||
TRACE(("enter session_cleanup"))
|
TRACE(("enter session_cleanup"))
|
||||||
|
|
||||||
@ -243,6 +243,10 @@ void common_session_cleanup() {
|
|||||||
TRACE(("leave session_cleanup: !sessinitdone"))
|
TRACE(("leave session_cleanup: !sessinitdone"))
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ses.extra_session_cleanup) {
|
||||||
|
ses.extra_session_cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
m_free(ses.session_id);
|
m_free(ses.session_id);
|
||||||
m_burn(ses.keys, sizeof(struct key_context));
|
m_burn(ses.keys, sizeof(struct key_context));
|
||||||
|
@ -44,7 +44,7 @@ extern int exitflag;
|
|||||||
|
|
||||||
void common_session_init(int sock_in, int sock_out);
|
void common_session_init(int sock_in, int sock_out);
|
||||||
void session_loop(void(*loophandler)());
|
void session_loop(void(*loophandler)());
|
||||||
void common_session_cleanup();
|
void session_cleanup();
|
||||||
void send_session_identification();
|
void send_session_identification();
|
||||||
void send_msg_ignore();
|
void send_msg_ignore();
|
||||||
|
|
||||||
@ -58,7 +58,6 @@ void svr_dropbear_log(int priority, const char* format, va_list param);
|
|||||||
|
|
||||||
/* Client */
|
/* Client */
|
||||||
void cli_session(int sock_in, int sock_out);
|
void cli_session(int sock_in, int sock_out);
|
||||||
void cli_session_cleanup();
|
|
||||||
void cleantext(unsigned char* dirtytext);
|
void cleantext(unsigned char* dirtytext);
|
||||||
|
|
||||||
/* crypto parameters that are stored individually for transmit and receive */
|
/* crypto parameters that are stored individually for transmit and receive */
|
||||||
@ -181,6 +180,7 @@ struct sshsession {
|
|||||||
void(*remoteclosed)(); /* A callback to handle closure of the
|
void(*remoteclosed)(); /* A callback to handle closure of the
|
||||||
remote connection */
|
remote connection */
|
||||||
|
|
||||||
|
void(*extra_session_cleanup)(); /* client or server specific cleanup */
|
||||||
|
|
||||||
struct AuthState authstate; /* Common amongst client and server, since most
|
struct AuthState authstate; /* Common amongst client and server, since most
|
||||||
struct elements are common */
|
struct elements are common */
|
||||||
|
@ -72,6 +72,13 @@ static const struct ChanType *svr_chantypes[] = {
|
|||||||
NULL /* Null termination is mandatory. */
|
NULL /* Null termination is mandatory. */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static void
|
||||||
|
svr_session_cleanup(void)
|
||||||
|
{
|
||||||
|
/* free potential public key options */
|
||||||
|
svr_pubkey_options_cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
void svr_session(int sock, int childpipe) {
|
void svr_session(int sock, int childpipe) {
|
||||||
char *host, *port;
|
char *host, *port;
|
||||||
size_t len;
|
size_t len;
|
||||||
@ -103,6 +110,7 @@ void svr_session(int sock, int childpipe) {
|
|||||||
|
|
||||||
/* set up messages etc */
|
/* set up messages etc */
|
||||||
ses.remoteclosed = svr_remoteclosed;
|
ses.remoteclosed = svr_remoteclosed;
|
||||||
|
ses.extra_session_cleanup = svr_session_cleanup;
|
||||||
|
|
||||||
/* packet handlers */
|
/* packet handlers */
|
||||||
ses.packettypes = svr_packettypes;
|
ses.packettypes = svr_packettypes;
|
||||||
@ -160,11 +168,8 @@ void svr_dropbear_exit(int exitcode, const char* format, va_list param) {
|
|||||||
if (svr_ses.server_pid == getpid())
|
if (svr_ses.server_pid == getpid())
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
/* free potential public key options */
|
|
||||||
svr_pubkey_options_cleanup();
|
|
||||||
|
|
||||||
/* must be after we've done with username etc */
|
/* must be after we've done with username etc */
|
||||||
common_session_cleanup();
|
session_cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
exit(exitcode);
|
exit(exitcode);
|
||||||
|
Loading…
Reference in New Issue
Block a user