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

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