Mercurial > dropbear
changeset 733:70811267715c
Run the cleanup handler also when we close due to TCP connection being closed
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Mon, 01 Apr 2013 22:26:55 +0800 |
parents | 2e5f2bc60e40 |
children | 619b1ed837fd 73b6e5d8801b |
files | cli-main.c cli-session.c common-session.c session.h svr-session.c |
diffstat | 5 files changed, 21 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/cli-main.c Mon Apr 01 22:26:24 2013 +0800 +++ b/cli-main.c Mon Apr 01 22:26:55 2013 +0800 @@ -98,8 +98,7 @@ } /* Do the cleanup first, since then the terminal will be reset */ - cli_session_cleanup(); - common_session_cleanup(); + session_cleanup(); _dropbear_log(LOG_INFO, fmtbuf, param);
--- a/cli-session.c Mon Apr 01 22:26:24 2013 +0800 +++ b/cli-session.c Mon Apr 01 22:26:55 2013 +0800 @@ -42,6 +42,7 @@ static void cli_session_init(); static void cli_finished(); static void recv_msg_service_accept(void); +static void cli_session_cleanup(void); struct clientsession cli_ses; /* GLOBAL */ @@ -143,6 +144,7 @@ /* For printing "remote host closed" for the user */ ses.remoteclosed = cli_remoteclosed; + ses.extra_session_cleanup = cli_session_cleanup; ses.buf_match_algo = cli_buf_match_algo; /* packet handlers */ @@ -290,7 +292,7 @@ } -void cli_session_cleanup() { +static void cli_session_cleanup(void) { if (!sessinitdone) { return; @@ -308,8 +310,7 @@ static void cli_finished() { - cli_session_cleanup(); - common_session_cleanup(); + session_cleanup(); fprintf(stderr, "Connection to %s@%s:%s closed.\n", cli_opts.username, cli_opts.remotehost, cli_opts.remoteport); exit(cli_ses.retval);
--- a/common-session.c Mon Apr 01 22:26:24 2013 +0800 +++ b/common-session.c Mon Apr 01 22:26:55 2013 +0800 @@ -234,7 +234,7 @@ } /* clean up a session on exit */ -void common_session_cleanup() { +void session_cleanup() { TRACE(("enter session_cleanup")) @@ -243,6 +243,10 @@ TRACE(("leave session_cleanup: !sessinitdone")) return; } + + if (ses.extra_session_cleanup) { + ses.extra_session_cleanup(); + } m_free(ses.session_id); m_burn(ses.keys, sizeof(struct key_context));
--- a/session.h Mon Apr 01 22:26:24 2013 +0800 +++ b/session.h Mon Apr 01 22:26:55 2013 +0800 @@ -44,7 +44,7 @@ void common_session_init(int sock_in, int sock_out); void session_loop(void(*loophandler)()); -void common_session_cleanup(); +void session_cleanup(); void send_session_identification(); void send_msg_ignore(); @@ -58,7 +58,6 @@ /* Client */ void cli_session(int sock_in, int sock_out); -void cli_session_cleanup(); void cleantext(unsigned char* dirtytext); /* crypto parameters that are stored individually for transmit and receive */ @@ -181,6 +180,7 @@ void(*remoteclosed)(); /* A callback to handle closure of the remote connection */ + void(*extra_session_cleanup)(); /* client or server specific cleanup */ struct AuthState authstate; /* Common amongst client and server, since most struct elements are common */
--- a/svr-session.c Mon Apr 01 22:26:24 2013 +0800 +++ b/svr-session.c Mon Apr 01 22:26:55 2013 +0800 @@ -72,6 +72,13 @@ 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) { char *host, *port; size_t len; @@ -103,6 +110,7 @@ /* set up messages etc */ ses.remoteclosed = svr_remoteclosed; + ses.extra_session_cleanup = svr_session_cleanup; /* packet handlers */ ses.packettypes = svr_packettypes; @@ -160,11 +168,8 @@ if (svr_ses.server_pid == getpid()) #endif { - /* free potential public key options */ - svr_pubkey_options_cleanup(); - /* must be after we've done with username etc */ - common_session_cleanup(); + session_cleanup(); } exit(exitcode);