From c9eaf8c1e02c155b7ca7ffb2b1edade8a23ce1ff Mon Sep 17 00:00:00 2001 From: Pavel Reichl Date: Tue, 4 Nov 2014 08:52:54 +0000 Subject: SYSDB: sysdb_get_bool() return ENOENT & unit tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit sysdb_get_bool() return ENOENT if no result is found. Unit test for sysdb_get_bool() & sysdb_set_bool() was added. This patch also fixes ldap_setup_enumeration() to handle ENOENT returned by sysdb_has_enumerated(). Resolves: https://fedorahosted.org/sssd/ticket/1991 Reviewed-by: Lukáš Slebodník --- src/db/sysdb.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/db') diff --git a/src/db/sysdb.c b/src/db/sysdb.c index 1f02585e..61a22400 100644 --- a/src/db/sysdb.c +++ b/src/db/sysdb.c @@ -1508,6 +1508,7 @@ errno_t sysdb_get_bool(struct sysdb_ctx *sysdb, errno_t ret; int lret; const char *attrs[2] = {attr_name, NULL}; + struct ldb_message_element *el; tmp_ctx = talloc_new(NULL); if (tmp_ctx == NULL) { @@ -1530,7 +1531,7 @@ errno_t sysdb_get_bool(struct sysdb_ctx *sysdb, * to contain this attribute. */ *value = false; - ret = EOK; + ret = ENOENT; goto done; } else if (res->count != 1) { DEBUG(SSSDBG_CRIT_FAILURE, @@ -1539,6 +1540,12 @@ errno_t sysdb_get_bool(struct sysdb_ctx *sysdb, goto done; } + el = ldb_msg_find_element(res->msgs[0], attr_name); + if (el == NULL || el->num_values == 0) { + ret = ENOENT; + goto done; + } + *value = ldb_msg_find_attr_as_bool(res->msgs[0], attr_name, false); ret = EOK; -- cgit