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

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