idmap_hash: remember new domain sids in idmap_hash_sid_to_id()
authorStefan Metzmacher <metze@samba.org>
Thu, 21 Mar 2019 15:54:31 +0000 (16:54 +0100)
committerJule Anger <janger@samba.org>
Thu, 30 Mar 2023 15:10:10 +0000 (15:10 +0000)
This change means that idmap_hash_id_to_sid() can return mappings
for new domains learned in idmap_hash_sid_to_id().

BUG: https://bugzilla.samba.org/show_bug.cgi?id=15319

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Autobuild-User(master): Stefan Metzmacher <metze@samba.org>
Autobuild-Date(master): Fri Mar 10 11:35:06 UTC 2023 on atb-devel-224

(cherry picked from commit 7ee725f2860d835e9619fa594a2ee6faedbc6d21)

source3/winbindd/idmap_hash/idmap_hash.c

index a34303506257d1bda7f7ac02c26ce1c855e53305..e9d90e3d02b19e2ca045d973da8eab4544518a56 100644 (file)
@@ -295,12 +295,11 @@ static NTSTATUS idmap_hash_sid_to_id(struct sid_hash_table *hashed_domains,
         */
        if (netsamlogon_cache_have(&sid)) {
                /*
-                * We keep the legacy behavior and
-                * just return the mapping, but
-                * the reverse mapping would not
-                * still not work.
+                * The domain is valid, so we'll
+                * remember it in order to
+                * allow reverse mappings to work.
                 */
-               goto return_mapping;
+               goto remember_domain;
        }
 
        if (id->xid.type == ID_TYPE_NOT_SPECIFIED) {
@@ -322,6 +321,17 @@ static NTSTATUS idmap_hash_sid_to_id(struct sid_hash_table *hashed_domains,
                return NT_STATUS_OK;
        }
 
+       /*
+        * Now we're sure the domain exist, remember
+        * the domain in order to return reverse mappings
+        * in future.
+        */
+remember_domain:
+       hashed_domains[h_domain].sid = dom_sid_dup(hashed_domains, &sid);
+       if (hashed_domains[h_domain].sid == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
+
        /*
         * idmap_hash used to bounce back the requested type,
         * which was ID_TYPE_UID, ID_TYPE_GID or