use WINBIND_DOMAIN_INFO_LEVEL_SEQNUM to get the seqnumber from the domain childs...
authorStefan Metzmacher <metze@sernet.de>
Fri, 14 Dec 2007 13:41:08 +0000 (14:41 +0100)
committerStefan Metzmacher <metze@sernet.de>
Fri, 2 May 2008 14:13:11 +0000 (16:13 +0200)
source/winbindd/winbindd_misc.c

index 665b616dc7162fcce65d61b1580e7cd1c89cf062..214f1c8edbd318ecb64df576a4d374763f8bb706 100644 (file)
@@ -547,15 +547,18 @@ void winbindd_get_domain_info_async(TALLOC_CTX *mem_ctx,
 }
 
 struct sequence_state {
-       TALLOC_CTX *mem_ctx;
        struct winbindd_cli_state *cli_state;
        struct winbindd_domain *domain;
-       struct winbindd_request *request;
-       struct winbindd_response *response;
+       struct winbind_get_domain_info *r;
        char *extra_data;
+       void (*recv_fn)(void *priv, bool succ,
+                       struct winbind_get_domain_info *r);
 };
 
-static void sequence_recv(void *private_data, bool success);
+static void sequence_one_recv(void *private_data, bool success,
+                             struct winbind_get_domain_info *r);
+static void sequence_next_recv(void *private_data, bool success,
+                              struct winbind_get_domain_info *r);
 
 void winbindd_show_sequence(struct winbindd_cli_state *state)
 {
@@ -564,76 +567,87 @@ void winbindd_show_sequence(struct winbindd_cli_state *state)
        /* Ensure null termination */
        state->request.domain_name[sizeof(state->request.domain_name)-1]='\0';
 
+       seq = TALLOC_P(state->mem_ctx, struct sequence_state);
+       if (!seq) goto nomem;
+       seq->cli_state = state;
+       seq->extra_data = talloc_strdup(state->mem_ctx, "");
+       if (!seq->extra_data) goto nomem;
+       seq->r = TALLOC_P(seq, struct winbind_get_domain_info);
+       if (!seq->r) goto nomem;
+       seq->r->in.level = TALLOC_P(seq->r, enum winbind_domain_info_level);
+       if (!seq->r->in.level) goto nomem;
+
        if (strlen(state->request.domain_name) > 0) {
-               struct winbindd_domain *domain;
-               domain = find_domain_from_name_noinit(
+               seq->domain = find_domain_from_name_noinit(
                        state->request.domain_name);
-               if (domain == NULL) {
+               if (seq->domain == NULL) {
+                       DEBUG(0,("domain '%s' not found\n",
+                                state->request.domain_name));
                        request_error(state);
                        return;
                }
-               sendto_domain(state, domain);
-               return;
+               seq->recv_fn = sequence_one_recv;
+       } else {
+               seq->domain = domain_list();
+               if (seq->domain == NULL) {
+                       DEBUG(0, ("domain list empty\n"));
+                       request_error(state);
+                       return;
+               }
+               seq->recv_fn = sequence_next_recv;
        }
 
-       /* Ask all domains in sequence, collect the results in sequence_recv */
+       *seq->r->in.level       = WINBIND_DOMAIN_INFO_LEVEL_SEQNUM;
+       seq->r->in.domain_name  = seq->domain->name;
+       seq->r->in.dc_name      = NULL;
 
-       seq = TALLOC_P(state->mem_ctx, struct sequence_state);
-       if (seq == NULL) {
-               DEBUG(0, ("talloc failed\n"));
-               request_error(state);
-               return;
-       }
+       winbindd_get_domain_info_async(seq, seq->domain, seq->r,
+                                      seq->recv_fn, seq);
+       return;
+nomem:
+       request_error(state);
+       return;
+}
 
-       seq->mem_ctx = state->mem_ctx;
-       seq->cli_state = state;
-       seq->domain = domain_list();
-       if (seq->domain == NULL) {
-               DEBUG(0, ("domain list empty\n"));
-               request_error(state);
-               return;
-       }
-       seq->request = TALLOC_ZERO_P(state->mem_ctx,
-                                    struct winbindd_request);
-       seq->response = TALLOC_ZERO_P(state->mem_ctx,
-                                     struct winbindd_response);
-       seq->extra_data = talloc_strdup(state->mem_ctx, "");
+static void sequence_one_recv(void *private_data, bool success,
+                             struct winbind_get_domain_info *r)
+{
+       struct sequence_state *state = talloc_get_type_abort(private_data,
+                                      struct sequence_state);
 
-       if ((seq->request == NULL) || (seq->response == NULL) ||
-           (seq->extra_data == NULL)) {
-               DEBUG(0, ("talloc failed\n"));
-               request_error(state);
+       if (!success) {
+               request_error(state->cli_state);
                return;
        }
 
-       seq->request->length = sizeof(*seq->request);
-       seq->request->cmd = WINBINDD_SHOW_SEQUENCE;
-       fstrcpy(seq->request->domain_name, seq->domain->name);
+       state->cli_state->response.data.sequence_number =
+               state->r->out.domain_info->seqnum;
 
-       async_domain_request(state->mem_ctx, seq->domain,
-                            seq->request, seq->response,
-                            sequence_recv, seq);
+       request_ok(state->cli_state);
 }
 
-static void sequence_recv(void *private_data, bool success)
+static void sequence_next_recv(void *private_data, bool success,
+                              struct winbind_get_domain_info *r)
 {
-       struct sequence_state *state =
-               (struct sequence_state *)private_data;
-       uint32 seq = DOM_SEQUENCE_NONE;
+       struct sequence_state *state = talloc_get_type_abort(private_data,
+                                      struct sequence_state);
+       uint64_t seq = DOM_SEQUENCE_NONE;
 
-       if ((success) && (state->response->result == WINBINDD_OK))
-               seq = state->response->data.sequence_number;
+       if (success) {
+               seq = state->r->out.domain_info->seqnum;
+       }
 
        if (seq == DOM_SEQUENCE_NONE) {
-               state->extra_data = talloc_asprintf(state->mem_ctx,
+               state->extra_data = talloc_asprintf(state,
                                                    "%s%s : DISCONNECTED\n",
                                                    state->extra_data,
                                                    state->domain->name);
        } else {
-               state->extra_data = talloc_asprintf(state->mem_ctx,
-                                                   "%s%s : %d\n",
+               state->extra_data = talloc_asprintf(state,
+                                                   "%s%s : %lld\n",
                                                    state->extra_data,
-                                                   state->domain->name, seq);
+                                                   state->domain->name,
+                                                   (unsigned long long)seq);
        }
 
        state->domain->sequence_number = seq;
@@ -652,10 +666,12 @@ static void sequence_recv(void *private_data, bool success)
        }
 
        /* Ask the next domain */
-       fstrcpy(state->request->domain_name, state->domain->name);
-       async_domain_request(state->mem_ctx, state->domain,
-                            state->request, state->response,
-                            sequence_recv, state);
+       *state->r->in.level     = WINBIND_DOMAIN_INFO_LEVEL_SEQNUM;
+       state->r->in.domain_name= state->domain->name;
+       state->r->in.dc_name    = NULL;
+
+       winbindd_get_domain_info_async(state, state->domain, state->r,
+                                      state->recv_fn, state);
 }
 
 /* This is the child-only version of --sequence. It only allows for a single