00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "includes.h"
00024
00025 static_decl_rpc;
00026
00027 static int am_parent = 1;
00028
00029
00030 int last_message = -1;
00031
00032
00033 #define LAST_MESSAGE() (last_message != -1 ? smb_fn_name(last_message) : "")
00034
00035 extern struct auth_context *negprot_global_auth_context;
00036 extern pstring user_socket_options;
00037 extern SIG_ATOMIC_T got_sig_term;
00038 extern SIG_ATOMIC_T reload_after_sighup;
00039 static SIG_ATOMIC_T got_sig_cld;
00040
00041 #ifdef WITH_DFS
00042 extern int dcelogin_atmost_once;
00043 #endif
00044
00045
00046
00047
00048
00049
00050
00051 static int server_fd = -1;
00052
00053 int smbd_server_fd(void)
00054 {
00055 return server_fd;
00056 }
00057
00058 static void smbd_set_server_fd(int fd)
00059 {
00060 server_fd = fd;
00061 client_setfd(fd);
00062 }
00063
00064 struct event_context *smbd_event_context(void)
00065 {
00066 static struct event_context *ctx;
00067
00068 if (!ctx && !(ctx = event_context_init(NULL))) {
00069 smb_panic("Could not init smbd event context\n");
00070 }
00071 return ctx;
00072 }
00073
00074 struct messaging_context *smbd_messaging_context(void)
00075 {
00076 static struct messaging_context *ctx;
00077
00078 if (!ctx && !(ctx = messaging_init(NULL, server_id_self(),
00079 smbd_event_context()))) {
00080 smb_panic("Could not init smbd messaging context\n");
00081 }
00082 return ctx;
00083 }
00084
00085
00086
00087
00088
00089 static void smb_conf_updated(int msg_type, struct process_id src,
00090 void *buf, size_t len, void *private_data)
00091 {
00092 DEBUG(10,("smb_conf_updated: Got message saying smb.conf was updated. Reloading.\n"));
00093 reload_services(False);
00094 }
00095
00096
00097
00098
00099
00100
00101 static void smb_stat_cache_delete(int msg_type, struct process_id src,
00102 void *buf, size_t len, void *private_data)
00103 {
00104 const char *name = (const char *)buf;
00105 DEBUG(10,("smb_stat_cache_delete: delete name %s\n", name));
00106 stat_cache_delete(name);
00107 }
00108
00109
00110
00111
00112
00113 static void sig_term(void)
00114 {
00115 got_sig_term = 1;
00116 sys_select_signal(SIGTERM);
00117 }
00118
00119
00120
00121
00122
00123 static void sig_hup(int sig)
00124 {
00125 reload_after_sighup = 1;
00126 sys_select_signal(SIGHUP);
00127 }
00128
00129
00130
00131
00132 static void sig_cld(int sig)
00133 {
00134 got_sig_cld = 1;
00135 sys_select_signal(SIGCLD);
00136 }
00137
00138
00139
00140
00141
00142 static void killkids(void)
00143 {
00144 if(am_parent) kill(0,SIGTERM);
00145 }
00146
00147
00148
00149
00150
00151
00152 static void msg_sam_sync(int UNUSED(msg_type), struct process_id UNUSED(pid),
00153 void *UNUSED(buf), size_t UNUSED(len),
00154 void *private_data)
00155 {
00156 DEBUG(10, ("** sam sync message received, ignoring\n"));
00157 }
00158
00159
00160
00161
00162
00163
00164 static void msg_sam_repl(int msg_type, struct process_id pid,
00165 void *buf, size_t len, void *private_data)
00166 {
00167 uint32 low_serial;
00168
00169 if (len != sizeof(uint32))
00170 return;
00171
00172 low_serial = *((uint32 *)buf);
00173
00174 DEBUG(3, ("received sam replication message, serial = 0x%04x\n",
00175 low_serial));
00176 }
00177
00178
00179
00180
00181
00182 static BOOL open_sockets_inetd(void)
00183 {
00184
00185
00186
00187 smbd_set_server_fd(dup(0));
00188
00189
00190 close_low_fds(False);
00191
00192 set_socket_options(smbd_server_fd(),"SO_KEEPALIVE");
00193 set_socket_options(smbd_server_fd(), user_socket_options);
00194
00195 return True;
00196 }
00197
00198 static void msg_exit_server(int msg_type, struct process_id src,
00199 void *buf, size_t len, void *private_data)
00200 {
00201 DEBUG(3, ("got a SHUTDOWN message\n"));
00202 exit_server_cleanly(NULL);
00203 }
00204
00205 #ifdef DEVELOPER
00206 static void msg_inject_fault(int msg_type, struct process_id src,
00207 void *buf, size_t len, void *private_data)
00208 {
00209 int sig;
00210
00211 if (len != sizeof(int)) {
00212
00213 DEBUG(0, ("Process %llu sent bogus signal injection request\n",
00214 (unsigned long long)src.pid));
00215 return;
00216 }
00217
00218 sig = *(int *)buf;
00219 if (sig == -1) {
00220 exit_server("internal error injected");
00221 return;
00222 }
00223
00224 #if HAVE_STRSIGNAL
00225 DEBUG(0, ("Process %llu requested injection of signal %d (%s)\n",
00226 (unsigned long long)src.pid, sig, strsignal(sig)));
00227 #else
00228 DEBUG(0, ("Process %llu requested injection of signal %d\n",
00229 (unsigned long long)src.pid, sig));
00230 #endif
00231
00232 kill(sys_getpid(), sig);
00233 }
00234 #endif
00235
00236 struct child_pid {
00237 struct child_pid *prev, *next;
00238 pid_t pid;
00239 };
00240
00241 static struct child_pid *children;
00242 static int num_children;
00243
00244 static void add_child_pid(pid_t pid)
00245 {
00246 struct child_pid *child;
00247
00248 if (lp_max_smbd_processes() == 0) {
00249
00250 return;
00251 }
00252
00253 child = SMB_MALLOC_P(struct child_pid);
00254 if (child == NULL) {
00255 DEBUG(0, ("Could not add child struct -- malloc failed\n"));
00256 return;
00257 }
00258 child->pid = pid;
00259 DLIST_ADD(children, child);
00260 num_children += 1;
00261 }
00262
00263 static void remove_child_pid(pid_t pid)
00264 {
00265 struct child_pid *child;
00266
00267 if (lp_max_smbd_processes() == 0) {
00268
00269 return;
00270 }
00271
00272 for (child = children; child != NULL; child = child->next) {
00273 if (child->pid == pid) {
00274 struct child_pid *tmp = child;
00275 DLIST_REMOVE(children, child);
00276 SAFE_FREE(tmp);
00277 num_children -= 1;
00278 return;
00279 }
00280 }
00281
00282 DEBUG(0, ("Could not find child %d -- ignoring\n", (int)pid));
00283 }
00284
00285
00286
00287
00288
00289 static BOOL allowable_number_of_smbd_processes(void)
00290 {
00291 int max_processes = lp_max_smbd_processes();
00292
00293 if (!max_processes)
00294 return True;
00295
00296 return num_children < max_processes;
00297 }
00298
00299
00300
00301
00302
00303 static BOOL open_sockets_smbd(BOOL is_daemon, BOOL interactive, const char *smb_ports)
00304 {
00305 int num_interfaces = iface_count();
00306 int num_sockets = 0;
00307 int fd_listenset[FD_SETSIZE];
00308 fd_set listen_set;
00309 int s;
00310 int maxfd = 0;
00311 int i;
00312 char *ports;
00313
00314 if (!is_daemon) {
00315 return open_sockets_inetd();
00316 }
00317
00318
00319 #ifdef HAVE_ATEXIT
00320 {
00321 static int atexit_set;
00322 if(atexit_set == 0) {
00323 atexit_set=1;
00324 atexit(killkids);
00325 }
00326 }
00327 #endif
00328
00329
00330 CatchSignal(SIGCLD, sig_cld);
00331
00332 FD_ZERO(&listen_set);
00333
00334
00335 if (!smb_ports) {
00336 ports = lp_smb_ports();
00337 if (!ports || !*ports) {
00338 ports = smb_xstrdup(SMB_PORTS);
00339 } else {
00340 ports = smb_xstrdup(ports);
00341 }
00342 } else {
00343 ports = smb_xstrdup(smb_ports);
00344 }
00345
00346 if (lp_interfaces() && lp_bind_interfaces_only()) {
00347
00348
00349
00350
00351
00352
00353
00354 for(i = 0; i < num_interfaces; i++) {
00355 struct in_addr *ifip = iface_n_ip(i);
00356 fstring tok;
00357 const char *ptr;
00358
00359 if(ifip == NULL) {
00360 DEBUG(0,("open_sockets_smbd: interface %d has NULL IP address !\n", i));
00361 continue;
00362 }
00363
00364 for (ptr=ports; next_token(&ptr, tok, " \t,", sizeof(tok)); ) {
00365 unsigned port = atoi(tok);
00366 if (port == 0 || port > 0xffff) {
00367 continue;
00368 }
00369 s = fd_listenset[num_sockets] = open_socket_in(SOCK_STREAM, port, 0, ifip->s_addr, True);
00370 if(s == -1)
00371 return False;
00372
00373
00374 set_socket_options(s,"SO_KEEPALIVE");
00375 set_socket_options(s,user_socket_options);
00376
00377
00378 set_blocking(s,False);
00379
00380 if (listen(s, SMBD_LISTEN_BACKLOG) == -1) {
00381 DEBUG(0,("listen: %s\n",strerror(errno)));
00382 close(s);
00383 return False;
00384 }
00385 FD_SET(s,&listen_set);
00386 maxfd = MAX( maxfd, s);
00387
00388 num_sockets++;
00389 if (num_sockets >= FD_SETSIZE) {
00390 DEBUG(0,("open_sockets_smbd: Too many sockets to bind to\n"));
00391 return False;
00392 }
00393 }
00394 }
00395 } else {
00396
00397
00398
00399 fstring tok;
00400 const char *ptr;
00401
00402 num_interfaces = 1;
00403
00404 for (ptr=ports; next_token(&ptr, tok, " \t,", sizeof(tok)); ) {
00405 unsigned port = atoi(tok);
00406 if (port == 0 || port > 0xffff) continue;
00407
00408 s = open_socket_in(SOCK_STREAM, port, 0,
00409 interpret_addr(lp_socket_address()),True);
00410 if (s == -1)
00411 return(False);
00412
00413
00414 set_socket_options(s,"SO_KEEPALIVE");
00415 set_socket_options(s,user_socket_options);
00416
00417
00418 set_blocking(s,False);
00419
00420 if (listen(s, SMBD_LISTEN_BACKLOG) == -1) {
00421 DEBUG(0,("open_sockets_smbd: listen: %s\n",
00422 strerror(errno)));
00423 close(s);
00424 return False;
00425 }
00426
00427 fd_listenset[num_sockets] = s;
00428 FD_SET(s,&listen_set);
00429 maxfd = MAX( maxfd, s);
00430
00431 num_sockets++;
00432
00433 if (num_sockets >= FD_SETSIZE) {
00434 DEBUG(0,("open_sockets_smbd: Too many sockets to bind to\n"));
00435 return False;
00436 }
00437 }
00438 }
00439
00440 SAFE_FREE(ports);
00441
00442
00443
00444 message_register(MSG_SMB_SAM_SYNC, msg_sam_sync, NULL);
00445 message_register(MSG_SMB_SAM_REPL, msg_sam_repl, NULL);
00446 message_register(MSG_SHUTDOWN, msg_exit_server, NULL);
00447 message_register(MSG_SMB_FILE_RENAME, msg_file_was_renamed, NULL);
00448 message_register(MSG_SMB_CONF_UPDATED, smb_conf_updated, NULL);
00449 message_register(MSG_SMB_STAT_CACHE_DELETE, smb_stat_cache_delete,
00450 NULL);
00451
00452 #ifdef DEVELOPER
00453 message_register(MSG_SMB_INJECT_FAULT, msg_inject_fault, NULL);
00454 #endif
00455
00456
00457
00458 DEBUG(2,("waiting for a connection\n"));
00459 while (1) {
00460 fd_set lfds;
00461 int num;
00462
00463
00464 lp_TALLOC_FREE();
00465
00466
00467 message_dispatch();
00468
00469 if (got_sig_cld) {
00470 pid_t pid;
00471 got_sig_cld = False;
00472
00473 while ((pid = sys_waitpid(-1, NULL, WNOHANG)) > 0) {
00474 remove_child_pid(pid);
00475 }
00476 }
00477
00478 memcpy((char *)&lfds, (char *)&listen_set,
00479 sizeof(listen_set));
00480
00481 num = sys_select(maxfd+1,&lfds,NULL,NULL,NULL);
00482
00483 if (num == -1 && errno == EINTR) {
00484 if (got_sig_term) {
00485 exit_server_cleanly(NULL);
00486 }
00487
00488
00489 if (reload_after_sighup) {
00490 change_to_root_user();
00491 DEBUG(1,("Reloading services after SIGHUP\n"));
00492 reload_services(False);
00493 reload_after_sighup = 0;
00494 }
00495
00496 continue;
00497 }
00498
00499
00500 check_reload(time(NULL));
00501
00502
00503
00504 for( ; num > 0; num--) {
00505 struct sockaddr addr;
00506 socklen_t in_addrlen = sizeof(addr);
00507 pid_t child = 0;
00508
00509 s = -1;
00510 for(i = 0; i < num_sockets; i++) {
00511 if(FD_ISSET(fd_listenset[i],&lfds)) {
00512 s = fd_listenset[i];
00513
00514
00515 FD_CLR(fd_listenset[i],&lfds);
00516 break;
00517 }
00518 }
00519
00520 smbd_set_server_fd(accept(s,&addr,&in_addrlen));
00521
00522 if (smbd_server_fd() == -1 && errno == EINTR)
00523 continue;
00524
00525 if (smbd_server_fd() == -1) {
00526 DEBUG(0,("open_sockets_smbd: accept: %s\n",
00527 strerror(errno)));
00528 continue;
00529 }
00530
00531
00532 set_blocking(smbd_server_fd(),True);
00533
00534 if (smbd_server_fd() != -1 && interactive)
00535 return True;
00536
00537 if (allowable_number_of_smbd_processes() &&
00538 smbd_server_fd() != -1 &&
00539 ((child = sys_fork())==0)) {
00540
00541
00542
00543
00544 CatchChild();
00545
00546
00547 for(i = 0; i < num_sockets; i++)
00548 close(fd_listenset[i]);
00549
00550
00551
00552 close_low_fds(False);
00553 am_parent = 0;
00554
00555 set_socket_options(smbd_server_fd(),"SO_KEEPALIVE");
00556 set_socket_options(smbd_server_fd(),user_socket_options);
00557
00558
00559
00560 set_remote_machine_name(get_peer_addr(smbd_server_fd()),
00561 False);
00562
00563
00564
00565
00566
00567
00568 set_need_random_reseed();
00569
00570
00571 if (tdb_reopen_all(1) == -1) {
00572 DEBUG(0,("tdb_reopen_all failed.\n"));
00573 smb_panic("tdb_reopen_all failed.");
00574 }
00575
00576 return True;
00577 }
00578
00579 close(smbd_server_fd());
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589 smbd_set_server_fd(-1);
00590
00591 if (child != 0) {
00592 add_child_pid(child);
00593 }
00594
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609 force_check_log_size();
00610
00611 }
00612 }
00613
00614
00615 }
00616
00617
00618
00619
00620 void reload_printers(void)
00621 {
00622 int snum;
00623 int n_services = lp_numservices();
00624 int pnum = lp_servicenumber(PRINTERS_NAME);
00625 const char *pname;
00626
00627 pcap_cache_reload();
00628
00629
00630 for (snum = 0; snum < n_services; snum++) {
00631
00632 if (snum == pnum || !(lp_snum_ok(snum) && lp_print_ok(snum) &&
00633 lp_autoloaded(snum)))
00634 continue;
00635
00636 pname = lp_printername(snum);
00637 if (!pcap_printername_ok(pname)) {
00638 DEBUG(3, ("removing stale printer %s\n", pname));
00639
00640 if (is_printer_published(NULL, snum, NULL))
00641 nt_printer_publish(NULL, snum, SPOOL_DS_UNPUBLISH);
00642 del_a_printer(pname);
00643 lp_killservice(snum);
00644 }
00645 }
00646
00647 load_printers();
00648 }
00649
00650
00651
00652
00653
00654 BOOL reload_services(BOOL test)
00655 {
00656 BOOL ret;
00657
00658 if (lp_loaded()) {
00659 pstring fname;
00660 pstrcpy(fname,lp_configfile());
00661 if (file_exist(fname, NULL) &&
00662 !strcsequal(fname, dyn_CONFIGFILE)) {
00663 pstrcpy(dyn_CONFIGFILE, fname);
00664 test = False;
00665 }
00666 }
00667
00668 reopen_logs();
00669
00670 if (test && !lp_file_list_changed())
00671 return(True);
00672
00673 lp_killunused(conn_snum_used);
00674
00675 ret = lp_load(dyn_CONFIGFILE, False, False, True, True);
00676
00677 reload_printers();
00678
00679
00680 if (!test)
00681 reload_services(True);
00682
00683 reopen_logs();
00684
00685 load_interfaces();
00686
00687 if (smbd_server_fd() != -1) {
00688 set_socket_options(smbd_server_fd(),"SO_KEEPALIVE");
00689 set_socket_options(smbd_server_fd(), user_socket_options);
00690 }
00691
00692 mangle_reset_cache();
00693 reset_stat_cache();
00694
00695
00696 set_current_service(NULL,0,True);
00697
00698 return(ret);
00699 }
00700
00701
00702
00703
00704
00705
00706 enum server_exit_reason { SERVER_EXIT_NORMAL, SERVER_EXIT_ABNORMAL };
00707
00708 static void exit_server_common(enum server_exit_reason how,
00709 const char *const reason) NORETURN_ATTRIBUTE;
00710
00711 static void exit_server_common(enum server_exit_reason how,
00712 const char *const reason)
00713 {
00714 static int firsttime=1;
00715
00716 if (!firsttime)
00717 exit(0);
00718 firsttime = 0;
00719
00720 change_to_root_user();
00721
00722 if (negprot_global_auth_context) {
00723 (negprot_global_auth_context->free)(&negprot_global_auth_context);
00724 }
00725
00726 conn_close_all();
00727
00728 invalidate_all_vuids();
00729
00730 print_notify_send_messages(3);
00731
00732
00733 yield_connection(NULL,"");
00734
00735 respond_to_all_remaining_local_messages();
00736
00737 #ifdef WITH_DFS
00738 if (dcelogin_atmost_once) {
00739 dfs_unlogin();
00740 }
00741 #endif
00742
00743 locking_end();
00744 printing_end();
00745
00746 if (how != SERVER_EXIT_NORMAL) {
00747 int oldlevel = DEBUGLEVEL;
00748 char *last_inbuf = get_InBuffer();
00749
00750 DEBUGLEVEL = 10;
00751
00752 DEBUGSEP(0);
00753 DEBUG(0,("Abnormal server exit: %s\n",
00754 reason ? reason : "no explanation provided"));
00755 DEBUGSEP(0);
00756
00757 log_stack_trace();
00758 if (last_inbuf) {
00759 DEBUG(0,("Last message was %s\n", LAST_MESSAGE()));
00760 show_msg(last_inbuf);
00761 }
00762
00763 DEBUGLEVEL = oldlevel;
00764 dump_core();
00765
00766 } else {
00767 DEBUG(3,("Server exit (%s)\n",
00768 (reason ? reason : "normal exit")));
00769 }
00770
00771 exit(0);
00772 }
00773
00774 void exit_server(const char *const explanation)
00775 {
00776 exit_server_common(SERVER_EXIT_ABNORMAL, explanation);
00777 }
00778
00779 void exit_server_cleanly(const char *const explanation)
00780 {
00781 exit_server_common(SERVER_EXIT_NORMAL, explanation);
00782 }
00783
00784 void exit_server_fault(void)
00785 {
00786 exit_server("critical server fault");
00787 }
00788
00789
00790
00791
00792
00793 static BOOL init_structs(void )
00794 {
00795
00796
00797
00798
00799
00800 if (!init_names())
00801 return False;
00802
00803 conn_init();
00804
00805 file_init();
00806
00807
00808 init_rpc_pipe_hnd();
00809
00810 init_dptrs();
00811
00812 secrets_init();
00813
00814 return True;
00815 }
00816
00817
00818
00819
00820
00821
00822
00823
00824
00825 extern void build_options(BOOL screen);
00826
00827 int main(int argc,const char *argv[])
00828 {
00829
00830 static BOOL is_daemon = False;
00831 static BOOL interactive = False;
00832 static BOOL Fork = True;
00833 static BOOL no_process_group = False;
00834 static BOOL log_stdout = False;
00835 static char *ports = NULL;
00836 static char *profile_level = NULL;
00837 int opt;
00838 poptContext pc;
00839
00840 struct poptOption long_options[] = {
00841 POPT_AUTOHELP
00842 {"daemon", 'D', POPT_ARG_VAL, &is_daemon, True, "Become a daemon (default)" },
00843 {"interactive", 'i', POPT_ARG_VAL, &interactive, True, "Run interactive (not a daemon)"},
00844 {"foreground", 'F', POPT_ARG_VAL, &Fork, False, "Run daemon in foreground (for daemontools, etc.)" },
00845 {"no-process-group", '\0', POPT_ARG_VAL, &no_process_group, True, "Don't create a new process group" },
00846 {"log-stdout", 'S', POPT_ARG_VAL, &log_stdout, True, "Log to stdout" },
00847 {"build-options", 'b', POPT_ARG_NONE, NULL, 'b', "Print build options" },
00848 {"port", 'p', POPT_ARG_STRING, &ports, 0, "Listen on the specified ports"},
00849 {"profiling-level", 'P', POPT_ARG_STRING, &profile_level, 0, "Set profiling level","PROFILE_LEVEL"},
00850 POPT_COMMON_SAMBA
00851 POPT_COMMON_DYNCONFIG
00852 POPT_TABLEEND
00853 };
00854
00855 load_case_tables();
00856
00857 TimeInit();
00858
00859 #ifdef HAVE_SET_AUTH_PARAMETERS
00860 set_auth_parameters(argc,argv);
00861 #endif
00862
00863 pc = poptGetContext("smbd", argc, argv, long_options, 0);
00864
00865 while((opt = poptGetNextOpt(pc)) != -1) {
00866 switch (opt) {
00867 case 'b':
00868 build_options(True);
00869 exit(0);
00870 break;
00871 }
00872 }
00873
00874 poptFreeContext(pc);
00875
00876 #ifdef HAVE_SETLUID
00877
00878 setluid(0);
00879 #endif
00880
00881 sec_init();
00882
00883 set_remote_machine_name("smbd", False);
00884
00885 if (interactive) {
00886 Fork = False;
00887 log_stdout = True;
00888 }
00889
00890 if (interactive && (DEBUGLEVEL >= 9)) {
00891 talloc_enable_leak_report();
00892 }
00893
00894 if (log_stdout && Fork) {
00895 DEBUG(0,("ERROR: Can't log to stdout (-S) unless daemon is in foreground (-F) or interactive (-i)\n"));
00896 exit(1);
00897 }
00898
00899 setup_logging(argv[0],log_stdout);
00900
00901
00902
00903 generate_random_buffer(NULL, 0);
00904
00905
00906
00907
00908 gain_root_privilege();
00909 gain_root_group_privilege();
00910
00911 fault_setup((void (*)(void *))exit_server_fault);
00912 dump_core_setup("smbd");
00913
00914 CatchSignal(SIGTERM , SIGNAL_CAST sig_term);
00915 CatchSignal(SIGHUP,SIGNAL_CAST sig_hup);
00916
00917
00918 BlockSignals(True,SIGPIPE);
00919
00920 #if defined(SIGFPE)
00921
00922 BlockSignals(True,SIGFPE);
00923 #endif
00924
00925 #if defined(SIGUSR2)
00926
00927 BlockSignals(True,SIGUSR2);
00928 #endif
00929
00930
00931
00932 BlockSignals(False, SIGHUP);
00933 BlockSignals(False, SIGUSR1);
00934 BlockSignals(False, SIGTERM);
00935
00936
00937
00938 umask(0);
00939
00940 init_sec_ctx();
00941
00942 reopen_logs();
00943
00944 DEBUG(0,( "smbd version %s started.\n", SAMBA_VERSION_STRING));
00945 DEBUGADD( 0, ( "%s\n", COPYRIGHT_STARTUP_MESSAGE ) );
00946
00947 DEBUG(2,("uid=%d gid=%d euid=%d egid=%d\n",
00948 (int)getuid(),(int)getgid(),(int)geteuid(),(int)getegid()));
00949
00950
00951 build_options(False);
00952
00953 if (sizeof(uint16) < 2 || sizeof(uint32) < 4) {
00954 DEBUG(0,("ERROR: Samba is not configured correctly for the word size on your machine\n"));
00955 exit(1);
00956 }
00957
00958
00959
00960
00961
00962 if (!reload_services(False))
00963 return(-1);
00964
00965 init_structs();
00966
00967 #ifdef WITH_PROFILE
00968 if (!profile_setup(False)) {
00969 DEBUG(0,("ERROR: failed to setup profiling\n"));
00970 return -1;
00971 }
00972 if (profile_level != NULL) {
00973 int pl = atoi(profile_level);
00974 struct process_id src;
00975
00976 DEBUG(1, ("setting profiling level: %s\n",profile_level));
00977 src.pid = getpid();
00978 set_profile_level(pl, src);
00979 }
00980 #endif
00981
00982 DEBUG(3,( "loaded services\n"));
00983
00984 if (!is_daemon && !is_a_socket(0)) {
00985 if (!interactive)
00986 DEBUG(0,("standard input is not a socket, assuming -D option\n"));
00987
00988
00989
00990
00991
00992
00993 is_daemon = True;
00994 }
00995
00996 if (is_daemon && !interactive) {
00997 DEBUG( 3, ( "Becoming a daemon.\n" ) );
00998 become_daemon(Fork, no_process_group);
00999 }
01000
01001 #if HAVE_SETPGID
01002
01003
01004
01005
01006 if (interactive && !no_process_group)
01007 setpgid( (pid_t)0, (pid_t)0);
01008 #endif
01009
01010 if (!directory_exist(lp_lockdir(), NULL))
01011 mkdir(lp_lockdir(), 0755);
01012
01013 if (is_daemon)
01014 pidfile_create("smbd");
01015
01016
01017 if (!message_init())
01018 exit(1);
01019
01020
01021
01022
01023 if(!initialize_password_db(False))
01024 exit(1);
01025
01026 if (!secrets_init()) {
01027 DEBUG(0, ("ERROR: smbd can not open secrets.tdb\n"));
01028 exit(1);
01029 }
01030
01031 if(!get_global_sam_sid()) {
01032 DEBUG(0,("ERROR: Samba cannot create a SAM SID.\n"));
01033 exit(1);
01034 }
01035
01036 if (!session_init())
01037 exit(1);
01038
01039 if (conn_tdb_ctx() == NULL)
01040 exit(1);
01041
01042 if (!locking_init(0))
01043 exit(1);
01044
01045 namecache_enable();
01046
01047 if (!init_registry())
01048 exit(1);
01049
01050 #if 0
01051 if (!init_svcctl_db())
01052 exit(1);
01053 #endif
01054
01055 if (!print_backend_init())
01056 exit(1);
01057
01058 if (!init_guest_info()) {
01059 DEBUG(0,("ERROR: failed to setup guest info.\n"));
01060 return -1;
01061 }
01062
01063
01064
01065
01066 claim_connection(NULL,"",0,True,FLAG_MSG_GENERAL|FLAG_MSG_SMBD);
01067
01068
01069
01070
01071
01072
01073 if ( is_daemon && !interactive )
01074 start_background_queue();
01075
01076
01077
01078
01079
01080 dmapi_init_session();
01081
01082 if (!open_sockets_smbd(is_daemon, interactive, ports))
01083 exit(1);
01084
01085
01086
01087
01088
01089 static_init_rpc;
01090
01091 init_modules();
01092
01093
01094
01095
01096 if (is_daemon) {
01097 reload_services(True);
01098 }
01099
01100 if (!init_account_policy()) {
01101 DEBUG(0,("Could not open account policy tdb.\n"));
01102 exit(1);
01103 }
01104
01105 if (*lp_rootdir()) {
01106 if (sys_chroot(lp_rootdir()) == 0)
01107 DEBUG(2,("Changed root to %s\n", lp_rootdir()));
01108 }
01109
01110
01111 if (!init_oplocks())
01112 exit(1);
01113
01114
01115 initialize_async_io_handler();
01116
01117
01118 message_register(MSG_SMB_FORCE_TDIS, msg_force_tdis, NULL);
01119
01120 smbd_process();
01121
01122 namecache_shutdown();
01123
01124 exit_server_cleanly(NULL);
01125 return(0);
01126 }