<div dir="ltr">This adds a command line option for specifying an idle_timeout. The command line is:<br>-I <secs>. If dropbear doesn't receive any data packets within <secs>, the dropbear process<br>associated with that session will exit.<br>
<br><br>diff -up ../../dropbear-vanilla/dropbear-0.51/cli-runopts.c ../../dropbear-idle_timeout/dropbear-0.51/cli-runopts.c<br>--- ../../dropbear-vanilla/dropbear-0.51/cli-runopts.c 2008-03-27 09:17:14.000000000 -0400<br>
+++ ../../dropbear-idle_timeout/dropbear-0.51/cli-runopts.c 2008-09-19 13:52:58.000000000 -0400<br>@@ -65,11 +65,12 @@ static void printhelp() {<br> #endif<br> "-W <receive_window_buffer> (default %d, larger may be faster, max 1MB)\n"<br>
"-K <keepalive> (0 is never, default %d)\n"<br>+ "-I <idle_timeout> (0 is never, default %d)\n"<br> #ifdef DEBUG_TRACE<br> "-v verbose\n"<br>
#endif<br> ,DROPBEAR_VERSION, cli_opts.progname,<br>- DEFAULT_RECV_WINDOW, DEFAULT_KEEPALIVE);<br>+ DEFAULT_RECV_WINDOW, DEFAULT_KEEPALIVE, DEFAULT_IDLE_TIMEOUT);<br>
<br> }<br> <br>@@ -91,6 +92,7 @@ void cli_getopts(int argc, char ** argv)<br> <br> char* recv_window_arg = NULL;<br> char* keepalive_arg = NULL;<br>+ char* idle_timeout_arg = NULL;<br> <br>
/* see printhelp() for options */<br> cli_opts.progname = argv[0];<br>@@ -215,6 +217,9 @@ void cli_getopts(int argc, char ** argv)<br> case 'K':<br> next = &keepalive_arg;<br>
break;<br>+ case 'I':<br>+ next = &idle_timeout_arg;<br>+ break;<br> #ifdef DEBUG_TRACE<br> case 'v':<br> debug_trace = 1;<br>
@@ -322,7 +327,12 @@ void cli_getopts(int argc, char ** argv)<br> dropbear_exit("Bad keepalive '%s'", keepalive_arg);<br> }<br> }<br>- <br>+ if (idle_timeout_arg) {<br>+ opts.idle_timeout_secs = strtoul(idle_timeout_arg, NULL, 10);<br>
+ if (opts.idle_timeout_secs == 0 && errno == EINVAL) {<br>+ dropbear_exit("Bad idle_timeout '%s'", idle_timeout_arg);<br>+ }<br>+ }<br> }<br> <br> #ifdef ENABLE_CLI_PUBKEY_AUTH<br>
diff -up ../../dropbear-vanilla/dropbear-0.51/common-session.c ../../dropbear-idle_timeout/dropbear-0.51/common-session.c<br>--- ../../dropbear-vanilla/dropbear-0.51/common-session.c 2008-03-27 09:17:14.000000000 -0400<br>
+++ ../../dropbear-idle_timeout/dropbear-0.51/common-session.c 2008-09-19 11:24:18.000000000 -0400<br>@@ -63,6 +63,7 @@ void common_session_init(int sock, char*<br> <br> ses.connect_time = 0;<br> ses.last_packet_time = 0;<br>
+ ses.last_recv_packet_time = 0;<br> <br> if (pipe(ses.signal_pipe) < 0) {<br> dropbear_exit("signal pipe failed");<br>@@ -397,6 +398,11 @@ static void checktimeouts() {<br> && now - ses.last_packet_time >= opts.keepalive_secs) {<br>
send_msg_ignore();<br> }<br>+<br>+ if (opts.idle_timeout_secs > 0 && ses.last_recv_packet_time > 0<br>+ && now - ses.last_recv_packet_time >= opts.idle_timeout_secs) {<br>+ dropbear_close("Idle timeout");<br>
+ }<br> }<br> <br> static long select_timeout() {<br>@@ -409,5 +415,7 @@ static long select_timeout() {<br> ret = MIN(AUTH_TIMEOUT, ret);<br> if (opts.keepalive_secs > 0)<br> ret = MIN(opts.keepalive_secs, ret);<br>
+ if (opts.idle_timeout_secs > 0)<br>+ ret = MIN(opts.idle_timeout_secs, ret);<br> return ret;<br> }<br>Common subdirectories: ../../dropbear-vanilla/dropbear-0.51/debian and ../../dropbear-idle_timeout/dropbear-0.51/debian<br>
Common subdirectories: ../../dropbear-vanilla/dropbear-0.51/libtomcrypt and ../../dropbear-idle_timeout/dropbear-0.51/libtomcrypt<br>Common subdirectories: ../../dropbear-vanilla/dropbear-0.51/libtommath and ../../dropbear-idle_timeout/dropbear-0.51/libtommath<br>
Common subdirectories: ../../dropbear-vanilla/dropbear-0.51/_MTN and ../../dropbear-idle_timeout/dropbear-0.51/_MTN<br>diff -up ../../dropbear-vanilla/dropbear-0.51/options.h ../../dropbear-idle_timeout/dropbear-0.51/options.h<br>
--- ../../dropbear-vanilla/dropbear-0.51/options.h 2008-03-27 09:34:39.000000000 -0400<br>+++ ../../dropbear-idle_timeout/dropbear-0.51/options.h 2008-09-19 11:26:04.000000000 -0400<br>@@ -235,6 +235,10 @@ etc) slower (perhaps by 50%). Recommende<br>
be overridden at runtime with -K. 0 disables keepalives */<br> #define DEFAULT_KEEPALIVE 0<br> <br>+/* Ensure that data is received within IDLE_TIMEOUT seconds. This can<br>+be overridden at runtime with -I. 0 disables idle timeouts */<br>
+#define DEFAULT_IDLE_TIMEOUT 0<br>+<br> /*******************************************************************<br> * You shouldn't edit below here unless you know you need to.<br> *******************************************************************/<br>
Only in ../../dropbear-idle_timeout/dropbear-0.51: patch051.idle_timeout<br>diff -up ../../dropbear-vanilla/dropbear-0.51/process-packet.c ../../dropbear-idle_timeout/dropbear-0.51/process-packet.c<br>--- ../../dropbear-vanilla/dropbear-0.51/process-packet.c 2008-03-27 09:17:15.000000000 -0400<br>
+++ ../../dropbear-idle_timeout/dropbear-0.51/process-packet.c 2008-09-19 11:26:58.000000000 -0400<br>@@ -51,6 +51,7 @@ void process_packet() {<br> TRACE(("process_packet: packet type = %d", type))<br> <br>
ses.lastpacket = type;<br>+ ses.last_recv_packet_time = time(NULL);<br> <br> /* These packets we can receive at any time */<br> switch(type) {<br>diff -up ../../dropbear-vanilla/dropbear-0.51/runopts.h ../../dropbear-idle_timeout/dropbear-0.51/runopts.h<br>
--- ../../dropbear-vanilla/dropbear-0.51/runopts.h 2008-03-27 09:17:15.000000000 -0400<br>+++ ../../dropbear-idle_timeout/dropbear-0.51/runopts.h 2008-09-19 11:29:17.000000000 -0400<br>@@ -38,6 +38,7 @@ typedef struct runopts {<br>
#endif<br> unsigned int recv_window;<br> time_t keepalive_secs;<br>+ time_t idle_timeout_secs;<br> <br> } runopts;<br> <br>diff -up ../../dropbear-vanilla/dropbear-0.51/session.h ../../dropbear-idle_timeout/dropbear-0.51/session.h<br>
--- ../../dropbear-vanilla/dropbear-0.51/session.h 2008-03-27 09:17:15.000000000 -0400<br>+++ ../../dropbear-idle_timeout/dropbear-0.51/session.h 2008-09-19 11:30:56.000000000 -0400<br>@@ -137,6 +137,10 @@ struct sshsession {<br>
time_t last_packet_time; /* time of the last packet transmission, for<br> keepalive purposes */<br> <br>+ time_t last_recv_packet_time; /* time of the last packet received, for<br>+ idle timeout purposes */<br>
+<br>+<br> /* KEX/encryption related */<br> struct KEXState kexstate;<br> struct key_context *keys;<br>diff -up ../../dropbear-vanilla/dropbear-0.51/svr-runopts.c ../../dropbear-idle_timeout/dropbear-0.51/svr-runopts.c<br>
--- ../../dropbear-vanilla/dropbear-0.51/svr-runopts.c 2008-03-27 09:17:16.000000000 -0400<br>+++ ../../dropbear-idle_timeout/dropbear-0.51/svr-runopts.c 2008-09-19 11:34:15.000000000 -0400<br>@@ -82,6 +82,7 @@ static void printhelp(const char * progn<br>
#endif<br> "-W <receive_window_buffer> (default %d, larger may be faster, max 1MB)\n"<br> "-K <keepalive> (0 is never, default %d)\n"<br>+ "-I <idle_timeout> (0 is never, default %d)\n"<br>
#ifdef DEBUG_TRACE<br> "-v verbose\n"<br> #endif<br>@@ -93,7 +94,7 @@ static void printhelp(const char * progn<br> RSA_PRIV_FILENAME,<br> #endif<br> DROPBEAR_MAX_PORTS, DROPBEAR_DEFPORT, DROPBEAR_PIDFILE,<br>
- DEFAULT_RECV_WINDOW, DEFAULT_KEEPALIVE);<br>+ DEFAULT_RECV_WINDOW, DEFAULT_KEEPALIVE, DEFAULT_IDLE_TIMEOUT);<br> }<br> <br> void svr_getopts(int argc, char ** argv) {<br>@@ -103,6 +104,7 @@ void svr_getopts(int argc, char ** argv)<br>
int nextisport = 0;<br> char* recv_window_arg = NULL;<br> char* keepalive_arg = NULL;<br>+ char* idle_timeout_arg = NULL;<br> <br> /* see printhelp() for options */<br> svr_opts.rsakeyfile = NULL;<br>
@@ -134,7 +136,8 @@ void svr_getopts(int argc, char ** argv)<br> svr_opts.usingsyslog = 1;<br> #endif<br> opts.recv_window = DEFAULT_RECV_WINDOW;<br>- opts.keepalive_secs = DEFAULT_KEEPALIVE; <br>+ opts.keepalive_secs = DEFAULT_KEEPALIVE;<br>
+ opts.idle_timeout_secs = DEFAULT_IDLE_TIMEOUT; <br> <br> #ifdef ENABLE_SVR_REMOTETCPFWD<br> opts.listen_fwd_all = 0;<br>@@ -218,6 +221,9 @@ void svr_getopts(int argc, char ** argv)<br> case 'K':<br>
next = &keepalive_arg;<br> break;<br>+ case 'I':<br>+ next = &idle_timeout_arg;<br>+ break;<br> #if defined(ENABLE_SVR_PASSWORD_AUTH) || defined(ENABLE_SVR_PAM_AUTH)<br>
case 's':<br> svr_opts.noauthpass = 1;<br>@@ -297,6 +303,13 @@ void svr_getopts(int argc, char ** argv)<br> dropbear_exit("Bad keepalive '%s'", keepalive_arg);<br>
}<br> }<br>+<br>+ if (idle_timeout_arg) {<br>+ opts.idle_timeout_secs = strtoul(idle_timeout_arg, NULL, 10);<br>+ if (opts.idle_timeout_secs == 0 && errno == EINVAL) {<br>+ dropbear_exit("Bad idle_timeout '%s'", idle_timeout_arg);<br>
+ }<br>+ }<br> }<br> <br> static void addportandaddress(char* spec) {<br></div>