comparison common-session.c @ 493:6cd2152aae0b idle-timeout

Idle-timeout patch from Farrell Aultman, need to figure whether to only account DATA packets and whether server->client data makes sense too.
author Matt Johnston <matt@ucc.asn.au>
date Mon, 22 Sep 2008 15:28:52 +0000
parents 738313e73b1c
children
comparison
equal deleted inserted replaced
492:b956d6151600 493:6cd2152aae0b
62 ses.sock_out = sock_out; 62 ses.sock_out = sock_out;
63 ses.maxfd = MAX(sock_in, sock_out); 63 ses.maxfd = MAX(sock_in, sock_out);
64 64
65 ses.connect_time = 0; 65 ses.connect_time = 0;
66 ses.last_packet_time = 0; 66 ses.last_packet_time = 0;
67 ses.last_recv_packet_time = 0;
67 68
68 if (pipe(ses.signal_pipe) < 0) { 69 if (pipe(ses.signal_pipe) < 0) {
69 dropbear_exit("signal pipe failed"); 70 dropbear_exit("signal pipe failed");
70 } 71 }
71 setnonblocking(ses.signal_pipe[0]); 72 setnonblocking(ses.signal_pipe[0]);
254 if (atomicio(write, ses.sock_out, LOCAL_IDENT "\r\n", 255 if (atomicio(write, ses.sock_out, LOCAL_IDENT "\r\n",
255 strlen(LOCAL_IDENT "\r\n")) == DROPBEAR_FAILURE) { 256 strlen(LOCAL_IDENT "\r\n")) == DROPBEAR_FAILURE) {
256 ses.remoteclosed(); 257 ses.remoteclosed();
257 } 258 }
258 259
259 /* If they send more than 50 lines, something is wrong */ 260 /* If they send more than 50 lines, something is wrong */
260 for (i = 0; i < 50; i++) { 261 for (i = 0; i < 50; i++) {
261 len = ident_readln(ses.sock_in, linebuf, sizeof(linebuf)); 262 len = ident_readln(ses.sock_in, linebuf, sizeof(linebuf));
262 263
263 if (len < 0 && errno != EINTR) { 264 if (len < 0 && errno != EINTR) {
264 /* It failed */ 265 /* It failed */
279 /* linebuf is already null terminated */ 280 /* linebuf is already null terminated */
280 ses.remoteident = m_malloc(len); 281 ses.remoteident = m_malloc(len);
281 memcpy(ses.remoteident, linebuf, len); 282 memcpy(ses.remoteident, linebuf, len);
282 } 283 }
283 284
284 /* Shall assume that 2.x will be backwards compatible. */ 285 /* Shall assume that 2.x will be backwards compatible. */
285 if (strncmp(ses.remoteident, "SSH-2.", 6) != 0 286 if (strncmp(ses.remoteident, "SSH-2.", 6) != 0
286 && strncmp(ses.remoteident, "SSH-1.99-", 9) != 0) { 287 && strncmp(ses.remoteident, "SSH-1.99-", 9) != 0) {
287 dropbear_exit("Incompatible remote version '%s'", ses.remoteident); 288 dropbear_exit("Incompatible remote version '%s'", ses.remoteident);
288 } 289 }
289 290
290 TRACE(("remoteident: %s", ses.remoteident)) 291 TRACE(("remoteident: %s", ses.remoteident))
291 292
292 } 293 }
293 294
398 399
399 if (opts.keepalive_secs > 0 400 if (opts.keepalive_secs > 0
400 && now - ses.last_packet_time >= opts.keepalive_secs) { 401 && now - ses.last_packet_time >= opts.keepalive_secs) {
401 send_msg_ignore(); 402 send_msg_ignore();
402 } 403 }
404
405 if (opts.idle_timeout_secs > 0 && ses.last_recv_packet_time > 0
406 && now - ses.last_recv_packet_time >= opts.idle_timeout_secs) {
407 dropbear_close("Idle timeout");
408 }
403 } 409 }
404 410
405 static long select_timeout() { 411 static long select_timeout() {
406 /* determine the minimum timeout that might be required, so 412 /* determine the minimum timeout that might be required, so
407 as to avoid waking when unneccessary */ 413 as to avoid waking when unneccessary */
410 ret = MIN(KEX_REKEY_TIMEOUT, ret); 416 ret = MIN(KEX_REKEY_TIMEOUT, ret);
411 if (AUTH_TIMEOUT > 0) 417 if (AUTH_TIMEOUT > 0)
412 ret = MIN(AUTH_TIMEOUT, ret); 418 ret = MIN(AUTH_TIMEOUT, ret);
413 if (opts.keepalive_secs > 0) 419 if (opts.keepalive_secs > 0)
414 ret = MIN(opts.keepalive_secs, ret); 420 ret = MIN(opts.keepalive_secs, ret);
421 if (opts.idle_timeout_secs > 0)
422 ret = MIN(opts.idle_timeout_secs, ret);
415 return ret; 423 return ret;
416 } 424 }
417 425
418 const char* get_user_shell() { 426 const char* get_user_shell() {
419 /* an empty shell should be interpreted as "/bin/sh" */ 427 /* an empty shell should be interpreted as "/bin/sh" */