From 05f40837ea5a622ed9fb264c204858384360bfeb Mon Sep 17 00:00:00 2001
From: Stephen Gallagher <sgallagh@redhat.com>
Date: Mon, 22 Feb 2010 10:42:01 -0500
Subject: [PATCH 2/2] Add introspection XML for Data Provider Backends

---
 src/Makefile.am                                    |    3 +-
 src/providers/data_provider.h                      |    3 +-
 src/providers/data_provider_be.c                   |   44 +++++++++++++++++++-
 ...rg.freedesktop.sssd.dataprovider.Introspect.xml |   41 ++++++++++++++++++
 4 files changed, 88 insertions(+), 3 deletions(-)
 create mode 100644 src/providers/org.freedesktop.sssd.dataprovider.Introspect.xml

diff --git a/src/Makefile.am b/src/Makefile.am
index b34ef43..954260b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -886,7 +886,8 @@ dist_sssdapiplugin_DATA = \
 
 dist_dbusintrospect_DATA = \
     monitor/org.freedesktop.sssd.monitor.Introspect.xml \
-    monitor/org.freedesktop.sssd.service.Introspect.xml
+    monitor/org.freedesktop.sssd.service.Introspect.xml \
+    providers/org.freedesktop.sssd.dataprovider.Introspect.xml
 
 installsssddirs::
 	mkdir -p \
diff --git a/src/providers/data_provider.h b/src/providers/data_provider.h
index 747e6e8..57a602a 100644
--- a/src/providers/data_provider.h
+++ b/src/providers/data_provider.h
@@ -48,6 +48,7 @@
 
 #define DP_INTERFACE "org.freedesktop.sssd.dataprovider"
 #define DP_PATH "/org/freedesktop/sssd/dataprovider"
+#define DP_INTROSPECT_FILE "org.freedesktop.sssd.dataprovider.Introspect.xml"
 
 #define BE_PROVIDE_ACC_INFO (1<<8)
 #define BE_PROVIDE_PAM (1<<9)
@@ -103,7 +104,7 @@
  * @param DBUS_TYPE_INT32 Privileged flag is set to a non-zero value if the
  * PAM client connected to the PAM responder via the privileged pipe, i.e. if
  * the PAM client is running with root privileges
- * @param DBUS_TYPE_UINT32
+ * @param DBUS_TYPE_UINT32 Process ID of client
  *
  * @retval DBUS_TYPE_UINT32 PAM return value, PAM_AUTHINFO_UNAVAIL is used to
  * indicate that the provider is offline and that the PAM responder should try
diff --git a/src/providers/data_provider_be.c b/src/providers/data_provider_be.c
index bde484f..617125a 100644
--- a/src/providers/data_provider_be.c
+++ b/src/providers/data_provider_be.c
@@ -58,6 +58,8 @@ static int data_provider_go_offline(DBusMessage *message,
                                     struct sbus_connection *conn);
 static int monitor_be_introspect(DBusMessage *message,
                                  struct sbus_connection *conn);
+static int dp_be_introspect(DBusMessage *message,
+                            struct sbus_connection *conn);
 
 struct sbus_method monitor_be_methods[] = {
     { MON_CLI_METHOD_PING, monitor_common_pong },
@@ -92,7 +94,7 @@ struct sbus_interface be_interface = {
     DP_PATH,
     SBUS_DEFAULT_VTABLE,
     be_methods,
-    NULL
+    dp_be_introspect
 };
 
 static struct bet_data bet_data[] = {
@@ -780,8 +782,26 @@ static int be_client_init(struct sbus_connection *conn, void *data)
 static int be_srv_init(struct be_ctx *ctx)
 {
     char *sbus_address;
+    char *xml_filename;
     int ret;
 
+    /* Prepare the introspection XML */
+    xml_filename = talloc_asprintf(NULL, "%s/%s",
+                                   SSSD_INTROSPECT_PATH,
+                                   DP_INTROSPECT_FILE);
+    if (!xml_filename) {
+        return ENOMEM;
+    }
+
+    ret = sbus_read_introspection_xml(ctx, xml_filename,
+                                      &ctx->dp_introspect_xml);
+    if (ret != EOK) {
+        DEBUG(0, ("Could not prepare introspection XML\n"));
+        talloc_free(xml_filename);
+        return ret;
+    }
+    talloc_free(xml_filename);
+
     /* Set up SBUS connection to the monitor */
     ret = dp_get_sbus_address(ctx, &sbus_address, ctx->domain->name);
     if (ret != EOK) {
@@ -1274,3 +1294,25 @@ static int monitor_be_introspect(DBusMessage *message,
 
     return sbus_introspect(message, conn, be->mon_introspect_xml);
 }
+
+static int dp_be_introspect(DBusMessage *message,
+                            struct sbus_connection *conn)
+{
+    struct be_ctx *be;
+
+    be = talloc_get_type(sbus_conn_get_private_data(conn),
+                         struct be_ctx);
+    if (!be) {
+        return EINVAL;
+    }
+
+    if (!be->dp_introspect_xml) {
+        /* Internal error
+         * Introspection XML should have been
+         * read in at startup.
+         */
+        return EIO;
+    }
+
+    return sbus_introspect(message, conn, be->dp_introspect_xml);
+}
diff --git a/src/providers/org.freedesktop.sssd.dataprovider.Introspect.xml b/src/providers/org.freedesktop.sssd.dataprovider.Introspect.xml
new file mode 100644
index 0000000..22dd765
--- /dev/null
+++ b/src/providers/org.freedesktop.sssd.dataprovider.Introspect.xml
@@ -0,0 +1,41 @@
+<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
+    "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
+<node name="/org/freedesktop/sssd/dataprovider">
+    <interface name="org.freedesktop.sssd.dataprovider">
+        <method name="RegisterService">
+            <arg name="ver" type="q" direction="in" />
+            <arg name="name" type="s" direction="in" />
+            <arg name="version" type="q" direction="out" />
+        </method>
+        <method name="getOnline">
+            <arg name="online" type="q" direction="out" />
+            <arg name="err_maj" type="q" direction="out" />
+            <arg name="err_min" type="u" direction="out" />
+            <arg name="err_msg" type="s" direction="out" />
+        </method>
+        <method name="getAccountInfo">
+            <arg name="type" type="u" direction="in" />
+            <arg name="attr_type" type="u" direction="in" />
+            <arg name="filter" type="s" direction="in" />
+            <arg name="err_maj" type="q" direction="out" />
+            <arg name="err_min" type="u" direction="out" />
+            <arg name="err_msg" type="s" direction="out" />
+        </method>
+        <method name="pamHandler">
+            <arg name="command" type="i" direction="in" />
+            <arg name="pam_user" type="s" direction="in" />
+            <arg name="pam_service" type="s" direction="in" />
+            <arg name="pam_tty" type="s" direction="in" />
+            <arg name="pam_ruser" type="s" direction="in" />
+            <arg name="pam_rhost" type="s" direction="in" />
+            <arg name="authtok_type" type="u" direction="in" />
+            <arg name="authtok" type="ay" direction="in" />
+            <arg name="newauthtok_type" type="u" direction="in" />
+            <arg name="newauthtok" type="ay" direction="in" />
+            <arg name="privileged" type="i" direction="in" />
+            <arg name="client-pid" type="u" direction="in" />
+            <arg name="pam_return_val" type="u" direction="out" />
+            <arg name="pam_responses" type="a(uay)" direction="out" />
+        </method>
+    </interface>
+</node>
-- 
1.6.6

