lib/util Rename samba_init_module_fns_run -> samba_module_init_fns_run
[kai/samba.git] / source4 / smbd / server.c
index 60269d003e76b8e30771a354b4a50a3e5013a7ce..6df55b88b609711b045e34ac213de9c441d07340 100644 (file)
@@ -42,6 +42,7 @@
 #include "librpc/gen_ndr/ndr_irpc.h"
 #include "cluster/cluster.h"
 #include "dynconfig/dynconfig.h"
+#include "lib/util/samba_module.h"
 
 /*
   recursively delete a directory tree
@@ -117,7 +118,7 @@ static void sig_term(int sig)
        }
 #endif
        DEBUG(0,("Exiting pid %d on SIGTERM\n", (int)getpid()));
-       exit(0);
+       exit(127);
 }
 
 /*
@@ -178,7 +179,8 @@ _NORETURN_ static void max_runtime_handler(struct tevent_context *ev,
                                           struct timeval t, void *private_data)
 {
        const char *binary_name = (const char *)private_data;
-       DEBUG(0,("%s: maximum runtime exceeded - terminating\n", binary_name));
+       DEBUG(0,("%s: maximum runtime exceeded - terminating, current ts: %llu\n",
+             binary_name, (unsigned long long) time(NULL)));
        exit(0);
 }
 
@@ -191,8 +193,8 @@ static void prime_ldb_databases(struct tevent_context *event_ctx)
        TALLOC_CTX *db_context;
        db_context = talloc_new(event_ctx);
 
-       samdb_connect(db_context, event_ctx, cmdline_lp_ctx, system_session(cmdline_lp_ctx));
-       privilege_connect(db_context, event_ctx, cmdline_lp_ctx);
+       samdb_connect(db_context, event_ctx, cmdline_lp_ctx, system_session(cmdline_lp_ctx), 0);
+       privilege_connect(db_context, cmdline_lp_ctx);
 
        /* we deliberately leave these open, which allows them to be
         * re-used in ldb_wrap_connect() */
@@ -215,12 +217,12 @@ static NTSTATUS samba_terminate(struct irpc_message *msg,
 static NTSTATUS setup_parent_messaging(struct tevent_context *event_ctx, 
                                       struct loadparm_context *lp_ctx)
 {
-       struct messaging_context *msg;
+       struct imessaging_context *msg;
        NTSTATUS status;
 
-       msg = messaging_init(talloc_autofree_context(), 
-                            lpcfg_messaging_path(event_ctx, lp_ctx),
-                            cluster_id(0, SAMBA_PARENT_TASKID), event_ctx);
+       msg = imessaging_init(talloc_autofree_context(),
+                             lp_ctx,
+                             cluster_id(0, SAMBA_PARENT_TASKID), event_ctx, false);
        NT_STATUS_HAVE_NO_MEMORY(msg);
 
        irpc_add_name(msg, "samba");
@@ -251,9 +253,12 @@ static void show_build(void)
                CONFIG_OPTION(DATADIR),
                CONFIG_OPTION(MODULESDIR),
                CONFIG_OPTION(LOCKDIR),
+               CONFIG_OPTION(STATEDIR),
+               CONFIG_OPTION(CACHEDIR),
                CONFIG_OPTION(PIDDIR),
                CONFIG_OPTION(PRIVATE_DIR),
                CONFIG_OPTION(SWATDIR),
+               CONFIG_OPTION(CODEPAGEDIR),
                CONFIG_OPTION(SETUPDIR),
                CONFIG_OPTION(WINBINDD_SOCKET_DIR),
                CONFIG_OPTION(WINBINDD_PRIVILEGED_SOCKET_DIR),
@@ -262,6 +267,7 @@ static void show_build(void)
        };
        int i;
 
+       printf("Samba version: %s\n", SAMBA_VERSION_STRING);
        printf("Build environment:\n");
 #ifdef BUILD_SYSTEM
        printf("   Build host:  %s\n", BUILD_SYSTEM);
@@ -284,24 +290,10 @@ static int binary_smbd_main(const char *binary_name, int argc, const char *argv[
        bool opt_interactive = false;
        int opt;
        poptContext pc;
-       extern NTSTATUS server_service_wrepl_init(void);
-       extern NTSTATUS server_service_kdc_init(void);
-       extern NTSTATUS server_service_ldap_init(void);
-       extern NTSTATUS server_service_web_init(void);
-       extern NTSTATUS server_service_ldap_init(void);
-       extern NTSTATUS server_service_winbind_init(void);
-       extern NTSTATUS server_service_nbtd_init(void);
-       extern NTSTATUS server_service_auth_init(void);
-       extern NTSTATUS server_service_cldapd_init(void);
-       extern NTSTATUS server_service_smb_init(void);
-       extern NTSTATUS server_service_drepl_init(void);
-       extern NTSTATUS server_service_kcc_init(void);
-       extern NTSTATUS server_service_dnsupdate_init(void);
-       extern NTSTATUS server_service_rpc_init(void);
-       extern NTSTATUS server_service_ntp_signd_init(void);
-       extern NTSTATUS server_service_samba3_smb_init(void);
-       init_module_fn static_init[] = { STATIC_service_MODULES };
-       init_module_fn *shared_init;
+#define _MODULE_PROTO(init) extern NTSTATUS init(void);
+       STATIC_service_MODULES_PROTO;
+       samba_module_init_fn static_init[] = { STATIC_service_MODULES };
+       samba_module_init_fn *shared_init;
        struct tevent_context *event_ctx;
        uint16_t stdin_event_flags;
        NTSTATUS status;
@@ -372,7 +364,7 @@ static int binary_smbd_main(const char *binary_name, int argc, const char *argv[
        umask(0);
 
        DEBUG(0,("%s version %s started.\n", binary_name, SAMBA_VERSION_STRING));
-       DEBUGADD(0,("Copyright Andrew Tridgell and the Samba Team 1992-2010\n"));
+       DEBUGADD(0,("Copyright Andrew Tridgell and the Samba Team 1992-2011\n"));
 
        if (sizeof(uint16_t) < 2 || sizeof(uint32_t) < 4 || sizeof(uint64_t) < 8) {
                DEBUG(0,("ERROR: Samba is not configured correctly for the word size on your machine\n"));
@@ -394,23 +386,22 @@ static int binary_smbd_main(const char *binary_name, int argc, const char *argv[
 
        pidfile_create(lpcfg_piddir(cmdline_lp_ctx), binary_name);
 
-       /* Do *not* remove this, until you have removed
-        * passdb/secrets.c, and proved that Samba still builds... */
-       /* Setup the SECRETS subsystem */
-       if (secrets_init(talloc_autofree_context(), cmdline_lp_ctx) == NULL) {
+       /* Set up a database to hold a random seed, in case we don't
+        * have /dev/urandom */
+       if (!randseed_init(talloc_autofree_context(), cmdline_lp_ctx)) {
                return 1;
        }
 
        if (lpcfg_server_role(cmdline_lp_ctx) == ROLE_DOMAIN_CONTROLLER) {
-               if (!open_schannel_session_store(talloc_autofree_context(), lpcfg_private_dir(cmdline_lp_ctx))) {
+               if (!open_schannel_session_store(talloc_autofree_context(), cmdline_lp_ctx)) {
                        DEBUG(0,("ERROR: Samba cannot open schannel store for secured NETLOGON operations.\n"));
                        exit(1);
                }
        }
 
-       gensec_init(cmdline_lp_ctx); /* FIXME: */
+       gensec_init(); /* FIXME: */
 
-       ntptr_init(cmdline_lp_ctx);     /* FIXME: maybe run this in the initialization function 
+       ntptr_init();   /* FIXME: maybe run this in the initialization function 
                                                of the spoolss RPC server instead? */
 
        ntvfs_init(cmdline_lp_ctx);     /* FIXME: maybe run this in the initialization functions 
@@ -418,10 +409,10 @@ static int binary_smbd_main(const char *binary_name, int argc, const char *argv[
 
        process_model_init(cmdline_lp_ctx); 
 
-       shared_init = load_samba_modules(NULL, cmdline_lp_ctx, "service");
+       shared_init = samba_modules_load(NULL, "service");
 
-       run_init_functions(static_init);
-       run_init_functions(shared_init);
+       samba_module_init_fns_run(static_init);
+       samba_module_init_fns_run(shared_init);
 
        talloc_free(shared_init);
        
@@ -429,9 +420,6 @@ static int binary_smbd_main(const char *binary_name, int argc, const char *argv[
           should hang off that */
        event_ctx = s4_event_context_init(talloc_autofree_context());
 
-       /* setup this as the default context */
-       s4_event_context_set_default(event_ctx);
-
        if (event_ctx == NULL) {
                DEBUG(0,("Initializing event context failed\n"));
                return 1;
@@ -454,6 +442,8 @@ static int binary_smbd_main(const char *binary_name, int argc, const char *argv[
                      discard_const(binary_name));
 
        if (max_runtime) {
+               DEBUG(0,("Called with maxruntime %d - current ts %llu\n",
+                     max_runtime, (unsigned long long) time(NULL)));
                tevent_add_timer(event_ctx, event_ctx,
                                 timeval_current_ofs(max_runtime, 0),
                                 max_runtime_handler,