]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
dsdb: Use samdb_get_system_container_dn() to get Password Settings Container
authorAndrew Bartlett <abartlet@samba.org>
Thu, 27 Jul 2023 04:44:10 +0000 (16:44 +1200)
committerJule Anger <janger@samba.org>
Tue, 1 Aug 2023 09:53:12 +0000 (09:53 +0000)
By doing this we use the common samdb_get_system_container_dn() routine and we
avoid doing a linerize and parse step on the main DN, instead using the
already stored parse of the DN.  This is more hygenic.

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

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
(cherry picked from commit 3669caa97f76d3e893ac6a1ab88341057929ee6a)

source4/dsdb/samdb/ldb_modules/operational.c

index 2b3cd2d7954576ff300e5e458e6c42fc7ac13f35..214079c09172a535efb4d246641a22907769edb8 100644 (file)
@@ -998,19 +998,20 @@ static int get_pso_count(struct ldb_module *module, TALLOC_CTX *mem_ctx,
 {
        static const char * const attrs[] = { NULL };
        int ret;
-       struct ldb_dn *domain_dn = NULL;
        struct ldb_dn *psc_dn = NULL;
        struct ldb_result *res = NULL;
        struct ldb_context *ldb = ldb_module_get_ctx(module);
+       bool psc_ok;
 
        *pso_count = 0;
-       domain_dn = ldb_get_default_basedn(ldb);
-       psc_dn = ldb_dn_new_fmt(mem_ctx, ldb,
-                               "CN=Password Settings Container,CN=System,%s",
-                               ldb_dn_get_linearized(domain_dn));
+       psc_dn = samdb_system_container_dn(ldb, mem_ctx);
        if (psc_dn == NULL) {
                return ldb_oom(ldb);
        }
+       psc_ok = ldb_dn_add_child_fmt(psc_dn, "CN=Password Settings Container");
+       if (psc_ok == false) {
+               return ldb_oom(ldb);
+       }
 
        /* get the number of PSO children */
        ret = dsdb_module_search(module, mem_ctx, &res, psc_dn,
@@ -1077,8 +1078,8 @@ static int pso_search_by_sids(struct ldb_module *module, TALLOC_CTX *mem_ctx,
        int i;
        struct ldb_context *ldb = ldb_module_get_ctx(module);
        char *sid_filter = NULL;
-       struct ldb_dn *domain_dn = NULL;
        struct ldb_dn *psc_dn = NULL;
+       bool psc_ok;
        const char *attrs[] = {
                "msDS-PasswordSettingsPrecedence",
                "objectGUID",
@@ -1104,13 +1105,14 @@ static int pso_search_by_sids(struct ldb_module *module, TALLOC_CTX *mem_ctx,
        }
 
        /* only PSOs located in the Password Settings Container are valid */
-       domain_dn = ldb_get_default_basedn(ldb);
-       psc_dn = ldb_dn_new_fmt(mem_ctx, ldb,
-                               "CN=Password Settings Container,CN=System,%s",
-                               ldb_dn_get_linearized(domain_dn));
+       psc_dn = samdb_system_container_dn(ldb, mem_ctx);
        if (psc_dn == NULL) {
                return ldb_oom(ldb);
        }
+       psc_ok = ldb_dn_add_child_fmt(psc_dn, "CN=Password Settings Container");
+       if (psc_ok == false) {
+               return ldb_oom(ldb);
+       }
 
        ret = dsdb_module_search(module, mem_ctx, result, psc_dn,
                                 LDB_SCOPE_ONELEVEL, attrs,