From 063b61289db73444d514d2897339cf135fc8dfc9 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 28 Sep 2010 12:55:48 +1000 Subject: s4-dsdb Make samdb_reference_dn() use dsdb_search() and DSDB_SEARCH_ONE_ONLY This simplifies the function. While doing so, also change the error string setting to set a really clear error string for the failure to find and failure to parse cases. Andrew Bartlett --- source4/dsdb/common/util.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'source4/dsdb') diff --git a/source4/dsdb/common/util.c b/source4/dsdb/common/util.c index a8186e879c..ceb12a836a 100644 --- a/source4/dsdb/common/util.c +++ b/source4/dsdb/common/util.c @@ -1690,20 +1690,21 @@ int samdb_reference_dn(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, struct ldb_ attrs[0] = attribute; attrs[1] = NULL; - ret = ldb_search(ldb, mem_ctx, &res, base, LDB_SCOPE_BASE, attrs, NULL); + ret = dsdb_search(ldb, mem_ctx, &res, base, LDB_SCOPE_BASE, attrs, DSDB_SEARCH_ONE_ONLY, NULL); if (ret != LDB_SUCCESS) { return ret; } - if (res->count != 1) { - talloc_free(res); - return LDB_ERR_NO_SUCH_OBJECT; - } *dn = ldb_msg_find_attr_as_dn(ldb, mem_ctx, res->msgs[0], attribute); if (!*dn) { + if (!ldb_msg_find_element(res->msgs[0], attribute)) { + ldb_asprintf_errstring(ldb, "Cannot find attribute %s of %s to calculate reference dn", attribute, + ldb_dn_get_linearized(base)); + } else { + ldb_asprintf_errstring(ldb, "Cannot interpret attribute %s of %s as a dn", attribute, + ldb_dn_get_linearized(base)); + } talloc_free(res); - ldb_asprintf_errstring(ldb, "Cannot find dn of attribute %s of %s", attribute, - ldb_dn_get_linearized(base)); return LDB_ERR_NO_SUCH_ATTRIBUTE; } -- cgit