diff options
author | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2011-04-05 15:21:56 +0100 |
---|---|---|
committer | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2011-08-17 19:18:34 +0100 |
commit | 98b3b3f323fd4001be0630c3e0a1dc4fb83cdeab (patch) | |
tree | 4424939290850ed45c258b6bbfd7cf85d26c6213 /dbus | |
parent | 6293849bf0469ce8d6d122b38db5091c21304a30 (diff) |
check_property_access: centralize error handling (and check for OOM)
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=35766
Reviewed-by: Cosimo Alfarano <cosimo.alfarano@collabora.co.uk>
Diffstat (limited to 'dbus')
-rw-r--r-- | dbus/dbus-gobject.c | 69 |
1 files changed, 43 insertions, 26 deletions
diff --git a/dbus/dbus-gobject.c b/dbus/dbus-gobject.c index ef6e981..e416bda 100644 --- a/dbus/dbus-gobject.c +++ b/dbus/dbus-gobject.c @@ -1959,6 +1959,20 @@ done: return result; } +/* + * @wincaps_propiface: the D-Bus interface name, conventionally WindowsCaps + * @requested_propname: the D-Bus property name, conventionally WindowsCaps + * @uscore_propname: the GObject property name, conventionally + * words_with_underscores or words-with-dashes + * @is_set: %TRUE if we're going to set the property, %FALSE if we're going + * to get it + * + * Check that the requested property exists and the requested access is + * allowed. If not, reply with a D-Bus AccessDenied error message. + * + * Returns: %TRUE if property access can continue, or FALSE if an error + * reply has been sent + */ static gboolean check_property_access (DBusConnection *connection, DBusMessage *message, @@ -1971,6 +1985,7 @@ check_property_access (DBusConnection *connection, const DBusGObjectInfo *object_info; const char *access_type; DBusMessage *ret; + gchar *error_message; if (!is_set && !disable_legacy_property_access) return TRUE; @@ -1978,14 +1993,11 @@ check_property_access (DBusConnection *connection, object_info = lookup_object_info_by_iface (object, wincaps_propiface, TRUE, NULL); if (!object_info) { - ret = dbus_message_new_error_printf (message, - DBUS_ERROR_ACCESS_DENIED, - "Interface \"%s\" isn't exported (or may not exist), can't access property \"%s\"", - wincaps_propiface, - requested_propname); - dbus_connection_send (connection, ret, NULL); - dbus_message_unref (ret); - return FALSE; + error_message = g_strdup_printf ( + "Interface \"%s\" isn't exported (or may not exist), can't access property \"%s\"", + wincaps_propiface, requested_propname); + + goto error; } /* Try both forms of property names: "foo_bar" or "FooBar"; for historical @@ -1995,32 +2007,37 @@ check_property_access (DBusConnection *connection, && !(property_info_from_object_info (object_info, wincaps_propiface, requested_propname, &access_type) || property_info_from_object_info (object_info, wincaps_propiface, uscore_propname, &access_type))) { - ret = dbus_message_new_error_printf (message, - DBUS_ERROR_ACCESS_DENIED, - "Property \"%s\" of interface \"%s\" isn't exported (or may not exist)", - requested_propname, - wincaps_propiface); - dbus_connection_send (connection, ret, NULL); - dbus_message_unref (ret); - return FALSE; + error_message = g_strdup_printf ( + "Property \"%s\" of interface \"%s\" isn't exported (or may not exist)", + requested_propname, wincaps_propiface); + + goto error; } if (strcmp (access_type, "readwrite") == 0) return TRUE; - else if (is_set ? strcmp (access_type, "read") == 0 + + if (is_set ? strcmp (access_type, "read") == 0 : strcmp (access_type, "write") == 0) { - ret = dbus_message_new_error_printf (message, - DBUS_ERROR_ACCESS_DENIED, - "Property \"%s\" of interface \"%s\" is not %s", - requested_propname, - wincaps_propiface, - is_set ? "settable" : "readable"); - dbus_connection_send (connection, ret, NULL); - dbus_message_unref (ret); - return FALSE; + error_message = g_strdup_printf ( + "Property \"%s\" of interface \"%s\" is not %s", + requested_propname, + wincaps_propiface, + is_set ? "settable" : "readable"); + + goto error; } + return TRUE; + +error: + ret = error_or_die (message, DBUS_ERROR_ACCESS_DENIED, error_message); + g_free (error_message); + + dbus_connection_send (connection, ret, NULL); + dbus_message_unref (ret); + return FALSE; } static DBusHandlerResult |