Mercurial > dropbear
comparison common-session.c @ 513:a3748e54273c
Idle timeout patch from Farrell Aultman. Needs testing, unsure if server
code works
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Fri, 07 Nov 2008 14:11:06 +0000 |
parents | 43bbe17d6ba0 |
children | da6340a60039 |
comparison
equal
deleted
inserted
replaced
510:b85507ade010 | 513:a3748e54273c |
---|---|
61 ses.sock_in = sock_in; | 61 ses.sock_in = sock_in; |
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_trx_packet_time = 0; | |
66 ses.last_packet_time = 0; | 67 ses.last_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 } |
256 if (atomicio(write, ses.sock_out, LOCAL_IDENT "\r\n", | 257 if (atomicio(write, ses.sock_out, LOCAL_IDENT "\r\n", |
257 strlen(LOCAL_IDENT "\r\n")) == DROPBEAR_FAILURE) { | 258 strlen(LOCAL_IDENT "\r\n")) == DROPBEAR_FAILURE) { |
258 ses.remoteclosed(); | 259 ses.remoteclosed(); |
259 } | 260 } |
260 | 261 |
261 /* If they send more than 50 lines, something is wrong */ | 262 /* If they send more than 50 lines, something is wrong */ |
262 for (i = 0; i < 50; i++) { | 263 for (i = 0; i < 50; i++) { |
263 len = ident_readln(ses.sock_in, linebuf, sizeof(linebuf)); | 264 len = ident_readln(ses.sock_in, linebuf, sizeof(linebuf)); |
264 | 265 |
265 if (len < 0 && errno != EINTR) { | 266 if (len < 0 && errno != EINTR) { |
266 /* It failed */ | 267 /* It failed */ |
281 /* linebuf is already null terminated */ | 282 /* linebuf is already null terminated */ |
282 ses.remoteident = m_malloc(len); | 283 ses.remoteident = m_malloc(len); |
283 memcpy(ses.remoteident, linebuf, len); | 284 memcpy(ses.remoteident, linebuf, len); |
284 } | 285 } |
285 | 286 |
286 /* Shall assume that 2.x will be backwards compatible. */ | 287 /* Shall assume that 2.x will be backwards compatible. */ |
287 if (strncmp(ses.remoteident, "SSH-2.", 6) != 0 | 288 if (strncmp(ses.remoteident, "SSH-2.", 6) != 0 |
288 && strncmp(ses.remoteident, "SSH-1.99-", 9) != 0) { | 289 && strncmp(ses.remoteident, "SSH-1.99-", 9) != 0) { |
289 dropbear_exit("Incompatible remote version '%s'", ses.remoteident); | 290 dropbear_exit("Incompatible remote version '%s'", ses.remoteident); |
290 } | 291 } |
291 | 292 |
292 TRACE(("remoteident: %s", ses.remoteident)) | 293 TRACE(("remoteident: %s", ses.remoteident)) |
293 | 294 |
294 } | 295 } |
295 | 296 |
397 TRACE(("rekeying after timeout or max data reached")) | 398 TRACE(("rekeying after timeout or max data reached")) |
398 send_msg_kexinit(); | 399 send_msg_kexinit(); |
399 } | 400 } |
400 | 401 |
401 if (opts.keepalive_secs > 0 | 402 if (opts.keepalive_secs > 0 |
402 && now - ses.last_packet_time >= opts.keepalive_secs) { | 403 && now - ses.last_trx_packet_time >= opts.keepalive_secs) { |
403 send_msg_ignore(); | 404 send_msg_ignore(); |
405 } | |
406 | |
407 if (opts.idle_timeout_secs > 0 && ses.last_packet_time > 0 | |
408 && now - ses.last_packet_time >= opts.idle_timeout_secs) { | |
409 dropbear_close("Idle timeout"); | |
404 } | 410 } |
405 } | 411 } |
406 | 412 |
407 static long select_timeout() { | 413 static long select_timeout() { |
408 /* determine the minimum timeout that might be required, so | 414 /* determine the minimum timeout that might be required, so |
412 ret = MIN(KEX_REKEY_TIMEOUT, ret); | 418 ret = MIN(KEX_REKEY_TIMEOUT, ret); |
413 if (AUTH_TIMEOUT > 0) | 419 if (AUTH_TIMEOUT > 0) |
414 ret = MIN(AUTH_TIMEOUT, ret); | 420 ret = MIN(AUTH_TIMEOUT, ret); |
415 if (opts.keepalive_secs > 0) | 421 if (opts.keepalive_secs > 0) |
416 ret = MIN(opts.keepalive_secs, ret); | 422 ret = MIN(opts.keepalive_secs, ret); |
423 if (opts.idle_timeout_secs > 0) | |
424 ret = MIN(opts.idle_timeout_secs, ret); | |
417 return ret; | 425 return ret; |
418 } | 426 } |
419 | 427 |
420 const char* get_user_shell() { | 428 const char* get_user_shell() { |
421 /* an empty shell should be interpreted as "/bin/sh" */ | 429 /* an empty shell should be interpreted as "/bin/sh" */ |