diff options
author | Tim Potter <tpot@samba.org> | 2002-11-02 01:36:42 +0000 |
---|---|---|
committer | Tim Potter <tpot@samba.org> | 2002-11-02 01:36:42 +0000 |
commit | d759a020941f323ea90e73dcbb83b6c64ecd614f (patch) | |
tree | 6609a2631bdedbb65f3f449bedf49d99e009deae | |
parent | 500905fedb0ff6b054ea121e8b42529d69a16ae7 (diff) | |
download | samba-d759a020941f323ea90e73dcbb83b6c64ecd614f.tar.gz samba-d759a020941f323ea90e73dcbb83b6c64ecd614f.tar.bz2 samba-d759a020941f323ea90e73dcbb83b6c64ecd614f.zip |
Some winbindd cleanups I made trying to fix cr1020:
- move winbindd client handling into accessor functions in
winbindd_util.c
- move some winbindd socket routines into accessor functions in
winbindd_utils.c
(The deadlock situation mentioned in the appliance branch is probably
not applicable since we don't clear the connection cache on SIGHUP.
Perhaps we should?)
(This used to be commit ee0e3d31a1d1bef70810aadcdafdf9678d21ea8f)
-rw-r--r-- | source3/nsswitch/winbindd.c | 60 | ||||
-rw-r--r-- | source3/nsswitch/winbindd_util.c | 86 |
2 files changed, 108 insertions, 38 deletions
diff --git a/source3/nsswitch/winbindd.c b/source3/nsswitch/winbindd.c index d394a57837..0df9408a60 100644 --- a/source3/nsswitch/winbindd.c +++ b/source3/nsswitch/winbindd.c @@ -23,10 +23,6 @@ #include "winbindd.h" -/* List of all connected clients */ - -static struct winbindd_cli_state *client_list; -static int num_clients; BOOL opt_nocache = False; BOOL opt_dual_daemon = False; @@ -121,11 +117,11 @@ static void winbindd_status(void) /* Print client state information */ - DEBUG(0, ("\t%d clients currently active\n", num_clients)); + DEBUG(0, ("\t%d clients currently active\n", winbindd_num_clients())); - if (DEBUGLEVEL >= 2 && num_clients) { + if (DEBUGLEVEL >= 2 && winbindd_num_clients()) { DEBUG(2, ("\tclient list:\n")); - for(tmp = client_list; tmp; tmp = tmp->next) { + for(tmp = winbindd_client_list(); tmp; tmp = tmp->next) { DEBUG(2, ("\t\tpid %d, sock %d, rbl %d, wbl %d\n", tmp->pid, tmp->sock, tmp->read_buf_len, tmp->write_buf_len)); @@ -189,14 +185,6 @@ static void sighup_handler(int signum) sys_select_signal(); } -/* Create winbindd socket */ - -static int create_sock(void) -{ - return create_pipe_sock( WINBINDD_SOCKET_DIR, - WINBINDD_SOCKET_NAME, 0755); -} - struct dispatch_table { enum winbindd_cmd cmd; enum winbindd_result (*fn)(struct winbindd_cli_state *state); @@ -303,7 +291,7 @@ static void process_request(struct winbindd_cli_state *state) /* Process a new connection by adding it to the client connection list */ -static void new_connection(int accept_sock) +static void new_connection(int listen_sock) { struct sockaddr_un sunaddr; struct winbindd_cli_state *state; @@ -315,7 +303,7 @@ static void new_connection(int accept_sock) len = sizeof(sunaddr); do { - sock = accept(accept_sock, (struct sockaddr *)&sunaddr, &len); + sock = accept(listen_sock, (struct sockaddr *)&sunaddr, &len); } while (sock == -1 && errno == EINTR); if (sock == -1) @@ -334,8 +322,7 @@ static void new_connection(int accept_sock) /* Add to connection list */ - DLIST_ADD(client_list, state); - num_clients++; + winbindd_add_client(state); } /* Remove a client connection from client connection list */ @@ -362,9 +349,8 @@ static void remove_client(struct winbindd_cli_state *state) /* Remove from list and free */ - DLIST_REMOVE(client_list, state); + winbindd_remove_client(state); SAFE_FREE(state); - num_clients--; } } @@ -507,14 +493,14 @@ static void client_write(struct winbindd_cli_state *state) simultaneous connections while remaining impervious to many denial of service attacks. */ -static void process_loop(int accept_sock) +static void process_loop(void) { /* We'll be doing this a lot */ while (1) { struct winbindd_cli_state *state; fd_set r_fds, w_fds; - int maxfd = accept_sock, selret; + int maxfd, listen_sock, selret; struct timeval timeout; /* Handle messages */ @@ -528,9 +514,12 @@ static void process_loop(int accept_sock) /* Initialise fd lists for select() */ + listen_sock = open_winbindd_socket(); + maxfd = listen_sock; + FD_ZERO(&r_fds); FD_ZERO(&w_fds); - FD_SET(accept_sock, &r_fds); + FD_SET(listen_sock, &r_fds); timeout.tv_sec = WINBINDD_ESTABLISH_LOOP; timeout.tv_usec = 0; @@ -541,7 +530,7 @@ static void process_loop(int accept_sock) /* Set up client readers and writers */ - state = client_list; + state = winbindd_client_list(); while (state) { @@ -597,12 +586,13 @@ static void process_loop(int accept_sock) dual_select(&w_fds); } - if (FD_ISSET(accept_sock, &r_fds)) - new_connection(accept_sock); + if (FD_ISSET(listen_sock, &r_fds)) + new_connection(listen_sock); /* Process activity on client connections */ - for (state = client_list; state; state = state->next) { + for (state = winbindd_client_list(); state; + state = state->next) { /* Data available for reading */ @@ -656,7 +646,9 @@ static void process_loop(int accept_sock) if (do_sighup) { - /* Flush winbindd cache */ + DEBUG(3, ("got SIGHUP\n")); + + /* Flush various caches */ flush_caches(); reload_services_file(True); @@ -751,7 +743,6 @@ static void usage(void) extern fstring global_myworkgroup; extern BOOL append_log; pstring logfile; - int accept_sock; BOOL interactive = False; int opt; @@ -879,16 +870,9 @@ static void usage(void) register_msg_pool_usage(); - /* Create UNIX domain socket */ - - if ((accept_sock = create_sock()) == -1) { - DEBUG(0, ("failed to create socket\n")); - return 1; - } - /* Loop waiting for requests */ - process_loop(accept_sock); + process_loop(); uni_group_cache_shutdown(); return 0; diff --git a/source3/nsswitch/winbindd_util.c b/source3/nsswitch/winbindd_util.c index 00354187aa..cb8870d6f3 100644 --- a/source3/nsswitch/winbindd_util.c +++ b/source3/nsswitch/winbindd_util.c @@ -441,3 +441,89 @@ void fill_domain_username(fstring name, const char *domain, const char *user) user); } } + +/* + * Winbindd socket accessor functions + */ + +/* Open the winbindd socket */ + +static int _winbindd_socket = -1; + +int open_winbindd_socket(void) +{ + if (_winbindd_socket == -1) { + _winbindd_socket = create_pipe_sock( + WINBINDD_SOCKET_DIR, WINBINDD_SOCKET_NAME, 0755); + DEBUG(10, ("open_winbindd_socket: opened socket fd %d\n", + _winbindd_socket)); + } + + return _winbindd_socket; +} + +/* Close the winbindd socket */ + +void close_winbindd_socket(void) +{ + if (_winbindd_socket != -1) { + DEBUG(10, ("close_winbindd_socket: closing socket fd %d\n", + _winbindd_socket)); + close(_winbindd_socket); + _winbindd_socket = -1; + } +} + +/* + * Client list accessor functions + */ + +static struct winbindd_cli_state *_client_list; +static int _num_clients; + +/* Return list of all connected clients */ + +struct winbindd_cli_state *winbindd_client_list(void) +{ + return _client_list; +} + +/* Add a connection to the list */ + +void winbindd_add_client(struct winbindd_cli_state *cli) +{ + DLIST_ADD(_client_list, cli); + _num_clients++; +} + +/* Remove a client from the list */ + +void winbindd_remove_client(struct winbindd_cli_state *cli) +{ + DLIST_REMOVE(_client_list, cli); + _num_clients--; +} + +/* Close all open clients */ + +void winbindd_kill_all_clients(void) +{ + struct winbindd_cli_state *cl = winbindd_client_list(); + + DEBUG(10, ("winbindd_kill_all_clients: going postal\n")); + + while (cl) { + struct winbindd_cli_state *next; + + next = cl->next; + winbindd_remove_client(cl); + cl = next; + } +} + +/* Return number of open clients */ + +int winbindd_num_clients(void) +{ + return _num_clients; +} |