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