param: Add startup checks for valid server role/binary combinations
[ambi/samba-autobuild/.git] / source4 / smbd / server.c
index 6acccd14ae4c9888d00e08647b7c14ba931ea36a..b3d8ae5f5da0681c822f932d26ace1960dcf98a5 100644 (file)
@@ -34,7 +34,7 @@
 #include "libcli/auth/schannel.h"
 #include "smbd/process_model.h"
 #include "param/secrets.h"
-#include "smbd/pidfile.h"
+#include "lib/util/pidfile.h"
 #include "param/param.h"
 #include "dsdb/samdb/samdb.h"
 #include "auth/session.h"
@@ -42,6 +42,7 @@
 #include "librpc/gen_ndr/ndr_irpc.h"
 #include "cluster/cluster.h"
 #include "dynconfig/dynconfig.h"
+#include "lib/util/samba_modules.h"
 
 /*
   recursively delete a directory tree
@@ -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, current ts: %d\n", binary_name, time(NULL)));
+       DEBUG(0,("%s: maximum runtime exceeded - terminating at %llu, current ts: %llu\n",
+                binary_name, (unsigned long long)t.tv_sec, (unsigned long long) time(NULL)));
        exit(0);
 }
 
@@ -219,11 +221,14 @@ static NTSTATUS setup_parent_messaging(struct tevent_context *event_ctx,
        NTSTATUS status;
 
        msg = imessaging_init(talloc_autofree_context(),
-                            lpcfg_imessaging_path(event_ctx, lp_ctx),
-                            cluster_id(0, SAMBA_PARENT_TASKID), event_ctx);
+                             lp_ctx,
+                             cluster_id(0, SAMBA_PARENT_TASKID), event_ctx, false);
        NT_STATUS_HAVE_NO_MEMORY(msg);
 
-       irpc_add_name(msg, "samba");
+       status = irpc_add_name(msg, "samba");
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
+       }
 
        status = IRPC_REGISTER(msg, irpc, SAMBA_TERMINATE,
                               samba_terminate, NULL);
@@ -251,6 +256,8 @@ 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),
@@ -360,7 +367,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-2011\n"));
+       DEBUGADD(0,("Copyright Andrew Tridgell and the Samba Team 1992-2012\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"));
@@ -388,8 +395,8 @@ static int binary_smbd_main(const char *binary_name, int argc, const char *argv[
                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 (lpcfg_server_role(cmdline_lp_ctx) == ROLE_ACTIVE_DIRECTORY_DC) {
+               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);
                }
@@ -438,13 +445,25 @@ 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 %d\n", max_runtime, time(NULL)));
+               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,
                                 discard_const(binary_name));
        }
 
+       if (lpcfg_server_role(cmdline_lp_ctx) != ROLE_ACTIVE_DIRECTORY_DC
+           && !lpcfg_parm_bool(cmdline_lp_ctx, NULL, "server role check", "inhibit", false)
+           && !str_list_check_ci(lpcfg_server_services(cmdline_lp_ctx), "smb") 
+           && !str_list_check_ci(lpcfg_dcerpc_endpoint_servers(cmdline_lp_ctx), "remote")
+           && !str_list_check_ci(lpcfg_dcerpc_endpoint_servers(cmdline_lp_ctx), "mapiproxy")) {
+               DEBUG(0, ("At this time the 'samba' binary should only be used for either:\n"));
+               DEBUGADD(0, ("'server role = active directory domain controller' or to access the ntvfs file server with 'server services = +smb' or the rpc proxy with 'dcerpc endpoint servers = remote'\n"));
+               DEBUGADD(0, ("You should start smbd/nmbd/winbindd instead for domain member and standalone file server tasks\n"));
+               exit(1);
+       };
+
        prime_ldb_databases(event_ctx);
 
        status = setup_parent_messaging(event_ctx, cmdline_lp_ctx);