]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
ldb: Attach appropriate ldb context to returned result
authorJo Sutton <josutton@catalyst.net.nz>
Wed, 1 May 2024 04:54:01 +0000 (16:54 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 11 Jun 2024 04:32:30 +0000 (04:32 +0000)
This is done by adding a new API that avoids the problems of
ldb_dn_copy() and makes it clear that a struct ldb_context *
pointer will be stored in the new copy.

Signed-off-by: Jo Sutton <josutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
lib/ldb/ABI/ldb-2.10.0.sigs
lib/ldb/common/ldb_dn.c
lib/ldb/include/ldb.h
lib/ldb/ldb_key_value/ldb_kv_search.c
python/samba/tests/krb5/gmsa_tests.py

index f23014ffaaa701e6a7735aa1037b9dcf570c3245..bd9aa54a0055be54121d2642732fed594f53044f 100644 (file)
@@ -47,6 +47,7 @@ ldb_dn_check_special: bool (struct ldb_dn *, const char *)
 ldb_dn_compare: int (struct ldb_dn *, struct ldb_dn *)
 ldb_dn_compare_base: int (struct ldb_dn *, struct ldb_dn *)
 ldb_dn_copy: struct ldb_dn *(TALLOC_CTX *, struct ldb_dn *)
+ldb_dn_copy_with_ldb_context: struct ldb_dn *(TALLOC_CTX *, struct ldb_dn *, struct ldb_context *)
 ldb_dn_escape_value: char *(TALLOC_CTX *, struct ldb_val)
 ldb_dn_extended_add_syntax: int (struct ldb_context *, unsigned int, const struct ldb_dn_extended_syntax *)
 ldb_dn_extended_filter: void (struct ldb_dn *, const char * const *)
index cb4266dca91b16e15ad6f25fd2faa38e67d0b7c9..e785a6d9e3d7d1a030c1837a2a0035d39980dc21 100644 (file)
@@ -1398,6 +1398,22 @@ struct ldb_dn *ldb_dn_copy(TALLOC_CTX *mem_ctx, struct ldb_dn *dn)
        return new_dn;
 }
 
+struct ldb_dn *ldb_dn_copy_with_ldb_context(TALLOC_CTX *mem_ctx,
+                                           struct ldb_dn *dn,
+                                           struct ldb_context *ldb)
+{
+       struct ldb_dn *new_dn = NULL;
+
+       new_dn = ldb_dn_copy(mem_ctx, dn);
+       if (new_dn == NULL) {
+               return NULL;
+       }
+
+       /* Set the ldb context. */
+       new_dn->ldb = ldb;
+       return new_dn;
+}
+
 /* modify the given dn by adding a base.
  *
  * return true if successful and false if not
index f29392ad4ea7816314cc4bfa6abddc3375c3b180..f2d4642375f3b2bf916d037260a767ea4ba2c5ef 100644 (file)
@@ -1902,6 +1902,9 @@ bool ldb_dn_add_child_val(struct ldb_dn *dn,
                          struct ldb_val value);
 
 struct ldb_dn *ldb_dn_copy(TALLOC_CTX *mem_ctx, struct ldb_dn *dn);
+struct ldb_dn *ldb_dn_copy_with_ldb_context(TALLOC_CTX *mem_ctx,
+                                           struct ldb_dn *dn,
+                                           struct ldb_context *ldb);
 struct ldb_dn *ldb_dn_get_parent(TALLOC_CTX *mem_ctx, struct ldb_dn *dn);
 char *ldb_dn_canonical_string(TALLOC_CTX *mem_ctx, struct ldb_dn *dn);
 char *ldb_dn_canonical_ex_string(TALLOC_CTX *mem_ctx, struct ldb_dn *dn);
index 5dbbae6b15c32c61ca190265b95fb03d9ad6f510..9d0d218b48a63a9fcb287917c82d864774669933 100644 (file)
@@ -586,7 +586,7 @@ static int ldb_kv_search_and_return_base(struct ldb_kv_private *ldb_kv,
                 * returned result, as it has already been
                 * casefolded
                 */
-               struct ldb_dn *dn = ldb_dn_copy(msg, ctx->base);
+               struct ldb_dn *dn = ldb_dn_copy_with_ldb_context(msg, ctx->base, ldb);
                if (dn != NULL) {
                        msg->dn = dn;
                }
index f27e42357131a95a5f8d518dfa0efca87e64180b..4189f05d22d360311e03facec83b8a3b95e6b09a 100755 (executable)
@@ -1800,7 +1800,7 @@ class GmsaTests(GkdiBaseTest, KDCBaseTest):
         modify_attr("lockoutThreshold", lockout_threshold)
 
         creds = self.gmsa_account(kerberos_enabled=kerberos_enabled)
-        dn = ldb.Dn(samdb, str(creds.get_dn()))
+        dn = creds.get_dn()
 
         # Truncate the password to ensure that it is invalid.
         creds.set_password(creds.get_password()[:-1])