summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@nokia.com>2007-01-25 20:52:11 +0000
committerJohan Hedberg <johan.hedberg@nokia.com>2007-01-25 20:52:11 +0000
commitb386b24147d4d535112e3af08374986010d2a2f5 (patch)
tree943e685b8d567d6ea0f4323eb042c7852592687e
parentaa6e167ce4b28f0997c53af89194dab39c082119 (diff)
Add extra checks for paths and identifiers of new services
-rw-r--r--hcid/dbus-service.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/hcid/dbus-service.c b/hcid/dbus-service.c
index 14798521..81d0a4d2 100644
--- a/hcid/dbus-service.c
+++ b/hcid/dbus-service.c
@@ -31,6 +31,7 @@
#include <stdlib.h>
#include <dirent.h>
#include <signal.h>
+#include <ctype.h>
#include <sys/types.h>
#include <sys/wait.h>
@@ -605,11 +606,26 @@ static const DBusObjectPathVTable services_vtable = {
.unregister_function = NULL
};
+static int service_cmp_path(struct service *service, const char *path)
+{
+ return strcmp(service->object_path, path);
+}
+
+static int service_cmp_ident(struct service *service, const char *ident)
+{
+ return strcmp(service->ident, ident);
+}
+
static int register_service(struct service *service)
{
char obj_path[PATH_MAX], *suffix;
DBusConnection *conn = get_dbus_connection();
DBusMessage *signal;
+ int i;
+
+ if (g_slist_find_custom(services, service->ident,
+ (GCompareFunc) service_cmp_ident))
+ return -EADDRINUSE;
if (service->external) {
snprintf(obj_path, sizeof(obj_path) - 1,
@@ -623,6 +639,16 @@ static int register_service(struct service *service)
*suffix = '\0';
}
+ /* Make the path valid for D-Bus */
+ for (i = strlen("/org/bluez/"); obj_path[i]; i++) {
+ if (!isalnum(obj_path[i]) || obj_path[i] != '_')
+ obj_path[i] = '_';
+ }
+
+ if (g_slist_find_custom(services, obj_path,
+ (GCompareFunc) service_cmp_path))
+ return -EADDRINUSE;
+
debug("Registering service object: ident=%s, name=%s (%s)",
service->ident, service->name, obj_path);