diff options
Diffstat (limited to 'source/nsswitch/winbindd.c')
-rw-r--r-- | source/nsswitch/winbindd.c | 189 |
1 files changed, 54 insertions, 135 deletions
diff --git a/source/nsswitch/winbindd.c b/source/nsswitch/winbindd.c index 2eedbcbd0f0..34f04adab2e 100644 --- a/source/nsswitch/winbindd.c +++ b/source/nsswitch/winbindd.c @@ -7,7 +7,6 @@ Copyright (C) Andrew Tridgell 2002 Copyright (C) Jelmer Vernooij 2003 Copyright (C) Volker Lendecke 2004 - Copyright (C) James Peach 2007 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -31,6 +30,7 @@ #define DBGC_CLASS DBGC_WINBIND BOOL opt_nocache = False; +static BOOL interactive = False; extern BOOL override_logfile; @@ -39,18 +39,7 @@ struct event_context *winbind_event_context(void) static struct event_context *ctx; if (!ctx && !(ctx = event_context_init(NULL))) { - smb_panic("Could not init winbind event context"); - } - return ctx; -} - -struct messaging_context *winbind_messaging_context(void) -{ - static struct messaging_context *ctx; - - if (!ctx && !(ctx = messaging_init(NULL, server_id_self(), - winbind_event_context()))) { - smb_panic("Could not init winbind messaging context"); + smb_panic("Could not init winbind event context\n"); } return ctx; } @@ -130,8 +119,13 @@ static void flush_caches(void) static void terminate(void) { + pstring path; + + /* Remove socket file */ + pstr_sprintf(path, "%s/%s", + WINBINDD_SOCKET_DIR, WINBINDD_SOCKET_NAME); + unlink(path); - winbindd_release_sockets(); idmap_close(); trustdom_cache_shutdown(); @@ -182,11 +176,8 @@ static void sigchld_handler(int signum) } /* React on 'smbcontrol winbindd reload-config' in the same way as on SIGHUP*/ -static void msg_reload_services(struct messaging_context *msg, - void *private_data, - uint32_t msg_type, - struct server_id server_id, - DATA_BLOB *data) +static void msg_reload_services(int msg_type, struct process_id src, + void *buf, size_t len, void *private_data) { /* Flush various caches */ flush_caches(); @@ -194,11 +185,8 @@ static void msg_reload_services(struct messaging_context *msg, } /* React on 'smbcontrol winbindd shutdown' in the same way as on SIGTERM*/ -static void msg_shutdown(struct messaging_context *msg, - void *private_data, - uint32_t msg_type, - struct server_id server_id, - DATA_BLOB *data) +static void msg_shutdown(int msg_type, struct process_id src, + void *buf, size_t len, void *private_data) { do_sigterm = True; } @@ -735,19 +723,28 @@ static BOOL remove_idle_client(void) simultaneous connections while remaining impervious to many denial of service attacks. */ -static int process_loop(int listen_sock, int listen_priv_sock) +static void process_loop(void) { struct winbindd_cli_state *state; struct fd_event *ev; fd_set r_fds, w_fds; - int maxfd, selret; + int maxfd, listen_sock, listen_priv_sock, selret; struct timeval timeout, ev_timeout; + /* Open Sockets here to get stuff going ASAP */ + listen_sock = open_winbindd_socket(); + listen_priv_sock = open_winbindd_priv_socket(); + + if (listen_sock == -1 || listen_priv_sock == -1) { + perror("open_winbind_socket"); + exit(1); + } + /* We'll be doing this a lot */ /* Handle messages */ - message_dispatch(winbind_messaging_context()); + message_dispatch(); run_events(winbind_event_context(), 0, NULL, NULL); @@ -892,9 +889,7 @@ static int process_loop(int listen_sock, int listen_priv_sock) DEBUG(3, ("got SIGHUP\n")); - flush_caches(); - reload_services_file(); - + msg_reload_services(MSG_SMB_CONF_UPDATED, pid_to_procid(0), NULL, 0, NULL); do_sighup = False; } @@ -912,55 +907,6 @@ static int process_loop(int listen_sock, int listen_priv_sock) winbind_child_died(pid); } } - - - return winbindd_num_clients(); -} - -static void winbindd_process_loop(enum smb_server_mode server_mode) -{ - int idle_timeout_sec; - struct timeval starttime; - int listen_public, listen_priv; - - errno = 0; - if (!winbindd_init_sockets(&listen_public, &listen_priv, - &idle_timeout_sec)) { - terminate(); - } - - starttime = timeval_current(); - - if (listen_public == -1 || listen_priv == -1) { - DEBUG(0, ("failed to open winbindd pipes: %s\n", - errno ? strerror(errno) : "unknown error")); - terminate(); - } - - for (;;) { - int clients = process_loop(listen_public, listen_priv); - - /* Don't bother figuring out the idle time if we won't be - * timing out anyway. - */ - if (idle_timeout_sec < 0) { - continue; - } - - if (clients == 0 && server_mode == SERVER_MODE_FOREGROUND) { - struct timeval now; - - now = timeval_current(); - if (timeval_elapsed2(&starttime, &now) > - (double)idle_timeout_sec) { - DEBUG(0, ("idle for %d secs, exitting\n", - idle_timeout_sec)); - terminate(); - } - } else { - starttime = timeval_current(); - } - } } /* Main function */ @@ -968,17 +914,15 @@ static void winbindd_process_loop(enum smb_server_mode server_mode) int main(int argc, char **argv, char **envp) { pstring logfile; - BOOL log_stdout = False; - BOOL no_process_group = False; - - enum smb_server_mode server_mode = SERVER_MODE_DAEMON; - + static BOOL Fork = True; + static BOOL log_stdout = False; + static BOOL no_process_group = False; struct poptOption long_options[] = { POPT_AUTOHELP { "stdout", 'S', POPT_ARG_VAL, &log_stdout, True, "Log to stdout" }, - { "foreground", 'F', POPT_ARG_VAL, &server_mode, SERVER_MODE_FOREGROUND, "Daemon in foreground mode" }, + { "foreground", 'F', POPT_ARG_VAL, &Fork, False, "Daemon in foreground mode" }, { "no-process-group", 0, POPT_ARG_VAL, &no_process_group, True, "Don't create a new process group" }, - { "interactive", 'i', POPT_ARG_VAL, &server_mode, SERVER_MODE_INTERACTIVE, "Interactive mode" }, + { "interactive", 'i', POPT_ARG_NONE, NULL, 'i', "Interactive mode" }, { "no-caching", 'n', POPT_ARG_VAL, &opt_nocache, True, "Disable caching" }, POPT_COMMON_SAMBA POPT_TABLEEND @@ -1016,17 +960,20 @@ int main(int argc, char **argv, char **envp) pc = poptGetContext("winbindd", argc, (const char **)argv, long_options, POPT_CONTEXT_KEEP_FIRST); - while ((opt = poptGetNextOpt(pc)) != -1) {} - - if (server_mode == SERVER_MODE_INTERACTIVE) { - log_stdout = True; - if (DEBUGLEVEL >= 9) { - talloc_enable_leak_report(); + while ((opt = poptGetNextOpt(pc)) != -1) { + switch (opt) { + /* Don't become a daemon */ + case 'i': + interactive = True; + log_stdout = True; + Fork = False; + break; } } - if (log_stdout && server_mode == SERVER_MODE_DAEMON) { - printf("Can't log to stdout (-S) unless daemon is in foreground (-F) or interactive (-i)\n"); + + if (log_stdout && Fork) { + printf("Can't log to stdout (-S) unless daemon is in foreground +(-F) or interactive (-i)\n"); poptPrintUsage(pc, stderr, 0); exit(1); } @@ -1097,44 +1044,25 @@ int main(int argc, char **argv, char **envp) CatchSignal(SIGUSR2, sigusr2_handler); /* Debugging sigs */ CatchSignal(SIGHUP, sighup_handler); - if (server_mode == SERVER_MODE_DAEMON) { - DEBUG( 3, ( "Becoming a daemon.\n" ) ); - become_daemon(True, no_process_group); - } else if (server_mode == SERVER_MODE_FOREGROUND) { - become_daemon(False, no_process_group); - } + if (!interactive) + become_daemon(Fork, no_process_group); pidfile_create("winbindd"); - /* Ensure all cache and idmap caches are consistent - before we startup. */ - - if (winbindd_validate_cache()) { - /* We have a bad cache, but luckily we - just deleted it. Restart ourselves */ - int i; - /* Ensure we have no open low fd's. */ - for (i = 3; i < 100; i++) { - close(i); - } - return execve(argv[0], argv, envp); - } - #if HAVE_SETPGID /* * If we're interactive we want to set our own process group for * signal management. */ - if (server_mode == SERVER_MODE_INTERACTIVE && !no_process_group) { + if (interactive && !no_process_group) setpgid( (pid_t)0, (pid_t)0); - } #endif TimeInit(); /* Initialise messaging system */ - if (winbind_messaging_context() == NULL) { + if (!message_init()) { DEBUG(0, ("unable to initialize messaging system\n")); exit(1); } @@ -1146,30 +1074,19 @@ int main(int argc, char **argv, char **envp) /* React on 'smbcontrol winbindd reload-config' in the same way as to SIGHUP signal */ - messaging_register(winbind_messaging_context(), NULL, - MSG_SMB_CONF_UPDATED, msg_reload_services); - messaging_register(winbind_messaging_context(), NULL, - MSG_SHUTDOWN, msg_shutdown); + message_register(MSG_SMB_CONF_UPDATED, msg_reload_services, NULL); + message_register(MSG_SHUTDOWN, msg_shutdown, NULL); /* Handle online/offline messages. */ - messaging_register(winbind_messaging_context(), NULL, - MSG_WINBIND_OFFLINE, winbind_msg_offline); - messaging_register(winbind_messaging_context(), NULL, - MSG_WINBIND_ONLINE, winbind_msg_online); - messaging_register(winbind_messaging_context(), NULL, - MSG_WINBIND_ONLINESTATUS, winbind_msg_onlinestatus); - - messaging_register(winbind_messaging_context(), NULL, - MSG_DUMP_EVENT_LIST, winbind_msg_dump_event_list); + message_register(MSG_WINBIND_OFFLINE, winbind_msg_offline, NULL); + message_register(MSG_WINBIND_ONLINE, winbind_msg_online, NULL); + message_register(MSG_WINBIND_ONLINESTATUS, winbind_msg_onlinestatus, + NULL); poptFreeContext(pc); netsamlogon_cache_init(); /* Non-critical */ - /* clear the cached list of trusted domains */ - - wcache_tdc_clear(); - if (!init_domain_list()) { DEBUG(0,("unable to initalize domain list\n")); exit(1); @@ -1181,7 +1098,9 @@ int main(int argc, char **argv, char **envp) smb_nscd_flush_group_cache(); /* Loop waiting for requests */ - winbindd_process_loop(server_mode); + + while (1) + process_loop(); return 0; } |