Hi list,

there is patch solving [1] attached.

It is possible that we will have similiar problem with other local keys, so I wrote special function for adding key to list of missing with condition if it is needed or not.

[1] https://fedorahosted.org/sssd/ticket/2841

Regards

--
Petr^4 Čech
>From 42ef4e523ad7e56f3014a7f6bb6a7423d24eccde Mon Sep 17 00:00:00 2001
From: Petr Cech <pc...@redhat.com>
Date: Fri, 22 Jul 2016 14:28:54 +0200
Subject: [PATCH] LDAP: Fixing of removing netgroup from cache

There were problem with local key which wasn't properly removed.
This patch fixes it.

Resolves:
https://fedorahosted.org/sssd/ticket/2841
---
 src/providers/ldap/sdap_async_netgroups.c | 40 +++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/src/providers/ldap/sdap_async_netgroups.c b/src/providers/ldap/sdap_async_netgroups.c
index df233d956df70cfcb5f68bd2afc9e2a23c50c3bb..f72106006c668d38ee794d4ba28b45517eb5a282 100644
--- a/src/providers/ldap/sdap_async_netgroups.c
+++ b/src/providers/ldap/sdap_async_netgroups.c
@@ -38,6 +38,35 @@ bool is_dn(const char *str)
     return (ret == LDAP_SUCCESS ? true : false);
 }
 
+static errno_t add_to_missing_attrs (TALLOC_CTX * mem_ctx,
+                                     struct sysdb_attrs *attrs,
+                                     const char *ext_key,
+                                     char ***_missing)
+{
+    bool is_present = false;
+    size_t size = 0;
+    size_t ret;
+
+    for (int i = 0; i < attrs->num; i++) {
+        if (strcmp(ext_key, attrs->a[i].name) == 0) {
+            is_present = true;
+        }
+        size++;
+    }
+
+    if (is_present == false) {
+        ret = add_string_to_list(attrs, ext_key, _missing);
+        if (ret != EOK) {
+            goto fail;
+        }
+    }
+
+    ret = EOK;
+
+fail:
+    return ret;
+}
+
 static errno_t sdap_save_netgroup(TALLOC_CTX *memctx,
                                   struct sss_domain_info *dom,
                                   struct sdap_options *opts,
@@ -138,6 +167,17 @@ static errno_t sdap_save_netgroup(TALLOC_CTX *memctx,
         goto fail;
     }
 
+    /* Prepare SYSDB_NETGROUP_MEMBER removing
+     * if not present in netgroup_attrs
+     */
+    ret = add_to_missing_attrs(attrs, netgroup_attrs, SYSDB_NETGROUP_MEMBER,
+                               &missing);
+    if (ret != EOK) {
+        DEBUG(SSSDBG_CRIT_FAILURE, "Failed to add [%s] to missing attributes\n",
+              SYSDB_NETGROUP_MEMBER);
+        goto fail;
+    }
+
     ret = sysdb_add_netgroup(dom, name, NULL, netgroup_attrs, missing,
                              dom->netgroup_timeout, now);
     if (ret) goto fail;
-- 
2.7.4

_______________________________________________
sssd-devel mailing list
sssd-devel@lists.fedorahosted.org
https://lists.fedorahosted.org/admin/lists/sssd-devel@lists.fedorahosted.org

Reply via email to