Blob Blame History Raw
From efe44597a3f1181fe60771c0efbfcab54585dc42 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrezina@redhat.com>
Date: Thu, 15 Aug 2019 14:20:26 +0200
Subject: [PATCH 72/90] sysdb: store original dn in autofs map
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This will be used later when fetching single entry.

Resolves:
https://pagure.io/SSSD/sssd/issue/2607

Reviewed-by: Tomáš Halman <thalman@redhat.com>
---
 src/db/sysdb_autofs.c                  |  9 +++++++++
 src/db/sysdb_autofs.h                  |  1 +
 src/providers/ldap/sdap_async_autofs.c | 10 +++++++++-
 src/tests/sysdb-tests.c                |  6 +++++-
 4 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/src/db/sysdb_autofs.c b/src/db/sysdb_autofs.c
index dc1ea5586..971abafa3 100644
--- a/src/db/sysdb_autofs.c
+++ b/src/db/sysdb_autofs.c
@@ -99,6 +99,7 @@ errno_t
 sysdb_save_autofsmap(struct sss_domain_info *domain,
                      const char *name,
                      const char *autofsmapname,
+                     const char *origdn,
                      struct sysdb_attrs *attrs,
                      int cache_timeout,
                      time_t now,
@@ -138,6 +139,13 @@ sysdb_save_autofsmap(struct sss_domain_info *domain,
         goto done;
     }
 
+    ret = sysdb_attrs_add_string(attrs, SYSDB_ORIG_DN, origdn);
+    if (ret != EOK) {
+        DEBUG(SSSDBG_OP_FAILURE, "Could not set origdn [%d]: %s\n",
+              ret, strerror(ret));
+        goto done;
+    }
+
     ret = sysdb_attrs_add_string(attrs, SYSDB_NAME, name);
     if (ret != EOK) {
         DEBUG(SSSDBG_OP_FAILURE, "Could not set name attribute [%d]: %s\n",
@@ -202,6 +210,7 @@ sysdb_get_map_byname(TALLOC_CTX *mem_ctx,
     size_t count;
     struct ldb_message **msgs;
     const char *attrs[] = { SYSDB_OBJECTCLASS,
+                            SYSDB_ORIG_DN,
                             SYSDB_CACHE_EXPIRE,
                             SYSDB_LAST_UPDATE,
                             SYSDB_AUTOFS_MAP_NAME,
diff --git a/src/db/sysdb_autofs.h b/src/db/sysdb_autofs.h
index 7170334c6..79ecbd94e 100644
--- a/src/db/sysdb_autofs.h
+++ b/src/db/sysdb_autofs.h
@@ -39,6 +39,7 @@ errno_t
 sysdb_save_autofsmap(struct sss_domain_info *domain,
                      const char *name,
                      const char *autofsmapname,
+                     const char *origdn,
                      struct sysdb_attrs *attrs,
                      int cache_timeout,
                      time_t now,
diff --git a/src/providers/ldap/sdap_async_autofs.c b/src/providers/ldap/sdap_async_autofs.c
index 453e95f7b..7548d4a67 100644
--- a/src/providers/ldap/sdap_async_autofs.c
+++ b/src/providers/ldap/sdap_async_autofs.c
@@ -193,15 +193,23 @@ save_autofs_map(struct sss_domain_info *dom,
                 bool enumerated)
 {
     const char *mapname;
+    const char *origdn;
     errno_t ret;
     time_t now;
 
     mapname = get_autofs_map_name(map, opts);
     if (!mapname) return EINVAL;
 
+    ret = sysdb_attrs_get_string(map, SYSDB_ORIG_DN, &origdn);
+    if (ret != EOK) {
+        DEBUG(SSSDBG_CRIT_FAILURE, "Unable to get original dn [%d]: %s\n",
+              ret, sss_strerror(ret));
+        return ret;
+    }
+
     now = time(NULL);
 
-    ret = sysdb_save_autofsmap(dom, mapname, mapname,
+    ret = sysdb_save_autofsmap(dom, mapname, mapname, origdn,
                                NULL, dom->autofsmap_timeout, now, enumerated);
     if (ret != EOK) {
         return ret;
diff --git a/src/tests/sysdb-tests.c b/src/tests/sysdb-tests.c
index 108ef8943..22460d9db 100644
--- a/src/tests/sysdb-tests.c
+++ b/src/tests/sysdb-tests.c
@@ -6365,6 +6365,7 @@ START_TEST(test_autofs_create_map)
 {
     struct sysdb_test_ctx *test_ctx;
     const char *autofsmapname;
+    const char *origdn;
     errno_t ret;
 
     ret = setup_sysdb_tests(&test_ctx);
@@ -6373,8 +6374,11 @@ START_TEST(test_autofs_create_map)
     autofsmapname = talloc_asprintf(test_ctx, "testmap%d", _i);
     fail_if(autofsmapname == NULL, "Out of memory\n");
 
+    origdn = talloc_asprintf(test_ctx, "cn=testmap%d,dc=test", _i);
+    fail_if(origdn == NULL, "Out of memory\n");
+
     ret = sysdb_save_autofsmap(test_ctx->domain, autofsmapname,
-                               autofsmapname, NULL, 0, 0, false);
+                               autofsmapname, origdn, NULL, 0, 0, false);
     fail_if(ret != EOK, "Could not store autofs map %s", autofsmapname);
     talloc_free(test_ctx);
 }
-- 
2.20.1