dpward / rpms / sssd

Forked from rpms/sssd 3 years ago
Clone

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

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