Skip to contentSkip to conversation

bluetooth: make use of secure flag for authorization

PATCH In review Luiz Augusto von Dentz 2 participants 7 messages Nov 27, 2011 – Nov 29, 2011

Subsystems (2)
lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH v2 1/6 bluetooth: make use of secure flag for authorization

From: Luiz Augusto von Dentz <[email protected]>

Using secure flag is probably safer here as other services beside OPP may not require security/authorization.
---

 plugins/bluetooth.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
plugins/bluetooth.c +1 -1
index c73beb6..613b2a5 100644
@@ -479,7 +479,7 @@ static void confirm_event(GIOChannel *io, void *user_data)
 		goto drop;
 	}
 
-	if (driver->service != OBEX_OPP) {
+	if (driver->secure) {
 		if (request_service_authorization(service, io, address) < 0)
 			goto drop;
 
Signature · 1 line
1.7.7.3
author maintainer
#1 lore raw

PATCH v2 2/6 bluetooth: add .getpeername support

From: Luiz Augusto von Dentz <[email protected]>

---
 plugins/bluetooth.c |   17 +++++++++++++++++
 src/transport.h     |    1 +
 2 files changed, 18 insertions(+), 0 deletions(-)
plugins/bluetooth.c +17 -0
index 613b2a5..e547857 100644
@@ -562,9 +562,26 @@ static void bluetooth_stop(void *data)
 	g_slist_free_full(ios, stop);
 }
 
+static int bluetooth_getpeername(GIOChannel *io, char **name)
+{
+	GError *gerr = NULL;
+	char address[18];
+
+	bt_io_get(io, BT_IO_RFCOMM, &gerr,
+			BT_IO_OPT_DEST, address,
+			BT_IO_OPT_INVALID);
+	if (gerr)
+		return -EINVAL;
+
+	*name = g_strdup(address);
+
+	return 0;
+}
+
 static struct obex_transport_driver driver = {
 	.name = "bluetooth",
 	.start = bluetooth_start,
+	.getpeername = bluetooth_getpeername,
 	.stop = bluetooth_stop
 };
 
src/transport.h +1 -0
index 320fafb..b81615b 100644
@@ -25,6 +25,7 @@ struct obex_transport_driver {
 	const char *name;
 	uint16_t service;
 	void *(*start) (struct obex_server *server, int *err);
+	int (*getpeername) (GIOChannel *io, char **name);
 	void (*stop) (void *data);
 };
 
Signature · 1 line
1.7.7.3
author maintainer
#2 lore raw

PATCH v2 3/6 Fix calling getpeername directly on manager.c

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

Manager should be transport agnostic and not pretend the transport is always RFCOMM since in future this might not be true even for Bluetooth.

---
 src/manager.c |   34 +++++++++++-----------------------
 src/obex.c    |   10 ++++++++++
 src/obex.h    |    1 +
 3 files changed, 22 insertions(+), 23 deletions(-)
src/manager.c +11 -23
index 3953e9d..b151a21 100644
@@ -31,9 +31,7 @@
 #include <errno.h>
 #include <gdbus.h>
 #include <sys/socket.h>
-
-#include <bluetooth/bluetooth.h>
-#include <bluetooth/rfcomm.h>
+#include <inttypes.h>
 
 #include <openobex/obex.h>
 
@@ -521,16 +519,12 @@ int manager_request_authorization(struct obex_session *os, int32_t time,
 {
 	DBusMessage *msg;
 	DBusPendingCall *call;
-	GIOChannel *io;
-	struct sockaddr_rc addr;
-	socklen_t addrlen;
-	char address[18];
-	const char *bda = address;
 	const char *filename = os->name ? os->name : "";
 	const char *type = os->type ? os->type : "";
-	char *path;
-	unsigned int watch, fd;
+	char *path, *address;
+	unsigned int watch;
 	gboolean got_reply;
+	int err;
 
 	if (!agent)
 		return -1;
@@ -541,23 +535,18 @@ int manager_request_authorization(struct obex_session *os, int32_t time,
 	if (!new_folder || !new_name)
 		return -EINVAL;
 
-	memset(&addr, 0, sizeof(addr));
-	addrlen = sizeof(addr);
-
-	fd = OBEX_GetFD(os->obex);
-	if (getpeername(fd, (struct sockaddr *) &addr, &addrlen) < 0)
-		return -errno;
-
-	ba2str(&addr.rc_bdaddr, address);
+	err = obex_getpeername(os, &address);
+	if (err < 0)
+		return err;
 
-	path = g_strdup_printf("/transfer%d", os->cid);
+	path = g_strdup_printf("/transfer%u", GPOINTER_TO_UINT(os));
 
 	msg = dbus_message_new_method_call(agent->bus_name, agent->path,
 					"org.openobex.Agent", "Authorize");
 
 	dbus_message_append_args(msg,
 			DBUS_TYPE_OBJECT_PATH, &path,
-			DBUS_TYPE_STRING, &bda,
+			DBUS_TYPE_STRING, &address,
 			DBUS_TYPE_STRING, &filename,
 			DBUS_TYPE_STRING, &type,
 			DBUS_TYPE_INT32, &os->size,
@@ -565,6 +554,7 @@ int manager_request_authorization(struct obex_session *os, int32_t time,
 			DBUS_TYPE_INVALID);
 
 	g_free(path);
+	g_free(address);
 
 	if (!dbus_connection_send_with_reply(connection,
 					msg, &call, TIMEOUT)) {
@@ -578,11 +568,9 @@ int manager_request_authorization(struct obex_session *os, int32_t time,
 	got_reply = FALSE;
 
 	/* Catches errors before authorization response comes */
-	io = g_io_channel_unix_new(fd);
-	watch = g_io_add_watch_full(io, G_PRIORITY_DEFAULT,
+	watch = g_io_add_watch_full(os->io, G_PRIORITY_DEFAULT,
 			G_IO_HUP | G_IO_ERR | G_IO_NVAL,
 			auth_error, NULL, NULL);
-	g_io_channel_unref(io);
 
 	dbus_pending_call_set_notify(call, agent_reply, &got_reply, NULL);
 
src/obex.c +10 -0
index 7d8d0e8..7f31c5d 100644
@@ -1556,6 +1556,16 @@ ssize_t obex_get_non_header_data(struct obex_session *os,
 	return os->nonhdr_len;
 }
 
+int obex_getpeername(struct obex_session *os, char **name)
+{
+	struct obex_transport_driver *transport = os->server->transport;
+
+	if (transport == NULL || transport->getpeername == NULL)
+		return -ENOTSUP;
+
+	return transport->getpeername(os->io, name);
+}
+
 int memncmp0(const void *a, size_t na, const void *b, size_t nb)
 {
 	if (na != nb)
src/obex.h +1 -0
index 3e8ce00..3ec49a9 100644
@@ -50,6 +50,7 @@ char *obex_get_id(struct obex_session *os);
 ssize_t obex_get_apparam(struct obex_session *os, const uint8_t **buffer);
 ssize_t obex_get_non_header_data(struct obex_session *os,
 							const uint8_t **data);
+int obex_getpeername(struct obex_session *os, char **name);
 
 /* Just a thin wrapper around memcmp to deal with NULL values */
 int memncmp0(const void *a, size_t na, const void *b, size_t nb);
Signature · 1 line
1.7.7.3
author maintainer
#3 lore raw

PATCH v2 4/6 Remove obex_get_id

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

Plugins that need the peer address/name should use obex_getpeername which uses the transport driver to resolve it.

---
 plugins/syncevolution.c |    8 +++++++-
 src/obex.c              |   17 -----------------
 src/obex.h              |    1 -
 3 files changed, 7 insertions(+), 19 deletions(-)
plugins/syncevolution.c +7 -1
index e3b06f4..b0cd626 100644
@@ -218,6 +218,7 @@ static void *synce_connect(struct obex_session *os, int *err)
 {
 	DBusConnection *conn;
 	struct synce_context *context;
+	char *address;
 
 	manager_register_session(os);
 
@@ -228,9 +229,14 @@ static void *synce_connect(struct obex_session *os, int *err)
 	context = g_new0(struct synce_context, 1);
 	context->dbus_conn = conn;
 	context->lasterr = -EAGAIN;
-	context->id = obex_get_id(os);
 	context->os = os;
 
+	if (obex_getpeername(os, &address) == 0) {
+		context->id = g_strdup_printf("%s+%d", address,
+							SYNCEVOLUTION_CHANNEL);
+		g_free(address);
+	}
+
 	if (err)
 		*err = 0;
 
src/obex.c +0 -17
index 7f31c5d..a88306d 100644
@@ -1524,23 +1524,6 @@ uint8_t obex_get_action_id(struct obex_session *os)
 	return os->action_id;
 }
 
-/* TODO: find a way to do this for tty or fix syncevolution */
-char *obex_get_id(struct obex_session *os)
-{
-	GError *gerr = NULL;
-	char address[18];
-	uint8_t channel;
-
-	bt_io_get(os->io, BT_IO_RFCOMM, &gerr,
-			BT_IO_OPT_DEST, address,
-			BT_IO_OPT_CHANNEL, &channel,
-			BT_IO_OPT_INVALID);
-	if (gerr)
-		return NULL;
-
-	return g_strdup_printf("%s+%d", address, channel);
-}
-
 ssize_t obex_get_apparam(struct obex_session *os, const uint8_t **buffer)
 {
 	*buffer = os->apparam;
src/obex.h +0 -1
index 3ec49a9..7f07fd2 100644
@@ -46,7 +46,6 @@ int obex_copy(struct obex_session *os, const char *source,
 int obex_move(struct obex_session *os, const char *source,
 						const char *destination);
 uint8_t obex_get_action_id(struct obex_session *os);
-char *obex_get_id(struct obex_session *os);
 ssize_t obex_get_apparam(struct obex_session *os, const uint8_t **buffer);
 ssize_t obex_get_non_header_data(struct obex_session *os,
 							const uint8_t **data);
Signature · 1 line
1.7.7.3
author maintainer
#4 lore raw

PATCH v2 5/6 Port core daemon to gobex

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

---
 src/manager.c   |   26 +-
 src/obex-priv.h |   11 +-
 src/obex.c      | 1393 ++++++++++++++++++++++---------------------------------
 src/server.c    |    4 +-
 4 files changed, 574 insertions(+), 860 deletions(-)
src/manager.c +13 -13
index b151a21..88a5439 100644
@@ -33,7 +33,7 @@
 #include <sys/socket.h>
 #include <inttypes.h>
 
-#include <openobex/obex.h>
+#include <gobex.h>
 
 #include "obexd.h"
 #include "obex.h"
@@ -381,7 +381,7 @@ void manager_cleanup(void)
 
 void manager_emit_transfer_started(struct obex_session *os)
 {
-	char *path = g_strdup_printf("/transfer%u", os->cid);
+	char *path = g_strdup_printf("/transfer%u", GPOINTER_TO_UINT(os));
 
 	g_dbus_emit_signal(connection, OPENOBEX_MANAGER_PATH,
 			OPENOBEX_MANAGER_INTERFACE, "TransferStarted",
@@ -391,9 +391,9 @@ void manager_emit_transfer_started(struct obex_session *os)
 	g_free(path);
 }
 
-static void emit_transfer_completed(uint32_t id, gboolean success)
+static void emit_transfer_completed(struct obex_session *os, gboolean success)
 {
-	char *path = g_strdup_printf("/transfer%u", id);
+	char *path = g_strdup_printf("/transfer%u", GPOINTER_TO_UINT(os));
 
 	g_dbus_emit_signal(connection, OPENOBEX_MANAGER_PATH,
 			OPENOBEX_MANAGER_INTERFACE, "TransferCompleted",
@@ -404,10 +404,10 @@ static void emit_transfer_completed(uint32_t id, gboolean success)
 	g_free(path);
 }
 
-static void emit_transfer_progress(uint32_t id, uint32_t total,
+static void emit_transfer_progress(struct obex_session *os, uint32_t total,
 							uint32_t transfered)
 {
-	char *path = g_strdup_printf("/transfer%u", id);
+	char *path = g_strdup_printf("/transfer%u", GPOINTER_TO_UINT(os));
 
 	g_dbus_emit_signal(connection, path,
 			TRANSFER_INTERFACE, "Progress",
@@ -420,7 +420,7 @@ static void emit_transfer_progress(uint32_t id, uint32_t total,
 
 void manager_register_transfer(struct obex_session *os)
 {
-	char *path = g_strdup_printf("/transfer%u", os->cid);
+	char *path = g_strdup_printf("/transfer%u", GPOINTER_TO_UINT(os));
 
 	if (!g_dbus_register_interface(connection, path,
 				TRANSFER_INTERFACE,
@@ -436,11 +436,11 @@ void manager_register_transfer(struct obex_session *os)
 
 void manager_unregister_transfer(struct obex_session *os)
 {
-	char *path = g_strdup_printf("/transfer%u", os->cid);
+	char *path = g_strdup_printf("/transfer%u", GPOINTER_TO_UINT(os));
 
 	/* Got an error during a transfer. */
 	if (os->object)
-		emit_transfer_completed(os->cid, os->offset == os->size);
+		emit_transfer_completed(os, os->offset == os->size);
 
 	g_dbus_unregister_interface(connection, path,
 				TRANSFER_INTERFACE);
@@ -600,7 +600,7 @@ int manager_request_authorization(struct obex_session *os, int32_t time,
 
 void manager_register_session(struct obex_session *os)
 {
-	char *path = g_strdup_printf("/session%u", os->cid);
+	char *path = g_strdup_printf("/session%u", GPOINTER_TO_UINT(os));
 
 	if (!g_dbus_register_interface(connection, path,
 				SESSION_INTERFACE,
@@ -621,7 +621,7 @@ void manager_register_session(struct obex_session *os)
 
 void manager_unregister_session(struct obex_session *os)
 {
-	char *path = g_strdup_printf("/session%u", os->cid);
+	char *path = g_strdup_printf("/session%u", GPOINTER_TO_UINT(os));
 
 	g_dbus_emit_signal(connection, OPENOBEX_MANAGER_PATH,
 			OPENOBEX_MANAGER_INTERFACE, "SessionRemoved",
@@ -636,13 +636,13 @@ void manager_unregister_session(struct obex_session *os)
 
 void manager_emit_transfer_progress(struct obex_session *os)
 {
-	emit_transfer_progress(os->cid, os->size, os->offset);
+	emit_transfer_progress(os, os->size, os->offset);
 }
 
 void manager_emit_transfer_completed(struct obex_session *os)
 {
 	if (os->object)
-		emit_transfer_completed(os->cid, !os->aborted);
+		emit_transfer_completed(os, !os->aborted);
 }
 
 DBusConnection *manager_dbus_get_connection(void)
src/obex-priv.h +3 -8
index 6a439b4..087400b 100644
@@ -24,9 +24,6 @@
 
 struct obex_session {
 	GIOChannel *io;
-	uint32_t cid;
-	uint16_t tx_mtu;
-	uint16_t rx_mtu;
 	uint8_t cmd;
 	uint8_t action_id;
 	char *name;
@@ -36,8 +33,9 @@ struct obex_session {
 	time_t time;
 	uint8_t *apparam;
 	size_t apparam_len;
-	uint8_t *nonhdr;
+	const void *nonhdr;
 	size_t nonhdr_len;
+	guint get_rsp;
 	uint8_t *buf;
 	int64_t pending;
 	int64_t offset;
@@ -48,11 +46,8 @@ struct obex_session {
 	void *service_data;
 	struct obex_server *server;
 	gboolean checked;
-	obex_t *obex;
-	obex_object_t *obj;
+	GObex *obex;
 	struct obex_mime_type_driver *driver;
-	gboolean stream_open;
-	gboolean stream_suspended;
 	gboolean headers_sent;
 };
 
src/obex.c +556 -837

1,789 lines not on this page · raw message

src/server.c +2 -2
index f91a622..e5dc22d 100644
@@ -33,10 +33,10 @@
 #include <fcntl.h>
 #include <errno.h>
 #include <string.h>
+#include <inttypes.h>
 
 #include <glib.h>
-
-#include <openobex/obex.h>
+#include <gobex.h>
 
 #include "log.h"
 #include "obex.h"
Signature · 1 line
1.7.7.3
author maintainer
#6 lore raw

PATCH v2 6/6 Remove dependency on OpenOBEX

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

Now that the server also uses gobex there is no need to depend on OpenOBEX anymore.

---
 Makefile.am  |   14 ++++++--------
 configure.ac |    5 -----
 2 files changed, 6 insertions(+), 13 deletions(-)
Makefile.am +6 -8
index 2582651..af03f2e 100644
@@ -85,9 +85,8 @@ src_obexd_SOURCES = $(gdbus_sources) $(builtin_sources) $(btio_sources) \
 			src/server.h src/server.c
 
 src_obexd_LDADD = @DBUS_LIBS@ @GLIB_LIBS@ @GTHREAD_LIBS@ \
-					@EBOOK_LIBS@ @OPENOBEX_LIBS@ \
-					@BLUEZ_LIBS@ @LIBICAL_LIBS@ \
-					@TRACKER_LIBS@ -ldl
+					@EBOOK_LIBS@ @BLUEZ_LIBS@ \
+					@LIBICAL_LIBS@ @TRACKER_LIBS@ -ldl
 
 src_obexd_LDFLAGS = -Wl,--export-dynamic
 
@@ -129,11 +128,10 @@ endif
 
 service_DATA = $(service_in_files:.service.in=.service)
 
-AM_CFLAGS = @OPENOBEX_CFLAGS@ @BLUEZ_CFLAGS@ @EBOOK_CFLAGS@ \
-			@GTHREAD_CFLAGS@ @GLIB_CFLAGS@ @DBUS_CFLAGS@ \
-			@LIBICAL_CFLAGS@ -D_FILE_OFFSET_BITS=64 \
-			@TRACKER_CFLAGS@ \
-			-DOBEX_PLUGIN_BUILTIN -DPLUGINDIR=\""$(plugindir)"\"
+AM_CFLAGS = @BLUEZ_CFLAGS@ @EBOOK_CFLAGS@ @GTHREAD_CFLAGS@ @GLIB_CFLAGS@ \
+			@DBUS_CFLAGS@ @LIBICAL_CFLAGS@ @TRACKER_CFLAGS@ \
+			-DOBEX_PLUGIN_BUILTIN -DPLUGINDIR=\""$(plugindir)"\" \
+			-D_FILE_OFFSET_BITS=64
 
 INCLUDES = -I$(builddir)/src -I$(srcdir)/src -I$(srcdir)/plugins \
 				-I$(srcdir)/gdbus \
configure.ac +0 -5
index 962e2e7..fca284e 100644
@@ -89,11 +89,6 @@ AC_CHECK_LIB(dbus-1, dbus_connection_can_send_type, dummy=yes,
 AC_SUBST(DBUS_CFLAGS)
 AC_SUBST(DBUS_LIBS)
 
-PKG_CHECK_MODULES(OPENOBEX, openobex, dummy=yes,
-				AC_MSG_ERROR(libopenobex is required))
-AC_SUBST(OPENOBEX_CFLAGS)
-AC_SUBST(OPENOBEX_LIBS)
-
 PKG_CHECK_MODULES(BLUEZ, bluez, dummy=yes,
 				AC_MSG_ERROR(libbluetooth is required))
 AC_SUBST(BLUEZ_CFLAGS)
Signature · 1 line
1.7.7.3
#5 lore raw

Re: [PATCH obexd 5/6 v2] Port core daemon to gobex

In reply to Luiz Augusto von Dentz

Hi Luiz,

Review

Quoted 1 line · Luiz Augusto von Dentz
(quoted diff) +1 -0
+	char *path = g_strdup_printf("/transfer%u", GPOINTER_TO_UINT(os));

The first four patches have been applied and (like we discussed offline) I'm waiting for an update to this one that doesn't expose our internal memory addresses to external processes like this.

Johan