chiark / gitweb /
nspawn: make kdbus namespaces actually work
[elogind.git] / src / libsystemd-bus / bus-message.c
index 920488dae7a17acc03b13e22bba5348cf7504bb8..dc856944719c50406f5419a96e0e1875714a0d86 100644 (file)
@@ -129,7 +129,7 @@ static void message_free(sd_bus_message *m) {
                 uint64_t off;
 
                 off = (uint8_t *)m->kdbus - (uint8_t *)m->bus->kdbus_buffer;
-                ioctl(m->bus->input_fd, KDBUS_CMD_MSG_RELEASE, &off);
+                ioctl(m->bus->input_fd, KDBUS_CMD_FREE, &off);
         }
 
         if (m->bus)
@@ -568,6 +568,7 @@ static int message_new_reply(
         }
 
         t->dont_send = !!(call->header->flags & SD_BUS_MESSAGE_NO_REPLY_EXPECTED);
+        t->enforced_reply_signature = call->enforced_reply_signature;
 
         *m = t;
         return 0;
@@ -609,6 +610,8 @@ _public_ int sd_bus_message_new_method_error(
                         goto fail;
         }
 
+        t->error._need_free = -1;
+
         *m = t;
         return 0;
 
@@ -709,6 +712,8 @@ int bus_message_new_synthetic_error(
                         goto fail;
         }
 
+        t->error._need_free = -1;
+
         *m = t;
         return 0;
 
@@ -3804,6 +3809,9 @@ int bus_message_parse_fields(sd_bus_message *m) {
                                 return -EBADMSG;
 
                         r = message_peek_field_string(m, error_name_is_valid, &ri, &m->error.name);
+                        if (r >= 0)
+                                m->error._need_free = -1;
+
                         break;
 
                 case SD_BUS_MESSAGE_HEADER_DESTINATION:
@@ -3826,6 +3834,12 @@ int bus_message_parse_fields(sd_bus_message *m) {
                                 return -EBADMSG;
 
                         r = message_peek_field_string(m, service_name_is_valid, &ri, &m->sender);
+
+                        if (r >= 0 && m->sender[0] == ':' && m->bus && m->bus->bus_client && !m->bus->is_kernel) {
+                                m->creds.unique_name = (char*) m->sender;
+                                m->creds.mask |= SD_BUS_CREDS_UNIQUE_NAME & m->bus->creds_mask;
+                        }
+
                         break;
 
 
@@ -3949,6 +3963,13 @@ int bus_message_seal(sd_bus_message *m, uint64_t serial) {
         if (m->poisoned)
                 return -ESTALE;
 
+        /* In vtables the return signature of method calls is listed,
+         * let's check if they match if this is a response */
+        if (m->header->type == SD_BUS_MESSAGE_METHOD_RETURN &&
+            m->enforced_reply_signature &&
+            !streq(strempty(m->root_container.signature), m->enforced_reply_signature))
+                return -ENOMSG;
+
         /* If there's a non-trivial signature set, then add it in here */
         if (!isempty(m->root_container.signature)) {
                 r = message_append_field_signature(m, SD_BUS_MESSAGE_HEADER_SIGNATURE, m->root_container.signature, NULL);