idmap_hash: split out a idmap_hash_id_to_sid() helper function
authorStefan Metzmacher <metze@samba.org>
Thu, 21 Mar 2019 13:05:13 +0000 (14:05 +0100)
committerStefan Metzmacher <metze@samba.org>
Tue, 15 Oct 2019 07:36:38 +0000 (09:36 +0200)
Signed-off-by: Stefan Metzmacher <metze@samba.org>
source3/winbindd/idmap_hash/idmap_hash.c

index c2f6e43f067d17a63e3e664b12ae41b016517ae4..97f34a2e0247399792bbbab0f3525b7ebe496453 100644 (file)
@@ -183,6 +183,30 @@ done:
 /*********************************************************************
  ********************************************************************/
 
+static NTSTATUS idmap_hash_id_to_sid(struct sid_hash_table *hashed_domains,
+                                    struct idmap_domain *dom,
+                                    struct id_map *id)
+{
+       uint32_t h_domain, h_rid;
+
+       id->status = ID_UNMAPPED;
+
+       separate_hashes(id->xid.id, &h_domain, &h_rid);
+
+       /*
+        * If the domain hash doesn't find a SID in the table,
+        * skip it
+        */
+       if (hashed_domains[h_domain].sid == NULL) {
+               return NT_STATUS_NONE_MAPPED;
+       }
+
+       sid_compose(id->sid, hashed_domains[h_domain].sid, h_rid);
+       id->status = ID_MAPPED;
+
+       return NT_STATUS_OK;
+}
+
 static NTSTATUS unixids_to_sids(struct idmap_domain *dom,
                                struct id_map **ids)
 {
@@ -199,21 +223,22 @@ static NTSTATUS unixids_to_sids(struct idmap_domain *dom,
        }
 
        for (i=0; ids[i]; i++) {
-               uint32_t h_domain, h_rid;
-
-               ids[i]->status = ID_UNMAPPED;
+               NTSTATUS ret;
 
-               separate_hashes(ids[i]->xid.id, &h_domain, &h_rid);
+               ret = idmap_hash_id_to_sid(hashed_domains, dom, ids[i]);
 
-               /* If the domain hash doesn't find a SID in the table,
-                  skip it */
-
-               if (!hashed_domains[h_domain].sid)
-                       continue;
+               if ((!NT_STATUS_IS_OK(ret)) &&
+                   (!NT_STATUS_EQUAL(ret, NT_STATUS_NONE_MAPPED))) {
+                       /* some fatal error occurred, log it */
+                       DBG_NOTICE("Unexpected error resolving an ID "
+                                  "(%d): %s\n", ids[i]->xid.id,
+                                  nt_errstr(ret));
+                       return ret;
+               }
 
-               sid_compose(ids[i]->sid, hashed_domains[h_domain].sid, h_rid);
-               ids[i]->status = ID_MAPPED;
-               num_mapped++;
+               if (NT_STATUS_IS_OK(ret) && ids[i]->status == ID_MAPPED) {
+                       num_mapped++;
+               }
        }
 
        if (num_tomap == num_mapped) {