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

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