Blob Blame History Raw
From 845e3a3acea6f83b15ed3d887fcc4ed42cb3eb5a Mon Sep 17 00:00:00 2001
From: Sumit Bose <sbose@redhat.com>
Date: Mon, 11 Jul 2016 15:04:32 +0200
Subject: [PATCH 28/31] views: allow override added for non-default views at
 runtime
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Currently a new override for a non-default view cannot be displayed at
run-time. It even does not only require a restart but the view must be
un-applied and applied again to make the changes visible.

This patch fixes this and makes non-default view behave like the default
view where the data from a newly added override are displayed after the
cached entry of the related object is expired.

Resolves https://fedorahosted.org/sssd/ticket/3092

Reviewed-by: Pavel Březina <pbrezina@redhat.com>
(cherry picked from commit 26a3d4f2ef35a088e4c5fc928290052c89a2ff43)
---
 src/db/sysdb_views.c | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/src/db/sysdb_views.c b/src/db/sysdb_views.c
index 7adc1523050243b8936cb98be3c71ce4364a03db..2b89e5ca41f719e1217ef3b9e0fd683656e05d42 100644
--- a/src/db/sysdb_views.c
+++ b/src/db/sysdb_views.c
@@ -454,15 +454,23 @@ errno_t sysdb_store_override(struct sss_domain_info *domain,
     obj_override_dn = ldb_msg_find_attr_as_string(msgs[0], SYSDB_OVERRIDE_DN,
                                                   NULL);
     if (obj_override_dn != NULL) {
+        /* obj_override_dn can either point to the object itself, i.e there is
+         * no override, or to a overide object. This means it can change from
+         * the object DN to a override DN and back but not from one override
+         * DN to a different override DN. If the new and the old DN are the
+         * same we do not need to update the original object.  */
         if (strcmp(obj_override_dn, override_dn_str) != 0) {
-            DEBUG(SSSDBG_CRIT_FAILURE,
-                  "Existing [%s] and new [%s] override DN do not match.\n",
-                   obj_override_dn, override_dn_str);
-            ret = EINVAL;
-            goto done;
+            if (strcmp(obj_override_dn, obj_dn_str) != 0
+                    && strcmp(override_dn_str, obj_dn_str) != 0) {
+                DEBUG(SSSDBG_CRIT_FAILURE,
+                      "Existing [%s] and new [%s] override DN do not match.\n",
+                       obj_override_dn, override_dn_str);
+                ret = EINVAL;
+                goto done;
+            }
+        } else {
+            add_ref = false;
         }
-
-        add_ref = false;
     }
 
     ret = ldb_transaction_start(domain->sysdb->ldb);
@@ -580,7 +588,9 @@ errno_t sysdb_store_override(struct sss_domain_info *domain,
 
         msg->dn = obj_dn;
 
-        ret = ldb_msg_add_empty(msg, SYSDB_OVERRIDE_DN, LDB_FLAG_MOD_ADD,
+        ret = ldb_msg_add_empty(msg, SYSDB_OVERRIDE_DN,
+                                obj_override_dn == NULL ? LDB_FLAG_MOD_ADD
+                                                        : LDB_FLAG_MOD_REPLACE,
                                 NULL);
         if (ret != LDB_SUCCESS) {
             DEBUG(SSSDBG_OP_FAILURE, "ldb_msg_add_empty failed.\n");
-- 
2.4.11