s4-dsdb Make samdb_reference_dn() use dsdb_search() and DSDB_SEARCH_ONE_ONLY
authorAndrew Bartlett <abartlet@samba.org>
Tue, 28 Sep 2010 02:55:48 +0000 (12:55 +1000)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 28 Sep 2010 18:23:07 +0000 (04:23 +1000)
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

index a8186e879cf3154031a40f1c504213e14009f794..ceb12a836a1bf69f79be653137e173f23eadc9aa 100644 (file)
@@ -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;
        }