Blame SOURCES/0107-CACHE_REQ-Allow-configurationless-shortname-lookups.patch

ecf709
From 7c6fd66fa9ca942bc240b49f903d9d3d85340c4c Mon Sep 17 00:00:00 2001
ecf709
From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= <fidencio@redhat.com>
ecf709
Date: Tue, 11 Apr 2017 17:19:29 +0200
ecf709
Subject: [PATCH 107/110] CACHE_REQ: Allow configurationless shortname lookups
ecf709
MIME-Version: 1.0
ecf709
Content-Type: text/plain; charset=UTF-8
ecf709
Content-Transfer-Encoding: 8bit
ecf709
ecf709
Configurationless shortnames lookups must be allowed when a domains'
ecf709
resolution order is present and the (head) domain is not enforcing the
ecf709
usage of fully-qualified-names.
ecf709
ecf709
With this patch SSSD does not require any kind of changes from client
ecf709
side for taking advantage of shortname lookups.
ecf709
ecf709
Related:
ecf709
https://pagure.io/SSSD/sssd/issue/3001
ecf709
ecf709
Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com>
ecf709
ecf709
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
ecf709
(cherry picked from commit dae798231fc2c575f213785768bc24ed765ba243)
ecf709
---
ecf709
 src/responder/common/cache_req/cache_req.c        |  2 +-
ecf709
 src/responder/common/cache_req/cache_req_domain.c | 48 +++++++++++++++++++++++
ecf709
 src/responder/common/cache_req/cache_req_domain.h |  1 +
ecf709
 3 files changed, 50 insertions(+), 1 deletion(-)
ecf709
ecf709
diff --git a/src/responder/common/cache_req/cache_req.c b/src/responder/common/cache_req/cache_req.c
ecf709
index 3a5fecf34427437bbf95317e05c5bd8b07b4537d..797325a30e6c1ed5f1d4b4c147c65391d5204b52 100644
ecf709
--- a/src/responder/common/cache_req/cache_req.c
ecf709
+++ b/src/responder/common/cache_req/cache_req.c
ecf709
@@ -480,7 +480,7 @@ static errno_t cache_req_search_domains_next(struct tevent_req *req)
ecf709
          * qualified names on domain less search. We do not descend into
ecf709
          * subdomains here since those are implicitly qualified.
ecf709
          */
ecf709
-        if (state->check_next && !allow_no_fqn && domain->fqnames) {
ecf709
+        if (state->check_next && !allow_no_fqn && state->cr_domain->fqnames) {
ecf709
             state->cr_domain = state->cr_domain->next;
ecf709
             continue;
ecf709
         }
ecf709
diff --git a/src/responder/common/cache_req/cache_req_domain.c b/src/responder/common/cache_req/cache_req_domain.c
ecf709
index 86a88efd54ca0f4a0748b44ece1b8515438d4628..bfdd2b7f640178f6d0a0d92f2fed329c856b478c 100644
ecf709
--- a/src/responder/common/cache_req/cache_req_domain.c
ecf709
+++ b/src/responder/common/cache_req/cache_req_domain.c
ecf709
@@ -60,6 +60,48 @@ void cache_req_domain_list_zfree(struct cache_req_domain **cr_domains)
ecf709
     *cr_domains = NULL;
ecf709
 }
ecf709
 
ecf709
+static bool
ecf709
+cache_req_domain_use_fqnames(struct sss_domain_info *domain,
ecf709
+                             bool enforce_non_fqnames)
ecf709
+{
ecf709
+    struct sss_domain_info *head;
ecf709
+
ecf709
+    head = get_domains_head(domain);
ecf709
+
ecf709
+    /*
ecf709
+     * In order to decide whether fully_qualified_names must be used on the
ecf709
+     * lookups we have to take into consideration:
ecf709
+     * - use_fully_qualified_name value of the head of the domains;
ecf709
+     *   (head->fqnames)
ecf709
+     * - the presence of a domains' resolution order list;
ecf709
+     *   (non_fqnames_enforced)
ecf709
+     *
ecf709
+     * The relationship between those two can be described by:
ecf709
+     * - head->fqnames:
ecf709
+     *   - true: in this case doesn't matter whether it's enforced or not,
ecf709
+     *           fully-qualified-names will _always_ be used
ecf709
+     *   - false: in this case (which is also the default case), the usage
ecf709
+     *            depends on it being enforced;
ecf709
+     *
ecf709
+     *     - enforce_non_fqnames:
ecf709
+     *       - true: in this case, the usage of fully-qualified-names is not
ecf709
+     *               needed;
ecf709
+     *       - false: in this case, the usage of fully-qualified-names will be
ecf709
+     *                done accordingly to what's set for the domain itself.
ecf709
+     */
ecf709
+    switch (head->fqnames) {
ecf709
+    case true:
ecf709
+        return true;
ecf709
+    case false:
ecf709
+        switch (enforce_non_fqnames) {
ecf709
+        case true:
ecf709
+            return false;
ecf709
+        case false:
ecf709
+            return domain->fqnames;
ecf709
+        }
ecf709
+    }
ecf709
+}
ecf709
+
ecf709
 static struct cache_req_domain *
ecf709
 cache_req_domain_new_list_from_string_list(TALLOC_CTX *mem_ctx,
ecf709
                                            struct sss_domain_info *domains,
ecf709
@@ -71,9 +113,11 @@ cache_req_domain_new_list_from_string_list(TALLOC_CTX *mem_ctx,
ecf709
     char *name;
ecf709
     int flag = SSS_GND_ALL_DOMAINS;
ecf709
     int i;
ecf709
+    bool enforce_non_fqnames = false;
ecf709
     errno_t ret;
ecf709
 
ecf709
     if (resolution_order != NULL) {
ecf709
+        enforce_non_fqnames = true;
ecf709
         for (i = 0; resolution_order[i] != NULL; i++) {
ecf709
             name = resolution_order[i];
ecf709
             for (dom = domains; dom; dom = get_next_domain(dom, flag)) {
ecf709
@@ -87,6 +131,8 @@ cache_req_domain_new_list_from_string_list(TALLOC_CTX *mem_ctx,
ecf709
                     goto done;
ecf709
                 }
ecf709
                 cr_domain->domain = dom;
ecf709
+                cr_domain->fqnames =
ecf709
+                    cache_req_domain_use_fqnames(dom, enforce_non_fqnames);
ecf709
 
ecf709
                 DLIST_ADD_END(cr_domains, cr_domain,
ecf709
                               struct cache_req_domain *);
ecf709
@@ -106,6 +152,8 @@ cache_req_domain_new_list_from_string_list(TALLOC_CTX *mem_ctx,
ecf709
             goto done;
ecf709
         }
ecf709
         cr_domain->domain = dom;
ecf709
+        cr_domain->fqnames =
ecf709
+            cache_req_domain_use_fqnames(dom, enforce_non_fqnames);
ecf709
 
ecf709
         DLIST_ADD_END(cr_domains, cr_domain, struct cache_req_domain *);
ecf709
     }
ecf709
diff --git a/src/responder/common/cache_req/cache_req_domain.h b/src/responder/common/cache_req/cache_req_domain.h
ecf709
index 000087e5ca2074f22169a4af627810f4f287e430..5bcbb9b493caf05bf71aac5cf7633ded91f22e73 100644
ecf709
--- a/src/responder/common/cache_req/cache_req_domain.h
ecf709
+++ b/src/responder/common/cache_req/cache_req_domain.h
ecf709
@@ -25,6 +25,7 @@
ecf709
 
ecf709
 struct cache_req_domain {
ecf709
     struct sss_domain_info *domain;
ecf709
+    bool fqnames;
ecf709
 
ecf709
     struct cache_req_domain *prev;
ecf709
     struct cache_req_domain *next;
ecf709
-- 
ecf709
2.9.3
ecf709