And finally IDMAP in 3_0
[Samba.git] / source3 / nsswitch / winbindd.c
blobc7e45e54293dc469521efd8f92aee5d7ac9d3438
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 = False;
30 /* Reload configuration */
32 static BOOL reload_services_file(BOOL test)
34 BOOL ret;
36 if (lp_loaded()) {
37 pstring fname;
39 pstrcpy(fname,lp_configfile());
40 if (file_exist(fname,NULL) && !strcsequal(fname,dyn_CONFIGFILE)) {
41 pstrcpy(dyn_CONFIGFILE,fname);
42 test = False;
46 reopen_logs();
47 ret = lp_load(dyn_CONFIGFILE,False,False,True);
49 reopen_logs();
50 load_interfaces();
52 return(ret);
55 #if DUMP_CORE
57 /**************************************************************************** **
58 Prepare to dump a core file - carefully!
59 **************************************************************************** */
61 static BOOL dump_core(void)
63 char *p;
64 pstring dname;
65 pstrcpy( dname, lp_logfile() );
66 if ((p=strrchr(dname,'/')))
67 *p=0;
68 pstrcat( dname, "/corefiles" );
69 mkdir( dname, 0700 );
70 sys_chown( dname, getuid(), getgid() );
71 chmod( dname, 0700 );
72 if ( chdir(dname) )
73 return( False );
74 umask( ~(0700) );
76 #ifdef HAVE_GETRLIMIT
77 #ifdef RLIMIT_CORE
79 struct rlimit rlp;
80 getrlimit( RLIMIT_CORE, &rlp );
81 rlp.rlim_cur = MAX( 4*1024*1024, rlp.rlim_cur );
82 setrlimit( RLIMIT_CORE, &rlp );
83 getrlimit( RLIMIT_CORE, &rlp );
84 DEBUG( 3, ( "Core limits now %d %d\n", (int)rlp.rlim_cur, (int)rlp.rlim_max ) );
86 #endif
87 #endif
89 DEBUG(0,("Dumping core in %s\n",dname));
90 abort();
91 return( True );
92 } /* dump_core */
93 #endif
95 /**************************************************************************** **
96 Handle a fault..
97 **************************************************************************** */
99 static void fault_quit(void)
101 #if DUMP_CORE
102 dump_core();
103 #endif
106 static void winbindd_status(void)
108 struct winbindd_cli_state *tmp;
110 DEBUG(0, ("winbindd status:\n"));
112 /* Print client state information */
114 DEBUG(0, ("\t%d clients currently active\n", winbindd_num_clients()));
116 if (DEBUGLEVEL >= 2 && winbindd_num_clients()) {
117 DEBUG(2, ("\tclient list:\n"));
118 for(tmp = winbindd_client_list(); tmp; tmp = tmp->next) {
119 DEBUG(2, ("\t\tpid %d, sock %d, rbl %d, wbl %d\n",
120 tmp->pid, tmp->sock, tmp->read_buf_len,
121 tmp->write_buf_len));
126 /* Print winbindd status to log file */
128 static void print_winbindd_status(void)
130 winbindd_status();
131 winbindd_cm_status();
134 /* Flush client cache */
136 static void flush_caches(void)
138 /* Clear cached user and group enumation info */
139 wcache_flush_cache();
142 /* Handle the signal by unlinking socket and exiting */
144 static void terminate(void)
146 pstring path;
148 idmap_close();
150 /* Remove socket file */
151 snprintf(path, sizeof(path), "%s/%s",
152 WINBINDD_SOCKET_DIR, WINBINDD_SOCKET_NAME);
153 unlink(path);
154 exit(0);
157 static BOOL do_sigterm;
159 static void termination_handler(int signum)
161 do_sigterm = True;
162 sys_select_signal();
165 static BOOL do_sigusr2;
167 static void sigusr2_handler(int signum)
169 do_sigusr2 = True;
170 sys_select_signal();
173 static BOOL do_sighup;
175 static void sighup_handler(int signum)
177 do_sighup = True;
178 sys_select_signal();
181 struct dispatch_table {
182 enum winbindd_cmd cmd;
183 enum winbindd_result (*fn)(struct winbindd_cli_state *state);
184 const char *winbindd_cmd_name;
187 static struct dispatch_table dispatch_table[] = {
189 /* User functions */
191 { WINBINDD_GETPWNAM, winbindd_getpwnam, "GETPWNAM" },
192 { WINBINDD_GETPWUID, winbindd_getpwuid, "GETPWUID" },
194 { WINBINDD_SETPWENT, winbindd_setpwent, "SETPWENT" },
195 { WINBINDD_ENDPWENT, winbindd_endpwent, "ENDPWENT" },
196 { WINBINDD_GETPWENT, winbindd_getpwent, "GETPWENT" },
198 { WINBINDD_GETGROUPS, winbindd_getgroups, "GETGROUPS" },
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" },
215 /* Enumeration functions */
217 { WINBINDD_LIST_USERS, winbindd_list_users, "LIST_USERS" },
218 { WINBINDD_LIST_GROUPS, winbindd_list_groups, "LIST_GROUPS" },
219 { WINBINDD_LIST_TRUSTDOM, winbindd_list_trusted_domains, "LIST_TRUSTDOM" },
220 { WINBINDD_SHOW_SEQUENCE, winbindd_show_sequence, "SHOW_SEQUENCE" },
222 /* SID related functions */
224 { WINBINDD_LOOKUPSID, winbindd_lookupsid, "LOOKUPSID" },
225 { WINBINDD_LOOKUPNAME, winbindd_lookupname, "LOOKUPNAME" },
227 /* Lookup related functions */
229 { WINBINDD_SID_TO_UID, winbindd_sid_to_uid, "SID_TO_UID" },
230 { WINBINDD_SID_TO_GID, winbindd_sid_to_gid, "SID_TO_GID" },
231 { WINBINDD_GID_TO_SID, winbindd_gid_to_sid, "GID_TO_SID" },
232 { WINBINDD_UID_TO_SID, winbindd_uid_to_sid, "UID_TO_SID" },
234 /* Miscellaneous */
236 { WINBINDD_CHECK_MACHACC, winbindd_check_machine_acct, "CHECK_MACHACC" },
237 { WINBINDD_PING, winbindd_ping, "PING" },
238 { WINBINDD_INFO, winbindd_info, "INFO" },
239 { WINBINDD_INTERFACE_VERSION, winbindd_interface_version, "INTERFACE_VERSION" },
240 { WINBINDD_DOMAIN_NAME, winbindd_domain_name, "DOMAIN_NAME" },
241 { WINBINDD_NETBIOS_NAME, winbindd_netbios_name, "NETBIOS_NAME" },
242 { WINBINDD_PRIV_PIPE_DIR, winbindd_priv_pipe_dir, "WINBINDD_PRIV_PIPE_DIR" },
244 /* WINS functions */
246 { WINBINDD_WINS_BYNAME, winbindd_wins_byname, "WINS_BYNAME" },
247 { WINBINDD_WINS_BYIP, winbindd_wins_byip, "WINS_BYIP" },
249 /* End of list */
251 { WINBINDD_NUM_CMDS, NULL, "NONE" }
254 static void process_request(struct winbindd_cli_state *state)
256 struct dispatch_table *table = dispatch_table;
258 /* Free response data - we may be interrupted and receive another
259 command before being able to send this data off. */
261 SAFE_FREE(state->response.extra_data);
263 ZERO_STRUCT(state->response);
265 state->response.result = WINBINDD_ERROR;
266 state->response.length = sizeof(struct winbindd_response);
268 /* Process command */
270 for (table = dispatch_table; table->fn; table++) {
271 if (state->request.cmd == table->cmd) {
272 DEBUG(10,("process_request: request fn %s\n", table->winbindd_cmd_name ));
273 state->response.result = table->fn(state);
274 break;
278 if (!table->fn)
279 DEBUG(10,("process_request: unknown request fn number %d\n", (int)state->request.cmd ));
281 /* In case extra data pointer is NULL */
283 if (!state->response.extra_data)
284 state->response.length = sizeof(struct winbindd_response);
287 /* Process a new connection by adding it to the client connection list */
289 static void new_connection(int listen_sock, BOOL privileged)
291 struct sockaddr_un sunaddr;
292 struct winbindd_cli_state *state;
293 socklen_t len;
294 int sock;
296 /* Accept connection */
298 len = sizeof(sunaddr);
300 do {
301 sock = accept(listen_sock, (struct sockaddr *)&sunaddr, &len);
302 } while (sock == -1 && errno == EINTR);
304 if (sock == -1)
305 return;
307 DEBUG(6,("accepted socket %d\n", sock));
309 /* Create new connection structure */
311 if ((state = (struct winbindd_cli_state *)
312 malloc(sizeof(*state))) == NULL)
313 return;
315 ZERO_STRUCTP(state);
316 state->sock = sock;
318 state->last_access = time(NULL);
320 state->privileged = privileged;
322 /* Add to connection list */
324 winbindd_add_client(state);
327 /* Remove a client connection from client connection list */
329 static void remove_client(struct winbindd_cli_state *state)
331 /* It's a dead client - hold a funeral */
333 if (state != NULL) {
335 /* Close socket */
337 close(state->sock);
339 /* Free any getent state */
341 free_getent_state(state->getpwent_state);
342 free_getent_state(state->getgrent_state);
344 /* We may have some extra data that was not freed if the
345 client was killed unexpectedly */
347 SAFE_FREE(state->response.extra_data);
349 /* Remove from list and free */
351 winbindd_remove_client(state);
352 SAFE_FREE(state);
357 /* Shutdown client connection which has been idle for the longest time */
359 static BOOL remove_idle_client(void)
361 struct winbindd_cli_state *state, *remove_state = NULL;
362 time_t last_access = 0;
363 int nidle = 0;
365 for (state = winbindd_client_list(); state; state = state->next) {
366 if (state->read_buf_len == 0 && state->write_buf_len == 0 &&
367 !state->getpwent_state && !state->getgrent_state) {
368 nidle++;
369 if (!last_access || state->last_access < last_access) {
370 last_access = state->last_access;
371 remove_state = state;
376 if (remove_state) {
377 DEBUG(5,("Found %d idle client connections, shutting down sock %d, pid %u\n",
378 nidle, remove_state->sock, (unsigned int)remove_state->pid));
379 remove_client(remove_state);
380 return True;
383 return False;
386 /* Process a complete received packet from a client */
388 void winbind_process_packet(struct winbindd_cli_state *state)
390 /* Process request */
392 /* Ensure null termination of entire request */
393 state->request.null_term = '\0';
395 state->pid = state->request.pid;
397 process_request(state);
399 /* Update client state */
401 state->read_buf_len = 0;
402 state->write_buf_len = sizeof(struct winbindd_response);
404 /* we might need to send it to the dual daemon */
405 if (opt_dual_daemon) {
406 dual_send_request(state);
410 /* Read some data from a client connection */
412 void winbind_client_read(struct winbindd_cli_state *state)
414 int n;
416 /* Read data */
418 n = sys_read(state->sock, state->read_buf_len +
419 (char *)&state->request,
420 sizeof(state->request) - state->read_buf_len);
422 DEBUG(10,("client_read: read %d bytes. Need %d more for a full request.\n", n, sizeof(state->request) - n - state->read_buf_len ));
424 /* Read failed, kill client */
426 if (n == -1 || n == 0) {
427 DEBUG(5,("read failed on sock %d, pid %d: %s\n",
428 state->sock, state->pid,
429 (n == -1) ? strerror(errno) : "EOF"));
431 state->finished = True;
432 return;
435 /* Update client state */
437 state->read_buf_len += n;
438 state->last_access = time(NULL);
441 /* Write some data to a client connection */
443 static void client_write(struct winbindd_cli_state *state)
445 char *data;
446 int num_written;
448 /* Write some data */
450 if (!state->write_extra_data) {
452 /* Write response structure */
454 data = (char *)&state->response + sizeof(state->response) -
455 state->write_buf_len;
457 } else {
459 /* Write extra data */
461 data = (char *)state->response.extra_data +
462 state->response.length -
463 sizeof(struct winbindd_response) -
464 state->write_buf_len;
467 num_written = sys_write(state->sock, data, state->write_buf_len);
469 DEBUG(10,("client_write: wrote %d bytes.\n", num_written ));
471 /* Write failed, kill cilent */
473 if (num_written == -1 || num_written == 0) {
475 DEBUG(3,("write failed on sock %d, pid %d: %s\n",
476 state->sock, state->pid,
477 (num_written == -1) ? strerror(errno) : "EOF"));
479 state->finished = True;
481 SAFE_FREE(state->response.extra_data);
483 return;
486 /* Update client state */
488 state->write_buf_len -= num_written;
489 state->last_access = time(NULL);
491 /* Have we written all data? */
493 if (state->write_buf_len == 0) {
495 /* Take care of extra data */
497 if (state->write_extra_data) {
499 SAFE_FREE(state->response.extra_data);
501 state->write_extra_data = False;
503 DEBUG(10,("client_write: client_write: complete response written.\n"));
505 } else if (state->response.length >
506 sizeof(struct winbindd_response)) {
508 /* Start writing extra data */
510 state->write_buf_len =
511 state->response.length -
512 sizeof(struct winbindd_response);
514 DEBUG(10,("client_write: need to write %d extra data bytes.\n", (int)state->write_buf_len));
516 state->write_extra_data = True;
521 /* Process incoming clients on listen_sock. We use a tricky non-blocking,
522 non-forking, non-threaded model which allows us to handle many
523 simultaneous connections while remaining impervious to many denial of
524 service attacks. */
526 static void process_loop(void)
528 /* We'll be doing this a lot */
530 while (1) {
531 struct winbindd_cli_state *state;
532 fd_set r_fds, w_fds;
533 int maxfd, listen_sock, listen_priv_sock, selret;
534 struct timeval timeout;
536 /* Handle messages */
538 message_dispatch();
540 /* rescan the trusted domains list. This must be done
541 regularly to cope with transitive trusts */
542 rescan_trusted_domains(False);
544 /* Free up temporary memory */
546 lp_talloc_free();
547 main_loop_talloc_free();
549 /* Initialise fd lists for select() */
551 listen_sock = open_winbindd_socket();
552 listen_priv_sock = open_winbindd_priv_socket();
554 if (listen_sock == -1 || listen_priv_sock == -1) {
555 perror("open_winbind_socket");
556 exit(1);
559 maxfd = MAX(listen_sock, listen_priv_sock);
561 FD_ZERO(&r_fds);
562 FD_ZERO(&w_fds);
563 FD_SET(listen_sock, &r_fds);
564 FD_SET(listen_priv_sock, &r_fds);
566 timeout.tv_sec = WINBINDD_ESTABLISH_LOOP;
567 timeout.tv_usec = 0;
569 if (opt_dual_daemon) {
570 maxfd = dual_select_setup(&w_fds, maxfd);
573 /* Set up client readers and writers */
575 state = winbindd_client_list();
577 while (state) {
579 /* Dispose of client connection if it is marked as
580 finished */
582 if (state->finished) {
583 struct winbindd_cli_state *next = state->next;
585 remove_client(state);
586 state = next;
587 continue;
590 /* Select requires we know the highest fd used */
592 if (state->sock > maxfd)
593 maxfd = state->sock;
595 /* Add fd for reading */
597 if (state->read_buf_len != sizeof(state->request))
598 FD_SET(state->sock, &r_fds);
600 /* Add fd for writing */
602 if (state->write_buf_len)
603 FD_SET(state->sock, &w_fds);
605 state = state->next;
608 /* Call select */
610 selret = sys_select(maxfd + 1, &r_fds, &w_fds, NULL, &timeout);
612 if (selret == 0)
613 continue;
615 if ((selret == -1 && errno != EINTR) || selret == 0) {
617 /* Select error, something is badly wrong */
619 perror("select");
620 exit(1);
623 /* Create a new connection if listen_sock readable */
625 if (selret > 0) {
627 if (opt_dual_daemon) {
628 dual_select(&w_fds);
631 if (FD_ISSET(listen_sock, &r_fds)) {
632 while (winbindd_num_clients() > WINBINDD_MAX_SIMULTANEOUS_CLIENTS - 1) {
633 DEBUG(5,("winbindd: Exceeding %d client connections, removing idle connection.\n",
634 WINBINDD_MAX_SIMULTANEOUS_CLIENTS));
635 if (!remove_idle_client()) {
636 DEBUG(0,("winbindd: Exceeding %d client connections, no idle connection found\n",
637 WINBINDD_MAX_SIMULTANEOUS_CLIENTS));
638 break;
641 /* new, non-privileged connection */
642 new_connection(listen_sock, False);
645 if (FD_ISSET(listen_priv_sock, &r_fds)) {
646 while (winbindd_num_clients() > WINBINDD_MAX_SIMULTANEOUS_CLIENTS - 1) {
647 DEBUG(5,("winbindd: Exceeding %d client connections, removing idle connection.\n",
648 WINBINDD_MAX_SIMULTANEOUS_CLIENTS));
649 if (!remove_idle_client()) {
650 DEBUG(0,("winbindd: Exceeding %d client connections, no idle connection found\n",
651 WINBINDD_MAX_SIMULTANEOUS_CLIENTS));
652 break;
655 /* new, privileged connection */
656 new_connection(listen_priv_sock, True);
659 /* Process activity on client connections */
661 for (state = winbindd_client_list(); state;
662 state = state->next) {
664 /* Data available for reading */
666 if (FD_ISSET(state->sock, &r_fds)) {
668 /* Read data */
670 winbind_client_read(state);
673 * If we have the start of a
674 * packet, then check the
675 * length field to make sure
676 * the client's not talking
677 * Mock Swedish.
680 if (state->read_buf_len >= sizeof(uint32)
681 && *(uint32 *) &state->request != sizeof(state->request)) {
682 DEBUG(0,("process_loop: Invalid request size from pid %d: %d bytes sent, should be %d\n",
683 state->request.pid, *(uint32 *) &state->request, sizeof(state->request)));
685 remove_client(state);
686 break;
689 /* A request packet might be
690 complete */
692 if (state->read_buf_len ==
693 sizeof(state->request)) {
694 winbind_process_packet(state);
698 /* Data available for writing */
700 if (FD_ISSET(state->sock, &w_fds))
701 client_write(state);
705 #if 0
706 winbindd_check_cache_size(time(NULL));
707 #endif
709 /* Check signal handling things */
711 if (do_sigterm)
712 terminate();
714 if (do_sighup) {
716 DEBUG(3, ("got SIGHUP\n"));
718 /* Flush various caches */
720 flush_caches();
721 reload_services_file(True);
722 do_sighup = False;
725 if (do_sigusr2) {
726 print_winbindd_status();
727 do_sigusr2 = False;
732 /* Main function */
734 struct winbindd_state server_state; /* Server state information */
736 int main(int argc, char **argv)
738 pstring logfile;
739 static BOOL interactive = False;
740 static BOOL Fork = True;
741 static BOOL log_stdout = False;
742 struct poptOption long_options[] = {
743 POPT_AUTOHELP
744 { "stdout", 'S', POPT_ARG_VAL, &log_stdout, True, "Log to stdout" },
745 { "foreground", 'F', POPT_ARG_VAL, &Fork, False, "Daemon in foreground mode" },
746 { "interactive", 'i', POPT_ARG_NONE, NULL, 'i', "Interactive mode" },
747 { "dual-daemon", 'B', POPT_ARG_VAL, &opt_dual_daemon, True, "Dual daemon mode" },
748 { "no-caching", 'n', POPT_ARG_VAL, &opt_nocache, False, "Disable caching" },
749 POPT_COMMON_SAMBA
750 POPT_TABLEEND
752 poptContext pc;
753 int opt;
755 /* glibc (?) likes to print "User defined signal 1" and exit if a
756 SIGUSR[12] is received before a handler is installed */
758 CatchSignal(SIGUSR1, SIG_IGN);
759 CatchSignal(SIGUSR2, SIG_IGN);
761 fault_setup((void (*)(void *))fault_quit );
763 /* Initialise for running in non-root mode */
765 sec_init();
767 set_remote_machine_name("winbindd", False);
769 /* Set environment variable so we don't recursively call ourselves.
770 This may also be useful interactively. */
772 setenv(WINBINDD_DONT_ENV, "1", 1);
774 /* Initialise samba/rpc client stuff */
776 pc = poptGetContext("winbindd", argc, (const char **)argv, long_options,
777 POPT_CONTEXT_KEEP_FIRST);
779 while ((opt = poptGetNextOpt(pc)) != -1) {
780 switch (opt) {
781 /* Don't become a daemon */
782 case 'i':
783 interactive = True;
784 log_stdout = True;
785 Fork = False;
786 break;
791 if (log_stdout && Fork) {
792 printf("Can't log to stdout (-S) unless daemon is in foreground +(-F) or interactive (-i)\n");
793 poptPrintUsage(pc, stderr, 0);
794 exit(1);
797 snprintf(logfile, sizeof(logfile), "%s/log.winbindd", dyn_LOGFILEBASE);
798 lp_set_logfile(logfile);
799 setup_logging("winbindd", log_stdout);
800 reopen_logs();
802 DEBUG(1, ("winbindd version %s started.\n", VERSION ) );
803 DEBUGADD( 1, ( "Copyright The Samba Team 2000-2003\n" ) );
805 if (!reload_services_file(False)) {
806 DEBUG(0, ("error opening config file\n"));
807 exit(1);
810 /* Setup names. */
812 if (!init_names())
813 exit(1);
815 load_interfaces();
817 if (!secrets_init()) {
819 DEBUG(0,("Could not initialize domain trust account secrets. Giving up\n"));
820 return False;
823 /* Enable netbios namecache */
825 namecache_enable();
827 /* Check winbindd parameters are valid */
829 ZERO_STRUCT(server_state);
831 if (!winbindd_param_init())
832 return 1;
834 /* Winbind daemon initialisation */
836 if (!idmap_init())
837 return 1;
839 if (!idmap_init_wellknown_sids())
840 exit(1);
842 /* Unblock all signals we are interested in as they may have been
843 blocked by the parent process. */
845 BlockSignals(False, SIGINT);
846 BlockSignals(False, SIGQUIT);
847 BlockSignals(False, SIGTERM);
848 BlockSignals(False, SIGUSR1);
849 BlockSignals(False, SIGUSR2);
850 BlockSignals(False, SIGHUP);
852 /* Setup signal handlers */
854 CatchSignal(SIGINT, termination_handler); /* Exit on these sigs */
855 CatchSignal(SIGQUIT, termination_handler);
856 CatchSignal(SIGTERM, termination_handler);
858 CatchSignal(SIGPIPE, SIG_IGN); /* Ignore sigpipe */
860 CatchSignal(SIGUSR2, sigusr2_handler); /* Debugging sigs */
861 CatchSignal(SIGHUP, sighup_handler);
863 if (!interactive)
864 become_daemon(Fork);
866 pidfile_create("winbindd");
868 #if HAVE_SETPGID
870 * If we're interactive we want to set our own process group for
871 * signal management.
873 if (interactive)
874 setpgid( (pid_t)0, (pid_t)0);
875 #endif
877 if (opt_dual_daemon) {
878 do_dual_daemon();
881 /* Initialise messaging system */
883 if (!message_init()) {
884 DEBUG(0, ("unable to initialise messaging system\n"));
885 exit(1);
887 poptFreeContext(pc);
889 /* Loop waiting for requests */
891 process_loop();
893 trustdom_cache_shutdown();
894 uni_group_cache_shutdown();
896 return 0;