From 63cc761feda00285129afd9c376999b0bdc02dd8 Mon Sep 17 00:00:00 2001 From: Lukas Slebodnik Date: Jan 28 2019 21:32:26 +0000 Subject: [PATCH 1/4] sss_cache: Do not fail for missing domains The conf.db needn't exist(sssd has never been started) and in such situation sss_cache failed when trying to invalidate all entries. There is nothing to invalidate and therefore we are already in state which we want to achieve with calling sss_cache. No reason to fail. Resolves: https://pagure.io/SSSD/sssd/issue/3919 Merges: https://pagure.io/SSSD/sssd/pull-request/3926 --- diff --git a/src/confdb/confdb.c b/src/confdb/confdb.c index d3fdd31..07a1b16 100644 --- a/src/confdb/confdb.c +++ b/src/confdb/confdb.c @@ -1505,7 +1505,7 @@ int confdb_get_domains(struct confdb_ctx *cdb, CONFDB_MONITOR_ACTIVE_DOMAINS, &domlist); if (ret == ENOENT) { - DEBUG(SSSDBG_FATAL_FAILURE, "No domains configured, fatal error!\n"); + DEBUG(SSSDBG_MINOR_FAILURE, "No domains configured, fatal error!\n"); goto done; } if (ret != EOK ) { diff --git a/src/tools/sss_cache.c b/src/tools/sss_cache.c index 8a40b38..eb310d3 100644 --- a/src/tools/sss_cache.c +++ b/src/tools/sss_cache.c @@ -148,7 +148,11 @@ int main(int argc, const char *argv[]) struct sss_domain_info *dinfo; ret = init_context(argc, argv, &tctx); - if (ret != EOK) { + if (ret == ENOENT) { + /* nothing to invalidate; no reason to fail */ + ret = EOK; + goto done; + } else if (ret != EOK) { DEBUG(SSSDBG_CRIT_FAILURE, "Error initializing context for the application\n"); goto done; @@ -847,7 +851,10 @@ static errno_t init_context(int argc, const char *argv[], } ret = init_domains(ctx, values.domain); - if (ret != EOK) { + if (ret == ENOENT) { + /* Nothing to invalidate; do not log confusing messages. */ + goto fini; + } else if (ret != EOK) { if (values.domain) { ERROR("Could not open domain %1$s. If the domain is a subdomain " "(trusted domain), use fully qualified name instead of " From 4b7033814d09b065f34eb1d7fb737e70cc0777b2 Mon Sep 17 00:00:00 2001 From: Lukas Slebodnik Date: Jan 28 2019 21:32:34 +0000 Subject: [PATCH 2/4] intg: Add test for sss_cache & shadow-utils use-case Related to: https://pagure.io/SSSD/sssd/issue/3919 --- diff --git a/src/tests/intg/test_sss_cache.py b/src/tests/intg/test_sss_cache.py new file mode 100644 index 0000000..22f12f0 --- /dev/null +++ b/src/tests/intg/test_sss_cache.py @@ -0,0 +1,34 @@ +# +# SSSD files domain tests +# +# Copyright (c) 2019 Red Hat, Inc. +# Author: Lukas Slebodnik +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +import subprocess + + +def test_missing_domains(): + # Utilities in shadow-utils call sss_cache but it might fail in case + # sssd has never been started on such host. + ret = subprocess.call(["sss_cache", "-U"]) + assert ret == 0 + + ret = subprocess.call(["sss_cache", "-G"]) + assert ret == 0 + + ret = subprocess.call(["sss_cache", "-E"]) + assert ret == 0 From 0d973730b0d9dd01f84f905fa972fdf4329b33f6 Mon Sep 17 00:00:00 2001 From: Lukas Slebodnik Date: Jan 28 2019 21:32:34 +0000 Subject: [PATCH 3/4] sss_cache: Do not fail if noting was cached It might happen that we have some domains in conf.db but nothing has been cached yet. sss_cache failed in such situation, bash-4.4# sss_cache -E No cache object matched the specified search bash-4.4# echo $? 2 Because there is nothing to invalidate and so we are already in state which we want to achieve with calling sss_cache. There is no reason to fail. We will still fail for invalidating particular entry. User might have a typo in the name and should be informed about possible mistake. bash-4.4# sss_cache -u test_user No cache object matched the specified search bash-4.4# echo $? 2 Resolves: https://pagure.io/SSSD/sssd/issue/3919 Merges: https://pagure.io/SSSD/sssd/pull-request/3926 --- diff --git a/src/tools/sss_cache.c b/src/tools/sss_cache.c index eb310d3..b6ff874 100644 --- a/src/tools/sss_cache.c +++ b/src/tools/sss_cache.c @@ -488,6 +488,13 @@ static bool invalidate_entries(TALLOC_CTX *ctx, if (ret == ENOENT) { DEBUG(SSSDBG_TRACE_FUNC, "'%s' %s: Not found in domain '%s'\n", type_string, name ? name : "", dinfo->name); + if (name == NULL) { + /* nothing to invalidate in that domain, no reason to fail */ + return true; + } else { + /* we failed to invalidate explicit name; inform about it */ + return false; + } } else { DEBUG(SSSDBG_CRIT_FAILURE, "Searching for %s in domain %s with filter %s failed\n", From 99a42d139dc941859600cc5a55c3a069db22c84c Mon Sep 17 00:00:00 2001 From: Lukas Slebodnik Date: Jan 28 2019 21:32:34 +0000 Subject: [PATCH 4/4] test_sss_cache: Add test case for invalidating missing entries Related to: https://pagure.io/SSSD/sssd/issue/3919 --- diff --git a/src/tests/intg/test_sss_cache.py b/src/tests/intg/test_sss_cache.py index 22f12f0..ced6c35 100644 --- a/src/tests/intg/test_sss_cache.py +++ b/src/tests/intg/test_sss_cache.py @@ -32,3 +32,30 @@ def test_missing_domains(): ret = subprocess.call(["sss_cache", "-E"]) assert ret == 0 + + +def test_nothing_cache(): + # Ensure we do not fail in case there are not any entries to invalidate + ret = subprocess.call(["sssd", "--genconf"]) + assert ret == 0 + + ret = subprocess.call(["sss_cache", "-U"]) + assert ret == 0 + + ret = subprocess.call(["sss_cache", "-G"]) + assert ret == 0 + + ret = subprocess.call(["sss_cache", "-E"]) + assert ret == 0 + + +def test_invalidate_missing_specific_entry(): + # Ensure we will fail when invalidating missing specific entry + ret = subprocess.call(["sssd", "--genconf"]) + assert ret == 0 + + ret = subprocess.call(["sss_cache", "-u", "non-existing"]) + assert ret == 2 + + ret = subprocess.call(["sss_cache", "-g", "non-existing"]) + assert ret == 2