s4:server.c - use always "return" instead of "exit" in the "binary_smbd_main" function
[ira/wip.git] / source4 / smbd / server.c
index a96991e6467c10d93c08f72c84bfc9baccde4b56..91fd5539392d1248916fa3af0b3835a4757df13e 100644 (file)
@@ -31,6 +31,7 @@
 #include "ntvfs/ntvfs.h"
 #include "ntptr/ntptr.h"
 #include "auth/gensec/gensec.h"
+#include "auth/gensec/schannel_state.h"
 #include "smbd/process_model.h"
 #include "param/secrets.h"
 #include "smbd/pidfile.h"
@@ -181,15 +182,20 @@ _NORETURN_ static void max_runtime_handler(struct tevent_context *ev,
 }
 
 /*
-  pre-open the sam ldb to ensure the schema has been loaded. This
-  saves a lot of time in child processes  
+  pre-open the key databases. This saves a lot of time in child
+  processes
  */
-static void prime_samdb_schema(struct tevent_context *event_ctx)
+static void prime_ldb_databases(struct tevent_context *event_ctx)
 {
-       TALLOC_CTX *samdb_context;
-       samdb_context = talloc_new(event_ctx);
-       samdb_connect(samdb_context, event_ctx, cmdline_lp_ctx, system_session(samdb_context, cmdline_lp_ctx));
-       talloc_free(samdb_context);
+       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);
+       schannel_db_connect(db_context, event_ctx, cmdline_lp_ctx);
+
+       /* we deliberately leave these open, which allows them to be
+        * re-used in ldb_wrap_connect() */
 }
 
 
@@ -250,6 +256,7 @@ static int binary_smbd_main(const char *binary_name, int argc, const char *argv[
        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);
@@ -296,7 +303,7 @@ static int binary_smbd_main(const char *binary_name, int argc, const char *argv[
                        fprintf(stderr, "\nInvalid option %s: %s\n\n",
                                  poptBadOption(pc, 0), poptStrerror(opt));
                        poptPrintUsage(pc, stderr, 0);
-                       exit(1);
+                       return 1;
                }
        }
 
@@ -304,7 +311,7 @@ static int binary_smbd_main(const char *binary_name, int argc, const char *argv[
                fprintf(stderr,"\nERROR: "
                          "Option -i|--interactive is not allowed together with -D|--daemon\n\n");
                poptPrintUsage(pc, stderr, 0);
-               exit(1);
+               return 1;
        } else if (!opt_interactive) {
                /* default is --daemon */
                opt_daemon = true;
@@ -320,13 +327,13 @@ 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-2009\n"));
+       DEBUGADD(0,("Copyright Andrew Tridgell and the Samba Team 1992-2010\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"));
                DEBUGADD(0,("sizeof(uint16_t) = %u, sizeof(uint32_t) %u, sizeof(uint64_t) = %u\n",
                            (unsigned int)sizeof(uint16_t), (unsigned int)sizeof(uint32_t), (unsigned int)sizeof(uint64_t)));
-               exit(1);
+               return 1;
        }
 
        if (opt_daemon) {
@@ -346,7 +353,7 @@ static int binary_smbd_main(const char *binary_name, int argc, const char *argv[
         * passdb/secrets.c, and proved that Samba still builds... */
        /* Setup the SECRETS subsystem */
        if (secrets_init(talloc_autofree_context(), cmdline_lp_ctx) == NULL) {
-               exit(1);
+               return 1;
        }
 
        gensec_init(cmdline_lp_ctx); /* FIXME: */
@@ -370,6 +377,9 @@ 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;
@@ -398,7 +408,7 @@ static int binary_smbd_main(const char *binary_name, int argc, const char *argv[
                                 discard_const(binary_name));
        }
 
-       prime_samdb_schema(event_ctx);
+       prime_ldb_databases(event_ctx);
 
        status = setup_parent_messaging(event_ctx, cmdline_lp_ctx);
        if (!NT_STATUS_IS_OK(status)) {
@@ -407,6 +417,7 @@ static int binary_smbd_main(const char *binary_name, int argc, const char *argv[
        }
 
        DEBUG(0,("%s: using '%s' process model\n", binary_name, model));
+
        status = server_service_startup(event_ctx, cmdline_lp_ctx, model, 
                                        lp_server_services(cmdline_lp_ctx));
        if (!NT_STATUS_IS_OK(status)) {
@@ -425,7 +436,7 @@ static int binary_smbd_main(const char *binary_name, int argc, const char *argv[
        return 0;
 }
 
- int main(int argc, const char *argv[])
+int main(int argc, const char *argv[])
 {
        return binary_smbd_main("samba", argc, argv);
 }