s4-dsdb: replaced another use of samdb_search in a ldb module
authorAndrew Tridgell <tridge@samba.org>
Fri, 14 Jan 2011 00:47:49 +0000 (11:47 +1100)
committerAndrew Tridgell <tridge@samba.org>
Fri, 14 Jan 2011 05:39:33 +0000 (16:39 +1100)
we should be using the dsdb_module_search*() calls

Pair-Programmed-With: Andrew Bartlett <abartlet@samba.org>

source4/dsdb/samdb/ldb_modules/samldb.c

index ff61583229725c2148f38064461f0f9a7b5fa041..94648c6621f0305bd123484cb9ce98f5e3ea099b 100644 (file)
@@ -167,6 +167,8 @@ static int samldb_check_sAMAccountName(struct samldb_ctx *ac)
        struct ldb_context *ldb = ldb_module_get_ctx(ac->module);
        const char *name;
        int ret;
+       struct ldb_result *res;
+       const char *noattrs[] = { NULL };
 
        if (ldb_msg_find_element(ac->msg, "sAMAccountName") == NULL) {
                ret = samldb_generate_sAMAccountName(ldb, ac->msg);
@@ -183,17 +185,21 @@ static int samldb_check_sAMAccountName(struct samldb_ctx *ac)
                return LDB_ERR_CONSTRAINT_VIOLATION;
        }
 
-       ret = samdb_search_count(ldb, ac, NULL, "(sAMAccountName=%s)",
+       ret = dsdb_module_search(ac->module, ac, &res,
+                                NULL, LDB_SCOPE_SUBTREE, noattrs,
+                                DSDB_FLAG_NEXT_MODULE, "(sAMAccountName=%s)",
                                 ldb_binary_encode_string(ac, name));
-       if ((ret < 0) || (ret > 1)) {
-               return ldb_operr(ldb);
+       if (ret != LDB_SUCCESS) {
+               return ret;
        }
-       if (ret == 1) {
+       if (res->count != 0) {
                ldb_asprintf_errstring(ldb,
                                       "samldb: Account name (sAMAccountName) '%s' already in use!",
                                       name);
+               talloc_free(res);
                return LDB_ERR_ENTRY_ALREADY_EXISTS;
        }
+       talloc_free(res);
 
        return samldb_next_step(ac);
 }