Blame SOURCES/0069-sysdb-add-sysdb_get_autofsentry.patch

5cd47f
From 57e33404e0f98d9358e8c31eb2c2f764ee380b13 Mon Sep 17 00:00:00 2001
5cd47f
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrezina@redhat.com>
5cd47f
Date: Tue, 13 Aug 2019 12:59:49 +0200
5cd47f
Subject: [PATCH 69/90] sysdb: add sysdb_get_autofsentry
5cd47f
MIME-Version: 1.0
5cd47f
Content-Type: text/plain; charset=UTF-8
5cd47f
Content-Transfer-Encoding: 8bit
5cd47f
5cd47f
Resolves:
5cd47f
https://pagure.io/SSSD/sssd/issue/2607
5cd47f
5cd47f
Reviewed-by: Tomáš Halman <thalman@redhat.com>
5cd47f
---
5cd47f
 src/db/sysdb_autofs.c | 73 +++++++++++++++++++++++++++++++++++++++++++
5cd47f
 src/db/sysdb_autofs.h |  8 +++++
5cd47f
 2 files changed, 81 insertions(+)
5cd47f
5cd47f
diff --git a/src/db/sysdb_autofs.c b/src/db/sysdb_autofs.c
5cd47f
index c92a51658..f5186451e 100644
5cd47f
--- a/src/db/sysdb_autofs.c
5cd47f
+++ b/src/db/sysdb_autofs.c
5cd47f
@@ -341,6 +341,79 @@ done:
5cd47f
     return ret;
5cd47f
 }
5cd47f
 
5cd47f
+errno_t
5cd47f
+sysdb_get_autofsentry(TALLOC_CTX *mem_ctx,
5cd47f
+                      struct sss_domain_info *domain,
5cd47f
+                      const char *map_name,
5cd47f
+                      const char *entry_name,
5cd47f
+                      struct ldb_message **_entry)
5cd47f
+{
5cd47f
+    TALLOC_CTX *tmp_ctx;
5cd47f
+    char *safe_entryname;
5cd47f
+    char *filter;
5cd47f
+    struct ldb_dn *mapdn;
5cd47f
+    size_t count;
5cd47f
+    struct ldb_message **msgs;
5cd47f
+    errno_t ret;
5cd47f
+    const char *attrs[] = { SYSDB_AUTOFS_ENTRY_KEY,
5cd47f
+                            SYSDB_AUTOFS_ENTRY_VALUE,
5cd47f
+                            SYSDB_CACHE_EXPIRE,
5cd47f
+                            NULL };
5cd47f
+
5cd47f
+    tmp_ctx = talloc_new(NULL);
5cd47f
+    if (tmp_ctx == NULL) {
5cd47f
+        DEBUG(SSSDBG_FATAL_FAILURE, "Out of memory!\n");
5cd47f
+        return ENOMEM;
5cd47f
+    }
5cd47f
+
5cd47f
+    ret = sss_filter_sanitize(tmp_ctx, entry_name, &safe_entryname);
5cd47f
+    if (ret != EOK) {
5cd47f
+        DEBUG(SSSDBG_CRIT_FAILURE,
5cd47f
+              "Cannot sanitize map [%s] error [%d]: %s\n",
5cd47f
+               map_name, ret, strerror(ret));
5cd47f
+        goto done;
5cd47f
+    }
5cd47f
+
5cd47f
+    filter = talloc_asprintf(tmp_ctx, "(&(objectclass=%s)(%s=%s))",
5cd47f
+                             SYSDB_AUTOFS_ENTRY_OC, SYSDB_AUTOFS_ENTRY_KEY,
5cd47f
+                             safe_entryname);
5cd47f
+    if (filter == NULL) {
5cd47f
+        ret = ENOMEM;
5cd47f
+        goto done;
5cd47f
+    }
5cd47f
+
5cd47f
+    mapdn = sysdb_autofsmap_dn(tmp_ctx, domain, map_name);
5cd47f
+    if (!mapdn) {
5cd47f
+        ret = ENOMEM;
5cd47f
+        goto done;
5cd47f
+    }
5cd47f
+
5cd47f
+    ret = sysdb_search_entry(tmp_ctx, domain->sysdb, mapdn, LDB_SCOPE_SUBTREE,
5cd47f
+                             filter, attrs, &count, &msgs);
5cd47f
+    if (ret == ENOENT) {
5cd47f
+        goto done;
5cd47f
+    } else if (ret != EOK) {
5cd47f
+        DEBUG(SSSDBG_OP_FAILURE, "sysdb search failed: %d\n", ret);
5cd47f
+        goto done;
5cd47f
+    }
5cd47f
+
5cd47f
+    if (count != 1) {
5cd47f
+        DEBUG(SSSDBG_CRIT_FAILURE, "More than one entry %s:%s found\n",
5cd47f
+              map_name, entry_name);
5cd47f
+        ret = ERR_INTERNAL;
5cd47f
+        goto done;
5cd47f
+    }
5cd47f
+
5cd47f
+    *_entry = talloc_steal(mem_ctx, msgs[0]);
5cd47f
+
5cd47f
+    ret = EOK;
5cd47f
+
5cd47f
+done:
5cd47f
+    talloc_free(tmp_ctx);
5cd47f
+
5cd47f
+    return ret;
5cd47f
+}
5cd47f
+
5cd47f
 errno_t
5cd47f
 sysdb_del_autofsentry(struct sss_domain_info *domain,
5cd47f
                       const char *entry_dn)
5cd47f
diff --git a/src/db/sysdb_autofs.h b/src/db/sysdb_autofs.h
5cd47f
index a3aba726c..0cbe6ddbf 100644
5cd47f
--- a/src/db/sysdb_autofs.h
5cd47f
+++ b/src/db/sysdb_autofs.h
5cd47f
@@ -61,6 +61,14 @@ sysdb_save_autofsentry(struct sss_domain_info *domain,
5cd47f
                        struct sysdb_attrs *attrs,
5cd47f
                        int cache_timeout,
5cd47f
                        time_t now);
5cd47f
+
5cd47f
+errno_t
5cd47f
+sysdb_get_autofsentry(TALLOC_CTX *mem_ctx,
5cd47f
+                      struct sss_domain_info *domain,
5cd47f
+                      const char *map_name,
5cd47f
+                      const char *entry_name,
5cd47f
+                      struct ldb_message **_entry);
5cd47f
+
5cd47f
 errno_t
5cd47f
 sysdb_del_autofsentry(struct sss_domain_info *domain,
5cd47f
                       const char *entry_dn);
5cd47f
-- 
5cd47f
2.20.1
5cd47f