Blame SOURCES/0021-SYSDB-prepare-for-LOCAL-view.patch

6cf099
From ea6cfe4e1d7c84370bfcc86251ea10b2658b52d3 Mon Sep 17 00:00:00 2001
6cf099
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrezina@redhat.com>
6cf099
Date: Fri, 24 Jul 2015 09:55:28 +0200
6cf099
Subject: [PATCH 21/23] SYSDB: prepare for LOCAL view
6cf099
6cf099
Objects doesn't have to have overrideDN specified when using LOCAL view.
6cf099
Since the view is not stored on the server we do not want to contact
6cf099
LDAP therefore we special case LOCAL view saying that it is OK that
6cf099
this attribute is missing.
6cf099
6cf099
Preparation for:
6cf099
https://fedorahosted.org/sssd/ticket/2584
6cf099
6cf099
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
6cf099
---
6cf099
 src/db/sysdb.h                      | 14 +++++++-
6cf099
 src/db/sysdb_views.c                |  7 ++++
6cf099
 src/providers/ipa/ipa_subdomains.c  |  3 +-
6cf099
 src/tests/cmocka/test_sysdb_views.c | 66 +++++++++++++++++++++++++++++++++++++
6cf099
 4 files changed, 88 insertions(+), 2 deletions(-)
6cf099
6cf099
diff --git a/src/db/sysdb.h b/src/db/sysdb.h
6cf099
index 0f745ccb1a646d77ba4ad3d714d5f4dce0a51211..9e28b5c6691f3710e3051d9746ac5fa47aff8424 100644
6cf099
--- a/src/db/sysdb.h
6cf099
+++ b/src/db/sysdb.h
6cf099
@@ -157,9 +157,10 @@
6cf099
 #define SYSDB_AD_ACCOUNT_EXPIRES "adAccountExpires"
6cf099
 #define SYSDB_AD_USER_ACCOUNT_CONTROL "adUserAccountControl"
6cf099
 
6cf099
+#define SYSDB_DEFAULT_VIEW_NAME "default"
6cf099
+#define SYSDB_LOCAL_VIEW_NAME "LOCAL" /* reserved for client-side overrides */
6cf099
 #define SYSDB_VIEW_CLASS "view"
6cf099
 #define SYSDB_VIEW_NAME "viewName"
6cf099
-#define SYSDB_DEFAULT_VIEW_NAME "default"
6cf099
 #define SYSDB_OVERRIDE_CLASS "overrride"
6cf099
 #define SYSDB_OVERRIDE_ANCHOR_UUID "overrideAnchorUUID"
6cf099
 #define SYSDB_OVERRIDE_USER_CLASS "userOverride"
6cf099
@@ -473,6 +474,17 @@ static inline bool is_default_view(const char *view_name)
6cf099
     }
6cf099
 }
6cf099
 
6cf099
+static inline bool is_local_view(const char *view_name)
6cf099
+{
6cf099
+    /* NULL is treated as default */
6cf099
+    if (view_name != NULL
6cf099
+            && strcmp(view_name, SYSDB_LOCAL_VIEW_NAME) == 0) {
6cf099
+        return true;
6cf099
+    } else {
6cf099
+        return false;
6cf099
+    }
6cf099
+}
6cf099
+
6cf099
 errno_t sysdb_delete_view_tree(struct sysdb_ctx *sysdb, const char *view_name);
6cf099
 
6cf099
 errno_t sysdb_invalidate_overrides(struct sysdb_ctx *sysdb);
6cf099
diff --git a/src/db/sysdb_views.c b/src/db/sysdb_views.c
6cf099
index aadd6018f4d1e2ca33e2e00dd8b13b55a8c03f3e..1db6c892de9e4764b673608166830800744b1148 100644
6cf099
--- a/src/db/sysdb_views.c
6cf099
+++ b/src/db/sysdb_views.c
6cf099
@@ -1186,9 +1186,16 @@ errno_t sysdb_add_overrides_to_object(struct sss_domain_info *domain,
6cf099
         override_dn_str = ldb_msg_find_attr_as_string(obj,
6cf099
                                                       SYSDB_OVERRIDE_DN, NULL);
6cf099
         if (override_dn_str == NULL) {
6cf099
+            if (is_local_view(domain->view_name)) {
6cf099
+                /* LOCAL view doesn't have to have overrideDN specified. */
6cf099
+                ret = EOK;
6cf099
+                goto done;
6cf099
+            }
6cf099
+
6cf099
             DEBUG(SSSDBG_CRIT_FAILURE,
6cf099
                   "Missing override DN for objext [%s].\n",
6cf099
                   ldb_dn_get_linearized(obj->dn));
6cf099
+
6cf099
             ret = ENOENT;
6cf099
             goto done;
6cf099
         }
6cf099
diff --git a/src/providers/ipa/ipa_subdomains.c b/src/providers/ipa/ipa_subdomains.c
6cf099
index cf72784473747c67d44a5d887faf867cfe62ce2b..cec8b3918b8f832e2c7376a867448fe876da6ffc 100644
6cf099
--- a/src/providers/ipa/ipa_subdomains.c
6cf099
+++ b/src/providers/ipa/ipa_subdomains.c
6cf099
@@ -905,7 +905,8 @@ static void ipa_get_view_name_done(struct tevent_req *req)
6cf099
                     goto done;
6cf099
                 }
6cf099
 
6cf099
-                if (!is_default_view(ctx->sd_ctx->id_ctx->view_name)) {
6cf099
+                if (!is_default_view(ctx->sd_ctx->id_ctx->view_name)
6cf099
+                        && !is_local_view(ctx->sd_ctx->id_ctx->view_name)) {
6cf099
                     /* Old view was not the default view, delete view tree */
6cf099
                     ret = sysdb_delete_view_tree(
6cf099
                                              ctx->sd_ctx->be_ctx->domain->sysdb,
6cf099
diff --git a/src/tests/cmocka/test_sysdb_views.c b/src/tests/cmocka/test_sysdb_views.c
6cf099
index 123d4c5cb613f41e1bca9e89feed701a1e86f8d3..83007b76a625edef67109850648b2d71645e22bb 100644
6cf099
--- a/src/tests/cmocka/test_sysdb_views.c
6cf099
+++ b/src/tests/cmocka/test_sysdb_views.c
6cf099
@@ -281,6 +281,68 @@ void test_sysdb_add_overrides_to_object(void **state)
6cf099
     assert_int_equal(ldb_val_string_cmp(&el->values[1], "OVERRIDEKEY2"), 0);
6cf099
 }
6cf099
 
6cf099
+void test_sysdb_add_overrides_to_object_local(void **state)
6cf099
+{
6cf099
+    int ret;
6cf099
+    struct ldb_message *orig;
6cf099
+    struct ldb_message_element *el;
6cf099
+    char *tmp_str;
6cf099
+    struct sysdb_test_ctx *test_ctx = talloc_get_type_abort(*state,
6cf099
+                                                         struct sysdb_test_ctx);
6cf099
+
6cf099
+    orig = ldb_msg_new(test_ctx);
6cf099
+    assert_non_null(orig);
6cf099
+
6cf099
+    tmp_str = talloc_strdup(orig,  "ORIGNAME");
6cf099
+    assert_non_null(tmp_str);
6cf099
+    ret = ldb_msg_add_string(orig, SYSDB_NAME, tmp_str);
6cf099
+    assert_int_equal(ret, EOK);
6cf099
+
6cf099
+    tmp_str = talloc_strdup(orig,  "ORIGGECOS");
6cf099
+    assert_non_null(tmp_str);
6cf099
+    ret = ldb_msg_add_string(orig, SYSDB_GECOS, tmp_str);
6cf099
+    assert_int_equal(ret, EOK);
6cf099
+
6cf099
+    test_ctx->domain->has_views = true;
6cf099
+    test_ctx->domain->view_name = "LOCAL";
6cf099
+
6cf099
+    ret = sysdb_add_overrides_to_object(test_ctx->domain, orig, NULL, NULL);
6cf099
+    assert_int_equal(ret, EOK);
6cf099
+}
6cf099
+
6cf099
+void test_sysdb_add_overrides_to_object_missing_overridedn(void **state)
6cf099
+{
6cf099
+    int ret;
6cf099
+    struct ldb_message *orig;
6cf099
+    struct ldb_message_element *el;
6cf099
+    char *tmp_str;
6cf099
+    struct sysdb_test_ctx *test_ctx = talloc_get_type_abort(*state,
6cf099
+                                                         struct sysdb_test_ctx);
6cf099
+
6cf099
+    orig = ldb_msg_new(test_ctx);
6cf099
+    assert_non_null(orig);
6cf099
+
6cf099
+    orig->dn = ldb_dn_new(orig, test_ctx->domain->sysdb->ldb,
6cf099
+                          "cn=somedn,dc=example,dc=com");
6cf099
+    assert_non_null(orig->dn);
6cf099
+
6cf099
+    tmp_str = talloc_strdup(orig,  "ORIGNAME");
6cf099
+    assert_non_null(tmp_str);
6cf099
+    ret = ldb_msg_add_string(orig, SYSDB_NAME, tmp_str);
6cf099
+    assert_int_equal(ret, EOK);
6cf099
+
6cf099
+    tmp_str = talloc_strdup(orig,  "ORIGGECOS");
6cf099
+    assert_non_null(tmp_str);
6cf099
+    ret = ldb_msg_add_string(orig, SYSDB_GECOS, tmp_str);
6cf099
+    assert_int_equal(ret, EOK);
6cf099
+
6cf099
+    test_ctx->domain->has_views = true;
6cf099
+    test_ctx->domain->view_name = "NON-LOCAL";
6cf099
+
6cf099
+    ret = sysdb_add_overrides_to_object(test_ctx->domain, orig, NULL, NULL);
6cf099
+    assert_int_equal(ret, ENOENT);
6cf099
+}
6cf099
+
6cf099
 void test_split_ipa_anchor(void **state)
6cf099
 {
6cf099
     int ret;
6cf099
@@ -923,6 +985,10 @@ int main(int argc, const char *argv[])
6cf099
                                         test_sysdb_setup, test_sysdb_teardown),
6cf099
         cmocka_unit_test_setup_teardown(test_sysdb_add_overrides_to_object,
6cf099
                                         test_sysdb_setup, test_sysdb_teardown),
6cf099
+        cmocka_unit_test_setup_teardown(test_sysdb_add_overrides_to_object_local,
6cf099
+                                        test_sysdb_setup, test_sysdb_teardown),
6cf099
+        cmocka_unit_test_setup_teardown(test_sysdb_add_overrides_to_object_missing_overridedn,
6cf099
+                                        test_sysdb_setup, test_sysdb_teardown),
6cf099
         cmocka_unit_test_setup_teardown(test_split_ipa_anchor,
6cf099
                                         test_sysdb_setup, test_sysdb_teardown),
6cf099
         cmocka_unit_test_setup_teardown(test_sysdb_delete_view_tree,
6cf099
-- 
6cf099
2.4.3
6cf099