diff options
Diffstat (limited to 'src/core/dbus-execute.c')
-rw-r--r-- | src/core/dbus-execute.c | 140 |
1 files changed, 96 insertions, 44 deletions
diff --git a/src/core/dbus-execute.c b/src/core/dbus-execute.c index 530a0f7a0b..df5168caaf 100644 --- a/src/core/dbus-execute.c +++ b/src/core/dbus-execute.c @@ -58,6 +58,7 @@ static BUS_DEFINE_PROPERTY_GET(property_get_mount_apivfs, "b", ExecContext, exec static BUS_DEFINE_PROPERTY_GET2(property_get_ioprio_class, "i", ExecContext, exec_context_get_effective_ioprio, ioprio_prio_class); static BUS_DEFINE_PROPERTY_GET2(property_get_ioprio_priority, "i", ExecContext, exec_context_get_effective_ioprio, ioprio_prio_data); static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_empty_string, "s", NULL); +static BUS_DEFINE_PROPERTY_GET_REF(property_get_private_tmp_ex, "s", PrivateTmp, private_tmp_to_string); static BUS_DEFINE_PROPERTY_GET_REF(property_get_syslog_level, "i", int, LOG_PRI); static BUS_DEFINE_PROPERTY_GET_REF(property_get_syslog_facility, "i", int, LOG_FAC); static BUS_DEFINE_PROPERTY_GET(property_get_cpu_affinity_from_numa, "b", ExecContext, exec_context_get_cpu_affinity_from_numa); @@ -482,17 +483,16 @@ static int property_get_bind_paths( if (r < 0) return r; - for (size_t i = 0; i < c->n_bind_mounts; i++) { - - if (ro != c->bind_mounts[i].read_only) + FOREACH_ARRAY(i, c->bind_mounts, c->n_bind_mounts) { + if (ro != i->read_only) continue; r = sd_bus_message_append( reply, "(ssbt)", - c->bind_mounts[i].source, - c->bind_mounts[i].destination, - c->bind_mounts[i].ignore_enoent, - c->bind_mounts[i].recursive ? (uint64_t) MS_REC : UINT64_C(0)); + i->source, + i->destination, + i->ignore_enoent, + i->recursive ? (uint64_t) MS_REC : UINT64_C(0)); if (r < 0) return r; } @@ -520,9 +520,7 @@ static int property_get_temporary_filesystems( if (r < 0) return r; - for (unsigned i = 0; i < c->n_temporary_filesystems; i++) { - TemporaryFileSystem *t = c->temporary_filesystems + i; - + FOREACH_ARRAY(t, c->temporary_filesystems, c->n_temporary_filesystems) { r = sd_bus_message_append( reply, "(ss)", t->path, @@ -554,8 +552,8 @@ static int property_get_log_extra_fields( if (r < 0) return r; - for (size_t i = 0; i < c->n_log_extra_fields; i++) { - r = sd_bus_message_append_array(reply, 'y', c->log_extra_fields[i].iov_base, c->log_extra_fields[i].iov_len); + FOREACH_ARRAY(i, c->log_extra_fields, c->n_log_extra_fields) { + r = sd_bus_message_append_array(reply, 'y', i->iov_base, i->iov_len); if (r < 0) return r; } @@ -777,30 +775,35 @@ static int property_get_mount_images( if (r < 0) return r; - for (size_t i = 0; i < c->n_mount_images; i++) { + FOREACH_ARRAY(i, c->mount_images, c->n_mount_images) { r = sd_bus_message_open_container(reply, SD_BUS_TYPE_STRUCT, "ssba(ss)"); if (r < 0) return r; + r = sd_bus_message_append( reply, "ssb", - c->mount_images[i].source, - c->mount_images[i].destination, - c->mount_images[i].ignore_enoent); + i->source, + i->destination, + i->ignore_enoent); if (r < 0) return r; + r = sd_bus_message_open_container(reply, 'a', "(ss)"); if (r < 0) return r; - LIST_FOREACH(mount_options, m, c->mount_images[i].mount_options) { + + LIST_FOREACH(mount_options, m, i->mount_options) { r = sd_bus_message_append(reply, "(ss)", partition_designator_to_string(m->partition_designator), m->options); if (r < 0) return r; } + r = sd_bus_message_close_container(reply); if (r < 0) return r; + r = sd_bus_message_close_container(reply); if (r < 0) return r; @@ -829,29 +832,34 @@ static int property_get_extension_images( if (r < 0) return r; - for (size_t i = 0; i < c->n_extension_images; i++) { + FOREACH_ARRAY(i, c->extension_images, c->n_extension_images) { r = sd_bus_message_open_container(reply, SD_BUS_TYPE_STRUCT, "sba(ss)"); if (r < 0) return r; + r = sd_bus_message_append( reply, "sb", - c->extension_images[i].source, - c->extension_images[i].ignore_enoent); + i->source, + i->ignore_enoent); if (r < 0) return r; + r = sd_bus_message_open_container(reply, 'a', "(ss)"); if (r < 0) return r; - LIST_FOREACH(mount_options, m, c->extension_images[i].mount_options) { + + LIST_FOREACH(mount_options, m, i->mount_options) { r = sd_bus_message_append(reply, "(ss)", partition_designator_to_string(m->partition_designator), m->options); if (r < 0) return r; } + r = sd_bus_message_close_container(reply); if (r < 0) return r; + r = sd_bus_message_close_container(reply); if (r < 0) return r; @@ -860,7 +868,7 @@ static int property_get_extension_images( return sd_bus_message_close_container(reply); } -static int bus_property_get_exec_dir( +static int property_get_exec_dir( sd_bus *bus, const char *path, const char *interface, @@ -880,8 +888,8 @@ static int bus_property_get_exec_dir( if (r < 0) return r; - for (size_t i = 0; i < d->n_items; i++) { - r = sd_bus_message_append_basic(reply, 's', d->items[i].path); + FOREACH_ARRAY(i, d->items, d->n_items) { + r = sd_bus_message_append_basic(reply, 's', i->path); if (r < 0) return r; } @@ -889,7 +897,7 @@ static int bus_property_get_exec_dir( return sd_bus_message_close_container(reply); } -static int bus_property_get_exec_dir_symlink( +static int property_get_exec_dir_symlink( sd_bus *bus, const char *path, const char *interface, @@ -909,9 +917,9 @@ static int bus_property_get_exec_dir_symlink( if (r < 0) return r; - for (size_t i = 0; i < d->n_items; i++) - STRV_FOREACH(dst, d->items[i].symlinks) { - r = sd_bus_message_append(reply, "(sst)", d->items[i].path, *dst, UINT64_C(0) /* flags, unused for now */); + FOREACH_ARRAY(i, d->items, d->n_items) + STRV_FOREACH(dst, i->symlinks) { + r = sd_bus_message_append(reply, "(sst)", i->path, *dst, UINT64_C(0) /* flags, unused for now */); if (r < 0) return r; } @@ -943,6 +951,21 @@ static int property_get_image_policy( return sd_bus_message_append(reply, "s", s); } +static int property_get_private_tmp( + sd_bus *bus, + const char *path, + const char *interface, + const char *property, + sd_bus_message *reply, + void *userdata, + sd_bus_error *error) { + + PrivateTmp *p = ASSERT_PTR(userdata); + int b = *p != PRIVATE_TMP_OFF; + + return sd_bus_message_append_basic(reply, 'b', &b); +} + const sd_bus_vtable bus_exec_vtable[] = { SD_BUS_VTABLE_START(0), SD_BUS_PROPERTY("Environment", "as", NULL, offsetof(ExecContext, environment), SD_BUS_VTABLE_PROPERTY_CONST), @@ -1055,7 +1078,8 @@ const sd_bus_vtable bus_exec_vtable[] = { SD_BUS_PROPERTY("NoExecPaths", "as", NULL, offsetof(ExecContext, no_exec_paths), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("ExecSearchPath", "as", NULL, offsetof(ExecContext, exec_search_path), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("MountFlags", "t", bus_property_get_ulong, offsetof(ExecContext, mount_propagation_flag), SD_BUS_VTABLE_PROPERTY_CONST), - SD_BUS_PROPERTY("PrivateTmp", "b", bus_property_get_private_tmp, offsetof(ExecContext, private_tmp), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("PrivateTmp", "b", property_get_private_tmp, offsetof(ExecContext, private_tmp), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("PrivateTmpEx", "s", property_get_private_tmp_ex, offsetof(ExecContext, private_tmp), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("PrivateDevices", "b", bus_property_get_bool, offsetof(ExecContext, private_devices), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("ProtectClock", "b", bus_property_get_bool, offsetof(ExecContext, protect_clock), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("ProtectKernelTunables", "b", bus_property_get_bool, offsetof(ExecContext, protect_kernel_tunables), SD_BUS_VTABLE_PROPERTY_CONST), @@ -1083,21 +1107,21 @@ const sd_bus_vtable bus_exec_vtable[] = { SD_BUS_PROPERTY("Personality", "s", property_get_personality, offsetof(ExecContext, personality), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("LockPersonality", "b", bus_property_get_bool, offsetof(ExecContext, lock_personality), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("RestrictAddressFamilies", "(bas)", property_get_address_families, 0, SD_BUS_VTABLE_PROPERTY_CONST), - SD_BUS_PROPERTY("RuntimeDirectorySymlink", "a(sst)", bus_property_get_exec_dir_symlink, offsetof(ExecContext, directories[EXEC_DIRECTORY_RUNTIME]), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("RuntimeDirectorySymlink", "a(sst)", property_get_exec_dir_symlink, offsetof(ExecContext, directories[EXEC_DIRECTORY_RUNTIME]), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("RuntimeDirectoryPreserve", "s", bus_property_get_exec_preserve_mode, offsetof(ExecContext, runtime_directory_preserve_mode), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("RuntimeDirectoryMode", "u", bus_property_get_mode, offsetof(ExecContext, directories[EXEC_DIRECTORY_RUNTIME].mode), SD_BUS_VTABLE_PROPERTY_CONST), - SD_BUS_PROPERTY("RuntimeDirectory", "as", bus_property_get_exec_dir, offsetof(ExecContext, directories[EXEC_DIRECTORY_RUNTIME]), SD_BUS_VTABLE_PROPERTY_CONST), - SD_BUS_PROPERTY("StateDirectorySymlink", "a(sst)", bus_property_get_exec_dir_symlink, offsetof(ExecContext, directories[EXEC_DIRECTORY_STATE]), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("RuntimeDirectory", "as", property_get_exec_dir, offsetof(ExecContext, directories[EXEC_DIRECTORY_RUNTIME]), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("StateDirectorySymlink", "a(sst)", property_get_exec_dir_symlink, offsetof(ExecContext, directories[EXEC_DIRECTORY_STATE]), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("StateDirectoryMode", "u", bus_property_get_mode, offsetof(ExecContext, directories[EXEC_DIRECTORY_STATE].mode), SD_BUS_VTABLE_PROPERTY_CONST), - SD_BUS_PROPERTY("StateDirectory", "as", bus_property_get_exec_dir, offsetof(ExecContext, directories[EXEC_DIRECTORY_STATE]), SD_BUS_VTABLE_PROPERTY_CONST), - SD_BUS_PROPERTY("CacheDirectorySymlink", "a(sst)", bus_property_get_exec_dir_symlink, offsetof(ExecContext, directories[EXEC_DIRECTORY_CACHE]), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("StateDirectory", "as", property_get_exec_dir, offsetof(ExecContext, directories[EXEC_DIRECTORY_STATE]), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("CacheDirectorySymlink", "a(sst)", property_get_exec_dir_symlink, offsetof(ExecContext, directories[EXEC_DIRECTORY_CACHE]), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("CacheDirectoryMode", "u", bus_property_get_mode, offsetof(ExecContext, directories[EXEC_DIRECTORY_CACHE].mode), SD_BUS_VTABLE_PROPERTY_CONST), - SD_BUS_PROPERTY("CacheDirectory", "as", bus_property_get_exec_dir, offsetof(ExecContext, directories[EXEC_DIRECTORY_CACHE]), SD_BUS_VTABLE_PROPERTY_CONST), - SD_BUS_PROPERTY("LogsDirectorySymlink", "a(sst)", bus_property_get_exec_dir_symlink, offsetof(ExecContext, directories[EXEC_DIRECTORY_LOGS]), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("CacheDirectory", "as", property_get_exec_dir, offsetof(ExecContext, directories[EXEC_DIRECTORY_CACHE]), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("LogsDirectorySymlink", "a(sst)", property_get_exec_dir_symlink, offsetof(ExecContext, directories[EXEC_DIRECTORY_LOGS]), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("LogsDirectoryMode", "u", bus_property_get_mode, offsetof(ExecContext, directories[EXEC_DIRECTORY_LOGS].mode), SD_BUS_VTABLE_PROPERTY_CONST), - SD_BUS_PROPERTY("LogsDirectory", "as", bus_property_get_exec_dir, offsetof(ExecContext, directories[EXEC_DIRECTORY_LOGS]), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("LogsDirectory", "as", property_get_exec_dir, offsetof(ExecContext, directories[EXEC_DIRECTORY_LOGS]), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("ConfigurationDirectoryMode", "u", bus_property_get_mode, offsetof(ExecContext, directories[EXEC_DIRECTORY_CONFIGURATION].mode), SD_BUS_VTABLE_PROPERTY_CONST), - SD_BUS_PROPERTY("ConfigurationDirectory", "as", bus_property_get_exec_dir, offsetof(ExecContext, directories[EXEC_DIRECTORY_CONFIGURATION]), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("ConfigurationDirectory", "as", property_get_exec_dir, offsetof(ExecContext, directories[EXEC_DIRECTORY_CONFIGURATION]), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("TimeoutCleanUSec", "t", bus_property_get_usec, offsetof(ExecContext, timeout_clean_usec), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("MemoryDenyWriteExecute", "b", bus_property_get_bool, offsetof(ExecContext, memory_deny_write_execute), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("RestrictRealtime", "b", bus_property_get_bool, offsetof(ExecContext, restrict_realtime), SD_BUS_VTABLE_PROPERTY_CONST), @@ -1735,8 +1759,40 @@ int bus_exec_context_set_transient_property( if (streq(name, "TTYColumns")) return bus_set_transient_unsigned(u, name, &c->tty_cols, message, flags, error); - if (streq(name, "PrivateTmp")) - return bus_set_transient_private_tmp(u, name, &c->private_tmp, message, flags, error); + if (streq(name, "PrivateTmp")) { + int v; + + r = sd_bus_message_read(message, "b", &v); + if (r < 0) + return r; + + if (!UNIT_WRITE_FLAGS_NOOP(flags)) { + c->private_tmp = v ? PRIVATE_TMP_CONNECTED : PRIVATE_TMP_OFF; + (void) unit_write_settingf(u, flags, name, "%s=%s", name, yes_no(v)); + } + + return 1; + + } else if (streq(name, "PrivateTmpEx")) { + const char *s; + PrivateTmp t; + + r = sd_bus_message_read(message, "s", &s); + if (r < 0) + return r; + + t = private_tmp_from_string(s); + if (t < 0) + return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid %s setting: %s", name, s); + + if (!UNIT_WRITE_FLAGS_NOOP(flags)) { + c->private_tmp = t; + (void) unit_write_settingf(u, flags, name, "PrivateTmp=%s", + private_tmp_to_string(c->private_tmp)); + } + + return 1; + } if (streq(name, "PrivateDevices")) return bus_set_transient_bool(u, name, &c->private_devices, message, flags, error); @@ -2743,10 +2799,6 @@ int bus_exec_context_set_transient_property( if (!path_is_normalized(simplified)) return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "WorkingDirectory= expects a normalized path or '~'"); - - if (path_below_api_vfs(simplified)) - return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, - "WorkingDirectory= may not be below /proc/, /sys/ or /dev/"); } } |