- r = message_peek_field_string(m, service_name_is_valid, &ri, &m->sender);
- break;
-
-
- case SD_BUS_MESSAGE_HEADER_SIGNATURE: {
- const char *s;
- char *c;
-
- if (m->root_container.signature)
- return -EBADMSG;
-
- if (!streq(signature, "g"))
- return -EBADMSG;
-
- r = message_peek_field_signature(m, &ri, &s);
- if (r < 0)
- return r;
-
- c = strdup(s);
- if (!c)
- return -ENOMEM;
-
- free(m->root_container.signature);
- m->root_container.signature = c;
- break;
- }
-
- case SD_BUS_MESSAGE_HEADER_REPLY_SERIAL:
- if (m->reply_serial != 0)
- return -EBADMSG;
-
- if (!streq(signature, "u"))
- return -EBADMSG;
-
- r = message_peek_field_uint32(m, &ri, &m->reply_serial);
- if (r < 0)
- return r;
-
- if (m->reply_serial == 0)
- return -EBADMSG;
-
- break;
-
- case SD_BUS_MESSAGE_HEADER_UNIX_FDS:
- if (unix_fds != 0)
- return -EBADMSG;
-
- if (!streq(signature, "u"))
- return -EBADMSG;
-
- r = message_peek_field_uint32(m, &ri, &unix_fds);
- if (r < 0)
- return -EBADMSG;
-
- if (unix_fds == 0)
- return -EBADMSG;
-
- break;
-
- default:
- r = message_skip_fields(m, &ri, (uint32_t) -1, (const char **) &signature);
- }
-
- if (r < 0)
- return r;
- }
-
- if (m->n_fds != unix_fds)
- return -EBADMSG;
-
- if (isempty(m->root_container.signature) != (BUS_MESSAGE_BODY_SIZE(m) == 0))
- return -EBADMSG;
-
- switch (m->header->type) {
-
- case SD_BUS_MESSAGE_TYPE_SIGNAL:
- if (!m->path || !m->interface || !m->member)
- return -EBADMSG;
- break;
-
- case SD_BUS_MESSAGE_TYPE_METHOD_CALL:
-
- if (!m->path || !m->member)
- return -EBADMSG;
-
- break;
-
- case SD_BUS_MESSAGE_TYPE_METHOD_RETURN:
-
- if (m->reply_serial == 0)
- return -EBADMSG;
- break;
-
- case SD_BUS_MESSAGE_TYPE_METHOD_ERROR:
-
- if (m->reply_serial == 0 || !m->error.name)
- return -EBADMSG;
- break;
- }
-
- /* Try to read the error message, but if we can't it's a non-issue */
- if (m->header->type == SD_BUS_MESSAGE_TYPE_METHOD_ERROR)
- sd_bus_message_read(m, "s", &m->error.message);
-
- return 0;
-}
-
-int bus_message_seal(sd_bus_message *m, uint64_t serial) {
- struct bus_body_part *part;
- size_t l, a;
- unsigned i;
- int r;
-
- assert(m);
-
- if (m->sealed)
- return -EPERM;
-
- if (m->n_containers > 0)
- return -EBADMSG;
-
- if (m->poisoned)
- return -ESTALE;
-
- /* 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);
- if (r < 0)
- return r;
- }
-
- if (m->n_fds > 0) {
- r = message_append_field_uint32(m, SD_BUS_MESSAGE_HEADER_UNIX_FDS, m->n_fds);
- if (r < 0)
- return r;
- }
-
- /* Add padding at the end, since we know the body
- * needs to start at an 8 byte alignment. */
-
- l = BUS_MESSAGE_FIELDS_SIZE(m);
- a = ALIGN8(l) - l;
- if (a > 0)
- memset((uint8_t*) BUS_MESSAGE_FIELDS(m) + l, 0, a);
-
- MESSAGE_FOREACH_PART(part, i, m)
- if (part->memfd >= 0 && !part->sealed) {
- ioctl(part->memfd, KDBUS_CMD_MEMFD_SEAL_SET, 1);
- part->sealed = true;
- }
-
- m->header->serial = serial;
- m->sealed = true;
-
- return 0;
-}
-
-int sd_bus_message_set_destination(sd_bus_message *m, const char *destination) {
- if (!m)
- return -EINVAL;
- if (!destination)
- return -EINVAL;
- if (m->sealed)
- return -EPERM;
- if (m->destination)
- return -EEXIST;
-
- return message_append_field_string(m, SD_BUS_MESSAGE_HEADER_DESTINATION, SD_BUS_TYPE_STRING, destination, &m->destination);
-}
-
-int bus_message_dump(sd_bus_message *m) {
- const char *u = NULL, *uu = NULL, *s = NULL;
- char **cmdline = NULL;
- unsigned level = 1;
- int r;
- uid_t owner, audit_loginuid;
- uint32_t audit_sessionid;
-
- assert(m);
-
- printf("Message %p\n"
- "\tn_ref=%u\n"
- "\tendian=%c\n"
- "\ttype=%i\n"
- "\tflags=%u\n"
- "\tversion=%u\n"
- "\tserial=%u\n"
- "\tfields_size=%u\n"
- "\tbody_size=%u\n"
- "\tpath=%s\n"
- "\tinterface=%s\n"
- "\tmember=%s\n"
- "\tdestination=%s\n"
- "\tsender=%s\n"
- "\tsignature=%s\n"
- "\treply_serial=%u\n"
- "\terror.name=%s\n"
- "\terror.message=%s\n"
- "\tsealed=%s\n"
- "\tn_body_parts=%u\n",
- m,
- m->n_ref,
- m->header->endian,
- m->header->type,
- m->header->flags,
- m->header->version,
- BUS_MESSAGE_SERIAL(m),
- BUS_MESSAGE_FIELDS_SIZE(m),
- BUS_MESSAGE_BODY_SIZE(m),
- strna(m->path),
- strna(m->interface),
- strna(m->member),
- strna(m->destination),
- strna(m->sender),
- strna(m->root_container.signature),
- m->reply_serial,
- strna(m->error.name),
- strna(m->error.message),
- yes_no(m->sealed),
- m->n_body_parts);
-
- if (m->pid != 0)
- printf("\tpid=%lu\n", (unsigned long) m->pid);
- if (m->tid != 0)
- printf("\ttid=%lu\n", (unsigned long) m->tid);
- if (m->uid_valid)
- printf("\tuid=%lu\n", (unsigned long) m->uid);
- if (m->gid_valid)
- printf("\tgid=%lu\n", (unsigned long) m->gid);
- if (m->pid_starttime != 0)
- printf("\tpid_starttime=%llu\n", (unsigned long long) m->pid_starttime);
- if (m->monotonic != 0)
- printf("\tmonotonic=%llu\n", (unsigned long long) m->monotonic);
- if (m->realtime != 0)
- printf("\trealtime=%llu\n", (unsigned long long) m->realtime);
- if (m->exe)
- printf("\texe=[%s]\n", m->exe);
- if (m->comm)
- printf("\tcomm=[%s]\n", m->comm);
- if (m->tid_comm)
- printf("\ttid_comm=[%s]\n", m->tid_comm);
- if (m->label)
- printf("\tlabel=[%s]\n", m->label);
- if (m->cgroup)
- printf("\tcgroup=[%s]\n", m->cgroup);
-
- sd_bus_message_get_unit(m, &u);
- if (u)
- printf("\tunit=[%s]\n", u);
- sd_bus_message_get_user_unit(m, &uu);
- if (uu)
- printf("\tuser_unit=[%s]\n", uu);
- sd_bus_message_get_session(m, &s);
- if (s)
- printf("\tsession=[%s]\n", s);
- if (sd_bus_message_get_owner_uid(m, &owner) >= 0)
- printf("\towner_uid=%lu\n", (unsigned long) owner);
- if (sd_bus_message_get_audit_loginuid(m, &audit_loginuid) >= 0)
- printf("\taudit_loginuid=%lu\n", (unsigned long) audit_loginuid);
- if (sd_bus_message_get_audit_sessionid(m, &audit_sessionid) >= 0)
- printf("\taudit_sessionid=%lu\n", (unsigned long) audit_sessionid);
-
- printf("\tCAP_KILL=%i\n", sd_bus_message_has_effective_cap(m, 5));
-
- if (sd_bus_message_get_cmdline(m, &cmdline) >= 0) {
- char **c;
-
- fputs("\tcmdline=[", stdout);
- STRV_FOREACH(c, cmdline) {
- if (c != cmdline)
- putchar(' ');
-
- fputs(*c, stdout);
- }
-
- fputs("]\n", stdout);
- }
-
- r = sd_bus_message_rewind(m, true);
- if (r < 0) {
- log_error("Failed to rewind: %s", strerror(-r));
- return r;
- }
-
- printf("BEGIN_MESSAGE \"%s\" {\n", strempty(m->root_container.signature));
-
- for(;;) {
- _cleanup_free_ char *prefix = NULL;
- const char *contents = NULL;
- char type;
- union {
- uint8_t u8;
- uint16_t u16;
- int16_t s16;
- uint32_t u32;
- int32_t s32;
- uint64_t u64;
- int64_t s64;
- double d64;
- const char *string;
- int i;
- } basic;
-
- r = sd_bus_message_peek_type(m, &type, &contents);
- if (r < 0) {
- log_error("Failed to peek type: %s", strerror(-r));
- return r;
- }
- if (r == 0) {
- if (level <= 1)
- break;
-
- r = sd_bus_message_exit_container(m);
- if (r < 0) {
- log_error("Failed to exit container: %s", strerror(-r));
- return r;