From 7ffaa2afb9e03a6f0b9c602c0f03b2074ea33eac Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sun, 14 Mar 2010 17:27:05 -0400 Subject: sysdb: convert sysdb_getpwnam --- src/db/sysdb_search.c | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) (limited to 'src/db/sysdb_search.c') diff --git a/src/db/sysdb_search.c b/src/db/sysdb_search.c index 4b9470ba..2403917b 100644 --- a/src/db/sysdb_search.c +++ b/src/db/sysdb_search.c @@ -215,38 +215,42 @@ int sysdb_getpwnam(TALLOC_CTX *mem_ctx, struct sysdb_ctx *ctx, struct sss_domain_info *domain, const char *name, - sysdb_callback_t fn, void *ptr) + struct ldb_result **_res) { + TALLOC_CTX *tmpctx; static const char *attrs[] = SYSDB_PW_ATTRS; - struct sysdb_search_ctx *sctx; - struct tevent_req *req; + struct ldb_dn *base_dn; + struct ldb_result *res; + int ret; if (!domain) { return EINVAL; } - sctx = init_src_ctx(mem_ctx, domain, ctx, fn, ptr); - if (!sctx) { + tmpctx = talloc_new(mem_ctx); + if (!tmpctx) { return ENOMEM; } - sctx->expression = talloc_asprintf(sctx, SYSDB_PWNAM_FILTER, name); - if (!sctx->expression) { - talloc_free(sctx); - return ENOMEM; + base_dn = ldb_dn_new_fmt(tmpctx, ctx->ldb, + SYSDB_TMPL_USER_BASE, domain->name); + if (!base_dn) { + ret = ENOMEM; + goto done; } - sctx->attrs = attrs; - - req = sysdb_operation_send(mem_ctx, ctx->ev, ctx); - if (!req) { - talloc_free(sctx); - return ENOMEM; + ret = ldb_search(ctx->ldb, tmpctx, &res, base_dn, + LDB_SCOPE_SUBTREE, attrs, SYSDB_PWNAM_FILTER, name); + if (ret) { + ret = sysdb_error_to_errno(ret); + goto done; } - tevent_req_set_callback(req, user_search, sctx); + *_res = talloc_steal(mem_ctx, res); - return EOK; +done: + talloc_zfree(tmpctx); + return ret; } int sysdb_getpwuid(TALLOC_CTX *mem_ctx, -- cgit