From e6951db0e171ce11b17694ecf081c1c7b8afc553 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Mon, 10 Feb 2003 09:56:23 +0200 Subject: [PATCH] Don't accept client connections before we're connected to all auth processes. --HG-- branch : HEAD --- src/login-common/auth-connection.c | 13 ++++++++++++- src/login-common/auth-connection.h | 2 ++ src/login-common/main.c | 14 ++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/login-common/auth-connection.c b/src/login-common/auth-connection.c index dd0801868a..ffe6f41ace 100644 --- a/src/login-common/auth-connection.c +++ b/src/login-common/auth-connection.c @@ -25,6 +25,7 @@ static int auth_reconnect; static unsigned int request_id_counter; static struct auth_connection *auth_connections; static struct timeout *to; +static unsigned int auth_waiting_handshake_count; static void auth_connection_destroy(struct auth_connection *conn); static void auth_connection_unref(struct auth_connection *conn); @@ -76,6 +77,7 @@ static struct auth_connection *auth_connection_new(const char *path) auth_connections = conn; /* send our handshake */ + auth_waiting_handshake_count++; memset(&handshake, 0, sizeof(handshake)); handshake.pid = login_process_uid; if (o_stream_send(conn->output, &handshake, sizeof(handshake)) < 0) { @@ -117,6 +119,8 @@ static void auth_connection_destroy(struct auth_connection *conn) } } + auth_waiting_handshake_count--; + if (close(conn->fd) < 0) i_error("close(auth) failed: %m"); io_remove(conn->io); @@ -195,6 +199,7 @@ static void auth_handle_handshake(struct auth_connection *conn, conn->available_auth_mechs = handshake->auth_mechanisms; conn->handshake_received = TRUE; + auth_waiting_handshake_count--; update_available_auth_mechs(); } @@ -359,6 +364,11 @@ void auth_request_unref(struct auth_request *request) auth_connection_unref(request->conn); } +int auth_is_connected(void) +{ + return !auth_reconnect && auth_waiting_handshake_count == 0; +} + static void auth_connect_missing(void) { DIR *dirp; @@ -404,7 +414,8 @@ void auth_connection_init(void) { auth_connections = NULL; request_id_counter = 0; - auth_reconnect = FALSE; + auth_reconnect = FALSE; + auth_waiting_handshake_count = 0; auth_connect_missing(); to = timeout_add(1000, auth_connect_missing_timeout, NULL); diff --git a/src/login-common/auth-connection.h b/src/login-common/auth-connection.h index 15e423cc0c..5e5cf7d121 100644 --- a/src/login-common/auth-connection.h +++ b/src/login-common/auth-connection.h @@ -55,6 +55,8 @@ void auth_abort_request(struct auth_request *request); void auth_request_ref(struct auth_request *request); void auth_request_unref(struct auth_request *request); +int auth_is_connected(void); + void auth_connection_init(void); void auth_connection_deinit(void); diff --git a/src/login-common/main.c b/src/login-common/main.c index 99ba52e8bd..5c7af2b015 100644 --- a/src/login-common/main.c +++ b/src/login-common/main.c @@ -76,6 +76,13 @@ static void login_accept(void *context __attr_unused__) struct ip_addr ip; int fd; + if (!auth_is_connected()) { + /* we're not yet connected to auth process - + don't accept client connections. FIXME: eats CPU if + none of the other login processes accept it either.. */ + return; + } + fd = net_accept(LOGIN_LISTEN_FD, &ip, NULL); if (fd < 0) { if (fd < -1) @@ -95,6 +102,13 @@ static void login_accept_ssl(void *context __attr_unused__) struct ip_addr ip; int fd, fd_ssl; + if (!auth_is_connected()) { + /* we're not yet connected to auth process - + don't accept client connections. FIXME: eats CPU if + none of the other login processes accept it either.. */ + return; + } + fd = net_accept(LOGIN_SSL_LISTEN_FD, &ip, NULL); if (fd < 0) { if (fd < -1) -- 2.47.3