summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2022-12-12 16:15:03 +1300
committerJule Anger <janger@samba.org>2023-02-03 09:35:08 +0000
commit96adf5afc01ee07f2b9ecd2415c6bda5d7e1ff1a (patch)
treea3e86d362f369b846275e315e0e5259a695142d0
parentdeac11ab428b73a712da15f55be135f2741be14d (diff)
downloadsamba-96adf5afc01ee07f2b9ecd2415c6bda5d7e1ff1a.tar.gz
s4-dsdb: Add dsdb_normalise_dn_and_find_nc_root() around dsdb_find_nc_root()
Reuse the search done for dsdb_find_nc_root() to normalise the DN. This will allow a GUID-input DN to be compared safely with a RID Manager DN or Naming Context. BUG: https://bugzilla.samba.org/show_bug.cgi?id=10635 Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org> (cherry picked from commit 8e1122420efd11a91aa1c5d60c0cc8fd9ffaf157)
-rw-r--r--source4/dsdb/common/util.c35
1 files changed, 33 insertions, 2 deletions
diff --git a/source4/dsdb/common/util.c b/source4/dsdb/common/util.c
index 58eef3abb66..029a7d69bf3 100644
--- a/source4/dsdb/common/util.c
+++ b/source4/dsdb/common/util.c
@@ -4289,8 +4289,11 @@ static int dsdb_get_partition_and_dn(struct ldb_request *req,
/*
find a NC root given a DN within the NC
*/
-int dsdb_find_nc_root(struct ldb_context *samdb, TALLOC_CTX *mem_ctx, struct ldb_dn *dn,
- struct ldb_dn **nc_root)
+int dsdb_normalise_dn_and_find_nc_root(struct ldb_context *samdb,
+ TALLOC_CTX *mem_ctx,
+ struct ldb_dn *dn,
+ struct ldb_dn **normalised_dn,
+ struct ldb_dn **nc_root)
{
TALLOC_CTX *tmp_ctx;
int ret;
@@ -4380,6 +4383,10 @@ int dsdb_find_nc_root(struct ldb_context *samdb, TALLOC_CTX *mem_ctx, struct ldb
*/
if (ret == LDB_ERR_NO_SUCH_OBJECT) {
+ if (normalised_dn != NULL) {
+ talloc_free(tmp_ctx);
+ return ret;
+ }
ret = LDB_SUCCESS;
ldb_reset_err_string(samdb);
} else if (ret != LDB_SUCCESS) {
@@ -4387,6 +4394,16 @@ int dsdb_find_nc_root(struct ldb_context *samdb, TALLOC_CTX *mem_ctx, struct ldb
return ret;
}
+ if (normalised_dn != NULL) {
+ if (context.count != 1) {
+ /* No results */
+ ldb_asprintf_errstring(samdb,
+ "Request for NC root for %s failed to return any results.",
+ ldb_dn_get_linearized(dn));
+ return LDB_ERR_NO_SUCH_OBJECT;
+ }
+ *normalised_dn = context.dn;
+ }
/*
* If the user did not need to find the nc_root,
@@ -4443,6 +4460,20 @@ int dsdb_find_nc_root(struct ldb_context *samdb, TALLOC_CTX *mem_ctx, struct ldb
nc_root);
}
+/*
+ find a NC root given a DN within the NC
+ */
+int dsdb_find_nc_root(struct ldb_context *samdb,
+ TALLOC_CTX *mem_ctx,
+ struct ldb_dn *dn,
+ struct ldb_dn **nc_root)
+{
+ return dsdb_normalise_dn_and_find_nc_root(samdb,
+ mem_ctx,
+ dn,
+ NULL,
+ nc_root);
+}
/*
find the deleted objects DN for any object, by looking for the NC