wb-ndr: implement WINBIND_LOOKUP_LEVEL_EXPANDALIASES
authorStefan Metzmacher <metze@sernet.de>
Tue, 11 Mar 2008 18:41:45 +0000 (19:41 +0100)
committerStefan Metzmacher <metze@sernet.de>
Fri, 2 May 2008 14:13:36 +0000 (16:13 +0200)
metze

source/winbindd/winbindd_async.c

index faaeccd9b7cb1ea0fc65281480b330fbe7637901..e5f23f196c2fa2864c540c9f055c1330a24a30d0 100644 (file)
@@ -523,6 +523,85 @@ static void ndr_child_lookup_sid2domgroups(struct winbindd_domain *domain,
        r->out.result = WINBIND_STATUS_OK;
 }
 
+static void ndr_child_lookup_expandaliases(struct winbindd_domain *domain,
+                                          struct winbindd_cli_state *state,
+                                          struct winbind_lookup *r)
+{
+       NTSTATUS status;
+       uint32_t i;
+       uint32_t num_sids = 0;
+       struct dom_sid *sids = NULL;
+       uint32_t num_aliases = 0;
+       uint32_t *alias_rids = NULL;
+       struct winbind_lookup_sid_info *a;
+
+       DEBUG(3, ("lookup expandaliases\n"));
+
+       for (i=0; i < r->in.req.sid_array.num_sids; i++) {
+               status = add_sid_to_array(state->mem_ctx,
+                                         r->in.req.sid_array.sids[i].sid,
+                                         &sids, &num_sids);
+               if (!NT_STATUS_IS_OK(status)) {
+                       DEBUG(1, ("error copying sid %s: %s\n",
+                                 sid_string_dbg(r->in.req.sid_array.sids[i].sid),
+                                 nt_errstr(status)));
+                       r->out.result = WINBIND_STATUS_FOOBAR;
+                       return;
+               }
+       }
+
+       status = domain->methods->lookup_useraliases(domain,
+                                                    state->mem_ctx,
+                                                    num_sids,
+                                                    sids,
+                                                    &num_aliases,
+                                                    &alias_rids);
+       TALLOC_FREE(sids);
+       if (!NT_STATUS_IS_OK(status)) {
+               DEBUG(3, ("Could not lookup_useraliases: %s\n",
+                         nt_errstr(status)));
+               r->out.result = WINBIND_STATUS_FOOBAR;
+               return;
+       }
+
+       num_sids = 0;
+
+       DEBUG(10, ("Got %d aliases\n", num_aliases));
+
+       for (i=0; i<num_aliases; i++) {
+               DOM_SID sid;
+               DEBUGADD(10, (" rid %d\n", alias_rids[i]));
+               sid_copy(&sid, &domain->sid);
+               sid_append_rid(&sid, alias_rids[i]);
+               status = add_sid_to_array(state->mem_ctx, &sid, &sids,
+                                         &num_sids);
+               if (!NT_STATUS_IS_OK(status)) {
+                       DEBUG(1, ("error copying sid %s: %s\n",
+                                 sid_string_dbg(r->in.req.sid_array.sids[i].sid),
+                                 nt_errstr(status)));
+                       r->out.result = WINBIND_STATUS_FOOBAR;
+                       return;
+               }
+       }
+
+       a = talloc_array(r, struct winbind_lookup_sid_info, num_aliases);
+       if (!a) {
+               r->out.result = WINBIND_STATUS_NO_MEMORY;
+               return;
+       }
+
+       for (i=0; i < num_aliases; i++) {
+               a[i].sid        = &sids[i];
+               /* TODO: get this from the backend */
+               a[i].type       = SID_NAME_ALIAS;
+       }
+
+       r->out.rep->sid_array.num_sids          = num_aliases;
+       r->out.rep->sid_array.sids              = a;
+
+       r->out.result = WINBIND_STATUS_OK;
+}
+
 void winbindd_ndr_domain_child_lookup(struct winbindd_domain *domain,
                                      struct winbindd_cli_state *state)
 {
@@ -551,6 +630,10 @@ void winbindd_ndr_domain_child_lookup(struct winbindd_domain *domain,
        case WINBIND_LOOKUP_LEVEL_SID2DOMGROUPS:
                ndr_child_lookup_sid2domgroups(domain, state, r);
                return;
+
+       case WINBIND_LOOKUP_LEVEL_EXPANDALIASES:
+               ndr_child_lookup_expandaliases(domain, state, r);
+               return;
        }
 
        r->out.result = WINBIND_STATUS_UNKNOWN_LEVEL;