From 759b7f34b0e386e3bdad97f7ba446de7a44ba69e Mon Sep 17 00:00:00 2001 From: Tzafrir Cohen Date: Sun, 20 Mar 2011 15:43:27 +0200 Subject: [PATCH] Timeout of 30 secconds to pre-auth manager reads A better work-around: introduce a timeout of (currently: hardcoded) 30 seconds to manager interface reads. In case of a time out: break connection. --- main/manager.c | 10 +++++++++- 1 files changed, 9 insertions(+), 1 deletions(-) diff --git a/main/manager.c b/main/manager.c index 74f9ecc..a4afe59 100644 --- a/main/manager.c +++ b/main/manager.c @@ -944,6 +944,7 @@ struct mansession_session { int send_events; /*!< XXX what ? */ struct eventqent *last_ev; /*!< last event processed. */ int writetimeout; /*!< Timeout for ast_carefulwrite() */ + int read_timeout; /*!< Timeout for ast_wait_for_input() */ int pending_event; /*!< Pending events indicator in case when waiting_thread is NULL */ time_t noncetime; /*!< Timer for nonce value expiration */ unsigned long oldnonce; /*!< Stale nonce value */ @@ -2929,6 +2930,8 @@ static int action_login(struct mansession *s, const struct message *m) return -1; } s->session->authenticated = 1; + /* Unlimited timeout for authenticated users: */ + s->session->read_timeout = -1; if (manager_displayconnects(s->session)) { ast_verb(2, "%sManager '%s' logged on from %s\n", (s->session->managerid ? "HTTP " : ""), s->session->username, ast_inet_ntoa(s->session->sin.sin_addr)); } @@ -4572,7 +4575,11 @@ static int get_input(struct mansession *s, char *output) s->session->waiting_thread = pthread_self(); ao2_unlock(s->session); - res = ast_wait_for_input(s->session->fd, -1); /* return 0 on timeout ? */ + res = ast_wait_for_input(s->session->fd, s->session->read_timeout); /* return 0 on timeout ? */ + if ((res == 0) && (s->session->read_timeout > 0)) { + res = -1; + errno = ETIME; + } ao2_lock(s->session); s->session->waiting_thread = AST_PTHREADT_NULL; @@ -4686,6 +4693,7 @@ static void *session_do(void *data) session->fd = s.fd = ser->fd; session->f = s.f = ser->f; session->sin = ser_remote_address_tmp; + session->read_timeout = 30000; /* 30 seconds */ s.session = session; AST_LIST_HEAD_INIT_NOLOCK(&session->datastores); -- 1.7.4.1