diff options
author | Simo Sorce <simo@redhat.com> | 2013-01-08 17:15:52 -0500 |
---|---|---|
committer | Jakub Hrozek <jhrozek@redhat.com> | 2013-01-10 10:50:10 +0100 |
commit | d0483eefc41ac295ed4c56e08ad76ca7b5fb3b2c (patch) | |
tree | 78a1c297b1e024d9f161aab642eb842e5f9ab1c4 | |
parent | a26dfbfdd5a325acd85f4f339587365f29810342 (diff) | |
download | sssd-d0483eefc41ac295ed4c56e08ad76ca7b5fb3b2c.tar.gz sssd-d0483eefc41ac295ed4c56e08ad76ca7b5fb3b2c.tar.xz sssd-d0483eefc41ac295ed4c56e08ad76ca7b5fb3b2c.zip |
Add sysdb_search_service() helper function
-rw-r--r-- | src/db/sysdb_services.c | 56 | ||||
-rw-r--r-- | src/db/sysdb_services.h | 7 |
2 files changed, 63 insertions, 0 deletions
diff --git a/src/db/sysdb_services.c b/src/db/sysdb_services.c index f3ed48ed8..45e294e57 100644 --- a/src/db/sysdb_services.c +++ b/src/db/sysdb_services.c @@ -802,3 +802,59 @@ done: talloc_free(tmp_ctx); return ret; } + +errno_t sysdb_search_services(TALLOC_CTX *mem_ctx, + struct sysdb_ctx *sysdb, + const char *sub_filter, + const char **attrs, + size_t *msgs_count, + struct ldb_message ***msgs) +{ + TALLOC_CTX *tmp_ctx; + struct ldb_dn *basedn; + char *filter; + int ret; + + tmp_ctx = talloc_new(NULL); + if (!tmp_ctx) { + return ENOMEM; + } + + basedn = ldb_dn_new_fmt(tmp_ctx, sysdb->ldb, + SYSDB_TMPL_SVC_BASE, sysdb->domain->name); + if (!basedn) { + DEBUG(SSSDBG_OP_FAILURE, ("Failed to build base dn\n")); + ret = ENOMEM; + goto fail; + } + + filter = talloc_asprintf(tmp_ctx, "(&(%s)%s)", SYSDB_SC, sub_filter); + if (!filter) { + DEBUG(SSSDBG_OP_FAILURE, ("Failed to build filter\n")); + ret = ENOMEM; + goto fail; + } + + DEBUG(SSSDBG_TRACE_INTERNAL, + ("Search services 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(tmp_ctx); + return EOK; + +fail: + if (ret == ENOENT) { + DEBUG(SSSDBG_TRACE_INTERNAL, ("No such entry\n")); + } + else if (ret) { + DEBUG(SSSDBG_MINOR_FAILURE, ("Error: %d (%s)\n", ret, strerror(ret))); + } + talloc_zfree(tmp_ctx); + return ret; +} diff --git a/src/db/sysdb_services.h b/src/db/sysdb_services.h index 29d531ed8..351a89f5b 100644 --- a/src/db/sysdb_services.h +++ b/src/db/sysdb_services.h @@ -91,4 +91,11 @@ sysdb_set_service_attr(struct sysdb_ctx *sysdb, struct sysdb_attrs *attrs, int mod_op); +errno_t sysdb_search_services(TALLOC_CTX *mem_ctx, + struct sysdb_ctx *sysdb, + const char *sub_filter, + const char **attrs, + size_t *msgs_count, + struct ldb_message ***msgs); + #endif /* SYSDB_SERVICES_H_ */ |