From ac223d84e22418a18e7aa7ca494153b36e90b6e2 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 5 Apr 2011 15:21:56 +0100 Subject: [PATCH 03/15] check_property_access: centralize error handling (and check for OOM) --- 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 284b575..24600f3 100644 --- a/dbus/dbus-gobject.c +++ b/dbus/dbus-gobject.c @@ -1936,6 +1936,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, @@ -1948,6 +1962,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; @@ -1955,14 +1970,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 @@ -1972,32 +1984,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 -- 1.7.4.1