r4348: syncing up for 3.0.11pre1
[Samba.git] / source / smbd / server.c
blob724a49321a27bf5b544e939b3566577887ff2bd2
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-2003
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.
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.
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.
23 #include "includes.h"
25 static int am_parent = 1;
27 /* the last message the was processed */
28 int last_message = -1;
30 /* a useful macro to debug the last message processed */
31 #define LAST_MESSAGE() smb_fn_name(last_message)
33 extern pstring user_socket_options;
34 extern SIG_ATOMIC_T got_sig_term;
35 extern SIG_ATOMIC_T reload_after_sighup;
37 #ifdef WITH_DFS
38 extern int dcelogin_atmost_once;
39 #endif /* WITH_DFS */
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 :(
44 the following 2 functions are an alternative - they make the file
45 descriptor private to smbd
47 static int server_fd = -1;
49 int smbd_server_fd(void)
51 return server_fd;
54 static void smbd_set_server_fd(int fd)
56 server_fd = fd;
57 client_setfd(fd);
60 /****************************************************************************
61 Terminate signal.
62 ****************************************************************************/
64 static void sig_term(void)
66 got_sig_term = 1;
67 sys_select_signal();
70 /****************************************************************************
71 Catch a sighup.
72 ****************************************************************************/
74 static void sig_hup(int sig)
76 reload_after_sighup = 1;
77 sys_select_signal();
80 /****************************************************************************
81 Send a SIGTERM to our process group.
82 *****************************************************************************/
84 static void killkids(void)
86 if(am_parent) kill(0,SIGTERM);
89 /****************************************************************************
90 Process a sam sync message - not sure whether to do this here or
91 somewhere else.
92 ****************************************************************************/
94 static void msg_sam_sync(int UNUSED(msg_type), pid_t UNUSED(pid),
95 void *UNUSED(buf), size_t UNUSED(len))
97 DEBUG(10, ("** sam sync message received, ignoring\n"));
100 /****************************************************************************
101 Process a sam sync replicate message - not sure whether to do this here or
102 somewhere else.
103 ****************************************************************************/
105 static void msg_sam_repl(int msg_type, pid_t pid, void *buf, size_t len)
107 uint32 low_serial;
109 if (len != sizeof(uint32))
110 return;
112 low_serial = *((uint32 *)buf);
114 DEBUG(3, ("received sam replication message, serial = 0x%04x\n",
115 low_serial));
118 /****************************************************************************
119 Open the socket communication - inetd.
120 ****************************************************************************/
122 static BOOL open_sockets_inetd(void)
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));
129 /* close our standard file descriptors */
130 close_low_fds(False); /* Don't close stderr */
132 set_socket_options(smbd_server_fd(),"SO_KEEPALIVE");
133 set_socket_options(smbd_server_fd(), user_socket_options);
135 return True;
138 static void msg_exit_server(int msg_type, pid_t src, void *buf, size_t len)
140 exit_server("Got a SHUTDOWN message");
144 /****************************************************************************
145 Have we reached the process limit ?
146 ****************************************************************************/
148 static BOOL allowable_number_of_smbd_processes(void)
150 int max_processes = lp_max_smbd_processes();
152 if (!max_processes)
153 return True;
156 TDB_CONTEXT *tdb = conn_tdb_ctx();
157 int32 val;
158 if (!tdb) {
159 DEBUG(0,("allowable_number_of_smbd_processes: can't open connection tdb.\n" ));
160 return False;
163 val = tdb_fetch_int32(tdb, "INFO/total_smbds");
164 if (val == -1 && (tdb_error(tdb) != TDB_ERR_NOEXIST)) {
165 DEBUG(0,("allowable_number_of_smbd_processes: can't fetch INFO/total_smbds. Error %s\n",
166 tdb_errorstr(tdb) ));
167 return False;
169 if (val > max_processes) {
170 DEBUG(0,("allowable_number_of_smbd_processes: number of processes (%d) is over allowed limit (%d)\n",
171 val, max_processes ));
172 return False;
175 return True;
178 /****************************************************************************
179 Open the socket communication.
180 ****************************************************************************/
182 static BOOL open_sockets_smbd(BOOL is_daemon, BOOL interactive, const char *smb_ports)
184 int num_interfaces = iface_count();
185 int num_sockets = 0;
186 int fd_listenset[FD_SETSIZE];
187 fd_set listen_set;
188 int s;
189 int maxfd = 0;
190 int i;
191 char *ports;
193 if (!is_daemon) {
194 return open_sockets_inetd();
198 #ifdef HAVE_ATEXIT
200 static int atexit_set;
201 if(atexit_set == 0) {
202 atexit_set=1;
203 atexit(killkids);
206 #endif
208 /* Stop zombies */
209 CatchChild();
211 FD_ZERO(&listen_set);
213 /* use a reasonable default set of ports - listing on 445 and 139 */
214 if (!smb_ports) {
215 ports = lp_smb_ports();
216 if (!ports || !*ports) {
217 ports = smb_xstrdup(SMB_PORTS);
218 } else {
219 ports = smb_xstrdup(ports);
221 } else {
222 ports = smb_xstrdup(smb_ports);
225 if (lp_interfaces() && lp_bind_interfaces_only()) {
226 /* We have been given an interfaces line, and been
227 told to only bind to those interfaces. Create a
228 socket per interface and bind to only these.
231 /* Now open a listen socket for each of the
232 interfaces. */
233 for(i = 0; i < num_interfaces; i++) {
234 struct in_addr *ifip = iface_n_ip(i);
235 fstring tok;
236 const char *ptr;
238 if(ifip == NULL) {
239 DEBUG(0,("open_sockets_smbd: interface %d has NULL IP address !\n", i));
240 continue;
243 for (ptr=ports; next_token(&ptr, tok, NULL, sizeof(tok)); ) {
244 unsigned port = atoi(tok);
245 if (port == 0) {
246 continue;
248 s = fd_listenset[num_sockets] = open_socket_in(SOCK_STREAM, port, 0, ifip->s_addr, True);
249 if(s == -1)
250 return False;
252 /* ready to listen */
253 set_socket_options(s,"SO_KEEPALIVE");
254 set_socket_options(s,user_socket_options);
256 /* Set server socket to non-blocking for the accept. */
257 set_blocking(s,False);
259 if (listen(s, SMBD_LISTEN_BACKLOG) == -1) {
260 DEBUG(0,("listen: %s\n",strerror(errno)));
261 close(s);
262 return False;
264 FD_SET(s,&listen_set);
265 maxfd = MAX( maxfd, s);
267 num_sockets++;
268 if (num_sockets >= FD_SETSIZE) {
269 DEBUG(0,("open_sockets_smbd: Too many sockets to bind to\n"));
270 return False;
274 } else {
275 /* Just bind to 0.0.0.0 - accept connections
276 from anywhere. */
278 fstring tok;
279 const char *ptr;
281 num_interfaces = 1;
283 for (ptr=ports; next_token(&ptr, tok, NULL, sizeof(tok)); ) {
284 unsigned port = atoi(tok);
285 if (port == 0) continue;
286 /* open an incoming socket */
287 s = open_socket_in(SOCK_STREAM, port, 0,
288 interpret_addr(lp_socket_address()),True);
289 if (s == -1)
290 return(False);
292 /* ready to listen */
293 set_socket_options(s,"SO_KEEPALIVE");
294 set_socket_options(s,user_socket_options);
296 /* Set server socket to non-blocking for the accept. */
297 set_blocking(s,False);
299 if (listen(s, SMBD_LISTEN_BACKLOG) == -1) {
300 DEBUG(0,("open_sockets_smbd: listen: %s\n",
301 strerror(errno)));
302 close(s);
303 return False;
306 fd_listenset[num_sockets] = s;
307 FD_SET(s,&listen_set);
308 maxfd = MAX( maxfd, s);
310 num_sockets++;
312 if (num_sockets >= FD_SETSIZE) {
313 DEBUG(0,("open_sockets_smbd: Too many sockets to bind to\n"));
314 return False;
319 SAFE_FREE(ports);
321 /* Listen to messages */
323 message_register(MSG_SMB_SAM_SYNC, msg_sam_sync);
324 message_register(MSG_SMB_SAM_REPL, msg_sam_repl);
325 message_register(MSG_SHUTDOWN, msg_exit_server);
327 /* now accept incoming connections - forking a new process
328 for each incoming connection */
329 DEBUG(2,("waiting for a connection\n"));
330 while (1) {
331 fd_set lfds;
332 int num;
334 /* Free up temporary memory from the main smbd. */
335 lp_talloc_free();
337 /* Ensure we respond to PING and DEBUG messages from the main smbd. */
338 message_dispatch();
340 memcpy((char *)&lfds, (char *)&listen_set,
341 sizeof(listen_set));
343 num = sys_select(maxfd+1,&lfds,NULL,NULL,NULL);
345 if (num == -1 && errno == EINTR) {
346 if (got_sig_term) {
347 exit_server("Caught TERM signal");
350 /* check for sighup processing */
351 if (reload_after_sighup) {
352 change_to_root_user();
353 DEBUG(1,("Reloading services after SIGHUP\n"));
354 reload_services(False);
355 reload_after_sighup = 0;
358 continue;
361 /* check if we need to reload services */
362 check_reload(time(NULL));
364 /* Find the sockets that are read-ready -
365 accept on these. */
366 for( ; num > 0; num--) {
367 struct sockaddr addr;
368 socklen_t in_addrlen = sizeof(addr);
370 s = -1;
371 for(i = 0; i < num_sockets; i++) {
372 if(FD_ISSET(fd_listenset[i],&lfds)) {
373 s = fd_listenset[i];
374 /* Clear this so we don't look
375 at it again. */
376 FD_CLR(fd_listenset[i],&lfds);
377 break;
381 smbd_set_server_fd(accept(s,&addr,&in_addrlen));
383 if (smbd_server_fd() == -1 && errno == EINTR)
384 continue;
386 if (smbd_server_fd() == -1) {
387 DEBUG(0,("open_sockets_smbd: accept: %s\n",
388 strerror(errno)));
389 continue;
392 /* Ensure child is set to blocking mode */
393 set_blocking(smbd_server_fd(),True);
395 if (smbd_server_fd() != -1 && interactive)
396 return True;
398 if (allowable_number_of_smbd_processes() && smbd_server_fd() != -1 && sys_fork()==0) {
399 /* Child code ... */
401 /* close the listening socket(s) */
402 for(i = 0; i < num_sockets; i++)
403 close(fd_listenset[i]);
405 /* close our standard file
406 descriptors */
407 close_low_fds(False);
408 am_parent = 0;
410 set_socket_options(smbd_server_fd(),"SO_KEEPALIVE");
411 set_socket_options(smbd_server_fd(),user_socket_options);
413 /* this is needed so that we get decent entries
414 in smbstatus for port 445 connects */
415 set_remote_machine_name(get_peer_addr(smbd_server_fd()), False);
417 /* Reset the state of the random
418 * number generation system, so
419 * children do not get the same random
420 * numbers as each other */
422 set_need_random_reseed();
423 /* tdb needs special fork handling - remove CLEAR_IF_FIRST flags */
424 if (tdb_reopen_all() == -1) {
425 DEBUG(0,("tdb_reopen_all failed.\n"));
426 smb_panic("tdb_reopen_all failed.");
429 return True;
431 /* The parent doesn't need this socket */
432 close(smbd_server_fd());
434 /* Sun May 6 18:56:14 2001 ackley@cs.unm.edu:
435 Clear the closed fd info out of server_fd --
436 and more importantly, out of client_fd in
437 util_sock.c, to avoid a possible
438 getpeername failure if we reopen the logs
439 and use %I in the filename.
442 smbd_set_server_fd(-1);
444 /* Force parent to check log size after
445 * spawning child. Fix from
446 * klausr@ITAP.Physik.Uni-Stuttgart.De. The
447 * parent smbd will log to logserver.smb. It
448 * writes only two messages for each child
449 * started/finished. But each child writes,
450 * say, 50 messages also in logserver.smb,
451 * begining with the debug_count of the
452 * parent, before the child opens its own log
453 * file logserver.client. In a worst case
454 * scenario the size of logserver.smb would be
455 * checked after about 50*50=2500 messages
456 * (ca. 100kb).
457 * */
458 force_check_log_size();
460 } /* end for num */
461 } /* end while 1 */
463 /* NOTREACHED return True; */
466 /****************************************************************************
467 Reload the services file.
468 **************************************************************************/
470 BOOL reload_services(BOOL test)
472 BOOL ret;
474 if (lp_loaded()) {
475 pstring fname;
476 pstrcpy(fname,lp_configfile());
477 if (file_exist(fname, NULL) &&
478 !strcsequal(fname, dyn_CONFIGFILE)) {
479 pstrcpy(dyn_CONFIGFILE, fname);
480 test = False;
484 reopen_logs();
486 if (test && !lp_file_list_changed())
487 return(True);
489 lp_killunused(conn_snum_used);
491 ret = lp_load(dyn_CONFIGFILE, False, False, True);
493 remove_stale_printers();
494 load_printers();
496 /* perhaps the config filename is now set */
497 if (!test)
498 reload_services(True);
500 reopen_logs();
502 load_interfaces();
504 if (smbd_server_fd() != -1) {
505 set_socket_options(smbd_server_fd(),"SO_KEEPALIVE");
506 set_socket_options(smbd_server_fd(), user_socket_options);
509 mangle_reset_cache();
510 reset_stat_cache();
512 /* this forces service parameters to be flushed */
513 set_current_service(NULL,0,True);
515 return(ret);
519 #if DUMP_CORE
520 /*******************************************************************
521 prepare to dump a core file - carefully!
522 ********************************************************************/
523 static BOOL dump_core(void)
525 char *p;
526 pstring dname;
528 pstrcpy(dname,lp_logfile());
529 if ((p=strrchr_m(dname,'/'))) *p=0;
530 pstrcat(dname,"/corefiles");
531 mkdir(dname,0700);
532 sys_chown(dname,getuid(),getgid());
533 chmod(dname,0700);
534 if (chdir(dname)) return(False);
535 umask(~(0700));
537 #ifdef HAVE_GETRLIMIT
538 #ifdef RLIMIT_CORE
540 struct rlimit rlp;
541 getrlimit(RLIMIT_CORE, &rlp);
542 rlp.rlim_cur = MAX(4*1024*1024,rlp.rlim_cur);
543 setrlimit(RLIMIT_CORE, &rlp);
544 getrlimit(RLIMIT_CORE, &rlp);
545 DEBUG(3,("Core limits now %d %d\n",
546 (int)rlp.rlim_cur,(int)rlp.rlim_max));
548 #endif
549 #endif
552 DEBUG(0,("Dumping core in %s\n", dname));
553 /* Ensure we don't have a signal handler for abort. */
554 #ifdef SIGABRT
555 CatchSignal(SIGABRT,SIGNAL_CAST SIG_DFL);
556 #endif
557 abort();
558 return(True);
560 #endif
562 /****************************************************************************
563 Exit the server.
564 ****************************************************************************/
566 void exit_server(const char *reason)
568 static int firsttime=1;
569 extern char *last_inbuf;
570 extern struct auth_context *negprot_global_auth_context;
572 if (!firsttime)
573 exit(0);
574 firsttime = 0;
576 change_to_root_user();
577 DEBUG(2,("Closing connections\n"));
579 if (negprot_global_auth_context) {
580 (negprot_global_auth_context->free)(&negprot_global_auth_context);
583 conn_close_all();
585 invalidate_all_vuids();
587 print_notify_send_messages(3); /* 3 second timeout. */
589 /* run all registered exit events */
590 smb_run_exit_events();
592 /* delete our entry in the connections database. */
593 yield_connection(NULL,"");
595 respond_to_all_remaining_local_messages();
596 decrement_smbd_process_count();
598 #ifdef WITH_DFS
599 if (dcelogin_atmost_once) {
600 dfs_unlogin();
602 #endif
604 if (!reason) {
605 int oldlevel = DEBUGLEVEL;
606 DEBUGLEVEL = 10;
607 DEBUG(0,("Last message was %s\n",smb_fn_name(last_message)));
608 if (last_inbuf)
609 show_msg(last_inbuf);
610 DEBUGLEVEL = oldlevel;
611 DEBUG(0,("===============================================================\n"));
612 #if DUMP_CORE
613 if (dump_core()) return;
614 #endif
617 locking_end();
618 printing_end();
620 DEBUG(3,("Server exit (%s)\n", (reason ? reason : "")));
621 exit(0);
624 /****************************************************************************
625 Initialise connect, service and file structs.
626 ****************************************************************************/
628 static BOOL init_structs(void )
631 * Set the machine NETBIOS name if not already
632 * set from the config file.
635 if (!init_names())
636 return False;
638 conn_init();
640 file_init();
642 /* for RPC pipes */
643 init_rpc_pipe_hnd();
645 init_dptrs();
647 secrets_init();
649 return True;
652 /****************************************************************************
653 main program.
654 ****************************************************************************/
656 /* Declare prototype for build_options() to avoid having to run it through
657 mkproto.h. Mixing $(builddir) and $(srcdir) source files in the current
658 prototype generation system is too complicated. */
660 void build_options(BOOL screen);
662 int main(int argc,const char *argv[])
664 /* shall I run as a daemon */
665 static BOOL is_daemon = False;
666 static BOOL interactive = False;
667 static BOOL Fork = True;
668 static BOOL log_stdout = False;
669 static char *ports = NULL;
670 int opt;
671 poptContext pc;
673 struct poptOption long_options[] = {
674 POPT_AUTOHELP
675 {"daemon", 'D', POPT_ARG_VAL, &is_daemon, True, "Become a daemon (default)" },
676 {"interactive", 'i', POPT_ARG_VAL, &interactive, True, "Run interactive (not a daemon)"},
677 {"foreground", 'F', POPT_ARG_VAL, &Fork, False, "Run daemon in foreground (for daemontools & etc)" },
678 {"log-stdout", 'S', POPT_ARG_VAL, &log_stdout, True, "Log to stdout" },
679 {"build-options", 'b', POPT_ARG_NONE, NULL, 'b', "Print build options" },
680 {"port", 'p', POPT_ARG_STRING, &ports, 0, "Listen on the specified ports"},
681 POPT_COMMON_SAMBA
682 { NULL }
685 #ifdef HAVE_SET_AUTH_PARAMETERS
686 set_auth_parameters(argc,argv);
687 #endif
689 pc = poptGetContext("smbd", argc, argv, long_options, 0);
691 while((opt = poptGetNextOpt(pc)) != -1) {
692 switch (opt) {
693 case 'b':
694 build_options(True); /* Display output to screen as well as debug */
695 exit(0);
696 break;
700 poptFreeContext(pc);
702 #ifdef HAVE_SETLUID
703 /* needed for SecureWare on SCO */
704 setluid(0);
705 #endif
707 sec_init();
709 load_case_tables();
711 set_remote_machine_name("smbd", False);
713 if (interactive) {
714 Fork = False;
715 log_stdout = True;
718 if (log_stdout && Fork) {
719 DEBUG(0,("ERROR: Can't log to stdout (-S) unless daemon is in foreground (-F) or interactive (-i)\n"));
720 exit(1);
723 setup_logging(argv[0],log_stdout);
725 /* we want to re-seed early to prevent time delays causing
726 client problems at a later date. (tridge) */
727 generate_random_buffer(NULL, 0);
729 /* make absolutely sure we run as root - to handle cases where people
730 are crazy enough to have it setuid */
732 gain_root_privilege();
733 gain_root_group_privilege();
735 fault_setup((void (*)(void *))exit_server);
736 CatchSignal(SIGTERM , SIGNAL_CAST sig_term);
737 CatchSignal(SIGHUP,SIGNAL_CAST sig_hup);
739 /* we are never interested in SIGPIPE */
740 BlockSignals(True,SIGPIPE);
742 #if defined(SIGFPE)
743 /* we are never interested in SIGFPE */
744 BlockSignals(True,SIGFPE);
745 #endif
747 #if defined(SIGUSR2)
748 /* We are no longer interested in USR2 */
749 BlockSignals(True,SIGUSR2);
750 #endif
752 /* POSIX demands that signals are inherited. If the invoking process has
753 * these signals masked, we will have problems, as we won't recieve them. */
754 BlockSignals(False, SIGHUP);
755 BlockSignals(False, SIGUSR1);
756 BlockSignals(False, SIGTERM);
758 /* we want total control over the permissions on created files,
759 so set our umask to 0 */
760 umask(0);
762 init_sec_ctx();
764 reopen_logs();
766 DEBUG(0,( "smbd version %s started.\n", SAMBA_VERSION_STRING));
767 DEBUGADD(0,( "Copyright Andrew Tridgell and the Samba Team 1992-2004\n"));
769 DEBUG(2,("uid=%d gid=%d euid=%d egid=%d\n",
770 (int)getuid(),(int)getgid(),(int)geteuid(),(int)getegid()));
772 /* Output the build options to the debug log */
773 build_options(False);
775 if (sizeof(uint16) < 2 || sizeof(uint32) < 4) {
776 DEBUG(0,("ERROR: Samba is not configured correctly for the word size on your machine\n"));
777 exit(1);
781 * Do this before reload_services.
784 if (!reload_services(False))
785 return(-1);
787 init_structs();
789 if (!init_guest_info())
790 return -1;
792 #ifdef WITH_PROFILE
793 if (!profile_setup(False)) {
794 DEBUG(0,("ERROR: failed to setup profiling\n"));
795 return -1;
797 #endif
799 DEBUG(3,( "loaded services\n"));
801 if (!is_daemon && !is_a_socket(0)) {
802 if (!interactive)
803 DEBUG(0,("standard input is not a socket, assuming -D option\n"));
806 * Setting is_daemon here prevents us from eventually calling
807 * the open_sockets_inetd()
810 is_daemon = True;
813 if (is_daemon && !interactive) {
814 DEBUG( 3, ( "Becoming a daemon.\n" ) );
815 become_daemon(Fork);
818 #if HAVE_SETPGID
820 * If we're interactive we want to set our own process group for
821 * signal management.
823 if (interactive)
824 setpgid( (pid_t)0, (pid_t)0);
825 #endif
827 if (!directory_exist(lp_lockdir(), NULL))
828 mkdir(lp_lockdir(), 0755);
830 if (is_daemon)
831 pidfile_create("smbd");
833 /* Setup all the TDB's - including CLEAR_IF_FIRST tdb's. */
834 if (!message_init())
835 exit(1);
837 if (!session_init())
838 exit(1);
840 if (conn_tdb_ctx() == NULL)
841 exit(1);
843 if (!locking_init(0))
844 exit(1);
846 if (!share_info_db_init())
847 exit(1);
849 namecache_enable();
851 if (!init_registry())
852 exit(1);
854 if (!print_backend_init())
855 exit(1);
857 /* Setup the main smbd so that we can get messages. */
858 /* don't worry about general printing messages here */
860 claim_connection(NULL,"",0,True,FLAG_MSG_GENERAL|FLAG_MSG_SMBD);
862 /* only start the background queue daemon if we are
863 running as a daemon -- bad things will happen if
864 smbd is launched via inetd and we fork a copy of
865 ourselves here */
867 if ( is_daemon && !interactive )
868 start_background_queue();
870 if (!open_sockets_smbd(is_daemon, interactive, ports))
871 exit(1);
874 * everything after this point is run after the fork()
877 /* Initialise the password backed before the global_sam_sid
878 to ensure that we fetch from ldap before we make a domain sid up */
880 if(!initialize_password_db(False))
881 exit(1);
883 if(!get_global_sam_sid()) {
884 DEBUG(0,("ERROR: Samba cannot create a SAM SID.\n"));
885 exit(1);
888 static_init_rpc;
890 init_modules();
892 /* possibly reload the services file. */
893 reload_services(True);
895 if (!init_account_policy()) {
896 DEBUG(0,("Could not open account policy tdb.\n"));
897 exit(1);
900 if (*lp_rootdir()) {
901 if (sys_chroot(lp_rootdir()) == 0)
902 DEBUG(2,("Changed root to %s\n", lp_rootdir()));
905 /* Setup oplocks */
906 if (!init_oplocks())
907 exit(1);
909 /* Setup change notify */
910 if (!init_change_notify())
911 exit(1);
913 /* re-initialise the timezone */
914 TimeInit();
916 /* register our message handlers */
917 message_register(MSG_SMB_FORCE_TDIS, msg_force_tdis);
919 smbd_process();
921 namecache_shutdown();
923 if (interactive) {
924 TALLOC_CTX *mem_ctx = talloc_init("end_description");
925 char *description = talloc_describe_all(mem_ctx);
927 DEBUG(3, ("tallocs left:\n%s\n", description));
928 talloc_destroy(mem_ctx);
931 exit_server("normal exit");
932 return(0);