dpward / rpms / sssd

Forked from rpms/sssd 3 years ago
Clone

Blame SOURCES/0099-PROXY-Do-not-abuse-data-provider-interface.patch

b2d430
From 4b23c3128726fe59e02d28352e37bb0ff7f97640 Mon Sep 17 00:00:00 2001
b2d430
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrezina@redhat.com>
b2d430
Date: Fri, 15 Jul 2016 14:20:32 +0200
b2d430
Subject: [PATCH 099/102] PROXY: Do not abuse data provider interface
b2d430
MIME-Version: 1.0
b2d430
Content-Type: text/plain; charset=UTF-8
b2d430
Content-Transfer-Encoding: 8bit
b2d430
b2d430
We want to use custom interface for proxy provider so we do not
b2d430
abuse the data provider one. This way we gain more control over
b2d430
it and we can remove the old interface entirely.
b2d430
b2d430
Reviewed-by: Lukáš Slebodník <lslebodn@redhat.com>
b2d430
(cherry picked from commit e07d700ed9daf0cf96607fa2d72978cb2431b794)
b2d430
---
b2d430
 Makefile.am                                 |   6 +-
b2d430
 src/providers/dp_auth_util.c                |  64 ---------------
b2d430
 src/providers/proxy/proxy.h                 |   2 +
b2d430
 src/providers/proxy/proxy_auth.c            |   8 +-
b2d430
 src/providers/proxy/proxy_child.c           | 119 +++++++++++++++-------------
b2d430
 src/providers/proxy/proxy_client.c          | 108 +++++++++++--------------
b2d430
 src/providers/proxy/proxy_iface.xml         |  17 ++++
b2d430
 src/providers/proxy/proxy_iface_generated.c |  80 +++++++++++++++++++
b2d430
 src/providers/proxy/proxy_iface_generated.h |  71 +++++++++++++++++
b2d430
 9 files changed, 288 insertions(+), 187 deletions(-)
b2d430
 create mode 100644 src/providers/proxy/proxy_iface.xml
b2d430
 create mode 100644 src/providers/proxy/proxy_iface_generated.c
b2d430
 create mode 100644 src/providers/proxy/proxy_iface_generated.h
b2d430
b2d430
diff --git a/Makefile.am b/Makefile.am
b2d430
index 1837e36da7302cb51c0b90e51b762ce0a87cd65f..5d54838659e44fa446fc921d014e48ac91469b25 100644
b2d430
--- a/Makefile.am
b2d430
+++ b/Makefile.am
b2d430
@@ -715,6 +715,7 @@ dist_noinst_HEADERS = \
b2d430
     src/providers/ad/ad_domain_info.h \
b2d430
     src/providers/ad/ad_subdomains.h \
b2d430
     src/providers/proxy/proxy.h \
b2d430
+    src/providers/proxy/proxy_iface_generated.h \
b2d430
     src/tools/tools_util.h \
b2d430
     src/tools/sss_sync_ops.h \
b2d430
     src/resolv/async_resolv.h \
b2d430
@@ -1197,6 +1198,7 @@ CODEGEN_XML = \
b2d430
     $(srcdir)/src/monitor/monitor_iface.xml \
b2d430
     $(srcdir)/src/providers/data_provider_iface.xml \
b2d430
     $(srcdir)/src/providers/data_provider/dp_iface.xml \
b2d430
+    $(srcdir)/src/providers/proxy/proxy_iface.xml \
b2d430
     $(srcdir)/src/responder/ifp/ifp_iface.xml
b2d430
 
b2d430
 SBUS_CODEGEN = src/sbus/sbus_codegen
b2d430
@@ -3337,7 +3339,7 @@ libsss_proxy_la_SOURCES = \
b2d430
     src/providers/proxy/proxy_netgroup.c \
b2d430
     src/providers/proxy/proxy_services.c \
b2d430
     src/providers/proxy/proxy_auth.c \
b2d430
-    src/providers/data_provider_iface_generated.c \
b2d430
+    src/providers/proxy/proxy_iface_generated.c \
b2d430
     $(NULL)
b2d430
 libsss_proxy_la_CFLAGS = \
b2d430
     $(AM_CFLAGS)
b2d430
@@ -3606,7 +3608,7 @@ gpo_child_LDADD = \
b2d430
 
b2d430
 proxy_child_SOURCES = \
b2d430
     src/providers/proxy/proxy_child.c \
b2d430
-    src/providers/data_provider_iface_generated.c \
b2d430
+    src/providers/proxy/proxy_iface_generated.c \
b2d430
     $(NULL)
b2d430
 proxy_child_CFLAGS = \
b2d430
     $(AM_CFLAGS) \
b2d430
diff --git a/src/providers/dp_auth_util.c b/src/providers/dp_auth_util.c
b2d430
index 8c09299b12c703ed703a025d1e8cfe5df2088eb2..35d22ab5f24ba2300889256f477a9ed856b69cb9 100644
b2d430
--- a/src/providers/dp_auth_util.c
b2d430
+++ b/src/providers/dp_auth_util.c
b2d430
@@ -321,67 +321,3 @@ bool dp_unpack_pam_response(DBusMessage *msg, struct pam_data *pd, DBusError *db
b2d430
 
b2d430
     return true;
b2d430
 }
b2d430
-
b2d430
-void dp_id_callback(DBusPendingCall *pending, void *ptr)
b2d430
-{
b2d430
-    DBusMessage *reply;
b2d430
-    DBusError dbus_error;
b2d430
-    dbus_bool_t ret;
b2d430
-    dbus_uint16_t dp_ver;
b2d430
-    int type;
b2d430
-
b2d430
-    dbus_error_init(&dbus_error);
b2d430
-
b2d430
-    reply = dbus_pending_call_steal_reply(pending);
b2d430
-    if (!reply) {
b2d430
-        /* reply should never be null. This function shouldn't be called
b2d430
-         * until reply is valid or timeout has occurred. If reply is NULL
b2d430
-         * here, something is seriously wrong and we should bail out.
b2d430
-         */
b2d430
-        DEBUG(SSSDBG_FATAL_FAILURE,
b2d430
-              "Severe error. A reply callback was called but no"
b2d430
-                  " reply was received and no timeout occurred\n");
b2d430
-
b2d430
-        /* FIXME: Destroy this connection ? */
b2d430
-        goto done;
b2d430
-    }
b2d430
-
b2d430
-    type = dbus_message_get_type(reply);
b2d430
-    switch (type) {
b2d430
-    case DBUS_MESSAGE_TYPE_METHOD_RETURN:
b2d430
-        ret = dbus_message_get_args(reply, &dbus_error,
b2d430
-                                    DBUS_TYPE_UINT16, &dp_ver,
b2d430
-                                    DBUS_TYPE_INVALID);
b2d430
-        if (!ret) {
b2d430
-            DEBUG(SSSDBG_CRIT_FAILURE, "Failed to parse message\n");
b2d430
-            if (dbus_error_is_set(&dbus_error)) dbus_error_free(&dbus_error);
b2d430
-            /* FIXME: Destroy this connection ? */
b2d430
-            goto done;
b2d430
-        }
b2d430
-
b2d430
-        DEBUG(SSSDBG_CONF_SETTINGS,
b2d430
-              "Got id ack and version (%d) from DP\n", dp_ver);
b2d430
-
b2d430
-        break;
b2d430
-
b2d430
-    case DBUS_MESSAGE_TYPE_ERROR:
b2d430
-        DEBUG(SSSDBG_FATAL_FAILURE,"The Monitor returned an error [%s]\n",
b2d430
-                 dbus_message_get_error_name(reply));
b2d430
-        /* Falling through to default intentionally*/
b2d430
-    default:
b2d430
-        /*
b2d430
-         * Timeout or other error occurred or something
b2d430
-         * unexpected happened.
b2d430
-         * It doesn't matter which, because either way we
b2d430
-         * know that this connection isn't trustworthy.
b2d430
-         * We'll destroy it now.
b2d430
-         */
b2d430
-
b2d430
-        /* FIXME: Destroy this connection ? */
b2d430
-        break;
b2d430
-    }
b2d430
-
b2d430
-done:
b2d430
-    dbus_pending_call_unref(pending);
b2d430
-    dbus_message_unref(reply);
b2d430
-}
b2d430
diff --git a/src/providers/proxy/proxy.h b/src/providers/proxy/proxy.h
b2d430
index 11c85c54ea64db7ad9feb163bd5a86f65ac0ea90..6f91782bb06ea8bbf3ac35052b840dd21300b96e 100644
b2d430
--- a/src/providers/proxy/proxy.h
b2d430
+++ b/src/providers/proxy/proxy.h
b2d430
@@ -42,6 +42,8 @@
b2d430
 #include "sss_client/nss_compat.h"
b2d430
 #include <dhash.h>
b2d430
 
b2d430
+#define PROXY_CHILD_PATH "/org/freedesktop/sssd/proxychild"
b2d430
+
b2d430
 struct proxy_nss_ops {
b2d430
     enum nss_status (*getpwnam_r)(const char *name, struct passwd *result,
b2d430
                                   char *buffer, size_t buflen, int *errnop);
b2d430
diff --git a/src/providers/proxy/proxy_auth.c b/src/providers/proxy/proxy_auth.c
b2d430
index 6e7139aaa5d45631fa08f265c54b66ab97555a64..2b3510c38b1cb265e3042425c373f39e524a71eb 100644
b2d430
--- a/src/providers/proxy/proxy_auth.c
b2d430
+++ b/src/providers/proxy/proxy_auth.c
b2d430
@@ -23,6 +23,7 @@
b2d430
 */
b2d430
 
b2d430
 #include "providers/proxy/proxy.h"
b2d430
+#include "providers/proxy/proxy_iface_generated.h"
b2d430
 
b2d430
 struct pc_init_ctx;
b2d430
 
b2d430
@@ -531,9 +532,9 @@ static struct tevent_req *proxy_pam_conv_send(TALLOC_CTX *mem_ctx,
b2d430
     state->pid = pid;
b2d430
 
b2d430
     msg = dbus_message_new_method_call(NULL,
b2d430
-                                       DP_PATH,
b2d430
-                                       DATA_PROVIDER_IFACE,
b2d430
-                                       DATA_PROVIDER_IFACE_PAMHANDLER);
b2d430
+                                       PROXY_CHILD_PATH,
b2d430
+                                       IFACE_PROXY_AUTH,
b2d430
+                                       IFACE_PROXY_AUTH_PAM);
b2d430
     if (msg == NULL) {
b2d430
         DEBUG(SSSDBG_CRIT_FAILURE, "dbus_message_new_method_call failed.\n");
b2d430
         talloc_zfree(req);
b2d430
@@ -847,4 +848,3 @@ proxy_pam_handler_recv(TALLOC_CTX *mem_ctx,
b2d430
 
b2d430
     return EOK;
b2d430
 }
b2d430
-
b2d430
diff --git a/src/providers/proxy/proxy_child.c b/src/providers/proxy/proxy_child.c
b2d430
index efd304d5aafd5e53792ef96b75d8aa0c908bbe13..b492adcb3b5efefc08e6eb9e069035aeff8d34df 100644
b2d430
--- a/src/providers/proxy/proxy_child.c
b2d430
+++ b/src/providers/proxy/proxy_child.c
b2d430
@@ -44,22 +44,10 @@
b2d430
 #include "confdb/confdb.h"
b2d430
 #include "sbus/sssd_dbus.h"
b2d430
 #include "providers/proxy/proxy.h"
b2d430
+#include "providers/proxy/proxy_iface_generated.h"
b2d430
 
b2d430
 #include "providers/backend.h"
b2d430
 
b2d430
-static int pc_pam_handler(struct sbus_request *dbus_req, void *user_data);
b2d430
-
b2d430
-struct data_provider_iface pc_methods = {
b2d430
-    { &data_provider_iface_meta, 0 },
b2d430
-    .RegisterService = NULL,
b2d430
-    .pamHandler = pc_pam_handler,
b2d430
-    .sudoHandler = NULL,
b2d430
-    .autofsHandler = NULL,
b2d430
-    .hostHandler = NULL,
b2d430
-    .getDomains = NULL,
b2d430
-    .getAccountInfo = NULL,
b2d430
-};
b2d430
-
b2d430
 struct pc_ctx {
b2d430
     struct tevent_context *ev;
b2d430
     struct confdb_ctx *cdb;
b2d430
@@ -382,17 +370,71 @@ done:
b2d430
     exit(ret);
b2d430
 }
b2d430
 
b2d430
-int proxy_child_send_id(struct sbus_connection *conn,
b2d430
-                        uint16_t version,
b2d430
-                        uint32_t id);
b2d430
+static void proxy_child_id_callback(DBusPendingCall *pending, void *ptr)
b2d430
+{
b2d430
+    DBusMessage *reply;
b2d430
+    errno_t ret;
b2d430
+
b2d430
+    reply = dbus_pending_call_steal_reply(pending);
b2d430
+    if (reply == NULL) {
b2d430
+        /* reply should never be null. This function shouldn't be called
b2d430
+         * until reply is valid or timeout has occurred. If reply is NULL
b2d430
+         * here, something is seriously wrong and we should bail out.
b2d430
+         */
b2d430
+        DEBUG(SSSDBG_FATAL_FAILURE, "Severe error. A reply callback was "
b2d430
+              "called but no reply was received and no timeout occurred\n");
b2d430
+        goto done;
b2d430
+    }
b2d430
+
b2d430
+    ret = sbus_parse_reply(reply);
b2d430
+    if (ret != EOK) {
b2d430
+        DEBUG(SSSDBG_CRIT_FAILURE, "Unable to get ID ack [%d]: %s\n",
b2d430
+              ret, sss_strerror(ret));
b2d430
+    }
b2d430
+
b2d430
+    DEBUG(SSSDBG_TRACE_FUNC, "Got id ack from proxy child\n");
b2d430
+
b2d430
+done:
b2d430
+    dbus_pending_call_unref(pending);
b2d430
+    dbus_message_unref(reply);
b2d430
+}
b2d430
+
b2d430
+static errno_t proxy_child_send_id(struct sbus_connection *conn, uint32_t id)
b2d430
+{
b2d430
+    DBusMessage *msg;
b2d430
+    errno_t ret;
b2d430
+
b2d430
+    msg = sbus_create_message(NULL, NULL, PROXY_CHILD_PATH, IFACE_PROXY_CLIENT,
b2d430
+                              IFACE_PROXY_CLIENT_REGISTER,
b2d430
+                              DBUS_TYPE_UINT32, &id;;
b2d430
+    if (msg == NULL) {
b2d430
+        DEBUG(SSSDBG_FATAL_FAILURE, "Out of memory?!\n");
b2d430
+        return ENOMEM;
b2d430
+    }
b2d430
+
b2d430
+    DEBUG(SSSDBG_TRACE_FUNC, "Sending ID to Proxy Backend: (%"PRIu32")\n", id);
b2d430
+
b2d430
+    ret = sbus_conn_send(conn, msg, 30000, proxy_child_id_callback, NULL, NULL);
b2d430
+
b2d430
+    dbus_message_unref(msg);
b2d430
+
b2d430
+    return ret;
b2d430
+}
b2d430
+
b2d430
 static int proxy_cli_init(struct pc_ctx *ctx)
b2d430
 {
b2d430
     char *sbus_address;
b2d430
     int ret;
b2d430
 
b2d430
+    static struct iface_proxy_auth iface_proxy_auth = {
b2d430
+        { &iface_proxy_auth_meta, 0 },
b2d430
+
b2d430
+        .PAM = pc_pam_handler,
b2d430
+    };
b2d430
+
b2d430
     sbus_address = talloc_asprintf(ctx, "unix:path=%s/%s_%s",
b2d430
-                                      PIPE_PATH, PROXY_CHILD_PIPE,
b2d430
-                                      ctx->domain->name);
b2d430
+                                   PIPE_PATH, PROXY_CHILD_PIPE,
b2d430
+                                   ctx->domain->name);
b2d430
     if (sbus_address == NULL) {
b2d430
         DEBUG(SSSDBG_CRIT_FAILURE, "talloc_asprintf failed.\n");
b2d430
         return ENOMEM;
b2d430
@@ -404,13 +446,14 @@ static int proxy_cli_init(struct pc_ctx *ctx)
b2d430
         return ret;
b2d430
     }
b2d430
 
b2d430
-    ret = sbus_conn_register_iface(ctx->conn, &pc_methods.vtable, DP_PATH, ctx);
b2d430
+    ret = sbus_conn_register_iface(ctx->conn, &iface_proxy_auth.vtable,
b2d430
+                                   PROXY_CHILD_PATH, ctx);
b2d430
     if (ret != EOK) {
b2d430
         DEBUG(SSSDBG_FATAL_FAILURE, "Failed to export proxy.\n");
b2d430
         return ret;
b2d430
     }
b2d430
 
b2d430
-    ret = proxy_child_send_id(ctx->conn, DATA_PROVIDER_VERSION, ctx->id);
b2d430
+    ret = proxy_child_send_id(ctx->conn, ctx->id);
b2d430
     if (ret != EOK) {
b2d430
         DEBUG(SSSDBG_FATAL_FAILURE, "dp_common_send_id failed.\n");
b2d430
         return ret;
b2d430
@@ -419,42 +462,6 @@ static int proxy_cli_init(struct pc_ctx *ctx)
b2d430
     return EOK;
b2d430
 }
b2d430
 
b2d430
-int proxy_child_send_id(struct sbus_connection *conn,
b2d430
-                        uint16_t version,
b2d430
-                        uint32_t id)
b2d430
-{
b2d430
-    DBusMessage *msg;
b2d430
-    dbus_bool_t ret;
b2d430
-    int retval;
b2d430
-
b2d430
-    /* create the message */
b2d430
-    msg = dbus_message_new_method_call(NULL,
b2d430
-                                       DP_PATH,
b2d430
-                                       DATA_PROVIDER_IFACE,
b2d430
-                                       DATA_PROVIDER_IFACE_REGISTERSERVICE);
b2d430
-    if (msg == NULL) {
b2d430
-        DEBUG(SSSDBG_FATAL_FAILURE, "Out of memory?!\n");
b2d430
-        return ENOMEM;
b2d430
-    }
b2d430
-
b2d430
-    DEBUG(SSSDBG_FUNC_DATA, "Sending ID to Proxy Backend: (%d,%"PRIu32")\n",
b2d430
-                             version, id);
b2d430
-
b2d430
-    ret = dbus_message_append_args(msg,
b2d430
-                                   DBUS_TYPE_UINT16, &version,
b2d430
-                                   DBUS_TYPE_UINT32, &id,
b2d430
-                                   DBUS_TYPE_INVALID);
b2d430
-    if (!ret) {
b2d430
-        DEBUG(SSSDBG_CRIT_FAILURE, "Failed to build message\n");
b2d430
-        return EIO;
b2d430
-    }
b2d430
-
b2d430
-    retval = sbus_conn_send(conn, msg, 30000, dp_id_callback, NULL, NULL);
b2d430
-
b2d430
-    dbus_message_unref(msg);
b2d430
-    return retval;
b2d430
-}
b2d430
-
b2d430
 int proxy_child_process_init(TALLOC_CTX *mem_ctx, const char *domain,
b2d430
                              struct tevent_context *ev, struct confdb_ctx *cdb,
b2d430
                              const char *pam_target, uint32_t id)
b2d430
diff --git a/src/providers/proxy/proxy_client.c b/src/providers/proxy/proxy_client.c
b2d430
index fc1735f2a101528a1edeaf3cf9c1118e4a21e937..74957caeec5bf50b5cb959d6f5b8ec1ca9ecba37 100644
b2d430
--- a/src/providers/proxy/proxy_client.c
b2d430
+++ b/src/providers/proxy/proxy_client.c
b2d430
@@ -22,24 +22,10 @@
b2d430
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
b2d430
 */
b2d430
 
b2d430
-#include "config.h"
b2d430
-
b2d430
-#include "util/sss_format.h"
b2d430
+#include "util/util.h"
b2d430
+#include "providers/proxy/proxy_iface_generated.h"
b2d430
 #include "providers/proxy/proxy.h"
b2d430
 
b2d430
-static int client_registration(struct sbus_request *dbus_req, void *data);
b2d430
-
b2d430
-static struct data_provider_iface proxy_methods = {
b2d430
-    { &data_provider_iface_meta, 0 },
b2d430
-    .RegisterService = client_registration,
b2d430
-    .pamHandler = NULL,
b2d430
-    .sudoHandler = NULL,
b2d430
-    .autofsHandler = NULL,
b2d430
-    .hostHandler = NULL,
b2d430
-    .getDomains = NULL,
b2d430
-    .getAccountInfo = NULL,
b2d430
-};
b2d430
-
b2d430
 struct proxy_client {
b2d430
     struct proxy_auth_ctx *proxy_auth_ctx;
b2d430
     struct sbus_connection *conn;
b2d430
@@ -47,24 +33,22 @@ struct proxy_client {
b2d430
     bool initialized;
b2d430
 };
b2d430
 
b2d430
-static int client_registration(struct sbus_request *dbus_req, void *data)
b2d430
+static int proxy_client_register(struct sbus_request *sbus_req,
b2d430
+                                 void *data,
b2d430
+                                 uint32_t cli_id)
b2d430
 {
b2d430
-    dbus_uint16_t version = DATA_PROVIDER_VERSION;
b2d430
     struct sbus_connection *conn;
b2d430
     struct proxy_client *proxy_cli;
b2d430
-    dbus_uint16_t cli_ver;
b2d430
-    uint32_t cli_id;
b2d430
     int hret;
b2d430
     hash_key_t key;
b2d430
     hash_value_t value;
b2d430
     struct tevent_req *req;
b2d430
     struct proxy_child_ctx *child_ctx;
b2d430
     struct pc_init_ctx *init_ctx;
b2d430
-    int ret;
b2d430
 
b2d430
-    conn = dbus_req->conn;
b2d430
+    conn = sbus_req->conn;
b2d430
     proxy_cli = talloc_get_type(data, struct proxy_client);
b2d430
-    if (!proxy_cli) {
b2d430
+    if (proxy_cli == NULL) {
b2d430
         DEBUG(SSSDBG_FATAL_FAILURE, "Connection holds no valid init data\n");
b2d430
         return EINVAL;
b2d430
     }
b2d430
@@ -74,14 +58,6 @@ static int client_registration(struct sbus_request *dbus_req, void *data)
b2d430
           "Cancel proxy client ID timeout [%p]\n", proxy_cli->timeout);
b2d430
     talloc_zfree(proxy_cli->timeout);
b2d430
 
b2d430
-    if (!sbus_request_parse_or_finish(dbus_req,
b2d430
-                                      DBUS_TYPE_UINT16, &cli_ver,
b2d430
-                                      DBUS_TYPE_UINT32, &cli_id,
b2d430
-                                      DBUS_TYPE_INVALID)) {
b2d430
-        sbus_disconnect(conn);
b2d430
-        return EOK; /* handled */
b2d430
-    }
b2d430
-
b2d430
     DEBUG(SSSDBG_FUNC_DATA, "Proxy client [%"PRIu32"] connected\n", cli_id);
b2d430
 
b2d430
     /* Check the hash table */
b2d430
@@ -94,20 +70,14 @@ static int client_registration(struct sbus_request *dbus_req, void *data)
b2d430
         return EIO;
b2d430
     }
b2d430
 
b2d430
-    /* reply that all is ok */
b2d430
-    ret = sbus_request_return_and_finish(dbus_req,
b2d430
-                                         DBUS_TYPE_UINT16, &version,
b2d430
-                                         DBUS_TYPE_INVALID);
b2d430
-    if (ret != EOK) {
b2d430
-        sbus_disconnect(conn);
b2d430
-        return ret;
b2d430
-    }
b2d430
+    iface_proxy_client_Register_finish(sbus_req);
b2d430
 
b2d430
     hret = hash_lookup(proxy_cli->proxy_auth_ctx->request_table, &key, &value);
b2d430
     if (hret != HASH_SUCCESS) {
b2d430
         DEBUG(SSSDBG_CRIT_FAILURE,
b2d430
-              "Hash error [%d][%s]\n", hret, hash_error_string(hret));
b2d430
+              "Hash error [%d]: %s\n", hret, hash_error_string(hret));
b2d430
         sbus_disconnect(conn);
b2d430
+        return EIO;
b2d430
     }
b2d430
 
b2d430
     /* Signal that the child is up and ready to receive the request */
b2d430
@@ -121,7 +91,7 @@ static int client_registration(struct sbus_request *dbus_req, void *data)
b2d430
          * break.
b2d430
          */
b2d430
         DEBUG(SSSDBG_CRIT_FAILURE, "Client connection from a request "
b2d430
-                  "that's not marked as running\n");
b2d430
+              "that's not marked as running\n");
b2d430
         return EIO;
b2d430
     }
b2d430
 
b2d430
@@ -133,9 +103,10 @@ static int client_registration(struct sbus_request *dbus_req, void *data)
b2d430
     return EOK;
b2d430
 }
b2d430
 
b2d430
-static void init_timeout(struct tevent_context *ev,
b2d430
-                         struct tevent_timer *te,
b2d430
-                         struct timeval t, void *ptr)
b2d430
+static void proxy_client_timeout(struct tevent_context *ev,
b2d430
+                                 struct tevent_timer *te,
b2d430
+                                 struct timeval t,
b2d430
+                                 void *ptr)
b2d430
 {
b2d430
     struct proxy_client *proxy_cli;
b2d430
 
b2d430
@@ -155,38 +126,53 @@ static void init_timeout(struct tevent_context *ev,
b2d430
 
b2d430
 int proxy_client_init(struct sbus_connection *conn, void *data)
b2d430
 {
b2d430
-    struct proxy_auth_ctx *proxy_auth_ctx;
b2d430
+    struct proxy_auth_ctx *auth_ctx;
b2d430
     struct proxy_client *proxy_cli;
b2d430
     struct timeval tv;
b2d430
+    errno_t ret;
b2d430
 
b2d430
-    proxy_auth_ctx = talloc_get_type(data, struct proxy_auth_ctx);
b2d430
+    static struct iface_proxy_client iface_proxy_client = {
b2d430
+        { &iface_proxy_client_meta, 0 },
b2d430
 
b2d430
-    /* hang off this memory to the connection so that when the connection
b2d430
-     * is freed we can potentially call a destructor */
b2d430
+        .Register = proxy_client_register,
b2d430
+    };
b2d430
 
b2d430
+    auth_ctx = talloc_get_type(data, struct proxy_auth_ctx);
b2d430
+
b2d430
+    /* When connection is lost we also free the client. */
b2d430
     proxy_cli = talloc_zero(conn, struct proxy_client);
b2d430
-    if (!proxy_cli) {
b2d430
-        DEBUG(SSSDBG_FATAL_FAILURE,"Out of memory?!\n");
b2d430
-        talloc_zfree(conn);
b2d430
+    if (proxy_cli == NULL) {
b2d430
+        DEBUG(SSSDBG_FATAL_FAILURE, "Out of memory, killing connection.\n");
b2d430
+        talloc_free(conn);
b2d430
         return ENOMEM;
b2d430
     }
b2d430
-    proxy_cli->proxy_auth_ctx = proxy_auth_ctx;
b2d430
+
b2d430
+    proxy_cli->proxy_auth_ctx = auth_ctx;
b2d430
     proxy_cli->conn = conn;
b2d430
     proxy_cli->initialized = false;
b2d430
 
b2d430
-    /* 5 seconds should be plenty */
b2d430
+    /* Setup timeout in case client fails to register himself in time. */
b2d430
     tv = tevent_timeval_current_ofs(5, 0);
b2d430
-
b2d430
-    proxy_cli->timeout = tevent_add_timer(proxy_auth_ctx->be->ev, proxy_cli,
b2d430
-                                          tv, init_timeout, proxy_cli);
b2d430
-    if (!proxy_cli->timeout) {
b2d430
-        DEBUG(SSSDBG_FATAL_FAILURE,"Out of memory?!\n");
b2d430
-        talloc_zfree(conn);
b2d430
+    proxy_cli->timeout = tevent_add_timer(auth_ctx->be->ev, proxy_cli, tv,
b2d430
+                                          proxy_client_timeout, proxy_cli);
b2d430
+    if (proxy_cli->timeout == NULL) {
b2d430
+        /* Connection is closed in the caller. */
b2d430
+        DEBUG(SSSDBG_FATAL_FAILURE, "Out of memory, killing connection\n");
b2d430
         return ENOMEM;
b2d430
     }
b2d430
+
b2d430
     DEBUG(SSSDBG_CONF_SETTINGS,
b2d430
           "Set-up proxy client ID timeout [%p]\n", proxy_cli->timeout);
b2d430
 
b2d430
-    return sbus_conn_register_iface(conn, &proxy_methods.vtable,
b2d430
-                                    DP_PATH, proxy_cli);
b2d430
+    /* Setup D-Bus interfaces and methods. */
b2d430
+    ret = sbus_conn_register_iface(conn, &iface_proxy_client.vtable,
b2d430
+                                   PROXY_CHILD_PATH, proxy_cli);
b2d430
+    if (ret != EOK) {
b2d430
+        /* Connection is closed in the caller. */
b2d430
+        DEBUG(SSSDBG_FATAL_FAILURE, "Unable to register D-Bus interface, "
b2d430
+              "killing connection [%d]: %s\n", ret, sss_strerror(ret));
b2d430
+        return ret;
b2d430
+    }
b2d430
+
b2d430
+    return ret;
b2d430
 }
b2d430
diff --git a/src/providers/proxy/proxy_iface.xml b/src/providers/proxy/proxy_iface.xml
b2d430
new file mode 100644
b2d430
index 0000000000000000000000000000000000000000..39b0b03928661a1851fd739598b0194547441c2c
b2d430
--- /dev/null
b2d430
+++ b/src/providers/proxy/proxy_iface.xml
b2d430
@@ -0,0 +1,17 @@
b2d430
+
b2d430
+ "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
b2d430
+<node>
b2d430
+    <interface name="org.freedesktop.sssd.ProxyChild.Client">
b2d430
+        <annotation value="iface_proxy_client" name="org.freedesktop.DBus.GLib.CSymbol"/>
b2d430
+        <method name="Register">
b2d430
+            <arg name="ID" type="u" direction="in" />
b2d430
+        </method>
b2d430
+    </interface>
b2d430
+
b2d430
+    <interface name="org.freedesktop.sssd.ProxyChild.Auth">
b2d430
+        <annotation value="iface_proxy_auth" name="org.freedesktop.DBus.GLib.CSymbol"/>
b2d430
+        <method name="PAM">
b2d430
+            <annotation name="org.freedesktop.sssd.RawHandler" value="true"/>
b2d430
+        </method>
b2d430
+    </interface>
b2d430
+</node>
b2d430
diff --git a/src/providers/proxy/proxy_iface_generated.c b/src/providers/proxy/proxy_iface_generated.c
b2d430
new file mode 100644
b2d430
index 0000000000000000000000000000000000000000..425727d1496b537eb25b002815d14e1f57b8f00d
b2d430
--- /dev/null
b2d430
+++ b/src/providers/proxy/proxy_iface_generated.c
b2d430
@@ -0,0 +1,80 @@
b2d430
+/* The following definitions are auto-generated from proxy_iface.xml */
b2d430
+
b2d430
+#include "util/util.h"
b2d430
+#include "sbus/sssd_dbus.h"
b2d430
+#include "sbus/sssd_dbus_meta.h"
b2d430
+#include "sbus/sssd_dbus_invokers.h"
b2d430
+#include "proxy_iface_generated.h"
b2d430
+
b2d430
+/* invokes a handler with a 'u' DBus signature */
b2d430
+static int invoke_u_method(struct sbus_request *dbus_req, void *function_ptr);
b2d430
+
b2d430
+/* arguments for org.freedesktop.sssd.ProxyChild.Client.Register */
b2d430
+const struct sbus_arg_meta iface_proxy_client_Register__in[] = {
b2d430
+    { "ID", "u" },
b2d430
+    { NULL, }
b2d430
+};
b2d430
+
b2d430
+int iface_proxy_client_Register_finish(struct sbus_request *req)
b2d430
+{
b2d430
+   return sbus_request_return_and_finish(req,
b2d430
+                                         DBUS_TYPE_INVALID);
b2d430
+}
b2d430
+
b2d430
+/* methods for org.freedesktop.sssd.ProxyChild.Client */
b2d430
+const struct sbus_method_meta iface_proxy_client__methods[] = {
b2d430
+    {
b2d430
+        "Register", /* name */
b2d430
+        iface_proxy_client_Register__in,
b2d430
+        NULL, /* no out_args */
b2d430
+        offsetof(struct iface_proxy_client, Register),
b2d430
+        invoke_u_method,
b2d430
+    },
b2d430
+    { NULL, }
b2d430
+};
b2d430
+
b2d430
+/* interface info for org.freedesktop.sssd.ProxyChild.Client */
b2d430
+const struct sbus_interface_meta iface_proxy_client_meta = {
b2d430
+    "org.freedesktop.sssd.ProxyChild.Client", /* name */
b2d430
+    iface_proxy_client__methods,
b2d430
+    NULL, /* no signals */
b2d430
+    NULL, /* no properties */
b2d430
+    sbus_invoke_get_all, /* GetAll invoker */
b2d430
+};
b2d430
+
b2d430
+/* methods for org.freedesktop.sssd.ProxyChild.Auth */
b2d430
+const struct sbus_method_meta iface_proxy_auth__methods[] = {
b2d430
+    {
b2d430
+        "PAM", /* name */
b2d430
+        NULL, /* no in_args */
b2d430
+        NULL, /* no out_args */
b2d430
+        offsetof(struct iface_proxy_auth, PAM),
b2d430
+        NULL, /* no invoker */
b2d430
+    },
b2d430
+    { NULL, }
b2d430
+};
b2d430
+
b2d430
+/* interface info for org.freedesktop.sssd.ProxyChild.Auth */
b2d430
+const struct sbus_interface_meta iface_proxy_auth_meta = {
b2d430
+    "org.freedesktop.sssd.ProxyChild.Auth", /* name */
b2d430
+    iface_proxy_auth__methods,
b2d430
+    NULL, /* no signals */
b2d430
+    NULL, /* no properties */
b2d430
+    sbus_invoke_get_all, /* GetAll invoker */
b2d430
+};
b2d430
+
b2d430
+/* invokes a handler with a 'u' DBus signature */
b2d430
+static int invoke_u_method(struct sbus_request *dbus_req, void *function_ptr)
b2d430
+{
b2d430
+    uint32_t arg_0;
b2d430
+    int (*handler)(struct sbus_request *, void *, uint32_t) = function_ptr;
b2d430
+
b2d430
+    if (!sbus_request_parse_or_finish(dbus_req,
b2d430
+                               DBUS_TYPE_UINT32, &arg_0,
b2d430
+                               DBUS_TYPE_INVALID)) {
b2d430
+         return EOK; /* request handled */
b2d430
+    }
b2d430
+
b2d430
+    return (handler)(dbus_req, dbus_req->intf->handler_data,
b2d430
+                     arg_0);
b2d430
+}
b2d430
diff --git a/src/providers/proxy/proxy_iface_generated.h b/src/providers/proxy/proxy_iface_generated.h
b2d430
new file mode 100644
b2d430
index 0000000000000000000000000000000000000000..7af074fa3d839263318ceac7ea34f62dcde64563
b2d430
--- /dev/null
b2d430
+++ b/src/providers/proxy/proxy_iface_generated.h
b2d430
@@ -0,0 +1,71 @@
b2d430
+/* The following declarations are auto-generated from proxy_iface.xml */
b2d430
+
b2d430
+#ifndef __PROXY_IFACE_XML__
b2d430
+#define __PROXY_IFACE_XML__
b2d430
+
b2d430
+#include "sbus/sssd_dbus.h"
b2d430
+
b2d430
+/* ------------------------------------------------------------------------
b2d430
+ * DBus Constants
b2d430
+ *
b2d430
+ * Various constants of interface and method names mostly for use by clients
b2d430
+ */
b2d430
+
b2d430
+/* constants for org.freedesktop.sssd.ProxyChild.Client */
b2d430
+#define IFACE_PROXY_CLIENT "org.freedesktop.sssd.ProxyChild.Client"
b2d430
+#define IFACE_PROXY_CLIENT_REGISTER "Register"
b2d430
+
b2d430
+/* constants for org.freedesktop.sssd.ProxyChild.Auth */
b2d430
+#define IFACE_PROXY_AUTH "org.freedesktop.sssd.ProxyChild.Auth"
b2d430
+#define IFACE_PROXY_AUTH_PAM "PAM"
b2d430
+
b2d430
+/* ------------------------------------------------------------------------
b2d430
+ * DBus handlers
b2d430
+ *
b2d430
+ * These structures are filled in by implementors of the different
b2d430
+ * dbus interfaces to handle method calls.
b2d430
+ *
b2d430
+ * Handler functions of type sbus_msg_handler_fn accept raw messages,
b2d430
+ * other handlers are typed appropriately. If a handler that is
b2d430
+ * set to NULL is invoked it will result in a
b2d430
+ * org.freedesktop.DBus.Error.NotSupported error for the caller.
b2d430
+ *
b2d430
+ * Handlers have a matching xxx_finish() function (unless the method has
b2d430
+ * accepts raw messages). These finish functions the
b2d430
+ * sbus_request_return_and_finish() with the appropriate arguments to
b2d430
+ * construct a valid reply. Once a finish function has been called, the
b2d430
+ * @dbus_req it was called with is freed and no longer valid.
b2d430
+ */
b2d430
+
b2d430
+/* vtable for org.freedesktop.sssd.ProxyChild.Client */
b2d430
+struct iface_proxy_client {
b2d430
+    struct sbus_vtable vtable; /* derive from sbus_vtable */
b2d430
+    int (*Register)(struct sbus_request *req, void *data, uint32_t arg_ID);
b2d430
+};
b2d430
+
b2d430
+/* finish function for Register */
b2d430
+int iface_proxy_client_Register_finish(struct sbus_request *req);
b2d430
+
b2d430
+/* vtable for org.freedesktop.sssd.ProxyChild.Auth */
b2d430
+struct iface_proxy_auth {
b2d430
+    struct sbus_vtable vtable; /* derive from sbus_vtable */
b2d430
+    sbus_msg_handler_fn PAM;
b2d430
+};
b2d430
+
b2d430
+/* ------------------------------------------------------------------------
b2d430
+ * DBus Interface Metadata
b2d430
+ *
b2d430
+ * These structure definitions are filled in with the information about
b2d430
+ * the interfaces, methods, properties and so on.
b2d430
+ *
b2d430
+ * The actual definitions are found in the accompanying C file next
b2d430
+ * to this header.
b2d430
+ */
b2d430
+
b2d430
+/* interface info for org.freedesktop.sssd.ProxyChild.Client */
b2d430
+extern const struct sbus_interface_meta iface_proxy_client_meta;
b2d430
+
b2d430
+/* interface info for org.freedesktop.sssd.ProxyChild.Auth */
b2d430
+extern const struct sbus_interface_meta iface_proxy_auth_meta;
b2d430
+
b2d430
+#endif /* __PROXY_IFACE_XML__ */
b2d430
-- 
b2d430
2.4.11
b2d430