Removed global_myworkgroup, global_myname, global_myscope. Added liberal
[kai/samba-autobuild/.git] / source3 / smbd / server.c
1 /* 
2    Unix SMB/CIFS implementation.
3    Main SMB server routines
4    Copyright (C) Andrew Tridgell                1992-1998
5    Copyright (C) Martin Pool                    2002
6    Copyright (C) Jelmer Vernooij                2002
7    
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12    
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #include "includes.h"
24
25 int am_parent = 1;
26
27 /* the last message the was processed */
28 int last_message = -1;
29
30 /* a useful macro to debug the last message processed */
31 #define LAST_MESSAGE() smb_fn_name(last_message)
32
33 extern pstring user_socket_options;
34 extern SIG_ATOMIC_T got_sig_term;
35 extern SIG_ATOMIC_T reload_after_sighup;
36
37 #ifdef WITH_DFS
38 extern int dcelogin_atmost_once;
39 #endif /* WITH_DFS */
40
41 /* really we should have a top level context structure that has the
42    client file descriptor as an element. That would require a major rewrite :(
43
44    the following 2 functions are an alternative - they make the file
45    descriptor private to smbd
46  */
47 static int server_fd = -1;
48
49 int smbd_server_fd(void)
50 {
51         return server_fd;
52 }
53
54 static void smbd_set_server_fd(int fd)
55 {
56         server_fd = fd;
57         client_setfd(fd);
58 }
59
60 /****************************************************************************
61  Terminate signal.
62 ****************************************************************************/
63
64 static void sig_term(void)
65 {
66         got_sig_term = 1;
67         sys_select_signal();
68 }
69
70 /****************************************************************************
71  Catch a sighup.
72 ****************************************************************************/
73
74 static void sig_hup(int sig)
75 {
76         reload_after_sighup = 1;
77         sys_select_signal();
78 }
79
80 /****************************************************************************
81   Send a SIGTERM to our process group.
82 *****************************************************************************/
83
84 static void  killkids(void)
85 {
86         if(am_parent) kill(0,SIGTERM);
87 }
88
89 /****************************************************************************
90  Process a sam sync message - not sure whether to do this here or
91  somewhere else.
92 ****************************************************************************/
93
94 static void msg_sam_sync(int UNUSED(msg_type), pid_t UNUSED(pid),
95                          void *UNUSED(buf), size_t UNUSED(len))
96 {
97         DEBUG(10, ("** sam sync message received, ignoring\n"));
98 }
99
100 /****************************************************************************
101  Process a sam sync replicate message - not sure whether to do this here or
102  somewhere else.
103 ****************************************************************************/
104
105 static void msg_sam_repl(int msg_type, pid_t pid, void *buf, size_t len)
106 {
107         uint32 low_serial;
108
109         if (len != sizeof(uint32))
110                 return;
111
112         low_serial = *((uint32 *)buf);
113
114         DEBUG(3, ("received sam replication message, serial = 0x%04x\n",
115                   low_serial));
116 }
117
118 /****************************************************************************
119  Open the socket communication - inetd.
120 ****************************************************************************/
121
122 static BOOL open_sockets_inetd(void)
123 {
124         /* Started from inetd. fd 0 is the socket. */
125         /* We will abort gracefully when the client or remote system 
126            goes away */
127         smbd_set_server_fd(dup(0));
128         
129         /* close our standard file descriptors */
130         close_low_fds(False); /* Don't close stderr */
131         
132         set_socket_options(smbd_server_fd(),"SO_KEEPALIVE");
133         set_socket_options(smbd_server_fd(), user_socket_options);
134
135         return True;
136 }
137
138 static void msg_exit_server(int msg_type, pid_t src, void *buf, size_t len)
139 {
140         exit_server("Got a SHUTDOWN message");
141 }
142
143
144 /****************************************************************************
145  Open the socket communication.
146 ****************************************************************************/
147
148 static BOOL open_sockets_smbd(BOOL is_daemon,const char *smb_ports)
149 {
150         int num_interfaces = iface_count();
151         int num_sockets = 0;
152         int fd_listenset[FD_SETSIZE];
153         fd_set listen_set;
154         int s;
155         int i;
156         char *ports;
157
158         if (!is_daemon) {
159                 return open_sockets_inetd();
160         }
161
162                 
163 #ifdef HAVE_ATEXIT
164         {
165                 static int atexit_set;
166                 if(atexit_set == 0) {
167                         atexit_set=1;
168                         atexit(killkids);
169                 }
170         }
171 #endif
172
173         /* Stop zombies */
174         CatchChild();
175                                 
176         FD_ZERO(&listen_set);
177
178         /* use a reasonable default set of ports - listing on 445 and 139 */
179         if (!smb_ports) {
180                 ports = lp_smb_ports();
181                 if (!ports || !*ports) {
182                         ports = SMB_PORTS;
183                 }
184                 ports = strdup(ports);
185         } else {
186                 ports = strdup(smb_ports);
187         }
188
189         if (lp_interfaces() && lp_bind_interfaces_only()) {
190                 /* We have been given an interfaces line, and been 
191                    told to only bind to those interfaces. Create a
192                    socket per interface and bind to only these.
193                 */
194                 
195                 /* Now open a listen socket for each of the
196                    interfaces. */
197                 for(i = 0; i < num_interfaces; i++) {
198                         struct in_addr *ifip = iface_n_ip(i);
199                         fstring tok;
200                         const char *ptr;
201
202                         if(ifip == NULL) {
203                                 DEBUG(0,("open_sockets_smbd: interface %d has NULL IP address !\n", i));
204                                 continue;
205                         }
206
207                         for (ptr=ports; next_token(&ptr, tok, NULL, sizeof(tok)); ) {
208                                 unsigned port = atoi(tok);
209                                 if (port == 0) continue;
210                                 s = fd_listenset[num_sockets] = open_socket_in(SOCK_STREAM, port, 0, ifip->s_addr, True);
211                                 if(s == -1)
212                                         return False;
213
214                                 /* ready to listen */
215                                 set_socket_options(s,"SO_KEEPALIVE"); 
216                                 set_socket_options(s,user_socket_options);
217       
218                                 if (listen(s, 5) == -1) {
219                                         DEBUG(0,("listen: %s\n",strerror(errno)));
220                                         close(s);
221                                         return False;
222                                 }
223                                 FD_SET(s,&listen_set);
224
225                                 num_sockets++;
226                                 if (num_sockets >= FD_SETSIZE) {
227                                         DEBUG(0,("open_sockets_smbd: Too many sockets to bind to\n"));
228                                         return False;
229                                 }
230                         }
231                 }
232         } else {
233                 /* Just bind to 0.0.0.0 - accept connections
234                    from anywhere. */
235
236                 fstring tok;
237                 const char *ptr;
238
239                 num_interfaces = 1;
240                 
241                 for (ptr=ports; next_token(&ptr, tok, NULL, sizeof(tok)); ) {
242                         unsigned port = atoi(tok);
243                         if (port == 0) continue;
244                         /* open an incoming socket */
245                         s = open_socket_in(SOCK_STREAM, port, 0,
246                                            interpret_addr(lp_socket_address()),True);
247                         if (s == -1)
248                                 return(False);
249                 
250                         /* ready to listen */
251                         set_socket_options(s,"SO_KEEPALIVE"); 
252                         set_socket_options(s,user_socket_options);
253                         
254                         if (listen(s, 5) == -1) {
255                                 DEBUG(0,("open_sockets_smbd: listen: %s\n",
256                                          strerror(errno)));
257                                 close(s);
258                                 return False;
259                         }
260
261                         fd_listenset[num_sockets] = s;
262                         FD_SET(s,&listen_set);
263
264                         num_sockets++;
265
266                         if (num_sockets >= FD_SETSIZE) {
267                                 DEBUG(0,("open_sockets_smbd: Too many sockets to bind to\n"));
268                                 return False;
269                         }
270                 }
271         } 
272
273         SAFE_FREE(ports);
274
275         /* Listen to messages */
276
277         message_register(MSG_SMB_SAM_SYNC, msg_sam_sync);
278         message_register(MSG_SMB_SAM_REPL, msg_sam_repl);
279         message_register(MSG_SHUTDOWN, msg_exit_server);
280
281         /* now accept incoming connections - forking a new process
282            for each incoming connection */
283         DEBUG(2,("waiting for a connection\n"));
284         while (1) {
285                 fd_set lfds;
286                 int num;
287                 
288                 /* Free up temporary memory from the main smbd. */
289                 lp_talloc_free();
290
291                 /* Ensure we respond to PING and DEBUG messages from the main smbd. */
292                 message_dispatch();
293
294                 memcpy((char *)&lfds, (char *)&listen_set, 
295                        sizeof(listen_set));
296                 
297                 num = sys_select(FD_SETSIZE,&lfds,NULL,NULL,NULL);
298                 
299                 if (num == -1 && errno == EINTR) {
300                         if (got_sig_term) {
301                                 exit_server("Caught TERM signal");
302                         }
303
304                         /* check for sighup processing */
305                         if (reload_after_sighup) {
306                                 change_to_root_user();
307                                 DEBUG(1,("Reloading services after SIGHUP\n"));
308                                 reload_services(False);
309                                 reload_after_sighup = 0;
310                         }
311
312                         continue;
313                 }
314                 
315                 /* check if we need to reload services */
316                 check_reload(time(NULL));
317
318                 /* Find the sockets that are read-ready -
319                    accept on these. */
320                 for( ; num > 0; num--) {
321                         struct sockaddr addr;
322                         socklen_t in_addrlen = sizeof(addr);
323                         
324                         s = -1;
325                         for(i = 0; i < num_sockets; i++) {
326                                 if(FD_ISSET(fd_listenset[i],&lfds)) {
327                                         s = fd_listenset[i];
328                                         /* Clear this so we don't look
329                                            at it again. */
330                                         FD_CLR(fd_listenset[i],&lfds);
331                                         break;
332                                 }
333                         }
334
335                         smbd_set_server_fd(accept(s,&addr,&in_addrlen));
336                         
337                         if (smbd_server_fd() == -1 && errno == EINTR)
338                                 continue;
339                         
340                         if (smbd_server_fd() == -1) {
341                                 DEBUG(0,("open_sockets_smbd: accept: %s\n",
342                                          strerror(errno)));
343                                 continue;
344                         }
345                         
346                         if (smbd_server_fd() != -1 && sys_fork()==0) {
347                                 /* Child code ... */
348                                 
349                                 /* close the listening socket(s) */
350                                 for(i = 0; i < num_sockets; i++)
351                                         close(fd_listenset[i]);
352                                 
353                                 /* close our standard file
354                                    descriptors */
355                                 close_low_fds(False);
356                                 am_parent = 0;
357                                 
358                                 set_socket_options(smbd_server_fd(),"SO_KEEPALIVE");
359                                 set_socket_options(smbd_server_fd(),user_socket_options);
360                                 
361                                 /* this is needed so that we get decent entries
362                                    in smbstatus for port 445 connects */
363                                 set_remote_machine_name(get_socket_addr(smbd_server_fd()));
364                                 
365                                 /* Reset global variables in util.c so
366                                    that client substitutions will be
367                                    done correctly in the process.  */
368                                 reset_globals_after_fork();
369
370                                 /* tdb needs special fork handling */
371                                 if (tdb_reopen_all() == -1) {
372                                         DEBUG(0,("tdb_reopen_all failed.\n"));
373                                         return False;
374                                 }
375
376                                 return True; 
377                         }
378                         /* The parent doesn't need this socket */
379                         close(smbd_server_fd()); 
380
381                         /* Sun May 6 18:56:14 2001 ackley@cs.unm.edu:
382                                 Clear the closed fd info out of server_fd --
383                                 and more importantly, out of client_fd in
384                                 util_sock.c, to avoid a possible
385                                 getpeername failure if we reopen the logs
386                                 and use %I in the filename.
387                         */
388
389                         smbd_set_server_fd(-1);
390
391                         /* Force parent to check log size after
392                          * spawning child.  Fix from
393                          * klausr@ITAP.Physik.Uni-Stuttgart.De.  The
394                          * parent smbd will log to logserver.smb.  It
395                          * writes only two messages for each child
396                          * started/finished. But each child writes,
397                          * say, 50 messages also in logserver.smb,
398                          * begining with the debug_count of the
399                          * parent, before the child opens its own log
400                          * file logserver.client. In a worst case
401                          * scenario the size of logserver.smb would be
402                          * checked after about 50*50=2500 messages
403                          * (ca. 100kb).
404                          * */
405                         force_check_log_size();
406  
407                 } /* end for num */
408         } /* end while 1 */
409
410 /* NOTREACHED   return True; */
411 }
412
413 /****************************************************************************
414  Reload the services file.
415 **************************************************************************/
416
417 BOOL reload_services(BOOL test)
418 {
419         BOOL ret;
420         
421         if (lp_loaded()) {
422                 pstring fname;
423                 pstrcpy(fname,lp_configfile());
424                 if (file_exist(fname, NULL) &&
425                     !strcsequal(fname, dyn_CONFIGFILE)) {
426                         pstrcpy(dyn_CONFIGFILE, fname);
427                         test = False;
428                 }
429         }
430
431         reopen_logs();
432
433         if (test && !lp_file_list_changed())
434                 return(True);
435
436         lp_killunused(conn_snum_used);
437         
438         ret = lp_load(dyn_CONFIGFILE, False, False, True);
439
440         load_printers();
441
442         /* perhaps the config filename is now set */
443         if (!test)
444                 reload_services(True);
445
446         reopen_logs();
447
448         load_interfaces();
449
450         {
451                 if (smbd_server_fd() != -1) {      
452                         set_socket_options(smbd_server_fd(),"SO_KEEPALIVE");
453                         set_socket_options(smbd_server_fd(), user_socket_options);
454                 }
455         }
456
457         mangle_reset_cache();
458         reset_stat_cache();
459
460         /* this forces service parameters to be flushed */
461         set_current_service(NULL,True);
462
463         return(ret);
464 }
465
466 #if DUMP_CORE
467 /*******************************************************************
468 prepare to dump a core file - carefully!
469 ********************************************************************/
470 static BOOL dump_core(void)
471 {
472         char *p;
473         pstring dname;
474         
475         pstrcpy(dname,lp_logfile());
476         if ((p=strrchr_m(dname,'/'))) *p=0;
477         pstrcat(dname,"/corefiles");
478         mkdir(dname,0700);
479         sys_chown(dname,getuid(),getgid());
480         chmod(dname,0700);
481         if (chdir(dname)) return(False);
482         umask(~(0700));
483
484 #ifdef HAVE_GETRLIMIT
485 #ifdef RLIMIT_CORE
486         {
487                 struct rlimit rlp;
488                 getrlimit(RLIMIT_CORE, &rlp);
489                 rlp.rlim_cur = MAX(4*1024*1024,rlp.rlim_cur);
490                 setrlimit(RLIMIT_CORE, &rlp);
491                 getrlimit(RLIMIT_CORE, &rlp);
492                 DEBUG(3,("Core limits now %d %d\n",
493                          (int)rlp.rlim_cur,(int)rlp.rlim_max));
494         }
495 #endif
496 #endif
497
498
499         DEBUG(0,("Dumping core in %s\n", dname));
500         abort();
501         return(True);
502 }
503 #endif
504
505 /****************************************************************************
506 update the current smbd process count
507 ****************************************************************************/
508
509 static void decrement_smbd_process_count(void)
510 {
511         int32 total_smbds;
512
513         if (lp_max_smbd_processes()) {
514                 total_smbds = 0;
515                 tdb_change_int32_atomic(conn_tdb_ctx(), "INFO/total_smbds", &total_smbds, -1);
516         }
517 }
518
519 /****************************************************************************
520  Exit the server.
521 ****************************************************************************/
522
523 void exit_server(char *reason)
524 {
525         static int firsttime=1;
526         extern char *last_inbuf;
527         extern struct auth_context *negprot_global_auth_context;
528
529         if (!firsttime)
530                 exit(0);
531         firsttime = 0;
532
533         change_to_root_user();
534         DEBUG(2,("Closing connections\n"));
535
536         if (negprot_global_auth_context) {
537                 (negprot_global_auth_context->free)(&negprot_global_auth_context);
538         }
539
540         conn_close_all();
541
542         invalidate_all_vuids();
543
544         print_notify_send_messages();   
545
546         /* delete our entry in the connections database. */
547         yield_connection(NULL,"");
548
549         respond_to_all_remaining_local_messages();
550         decrement_smbd_process_count();
551
552 #ifdef WITH_DFS
553         if (dcelogin_atmost_once) {
554                 dfs_unlogin();
555         }
556 #endif
557
558         if (!reason) {   
559                 int oldlevel = DEBUGLEVEL;
560                 DEBUGLEVEL = 10;
561                 DEBUG(0,("Last message was %s\n",smb_fn_name(last_message)));
562                 if (last_inbuf)
563                         show_msg(last_inbuf);
564                 DEBUGLEVEL = oldlevel;
565                 DEBUG(0,("===============================================================\n"));
566 #if DUMP_CORE
567                 if (dump_core()) return;
568 #endif
569         }    
570
571         locking_end();
572         printing_end();
573
574         DEBUG(3,("Server exit (%s)\n", (reason ? reason : "")));
575         exit(0);
576 }
577
578 /****************************************************************************
579  Initialise connect, service and file structs.
580 ****************************************************************************/
581
582 static BOOL init_structs(void )
583 {
584         /*
585          * Set the machine NETBIOS name if not already
586          * set from the config file.
587          */
588
589         if (!init_names())
590                 return False;
591
592         conn_init();
593
594         file_init();
595
596         /* for RPC pipes */
597         init_rpc_pipe_hnd();
598
599         init_dptrs();
600
601         secrets_init();
602
603         return True;
604 }
605
606 /****************************************************************************
607  main program.
608 ****************************************************************************/
609
610  int main(int argc,const char *argv[])
611 {
612         /* shall I run as a daemon */
613         static BOOL is_daemon = False;
614         static BOOL interactive = False;
615         static char *ports = NULL;
616         int opt;
617         poptContext pc;
618
619         struct poptOption long_options[] = {
620                 POPT_AUTOHELP
621         {"daemon", 'D', POPT_ARG_VAL, &is_daemon, True, "Become a daemon (default)" },
622         {"interactive", 'i', POPT_ARG_VAL, &interactive, True, "Run interactive (not a daemon)"},
623         {"build-options", 'b', POPT_ARG_NONE, NULL, 'b', "Print build options" },
624         {"port", 'p', POPT_ARG_STRING, &ports, 0, "Listen on the specified ports"},
625         {NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_debug},
626         {NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_configfile},
627         {NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_socket_options},
628         {NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_log_base},
629         {NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_version},
630         { NULL }
631         };
632
633 #ifdef HAVE_SET_AUTH_PARAMETERS
634         set_auth_parameters(argc,argv);
635 #endif
636
637         pc = poptGetContext("smbd", argc, argv, long_options, 0);
638         
639         while((opt = poptGetNextOpt(pc)) != -1) {
640                 switch (opt)  {
641                 case 'b':
642                         build_options(True); /* Display output to screen as well as debug */ 
643                         exit(0);
644                         break;
645                 }
646         }
647
648         poptFreeContext(pc);
649
650 #ifdef HAVE_SETLUID
651         /* needed for SecureWare on SCO */
652         setluid(0);
653 #endif
654
655         sec_init();
656
657         load_case_tables();
658
659         set_remote_machine_name("smbd");
660
661         setup_logging(argv[0],interactive);
662
663         /* we want to re-seed early to prevent time delays causing
664            client problems at a later date. (tridge) */
665         generate_random_buffer(NULL, 0, False);
666
667         /* make absolutely sure we run as root - to handle cases where people
668            are crazy enough to have it setuid */
669
670         gain_root_privilege();
671         gain_root_group_privilege();
672
673         fault_setup((void (*)(void *))exit_server);
674         CatchSignal(SIGTERM , SIGNAL_CAST sig_term);
675         CatchSignal(SIGHUP,SIGNAL_CAST sig_hup);
676         
677         /* we are never interested in SIGPIPE */
678         BlockSignals(True,SIGPIPE);
679
680 #if defined(SIGFPE)
681         /* we are never interested in SIGFPE */
682         BlockSignals(True,SIGFPE);
683 #endif
684
685 #if defined(SIGUSR2)
686         /* We are no longer interested in USR2 */
687         BlockSignals(True,SIGUSR2);
688 #endif
689
690         /* POSIX demands that signals are inherited. If the invoking process has
691          * these signals masked, we will have problems, as we won't recieve them. */
692         BlockSignals(False, SIGHUP);
693         BlockSignals(False, SIGUSR1);
694         BlockSignals(False, SIGTERM);
695
696         /* we want total control over the permissions on created files,
697            so set our umask to 0 */
698         umask(0);
699
700         init_sec_ctx();
701
702         reopen_logs();
703
704         DEBUG(0,( "smbd version %s started.\n", VERSION));
705         DEBUGADD(0,( "Copyright Andrew Tridgell and the Samba Team 1992-2002\n"));
706
707         DEBUG(2,("uid=%d gid=%d euid=%d egid=%d\n",
708                  (int)getuid(),(int)getgid(),(int)geteuid(),(int)getegid()));
709
710         /* Output the build options to the debug log */ 
711         build_options(False);
712
713         if (sizeof(uint16) < 2 || sizeof(uint32) < 4) {
714                 DEBUG(0,("ERROR: Samba is not configured correctly for the word size on your machine\n"));
715                 exit(1);
716         }
717
718         /*
719          * Do this before reload_services.
720          */
721
722         if (!reload_services(False))
723                 return(-1);     
724
725         init_structs();
726
727 #ifdef WITH_PROFILE
728         if (!profile_setup(False)) {
729                 DEBUG(0,("ERROR: failed to setup profiling\n"));
730                 return -1;
731         }
732 #endif
733
734         DEBUG(3,( "loaded services\n"));
735
736         if (!is_daemon && !is_a_socket(0)) {
737                 if (!interactive)
738                         DEBUG(0,("standard input is not a socket, assuming -D option\n"));
739
740                 /*
741                  * Setting is_daemon here prevents us from eventually calling
742                  * the open_sockets_inetd()
743                  */
744
745                 is_daemon = True;
746         }
747
748         if (is_daemon && !interactive) {
749                 DEBUG( 3, ( "Becoming a daemon.\n" ) );
750                 become_daemon();
751         }
752
753 #if HAVE_SETPGID
754         /*
755          * If we're interactive we want to set our own process group for
756          * signal management.
757          */
758         if (interactive)
759                 setpgid( (pid_t)0, (pid_t)0);
760 #endif
761
762         if (!directory_exist(lp_lockdir(), NULL)) {
763                 mkdir(lp_lockdir(), 0755);
764         }
765
766         if (is_daemon) {
767                 pidfile_create("smbd");
768         }
769
770         if (!message_init()) {
771                 exit(1);
772         }
773         register_msg_pool_usage();
774         register_dmalloc_msgs();
775
776         if (!print_backend_init())
777                 exit(1);
778
779         /* Setup the main smbd so that we can get messages. */
780         claim_connection(NULL,"",0,True,FLAG_MSG_GENERAL|FLAG_MSG_SMBD);
781
782         /* 
783            DO NOT ENABLE THIS TILL YOU COPE WITH KILLING THESE TASKS AND INETD
784            THIS *killed* LOTS OF BUILD FARM MACHINES. IT CREATED HUNDREDS OF 
785            smbd PROCESSES THAT NEVER DIE
786            start_background_queue(); 
787         */
788
789         if (!open_sockets_smbd(is_daemon,ports))
790                 exit(1);
791
792         /*
793          * everything after this point is run after the fork()
794          */ 
795
796         namecache_enable();
797
798         if (!locking_init(0))
799                 exit(1);
800
801         if (!share_info_db_init())
802                 exit(1);
803
804         if (!init_registry())
805                 exit(1);
806
807         if(!initialize_password_db(False))
808                 exit(1);
809
810         uni_group_cache_init(); /* Non-critical */
811         
812         /* possibly reload the services file. */
813         reload_services(True);
814
815         if(!get_global_sam_sid()) {
816                 DEBUG(0,("ERROR: Samba cannot create a SAM SID.\n"));
817                 exit(1);
818         }
819
820         if (!init_account_policy()) {
821                 DEBUG(0,("Could not open account policy tdb.\n"));
822                 exit(1);
823         }
824
825         if (*lp_rootdir()) {
826                 if (sys_chroot(lp_rootdir()) == 0)
827                         DEBUG(2,("Changed root to %s\n", lp_rootdir()));
828         }
829
830         /* Setup oplocks */
831         if (!init_oplocks())
832                 exit(1);
833         
834         /* Setup change notify */
835         if (!init_change_notify())
836                 exit(1);
837
838         /* re-initialise the timezone */
839         TimeInit();
840
841         /* register our message handlers */
842         message_register(MSG_SMB_FORCE_TDIS, msg_force_tdis);
843         talloc_init_named("dummy!");
844
845         smbd_process();
846         
847         uni_group_cache_shutdown();
848         exit_server("normal exit");
849         return(0);
850 }