Store some path names in global variables initialized to configure
[tprouty/samba.git] / source / 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 pstring debugf;
25 extern fstring global_myworkgroup;
26 extern pstring global_myname;
27
28 int am_parent = 1;
29
30 /* the last message the was processed */
31 int last_message = -1;
32
33 /* a useful macro to debug the last message processed */
34 #define LAST_MESSAGE() smb_fn_name(last_message)
35
36 extern pstring user_socket_options;
37
38 #ifdef WITH_DFS
39 extern int dcelogin_atmost_once;
40 #endif /* WITH_DFS */
41
42 extern fstring remote_machine;
43
44 /* really we should have a top level context structure that has the
45    client file descriptor as an element. That would require a major rewrite :(
46
47    the following 2 functions are an alternative - they make the file
48    descriptor private to smbd
49  */
50 static int server_fd = -1;
51
52 int smbd_server_fd(void)
53 {
54         return server_fd;
55 }
56
57 void smbd_set_server_fd(int fd)
58 {
59         server_fd = fd;
60         client_setfd(fd);
61 }
62
63 /****************************************************************************
64   when exiting, take the whole family
65 ****************************************************************************/
66 static void *dflt_sig(void)
67 {
68         exit_server("caught signal");
69         return NULL;
70 }
71
72 /****************************************************************************
73   Send a SIGTERM to our process group.
74 *****************************************************************************/
75 static void  killkids(void)
76 {
77         if(am_parent) kill(0,SIGTERM);
78 }
79
80 /****************************************************************************
81   process a sam sync message - not sure whether to do this here or
82   somewhere else
83 ****************************************************************************/
84 static void msg_sam_sync(int msg_type, pid_t pid, void *buf, size_t 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,debugf);
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         int total_smbds;
465
466         if (lp_max_smbd_processes()) {
467                 total_smbds = 0;
468                 tdb_change_int_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
480
481         if (!firsttime)
482                 exit(0);
483         firsttime = 0;
484
485         change_to_root_user();
486         DEBUG(2,("Closing connections\n"));
487
488         conn_close_all();
489
490         invalidate_all_vuids();
491
492         /* delete our entry in the connections database. */
493         yield_connection(NULL,"",MAXSTATUS);
494
495         respond_to_all_remaining_local_messages();
496         decrement_smbd_process_count();
497
498 #ifdef WITH_DFS
499         if (dcelogin_atmost_once) {
500                 dfs_unlogin();
501         }
502 #endif
503
504         if (!reason) {   
505                 int oldlevel = DEBUGLEVEL;
506                 DEBUGLEVEL = 10;
507                 DEBUG(0,("Last message was %s\n",smb_fn_name(last_message)));
508                 if (last_inbuf)
509                         show_msg(last_inbuf);
510                 DEBUGLEVEL = oldlevel;
511                 DEBUG(0,("===============================================================\n"));
512 #if DUMP_CORE
513                 if (dump_core()) return;
514 #endif
515         }    
516
517         locking_end();
518
519         DEBUG(3,("Server exit (%s)\n", (reason ? reason : "")));
520         exit(0);
521 }
522
523 /****************************************************************************
524   initialise connect, service and file structs
525 ****************************************************************************/
526 static void init_structs(void )
527 {
528         /*
529          * Set the machine NETBIOS name if not already
530          * set from the config file.
531          */
532
533         if (!*global_myname) {
534                 char *p;
535                 fstrcpy( global_myname, myhostname() );
536                 p = strchr_m( global_myname, '.' );
537                 if (p) 
538                         *p = 0;
539         }
540
541         strupper( global_myname );
542
543         conn_init();
544
545         file_init();
546
547         /* for RPC pipes */
548         init_rpc_pipe_hnd();
549
550         init_dptrs();
551
552         secrets_init();
553 }
554
555 /****************************************************************************
556 usage on the program
557 ****************************************************************************/
558 static void usage(char *pname)
559 {
560
561         d_printf("Usage: %s [-DaoPh?Vb] [-d debuglevel] [-l log basename] [-p port]\n", pname);
562         d_printf("       [-O socket options] [-s services file]\n");
563         d_printf("\t-D                    Become a daemon\n");
564         d_printf("\t-a                    Append to log file (default)\n");
565         d_printf("\t-o                    Overwrite log file, don't append\n");
566         d_printf("\t-h                    Print usage\n");
567         d_printf("\t-?                    Print usage\n");
568         d_printf("\t-V                    Print version\n");
569         d_printf("\t-b                    Print build options\n");
570         d_printf("\t-d debuglevel         Set the debuglevel\n");
571         d_printf("\t-l log basename.      Basename for log/debug files\n");
572         d_printf("\t-p port               Listen on the specified port\n");
573         d_printf("\t-O socket options     Socket options\n");
574         d_printf("\t-s services file.     Filename of services file\n");
575         d_printf("\n");
576 }
577
578 /****************************************************************************
579   main program
580 ****************************************************************************/
581  int main(int argc,char *argv[])
582 {
583         extern BOOL append_log;
584         /* shall I run as a daemon */
585         BOOL is_daemon = False;
586         BOOL specified_logfile = False;
587         int port = SMB_PORT;
588         int opt;
589         extern char *optarg;
590
591 #ifdef HAVE_SET_AUTH_PARAMETERS
592         set_auth_parameters(argc,argv);
593 #endif
594
595         /* this is for people who can't start the program correctly */
596         while (argc > 1 && (*argv[1] != '-')) {
597                 argv++;
598                 argc--;
599         }
600
601         while ( EOF != (opt = getopt(argc, argv, "O:l:s:d:Dp:h?bVaof:")) )
602                 switch (opt)  {
603                 case 'O':
604                         pstrcpy(user_socket_options,optarg);
605                         break;
606
607                 case 's':
608                         pstrcpy(dyn_CONFIGFILE,optarg);
609                         break;
610
611                 case 'l':
612                         specified_logfile = True;
613                         slprintf(debugf, sizeof(debugf)-1, "%s/log.smbd", optarg);
614                         break;
615
616                 case 'a':
617                         append_log = True;
618                         break;
619
620                 case 'o':
621                         append_log = False;
622                         break;
623
624                 case 'D':
625                         is_daemon = True;
626                         break;
627
628                 case 'd':
629                         if (*optarg == 'A')
630                                 DEBUGLEVEL = 10000;
631                         else
632                                 DEBUGLEVEL = atoi(optarg);
633                         break;
634
635                 case 'p':
636                         port = atoi(optarg);
637                         break;
638
639                 case 'h':
640                 case '?':
641                         usage(argv[0]);
642                         exit(0);
643                         break;
644
645                 case 'V':
646                         d_printf("Version %s\n",VERSION);
647                         exit(0);
648                         break;
649                 case 'b':
650                         build_options(True); /* Display output to screen as well as debug */ 
651                         exit(0);
652                         break;
653                 default:
654                         DEBUG(0,("Incorrect program usage - are you sure the command line is correct?\n"));
655                         usage(argv[0]);
656                         exit(1);
657                 }
658
659 #ifdef HAVE_SETLUID
660         /* needed for SecureWare on SCO */
661         setluid(0);
662 #endif
663
664         sec_init();
665
666         load_case_tables();
667
668         append_log = True;
669
670         TimeInit();
671
672         if(!specified_logfile) {
673                 slprintf(debugf, sizeof(debugf)-1, "%s/log.smbd",
674                          dyn_LOGFILEBASE);
675         }
676
677         pstrcpy(remote_machine, "smbd");
678
679         setup_logging(argv[0],False);
680
681         /* we want to re-seed early to prevent time delays causing
682            client problems at a later date. (tridge) */
683         generate_random_buffer(NULL, 0, False);
684
685         /* make absolutely sure we run as root - to handle cases where people
686            are crazy enough to have it setuid */
687
688         gain_root_privilege();
689         gain_root_group_privilege();
690
691         fault_setup((void (*)(void *))exit_server);
692         CatchSignal(SIGTERM , SIGNAL_CAST dflt_sig);
693
694         /* we are never interested in SIGPIPE */
695         BlockSignals(True,SIGPIPE);
696
697 #if defined(SIGFPE)
698         /* we are never interested in SIGFPE */
699         BlockSignals(True,SIGFPE);
700 #endif
701
702 #if defined(SIGUSR2)
703         /* We are no longer interested in USR2 */
704         BlockSignals(True,SIGUSR2);
705 #endif
706
707         /* POSIX demands that signals are inherited. If the invoking process has
708          * these signals masked, we will have problems, as we won't recieve them. */
709         BlockSignals(False, SIGHUP);
710         BlockSignals(False, SIGUSR1);
711
712         /* we want total control over the permissions on created files,
713            so set our umask to 0 */
714         umask(0);
715
716         init_sec_ctx();
717
718         reopen_logs();
719
720         DEBUG(1,( "smbd version %s started.\n", VERSION));
721         DEBUGADD(1,( "Copyright Andrew Tridgell 1992-1998\n"));
722
723         DEBUG(2,("uid=%d gid=%d euid=%d egid=%d\n",
724                  (int)getuid(),(int)getgid(),(int)geteuid(),(int)getegid()));
725
726         /* Output the build options to the debug log */ 
727         build_options(False);
728
729         if (sizeof(uint16) < 2 || sizeof(uint32) < 4) {
730                 DEBUG(0,("ERROR: Samba is not configured correctly for the word size on your machine\n"));
731                 exit(1);
732         }
733
734         /*
735          * Do this before reload_services.
736          */
737
738         if (!reload_services(False))
739                 return(-1);     
740
741         init_structs();
742
743         /* don't call winbind for our domain if we are the DC */
744         if (lp_domain_logons()) {
745                 winbind_exclude_domain(lp_workgroup());
746         }
747         
748 #ifdef WITH_PROFILE
749         if (!profile_setup(False)) {
750                 DEBUG(0,("ERROR: failed to setup profiling\n"));
751                 return -1;
752         }
753 #endif
754
755 #ifdef WITH_SSL
756         {
757                 extern BOOL sslEnabled;
758                 sslEnabled = lp_ssl_enabled();
759                 if(sslEnabled)
760                         sslutil_init(True);
761         }
762 #endif        /* WITH_SSL */
763
764         fstrcpy(global_myworkgroup, lp_workgroup());
765
766         CatchSignal(SIGHUP,SIGNAL_CAST sig_hup);
767         
768         DEBUG(3,( "loaded services\n"));
769
770         if (!is_daemon && !is_a_socket(0)) {
771                 DEBUG(0,("standard input is not a socket, assuming -D option\n"));
772                 is_daemon = True;
773         }
774
775         if (is_daemon) {
776                 DEBUG( 3, ( "Becoming a daemon.\n" ) );
777                 become_daemon();
778         }
779
780         if (!directory_exist(lp_lockdir(), NULL)) {
781                 mkdir(lp_lockdir(), 0755);
782         }
783
784         if (is_daemon) {
785                 pidfile_create("smbd");
786         }
787
788         if (!message_init()) {
789                 exit(1);
790         }
791
792         /* Setup the main smbd so that we can get messages. */
793         claim_connection(NULL,"",MAXSTATUS,True);
794
795         /* 
796            DO NOT ENABLE THIS TILL YOU COPE WITH KILLING THESE TASKS AND INETD
797            THIS *killed* LOTS OF BUILD FARM MACHINES. IT CREATED HUNDREDS OF 
798            smbd PROCESSES THAT NEVER DIE
799            start_background_queue(); 
800         */
801
802         if (!open_sockets(is_daemon,port))
803                 exit(1);
804
805         /*
806          * everything after this point is run after the fork()
807          */ 
808
809         if (!locking_init(0)) {
810                 exit(1);
811         }
812
813         if (!print_backend_init()) {
814                 exit(1);
815         }
816
817         if (!share_info_db_init()) {
818                 exit(1);
819         }
820
821         if(!initialize_password_db(False)) {
822                 exit(1);
823         }
824
825         /* possibly reload the services file. */
826         reload_services(True);
827
828         if (init_group_mapping()==False) {
829                 printf("Could not open tdb mapping file.\n");
830                 return 0;
831         }
832
833         if(!pdb_generate_sam_sid()) {
834                 DEBUG(0,("ERROR: Samba cannot create a SAM SID.\n"));
835                 exit(1);
836         }
837
838         if (*lp_rootdir()) {
839                 if (sys_chroot(lp_rootdir()) == 0)
840                         DEBUG(2,("Changed root to %s\n", lp_rootdir()));
841         }
842
843         /* Setup oplocks */
844         if (!init_oplocks()) {
845                 exit(1);
846         }
847         
848         /* Setup mangle */
849         if (!init_mangle_tdb()) {
850                 exit(1);
851         }
852
853         /* Setup change notify */
854         if (!init_change_notify()) {
855                 exit(1);
856         }
857
858         smbd_process();
859         
860         exit_server("normal exit");
861         return(0);
862 }