chiark / gitweb /
bus-proxy: properly check for bus name prefixes when enforcing policy
authorLennart Poettering <lennart@poettering.net>
Fri, 14 Nov 2014 19:06:01 +0000 (20:06 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 14 Nov 2014 19:06:01 +0000 (20:06 +0100)
src/bus-proxyd/bus-policy.c
src/libsystemd/sd-bus/bus-internal.c
src/libsystemd/sd-bus/bus-internal.h

index 625f5dd..cb0726a 100644 (file)
@@ -651,7 +651,7 @@ static int check_policy_item(PolicyItem *i, const struct policy_check_filter *fi
         case POLICY_ITEM_OWN_PREFIX:
                 assert(filter->name);
 
-                if (streq(i->name, "*") || startswith(i->name, filter->name))
+                if (streq(i->name, "*") || service_name_startswith(i->name, filter->name))
                         return is_permissive(i);
                 break;
 
index 0bea8ca..91b288c 100644 (file)
@@ -166,6 +166,26 @@ bool service_name_is_valid(const char *p) {
         return true;
 }
 
+char* service_name_startswith(const char *a, const char *b) {
+        const char *p;
+
+        if (!service_name_is_valid(a) ||
+            !service_name_is_valid(b))
+                return NULL;
+
+        p = startswith(a, b);
+        if (!p)
+                return NULL;
+
+        if (*p == 0)
+                return (char*) p;
+
+        if (*p == '.')
+                return (char*) p + 1;
+
+        return NULL;
+}
+
 bool member_name_is_valid(const char *p) {
         const char *q;
 
index 0738148..f6b0211 100644 (file)
@@ -340,6 +340,7 @@ struct sd_bus {
 
 bool interface_name_is_valid(const char *p) _pure_;
 bool service_name_is_valid(const char *p) _pure_;
+char* service_name_startswith(const char *a, const char *b);
 bool member_name_is_valid(const char *p) _pure_;
 bool object_path_is_valid(const char *p) _pure_;
 char *object_path_startswith(const char *a, const char *b) _pure_;