Skip to contentSkip to conversation

Authorization

PATCH New Claudio Takahasi 1 participant 1 message Apr 30, 2008 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Authorization

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.

Signature · 5 lines
--
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

main.c +16 -0
diff -u -r1.33 main.c
@@ -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

dbus-database.c +11 -5
diff -u -r1.44 dbus-database.c
@@ -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

dbus-security.c +4 -4
diff -u -r1.89 dbus-security.c
@@ -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

dbus-service.c +112 -5

150 lines not on this page · raw message

Index: hcid/dbus-service.h
===================================================================
RCS file: /cvsroot/bluez/utils/hcid/dbus-service.h,v retrieving revision 1.34

dbus-service.h +5 -0
diff -u -r1.34 dbus-service.h
@@ -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

plugin.c +5 -7
diff -u -r1.12 plugin.c
@@ -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

main.c +9 -0
diff -u -r1.20 main.c
@@ -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

server.c +1 -2
diff -u -r1.20 server.c
@@ -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

main.c +13 -0
diff -u -r1.20 main.c
@@ -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
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel