Blame SOURCES/0072-sysdb-store-original-dn-in-autofs-map.patch

5fca41
From efe44597a3f1181fe60771c0efbfcab54585dc42 Mon Sep 17 00:00:00 2001
5fca41
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrezina@redhat.com>
5fca41
Date: Thu, 15 Aug 2019 14:20:26 +0200
5fca41
Subject: [PATCH 72/90] sysdb: store original dn in autofs map
5fca41
MIME-Version: 1.0
5fca41
Content-Type: text/plain; charset=UTF-8
5fca41
Content-Transfer-Encoding: 8bit
5fca41
5fca41
This will be used later when fetching single entry.
5fca41
5fca41
Resolves:
5fca41
https://pagure.io/SSSD/sssd/issue/2607
5fca41
5fca41
Reviewed-by: Tomáš Halman <thalman@redhat.com>
5fca41
---
5fca41
 src/db/sysdb_autofs.c                  |  9 +++++++++
5fca41
 src/db/sysdb_autofs.h                  |  1 +
5fca41
 src/providers/ldap/sdap_async_autofs.c | 10 +++++++++-
5fca41
 src/tests/sysdb-tests.c                |  6 +++++-
5fca41
 4 files changed, 24 insertions(+), 2 deletions(-)
5fca41
5fca41
diff --git a/src/db/sysdb_autofs.c b/src/db/sysdb_autofs.c
5fca41
index dc1ea5586..971abafa3 100644
5fca41
--- a/src/db/sysdb_autofs.c
5fca41
+++ b/src/db/sysdb_autofs.c
5fca41
@@ -99,6 +99,7 @@ errno_t
5fca41
 sysdb_save_autofsmap(struct sss_domain_info *domain,
5fca41
                      const char *name,
5fca41
                      const char *autofsmapname,
5fca41
+                     const char *origdn,
5fca41
                      struct sysdb_attrs *attrs,
5fca41
                      int cache_timeout,
5fca41
                      time_t now,
5fca41
@@ -138,6 +139,13 @@ sysdb_save_autofsmap(struct sss_domain_info *domain,
5fca41
         goto done;
5fca41
     }
5fca41
 
5fca41
+    ret = sysdb_attrs_add_string(attrs, SYSDB_ORIG_DN, origdn);
5fca41
+    if (ret != EOK) {
5fca41
+        DEBUG(SSSDBG_OP_FAILURE, "Could not set origdn [%d]: %s\n",
5fca41
+              ret, strerror(ret));
5fca41
+        goto done;
5fca41
+    }
5fca41
+
5fca41
     ret = sysdb_attrs_add_string(attrs, SYSDB_NAME, name);
5fca41
     if (ret != EOK) {
5fca41
         DEBUG(SSSDBG_OP_FAILURE, "Could not set name attribute [%d]: %s\n",
5fca41
@@ -202,6 +210,7 @@ sysdb_get_map_byname(TALLOC_CTX *mem_ctx,
5fca41
     size_t count;
5fca41
     struct ldb_message **msgs;
5fca41
     const char *attrs[] = { SYSDB_OBJECTCLASS,
5fca41
+                            SYSDB_ORIG_DN,
5fca41
                             SYSDB_CACHE_EXPIRE,
5fca41
                             SYSDB_LAST_UPDATE,
5fca41
                             SYSDB_AUTOFS_MAP_NAME,
5fca41
diff --git a/src/db/sysdb_autofs.h b/src/db/sysdb_autofs.h
5fca41
index 7170334c6..79ecbd94e 100644
5fca41
--- a/src/db/sysdb_autofs.h
5fca41
+++ b/src/db/sysdb_autofs.h
5fca41
@@ -39,6 +39,7 @@ errno_t
5fca41
 sysdb_save_autofsmap(struct sss_domain_info *domain,
5fca41
                      const char *name,
5fca41
                      const char *autofsmapname,
5fca41
+                     const char *origdn,
5fca41
                      struct sysdb_attrs *attrs,
5fca41
                      int cache_timeout,
5fca41
                      time_t now,
5fca41
diff --git a/src/providers/ldap/sdap_async_autofs.c b/src/providers/ldap/sdap_async_autofs.c
5fca41
index 453e95f7b..7548d4a67 100644
5fca41
--- a/src/providers/ldap/sdap_async_autofs.c
5fca41
+++ b/src/providers/ldap/sdap_async_autofs.c
5fca41
@@ -193,15 +193,23 @@ save_autofs_map(struct sss_domain_info *dom,
5fca41
                 bool enumerated)
5fca41
 {
5fca41
     const char *mapname;
5fca41
+    const char *origdn;
5fca41
     errno_t ret;
5fca41
     time_t now;
5fca41
 
5fca41
     mapname = get_autofs_map_name(map, opts);
5fca41
     if (!mapname) return EINVAL;
5fca41
 
5fca41
+    ret = sysdb_attrs_get_string(map, SYSDB_ORIG_DN, &origdn);
5fca41
+    if (ret != EOK) {
5fca41
+        DEBUG(SSSDBG_CRIT_FAILURE, "Unable to get original dn [%d]: %s\n",
5fca41
+              ret, sss_strerror(ret));
5fca41
+        return ret;
5fca41
+    }
5fca41
+
5fca41
     now = time(NULL);
5fca41
 
5fca41
-    ret = sysdb_save_autofsmap(dom, mapname, mapname,
5fca41
+    ret = sysdb_save_autofsmap(dom, mapname, mapname, origdn,
5fca41
                                NULL, dom->autofsmap_timeout, now, enumerated);
5fca41
     if (ret != EOK) {
5fca41
         return ret;
5fca41
diff --git a/src/tests/sysdb-tests.c b/src/tests/sysdb-tests.c
5fca41
index 108ef8943..22460d9db 100644
5fca41
--- a/src/tests/sysdb-tests.c
5fca41
+++ b/src/tests/sysdb-tests.c
5fca41
@@ -6365,6 +6365,7 @@ START_TEST(test_autofs_create_map)
5fca41
 {
5fca41
     struct sysdb_test_ctx *test_ctx;
5fca41
     const char *autofsmapname;
5fca41
+    const char *origdn;
5fca41
     errno_t ret;
5fca41
 
5fca41
     ret = setup_sysdb_tests(&test_ctx);
5fca41
@@ -6373,8 +6374,11 @@ START_TEST(test_autofs_create_map)
5fca41
     autofsmapname = talloc_asprintf(test_ctx, "testmap%d", _i);
5fca41
     fail_if(autofsmapname == NULL, "Out of memory\n");
5fca41
 
5fca41
+    origdn = talloc_asprintf(test_ctx, "cn=testmap%d,dc=test", _i);
5fca41
+    fail_if(origdn == NULL, "Out of memory\n");
5fca41
+
5fca41
     ret = sysdb_save_autofsmap(test_ctx->domain, autofsmapname,
5fca41
-                               autofsmapname, NULL, 0, 0, false);
5fca41
+                               autofsmapname, origdn, NULL, 0, 0, false);
5fca41
     fail_if(ret != EOK, "Could not store autofs map %s", autofsmapname);
5fca41
     talloc_free(test_ctx);
5fca41
 }
5fca41
-- 
5fca41
2.20.1
5fca41