WURST - rework dual_srv: Sids2UnixIDs idmap
authorMichael Adam <obnox@samba.org>
Mon, 15 Aug 2016 22:32:53 +0000 (00:32 +0200)
committerMichael Adam <obnox@samba.org>
Mon, 15 Aug 2016 22:34:01 +0000 (00:34 +0200)
source3/winbindd/winbindd_dual_srv.c

index 0aa18dc2cf1785047e714e6572ba154eb8e96418..03a66f74fd0f5d87829f6fcc4fc1a3506d641bc6 100644 (file)
@@ -126,8 +126,9 @@ NTSTATUS _wbint_Sids2UnixIDs(struct pipes_struct *p,
        struct lsa_DomainInfo *d;
        struct wbint_TransID *ids;
        uint32_t num_ids;
+       uint32_t num_mapped = 0;
 
-       struct id_map **id_map_ptrs = NULL;
+       struct id_map **maps = NULL;
        struct idmap_domain *dom;
        NTSTATUS status = NT_STATUS_NO_MEMORY;
 
@@ -139,25 +140,9 @@ NTSTATUS _wbint_Sids2UnixIDs(struct pipes_struct *p,
        ids = r->in.ids->ids;
        num_ids = r->in.ids->num_ids;
 
-       dom = idmap_find_domain_with_sid(d->name.string, d->sid);
-       if (dom == NULL) {
-               DEBUG(10, ("idmap domain %s:%s not found\n",
-                          d->name.string, sid_string_dbg(d->sid)));
-
-               for (i=0; i<num_ids; i++) {
-
-                       ids[i].xid = (struct unixid) {
-                               .id = UINT32_MAX,
-                               .type = ID_TYPE_NOT_SPECIFIED
-                       };
-               }
-
-               return NT_STATUS_OK;
-       }
-
-       id_map_ptrs = id_map_ptrs_init(talloc_tos(), num_ids);
-       if (id_map_ptrs == NULL) {
-               goto nomem;
+       maps = id_map_ptrs_init(talloc_tos(), num_ids);
+       if (maps == NULL) {
+               return NT_STATUS_NO_MEMORY;
        }
 
        /*
@@ -167,16 +152,26 @@ NTSTATUS _wbint_Sids2UnixIDs(struct pipes_struct *p,
         */
 
        for (i=0; i<num_ids; i++) {
-               struct id_map *m = id_map_ptrs[i];
+               struct id_map *m = maps[i];
 
                sid_compose(m->sid, d->sid, ids[i].rid);
                m->status = ID_UNKNOWN;
                m->xid = (struct unixid) { .type = ids[i].type };
        }
 
-       status = dom->methods->sids_to_unixids(dom, id_map_ptrs);
+       dom = idmap_find_domain_with_sid(d->name.string, d->sid);
+       if (dom == NULL) {
+               DEBUG(10, ("idmap domain %s:%s not found\n",
+                          d->name.string, sid_string_dbg(d->sid)));
 
-       if (!NT_STATUS_IS_OK(status)) {
+               status = NT_STATUS_NONE_MAPPED;
+               goto done;
+       }
+
+       status = dom->methods->sids_to_unixids(dom, maps);
+       if (!NT_STATUS_IS_OK(status) &&
+           !NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED))
+       {
                DEBUG(10, ("sids_to_unixids returned %s\n",
                           nt_errstr(status)));
                goto done;
@@ -187,7 +182,7 @@ NTSTATUS _wbint_Sids2UnixIDs(struct pipes_struct *p,
         */
 
        for (i=0; i<num_ids; i++) {
-               struct id_map *m = id_map_ptrs[i];
+               struct id_map *m = maps[i];
 
                if (!idmap_unix_id_is_in_range(m->xid.id, dom)) {
                        m->status = ID_UNMAPPED;
@@ -195,17 +190,23 @@ NTSTATUS _wbint_Sids2UnixIDs(struct pipes_struct *p,
 
                if (m->status == ID_MAPPED) {
                        ids[i].xid = m->xid;
+                       num_mapped += 1;
                } else {
                        ids[i].xid.id = UINT32_MAX;
                        ids[i].xid.type = ID_TYPE_NOT_SPECIFIED;
                }
        }
 
-       goto done;
-nomem:
-       status = NT_STATUS_NO_MEMORY;
+       if (num_mapped == 0) {
+               status = NT_STATUS_NONE_MAPPED;
+       } else if (num_mapped < num_ids) {
+               status = STATUS_SOME_UNMAPPED;
+       } else {
+               status = NT_STATUS_OK;
+       }
+
 done:
-       TALLOC_FREE(id_map_ptrs);
+       TALLOC_FREE(maps);
        return status;
 }