4bfec1afe49338387de64b90fcc42b561631b027
[kamenim/samba-autobuild/.git] / source3 / nsswitch / winbindd.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    Winbind daemon for ntdom nss module
5
6    Copyright (C) by Tim Potter 2000-2002
7    Copyright (C) Andrew Tridgell 2002
8    
9    This program is free software; you can redistribute it and/or modify
10    it under the terms of the GNU General Public License as published by
11    the Free Software Foundation; either version 2 of the License, or
12    (at your option) any later version.
13    
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License for more details.
18    
19    You should have received a copy of the GNU General Public License
20    along with this program; if not, write to the Free Software
21    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24 #include "winbindd.h"
25
26 BOOL opt_nocache = False;
27 BOOL opt_dual_daemon = False;
28
29 /* Reload configuration */
30
31 static BOOL reload_services_file(BOOL test)
32 {
33         BOOL ret;
34         pstring logfile;
35
36         if (lp_loaded()) {
37                 pstring fname;
38
39                 pstrcpy(fname,lp_configfile());
40                 if (file_exist(fname,NULL) && !strcsequal(fname,dyn_CONFIGFILE)) {
41                         pstrcpy(dyn_CONFIGFILE,fname);
42                         test = False;
43                 }
44         }
45
46         snprintf(logfile, sizeof(logfile), "%s/log.winbindd", dyn_LOGFILEBASE);
47         lp_set_logfile(logfile);
48
49         reopen_logs();
50         ret = lp_load(dyn_CONFIGFILE,False,False,True);
51
52         snprintf(logfile, sizeof(logfile), "%s/log.winbindd", dyn_LOGFILEBASE);
53         lp_set_logfile(logfile);
54
55         reopen_logs();
56         load_interfaces();
57
58         return(ret);
59 }
60
61 #if DUMP_CORE
62
63 /**************************************************************************** **
64  Prepare to dump a core file - carefully!
65  **************************************************************************** */
66
67 static BOOL dump_core(void)
68 {
69         char *p;
70         pstring dname;
71         pstrcpy( dname, lp_logfile() );
72         if ((p=strrchr(dname,'/')))
73                 *p=0;
74         pstrcat( dname, "/corefiles" );
75         mkdir( dname, 0700 );
76         sys_chown( dname, getuid(), getgid() );
77         chmod( dname, 0700 );
78         if ( chdir(dname) )
79                 return( False );
80         umask( ~(0700) );
81  
82 #ifdef HAVE_GETRLIMIT
83 #ifdef RLIMIT_CORE
84         {
85                 struct rlimit rlp;
86                 getrlimit( RLIMIT_CORE, &rlp );
87                 rlp.rlim_cur = MAX( 4*1024*1024, rlp.rlim_cur );
88                 setrlimit( RLIMIT_CORE, &rlp );
89                 getrlimit( RLIMIT_CORE, &rlp );
90                 DEBUG( 3, ( "Core limits now %d %d\n", (int)rlp.rlim_cur, (int)rlp.rlim_max ) );
91         }
92 #endif
93 #endif
94  
95         DEBUG(0,("Dumping core in %s\n",dname));
96         abort();
97         return( True );
98 } /* dump_core */
99 #endif
100
101 /**************************************************************************** **
102  Handle a fault..
103  **************************************************************************** */
104
105 static void fault_quit(void)
106 {
107 #if DUMP_CORE
108         dump_core();
109 #endif
110 }
111
112 static void winbindd_status(void)
113 {
114         struct winbindd_cli_state *tmp;
115
116         DEBUG(0, ("winbindd status:\n"));
117
118         /* Print client state information */
119         
120         DEBUG(0, ("\t%d clients currently active\n", winbindd_num_clients()));
121         
122         if (DEBUGLEVEL >= 2 && winbindd_num_clients()) {
123                 DEBUG(2, ("\tclient list:\n"));
124                 for(tmp = winbindd_client_list(); tmp; tmp = tmp->next) {
125                         DEBUG(2, ("\t\tpid %d, sock %d, rbl %d, wbl %d\n",
126                                   tmp->pid, tmp->sock, tmp->read_buf_len, 
127                                   tmp->write_buf_len));
128                 }
129         }
130 }
131
132 /* Print winbindd status to log file */
133
134 static void print_winbindd_status(void)
135 {
136         winbindd_status();
137         winbindd_idmap_status();
138         winbindd_cm_status();
139 }
140
141 /* Flush client cache */
142
143 static void flush_caches(void)
144 {
145         /* Clear cached user and group enumation info */        
146         wcache_flush_cache();
147 }
148
149 /* Handle the signal by unlinking socket and exiting */
150
151 static void terminate(void)
152 {
153         pstring path;
154
155         winbindd_idmap_close();
156         
157         /* Remove socket file */
158         snprintf(path, sizeof(path), "%s/%s", 
159                  WINBINDD_SOCKET_DIR, WINBINDD_SOCKET_NAME);
160         unlink(path);
161         exit(0);
162 }
163
164 static BOOL do_sigterm;
165
166 static void termination_handler(int signum)
167 {
168         do_sigterm = True;
169         sys_select_signal();
170 }
171
172 static BOOL do_sigusr2;
173
174 static void sigusr2_handler(int signum)
175 {
176         do_sigusr2 = True;
177         sys_select_signal();
178 }
179
180 static BOOL do_sighup;
181
182 static void sighup_handler(int signum)
183 {
184         do_sighup = True;
185         sys_select_signal();
186 }
187
188 struct dispatch_table {
189         enum winbindd_cmd cmd;
190         enum winbindd_result (*fn)(struct winbindd_cli_state *state);
191         char *winbindd_cmd_name;
192 };
193
194 static struct dispatch_table dispatch_table[] = {
195         
196         /* User functions */
197
198         { WINBINDD_GETPWNAM, winbindd_getpwnam, "GETPWNAM" },
199         { WINBINDD_GETPWUID, winbindd_getpwuid, "GETPWUID" },
200
201         { WINBINDD_SETPWENT, winbindd_setpwent, "SETPWENT" },
202         { WINBINDD_ENDPWENT, winbindd_endpwent, "ENDPWENT" },
203         { WINBINDD_GETPWENT, winbindd_getpwent, "GETPWENT" },
204
205         { WINBINDD_GETGROUPS, winbindd_getgroups, "GETGROUPS" },
206
207         /* Group functions */
208
209         { WINBINDD_GETGRNAM, winbindd_getgrnam, "GETGRNAM" },
210         { WINBINDD_GETGRGID, winbindd_getgrgid, "GETGRGID" },
211         { WINBINDD_SETGRENT, winbindd_setgrent, "SETGRENT" },
212         { WINBINDD_ENDGRENT, winbindd_endgrent, "ENDGRENT" },
213         { WINBINDD_GETGRENT, winbindd_getgrent, "GETGRENT" },
214         { WINBINDD_GETGRLST, winbindd_getgrent, "GETGRLST" },
215
216         /* PAM auth functions */
217
218         { WINBINDD_PAM_AUTH, winbindd_pam_auth, "PAM_AUTH" },
219         { WINBINDD_PAM_AUTH_CRAP, winbindd_pam_auth_crap, "AUTH_CRAP" },
220         { WINBINDD_PAM_CHAUTHTOK, winbindd_pam_chauthtok, "CHAUTHTOK" },
221
222         /* Enumeration functions */
223
224         { WINBINDD_LIST_USERS, winbindd_list_users, "LIST_USERS" },
225         { WINBINDD_LIST_GROUPS, winbindd_list_groups, "LIST_GROUPS" },
226         { WINBINDD_LIST_TRUSTDOM, winbindd_list_trusted_domains, "LIST_TRUSTDOM" },
227         { WINBINDD_SHOW_SEQUENCE, winbindd_show_sequence, "SHOW_SEQUENCE" },
228
229         /* SID related functions */
230
231         { WINBINDD_LOOKUPSID, winbindd_lookupsid, "LOOKUPSID" },
232         { WINBINDD_LOOKUPNAME, winbindd_lookupname, "LOOKUPNAME" },
233
234         /* Lookup related functions */
235
236         { WINBINDD_SID_TO_UID, winbindd_sid_to_uid, "SID_TO_UID" },
237         { WINBINDD_SID_TO_GID, winbindd_sid_to_gid, "SID_TO_GID" },
238         { WINBINDD_GID_TO_SID, winbindd_gid_to_sid, "GID_TO_SID" },
239         { WINBINDD_UID_TO_SID, winbindd_uid_to_sid, "UID_TO_SID" },
240
241         /* Miscellaneous */
242
243         { WINBINDD_CHECK_MACHACC, winbindd_check_machine_acct, "CHECK_MACHACC" },
244         { WINBINDD_PING, winbindd_ping, "PING" },
245         { WINBINDD_INFO, winbindd_info, "INFO" },
246         { WINBINDD_INTERFACE_VERSION, winbindd_interface_version, "INTERFACE_VERSION" },
247         { WINBINDD_DOMAIN_NAME, winbindd_domain_name, "DOMAIN_NAME" },
248
249         /* WINS functions */
250
251         { WINBINDD_WINS_BYNAME, winbindd_wins_byname, "WINS_BYNAME" },
252         { WINBINDD_WINS_BYIP, winbindd_wins_byip, "WINS_BYIP" },
253
254         /* End of list */
255
256         { WINBINDD_NUM_CMDS, NULL, "NONE" }
257 };
258
259 static void process_request(struct winbindd_cli_state *state)
260 {
261         struct dispatch_table *table = dispatch_table;
262
263         /* Free response data - we may be interrupted and receive another
264            command before being able to send this data off. */
265
266         SAFE_FREE(state->response.extra_data);  
267
268         ZERO_STRUCT(state->response);
269
270         state->response.result = WINBINDD_ERROR;
271         state->response.length = sizeof(struct winbindd_response);
272
273         /* Process command */
274
275         for (table = dispatch_table; table->fn; table++) {
276                 if (state->request.cmd == table->cmd) {
277                         DEBUG(10,("process_request: request fn %s\n", table->winbindd_cmd_name ));
278                         state->response.result = table->fn(state);
279                         break;
280                 }
281         }
282
283         if (!table->fn)
284                 DEBUG(10,("process_request: unknown request fn number %d\n", (int)state->request.cmd ));
285
286         /* In case extra data pointer is NULL */
287
288         if (!state->response.extra_data)
289                 state->response.length = sizeof(struct winbindd_response);
290 }
291
292 /* Process a new connection by adding it to the client connection list */
293
294 static void new_connection(int listen_sock)
295 {
296         struct sockaddr_un sunaddr;
297         struct winbindd_cli_state *state;
298         socklen_t len;
299         int sock;
300         
301         /* Accept connection */
302         
303         len = sizeof(sunaddr);
304
305         do {
306                 sock = accept(listen_sock, (struct sockaddr *)&sunaddr, &len);
307         } while (sock == -1 && errno == EINTR);
308
309         if (sock == -1)
310                 return;
311         
312         DEBUG(6,("accepted socket %d\n", sock));
313         
314         /* Create new connection structure */
315         
316         if ((state = (struct winbindd_cli_state *) 
317              malloc(sizeof(*state))) == NULL)
318                 return;
319         
320         ZERO_STRUCTP(state);
321         state->sock = sock;
322         
323         /* Add to connection list */
324         
325         winbindd_add_client(state);
326 }
327
328 /* Remove a client connection from client connection list */
329
330 static void remove_client(struct winbindd_cli_state *state)
331 {
332         /* It's a dead client - hold a funeral */
333         
334         if (state != NULL) {
335                 
336                 /* Close socket */
337                 
338                 close(state->sock);
339                 
340                 /* Free any getent state */
341                 
342                 free_getent_state(state->getpwent_state);
343                 free_getent_state(state->getgrent_state);
344                 
345                 /* We may have some extra data that was not freed if the
346                    client was killed unexpectedly */
347
348                 SAFE_FREE(state->response.extra_data);
349                 
350                 /* Remove from list and free */
351                 
352                 winbindd_remove_client(state);
353                 SAFE_FREE(state);
354         }
355 }
356
357
358 /* Process a complete received packet from a client */
359
360 void winbind_process_packet(struct winbindd_cli_state *state)
361 {
362         /* Process request */
363         
364         /* Ensure null termination of entire request */
365         state->request.domain[sizeof(state->request.domain)-1]='\0';
366
367         state->pid = state->request.pid;
368         
369         process_request(state);
370
371         /* Update client state */
372         
373         state->read_buf_len = 0;
374         state->write_buf_len = sizeof(struct winbindd_response);
375
376         /* we might need to send it to the dual daemon */
377         if (opt_dual_daemon) {
378                 dual_send_request(state);
379         }
380 }
381
382 /* Read some data from a client connection */
383
384 void winbind_client_read(struct winbindd_cli_state *state)
385 {
386         int n;
387     
388         /* Read data */
389
390         n = sys_read(state->sock, state->read_buf_len + 
391                  (char *)&state->request, 
392                  sizeof(state->request) - state->read_buf_len);
393         
394         DEBUG(10,("client_read: read %d bytes. Need %d more for a full request.\n", n, sizeof(state->request) - n - state->read_buf_len ));
395
396         /* Read failed, kill client */
397         
398         if (n == -1 || n == 0) {
399                 DEBUG(5,("read failed on sock %d, pid %d: %s\n",
400                          state->sock, state->pid, 
401                          (n == -1) ? strerror(errno) : "EOF"));
402                 
403                 state->finished = True;
404                 return;
405         }
406         
407         /* Update client state */
408         
409         state->read_buf_len += n;
410 }
411
412 /* Write some data to a client connection */
413
414 static void client_write(struct winbindd_cli_state *state)
415 {
416         char *data;
417         int num_written;
418         
419         /* Write some data */
420         
421         if (!state->write_extra_data) {
422
423                 /* Write response structure */
424                 
425                 data = (char *)&state->response + sizeof(state->response) - 
426                         state->write_buf_len;
427
428         } else {
429
430                 /* Write extra data */
431                 
432                 data = (char *)state->response.extra_data + 
433                         state->response.length - 
434                         sizeof(struct winbindd_response) - 
435                         state->write_buf_len;
436         }
437         
438         num_written = sys_write(state->sock, data, state->write_buf_len);
439         
440         DEBUG(10,("client_write: wrote %d bytes.\n", num_written ));
441
442         /* Write failed, kill cilent */
443         
444         if (num_written == -1 || num_written == 0) {
445                 
446                 DEBUG(3,("write failed on sock %d, pid %d: %s\n",
447                          state->sock, state->pid, 
448                          (num_written == -1) ? strerror(errno) : "EOF"));
449                 
450                 state->finished = True;
451
452                 SAFE_FREE(state->response.extra_data);
453
454                 return;
455         }
456         
457         /* Update client state */
458         
459         state->write_buf_len -= num_written;
460         
461         /* Have we written all data? */
462         
463         if (state->write_buf_len == 0) {
464                 
465                 /* Take care of extra data */
466                 
467                 if (state->write_extra_data) {
468
469                         SAFE_FREE(state->response.extra_data);
470
471                         state->write_extra_data = False;
472
473                         DEBUG(10,("client_write: client_write: complete response written.\n"));
474
475                 } else if (state->response.length > 
476                            sizeof(struct winbindd_response)) {
477                         
478                         /* Start writing extra data */
479
480                         state->write_buf_len = 
481                                 state->response.length -
482                                 sizeof(struct winbindd_response);
483                         
484                         DEBUG(10,("client_write: need to write %d extra data bytes.\n", (int)state->write_buf_len));
485
486                         state->write_extra_data = True;
487                 }
488         }
489 }
490
491 /* Process incoming clients on accept_sock.  We use a tricky non-blocking,
492    non-forking, non-threaded model which allows us to handle many
493    simultaneous connections while remaining impervious to many denial of
494    service attacks. */
495
496 static void process_loop(void)
497 {
498         /* We'll be doing this a lot */
499
500         while (1) {
501                 struct winbindd_cli_state *state;
502                 fd_set r_fds, w_fds;
503                 int maxfd, listen_sock, selret;
504                 struct timeval timeout;
505
506                 /* Handle messages */
507
508                 message_dispatch();
509
510                 /* rescan the trusted domains list. This must be done
511                    regularly to cope with transitive trusts */
512                 rescan_trusted_domains();
513
514                 /* Free up temporary memory */
515
516                 lp_talloc_free();
517                 main_loop_talloc_free();
518
519                 /* Initialise fd lists for select() */
520
521                 listen_sock = open_winbindd_socket();
522                 maxfd = listen_sock;
523
524                 FD_ZERO(&r_fds);
525                 FD_ZERO(&w_fds);
526                 FD_SET(listen_sock, &r_fds);
527
528                 timeout.tv_sec = WINBINDD_ESTABLISH_LOOP;
529                 timeout.tv_usec = 0;
530
531                 if (opt_dual_daemon) {
532                         maxfd = dual_select_setup(&w_fds, maxfd);
533                 }
534
535                 /* Set up client readers and writers */
536
537                 state = winbindd_client_list();
538
539                 while (state) {
540
541                         /* Dispose of client connection if it is marked as 
542                            finished */ 
543
544                         if (state->finished) {
545                                 struct winbindd_cli_state *next = state->next;
546
547                                 remove_client(state);
548                                 state = next;
549                                 continue;
550                         }
551
552                         /* Select requires we know the highest fd used */
553
554                         if (state->sock > maxfd)
555                                 maxfd = state->sock;
556
557                         /* Add fd for reading */
558
559                         if (state->read_buf_len != sizeof(state->request))
560                                 FD_SET(state->sock, &r_fds);
561
562                         /* Add fd for writing */
563
564                         if (state->write_buf_len)
565                                 FD_SET(state->sock, &w_fds);
566
567                         state = state->next;
568                 }
569
570                 /* Call select */
571         
572                 selret = sys_select(maxfd + 1, &r_fds, &w_fds, NULL, &timeout);
573
574                 if (selret == 0)
575                         continue;
576
577                 if ((selret == -1 && errno != EINTR) || selret == 0) {
578
579                         /* Select error, something is badly wrong */
580
581                         perror("select");
582                         exit(1);
583                 }
584
585                 /* Create a new connection if accept_sock readable */
586
587                 if (selret > 0) {
588
589                         if (opt_dual_daemon) {
590                                 dual_select(&w_fds);
591                         }
592
593                         if (FD_ISSET(listen_sock, &r_fds))
594                                 new_connection(listen_sock);
595             
596                         /* Process activity on client connections */
597             
598                         for (state = winbindd_client_list(); state; 
599                              state = state->next) {
600                 
601                                 /* Data available for reading */
602                 
603                                 if (FD_ISSET(state->sock, &r_fds)) {
604                     
605                                         /* Read data */
606                     
607                                         winbind_client_read(state);
608
609                                         /* 
610                                          * If we have the start of a
611                                          * packet, then check the
612                                          * length field to make sure
613                                          * the client's not talking
614                                          * Mock Swedish.
615                                          */
616
617                                         if (state->read_buf_len >= sizeof(uint32)
618                                             && *(uint32 *) &state->request != sizeof(state->request)) {
619                                                 DEBUG(0,("process_loop: Invalid request size from pid %d: %d bytes sent, should be %d\n",
620                                                                 state->request.pid, *(uint32 *) &state->request, sizeof(state->request)));
621
622                                                 remove_client(state);
623                                                 break;
624                                         }
625
626                                         /* A request packet might be 
627                                            complete */
628                     
629                                         if (state->read_buf_len == 
630                                             sizeof(state->request)) {
631                                                 winbind_process_packet(state);
632                                         }
633                                 }
634                 
635                                 /* Data available for writing */
636                 
637                                 if (FD_ISSET(state->sock, &w_fds))
638                                         client_write(state);
639                         }
640                 }
641
642 #if 0
643                 winbindd_check_cache_size(time(NULL));
644 #endif
645
646                 /* Check signal handling things */
647
648                 if (do_sigterm)
649                         terminate();
650
651                 if (do_sighup) {
652
653                         DEBUG(3, ("got SIGHUP\n"));
654  
655                         /* Flush various caches */
656
657                         flush_caches();
658                         reload_services_file(True);
659                         do_sighup = False;
660                 }
661
662                 if (do_sigusr2) {
663                         print_winbindd_status();
664                         do_sigusr2 = False;
665                 }
666         }
667 }
668
669
670 /*
671   these are split out from the main winbindd for use by the background daemon
672  */
673 BOOL winbind_setup_common(void)
674 {
675         load_interfaces();
676
677         if (!secrets_init()) {
678
679                 DEBUG(0,("Could not initialize domain trust account secrets. Giving up\n"));
680                 return False;
681         }
682
683         namecache_enable();     /* Enable netbios namecache */
684
685         /* Check winbindd parameters are valid */
686
687         ZERO_STRUCT(server_state);
688
689         if (!winbindd_param_init())
690                 return False;
691
692         /* Get list of domains we look up requests for.  This includes the
693            domain which we are a member of as well as any trusted
694            domains. */ 
695
696         init_domain_list();
697
698         /* Winbind daemon initialisation */
699
700         if (!winbindd_idmap_init())
701                 return False;
702
703         /* Unblock all signals we are interested in as they may have been
704            blocked by the parent process. */
705
706         BlockSignals(False, SIGINT);
707         BlockSignals(False, SIGQUIT);
708         BlockSignals(False, SIGTERM);
709         BlockSignals(False, SIGUSR1);
710         BlockSignals(False, SIGUSR2);
711         BlockSignals(False, SIGHUP);
712
713         /* Setup signal handlers */
714         
715         CatchSignal(SIGINT, termination_handler);      /* Exit on these sigs */
716         CatchSignal(SIGQUIT, termination_handler);
717         CatchSignal(SIGTERM, termination_handler);
718
719         CatchSignal(SIGPIPE, SIG_IGN);                 /* Ignore sigpipe */
720
721         CatchSignal(SIGUSR2, sigusr2_handler);         /* Debugging sigs */
722         CatchSignal(SIGHUP, sighup_handler);
723
724         return True;
725 }
726
727
728 /* Main function */
729
730 struct winbindd_state server_state;   /* Server state information */
731
732
733 static void usage(void)
734 {
735         printf("Usage: winbindd [options]\n");
736         printf("\t-i                interactive mode\n");
737         printf("\t-B                dual daemon mode\n");
738         printf("\t-n                disable cacheing\n");
739         printf("\t-d level          set debug level\n");
740         printf("\t-s configfile     choose smb.conf location\n");
741         printf("\t-h                show this help message\n");
742 }
743
744  int main(int argc, char **argv)
745 {
746         extern BOOL AllowDebugChange;
747         pstring logfile;
748         BOOL interactive = False;
749         int opt;
750
751         /* glibc (?) likes to print "User defined signal 1" and exit if a
752            SIGUSR[12] is received before a handler is installed */
753
754         CatchSignal(SIGUSR1, SIG_IGN);
755         CatchSignal(SIGUSR2, SIG_IGN);
756
757         fault_setup((void (*)(void *))fault_quit );
758
759         snprintf(logfile, sizeof(logfile), "%s/log.winbindd", dyn_LOGFILEBASE);
760         lp_set_logfile(logfile);
761
762         /* Initialise for running in non-root mode */
763
764         sec_init();
765
766         /* Set environment variable so we don't recursively call ourselves.
767            This may also be useful interactively. */
768
769         SETENV(WINBINDD_DONT_ENV, "1", 1);
770
771         /* Initialise samba/rpc client stuff */
772
773         while ((opt = getopt(argc, argv, "id:s:nhB")) != EOF) {
774                 switch (opt) {
775
776                         /* Don't become a daemon */
777                 case 'i':
778                         interactive = True;
779                         break;
780
781                         /* dual daemon system */
782                 case 'B':
783                         opt_dual_daemon = True;
784                         break;
785
786                         /* disable cacheing */
787                 case 'n':
788                         opt_nocache = True;
789                         break;
790
791                         /* Run with specified debug level */
792                 case 'd':
793                         DEBUGLEVEL = atoi(optarg);
794                         AllowDebugChange = False;
795                         break;
796
797                         /* Load a different smb.conf file */
798                 case 's':
799                         pstrcpy(dyn_CONFIGFILE,optarg);
800                         break;
801
802                 case 'h':
803                         usage();
804                         exit(0);
805
806                 default:
807                         printf("Unknown option %c\n", (char)opt);
808                         exit(1);
809                 }
810         }
811
812         snprintf(logfile, sizeof(logfile), "%s/log.winbindd", dyn_LOGFILEBASE);
813         lp_set_logfile(logfile);
814         setup_logging("winbindd", interactive);
815         reopen_logs();
816
817         DEBUG(1, ("winbindd version %s started.\n", VERSION ) );
818         DEBUGADD( 1, ( "Copyright The Samba Team 2000-2001\n" ) );
819
820         if (!reload_services_file(False)) {
821                 DEBUG(0, ("error opening config file\n"));
822                 exit(1);
823         }
824
825         /* Setup names. */
826
827         if (!init_names())
828                 exit(1);
829
830         if (!interactive) {
831                 become_daemon();
832                 pidfile_create("winbindd");
833         }
834
835
836 #if HAVE_SETPGID
837         /*
838          * If we're interactive we want to set our own process group for
839          * signal management.
840          */
841         if (interactive)
842                 setpgid( (pid_t)0, (pid_t)0);
843 #endif
844
845         if (!winbind_setup_common()) {
846                 return 1;
847         }
848
849         if (opt_dual_daemon) {
850                 do_dual_daemon();
851         }
852
853         /* Initialise messaging system */
854
855         if (!message_init()) {
856                 DEBUG(0, ("unable to initialise messaging system\n"));
857                 exit(1);
858         }
859
860         register_msg_pool_usage();
861
862         /* Loop waiting for requests */
863
864         process_loop();
865
866         uni_group_cache_shutdown();
867         return 0;
868 }