Blame SOURCES/0115-sdap-Skip-exact-duplicates-when-extending-maps.patch

b2d430
From c4379aa97754b4c4cfc02663315b7c6319e3fa61 Mon Sep 17 00:00:00 2001
b2d430
From: =?UTF-8?q?Michal=20=C5=BDidek?= <mzidek@redhat.com>
b2d430
Date: Wed, 10 Aug 2016 15:41:34 +0200
b2d430
Subject: [PATCH 115/115] sdap: Skip exact duplicates when extending maps
b2d430
MIME-Version: 1.0
b2d430
Content-Type: text/plain; charset=UTF-8
b2d430
Content-Transfer-Encoding: 8bit
b2d430
b2d430
When extending map with entry that already
b2d430
exists in the map in the exacty same form,
b2d430
then there is no need to fail.
b2d430
b2d430
We should only fail if we try to
b2d430
change purpose of already used sysdb
b2d430
attribute.
b2d430
b2d430
Resolves:
b2d430
https://fedorahosted.org/sssd/ticket/3120
b2d430
b2d430
Signed-off-by: Lukas Slebodnik <lslebodn@redhat.com>
b2d430
b2d430
Reviewed-by: Lukáš Slebodník <lslebodn@redhat.com>
b2d430
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
b2d430
---
b2d430
 src/providers/ldap/sdap.c | 42 ++++++++++++++++++++++++++++++++----------
b2d430
 1 file changed, 32 insertions(+), 10 deletions(-)
b2d430
b2d430
diff --git a/src/providers/ldap/sdap.c b/src/providers/ldap/sdap.c
b2d430
index 97b8f126d4ed6bc59c510d5763789a458bd4863a..dc7d5e0caf223c3ee3c43054aa44e796f1b37766 100644
b2d430
--- a/src/providers/ldap/sdap.c
b2d430
+++ b/src/providers/ldap/sdap.c
b2d430
@@ -122,19 +122,30 @@ static errno_t split_extra_attr(TALLOC_CTX *mem_ctx,
b2d430
     return EOK;
b2d430
 }
b2d430
 
b2d430
-static bool is_sysdb_duplicate(struct sdap_attr_map *map,
b2d430
-                               int num_entries,
b2d430
-                               const char *sysdb_attr)
b2d430
+enum duplicate_t {
b2d430
+    NOT_FOUND = 0,
b2d430
+    ALREADY_IN_MAP, /* nothing to add */
b2d430
+    CONFLICT_WITH_MAP /* attempt to redefine attribute */
b2d430
+};
b2d430
+
b2d430
+static enum duplicate_t check_duplicate(struct sdap_attr_map *map,
b2d430
+                                        int num_entries,
b2d430
+                                        const char *sysdb_attr,
b2d430
+                                        const char *ldap_attr)
b2d430
 {
b2d430
     int i;
b2d430
 
b2d430
     for (i = 0; i < num_entries; i++) {
b2d430
         if (strcmp(map[i].sys_name, sysdb_attr) == 0) {
b2d430
-            return true;
b2d430
+            if (strcmp(map[i].name, ldap_attr) == 0) {
b2d430
+                return ALREADY_IN_MAP;
b2d430
+            } else {
b2d430
+                return CONFLICT_WITH_MAP;
b2d430
+            }
b2d430
         }
b2d430
     }
b2d430
 
b2d430
-    return false;
b2d430
+    return NOT_FOUND;
b2d430
 }
b2d430
 
b2d430
 int sdap_extend_map(TALLOC_CTX *memctx,
b2d430
@@ -167,14 +178,20 @@ int sdap_extend_map(TALLOC_CTX *memctx,
b2d430
         return ENOMEM;
b2d430
     }
b2d430
 
b2d430
-    for (i = 0; extra_attrs[i]; i++) {
b2d430
-        ret = split_extra_attr(map, extra_attrs[i], &sysdb_attr, &ldap_attr);
b2d430
+    for (i = 0; *extra_attrs != NULL; extra_attrs++) {
b2d430
+        ret = split_extra_attr(map, *extra_attrs, &sysdb_attr, &ldap_attr);
b2d430
         if (ret != EOK) {
b2d430
-            DEBUG(SSSDBG_MINOR_FAILURE, "Cannot split %s\n", extra_attrs[i]);
b2d430
+            DEBUG(SSSDBG_MINOR_FAILURE, "Cannot split %s\n", *extra_attrs);
b2d430
             continue;
b2d430
         }
b2d430
 
b2d430
-        if (is_sysdb_duplicate(map, num_entries, sysdb_attr)) {
b2d430
+        ret = check_duplicate(map, num_entries, sysdb_attr, ldap_attr);
b2d430
+        if (ret == ALREADY_IN_MAP) {
b2d430
+            DEBUG(SSSDBG_TRACE_FUNC,
b2d430
+                  "Attribute %s (%s in LDAP) is already in map.\n",
b2d430
+                  sysdb_attr, ldap_attr);
b2d430
+            continue;
b2d430
+        } else if (ret == CONFLICT_WITH_MAP) {
b2d430
             DEBUG(SSSDBG_FATAL_FAILURE,
b2d430
                   "Attribute %s (%s in LDAP) is already used by SSSD, please "
b2d430
                   "choose a different cache name\n", sysdb_attr, ldap_attr);
b2d430
@@ -193,9 +210,14 @@ int sdap_extend_map(TALLOC_CTX *memctx,
b2d430
             map[num_entries+i].def_name == NULL) {
b2d430
             return ENOMEM;
b2d430
         }
b2d430
-        DEBUG(SSSDBG_TRACE_FUNC, "Extending map with %s\n", extra_attrs[i]);
b2d430
+        DEBUG(SSSDBG_TRACE_FUNC, "Extending map with %s\n", *extra_attrs);
b2d430
+
b2d430
+        /* index must be incremented only for appended entry. */
b2d430
+        i++;
b2d430
     }
b2d430
 
b2d430
+    nextra = i;
b2d430
+
b2d430
     /* Sentinel */
b2d430
     memset(&map[num_entries+nextra], 0, sizeof(struct sdap_attr_map));
b2d430
 
b2d430
-- 
b2d430
2.4.11
b2d430