summaryrefslogtreecommitdiffstats
path: root/network
diff options
context:
space:
mode:
authorLuiz Augusto von Dentz <luiz.dentz@openbossa.org>2008-12-01 16:31:41 -0300
committerLuiz Augusto von Dentz <luiz.dentz@openbossa.org>2008-12-01 16:37:36 -0300
commit1a092fcbf4bf5ac7b59c8de58d2d3b890987596b (patch)
tree75531f922ffec0df508d1dff94f1faf6b802a7c1 /network
parent341818bd8834d430652e4b0b3210335b9657ce8a (diff)
Disallow Network.Disconnect from unauthorized senders.
Disconnect should only be possible for the 'owner' of the connection, the application which called Connect.
Diffstat (limited to 'network')
-rw-r--r--network/connection.c17
1 files changed, 17 insertions, 0 deletions
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);