Back-port of Volkers fix.
[samba.git] / source / nsswitch / winbindd_dual.c
index 7df630d6f93e56ed69ffde50f3d344f787b3c7fc..396eca7beb389c181f06b01166b4ed3599f082f4 100644 (file)
@@ -35,7 +35,6 @@
 #define DBGC_CLASS DBGC_WINBIND
 
 extern BOOL override_logfile;
-extern struct winbindd_methods cache_methods;
 
 /* Read some data from a client connection */
 
@@ -103,6 +102,7 @@ struct winbindd_async_request {
        void *private_data;
 };
 
+static void async_request_fail(struct winbindd_async_request *state);
 static void async_main_request_sent(void *private_data, BOOL success);
 static void async_request_sent(void *private_data, BOOL success);
 static void async_reply_recv(void *private_data, BOOL success);
@@ -128,6 +128,7 @@ void async_request(TALLOC_CTX *mem_ctx, struct winbindd_child *child,
 
        state->mem_ctx = mem_ctx;
        state->child = child;
+       state->reply_timeout_event = NULL;
        state->request = request;
        state->response = response;
        state->continuation = continuation;
@@ -147,10 +148,7 @@ static void async_main_request_sent(void *private_data, BOOL success)
 
        if (!success) {
                DEBUG(5, ("Could not send async request\n"));
-
-               state->response->length = sizeof(struct winbindd_response);
-               state->response->result = WINBINDD_ERROR;
-               state->continuation(state->private_data, False);
+               async_request_fail(state);
                return;
        }
 
@@ -527,6 +525,10 @@ void winbind_child_died(pid_t pid)
                return;
        }
 
+       /* This will be re-added in fork_domain_child() */
+
+       DLIST_REMOVE(children, child);
+       
        remove_fd_event(&child->event);
        close(child->event.fd);
        child->event.fd = 0;
@@ -883,6 +885,7 @@ static BOOL fork_domain_child(struct winbindd_child *child)
        int fdpair[2];
        struct winbindd_cli_state state;
        struct winbindd_domain *domain;
+       struct winbindd_domain *primary_domain = NULL;
 
        if (socketpair(AF_UNIX, SOCK_STREAM, 0, fdpair) != 0) {
                DEBUG(0, ("Could not open child pipe: %s\n",
@@ -893,9 +896,6 @@ static BOOL fork_domain_child(struct winbindd_child *child)
        ZERO_STRUCT(state);
        state.pid = sys_getpid();
 
-       /* Stop zombies */
-       CatchChild();
-
        /* Ensure we don't process messages whilst we're
           changing the disposition for the child. */
        message_block();
@@ -924,6 +924,9 @@ static BOOL fork_domain_child(struct winbindd_child *child)
 
        /* Child */
 
+       /* Stop zombies in children */
+       CatchChild();
+
        state.sock = fdpair[0];
        close(fdpair[1]);
 
@@ -962,10 +965,13 @@ static BOOL fork_domain_child(struct winbindd_child *child)
        }
 
        /* Ensure we have no pending check_online events other
-          than one for this domain. */
+          than one for this domain or the primary domain. */
 
        for (domain = domain_list(); domain; domain = domain->next) {
-               if (domain != child->domain) {
+               if (domain->primary) {
+                       primary_domain = domain;
+               }
+               if ((domain != child->domain) && !domain->primary) {
                        TALLOC_FREE(domain->check_online_event);
                }
        }
@@ -982,6 +988,20 @@ static BOOL fork_domain_child(struct winbindd_child *child)
 
                set_domain_online_request(child->domain);
 
+               if (primary_domain != child->domain) {
+                       /* We need to talk to the primary
+                        * domain as well as the trusted
+                        * domain inside a trusted domain
+                        * child.
+                        * See the code in :
+                        * winbindd_dual_pam_auth_samlogon()
+                        * especially the calling of 
+                        * contact_domain = find_our_domain()
+                        * in the non-DC case for details.
+                        */
+                       set_domain_online_request(primary_domain);
+               }
+
                child->lockout_policy_event = event_add_timed(
                        winbind_event_context(), NULL, timeval_zero(),
                        "account_lockout_policy_handler",
@@ -989,15 +1009,6 @@ static BOOL fork_domain_child(struct winbindd_child *child)
                        child);
        }
 
-       /* Special case for Winbindd on a Samba DC,
-        * We want to make sure the child can connect to smbd
-        * but not the main daemon */
-
-       if (child->domain && child->domain->internal && IS_DC) {
-               child->domain->methods = &cache_methods;
-               child->domain->online = False;
-       }
-
        while (1) {
 
                int ret;
@@ -1010,6 +1021,11 @@ static BOOL fork_domain_child(struct winbindd_child *child)
                lp_TALLOC_FREE();
                main_loop_TALLOC_FREE();
 
+               /* check for signals */
+               winbind_check_sigterm(false);
+               winbind_check_sighup(override_logfile ? NULL :
+                       child->logfilename);
+
                run_events(winbind_event_context(), 0, NULL, NULL);
 
                GetTimeOfDay(&now);