From 3b7c49843734720fb31d4fa7d5d14ec0debb5867 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 14 Jan 2011 11:47:49 +1100 Subject: [PATCH] s4-dsdb: replaced another use of samdb_search in a ldb module we should be using the dsdb_module_search*() calls Pair-Programmed-With: Andrew Bartlett --- source4/dsdb/samdb/ldb_modules/samldb.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/source4/dsdb/samdb/ldb_modules/samldb.c b/source4/dsdb/samdb/ldb_modules/samldb.c index ff615832297..94648c6621f 100644 --- a/source4/dsdb/samdb/ldb_modules/samldb.c +++ b/source4/dsdb/samdb/ldb_modules/samldb.c @@ -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); } -- 2.34.1