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