idmap_hash: split out a idmap_hash_sid_to_id() 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 97f34a2e0247399792bbbab0f3525b7ebe496453..65526fce4da0e86d5097990d77580af5adc9e59f 100644 (file)
@@ -253,9 +253,41 @@ static NTSTATUS unixids_to_sids(struct idmap_domain *dom,
 /*********************************************************************
  ********************************************************************/
 
+static NTSTATUS idmap_hash_sid_to_id(struct sid_hash_table *hashed_domains,
+                                    struct idmap_domain *dom,
+                                    struct id_map *id)
+{
+       struct dom_sid sid;
+       uint32_t rid;
+       uint32_t h_domain, h_rid;
+
+       id->status = ID_UNMAPPED;
+
+       sid_copy(&sid, id->sid);
+       sid_split_rid(&sid, &rid);
+
+       h_domain = hash_domain_sid(&sid);
+       h_rid = hash_rid(rid);
+
+       /* Check that both hashes are non-zero*/
+       if (h_domain == 0) {
+               return NT_STATUS_NONE_MAPPED;
+       }
+       if (h_rid == 0) {
+               return NT_STATUS_NONE_MAPPED;
+       }
+
+       id->xid.id = combine_hashes(h_domain, h_rid);
+       id->status = ID_MAPPED;
+
+       return NT_STATUS_OK;
+}
+
 static NTSTATUS sids_to_unixids(struct idmap_domain *dom,
                                struct id_map **ids)
 {
+       struct sid_hash_table *hashed_domains = talloc_get_type_abort(
+               dom->private_data, struct sid_hash_table);
        int i;
        int num_tomap = 0;
        int num_mapped = 0;
@@ -267,23 +299,22 @@ static NTSTATUS sids_to_unixids(struct idmap_domain *dom,
        }
 
        for (i=0; ids[i]; i++) {
-               struct dom_sid sid;
-               uint32_t rid;
-               uint32_t h_domain, h_rid;
-
-               ids[i]->status = ID_UNMAPPED;
-
-               sid_copy(&sid, ids[i]->sid);
-               sid_split_rid(&sid, &rid);
+               NTSTATUS ret;
 
-               h_domain = hash_domain_sid(&sid);
-               h_rid = hash_rid(rid);
+               ret = idmap_hash_sid_to_id(hashed_domains, dom, ids[i]);
 
-               /* Check that both hashes are non-zero*/
+               if ((!NT_STATUS_IS_OK(ret)) &&
+                   (!NT_STATUS_EQUAL(ret, NT_STATUS_NONE_MAPPED))) {
+                       struct dom_sid_buf buf;
+                       /* some fatal error occurred, log it */
+                       DBG_NOTICE("Unexpected error resolving a SID "
+                                  "(%s): %s\n",
+                                  dom_sid_str_buf(ids[i]->sid, &buf),
+                                  nt_errstr(ret));
+                       return ret;
+               }
 
-               if (h_domain && h_rid) {
-                       ids[i]->xid.id = combine_hashes(h_domain, h_rid);
-                       ids[i]->status = ID_MAPPED;
+               if (NT_STATUS_IS_OK(ret) && ids[i]->status == ID_MAPPED) {
                        num_mapped++;
                }
        }