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
7 Copyright (C) James Peach 2007
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
27 static int am_parent = 1;
29 /* the last message the was processed */
30 int last_message = -1;
32 /* a useful macro to debug the last message processed */
33 #define LAST_MESSAGE() smb_fn_name(last_message)
35 extern struct auth_context *negprot_global_auth_context;
36 extern pstring user_socket_options;
37 extern SIG_ATOMIC_T got_sig_term;
38 extern SIG_ATOMIC_T reload_after_sighup;
39 static SIG_ATOMIC_T got_sig_cld;
42 extern int dcelogin_atmost_once;
45 /* really we should have a top level context structure that has the
46 client file descriptor as an element. That would require a major rewrite :(
48 the following 2 functions are an alternative - they make the file
49 descriptor private to smbd
51 static int server_fd = -1;
53 int smbd_server_fd(void)
58 static void smbd_set_server_fd(int fd)
64 struct event_context *smbd_event_context(void)
66 static struct event_context *ctx;
68 if (!ctx && !(ctx = event_context_init(NULL))) {
69 smb_panic("Could not init smbd event context");
74 struct messaging_context *smbd_messaging_context(void)
76 static struct messaging_context *ctx;
78 if (!ctx && !(ctx = messaging_init(NULL, server_id_self(),
79 smbd_event_context()))) {
80 smb_panic("Could not init smbd messaging context");
85 /*******************************************************************
86 What to do when smb.conf is updated.
87 ********************************************************************/
89 static void smb_conf_updated(struct messaging_context *msg,
92 struct server_id server_id,
95 DEBUG(10,("smb_conf_updated: Got message saying smb.conf was "
96 "updated. Reloading.\n"));
97 reload_services(False);
101 /*******************************************************************
102 Delete a statcache entry.
103 ********************************************************************/
105 static void smb_stat_cache_delete(struct messaging_context *msg,
108 struct server_id server_id,
111 const char *name = (const char *)data->data;
112 DEBUG(10,("smb_stat_cache_delete: delete name %s\n", name));
113 stat_cache_delete(name);
116 /****************************************************************************
118 ****************************************************************************/
120 static void sig_term(void)
123 sys_select_signal(SIGTERM);
126 /****************************************************************************
128 ****************************************************************************/
130 static void sig_hup(int sig)
132 reload_after_sighup = 1;
133 sys_select_signal(SIGHUP);
136 /****************************************************************************
138 ****************************************************************************/
139 static void sig_cld(int sig)
142 sys_select_signal(SIGCLD);
145 /****************************************************************************
146 Send a SIGTERM to our process group.
147 *****************************************************************************/
149 static void killkids(void)
151 if(am_parent) kill(0,SIGTERM);
154 /****************************************************************************
155 Process a sam sync message - not sure whether to do this here or
157 ****************************************************************************/
159 static void msg_sam_sync(struct messaging_context *msg,
162 struct server_id server_id,
165 DEBUG(10, ("** sam sync message received, ignoring\n"));
169 /****************************************************************************
170 Open the socket communication - inetd.
171 ****************************************************************************/
173 static BOOL open_sockets_inetd(void)
175 /* Started from inetd. fd 0 is the socket. */
176 /* We will abort gracefully when the client or remote system
178 smbd_set_server_fd(dup(0));
180 /* close our standard file descriptors */
181 close_low_fds(False); /* Don't close stderr */
183 set_socket_options(smbd_server_fd(),"SO_KEEPALIVE");
184 set_socket_options(smbd_server_fd(), user_socket_options);
189 static void msg_exit_server(struct messaging_context *msg,
192 struct server_id server_id,
195 DEBUG(3, ("got a SHUTDOWN message\n"));
196 exit_server_cleanly(NULL);
200 static void msg_inject_fault(struct messaging_context *msg,
203 struct server_id src,
208 if (data->length != sizeof(sig)) {
210 DEBUG(0, ("Process %s sent bogus signal injection request\n",
211 procid_str_static(&src)));
215 sig = *(int *)data->data;
217 exit_server("internal error injected");
222 DEBUG(0, ("Process %s requested injection of signal %d (%s)\n",
223 procid_str_static(&src), sig, strsignal(sig)));
225 DEBUG(0, ("Process %s requested injection of signal %d\n",
226 procid_str_static(&src), sig));
229 kill(sys_getpid(), sig);
231 #endif /* DEVELOPER */
234 struct child_pid *prev, *next;
238 static struct child_pid *children;
239 static int num_children;
241 static void add_child_pid(pid_t pid)
243 struct child_pid *child;
245 if (lp_max_smbd_processes() == 0) {
246 /* Don't bother with the child list if we don't care anyway */
250 child = SMB_MALLOC_P(struct child_pid);
252 DEBUG(0, ("Could not add child struct -- malloc failed\n"));
256 DLIST_ADD(children, child);
260 static void remove_child_pid(pid_t pid)
262 struct child_pid *child;
264 if (lp_max_smbd_processes() == 0) {
265 /* Don't bother with the child list if we don't care anyway */
269 for (child = children; child != NULL; child = child->next) {
270 if (child->pid == pid) {
271 struct child_pid *tmp = child;
272 DLIST_REMOVE(children, child);
279 DEBUG(0, ("Could not find child %d -- ignoring\n", (int)pid));
282 /****************************************************************************
283 Have we reached the process limit ?
284 ****************************************************************************/
286 static BOOL allowable_number_of_smbd_processes(void)
288 int max_processes = lp_max_smbd_processes();
293 return num_children < max_processes;
296 /****************************************************************************
297 Are we idle enough that we could safely exit?
298 ****************************************************************************/
300 static BOOL smbd_is_idle(void)
302 /* Currently we define "idle" as having no client connections. */
303 return count_all_current_connections() == 0;
306 /****************************************************************************
307 Open the socket communication.
308 ****************************************************************************/
310 static BOOL open_sockets_smbd(enum smb_server_mode server_mode, const char *smb_ports)
313 int fd_listenset[FD_SETSIZE];
318 struct timeval idle_timeout = timeval_zero();
320 if (server_mode == SERVER_MODE_INETD) {
321 return open_sockets_inetd();
326 static int atexit_set;
327 if(atexit_set == 0) {
335 CatchSignal(SIGCLD, sig_cld);
337 FD_ZERO(&listen_set);
339 /* At this point, it doesn't matter what daemon mode we are in, we
340 * need some sockets to listen on.
342 num_sockets = smbd_sockinit(smb_ports, fd_listenset, &idle_timeout);
343 if (num_sockets == 0) {
347 for (i = 0; i < num_sockets; ++i) {
348 FD_SET(fd_listenset[i], &listen_set);
349 maxfd = MAX(maxfd, fd_listenset[i]);
353 /* Setup the main smbd so that we can get messages. Note that
354 do this after starting listening. This is needed as when in
355 clustered mode, ctdb won't allow us to start doing database
356 operations until it has gone thru a full startup, which
357 includes checking to see that smbd is listening. */
358 claim_connection(NULL,"",FLAG_MSG_GENERAL|FLAG_MSG_SMBD);
360 /* Listen to messages */
362 messaging_register(smbd_messaging_context(), NULL,
363 MSG_SMB_SAM_SYNC, msg_sam_sync);
364 messaging_register(smbd_messaging_context(), NULL,
365 MSG_SHUTDOWN, msg_exit_server);
366 messaging_register(smbd_messaging_context(), NULL,
367 MSG_SMB_FILE_RENAME, msg_file_was_renamed);
368 messaging_register(smbd_messaging_context(), NULL,
369 MSG_SMB_CONF_UPDATED, smb_conf_updated);
370 messaging_register(smbd_messaging_context(), NULL,
371 MSG_SMB_STAT_CACHE_DELETE, smb_stat_cache_delete);
372 brl_register_msgs(smbd_messaging_context());
375 messaging_register(smbd_messaging_context(), NULL,
376 MSG_SMB_INJECT_FAULT, msg_inject_fault);
379 /* now accept incoming connections - forking a new process
380 for each incoming connection */
381 DEBUG(2,("waiting for a connection\n"));
387 /* Free up temporary memory from the main smbd. */
390 /* Ensure we respond to PING and DEBUG messages from the main smbd. */
391 message_dispatch(smbd_messaging_context());
397 while ((pid = sys_waitpid(-1, NULL, WNOHANG)) > 0) {
398 remove_child_pid(pid);
402 memcpy((char *)&r_fds, (char *)&listen_set,
407 event_add_to_select_args(smbd_event_context(), &now,
408 &r_fds, &w_fds, &idle_timeout,
411 if (timeval_is_zero(&idle_timeout)) {
412 num = sys_select(maxfd + 1, &r_fds, &w_fds,
415 num = sys_select(maxfd + 1, &r_fds, &w_fds,
416 NULL, &idle_timeout);
418 /* If the idle timeout fired and we are idle, exit
419 * gracefully. We expect to be running under a process
420 * controller that will restart us if necessry.
422 if (num == 0 && smbd_is_idle()) {
423 exit_server_cleanly("idle timeout");
427 if (num == -1 && errno == EINTR) {
429 exit_server_cleanly(NULL);
432 /* check for sighup processing */
433 if (reload_after_sighup) {
434 change_to_root_user();
435 DEBUG(1,("Reloading services after SIGHUP\n"));
436 reload_services(False);
437 reload_after_sighup = 0;
443 if (run_events(smbd_event_context(), num, &r_fds, &w_fds)) {
447 /* check if we need to reload services */
448 check_reload(time(NULL));
450 /* Find the sockets that are read-ready -
452 for( ; num > 0; num--) {
453 struct sockaddr addr;
454 socklen_t in_addrlen = sizeof(addr);
458 for(i = 0; i < num_sockets; i++) {
459 if(FD_ISSET(fd_listenset[i],&r_fds)) {
461 /* Clear this so we don't look
463 FD_CLR(fd_listenset[i],&r_fds);
468 smbd_set_server_fd(accept(s,&addr,&in_addrlen));
470 if (smbd_server_fd() == -1 && errno == EINTR)
473 if (smbd_server_fd() == -1) {
474 DEBUG(0,("open_sockets_smbd: accept: %s\n",
479 /* Ensure child is set to blocking mode */
480 set_blocking(smbd_server_fd(),True);
482 /* In interactive mode, return with a connected socket.
483 * Foreground and daemon modes should fork worker
486 if (server_mode == SERVER_MODE_INTERACTIVE) {
490 if (allowable_number_of_smbd_processes() &&
491 smbd_server_fd() != -1 &&
492 ((child = sys_fork())==0)) {
495 /* Stop zombies, the parent explicitly handles
496 * them, counting worker smbds. */
499 /* close the listening socket(s) */
500 for(i = 0; i < num_sockets; i++)
501 close(fd_listenset[i]);
503 /* close our standard file
505 close_low_fds(False);
508 set_socket_options(smbd_server_fd(),"SO_KEEPALIVE");
509 set_socket_options(smbd_server_fd(),user_socket_options);
511 /* this is needed so that we get decent entries
512 in smbstatus for port 445 connects */
513 set_remote_machine_name(get_peer_addr(smbd_server_fd()),
516 /* Reset the state of the random
517 * number generation system, so
518 * children do not get the same random
519 * numbers as each other */
521 set_need_random_reseed();
522 /* tdb needs special fork handling - remove
523 * CLEAR_IF_FIRST flags */
524 if (tdb_reopen_all(1) == -1) {
525 DEBUG(0,("tdb_reopen_all failed.\n"));
526 smb_panic("tdb_reopen_all failed");
531 /* The parent doesn't need this socket */
532 close(smbd_server_fd());
534 /* Sun May 6 18:56:14 2001 ackley@cs.unm.edu:
535 Clear the closed fd info out of server_fd --
536 and more importantly, out of client_fd in
537 util_sock.c, to avoid a possible
538 getpeername failure if we reopen the logs
539 and use %I in the filename.
542 smbd_set_server_fd(-1);
545 add_child_pid(child);
548 /* Force parent to check log size after
549 * spawning child. Fix from
550 * klausr@ITAP.Physik.Uni-Stuttgart.De. The
551 * parent smbd will log to logserver.smb. It
552 * writes only two messages for each child
553 * started/finished. But each child writes,
554 * say, 50 messages also in logserver.smb,
555 * begining with the debug_count of the
556 * parent, before the child opens its own log
557 * file logserver.client. In a worst case
558 * scenario the size of logserver.smb would be
559 * checked after about 50*50=2500 messages
562 force_check_log_size();
567 /* NOTREACHED return True; */
570 /****************************************************************************
572 **************************************************************************/
573 void reload_printers(void)
576 int n_services = lp_numservices();
577 int pnum = lp_servicenumber(PRINTERS_NAME);
582 /* remove stale printers */
583 for (snum = 0; snum < n_services; snum++) {
584 /* avoid removing PRINTERS_NAME or non-autoloaded printers */
585 if (snum == pnum || !(lp_snum_ok(snum) && lp_print_ok(snum) &&
586 lp_autoloaded(snum)))
589 pname = lp_printername(snum);
590 if (!pcap_printername_ok(pname)) {
591 DEBUG(3, ("removing stale printer %s\n", pname));
593 if (is_printer_published(NULL, snum, NULL))
594 nt_printer_publish(NULL, snum, SPOOL_DS_UNPUBLISH);
595 del_a_printer(pname);
596 lp_killservice(snum);
603 /****************************************************************************
604 Reload the services file.
605 **************************************************************************/
607 BOOL reload_services(BOOL test)
613 pstrcpy(fname,lp_configfile());
614 if (file_exist(fname, NULL) &&
615 !strcsequal(fname, dyn_CONFIGFILE)) {
616 pstrcpy(dyn_CONFIGFILE, fname);
623 if (test && !lp_file_list_changed())
626 lp_killunused(conn_snum_used);
628 ret = lp_load(dyn_CONFIGFILE, False, False, True, True);
632 /* perhaps the config filename is now set */
634 reload_services(True);
640 if (smbd_server_fd() != -1) {
641 set_socket_options(smbd_server_fd(),"SO_KEEPALIVE");
642 set_socket_options(smbd_server_fd(), user_socket_options);
645 mangle_reset_cache();
648 /* this forces service parameters to be flushed */
649 set_current_service(NULL,0,True);
654 /****************************************************************************
656 ****************************************************************************/
658 /* Reasons for shutting down a server process. */
659 enum server_exit_reason { SERVER_EXIT_NORMAL, SERVER_EXIT_ABNORMAL };
661 static void exit_server_common(enum server_exit_reason how,
662 const char *const reason) NORETURN_ATTRIBUTE;
664 static void exit_server_common(enum server_exit_reason how,
665 const char *const reason)
667 static int firsttime=1;
673 change_to_root_user();
675 if (negprot_global_auth_context) {
676 (negprot_global_auth_context->free)(&negprot_global_auth_context);
681 invalidate_all_vuids();
683 /* 3 second timeout. */
684 print_notify_send_messages(smbd_messaging_context(), 3);
686 /* delete our entry in the connections database. */
687 yield_connection(NULL,"");
689 respond_to_all_remaining_local_messages();
692 if (dcelogin_atmost_once) {
700 server_encryption_shutdown();
702 if (how != SERVER_EXIT_NORMAL) {
703 int oldlevel = DEBUGLEVEL;
704 char *last_inbuf = get_InBuffer();
709 DEBUG(0,("Abnormal server exit: %s\n",
710 reason ? reason : "no explanation provided"));
715 DEBUG(0,("Last message was %s\n", LAST_MESSAGE()));
716 show_msg(last_inbuf);
719 DEBUGLEVEL = oldlevel;
723 DEBUG(3,("Server exit (%s)\n",
724 (reason ? reason : "normal exit")));
730 void exit_server(const char *const explanation)
732 exit_server_common(SERVER_EXIT_ABNORMAL, explanation);
735 void exit_server_cleanly(const char *const explanation)
737 exit_server_common(SERVER_EXIT_NORMAL, explanation);
740 void exit_server_fault(void)
742 exit_server("critical server fault");
745 /****************************************************************************
746 Initialise connect, service and file structs.
747 ****************************************************************************/
749 static BOOL init_structs(void )
752 * Set the machine NETBIOS name if not already
753 * set from the config file.
774 * Send keepalive packets to our client
776 static BOOL keepalive_fn(const struct timeval *now, void *private_data)
778 if (!send_keepalive(smbd_server_fd())) {
779 DEBUG( 2, ( "Keepalive failed - exiting.\n" ) );
786 * Do the recurring check if we're idle
788 static BOOL deadtime_fn(const struct timeval *now, void *private_data)
790 if ((conn_num_open() == 0)
791 || (conn_idle_all(now->tv_sec))) {
792 DEBUG( 2, ( "Closing idle connection\n" ) );
793 messaging_send(smbd_messaging_context(), procid_self(),
794 MSG_SHUTDOWN, &data_blob_null);
802 /****************************************************************************
804 ****************************************************************************/
806 /* Declare prototype for build_options() to avoid having to run it through
807 mkproto.h. Mixing $(builddir) and $(srcdir) source files in the current
808 prototype generation system is too complicated. */
810 extern void build_options(BOOL screen);
812 int main(int argc,const char *argv[])
814 /* shall I run as a daemon */
815 BOOL no_process_group = False;
816 BOOL log_stdout = False;
817 const char *ports = NULL;
818 const char *profile_level = NULL;
821 BOOL print_build_options = False;
823 enum smb_server_mode server_mode = SERVER_MODE_DAEMON;
825 struct poptOption long_options[] = {
827 {"daemon", 'D', POPT_ARG_VAL, &server_mode, SERVER_MODE_DAEMON,
828 "Become a daemon (default)" },
829 {"interactive", 'i', POPT_ARG_VAL, &server_mode, SERVER_MODE_INTERACTIVE,
830 "Run interactive (not a daemon)"},
831 {"foreground", 'F', POPT_ARG_VAL, &server_mode, SERVER_MODE_FOREGROUND,
832 "Run daemon in foreground (for daemontools, etc.)" },
833 {"no-process-group", '\0', POPT_ARG_VAL, &no_process_group, True,
834 "Don't create a new process group" },
835 {"log-stdout", 'S', POPT_ARG_VAL, &log_stdout, True, "Log to stdout" },
836 {"build-options", 'b', POPT_ARG_NONE, NULL, 'b', "Print build options" },
837 {"port", 'p', POPT_ARG_STRING, &ports, 0, "Listen on the specified ports"},
838 {"profiling-level", 'P', POPT_ARG_STRING, &profile_level, 0, "Set profiling level","PROFILE_LEVEL"},
840 POPT_COMMON_DYNCONFIG
848 #ifdef HAVE_SET_AUTH_PARAMETERS
849 set_auth_parameters(argc,argv);
852 pc = poptGetContext("smbd", argc, argv, long_options, 0);
853 while((opt = poptGetNextOpt(pc)) != -1) {
856 print_build_options = True;
859 d_fprintf(stderr, "\nInvalid option %s: %s\n\n",
860 poptBadOption(pc, 0), poptStrerror(opt));
861 poptPrintUsage(pc, stderr, 0);
867 if (print_build_options) {
868 build_options(True); /* Display output to screen as well as debug */
873 /* needed for SecureWare on SCO */
879 set_remote_machine_name("smbd", False);
881 if (server_mode == SERVER_MODE_INTERACTIVE) {
883 if (DEBUGLEVEL >= 9) {
884 talloc_enable_leak_report();
888 if (log_stdout && server_mode == SERVER_MODE_DAEMON) {
889 DEBUG(0,("ERROR: Can't log to stdout (-S) unless daemon is in foreground (-F) or interactive (-i)\n"));
893 setup_logging(argv[0],log_stdout);
895 /* we want to re-seed early to prevent time delays causing
896 client problems at a later date. (tridge) */
897 generate_random_buffer(NULL, 0);
899 /* make absolutely sure we run as root - to handle cases where people
900 are crazy enough to have it setuid */
902 gain_root_privilege();
903 gain_root_group_privilege();
905 fault_setup((void (*)(void *))exit_server_fault);
906 dump_core_setup("smbd");
908 CatchSignal(SIGTERM , SIGNAL_CAST sig_term);
909 CatchSignal(SIGHUP,SIGNAL_CAST sig_hup);
911 /* we are never interested in SIGPIPE */
912 BlockSignals(True,SIGPIPE);
915 /* we are never interested in SIGFPE */
916 BlockSignals(True,SIGFPE);
920 /* We are no longer interested in USR2 */
921 BlockSignals(True,SIGUSR2);
924 /* POSIX demands that signals are inherited. If the invoking process has
925 * these signals masked, we will have problems, as we won't recieve them. */
926 BlockSignals(False, SIGHUP);
927 BlockSignals(False, SIGUSR1);
928 BlockSignals(False, SIGTERM);
930 /* we want total control over the permissions on created files,
931 so set our umask to 0 */
938 DEBUG(0,( "smbd version %s started.\n", SAMBA_VERSION_STRING));
939 DEBUGADD( 0, ( "%s\n", COPYRIGHT_STARTUP_MESSAGE ) );
941 DEBUG(2,("uid=%d gid=%d euid=%d egid=%d\n",
942 (int)getuid(),(int)getgid(),(int)geteuid(),(int)getegid()));
944 /* Output the build options to the debug log */
945 build_options(False);
947 if (sizeof(uint16) < 2 || sizeof(uint32) < 4) {
948 DEBUG(0,("ERROR: Samba is not configured correctly for the word size on your machine\n"));
953 * Do this before reload_services.
956 if (!reload_services(False))
962 if (!profile_setup(smbd_messaging_context(), False)) {
963 DEBUG(0,("ERROR: failed to setup profiling\n"));
966 if (profile_level != NULL) {
967 int pl = atoi(profile_level);
968 struct server_id src;
970 DEBUG(1, ("setting profiling level: %s\n",profile_level));
972 set_profile_level(pl, src);
976 DEBUG(3,( "loaded services\n"));
978 if (is_a_socket(0)) {
979 if (server_mode == SERVER_MODE_DAEMON) {
980 DEBUG(0,("standard input is a socket, "
981 "assuming -F option\n"));
983 server_mode = SERVER_MODE_INETD;
986 if (server_mode == SERVER_MODE_DAEMON) {
987 DEBUG( 3, ( "Becoming a daemon.\n" ) );
988 become_daemon(True, no_process_group);
989 } else if (server_mode == SERVER_MODE_FOREGROUND) {
990 become_daemon(False, no_process_group);
995 * If we're interactive we want to set our own process group for
998 if (server_mode == SERVER_MODE_INTERACTIVE && !no_process_group) {
999 setpgid( (pid_t)0, (pid_t)0);
1003 if (!directory_exist(lp_lockdir(), NULL))
1004 mkdir(lp_lockdir(), 0755);
1006 if (server_mode != SERVER_MODE_INETD &&
1007 server_mode != SERVER_MODE_INTERACTIVE) {
1008 pidfile_create("smbd");
1011 /* Setup all the TDB's - including CLEAR_IF_FIRST tdb's. */
1013 if (smbd_messaging_context() == NULL)
1016 /* Initialise the password backed before the global_sam_sid
1017 to ensure that we fetch from ldap before we make a domain sid up */
1019 if(!initialize_password_db(False, smbd_event_context()))
1022 if (!secrets_init()) {
1023 DEBUG(0, ("ERROR: smbd can not open secrets.tdb\n"));
1027 if(!get_global_sam_sid()) {
1028 DEBUG(0,("ERROR: Samba cannot create a SAM SID.\n"));
1032 if (!session_init())
1035 if (!connections_init(True))
1038 if (!locking_init(0))
1043 if (!init_registry())
1047 if (!init_svcctl_db())
1051 if (!print_backend_init(smbd_messaging_context()))
1054 if (!init_guest_info()) {
1055 DEBUG(0,("ERROR: failed to setup guest info.\n"));
1059 /* only start the background queue daemon if we are
1060 running as a daemon -- bad things will happen if
1061 smbd is launched via inetd and we fork a copy of
1063 if (server_mode != SERVER_MODE_INETD &&
1064 server_mode != SERVER_MODE_INTERACTIVE) {
1065 start_background_queue();
1068 /* Always attempt to initialize DMAPI. We will only use it later if
1069 * lp_dmapi_support is set on the share, but we need a single global
1070 * session to work with.
1072 dmapi_init_session();
1074 if (!open_sockets_smbd(server_mode, ports)) {
1079 * everything after this point is run after the fork()
1086 /* Possibly reload the services file. Only worth doing in
1087 * daemon mode. In inetd mode, we know we only just loaded this.
1089 if (server_mode != SERVER_MODE_INETD &&
1090 server_mode != SERVER_MODE_INTERACTIVE) {
1091 reload_services(True);
1094 if (!init_account_policy()) {
1095 DEBUG(0,("Could not open account policy tdb.\n"));
1099 if (*lp_rootdir()) {
1100 if (sys_chroot(lp_rootdir()) == 0)
1101 DEBUG(2,("Changed root to %s\n", lp_rootdir()));
1105 if (!init_oplocks(smbd_messaging_context()))
1108 /* Setup aio signal handler. */
1109 initialize_async_io_handler();
1112 * For clustering, we need to re-init our ctdbd connection after the
1115 if (!NT_STATUS_IS_OK(messaging_reinit(smbd_messaging_context())))
1118 /* register our message handlers */
1119 messaging_register(smbd_messaging_context(), NULL,
1120 MSG_SMB_FORCE_TDIS, msg_force_tdis);
1122 if ((lp_keepalive() != 0)
1123 && !(event_add_idle(smbd_event_context(), NULL,
1124 timeval_set(lp_keepalive(), 0),
1125 "keepalive", keepalive_fn,
1127 DEBUG(0, ("Could not add keepalive event\n"));
1131 if (!(event_add_idle(smbd_event_context(), NULL,
1132 timeval_set(IDLE_CLOSED_TIMEOUT, 0),
1133 "deadtime", deadtime_fn, NULL))) {
1134 DEBUG(0, ("Could not add deadtime event\n"));
1140 namecache_shutdown();
1142 exit_server_cleanly(NULL);