diff options
author | Andrew Bartlett <abartlet@samba.org> | 2010-09-28 12:55:48 +1000 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2010-09-29 04:23:07 +1000 |
commit | 063b61289db73444d514d2897339cf135fc8dfc9 (patch) | |
tree | 9db3ff760ead866ff8ed93307478f9d6a1ef36ec | |
parent | 990720b8cd869a375686cc78f270e68ca9bd28b3 (diff) | |
download | samba-063b61289db73444d514d2897339cf135fc8dfc9.tar.gz samba-063b61289db73444d514d2897339cf135fc8dfc9.tar.bz2 samba-063b61289db73444d514d2897339cf135fc8dfc9.zip |
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
-rw-r--r-- | source4/dsdb/common/util.c | 15 |
1 files changed, 8 insertions, 7 deletions
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; } |