chiark / gitweb /
import: introduce new mini-daemon systemd-importd, and make machinectl a client to it
[elogind.git] / src / libsystemd / sd-bus / bus-message.c
index 06d8d770fdba6e0f8d4b86064c6408b8cd495b92..23076d25ddb3360b4a6848485633f79bed77a05c 100644 (file)
@@ -65,9 +65,11 @@ static void message_free_part(sd_bus_message *m, struct bus_body_part *part) {
                 /* If we can reuse the memfd, try that. For that it
                  * can't be sealed yet. */
 
-                if (!part->sealed)
+                if (!part->sealed) {
+                        assert(part->memfd_offset == 0);
+                        assert(part->data == part->mmap_begin);
                         bus_kernel_push_memfd(m->bus, part->memfd, part->data, part->mapped, part->allocated);
-                else {
+                else {
                         if (part->mapped > 0)
                                 assert_se(munmap(part->mmap_begin, part->mapped) == 0);
 
@@ -128,8 +130,9 @@ static void message_free(sd_bus_message *m) {
         message_reset_parts(m);
 
         if (m->release_kdbus) {
-                struct kdbus_cmd_free cmd_free;
+                struct kdbus_cmd_free cmd_free = { };
 
+                cmd_free.size = sizeof(cmd_free);
                 cmd_free.flags = 0;
                 cmd_free.offset = (uint8_t *)m->kdbus - (uint8_t *)m->bus->kdbus_buffer;
                 (void) ioctl(m->bus->input_fd, KDBUS_CMD_FREE, &cmd_free);
@@ -421,19 +424,19 @@ int bus_message_from_header(
 
         if (ucred) {
                 m->creds.pid = ucred->pid;
-                m->creds.uid = ucred->uid;
-                m->creds.gid = ucred->gid;
+                m->creds.euid = ucred->uid;
+                m->creds.egid = ucred->gid;
 
                 /* Due to namespace translations some data might be
                  * missing from this ucred record. */
                 if (m->creds.pid > 0)
                         m->creds.mask |= SD_BUS_CREDS_PID;
 
-                if (m->creds.uid != UID_INVALID)
-                        m->creds.mask |= SD_BUS_CREDS_UID;
+                if (m->creds.euid != UID_INVALID)
+                        m->creds.mask |= SD_BUS_CREDS_EUID;
 
-                if (m->creds.gid != GID_INVALID)
-                        m->creds.mask |= SD_BUS_CREDS_GID;
+                if (m->creds.egid != GID_INVALID)
+                        m->creds.mask |= SD_BUS_CREDS_EGID;
         }
 
         if (label) {
@@ -751,6 +754,24 @@ _public_ int sd_bus_message_new_method_errnof(
         return sd_bus_message_new_method_error(call, m, &berror);
 }
 
+void bus_message_set_sender_local(sd_bus *bus, sd_bus_message *m) {
+        assert(bus);
+        assert(m);
+
+        m->sender = m->creds.unique_name = (char*) "org.freedesktop.DBus.Local";
+        m->creds.well_known_names_local = true;
+        m->creds.mask |= (SD_BUS_CREDS_UNIQUE_NAME|SD_BUS_CREDS_WELL_KNOWN_NAMES) & bus->creds_mask;
+}
+
+void bus_message_set_sender_driver(sd_bus *bus, sd_bus_message *m) {
+        assert(bus);
+        assert(m);
+
+        m->sender = m->creds.unique_name = (char*) "org.freedesktop.DBus";
+        m->creds.well_known_names_driver = true;
+        m->creds.mask |= (SD_BUS_CREDS_UNIQUE_NAME|SD_BUS_CREDS_WELL_KNOWN_NAMES) & bus->creds_mask;
+}
+
 int bus_message_new_synthetic_error(
                 sd_bus *bus,
                 uint64_t cookie,
@@ -793,6 +814,8 @@ int bus_message_new_synthetic_error(
 
         t->error._need_free = -1;
 
+        bus_message_set_sender_driver(bus, t);
+
         *m = t;
         return 0;
 
@@ -1103,8 +1126,10 @@ static int part_make_space(
         if (m->poisoned)
                 return -ENOMEM;
 
-        if (!part->data && part->memfd < 0)
+        if (!part->data && part->memfd < 0) {
                 part->memfd = bus_kernel_pop_memfd(m->bus, &part->data, &part->mapped, &part->allocated);
+                part->mmap_begin = part->data;
+        }
 
         if (part->memfd >= 0) {
 
@@ -1346,7 +1371,7 @@ int message_append_basic(sd_bus_message *m, char type, const void *p, const void
         } else {
                 char *e;
 
-                /* Maybe we can append to the signature? But only if this is the top-level container*/
+                /* Maybe we can append to the signature? But only if this is the top-level container */
                 if (c->enclosing != 0)
                         return -ENXIO;
 
@@ -1539,7 +1564,7 @@ _public_ int sd_bus_message_append_string_space(
         } else {
                 char *e;
 
-                /* Maybe we can append to the signature? But only if this is the top-level container*/
+                /* Maybe we can append to the signature? But only if this is the top-level container */
                 if (c->enclosing != 0)
                         return -ENXIO;
 
@@ -2693,7 +2718,7 @@ _public_ int sd_bus_message_append_string_memfd(
         } else {
                 char *e;
 
-                /* Maybe we can append to the signature? But only if this is the top-level container*/
+                /* Maybe we can append to the signature? But only if this is the top-level container */
                 if (c->enclosing != 0)
                         return -ENXIO;