diff options
author | Andrew Tridgell <tridge@samba.org> | 2010-02-16 16:09:07 +1100 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 2010-02-16 21:10:52 +1100 |
commit | 86f8ddf75458582195954cd0b3ad3dcea28c9d0f (patch) | |
tree | aadf73cc8ece5bba297089d2fb66672de3cbd0fe /source4/dsdb | |
parent | 6d65f4c64739094f3657fbf5c081477d04b3cfe3 (diff) | |
download | samba-86f8ddf75458582195954cd0b3ad3dcea28c9d0f.tar.gz samba-86f8ddf75458582195954cd0b3ad3dcea28c9d0f.tar.bz2 samba-86f8ddf75458582195954cd0b3ad3dcea28c9d0f.zip |
s4-samdb: use dsdb_search() in cracknames
greatly simplifies some of the cracknames code
Pair-Programmed-With: Andrew Bartlett <abartlet@samba.org>
Diffstat (limited to 'source4/dsdb')
-rw-r--r-- | source4/dsdb/samdb/cracknames.c | 81 |
1 files changed, 24 insertions, 57 deletions
diff --git a/source4/dsdb/samdb/cracknames.c b/source4/dsdb/samdb/cracknames.c index f0bd5d23ab..3095ee2d46 100644 --- a/source4/dsdb/samdb/cracknames.c +++ b/source4/dsdb/samdb/cracknames.c @@ -34,6 +34,7 @@ #include "auth/auth.h" #include "../lib/util/util_ldb.h" #include "dsdb/samdb/samdb.h" +#include "dsdb/common/util.h" #include "param/param.h" static WERROR DsCrackNameOneFilter(struct ldb_context *sam_ctx, TALLOC_CTX *mem_ctx, @@ -721,7 +722,6 @@ static WERROR DsCrackNameOneFilter(struct ldb_context *sam_ctx, TALLOC_CTX *mem_ const char * const *result_attrs; struct ldb_message **result_res = NULL; struct ldb_message *result = NULL; - struct ldb_dn *result_basedn = NULL; int i; char *p; struct ldb_dn *partitions_basedn = samdb_partitions_dn(sam_ctx, mem_ctx); @@ -809,66 +809,33 @@ static WERROR DsCrackNameOneFilter(struct ldb_context *sam_ctx, TALLOC_CTX *mem_ if (result_filter) { int ret; struct ldb_result *res; - if (domain_res) { - result_basedn = samdb_result_dn(sam_ctx, mem_ctx, domain_res->msgs[0], "ncName", NULL); + uint32_t dsdb_flags = 0; + struct ldb_dn *search_dn; - ret = ldb_search(sam_ctx, mem_ctx, &res, - result_basedn, LDB_SCOPE_SUBTREE, - result_attrs, "%s", result_filter); - if (ret != LDB_SUCCESS) { - talloc_free(result_res); - info1->status = DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR; - return WERR_OK; - } - ldb_ret = res->count; - result_res = res->msgs; + if (domain_res) { + dsdb_flags = 0; + search_dn = samdb_result_dn(sam_ctx, mem_ctx, domain_res->msgs[0], "ncName", NULL); } else { - /* search with the 'phantom root' flag */ - struct ldb_request *req; - - res = talloc_zero(mem_ctx, struct ldb_result); - W_ERROR_HAVE_NO_MEMORY(res); - - ret = ldb_build_search_req(&req, sam_ctx, mem_ctx, - ldb_get_root_basedn(sam_ctx), - LDB_SCOPE_SUBTREE, - result_filter, - result_attrs, - NULL, - res, - ldb_search_default_callback, - NULL); - if (ret == LDB_SUCCESS) { - struct ldb_search_options_control *search_options; - search_options = talloc(req, struct ldb_search_options_control); - W_ERROR_HAVE_NO_MEMORY(search_options); - search_options->search_options = LDB_SEARCH_OPTION_PHANTOM_ROOT; - - ret = ldb_request_add_control(req, LDB_CONTROL_SEARCH_OPTIONS_OID, false, search_options); - } - if (ret != LDB_SUCCESS) { - talloc_free(res); - info1->status = DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR; - return WERR_OK; - } - - ret = ldb_request(sam_ctx, req); - - if (ret == LDB_SUCCESS) { - ret = ldb_wait(req->handle, LDB_WAIT_ALL); - } - - talloc_free(req); + dsdb_flags = DSDB_SEARCH_SEARCH_ALL_PARTITIONS; + search_dn = ldb_get_root_basedn(sam_ctx); + } - if (ret != LDB_SUCCESS) { - DEBUG(2, ("DsCrackNameOneFilter phantom root search failed: %s", - ldb_errstring(sam_ctx))); - info1->status = DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR; - return WERR_OK; - } - ldb_ret = res->count; - result_res = res->msgs; + /* search with the 'phantom root' flag */ + ret = dsdb_search(sam_ctx, mem_ctx, &res, + search_dn, + LDB_SCOPE_SUBTREE, + result_attrs, + DSDB_SEARCH_SEARCH_ALL_PARTITIONS, + "%s", result_filter); + if (ret != LDB_SUCCESS) { + DEBUG(2, ("DsCrackNameOneFilter phantom root search failed: %s", + ldb_errstring(sam_ctx))); + info1->status = DRSUAPI_DS_NAME_STATUS_RESOLVE_ERROR; + return WERR_OK; } + + ldb_ret = res->count; + result_res = res->msgs; } else if (format_offered == DRSUAPI_DS_NAME_FORMAT_FQDN_1779) { ldb_ret = gendb_search_dn(sam_ctx, mem_ctx, name_dn, &result_res, result_attrs); |