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

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