Blob Blame History Raw
From 0b780a0d50e4ebb279b3ba36869d8e62c3c38044 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrezina@redhat.com>
Date: Wed, 28 Aug 2019 12:40:56 +0200
Subject: [PATCH 82/90] dp: add additional autofs methods
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Resolves:
https://pagure.io/SSSD/sssd/issue/2607

Reviewed-by: Tomáš Halman <thalman@redhat.com>
---
 src/providers/data_provider/dp.h              |  2 ++
 src/providers/data_provider/dp_custom_data.h  |  1 +
 src/providers/data_provider/dp_iface.h        |  4 ++-
 src/providers/data_provider/dp_iface.xml      |  2 ++
 .../data_provider/dp_iface_generated.c        | 36 +++++++++++++++++--
 .../data_provider/dp_iface_generated.h        |  2 +-
 .../data_provider/dp_target_autofs.c          | 28 +++++++++++++--
 .../plugins/cache_req_autofs_entry_by_name.c  |  3 +-
 .../plugins/cache_req_autofs_map_by_name.c    |  3 +-
 .../plugins/cache_req_autofs_map_entries.c    |  3 +-
 src/responder/common/responder.h              |  7 ++--
 src/responder/common/responder_dp_autofs.c    | 19 ++++++----
 12 files changed, 91 insertions(+), 19 deletions(-)

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