From 5e3966c99180abdcd1e21774a882f1c14c47aae8 Mon Sep 17 00:00:00 2001 From: Stephen Gallagher Date: Mon, 2 Mar 2009 09:35:06 -0500 Subject: Implement GetUserAttributes in the InfoPipe This patch adds support for requesting user data in the sysdb via the InfoPipe. It currently has support for reading defined entries of integral, floating-point or string types. Tasks remaining: 1) Implement call to the provider when cache is out of date 2) Support byte arrays for userpic and similar I modified sysdb_search_ctx in sysdb_search.c to accept an array of attributes to pass into the LDB search. I also made one additional related fix: the btreemap now sorts in the correct order. Previously I had accidentally transposed the two values for sorting, so the map would always have been in exact reverse order. --- server/db/sysdb_search.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) (limited to 'server/db/sysdb_search.c') diff --git a/server/db/sysdb_search.c b/server/db/sysdb_search.c index bb71079b8..b1e63112b 100644 --- a/server/db/sysdb_search.c +++ b/server/db/sysdb_search.c @@ -44,6 +44,8 @@ struct sysdb_search_ctx { struct get_mem_ctx *gmctx; struct ldb_result *res; + + const char **attrs; }; static struct sysdb_search_ctx *init_src_ctx(TALLOC_CTX *mem_ctx, @@ -204,6 +206,37 @@ static void pwd_search(struct sysdb_req *sysreq, void *ptr) } } +static void user_search(struct sysdb_req *sysreq, void *ptr) +{ + struct sysdb_search_ctx *sctx; + struct ldb_request *req; + struct ldb_dn *base_dn; + int ret; + + sctx = talloc_get_type(ptr, struct sysdb_search_ctx); + sctx->req = sysreq; + + base_dn = ldb_dn_new_fmt(sctx, sctx->ctx->ldb, + SYSDB_TMPL_USER_BASE, sctx->domain); + if (!base_dn) { + return request_error(sctx, ENOMEM); + } + + ret = ldb_build_search_req(&req, sctx->ctx->ldb, sctx, + base_dn, LDB_SCOPE_SUBTREE, + sctx->expression, sctx->attrs, NULL, + sctx, get_gen_callback, + NULL); + if (ret != LDB_SUCCESS) { + return request_ldberror(sctx, ret); + } + + ret = ldb_request(sctx->ctx->ldb, req); + if (ret != LDB_SUCCESS) { + return request_ldberror(sctx, ret); + } +} + int sysdb_getpwnam(TALLOC_CTX *mem_ctx, struct sysdb_ctx *ctx, const char *domain, @@ -729,3 +762,31 @@ int sysdb_initgroups(TALLOC_CTX *mem_ctx, return sysdb_operation(mem_ctx, ctx, initgr_search, sctx); } +int sysdb_get_user_attr(TALLOC_CTX *mem_ctx, + struct sysdb_ctx *ctx, + struct sss_domain_info *domain, + const char *name, + const char **attributes, + sysdb_callback_t fn, void *ptr) +{ + struct sysdb_search_ctx *sctx; + + if (!domain) { + return EINVAL; + } + + sctx = init_src_ctx(mem_ctx, domain->name, domain->legacy, ctx, fn, ptr); + if (!sctx) { + return ENOMEM; + } + + sctx->expression = talloc_asprintf(sctx, SYSDB_PWNAM_FILTER, name); + if (!sctx->expression) { + talloc_free(sctx); + return ENOMEM; + } + + sctx->attrs = attributes; + + return sysdb_operation(mem_ctx, ctx, user_search, sctx); +} -- cgit