2 Unix SMB/CIFS implementation.
4 Winbind daemon for ntdom nss module
6 Copyright (C) by Tim Potter 2000-2002
7 Copyright (C) Andrew Tridgell 2002
8 Copyright (C) Jelmer Vernooij 2003
9 Copyright (C) Volker Lendecke 2004
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30 #define DBGC_CLASS DBGC_WINBIND
32 BOOL opt_nocache = False;
33 static BOOL interactive = False;
35 extern BOOL override_logfile;
37 /* Reload configuration */
39 static BOOL reload_services_file(void)
46 pstrcpy(fname,lp_configfile());
47 if (file_exist(fname,NULL) && !strcsequal(fname,dyn_CONFIGFILE)) {
48 pstrcpy(dyn_CONFIGFILE,fname);
53 ret = lp_load(dyn_CONFIGFILE,False,False,True,True);
62 /**************************************************************************** **
64 **************************************************************************** */
66 static void fault_quit(void)
71 static void winbindd_status(void)
73 struct winbindd_cli_state *tmp;
75 DEBUG(0, ("winbindd status:\n"));
77 /* Print client state information */
79 DEBUG(0, ("\t%d clients currently active\n", winbindd_num_clients()));
81 if (DEBUGLEVEL >= 2 && winbindd_num_clients()) {
82 DEBUG(2, ("\tclient list:\n"));
83 for(tmp = winbindd_client_list(); tmp; tmp = tmp->next) {
84 DEBUGADD(2, ("\t\tpid %lu, sock %d\n",
85 (unsigned long)tmp->pid, tmp->sock));
90 /* Print winbindd status to log file */
92 static void print_winbindd_status(void)
97 /* Flush client cache */
99 static void flush_caches(void)
101 /* We need to invalidate cached user list entries on a SIGHUP
102 otherwise cached access denied errors due to restrict anonymous
103 hang around until the sequence number changes. */
105 wcache_invalidate_cache();
108 /* Handle the signal by unlinking socket and exiting */
110 static void terminate(void)
116 /* Remove socket file */
117 pstr_sprintf(path, "%s/%s",
118 WINBINDD_SOCKET_DIR, WINBINDD_SOCKET_NAME);
123 TALLOC_CTX *mem_ctx = talloc_init("end_description");
124 char *description = talloc_describe_all(mem_ctx);
126 DEBUG(3, ("tallocs left:\n%s\n", description));
127 talloc_destroy(mem_ctx);
134 static BOOL do_sigterm;
136 static void termination_handler(int signum)
139 sys_select_signal(signum);
142 static BOOL do_sigusr2;
144 static void sigusr2_handler(int signum)
147 sys_select_signal(SIGUSR2);
150 static BOOL do_sighup;
152 static void sighup_handler(int signum)
155 sys_select_signal(SIGHUP);
158 static BOOL do_sigchld;
160 static void sigchld_handler(int signum)
163 sys_select_signal(SIGCHLD);
166 /* React on 'smbcontrol winbindd reload-config' in the same way as on SIGHUP*/
167 static void msg_reload_services(int msg_type, struct process_id src, void *buf, size_t len)
169 /* Flush various caches */
171 reload_services_file();
174 /* React on 'smbcontrol winbindd shutdown' in the same way as on SIGTERM*/
175 static void msg_shutdown(int msg_type, struct process_id src, void *buf, size_t len)
180 static struct winbindd_dispatch_table {
181 enum winbindd_cmd cmd;
182 void (*fn)(struct winbindd_cli_state *state);
183 const char *winbindd_cmd_name;
184 } dispatch_table[] = {
188 { WINBINDD_GETPWNAM, winbindd_getpwnam, "GETPWNAM" },
189 { WINBINDD_GETPWUID, winbindd_getpwuid, "GETPWUID" },
191 { WINBINDD_SETPWENT, winbindd_setpwent, "SETPWENT" },
192 { WINBINDD_ENDPWENT, winbindd_endpwent, "ENDPWENT" },
193 { WINBINDD_GETPWENT, winbindd_getpwent, "GETPWENT" },
195 { WINBINDD_GETGROUPS, winbindd_getgroups, "GETGROUPS" },
196 { WINBINDD_GETUSERSIDS, winbindd_getusersids, "GETUSERSIDS" },
197 { WINBINDD_GETUSERDOMGROUPS, winbindd_getuserdomgroups,
198 "GETUSERDOMGROUPS" },
200 /* Group functions */
202 { WINBINDD_GETGRNAM, winbindd_getgrnam, "GETGRNAM" },
203 { WINBINDD_GETGRGID, winbindd_getgrgid, "GETGRGID" },
204 { WINBINDD_SETGRENT, winbindd_setgrent, "SETGRENT" },
205 { WINBINDD_ENDGRENT, winbindd_endgrent, "ENDGRENT" },
206 { WINBINDD_GETGRENT, winbindd_getgrent, "GETGRENT" },
207 { WINBINDD_GETGRLST, winbindd_getgrent, "GETGRLST" },
209 /* PAM auth functions */
211 { WINBINDD_PAM_AUTH, winbindd_pam_auth, "PAM_AUTH" },
212 { WINBINDD_PAM_AUTH_CRAP, winbindd_pam_auth_crap, "AUTH_CRAP" },
213 { WINBINDD_PAM_CHAUTHTOK, winbindd_pam_chauthtok, "CHAUTHTOK" },
214 { WINBINDD_PAM_LOGOFF, winbindd_pam_logoff, "PAM_LOGOFF" },
215 { WINBINDD_PAM_CHNG_PSWD_AUTH_CRAP, winbindd_pam_chng_pswd_auth_crap, "CHNG_PSWD_AUTH_CRAP" },
217 /* Enumeration functions */
219 { WINBINDD_LIST_USERS, winbindd_list_users, "LIST_USERS" },
220 { WINBINDD_LIST_GROUPS, winbindd_list_groups, "LIST_GROUPS" },
221 { WINBINDD_LIST_TRUSTDOM, winbindd_list_trusted_domains,
223 { WINBINDD_SHOW_SEQUENCE, winbindd_show_sequence, "SHOW_SEQUENCE" },
225 /* SID related functions */
227 { WINBINDD_LOOKUPSID, winbindd_lookupsid, "LOOKUPSID" },
228 { WINBINDD_LOOKUPNAME, winbindd_lookupname, "LOOKUPNAME" },
229 { WINBINDD_LOOKUPRIDS, winbindd_lookuprids, "LOOKUPRIDS" },
231 /* Lookup related functions */
233 { WINBINDD_SID_TO_UID, winbindd_sid_to_uid, "SID_TO_UID" },
234 { WINBINDD_SID_TO_GID, winbindd_sid_to_gid, "SID_TO_GID" },
235 { WINBINDD_UID_TO_SID, winbindd_uid_to_sid, "UID_TO_SID" },
236 { WINBINDD_GID_TO_SID, winbindd_gid_to_sid, "GID_TO_SID" },
237 { WINBINDD_SIDS_TO_XIDS, winbindd_sids_to_unixids, "SIDS_TO_XIDS" },
238 { WINBINDD_ALLOCATE_UID, winbindd_allocate_uid, "ALLOCATE_UID" },
239 { WINBINDD_ALLOCATE_GID, winbindd_allocate_gid, "ALLOCATE_GID" },
240 { WINBINDD_SET_MAPPING, winbindd_set_mapping, "SET_MAPPING" },
241 { WINBINDD_SET_HWM, winbindd_set_hwm, "SET_HWMS" },
245 { WINBINDD_DUMP_MAPS, winbindd_dump_maps, "DUMP_MAPS" },
247 { WINBINDD_CHECK_MACHACC, winbindd_check_machine_acct, "CHECK_MACHACC" },
248 { WINBINDD_PING, winbindd_ping, "PING" },
249 { WINBINDD_INFO, winbindd_info, "INFO" },
250 { WINBINDD_INTERFACE_VERSION, winbindd_interface_version,
251 "INTERFACE_VERSION" },
252 { WINBINDD_DOMAIN_NAME, winbindd_domain_name, "DOMAIN_NAME" },
253 { WINBINDD_DOMAIN_INFO, winbindd_domain_info, "DOMAIN_INFO" },
254 { WINBINDD_NETBIOS_NAME, winbindd_netbios_name, "NETBIOS_NAME" },
255 { WINBINDD_PRIV_PIPE_DIR, winbindd_priv_pipe_dir,
256 "WINBINDD_PRIV_PIPE_DIR" },
257 { WINBINDD_GETDCNAME, winbindd_getdcname, "GETDCNAME" },
259 /* Credential cache access */
260 { WINBINDD_CCACHE_NTLMAUTH, winbindd_ccache_ntlm_auth, "NTLMAUTH" },
264 { WINBINDD_WINS_BYNAME, winbindd_wins_byname, "WINS_BYNAME" },
265 { WINBINDD_WINS_BYIP, winbindd_wins_byip, "WINS_BYIP" },
269 { WINBINDD_NUM_CMDS, NULL, "NONE" }
272 static void process_request(struct winbindd_cli_state *state)
274 struct winbindd_dispatch_table *table = dispatch_table;
276 /* Free response data - we may be interrupted and receive another
277 command before being able to send this data off. */
279 SAFE_FREE(state->response.extra_data.data);
281 ZERO_STRUCT(state->response);
283 state->response.result = WINBINDD_PENDING;
284 state->response.length = sizeof(struct winbindd_response);
286 state->mem_ctx = talloc_init("winbind request");
287 if (state->mem_ctx == NULL)
290 /* Process command */
292 for (table = dispatch_table; table->fn; table++) {
293 if (state->request.cmd == table->cmd) {
294 DEBUG(10,("process_request: request fn %s\n",
295 table->winbindd_cmd_name ));
302 DEBUG(10,("process_request: unknown request fn number %d\n",
303 (int)state->request.cmd ));
304 request_error(state);
309 * A list of file descriptors being monitored by select in the main processing
310 * loop. fd_event->handler is called whenever the socket is readable/writable.
313 static struct fd_event *fd_events = NULL;
315 void add_fd_event(struct fd_event *ev)
317 struct fd_event *match;
319 /* only add unique fd_event structs */
321 for (match=fd_events; match; match=match->next ) {
323 SMB_ASSERT( match != ev );
330 DLIST_ADD(fd_events, ev);
333 void remove_fd_event(struct fd_event *ev)
335 DLIST_REMOVE(fd_events, ev);
339 * Handler for fd_events to complete a read/write request, set up by
340 * setup_async_read/setup_async_write.
343 static void rw_callback(struct fd_event *event, int flags)
348 todo = event->length - event->done;
350 if (event->flags & EVENT_FD_WRITE) {
351 SMB_ASSERT(flags == EVENT_FD_WRITE);
352 done = sys_write(event->fd,
353 &((char *)event->data)[event->done],
358 event->finished(event->private_data, False);
363 if (event->flags & EVENT_FD_READ) {
364 SMB_ASSERT(flags == EVENT_FD_READ);
365 done = sys_read(event->fd, &((char *)event->data)[event->done],
370 event->finished(event->private_data, False);
377 if (event->done == event->length) {
379 event->finished(event->private_data, True);
384 * Request an async read/write on a fd_event structure. (*finished) is called
385 * when the request is completed or an error had occurred.
388 void setup_async_read(struct fd_event *event, void *data, size_t length,
389 void (*finished)(void *private_data, BOOL success),
392 SMB_ASSERT(event->flags == 0);
394 event->length = length;
396 event->handler = rw_callback;
397 event->finished = finished;
398 event->private_data = private_data;
399 event->flags = EVENT_FD_READ;
402 void setup_async_write(struct fd_event *event, void *data, size_t length,
403 void (*finished)(void *private_data, BOOL success),
406 SMB_ASSERT(event->flags == 0);
408 event->length = length;
410 event->handler = rw_callback;
411 event->finished = finished;
412 event->private_data = private_data;
413 event->flags = EVENT_FD_WRITE;
417 * This is the main event loop of winbind requests. It goes through a
418 * state-machine of 3 read/write requests, 4 if you have extra data to send.
420 * An idle winbind client has a read request of 4 bytes outstanding,
421 * finalizing function is request_len_recv, checking the length. request_recv
422 * then processes the packet. The processing function then at some point has
423 * to call request_finished which schedules sending the response.
426 static void request_len_recv(void *private_data, BOOL success);
427 static void request_recv(void *private_data, BOOL success);
428 static void request_main_recv(void *private_data, BOOL success);
429 static void request_finished(struct winbindd_cli_state *state);
430 void request_finished_cont(void *private_data, BOOL success);
431 static void response_main_sent(void *private_data, BOOL success);
432 static void response_extra_sent(void *private_data, BOOL success);
434 static void response_extra_sent(void *private_data, BOOL success)
436 struct winbindd_cli_state *state =
437 talloc_get_type_abort(private_data, struct winbindd_cli_state);
439 if (state->mem_ctx != NULL) {
440 talloc_destroy(state->mem_ctx);
441 state->mem_ctx = NULL;
445 state->finished = True;
449 SAFE_FREE(state->request.extra_data.data);
450 SAFE_FREE(state->response.extra_data.data);
452 setup_async_read(&state->fd_event, &state->request, sizeof(uint32),
453 request_len_recv, state);
456 static void response_main_sent(void *private_data, BOOL success)
458 struct winbindd_cli_state *state =
459 talloc_get_type_abort(private_data, struct winbindd_cli_state);
462 state->finished = True;
466 if (state->response.length == sizeof(state->response)) {
467 if (state->mem_ctx != NULL) {
468 talloc_destroy(state->mem_ctx);
469 state->mem_ctx = NULL;
472 setup_async_read(&state->fd_event, &state->request,
473 sizeof(uint32), request_len_recv, state);
477 setup_async_write(&state->fd_event, state->response.extra_data.data,
478 state->response.length - sizeof(state->response),
479 response_extra_sent, state);
482 static void request_finished(struct winbindd_cli_state *state)
484 setup_async_write(&state->fd_event, &state->response,
485 sizeof(state->response), response_main_sent, state);
488 void request_error(struct winbindd_cli_state *state)
490 SMB_ASSERT(state->response.result == WINBINDD_PENDING);
491 state->response.result = WINBINDD_ERROR;
492 request_finished(state);
495 void request_ok(struct winbindd_cli_state *state)
497 SMB_ASSERT(state->response.result == WINBINDD_PENDING);
498 state->response.result = WINBINDD_OK;
499 request_finished(state);
502 void request_finished_cont(void *private_data, BOOL success)
504 struct winbindd_cli_state *state =
505 talloc_get_type_abort(private_data, struct winbindd_cli_state);
510 request_error(state);
513 static void request_len_recv(void *private_data, BOOL success)
515 struct winbindd_cli_state *state =
516 talloc_get_type_abort(private_data, struct winbindd_cli_state);
519 state->finished = True;
523 if (*(uint32 *)(&state->request) != sizeof(state->request)) {
524 DEBUG(0,("request_len_recv: Invalid request size received: %d\n",
525 *(uint32 *)(&state->request)));
526 state->finished = True;
530 setup_async_read(&state->fd_event, (uint32 *)(&state->request)+1,
531 sizeof(state->request) - sizeof(uint32),
532 request_main_recv, state);
535 static void request_main_recv(void *private_data, BOOL success)
537 struct winbindd_cli_state *state =
538 talloc_get_type_abort(private_data, struct winbindd_cli_state);
541 state->finished = True;
545 if (state->request.extra_len == 0) {
546 state->request.extra_data.data = NULL;
547 request_recv(state, True);
551 if ((!state->privileged) &&
552 (state->request.extra_len > WINBINDD_MAX_EXTRA_DATA)) {
553 DEBUG(3, ("Got request with %d bytes extra data on "
554 "unprivileged socket\n", (int)state->request.extra_len));
555 state->request.extra_data.data = NULL;
556 state->finished = True;
560 state->request.extra_data.data =
561 SMB_MALLOC_ARRAY(char, state->request.extra_len + 1);
563 if (state->request.extra_data.data == NULL) {
564 DEBUG(0, ("malloc failed\n"));
565 state->finished = True;
569 /* Ensure null termination */
570 state->request.extra_data.data[state->request.extra_len] = '\0';
572 setup_async_read(&state->fd_event, state->request.extra_data.data,
573 state->request.extra_len, request_recv, state);
576 static void request_recv(void *private_data, BOOL success)
578 struct winbindd_cli_state *state =
579 talloc_get_type_abort(private_data, struct winbindd_cli_state);
582 state->finished = True;
586 process_request(state);
589 /* Process a new connection by adding it to the client connection list */
591 static void new_connection(int listen_sock, BOOL privileged)
593 struct sockaddr_un sunaddr;
594 struct winbindd_cli_state *state;
598 /* Accept connection */
600 len = sizeof(sunaddr);
603 sock = accept(listen_sock, (struct sockaddr *)&sunaddr, &len);
604 } while (sock == -1 && errno == EINTR);
609 DEBUG(6,("accepted socket %d\n", sock));
611 /* Create new connection structure */
613 if ((state = TALLOC_ZERO_P(NULL, struct winbindd_cli_state)) == NULL)
618 state->last_access = time(NULL);
620 state->privileged = privileged;
622 state->fd_event.fd = state->sock;
623 state->fd_event.flags = 0;
624 add_fd_event(&state->fd_event);
626 setup_async_read(&state->fd_event, &state->request, sizeof(uint32),
627 request_len_recv, state);
629 /* Add to connection list */
631 winbindd_add_client(state);
634 /* Remove a client connection from client connection list */
636 static void remove_client(struct winbindd_cli_state *state)
638 /* It's a dead client - hold a funeral */
648 /* Free any getent state */
650 free_getent_state(state->getpwent_state);
651 free_getent_state(state->getgrent_state);
653 /* We may have some extra data that was not freed if the client was
654 killed unexpectedly */
656 SAFE_FREE(state->response.extra_data.data);
658 if (state->mem_ctx != NULL) {
659 talloc_destroy(state->mem_ctx);
660 state->mem_ctx = NULL;
663 remove_fd_event(&state->fd_event);
665 /* Remove from list and free */
667 winbindd_remove_client(state);
671 /* Shutdown client connection which has been idle for the longest time */
673 static BOOL remove_idle_client(void)
675 struct winbindd_cli_state *state, *remove_state = NULL;
676 time_t last_access = 0;
679 for (state = winbindd_client_list(); state; state = state->next) {
680 if (state->response.result != WINBINDD_PENDING &&
681 !state->getpwent_state && !state->getgrent_state) {
683 if (!last_access || state->last_access < last_access) {
684 last_access = state->last_access;
685 remove_state = state;
691 DEBUG(5,("Found %d idle client connections, shutting down sock %d, pid %u\n",
692 nidle, remove_state->sock, (unsigned int)remove_state->pid));
693 remove_client(remove_state);
700 /* Process incoming clients on listen_sock. We use a tricky non-blocking,
701 non-forking, non-threaded model which allows us to handle many
702 simultaneous connections while remaining impervious to many denial of
705 static void process_loop(void)
707 struct winbindd_cli_state *state;
710 int maxfd, listen_sock, listen_priv_sock, selret;
711 struct timeval timeout;
713 /* We'll be doing this a lot */
715 /* Handle messages */
719 /* refresh the trusted domain cache */
721 rescan_trusted_domains();
723 /* Free up temporary memory */
726 main_loop_TALLOC_FREE();
728 /* Initialise fd lists for select() */
730 listen_sock = open_winbindd_socket();
731 listen_priv_sock = open_winbindd_priv_socket();
733 if (listen_sock == -1 || listen_priv_sock == -1) {
734 perror("open_winbind_socket");
738 maxfd = MAX(listen_sock, listen_priv_sock);
742 FD_SET(listen_sock, &r_fds);
743 FD_SET(listen_priv_sock, &r_fds);
745 timeout.tv_sec = WINBINDD_ESTABLISH_LOOP;
748 /* Set up client readers and writers */
750 state = winbindd_client_list();
754 struct winbindd_cli_state *next = state->next;
756 /* Dispose of client connection if it is marked as
760 remove_client(state);
765 for (ev = fd_events; ev; ev = ev->next) {
766 if (ev->flags & EVENT_FD_READ) {
767 FD_SET(ev->fd, &r_fds);
768 maxfd = MAX(ev->fd, maxfd);
770 if (ev->flags & EVENT_FD_WRITE) {
771 FD_SET(ev->fd, &w_fds);
772 maxfd = MAX(ev->fd, maxfd);
778 selret = sys_select(maxfd + 1, &r_fds, &w_fds, NULL, &timeout);
785 if (errno == EINTR) {
789 /* Select error, something is badly wrong */
799 struct fd_event *next = ev->next;
801 if (FD_ISSET(ev->fd, &r_fds))
802 flags |= EVENT_FD_READ;
803 if (FD_ISSET(ev->fd, &w_fds))
804 flags |= EVENT_FD_WRITE;
806 ev->handler(ev, flags);
810 if (FD_ISSET(listen_sock, &r_fds)) {
811 while (winbindd_num_clients() >
812 WINBINDD_MAX_SIMULTANEOUS_CLIENTS - 1) {
813 DEBUG(5,("winbindd: Exceeding %d client "
814 "connections, removing idle "
816 WINBINDD_MAX_SIMULTANEOUS_CLIENTS));
817 if (!remove_idle_client()) {
818 DEBUG(0,("winbindd: Exceeding %d "
819 "client connections, no idle "
820 "connection found\n",
821 WINBINDD_MAX_SIMULTANEOUS_CLIENTS));
825 /* new, non-privileged connection */
826 new_connection(listen_sock, False);
829 if (FD_ISSET(listen_priv_sock, &r_fds)) {
830 while (winbindd_num_clients() >
831 WINBINDD_MAX_SIMULTANEOUS_CLIENTS - 1) {
832 DEBUG(5,("winbindd: Exceeding %d client "
833 "connections, removing idle "
835 WINBINDD_MAX_SIMULTANEOUS_CLIENTS));
836 if (!remove_idle_client()) {
837 DEBUG(0,("winbindd: Exceeding %d "
838 "client connections, no idle "
839 "connection found\n",
840 WINBINDD_MAX_SIMULTANEOUS_CLIENTS));
844 /* new, privileged connection */
845 new_connection(listen_priv_sock, True);
851 winbindd_check_cache_size(time(NULL));
854 /* Check signal handling things */
861 DEBUG(3, ("got SIGHUP\n"));
863 msg_reload_services(MSG_SMB_CONF_UPDATED, pid_to_procid(0), NULL, 0);
868 print_winbindd_status();
877 while ((pid = sys_waitpid(-1, NULL, WNOHANG)) > 0) {
878 winbind_child_died(pid);
885 int main(int argc, char **argv, char **envp)
888 static BOOL Fork = True;
889 static BOOL log_stdout = False;
890 static BOOL no_process_group = False;
891 struct poptOption long_options[] = {
893 { "stdout", 'S', POPT_ARG_VAL, &log_stdout, True, "Log to stdout" },
894 { "foreground", 'F', POPT_ARG_VAL, &Fork, False, "Daemon in foreground mode" },
895 { "no-process-group", 0, POPT_ARG_VAL, &no_process_group, True, "Don't create a new process group" },
896 { "interactive", 'i', POPT_ARG_NONE, NULL, 'i', "Interactive mode" },
897 { "no-caching", 'n', POPT_ARG_VAL, &opt_nocache, True, "Disable caching" },
904 /* glibc (?) likes to print "User defined signal 1" and exit if a
905 SIGUSR[12] is received before a handler is installed */
907 CatchSignal(SIGUSR1, SIG_IGN);
908 CatchSignal(SIGUSR2, SIG_IGN);
910 fault_setup((void (*)(void *))fault_quit );
911 dump_core_setup("winbindd");
915 /* Initialise for running in non-root mode */
919 set_remote_machine_name("winbindd", False);
921 /* Set environment variable so we don't recursively call ourselves.
922 This may also be useful interactively. */
924 if ( !winbind_off() ) {
925 DEBUG(0,("Failed to disable recusive winbindd calls. Exiting.\n"));
929 /* Initialise samba/rpc client stuff */
931 pc = poptGetContext("winbindd", argc, (const char **)argv, long_options,
932 POPT_CONTEXT_KEEP_FIRST);
934 while ((opt = poptGetNextOpt(pc)) != -1) {
936 /* Don't become a daemon */
946 if (log_stdout && Fork) {
947 printf("Can't log to stdout (-S) unless daemon is in foreground +(-F) or interactive (-i)\n");
948 poptPrintUsage(pc, stderr, 0);
952 if (!override_logfile) {
953 pstr_sprintf(logfile, "%s/log.winbindd", dyn_LOGFILEBASE);
954 lp_set_logfile(logfile);
956 setup_logging("winbindd", log_stdout);
959 DEBUG(1, ("winbindd version %s started.\n", SAMBA_VERSION_STRING) );
960 DEBUGADD( 1, ( "Copyright The Samba Team 2000-2004\n" ) );
962 if (!reload_services_file()) {
963 DEBUG(0, ("error opening config file\n"));
967 if (!directory_exist(lp_lockdir(), NULL)) {
968 mkdir(lp_lockdir(), 0755);
978 if (!secrets_init()) {
980 DEBUG(0,("Could not initialize domain trust account secrets. Giving up\n"));
984 /* Enable netbios namecache */
988 /* Winbind daemon initialisation */
990 if ( ! NT_STATUS_IS_OK(idmap_init()) ) {
991 DEBUG(1, ("Could not init idmap! - Sid/[UG]id mapping will not be available\n"));
994 /* Unblock all signals we are interested in as they may have been
995 blocked by the parent process. */
997 BlockSignals(False, SIGINT);
998 BlockSignals(False, SIGQUIT);
999 BlockSignals(False, SIGTERM);
1000 BlockSignals(False, SIGUSR1);
1001 BlockSignals(False, SIGUSR2);
1002 BlockSignals(False, SIGHUP);
1003 BlockSignals(False, SIGCHLD);
1005 /* Setup signal handlers */
1007 CatchSignal(SIGINT, termination_handler); /* Exit on these sigs */
1008 CatchSignal(SIGQUIT, termination_handler);
1009 CatchSignal(SIGTERM, termination_handler);
1010 CatchSignal(SIGCHLD, sigchld_handler);
1012 CatchSignal(SIGPIPE, SIG_IGN); /* Ignore sigpipe */
1014 CatchSignal(SIGUSR2, sigusr2_handler); /* Debugging sigs */
1015 CatchSignal(SIGHUP, sighup_handler);
1018 become_daemon(Fork, no_process_group);
1020 pidfile_create("winbindd");
1022 /* Ensure all cache and idmap caches are consistent
1023 before we startup. */
1025 if (winbindd_validate_cache()) {
1026 /* We have a bad cache, but luckily we
1027 just deleted it. Restart ourselves */
1029 /* Ensure we have no open low fd's. */
1030 for (i = 3; i < 100; i++) {
1033 return execve(argv[0], argv, envp);
1038 * If we're interactive we want to set our own process group for
1039 * signal management.
1041 if (interactive && !no_process_group)
1042 setpgid( (pid_t)0, (pid_t)0);
1047 /* Initialise messaging system */
1049 if (!message_init()) {
1050 DEBUG(0, ("unable to initialize messaging system\n"));
1054 /* React on 'smbcontrol winbindd reload-config' in the same way
1055 as to SIGHUP signal */
1056 message_register(MSG_SMB_CONF_UPDATED, msg_reload_services);
1057 message_register(MSG_SHUTDOWN, msg_shutdown);
1059 /* Handle online/offline messages. */
1060 message_register(MSG_WINBIND_OFFLINE,winbind_msg_offline);
1061 message_register(MSG_WINBIND_ONLINE,winbind_msg_online);
1062 message_register(MSG_WINBIND_ONLINESTATUS,winbind_msg_onlinestatus);
1064 poptFreeContext(pc);
1066 netsamlogon_cache_init(); /* Non-critical */
1068 if (!init_domain_list()) {
1069 DEBUG(0,("unable to initalize domain list\n"));
1075 smb_nscd_flush_user_cache();
1076 smb_nscd_flush_group_cache();
1078 /* Loop waiting for requests */
1083 trustdom_cache_shutdown();