diff options
author | Claudio Takahasi <claudio.takahasi@openbossa.org> | 2006-11-08 18:22:17 +0000 |
---|---|---|
committer | Claudio Takahasi <claudio.takahasi@openbossa.org> | 2006-11-08 18:22:17 +0000 |
commit | ee8c7e7f6d6ad14e111ca15d5df1a385563cd1b6 (patch) | |
tree | 68296d44e15bb612eb9093b9e9d100750d4f96af | |
parent | 135151c382018639cd3fce5f67bb53eb621b528e (diff) |
Cleanup: checking service register/unregister return value
-rw-r--r-- | hcid/dbus-manager.c | 13 | ||||
-rw-r--r-- | hcid/dbus-service.c | 14 |
2 files changed, 22 insertions, 5 deletions
diff --git a/hcid/dbus-manager.c b/hcid/dbus-manager.c index 30c8874a..53095769 100644 --- a/hcid/dbus-manager.c +++ b/hcid/dbus-manager.c @@ -277,8 +277,12 @@ static DBusHandlerResult register_service(DBusConnection *conn, reg_err = register_service_agent(conn, dbus_message_get_sender(msg), path, name, description); - if (reg_err < 0) + if (reg_err < 0) { + if (reg_err == -EADDRNOTAVAIL) + return error_service_already_exists(conn, msg); + return error_failed(conn, msg, -reg_err); + } /* Report that a new service was registered */ message = dbus_message_new_signal(BASE_PATH, MANAGER_INTERFACE, @@ -337,8 +341,13 @@ static DBusHandlerResult unregister_service(DBusConnection *conn, unreg_err = unregister_service_agent(conn, dbus_message_get_sender(msg), path); - if (unreg_err < 0) + if (unreg_err < 0) { + /* Only the owner can unregister it */ + if (unreg_err == -EPERM) + return error_not_authorized(conn, msg); + return error_failed(conn, msg, -unreg_err); + } /* Report that the service was unregistered */ message = dbus_message_new_signal(BASE_PATH, MANAGER_INTERFACE, diff --git a/hcid/dbus-service.c b/hcid/dbus-service.c index 00693439..34602846 100644 --- a/hcid/dbus-service.c +++ b/hcid/dbus-service.c @@ -727,6 +727,7 @@ int register_service_agent(DBusConnection *conn, const char *sender, const char *path, const char *name, const char *description) { struct service_agent *agent; + struct slist *l; debug("Registering service object: %s", path); @@ -735,14 +736,17 @@ int register_service_agent(DBusConnection *conn, const char *sender, if (!agent) return -ENOMEM; + l = slist_find(services, path, (cmp_func_t) strcmp); + if (l) + return -EADDRNOTAVAIL; + if (!dbus_connection_register_object_path(conn, path, &services_vtable, agent)) { free(agent); - return -1; + return -ENOMEM; } services = slist_append(services, strdup(path)); - /* FIXME: only one listener per sender */ name_listener_add(conn, sender, (name_cb_t) service_agent_exit, conn); return 0; @@ -756,6 +760,10 @@ int unregister_service_agent(DBusConnection *conn, const char *sender, const cha debug("Unregistering service object: %s", path); if (dbus_connection_get_object_path_data(conn, path, (void *) &agent)) { + /* No data assigned to this path or it is not the owner */ + if (!agent || strcmp(sender, agent->id)) + return -EPERM; + if (agent->records) unregister_agent_records(agent->records); @@ -763,7 +771,7 @@ int unregister_service_agent(DBusConnection *conn, const char *sender, const cha } if (!dbus_connection_unregister_object_path(conn, path)) - return -1; + return -ENOMEM; l = slist_find(services, path, (cmp_func_t) strcmp); if (l) { |