|
|
160847 |
From 26654d3e5f5882dd1681116cb49228d108351d48 Mon Sep 17 00:00:00 2001
|
|
|
160847 |
From: Sumit Bose <sbose@redhat.com>
|
|
|
160847 |
Date: Thu, 12 Aug 2021 09:27:57 +0200
|
|
|
160847 |
Subject: [PATCH] cache_req: cache_first fix for fully-qualified names
|
|
|
160847 |
MIME-Version: 1.0
|
|
|
160847 |
Content-Type: text/plain; charset=UTF-8
|
|
|
160847 |
Content-Transfer-Encoding: 8bit
|
|
|
160847 |
|
|
|
160847 |
With commit b572871236a7f9059d375a5ab1bff8cbfd519956 "cache_req:
|
|
|
160847 |
introduce cache_behavior enumeration" the processing of cache and
|
|
|
160847 |
backend lookups was refactored. Unfortunately this introduce an issue
|
|
|
160847 |
when looking up users or groups with a fully-qualified name and the
|
|
|
160847 |
'cache_first = True' option is set.
|
|
|
160847 |
|
|
|
160847 |
In the old code the case when a domain name is available was handle
|
|
|
160847 |
before the cache_first first option was evaluated and cache_req was
|
|
|
160847 |
instructed to first look in the cache and then call the backend if the
|
|
|
160847 |
object is not available or expired, i.e. the default behavior. Since
|
|
|
160847 |
only a single domain is involved this is in agreement with 'cache_first
|
|
|
160847 |
= True' and only a single iteration is needed.
|
|
|
160847 |
|
|
|
160847 |
In the new code the cache_first option is evaluated before the presence
|
|
|
160847 |
of a domain name is checked and as a result even for single domain
|
|
|
160847 |
searches the first cache_req iteration is only looking at the cache and
|
|
|
160847 |
will not call the backend. This means the now for searches with a
|
|
|
160847 |
fully-qualified name a second iteration is needed if the object was not
|
|
|
160847 |
found in the cache.
|
|
|
160847 |
|
|
|
160847 |
Unfortunately the old exit condition that if a domain name is present
|
|
|
160847 |
only a single iteration is needed is still present in the new code which
|
|
|
160847 |
effectively makes requests with fully-qualified named only search the
|
|
|
160847 |
cache and never call the backends. This patch removes the exit condition
|
|
|
160847 |
and does a second iteration for fully-qualified names as well if
|
|
|
160847 |
'cache_first = True' is set.
|
|
|
160847 |
|
|
|
160847 |
Resolves: https://github.com/SSSD/sssd/issues/5744
|
|
|
160847 |
|
|
|
160847 |
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
|
|
|
160847 |
---
|
|
|
160847 |
src/responder/common/cache_req/cache_req.c | 3 +-
|
|
|
160847 |
src/tests/cmocka/test_responder_cache_req.c | 53 +++++++++++++++++++++
|
|
|
160847 |
2 files changed, 54 insertions(+), 2 deletions(-)
|
|
|
160847 |
|
|
|
160847 |
diff --git a/src/responder/common/cache_req/cache_req.c b/src/responder/common/cache_req/cache_req.c
|
|
|
160847 |
index 750d655c1..56ec077f3 100644
|
|
|
160847 |
--- a/src/responder/common/cache_req/cache_req.c
|
|
|
160847 |
+++ b/src/responder/common/cache_req/cache_req.c
|
|
|
160847 |
@@ -1331,8 +1331,7 @@ static errno_t cache_req_select_domains(struct tevent_req *req,
|
|
|
160847 |
|
|
|
160847 |
state = tevent_req_data(req, struct cache_req_state);
|
|
|
160847 |
|
|
|
160847 |
- if ((state->cr->cache_behavior != CACHE_REQ_CACHE_FIRST)
|
|
|
160847 |
- || (domain_name != NULL)) {
|
|
|
160847 |
+ if (state->cr->cache_behavior != CACHE_REQ_CACHE_FIRST) {
|
|
|
160847 |
|
|
|
160847 |
if (!state->first_iteration) {
|
|
|
160847 |
/* We're done here. */
|
|
|
160847 |
diff --git a/src/tests/cmocka/test_responder_cache_req.c b/src/tests/cmocka/test_responder_cache_req.c
|
|
|
160847 |
index 5cf7660e7..27a525f6e 100644
|
|
|
160847 |
--- a/src/tests/cmocka/test_responder_cache_req.c
|
|
|
160847 |
+++ b/src/tests/cmocka/test_responder_cache_req.c
|
|
|
160847 |
@@ -992,6 +992,56 @@ void test_user_by_name_missing_notfound(void **state)
|
|
|
160847 |
assert_true(test_ctx->dp_called);
|
|
|
160847 |
}
|
|
|
160847 |
|
|
|
160847 |
+void test_user_by_name_missing_notfound_cache_first(void **state)
|
|
|
160847 |
+{
|
|
|
160847 |
+ struct cache_req_test_ctx *test_ctx = NULL;
|
|
|
160847 |
+
|
|
|
160847 |
+ test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
|
|
|
160847 |
+ test_ctx->rctx->cache_first = true;
|
|
|
160847 |
+
|
|
|
160847 |
+ /* Mock values. */
|
|
|
160847 |
+ will_return(__wrap_sss_dp_get_account_send, test_ctx);
|
|
|
160847 |
+ mock_account_recv_simple();
|
|
|
160847 |
+ mock_parse_inp(users[0].short_name, NULL, ERR_OK);
|
|
|
160847 |
+
|
|
|
160847 |
+ /* Test. */
|
|
|
160847 |
+ run_user_by_name(test_ctx, test_ctx->tctx->dom, 0, ENOENT);
|
|
|
160847 |
+ assert_true(test_ctx->dp_called);
|
|
|
160847 |
+}
|
|
|
160847 |
+
|
|
|
160847 |
+void test_user_by_name_missing_notfound_full_name(void **state)
|
|
|
160847 |
+{
|
|
|
160847 |
+ struct cache_req_test_ctx *test_ctx = NULL;
|
|
|
160847 |
+
|
|
|
160847 |
+ test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
|
|
|
160847 |
+
|
|
|
160847 |
+ /* Mock values. */
|
|
|
160847 |
+ will_return(__wrap_sss_dp_get_account_send, test_ctx);
|
|
|
160847 |
+ mock_account_recv_simple();
|
|
|
160847 |
+ mock_parse_inp(users[0].short_name, TEST_DOM_NAME, ERR_OK);
|
|
|
160847 |
+
|
|
|
160847 |
+ /* Test. */
|
|
|
160847 |
+ run_user_by_name(test_ctx, test_ctx->tctx->dom, 0, ENOENT);
|
|
|
160847 |
+ assert_true(test_ctx->dp_called);
|
|
|
160847 |
+}
|
|
|
160847 |
+
|
|
|
160847 |
+void test_user_by_name_missing_notfound_cache_first_full_name(void **state)
|
|
|
160847 |
+{
|
|
|
160847 |
+ struct cache_req_test_ctx *test_ctx = NULL;
|
|
|
160847 |
+
|
|
|
160847 |
+ test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
|
|
|
160847 |
+ test_ctx->rctx->cache_first = true;
|
|
|
160847 |
+
|
|
|
160847 |
+ /* Mock values. */
|
|
|
160847 |
+ will_return(__wrap_sss_dp_get_account_send, test_ctx);
|
|
|
160847 |
+ mock_account_recv_simple();
|
|
|
160847 |
+ mock_parse_inp(users[0].short_name, TEST_DOM_NAME, ERR_OK);
|
|
|
160847 |
+
|
|
|
160847 |
+ /* Test. */
|
|
|
160847 |
+ run_user_by_name(test_ctx, test_ctx->tctx->dom, 0, ENOENT);
|
|
|
160847 |
+ assert_true(test_ctx->dp_called);
|
|
|
160847 |
+}
|
|
|
160847 |
+
|
|
|
160847 |
void test_user_by_name_multiple_domains_requested_domains_found(void **state)
|
|
|
160847 |
{
|
|
|
160847 |
struct cache_req_test_ctx *test_ctx = NULL;
|
|
|
160847 |
@@ -4255,6 +4305,9 @@ int main(int argc, const char *argv[])
|
|
|
160847 |
new_single_domain_test(user_by_name_ncache),
|
|
|
160847 |
new_single_domain_test(user_by_name_missing_found),
|
|
|
160847 |
new_single_domain_test(user_by_name_missing_notfound),
|
|
|
160847 |
+ new_single_domain_test(user_by_name_missing_notfound_cache_first),
|
|
|
160847 |
+ new_single_domain_test(user_by_name_missing_notfound_full_name),
|
|
|
160847 |
+ new_single_domain_test(user_by_name_missing_notfound_cache_first_full_name),
|
|
|
160847 |
new_multi_domain_test(user_by_name_multiple_domains_found),
|
|
|
160847 |
new_multi_domain_test(user_by_name_multiple_domains_notfound),
|
|
|
160847 |
new_multi_domain_test(user_by_name_multiple_domains_parse),
|
|
|
160847 |
--
|
|
|
160847 |
2.26.3
|
|
|
160847 |
|