|
|
8d3578 |
From 01b7dc92180cf80080f657b80f72cec20eafa0e7 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 13:31:21 +0200
|
|
|
8d3578 |
Subject: [PATCH 75/90] cache_req: add autofs map entries plugin
|
|
|
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 |
Makefile.am | 1 +
|
|
|
8d3578 |
src/responder/common/cache_req/cache_req.c | 2 +
|
|
|
8d3578 |
src/responder/common/cache_req/cache_req.h | 14 ++
|
|
|
8d3578 |
.../common/cache_req/cache_req_data.c | 1 +
|
|
|
8d3578 |
.../common/cache_req/cache_req_plugin.h | 1 +
|
|
|
8d3578 |
.../plugins/cache_req_autofs_map_entries.c | 156 ++++++++++++++++++
|
|
|
8d3578 |
src/tests/cwrap/Makefile.am | 1 +
|
|
|
8d3578 |
7 files changed, 176 insertions(+)
|
|
|
8d3578 |
create mode 100644 src/responder/common/cache_req/plugins/cache_req_autofs_map_entries.c
|
|
|
8d3578 |
|
|
|
8d3578 |
diff --git a/Makefile.am b/Makefile.am
|
|
|
8d3578 |
index c109afe56..879f38311 100644
|
|
|
8d3578 |
--- a/Makefile.am
|
|
|
8d3578 |
+++ b/Makefile.am
|
|
|
8d3578 |
@@ -559,6 +559,7 @@ SSSD_CACHE_REQ_OBJ = \
|
|
|
8d3578 |
src/responder/common/cache_req/plugins/cache_req_svc_by_port.c \
|
|
|
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 |
$(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 28b563392..2ce9deca0 100644
|
|
|
8d3578 |
--- a/src/responder/common/cache_req/cache_req.c
|
|
|
8d3578 |
+++ b/src/responder/common/cache_req/cache_req.c
|
|
|
8d3578 |
@@ -60,6 +60,8 @@ cache_req_get_plugin(enum cache_req_type type)
|
|
|
8d3578 |
&cache_req_netgroup_by_name,
|
|
|
8d3578 |
|
|
|
8d3578 |
&cache_req_host_by_name,
|
|
|
8d3578 |
+
|
|
|
8d3578 |
+ &cache_req_autofs_map_entries,
|
|
|
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 84dd22c25..0c214a483 100644
|
|
|
8d3578 |
--- a/src/responder/common/cache_req/cache_req.h
|
|
|
8d3578 |
+++ b/src/responder/common/cache_req/cache_req.h
|
|
|
8d3578 |
@@ -54,6 +54,8 @@ enum cache_req_type {
|
|
|
8d3578 |
|
|
|
8d3578 |
CACHE_REQ_HOST_BY_NAME,
|
|
|
8d3578 |
|
|
|
8d3578 |
+ CACHE_REQ_AUTOFS_MAP_ENTRIES,
|
|
|
8d3578 |
+
|
|
|
8d3578 |
CACHE_REQ_SENTINEL
|
|
|
8d3578 |
};
|
|
|
8d3578 |
|
|
|
8d3578 |
@@ -430,4 +432,16 @@ cache_req_host_by_name_send(TALLOC_CTX *mem_ctx,
|
|
|
8d3578 |
#define cache_req_host_by_name_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_entries_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_entries_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 77959f9fe..20d73ebfd 100644
|
|
|
8d3578 |
--- a/src/responder/common/cache_req/cache_req_data.c
|
|
|
8d3578 |
+++ b/src/responder/common/cache_req/cache_req_data.c
|
|
|
8d3578 |
@@ -93,6 +93,7 @@ cache_req_data_create(TALLOC_CTX *mem_ctx,
|
|
|
8d3578 |
case CACHE_REQ_INITGROUPS_BY_UPN:
|
|
|
8d3578 |
case CACHE_REQ_NETGROUP_BY_NAME:
|
|
|
8d3578 |
case CACHE_REQ_OBJECT_BY_NAME:
|
|
|
8d3578 |
+ case CACHE_REQ_AUTOFS_MAP_ENTRIES:
|
|
|
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 d547c9bf3..1071cd889 100644
|
|
|
8d3578 |
--- a/src/responder/common/cache_req/cache_req_plugin.h
|
|
|
8d3578 |
+++ b/src/responder/common/cache_req/cache_req_plugin.h
|
|
|
8d3578 |
@@ -314,5 +314,6 @@ extern const struct cache_req_plugin cache_req_svc_by_name;
|
|
|
8d3578 |
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 |
|
|
|
8d3578 |
#endif /* _CACHE_REQ_PLUGIN_H_ */
|
|
|
8d3578 |
diff --git a/src/responder/common/cache_req/plugins/cache_req_autofs_map_entries.c b/src/responder/common/cache_req/plugins/cache_req_autofs_map_entries.c
|
|
|
8d3578 |
new file mode 100644
|
|
|
8d3578 |
index 000000000..73d2b3cf2
|
|
|
8d3578 |
--- /dev/null
|
|
|
8d3578 |
+++ b/src/responder/common/cache_req/plugins/cache_req_autofs_map_entries.c
|
|
|
8d3578 |
@@ -0,0 +1,156 @@
|
|
|
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_entries_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_entries_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 |
+ TALLOC_CTX *tmp_ctx;
|
|
|
8d3578 |
+ struct ldb_message *map;
|
|
|
8d3578 |
+ struct ldb_message **mounts;
|
|
|
8d3578 |
+ struct ldb_message **msgs;
|
|
|
8d3578 |
+ struct ldb_result *result;
|
|
|
8d3578 |
+ size_t count;
|
|
|
8d3578 |
+ size_t i;
|
|
|
8d3578 |
+ errno_t ret;
|
|
|
8d3578 |
+
|
|
|
8d3578 |
+ tmp_ctx = talloc_new(NULL);
|
|
|
8d3578 |
+ if (tmp_ctx == NULL) {
|
|
|
8d3578 |
+ return ENOMEM;
|
|
|
8d3578 |
+ }
|
|
|
8d3578 |
+
|
|
|
8d3578 |
+ ret = sysdb_get_map_byname(tmp_ctx, domain, data->name.name, &map);
|
|
|
8d3578 |
+ if (ret != EOK) {
|
|
|
8d3578 |
+ goto done;
|
|
|
8d3578 |
+ }
|
|
|
8d3578 |
+
|
|
|
8d3578 |
+ ret = sysdb_autofs_entries_by_map(tmp_ctx, domain, data->name.name,
|
|
|
8d3578 |
+ &count, &mounts);
|
|
|
8d3578 |
+ if (ret != EOK && ret != ENOENT) {
|
|
|
8d3578 |
+ goto done;
|
|
|
8d3578 |
+ }
|
|
|
8d3578 |
+
|
|
|
8d3578 |
+ msgs = talloc_zero_array(tmp_ctx, struct ldb_message *, count + 1);
|
|
|
8d3578 |
+ if (msgs == NULL) {
|
|
|
8d3578 |
+ ret = ENOMEM;
|
|
|
8d3578 |
+ goto done;
|
|
|
8d3578 |
+ }
|
|
|
8d3578 |
+
|
|
|
8d3578 |
+ msgs[0] = talloc_steal(msgs, map);
|
|
|
8d3578 |
+ for (i = 0; i < count; i++) {
|
|
|
8d3578 |
+ msgs[i + 1] = talloc_steal(msgs, mounts[i]);
|
|
|
8d3578 |
+ }
|
|
|
8d3578 |
+
|
|
|
8d3578 |
+ result = cache_req_create_ldb_result_from_msg_list(tmp_ctx, msgs, count + 1);
|
|
|
8d3578 |
+ if (result == NULL) {
|
|
|
8d3578 |
+ ret = ENOMEM;
|
|
|
8d3578 |
+ goto done;
|
|
|
8d3578 |
+ }
|
|
|
8d3578 |
+
|
|
|
8d3578 |
+ *_result = talloc_steal(mem_ctx, result);
|
|
|
8d3578 |
+ ret = EOK;
|
|
|
8d3578 |
+
|
|
|
8d3578 |
+done:
|
|
|
8d3578 |
+ talloc_free(tmp_ctx);
|
|
|
8d3578 |
+
|
|
|
8d3578 |
+ return ret;
|
|
|
8d3578 |
+}
|
|
|
8d3578 |
+
|
|
|
8d3578 |
+static struct tevent_req *
|
|
|
8d3578 |
+cache_req_autofs_map_entries_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_entries = {
|
|
|
8d3578 |
+ .name = "Get autofs entries",
|
|
|
8d3578 |
+ .attr_expiration = SYSDB_ENUM_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_entries_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_entries_lookup,
|
|
|
8d3578 |
+ .dp_send_fn = cache_req_autofs_map_entries_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_entries_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_ENTRIES, 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 1edefc678..dfaf3f770 100644
|
|
|
8d3578 |
--- a/src/tests/cwrap/Makefile.am
|
|
|
8d3578 |
+++ b/src/tests/cwrap/Makefile.am
|
|
|
8d3578 |
@@ -64,6 +64,7 @@ SSSD_CACHE_REQ_OBJ = \
|
|
|
8d3578 |
../../../src/responder/common/cache_req/plugins/cache_req_svc_by_port.c \
|
|
|
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 |
$(NULL)
|
|
|
8d3578 |
|
|
|
8d3578 |
SSSD_RESPONDER_IFACE_OBJ = \
|
|
|
8d3578 |
--
|
|
|
8d3578 |
2.20.1
|
|
|
8d3578 |
|