summaryrefslogtreecommitdiffstats
path: root/src/sbus
diff options
context:
space:
mode:
authorPavel Březina <pbrezina@redhat.com>2014-12-11 11:01:57 +0100
committerJakub Hrozek <jhrozek@redhat.com>2015-01-23 21:29:27 +0100
commit894f09f146f0c9cda9e0f7dfe1916519d73dde72 (patch)
tree4b43904c6cf451a166c9ffabe28c39697a182a7d /src/sbus
parentd87e960c17d7598781cf032d06ba03a3ecadbfa2 (diff)
downloadsssd-894f09f146f0c9cda9e0f7dfe1916519d73dde72.tar.gz
sssd-894f09f146f0c9cda9e0f7dfe1916519d73dde72.tar.xz
sssd-894f09f146f0c9cda9e0f7dfe1916519d73dde72.zip
sbus: use 'path/*' to represent a D-Bus fallback
Use 'path/*' instead of 'path*' since it better describes what we are actually doing i.e. registering a message handler for a subtree. Although D-Bus fallback will invoke a message handler for both 'path' and 'path/subtree' object paths it does not make usually sence to support the same interfaces for both parent and it children. This commit also renames related functions to better describe what are they doing. Note: the tilda in comments is used to suppress -Wcomment warning Preparation for: https://fedorahosted.org/sssd/ticket/2339 Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
Diffstat (limited to 'src/sbus')
-rw-r--r--src/sbus/sssd_dbus_interface.c92
1 files changed, 56 insertions, 36 deletions
diff --git a/src/sbus/sssd_dbus_interface.c b/src/sbus/sssd_dbus_interface.c
index ab1bdbe9b..acede4d32 100644
--- a/src/sbus/sssd_dbus_interface.c
+++ b/src/sbus/sssd_dbus_interface.c
@@ -28,21 +28,6 @@
DBusObjectPathVTable dbus_object_path_vtable =
{ NULL, sbus_message_handler, NULL, NULL, NULL, NULL };
-static char *sbus_iface_get_reg_path(TALLOC_CTX *mem_ctx,
- const char *path,
- bool fallback)
-{
- char *reg_path;
-
- reg_path = talloc_strdup(mem_ctx, path);
- if (reg_path == NULL) return NULL;
-
- if (fallback) {
- reg_path[strlen(path)-1] = '\0';
- }
- return reg_path;
-}
-
static bool path_in_interface_list(struct sbus_interface_p *list,
const char *path)
{
@@ -74,38 +59,73 @@ void sbus_unreg_object_paths(struct sbus_connection *conn)
}
}
-static bool sbus_fb_path_has_prefix(const char *path, const char *prefix)
+/**
+ * Object paths that represent all objects under the path:
+ * /org/object/path/~* (without tilda)
+ */
+static bool sbus_opath_is_subtree(const char *path)
{
- /* strlen-1 because we don't want to match the trailing '*' */
- if (strncmp(path, prefix, strlen(prefix)-1) == 0) {
- return true;
+ size_t len;
+
+ len = strlen(path);
+
+ if (len < 2) {
+ return false;
}
- return false;
+ return path[len - 2] == '/' && path[len - 1] == '*';
}
-static bool sbus_path_has_fallback(const char *path)
+static bool sbus_opath_match_tree(const char *object_path,
+ const char *tree_path)
{
- char *wildcard;
-
- wildcard = strrchr(path, '*');
- if (wildcard != NULL) {
- /* This path was registered as fallback */
- if (*(wildcard + 1) != '\0') {
- /* Wildcard is only allowed as the last character in the path */
- return false;
- }
- return true;
+ if (object_path == NULL || tree_path == NULL || tree_path[0] == '\0') {
+ return false;
+ };
+
+ /* first check if tree is a base path or a subtree path */
+ if (!sbus_opath_is_subtree(tree_path)) {
+ return strcmp(object_path, tree_path) == 0;
}
- return false;
+ /* Compare without the asterisk, which is the last character.
+ * Slash, that has to be present before the asterisk, will ensure that only
+ * subtree object path matches. */
+ return strncmp(object_path, tree_path, strlen(tree_path) - 1) == 0;
+}
+
+/**
+ * If the path represents a subtree object path, this function will
+ * remove /~* from the end.
+ */
+static char *sbus_opath_get_base_path(TALLOC_CTX *mem_ctx,
+ const char *object_path)
+{
+ char *tree_path;
+ size_t len;
+
+ tree_path = talloc_strdup(mem_ctx, object_path);
+ if (tree_path == NULL) {
+ return NULL;
+ }
+
+ if (!sbus_opath_is_subtree(tree_path)) {
+ return tree_path;
+ }
+
+ /* replace / only if it is not a root path (only slash) */
+ len = strlen(tree_path);
+ tree_path[len - 1] = '\0';
+ tree_path[len - 2] = (len - 2 != 0) ? '\0' : '/';
+
+ return tree_path;
}
bool sbus_iface_handles_path(struct sbus_interface_p *intf_p,
const char *path)
{
- if (sbus_path_has_fallback(intf_p->intf->path)) {
- return sbus_fb_path_has_prefix(path, intf_p->intf->path);
+ if (sbus_opath_is_subtree(intf_p->intf->path)) {
+ return sbus_opath_match_tree(path, intf_p->intf->path);
}
return strcmp(path, intf_p->intf->path) == 0;
@@ -158,7 +178,7 @@ int sbus_conn_register_iface(struct sbus_connection *conn,
}
path = intf->path;
- fallback = sbus_path_has_fallback(path);
+ fallback = sbus_opath_is_subtree(path);
if (path_in_interface_list(conn->intf_list, path)) {
DEBUG(SSSDBG_FATAL_FAILURE,
@@ -172,7 +192,7 @@ int sbus_conn_register_iface(struct sbus_connection *conn,
}
intf_p->conn = conn;
intf_p->intf = intf;
- intf_p->reg_path = sbus_iface_get_reg_path(intf_p, path, fallback);
+ intf_p->reg_path = sbus_opath_get_base_path(intf_p, path);
if (intf_p->reg_path == NULL) {
return ENOMEM;
}