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

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