Blame SOURCES/0082-dp-add-additional-autofs-methods.patch

8d3578
From 0b780a0d50e4ebb279b3ba36869d8e62c3c38044 Mon Sep 17 00:00:00 2001
8d3578
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrezina@redhat.com>
8d3578
Date: Wed, 28 Aug 2019 12:40:56 +0200
8d3578
Subject: [PATCH 82/90] dp: add additional autofs methods
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/providers/data_provider/dp.h              |  2 ++
8d3578
 src/providers/data_provider/dp_custom_data.h  |  1 +
8d3578
 src/providers/data_provider/dp_iface.h        |  4 ++-
8d3578
 src/providers/data_provider/dp_iface.xml      |  2 ++
8d3578
 .../data_provider/dp_iface_generated.c        | 36 +++++++++++++++++--
8d3578
 .../data_provider/dp_iface_generated.h        |  2 +-
8d3578
 .../data_provider/dp_target_autofs.c          | 28 +++++++++++++--
8d3578
 .../plugins/cache_req_autofs_entry_by_name.c  |  3 +-
8d3578
 .../plugins/cache_req_autofs_map_by_name.c    |  3 +-
8d3578
 .../plugins/cache_req_autofs_map_entries.c    |  3 +-
8d3578
 src/responder/common/responder.h              |  7 ++--
8d3578
 src/responder/common/responder_dp_autofs.c    | 19 ++++++----
8d3578
 12 files changed, 91 insertions(+), 19 deletions(-)
8d3578
8d3578
diff --git a/src/providers/data_provider/dp.h b/src/providers/data_provider/dp.h
8d3578
index 8ef4a92ae..df774fcf4 100644
8d3578
--- a/src/providers/data_provider/dp.h
8d3578
+++ b/src/providers/data_provider/dp.h
8d3578
@@ -85,6 +85,8 @@ enum dp_methods {
8d3578
 
8d3578
     DPM_REFRESH_ACCESS_RULES,
8d3578
 
8d3578
+    DPM_AUTOFS_GET_MAP,
8d3578
+    DPM_AUTOFS_GET_ENTRY,
8d3578
     DPM_AUTOFS_ENUMERATE,
8d3578
 
8d3578
     DP_METHOD_SENTINEL
8d3578
diff --git a/src/providers/data_provider/dp_custom_data.h b/src/providers/data_provider/dp_custom_data.h
8d3578
index 7c64bde45..b5f41786c 100644
8d3578
--- a/src/providers/data_provider/dp_custom_data.h
8d3578
+++ b/src/providers/data_provider/dp_custom_data.h
8d3578
@@ -37,6 +37,7 @@ struct dp_hostid_data {
8d3578
 
8d3578
 struct dp_autofs_data {
8d3578
     const char *mapname;
8d3578
+    const char *entryname;
8d3578
 };
8d3578
 
8d3578
 struct dp_subdomains_data {
8d3578
diff --git a/src/providers/data_provider/dp_iface.h b/src/providers/data_provider/dp_iface.h
8d3578
index 0a2f81eb5..5af1fdff0 100644
8d3578
--- a/src/providers/data_provider/dp_iface.h
8d3578
+++ b/src/providers/data_provider/dp_iface.h
8d3578
@@ -52,7 +52,9 @@ errno_t dp_host_handler(struct sbus_request *sbus_req,
8d3578
 errno_t dp_autofs_handler(struct sbus_request *sbus_req,
8d3578
                           void *dp_cli,
8d3578
                           uint32_t dp_flags,
8d3578
-                          const char *mapname);
8d3578
+                          uint32_t method,
8d3578
+                          const char *mapname,
8d3578
+                          const char *entryname);
8d3578
 
8d3578
 errno_t dp_subdomains_handler(struct sbus_request *sbus_req,
8d3578
                               void *dp_cli,
8d3578
diff --git a/src/providers/data_provider/dp_iface.xml b/src/providers/data_provider/dp_iface.xml
8d3578
index c2431850b..545d9aaa4 100644
8d3578
--- a/src/providers/data_provider/dp_iface.xml
8d3578
+++ b/src/providers/data_provider/dp_iface.xml
8d3578
@@ -50,7 +50,9 @@
8d3578
         </method>
8d3578
         <method name="autofsHandler">
8d3578
             <arg name="dp_flags" type="u" direction="in" />
8d3578
+            <arg name="method" type="u" direction="in" />
8d3578
             <arg name="mapname" type="s" direction="in" />
8d3578
+            <arg name="entryname" type="s" direction="in" />
8d3578
             <arg name="dp_error" type="q" direction="out" />
8d3578
             <arg name="error" type="u" direction="out" />
8d3578
             <arg name="error_message" type="s" direction="out" />
8d3578
diff --git a/src/providers/data_provider/dp_iface_generated.c b/src/providers/data_provider/dp_iface_generated.c
8d3578
index 4d0934445..453ca8854 100644
8d3578
--- a/src/providers/data_provider/dp_iface_generated.c
8d3578
+++ b/src/providers/data_provider/dp_iface_generated.c
8d3578
@@ -12,8 +12,8 @@
8d3578
 /* invokes a handler with a 's' DBus signature */
8d3578
 static int invoke_s_method(struct sbus_request *dbus_req, void *function_ptr);
8d3578
 
8d3578
-/* invokes a handler with a 'us' DBus signature */
8d3578
-static int invoke_us_method(struct sbus_request *dbus_req, void *function_ptr);
8d3578
+/* invokes a handler with a 'uuss' DBus signature */
8d3578
+static int invoke_uuss_method(struct sbus_request *dbus_req, void *function_ptr);
8d3578
 
8d3578
 /* invokes a handler with a 'uss' DBus signature */
8d3578
 static int invoke_uss_method(struct sbus_request *dbus_req, void *function_ptr);
8d3578
@@ -21,6 +21,9 @@ static int invoke_uss_method(struct sbus_request *dbus_req, void *function_ptr);
8d3578
 /* invokes a handler with a 'uusss' DBus signature */
8d3578
 static int invoke_uusss_method(struct sbus_request *dbus_req, void *function_ptr);
8d3578
 
8d3578
+/* invokes a handler with a 'us' DBus signature */
8d3578
+static int invoke_us_method(struct sbus_request *dbus_req, void *function_ptr);
8d3578
+
8d3578
 /* arguments for org.freedesktop.sssd.DataProvider.Client.Register */
8d3578
 const struct sbus_arg_meta iface_dp_client_Register__in[] = {
8d3578
     { "Name", "s" },
8d3578
@@ -217,7 +220,9 @@ const struct sbus_interface_meta iface_dp_access_control_meta = {
8d3578
 /* arguments for org.freedesktop.sssd.dataprovider.autofsHandler */
8d3578
 const struct sbus_arg_meta iface_dp_autofsHandler__in[] = {
8d3578
     { "dp_flags", "u" },
8d3578
+    { "method", "u" },
8d3578
     { "mapname", "s" },
8d3578
+    { "entryname", "s" },
8d3578
     { NULL, }
8d3578
 };
8d3578
 
8d3578
@@ -358,7 +363,7 @@ const struct sbus_method_meta iface_dp__methods[] = {
8d3578
         iface_dp_autofsHandler__in,
8d3578
         iface_dp_autofsHandler__out,
8d3578
         offsetof(struct iface_dp, autofsHandler),
8d3578
-        invoke_us_method,
8d3578
+        invoke_uuss_method,
8d3578
     },
8d3578
     {
8d3578
         "hostHandler", /* name */
8d3578
@@ -400,6 +405,31 @@ const struct sbus_interface_meta iface_dp_meta = {
8d3578
     sbus_invoke_get_all, /* GetAll invoker */
8d3578
 };
8d3578
 
8d3578
+/* invokes a handler with a 'uuss' DBus signature */
8d3578
+static int invoke_uuss_method(struct sbus_request *dbus_req, void *function_ptr)
8d3578
+{
8d3578
+    uint32_t arg_0;
8d3578
+    uint32_t arg_1;
8d3578
+    const char * arg_2;
8d3578
+    const char * arg_3;
8d3578
+    int (*handler)(struct sbus_request *, void *, uint32_t, uint32_t, const char *, const char *) = function_ptr;
8d3578
+
8d3578
+    if (!sbus_request_parse_or_finish(dbus_req,
8d3578
+                               DBUS_TYPE_UINT32, &arg_0,
8d3578
+                               DBUS_TYPE_UINT32, &arg_1,
8d3578
+                               DBUS_TYPE_STRING, &arg_2,
8d3578
+                               DBUS_TYPE_STRING, &arg_3,
8d3578
+                               DBUS_TYPE_INVALID)) {
8d3578
+         return EOK; /* request handled */
8d3578
+    }
8d3578
+
8d3578
+    return (handler)(dbus_req, dbus_req->intf->handler_data,
8d3578
+                     arg_0,
8d3578
+                     arg_1,
8d3578
+                     arg_2,
8d3578
+                     arg_3);
8d3578
+}
8d3578
+
8d3578
 /* invokes a handler with a 's' DBus signature */
8d3578
 static int invoke_s_method(struct sbus_request *dbus_req, void *function_ptr)
8d3578
 {
8d3578
diff --git a/src/providers/data_provider/dp_iface_generated.h b/src/providers/data_provider/dp_iface_generated.h
8d3578
index b629ec774..7dd0f27cc 100644
8d3578
--- a/src/providers/data_provider/dp_iface_generated.h
8d3578
+++ b/src/providers/data_provider/dp_iface_generated.h
8d3578
@@ -107,7 +107,7 @@ struct iface_dp {
8d3578
     struct sbus_vtable vtable; /* derive from sbus_vtable */
8d3578
     sbus_msg_handler_fn pamHandler;
8d3578
     sbus_msg_handler_fn sudoHandler;
8d3578
-    int (*autofsHandler)(struct sbus_request *req, void *data, uint32_t arg_dp_flags, const char *arg_mapname);
8d3578
+    int (*autofsHandler)(struct sbus_request *req, void *data, uint32_t arg_dp_flags, uint32_t arg_method, const char *arg_mapname, const char *arg_entryname);
8d3578
     int (*hostHandler)(struct sbus_request *req, void *data, uint32_t arg_dp_flags, const char *arg_name, const char *arg_alias);
8d3578
     int (*getDomains)(struct sbus_request *req, void *data, const char *arg_domain_hint);
8d3578
     int (*getAccountInfo)(struct sbus_request *req, void *data, uint32_t arg_dp_flags, uint32_t arg_entry_type, const char *arg_filter, const char *arg_domain, const char *arg_extra);
8d3578
diff --git a/src/providers/data_provider/dp_target_autofs.c b/src/providers/data_provider/dp_target_autofs.c
8d3578
index 5f24f2975..8b5447aef 100644
8d3578
--- a/src/providers/data_provider/dp_target_autofs.c
8d3578
+++ b/src/providers/data_provider/dp_target_autofs.c
8d3578
@@ -26,14 +26,19 @@
8d3578
 #include "providers/data_provider/dp_iface.h"
8d3578
 #include "providers/backend.h"
8d3578
 #include "util/util.h"
8d3578
+#include "responder/common/responder.h"
8d3578
 
8d3578
 errno_t dp_autofs_handler(struct sbus_request *sbus_req,
8d3578
                           void *dp_cli,
8d3578
                           uint32_t dp_flags,
8d3578
-                          const char *mapname)
8d3578
+                          uint32_t method,
8d3578
+                          const char *mapname,
8d3578
+                          const char *entryname)
8d3578
 {
8d3578
     struct dp_autofs_data *data;
8d3578
     const char *key;
8d3578
+    enum dp_methods dp_method;
8d3578
+
8d3578
 
8d3578
     if (mapname == NULL) {
8d3578
         return EINVAL;
8d3578
@@ -45,10 +50,27 @@ errno_t dp_autofs_handler(struct sbus_request *sbus_req,
8d3578
     }
8d3578
 
8d3578
     data->mapname = mapname;
8d3578
-    key = mapname;
8d3578
+    data->entryname = entryname;
8d3578
+
8d3578
+    key = talloc_asprintf(sbus_req, "%u:%s:%s", method, mapname, entryname);
8d3578
+    if (key == NULL) {
8d3578
+        return ENOMEM;
8d3578
+    }
8d3578
+
8d3578
+    switch (method) {
8d3578
+    case SSS_DP_AUTOFS_ENUMERATE:
8d3578
+        dp_method = DPM_AUTOFS_ENUMERATE;
8d3578
+        break;
8d3578
+    case SSS_DP_AUTOFS_GET_MAP:
8d3578
+        dp_method = DPM_AUTOFS_GET_MAP;
8d3578
+        break;
8d3578
+    case SSS_DP_AUTOFS_GET_ENTRY:
8d3578
+        dp_method = DPM_AUTOFS_GET_ENTRY;
8d3578
+        break;
8d3578
+    }
8d3578
 
8d3578
     dp_req_with_reply(dp_cli, NULL, "AutoFS", key, sbus_req, DPT_AUTOFS,
8d3578
-                      DPM_AUTOFS_ENUMERATE, dp_flags, data,
8d3578
+                      dp_method, dp_flags, data,
8d3578
                       dp_req_reply_std, struct dp_reply_std);
8d3578
 
8d3578
     return EOK;
8d3578
diff --git a/src/responder/common/cache_req/plugins/cache_req_autofs_entry_by_name.c b/src/responder/common/cache_req/plugins/cache_req_autofs_entry_by_name.c
8d3578
index 17b0b508e..f4d0cb140 100644
8d3578
--- a/src/responder/common/cache_req/plugins/cache_req_autofs_entry_by_name.c
8d3578
+++ b/src/responder/common/cache_req/plugins/cache_req_autofs_entry_by_name.c
8d3578
@@ -72,7 +72,8 @@ cache_req_autofs_entry_by_name_dp_send(TALLOC_CTX *mem_ctx,
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
+                                  SSS_DP_AUTOFS_ENUMERATE,
8d3578
+                                  data->name.name, NULL);
8d3578
 }
8d3578
 
8d3578
 const struct cache_req_plugin cache_req_autofs_entry_by_name = {
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
index 2f69c762c..268711678 100644
8d3578
--- a/src/responder/common/cache_req/plugins/cache_req_autofs_map_by_name.c
8d3578
+++ b/src/responder/common/cache_req/plugins/cache_req_autofs_map_by_name.c
8d3578
@@ -69,7 +69,8 @@ cache_req_autofs_map_by_name_dp_send(TALLOC_CTX *mem_ctx,
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
+                                  SSS_DP_AUTOFS_ENUMERATE,
8d3578
+                                  data->name.name, NULL);
8d3578
 }
8d3578
 
8d3578
 const struct cache_req_plugin cache_req_autofs_map_by_name = {
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
index 73d2b3cf2..7a2691f2f 100644
8d3578
--- a/src/responder/common/cache_req/plugins/cache_req_autofs_map_entries.c
8d3578
+++ b/src/responder/common/cache_req/plugins/cache_req_autofs_map_entries.c
8d3578
@@ -101,7 +101,8 @@ cache_req_autofs_map_entries_dp_send(TALLOC_CTX *mem_ctx,
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
+                                  SSS_DP_AUTOFS_ENUMERATE,
8d3578
+                                  data->name.name, NULL);
8d3578
 }
8d3578
 
8d3578
 const struct cache_req_plugin cache_req_autofs_map_entries = {
8d3578
diff --git a/src/responder/common/responder.h b/src/responder/common/responder.h
8d3578
index 17b04c3de..4007bfd41 100644
8d3578
--- a/src/responder/common/responder.h
8d3578
+++ b/src/responder/common/responder.h
8d3578
@@ -364,7 +364,9 @@ sss_dp_get_ssh_host_recv(TALLOC_CTX *mem_ctx,
8d3578
                          char **err_msg);
8d3578
 
8d3578
 enum sss_dp_autofs_type {
8d3578
-    SSS_DP_AUTOFS
8d3578
+    SSS_DP_AUTOFS_ENUMERATE,
8d3578
+    SSS_DP_AUTOFS_GET_MAP,
8d3578
+    SSS_DP_AUTOFS_GET_ENTRY
8d3578
 };
8d3578
 
8d3578
 struct tevent_req *
8d3578
@@ -373,7 +375,8 @@ sss_dp_get_autofs_send(TALLOC_CTX *mem_ctx,
8d3578
                        struct sss_domain_info *dom,
8d3578
                        bool fast_reply,
8d3578
                        enum sss_dp_autofs_type type,
8d3578
-                       const char *name);
8d3578
+                       const char *mapname,
8d3578
+                       const char *entryname);
8d3578
 
8d3578
 errno_t
8d3578
 sss_dp_get_autofs_recv(TALLOC_CTX *mem_ctx,
8d3578
diff --git a/src/responder/common/responder_dp_autofs.c b/src/responder/common/responder_dp_autofs.c
8d3578
index bb8c2a428..edf31d035 100644
8d3578
--- a/src/responder/common/responder_dp_autofs.c
8d3578
+++ b/src/responder/common/responder_dp_autofs.c
8d3578
@@ -34,7 +34,8 @@ struct sss_dp_get_autofs_info {
8d3578
 
8d3578
     bool fast_reply;
8d3578
     enum sss_dp_autofs_type type;
8d3578
-    const char *name;
8d3578
+    const char *mapname;
8d3578
+    const char *entryname;
8d3578
 };
8d3578
 
8d3578
 static DBusMessage *
8d3578
@@ -46,7 +47,8 @@ sss_dp_get_autofs_send(TALLOC_CTX *mem_ctx,
8d3578
                        struct sss_domain_info *dom,
8d3578
                        bool fast_reply,
8d3578
                        enum sss_dp_autofs_type type,
8d3578
-                       const char *name)
8d3578
+                       const char *mapname,
8d3578
+                       const char *entryname)
8d3578
 {
8d3578
     struct tevent_req *req;
8d3578
     struct sss_dp_req_state *state;
8d3578
@@ -64,6 +66,8 @@ sss_dp_get_autofs_send(TALLOC_CTX *mem_ctx,
8d3578
         goto error;
8d3578
     }
8d3578
 
8d3578
+    entryname = entryname == NULL ? "" : entryname;
8d3578
+
8d3578
     info = talloc_zero(state, struct sss_dp_get_autofs_info);
8d3578
     if (info == NULL) {
8d3578
         ret = ENOMEM;
8d3578
@@ -71,10 +75,11 @@ sss_dp_get_autofs_send(TALLOC_CTX *mem_ctx,
8d3578
     }
8d3578
     info->fast_reply = fast_reply;
8d3578
     info->type = type;
8d3578
-    info->name = name;
8d3578
+    info->mapname = mapname;
8d3578
+    info->entryname = entryname;
8d3578
     info->dom = dom;
8d3578
 
8d3578
-    key = talloc_asprintf(state, "%d:%s@%s", type, name, dom->name);
8d3578
+    key = talloc_asprintf(state, "%d:%s@%s:%s", type, mapname, dom->name, entryname);
8d3578
     if (!key) {
8d3578
         ret = ENOMEM;
8d3578
         goto error;
8d3578
@@ -124,11 +129,13 @@ sss_dp_get_autofs_msg(void *pvt)
8d3578
     /* create the message */
8d3578
     DEBUG(SSSDBG_TRACE_FUNC,
8d3578
           "Creating autofs request for [%s][%u][%s]\n",
8d3578
-           info->dom->name, dp_flags, info->name);
8d3578
+           info->dom->name, dp_flags, info->mapname);
8d3578
 
8d3578
     dbret = dbus_message_append_args(msg,
8d3578
                                      DBUS_TYPE_UINT32, &dp_flags,
8d3578
-                                     DBUS_TYPE_STRING, &info->name,
8d3578
+                                     DBUS_TYPE_UINT32, &info->type,
8d3578
+                                     DBUS_TYPE_STRING, &info->mapname,
8d3578
+                                     DBUS_TYPE_STRING, &info->entryname,
8d3578
                                      DBUS_TYPE_INVALID);
8d3578
     if (!dbret) {
8d3578
         DEBUG(SSSDBG_CRIT_FAILURE, "Failed to build message\n");
8d3578
-- 
8d3578
2.20.1
8d3578