diff options
-rw-r--r-- | hcid/dbus-api.txt | 8 | ||||
-rw-r--r-- | hcid/dbus-error.c | 11 | ||||
-rw-r--r-- | hcid/dbus-error.h | 2 | ||||
-rw-r--r-- | hcid/dbus-security.c | 7 | ||||
-rw-r--r-- | hcid/dbus-service.c | 14 |
5 files changed, 33 insertions, 9 deletions
diff --git a/hcid/dbus-api.txt b/hcid/dbus-api.txt index 95ed2f40..b43a8429 100644 --- a/hcid/dbus-api.txt +++ b/hcid/dbus-api.txt @@ -1163,16 +1163,24 @@ Methods string GetConnectionName() Marks the user as trusted. + Possible errors: org.bluez.Error.InvalidArguments + org.bluez.Error.AlreadyExists + boolean IsTrusted(string address) Returns true if the user is trusted or false otherwise. The address parameter must match one of the current users of the service. + Possible errors: org.bluez.Error.InvalidArguments + void RemoveTrust(string address) Marks the user as not trusted. + Possible errors: org.bluez.Error.InvalidArguments + org.bluez.Error.DoesNotExist + Signals void Started() The object path of this signal contains which service diff --git a/hcid/dbus-error.c b/hcid/dbus-error.c index 4db8a8cf..8a87cff5 100644 --- a/hcid/dbus-error.c +++ b/hcid/dbus-error.c @@ -268,6 +268,17 @@ DBusHandlerResult error_audit_already_exists(DBusConnection *conn, DBusMessage * return error_already_exists(conn, msg, "Audit already performed"); } +DBusHandlerResult error_trusted_device_already_exists(DBusConnection *conn, DBusMessage *msg) +{ + return error_already_exists(conn, msg, "Trusted device already exists"); +} + +DBusHandlerResult error_trusted_device_does_not_exists(DBusConnection *conn, DBusMessage *msg) +{ + return error_does_not_exist(conn, msg, "Trusted device does not exist"); +} + + static const char *strsdperror(int err) { switch (err) { diff --git a/hcid/dbus-error.h b/hcid/dbus-error.h index 92b4f47b..c88ce815 100644 --- a/hcid/dbus-error.h +++ b/hcid/dbus-error.h @@ -63,5 +63,7 @@ DBusHandlerResult error_service_search_in_progress(DBusConnection *conn, DBusMes DBusHandlerResult error_connect_canceled(DBusConnection *conn, DBusMessage *msg); DBusHandlerResult error_sdp_failed(DBusConnection *conn, DBusMessage *msg, int err); DBusHandlerResult error_audit_already_exists(DBusConnection *conn, DBusMessage *msg); +DBusHandlerResult error_trusted_device_already_exists(DBusConnection *conn, DBusMessage *msg); +DBusHandlerResult error_trusted_device_does_not_exists(DBusConnection *conn, DBusMessage *msg); #endif /* __BLUEZ_DBUS_ERROR_H */ diff --git a/hcid/dbus-security.c b/hcid/dbus-security.c index 0fe55dd2..cd70616b 100644 --- a/hcid/dbus-security.c +++ b/hcid/dbus-security.c @@ -761,6 +761,7 @@ static DBusHandlerResult authorize_service(DBusConnection *conn, { const char *service_path, *adapter_path, *address, *action; struct service_agent *sagent; + struct slist *l; if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &service_path, @@ -783,6 +784,12 @@ static DBusHandlerResult authorize_service(DBusConnection *conn, if (strcmp(dbus_message_get_sender(msg), sagent->id)) return error_rejected(conn, msg); + /* Check it is a trusted device */ + l = slist_find(sagent->trusted_devices, address, (cmp_func_t) strcasecmp); + if (l) + return send_message_and_unref(conn, + dbus_message_new_method_return(msg)); + if (!default_auth_agent) return error_auth_agent_does_not_exist(conn, msg); diff --git a/hcid/dbus-service.c b/hcid/dbus-service.c index 324ac681..69136f8f 100644 --- a/hcid/dbus-service.c +++ b/hcid/dbus-service.c @@ -561,8 +561,6 @@ static DBusHandlerResult set_trusted(DBusConnection *conn, DBusMessage *reply; const char *address; - /* FIXME: Missing define security policy */ - if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &address, DBUS_TYPE_INVALID)) @@ -571,9 +569,9 @@ static DBusHandlerResult set_trusted(DBusConnection *conn, if (check_address(address) < 0) return error_invalid_arguments(conn, msg); - l = slist_find(agent->trusted_devices, address, (cmp_func_t) strcmp); + l = slist_find(agent->trusted_devices, address, (cmp_func_t) strcasecmp); if (l) - return error_failed(conn, msg, EINVAL); + return error_trusted_device_already_exists(conn, msg); reply = dbus_message_new_method_return(msg); if (!reply) @@ -598,7 +596,7 @@ static DBusHandlerResult is_trusted(DBusConnection *conn, DBUS_TYPE_INVALID)) return error_invalid_arguments(conn, msg); - l = slist_find(agent->trusted_devices, address, (cmp_func_t) strcmp); + l = slist_find(agent->trusted_devices, address, (cmp_func_t) strcasecmp); trusted = (l? TRUE : FALSE); reply = dbus_message_new_method_return(msg); @@ -621,16 +619,14 @@ static DBusHandlerResult remove_trust(DBusConnection *conn, const char *address; void *paddress; - /* FIXME: Missing define security policy */ - if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &address, DBUS_TYPE_INVALID)) return error_invalid_arguments(conn, msg); - l = slist_find(agent->trusted_devices, address, (cmp_func_t) strcmp); + l = slist_find(agent->trusted_devices, address, (cmp_func_t) strcasecmp); if (!l) - return error_invalid_arguments(conn, msg); /* FIXME: find a better error name */ + return error_trusted_device_does_not_exists(conn, msg); reply = dbus_message_new_method_return(msg); if (!reply) |