chiark / gitweb /
bus: introduce new SD_BUS_VTABLE_HIDDEN flag for vtable members
[elogind.git] / src / libsystemd-bus / bus-objects.c
index 5867907a624a393dd7274f28e1291dbf57812778..8ffda2f95db0f6ecef8be40e70761d14d2e2aeb6 100644 (file)
@@ -19,6 +19,8 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
+#include <sys/capability.h>
+
 #include "strv.h"
 #include "set.h"
 #include "bus-internal.h"
 #include "strv.h"
 #include "set.h"
 #include "bus-internal.h"
@@ -33,7 +35,8 @@ static int node_vtable_get_userdata(
                 sd_bus *bus,
                 const char *path,
                 struct node_vtable *c,
                 sd_bus *bus,
                 const char *path,
                 struct node_vtable *c,
-                void **userdata) {
+                void **userdata,
+                sd_bus_error *error) {
 
         void *u;
         int r;
 
         void *u;
         int r;
@@ -44,8 +47,12 @@ static int node_vtable_get_userdata(
 
         u = c->userdata;
         if (c->find) {
 
         u = c->userdata;
         if (c->find) {
-                r = c->find(bus, path, c->interface, &u, u);
-                if (r <= 0)
+                r = c->find(bus, path, c->interface, u, &u, error);
+                if (r < 0)
+                        return r;
+                if (sd_bus_error_is_set(error))
+                        return sd_bus_error_get_errno(error);
+                if (r == 0)
                         return r;
         }
 
                         return r;
         }
 
@@ -65,7 +72,8 @@ static int vtable_property_get_userdata(
                 sd_bus *bus,
                 const char *path,
                 struct vtable_member *p,
                 sd_bus *bus,
                 const char *path,
                 struct vtable_member *p,
-                void **userdata) {
+                void **userdata,
+                sd_bus_error *error) {
 
         void *u;
         int r;
 
         void *u;
         int r;
@@ -75,7 +83,7 @@ static int vtable_property_get_userdata(
         assert(p);
         assert(userdata);
 
         assert(p);
         assert(userdata);
 
-        r = node_vtable_get_userdata(bus, path, p->parent, &u);
+        r = node_vtable_get_userdata(bus, path, p->parent, &u, error);
         if (r <= 0)
                 return r;
         if (bus->nodes_modified)
         if (r <= 0)
                 return r;
         if (bus->nodes_modified)
@@ -89,7 +97,8 @@ static int add_enumerated_to_set(
                 sd_bus *bus,
                 const char *prefix,
                 struct node_enumerator *first,
                 sd_bus *bus,
                 const char *prefix,
                 struct node_enumerator *first,
-                Set *s) {
+                Set *s,
+                sd_bus_error *error) {
 
         struct node_enumerator *c;
         int r;
 
         struct node_enumerator *c;
         int r;
@@ -104,9 +113,11 @@ static int add_enumerated_to_set(
                 if (bus->nodes_modified)
                         return 0;
 
                 if (bus->nodes_modified)
                         return 0;
 
-                r = c->callback(bus, prefix, &children, c->userdata);
+                r = c->callback(bus, prefix, c->userdata, &children, error);
                 if (r < 0)
                         return r;
                 if (r < 0)
                         return r;
+                if (sd_bus_error_is_set(error))
+                        return sd_bus_error_get_errno(error);
 
                 STRV_FOREACH(k, children) {
                         if (r < 0) {
 
                 STRV_FOREACH(k, children) {
                         if (r < 0) {
@@ -114,13 +125,20 @@ static int add_enumerated_to_set(
                                 continue;
                         }
 
                                 continue;
                         }
 
-                        if (!object_path_is_valid(*k) && object_path_startswith(*k, prefix)) {
+                        if (!object_path_is_valid(*k)){
                                 free(*k);
                                 r = -EINVAL;
                                 continue;
                         }
 
                                 free(*k);
                                 r = -EINVAL;
                                 continue;
                         }
 
+                        if (!object_path_startswith(*k, prefix)) {
+                                free(*k);
+                                continue;
+                        }
+
                         r = set_consume(s, *k);
                         r = set_consume(s, *k);
+                        if (r == -EEXIST)
+                                r = 0;
                 }
 
                 free(children);
                 }
 
                 free(children);
@@ -135,7 +153,8 @@ static int add_subtree_to_set(
                 sd_bus *bus,
                 const char *prefix,
                 struct node *n,
                 sd_bus *bus,
                 const char *prefix,
                 struct node *n,
-                Set *s) {
+                Set *s,
+                sd_bus_error *error) {
 
         struct node *i;
         int r;
 
         struct node *i;
         int r;
@@ -145,7 +164,7 @@ static int add_subtree_to_set(
         assert(n);
         assert(s);
 
         assert(n);
         assert(s);
 
-        r = add_enumerated_to_set(bus, prefix, n->enumerators, s);
+        r = add_enumerated_to_set(bus, prefix, n->enumerators, s, error);
         if (r < 0)
                 return r;
         if (bus->nodes_modified)
         if (r < 0)
                 return r;
         if (bus->nodes_modified)
@@ -154,6 +173,9 @@ static int add_subtree_to_set(
         LIST_FOREACH(siblings, i, n->child) {
                 char *t;
 
         LIST_FOREACH(siblings, i, n->child) {
                 char *t;
 
+                if (!object_path_startswith(i->path, prefix))
+                        continue;
+
                 t = strdup(i->path);
                 if (!t)
                         return -ENOMEM;
                 t = strdup(i->path);
                 if (!t)
                         return -ENOMEM;
@@ -162,7 +184,7 @@ static int add_subtree_to_set(
                 if (r < 0 && r != -EEXIST)
                         return r;
 
                 if (r < 0 && r != -EEXIST)
                         return r;
 
-                r = add_subtree_to_set(bus, prefix, i, s);
+                r = add_subtree_to_set(bus, prefix, i, s, error);
                 if (r < 0)
                         return r;
                 if (bus->nodes_modified)
                 if (r < 0)
                         return r;
                 if (bus->nodes_modified)
@@ -176,7 +198,8 @@ static int get_child_nodes(
                 sd_bus *bus,
                 const char *prefix,
                 struct node *n,
                 sd_bus *bus,
                 const char *prefix,
                 struct node *n,
-                Set **_s) {
+                Set **_s,
+                sd_bus_error *error) {
 
         Set *s = NULL;
         int r;
 
         Set *s = NULL;
         int r;
@@ -190,7 +213,7 @@ static int get_child_nodes(
         if (!s)
                 return -ENOMEM;
 
         if (!s)
                 return -ENOMEM;
 
-        r = add_subtree_to_set(bus, prefix, n, s);
+        r = add_subtree_to_set(bus, prefix, n, s, error);
         if (r < 0) {
                 set_free_free(s);
                 return r;
         if (r < 0) {
                 set_free_free(s);
                 return r;
@@ -215,6 +238,8 @@ static int node_callbacks_run(
         assert(found_object);
 
         LIST_FOREACH(callbacks, c, first) {
         assert(found_object);
 
         LIST_FOREACH(callbacks, c, first) {
+                _cleanup_bus_error_free_ sd_bus_error error_buffer = SD_BUS_ERROR_NULL;
+
                 if (bus->nodes_modified)
                         return 0;
 
                 if (bus->nodes_modified)
                         return 0;
 
@@ -232,7 +257,8 @@ static int node_callbacks_run(
                 if (r < 0)
                         return r;
 
                 if (r < 0)
                         return r;
 
-                r = c->callback(bus, m, c->userdata);
+                r = c->callback(bus, m, c->userdata, &error_buffer);
+                r = bus_maybe_reply_error(m, r, &error_buffer);
                 if (r != 0)
                         return r;
         }
                 if (r != 0)
                         return r;
         }
@@ -240,6 +266,64 @@ static int node_callbacks_run(
         return 0;
 }
 
         return 0;
 }
 
+#define CAPABILITY_SHIFT(x) (((x) >> __builtin_ctzll(_SD_BUS_VTABLE_CAPABILITY_MASK)) & 0xFFFF)
+
+static int check_access(sd_bus *bus, sd_bus_message *m, struct vtable_member *c, sd_bus_error *error) {
+        _cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL;
+        uint64_t cap;
+        uid_t uid;
+        int r;
+
+        assert(bus);
+        assert(m);
+        assert(c);
+
+        /* If the entire bus is trusted let's grant access */
+        if (bus->trusted)
+                return 0;
+
+        /* If the member is marked UNPRIVILEGED let's grant access */
+        if (c->vtable->flags & SD_BUS_VTABLE_UNPRIVILEGED)
+                return 0;
+
+        /* If we are not connected to kdbus we cannot retrieve the
+         * effective capability set without race. Since we need this
+         * for a security decision we cannot use racy data, hence
+         * don't request it. */
+        if (bus->is_kernel)
+                r = sd_bus_query_sender_creds(m, SD_BUS_CREDS_UID|SD_BUS_CREDS_EFFECTIVE_CAPS, &creds);
+        else
+                r = sd_bus_query_sender_creds(m, SD_BUS_CREDS_UID, &creds);
+        if (r < 0)
+                return r;
+
+        /* Check have the caller has the requested capability
+         * set. Note that the flags value contains the capability
+         * number plus one, which we need to subtract here. We do this
+         * so that we have 0 as special value for "default
+         * capability". */
+        cap = CAPABILITY_SHIFT(c->vtable->flags);
+        if (cap == 0)
+                cap = CAPABILITY_SHIFT(c->parent->vtable[0].flags);
+        if (cap == 0)
+                cap = CAP_SYS_ADMIN;
+        else
+                cap --;
+
+        r = sd_bus_creds_has_effective_cap(creds, cap);
+        if (r > 0)
+                return 1;
+
+        /* Caller has same UID as us, then let's grant access */
+        r = sd_bus_creds_get_uid(creds, &uid);
+        if (r >= 0) {
+                if (uid == getuid())
+                        return 1;
+        }
+
+        return sd_bus_error_setf(error, SD_BUS_ERROR_ACCESS_DENIED, "Access to %s.%s() not permitted.", c->interface, c->member);
+}
+
 static int method_callbacks_run(
                 sd_bus *bus,
                 sd_bus_message *m,
 static int method_callbacks_run(
                 sd_bus *bus,
                 sd_bus_message *m,
@@ -247,6 +331,7 @@ static int method_callbacks_run(
                 bool require_fallback,
                 bool *found_object) {
 
                 bool require_fallback,
                 bool *found_object) {
 
+        _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
         const char *signature;
         void *u;
         int r;
         const char *signature;
         void *u;
         int r;
@@ -259,9 +344,13 @@ static int method_callbacks_run(
         if (require_fallback && !c->parent->is_fallback)
                 return 0;
 
         if (require_fallback && !c->parent->is_fallback)
                 return 0;
 
-        r = node_vtable_get_userdata(bus, m->path, c->parent, &u);
+        r = check_access(bus, m, c, &error);
+        if (r < 0)
+                return bus_maybe_reply_error(m, r, &error);
+
+        r = node_vtable_get_userdata(bus, m->path, c->parent, &u, &error);
         if (r <= 0)
         if (r <= 0)
-                return r;
+                return bus_maybe_reply_error(m, r, &error);
         if (bus->nodes_modified)
                 return 0;
 
         if (bus->nodes_modified)
                 return 0;
 
@@ -280,22 +369,25 @@ static int method_callbacks_run(
         if (!signature)
                 return -EINVAL;
 
         if (!signature)
                 return -EINVAL;
 
-        if (!streq(strempty(c->vtable->x.method.signature), signature)) {
-                r = sd_bus_reply_method_errorf(bus, m,
-                                               SD_BUS_ERROR_INVALID_ARGS,
-                                               "Invalid arguments '%s' to call %s:%s, expecting '%s'.",
-                                               signature, c->interface, c->member, strempty(c->vtable->x.method.signature));
-                if (r < 0)
-                        return r;
-
-                return 1;
+        if (!streq(strempty(c->vtable->x.method.signature), signature))
+                return sd_bus_reply_method_errorf(
+                                m,
+                                SD_BUS_ERROR_INVALID_ARGS,
+                                "Invalid arguments '%s' to call %s.%s(), expecting '%s'.",
+                                signature, c->interface, c->member, strempty(c->vtable->x.method.signature));
+
+        /* Keep track what the signature of the reply to this message
+         * should be, so that this can be enforced when sealing the
+         * reply. */
+        m->enforced_reply_signature = strempty(c->vtable->x.method.result);
+
+        if (c->vtable->x.method.handler) {
+                r = c->vtable->x.method.handler(bus, m, u, &error);
+                return bus_maybe_reply_error(m, r, &error);
         }
 
         }
 
-        if (c->vtable->x.method.handler)
-                return c->vtable->x.method.handler(bus, m, u);
-
         /* If the method callback is NULL, make this a successful NOP */
         /* If the method callback is NULL, make this a successful NOP */
-        r = sd_bus_reply_method_return(bus, m, NULL);
+        r = sd_bus_reply_method_return(m, NULL);
         if (r < 0)
                 return r;
 
         if (r < 0)
                 return r;
 
@@ -308,25 +400,34 @@ static int invoke_property_get(
                 const char *path,
                 const char *interface,
                 const char *property,
                 const char *path,
                 const char *interface,
                 const char *property,
-                sd_bus_message *m,
-                sd_bus_error *error,
-                void *userdata) {
+                sd_bus_message *reply,
+                void *userdata,
+                sd_bus_error *error) {
 
 
-        int r;
         const void *p;
         const void *p;
+        int r;
 
         assert(bus);
         assert(v);
         assert(path);
         assert(interface);
         assert(property);
 
         assert(bus);
         assert(v);
         assert(path);
         assert(interface);
         assert(property);
-        assert(m);
+        assert(reply);
 
 
-        if (v->x.property.get)
-                return v->x.property.get(bus, path, interface, property, m, error, userdata);
+        if (v->x.property.get) {
+                r = v->x.property.get(bus, path, interface, property, reply, userdata, error);
+                if (r < 0)
+                        return r;
+                if (sd_bus_error_is_set(error))
+                        return sd_bus_error_get_errno(error);
+                return r;
+        }
 
         /* Automatic handling if no callback is defined. */
 
 
         /* Automatic handling if no callback is defined. */
 
+        if (streq(v->x.property.signature, "as"))
+                return sd_bus_message_append_strv(reply, *(char***) userdata);
+
         assert(signature_is_single(v->x.property.signature, false));
         assert(bus_type_is_basic(v->x.property.signature[0]));
 
         assert(signature_is_single(v->x.property.signature, false));
         assert(bus_type_is_basic(v->x.property.signature[0]));
 
@@ -347,11 +448,7 @@ static int invoke_property_get(
                 break;
         }
 
                 break;
         }
 
-        r = sd_bus_message_append_basic(m, v->x.property.signature[0], p);
-        if (r < 0)
-                return r;
-
-        return 1;
+        return sd_bus_message_append_basic(reply, v->x.property.signature[0], p);
 }
 
 static int invoke_property_set(
 }
 
 static int invoke_property_set(
@@ -361,8 +458,8 @@ static int invoke_property_set(
                 const char *interface,
                 const char *property,
                 sd_bus_message *value,
                 const char *interface,
                 const char *property,
                 sd_bus_message *value,
-                sd_bus_error *error,
-                void *userdata) {
+                void *userdata,
+                sd_bus_error *error) {
 
         int r;
 
 
         int r;
 
@@ -373,8 +470,14 @@ static int invoke_property_set(
         assert(property);
         assert(value);
 
         assert(property);
         assert(value);
 
-        if (v->x.property.set)
-                return v->x.property.set(bus, path, interface, property, value, error, userdata);
+        if (v->x.property.set) {
+                r = v->x.property.set(bus, path, interface, property, value, userdata, error);
+                if (r < 0)
+                        return r;
+                if (sd_bus_error_is_set(error))
+                        return sd_bus_error_get_errno(error);
+                return r;
+        }
 
         /*  Automatic handling if no callback is defined. */
 
 
         /*  Automatic handling if no callback is defined. */
 
@@ -422,8 +525,8 @@ static int property_get_set_callbacks_run(
                 bool is_get,
                 bool *found_object) {
 
                 bool is_get,
                 bool *found_object) {
 
-        _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
         _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
         _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
+        _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
         void *u;
         int r;
 
         void *u;
         int r;
 
@@ -435,15 +538,15 @@ static int property_get_set_callbacks_run(
         if (require_fallback && !c->parent->is_fallback)
                 return 0;
 
         if (require_fallback && !c->parent->is_fallback)
                 return 0;
 
-        r = vtable_property_get_userdata(bus, m->path, c, &u);
+        r = vtable_property_get_userdata(bus, m->path, c, &u, &error);
         if (r <= 0)
         if (r <= 0)
-                return r;
+                return bus_maybe_reply_error(m, r, &error);
         if (bus->nodes_modified)
                 return 0;
 
         *found_object = true;
 
         if (bus->nodes_modified)
                 return 0;
 
         *found_object = true;
 
-        r = sd_bus_message_new_method_return(bus, m, &reply);
+        r = sd_bus_message_new_method_return(m, &reply);
         if (r < 0)
                 return r;
 
         if (r < 0)
                 return r;
 
@@ -459,17 +562,14 @@ static int property_get_set_callbacks_run(
                 if (r < 0)
                         return r;
 
                 if (r < 0)
                         return r;
 
-                r = invoke_property_get(bus, c->vtable, m->path, c->interface, c->member, reply, &error, u);
-                if (r < 0)
-                        return r;
-
-                if (sd_bus_error_is_set(&error)) {
-                        r = sd_bus_reply_method_error(bus, m, &error);
-                        if (r < 0)
-                                return r;
+                /* Note that we do not do an access check here. Read
+                 * access to properties is always unrestricted, since
+                 * PropertiesChanged signals broadcast contents
+                 * anyway. */
 
 
-                        return 1;
-                }
+                r = invoke_property_get(bus, c->vtable, m->path, c->interface, c->member, reply, u, &error);
+                if (r < 0)
+                        return bus_maybe_reply_error(m, r, &error);
 
                 if (bus->nodes_modified)
                         return 0;
 
                 if (bus->nodes_modified)
                         return 0;
@@ -480,33 +580,27 @@ static int property_get_set_callbacks_run(
 
         } else {
                 if (c->vtable->type != _SD_BUS_VTABLE_WRITABLE_PROPERTY)
 
         } else {
                 if (c->vtable->type != _SD_BUS_VTABLE_WRITABLE_PROPERTY)
-                        sd_bus_error_setf(&error, SD_BUS_ERROR_PROPERTY_READ_ONLY, "Property '%s' is not writable.", c->member);
-                else  {
-                        /* Avoid that we call the set routine more
-                         * than once if the processing of this message
-                         * got restarted because the node tree
-                         * changed. */
-                        if (c->last_iteration == bus->iteration_counter)
-                                return 0;
+                        return sd_bus_reply_method_errorf(m, SD_BUS_ERROR_PROPERTY_READ_ONLY, "Property '%s' is not writable.", c->member);
 
 
-                        c->last_iteration = bus->iteration_counter;
+                /* Avoid that we call the set routine more than once
+                 * if the processing of this message got restarted
+                 * because the node tree changed. */
+                if (c->last_iteration == bus->iteration_counter)
+                        return 0;
 
 
-                        r = sd_bus_message_enter_container(m, 'v', c->vtable->x.property.signature);
-                        if (r < 0)
-                                return r;
+                c->last_iteration = bus->iteration_counter;
 
 
-                        r = invoke_property_set(bus, c->vtable, m->path, c->interface, c->member, m, &error, u);
-                        if (r < 0)
-                                return r;
-                }
+                r = sd_bus_message_enter_container(m, 'v', c->vtable->x.property.signature);
+                if (r < 0)
+                        return r;
 
 
-                if (sd_bus_error_is_set(&error)) {
-                        r = sd_bus_reply_method_error(bus, m, &error);
-                        if (r < 0)
-                                return r;
+                r = check_access(bus, m, c, &error);
+                if (r < 0)
+                        return bus_maybe_reply_error(m, r, &error);
 
 
-                        return 1;
-                }
+                r = invoke_property_set(bus, c->vtable, m->path, c->interface, c->member, m, u, &error);
+                if (r < 0)
+                        return bus_maybe_reply_error(m, r, &error);
 
                 if (bus->nodes_modified)
                         return 0;
 
                 if (bus->nodes_modified)
                         return 0;
@@ -539,10 +633,16 @@ static int vtable_append_all_properties(
         assert(path);
         assert(c);
 
         assert(path);
         assert(c);
 
+        if (c->vtable[0].flags & SD_BUS_VTABLE_HIDDEN)
+                return 1;
+
         for (v = c->vtable+1; v->type != _SD_BUS_VTABLE_END; v++) {
                 if (v->type != _SD_BUS_VTABLE_PROPERTY && v->type != _SD_BUS_VTABLE_WRITABLE_PROPERTY)
                         continue;
 
         for (v = c->vtable+1; v->type != _SD_BUS_VTABLE_END; v++) {
                 if (v->type != _SD_BUS_VTABLE_PROPERTY && v->type != _SD_BUS_VTABLE_WRITABLE_PROPERTY)
                         continue;
 
+                if (v->flags & SD_BUS_VTABLE_HIDDEN)
+                        continue;
+
                 r = sd_bus_message_open_container(reply, 'e', "sv");
                 if (r < 0)
                         return r;
                 r = sd_bus_message_open_container(reply, 'e', "sv");
                 if (r < 0)
                         return r;
@@ -555,11 +655,9 @@ static int vtable_append_all_properties(
                 if (r < 0)
                         return r;
 
                 if (r < 0)
                         return r;
 
-                r = invoke_property_get(bus, v, path, c->interface, v->x.property.member, reply, error, vtable_property_convert_userdata(v, userdata));
+                r = invoke_property_get(bus, v, path, c->interface, v->x.property.member, reply, vtable_property_convert_userdata(v, userdata), error);
                 if (r < 0)
                         return r;
                 if (r < 0)
                         return r;
-                if (sd_bus_error_is_set(error))
-                        return 0;
                 if (bus->nodes_modified)
                         return 0;
 
                 if (bus->nodes_modified)
                         return 0;
 
@@ -592,7 +690,7 @@ static int property_get_all_callbacks_run(
         assert(m);
         assert(found_object);
 
         assert(m);
         assert(found_object);
 
-        r = sd_bus_message_new_method_return(bus, m, &reply);
+        r = sd_bus_message_new_method_return(m, &reply);
         if (r < 0)
                 return r;
 
         if (r < 0)
                 return r;
 
@@ -600,7 +698,7 @@ static int property_get_all_callbacks_run(
         if (r < 0)
                 return r;
 
         if (r < 0)
                 return r;
 
-        found_interface =
+        found_interface = !iface ||
                 streq(iface, "org.freedesktop.DBus.Properties") ||
                 streq(iface, "org.freedesktop.DBus.Peer") ||
                 streq(iface, "org.freedesktop.DBus.Introspectable");
                 streq(iface, "org.freedesktop.DBus.Properties") ||
                 streq(iface, "org.freedesktop.DBus.Peer") ||
                 streq(iface, "org.freedesktop.DBus.Introspectable");
@@ -612,9 +710,9 @@ static int property_get_all_callbacks_run(
                 if (require_fallback && !c->is_fallback)
                         continue;
 
                 if (require_fallback && !c->is_fallback)
                         continue;
 
-                r = node_vtable_get_userdata(bus, m->path, c, &u);
+                r = node_vtable_get_userdata(bus, m->path, c, &u, &error);
                 if (r < 0)
                 if (r < 0)
-                        return r;
+                        return bus_maybe_reply_error(m, r, &error);
                 if (bus->nodes_modified)
                         return 0;
                 if (r == 0)
                 if (bus->nodes_modified)
                         return 0;
                 if (r == 0)
@@ -628,22 +726,14 @@ static int property_get_all_callbacks_run(
 
                 r = vtable_append_all_properties(bus, reply, m->path, c, u, &error);
                 if (r < 0)
 
                 r = vtable_append_all_properties(bus, reply, m->path, c, u, &error);
                 if (r < 0)
-                        return r;
-
-                if (sd_bus_error_is_set(&error)) {
-                        r = sd_bus_reply_method_error(bus, m, &error);
-                        if (r < 0)
-                                return r;
-
-                        return 1;
-                }
+                        return bus_maybe_reply_error(m, r, &error);
                 if (bus->nodes_modified)
                         return 0;
         }
 
         if (!found_interface) {
                 r = sd_bus_reply_method_errorf(
                 if (bus->nodes_modified)
                         return 0;
         }
 
         if (!found_interface) {
                 r = sd_bus_reply_method_errorf(
-                                bus, m,
+                                m,
                                 SD_BUS_ERROR_UNKNOWN_INTERFACE,
                                 "Unknown interface '%s'.", iface);
                 if (r < 0)
                                 SD_BUS_ERROR_UNKNOWN_INTERFACE,
                                 "Unknown interface '%s'.", iface);
                 if (r < 0)
@@ -700,11 +790,12 @@ static bool bus_node_exists(
         }
 
         LIST_FOREACH(vtables, c, n->vtables) {
         }
 
         LIST_FOREACH(vtables, c, n->vtables) {
+                _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
 
                 if (require_fallback && !c->is_fallback)
                         continue;
 
 
                 if (require_fallback && !c->is_fallback)
                         continue;
 
-                if (node_vtable_get_userdata(bus, path, c, NULL) > 0)
+                if (node_vtable_get_userdata(bus, path, c, NULL, &error) > 0)
                         return true;
                 if (bus->nodes_modified)
                         return false;
                         return true;
                 if (bus->nodes_modified)
                         return false;
@@ -720,8 +811,10 @@ static int process_introspect(
                 bool require_fallback,
                 bool *found_object) {
 
                 bool require_fallback,
                 bool *found_object) {
 
+        _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
         _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
         _cleanup_set_free_free_ Set *s = NULL;
         _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
         _cleanup_set_free_free_ Set *s = NULL;
+        const char *previous_interface = NULL;
         struct introspect intro;
         struct node_vtable *c;
         bool empty;
         struct introspect intro;
         struct node_vtable *c;
         bool empty;
@@ -732,9 +825,9 @@ static int process_introspect(
         assert(n);
         assert(found_object);
 
         assert(n);
         assert(found_object);
 
-        r = get_child_nodes(bus, m->path, n, &s);
+        r = get_child_nodes(bus, m->path, n, &s, &error);
         if (r < 0)
         if (r < 0)
-                return r;
+                return bus_maybe_reply_error(m, r, &error);
         if (bus->nodes_modified)
                 return 0;
 
         if (bus->nodes_modified)
                 return 0;
 
@@ -752,21 +845,41 @@ static int process_introspect(
                 if (require_fallback && !c->is_fallback)
                         continue;
 
                 if (require_fallback && !c->is_fallback)
                         continue;
 
-                r = node_vtable_get_userdata(bus, m->path, c, NULL);
-                if (r < 0)
-                        return r;
-                if (bus->nodes_modified)
-                        return 0;
+                r = node_vtable_get_userdata(bus, m->path, c, NULL, &error);
+                if (r < 0) {
+                        r = bus_maybe_reply_error(m, r, &error);
+                        goto finish;
+                }
+                if (bus->nodes_modified) {
+                        r = 0;
+                        goto finish;
+                }
                 if (r == 0)
                         continue;
 
                 empty = false;
 
                 if (r == 0)
                         continue;
 
                 empty = false;
 
-                r = introspect_write_interface(&intro, c->interface, c->vtable);
+                if (c->vtable[0].flags & SD_BUS_VTABLE_HIDDEN)
+                        continue;
+
+                if (!streq_ptr(previous_interface, c->interface)) {
+
+                        if (previous_interface)
+                                fputs(" </interface>\n", intro.f);
+
+                        fprintf(intro.f, " <interface name=\"%s\">\n", c->interface);
+                }
+
+                r = introspect_write_interface(&intro, c->vtable);
                 if (r < 0)
                         goto finish;
                 if (r < 0)
                         goto finish;
+
+                previous_interface = c->interface;
         }
 
         }
 
+        if (previous_interface)
+                fputs(" </interface>\n", intro.f);
+
         if (empty) {
                 /* Nothing?, let's see if we exist at all, and if not
                  * refuse to do anything */
         if (empty) {
                 /* Nothing?, let's see if we exist at all, and if not
                  * refuse to do anything */
@@ -800,51 +913,6 @@ finish:
         return r;
 }
 
         return r;
 }
 
-static int object_manager_serialize_vtable(
-                sd_bus *bus,
-                sd_bus_message *reply,
-                const char *path,
-                struct node_vtable *c,
-                sd_bus_error *error,
-                void *userdata) {
-
-        int r;
-
-        assert(bus);
-        assert(reply);
-        assert(path);
-        assert(c);
-        assert(error);
-
-        r = sd_bus_message_open_container(reply, 'e', "sa{sv}");
-        if (r < 0)
-                return r;
-
-        r = sd_bus_message_append(reply, "s", c->interface);
-        if (r < 0)
-                return r;
-
-        r = sd_bus_message_open_container(reply, 'a', "{sv}");
-        if (r < 0)
-                return r;
-
-        r = vtable_append_all_properties(bus, reply, path, c, userdata, error);
-        if (r < 0)
-                return r;
-        if (bus->nodes_modified)
-                return 0;
-
-        r = sd_bus_message_close_container(reply);
-        if (r < 0)
-                return r;
-
-        r = sd_bus_message_close_container(reply);
-        if (r < 0)
-                return r;
-
-        return 0;
-}
-
 static int object_manager_serialize_path(
                 sd_bus *bus,
                 sd_bus_message *reply,
 static int object_manager_serialize_path(
                 sd_bus *bus,
                 sd_bus_message *reply,
@@ -853,9 +921,10 @@ static int object_manager_serialize_path(
                 bool require_fallback,
                 sd_bus_error *error) {
 
                 bool require_fallback,
                 sd_bus_error *error) {
 
+        const char *previous_interface = NULL;
+        bool found_something = false;
         struct node_vtable *i;
         struct node *n;
         struct node_vtable *i;
         struct node *n;
-        bool found_something = false;
         int r;
 
         assert(bus);
         int r;
 
         assert(bus);
@@ -874,7 +943,7 @@ static int object_manager_serialize_path(
                 if (require_fallback && !i->is_fallback)
                         continue;
 
                 if (require_fallback && !i->is_fallback)
                         continue;
 
-                r = node_vtable_get_userdata(bus, path, i, &u);
+                r = node_vtable_get_userdata(bus, path, i, &u, error);
                 if (r < 0)
                         return r;
                 if (bus->nodes_modified)
                 if (r < 0)
                         return r;
                 if (bus->nodes_modified)
@@ -883,6 +952,9 @@ static int object_manager_serialize_path(
                         continue;
 
                 if (!found_something) {
                         continue;
 
                 if (!found_something) {
+
+                        /* Open the object part */
+
                         r = sd_bus_message_open_container(reply, 'e', "oa{sa{sv}}");
                         if (r < 0)
                                 return r;
                         r = sd_bus_message_open_container(reply, 'e', "oa{sa{sv}}");
                         if (r < 0)
                                 return r;
@@ -898,13 +970,52 @@ static int object_manager_serialize_path(
                         found_something = true;
                 }
 
                         found_something = true;
                 }
 
-                r = object_manager_serialize_vtable(bus, reply, path, i, error, u);
+                if (!streq_ptr(previous_interface, i->interface)) {
+
+                        /* Maybe close the previous interface part */
+
+                        if (previous_interface) {
+                                r = sd_bus_message_close_container(reply);
+                                if (r < 0)
+                                        return r;
+
+                                r = sd_bus_message_close_container(reply);
+                                if (r < 0)
+                                        return r;
+                        }
+
+                        /* Open the new interface part */
+
+                        r = sd_bus_message_open_container(reply, 'e', "sa{sv}");
+                        if (r < 0)
+                                return r;
+
+                        r = sd_bus_message_append(reply, "s", i->interface);
+                        if (r < 0)
+                                return r;
+
+                        r = sd_bus_message_open_container(reply, 'a', "{sv}");
+                        if (r < 0)
+                                return r;
+                }
+
+                r = vtable_append_all_properties(bus, reply, path, i, u, error);
                 if (r < 0)
                         return r;
                 if (r < 0)
                         return r;
-                if (sd_bus_error_is_set(error))
-                        return 0;
                 if (bus->nodes_modified)
                         return 0;
                 if (bus->nodes_modified)
                         return 0;
+
+                previous_interface = i->interface;
+        }
+
+        if (previous_interface) {
+                r = sd_bus_message_close_container(reply);
+                if (r < 0)
+                        return r;
+
+                r = sd_bus_message_close_container(reply);
+                if (r < 0)
+                        return r;
         }
 
         if (found_something) {
         }
 
         if (found_something) {
@@ -938,8 +1049,6 @@ static int object_manager_serialize_path_and_fallbacks(
         r = object_manager_serialize_path(bus, reply, path, path, false, error);
         if (r < 0)
                 return r;
         r = object_manager_serialize_path(bus, reply, path, path, false, error);
         if (r < 0)
                 return r;
-        if (sd_bus_error_is_set(error))
-                return 0;
         if (bus->nodes_modified)
                 return 0;
 
         if (bus->nodes_modified)
                 return 0;
 
@@ -949,8 +1058,6 @@ static int object_manager_serialize_path_and_fallbacks(
                 r = object_manager_serialize_path(bus, reply, prefix, path, true, error);
                 if (r < 0)
                         return r;
                 r = object_manager_serialize_path(bus, reply, prefix, path, true, error);
                 if (r < 0)
                         return r;
-                if (sd_bus_error_is_set(error))
-                        return 0;
                 if (bus->nodes_modified)
                         return 0;
         }
                 if (bus->nodes_modified)
                         return 0;
         }
@@ -965,6 +1072,7 @@ static int process_get_managed_objects(
                 bool require_fallback,
                 bool *found_object) {
 
                 bool require_fallback,
                 bool *found_object) {
 
+        _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
         _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
         _cleanup_set_free_free_ Set *s = NULL;
         bool empty;
         _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
         _cleanup_set_free_free_ Set *s = NULL;
         bool empty;
@@ -978,13 +1086,13 @@ static int process_get_managed_objects(
         if (!bus_node_with_object_manager(bus, n))
                 return 0;
 
         if (!bus_node_with_object_manager(bus, n))
                 return 0;
 
-        r = get_child_nodes(bus, m->path, n, &s);
+        r = get_child_nodes(bus, m->path, n, &s, &error);
         if (r < 0)
                 return r;
         if (bus->nodes_modified)
                 return 0;
 
         if (r < 0)
                 return r;
         if (bus->nodes_modified)
                 return 0;
 
-        r = sd_bus_message_new_method_return(bus, m, &reply);
+        r = sd_bus_message_new_method_return(m, &reply);
         if (r < 0)
                 return r;
 
         if (r < 0)
                 return r;
 
@@ -1021,19 +1129,9 @@ static int process_get_managed_objects(
                 char *path;
 
                 SET_FOREACH(path, s, i) {
                 char *path;
 
                 SET_FOREACH(path, s, i) {
-                        _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
-
                         r = object_manager_serialize_path_and_fallbacks(bus, reply, path, &error);
                         if (r < 0)
                         r = object_manager_serialize_path_and_fallbacks(bus, reply, path, &error);
                         if (r < 0)
-                                return -ENOMEM;
-
-                        if (sd_bus_error_is_set(&error)) {
-                                r = sd_bus_reply_method_error(bus, m, &error);
-                                if (r < 0)
-                                        return r;
-
-                                return 1;
-                        }
+                                return r;
 
                         if (bus->nodes_modified)
                                 return 0;
 
                         if (bus->nodes_modified)
                                 return 0;
@@ -1111,7 +1209,7 @@ static int object_find_and_run(
 
                         r = sd_bus_message_read(m, "ss", &vtable_key.interface, &vtable_key.member);
                         if (r < 0)
 
                         r = sd_bus_message_read(m, "ss", &vtable_key.interface, &vtable_key.member);
                         if (r < 0)
-                                return r;
+                                return sd_bus_reply_method_errorf(m, SD_BUS_ERROR_INVALID_ARGS, "Expected interface and member parameters");
 
                         v = hashmap_get(bus->vtable_properties, &vtable_key);
                         if (v) {
 
                         v = hashmap_get(bus->vtable_properties, &vtable_key);
                         if (v) {
@@ -1129,7 +1227,7 @@ static int object_find_and_run(
 
                         r = sd_bus_message_read(m, "s", &iface);
                         if (r < 0)
 
                         r = sd_bus_message_read(m, "s", &iface);
                         if (r < 0)
-                                return r;
+                                return sd_bus_reply_method_errorf(m, SD_BUS_ERROR_INVALID_ARGS, "Expected interface parameter");
 
                         if (iface[0] == 0)
                                 iface = NULL;
 
                         if (iface[0] == 0)
                                 iface = NULL;
@@ -1141,12 +1239,18 @@ static int object_find_and_run(
 
         } else if (sd_bus_message_is_method_call(m, "org.freedesktop.DBus.Introspectable", "Introspect")) {
 
 
         } else if (sd_bus_message_is_method_call(m, "org.freedesktop.DBus.Introspectable", "Introspect")) {
 
+                if (!isempty(sd_bus_message_get_signature(m, true)))
+                        return sd_bus_reply_method_errorf(m, SD_BUS_ERROR_INVALID_ARGS, "Expected no parameters");
+
                 r = process_introspect(bus, m, n, require_fallback, found_object);
                 if (r != 0)
                         return r;
 
         } else if (sd_bus_message_is_method_call(m, "org.freedesktop.DBus.ObjectManager", "GetManagedObjects")) {
 
                 r = process_introspect(bus, m, n, require_fallback, found_object);
                 if (r != 0)
                         return r;
 
         } else if (sd_bus_message_is_method_call(m, "org.freedesktop.DBus.ObjectManager", "GetManagedObjects")) {
 
+                if (!isempty(sd_bus_message_get_signature(m, true)))
+                        return sd_bus_reply_method_errorf(m, SD_BUS_ERROR_INVALID_ARGS, "Expected no parameters");
+
                 r = process_get_managed_objects(bus, m, n, require_fallback, found_object);
                 if (r != 0)
                         return r;
                 r = process_get_managed_objects(bus, m, n, require_fallback, found_object);
                 if (r != 0)
                         return r;
@@ -1177,12 +1281,12 @@ int bus_process_object(sd_bus *bus, sd_bus_message *m) {
         if (m->header->type != SD_BUS_MESSAGE_METHOD_CALL)
                 return 0;
 
         if (m->header->type != SD_BUS_MESSAGE_METHOD_CALL)
                 return 0;
 
-        if (!m->path)
-                return 0;
-
         if (hashmap_isempty(bus->nodes))
                 return 0;
 
         if (hashmap_isempty(bus->nodes))
                 return 0;
 
+        assert(m->path);
+        assert(m->member);
+
         pl = strlen(m->path);
         do {
                 char prefix[pl+1];
         pl = strlen(m->path);
         do {
                 char prefix[pl+1];
@@ -1212,12 +1316,12 @@ int bus_process_object(sd_bus *bus, sd_bus_message *m) {
         if (sd_bus_message_is_method_call(m, "org.freedesktop.DBus.Properties", "Get") ||
             sd_bus_message_is_method_call(m, "org.freedesktop.DBus.Properties", "Set"))
                 r = sd_bus_reply_method_errorf(
         if (sd_bus_message_is_method_call(m, "org.freedesktop.DBus.Properties", "Get") ||
             sd_bus_message_is_method_call(m, "org.freedesktop.DBus.Properties", "Set"))
                 r = sd_bus_reply_method_errorf(
-                                bus, m,
+                                m,
                                 SD_BUS_ERROR_UNKNOWN_PROPERTY,
                                 "Unknown property or interface.");
         else
                 r = sd_bus_reply_method_errorf(
                                 SD_BUS_ERROR_UNKNOWN_PROPERTY,
                                 "Unknown property or interface.");
         else
                 r = sd_bus_reply_method_errorf(
-                                bus, m,
+                                m,
                                 SD_BUS_ERROR_UNKNOWN_METHOD,
                                 "Unknown method '%s' or interface '%s'.", m->member, m->interface);
 
                                 SD_BUS_ERROR_UNKNOWN_METHOD,
                                 "Unknown method '%s' or interface '%s'.", m->member, m->interface);
 
@@ -1383,19 +1487,35 @@ static int bus_remove_object(
         return 1;
 }
 
         return 1;
 }
 
-int sd_bus_add_object(sd_bus *bus, const char *path, sd_bus_message_handler_t callback, void *userdata) {
+_public_ int sd_bus_add_object(sd_bus *bus,
+                               const char *path,
+                               sd_bus_message_handler_t callback,
+                               void *userdata) {
+
         return bus_add_object(bus, false, path, callback, userdata);
 }
 
         return bus_add_object(bus, false, path, callback, userdata);
 }
 
-int sd_bus_remove_object(sd_bus *bus, const char *path, sd_bus_message_handler_t callback, void *userdata) {
+_public_ int sd_bus_remove_object(sd_bus *bus,
+                                  const char *path,
+                                  sd_bus_message_handler_t callback,
+                                  void *userdata) {
+
         return bus_remove_object(bus, false, path, callback, userdata);
 }
 
         return bus_remove_object(bus, false, path, callback, userdata);
 }
 
-int sd_bus_add_fallback(sd_bus *bus, const char *prefix, sd_bus_message_handler_t callback, void *userdata) {
+_public_ int sd_bus_add_fallback(sd_bus *bus,
+                                 const char *prefix,
+                                 sd_bus_message_handler_t callback,
+                                 void *userdata) {
+
         return bus_add_object(bus, true, prefix, callback, userdata);
 }
 
         return bus_add_object(bus, true, prefix, callback, userdata);
 }
 
-int sd_bus_remove_fallback(sd_bus *bus, const char *prefix, sd_bus_message_handler_t callback, void *userdata) {
+_public_ int sd_bus_remove_fallback(sd_bus *bus,
+                                    const char *prefix,
+                                    sd_bus_message_handler_t callback,
+                                    void *userdata) {
+
         return bus_remove_object(bus, true, prefix, callback, userdata);
 }
 
         return bus_remove_object(bus, true, prefix, callback, userdata);
 }
 
@@ -1481,7 +1601,7 @@ static int add_object_vtable_internal(
                 sd_bus_object_find_t find,
                 void *userdata) {
 
                 sd_bus_object_find_t find,
                 void *userdata) {
 
-        struct node_vtable *c = NULL, *i;
+        struct node_vtable *c = NULL, *i, *existing = NULL;
         const sd_bus_vtable *v;
         struct node *n;
         int r;
         const sd_bus_vtable *v;
         struct node *n;
         int r;
@@ -1493,6 +1613,10 @@ static int add_object_vtable_internal(
         assert_return(vtable[0].type == _SD_BUS_VTABLE_START, -EINVAL);
         assert_return(vtable[0].x.start.element_size == sizeof(struct sd_bus_vtable), -EINVAL);
         assert_return(!bus_pid_changed(bus), -ECHILD);
         assert_return(vtable[0].type == _SD_BUS_VTABLE_START, -EINVAL);
         assert_return(vtable[0].x.start.element_size == sizeof(struct sd_bus_vtable), -EINVAL);
         assert_return(!bus_pid_changed(bus), -ECHILD);
+        assert_return(!streq(interface, "org.freedesktop.DBus.Properties") &&
+                      !streq(interface, "org.freedesktop.DBus.Introspectable") &&
+                      !streq(interface, "org.freedesktop.DBus.Peer") &&
+                      !streq(interface, "org.freedesktop.DBus.ObjectManager"), -EINVAL);
 
         r = hashmap_ensure_allocated(&bus->vtable_methods, vtable_member_hash_func, vtable_member_compare_func);
         if (r < 0)
 
         r = hashmap_ensure_allocated(&bus->vtable_methods, vtable_member_hash_func, vtable_member_compare_func);
         if (r < 0)
@@ -1507,15 +1631,20 @@ static int add_object_vtable_internal(
                 return -ENOMEM;
 
         LIST_FOREACH(vtables, i, n->vtables) {
                 return -ENOMEM;
 
         LIST_FOREACH(vtables, i, n->vtables) {
-                if (streq(i->interface, interface)) {
-                        r = -EEXIST;
-                        goto fail;
-                }
-
                 if (i->is_fallback != fallback) {
                         r = -EPROTOTYPE;
                         goto fail;
                 }
                 if (i->is_fallback != fallback) {
                         r = -EPROTOTYPE;
                         goto fail;
                 }
+
+                if (streq(i->interface, interface)) {
+
+                        if (i->vtable == vtable) {
+                                r = -EEXIST;
+                                goto fail;
+                        }
+
+                        existing = i;
+                }
         }
 
         c = new0(struct node_vtable, 1);
         }
 
         c = new0(struct node_vtable, 1);
@@ -1587,9 +1716,10 @@ static int add_object_vtable_internal(
 
                         if (!member_name_is_valid(v->x.property.member) ||
                             !signature_is_single(v->x.property.signature, false) ||
 
                         if (!member_name_is_valid(v->x.property.member) ||
                             !signature_is_single(v->x.property.signature, false) ||
-                            !(v->x.property.get || bus_type_is_basic(v->x.property.signature[0])) ||
+                            !(v->x.property.get || bus_type_is_basic(v->x.property.signature[0]) || streq(v->x.property.signature, "as")) ||
                             v->flags & SD_BUS_VTABLE_METHOD_NO_REPLY ||
                             v->flags & SD_BUS_VTABLE_METHOD_NO_REPLY ||
-                            (v->flags & SD_BUS_VTABLE_PROPERTY_INVALIDATE_ONLY && !(v->flags & SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE))) {
+                            (v->flags & SD_BUS_VTABLE_PROPERTY_INVALIDATE_ONLY && !(v->flags & SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE)) ||
+                            (v->flags & SD_BUS_VTABLE_UNPRIVILEGED && v->type == _SD_BUS_VTABLE_PROPERTY)) {
                                 r = -EINVAL;
                                 goto fail;
                         }
                                 r = -EINVAL;
                                 goto fail;
                         }
@@ -1619,7 +1749,8 @@ static int add_object_vtable_internal(
                 case _SD_BUS_VTABLE_SIGNAL:
 
                         if (!member_name_is_valid(v->x.signal.member) ||
                 case _SD_BUS_VTABLE_SIGNAL:
 
                         if (!member_name_is_valid(v->x.signal.member) ||
-                            !signature_is_valid(strempty(v->x.signal.signature), false)) {
+                            !signature_is_valid(strempty(v->x.signal.signature), false) ||
+                            v->flags & SD_BUS_VTABLE_UNPRIVILEGED) {
                                 r = -EINVAL;
                                 goto fail;
                         }
                                 r = -EINVAL;
                                 goto fail;
                         }
@@ -1632,7 +1763,7 @@ static int add_object_vtable_internal(
                 }
         }
 
                 }
         }
 
-        LIST_PREPEND(vtables, n->vtables, c);
+        LIST_INSERT_AFTER(vtables, n->vtables, existing, c);
         bus->nodes_modified = true;
 
         return 0;
         bus->nodes_modified = true;
 
         return 0;
@@ -1649,7 +1780,10 @@ static int remove_object_vtable_internal(
                 sd_bus *bus,
                 const char *path,
                 const char *interface,
                 sd_bus *bus,
                 const char *path,
                 const char *interface,
-                bool fallback) {
+                const sd_bus_vtable *vtable,
+                bool fallback,
+                sd_bus_object_find_t find,
+                void *userdata) {
 
         struct node_vtable *c;
         struct node *n;
 
         struct node_vtable *c;
         struct node *n;
@@ -1664,7 +1798,11 @@ static int remove_object_vtable_internal(
                 return 0;
 
         LIST_FOREACH(vtables, c, n->vtables)
                 return 0;
 
         LIST_FOREACH(vtables, c, n->vtables)
-                if (streq(c->interface, interface) && c->is_fallback == fallback)
+                if (streq(c->interface, interface) &&
+                    c->is_fallback == fallback &&
+                    c->vtable == vtable &&
+                    c->find == find &&
+                    c->userdata == userdata)
                         break;
 
         if (!c)
                         break;
 
         if (!c)
@@ -1680,7 +1818,7 @@ static int remove_object_vtable_internal(
         return 1;
 }
 
         return 1;
 }
 
-int sd_bus_add_object_vtable(
+_public_ int sd_bus_add_object_vtable(
                 sd_bus *bus,
                 const char *path,
                 const char *interface,
                 sd_bus *bus,
                 const char *path,
                 const char *interface,
@@ -1690,15 +1828,17 @@ int sd_bus_add_object_vtable(
         return add_object_vtable_internal(bus, path, interface, vtable, false, NULL, userdata);
 }
 
         return add_object_vtable_internal(bus, path, interface, vtable, false, NULL, userdata);
 }
 
-int sd_bus_remove_object_vtable(
+_public_ int sd_bus_remove_object_vtable(
                 sd_bus *bus,
                 const char *path,
                 sd_bus *bus,
                 const char *path,
-                const char *interface) {
+                const char *interface,
+                const sd_bus_vtable *vtable,
+                void *userdata) {
 
 
-        return remove_object_vtable_internal(bus, path, interface, false);
+        return remove_object_vtable_internal(bus, path, interface, vtable, false, NULL, userdata);
 }
 
 }
 
-int sd_bus_add_fallback_vtable(
+_public_ int sd_bus_add_fallback_vtable(
                 sd_bus *bus,
                 const char *path,
                 const char *interface,
                 sd_bus *bus,
                 const char *path,
                 const char *interface,
@@ -1709,15 +1849,18 @@ int sd_bus_add_fallback_vtable(
         return add_object_vtable_internal(bus, path, interface, vtable, true, find, userdata);
 }
 
         return add_object_vtable_internal(bus, path, interface, vtable, true, find, userdata);
 }
 
-int sd_bus_remove_fallback_vtable(
+_public_ int sd_bus_remove_fallback_vtable(
                 sd_bus *bus,
                 const char *path,
                 sd_bus *bus,
                 const char *path,
-                const char *interface) {
+                const char *interface,
+                const sd_bus_vtable *vtable,
+                sd_bus_object_find_t find,
+                void *userdata) {
 
 
-        return remove_object_vtable_internal(bus, path, interface, true);
+        return remove_object_vtable_internal(bus, path, interface, vtable, true, find, userdata);
 }
 
 }
 
-int sd_bus_add_node_enumerator(
+_public_ int sd_bus_add_node_enumerator(
                 sd_bus *bus,
                 const char *path,
                 sd_bus_node_enumerator_t callback,
                 sd_bus *bus,
                 const char *path,
                 sd_bus_node_enumerator_t callback,
@@ -1758,7 +1901,7 @@ fail:
         return r;
 }
 
         return r;
 }
 
-int sd_bus_remove_node_enumerator(
+_public_ int sd_bus_remove_node_enumerator(
                 sd_bus *bus,
                 const char *path,
                 sd_bus_node_enumerator_t callback,
                 sd_bus *bus,
                 const char *path,
                 sd_bus_node_enumerator_t callback,
@@ -1801,9 +1944,10 @@ static int emit_properties_changed_on_interface(
                 bool require_fallback,
                 char **names) {
 
                 bool require_fallback,
                 char **names) {
 
+        _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
         _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
         _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
-        bool has_invalidating = false;
-        struct vtable_member key;
+        bool has_invalidating = false, has_changing = false;
+        struct vtable_member key = {};
         struct node_vtable *c;
         struct node *n;
         char **property;
         struct node_vtable *c;
         struct node *n;
         char **property;
@@ -1819,23 +1963,6 @@ static int emit_properties_changed_on_interface(
         if (!n)
                 return 0;
 
         if (!n)
                 return 0;
 
-        LIST_FOREACH(vtables, c, n->vtables) {
-                if (require_fallback && !c->is_fallback)
-                        continue;
-
-                if (streq(c->interface, interface))
-                        break;
-        }
-
-        if (!c)
-                return 0;
-
-        r = node_vtable_get_userdata(bus, path, c, &u);
-        if (r <= 0)
-                return r;
-        if (bus->nodes_modified)
-                return 0;
-
         r = sd_bus_message_new_signal(bus, path, "org.freedesktop.DBus.Properties", "PropertiesChanged", &m);
         if (r < 0)
                 return r;
         r = sd_bus_message_new_signal(bus, path, "org.freedesktop.DBus.Properties", "PropertiesChanged", &m);
         if (r < 0)
                 return r;
@@ -1851,52 +1978,77 @@ static int emit_properties_changed_on_interface(
         key.path = prefix;
         key.interface = interface;
 
         key.path = prefix;
         key.interface = interface;
 
-        STRV_FOREACH(property, names) {
-                _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
-                struct vtable_member *v;
-
-                assert_return(member_name_is_valid(*property), -EINVAL);
-
-                key.member = *property;
-                v = hashmap_get(bus->vtable_properties, &key);
-                if (!v)
-                        return -ENOENT;
-
-                assert(c == v->parent);
-                assert_return(v->vtable->flags & SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE, -EDOM);
+        LIST_FOREACH(vtables, c, n->vtables) {
+                if (require_fallback && !c->is_fallback)
+                        continue;
 
 
-                if (v->vtable->flags & SD_BUS_VTABLE_PROPERTY_INVALIDATE_ONLY) {
-                        has_invalidating = true;
+                if (!streq(c->interface, interface))
                         continue;
                         continue;
-                }
 
 
-                r = sd_bus_message_open_container(m, 'e', "sv");
+                r = node_vtable_get_userdata(bus, path, c, &u, &error);
                 if (r < 0)
                         return r;
                 if (r < 0)
                         return r;
+                if (bus->nodes_modified)
+                        return 0;
+                if (r == 0)
+                        continue;
 
 
-                r = sd_bus_message_append(m, "s", *property);
-                if (r < 0)
-                        return r;
+                STRV_FOREACH(property, names) {
+                        struct vtable_member *v;
 
 
-                r = sd_bus_message_open_container(m, 'v', v->vtable->x.property.signature);
-                if (r < 0)
-                        return r;
+                        assert_return(member_name_is_valid(*property), -EINVAL);
 
 
-                r = invoke_property_get(bus, v->vtable, m->path, interface, *property, m, &error, vtable_property_convert_userdata(v->vtable, u));
-                if (r < 0)
-                        return r;
-                if (bus->nodes_modified)
-                        return 0;
+                        key.member = *property;
+                        v = hashmap_get(bus->vtable_properties, &key);
+                        if (!v)
+                                return -ENOENT;
+
+                        /* If there are two vtables for the same
+                         * interface, let's handle this property when
+                         * we come to that vtable. */
+                        if (c != v->parent)
+                                continue;
 
 
-                r = sd_bus_message_close_container(m);
-                if (r < 0)
-                        return r;
+                        assert_return(v->vtable->flags & SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE, -EDOM);
 
 
-                r = sd_bus_message_close_container(m);
-                if (r < 0)
-                        return r;
+                        if (v->vtable->flags & SD_BUS_VTABLE_PROPERTY_INVALIDATE_ONLY) {
+                                has_invalidating = true;
+                                continue;
+                        }
+
+                        has_changing = true;
+
+                        r = sd_bus_message_open_container(m, 'e', "sv");
+                        if (r < 0)
+                                return r;
+
+                        r = sd_bus_message_append(m, "s", *property);
+                        if (r < 0)
+                                return r;
+
+                        r = sd_bus_message_open_container(m, 'v', v->vtable->x.property.signature);
+                        if (r < 0)
+                                return r;
+
+                        r = invoke_property_get(bus, v->vtable, m->path, interface, *property, m, vtable_property_convert_userdata(v->vtable, u), &error);
+                        if (r < 0)
+                                return r;
+                        if (bus->nodes_modified)
+                                return 0;
+
+                        r = sd_bus_message_close_container(m);
+                        if (r < 0)
+                                return r;
+
+                        r = sd_bus_message_close_container(m);
+                        if (r < 0)
+                                return r;
+                }
         }
 
         }
 
+        if (!has_invalidating && !has_changing)
+                return 0;
+
         r = sd_bus_message_close_container(m);
         if (r < 0)
                 return r;
         r = sd_bus_message_close_container(m);
         if (r < 0)
                 return r;
@@ -1906,19 +2058,35 @@ static int emit_properties_changed_on_interface(
                 return r;
 
         if (has_invalidating) {
                 return r;
 
         if (has_invalidating) {
-                STRV_FOREACH(property, names) {
-                        struct vtable_member *v;
-
-                        key.member = *property;
-                        assert_se(v = hashmap_get(bus->vtable_properties, &key));
-                        assert(c == v->parent);
+                LIST_FOREACH(vtables, c, n->vtables) {
+                        if (require_fallback && !c->is_fallback)
+                                continue;
 
 
-                        if (!(v->vtable->flags & SD_BUS_VTABLE_PROPERTY_INVALIDATE_ONLY))
+                        if (!streq(c->interface, interface))
                                 continue;
 
                                 continue;
 
-                        r = sd_bus_message_append(m, "s", *property);
+                        r = node_vtable_get_userdata(bus, path, c, &u, &error);
                         if (r < 0)
                                 return r;
                         if (r < 0)
                                 return r;
+                        if (bus->nodes_modified)
+                                return 0;
+                        if (r == 0)
+                                continue;
+
+                        STRV_FOREACH(property, names) {
+                                struct vtable_member *v;
+
+                                key.member = *property;
+                                assert_se(v = hashmap_get(bus->vtable_properties, &key));
+                                assert(c == v->parent);
+
+                                if (!(v->vtable->flags & SD_BUS_VTABLE_PROPERTY_INVALIDATE_ONLY))
+                                        continue;
+
+                                r = sd_bus_message_append(m, "s", *property);
+                                if (r < 0)
+                                        return r;
+                        }
                 }
         }
 
                 }
         }
 
@@ -1933,7 +2101,7 @@ static int emit_properties_changed_on_interface(
         return 1;
 }
 
         return 1;
 }
 
-int sd_bus_emit_properties_changed_strv(
+_public_ int sd_bus_emit_properties_changed_strv(
                 sd_bus *bus,
                 const char *path,
                 const char *interface,
                 sd_bus *bus,
                 const char *path,
                 const char *interface,
@@ -1975,7 +2143,7 @@ int sd_bus_emit_properties_changed_strv(
         return -ENOENT;
 }
 
         return -ENOENT;
 }
 
-int sd_bus_emit_properties_changed(
+_public_ int sd_bus_emit_properties_changed(
                 sd_bus *bus,
                 const char *path,
                 const char *interface,
                 sd_bus *bus,
                 const char *path,
                 const char *interface,
@@ -2006,6 +2174,7 @@ static int interfaces_added_append_one_prefix(
                 bool require_fallback) {
 
         _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
                 bool require_fallback) {
 
         _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
+        bool found_interface = false;
         struct node_vtable *c;
         struct node *n;
         void *u = NULL;
         struct node_vtable *c;
         struct node *n;
         void *u = NULL;
@@ -2025,38 +2194,43 @@ static int interfaces_added_append_one_prefix(
                 if (require_fallback && !c->is_fallback)
                         continue;
 
                 if (require_fallback && !c->is_fallback)
                         continue;
 
-                if (streq(c->interface, interface))
-                        break;
-        }
+                if (!streq(c->interface, interface))
+                        continue;
 
 
-        if (!c)
-                return 0;
+                r = node_vtable_get_userdata(bus, path, c, &u, &error);
+                if (r < 0)
+                        return r;
+                if (bus->nodes_modified)
+                        return 0;
+                if (r == 0)
+                        continue;
 
 
-        r = node_vtable_get_userdata(bus, path, c, &u);
-        if (r <= 0)
-                return r;
-        if (bus->nodes_modified)
-                return 0;
+                if (!found_interface) {
+                        r = sd_bus_message_append_basic(m, 's', interface);
+                        if (r < 0)
+                                return r;
 
 
-        r = sd_bus_message_append_basic(m, 's', interface);
-        if (r < 0)
-                return r;
+                        r = sd_bus_message_open_container(m, 'a', "{sv}");
+                        if (r < 0)
+                                return r;
 
 
-        r = sd_bus_message_open_container(m, 'a', "{sv}");
-        if (r < 0)
-                return r;
+                        found_interface = true;
+                }
 
 
-        r = vtable_append_all_properties(bus, m,path, c, u, &error);
-        if (r < 0)
-                return r;
-        if (bus->nodes_modified)
-                return 0;
+                r = vtable_append_all_properties(bus, m, path, c, u, &error);
+                if (r < 0)
+                        return r;
+                if (bus->nodes_modified)
+                        return 0;
+        }
 
 
-        r = sd_bus_message_close_container(m);
-        if (r < 0)
-                return r;
+        if (found_interface) {
+                r = sd_bus_message_close_container(m);
+                if (r < 0)
+                        return r;
+        }
 
 
-        return 1;
+        return found_interface;
 }
 
 static int interfaces_added_append_one(
 }
 
 static int interfaces_added_append_one(
@@ -2091,7 +2265,7 @@ static int interfaces_added_append_one(
         return -ENOENT;
 }
 
         return -ENOENT;
 }
 
-int sd_bus_emit_interfaces_added_strv(sd_bus *bus, const char *path, char **interfaces) {
+_public_ int sd_bus_emit_interfaces_added_strv(sd_bus *bus, const char *path, char **interfaces) {
         BUS_DONT_DESTROY(bus);
 
         _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
         BUS_DONT_DESTROY(bus);
 
         _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
@@ -2155,7 +2329,7 @@ int sd_bus_emit_interfaces_added_strv(sd_bus *bus, const char *path, char **inte
         return sd_bus_send(bus, m, NULL);
 }
 
         return sd_bus_send(bus, m, NULL);
 }
 
-int sd_bus_emit_interfaces_added(sd_bus *bus, const char *path, const char *interface, ...) {
+_public_ int sd_bus_emit_interfaces_added(sd_bus *bus, const char *path, const char *interface, ...) {
         char **interfaces;
 
         assert_return(bus, -EINVAL);
         char **interfaces;
 
         assert_return(bus, -EINVAL);
@@ -2168,7 +2342,7 @@ int sd_bus_emit_interfaces_added(sd_bus *bus, const char *path, const char *inte
         return sd_bus_emit_interfaces_added_strv(bus, path, interfaces);
 }
 
         return sd_bus_emit_interfaces_added_strv(bus, path, interfaces);
 }
 
-int sd_bus_emit_interfaces_removed_strv(sd_bus *bus, const char *path, char **interfaces) {
+_public_ int sd_bus_emit_interfaces_removed_strv(sd_bus *bus, const char *path, char **interfaces) {
         _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
         int r;
 
         _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
         int r;
 
@@ -2195,7 +2369,7 @@ int sd_bus_emit_interfaces_removed_strv(sd_bus *bus, const char *path, char **in
         return sd_bus_send(bus, m, NULL);
 }
 
         return sd_bus_send(bus, m, NULL);
 }
 
-int sd_bus_emit_interfaces_removed(sd_bus *bus, const char *path, const char *interface, ...) {
+_public_ int sd_bus_emit_interfaces_removed(sd_bus *bus, const char *path, const char *interface, ...) {
         char **interfaces;
 
         assert_return(bus, -EINVAL);
         char **interfaces;
 
         assert_return(bus, -EINVAL);
@@ -2208,7 +2382,7 @@ int sd_bus_emit_interfaces_removed(sd_bus *bus, const char *path, const char *in
         return sd_bus_emit_interfaces_removed_strv(bus, path, interfaces);
 }
 
         return sd_bus_emit_interfaces_removed_strv(bus, path, interfaces);
 }
 
-int sd_bus_add_object_manager(sd_bus *bus, const char *path) {
+_public_ int sd_bus_add_object_manager(sd_bus *bus, const char *path) {
         struct node *n;
 
         assert_return(bus, -EINVAL);
         struct node *n;
 
         assert_return(bus, -EINVAL);
@@ -2224,7 +2398,7 @@ int sd_bus_add_object_manager(sd_bus *bus, const char *path) {
         return 0;
 }
 
         return 0;
 }
 
-int sd_bus_remove_object_manager(sd_bus *bus, const char *path) {
+_public_ int sd_bus_remove_object_manager(sd_bus *bus, const char *path) {
         struct node *n;
 
         assert_return(bus, -EINVAL);
         struct node *n;
 
         assert_return(bus, -EINVAL);