From 61602026ed8c91efd166000562899670449f1b50 Mon Sep 17 00:00:00 2001 From: Pavel Reichl Date: Fri, 11 Jul 2014 15:21:59 +0100 Subject: SYSDB: SSS_LDB_SEARCH - macro around ldb_search MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch amends previous patch 5153e8b9793dea1e212ca08af0f77ea1d023cbb7. Macro SSS_LDB_SEARCH is used instead of using fuction sss_ldb_search as a wrapper around ldb_search which could lead to premature expansion of variadic parameters. Part of solution for: https://fedorahosted.org/sssd/ticket/1991 Reviewed-by: Lukáš Slebodník --- src/db/sysdb.h | 17 ++++++++++++----- src/db/sysdb_ops.c | 51 --------------------------------------------------- src/db/sysdb_search.c | 10 +++++----- 3 files changed, 17 insertions(+), 61 deletions(-) (limited to 'src/db') diff --git a/src/db/sysdb.h b/src/db/sysdb.h index 3cef1e66b..295949cf4 100644 --- a/src/db/sysdb.h +++ b/src/db/sysdb.h @@ -481,11 +481,6 @@ int sysdb_get_netgroup_attr(TALLOC_CTX *mem_ctx, const char **attributes, struct ldb_result **res); -errno_t sss_ldb_search(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, - struct ldb_result **_result, struct ldb_dn *base, - enum ldb_scope scope, const char * const *attrs, - const char *exp_fmt, ...) SSS_ATTRIBUTE_PRINTF(7, 8); - /* functions that modify the databse * they have to be called within a transaction * See sysdb_transaction_send()/_recv() */ @@ -514,6 +509,18 @@ int sysdb_search_entry(TALLOC_CTX *mem_ctx, size_t *_msgs_count, struct ldb_message ***_msgs); +#define SSS_LDB_SEARCH(ret, ldb, mem_ctx, _result, base, scope, attrs, \ + exp_fmt, ...) do { \ + int _sls_lret; \ + \ + _sls_lret = ldb_search(ldb, mem_ctx, _result, base, scope, attrs, \ + exp_fmt, ##__VA_ARGS__); \ + ret = sysdb_error_to_errno(_sls_lret); \ + if (ret == EOK && (*_result)->count == 0) { \ + ret = ENOENT; \ + } \ +} while(0) + /* Search User (by uid, sid or name) */ int sysdb_search_user_by_name(TALLOC_CTX *mem_ctx, struct sss_domain_info *domain, diff --git a/src/db/sysdb_ops.c b/src/db/sysdb_ops.c index e32d79a70..8a7feaefe 100644 --- a/src/db/sysdb_ops.c +++ b/src/db/sysdb_ops.c @@ -74,57 +74,6 @@ static uint32_t get_attr_as_uint32(struct ldb_message *msg, const char *attr) return l; } - -/* Wrapper around ldb_search to ensure that if zero results are found then - * ENOENT is returned - */ -errno_t sss_ldb_search(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, - struct ldb_result **_result, struct ldb_dn *base, - enum ldb_scope scope, const char * const *attrs, - const char *exp_fmt, ...) -{ - char *s; - int lret; - va_list ap; - errno_t ret; - TALLOC_CTX *tmp_ctx = NULL; - - if (exp_fmt != NULL) { - tmp_ctx = talloc_new(NULL); - if (tmp_ctx == NULL) { - ret = ENOMEM; - goto done; - } - - va_start(ap, exp_fmt); - s = talloc_vasprintf(tmp_ctx, exp_fmt, ap); - va_end(ap); - - if (s == NULL) { - DEBUG(SSSDBG_MINOR_FAILURE, "Failed to process filter.\n"); - ret = ENOMEM; - goto done; - } - lret = ldb_search(ldb, mem_ctx, _result, base, scope, attrs, "%s", s); - } else { - lret = ldb_search(ldb, mem_ctx, _result, base, scope, attrs, NULL); - } - - ret = sysdb_error_to_errno(lret); - if (ret != EOK) { - goto done; - } - - if ((*_result)->count == 0) { - ret = ENOENT; - goto done; - } - -done: - talloc_free(tmp_ctx); - return ret; -} - /* * The wrapper around ldb_modify that uses LDB_CONTROL_PERMISSIVE_MODIFY_OID * so that on adds entries that already exist are skipped and similarly diff --git a/src/db/sysdb_search.c b/src/db/sysdb_search.c index ff14c4a98..3d789ae85 100644 --- a/src/db/sysdb_search.c +++ b/src/db/sysdb_search.c @@ -815,11 +815,11 @@ errno_t sysdb_getnetgr(TALLOC_CTX *mem_ctx, goto done; } - ret = sss_ldb_search(domain->sysdb->ldb, tmp_ctx, &result, base_dn, - LDB_SCOPE_SUBTREE, attrs, - SYSDB_NETGR_TRIPLES_FILTER, lc_sanitized_netgroup, - sanitized_netgroup, sanitized_netgroup, - netgroup_dn); + SSS_LDB_SEARCH(ret, domain->sysdb->ldb, tmp_ctx, &result, base_dn, + LDB_SCOPE_SUBTREE, attrs, + SYSDB_NETGR_TRIPLES_FILTER, lc_sanitized_netgroup, + sanitized_netgroup, sanitized_netgroup, + netgroup_dn); if (ret == EOK || ret == ENOENT) { *res = talloc_steal(mem_ctx, result); -- cgit