use the ndr calls in init_child_connection()
authorStefan Metzmacher <metze@sernet.de>
Wed, 12 Sep 2007 12:41:36 +0000 (14:41 +0200)
committerStefan Metzmacher <metze@sernet.de>
Thu, 11 Oct 2007 15:21:48 +0000 (17:21 +0200)
metze

source/winbindd/winbindd_util.c

index d45b8ee..3ec1179 100644 (file)
@@ -516,130 +516,160 @@ void rescan_trusted_domains( void )
 }
 
 struct init_child_state {
-       TALLOC_CTX *mem_ctx;
        struct winbindd_domain *domain;
-       struct winbindd_request *request;
-       struct winbindd_response *response;
-       void (*continuation)(void *private_data, BOOL success);
-       void *private_data;
+       struct winbind_get_domain_info *r1;
+       struct winbind_get_dc_info *r2;
 };
 
-static void init_child_recv(void *private_data, BOOL success);
-static void init_child_getdc_recv(void *private_data, BOOL success);
+static void init_child_getdc_recv(TALLOC_CTX *mem_ctx, BOOL success,
+                                 struct winbindd_ndr_call *call,
+                                 void *private_data,
+                                 void *_caller_cont, void *caller_private);
+static void init_child_recv(TALLOC_CTX *mem_ctx, BOOL success,
+                           struct winbindd_ndr_call *call,
+                           void *private_data,
+                           void *_caller_cont, void *caller_private);
 
 enum winbindd_result init_child_connection(struct winbindd_domain *domain,
-                                          void (*continuation)(void *private_data,
-                                                               BOOL success),
+                                          void (*cont)(void *private_data,
+                                                       BOOL success),
                                           void *private_data)
 {
-       TALLOC_CTX *mem_ctx;
-       struct winbindd_request *request;
-       struct winbindd_response *response;
-       struct init_child_state *state;
-       struct winbindd_domain *request_domain;
+       struct init_child_state *s;
 
-       mem_ctx = talloc_init("init_child_connection");
-       if (mem_ctx == NULL) {
-               DEBUG(0, ("talloc_init failed\n"));
-               return WINBINDD_ERROR;
-       }
+       s = TALLOC_ZERO_P(NULL, struct init_child_state);
+       if (!s) goto nomem;
 
-       request = TALLOC_ZERO_P(mem_ctx, struct winbindd_request);
-       response = TALLOC_P(mem_ctx, struct winbindd_response);
-       state = TALLOC_P(mem_ctx, struct init_child_state);
+       s->domain = domain;
 
-       if ((request == NULL) || (response == NULL) || (state == NULL)) {
-               DEBUG(0, ("talloc failed\n"));
-               TALLOC_FREE(mem_ctx);
-               continuation(private_data, False);
-               return WINBINDD_ERROR;
-       }
+       if (IS_DC || s->domain->primary || s->domain->internal ) {
+               /* The primary domain has to find the DC name itself */
 
-       request->length = sizeof(*request);
+               s->r1 = TALLOC_P(s, struct winbind_get_domain_info);
+               if (!s->r1) goto nomem;
+               s->r1->in.level = TALLOC_P(s->r1,
+                                          enum winbind_domain_info_level);
+               if (!s->r1->in.level) goto nomem;
 
-       state->mem_ctx = mem_ctx;
-       state->domain = domain;
-       state->request = request;
-       state->response = response;
-       state->continuation = continuation;
-       state->private_data = private_data;
+               *s->r1->in.level        = WINBIND_DOMAIN_INFO_LEVEL_COMPAT;
+               s->r1->in.domain_name   = s->domain->name;
+               s->r1->in.dc_name       = NULL;
 
-       if (IS_DC || domain->primary || domain->internal ) {
-               /* The primary domain has to find the DC name itself */
-               request->cmd = WINBINDD_INIT_CONNECTION;
-               fstrcpy(request->domain_name, domain->name);
-               request->data.init_conn.is_primary = domain->internal ? False : True;
-               fstrcpy(request->data.init_conn.dcname, "");
-               async_request(mem_ctx, &domain->child, request, response,
-                             init_child_recv, state);
+               do_async_ndr(s, &s->domain->child,
+                            NDR_WINBIND_GET_DOMAIN_INFO, s->r1,
+                            init_child_recv, s,
+                            cont, private_data);
+               return WINBINDD_PENDING;
+       } else {
+               /* This is *not* the primary domain, let's ask our DC about a DC
+                * name */
+               struct winbindd_domain *request_domain;
+
+               s->r2 = TALLOC_P(s, struct winbind_get_dc_info);
+               if (!s->r2) goto nomem;
+               s->r2->in.level = TALLOC_P(s->r2,
+                                          enum winbind_dc_info_level);
+               if (!s->r2->in.level) goto nomem;
+
+               *s->r2->in.level        = WINBIND_DC_INFO_LEVEL_COMPAT_NT4;
+               s->r2->in.domain_name   = s->domain->name;
+               s->r2->in.dc_name       = NULL;
+
+               request_domain = find_our_domain();
+
+               do_async_ndr_domain(s, request_domain,
+                                   NDR_WINBIND_GET_DC_INFO, s->r2,
+                                   init_child_getdc_recv, s,
+                                   cont, private_data);
                return WINBINDD_PENDING;
        }
 
-       /* This is *not* the primary domain, let's ask our DC about a DC
-        * name */
-
-       request->cmd = WINBINDD_GETDCNAME;
-       fstrcpy(request->domain_name, domain->name);
-
-       request_domain = find_our_domain();
-       async_domain_request(mem_ctx, request_domain, request, response,
-                            init_child_getdc_recv, state);
-       return WINBINDD_PENDING;
+nomem:
+       DEBUG(0, ("talloc failed\n"));
+       cont(private_data, False);
+       TALLOC_FREE(s);
+       return WINBINDD_ERROR;
 }
 
-static void init_child_getdc_recv(void *private_data, BOOL success)
+static void init_child_getdc_recv(TALLOC_CTX *mem_ctx, BOOL success,
+                                 struct winbindd_ndr_call *call,
+                                 void *_s,
+                                 void *_cont, void *private_data)
 {
-       struct init_child_state *state =
-               talloc_get_type_abort(private_data, struct init_child_state);
-       const char *dcname = "";
+       void (*cont)(void *priv, BOOL succ) = (void (*)(void *, BOOL))_cont;
+       struct init_child_state *s =
+               talloc_get_type_abort(_s, struct init_child_state);
+       const char *dcname = NULL;
 
        DEBUG(10, ("Received getdcname response\n"));
 
-       if (success && (state->response->result == WINBINDD_OK)) {
-               dcname = state->response->data.dc_name;
+       /* why not bailing out, on failure...? */
+       if (success && s->r2->out.result == WINBIND_STATUS_OK) {
+               dcname = s->r2->out.dc_info->name;
        }
 
-       state->request->cmd = WINBINDD_INIT_CONNECTION;
-       fstrcpy(state->request->domain_name, state->domain->name);
-       state->request->data.init_conn.is_primary = False;
-       fstrcpy(state->request->data.init_conn.dcname, dcname);
+       s->r1 = TALLOC_P(s, struct winbind_get_domain_info);
+       if (!s->r1) goto nomem;
+       s->r1->in.level = TALLOC_P(s->r1,
+                                  enum winbind_domain_info_level);
+       if (!s->r1->in.level) goto nomem;
+
+       *s->r1->in.level        = WINBIND_DOMAIN_INFO_LEVEL_COMPAT;
+       s->r1->in.domain_name   = s->domain->name;
+       s->r1->in.dc_name       = dcname;
 
-       async_request(state->mem_ctx, &state->domain->child,
-                     state->request, state->response,
-                     init_child_recv, state);
+       do_async_ndr(s, &s->domain->child,
+                    NDR_WINBIND_GET_DOMAIN_INFO, s->r1,
+                    init_child_recv, s,
+                    cont, private_data);
+       return;
+nomem:
+       DEBUG(0, ("talloc failed\n"));
+       cont(private_data, False);
+       TALLOC_FREE(s);
 }
 
-static void init_child_recv(void *private_data, BOOL success)
+static void init_child_recv(TALLOC_CTX *mem_ctx, BOOL success,
+                           struct winbindd_ndr_call *call,
+                           void *_s,
+                           void *_cont, void *private_data)
 {
-       struct init_child_state *state =
-               talloc_get_type_abort(private_data, struct init_child_state);
+       void (*cont)(void *priv, BOOL succ) = (void (*)(void *, BOOL))_cont;
+       struct init_child_state *s =
+               talloc_get_type_abort(_s, struct init_child_state);
+       struct winbind_domain_info_compat *compat;
 
        DEBUG(5, ("Received child initialization response for domain %s\n",
-                 state->domain->name));
+                 s->domain->name));
 
-       if ((!success) || (state->response->result != WINBINDD_OK)) {
+       if (!success) {
                DEBUG(3, ("Could not init child\n"));
-               state->continuation(state->private_data, False);
-               talloc_destroy(state->mem_ctx);
-               return;
+               goto failed;
        }
 
-       fstrcpy(state->domain->name,
-               state->response->data.domain_info.name);
-       fstrcpy(state->domain->alt_name,
-               state->response->data.domain_info.alt_name);
-       string_to_sid(&state->domain->sid,
-                     state->response->data.domain_info.sid);
-       state->domain->native_mode =
-               state->response->data.domain_info.native_mode;
-       state->domain->active_directory =
-               state->response->data.domain_info.active_directory;
-
-       init_dc_connection(state->domain);
-
-       if (state->continuation != NULL)
-               state->continuation(state->private_data, True);
-       talloc_destroy(state->mem_ctx);
+       if (s->r1->out.result != WINBIND_STATUS_OK) {
+               DEBUG(3, ("Could not init child:0x%08X\n", s->r1->out.result));
+               goto failed;
+       }
+
+       compat = &s->r1->out.domain_info->compat;
+
+       fstrcpy(s->domain->name, compat->netbios_name);
+       fstrcpy(s->domain->alt_name,
+               compat->dns_name?compat->dns_name:"");
+       /* compat->sid is a [ref] pointer and always valid */
+       s->domain->sid = *compat->sid;
+       s->domain->native_mode = compat->is_native_mode;
+       s->domain->active_directory = compat->is_active_directory;
+
+       init_dc_connection(s->domain);
+
+       cont(private_data, True);
+       TALLOC_FREE(s);
+       return;
+failed:
+       cont(private_data, False);
+       TALLOC_FREE(s);
 }
 
 enum winbindd_result winbindd_dual_init_connection(struct winbindd_domain *domain,