Fix race condition in authorizing audio connections

The current check for implicit authorization is if any other audio profile
is already connected. However, a the second profile might try to connect
right after we've gotten a positive authorization reply for the first one
but before the first profile has reached "connected" state. So just by
checking the connected state of other profiles we might get a false
negative for the decision of doing implicit authorization.

This patch adds a variable to the audio_device struct for keeping track of
if we've gotten a positive authorization reply that can be used in
addition to the "any other profiles" connected check. This variable gets
cleared when the (global audio) device state goes back to disconnected.
This commit is contained in:
Johan Hedberg 2009-09-04 19:40:19 +03:00
parent ad3cdc0bd1
commit 763c7011e1
2 changed files with 8 additions and 1 deletions

View File

@ -150,6 +150,9 @@ static void device_set_state(struct audio_device *dev, audio_state_t new_state)
if (!state_str)
return;
if (new_state == AUDIO_STATE_DISCONNECTED)
dev->authorized = FALSE;
if (dev->priv->state == new_state) {
debug("state change attempted from %s to %s",
state_str, state_str);
@ -679,6 +682,9 @@ static void auth_cb(DBusError *derr, void *user_data)
struct audio_device *dev = user_data;
struct dev_priv *priv = dev->priv;
if (derr == NULL)
dev->authorized = TRUE;
while (priv->auths) {
struct service_auth *auth = priv->auths->data;
@ -743,7 +749,7 @@ int audio_device_request_authorization(struct audio_device *dev,
if (g_slist_length(priv->auths) > 1)
return 0;
if (audio_device_is_connected(dev)) {
if (dev->authorized || audio_device_is_connected(dev)) {
g_idle_add(auth_idle_cb, dev);
return 0;
}

View File

@ -59,6 +59,7 @@ struct audio_device {
bdaddr_t dst;
gboolean auto_connect;
gboolean authorized;
struct headset *headset;
struct gateway *gateway;