#include "strv.h"
#include "time-util.h"
#include "cgroup-util.h"
-#include "memfd.h"
+#include "memfd-util.h"
#include "sd-bus.h"
#include "bus-message.h"
if (m->iovec != m->iovec_fixed)
free(m->iovec);
+ if (m->destination_ptr) {
+ free(m->destination_ptr);
+ m->destination_ptr = NULL;
+ }
+
message_reset_containers(m);
free(m->root_container.signature);
free(m->root_container.offsets);
m->n_fds = n_fds;
if (ucred) {
- m->creds.uid = ucred->uid;
m->creds.pid = ucred->pid;
+ m->creds.uid = ucred->uid;
m->creds.gid = ucred->gid;
- m->creds.mask |= SD_BUS_CREDS_UID | SD_BUS_CREDS_PID | SD_BUS_CREDS_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_t) -1)
+ m->creds.mask |= SD_BUS_CREDS_UID;
+
+ if (m->creds.gid != (gid_t) -1)
+ m->creds.mask |= SD_BUS_CREDS_GID;
}
if (label) {
return !(m->header->flags & BUS_MESSAGE_NO_AUTO_START);
}
+_public_ int sd_bus_message_get_allow_interactive_authorization(sd_bus_message *m) {
+ assert_return(m, -EINVAL);
+
+ return m->header->type == SD_BUS_MESSAGE_METHOD_CALL &&
+ (m->header->flags & BUS_MESSAGE_ALLOW_INTERACTIVE_AUTHORIZATION);
+}
+
_public_ const char *sd_bus_message_get_path(sd_bus_message *m) {
assert_return(m, NULL);
return 0;
}
+_public_ int sd_bus_message_set_allow_interactive_authorization(sd_bus_message *m, int b) {
+ assert_return(m, -EINVAL);
+ assert_return(!m->sealed, -EPERM);
+
+ if (b)
+ m->header->flags |= BUS_MESSAGE_ALLOW_INTERACTIVE_AUTHORIZATION;
+ else
+ m->header->flags &= ~BUS_MESSAGE_ALLOW_INTERACTIVE_AUTHORIZATION;
+
+ return 0;
+}
+
static struct bus_container *message_get_container(sd_bus_message *m) {
assert(m);
uint64_t new_allocated;
new_allocated = PAGE_ALIGN(sz > 0 ? 2 * sz : 1);
- r = ftruncate(part->memfd, new_allocated);
+ r = memfd_set_size(part->memfd, new_allocated);
if (r < 0) {
m->poisoned = true;
- return -errno;
+ return r;
}
part->allocated = new_allocated;
/* Then, sync up real memfd size */
sz = part->size;
- if (ftruncate(part->memfd, sz) < 0)
- return -errno;
+ r = memfd_set_size(part->memfd, sz);
+ if (r < 0)
+ return r;
/* Finally, try to seal */
- if (fcntl(part->memfd, F_ADD_SEALS, F_SEAL_SHRINK | F_SEAL_GROW | F_SEAL_WRITE) >= 0)
+ if (memfd_set_sealed(part->memfd) >= 0)
part->sealed = true;
}
}
case SD_BUS_MESSAGE_SIGNAL:
if (!m->path || !m->interface || !m->member)
return -EBADMSG;
+
+ if (m->reply_cookie != 0)
+ return -EBADMSG;
+
break;
case SD_BUS_MESSAGE_METHOD_CALL:
if (!m->path || !m->member)
return -EBADMSG;
+ if (m->reply_cookie != 0)
+ return -EBADMSG;
+
break;
case SD_BUS_MESSAGE_METHOD_RETURN:
return strempty(c->signature);
}
+_public_ int sd_bus_message_is_empty(sd_bus_message *m) {
+ assert_return(m, -EINVAL);
+
+ return isempty(m->root_container.signature);
+}
+
+_public_ int sd_bus_message_has_signature(sd_bus_message *m, const char *signature) {
+ assert_return(m, -EINVAL);
+
+ return streq(strempty(m->root_container.signature), strempty(signature));
+}
+
_public_ int sd_bus_message_copy(sd_bus_message *m, sd_bus_message *source, int all) {
bool done_something = false;
int r;