From 8baf23b2d0c24637f5e5790ab6c6f4873dd55f6f Mon Sep 17 00:00:00 2001 From: Lukas Slebodnik Date: Feb 02 2019 21:16:16 +0000 Subject: [PATCH 1/2] sss_cache: Fail if unknown domain is passed in parameter If sss_cache is called with --domain parameter we should fail in case of unknown domain. It might be a typo and user should know about such case. Resolves: https://pagure.io/SSSD/sssd/issue/3919 Merges: https://pagure.io/SSSD/sssd/pull-request/3940 --- diff --git a/src/tools/sss_cache.c b/src/tools/sss_cache.c index b6ff874..6bdcf61 100644 --- a/src/tools/sss_cache.c +++ b/src/tools/sss_cache.c @@ -152,6 +152,12 @@ int main(int argc, const char *argv[]) /* nothing to invalidate; no reason to fail */ ret = EOK; goto done; + } else if (ret == ERR_DOMAIN_NOT_FOUND) { + /* Cannot find domain specified in the parameter --domain. + * It might be a typo and therefore we will fail. + */ + ret = ENOENT; + goto done; } else if (ret != EOK) { DEBUG(SSSDBG_CRIT_FAILURE, "Error initializing context for the application\n"); @@ -858,7 +864,7 @@ static errno_t init_context(int argc, const char *argv[], } ret = init_domains(ctx, values.domain); - if (ret == ENOENT) { + if (ret == ENOENT && values.domain == NULL) { /* Nothing to invalidate; do not log confusing messages. */ goto fini; } else if (ret != EOK) { @@ -866,6 +872,7 @@ static errno_t init_context(int argc, const char *argv[], ERROR("Could not open domain %1$s. If the domain is a subdomain " "(trusted domain), use fully qualified name instead of " "--domain/-d parameter.\n", values.domain); + ret = ERR_DOMAIN_NOT_FOUND; } else { ERROR("Could not open available domains\n"); } From bf0f9914ba54324a067350609bd2151bb5fb4d05 Mon Sep 17 00:00:00 2001 From: Lukas Slebodnik Date: Feb 02 2019 21:51:46 +0000 Subject: [PATCH 2/2] test_sss_cache: Add test case for wrong domain in parameter Related to: https://pagure.io/SSSD/sssd/issue/3919 Merges: https://pagure.io/SSSD/sssd/pull-request/3940 --- diff --git a/src/tests/intg/test_sss_cache.py b/src/tests/intg/test_sss_cache.py index ced6c35..474d56d 100644 --- a/src/tests/intg/test_sss_cache.py +++ b/src/tests/intg/test_sss_cache.py @@ -57,5 +57,11 @@ def test_invalidate_missing_specific_entry(): ret = subprocess.call(["sss_cache", "-u", "non-existing"]) assert ret == 2 + ret = subprocess.call(["sss_cache", "-d", "non-existing", "-u", "dummy"]) + assert ret == 2 + ret = subprocess.call(["sss_cache", "-g", "non-existing"]) assert ret == 2 + + ret = subprocess.call(["sss_cache", "-d", "non-existing", "-g", "dummy"]) + assert ret == 2