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

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