Add support for MSG_SMB_CONF_UPDATED and MSG_SHUTDOWN to all daemons (smbd, nmbd...
[Samba/gebeck_regimport.git] / source / nsswitch / winbindd.c
blob0336312e897a96db6893e3d63b324729be905361
1 /*
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
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include "winbindd.h"
27 BOOL opt_nocache = False;
28 BOOL opt_dual_daemon = True;
30 /*****************************************************************************
31 stubb functions
32 ****************************************************************************/
34 void become_root( void )
36 return;
39 void unbecome_root( void )
41 return;
44 /* Reload configuration */
46 static BOOL reload_services_file(BOOL test)
48 BOOL ret;
50 if (lp_loaded()) {
51 pstring fname;
53 pstrcpy(fname,lp_configfile());
54 if (file_exist(fname,NULL) && !strcsequal(fname,dyn_CONFIGFILE)) {
55 pstrcpy(dyn_CONFIGFILE,fname);
56 test = False;
60 reopen_logs();
61 ret = lp_load(dyn_CONFIGFILE,False,False,True);
63 reopen_logs();
64 load_interfaces();
66 return(ret);
70 #if DUMP_CORE
72 /**************************************************************************** **
73 Prepare to dump a core file - carefully!
74 **************************************************************************** */
76 static BOOL dump_core(void)
78 char *p;
79 pstring dname;
80 pstrcpy( dname, lp_logfile() );
81 if ((p=strrchr(dname,'/')))
82 *p=0;
83 pstrcat( dname, "/corefiles" );
84 mkdir( dname, 0700 );
85 sys_chown( dname, getuid(), getgid() );
86 chmod( dname, 0700 );
87 if ( chdir(dname) )
88 return( False );
89 umask( ~(0700) );
91 #ifdef HAVE_GETRLIMIT
92 #ifdef RLIMIT_CORE
94 struct rlimit rlp;
95 getrlimit( RLIMIT_CORE, &rlp );
96 rlp.rlim_cur = MAX( 4*1024*1024, rlp.rlim_cur );
97 setrlimit( RLIMIT_CORE, &rlp );
98 getrlimit( RLIMIT_CORE, &rlp );
99 DEBUG( 3, ( "Core limits now %d %d\n", (int)rlp.rlim_cur, (int)rlp.rlim_max ) );
101 #endif
102 #endif
104 DEBUG(0,("Dumping core in %s\n",dname));
105 abort();
106 return( True );
107 } /* dump_core */
108 #endif
110 /**************************************************************************** **
111 Handle a fault..
112 **************************************************************************** */
114 static void fault_quit(void)
116 #if DUMP_CORE
117 dump_core();
118 #endif
121 static void winbindd_status(void)
123 struct winbindd_cli_state *tmp;
125 DEBUG(0, ("winbindd status:\n"));
127 /* Print client state information */
129 DEBUG(0, ("\t%d clients currently active\n", winbindd_num_clients()));
131 if (DEBUGLEVEL >= 2 && winbindd_num_clients()) {
132 DEBUG(2, ("\tclient list:\n"));
133 for(tmp = winbindd_client_list(); tmp; tmp = tmp->next) {
134 DEBUG(2, ("\t\tpid %d, sock %d, rbl %d, wbl %d\n",
135 tmp->pid, tmp->sock, tmp->read_buf_len,
136 tmp->write_buf_len));
141 /* Print winbindd status to log file */
143 static void print_winbindd_status(void)
145 winbindd_status();
146 winbindd_cm_status();
149 /* Flush client cache */
151 static void flush_caches(void)
153 #if 0
154 /* Clear cached user and group enumation info */
155 if (!opt_dual_daemon) /* Until we have coherent cache flush. */
156 wcache_flush_cache();
157 #endif
159 /* We need to invalidate cached user list entries on a SIGHUP
160 otherwise cached access denied errors due to restrict anonymous
161 hang around until the sequence number changes. */
163 wcache_invalidate_cache();
166 /* Handle the signal by unlinking socket and exiting */
168 static void terminate(void)
170 pstring path;
172 idmap_close();
174 /* Remove socket file */
175 snprintf(path, sizeof(path), "%s/%s",
176 WINBINDD_SOCKET_DIR, WINBINDD_SOCKET_NAME);
177 unlink(path);
178 exit(0);
181 static BOOL do_sigterm;
183 static void termination_handler(int signum)
185 do_sigterm = True;
186 sys_select_signal();
189 static BOOL do_sigusr2;
191 static void sigusr2_handler(int signum)
193 do_sigusr2 = True;
194 sys_select_signal();
197 static BOOL do_sighup;
199 static void sighup_handler(int signum)
201 do_sighup = True;
202 sys_select_signal();
205 /* React on 'smbcontrol winbindd reload-config' in the same way as on SIGHUP*/
206 static void msg_reload_services(int msg_type, pid_t src, void *buf, size_t len)
208 /* Flush various caches */
209 flush_caches();
210 reload_services_file(True);
213 /* React on 'smbcontrol winbindd shutdown' in the same way as on SIGTERM*/
214 static void msg_shutdown(int msg_type, pid_t src, void *buf, size_t len)
216 terminate();
219 struct dispatch_table {
220 enum winbindd_cmd cmd;
221 enum winbindd_result (*fn)(struct winbindd_cli_state *state);
222 const char *winbindd_cmd_name;
225 static struct dispatch_table dispatch_table[] = {
227 /* User functions */
229 { WINBINDD_GETPWNAM, winbindd_getpwnam, "GETPWNAM" },
230 { WINBINDD_GETPWUID, winbindd_getpwuid, "GETPWUID" },
232 { WINBINDD_SETPWENT, winbindd_setpwent, "SETPWENT" },
233 { WINBINDD_ENDPWENT, winbindd_endpwent, "ENDPWENT" },
234 { WINBINDD_GETPWENT, winbindd_getpwent, "GETPWENT" },
236 { WINBINDD_GETGROUPS, winbindd_getgroups, "GETGROUPS" },
238 /* Group functions */
240 { WINBINDD_GETGRNAM, winbindd_getgrnam, "GETGRNAM" },
241 { WINBINDD_GETGRGID, winbindd_getgrgid, "GETGRGID" },
242 { WINBINDD_SETGRENT, winbindd_setgrent, "SETGRENT" },
243 { WINBINDD_ENDGRENT, winbindd_endgrent, "ENDGRENT" },
244 { WINBINDD_GETGRENT, winbindd_getgrent, "GETGRENT" },
245 { WINBINDD_GETGRLST, winbindd_getgrent, "GETGRLST" },
247 /* PAM auth functions */
249 { WINBINDD_PAM_AUTH, winbindd_pam_auth, "PAM_AUTH" },
250 { WINBINDD_PAM_AUTH_CRAP, winbindd_pam_auth_crap, "AUTH_CRAP" },
251 { WINBINDD_PAM_CHAUTHTOK, winbindd_pam_chauthtok, "CHAUTHTOK" },
253 /* Enumeration functions */
255 { WINBINDD_LIST_USERS, winbindd_list_users, "LIST_USERS" },
256 { WINBINDD_LIST_GROUPS, winbindd_list_groups, "LIST_GROUPS" },
257 { WINBINDD_LIST_TRUSTDOM, winbindd_list_trusted_domains, "LIST_TRUSTDOM" },
258 { WINBINDD_SHOW_SEQUENCE, winbindd_show_sequence, "SHOW_SEQUENCE" },
260 /* SID related functions */
262 { WINBINDD_LOOKUPSID, winbindd_lookupsid, "LOOKUPSID" },
263 { WINBINDD_LOOKUPNAME, winbindd_lookupname, "LOOKUPNAME" },
265 /* Lookup related functions */
267 { WINBINDD_SID_TO_UID, winbindd_sid_to_uid, "SID_TO_UID" },
268 { WINBINDD_SID_TO_GID, winbindd_sid_to_gid, "SID_TO_GID" },
269 { WINBINDD_GID_TO_SID, winbindd_gid_to_sid, "GID_TO_SID" },
270 { WINBINDD_UID_TO_SID, winbindd_uid_to_sid, "UID_TO_SID" },
272 /* Miscellaneous */
274 { WINBINDD_CHECK_MACHACC, winbindd_check_machine_acct, "CHECK_MACHACC" },
275 { WINBINDD_PING, winbindd_ping, "PING" },
276 { WINBINDD_INFO, winbindd_info, "INFO" },
277 { WINBINDD_INTERFACE_VERSION, winbindd_interface_version, "INTERFACE_VERSION" },
278 { WINBINDD_DOMAIN_NAME, winbindd_domain_name, "DOMAIN_NAME" },
279 { WINBINDD_NETBIOS_NAME, winbindd_netbios_name, "NETBIOS_NAME" },
280 { WINBINDD_PRIV_PIPE_DIR, winbindd_priv_pipe_dir, "WINBINDD_PRIV_PIPE_DIR" },
282 /* WINS functions */
284 { WINBINDD_WINS_BYNAME, winbindd_wins_byname, "WINS_BYNAME" },
285 { WINBINDD_WINS_BYIP, winbindd_wins_byip, "WINS_BYIP" },
287 /* UNIX account management functions */
288 { WINBINDD_CREATE_USER, winbindd_create_user, "CREATE_USER" },
289 { WINBINDD_CREATE_GROUP, winbindd_create_group, "CREATE_GROUP" },
290 { WINBINDD_ADD_USER_TO_GROUP, winbindd_add_user_to_group, "ADD_USER_TO_GROUP" },
291 { WINBINDD_REMOVE_USER_FROM_GROUP, winbindd_remove_user_from_group,"REMOVE_USER_FROM_GROUP"},
292 { WINBINDD_SET_USER_PRIMARY_GROUP, winbindd_set_user_primary_group,"SET_USER_PRIMARY_GROUP"},
293 { WINBINDD_DELETE_USER, winbindd_delete_user, "DELETE_USER" },
294 { WINBINDD_DELETE_GROUP, winbindd_delete_group, "DELETE_GROUP" },
296 /* End of list */
298 { WINBINDD_NUM_CMDS, NULL, "NONE" }
301 static void process_request(struct winbindd_cli_state *state)
303 struct dispatch_table *table = dispatch_table;
305 /* Free response data - we may be interrupted and receive another
306 command before being able to send this data off. */
308 SAFE_FREE(state->response.extra_data);
310 ZERO_STRUCT(state->response);
312 state->response.result = WINBINDD_ERROR;
313 state->response.length = sizeof(struct winbindd_response);
315 /* Process command */
317 for (table = dispatch_table; table->fn; table++) {
318 if (state->request.cmd == table->cmd) {
319 DEBUG(10,("process_request: request fn %s\n", table->winbindd_cmd_name ));
320 state->response.result = table->fn(state);
321 break;
325 if (!table->fn)
326 DEBUG(10,("process_request: unknown request fn number %d\n", (int)state->request.cmd ));
328 /* In case extra data pointer is NULL */
330 if (!state->response.extra_data)
331 state->response.length = sizeof(struct winbindd_response);
334 /* Process a new connection by adding it to the client connection list */
336 static void new_connection(int listen_sock, BOOL privileged)
338 struct sockaddr_un sunaddr;
339 struct winbindd_cli_state *state;
340 socklen_t len;
341 int sock;
343 /* Accept connection */
345 len = sizeof(sunaddr);
347 do {
348 sock = accept(listen_sock, (struct sockaddr *)&sunaddr, &len);
349 } while (sock == -1 && errno == EINTR);
351 if (sock == -1)
352 return;
354 DEBUG(6,("accepted socket %d\n", sock));
356 /* Create new connection structure */
358 if ((state = (struct winbindd_cli_state *)
359 malloc(sizeof(*state))) == NULL)
360 return;
362 ZERO_STRUCTP(state);
363 state->sock = sock;
365 state->last_access = time(NULL);
367 state->privileged = privileged;
369 /* Add to connection list */
371 winbindd_add_client(state);
374 /* Remove a client connection from client connection list */
376 static void remove_client(struct winbindd_cli_state *state)
378 /* It's a dead client - hold a funeral */
380 if (state != NULL) {
382 /* Close socket */
384 close(state->sock);
386 /* Free any getent state */
388 free_getent_state(state->getpwent_state);
389 free_getent_state(state->getgrent_state);
391 /* We may have some extra data that was not freed if the
392 client was killed unexpectedly */
394 SAFE_FREE(state->response.extra_data);
396 /* Remove from list and free */
398 winbindd_remove_client(state);
399 SAFE_FREE(state);
404 /* Shutdown client connection which has been idle for the longest time */
406 static BOOL remove_idle_client(void)
408 struct winbindd_cli_state *state, *remove_state = NULL;
409 time_t last_access = 0;
410 int nidle = 0;
412 for (state = winbindd_client_list(); state; state = state->next) {
413 if (state->read_buf_len == 0 && state->write_buf_len == 0 &&
414 !state->getpwent_state && !state->getgrent_state) {
415 nidle++;
416 if (!last_access || state->last_access < last_access) {
417 last_access = state->last_access;
418 remove_state = state;
423 if (remove_state) {
424 DEBUG(5,("Found %d idle client connections, shutting down sock %d, pid %u\n",
425 nidle, remove_state->sock, (unsigned int)remove_state->pid));
426 remove_client(remove_state);
427 return True;
430 return False;
433 /* Process a complete received packet from a client */
435 void winbind_process_packet(struct winbindd_cli_state *state)
437 /* Process request */
439 /* Ensure null termination of entire request */
440 state->request.null_term = '\0';
442 state->pid = state->request.pid;
444 process_request(state);
446 /* Update client state */
448 state->read_buf_len = 0;
449 state->write_buf_len = sizeof(struct winbindd_response);
451 /* we might need to send it to the dual daemon */
452 if (opt_dual_daemon) {
453 dual_send_request(state);
457 /* Read some data from a client connection */
459 void winbind_client_read(struct winbindd_cli_state *state)
461 int n;
463 /* Read data */
465 n = sys_read(state->sock, state->read_buf_len +
466 (char *)&state->request,
467 sizeof(state->request) - state->read_buf_len);
469 DEBUG(10,("client_read: read %d bytes. Need %d more for a full request.\n", n, sizeof(state->request) - n - state->read_buf_len ));
471 /* Read failed, kill client */
473 if (n == -1 || n == 0) {
474 DEBUG(5,("read failed on sock %d, pid %d: %s\n",
475 state->sock, state->pid,
476 (n == -1) ? strerror(errno) : "EOF"));
478 state->finished = True;
479 return;
482 /* Update client state */
484 state->read_buf_len += n;
485 state->last_access = time(NULL);
488 /* Write some data to a client connection */
490 static void client_write(struct winbindd_cli_state *state)
492 char *data;
493 int num_written;
495 /* Write some data */
497 if (!state->write_extra_data) {
499 /* Write response structure */
501 data = (char *)&state->response + sizeof(state->response) -
502 state->write_buf_len;
504 } else {
506 /* Write extra data */
508 data = (char *)state->response.extra_data +
509 state->response.length -
510 sizeof(struct winbindd_response) -
511 state->write_buf_len;
514 num_written = sys_write(state->sock, data, state->write_buf_len);
516 DEBUG(10,("client_write: wrote %d bytes.\n", num_written ));
518 /* Write failed, kill cilent */
520 if (num_written == -1 || num_written == 0) {
522 DEBUG(3,("write failed on sock %d, pid %d: %s\n",
523 state->sock, state->pid,
524 (num_written == -1) ? strerror(errno) : "EOF"));
526 state->finished = True;
528 SAFE_FREE(state->response.extra_data);
530 return;
533 /* Update client state */
535 state->write_buf_len -= num_written;
536 state->last_access = time(NULL);
538 /* Have we written all data? */
540 if (state->write_buf_len == 0) {
542 /* Take care of extra data */
544 if (state->write_extra_data) {
546 SAFE_FREE(state->response.extra_data);
548 state->write_extra_data = False;
550 DEBUG(10,("client_write: client_write: complete response written.\n"));
552 } else if (state->response.length >
553 sizeof(struct winbindd_response)) {
555 /* Start writing extra data */
557 state->write_buf_len =
558 state->response.length -
559 sizeof(struct winbindd_response);
561 DEBUG(10,("client_write: need to write %d extra data bytes.\n", (int)state->write_buf_len));
563 state->write_extra_data = True;
568 /* Process incoming clients on listen_sock. We use a tricky non-blocking,
569 non-forking, non-threaded model which allows us to handle many
570 simultaneous connections while remaining impervious to many denial of
571 service attacks. */
573 static void process_loop(void)
575 /* We'll be doing this a lot */
577 while (1) {
578 struct winbindd_cli_state *state;
579 fd_set r_fds, w_fds;
580 int maxfd, listen_sock, listen_priv_sock, selret;
581 struct timeval timeout;
583 /* Handle messages */
585 message_dispatch();
587 /* rescan the trusted domains list. This must be done
588 regularly to cope with transitive trusts */
589 rescan_trusted_domains(False);
591 /* Free up temporary memory */
593 lp_talloc_free();
594 main_loop_talloc_free();
596 /* Initialise fd lists for select() */
598 listen_sock = open_winbindd_socket();
599 listen_priv_sock = open_winbindd_priv_socket();
601 if (listen_sock == -1 || listen_priv_sock == -1) {
602 perror("open_winbind_socket");
603 exit(1);
606 maxfd = MAX(listen_sock, listen_priv_sock);
608 FD_ZERO(&r_fds);
609 FD_ZERO(&w_fds);
610 FD_SET(listen_sock, &r_fds);
611 FD_SET(listen_priv_sock, &r_fds);
613 timeout.tv_sec = WINBINDD_ESTABLISH_LOOP;
614 timeout.tv_usec = 0;
616 if (opt_dual_daemon) {
617 maxfd = dual_select_setup(&w_fds, maxfd);
620 /* Set up client readers and writers */
622 state = winbindd_client_list();
624 while (state) {
626 /* Dispose of client connection if it is marked as
627 finished */
629 if (state->finished) {
630 struct winbindd_cli_state *next = state->next;
632 remove_client(state);
633 state = next;
634 continue;
637 /* Select requires we know the highest fd used */
639 if (state->sock > maxfd)
640 maxfd = state->sock;
642 /* Add fd for reading */
644 if (state->read_buf_len != sizeof(state->request))
645 FD_SET(state->sock, &r_fds);
647 /* Add fd for writing */
649 if (state->write_buf_len)
650 FD_SET(state->sock, &w_fds);
652 state = state->next;
655 /* Call select */
657 selret = sys_select(maxfd + 1, &r_fds, &w_fds, NULL, &timeout);
659 if (selret == 0)
660 continue;
662 if ((selret == -1 && errno != EINTR) || selret == 0) {
664 /* Select error, something is badly wrong */
666 perror("select");
667 exit(1);
670 /* Create a new connection if listen_sock readable */
672 if (selret > 0) {
674 if (opt_dual_daemon) {
675 dual_select(&w_fds);
678 if (FD_ISSET(listen_sock, &r_fds)) {
679 while (winbindd_num_clients() > WINBINDD_MAX_SIMULTANEOUS_CLIENTS - 1) {
680 DEBUG(5,("winbindd: Exceeding %d client connections, removing idle connection.\n",
681 WINBINDD_MAX_SIMULTANEOUS_CLIENTS));
682 if (!remove_idle_client()) {
683 DEBUG(0,("winbindd: Exceeding %d client connections, no idle connection found\n",
684 WINBINDD_MAX_SIMULTANEOUS_CLIENTS));
685 break;
688 /* new, non-privileged connection */
689 new_connection(listen_sock, False);
692 if (FD_ISSET(listen_priv_sock, &r_fds)) {
693 while (winbindd_num_clients() > WINBINDD_MAX_SIMULTANEOUS_CLIENTS - 1) {
694 DEBUG(5,("winbindd: Exceeding %d client connections, removing idle connection.\n",
695 WINBINDD_MAX_SIMULTANEOUS_CLIENTS));
696 if (!remove_idle_client()) {
697 DEBUG(0,("winbindd: Exceeding %d client connections, no idle connection found\n",
698 WINBINDD_MAX_SIMULTANEOUS_CLIENTS));
699 break;
702 /* new, privileged connection */
703 new_connection(listen_priv_sock, True);
706 /* Process activity on client connections */
708 for (state = winbindd_client_list(); state;
709 state = state->next) {
711 /* Data available for reading */
713 if (FD_ISSET(state->sock, &r_fds)) {
715 /* Read data */
717 winbind_client_read(state);
720 * If we have the start of a
721 * packet, then check the
722 * length field to make sure
723 * the client's not talking
724 * Mock Swedish.
727 if (state->read_buf_len >= sizeof(uint32)
728 && *(uint32 *) &state->request != sizeof(state->request)) {
729 DEBUG(0,("process_loop: Invalid request size from pid %d: %d bytes sent, should be %d\n",
730 state->request.pid, *(uint32 *) &state->request, sizeof(state->request)));
732 remove_client(state);
733 break;
736 /* A request packet might be
737 complete */
739 if (state->read_buf_len ==
740 sizeof(state->request)) {
741 winbind_process_packet(state);
745 /* Data available for writing */
747 if (FD_ISSET(state->sock, &w_fds))
748 client_write(state);
752 #if 0
753 winbindd_check_cache_size(time(NULL));
754 #endif
756 /* Check signal handling things */
758 if (do_sigterm)
759 terminate();
761 if (do_sighup) {
763 DEBUG(3, ("got SIGHUP\n"));
765 msg_reload_services(MSG_SMB_CONF_UPDATED, (pid_t) 0, NULL, 0);
766 do_sighup = False;
769 if (do_sigusr2) {
770 print_winbindd_status();
771 do_sigusr2 = False;
776 /* Main function */
778 struct winbindd_state server_state; /* Server state information */
780 int main(int argc, char **argv)
782 pstring logfile;
783 static BOOL interactive = False;
784 static BOOL Fork = True;
785 static BOOL log_stdout = False;
786 struct poptOption long_options[] = {
787 POPT_AUTOHELP
788 { "stdout", 'S', POPT_ARG_VAL, &log_stdout, True, "Log to stdout" },
789 { "foreground", 'F', POPT_ARG_VAL, &Fork, False, "Daemon in foreground mode" },
790 { "interactive", 'i', POPT_ARG_NONE, NULL, 'i', "Interactive mode" },
791 { "single-daemon", 'Y', POPT_ARG_VAL, &opt_dual_daemon, False, "Single daemon mode" },
792 { "no-caching", 'n', POPT_ARG_VAL, &opt_nocache, False, "Disable caching" },
793 POPT_COMMON_SAMBA
794 POPT_TABLEEND
796 poptContext pc;
797 int opt;
799 /* glibc (?) likes to print "User defined signal 1" and exit if a
800 SIGUSR[12] is received before a handler is installed */
802 CatchSignal(SIGUSR1, SIG_IGN);
803 CatchSignal(SIGUSR2, SIG_IGN);
805 fault_setup((void (*)(void *))fault_quit );
807 /* Initialise for running in non-root mode */
809 sec_init();
811 set_remote_machine_name("winbindd", False);
813 /* Set environment variable so we don't recursively call ourselves.
814 This may also be useful interactively. */
816 setenv(WINBINDD_DONT_ENV, "1", 1);
818 /* Initialise samba/rpc client stuff */
820 pc = poptGetContext("winbindd", argc, (const char **)argv, long_options,
821 POPT_CONTEXT_KEEP_FIRST);
823 while ((opt = poptGetNextOpt(pc)) != -1) {
824 switch (opt) {
825 /* Don't become a daemon */
826 case 'i':
827 interactive = True;
828 log_stdout = True;
829 Fork = False;
830 break;
835 if (log_stdout && Fork) {
836 printf("Can't log to stdout (-S) unless daemon is in foreground +(-F) or interactive (-i)\n");
837 poptPrintUsage(pc, stderr, 0);
838 exit(1);
841 snprintf(logfile, sizeof(logfile), "%s/log.winbindd", dyn_LOGFILEBASE);
842 lp_set_logfile(logfile);
843 setup_logging("winbindd", log_stdout);
844 reopen_logs();
846 DEBUG(1, ("winbindd version %s started.\n", VERSION ) );
847 DEBUGADD( 1, ( "Copyright The Samba Team 2000-2003\n" ) );
849 if (!reload_services_file(False)) {
850 DEBUG(0, ("error opening config file\n"));
851 exit(1);
854 /* Setup names. */
856 if (!init_names())
857 exit(1);
859 load_interfaces();
861 if (!secrets_init()) {
863 DEBUG(0,("Could not initialize domain trust account secrets. Giving up\n"));
864 return False;
867 /* Enable netbios namecache */
869 namecache_enable();
871 /* Check winbindd parameters are valid */
873 ZERO_STRUCT(server_state);
875 if (!winbindd_param_init())
876 return 1;
878 /* Winbind daemon initialisation */
880 if (!winbindd_upgrade_idmap())
881 return 1;
883 if (!idmap_init(lp_idmap_backend()))
884 return 1;
886 if (!idmap_init_wellknown_sids())
887 exit(1);
889 /* Unblock all signals we are interested in as they may have been
890 blocked by the parent process. */
892 BlockSignals(False, SIGINT);
893 BlockSignals(False, SIGQUIT);
894 BlockSignals(False, SIGTERM);
895 BlockSignals(False, SIGUSR1);
896 BlockSignals(False, SIGUSR2);
897 BlockSignals(False, SIGHUP);
899 /* Setup signal handlers */
901 CatchSignal(SIGINT, termination_handler); /* Exit on these sigs */
902 CatchSignal(SIGQUIT, termination_handler);
903 CatchSignal(SIGTERM, termination_handler);
905 CatchSignal(SIGPIPE, SIG_IGN); /* Ignore sigpipe */
907 CatchSignal(SIGUSR2, sigusr2_handler); /* Debugging sigs */
908 CatchSignal(SIGHUP, sighup_handler);
910 if (!interactive)
911 become_daemon(Fork);
913 pidfile_create("winbindd");
915 #if HAVE_SETPGID
917 * If we're interactive we want to set our own process group for
918 * signal management.
920 if (interactive)
921 setpgid( (pid_t)0, (pid_t)0);
922 #endif
924 if (opt_dual_daemon) {
925 do_dual_daemon();
928 /* Initialise messaging system */
930 if (!message_init()) {
931 DEBUG(0, ("unable to initialise messaging system\n"));
932 exit(1);
935 /* React on 'smbcontrol winbindd reload-config' in the same way
936 as to SIGHUP signal */
937 message_register(MSG_SMB_CONF_UPDATED, msg_reload_services);
938 message_register(MSG_SHUTDOWN, msg_shutdown);
940 poptFreeContext(pc);
942 netsamlogon_cache_init(); /* Non-critical */
944 /* Loop waiting for requests */
946 process_loop();
948 trustdom_cache_shutdown();
950 return 0;