s3-winbind: avoid talloc_tos in fork_domain_child
authorDavid Disseldorp <ddiss@samba.org>
Tue, 16 Apr 2013 11:11:00 +0000 (13:11 +0200)
committerDavid Disseldorp <ddiss@samba.org>
Tue, 16 Apr 2013 13:51:57 +0000 (15:51 +0200)
In preparation for asynchronous dispatch support, the fork_domain_child
code path should not rely on talloc_tos. This commit also changes the
function to only call winbind_event_context() once after initialisation.

source3/winbindd/winbindd_dual.c

index bcd8c0f46bffbbfa57936d245df5c1a2aae2df05..f4b55643a090ca94da3f6c735a105309292ec29e 100644 (file)
@@ -446,9 +446,6 @@ static void child_process_request(struct winbindd_child *child,
        state->response->result = WINBINDD_ERROR;
        state->response->length = sizeof(struct winbindd_response);
 
-       /* as all requests in the child are sync, we can use talloc_tos() */
-       state->mem_ctx = talloc_tos();
-
        /* Process command */
 
        for (; table->name; table++) {
@@ -1317,6 +1314,7 @@ static bool fork_domain_child(struct winbindd_child *child)
        struct winbindd_domain *primary_domain = NULL;
        NTSTATUS status;
        ssize_t nwritten;
+       struct tevent_context *ev;
 
        if (child->domain) {
                DEBUG(10, ("fork_domain_child called for domain '%s'\n",
@@ -1392,6 +1390,7 @@ static bool fork_domain_child(struct winbindd_child *child)
                          nt_errstr(status)));
                _exit(0);
        }
+       ev = winbind_event_context();
 
        /* Handle online/offline messages. */
        messaging_register(winbind_messaging_context(), NULL,
@@ -1458,7 +1457,7 @@ static bool fork_domain_child(struct winbindd_child *child)
                }
 
                child->lockout_policy_event = event_add_timed(
-                       winbind_event_context(), NULL, timeval_zero(),
+                       ev, NULL, timeval_zero(),
                        account_lockout_policy_handler,
                        child);
        }
@@ -1472,7 +1471,7 @@ static bool fork_domain_child(struct winbindd_child *child)
                if (calculate_next_machine_pwd_change(child->domain->name,
                                                       &next_change)) {
                        child->machine_password_change_event = event_add_timed(
-                               winbind_event_context(), NULL, next_change,
+                               ev, NULL, next_change,
                                machine_password_change_handler,
                                child);
                }
@@ -1486,10 +1485,13 @@ static bool fork_domain_child(struct winbindd_child *child)
                int timeout;
                struct timeval t;
                struct timeval *tp;
-               TALLOC_CTX *frame = talloc_stackframe();
+               TALLOC_CTX *mem_ctx = talloc_new(NULL);
+               if (mem_ctx == NULL) {
+                       _exit(1);
+               }
 
-               if (run_events_poll(winbind_event_context(), 0, NULL, 0)) {
-                       TALLOC_FREE(frame);
+               if (run_events_poll(ev, 0, NULL, 0)) {
+                       TALLOC_FREE(mem_ctx);
                        continue;
                }
 
@@ -1501,7 +1503,7 @@ static bool fork_domain_child(struct winbindd_child *child)
                        child->domain->startup = False;
                }
 
-               pfds = talloc_zero(talloc_tos(), struct pollfd);
+               pfds = talloc_zero(mem_ctx, struct pollfd);
                if (pfds == NULL) {
                        DEBUG(1, ("talloc failed\n"));
                        _exit(1);
@@ -1514,12 +1516,12 @@ static bool fork_domain_child(struct winbindd_child *child)
                timeout = INT_MAX;
 
                if (!event_add_to_poll_args(
-                           winbind_event_context(), talloc_tos(),
+                           ev, mem_ctx,
                            &pfds, &num_pfds, &timeout)) {
                        DEBUG(1, ("event_add_to_poll_args failed\n"));
                        _exit(1);
                }
-               tp = get_timed_events_timeout(winbind_event_context(), &t);
+               tp = get_timed_events_timeout(ev, &t);
                if (tp) {
                        DEBUG(11,("select will use timeout of %u.%u seconds\n",
                                (unsigned int)tp->tv_sec, (unsigned int)tp->tv_usec ));
@@ -1527,10 +1529,10 @@ static bool fork_domain_child(struct winbindd_child *child)
 
                ret = poll(pfds, num_pfds, timeout);
 
-               if (run_events_poll(winbind_event_context(), ret,
+               if (run_events_poll(ev, ret,
                                    pfds, num_pfds)) {
                        /* We got a signal - continue. */
-                       TALLOC_FREE(frame);
+                       TALLOC_FREE(mem_ctx);
                        continue;
                }
 
@@ -1538,19 +1540,19 @@ static bool fork_domain_child(struct winbindd_child *child)
 
                if (ret == 0) {
                        DEBUG(11,("nothing is ready yet, continue\n"));
-                       TALLOC_FREE(frame);
+                       TALLOC_FREE(mem_ctx);
                        continue;
                }
 
                if (ret == -1 && errno == EINTR) {
                        /* We got a signal - continue. */
-                       TALLOC_FREE(frame);
+                       TALLOC_FREE(mem_ctx);
                        continue;
                }
 
                if (ret == -1 && errno != EINTR) {
                        DEBUG(0,("poll error occured\n"));
-                       TALLOC_FREE(frame);
+                       TALLOC_FREE(mem_ctx);
                        perror("poll");
                        _exit(1);
                }
@@ -1567,7 +1569,7 @@ static bool fork_domain_child(struct winbindd_child *child)
 
                ZERO_STRUCTP(state.response);
                state.request->null_term = '\0';
-               state.mem_ctx = frame;
+               state.mem_ctx = mem_ctx;
                child_process_request(child, &state);
 
                DEBUG(4, ("Finished processing child request %d\n",
@@ -1579,7 +1581,7 @@ static bool fork_domain_child(struct winbindd_child *child)
                if (!NT_STATUS_IS_OK(status)) {
                        _exit(1);
                }
-               TALLOC_FREE(frame);
+               TALLOC_FREE(mem_ctx);
        }
 }