summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorTim Potter <tpot@samba.org>2002-11-02 01:35:18 +0000
committerTim Potter <tpot@samba.org>2002-11-02 01:35:18 +0000
commit674790b7bdffe227674740e119b7b015d2593b43 (patch)
tree89723cba8fa17cf3d2b9102247817aec02187502 /source3
parent209f91134455215999b5764957bff60f6b500c4e (diff)
downloadsamba-674790b7bdffe227674740e119b7b015d2593b43.tar.gz
samba-674790b7bdffe227674740e119b7b015d2593b43.tar.bz2
samba-674790b7bdffe227674740e119b7b015d2593b43.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 846b5494942c73e68616e7eae0d2fd5ae4b2bc05)
Diffstat (limited to 'source3')
-rw-r--r--source3/nsswitch/winbindd.c60
-rw-r--r--source3/nsswitch/winbindd_util.c86
2 files changed, 108 insertions, 38 deletions
diff --git a/source3/nsswitch/winbindd.c b/source3/nsswitch/winbindd.c
index 5b9c5418a1..7dbdca97ee 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 */
@@ -532,9 +518,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;
@@ -545,7 +534,7 @@ static void process_loop(int accept_sock)
/* Set up client readers and writers */
- state = client_list;
+ state = winbindd_client_list();
while (state) {
@@ -601,12 +590,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 */
@@ -660,7 +650,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);
@@ -755,7 +747,6 @@ static void usage(void)
extern fstring global_myworkgroup;
extern BOOL append_log;
pstring logfile;
- int accept_sock;
BOOL interactive = False;
int opt;
@@ -883,16 +874,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 fd3e547afb..ebca273d70 100644
--- a/source3/nsswitch/winbindd_util.c
+++ b/source3/nsswitch/winbindd_util.c
@@ -446,3 +446,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;
+}