63
/*******************************************************************
64
What to do when smb.conf is updated.
65
********************************************************************/
67
static void smb_conf_updated(int msg_type, struct process_id src,
68
void *buf, size_t len)
70
DEBUG(10,("smb_conf_updated: Got message saying smb.conf was updated. Reloading.\n"));
71
reload_services(False);
65
75
/****************************************************************************
67
77
****************************************************************************/
144
154
static void msg_exit_server(int msg_type, struct process_id src,
145
155
void *buf, size_t len)
147
exit_server("Got a SHUTDOWN message");
157
DEBUG(3, ("got a SHUTDOWN message\n"));
158
exit_server_cleanly(NULL);
162
static void msg_inject_fault(int msg_type, struct process_id src,
163
void *buf, size_t len)
167
if (len != sizeof(int)) {
169
DEBUG(0, ("Process %llu sent bogus signal injection request\n",
170
(unsigned long long)src.pid));
176
exit_server("internal error injected");
181
DEBUG(0, ("Process %llu requested injection of signal %d (%s)\n",
182
(unsigned long long)src.pid, sig, strsignal(sig)));
184
DEBUG(0, ("Process %llu requested injection of signal %d\n",
185
(unsigned long long)src.pid, sig));
188
kill(sys_getpid(), sig);
190
#endif /* DEVELOPER */
151
193
/****************************************************************************
330
372
message_register(MSG_SMB_SAM_SYNC, msg_sam_sync);
331
373
message_register(MSG_SMB_SAM_REPL, msg_sam_repl);
332
374
message_register(MSG_SHUTDOWN, msg_exit_server);
375
message_register(MSG_SMB_FILE_RENAME, msg_file_was_renamed);
376
message_register(MSG_SMB_CONF_UPDATED, smb_conf_updated);
379
message_register(MSG_SMB_INJECT_FAULT, msg_inject_fault);
334
382
/* now accept incoming connections - forking a new process
335
383
for each incoming connection */
429
477
set_need_random_reseed();
430
478
/* tdb needs special fork handling - remove CLEAR_IF_FIRST flags */
431
if (tdb_reopen_all() == -1) {
479
if (tdb_reopen_all(1) == -1) {
432
480
DEBUG(0,("tdb_reopen_all failed.\n"));
433
481
smb_panic("tdb_reopen_all failed.");
529
577
lp_killunused(conn_snum_used);
531
ret = lp_load(dyn_CONFIGFILE, False, False, True);
579
ret = lp_load(dyn_CONFIGFILE, False, False, True, True);
533
581
reload_printers();
559
/*******************************************************************
560
prepare to dump a core file - carefully!
561
********************************************************************/
562
static BOOL dump_core(void)
567
pstrcpy(dname,lp_logfile());
568
if ((p=strrchr_m(dname,'/'))) *p=0;
569
pstrcat(dname,"/corefiles");
571
sys_chown(dname,getuid(),getgid());
573
if (chdir(dname)) return(False);
576
#ifdef HAVE_GETRLIMIT
580
getrlimit(RLIMIT_CORE, &rlp);
581
rlp.rlim_cur = MAX(4*1024*1024,rlp.rlim_cur);
582
setrlimit(RLIMIT_CORE, &rlp);
583
getrlimit(RLIMIT_CORE, &rlp);
584
DEBUG(3,("Core limits now %d %d\n",
585
(int)rlp.rlim_cur,(int)rlp.rlim_max));
591
DEBUG(0,("Dumping core in %s\n", dname));
592
/* Ensure we don't have a signal handler for abort. */
594
CatchSignal(SIGABRT,SIGNAL_CAST SIG_DFL);
601
605
/****************************************************************************
603
607
****************************************************************************/
605
void exit_server(const char *reason)
609
/* Reasons for shutting down a server process. */
610
enum server_exit_reason { SERVER_EXIT_NORMAL, SERVER_EXIT_ABNORMAL };
612
static void exit_server_common(enum server_exit_reason how,
613
const char *const reason) NORETURN_ATTRIBUTE;
615
static void exit_server_common(enum server_exit_reason how,
616
const char *const reason)
607
618
static int firsttime=1;
651
if (how != SERVER_EXIT_NORMAL) {
639
652
int oldlevel = DEBUGLEVEL;
640
653
char *last_inbuf = get_InBuffer();
642
DEBUG(0,("Last message was %s\n",smb_fn_name(last_message)));
658
DEBUG(0,("Abnormal server exit: %s\n",
659
reason ? reason : "no explanation provided"));
664
DEBUG(0,("Last message was %s\n", LAST_MESSAGE()));
644
665
show_msg(last_inbuf);
645
668
DEBUGLEVEL = oldlevel;
646
DEBUG(0,("===============================================================\n"));
648
if (dump_core()) return;
655
DEBUG(3,("Server exit (%s)\n", (reason ? reason : "")));
674
DEBUG(3,("Server exit (%s)\n",
675
(reason ? reason : "normal exit")));
681
void exit_server(const char *const explanation)
683
exit_server_common(SERVER_EXIT_ABNORMAL, explanation);
686
void exit_server_cleanly(const char *const explanation)
688
exit_server_common(SERVER_EXIT_NORMAL, explanation);
691
void exit_server_fault(void)
693
exit_server("critical server fault");
659
696
/****************************************************************************
660
697
Initialise connect, service and file structs.
661
698
****************************************************************************/
700
737
static BOOL is_daemon = False;
701
738
static BOOL interactive = False;
702
739
static BOOL Fork = True;
740
static BOOL no_process_group = False;
703
741
static BOOL log_stdout = False;
704
742
static char *ports = NULL;
708
746
struct poptOption long_options[] = {
710
748
{"daemon", 'D', POPT_ARG_VAL, &is_daemon, True, "Become a daemon (default)" },
711
749
{"interactive", 'i', POPT_ARG_VAL, &interactive, True, "Run interactive (not a daemon)"},
712
{"foreground", 'F', POPT_ARG_VAL, &Fork, False, "Run daemon in foreground (for daemontools & etc)" },
750
{"foreground", 'F', POPT_ARG_VAL, &Fork, False, "Run daemon in foreground (for daemontools, etc.)" },
751
{"no-process-group", '\0', POPT_ARG_VAL, &no_process_group, True, "Don't create a new process group" },
713
752
{"log-stdout", 'S', POPT_ARG_VAL, &log_stdout, True, "Log to stdout" },
714
753
{"build-options", 'b', POPT_ARG_NONE, NULL, 'b', "Print build options" },
715
754
{"port", 'p', POPT_ARG_STRING, &ports, 0, "Listen on the specified ports"},
716
755
POPT_COMMON_SAMBA
756
POPT_COMMON_DYNCONFIG
720
760
load_case_tables();
771
811
gain_root_privilege();
772
812
gain_root_group_privilege();
774
fault_setup((void (*)(void *))exit_server);
814
fault_setup((void (*)(void *))exit_server_fault);
815
dump_core_setup("smbd");
775
817
CatchSignal(SIGTERM , SIGNAL_CAST sig_term);
776
818
CatchSignal(SIGHUP,SIGNAL_CAST sig_hup);
828
if (!init_guest_info()) {
829
DEBUG(0,("ERROR: failed to setup guest info.\n"));
833
870
#ifdef WITH_PROFILE
834
871
if (!profile_setup(False)) {
835
872
DEBUG(0,("ERROR: failed to setup profiling\n"));
875
912
if (!message_init())
915
/* Initialize our global sam sid first -- quite a lot of the other
916
* initialization routines further down depend on it.
919
/* Initialise the password backed before the global_sam_sid
920
to ensure that we fetch from ldap before we make a domain sid up */
922
if(!initialize_password_db(False))
925
/* Fail gracefully if we can't open secrets.tdb */
927
if (!secrets_init()) {
928
DEBUG(0, ("ERROR: smbd can not open secrets.tdb\n"));
932
if(!get_global_sam_sid()) {
933
DEBUG(0,("ERROR: Samba cannot create a SAM SID.\n"));
878
937
if (!session_init())
900
956
if (!print_backend_init())
959
if (!init_guest_info()) {
960
DEBUG(0,("ERROR: failed to setup guest info.\n"));
903
964
/* Setup the main smbd so that we can get messages. */
904
965
/* don't worry about general printing messages here */
913
974
if ( is_daemon && !interactive )
914
975
start_background_queue();
977
/* Always attempt to initialize DMAPI. We will only use it later if
978
* lp_dmapi_support is set on the share, but we need a single global
979
* session to work with.
981
dmapi_init_session();
916
983
if (!open_sockets_smbd(is_daemon, interactive, ports))
920
987
* everything after this point is run after the fork()
923
#if defined(HAVE_PRCTL) && defined(PR_SET_DUMPABLE)
924
/* On Linux we lose the ability to dump core when we change our user
925
* ID. We know how to dump core safely, so let's make sure we have our
928
prctl(PR_SET_DUMPABLE, 1);
931
/* Initialise the password backed before the global_sam_sid
932
to ensure that we fetch from ldap before we make a domain sid up */
934
if(!initialize_password_db(False))
937
if(!get_global_sam_sid()) {
938
DEBUG(0,("ERROR: Samba cannot create a SAM SID.\n"));