Hi Marcel, Vinicius,
Here is the patch/workaround for service authorization.
Comments?
The next step is implement global trust: SetProperty("Trusted", True/False)
Regards,
Claudio.
--
--
Claudio Takahasi
Instituto Nokia de Tecnologia
Recife - Pernambuco - Brasil
+55 81 30879999
Index: audio/main.c
===================================================================
RCS file: /cvsroot/bluez/utils/audio/main.c,v
retrieving revision 1.33
diff -u -r1.33 main.c
--- audio/main.c 28 Mar 2008 20:46:51 -0000 1.33
+++ audio/main.c 30 Apr 2008 23:45:35 -0000
@@ -41,6 +41,20 @@
#include "device.h"
#include "manager.h"
+static const char *uuids[] = {
+ GENERIC_AUDIO_UUID,
+ HSP_HS_UUID,
+ HSP_AG_UUID,
+ HFP_HS_UUID,
+ HFP_AG_UUID,
+ ADVANCED_AUDIO_UUID,
+ A2DP_SOURCE_UUID,
+ A2DP_SINK_UUID,
+ AVRCP_REMOTE_UUID,
+ AVRCP_TARGET_UUID,
+ NULL
+};
+
static GKeyFile *load_config_file(const char *file)
{
GError *err = NULL;
@@ -82,6 +96,8 @@
g_key_file_free(config);
+ register_uuids("audio", &uuids);
+
register_external_service(conn, "audio", "Audio service", "");
return 0;
Index: hcid/dbus-database.c
===================================================================
RCS file: /cvsroot/bluez/utils/hcid/dbus-database.c,v
retrieving revision 1.44
diff -u -r1.44 dbus-database.c
--- hcid/dbus-database.c 9 Apr 2008 21:48:30 -0000 1.44
+++ hcid/dbus-database.c 30 Apr 2008 23:45:36 -0000
@@ -422,7 +422,10 @@
sender = dbus_message_get_sender(msg);
- service = search_service(sender);
+ service = search_service_by_uuid(uuid);
+ if (!service)
+ service = search_service(sender);
+
if (!service) {
debug("Got RequestAuthorization from non-service owner %s",
sender);
@@ -458,20 +461,23 @@
static DBusHandlerResult cancel_authorization_request(DBusConnection *conn,
DBusMessage *msg, void *data)
{
- const char *sender, *address, *path;
+ const char *sender, *address, *uuid;
struct service *service;
if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &address,
- DBUS_TYPE_STRING, &path, DBUS_TYPE_INVALID) == FALSE)
+ DBUS_TYPE_STRING, &uuid, DBUS_TYPE_INVALID) == FALSE)
return error_invalid_arguments(conn, msg, NULL);
sender = dbus_message_get_sender(msg);
- service = search_service(sender);
+ service = search_service_by_uuid(uuid);
+ if (!service)
+ service = search_service(sender);
+
if (!service)
return error_not_authorized(conn, msg);
- return cancel_authorize_request_old(conn, msg, service, address, path);
+ return cancel_authorize_request_old(conn, msg, service, address, uuid);
}
static DBusMethodVTable database_methods[] = {
Index: hcid/dbus-security.c
===================================================================
RCS file: /cvsroot/bluez/utils/hcid/dbus-security.c,v
retrieving revision 1.89
diff -u -r1.89 dbus-security.c
--- hcid/dbus-security.c 8 Apr 2008 21:28:26 -0000 1.89
+++ hcid/dbus-security.c 30 Apr 2008 23:45:37 -0000
@@ -766,7 +766,7 @@
const char *adapter_path,
struct service *service,
const char *address,
- const char *path)
+ const char *uuid)
{
struct auth_agent_req *req = NULL;
DBusMessage *message;
@@ -777,7 +777,7 @@
if (!strcmp(adapter_path, req->adapter_path) &&
!strcmp(address, req->address) &&
!strcmp(service->object_path, req->service_path) &&
- !strcmp(path, req->uuid))
+ !strcmp(uuid, req->uuid))
break;
}
@@ -801,7 +801,7 @@
DBusMessage *msg,
struct service *service,
const char *address,
- const char *path)
+ const char *uuid)
{
char adapter_path[PATH_MAX];
int adapter_id;
@@ -820,7 +820,7 @@
adapter_id);
return auth_agent_send_cancel(msg, default_auth_agent, adapter_path,
- service, address, path);
+ service, address, uuid);
}
static DBusMethodVTable security_methods[] = {
Index: hcid/dbus-service.c
===================================================================
RCS file: /cvsroot/bluez/utils/hcid/dbus-service.c,v
retrieving revision 1.146
diff -u -r1.146 dbus-service.c
--- hcid/dbus-service.c 3 Apr 2008 18:01:20 -0000 1.146
+++ hcid/dbus-service.c 30 Apr 2008 23:45:37 -0000
@@ -65,7 +65,13 @@
#define NAME_MATCH "interface=" DBUS_INTERFACE_DBUS ",member=NameOwnerChanged"
+struct service_uuids {
+ char *name;
+ char **uuids;
+};
+
static GSList *services = NULL;
+static GSList *services_uuids = NULL;
static GSList *removed = NULL;
static void service_free(struct service *service)
@@ -829,6 +835,12 @@
struct service *search_service(const char *pattern)
{
GSList *l;
+ const char *bus_id;
+
+ /* Workaround for plugins: share the same bus id */
+ bus_id = dbus_bus_get_unique_name(get_dbus_connection());
+ if (!strcmp(bus_id, pattern))
+ return NULL;
for (l = services; l != NULL; l = l->next) {
struct service *service = l->data;
@@ -1060,22 +1072,25 @@
const char *name, const char *description)
{
struct service *service;
-
- if (!conn)
- return -1;
+ const char *sender;
service = create_external_service(ident, name, description);
if (!service)
return -1;
- service->bus_name = g_strdup(bus_name);
+ if (!bus_name) {
+ sender = dbus_bus_get_unique_name(get_dbus_connection());
+ service->bus_name = g_strdup(sender);
+ } else
+ service->bus_name = g_strdup(bus_name);
if (register_service(service) < 0) {
service_free(service);
return -1;
}
- name_listener_add(conn, bus_name, (name_cb_t) external_service_exit,
+ if (conn && bus_name)
+ name_listener_add(conn, bus_name, (name_cb_t) external_service_exit,
service);
dbus_connection_emit_signal(get_dbus_connection(), service->object_path,
@@ -1089,3 +1104,95 @@
{
return unregister_service_for_connection(conn, service);
}
+
+static gint name_cmp(struct service_uuids *su, const char *name)
+{
+ return strcmp(su->name, name);
+}
+
+static gint uuid_cmp(struct service_uuids *su, const char *uuid)
+{
+ int i;
+
+ for (i = 0; su->uuids[i]; i++) {
+ if (!strcasecmp(su->uuids[i], uuid))
+ return 0;
+ }
+
+ return -1;
+}
+
+struct service *search_service_by_uuid(const char *uuid)
+{
+ struct service_uuids *su;
+ struct service *service;
+ GSList *l;
+
+ if (!services_uuids)
+ return NULL;
+
+ l = g_slist_find_custom(services_uuids, uuid, (GCompareFunc) uuid_cmp);
+ if (!l)
+ return NULL;
+
+ su = l->data;
+ service = search_service(su->name);
+ if (!service)
+ return NULL;
+
+ return service;
+}
+
+void register_uuids(const char *name, const char **uuids)
+{
+ struct service_uuids *su;
+ int i;
+
+ if (!name)
+ return;
+
+ su = g_new0(struct service_uuids, 1);
+ su->name = g_strdup(name);
+
+ for (i = 0; uuids[i]; i++);
+
+ su->uuids = g_new0(char *, i + 1);
+
+ for (i = 0; uuids[i]; i++)
+ su->uuids[i] = g_strdup(uuids[i]);
+
+ services_uuids = g_slist_append(services_uuids, su);
+}
+
+static void service_uuids_free(struct service_uuids *su)
+{
+ int i;
+
+ if (!su)
+ return;
+
+ g_free(su->name);
+
+ for (i = 0; su->uuids[i]; i++)
+ g_free(su->uuids[i]);
+
+ g_free(su);
+}
+
+void unregister_uuids(const char *name)
+{
+ struct service_uuids *su;
+ GSList *l;
+
+ if (!services_uuids)
+ return;
+
+ l = g_slist_find_custom(services_uuids, name, (GCompareFunc) name_cmp);
+ if (!l)
+ return;
+
+ su = l->data;
+ services_uuids = g_slist_remove(services_uuids, su);
+
+ service_uuids_free(su);
+}
Index: hcid/dbus-service.h
===================================================================
RCS file: /cvsroot/bluez/utils/hcid/dbus-service.h,v
retrieving revision 1.34
diff -u -r1.34 dbus-service.h
--- hcid/dbus-service.h 3 Apr 2008 18:01:20 -0000 1.34
+++ hcid/dbus-service.h 30 Apr 2008 23:45:38 -0000
@@ -53,6 +53,8 @@
struct service *search_service(const char *pattern);
+struct service *search_service_by_uuid(const char *uuid);
+
int service_start(struct service *service, DBusConnection *conn);
int init_services(const char *path);
@@ -61,3 +63,6 @@
const char *name, const char *description);
int service_unregister(DBusConnection *conn, struct service *service);
+
+void register_uuids(const char *name, const char **uuids);
+void unregister_uuids(const char *name);
Index: hcid/plugin.c
===================================================================
RCS file: /cvsroot/bluez/utils/hcid/plugin.c,v
retrieving revision 1.12
diff -u -r1.12 plugin.c
--- hcid/plugin.c 17 Apr 2008 17:46:50 -0000 1.12
+++ hcid/plugin.c 30 Apr 2008 23:45:38 -0000
@@ -38,6 +38,7 @@
#include <dbus/dbus.h>
#include "dbus-helper.h"
+#include "dbus-service.h"
#include "adapter.h"
#include "dbus-hci.h"
#include "agent.h"
@@ -210,18 +211,15 @@
dst, active_conn_find_by_bdaddr))
return -ENOTCONN;
- /* FIXME: Is there a plugin that exports this service? */
-
ba2str(dst, address);
device = adapter_find_device(adapter, address);
if (!device)
return -EPERM;
- /*
- * FIXME: Trusted device? Currently, service are based on a friendly
- * name, it is necessary convert UUID128 to friendly name or store the
- * UUID128 in the trusted file.
- */
+ if (!search_service_by_uuid(uuid))
+ return -EPERM;
+
+ /* FIXME: Missing check trusted file entries */
agent = (device->agent ? : adapter->agent);
if (!agent)
Index: input/main.c
===================================================================
RCS file: /cvsroot/bluez/utils/input/main.c,v
retrieving revision 1.20
diff -u -r1.20 main.c
--- input/main.c 9 Apr 2008 22:00:34 -0000 1.20
+++ input/main.c 30 Apr 2008 23:45:38 -0000
@@ -34,6 +34,13 @@
#include "dbus.h"
#include "manager.h"
+#define HID_UUID "00001124-0000-1000-8000-00805f9b34fb"
+
+static const char *uuids[] = {
+ HID_UUID,
+ NULL
+};
+
static DBusConnection *conn;
static int input_init(void)
@@ -47,6 +54,8 @@
return -EIO;
}
+ register_uuids("input", &uuids);
+
register_external_service(conn, "input", "Input service", "");
return 0;
Index: input/server.c
===================================================================
RCS file: /cvsroot/bluez/utils/input/server.c,v
retrieving revision 1.20
diff -u -r1.20 server.c
--- input/server.c 17 Apr 2008 14:54:30 -0000 1.20
+++ input/server.c 30 Apr 2008 23:45:38 -0000
@@ -55,7 +55,6 @@
static void cancel_authorization(const char *addr)
{
DBusMessage *msg;
- const char *uuid = "";
msg = dbus_message_new_method_call("org.bluez", "/org/bluez",
"org.bluez.Database",
@@ -67,7 +66,7 @@
dbus_message_append_args(msg,
DBUS_TYPE_STRING, &addr,
- DBUS_TYPE_STRING, &uuid,
+ DBUS_TYPE_STRING, &HID_UUID,
DBUS_TYPE_INVALID);
send_message_and_unref(connection, msg);
Index: network/main.c
===================================================================
RCS file: /cvsroot/bluez/utils/network/main.c,v
retrieving revision 1.20
diff -u -r1.20 main.c
--- network/main.c 11 Apr 2008 23:04:17 -0000 1.20
+++ network/main.c 30 Apr 2008 23:45:38 -0000
@@ -41,6 +41,17 @@
#define GN_IFACE "pan0"
#define NAP_IFACE "pan1"
+#define PANU_UUID "00001115-0000-1000-8000-00805f9b34fb"
+#define NAP_UUID "00001116-0000-1000-8000-00805f9b34fb"
+#define GN_UUID "00001117-0000-1000-8000-00805f9b34fb"
+
+static const char *uuids[] = {
+ PANU_UUID,
+ NAP_UUID,
+ GN_UUID,
+ NULL
+};
+
static struct network_conf conf = {
.connection_enabled = TRUE,
.server_enabled = TRUE,
@@ -170,6 +181,8 @@
return -EIO;
}
+ register_uuids("network", &uuids);
+
register_external_service(conn, "network", "Network service", "");
return 0;
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Bluez-devel mailing list
Bluez-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.sourceforge.net/lists/listinfo/bluez-devel