Blame SOURCES/0128-dbus-add-a-new-method-GetProblemData.patch

06486d
From 5f765f63193a0f13af2b7c31b466f0f207e0b4e0 Mon Sep 17 00:00:00 2001
06486d
From: Jakub Filak <jfilak@redhat.com>
06486d
Date: Mon, 16 Mar 2015 08:58:58 +0100
06486d
Subject: [PATCH] dbus: add a new method GetProblemData
06486d
06486d
The method returns serialized problem_data_t for a given problem id.
06486d
06486d
The method is needed by cockpit-abrt which is supposed to have a page
06486d
showing comprehensive problem details.
06486d
06486d
Related: #1224984
06486d
06486d
Signed-off-by: Jakub Filak <jfilak@redhat.com>
06486d
---
06486d
 src/dbus/abrt-dbus.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++--
06486d
 1 file changed, 70 insertions(+), 2 deletions(-)
06486d
06486d
diff --git a/src/dbus/abrt-dbus.c b/src/dbus/abrt-dbus.c
06486d
index f2f742b..335c234 100644
06486d
--- a/src/dbus/abrt-dbus.c
06486d
+++ b/src/dbus/abrt-dbus.c
06486d
@@ -49,6 +49,10 @@ static const gchar introspection_xml[] =
06486d
   "      <arg type='s' name='problem_dir' direction='in'/>"
06486d
   "      <arg type='s' name='name' direction='in'/>"
06486d
   "    </method>"
06486d
+  "    <method name='GetProblemData'>"
06486d
+  "      <arg type='s' name='problem_dir' direction='in'/>"
06486d
+  "      <arg type='a{s(its)}' name='problem_data' direction='out'/>"
06486d
+  "    </method>"
06486d
   "    <method name='ChownProblemDir'>"
06486d
   "      <arg type='s' name='problem_dir' direction='in'/>"
06486d
   "    </method>"
06486d
@@ -599,6 +603,68 @@ static void handle_method_call(GDBusConnection *connection,
06486d
         return;
06486d
     }
06486d
 
06486d
+    if (g_strcmp0(method_name, "GetProblemData") == 0)
06486d
+    {
06486d
+        /* Parameter tuple is (s) */
06486d
+        const char *problem_id;
06486d
+
06486d
+        g_variant_get(parameters, "(&s)", &problem_id);
06486d
+
06486d
+        int ddstat = dump_dir_stat_for_uid(problem_id, caller_uid);
06486d
+        if ((ddstat & DD_STAT_ACCESSIBLE_BY_UID) == 0 &&
06486d
+                polkit_check_authorization_dname(caller, "org.freedesktop.problems.getall") != PolkitYes)
06486d
+        {
06486d
+            log_notice("Unauthorized access : '%s'", problem_id);
06486d
+            g_dbus_method_invocation_return_dbus_error(invocation,
06486d
+                                              "org.freedesktop.problems.AuthFailure",
06486d
+                                              _("Not Authorized"));
06486d
+            return;
06486d
+        }
06486d
+
06486d
+        struct dump_dir *dd = dd_opendir(problem_id, DD_OPEN_READONLY);
06486d
+        if (dd == NULL)
06486d
+        {
06486d
+            log_notice("Can't access the problem '%s' for reading", problem_id);
06486d
+            g_dbus_method_invocation_return_dbus_error(invocation,
06486d
+                                    "org.freedesktop.problems.Failure",
06486d
+                                    _("Can't access the problem for reading"));
06486d
+            return;
06486d
+        }
06486d
+
06486d
+        problem_data_t *pd = create_problem_data_from_dump_dir(dd);
06486d
+        dd_close(dd);
06486d
+
06486d
+        GVariantBuilder *response_builder = g_variant_builder_new(G_VARIANT_TYPE_ARRAY);
06486d
+
06486d
+        GHashTableIter pd_iter;
06486d
+        char *element_name;
06486d
+        struct problem_item *element_info;
06486d
+        g_hash_table_iter_init(&pd_iter, pd);
06486d
+        while (g_hash_table_iter_next(&pd_iter, (void**)&element_name, (void**)&element_info))
06486d
+        {
06486d
+            unsigned long size = 0;
06486d
+            if (problem_item_get_size(element_info, &size) != 0)
06486d
+            {
06486d
+                log_notice("Can't get stat of : '%s'", element_info->content);
06486d
+                continue;
06486d
+            }
06486d
+
06486d
+            g_variant_builder_add(response_builder, "{s(its)}",
06486d
+                                                    element_name,
06486d
+                                                    element_info->flags,
06486d
+                                                    size,
06486d
+                                                    element_info->content);
06486d
+        }
06486d
+
06486d
+        GVariant *response = g_variant_new("(a{s(its)})", response_builder);
06486d
+        g_variant_builder_unref(response_builder);
06486d
+
06486d
+        problem_data_free(pd);
06486d
+
06486d
+        g_dbus_method_invocation_return_value(invocation, response);
06486d
+        return;
06486d
+    }
06486d
+
06486d
     if (g_strcmp0(method_name, "SetElement") == 0)
06486d
     {
06486d
         const char *problem_id;
06486d
@@ -923,8 +989,10 @@ int main(int argc, char *argv[])
06486d
     * the introspection data structures - so we just build
06486d
     * them from XML.
06486d
     */
06486d
-    introspection_data = g_dbus_node_info_new_for_xml(introspection_xml, NULL);
06486d
-    g_assert(introspection_data != NULL);
06486d
+    GError *err = NULL;
06486d
+    introspection_data = g_dbus_node_info_new_for_xml(introspection_xml, &err;;
06486d
+    if (err != NULL)
06486d
+        error_msg_and_die("Invalid D-Bus interface: %s", err->message);
06486d
 
06486d
     owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
06486d
                              ABRT_DBUS_NAME,
06486d
-- 
06486d
2.4.3
06486d