smbd/winbindd: Do an early check if ctdbd is functional
[mat/samba.git] / source3 / smbd / server.c
index 8eb3d9ef9330de1bbb299c5d29dcb56f3160d8fd..3536f18cf4983aab738212e5e793fd110f3b242d 100644 (file)
@@ -45,6 +45,7 @@
 #include "lib/conn_tdb.h"
 #include "../lib/util/pidfile.h"
 #include "lib/smbd_shim.h"
+#include "scavenger.h"
 
 struct smbd_open_socket;
 struct smbd_child_pid;
@@ -62,7 +63,7 @@ struct smbd_parent_context {
        struct smbd_child_pid *children;
        size_t num_children;
 
-       struct timed_event *cleanup_te;
+       struct tevent_timer *cleanup_te;
 };
 
 struct smbd_open_socket {
@@ -80,7 +81,7 @@ struct smbd_child_pid {
 extern void start_epmd(struct tevent_context *ev_ctx,
                       struct messaging_context *msg_ctx);
 
-extern void start_lsasd(struct event_context *ev_ctx,
+extern void start_lsasd(struct tevent_context *ev_ctx,
                        struct messaging_context *msg_ctx);
 
 #ifdef WITH_DFS
@@ -282,7 +283,7 @@ static bool smbd_parent_notify_init(TALLOC_CTX *mem_ctx,
 
        state = talloc(mem_ctx, struct smbd_parent_notify_state);
        if (state == NULL) {
-               return NULL;
+               return false;
        }
        state->msg = msg;
        state->ev = ev;
@@ -394,8 +395,8 @@ static void add_child_pid(struct smbd_parent_context *parent,
   network outage).  
 */
 
-static void cleanup_timeout_fn(struct event_context *event_ctx,
-                               struct timed_event *te,
+static void cleanup_timeout_fn(struct tevent_context *event_ctx,
+                               struct tevent_timer *te,
                                struct timeval now,
                                void *private_data)
 {
@@ -551,7 +552,7 @@ static void smbd_accept_connection(struct tevent_context *ev,
                return;
 
        if (fd == -1) {
-               DEBUG(0,("open_sockets_smbd: accept: %s\n",
+               DEBUG(0,("accept: %s\n",
                         strerror(errno)));
                return;
        }
@@ -662,7 +663,6 @@ static void smbd_accept_connection(struct tevent_context *ev,
 
 static bool smbd_open_one_socket(struct smbd_parent_context *parent,
                                 struct tevent_context *ev_ctx,
-                                struct messaging_context *msg_ctx,
                                 const struct sockaddr_storage *ifss,
                                 uint16_t port)
 {
@@ -792,7 +792,6 @@ static bool open_sockets_smbd(struct smbd_parent_context *parent,
 
                                if (!smbd_open_one_socket(parent,
                                                          ev_ctx,
-                                                         msg_ctx,
                                                          ifss,
                                                          port)) {
                                        return false;
@@ -834,7 +833,6 @@ static bool open_sockets_smbd(struct smbd_parent_context *parent,
 
                                if (!smbd_open_one_socket(parent,
                                                          ev_ctx,
-                                                         msg_ctx,
                                                          &ss,
                                                          port)) {
                                        return false;
@@ -1216,6 +1214,17 @@ extern void build_options(bool screen);
                exit(1);
        }
 
+       if (lp_clustering()) {
+               NTSTATUS status;
+
+               status = ctdbd_probe();
+               if (!NT_STATUS_IS_OK(status)) {
+                       DEBUG(0, ("clustering=yes but ctdbd connect failed: "
+                                 "%s\n", nt_errstr(status)));
+                       exit(1);
+               }
+       }
+
        /* Init the security context and global current_user */
        init_sec_ctx();
 
@@ -1398,17 +1407,11 @@ extern void build_options(bool screen);
                exit(1);
        }
 
-       if (!sessionid_init()) {
-               exit(1);
-       }
        status = smbXsrv_session_global_init();
        if (!NT_STATUS_IS_OK(status)) {
                exit(1);
        }
 
-       if (!connections_init(true)) {
-               exit(1);
-       }
        status = smbXsrv_tcon_global_init();
        if (!NT_STATUS_IS_OK(status)) {
                exit(1);
@@ -1425,6 +1428,10 @@ extern void build_options(bool screen);
                exit(1);
        }
 
+       if (!smbd_scavenger_init(NULL, msg_ctx, ev_ctx)) {
+               exit(1);
+       }
+
        if (!serverid_parent_init(ev_ctx)) {
                exit(1);
        }
@@ -1477,7 +1484,7 @@ extern void build_options(bool screen);
                return -1;
        }
 
-       if (!directory_create_or_exist(np_dir, geteuid(), 0700)) {
+       if (!directory_create_or_exist_strict(np_dir, geteuid(), 0700)) {
                DEBUG(0, ("Failed to create pipe directory %s - %s\n",
                          np_dir, strerror(errno)));
                return -1;
@@ -1562,8 +1569,20 @@ extern void build_options(bool screen);
                /* if we are running in the foreground then look for
                   EOF on stdin, and exit if it happens. This allows
                   us to die if the parent process dies
+                  Only do this on a pipe or socket, no other device.
                */
-               tevent_add_fd(ev_ctx, parent, 0, TEVENT_FD_READ, smbd_stdin_handler, NULL);
+               struct stat st;
+               if (fstat(0, &st) != 0) {
+                       return false;
+               }
+               if (S_ISFIFO(st.st_mode) || S_ISSOCK(st.st_mode)) {
+                       tevent_add_fd(ev_ctx,
+                                       parent,
+                                       0,
+                                       TEVENT_FD_READ,
+                                       smbd_stdin_handler,
+                                       NULL);
+               }
        }
 
        smbd_parent_loop(ev_ctx, parent);