summaryrefslogtreecommitdiffstats
path: root/hcid
diff options
context:
space:
mode:
authorClaudio Takahasi <claudio.takahasi@openbossa.org>2006-03-10 19:37:21 +0000
committerClaudio Takahasi <claudio.takahasi@openbossa.org>2006-03-10 19:37:21 +0000
commit62bf14a7a2b1059ce37f342ba26933f187e0885c (patch)
tree73e16f8f3f0f26035ed31aaf41fd0e52cd7f6635 /hcid
parentc455022aae4b9da5ccad1698f2b02b9b1f0ce22a (diff)
Added requestor unique name verification before cancel an inquiry process
Diffstat (limited to 'hcid')
-rw-r--r--hcid/dbus-adapter.c22
-rw-r--r--hcid/dbus.c21
2 files changed, 31 insertions, 12 deletions
diff --git a/hcid/dbus-adapter.c b/hcid/dbus-adapter.c
index 3c2a3300..984b7778 100644
--- a/hcid/dbus-adapter.c
+++ b/hcid/dbus-adapter.c
@@ -1129,6 +1129,7 @@ static DBusMessage *handle_dev_get_encryption_key_size_req(DBusMessage *msg, voi
static DBusMessage *handle_dev_discover_devices_req(DBusMessage *msg, void *data)
{
DBusMessage *reply = NULL;
+ const char *requestor_name;
inquiry_cp cp;
evt_cmd_status rp;
struct hci_request rq;
@@ -1137,7 +1138,7 @@ static DBusMessage *handle_dev_discover_devices_req(DBusMessage *msg, void *data
uint32_t lap = 0x9e8b33;
int dd;
- if (dbus_data->busy)
+ if (dbus_data->requestor_name)
return error_discover_in_progress(msg);
dd = hci_open_dev(dbus_data->dev_id);
@@ -1167,6 +1168,9 @@ static DBusMessage *handle_dev_discover_devices_req(DBusMessage *msg, void *data
goto failed;
}
+ requestor_name = dbus_message_get_sender(msg);
+ dbus_data->requestor_name = strdup(requestor_name);
+
reply = dbus_message_new_method_return(msg);
failed:
@@ -1178,10 +1182,21 @@ failed:
static DBusMessage *handle_dev_cancel_discovery_req(DBusMessage *msg, void *data)
{
DBusMessage *reply = NULL;
+ const char *requestor_name;
struct hci_request rq;
struct hci_dbus_data *dbus_data = data;
uint8_t status;
- int dd;
+ int dd = -1;
+
+ requestor_name = dbus_message_get_sender(msg);
+
+ /* is there discover pending? */
+ if (!dbus_data->requestor_name)
+ return error_not_authorized(msg);
+
+ /* only the discover requestor can cancel the inquiry process */
+ if (strcmp(dbus_data->requestor_name, requestor_name))
+ return error_not_authorized(msg);
dd = hci_open_dev(dbus_data->dev_id);
if (dd < 0)
@@ -1206,6 +1221,9 @@ static DBusMessage *handle_dev_cancel_discovery_req(DBusMessage *msg, void *data
goto failed;
}
+ free(dbus_data->requestor_name);
+ dbus_data->requestor_name = NULL;
+
reply = dbus_message_new_method_return(msg);
failed:
diff --git a/hcid/dbus.c b/hcid/dbus.c
index bb8d2528..b1e7a30f 100644
--- a/hcid/dbus.c
+++ b/hcid/dbus.c
@@ -281,7 +281,7 @@ static gboolean register_dbus_path(const char *path, uint16_t path_id, uint16_t
data->discoverable_timeout = DFT_DISCOVERABLE_TIMEOUT;
data->timeout_hits = 0;
data->timeout_handler = NULL;
- data->busy = 0;
+ data->requestor_name = NULL;
if (fallback) {
if (!dbus_connection_register_fallback(connection, path, pvtable, data)) {
@@ -306,12 +306,15 @@ failed:
static gboolean unregister_dbus_path(const char *path)
{
- void *data;
+ struct hci_dbus_data *data;
syslog(LOG_INFO, "Unregister path:%s", path);
- if (dbus_connection_get_object_path_data(connection, path, &data) && data)
+ if (dbus_connection_get_object_path_data(connection, path, (void*)&data) && data) {
+ if (data->requestor_name)
+ free(data->requestor_name);
free(data);
+ }
if (!dbus_connection_unregister_object_path (connection, path)) {
syslog(LOG_ERR, "D-Bus failed to unregister %s object", path);
@@ -555,7 +558,6 @@ void hcid_dbus_inquiry_start(bdaddr_t *local)
{
DBusMessage *message = NULL;
char path[MAX_PATH_LENGTH];
- struct hci_dbus_data *pdata = NULL;
char *local_addr;
bdaddr_t tmp;
int id;
@@ -570,10 +572,6 @@ void hcid_dbus_inquiry_start(bdaddr_t *local)
snprintf(path, sizeof(path), "%s/hci%d", ADAPTER_PATH, id);
- if (dbus_connection_get_object_path_data(connection, path, (void*) &pdata)) {
- pdata->busy = 1;
- }
-
message = dbus_message_new_signal(path, ADAPTER_INTERFACE,
DEV_SIG_DISCOVER_START);
if (message == NULL) {
@@ -596,8 +594,8 @@ failed:
void hcid_dbus_inquiry_complete(bdaddr_t *local)
{
DBusMessage *message = NULL;
- char path[MAX_PATH_LENGTH];
struct hci_dbus_data *pdata = NULL;
+ char path[MAX_PATH_LENGTH];
char *local_addr;
bdaddr_t tmp;
int id;
@@ -613,7 +611,10 @@ void hcid_dbus_inquiry_complete(bdaddr_t *local)
snprintf(path, sizeof(path), "%s/hci%d", ADAPTER_PATH, id);
if (dbus_connection_get_object_path_data(connection, path, (void*) &pdata)) {
- pdata->busy = 0;
+ if (pdata->requestor_name) {
+ free(pdata->requestor_name);
+ pdata->requestor_name = NULL;
+ }
}
message = dbus_message_new_signal(path, ADAPTER_INTERFACE,