From f7aadae810c3715909c08a011323b1d74d85551e Mon Sep 17 00:00:00 2001 From: Sumit Bose Date: Fri, 17 Oct 2014 13:52:24 +0200 Subject: [PATCH 14/15] sysdb: add sysdb_enumpw/grent_with_views() --- src/db/sysdb.h | 8 +++++ src/db/sysdb_search.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+) diff --git a/src/db/sysdb.h b/src/db/sysdb.h index f7e507c..fa5b714 100644 --- a/src/db/sysdb.h +++ b/src/db/sysdb.h @@ -543,6 +543,10 @@ int sysdb_enumpwent(TALLOC_CTX *mem_ctx, struct sss_domain_info *domain, struct ldb_result **res); +int sysdb_enumpwent_with_views(TALLOC_CTX *mem_ctx, + struct sss_domain_info *domain, + struct ldb_result **res); + int sysdb_getgrnam(TALLOC_CTX *mem_ctx, struct sss_domain_info *domain, const char *name, @@ -557,6 +561,10 @@ int sysdb_enumgrent(TALLOC_CTX *mem_ctx, struct sss_domain_info *domain, struct ldb_result **res); +int sysdb_enumgrent_with_views(TALLOC_CTX *mem_ctx, + struct sss_domain_info *domain, + struct ldb_result **res); + struct sysdb_netgroup_ctx { enum {SYSDB_NETGROUP_TRIPLE_VAL, SYSDB_NETGROUP_GROUP_VAL} type; union { diff --git a/src/db/sysdb_search.c b/src/db/sysdb_search.c index f4cecfc..ca52f11 100644 --- a/src/db/sysdb_search.c +++ b/src/db/sysdb_search.c @@ -291,6 +291,46 @@ done: return ret; } +int sysdb_enumpwent_with_views(TALLOC_CTX *mem_ctx, + struct sss_domain_info *domain, + struct ldb_result **_res) +{ + TALLOC_CTX *tmp_ctx; + struct ldb_result *res; + size_t c; + int ret; + + tmp_ctx = talloc_new(NULL); + if (tmp_ctx == NULL) { + DEBUG(SSSDBG_OP_FAILURE, "talloc_new failed.\n"); + return ENOMEM; + } + + ret = sysdb_enumpwent(tmp_ctx, domain, &res); + if (ret != EOK) { + DEBUG(SSSDBG_OP_FAILURE, "sysdb_enumpwent failed.\n"); + goto done; + } + + if (DOM_HAS_VIEWS(domain)) { + for (c = 0; c < res->count; c++) { + ret = sysdb_add_overrides_to_object(domain, res->msgs[c], NULL); + /* enumeration assumes that the cache is up-to-date, hence we do not + * need to handle ENOENT separately. */ + if (ret != EOK) { + DEBUG(SSSDBG_OP_FAILURE, "sysdb_add_overrides_to_object failed.\n"); + goto done; + } + } + } + + *_res = talloc_steal(mem_ctx, res); + +done: + talloc_zfree(tmp_ctx); + return ret; +} + /* groups */ static int mpg_convert(struct ldb_message *msg) @@ -671,6 +711,54 @@ done: return ret; } +int sysdb_enumgrent_with_views(TALLOC_CTX *mem_ctx, + struct sss_domain_info *domain, + struct ldb_result **_res) +{ + TALLOC_CTX *tmp_ctx; + struct ldb_result *res; + size_t c; + int ret; + + tmp_ctx = talloc_new(NULL); + if (tmp_ctx == NULL) { + DEBUG(SSSDBG_OP_FAILURE, "talloc_new failed.\n"); + return ENOMEM; + } + + ret = sysdb_enumgrent(tmp_ctx, domain,&res); + if (ret != EOK) { + DEBUG(SSSDBG_OP_FAILURE, "sysdb_enumgrent failed.\n"); + goto done; + } + + if (DOM_HAS_VIEWS(domain)) { + for (c = 0; c < res->count; c++) { + ret = sysdb_add_overrides_to_object(domain, res->msgs[c], NULL); + /* enumeration assumes that the cache is up-to-date, hence we do not + * need to handle ENOENT separately. */ + if (ret != EOK) { + DEBUG(SSSDBG_OP_FAILURE, "sysdb_add_overrides_to_object failed.\n"); + goto done; + } + + ret = sysdb_add_group_member_overrides(domain, res->msgs[c]); + if (ret != EOK) { + DEBUG(SSSDBG_OP_FAILURE, + "sysdb_add_group_member_overrides failed.\n"); + goto done; + } + } + } + + + *_res = talloc_steal(mem_ctx, res); + +done: + talloc_zfree(tmp_ctx); + return ret; +} + int sysdb_initgroups(TALLOC_CTX *mem_ctx, struct sss_domain_info *domain, const char *name, -- 1.8.3.1