Blame 0130-dbus-add-new-method-to-test-existence-of-an-element.patch

69165ba
From 736efc6b1ba8e7aabba96b5dc726aad61c2781ba Mon Sep 17 00:00:00 2001
69165ba
From: Jakub Filak <jfilak@redhat.com>
69165ba
Date: Tue, 24 Mar 2015 20:48:33 +0100
69165ba
Subject: [PATCH] dbus: add new method to test existence of an element
69165ba
69165ba
It is sometimes necessary to check if some elemen exist, so this method
69165ba
should be fast as much as it is possible to do this task over DBus.
69165ba
69165ba
I was thinking about calling the GetInfo method with a single element
69165ba
but I refused this idea as it is inherently overcomplicated and error
69165ba
prone.
69165ba
69165ba
Related: #1224984
69165ba
69165ba
Signed-off-by: Jakub Filak <jfilak@redhat.com>
69165ba
69165ba
Conflicts:
69165ba
	doc/problems-service/org.freedesktop.Problems.xml.in
69165ba
---
69165ba
 .../org.freedesktop.Problems.xml.in                | 28 ++++++++++++++
69165ba
 src/dbus/abrt-dbus.c                               | 44 ++++++++++++++++++++++
69165ba
 2 files changed, 72 insertions(+)
69165ba
69165ba
diff --git a/doc/problems-service/org.freedesktop.Problems.xml.in b/doc/problems-service/org.freedesktop.Problems.xml.in
69165ba
index 705b286..2bf8c32 100644
69165ba
--- a/doc/problems-service/org.freedesktop.Problems.xml.in
69165ba
+++ b/doc/problems-service/org.freedesktop.Problems.xml.in
69165ba
@@ -253,6 +253,34 @@ for prblmid in problems.GetProblems():
69165ba
                 </arg>
69165ba
             </method>
69165ba
 
69165ba
+            <method name='TestElementExists'>
69165ba
+                <tp:docstring>Checks whether the element exists.</tp:docstring>
69165ba
+
69165ba
+                <arg type='s' name='problem_dir' direction='in'>
69165ba
+                    <tp:docstring>An identifier of problem.</tp:docstring>
69165ba
+                </arg>
69165ba
+
69165ba
+                <arg type='s' name='name' direction='in'>
69165ba
+                    <tp:docstring>A name of checked element.</tp:docstring>
69165ba
+                </arg>
69165ba
+
69165ba
+                <arg type='b' name='response' direction='out'>
69165ba
+                    <tp:docstring>True if the element exists; otherwise false.</tp:docstring>
69165ba
+                </arg>
69165ba
+            </method>
69165ba
+
69165ba
+            <method name='GetProblemData'>"
69165ba
+                <tp:docstring>Returns problem's data.</tp:docstring>
69165ba
+
69165ba
+                <arg type='s' name='problem_dir' direction='in'>
69165ba
+                    <tp:docstring>An identifier of problem.</tp:docstring>
69165ba
+                </arg>
69165ba
+
69165ba
+                <arg type='a{sits}' name='problem_data' direction='out'>
69165ba
+                    <tp:docstring>A dictionary where keys are element names and values are triplets (element libreport flags, element size, element contents).</tp:docstring>
69165ba
+                </arg>
69165ba
+            </method>
69165ba
+
69165ba
             <method name='ChownProblemDir'>
69165ba
                 <tp:docstring>Assures ownership of a specified problem for the caller.</tp:docstring>
69165ba
 
69165ba
diff --git a/src/dbus/abrt-dbus.c b/src/dbus/abrt-dbus.c
69165ba
index 335c234..173cec4 100644
69165ba
--- a/src/dbus/abrt-dbus.c
69165ba
+++ b/src/dbus/abrt-dbus.c
69165ba
@@ -49,6 +49,11 @@ 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='TestElementExists'>"
69165ba
+  "      <arg type='s' name='problem_dir' direction='in'/>"
69165ba
+  "      <arg type='s' name='name' direction='in'/>"
69165ba
+  "      <arg type='b' name='response' direction='out'/>"
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
@@ -781,6 +786,45 @@ static void handle_method_call(GDBusConnection *connection,
69165ba
         return;
69165ba
     }
69165ba
 
69165ba
+    if (g_strcmp0(method_name, "TestElementExists") == 0)
69165ba
+    {
69165ba
+        const char *problem_id;
69165ba
+        const char *element;
69165ba
+
69165ba
+        g_variant_get(parameters, "(&s&s)", &problem_id, &element);
69165ba
+
69165ba
+
69165ba
+        struct dump_dir *dd = dd_opendir(problem_id, DD_OPEN_READONLY);
69165ba
+        if (!dd)
69165ba
+        {
69165ba
+            log_notice("Can't access the problem '%s'", problem_id);
69165ba
+            g_dbus_method_invocation_return_dbus_error(invocation,
69165ba
+                                    "org.freedesktop.problems.Failure",
69165ba
+                                    _("Can't access the problem"));
69165ba
+            return;
69165ba
+        }
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
+            dd_close(dd);
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
+        int ret = dd_exist(dd, element);
69165ba
+        dd_close(dd);
69165ba
+
69165ba
+        GVariant *response = g_variant_new("(b)", ret);
69165ba
+        g_dbus_method_invocation_return_value(invocation, response);
69165ba
+
69165ba
+        return;
69165ba
+    }
69165ba
+
69165ba
     if (g_strcmp0(method_name, "DeleteProblem") == 0)
69165ba
     {
69165ba
         /* Dbus parameters are always tuples.
69165ba
-- 
69165ba
2.4.3
69165ba