From 1a092fcbf4bf5ac7b59c8de58d2d3b890987596b Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Mon, 1 Dec 2008 16:31:41 -0300 Subject: Disallow Network.Disconnect from unauthorized senders. Disconnect should only be possible for the 'owner' of the connection, the application which called Connect. --- network/connection.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'network') diff --git a/network/connection.c b/network/connection.c index ea954ade..5772d4b2 100644 --- a/network/connection.c +++ b/network/connection.c @@ -125,6 +125,12 @@ static inline DBusMessage *not_connected(DBusMessage *msg) "Device not connected"); } +static inline DBusMessage *not_permited(DBusMessage *msg) +{ + return g_dbus_create_error(msg, ERROR_INTERFACE ".Failed", + "Operation not permited"); +} + static inline DBusMessage *connection_attempt_failed(DBusMessage *msg, int err) { return g_dbus_create_error(msg, ERROR_INTERFACE ".ConnectionAttemptFailed", @@ -335,6 +341,10 @@ static void connect_cb(GIOChannel *chan, int err, const bdaddr_t *src, failed: nc->state = DISCONNECTED; + if (nc->watch) { + g_dbus_remove_watch(connection, nc->watch); + nc->watch = 0; + } reply = connection_attempt_failed(nc->msg, -err); g_dbus_send_message(connection, reply); @@ -389,6 +399,8 @@ static DBusMessage *connection_connect(DBusConnection *conn, dbus_message_unref(nc->msg); nc->msg = NULL; nc->state = DISCONNECTED; + g_dbus_remove_watch(conn, nc->watch); + nc->watch = 0; return connection_attempt_failed(msg, -err); } @@ -399,6 +411,11 @@ static DBusMessage *connection_cancel(DBusConnection *conn, DBusMessage *msg, void *data) { struct network_conn *nc = data; + const char *owner = dbus_message_get_sender(nc->msg); + const char *caller = dbus_message_get_sender(msg); + + if (!g_str_equal(owner, caller)) + return not_permited(msg); if (nc->watch) { g_dbus_remove_watch(conn, nc->watch); -- cgit