Blame SOURCES/0076-cache_req-add-autofs-map-by-name-plugin.patch

8d3578
From e683556dc6671a6047de8bb970d32360d5aa59dc Mon Sep 17 00:00:00 2001
8d3578
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrezina@redhat.com>
8d3578
Date: Tue, 6 Aug 2019 12:08:59 +0200
8d3578
Subject: [PATCH 76/90] cache_req: add autofs map by name plugin
8d3578
MIME-Version: 1.0
8d3578
Content-Type: text/plain; charset=UTF-8
8d3578
Content-Transfer-Encoding: 8bit
8d3578
8d3578
We will use the current data provider call that downloads all map entries
8d3578
but we will replace it later when new call is available.
8d3578
8d3578
Resolves:
8d3578
https://pagure.io/SSSD/sssd/issue/2607
8d3578
8d3578
Reviewed-by: Tomáš Halman <thalman@redhat.com>
8d3578
---
8d3578
 Makefile.am                                   |   1 +
8d3578
 src/responder/common/cache_req/cache_req.c    |   1 +
8d3578
 src/responder/common/cache_req/cache_req.h    |  13 ++
8d3578
 .../common/cache_req/cache_req_data.c         |   1 +
8d3578
 .../common/cache_req/cache_req_plugin.h       |   1 +
8d3578
 .../plugins/cache_req_autofs_map_by_name.c    | 124 ++++++++++++++++++
8d3578
 src/tests/cwrap/Makefile.am                   |   1 +
8d3578
 7 files changed, 142 insertions(+)
8d3578
 create mode 100644 src/responder/common/cache_req/plugins/cache_req_autofs_map_by_name.c
8d3578
8d3578
diff --git a/Makefile.am b/Makefile.am
8d3578
index 879f38311..461a9355f 100644
8d3578
--- a/Makefile.am
8d3578
+++ b/Makefile.am
8d3578
@@ -560,6 +560,7 @@ SSSD_CACHE_REQ_OBJ = \
8d3578
 	src/responder/common/cache_req/plugins/cache_req_netgroup_by_name.c \
8d3578
 	src/responder/common/cache_req/plugins/cache_req_host_by_name.c \
8d3578
 	src/responder/common/cache_req/plugins/cache_req_autofs_map_entries.c \
8d3578
+	src/responder/common/cache_req/plugins/cache_req_autofs_map_by_name.c \
8d3578
 	$(NULL)
8d3578
 
8d3578
 SSSD_RESPONDER_IFACE_OBJ = \
8d3578
diff --git a/src/responder/common/cache_req/cache_req.c b/src/responder/common/cache_req/cache_req.c
8d3578
index 2ce9deca0..75f396a23 100644
8d3578
--- a/src/responder/common/cache_req/cache_req.c
8d3578
+++ b/src/responder/common/cache_req/cache_req.c
8d3578
@@ -62,6 +62,7 @@ cache_req_get_plugin(enum cache_req_type type)
8d3578
         &cache_req_host_by_name,
8d3578
 
8d3578
         &cache_req_autofs_map_entries,
8d3578
+        &cache_req_autofs_map_by_name
8d3578
     };
8d3578
 
8d3578
     if (type >= CACHE_REQ_SENTINEL) {
8d3578
diff --git a/src/responder/common/cache_req/cache_req.h b/src/responder/common/cache_req/cache_req.h
8d3578
index 0c214a483..66a13445c 100644
8d3578
--- a/src/responder/common/cache_req/cache_req.h
8d3578
+++ b/src/responder/common/cache_req/cache_req.h
8d3578
@@ -55,6 +55,7 @@ enum cache_req_type {
8d3578
     CACHE_REQ_HOST_BY_NAME,
8d3578
 
8d3578
     CACHE_REQ_AUTOFS_MAP_ENTRIES,
8d3578
+    CACHE_REQ_AUTOFS_MAP_BY_NAME,
8d3578
 
8d3578
     CACHE_REQ_SENTINEL
8d3578
 };
8d3578
@@ -444,4 +445,16 @@ cache_req_autofs_map_entries_send(TALLOC_CTX *mem_ctx,
8d3578
 #define cache_req_autofs_map_entries_recv(mem_ctx, req, _result) \
8d3578
     cache_req_single_domain_recv(mem_ctx, req, _result)
8d3578
 
8d3578
+struct tevent_req *
8d3578
+cache_req_autofs_map_by_name_send(TALLOC_CTX *mem_ctx,
8d3578
+                                  struct tevent_context *ev,
8d3578
+                                  struct resp_ctx *rctx,
8d3578
+                                  struct sss_nc_ctx *ncache,
8d3578
+                                  int cache_refresh_percent,
8d3578
+                                  const char *domain,
8d3578
+                                  const char *name);
8d3578
+
8d3578
+#define cache_req_autofs_map_by_name_recv(mem_ctx, req, _result) \
8d3578
+    cache_req_single_domain_recv(mem_ctx, req, _result)
8d3578
+
8d3578
 #endif /* _CACHE_REQ_H_ */
8d3578
diff --git a/src/responder/common/cache_req/cache_req_data.c b/src/responder/common/cache_req/cache_req_data.c
8d3578
index 20d73ebfd..ad6176641 100644
8d3578
--- a/src/responder/common/cache_req/cache_req_data.c
8d3578
+++ b/src/responder/common/cache_req/cache_req_data.c
8d3578
@@ -94,6 +94,7 @@ cache_req_data_create(TALLOC_CTX *mem_ctx,
8d3578
     case CACHE_REQ_NETGROUP_BY_NAME:
8d3578
     case CACHE_REQ_OBJECT_BY_NAME:
8d3578
     case CACHE_REQ_AUTOFS_MAP_ENTRIES:
8d3578
+    case CACHE_REQ_AUTOFS_MAP_BY_NAME:
8d3578
         if (input->name.input == NULL) {
8d3578
             DEBUG(SSSDBG_CRIT_FAILURE, "Bug: name cannot be NULL!\n");
8d3578
             ret = ERR_INTERNAL;
8d3578
diff --git a/src/responder/common/cache_req/cache_req_plugin.h b/src/responder/common/cache_req/cache_req_plugin.h
8d3578
index 1071cd889..c040bf380 100644
8d3578
--- a/src/responder/common/cache_req/cache_req_plugin.h
8d3578
+++ b/src/responder/common/cache_req/cache_req_plugin.h
8d3578
@@ -315,5 +315,6 @@ extern const struct cache_req_plugin cache_req_svc_by_port;
8d3578
 extern const struct cache_req_plugin cache_req_netgroup_by_name;
8d3578
 extern const struct cache_req_plugin cache_req_host_by_name;
8d3578
 extern const struct cache_req_plugin cache_req_autofs_map_entries;
8d3578
+extern const struct cache_req_plugin cache_req_autofs_map_by_name;
8d3578
 
8d3578
 #endif /* _CACHE_REQ_PLUGIN_H_ */
8d3578
diff --git a/src/responder/common/cache_req/plugins/cache_req_autofs_map_by_name.c b/src/responder/common/cache_req/plugins/cache_req_autofs_map_by_name.c
8d3578
new file mode 100644
8d3578
index 000000000..2f69c762c
8d3578
--- /dev/null
8d3578
+++ b/src/responder/common/cache_req/plugins/cache_req_autofs_map_by_name.c
8d3578
@@ -0,0 +1,124 @@
8d3578
+/*
8d3578
+    Authors:
8d3578
+        Pavel Březina <pbrezina@redhat.com>
8d3578
+
8d3578
+    Copyright (C) 2019 Red Hat
8d3578
+
8d3578
+    This program is free software; you can redistribute it and/or modify
8d3578
+    it under the terms of the GNU General Public License as published by
8d3578
+    the Free Software Foundation; either version 3 of the License, or
8d3578
+    (at your option) any later version.
8d3578
+
8d3578
+    This program is distributed in the hope that it will be useful,
8d3578
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
8d3578
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
8d3578
+    GNU General Public License for more details.
8d3578
+
8d3578
+    You should have received a copy of the GNU General Public License
8d3578
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
8d3578
+*/
8d3578
+
8d3578
+#include <talloc.h>
8d3578
+#include <ldb.h>
8d3578
+
8d3578
+#include "db/sysdb.h"
8d3578
+#include "db/sysdb_autofs.h"
8d3578
+#include "util/util.h"
8d3578
+#include "providers/data_provider.h"
8d3578
+#include "responder/common/cache_req/cache_req_plugin.h"
8d3578
+
8d3578
+static const char *
8d3578
+cache_req_autofs_map_by_name_create_debug_name(TALLOC_CTX *mem_ctx,
8d3578
+                                               struct cache_req_data *data,
8d3578
+                                               struct sss_domain_info *domain)
8d3578
+{
8d3578
+    return talloc_strdup(mem_ctx, data->name.name);
8d3578
+}
8d3578
+
8d3578
+static errno_t
8d3578
+cache_req_autofs_map_by_name_lookup(TALLOC_CTX *mem_ctx,
8d3578
+                                    struct cache_req *cr,
8d3578
+                                    struct cache_req_data *data,
8d3578
+                                    struct sss_domain_info *domain,
8d3578
+                                    struct ldb_result **_result)
8d3578
+{
8d3578
+    struct ldb_message *map;
8d3578
+    struct ldb_result *result;
8d3578
+    errno_t ret;
8d3578
+
8d3578
+    ret = sysdb_get_map_byname(mem_ctx, domain, data->name.name, &map);
8d3578
+    if (ret != EOK) {
8d3578
+        return ret;
8d3578
+    }
8d3578
+
8d3578
+    result = cache_req_create_ldb_result_from_msg(mem_ctx, map);
8d3578
+    if (result == NULL) {
8d3578
+        talloc_free(map);
8d3578
+        return ENOMEM;
8d3578
+    }
8d3578
+
8d3578
+    *_result = talloc_steal(mem_ctx, result);
8d3578
+    return EOK;
8d3578
+}
8d3578
+
8d3578
+static struct tevent_req *
8d3578
+cache_req_autofs_map_by_name_dp_send(TALLOC_CTX *mem_ctx,
8d3578
+                                     struct cache_req *cr,
8d3578
+                                     struct cache_req_data *data,
8d3578
+                                     struct sss_domain_info *domain,
8d3578
+                                     struct ldb_result *result)
8d3578
+{
8d3578
+    return sss_dp_get_autofs_send(mem_ctx, cr->rctx, domain, true,
8d3578
+                                  SSS_DP_AUTOFS, data->name.name);
8d3578
+}
8d3578
+
8d3578
+const struct cache_req_plugin cache_req_autofs_map_by_name = {
8d3578
+    .name = "Get autofs map",
8d3578
+    .attr_expiration = SYSDB_CACHE_EXPIRE,
8d3578
+    .parse_name = true,
8d3578
+    .ignore_default_domain = true,
8d3578
+    .bypass_cache = false,
8d3578
+    .only_one_result = false,
8d3578
+    .search_all_domains = false,
8d3578
+    .require_enumeration = false,
8d3578
+    .allow_missing_fqn = true,
8d3578
+    .allow_switch_to_upn = false,
8d3578
+    .upn_equivalent = CACHE_REQ_SENTINEL,
8d3578
+    .get_next_domain_flags = 0,
8d3578
+
8d3578
+    .is_well_known_fn = NULL,
8d3578
+    .prepare_domain_data_fn = NULL,
8d3578
+    .create_debug_name_fn = cache_req_autofs_map_by_name_create_debug_name,
8d3578
+    .global_ncache_add_fn = NULL,
8d3578
+    .ncache_check_fn = NULL,
8d3578
+    .ncache_add_fn = NULL,
8d3578
+    .ncache_filter_fn = NULL,
8d3578
+    .lookup_fn = cache_req_autofs_map_by_name_lookup,
8d3578
+    .dp_send_fn = cache_req_autofs_map_by_name_dp_send,
8d3578
+    .dp_recv_fn = cache_req_common_dp_recv,
8d3578
+    .dp_get_domain_check_fn = NULL,
8d3578
+    .dp_get_domain_send_fn = NULL,
8d3578
+    .dp_get_domain_recv_fn = NULL,
8d3578
+};
8d3578
+
8d3578
+struct tevent_req *
8d3578
+cache_req_autofs_map_by_name_send(TALLOC_CTX *mem_ctx,
8d3578
+                                  struct tevent_context *ev,
8d3578
+                                  struct resp_ctx *rctx,
8d3578
+                                  struct sss_nc_ctx *ncache,
8d3578
+                                  int cache_refresh_percent,
8d3578
+                                  const char *domain,
8d3578
+                                  const char *name)
8d3578
+{
8d3578
+    struct cache_req_data *data;
8d3578
+
8d3578
+    data = cache_req_data_name(mem_ctx, CACHE_REQ_AUTOFS_MAP_BY_NAME, name);
8d3578
+    if (data == NULL) {
8d3578
+        return NULL;
8d3578
+    }
8d3578
+
8d3578
+    return cache_req_steal_data_and_send(mem_ctx, ev, rctx, ncache,
8d3578
+                                         cache_refresh_percent,
8d3578
+                                         CACHE_REQ_POSIX_DOM, domain,
8d3578
+                                         data);
8d3578
+}
8d3578
diff --git a/src/tests/cwrap/Makefile.am b/src/tests/cwrap/Makefile.am
8d3578
index dfaf3f770..3fbcebf3c 100644
8d3578
--- a/src/tests/cwrap/Makefile.am
8d3578
+++ b/src/tests/cwrap/Makefile.am
8d3578
@@ -65,6 +65,7 @@ SSSD_CACHE_REQ_OBJ = \
8d3578
     ../../../src/responder/common/cache_req/plugins/cache_req_netgroup_by_name.c \
8d3578
     ../../../src/responder/common/cache_req/plugins/cache_req_host_by_name.c \
8d3578
     ../../../src/responder/common/cache_req/plugins/cache_req_autofs_map_entries.c \
8d3578
+    ../../../src/responder/common/cache_req/plugins/cache_req_autofs_map_by_name.c \
8d3578
     $(NULL)
8d3578
 
8d3578
 SSSD_RESPONDER_IFACE_OBJ = \
8d3578
-- 
8d3578
2.20.1
8d3578