Ignore:
Timestamp:
Nov 27, 2012, 4:43:17 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: updated trunk to 3.6.0

Location:
trunk/server
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/server

  • trunk/server/source3/smbd/server.c

    r668 r745  
    2323
    2424#include "includes.h"
     25#include "system/filesys.h"
     26#include "popt_common.h"
     27#include "smbd/smbd.h"
    2528#include "smbd/globals.h"
    26 
    27 static_decl_rpc;
     29#include "registry/reg_init_full.h"
     30#include "libcli/auth/schannel.h"
     31#include "secrets.h"
     32#include "memcache.h"
     33#include "ctdbd_conn.h"
     34#include "printing/printer_list.h"
     35#include "rpc_server/rpc_ep_setup.h"
     36#include "printing/pcap.h"
     37#include "printing.h"
     38#include "serverid.h"
     39#include "passdb.h"
     40#include "auth.h"
     41#include "messages.h"
     42#include "smbprofile.h"
     43
     44extern void start_epmd(struct tevent_context *ev_ctx,
     45                       struct messaging_context *msg_ctx);
     46
     47extern void start_spoolssd(struct event_context *ev_ctx,
     48                           struct messaging_context *msg_ctx);
    2849
    2950#ifdef WITH_DFS
     
    3152#endif /* WITH_DFS */
    3253
    33 int smbd_server_fd(void)
    34 {
    35         return server_fd;
    36 }
    37 
    3854static void smbd_set_server_fd(int fd)
    3955{
    40         server_fd = fd;
    41 }
    42 
    43 int get_client_fd(void)
    44 {
    45         return server_fd;
     56        struct smbd_server_connection *sconn = smbd_server_conn;
     57        char addr[INET6_ADDRSTRLEN];
     58        const char *name;
     59
     60        sconn->sock = fd;
     61
     62        /*
     63         * Initialize sconn->client_id: If we can't find the client's
     64         * name, default to its address.
     65         */
     66
     67        client_addr(fd, sconn->client_id.addr, sizeof(sconn->client_id.addr));
     68
     69        name = client_name(sconn->sock);
     70        if (strcmp(name, "UNKNOWN") != 0) {
     71                name = talloc_strdup(sconn, name);
     72        } else {
     73                name = NULL;
     74        }
     75        sconn->client_id.name =
     76                (name != NULL) ? name : sconn->client_id.addr;
     77
     78        sub_set_socket_ids(sconn->client_id.addr, sconn->client_id.name,
     79                           client_socket_addr(sconn->sock, addr,
     80                                              sizeof(addr)));
    4681}
    4782
    4883struct event_context *smbd_event_context(void)
    4984{
    50         if (!smbd_event_ctx) {
    51                 smbd_event_ctx = event_context_init(talloc_autofree_context());
    52         }
    53         if (!smbd_event_ctx) {
    54                 smb_panic("Could not init smbd event context");
    55         }
    56         return smbd_event_ctx;
    57 }
    58 
    59 struct messaging_context *smbd_messaging_context(void)
    60 {
    61         if (smbd_msg_ctx == NULL) {
    62                 smbd_msg_ctx = messaging_init(talloc_autofree_context(),
    63                                               server_id_self(),
    64                                               smbd_event_context());
    65         }
    66         if (smbd_msg_ctx == NULL) {
    67                 DEBUG(0, ("Could not init smbd messaging context.\n"));
    68         }
    69         return smbd_msg_ctx;
    70 }
    71 
    72 struct memcache *smbd_memcache(void)
    73 {
    74         if (!smbd_memcache_ctx) {
    75                 smbd_memcache_ctx = memcache_init(talloc_autofree_context(),
    76                                                   lp_max_stat_cache_size()*1024);
    77         }
    78         if (!smbd_memcache_ctx) {
    79                 smb_panic("Could not init smbd memcache");
    80         }
    81 
    82         return smbd_memcache_ctx;
     85        return server_event_context();
    8386}
    8487
     
    9396                             DATA_BLOB *data)
    9497{
     98        struct tevent_context *ev_ctx =
     99                talloc_get_type_abort(private_data, struct tevent_context);
     100
    95101        DEBUG(10,("smb_conf_updated: Got message saying smb.conf was "
    96102                  "updated. Reloading.\n"));
    97103        change_to_root_user();
    98         reload_services(False);
    99 }
    100 
     104        reload_services(msg, smbd_server_conn->sock, False);
     105        if (am_parent) {
     106                pcap_cache_reload(ev_ctx, msg,
     107                                  &reload_pcap_change_notify);
     108        }
     109}
     110
     111/*******************************************************************
     112 What to do when printcap is updated.
     113 ********************************************************************/
     114
     115static void smb_pcap_updated(struct messaging_context *msg,
     116                             void *private_data,
     117                             uint32_t msg_type,
     118                             struct server_id server_id,
     119                             DATA_BLOB *data)
     120{
     121        struct tevent_context *ev_ctx =
     122                talloc_get_type_abort(private_data, struct tevent_context);
     123
     124        DEBUG(10,("Got message saying pcap was updated. Reloading.\n"));
     125        change_to_root_user();
     126        reload_printers(ev_ctx, msg);
     127}
    101128
    102129/*******************************************************************
     
    158185
    159186        if (data->length != sizeof(sig)) {
    160                
    161187                DEBUG(0, ("Process %s sent bogus signal injection request\n",
    162188                          procid_str_static(&src)));
     
    240266        DEBUG(1,("Cleaning up brl and lock database after unclean shutdown\n"));
    241267        message_send_all(smbd_messaging_context(), MSG_SMB_UNLOCK, NULL, 0, NULL);
    242         messaging_send_buf(smbd_messaging_context(), procid_self(), 
     268        messaging_send_buf(smbd_messaging_context(), procid_self(),
    243269                                MSG_SMB_BRL_VALIDATE, NULL, 0);
    244270        /* mark the cleanup as having been done */
     
    250276        struct child_pid *child;
    251277        static struct timed_event *cleanup_te;
     278        struct server_id child_id;
    252279
    253280        if (unclean_shutdown) {
     
    256283                   pending locks
    257284                */
    258                 DEBUG(3,(__location__ " Unclean shutdown of pid %u\n", 
     285                DEBUG(3,(__location__ " Unclean shutdown of pid %u\n",
    259286                        (unsigned int)pid));
    260287                if (!cleanup_te) {
     
    263290                        cleanup_te = event_add_timed(smbd_event_context(), NULL,
    264291                                                timeval_current_ofs(cleanup_time, 0),
    265                                                 cleanup_timeout_fn, 
     292                                                cleanup_timeout_fn,
    266293                                                &cleanup_te);
    267294                        DEBUG(1,("Scheduled cleanup of brl and lock database after unclean shutdown\n"));
    268295                }
     296        }
     297
     298        child_id = procid_self(); /* Just initialize pid and potentially vnn */
     299        child_id.pid = pid;
     300
     301        if (!serverid_deregister(child_id)) {
     302                DEBUG(1, ("Could not remove pid %d from serverid.tdb\n",
     303                          (int)pid));
    269304        }
    270305
     
    375410        struct sockaddr_storage addr;
    376411        socklen_t in_addrlen = sizeof(addr);
     412        int fd;
    377413        pid_t pid = 0;
    378 
    379         smbd_set_server_fd(accept(s->fd,(struct sockaddr *)&addr,&in_addrlen));
    380 
    381         if (smbd_server_fd() == -1 && errno == EINTR)
     414        uint64_t unique_id;
     415
     416        fd = accept(s->fd, (struct sockaddr *)(void *)&addr,&in_addrlen);
     417        smbd_set_server_fd(fd);
     418
     419        if (fd == -1 && errno == EINTR)
    382420                return;
    383421
    384         if (smbd_server_fd() == -1) {
     422        if (fd == -1) {
    385423                DEBUG(0,("open_sockets_smbd: accept: %s\n",
    386424                         strerror(errno)));
     
    389427
    390428        if (s->parent->interactive) {
    391                 smbd_process();
     429                smbd_process(smbd_server_conn);
    392430                exit_server_cleanly("end of interactive mode");
    393431                return;
     
    395433
    396434        if (!allowable_number_of_smbd_processes()) {
    397                 close(smbd_server_fd());
     435                close(fd);
    398436                smbd_set_server_fd(-1);
    399437                return;
    400438        }
     439
     440        /*
     441         * Generate a unique id in the parent process so that we use
     442         * the global random state in the parent.
     443         */
     444        generate_random_buffer((uint8_t *)&unique_id, sizeof(unique_id));
    401445
    402446        pid = sys_fork();
    403447        if (pid == 0) {
    404448                NTSTATUS status = NT_STATUS_OK;
     449
    405450                /* Child code ... */
    406451                am_parent = 0;
     452
     453                set_my_unique_id(unique_id);
    407454
    408455                /* Stop zombies, the parent explicitly handles
     
    422469
    423470                status = reinit_after_fork(smbd_messaging_context(),
    424                                            smbd_event_context(), true);
     471                                           smbd_event_context(), procid_self(),
     472                                           true);
    425473                if (!NT_STATUS_IS_OK(status)) {
    426474                        if (NT_STATUS_EQUAL(status,
     
    430478                                goto exit;
    431479                        }
     480                        if (lp_clustering() &&
     481                            NT_STATUS_EQUAL(status,
     482                            NT_STATUS_INTERNAL_DB_ERROR)) {
     483                                DEBUG(1,("child process cannot initialize "
     484                                         "because connection to CTDB "
     485                                         "has failed\n"));
     486                                goto exit;
     487                        }
     488
    432489                        DEBUG(0,("reinit_after_fork() failed\n"));
    433490                        smb_panic("reinit_after_fork() failed");
     
    435492
    436493                smbd_setup_sig_term_handler();
    437                 smbd_setup_sig_hup_handler();
    438 
    439                 smbd_process();
     494                smbd_setup_sig_hup_handler(server_event_context(),
     495                                           server_messaging_context());
     496
     497                if (!serverid_register(procid_self(),
     498                                       FLAG_MSG_GENERAL|FLAG_MSG_SMBD
     499                                       |FLAG_MSG_DBWRAP
     500                                       |FLAG_MSG_PRINT_GENERAL)) {
     501                        exit_server_cleanly("Could not register myself in "
     502                                            "serverid.tdb");
     503                }
     504
     505                smbd_process(smbd_server_conn);
    440506         exit:
    441507                exit_server_cleanly("end of child");
    442508                return;
    443         } else if (pid < 0) {
     509        }
     510
     511        if (pid < 0) {
    444512                DEBUG(0,("smbd_accept_connection: sys_fork() failed: %s\n",
    445513                         strerror(errno)));
     
    447515
    448516        /* The parent doesn't need this socket */
    449         close(smbd_server_fd());
     517        close(fd);
    450518
    451519        /* Sun May 6 18:56:14 2001 ackley@cs.unm.edu:
     
    543611}
    544612
    545 static bool parent_housekeeping_fn(const struct timeval *now, void *private_data)
    546 {
    547         DEBUG(5, ("houskeeping\n"));
    548         /* check if we need to reload services */
    549         check_reload(time(NULL));
     613static bool smbd_parent_housekeeping(const struct timeval *now, void *private_data)
     614{
     615        time_t printcap_cache_time = (time_t)lp_printcap_cache_time();
     616        time_t t = time_mono(NULL);
     617
     618        DEBUG(5, ("parent housekeeping\n"));
     619
     620        /* if periodic printcap rescan is enabled, see if it's time to reload */
     621        if ((printcap_cache_time != 0)
     622         && (t >= (last_printer_reload_time + printcap_cache_time))) {
     623                DEBUG( 3,( "Printcap cache time expired.\n"));
     624                pcap_cache_reload(server_event_context(),
     625                                  smbd_messaging_context(),
     626                                  &reload_pcap_change_notify);
     627                last_printer_reload_time = t;
     628        }
     629
    550630        return true;
    551631}
     
    556636
    557637static bool open_sockets_smbd(struct smbd_parent_context *parent,
     638                              struct messaging_context *msg_ctx,
    558639                              const char *smb_ports)
    559640{
     
    682763           operations until it has gone thru a full startup, which
    683764           includes checking to see that smbd is listening. */
    684         claim_connection(NULL,"",
    685                          FLAG_MSG_GENERAL|FLAG_MSG_SMBD|FLAG_MSG_DBWRAP);
     765
     766        if (!serverid_register(procid_self(),
     767                               FLAG_MSG_GENERAL|FLAG_MSG_SMBD
     768                               |FLAG_MSG_DBWRAP)) {
     769                DEBUG(0, ("open_sockets_smbd: Failed to register "
     770                          "myself in serverid.tdb\n"));
     771                return false;
     772        }
    686773
    687774        if (!(event_add_idle(smbd_event_context(), NULL,
    688775                             timeval_set(SMBD_HOUSEKEEPING_INTERVAL, 0),
    689                              "parent_housekeeping", parent_housekeeping_fn,
    690                              parent))) {
    691                 DEBUG(0, ("Could not add housekeeping event\n"));
    692                 exit(1);
     776                             "parent_housekeeping", smbd_parent_housekeeping,
     777                             NULL))) {
     778                DEBUG(0, ("Could not add parent_housekeeping event\n"));
     779                return false;
    693780        }
    694781
    695782        /* Listen to messages */
    696783
    697         messaging_register(smbd_messaging_context(), NULL,
    698                            MSG_SMB_SAM_SYNC, msg_sam_sync);
    699         messaging_register(smbd_messaging_context(), NULL,
    700                            MSG_SHUTDOWN, msg_exit_server);
    701         messaging_register(smbd_messaging_context(), NULL,
    702                            MSG_SMB_FILE_RENAME, msg_file_was_renamed);
    703         messaging_register(smbd_messaging_context(), NULL,
    704                            MSG_SMB_CONF_UPDATED, smb_conf_updated);
    705         messaging_register(smbd_messaging_context(), NULL,
    706                            MSG_SMB_STAT_CACHE_DELETE, smb_stat_cache_delete);
    707         messaging_register(smbd_messaging_context(), NULL,
    708                            MSG_DEBUG, smbd_msg_debug);
    709         brl_register_msgs(smbd_messaging_context());
     784        messaging_register(msg_ctx, NULL, MSG_SMB_SAM_SYNC, msg_sam_sync);
     785        messaging_register(msg_ctx, NULL, MSG_SHUTDOWN, msg_exit_server);
     786        messaging_register(msg_ctx, NULL, MSG_SMB_FILE_RENAME,
     787                           msg_file_was_renamed);
     788        messaging_register(msg_ctx, server_event_context(), MSG_SMB_CONF_UPDATED,
     789                           smb_conf_updated);
     790        messaging_register(msg_ctx, NULL, MSG_SMB_STAT_CACHE_DELETE,
     791                           smb_stat_cache_delete);
     792        messaging_register(msg_ctx, NULL, MSG_DEBUG, smbd_msg_debug);
     793        messaging_register(msg_ctx, server_event_context(), MSG_PRINTER_PCAP,
     794                           smb_pcap_updated);
     795        brl_register_msgs(msg_ctx);
     796
     797        msg_idmap_register_msgs(msg_ctx);
    710798
    711799#ifdef CLUSTER_SUPPORT
     
    716804
    717805#ifdef DEVELOPER
    718         messaging_register(smbd_messaging_context(), NULL,
    719                            MSG_SMB_INJECT_FAULT, msg_inject_fault);
    720 #endif
    721 
    722         if (dns_port != 0) {
     806        messaging_register(msg_ctx, NULL, MSG_SMB_INJECT_FAULT,
     807                           msg_inject_fault);
     808#endif
     809
     810        if (lp_multicast_dns_register() && (dns_port != 0)) {
    723811#ifdef WITH_DNSSD_SUPPORT
    724812                smbd_setup_mdns_registration(smbd_event_context(),
     
    747835                int ret;
    748836                TALLOC_CTX *frame = talloc_stackframe();
     837
    749838                ret = tevent_loop_once(smbd_event_context());
    750839                if (ret != 0) {
     
    758847}
    759848
    760 /***************************************************************************
    761  purge stale printers and reload from pre-populated pcap cache
    762 ***************************************************************************/
    763 void reload_printers(void)
    764 {
    765         int snum;
    766         int n_services = lp_numservices();
    767         int pnum = lp_servicenumber(PRINTERS_NAME);
    768         const char *pname;
    769 
    770         DEBUG(10, ("reloading printer services from pcap cache\n"));
    771         for (snum = 0; snum < n_services; snum++) {
    772                 /* avoid removing PRINTERS_NAME or non-autoloaded printers */
    773                 if (snum == pnum || !(lp_snum_ok(snum) && lp_print_ok(snum) &&
    774                                       lp_autoloaded(snum)))
    775                         continue;
    776 
    777                 pname = lp_printername(snum);
    778                 if (!pcap_printername_ok(pname)) {
    779                         DEBUG(3, ("removing stale printer %s\n", pname));
    780 
    781                         if (is_printer_published(NULL, snum, NULL))
    782                                 nt_printer_publish(NULL, snum, DSPRINT_UNPUBLISH);
    783                         del_a_printer(pname);
    784                         lp_killservice(snum);
    785                 }
    786         }
    787 
    788         load_printers();
    789 }
    790 
    791 /****************************************************************************
    792  Reload the services file.
    793 **************************************************************************/
    794 
    795 bool reload_services(bool test)
    796 {
    797         bool ret;
    798 
    799         if (lp_loaded()) {
    800                 char *fname = lp_configfile();
    801                 if (file_exist(fname) &&
    802                     !strcsequal(fname, get_dyn_CONFIGFILE())) {
    803                         set_dyn_CONFIGFILE(fname);
    804                         test = False;
    805                 }
    806         }
    807 
    808         reopen_logs();
    809 
    810         if (test && !lp_file_list_changed())
    811                 return(True);
    812 
    813         lp_killunused(conn_snum_used);
    814 
    815         ret = lp_load(get_dyn_CONFIGFILE(), False, False, True, True);
    816 
    817         pcap_cache_reload(&reload_printers);
    818 
    819         /* perhaps the config filename is now set */
    820         if (!test)
    821                 reload_services(True);
    822 
    823         reopen_logs();
    824 
    825         load_interfaces();
    826 
    827         if (smbd_server_fd() != -1) {
    828                 set_socket_options(smbd_server_fd(),"SO_KEEPALIVE");
    829                 set_socket_options(smbd_server_fd(), lp_socket_options());
    830         }
    831 
    832         mangle_reset_cache();
    833         reset_stat_cache();
    834 
    835         /* this forces service parameters to be flushed */
    836         set_current_service(NULL,0,True);
    837 
    838         return(ret);
    839 }
    840 
    841 /****************************************************************************
    842  Exit the server.
    843 ****************************************************************************/
    844 
    845 /* Reasons for shutting down a server process. */
    846 enum server_exit_reason { SERVER_EXIT_NORMAL, SERVER_EXIT_ABNORMAL };
    847 
    848 static void exit_server_common(enum server_exit_reason how,
    849         const char *const reason) _NORETURN_;
    850 
    851 static void exit_server_common(enum server_exit_reason how,
    852         const char *const reason)
    853 {
    854         bool had_open_conn = false;
    855         struct smbd_server_connection *sconn = smbd_server_conn;
    856 
    857         if (!exit_firsttime)
    858                 exit(0);
    859         exit_firsttime = false;
    860 
    861         change_to_root_user();
    862 
    863         if (sconn && sconn->smb1.negprot.auth_context) {
    864                 struct auth_context *a = sconn->smb1.negprot.auth_context;
    865                 a->free(&sconn->smb1.negprot.auth_context);
    866         }
    867 
    868         if (sconn) {
    869                 had_open_conn = conn_close_all(sconn);
    870                 invalidate_all_vuids(sconn);
    871         }
    872 
    873         /* 3 second timeout. */
    874         print_notify_send_messages(smbd_messaging_context(), 3);
    875 
    876         /* delete our entry in the connections database. */
    877         yield_connection(NULL,"");
    878 
    879 #ifdef WITH_DFS
    880         if (dcelogin_atmost_once) {
    881                 dfs_unlogin();
    882         }
    883 #endif
    884 
    885 #ifdef USE_DMAPI
    886         /* Destroy Samba DMAPI session only if we are master smbd process */
    887         if (am_parent) {
    888                 if (!dmapi_destroy_session()) {
    889                         DEBUG(0,("Unable to close Samba DMAPI session\n"));
    890                 }
    891         }
    892 #endif
    893 
    894         locking_end();
    895         printing_end();
    896 
    897         /*
    898          * we need to force the order of freeing the following,
    899          * because smbd_msg_ctx is not a talloc child of smbd_server_conn.
    900          */
    901         sconn = NULL;
    902         TALLOC_FREE(smbd_server_conn);
    903         TALLOC_FREE(smbd_msg_ctx);
    904         TALLOC_FREE(smbd_event_ctx);
    905 
    906         if (how != SERVER_EXIT_NORMAL) {
    907                 int oldlevel = DEBUGLEVEL;
    908 
    909                 DEBUGLEVEL = 10;
    910 
    911                 DEBUGSEP(0);
    912                 DEBUG(0,("Abnormal server exit: %s\n",
    913                         reason ? reason : "no explanation provided"));
    914                 DEBUGSEP(0);
    915 
    916                 log_stack_trace();
    917 
    918                 DEBUGLEVEL = oldlevel;
    919                 dump_core();
    920 
    921         } else {   
    922                 DEBUG(3,("Server exit (%s)\n",
    923                         (reason ? reason : "normal exit")));
    924                 if (am_parent) {
    925                         pidfile_unlink();
    926                 }
    927                 gencache_stabilize();
    928         }
    929 
    930         /* if we had any open SMB connections when we exited then we
    931            need to tell the parent smbd so that it can trigger a retry
    932            of any locks we may have been holding or open files we were
    933            blocking */
    934         if (had_open_conn) {
    935                 exit(1);
    936         } else {
    937                 exit(0);
    938         }
    939 }
    940 
    941 void exit_server(const char *const explanation)
    942 {
    943         exit_server_common(SERVER_EXIT_ABNORMAL, explanation);
    944 }
    945 
    946 void exit_server_cleanly(const char *const explanation)
    947 {
    948         exit_server_common(SERVER_EXIT_NORMAL, explanation);
    949 }
    950 
    951 void exit_server_fault(void)
    952 {
    953         exit_server("critical server fault");
    954 }
    955849
    956850/****************************************************************************
     
    967861        if (!init_names())
    968862                return False;
    969 
    970         file_init();
    971863
    972864        if (!secrets_init())
     
    1021913        };
    1022914        struct smbd_parent_context *parent = NULL;
    1023         TALLOC_CTX *frame = talloc_stackframe(); /* Setup tos. */
     915        TALLOC_CTX *frame;
     916        NTSTATUS status;
     917        uint64_t unique_id;
     918
     919        /*
     920         * Do this before any other talloc operation
     921         */
     922        talloc_enable_null_tracking();
     923        frame = talloc_stackframe();
     924
     925        load_case_tables();
     926
     927        /* Initialize the event context, it will panic on error */
     928        smbd_event_context();
    1024929
    1025930        smbd_init_globals();
     
    1066971        }
    1067972
    1068         setup_logging(argv[0],log_stdout);
     973        if (log_stdout) {
     974                setup_logging(argv[0], DEBUG_STDOUT);
     975        } else {
     976                setup_logging(argv[0], DEBUG_FILE);
     977        }
    1069978
    1070979        if (print_build_options) {
     
    1073982        }
    1074983
    1075         load_case_tables();
    1076 
    1077984#ifdef HAVE_SETLUID
    1078985        /* needed for SecureWare on SCO */
     
    1080987#endif
    1081988
    1082         sec_init();
    1083 
    1084989        set_remote_machine_name("smbd", False);
    1085990
     
    10971002        generate_random_buffer(NULL, 0);
    10981003
     1004        /* get initial effective uid and gid */
     1005        sec_init();
     1006
    10991007        /* make absolutely sure we run as root - to handle cases where people
    11001008           are crazy enough to have it setuid */
    1101 
    11021009        gain_root_privilege();
    11031010        gain_root_group_privilege();
     
    11331040           so set our umask to 0 */
    11341041        umask(0);
    1135 
    1136         init_sec_ctx();
    11371042
    11381043        reopen_logs();
     
    11681073        }
    11691074
     1075        /* Init the security context and global current_user */
     1076        init_sec_ctx();
     1077
    11701078        if (smbd_messaging_context() == NULL)
    11711079                exit(1);
    11721080
    1173         if (!reload_services(False))
    1174                 return(-1);     
     1081        /*
     1082         * Reloading of the printers will not work here as we don't have a
     1083         * server info and rpc services set up. It will be called later.
     1084         */
     1085        if (!reload_services(smbd_messaging_context(), -1, False)) {
     1086                exit(1);
     1087        }
     1088
     1089        /* ...NOTE... Log files are working from this point! */
     1090
     1091        DEBUG(3,("loaded services\n"));
    11751092
    11761093        init_structs();
     
    11911108#endif
    11921109
    1193         DEBUG(3,( "loaded services\n"));
    1194 
    11951110        if (!is_daemon && !is_a_socket(0)) {
    11961111                if (!interactive)
     
    12071122        if (is_daemon && !interactive) {
    12081123                DEBUG( 3, ( "Becoming a daemon.\n" ) );
    1209                 become_daemon(Fork, no_process_group);
    1210         }
     1124                become_daemon(Fork, no_process_group, log_stdout);
     1125        }
     1126
     1127        generate_random_buffer((uint8_t *)&unique_id, sizeof(unique_id));
     1128        set_my_unique_id(unique_id);
    12111129
    12121130#if HAVE_SETPGID
     
    12251143                pidfile_create("smbd");
    12261144
    1227         if (!NT_STATUS_IS_OK(reinit_after_fork(smbd_messaging_context(),
    1228                              smbd_event_context(), false))) {
     1145        status = reinit_after_fork(smbd_messaging_context(),
     1146                                   smbd_event_context(),
     1147                                   procid_self(), false);
     1148        if (!NT_STATUS_IS_OK(status)) {
    12291149                DEBUG(0,("reinit_after_fork() failed\n"));
    12301150                exit(1);
    12311151        }
    12321152
     1153        smbd_server_conn->msg_ctx = smbd_messaging_context();
     1154
    12331155        smbd_setup_sig_term_handler();
    1234         smbd_setup_sig_hup_handler();
     1156        smbd_setup_sig_hup_handler(smbd_event_context(),
     1157                                   smbd_server_conn->msg_ctx);
    12351158
    12361159        /* Setup all the TDB's - including CLEAR_IF_FIRST tdb's. */
     
    12531176        }
    12541177
     1178        if (lp_server_role() == ROLE_DOMAIN_BDC || lp_server_role() == ROLE_DOMAIN_PDC) {
     1179                if (!open_schannel_session_store(NULL, lp_private_dir())) {
     1180                        DEBUG(0,("ERROR: Samba cannot open schannel store for secured NETLOGON operations.\n"));
     1181                        exit(1);
     1182                }
     1183        }
     1184
    12551185        if(!get_global_sam_sid()) {
    12561186                DEBUG(0,("ERROR: Samba cannot create a SAM SID.\n"));
     
    12581188        }
    12591189
    1260         if (!session_init())
    1261                 exit(1);
     1190        if (!sessionid_init()) {
     1191                exit(1);
     1192        }
    12621193
    12631194        if (!connections_init(True))
     
    12671198                exit(1);
    12681199
    1269         namecache_enable();
     1200        if (!messaging_tdb_parent_init(smbd_event_context())) {
     1201                exit(1);
     1202        }
     1203
     1204        if (!notify_internal_parent_init(smbd_event_context())) {
     1205                exit(1);
     1206        }
     1207
     1208        if (!serverid_parent_init(smbd_event_context())) {
     1209                exit(1);
     1210        }
     1211
     1212        if (!printer_list_parent_init()) {
     1213                exit(1);
     1214        }
    12701215
    12711216        if (!W_ERROR_IS_OK(registry_init_full()))
    12721217                exit(1);
    12731218
    1274 #if 0
    1275         if (!init_svcctl_db())
    1276                 exit(1);
    1277 #endif
    1278 
    12791219        if (!print_backend_init(smbd_messaging_context()))
    12801220                exit(1);
    1281 
    1282         if (!init_guest_info()) {
    1283                 DEBUG(0,("ERROR: failed to setup guest info.\n"));
    1284                 return -1;
    1285         }
    12861221
    12871222        /* Open the share_info.tdb here, so we don't have to open
     
    12941229        }
    12951230
     1231        status = init_system_info();
     1232        if (!NT_STATUS_IS_OK(status)) {
     1233                DEBUG(1, ("ERROR: failed to setup system user info: %s.\n",
     1234                          nt_errstr(status)));
     1235                return -1;
     1236        }
     1237
     1238        if (!init_guest_info()) {
     1239                DEBUG(0,("ERROR: failed to setup guest info.\n"));
     1240                return -1;
     1241        }
     1242
     1243        if (!file_init(smbd_server_conn)) {
     1244                DEBUG(0, ("ERROR: file_init failed\n"));
     1245                return -1;
     1246        }
     1247
     1248        if (is_daemon && !interactive) {
     1249                const char *rpcsrv_type;
     1250
     1251                rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
     1252                                                   "rpc_server", "epmapper",
     1253                                                   "none");
     1254                if (StrCaseCmp(rpcsrv_type, "daemon") == 0) {
     1255                        start_epmd(smbd_event_context(),
     1256                                   smbd_server_conn->msg_ctx);
     1257                }
     1258        }
     1259
     1260        if (!dcesrv_ep_setup(smbd_event_context(), smbd_server_conn->msg_ctx)) {
     1261                exit(1);
     1262        }
     1263
     1264        /* Publish nt printers, this requires a working winreg pipe */
     1265        pcap_cache_reload(server_event_context(), smbd_messaging_context(),
     1266                          &reload_printers);
     1267
    12961268        /* only start the background queue daemon if we are
    12971269           running as a daemon -- bad things will happen if
     
    13011273        if (is_daemon && !interactive
    13021274            && lp_parm_bool(-1, "smbd", "backgroundqueue", true)) {
    1303                 start_background_queue();
     1275                start_background_queue(smbd_event_context(),
     1276                                       smbd_messaging_context());
     1277        }
     1278
     1279        if (is_daemon && !_lp_disable_spoolss()) {
     1280                const char *rpcsrv_type;
     1281
     1282                /* start spoolss daemon */
     1283                /* start as a separate daemon only if enabled */
     1284                rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
     1285                                                   "rpc_server", "spoolss",
     1286                                                   "embedded");
     1287                if (StrCaseCmp(rpcsrv_type, "daemon") == 0) {
     1288                        start_spoolssd(smbd_event_context(),
     1289                                       smbd_messaging_context());
     1290                }
    13041291        }
    13051292
     
    13231310                smbd_setup_sig_chld_handler();
    13241311
    1325                 smbd_process();
     1312                smbd_process(smbd_server_conn);
    13261313
    13271314                exit_server_cleanly(NULL);
     
    13351322        parent->interactive = interactive;
    13361323
    1337         if (!open_sockets_smbd(parent, ports))
     1324        if (!open_sockets_smbd(parent, smbd_messaging_context(), ports))
    13381325                exit_server("open_sockets_smbd() failed");
    13391326
Note: See TracChangeset for help on using the changeset viewer.