summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Zeleny <jzeleny@redhat.com>2011-05-03 05:21:33 -0400
committerStephen Gallagher <sgallagh@redhat.com>2011-05-04 10:46:55 -0400
commitf62b9b41b0a29a0294d6e532e2bed2b4ce9012e4 (patch)
treeca20778c52c59aa6a4a1f58b1f84433c26191a5e
parent9dfa22c3925792204b22962851dd44175e1b5735 (diff)
downloadsssd-f62b9b41b0a29a0294d6e532e2bed2b4ce9012e4.tar.gz
sssd-f62b9b41b0a29a0294d6e532e2bed2b4ce9012e4.tar.bz2
sssd-f62b9b41b0a29a0294d6e532e2bed2b4ce9012e4.zip
Add a function for searching netgroups with custom filter
-rw-r--r--src/db/sysdb.h8
-rw-r--r--src/db/sysdb_ops.c57
2 files changed, 65 insertions, 0 deletions
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,