From f62b9b41b0a29a0294d6e532e2bed2b4ce9012e4 Mon Sep 17 00:00:00 2001 From: Jan Zeleny Date: Tue, 3 May 2011 05:21:33 -0400 Subject: Add a function for searching netgroups with custom filter --- src/db/sysdb.h | 8 ++++++++ src/db/sysdb_ops.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/src/db/sysdb.h b/src/db/sysdb.h index a7d3e7ea..c133072d 100644 --- a/src/db/sysdb.h +++ b/src/db/sysdb.h @@ -713,6 +713,14 @@ int sysdb_delete_group(TALLOC_CTX *mem_ctx, struct sss_domain_info *domain, const char *name, gid_t gid); +int sysdb_search_netgroups(TALLOC_CTX *mem_ctx, + struct sysdb_ctx *sysdb, + struct sss_domain_info *domain, + const char *sub_filter, + const char **attrs, + size_t *msgs_count, + struct ldb_message ***msgs); + int sysdb_delete_netgroup(struct sysdb_ctx *sysdb, struct sss_domain_info *domain, const char *name); diff --git a/src/db/sysdb_ops.c b/src/db/sysdb_ops.c index ba1f6672..7eb4b48c 100644 --- a/src/db/sysdb_ops.c +++ b/src/db/sysdb_ops.c @@ -2295,6 +2295,63 @@ fail: return ret; } +/* =Search-Netgroups-with-Custom-Filter===================================== */ + +int sysdb_search_netgroups(TALLOC_CTX *mem_ctx, + struct sysdb_ctx *sysdb, + struct sss_domain_info *domain, + const char *sub_filter, + const char **attrs, + size_t *msgs_count, + struct ldb_message ***msgs) +{ + TALLOC_CTX *tmpctx; + struct ldb_dn *basedn; + char *filter; + int ret; + + tmpctx = talloc_new(mem_ctx); + if (!tmpctx) { + return ENOMEM; + } + + if (domain == NULL) { + domain = sysdb->domain; + } + + basedn = ldb_dn_new_fmt(tmpctx, sysdb->ldb, + SYSDB_TMPL_NETGROUP_BASE, domain->name); + if (!basedn) { + DEBUG(2, ("Failed to build base dn\n")); + ret = ENOMEM; + goto fail; + } + + filter = talloc_asprintf(tmpctx, "(&(%s)%s)", SYSDB_NC, sub_filter); + if (!filter) { + DEBUG(2, ("Failed to build filter\n")); + ret = ENOMEM; + goto fail; + } + + DEBUG(6, ("Search netgroups with filter: %s\n", filter)); + + ret = sysdb_search_entry(mem_ctx, sysdb, basedn, + LDB_SCOPE_SUBTREE, filter, attrs, + msgs_count, msgs); + if (ret) { + goto fail; + } + + talloc_zfree(tmpctx); + return EOK; + +fail: + DEBUG(6, ("Error: %d (%s)\n", ret, strerror(ret))); + talloc_zfree(tmpctx); + return ret; +} + /* =Delete-Netgroup-by-Name============================================== */ int sysdb_delete_netgroup(struct sysdb_ctx *sysdb, -- cgit