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