1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
6 #include "alloc-util.h"
7 #include "bus-get-properties.h"
10 #include "capability-util.h"
11 #include "cpu-set-util.h"
12 #include "creds-util.h"
13 #include "dbus-execute.h"
14 #include "dbus-util.h"
16 #include "errno-list.h"
18 #include "exec-credential.h"
22 #include "hexdecoct.h"
24 #include "ioprio-util.h"
25 #include "journal-file.h"
26 #include "load-fragment.h"
27 #include "memstream-util.h"
28 #include "missing_ioprio.h"
29 #include "mountpoint-util.h"
30 #include "namespace.h"
31 #include "parse-util.h"
32 #include "path-util.h"
33 #include "pcre2-util.h"
34 #include "process-util.h"
35 #include "rlimit-util.h"
36 #include "seccomp-util.h"
37 #include "securebits-util.h"
38 #include "specifier.h"
39 #include "stat-util.h"
41 #include "syslog-util.h"
42 #include "unit-printf.h"
43 #include "user-util.h"
46 BUS_DEFINE_PROPERTY_GET_ENUM(bus_property_get_exec_output
, exec_output
, ExecOutput
);
47 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_input
, exec_input
, ExecInput
);
48 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_utmp_mode
, exec_utmp_mode
, ExecUtmpMode
);
49 BUS_DEFINE_PROPERTY_GET_ENUM(bus_property_get_exec_preserve_mode
, exec_preserve_mode
, ExecPreserveMode
);
50 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_keyring_mode
, exec_keyring_mode
, ExecKeyringMode
);
51 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_protect_proc
, protect_proc
, ProtectProc
);
52 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_proc_subset
, proc_subset
, ProcSubset
);
53 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_protect_home
, protect_home
, ProtectHome
);
54 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_protect_system
, protect_system
, ProtectSystem
);
55 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_personality
, personality
, unsigned long);
56 static BUS_DEFINE_PROPERTY_GET(property_get_ioprio
, "i", ExecContext
, exec_context_get_effective_ioprio
);
57 static BUS_DEFINE_PROPERTY_GET(property_get_mount_apivfs
, "b", ExecContext
, exec_context_get_effective_mount_apivfs
);
58 static BUS_DEFINE_PROPERTY_GET2(property_get_ioprio_class
, "i", ExecContext
, exec_context_get_effective_ioprio
, ioprio_prio_class
);
59 static BUS_DEFINE_PROPERTY_GET2(property_get_ioprio_priority
, "i", ExecContext
, exec_context_get_effective_ioprio
, ioprio_prio_data
);
60 static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_empty_string
, "s", NULL
);
61 static BUS_DEFINE_PROPERTY_GET_REF(property_get_syslog_level
, "i", int, LOG_PRI
);
62 static BUS_DEFINE_PROPERTY_GET_REF(property_get_syslog_facility
, "i", int, LOG_FAC
);
63 static BUS_DEFINE_PROPERTY_GET(property_get_cpu_affinity_from_numa
, "b", ExecContext
, exec_context_get_cpu_affinity_from_numa
);
65 static int property_get_environment_files(
68 const char *interface
,
70 sd_bus_message
*reply
,
72 sd_bus_error
*error
) {
74 ExecContext
*c
= ASSERT_PTR(userdata
);
80 r
= sd_bus_message_open_container(reply
, 'a', "(sb)");
84 STRV_FOREACH(j
, c
->environment_files
) {
87 r
= sd_bus_message_append(reply
, "(sb)", fn
[0] == '-' ? fn
+ 1 : fn
, fn
[0] == '-');
92 return sd_bus_message_close_container(reply
);
95 static int property_get_oom_score_adjust(
98 const char *interface
,
100 sd_bus_message
*reply
,
102 sd_bus_error
*error
) {
104 ExecContext
*c
= ASSERT_PTR(userdata
);
110 if (c
->oom_score_adjust_set
)
111 n
= c
->oom_score_adjust
;
114 r
= get_oom_score_adjust(&n
);
116 log_debug_errno(r
, "Failed to read /proc/self/oom_score_adj, ignoring: %m");
119 return sd_bus_message_append(reply
, "i", n
);
122 static int property_get_coredump_filter(
125 const char *interface
,
126 const char *property
,
127 sd_bus_message
*reply
,
129 sd_bus_error
*error
) {
131 ExecContext
*c
= ASSERT_PTR(userdata
);
138 if (c
->coredump_filter_set
)
139 n
= c
->coredump_filter
;
141 _cleanup_free_
char *t
= NULL
;
143 n
= COREDUMP_FILTER_MASK_DEFAULT
;
144 r
= read_one_line_file("/proc/self/coredump_filter", &t
);
146 log_debug_errno(r
, "Failed to read /proc/self/coredump_filter, ignoring: %m");
148 r
= safe_atoux64(t
, &n
);
150 log_debug_errno(r
, "Failed to parse \"%s\" from /proc/self/coredump_filter, ignoring: %m", t
);
154 return sd_bus_message_append(reply
, "t", n
);
157 static int property_get_nice(
160 const char *interface
,
161 const char *property
,
162 sd_bus_message
*reply
,
164 sd_bus_error
*error
) {
166 ExecContext
*c
= ASSERT_PTR(userdata
);
176 n
= getpriority(PRIO_PROCESS
, 0);
181 return sd_bus_message_append(reply
, "i", n
);
184 static int property_get_cpu_sched_policy(
187 const char *interface
,
188 const char *property
,
189 sd_bus_message
*reply
,
191 sd_bus_error
*error
) {
193 ExecContext
*c
= ASSERT_PTR(userdata
);
199 if (c
->cpu_sched_set
)
200 n
= c
->cpu_sched_policy
;
202 n
= sched_getscheduler(0);
207 return sd_bus_message_append(reply
, "i", n
);
210 static int property_get_cpu_sched_priority(
213 const char *interface
,
214 const char *property
,
215 sd_bus_message
*reply
,
217 sd_bus_error
*error
) {
219 ExecContext
*c
= ASSERT_PTR(userdata
);
225 if (c
->cpu_sched_set
)
226 n
= c
->cpu_sched_priority
;
228 struct sched_param p
= {};
230 if (sched_getparam(0, &p
) >= 0)
231 n
= p
.sched_priority
;
236 return sd_bus_message_append(reply
, "i", n
);
239 static int property_get_cpu_affinity(
242 const char *interface
,
243 const char *property
,
244 sd_bus_message
*reply
,
246 sd_bus_error
*error
) {
248 ExecContext
*c
= ASSERT_PTR(userdata
);
249 _cleanup_(cpu_set_reset
) CPUSet s
= {};
250 _cleanup_free_
uint8_t *array
= NULL
;
256 if (c
->cpu_affinity_from_numa
) {
259 r
= numa_to_cpu_set(&c
->numa_policy
, &s
);
264 (void) cpu_set_to_dbus(c
->cpu_affinity_from_numa
? &s
: &c
->cpu_set
, &array
, &allocated
);
266 return sd_bus_message_append_array(reply
, 'y', array
, allocated
);
269 static int property_get_numa_mask(
272 const char *interface
,
273 const char *property
,
274 sd_bus_message
*reply
,
276 sd_bus_error
*error
) {
278 ExecContext
*c
= ASSERT_PTR(userdata
);
279 _cleanup_free_
uint8_t *array
= NULL
;
285 (void) cpu_set_to_dbus(&c
->numa_policy
.nodes
, &array
, &allocated
);
287 return sd_bus_message_append_array(reply
, 'y', array
, allocated
);
290 static int property_get_numa_policy(
293 const char *interface
,
294 const char *property
,
295 sd_bus_message
*reply
,
297 sd_bus_error
*error
) {
298 ExecContext
*c
= ASSERT_PTR(userdata
);
304 policy
= numa_policy_get_type(&c
->numa_policy
);
306 return sd_bus_message_append_basic(reply
, 'i', &policy
);
309 static int property_get_timer_slack_nsec(
312 const char *interface
,
313 const char *property
,
314 sd_bus_message
*reply
,
316 sd_bus_error
*error
) {
318 ExecContext
*c
= ASSERT_PTR(userdata
);
324 if (c
->timer_slack_nsec
!= NSEC_INFINITY
)
325 u
= (uint64_t) c
->timer_slack_nsec
;
327 u
= (uint64_t) prctl(PR_GET_TIMERSLACK
);
329 return sd_bus_message_append(reply
, "t", u
);
332 static int property_get_syscall_filter(
335 const char *interface
,
336 const char *property
,
337 sd_bus_message
*reply
,
339 sd_bus_error
*error
) {
341 ExecContext
*c
= ASSERT_PTR(userdata
);
342 _cleanup_strv_free_
char **l
= NULL
;
348 r
= sd_bus_message_open_container(reply
, 'r', "bas");
352 r
= sd_bus_message_append(reply
, "b", c
->syscall_allow_list
);
358 HASHMAP_FOREACH_KEY(val
, id
, c
->syscall_filter
) {
359 _cleanup_free_
char *name
= NULL
;
360 const char *e
= NULL
;
362 int num
= PTR_TO_INT(val
);
364 if (c
->syscall_allow_list
&& num
>= 0)
365 /* syscall with num >= 0 in allow-list is denied. */
368 name
= seccomp_syscall_resolve_num_arch(SCMP_ARCH_NATIVE
, PTR_TO_INT(id
) - 1);
373 e
= seccomp_errno_or_action_to_string(num
);
375 s
= strjoin(name
, ":", e
);
379 r
= asprintf(&s
, "%s:%d", name
, num
);
386 r
= strv_consume(&l
, s
);
394 r
= sd_bus_message_append_strv(reply
, l
);
398 return sd_bus_message_close_container(reply
);
401 static int property_get_syscall_log(
404 const char *interface
,
405 const char *property
,
406 sd_bus_message
*reply
,
408 sd_bus_error
*error
) {
410 ExecContext
*c
= ASSERT_PTR(userdata
);
411 _cleanup_strv_free_
char **l
= NULL
;
417 r
= sd_bus_message_open_container(reply
, 'r', "bas");
421 r
= sd_bus_message_append(reply
, "b", c
->syscall_log_allow_list
);
427 HASHMAP_FOREACH_KEY(val
, id
, c
->syscall_log
) {
430 name
= seccomp_syscall_resolve_num_arch(SCMP_ARCH_NATIVE
, PTR_TO_INT(id
) - 1);
434 r
= strv_consume(&l
, name
);
442 r
= sd_bus_message_append_strv(reply
, l
);
446 return sd_bus_message_close_container(reply
);
449 static int property_get_syscall_archs(
452 const char *interface
,
453 const char *property
,
454 sd_bus_message
*reply
,
456 sd_bus_error
*error
) {
458 _cleanup_strv_free_
char **l
= NULL
;
466 SET_FOREACH(id
, ASSERT_PTR((ExecContext
*) userdata
)->syscall_archs
) {
469 name
= seccomp_arch_to_string(PTR_TO_UINT32(id
) - 1);
473 r
= strv_extend(&l
, name
);
481 r
= sd_bus_message_append_strv(reply
, l
);
488 static int property_get_selinux_context(
491 const char *interface
,
492 const char *property
,
493 sd_bus_message
*reply
,
495 sd_bus_error
*error
) {
497 ExecContext
*c
= ASSERT_PTR(userdata
);
502 return sd_bus_message_append(reply
, "(bs)", c
->selinux_context_ignore
, c
->selinux_context
);
505 static int property_get_apparmor_profile(
508 const char *interface
,
509 const char *property
,
510 sd_bus_message
*reply
,
512 sd_bus_error
*error
) {
514 ExecContext
*c
= ASSERT_PTR(userdata
);
519 return sd_bus_message_append(reply
, "(bs)", c
->apparmor_profile_ignore
, c
->apparmor_profile
);
522 static int property_get_smack_process_label(
525 const char *interface
,
526 const char *property
,
527 sd_bus_message
*reply
,
529 sd_bus_error
*error
) {
531 ExecContext
*c
= ASSERT_PTR(userdata
);
536 return sd_bus_message_append(reply
, "(bs)", c
->smack_process_label_ignore
, c
->smack_process_label
);
539 static int property_get_address_families(
542 const char *interface
,
543 const char *property
,
544 sd_bus_message
*reply
,
546 sd_bus_error
*error
) {
548 ExecContext
*c
= ASSERT_PTR(userdata
);
549 _cleanup_strv_free_
char **l
= NULL
;
556 r
= sd_bus_message_open_container(reply
, 'r', "bas");
560 r
= sd_bus_message_append(reply
, "b", c
->address_families_allow_list
);
564 SET_FOREACH(af
, c
->address_families
) {
567 name
= af_to_name(PTR_TO_INT(af
));
571 r
= strv_extend(&l
, name
);
578 r
= sd_bus_message_append_strv(reply
, l
);
582 return sd_bus_message_close_container(reply
);
585 static int property_get_working_directory(
588 const char *interface
,
589 const char *property
,
590 sd_bus_message
*reply
,
592 sd_bus_error
*error
) {
594 ExecContext
*c
= ASSERT_PTR(userdata
);
600 if (c
->working_directory_home
)
603 wd
= c
->working_directory
;
605 if (c
->working_directory_missing_ok
)
606 wd
= strjoina("!", wd
);
608 return sd_bus_message_append(reply
, "s", wd
);
611 static int property_get_stdio_fdname(
614 const char *interface
,
615 const char *property
,
616 sd_bus_message
*reply
,
618 sd_bus_error
*error
) {
620 ExecContext
*c
= ASSERT_PTR(userdata
);
627 if (streq(property
, "StandardInputFileDescriptorName"))
628 fileno
= STDIN_FILENO
;
629 else if (streq(property
, "StandardOutputFileDescriptorName"))
630 fileno
= STDOUT_FILENO
;
632 assert(streq(property
, "StandardErrorFileDescriptorName"));
633 fileno
= STDERR_FILENO
;
636 return sd_bus_message_append(reply
, "s", exec_context_fdname(c
, fileno
));
639 static int property_get_input_data(
642 const char *interface
,
643 const char *property
,
644 sd_bus_message
*reply
,
646 sd_bus_error
*error
) {
648 ExecContext
*c
= ASSERT_PTR(userdata
);
654 return sd_bus_message_append_array(reply
, 'y', c
->stdin_data
, c
->stdin_data_size
);
657 static int property_get_restrict_filesystems(
660 const char *interface
,
661 const char *property
,
662 sd_bus_message
*reply
,
664 sd_bus_error
*error
) {
666 ExecContext
*c
= ASSERT_PTR(userdata
);
667 _cleanup_free_
char **l
= NULL
;
673 r
= sd_bus_message_open_container(reply
, 'r', "bas");
677 r
= sd_bus_message_append(reply
, "b", c
->restrict_filesystems_allow_list
);
682 l
= set_get_strv(c
->restrict_filesystems
);
689 r
= sd_bus_message_append_strv(reply
, l
);
693 return sd_bus_message_close_container(reply
);
696 static int property_get_bind_paths(
699 const char *interface
,
700 const char *property
,
701 sd_bus_message
*reply
,
703 sd_bus_error
*error
) {
705 ExecContext
*c
= ASSERT_PTR(userdata
);
713 ro
= strstr(property
, "ReadOnly");
715 r
= sd_bus_message_open_container(reply
, 'a', "(ssbt)");
719 for (size_t i
= 0; i
< c
->n_bind_mounts
; i
++) {
721 if (ro
!= c
->bind_mounts
[i
].read_only
)
724 r
= sd_bus_message_append(
726 c
->bind_mounts
[i
].source
,
727 c
->bind_mounts
[i
].destination
,
728 c
->bind_mounts
[i
].ignore_enoent
,
729 c
->bind_mounts
[i
].recursive
? (uint64_t) MS_REC
: (uint64_t) 0);
734 return sd_bus_message_close_container(reply
);
737 static int property_get_temporary_filesystems(
740 const char *interface
,
741 const char *property
,
742 sd_bus_message
*reply
,
744 sd_bus_error
*error
) {
746 ExecContext
*c
= ASSERT_PTR(userdata
);
753 r
= sd_bus_message_open_container(reply
, 'a', "(ss)");
757 for (unsigned i
= 0; i
< c
->n_temporary_filesystems
; i
++) {
758 TemporaryFileSystem
*t
= c
->temporary_filesystems
+ i
;
760 r
= sd_bus_message_append(
768 return sd_bus_message_close_container(reply
);
771 static int property_get_log_extra_fields(
774 const char *interface
,
775 const char *property
,
776 sd_bus_message
*reply
,
778 sd_bus_error
*error
) {
780 ExecContext
*c
= ASSERT_PTR(userdata
);
787 r
= sd_bus_message_open_container(reply
, 'a', "ay");
791 for (size_t i
= 0; i
< c
->n_log_extra_fields
; i
++) {
792 r
= sd_bus_message_append_array(reply
, 'y', c
->log_extra_fields
[i
].iov_base
, c
->log_extra_fields
[i
].iov_len
);
797 return sd_bus_message_close_container(reply
);
800 static int sd_bus_message_append_log_filter_patterns(sd_bus_message
*reply
, Set
*patterns
, bool is_allowlist
) {
806 SET_FOREACH(pattern
, patterns
) {
807 r
= sd_bus_message_append(reply
, "(bs)", is_allowlist
, pattern
);
815 static int property_get_log_filter_patterns(
818 const char *interface
,
819 const char *property
,
820 sd_bus_message
*reply
,
822 sd_bus_error
*error
) {
824 ExecContext
*c
= userdata
;
830 r
= sd_bus_message_open_container(reply
, 'a', "(bs)");
834 r
= sd_bus_message_append_log_filter_patterns(reply
, c
->log_filter_allowed_patterns
,
835 /* is_allowlist = */ true);
839 r
= sd_bus_message_append_log_filter_patterns(reply
, c
->log_filter_denied_patterns
,
840 /* is_allowlist = */ false);
844 return sd_bus_message_close_container(reply
);
847 static int property_get_set_credential(
850 const char *interface
,
851 const char *property
,
852 sd_bus_message
*reply
,
854 sd_bus_error
*error
) {
856 ExecContext
*c
= ASSERT_PTR(userdata
);
857 ExecSetCredential
*sc
;
864 r
= sd_bus_message_open_container(reply
, 'a', "(say)");
868 HASHMAP_FOREACH(sc
, c
->set_credentials
) {
870 if (sc
->encrypted
!= streq(property
, "SetCredentialEncrypted"))
873 r
= sd_bus_message_open_container(reply
, 'r', "say");
877 r
= sd_bus_message_append(reply
, "s", sc
->id
);
881 r
= sd_bus_message_append_array(reply
, 'y', sc
->data
, sc
->size
);
885 r
= sd_bus_message_close_container(reply
);
890 return sd_bus_message_close_container(reply
);
893 static int property_get_load_credential(
896 const char *interface
,
897 const char *property
,
898 sd_bus_message
*reply
,
900 sd_bus_error
*error
) {
902 ExecContext
*c
= ASSERT_PTR(userdata
);
903 ExecLoadCredential
*lc
;
910 r
= sd_bus_message_open_container(reply
, 'a', "(ss)");
914 HASHMAP_FOREACH(lc
, c
->load_credentials
) {
916 if (lc
->encrypted
!= streq(property
, "LoadCredentialEncrypted"))
919 r
= sd_bus_message_append(reply
, "(ss)", lc
->id
, lc
->path
);
924 return sd_bus_message_close_container(reply
);
927 static int property_get_root_hash(
930 const char *interface
,
931 const char *property
,
932 sd_bus_message
*reply
,
934 sd_bus_error
*error
) {
936 ExecContext
*c
= ASSERT_PTR(userdata
);
942 return sd_bus_message_append_array(reply
, 'y', c
->root_hash
, c
->root_hash_size
);
945 static int property_get_root_hash_sig(
948 const char *interface
,
949 const char *property
,
950 sd_bus_message
*reply
,
952 sd_bus_error
*error
) {
954 ExecContext
*c
= ASSERT_PTR(userdata
);
960 return sd_bus_message_append_array(reply
, 'y', c
->root_hash_sig
, c
->root_hash_sig_size
);
963 static int property_get_root_image_options(
966 const char *interface
,
967 const char *property
,
968 sd_bus_message
*reply
,
970 sd_bus_error
*error
) {
972 ExecContext
*c
= ASSERT_PTR(userdata
);
979 r
= sd_bus_message_open_container(reply
, 'a', "(ss)");
983 LIST_FOREACH(mount_options
, m
, c
->root_image_options
) {
984 r
= sd_bus_message_append(reply
, "(ss)",
985 partition_designator_to_string(m
->partition_designator
),
991 return sd_bus_message_close_container(reply
);
994 static int property_get_mount_images(
997 const char *interface
,
998 const char *property
,
999 sd_bus_message
*reply
,
1001 sd_bus_error
*error
) {
1003 ExecContext
*c
= ASSERT_PTR(userdata
);
1010 r
= sd_bus_message_open_container(reply
, 'a', "(ssba(ss))");
1014 for (size_t i
= 0; i
< c
->n_mount_images
; i
++) {
1015 r
= sd_bus_message_open_container(reply
, SD_BUS_TYPE_STRUCT
, "ssba(ss)");
1018 r
= sd_bus_message_append(
1020 c
->mount_images
[i
].source
,
1021 c
->mount_images
[i
].destination
,
1022 c
->mount_images
[i
].ignore_enoent
);
1025 r
= sd_bus_message_open_container(reply
, 'a', "(ss)");
1028 LIST_FOREACH(mount_options
, m
, c
->mount_images
[i
].mount_options
) {
1029 r
= sd_bus_message_append(reply
, "(ss)",
1030 partition_designator_to_string(m
->partition_designator
),
1035 r
= sd_bus_message_close_container(reply
);
1038 r
= sd_bus_message_close_container(reply
);
1043 return sd_bus_message_close_container(reply
);
1046 static int property_get_extension_images(
1049 const char *interface
,
1050 const char *property
,
1051 sd_bus_message
*reply
,
1053 sd_bus_error
*error
) {
1055 ExecContext
*c
= ASSERT_PTR(userdata
);
1062 r
= sd_bus_message_open_container(reply
, 'a', "(sba(ss))");
1066 for (size_t i
= 0; i
< c
->n_extension_images
; i
++) {
1067 r
= sd_bus_message_open_container(reply
, SD_BUS_TYPE_STRUCT
, "sba(ss)");
1070 r
= sd_bus_message_append(
1072 c
->extension_images
[i
].source
,
1073 c
->extension_images
[i
].ignore_enoent
);
1076 r
= sd_bus_message_open_container(reply
, 'a', "(ss)");
1079 LIST_FOREACH(mount_options
, m
, c
->extension_images
[i
].mount_options
) {
1080 r
= sd_bus_message_append(reply
, "(ss)",
1081 partition_designator_to_string(m
->partition_designator
),
1086 r
= sd_bus_message_close_container(reply
);
1089 r
= sd_bus_message_close_container(reply
);
1094 return sd_bus_message_close_container(reply
);
1097 static int bus_property_get_exec_dir(
1100 const char *interface
,
1101 const char *property
,
1102 sd_bus_message
*reply
,
1104 sd_bus_error
*error
) {
1106 ExecDirectory
*d
= ASSERT_PTR(userdata
);
1113 r
= sd_bus_message_open_container(reply
, 'a', "s");
1117 for (size_t i
= 0; i
< d
->n_items
; i
++) {
1118 r
= sd_bus_message_append_basic(reply
, 's', d
->items
[i
].path
);
1123 return sd_bus_message_close_container(reply
);
1126 static int bus_property_get_exec_dir_symlink(
1129 const char *interface
,
1130 const char *property
,
1131 sd_bus_message
*reply
,
1133 sd_bus_error
*error
) {
1135 ExecDirectory
*d
= ASSERT_PTR(userdata
);
1142 r
= sd_bus_message_open_container(reply
, 'a', "(sst)");
1146 for (size_t i
= 0; i
< d
->n_items
; i
++)
1147 STRV_FOREACH(dst
, d
->items
[i
].symlinks
) {
1148 r
= sd_bus_message_append(reply
, "(sst)", d
->items
[i
].path
, *dst
, 0 /* flags, unused for now */);
1153 return sd_bus_message_close_container(reply
);
1156 static int property_get_image_policy(
1159 const char *interface
,
1160 const char *property
,
1161 sd_bus_message
*reply
,
1163 sd_bus_error
*error
) {
1165 ImagePolicy
**pp
= ASSERT_PTR(userdata
);
1166 _cleanup_free_
char *s
= NULL
;
1173 r
= image_policy_to_string(*pp
?: &image_policy_service
, /* simplify= */ true, &s
);
1177 return sd_bus_message_append(reply
, "s", s
);
1180 const sd_bus_vtable bus_exec_vtable
[] = {
1181 SD_BUS_VTABLE_START(0),
1182 SD_BUS_PROPERTY("Environment", "as", NULL
, offsetof(ExecContext
, environment
), SD_BUS_VTABLE_PROPERTY_CONST
),
1183 SD_BUS_PROPERTY("EnvironmentFiles", "a(sb)", property_get_environment_files
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1184 SD_BUS_PROPERTY("PassEnvironment", "as", NULL
, offsetof(ExecContext
, pass_environment
), SD_BUS_VTABLE_PROPERTY_CONST
),
1185 SD_BUS_PROPERTY("UnsetEnvironment", "as", NULL
, offsetof(ExecContext
, unset_environment
), SD_BUS_VTABLE_PROPERTY_CONST
),
1186 SD_BUS_PROPERTY("UMask", "u", bus_property_get_mode
, offsetof(ExecContext
, umask
), SD_BUS_VTABLE_PROPERTY_CONST
),
1187 SD_BUS_PROPERTY("LimitCPU", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_CPU
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1188 SD_BUS_PROPERTY("LimitCPUSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_CPU
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1189 SD_BUS_PROPERTY("LimitFSIZE", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_FSIZE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1190 SD_BUS_PROPERTY("LimitFSIZESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_FSIZE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1191 SD_BUS_PROPERTY("LimitDATA", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_DATA
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1192 SD_BUS_PROPERTY("LimitDATASoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_DATA
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1193 SD_BUS_PROPERTY("LimitSTACK", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_STACK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1194 SD_BUS_PROPERTY("LimitSTACKSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_STACK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1195 SD_BUS_PROPERTY("LimitCORE", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_CORE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1196 SD_BUS_PROPERTY("LimitCORESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_CORE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1197 SD_BUS_PROPERTY("LimitRSS", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RSS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1198 SD_BUS_PROPERTY("LimitRSSSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RSS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1199 SD_BUS_PROPERTY("LimitNOFILE", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NOFILE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1200 SD_BUS_PROPERTY("LimitNOFILESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NOFILE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1201 SD_BUS_PROPERTY("LimitAS", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_AS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1202 SD_BUS_PROPERTY("LimitASSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_AS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1203 SD_BUS_PROPERTY("LimitNPROC", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NPROC
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1204 SD_BUS_PROPERTY("LimitNPROCSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NPROC
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1205 SD_BUS_PROPERTY("LimitMEMLOCK", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_MEMLOCK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1206 SD_BUS_PROPERTY("LimitMEMLOCKSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_MEMLOCK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1207 SD_BUS_PROPERTY("LimitLOCKS", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_LOCKS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1208 SD_BUS_PROPERTY("LimitLOCKSSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_LOCKS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1209 SD_BUS_PROPERTY("LimitSIGPENDING", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_SIGPENDING
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1210 SD_BUS_PROPERTY("LimitSIGPENDINGSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_SIGPENDING
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1211 SD_BUS_PROPERTY("LimitMSGQUEUE", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_MSGQUEUE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1212 SD_BUS_PROPERTY("LimitMSGQUEUESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_MSGQUEUE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1213 SD_BUS_PROPERTY("LimitNICE", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NICE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1214 SD_BUS_PROPERTY("LimitNICESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NICE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1215 SD_BUS_PROPERTY("LimitRTPRIO", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RTPRIO
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1216 SD_BUS_PROPERTY("LimitRTPRIOSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RTPRIO
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1217 SD_BUS_PROPERTY("LimitRTTIME", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RTTIME
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1218 SD_BUS_PROPERTY("LimitRTTIMESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RTTIME
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1219 SD_BUS_PROPERTY("WorkingDirectory", "s", property_get_working_directory
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1220 SD_BUS_PROPERTY("RootDirectory", "s", NULL
, offsetof(ExecContext
, root_directory
), SD_BUS_VTABLE_PROPERTY_CONST
),
1221 SD_BUS_PROPERTY("RootImage", "s", NULL
, offsetof(ExecContext
, root_image
), SD_BUS_VTABLE_PROPERTY_CONST
),
1222 SD_BUS_PROPERTY("RootImageOptions", "a(ss)", property_get_root_image_options
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1223 SD_BUS_PROPERTY("RootHash", "ay", property_get_root_hash
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1224 SD_BUS_PROPERTY("RootHashPath", "s", NULL
, offsetof(ExecContext
, root_hash_path
), SD_BUS_VTABLE_PROPERTY_CONST
),
1225 SD_BUS_PROPERTY("RootHashSignature", "ay", property_get_root_hash_sig
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1226 SD_BUS_PROPERTY("RootHashSignaturePath", "s", NULL
, offsetof(ExecContext
, root_hash_sig_path
), SD_BUS_VTABLE_PROPERTY_CONST
),
1227 SD_BUS_PROPERTY("RootVerity", "s", NULL
, offsetof(ExecContext
, root_verity
), SD_BUS_VTABLE_PROPERTY_CONST
),
1228 SD_BUS_PROPERTY("RootEphemeral", "b", bus_property_get_bool
, offsetof(ExecContext
, root_ephemeral
), SD_BUS_VTABLE_PROPERTY_CONST
),
1229 SD_BUS_PROPERTY("ExtensionDirectories", "as", NULL
, offsetof(ExecContext
, extension_directories
), SD_BUS_VTABLE_PROPERTY_CONST
),
1230 SD_BUS_PROPERTY("ExtensionImages", "a(sba(ss))", property_get_extension_images
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1231 SD_BUS_PROPERTY("MountImages", "a(ssba(ss))", property_get_mount_images
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1232 SD_BUS_PROPERTY("OOMScoreAdjust", "i", property_get_oom_score_adjust
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1233 SD_BUS_PROPERTY("CoredumpFilter", "t", property_get_coredump_filter
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1234 SD_BUS_PROPERTY("Nice", "i", property_get_nice
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1235 SD_BUS_PROPERTY("IOSchedulingClass", "i", property_get_ioprio_class
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1236 SD_BUS_PROPERTY("IOSchedulingPriority", "i", property_get_ioprio_priority
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1237 SD_BUS_PROPERTY("CPUSchedulingPolicy", "i", property_get_cpu_sched_policy
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1238 SD_BUS_PROPERTY("CPUSchedulingPriority", "i", property_get_cpu_sched_priority
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1239 SD_BUS_PROPERTY("CPUAffinity", "ay", property_get_cpu_affinity
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1240 SD_BUS_PROPERTY("CPUAffinityFromNUMA", "b", property_get_cpu_affinity_from_numa
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1241 SD_BUS_PROPERTY("NUMAPolicy", "i", property_get_numa_policy
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1242 SD_BUS_PROPERTY("NUMAMask", "ay", property_get_numa_mask
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1243 SD_BUS_PROPERTY("TimerSlackNSec", "t", property_get_timer_slack_nsec
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1244 SD_BUS_PROPERTY("CPUSchedulingResetOnFork", "b", bus_property_get_bool
, offsetof(ExecContext
, cpu_sched_reset_on_fork
), SD_BUS_VTABLE_PROPERTY_CONST
),
1245 SD_BUS_PROPERTY("NonBlocking", "b", bus_property_get_bool
, offsetof(ExecContext
, non_blocking
), SD_BUS_VTABLE_PROPERTY_CONST
),
1246 SD_BUS_PROPERTY("StandardInput", "s", property_get_exec_input
, offsetof(ExecContext
, std_input
), SD_BUS_VTABLE_PROPERTY_CONST
),
1247 SD_BUS_PROPERTY("StandardInputFileDescriptorName", "s", property_get_stdio_fdname
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1248 SD_BUS_PROPERTY("StandardInputData", "ay", property_get_input_data
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1249 SD_BUS_PROPERTY("StandardOutput", "s", bus_property_get_exec_output
, offsetof(ExecContext
, std_output
), SD_BUS_VTABLE_PROPERTY_CONST
),
1250 SD_BUS_PROPERTY("StandardOutputFileDescriptorName", "s", property_get_stdio_fdname
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1251 SD_BUS_PROPERTY("StandardError", "s", bus_property_get_exec_output
, offsetof(ExecContext
, std_error
), SD_BUS_VTABLE_PROPERTY_CONST
),
1252 SD_BUS_PROPERTY("StandardErrorFileDescriptorName", "s", property_get_stdio_fdname
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1253 SD_BUS_PROPERTY("TTYPath", "s", NULL
, offsetof(ExecContext
, tty_path
), SD_BUS_VTABLE_PROPERTY_CONST
),
1254 SD_BUS_PROPERTY("TTYReset", "b", bus_property_get_bool
, offsetof(ExecContext
, tty_reset
), SD_BUS_VTABLE_PROPERTY_CONST
),
1255 SD_BUS_PROPERTY("TTYVHangup", "b", bus_property_get_bool
, offsetof(ExecContext
, tty_vhangup
), SD_BUS_VTABLE_PROPERTY_CONST
),
1256 SD_BUS_PROPERTY("TTYVTDisallocate", "b", bus_property_get_bool
, offsetof(ExecContext
, tty_vt_disallocate
), SD_BUS_VTABLE_PROPERTY_CONST
),
1257 SD_BUS_PROPERTY("TTYRows", "q", bus_property_get_unsigned
, offsetof(ExecContext
, tty_rows
), SD_BUS_VTABLE_PROPERTY_CONST
),
1258 SD_BUS_PROPERTY("TTYColumns", "q", bus_property_get_unsigned
, offsetof(ExecContext
, tty_cols
), SD_BUS_VTABLE_PROPERTY_CONST
),
1259 SD_BUS_PROPERTY("SyslogPriority", "i", bus_property_get_int
, offsetof(ExecContext
, syslog_priority
), SD_BUS_VTABLE_PROPERTY_CONST
),
1260 SD_BUS_PROPERTY("SyslogIdentifier", "s", NULL
, offsetof(ExecContext
, syslog_identifier
), SD_BUS_VTABLE_PROPERTY_CONST
),
1261 SD_BUS_PROPERTY("SyslogLevelPrefix", "b", bus_property_get_bool
, offsetof(ExecContext
, syslog_level_prefix
), SD_BUS_VTABLE_PROPERTY_CONST
),
1262 SD_BUS_PROPERTY("SyslogLevel", "i", property_get_syslog_level
, offsetof(ExecContext
, syslog_priority
), SD_BUS_VTABLE_PROPERTY_CONST
),
1263 SD_BUS_PROPERTY("SyslogFacility", "i", property_get_syslog_facility
, offsetof(ExecContext
, syslog_priority
), SD_BUS_VTABLE_PROPERTY_CONST
),
1264 SD_BUS_PROPERTY("LogLevelMax", "i", bus_property_get_int
, offsetof(ExecContext
, log_level_max
), SD_BUS_VTABLE_PROPERTY_CONST
),
1265 SD_BUS_PROPERTY("LogRateLimitIntervalUSec", "t", bus_property_get_usec
, offsetof(ExecContext
, log_ratelimit_interval_usec
), SD_BUS_VTABLE_PROPERTY_CONST
),
1266 SD_BUS_PROPERTY("LogRateLimitBurst", "u", bus_property_get_unsigned
, offsetof(ExecContext
, log_ratelimit_burst
), SD_BUS_VTABLE_PROPERTY_CONST
),
1267 SD_BUS_PROPERTY("LogExtraFields", "aay", property_get_log_extra_fields
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1268 SD_BUS_PROPERTY("LogFilterPatterns", "a(bs)", property_get_log_filter_patterns
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1269 SD_BUS_PROPERTY("LogNamespace", "s", NULL
, offsetof(ExecContext
, log_namespace
), SD_BUS_VTABLE_PROPERTY_CONST
),
1270 SD_BUS_PROPERTY("SecureBits", "i", bus_property_get_int
, offsetof(ExecContext
, secure_bits
), SD_BUS_VTABLE_PROPERTY_CONST
),
1271 SD_BUS_PROPERTY("CapabilityBoundingSet", "t", NULL
, offsetof(ExecContext
, capability_bounding_set
), SD_BUS_VTABLE_PROPERTY_CONST
),
1272 SD_BUS_PROPERTY("AmbientCapabilities", "t", NULL
, offsetof(ExecContext
, capability_ambient_set
), SD_BUS_VTABLE_PROPERTY_CONST
),
1273 SD_BUS_PROPERTY("User", "s", NULL
, offsetof(ExecContext
, user
), SD_BUS_VTABLE_PROPERTY_CONST
),
1274 SD_BUS_PROPERTY("Group", "s", NULL
, offsetof(ExecContext
, group
), SD_BUS_VTABLE_PROPERTY_CONST
),
1275 SD_BUS_PROPERTY("DynamicUser", "b", bus_property_get_bool
, offsetof(ExecContext
, dynamic_user
), SD_BUS_VTABLE_PROPERTY_CONST
),
1276 SD_BUS_PROPERTY("RemoveIPC", "b", bus_property_get_bool
, offsetof(ExecContext
, remove_ipc
), SD_BUS_VTABLE_PROPERTY_CONST
),
1277 SD_BUS_PROPERTY("SetCredential", "a(say)", property_get_set_credential
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1278 SD_BUS_PROPERTY("SetCredentialEncrypted", "a(say)", property_get_set_credential
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1279 SD_BUS_PROPERTY("LoadCredential", "a(ss)", property_get_load_credential
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1280 SD_BUS_PROPERTY("LoadCredentialEncrypted", "a(ss)", property_get_load_credential
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1281 SD_BUS_PROPERTY("ImportCredential", "as", bus_property_get_string_set
, offsetof(ExecContext
, import_credentials
), SD_BUS_VTABLE_PROPERTY_CONST
),
1282 SD_BUS_PROPERTY("SupplementaryGroups", "as", NULL
, offsetof(ExecContext
, supplementary_groups
), SD_BUS_VTABLE_PROPERTY_CONST
),
1283 SD_BUS_PROPERTY("PAMName", "s", NULL
, offsetof(ExecContext
, pam_name
), SD_BUS_VTABLE_PROPERTY_CONST
),
1284 SD_BUS_PROPERTY("ReadWritePaths", "as", NULL
, offsetof(ExecContext
, read_write_paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
1285 SD_BUS_PROPERTY("ReadOnlyPaths", "as", NULL
, offsetof(ExecContext
, read_only_paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
1286 SD_BUS_PROPERTY("InaccessiblePaths", "as", NULL
, offsetof(ExecContext
, inaccessible_paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
1287 SD_BUS_PROPERTY("ExecPaths", "as", NULL
, offsetof(ExecContext
, exec_paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
1288 SD_BUS_PROPERTY("NoExecPaths", "as", NULL
, offsetof(ExecContext
, no_exec_paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
1289 SD_BUS_PROPERTY("ExecSearchPath", "as", NULL
, offsetof(ExecContext
, exec_search_path
), SD_BUS_VTABLE_PROPERTY_CONST
),
1290 SD_BUS_PROPERTY("MountFlags", "t", bus_property_get_ulong
, offsetof(ExecContext
, mount_propagation_flag
), SD_BUS_VTABLE_PROPERTY_CONST
),
1291 SD_BUS_PROPERTY("PrivateTmp", "b", bus_property_get_bool
, offsetof(ExecContext
, private_tmp
), SD_BUS_VTABLE_PROPERTY_CONST
),
1292 SD_BUS_PROPERTY("PrivateDevices", "b", bus_property_get_bool
, offsetof(ExecContext
, private_devices
), SD_BUS_VTABLE_PROPERTY_CONST
),
1293 SD_BUS_PROPERTY("ProtectClock", "b", bus_property_get_bool
, offsetof(ExecContext
, protect_clock
), SD_BUS_VTABLE_PROPERTY_CONST
),
1294 SD_BUS_PROPERTY("ProtectKernelTunables", "b", bus_property_get_bool
, offsetof(ExecContext
, protect_kernel_tunables
), SD_BUS_VTABLE_PROPERTY_CONST
),
1295 SD_BUS_PROPERTY("ProtectKernelModules", "b", bus_property_get_bool
, offsetof(ExecContext
, protect_kernel_modules
), SD_BUS_VTABLE_PROPERTY_CONST
),
1296 SD_BUS_PROPERTY("ProtectKernelLogs", "b", bus_property_get_bool
, offsetof(ExecContext
, protect_kernel_logs
), SD_BUS_VTABLE_PROPERTY_CONST
),
1297 SD_BUS_PROPERTY("ProtectControlGroups", "b", bus_property_get_bool
, offsetof(ExecContext
, protect_control_groups
), SD_BUS_VTABLE_PROPERTY_CONST
),
1298 SD_BUS_PROPERTY("PrivateNetwork", "b", bus_property_get_bool
, offsetof(ExecContext
, private_network
), SD_BUS_VTABLE_PROPERTY_CONST
),
1299 SD_BUS_PROPERTY("PrivateUsers", "b", bus_property_get_bool
, offsetof(ExecContext
, private_users
), SD_BUS_VTABLE_PROPERTY_CONST
),
1300 SD_BUS_PROPERTY("PrivateMounts", "b", bus_property_get_tristate
, offsetof(ExecContext
, private_mounts
), SD_BUS_VTABLE_PROPERTY_CONST
),
1301 SD_BUS_PROPERTY("PrivateIPC", "b", bus_property_get_bool
, offsetof(ExecContext
, private_ipc
), SD_BUS_VTABLE_PROPERTY_CONST
),
1302 SD_BUS_PROPERTY("ProtectHome", "s", property_get_protect_home
, offsetof(ExecContext
, protect_home
), SD_BUS_VTABLE_PROPERTY_CONST
),
1303 SD_BUS_PROPERTY("ProtectSystem", "s", property_get_protect_system
, offsetof(ExecContext
, protect_system
), SD_BUS_VTABLE_PROPERTY_CONST
),
1304 SD_BUS_PROPERTY("SameProcessGroup", "b", bus_property_get_bool
, offsetof(ExecContext
, same_pgrp
), SD_BUS_VTABLE_PROPERTY_CONST
),
1305 SD_BUS_PROPERTY("UtmpIdentifier", "s", NULL
, offsetof(ExecContext
, utmp_id
), SD_BUS_VTABLE_PROPERTY_CONST
),
1306 SD_BUS_PROPERTY("UtmpMode", "s", property_get_exec_utmp_mode
, offsetof(ExecContext
, utmp_mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
1307 SD_BUS_PROPERTY("SELinuxContext", "(bs)", property_get_selinux_context
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1308 SD_BUS_PROPERTY("AppArmorProfile", "(bs)", property_get_apparmor_profile
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1309 SD_BUS_PROPERTY("SmackProcessLabel", "(bs)", property_get_smack_process_label
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1310 SD_BUS_PROPERTY("IgnoreSIGPIPE", "b", bus_property_get_bool
, offsetof(ExecContext
, ignore_sigpipe
), SD_BUS_VTABLE_PROPERTY_CONST
),
1311 SD_BUS_PROPERTY("NoNewPrivileges", "b", bus_property_get_bool
, offsetof(ExecContext
, no_new_privileges
), SD_BUS_VTABLE_PROPERTY_CONST
),
1312 SD_BUS_PROPERTY("SystemCallFilter", "(bas)", property_get_syscall_filter
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1313 SD_BUS_PROPERTY("SystemCallArchitectures", "as", property_get_syscall_archs
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1314 SD_BUS_PROPERTY("SystemCallErrorNumber", "i", bus_property_get_int
, offsetof(ExecContext
, syscall_errno
), SD_BUS_VTABLE_PROPERTY_CONST
),
1315 SD_BUS_PROPERTY("SystemCallLog", "(bas)", property_get_syscall_log
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1316 SD_BUS_PROPERTY("Personality", "s", property_get_personality
, offsetof(ExecContext
, personality
), SD_BUS_VTABLE_PROPERTY_CONST
),
1317 SD_BUS_PROPERTY("LockPersonality", "b", bus_property_get_bool
, offsetof(ExecContext
, lock_personality
), SD_BUS_VTABLE_PROPERTY_CONST
),
1318 SD_BUS_PROPERTY("RestrictAddressFamilies", "(bas)", property_get_address_families
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1319 SD_BUS_PROPERTY("RuntimeDirectorySymlink", "a(sst)", bus_property_get_exec_dir_symlink
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_RUNTIME
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1320 SD_BUS_PROPERTY("RuntimeDirectoryPreserve", "s", bus_property_get_exec_preserve_mode
, offsetof(ExecContext
, runtime_directory_preserve_mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
1321 SD_BUS_PROPERTY("RuntimeDirectoryMode", "u", bus_property_get_mode
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_RUNTIME
].mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
1322 SD_BUS_PROPERTY("RuntimeDirectory", "as", bus_property_get_exec_dir
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_RUNTIME
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1323 SD_BUS_PROPERTY("StateDirectorySymlink", "a(sst)", bus_property_get_exec_dir_symlink
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_STATE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1324 SD_BUS_PROPERTY("StateDirectoryMode", "u", bus_property_get_mode
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_STATE
].mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
1325 SD_BUS_PROPERTY("StateDirectory", "as", bus_property_get_exec_dir
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_STATE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1326 SD_BUS_PROPERTY("CacheDirectorySymlink", "a(sst)", bus_property_get_exec_dir_symlink
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_CACHE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1327 SD_BUS_PROPERTY("CacheDirectoryMode", "u", bus_property_get_mode
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_CACHE
].mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
1328 SD_BUS_PROPERTY("CacheDirectory", "as", bus_property_get_exec_dir
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_CACHE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1329 SD_BUS_PROPERTY("LogsDirectorySymlink", "a(sst)", bus_property_get_exec_dir_symlink
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_LOGS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1330 SD_BUS_PROPERTY("LogsDirectoryMode", "u", bus_property_get_mode
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_LOGS
].mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
1331 SD_BUS_PROPERTY("LogsDirectory", "as", bus_property_get_exec_dir
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_LOGS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1332 SD_BUS_PROPERTY("ConfigurationDirectoryMode", "u", bus_property_get_mode
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_CONFIGURATION
].mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
1333 SD_BUS_PROPERTY("ConfigurationDirectory", "as", bus_property_get_exec_dir
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_CONFIGURATION
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1334 SD_BUS_PROPERTY("TimeoutCleanUSec", "t", bus_property_get_usec
, offsetof(ExecContext
, timeout_clean_usec
), SD_BUS_VTABLE_PROPERTY_CONST
),
1335 SD_BUS_PROPERTY("MemoryDenyWriteExecute", "b", bus_property_get_bool
, offsetof(ExecContext
, memory_deny_write_execute
), SD_BUS_VTABLE_PROPERTY_CONST
),
1336 SD_BUS_PROPERTY("RestrictRealtime", "b", bus_property_get_bool
, offsetof(ExecContext
, restrict_realtime
), SD_BUS_VTABLE_PROPERTY_CONST
),
1337 SD_BUS_PROPERTY("RestrictSUIDSGID", "b", bus_property_get_bool
, offsetof(ExecContext
, restrict_suid_sgid
), SD_BUS_VTABLE_PROPERTY_CONST
),
1338 SD_BUS_PROPERTY("RestrictNamespaces", "t", bus_property_get_ulong
, offsetof(ExecContext
, restrict_namespaces
), SD_BUS_VTABLE_PROPERTY_CONST
),
1339 SD_BUS_PROPERTY("RestrictFileSystems", "(bas)", property_get_restrict_filesystems
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1340 SD_BUS_PROPERTY("BindPaths", "a(ssbt)", property_get_bind_paths
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1341 SD_BUS_PROPERTY("BindReadOnlyPaths", "a(ssbt)", property_get_bind_paths
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1342 SD_BUS_PROPERTY("TemporaryFileSystem", "a(ss)", property_get_temporary_filesystems
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1343 SD_BUS_PROPERTY("MountAPIVFS", "b", property_get_mount_apivfs
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1344 SD_BUS_PROPERTY("KeyringMode", "s", property_get_exec_keyring_mode
, offsetof(ExecContext
, keyring_mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
1345 SD_BUS_PROPERTY("ProtectProc", "s", property_get_protect_proc
, offsetof(ExecContext
, protect_proc
), SD_BUS_VTABLE_PROPERTY_CONST
),
1346 SD_BUS_PROPERTY("ProcSubset", "s", property_get_proc_subset
, offsetof(ExecContext
, proc_subset
), SD_BUS_VTABLE_PROPERTY_CONST
),
1347 SD_BUS_PROPERTY("ProtectHostname", "b", bus_property_get_bool
, offsetof(ExecContext
, protect_hostname
), SD_BUS_VTABLE_PROPERTY_CONST
),
1348 SD_BUS_PROPERTY("MemoryKSM", "b", bus_property_get_tristate
, offsetof(ExecContext
, memory_ksm
), SD_BUS_VTABLE_PROPERTY_CONST
),
1349 SD_BUS_PROPERTY("NetworkNamespacePath", "s", NULL
, offsetof(ExecContext
, network_namespace_path
), SD_BUS_VTABLE_PROPERTY_CONST
),
1350 SD_BUS_PROPERTY("IPCNamespacePath", "s", NULL
, offsetof(ExecContext
, ipc_namespace_path
), SD_BUS_VTABLE_PROPERTY_CONST
),
1351 SD_BUS_PROPERTY("RootImagePolicy", "s", property_get_image_policy
, offsetof(ExecContext
, root_image_policy
), SD_BUS_VTABLE_PROPERTY_CONST
),
1352 SD_BUS_PROPERTY("MountImagePolicy", "s", property_get_image_policy
, offsetof(ExecContext
, mount_image_policy
), SD_BUS_VTABLE_PROPERTY_CONST
),
1353 SD_BUS_PROPERTY("ExtensionImagePolicy", "s", property_get_image_policy
, offsetof(ExecContext
, extension_image_policy
), SD_BUS_VTABLE_PROPERTY_CONST
),
1355 /* Obsolete/redundant properties: */
1356 SD_BUS_PROPERTY("Capabilities", "s", property_get_empty_string
, 0, SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
1357 SD_BUS_PROPERTY("ReadWriteDirectories", "as", NULL
, offsetof(ExecContext
, read_write_paths
), SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
1358 SD_BUS_PROPERTY("ReadOnlyDirectories", "as", NULL
, offsetof(ExecContext
, read_only_paths
), SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
1359 SD_BUS_PROPERTY("InaccessibleDirectories", "as", NULL
, offsetof(ExecContext
, inaccessible_paths
), SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
1360 SD_BUS_PROPERTY("IOScheduling", "i", property_get_ioprio
, 0, SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
1365 static int append_exec_command(sd_bus_message
*reply
, ExecCommand
*c
) {
1374 r
= sd_bus_message_open_container(reply
, 'r', "sasbttttuii");
1378 r
= sd_bus_message_append(reply
, "s", c
->path
);
1382 r
= sd_bus_message_append_strv(reply
, c
->argv
);
1386 r
= sd_bus_message_append(reply
, "bttttuii",
1387 !!(c
->flags
& EXEC_COMMAND_IGNORE_FAILURE
),
1388 c
->exec_status
.start_timestamp
.realtime
,
1389 c
->exec_status
.start_timestamp
.monotonic
,
1390 c
->exec_status
.exit_timestamp
.realtime
,
1391 c
->exec_status
.exit_timestamp
.monotonic
,
1392 (uint32_t) c
->exec_status
.pid
,
1393 (int32_t) c
->exec_status
.code
,
1394 (int32_t) c
->exec_status
.status
);
1398 return sd_bus_message_close_container(reply
);
1401 static int append_exec_ex_command(sd_bus_message
*reply
, ExecCommand
*c
) {
1402 _cleanup_strv_free_
char **ex_opts
= NULL
;
1411 r
= sd_bus_message_open_container(reply
, 'r', "sasasttttuii");
1415 r
= sd_bus_message_append(reply
, "s", c
->path
);
1419 r
= sd_bus_message_append_strv(reply
, c
->argv
);
1423 r
= exec_command_flags_to_strv(c
->flags
, &ex_opts
);
1427 r
= sd_bus_message_append_strv(reply
, ex_opts
);
1431 r
= sd_bus_message_append(reply
, "ttttuii",
1432 c
->exec_status
.start_timestamp
.realtime
,
1433 c
->exec_status
.start_timestamp
.monotonic
,
1434 c
->exec_status
.exit_timestamp
.realtime
,
1435 c
->exec_status
.exit_timestamp
.monotonic
,
1436 (uint32_t) c
->exec_status
.pid
,
1437 (int32_t) c
->exec_status
.code
,
1438 (int32_t) c
->exec_status
.status
);
1442 return sd_bus_message_close_container(reply
);
1445 int bus_property_get_exec_command(
1448 const char *interface
,
1449 const char *property
,
1450 sd_bus_message
*reply
,
1452 sd_bus_error
*ret_error
) {
1454 ExecCommand
*c
= (ExecCommand
*) userdata
;
1460 r
= sd_bus_message_open_container(reply
, 'a', "(sasbttttuii)");
1464 r
= append_exec_command(reply
, c
);
1468 return sd_bus_message_close_container(reply
);
1471 int bus_property_get_exec_command_list(
1474 const char *interface
,
1475 const char *property
,
1476 sd_bus_message
*reply
,
1478 sd_bus_error
*ret_error
) {
1480 ExecCommand
*exec_command
= *(ExecCommand
**) userdata
;
1486 r
= sd_bus_message_open_container(reply
, 'a', "(sasbttttuii)");
1490 LIST_FOREACH(command
, c
, exec_command
) {
1491 r
= append_exec_command(reply
, c
);
1496 return sd_bus_message_close_container(reply
);
1499 int bus_property_get_exec_ex_command_list(
1502 const char *interface
,
1503 const char *property
,
1504 sd_bus_message
*reply
,
1506 sd_bus_error
*ret_error
) {
1508 ExecCommand
*exec_command
= *(ExecCommand
**) userdata
;
1514 r
= sd_bus_message_open_container(reply
, 'a', "(sasasttttuii)");
1518 LIST_FOREACH(command
, c
, exec_command
) {
1519 r
= append_exec_ex_command(reply
, c
);
1524 return sd_bus_message_close_container(reply
);
1527 static char *exec_command_flags_to_exec_chars(ExecCommandFlags flags
) {
1528 return strjoin(FLAGS_SET(flags
, EXEC_COMMAND_IGNORE_FAILURE
) ? "-" : "",
1529 FLAGS_SET(flags
, EXEC_COMMAND_NO_ENV_EXPAND
) ? ":" : "",
1530 FLAGS_SET(flags
, EXEC_COMMAND_FULLY_PRIVILEGED
) ? "+" : "",
1531 FLAGS_SET(flags
, EXEC_COMMAND_NO_SETUID
) ? "!" : "",
1532 FLAGS_SET(flags
, EXEC_COMMAND_AMBIENT_MAGIC
) ? "!!" : "");
1535 int bus_set_transient_exec_command(
1538 ExecCommand
**exec_command
,
1539 sd_bus_message
*message
,
1540 UnitWriteFlags flags
,
1541 sd_bus_error
*error
) {
1542 bool is_ex_prop
= endswith(name
, "Ex");
1546 /* Drop Ex from the written setting. E.g. ExecStart=, not ExecStartEx=. */
1547 const char *written_name
= is_ex_prop
? strndupa(name
, strlen(name
) - 2) : name
;
1549 r
= sd_bus_message_enter_container(message
, 'a', is_ex_prop
? "(sasas)" : "(sasb)");
1553 while ((r
= sd_bus_message_enter_container(message
, 'r', is_ex_prop
? "sasas" : "sasb")) > 0) {
1554 _cleanup_strv_free_
char **argv
= NULL
, **ex_opts
= NULL
;
1558 r
= sd_bus_message_read(message
, "s", &path
);
1562 if (!path_is_absolute(path
) && !filename_is_valid(path
))
1563 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
,
1564 "\"%s\" is neither a valid executable name nor an absolute path",
1567 r
= sd_bus_message_read_strv(message
, &argv
);
1571 if (strv_isempty(argv
))
1572 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
,
1573 "\"%s\" argv cannot be empty", name
);
1575 r
= is_ex_prop
? sd_bus_message_read_strv(message
, &ex_opts
) : sd_bus_message_read(message
, "b", &b
);
1579 r
= sd_bus_message_exit_container(message
);
1583 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1586 c
= new0(ExecCommand
, 1);
1590 c
->path
= strdup(path
);
1596 c
->argv
= TAKE_PTR(argv
);
1599 r
= exec_command_flags_from_strv(ex_opts
, &c
->flags
);
1603 c
->flags
= b
? EXEC_COMMAND_IGNORE_FAILURE
: 0;
1605 path_simplify(c
->path
);
1606 exec_command_append_list(exec_command
, c
);
1614 r
= sd_bus_message_exit_container(message
);
1618 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1619 _cleanup_(memstream_done
) MemStream m
= {};
1620 _cleanup_free_
char *buf
= NULL
;
1624 *exec_command
= exec_command_free_list(*exec_command
);
1626 f
= memstream_init(&m
);
1630 fprintf(f
, "%s=\n", written_name
);
1632 LIST_FOREACH(command
, c
, *exec_command
) {
1633 _cleanup_free_
char *a
= NULL
, *exec_chars
= NULL
;
1634 UnitWriteFlags esc_flags
= UNIT_ESCAPE_SPECIFIERS
|
1635 (FLAGS_SET(c
->flags
, EXEC_COMMAND_NO_ENV_EXPAND
) ? UNIT_ESCAPE_EXEC_SYNTAX
: UNIT_ESCAPE_EXEC_SYNTAX_ENV
);
1637 exec_chars
= exec_command_flags_to_exec_chars(c
->flags
);
1641 a
= unit_concat_strv(c
->argv
, esc_flags
);
1645 if (streq_ptr(c
->path
, c
->argv
? c
->argv
[0] : NULL
))
1646 fprintf(f
, "%s=%s%s\n", written_name
, exec_chars
, a
);
1648 _cleanup_free_
char *t
= NULL
;
1651 p
= unit_escape_setting(c
->path
, esc_flags
, &t
);
1655 fprintf(f
, "%s=%s@%s %s\n", written_name
, exec_chars
, p
, a
);
1659 r
= memstream_finalize(&m
, &buf
, NULL
);
1663 unit_write_setting(u
, flags
, written_name
, buf
);
1669 static int parse_personality(const char *s
, unsigned long *p
) {
1674 v
= personality_from_string(s
);
1675 if (v
== PERSONALITY_INVALID
)
1682 static const char* mount_propagation_flag_to_string_with_check(unsigned long n
) {
1683 if (!mount_propagation_flag_is_valid(n
))
1686 return mount_propagation_flag_to_string(n
);
1689 static BUS_DEFINE_SET_TRANSIENT(nsec
, "t", uint64_t, nsec_t
, NSEC_FMT
);
1690 static BUS_DEFINE_SET_TRANSIENT_IS_VALID(log_level
, "i", int32_t, int, "%" PRIi32
, log_level_is_valid
);
1692 static BUS_DEFINE_SET_TRANSIENT_IS_VALID(errno
, "i", int32_t, int, "%" PRIi32
, seccomp_errno_or_action_is_valid
);
1694 static BUS_DEFINE_SET_TRANSIENT_PARSE(std_input
, ExecInput
, exec_input_from_string
);
1695 static BUS_DEFINE_SET_TRANSIENT_PARSE(std_output
, ExecOutput
, exec_output_from_string
);
1696 static BUS_DEFINE_SET_TRANSIENT_PARSE(utmp_mode
, ExecUtmpMode
, exec_utmp_mode_from_string
);
1697 static BUS_DEFINE_SET_TRANSIENT_PARSE(protect_system
, ProtectSystem
, protect_system_from_string
);
1698 static BUS_DEFINE_SET_TRANSIENT_PARSE(protect_home
, ProtectHome
, protect_home_from_string
);
1699 static BUS_DEFINE_SET_TRANSIENT_PARSE(keyring_mode
, ExecKeyringMode
, exec_keyring_mode_from_string
);
1700 static BUS_DEFINE_SET_TRANSIENT_PARSE(protect_proc
, ProtectProc
, protect_proc_from_string
);
1701 static BUS_DEFINE_SET_TRANSIENT_PARSE(proc_subset
, ProcSubset
, proc_subset_from_string
);
1702 BUS_DEFINE_SET_TRANSIENT_PARSE(exec_preserve_mode
, ExecPreserveMode
, exec_preserve_mode_from_string
);
1703 static BUS_DEFINE_SET_TRANSIENT_PARSE_PTR(personality
, unsigned long, parse_personality
);
1704 static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(secure_bits
, "i", int32_t, int, "%" PRIi32
, secure_bits_to_string_alloc_with_check
);
1705 static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(capability
, "t", uint64_t, uint64_t, "%" PRIu64
, capability_set_to_string
);
1706 static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(namespace_flag
, "t", uint64_t, unsigned long, "%" PRIu64
, namespace_flags_to_string
);
1707 static BUS_DEFINE_SET_TRANSIENT_TO_STRING(mount_propagation_flag
, "t", uint64_t, unsigned long, "%" PRIu64
, mount_propagation_flag_to_string_with_check
);
1709 int bus_exec_context_set_transient_property(
1713 sd_bus_message
*message
,
1714 UnitWriteFlags flags
,
1715 sd_bus_error
*error
) {
1725 flags
|= UNIT_PRIVATE
;
1727 if (streq(name
, "User"))
1728 return bus_set_transient_user_relaxed(u
, name
, &c
->user
, message
, flags
, error
);
1730 if (streq(name
, "Group"))
1731 return bus_set_transient_user_relaxed(u
, name
, &c
->group
, message
, flags
, error
);
1733 if (streq(name
, "TTYPath"))
1734 return bus_set_transient_path(u
, name
, &c
->tty_path
, message
, flags
, error
);
1736 if (streq(name
, "RootImage"))
1737 return bus_set_transient_path(u
, name
, &c
->root_image
, message
, flags
, error
);
1739 if (streq(name
, "RootImageOptions")) {
1740 _cleanup_(mount_options_free_allp
) MountOptions
*options
= NULL
;
1741 _cleanup_free_
char *format_str
= NULL
;
1743 r
= bus_read_mount_options(message
, error
, &options
, &format_str
, " ");
1747 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1749 LIST_JOIN(mount_options
, c
->root_image_options
, options
);
1750 unit_write_settingf(
1751 u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
,
1756 c
->root_image_options
= mount_options_free_all(c
->root_image_options
);
1757 unit_write_settingf(u
, flags
, name
, "%s=", name
);
1764 if (streq(name
, "RootHash")) {
1765 const void *roothash_decoded
;
1766 size_t roothash_decoded_size
;
1768 r
= sd_bus_message_read_array(message
, 'y', &roothash_decoded
, &roothash_decoded_size
);
1772 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1773 _cleanup_free_
char *encoded
= NULL
;
1775 if (roothash_decoded_size
== 0) {
1776 c
->root_hash_path
= mfree(c
->root_hash_path
);
1777 c
->root_hash
= mfree(c
->root_hash
);
1778 c
->root_hash_size
= 0;
1780 unit_write_settingf(u
, flags
, name
, "RootHash=");
1782 _cleanup_free_
void *p
= NULL
;
1784 encoded
= hexmem(roothash_decoded
, roothash_decoded_size
);
1788 p
= memdup(roothash_decoded
, roothash_decoded_size
);
1792 free_and_replace(c
->root_hash
, p
);
1793 c
->root_hash_size
= roothash_decoded_size
;
1794 c
->root_hash_path
= mfree(c
->root_hash_path
);
1796 unit_write_settingf(u
, flags
, name
, "RootHash=%s", encoded
);
1803 if (streq(name
, "RootHashPath")) {
1804 c
->root_hash_size
= 0;
1805 c
->root_hash
= mfree(c
->root_hash
);
1807 return bus_set_transient_path(u
, "RootHash", &c
->root_hash_path
, message
, flags
, error
);
1810 if (streq(name
, "RootHashSignature")) {
1811 const void *roothash_sig_decoded
;
1812 size_t roothash_sig_decoded_size
;
1814 r
= sd_bus_message_read_array(message
, 'y', &roothash_sig_decoded
, &roothash_sig_decoded_size
);
1818 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1819 _cleanup_free_
char *encoded
= NULL
;
1821 if (roothash_sig_decoded_size
== 0) {
1822 c
->root_hash_sig_path
= mfree(c
->root_hash_sig_path
);
1823 c
->root_hash_sig
= mfree(c
->root_hash_sig
);
1824 c
->root_hash_sig_size
= 0;
1826 unit_write_settingf(u
, flags
, name
, "RootHashSignature=");
1828 _cleanup_free_
void *p
= NULL
;
1831 len
= base64mem(roothash_sig_decoded
, roothash_sig_decoded_size
, &encoded
);
1835 p
= memdup(roothash_sig_decoded
, roothash_sig_decoded_size
);
1839 free_and_replace(c
->root_hash_sig
, p
);
1840 c
->root_hash_sig_size
= roothash_sig_decoded_size
;
1841 c
->root_hash_sig_path
= mfree(c
->root_hash_sig_path
);
1843 unit_write_settingf(u
, flags
, name
, "RootHashSignature=base64:%s", encoded
);
1850 if (streq(name
, "RootHashSignaturePath")) {
1851 c
->root_hash_sig_size
= 0;
1852 c
->root_hash_sig
= mfree(c
->root_hash_sig
);
1854 return bus_set_transient_path(u
, "RootHashSignature", &c
->root_hash_sig_path
, message
, flags
, error
);
1857 if (streq(name
, "RootVerity"))
1858 return bus_set_transient_path(u
, name
, &c
->root_verity
, message
, flags
, error
);
1860 if (streq(name
, "RootDirectory"))
1861 return bus_set_transient_path(u
, name
, &c
->root_directory
, message
, flags
, error
);
1863 if (streq(name
, "RootEphemeral"))
1864 return bus_set_transient_bool(u
, name
, &c
->root_ephemeral
, message
, flags
, error
);
1866 if (streq(name
, "SyslogIdentifier"))
1867 return bus_set_transient_string(u
, name
, &c
->syslog_identifier
, message
, flags
, error
);
1869 if (streq(name
, "LogLevelMax"))
1870 return bus_set_transient_log_level(u
, name
, &c
->log_level_max
, message
, flags
, error
);
1872 if (streq(name
, "LogRateLimitIntervalUSec"))
1873 return bus_set_transient_usec(u
, name
, &c
->log_ratelimit_interval_usec
, message
, flags
, error
);
1875 if (streq(name
, "LogRateLimitBurst"))
1876 return bus_set_transient_unsigned(u
, name
, &c
->log_ratelimit_burst
, message
, flags
, error
);
1878 if (streq(name
, "LogFilterPatterns")) {
1879 /* Use _cleanup_free_, not _cleanup_strv_free_, as we don't want the content of the strv
1881 _cleanup_free_
char **allow_list
= NULL
, **deny_list
= NULL
;
1882 const char *pattern
;
1885 r
= sd_bus_message_enter_container(message
, 'a', "(bs)");
1889 while ((r
= sd_bus_message_read(message
, "(bs)", &is_allowlist
, &pattern
)) > 0) {
1890 _cleanup_(pattern_freep
) pcre2_code
*compiled_pattern
= NULL
;
1892 if (isempty(pattern
))
1895 r
= pattern_compile_and_log(pattern
, 0, &compiled_pattern
);
1899 r
= strv_push(is_allowlist
? &allow_list
: &deny_list
, (char *)pattern
);
1906 r
= sd_bus_message_exit_container(message
);
1910 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1911 if (strv_isempty(allow_list
) && strv_isempty(deny_list
)) {
1912 c
->log_filter_allowed_patterns
= set_free_free(c
->log_filter_allowed_patterns
);
1913 c
->log_filter_denied_patterns
= set_free_free(c
->log_filter_denied_patterns
);
1914 unit_write_settingf(u
, flags
, name
, "%s=", name
);
1916 r
= set_put_strdupv(&c
->log_filter_allowed_patterns
, allow_list
);
1919 r
= set_put_strdupv(&c
->log_filter_denied_patterns
, deny_list
);
1923 STRV_FOREACH(unit_pattern
, allow_list
)
1924 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, *unit_pattern
);
1925 STRV_FOREACH(unit_pattern
, deny_list
)
1926 unit_write_settingf(u
, flags
, name
, "%s=~%s", name
, *unit_pattern
);
1933 if (streq(name
, "Personality"))
1934 return bus_set_transient_personality(u
, name
, &c
->personality
, message
, flags
, error
);
1936 if (streq(name
, "StandardInput"))
1937 return bus_set_transient_std_input(u
, name
, &c
->std_input
, message
, flags
, error
);
1939 if (streq(name
, "StandardOutput"))
1940 return bus_set_transient_std_output(u
, name
, &c
->std_output
, message
, flags
, error
);
1942 if (streq(name
, "StandardError"))
1943 return bus_set_transient_std_output(u
, name
, &c
->std_error
, message
, flags
, error
);
1945 if (streq(name
, "IgnoreSIGPIPE"))
1946 return bus_set_transient_bool(u
, name
, &c
->ignore_sigpipe
, message
, flags
, error
);
1948 if (streq(name
, "TTYVHangup"))
1949 return bus_set_transient_bool(u
, name
, &c
->tty_vhangup
, message
, flags
, error
);
1951 if (streq(name
, "TTYReset"))
1952 return bus_set_transient_bool(u
, name
, &c
->tty_reset
, message
, flags
, error
);
1954 if (streq(name
, "TTYVTDisallocate"))
1955 return bus_set_transient_bool(u
, name
, &c
->tty_vt_disallocate
, message
, flags
, error
);
1957 if (streq(name
, "TTYRows"))
1958 return bus_set_transient_unsigned(u
, name
, &c
->tty_rows
, message
, flags
, error
);
1960 if (streq(name
, "TTYColumns"))
1961 return bus_set_transient_unsigned(u
, name
, &c
->tty_cols
, message
, flags
, error
);
1963 if (streq(name
, "PrivateTmp"))
1964 return bus_set_transient_bool(u
, name
, &c
->private_tmp
, message
, flags
, error
);
1966 if (streq(name
, "PrivateDevices"))
1967 return bus_set_transient_bool(u
, name
, &c
->private_devices
, message
, flags
, error
);
1969 if (streq(name
, "PrivateMounts"))
1970 return bus_set_transient_tristate(u
, name
, &c
->private_mounts
, message
, flags
, error
);
1972 if (streq(name
, "PrivateNetwork"))
1973 return bus_set_transient_bool(u
, name
, &c
->private_network
, message
, flags
, error
);
1975 if (streq(name
, "PrivateIPC"))
1976 return bus_set_transient_bool(u
, name
, &c
->private_ipc
, message
, flags
, error
);
1978 if (streq(name
, "PrivateUsers"))
1979 return bus_set_transient_bool(u
, name
, &c
->private_users
, message
, flags
, error
);
1981 if (streq(name
, "NoNewPrivileges"))
1982 return bus_set_transient_bool(u
, name
, &c
->no_new_privileges
, message
, flags
, error
);
1984 if (streq(name
, "SyslogLevelPrefix"))
1985 return bus_set_transient_bool(u
, name
, &c
->syslog_level_prefix
, message
, flags
, error
);
1987 if (streq(name
, "MemoryDenyWriteExecute"))
1988 return bus_set_transient_bool(u
, name
, &c
->memory_deny_write_execute
, message
, flags
, error
);
1990 if (streq(name
, "RestrictRealtime"))
1991 return bus_set_transient_bool(u
, name
, &c
->restrict_realtime
, message
, flags
, error
);
1993 if (streq(name
, "RestrictSUIDSGID"))
1994 return bus_set_transient_bool(u
, name
, &c
->restrict_suid_sgid
, message
, flags
, error
);
1996 if (streq(name
, "DynamicUser"))
1997 return bus_set_transient_bool(u
, name
, &c
->dynamic_user
, message
, flags
, error
);
1999 if (streq(name
, "RemoveIPC"))
2000 return bus_set_transient_bool(u
, name
, &c
->remove_ipc
, message
, flags
, error
);
2002 if (streq(name
, "ProtectKernelTunables"))
2003 return bus_set_transient_bool(u
, name
, &c
->protect_kernel_tunables
, message
, flags
, error
);
2005 if (streq(name
, "ProtectKernelModules"))
2006 return bus_set_transient_bool(u
, name
, &c
->protect_kernel_modules
, message
, flags
, error
);
2008 if (streq(name
, "ProtectKernelLogs"))
2009 return bus_set_transient_bool(u
, name
, &c
->protect_kernel_logs
, message
, flags
, error
);
2011 if (streq(name
, "ProtectClock"))
2012 return bus_set_transient_bool(u
, name
, &c
->protect_clock
, message
, flags
, error
);
2014 if (streq(name
, "ProtectControlGroups"))
2015 return bus_set_transient_bool(u
, name
, &c
->protect_control_groups
, message
, flags
, error
);
2017 if (streq(name
, "CPUSchedulingResetOnFork"))
2018 return bus_set_transient_bool(u
, name
, &c
->cpu_sched_reset_on_fork
, message
, flags
, error
);
2020 if (streq(name
, "NonBlocking"))
2021 return bus_set_transient_bool(u
, name
, &c
->non_blocking
, message
, flags
, error
);
2023 if (streq(name
, "LockPersonality"))
2024 return bus_set_transient_bool(u
, name
, &c
->lock_personality
, message
, flags
, error
);
2026 if (streq(name
, "ProtectHostname"))
2027 return bus_set_transient_bool(u
, name
, &c
->protect_hostname
, message
, flags
, error
);
2029 if (streq(name
, "MemoryKSM"))
2030 return bus_set_transient_tristate(u
, name
, &c
->memory_ksm
, message
, flags
, error
);
2032 if (streq(name
, "UtmpIdentifier"))
2033 return bus_set_transient_string(u
, name
, &c
->utmp_id
, message
, flags
, error
);
2035 if (streq(name
, "UtmpMode"))
2036 return bus_set_transient_utmp_mode(u
, name
, &c
->utmp_mode
, message
, flags
, error
);
2038 if (streq(name
, "PAMName"))
2039 return bus_set_transient_string(u
, name
, &c
->pam_name
, message
, flags
, error
);
2041 if (streq(name
, "TimerSlackNSec"))
2042 return bus_set_transient_nsec(u
, name
, &c
->timer_slack_nsec
, message
, flags
, error
);
2044 if (streq(name
, "ProtectSystem"))
2045 return bus_set_transient_protect_system(u
, name
, &c
->protect_system
, message
, flags
, error
);
2047 if (streq(name
, "ProtectHome"))
2048 return bus_set_transient_protect_home(u
, name
, &c
->protect_home
, message
, flags
, error
);
2050 if (streq(name
, "KeyringMode"))
2051 return bus_set_transient_keyring_mode(u
, name
, &c
->keyring_mode
, message
, flags
, error
);
2053 if (streq(name
, "ProtectProc"))
2054 return bus_set_transient_protect_proc(u
, name
, &c
->protect_proc
, message
, flags
, error
);
2056 if (streq(name
, "ProcSubset"))
2057 return bus_set_transient_proc_subset(u
, name
, &c
->proc_subset
, message
, flags
, error
);
2059 if (streq(name
, "RuntimeDirectoryPreserve"))
2060 return bus_set_transient_exec_preserve_mode(u
, name
, &c
->runtime_directory_preserve_mode
, message
, flags
, error
);
2062 if (streq(name
, "UMask"))
2063 return bus_set_transient_mode_t(u
, name
, &c
->umask
, message
, flags
, error
);
2065 if (streq(name
, "RuntimeDirectoryMode"))
2066 return bus_set_transient_mode_t(u
, name
, &c
->directories
[EXEC_DIRECTORY_RUNTIME
].mode
, message
, flags
, error
);
2068 if (streq(name
, "StateDirectoryMode"))
2069 return bus_set_transient_mode_t(u
, name
, &c
->directories
[EXEC_DIRECTORY_STATE
].mode
, message
, flags
, error
);
2071 if (streq(name
, "CacheDirectoryMode"))
2072 return bus_set_transient_mode_t(u
, name
, &c
->directories
[EXEC_DIRECTORY_CACHE
].mode
, message
, flags
, error
);
2074 if (streq(name
, "LogsDirectoryMode"))
2075 return bus_set_transient_mode_t(u
, name
, &c
->directories
[EXEC_DIRECTORY_LOGS
].mode
, message
, flags
, error
);
2077 if (streq(name
, "ConfigurationDirectoryMode"))
2078 return bus_set_transient_mode_t(u
, name
, &c
->directories
[EXEC_DIRECTORY_CONFIGURATION
].mode
, message
, flags
, error
);
2080 if (streq(name
, "SELinuxContext"))
2081 return bus_set_transient_string(u
, name
, &c
->selinux_context
, message
, flags
, error
);
2083 if (streq(name
, "SecureBits"))
2084 return bus_set_transient_secure_bits(u
, name
, &c
->secure_bits
, message
, flags
, error
);
2086 if (streq(name
, "CapabilityBoundingSet"))
2087 return bus_set_transient_capability(u
, name
, &c
->capability_bounding_set
, message
, flags
, error
);
2089 if (streq(name
, "AmbientCapabilities"))
2090 return bus_set_transient_capability(u
, name
, &c
->capability_ambient_set
, message
, flags
, error
);
2092 if (streq(name
, "RestrictNamespaces"))
2093 return bus_set_transient_namespace_flag(u
, name
, &c
->restrict_namespaces
, message
, flags
, error
);
2095 if (streq(name
, "RestrictFileSystems")) {
2097 _cleanup_strv_free_
char **l
= NULL
;
2099 r
= sd_bus_message_enter_container(message
, 'r', "bas");
2103 r
= sd_bus_message_read(message
, "b", &allow_list
);
2107 r
= sd_bus_message_read_strv(message
, &l
);
2111 r
= sd_bus_message_exit_container(message
);
2115 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2116 _cleanup_free_
char *joined
= NULL
;
2117 FilesystemParseFlags invert_flag
= allow_list
? 0 : FILESYSTEM_PARSE_INVERT
;
2119 if (strv_isempty(l
)) {
2120 c
->restrict_filesystems_allow_list
= false;
2121 c
->restrict_filesystems
= set_free_free(c
->restrict_filesystems
);
2123 unit_write_setting(u
, flags
, name
, "RestrictFileSystems=");
2127 if (!c
->restrict_filesystems
)
2128 c
->restrict_filesystems_allow_list
= allow_list
;
2130 STRV_FOREACH(s
, l
) {
2131 r
= lsm_bpf_parse_filesystem(
2133 &c
->restrict_filesystems
,
2134 FILESYSTEM_PARSE_LOG
|
2135 (invert_flag
? FILESYSTEM_PARSE_INVERT
: 0)|
2136 (c
->restrict_filesystems_allow_list
? FILESYSTEM_PARSE_ALLOW_LIST
: 0),
2142 joined
= strv_join(l
, " ");
2146 unit_write_settingf(u
, flags
, name
, "%s=%s%s", name
, allow_list
? "" : "~", joined
);
2152 if (streq(name
, "MountFlags"))
2153 return bus_set_transient_mount_propagation_flag(u
, name
, &c
->mount_propagation_flag
, message
, flags
, error
);
2155 if (streq(name
, "NetworkNamespacePath"))
2156 return bus_set_transient_path(u
, name
, &c
->network_namespace_path
, message
, flags
, error
);
2158 if (streq(name
, "IPCNamespacePath"))
2159 return bus_set_transient_path(u
, name
, &c
->ipc_namespace_path
, message
, flags
, error
);
2161 if (streq(name
, "SupplementaryGroups")) {
2162 _cleanup_strv_free_
char **l
= NULL
;
2164 r
= sd_bus_message_read_strv(message
, &l
);
2169 if (!isempty(*p
) && !valid_user_group_name(*p
, VALID_USER_ALLOW_NUMERIC
|VALID_USER_RELAX
|VALID_USER_WARN
))
2170 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
,
2171 "Invalid supplementary group names");
2173 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2174 if (strv_isempty(l
)) {
2175 c
->supplementary_groups
= strv_free(c
->supplementary_groups
);
2176 unit_write_settingf(u
, flags
, name
, "%s=", name
);
2178 _cleanup_free_
char *joined
= NULL
;
2180 r
= strv_extend_strv(&c
->supplementary_groups
, l
, true);
2184 joined
= strv_join(c
->supplementary_groups
, " ");
2188 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "%s=%s", name
, joined
);
2194 } else if (STR_IN_SET(name
, "SetCredential", "SetCredentialEncrypted")) {
2195 bool isempty
= true;
2197 r
= sd_bus_message_enter_container(message
, 'a', "(say)");
2206 r
= sd_bus_message_enter_container(message
, 'r', "say");
2212 r
= sd_bus_message_read(message
, "s", &id
);
2216 r
= sd_bus_message_read_array(message
, 'y', &p
, &sz
);
2220 r
= sd_bus_message_exit_container(message
);
2224 if (!credential_name_valid(id
))
2225 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Credential ID is invalid: %s", id
);
2229 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2230 _cleanup_free_
char *a
= NULL
, *b
= NULL
;
2231 _cleanup_free_
void *copy
= NULL
;
2232 ExecSetCredential
*old
;
2234 copy
= memdup(p
, sz
);
2238 old
= hashmap_get(c
->set_credentials
, id
);
2240 free_and_replace(old
->data
, copy
);
2242 old
->encrypted
= streq(name
, "SetCredentialEncrypted");
2244 _cleanup_(exec_set_credential_freep
) ExecSetCredential
*sc
= NULL
;
2246 sc
= new(ExecSetCredential
, 1);
2250 *sc
= (ExecSetCredential
) {
2252 .data
= TAKE_PTR(copy
),
2254 .encrypted
= streq(name
, "SetCredentialEncrypted"),
2260 r
= hashmap_ensure_put(&c
->set_credentials
, &exec_set_credential_hash_ops
, sc
->id
, sc
);
2267 a
= specifier_escape(id
);
2271 b
= cescape_length(p
, sz
);
2275 (void) unit_write_settingf(u
, flags
, name
, "%s=%s:%s", name
, a
, b
);
2279 r
= sd_bus_message_exit_container(message
);
2283 if (!UNIT_WRITE_FLAGS_NOOP(flags
) && isempty
) {
2284 c
->set_credentials
= hashmap_free(c
->set_credentials
);
2285 (void) unit_write_settingf(u
, flags
, name
, "%s=", name
);
2290 } else if (STR_IN_SET(name
, "LoadCredential", "LoadCredentialEncrypted")) {
2291 bool isempty
= true;
2293 r
= sd_bus_message_enter_container(message
, 'a', "(ss)");
2298 const char *id
, *source
;
2300 r
= sd_bus_message_read(message
, "(ss)", &id
, &source
);
2306 if (!credential_name_valid(id
))
2307 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Credential ID is invalid: %s", id
);
2309 if (!(path_is_absolute(source
) ? path_is_normalized(source
) : credential_name_valid(source
)))
2310 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Credential source is invalid: %s", source
);
2314 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2315 bool encrypted
= streq(name
, "LoadCredentialEncrypted");
2317 r
= hashmap_put_credential(&c
->load_credentials
, id
, source
, encrypted
);
2321 (void) unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "%s=%s:%s", name
, id
, source
);
2325 r
= sd_bus_message_exit_container(message
);
2329 if (!UNIT_WRITE_FLAGS_NOOP(flags
) && isempty
) {
2330 c
->load_credentials
= hashmap_free(c
->load_credentials
);
2331 (void) unit_write_settingf(u
, flags
, name
, "%s=", name
);
2336 } else if (streq(name
, "ImportCredential")) {
2337 bool isempty
= true;
2339 r
= sd_bus_message_enter_container(message
, 'a', "s");
2346 r
= sd_bus_message_read(message
, "s", &s
);
2352 if (!credential_glob_valid(s
))
2353 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Credential name or glob is invalid: %s", s
);
2357 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2358 r
= set_put_strdup(&c
->import_credentials
, s
);
2362 (void) unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "%s=%s", name
, s
);
2366 r
= sd_bus_message_exit_container(message
);
2370 if (!UNIT_WRITE_FLAGS_NOOP(flags
) && isempty
) {
2371 c
->import_credentials
= set_free_free(c
->import_credentials
);
2372 (void) unit_write_settingf(u
, flags
, name
, "%s=", name
);
2377 } else if (streq(name
, "SyslogLevel")) {
2380 r
= sd_bus_message_read(message
, "i", &level
);
2384 if (!log_level_is_valid(level
))
2385 return sd_bus_error_set(error
, SD_BUS_ERROR_INVALID_ARGS
, "Log level value out of range");
2387 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2388 c
->syslog_priority
= (c
->syslog_priority
& LOG_FACMASK
) | level
;
2389 unit_write_settingf(u
, flags
, name
, "SyslogLevel=%i", level
);
2394 } else if (streq(name
, "SyslogFacility")) {
2397 r
= sd_bus_message_read(message
, "i", &facility
);
2401 if (!log_facility_unshifted_is_valid(facility
))
2402 return sd_bus_error_set(error
, SD_BUS_ERROR_INVALID_ARGS
, "Log facility value out of range");
2404 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2405 c
->syslog_priority
= (facility
<< 3) | LOG_PRI(c
->syslog_priority
);
2406 unit_write_settingf(u
, flags
, name
, "SyslogFacility=%i", facility
);
2411 } else if (streq(name
, "LogNamespace")) {
2414 r
= sd_bus_message_read(message
, "s", &n
);
2418 if (!isempty(n
) && !log_namespace_name_valid(n
))
2419 return sd_bus_error_set(error
, SD_BUS_ERROR_INVALID_ARGS
, "Log namespace name not valid");
2421 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2424 c
->log_namespace
= mfree(c
->log_namespace
);
2425 unit_write_settingf(u
, flags
, name
, "%s=", name
);
2427 r
= free_and_strdup(&c
->log_namespace
, n
);
2431 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, n
);
2437 } else if (streq(name
, "LogExtraFields")) {
2440 r
= sd_bus_message_enter_container(message
, 'a', "ay");
2445 _cleanup_free_
void *copy
= NULL
;
2451 /* Note that we expect a byte array for each field, instead of a string. That's because on the
2452 * lower-level journal fields can actually contain binary data and are not restricted to text,
2453 * and we should not "lose precision" in our types on the way. That said, I am pretty sure
2454 * actually encoding binary data as unit metadata is not a good idea. Hence we actually refuse
2455 * any actual binary data, and only accept UTF-8. This allows us to eventually lift this
2456 * limitation, should a good, valid use case arise. */
2458 r
= sd_bus_message_read_array(message
, 'y', &p
, &sz
);
2464 if (memchr(p
, 0, sz
))
2465 return sd_bus_error_set(error
, SD_BUS_ERROR_INVALID_ARGS
, "Journal field contains zero byte");
2467 eq
= memchr(p
, '=', sz
);
2469 return sd_bus_error_set(error
, SD_BUS_ERROR_INVALID_ARGS
, "Journal field contains no '=' character");
2470 if (!journal_field_valid(p
, eq
- (const char*) p
, false))
2471 return sd_bus_error_set(error
, SD_BUS_ERROR_INVALID_ARGS
, "Journal field invalid");
2473 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2474 t
= reallocarray(c
->log_extra_fields
, c
->n_log_extra_fields
+1, sizeof(struct iovec
));
2477 c
->log_extra_fields
= t
;
2480 copy
= malloc(sz
+ 1);
2484 memcpy(copy
, p
, sz
);
2485 ((uint8_t*) copy
)[sz
] = 0;
2487 if (!utf8_is_valid(copy
))
2488 return sd_bus_error_set(error
, SD_BUS_ERROR_INVALID_ARGS
, "Journal field is not valid UTF-8");
2490 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2491 c
->log_extra_fields
[c
->n_log_extra_fields
++] = IOVEC_MAKE(copy
, sz
);
2492 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
|UNIT_ESCAPE_C
, name
, "LogExtraFields=%s", (char*) copy
);
2500 r
= sd_bus_message_exit_container(message
);
2504 if (!UNIT_WRITE_FLAGS_NOOP(flags
) && n
== 0) {
2505 exec_context_free_log_extra_fields(c
);
2506 unit_write_setting(u
, flags
, name
, "LogExtraFields=");
2514 if (streq(name
, "SystemCallErrorNumber"))
2515 return bus_set_transient_errno(u
, name
, &c
->syscall_errno
, message
, flags
, error
);
2517 if (streq(name
, "SystemCallFilter")) {
2519 _cleanup_strv_free_
char **l
= NULL
;
2521 r
= sd_bus_message_enter_container(message
, 'r', "bas");
2525 r
= sd_bus_message_read(message
, "b", &allow_list
);
2529 r
= sd_bus_message_read_strv(message
, &l
);
2533 r
= sd_bus_message_exit_container(message
);
2537 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2538 _cleanup_free_
char *joined
= NULL
;
2539 SeccompParseFlags invert_flag
= allow_list
? 0 : SECCOMP_PARSE_INVERT
;
2541 if (strv_isempty(l
)) {
2542 c
->syscall_allow_list
= false;
2543 c
->syscall_filter
= hashmap_free(c
->syscall_filter
);
2545 unit_write_settingf(u
, flags
, name
, "SystemCallFilter=");
2549 if (!c
->syscall_filter
) {
2550 c
->syscall_filter
= hashmap_new(NULL
);
2551 if (!c
->syscall_filter
)
2554 c
->syscall_allow_list
= allow_list
;
2556 if (c
->syscall_allow_list
) {
2557 r
= seccomp_parse_syscall_filter("@default",
2560 SECCOMP_PARSE_PERMISSIVE
|
2561 SECCOMP_PARSE_ALLOW_LIST
,
2569 STRV_FOREACH(s
, l
) {
2570 _cleanup_free_
char *n
= NULL
;
2573 r
= parse_syscall_and_errno(*s
, &n
, &e
);
2577 if (allow_list
&& e
>= 0)
2580 r
= seccomp_parse_syscall_filter(n
,
2583 SECCOMP_PARSE_LOG
| SECCOMP_PARSE_PERMISSIVE
|
2585 (c
->syscall_allow_list
? SECCOMP_PARSE_ALLOW_LIST
: 0),
2592 joined
= strv_join(l
, " ");
2596 unit_write_settingf(u
, flags
, name
, "SystemCallFilter=%s%s", allow_list
? "" : "~", joined
);
2601 } else if (streq(name
, "SystemCallLog")) {
2603 _cleanup_strv_free_
char **l
= NULL
;
2605 r
= sd_bus_message_enter_container(message
, 'r', "bas");
2609 r
= sd_bus_message_read(message
, "b", &allow_list
);
2613 r
= sd_bus_message_read_strv(message
, &l
);
2617 r
= sd_bus_message_exit_container(message
);
2621 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2622 _cleanup_free_
char *joined
= NULL
;
2623 SeccompParseFlags invert_flag
= allow_list
? 0 : SECCOMP_PARSE_INVERT
;
2625 if (strv_isempty(l
)) {
2626 c
->syscall_log_allow_list
= false;
2627 c
->syscall_log
= hashmap_free(c
->syscall_log
);
2629 unit_write_settingf(u
, flags
, name
, "SystemCallLog=");
2633 if (!c
->syscall_log
) {
2634 c
->syscall_log
= hashmap_new(NULL
);
2635 if (!c
->syscall_log
)
2638 c
->syscall_log_allow_list
= allow_list
;
2641 STRV_FOREACH(s
, l
) {
2642 r
= seccomp_parse_syscall_filter(*s
,
2643 -1, /* errno not used */
2645 SECCOMP_PARSE_LOG
| SECCOMP_PARSE_PERMISSIVE
|
2647 (c
->syscall_log_allow_list
? SECCOMP_PARSE_ALLOW_LIST
: 0),
2654 joined
= strv_join(l
, " ");
2658 unit_write_settingf(u
, flags
, name
, "SystemCallLog=%s%s", allow_list
? "" : "~", joined
);
2663 } else if (streq(name
, "SystemCallArchitectures")) {
2664 _cleanup_strv_free_
char **l
= NULL
;
2666 r
= sd_bus_message_read_strv(message
, &l
);
2670 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2671 _cleanup_free_
char *joined
= NULL
;
2673 if (strv_isempty(l
))
2674 c
->syscall_archs
= set_free(c
->syscall_archs
);
2676 STRV_FOREACH(s
, l
) {
2679 r
= seccomp_arch_from_string(*s
, &a
);
2683 r
= set_ensure_put(&c
->syscall_archs
, NULL
, UINT32_TO_PTR(a
+ 1));
2688 joined
= strv_join(l
, " ");
2692 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, joined
);
2697 } else if (streq(name
, "RestrictAddressFamilies")) {
2698 _cleanup_strv_free_
char **l
= NULL
;
2701 r
= sd_bus_message_enter_container(message
, 'r', "bas");
2705 r
= sd_bus_message_read(message
, "b", &allow_list
);
2709 r
= sd_bus_message_read_strv(message
, &l
);
2713 r
= sd_bus_message_exit_container(message
);
2717 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2718 _cleanup_free_
char *joined
= NULL
;
2720 if (strv_isempty(l
)) {
2721 c
->address_families_allow_list
= allow_list
;
2722 c
->address_families
= set_free(c
->address_families
);
2724 unit_write_settingf(u
, flags
, name
, "RestrictAddressFamilies=%s",
2725 allow_list
? "none" : "");
2729 if (!c
->address_families
) {
2730 c
->address_families
= set_new(NULL
);
2731 if (!c
->address_families
)
2734 c
->address_families_allow_list
= allow_list
;
2737 STRV_FOREACH(s
, l
) {
2740 af
= af_from_name(*s
);
2744 if (allow_list
== c
->address_families_allow_list
) {
2745 r
= set_put(c
->address_families
, INT_TO_PTR(af
));
2749 set_remove(c
->address_families
, INT_TO_PTR(af
));
2752 joined
= strv_join(l
, " ");
2756 unit_write_settingf(u
, flags
, name
, "RestrictAddressFamilies=%s%s", allow_list
? "" : "~", joined
);
2762 if (STR_IN_SET(name
, "CPUAffinity", "NUMAMask")) {
2765 bool affinity
= streq(name
, "CPUAffinity");
2766 _cleanup_(cpu_set_reset
) CPUSet set
= {};
2768 r
= sd_bus_message_read_array(message
, 'y', &a
, &n
);
2772 r
= cpu_set_from_dbus(a
, n
, &set
);
2776 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2778 cpu_set_reset(affinity
? &c
->cpu_set
: &c
->numa_policy
.nodes
);
2779 unit_write_settingf(u
, flags
, name
, "%s=", name
);
2781 _cleanup_free_
char *str
= NULL
;
2783 str
= cpu_set_to_string(&set
);
2787 /* We forego any optimizations here, and always create the structure using
2788 * cpu_set_add_all(), because we don't want to care if the existing size we
2789 * got over dbus is appropriate. */
2790 r
= cpu_set_add_all(affinity
? &c
->cpu_set
: &c
->numa_policy
.nodes
, &set
);
2794 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, str
);
2800 } else if (streq(name
, "CPUAffinityFromNUMA")) {
2803 r
= sd_bus_message_read_basic(message
, 'b', &q
);
2807 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2808 c
->cpu_affinity_from_numa
= q
;
2809 unit_write_settingf(u
, flags
, name
, "%s=%s", "CPUAffinity", "numa");
2814 } else if (streq(name
, "NUMAPolicy")) {
2817 r
= sd_bus_message_read(message
, "i", &type
);
2821 if (!mpol_is_valid(type
))
2822 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid NUMAPolicy value: %i", type
);
2824 if (!UNIT_WRITE_FLAGS_NOOP(flags
))
2825 c
->numa_policy
.type
= type
;
2829 } else if (streq(name
, "Nice")) {
2832 r
= sd_bus_message_read(message
, "i", &q
);
2836 if (!nice_is_valid(q
))
2837 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid Nice value: %i", q
);
2839 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2843 unit_write_settingf(u
, flags
, name
, "Nice=%i", q
);
2848 } else if (streq(name
, "CPUSchedulingPolicy")) {
2851 r
= sd_bus_message_read(message
, "i", &q
);
2855 if (!sched_policy_is_valid(q
))
2856 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid CPU scheduling policy: %i", q
);
2858 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2859 _cleanup_free_
char *s
= NULL
;
2861 r
= sched_policy_to_string_alloc(q
, &s
);
2865 c
->cpu_sched_policy
= q
;
2866 c
->cpu_sched_priority
= CLAMP(c
->cpu_sched_priority
, sched_get_priority_min(q
), sched_get_priority_max(q
));
2867 c
->cpu_sched_set
= true;
2869 unit_write_settingf(u
, flags
, name
, "CPUSchedulingPolicy=%s", s
);
2874 } else if (streq(name
, "CPUSchedulingPriority")) {
2877 r
= sd_bus_message_read(message
, "i", &p
);
2881 /* On Linux RR/FIFO range from 1 to 99 and OTHER/BATCH may only be 0. Policy might be set
2882 * later so we do not check the precise range, but only the generic outer bounds. */
2883 if (p
< 0 || p
> 99)
2884 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid CPU scheduling priority: %i", p
);
2886 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2887 c
->cpu_sched_priority
= p
;
2888 c
->cpu_sched_set
= true;
2890 unit_write_settingf(u
, flags
, name
, "CPUSchedulingPriority=%i", p
);
2895 } else if (streq(name
, "IOSchedulingClass")) {
2898 r
= sd_bus_message_read(message
, "i", &q
);
2902 if (!ioprio_class_is_valid(q
))
2903 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid IO scheduling class: %i", q
);
2905 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2906 _cleanup_free_
char *s
= NULL
;
2908 r
= ioprio_class_to_string_alloc(q
, &s
);
2912 c
->ioprio
= ioprio_normalize(ioprio_prio_value(q
, ioprio_prio_data(c
->ioprio
)));
2913 c
->ioprio_set
= true;
2915 unit_write_settingf(u
, flags
, name
, "IOSchedulingClass=%s", s
);
2920 } else if (streq(name
, "IOSchedulingPriority")) {
2923 r
= sd_bus_message_read(message
, "i", &p
);
2927 if (!ioprio_priority_is_valid(p
))
2928 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid IO scheduling priority: %i", p
);
2930 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2931 c
->ioprio
= ioprio_normalize(ioprio_prio_value(ioprio_prio_class(c
->ioprio
), p
));
2932 c
->ioprio_set
= true;
2934 unit_write_settingf(u
, flags
, name
, "IOSchedulingPriority=%i", p
);
2939 } else if (streq(name
, "MountAPIVFS")) {
2942 r
= bus_set_transient_bool(u
, name
, &b
, message
, flags
, error
);
2946 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2947 c
->mount_apivfs
= b
;
2948 c
->mount_apivfs_set
= true;
2953 } else if (streq(name
, "WorkingDirectory")) {
2957 r
= sd_bus_message_read(message
, "s", &s
);
2967 if (!isempty(s
) && !streq(s
, "~") && !path_is_absolute(s
))
2968 return sd_bus_error_set(error
, SD_BUS_ERROR_INVALID_ARGS
, "WorkingDirectory= expects an absolute path or '~'");
2970 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2971 if (streq(s
, "~")) {
2972 c
->working_directory
= mfree(c
->working_directory
);
2973 c
->working_directory_home
= true;
2975 r
= free_and_strdup(&c
->working_directory
, empty_to_null(s
));
2979 c
->working_directory_home
= false;
2982 c
->working_directory_missing_ok
= missing_ok
;
2983 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "WorkingDirectory=%s%s", missing_ok
? "-" : "", s
);
2988 } else if (STR_IN_SET(name
,
2989 "StandardInputFileDescriptorName", "StandardOutputFileDescriptorName", "StandardErrorFileDescriptorName")) {
2992 r
= sd_bus_message_read(message
, "s", &s
);
2996 if (!isempty(s
) && !fdname_is_valid(s
))
2997 return sd_bus_error_set(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid file descriptor name");
2999 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3001 if (streq(name
, "StandardInputFileDescriptorName")) {
3002 r
= free_and_strdup(c
->stdio_fdname
+ STDIN_FILENO
, empty_to_null(s
));
3006 c
->std_input
= EXEC_INPUT_NAMED_FD
;
3007 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardInput=fd:%s", exec_context_fdname(c
, STDIN_FILENO
));
3009 } else if (streq(name
, "StandardOutputFileDescriptorName")) {
3010 r
= free_and_strdup(c
->stdio_fdname
+ STDOUT_FILENO
, empty_to_null(s
));
3014 c
->std_output
= EXEC_OUTPUT_NAMED_FD
;
3015 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardOutput=fd:%s", exec_context_fdname(c
, STDOUT_FILENO
));
3018 assert(streq(name
, "StandardErrorFileDescriptorName"));
3020 r
= free_and_strdup(&c
->stdio_fdname
[STDERR_FILENO
], empty_to_null(s
));
3024 c
->std_error
= EXEC_OUTPUT_NAMED_FD
;
3025 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardError=fd:%s", exec_context_fdname(c
, STDERR_FILENO
));
3031 } else if (STR_IN_SET(name
,
3032 "StandardInputFile",
3033 "StandardOutputFile", "StandardOutputFileToAppend", "StandardOutputFileToTruncate",
3034 "StandardErrorFile", "StandardErrorFileToAppend", "StandardErrorFileToTruncate")) {
3037 r
= sd_bus_message_read(message
, "s", &s
);
3042 if (!path_is_absolute(s
))
3043 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Path %s is not absolute", s
);
3044 if (!path_is_normalized(s
))
3045 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Path %s is not normalized", s
);
3048 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3050 if (streq(name
, "StandardInputFile")) {
3051 r
= free_and_strdup(&c
->stdio_file
[STDIN_FILENO
], empty_to_null(s
));
3055 c
->std_input
= EXEC_INPUT_FILE
;
3056 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardInput=file:%s", s
);
3058 } else if (STR_IN_SET(name
, "StandardOutputFile", "StandardOutputFileToAppend", "StandardOutputFileToTruncate")) {
3059 r
= free_and_strdup(&c
->stdio_file
[STDOUT_FILENO
], empty_to_null(s
));
3063 if (streq(name
, "StandardOutputFile")) {
3064 c
->std_output
= EXEC_OUTPUT_FILE
;
3065 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardOutput=file:%s", s
);
3066 } else if (streq(name
, "StandardOutputFileToAppend")) {
3067 c
->std_output
= EXEC_OUTPUT_FILE_APPEND
;
3068 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardOutput=append:%s", s
);
3070 assert(streq(name
, "StandardOutputFileToTruncate"));
3071 c
->std_output
= EXEC_OUTPUT_FILE_TRUNCATE
;
3072 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardOutput=truncate:%s", s
);
3075 assert(STR_IN_SET(name
, "StandardErrorFile", "StandardErrorFileToAppend", "StandardErrorFileToTruncate"));
3077 r
= free_and_strdup(&c
->stdio_file
[STDERR_FILENO
], empty_to_null(s
));
3081 if (streq(name
, "StandardErrorFile")) {
3082 c
->std_error
= EXEC_OUTPUT_FILE
;
3083 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardError=file:%s", s
);
3084 } else if (streq(name
, "StandardErrorFileToAppend")) {
3085 c
->std_error
= EXEC_OUTPUT_FILE_APPEND
;
3086 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardError=append:%s", s
);
3088 assert(streq(name
, "StandardErrorFileToTruncate"));
3089 c
->std_error
= EXEC_OUTPUT_FILE_TRUNCATE
;
3090 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardError=truncate:%s", s
);
3097 } else if (streq(name
, "StandardInputData")) {
3101 r
= sd_bus_message_read_array(message
, 'y', &p
, &sz
);
3105 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3106 _cleanup_free_
char *encoded
= NULL
;
3109 c
->stdin_data
= mfree(c
->stdin_data
);
3110 c
->stdin_data_size
= 0;
3112 unit_write_settingf(u
, flags
, name
, "StandardInputData=");
3117 if (c
->stdin_data_size
+ sz
< c
->stdin_data_size
|| /* check for overflow */
3118 c
->stdin_data_size
+ sz
> EXEC_STDIN_DATA_MAX
)
3121 n
= base64mem(p
, sz
, &encoded
);
3125 q
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
);
3129 memcpy((uint8_t*) q
+ c
->stdin_data_size
, p
, sz
);
3132 c
->stdin_data_size
+= sz
;
3134 unit_write_settingf(u
, flags
, name
, "StandardInputData=%s", encoded
);
3140 } else if (streq(name
, "Environment")) {
3142 _cleanup_strv_free_
char **l
= NULL
;
3144 r
= sd_bus_message_read_strv(message
, &l
);
3148 if (!strv_env_is_valid(l
))
3149 return sd_bus_error_set(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid environment block.");
3151 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3152 if (strv_isempty(l
)) {
3153 c
->environment
= strv_free(c
->environment
);
3154 unit_write_setting(u
, flags
, name
, "Environment=");
3156 _cleanup_free_
char *joined
= NULL
;
3159 joined
= unit_concat_strv(l
, UNIT_ESCAPE_SPECIFIERS
|UNIT_ESCAPE_C
);
3163 e
= strv_env_merge(c
->environment
, l
);
3167 strv_free_and_replace(c
->environment
, e
);
3168 unit_write_settingf(u
, flags
, name
, "Environment=%s", joined
);
3174 } else if (streq(name
, "UnsetEnvironment")) {
3176 _cleanup_strv_free_
char **l
= NULL
;
3178 r
= sd_bus_message_read_strv(message
, &l
);
3182 if (!strv_env_name_or_assignment_is_valid(l
))
3183 return sd_bus_error_set(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid UnsetEnvironment= list.");
3185 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3186 if (strv_isempty(l
)) {
3187 c
->unset_environment
= strv_free(c
->unset_environment
);
3188 unit_write_setting(u
, flags
, name
, "UnsetEnvironment=");
3190 _cleanup_free_
char *joined
= NULL
;
3193 joined
= unit_concat_strv(l
, UNIT_ESCAPE_SPECIFIERS
|UNIT_ESCAPE_C
);
3197 e
= strv_env_merge(c
->unset_environment
, l
);
3201 strv_free_and_replace(c
->unset_environment
, e
);
3202 unit_write_settingf(u
, flags
, name
, "UnsetEnvironment=%s", joined
);
3208 } else if (streq(name
, "OOMScoreAdjust")) {
3211 r
= sd_bus_message_read(message
, "i", &oa
);
3215 if (!oom_score_adjust_is_valid(oa
))
3216 return sd_bus_error_set(error
, SD_BUS_ERROR_INVALID_ARGS
, "OOM score adjust value out of range");
3218 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3219 c
->oom_score_adjust
= oa
;
3220 c
->oom_score_adjust_set
= true;
3221 unit_write_settingf(u
, flags
, name
, "OOMScoreAdjust=%i", oa
);
3226 } else if (streq(name
, "CoredumpFilter")) {
3229 r
= sd_bus_message_read(message
, "t", &f
);
3233 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3234 c
->coredump_filter
= f
;
3235 c
->coredump_filter_set
= true;
3236 unit_write_settingf(u
, flags
, name
, "CoredumpFilter=0x%"PRIx64
, f
);
3241 } else if (streq(name
, "EnvironmentFiles")) {
3242 _cleanup_(memstream_done
) MemStream m
= {};
3243 _cleanup_free_
char *joined
= NULL
;
3244 _cleanup_strv_free_
char **l
= NULL
;
3247 r
= sd_bus_message_enter_container(message
, 'a', "(sb)");
3251 f
= memstream_init(&m
);
3255 fputs("EnvironmentFile=\n", f
);
3257 STRV_FOREACH(i
, c
->environment_files
) {
3258 _cleanup_free_
char *q
= NULL
;
3260 q
= specifier_escape(*i
);
3264 fprintf(f
, "EnvironmentFile=%s\n", q
);
3267 while ((r
= sd_bus_message_enter_container(message
, 'r', "sb")) > 0) {
3271 r
= sd_bus_message_read(message
, "sb", &path
, &b
);
3275 r
= sd_bus_message_exit_container(message
);
3279 if (!path_is_absolute(path
))
3280 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Path %s is not absolute.", path
);
3282 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3283 _cleanup_free_
char *q
= NULL
, *buf
= NULL
;
3285 buf
= strjoin(b
? "-" : "", path
);
3289 q
= specifier_escape(buf
);
3293 fprintf(f
, "EnvironmentFile=%s\n", q
);
3295 r
= strv_consume(&l
, TAKE_PTR(buf
));
3303 r
= sd_bus_message_exit_container(message
);
3307 r
= memstream_finalize(&m
, &joined
, NULL
);
3311 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3312 if (strv_isempty(l
)) {
3313 c
->environment_files
= strv_free(c
->environment_files
);
3314 unit_write_setting(u
, flags
, name
, "EnvironmentFile=");
3316 r
= strv_extend_strv(&c
->environment_files
, l
, true);
3320 unit_write_setting(u
, flags
, name
, joined
);
3326 } else if (streq(name
, "PassEnvironment")) {
3328 _cleanup_strv_free_
char **l
= NULL
;
3330 r
= sd_bus_message_read_strv(message
, &l
);
3334 if (!strv_env_name_is_valid(l
))
3335 return sd_bus_error_set(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid PassEnvironment= block.");
3337 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3338 if (strv_isempty(l
)) {
3339 c
->pass_environment
= strv_free(c
->pass_environment
);
3340 unit_write_setting(u
, flags
, name
, "PassEnvironment=");
3342 _cleanup_free_
char *joined
= NULL
;
3344 r
= strv_extend_strv(&c
->pass_environment
, l
, true);
3348 /* We write just the new settings out to file, with unresolved specifiers. */
3349 joined
= unit_concat_strv(l
, UNIT_ESCAPE_SPECIFIERS
);
3353 unit_write_settingf(u
, flags
, name
, "PassEnvironment=%s", joined
);
3359 } else if (STR_IN_SET(name
, "ReadWriteDirectories", "ReadOnlyDirectories", "InaccessibleDirectories",
3360 "ReadWritePaths", "ReadOnlyPaths", "InaccessiblePaths", "ExecPaths", "NoExecPaths",
3361 "ExtensionDirectories")) {
3362 _cleanup_strv_free_
char **l
= NULL
;
3365 r
= sd_bus_message_read_strv(message
, &l
);
3369 STRV_FOREACH(p
, l
) {
3373 offset
= i
[0] == '-';
3374 offset
+= i
[offset
] == '+';
3375 if (!path_is_absolute(i
+ offset
))
3376 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid %s", name
);
3378 path_simplify(i
+ offset
);
3381 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3382 if (STR_IN_SET(name
, "ReadWriteDirectories", "ReadWritePaths"))
3383 dirs
= &c
->read_write_paths
;
3384 else if (STR_IN_SET(name
, "ReadOnlyDirectories", "ReadOnlyPaths"))
3385 dirs
= &c
->read_only_paths
;
3386 else if (streq(name
, "ExecPaths"))
3387 dirs
= &c
->exec_paths
;
3388 else if (streq(name
, "NoExecPaths"))
3389 dirs
= &c
->no_exec_paths
;
3390 else if (streq(name
, "ExtensionDirectories"))
3391 dirs
= &c
->extension_directories
;
3392 else /* "InaccessiblePaths" */
3393 dirs
= &c
->inaccessible_paths
;
3395 if (strv_isempty(l
)) {
3396 *dirs
= strv_free(*dirs
);
3397 unit_write_settingf(u
, flags
, name
, "%s=", name
);
3399 _cleanup_free_
char *joined
= NULL
;
3401 joined
= unit_concat_strv(l
, UNIT_ESCAPE_SPECIFIERS
);
3405 r
= strv_extend_strv(dirs
, l
, true);
3409 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, joined
);
3415 } else if (streq(name
, "ExecSearchPath")) {
3416 _cleanup_strv_free_
char **l
= NULL
;
3418 r
= sd_bus_message_read_strv(message
, &l
);
3423 if (!path_is_absolute(*p
) || !path_is_normalized(*p
) || strchr(*p
, ':'))
3424 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid %s", name
);
3426 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3427 if (strv_isempty(l
)) {
3428 c
->exec_search_path
= strv_free(c
->exec_search_path
);
3429 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "ExecSearchPath=");
3431 _cleanup_free_
char *joined
= NULL
;
3432 r
= strv_extend_strv(&c
->exec_search_path
, l
, true);
3435 joined
= strv_join(c
->exec_search_path
, ":");
3438 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "ExecSearchPath=%s", joined
);
3444 } else if (STR_IN_SET(name
, "RuntimeDirectory", "StateDirectory", "CacheDirectory", "LogsDirectory", "ConfigurationDirectory")) {
3445 _cleanup_strv_free_
char **l
= NULL
;
3447 r
= sd_bus_message_read_strv(message
, &l
);
3451 STRV_FOREACH(p
, l
) {
3452 if (!path_is_normalized(*p
))
3453 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "%s= path is not normalized: %s", name
, *p
);
3455 if (path_is_absolute(*p
))
3456 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "%s= path is absolute: %s", name
, *p
);
3458 if (path_startswith(*p
, "private"))
3459 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "%s= path can't be 'private': %s", name
, *p
);
3462 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3463 ExecDirectoryType i
;
3466 assert_se((i
= exec_directory_type_from_string(name
)) >= 0);
3467 d
= c
->directories
+ i
;
3469 if (strv_isempty(l
)) {
3470 exec_directory_done(d
);
3471 unit_write_settingf(u
, flags
, name
, "%s=", name
);
3473 _cleanup_free_
char *joined
= NULL
;
3475 STRV_FOREACH(source
, l
) {
3476 r
= exec_directory_add(d
, *source
, NULL
);
3480 exec_directory_sort(d
);
3482 joined
= unit_concat_strv(l
, UNIT_ESCAPE_SPECIFIERS
);
3486 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, joined
);
3492 } else if (STR_IN_SET(name
, "AppArmorProfile", "SmackProcessLabel")) {
3496 r
= sd_bus_message_read(message
, "(bs)", &ignore
, &s
);
3500 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3504 if (streq(name
, "AppArmorProfile")) {
3505 p
= &c
->apparmor_profile
;
3506 b
= &c
->apparmor_profile_ignore
;
3507 } else { /* "SmackProcessLabel" */
3508 p
= &c
->smack_process_label
;
3509 b
= &c
->smack_process_label_ignore
;
3516 if (free_and_strdup(p
, s
) < 0)
3521 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "%s=%s%s", name
, ignore
? "-" : "", strempty(s
));
3526 } else if (STR_IN_SET(name
, "BindPaths", "BindReadOnlyPaths")) {
3527 char *source
, *destination
;
3529 uint64_t mount_flags
;
3532 r
= sd_bus_message_enter_container(message
, 'a', "(ssbt)");
3536 while ((r
= sd_bus_message_read(message
, "(ssbt)", &source
, &destination
, &ignore_enoent
, &mount_flags
)) > 0) {
3538 if (!path_is_absolute(source
))
3539 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Source path %s is not absolute.", source
);
3540 if (!path_is_absolute(destination
))
3541 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Destination path %s is not absolute.", destination
);
3542 if (!IN_SET(mount_flags
, 0, MS_REC
))
3543 return sd_bus_error_set(error
, SD_BUS_ERROR_INVALID_ARGS
, "Unknown mount flags.");
3545 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3546 r
= bind_mount_add(&c
->bind_mounts
, &c
->n_bind_mounts
,
3549 .destination
= destination
,
3550 .read_only
= !!strstr(name
, "ReadOnly"),
3551 .recursive
= !!(mount_flags
& MS_REC
),
3552 .ignore_enoent
= ignore_enoent
,
3557 unit_write_settingf(
3558 u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
,
3561 ignore_enoent
? "-" : "",
3564 (mount_flags
& MS_REC
) ? "rbind" : "norbind");
3572 r
= sd_bus_message_exit_container(message
);
3577 bind_mount_free_many(c
->bind_mounts
, c
->n_bind_mounts
);
3578 c
->bind_mounts
= NULL
;
3579 c
->n_bind_mounts
= 0;
3581 unit_write_settingf(u
, flags
, name
, "%s=", name
);
3586 } else if (streq(name
, "TemporaryFileSystem")) {
3587 const char *path
, *options
;
3590 r
= sd_bus_message_enter_container(message
, 'a', "(ss)");
3594 while ((r
= sd_bus_message_read(message
, "(ss)", &path
, &options
)) > 0) {
3596 if (!path_is_absolute(path
))
3597 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Mount point %s is not absolute.", path
);
3599 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3600 r
= temporary_filesystem_add(&c
->temporary_filesystems
, &c
->n_temporary_filesystems
, path
, options
);
3604 unit_write_settingf(
3605 u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
,
3617 r
= sd_bus_message_exit_container(message
);
3622 temporary_filesystem_free_many(c
->temporary_filesystems
, c
->n_temporary_filesystems
);
3623 c
->temporary_filesystems
= NULL
;
3624 c
->n_temporary_filesystems
= 0;
3626 unit_write_settingf(u
, flags
, name
, "%s=", name
);
3631 } else if ((suffix
= startswith(name
, "Limit"))) {
3632 const char *soft
= NULL
;
3635 ri
= rlimit_from_string(suffix
);
3637 soft
= endswith(suffix
, "Soft");
3641 n
= strndupa_safe(suffix
, soft
- suffix
);
3642 ri
= rlimit_from_string(n
);
3644 name
= strjoina("Limit", n
);
3652 r
= sd_bus_message_read(message
, "t", &rl
);
3656 if (rl
== UINT64_MAX
)
3661 if ((uint64_t) x
!= rl
)
3665 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3666 _cleanup_free_
char *f
= NULL
;
3669 if (c
->rlimit
[ri
]) {
3670 nl
= *c
->rlimit
[ri
];
3677 /* When the resource limit is not initialized yet, then assign the value to both fields */
3678 nl
= (struct rlimit
) {
3683 r
= rlimit_format(&nl
, &f
);
3688 *c
->rlimit
[ri
] = nl
;
3690 c
->rlimit
[ri
] = newdup(struct rlimit
, &nl
, 1);
3695 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, f
);
3701 } else if (streq(name
, "MountImages")) {
3702 _cleanup_free_
char *format_str
= NULL
;
3703 MountImage
*mount_images
= NULL
;
3704 size_t n_mount_images
= 0;
3705 char *source
, *destination
;
3708 r
= sd_bus_message_enter_container(message
, 'a', "(ssba(ss))");
3713 _cleanup_(mount_options_free_allp
) MountOptions
*options
= NULL
;
3714 _cleanup_free_
char *source_escaped
= NULL
, *destination_escaped
= NULL
;
3717 r
= sd_bus_message_enter_container(message
, 'r', "ssba(ss)");
3721 r
= sd_bus_message_read(message
, "ssb", &source
, &destination
, &permissive
);
3725 if (!path_is_absolute(source
))
3726 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Source path %s is not absolute.", source
);
3727 if (!path_is_normalized(source
))
3728 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Source path %s is not normalized.", source
);
3729 if (!path_is_absolute(destination
))
3730 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Destination path %s is not absolute.", destination
);
3731 if (!path_is_normalized(destination
))
3732 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Destination path %s is not normalized.", destination
);
3734 /* Need to store them in the unit with the escapes, so that they can be parsed again */
3735 source_escaped
= shell_escape(source
, ":");
3736 if (!source_escaped
)
3738 destination_escaped
= shell_escape(destination
, ":");
3739 if (!destination_escaped
)
3742 tuple
= strjoin(format_str
,
3743 format_str
? " " : "",
3744 permissive
? "-" : "",
3747 destination_escaped
);
3750 free_and_replace(format_str
, tuple
);
3752 r
= bus_read_mount_options(message
, error
, &options
, &format_str
, ":");
3756 r
= sd_bus_message_exit_container(message
);
3760 r
= mount_image_add(&mount_images
, &n_mount_images
,
3763 .destination
= destination
,
3764 .mount_options
= options
,
3765 .ignore_enoent
= permissive
,
3766 .type
= MOUNT_IMAGE_DISCRETE
,
3774 r
= sd_bus_message_exit_container(message
);
3778 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3779 if (n_mount_images
== 0) {
3780 c
->mount_images
= mount_image_free_many(c
->mount_images
, &c
->n_mount_images
);
3782 unit_write_settingf(u
, flags
, name
, "%s=", name
);
3784 for (size_t i
= 0; i
< n_mount_images
; ++i
) {
3785 r
= mount_image_add(&c
->mount_images
, &c
->n_mount_images
, &mount_images
[i
]);
3790 unit_write_settingf(u
, flags
|UNIT_ESCAPE_C
|UNIT_ESCAPE_SPECIFIERS
,
3798 mount_images
= mount_image_free_many(mount_images
, &n_mount_images
);
3801 } else if (streq(name
, "ExtensionImages")) {
3802 _cleanup_free_
char *format_str
= NULL
;
3803 MountImage
*extension_images
= NULL
;
3804 size_t n_extension_images
= 0;
3806 r
= sd_bus_message_enter_container(message
, 'a', "(sba(ss))");
3811 _cleanup_(mount_options_free_allp
) MountOptions
*options
= NULL
;
3812 _cleanup_free_
char *source_escaped
= NULL
;
3813 char *source
, *tuple
;
3816 r
= sd_bus_message_enter_container(message
, 'r', "sba(ss)");
3820 r
= sd_bus_message_read(message
, "sb", &source
, &permissive
);
3824 if (!path_is_absolute(source
))
3825 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Source path %s is not absolute.", source
);
3826 if (!path_is_normalized(source
))
3827 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Source path %s is not normalized.", source
);
3829 /* Need to store them in the unit with the escapes, so that they can be parsed again */
3830 source_escaped
= shell_escape(source
, ":");
3831 if (!source_escaped
)
3834 tuple
= strjoin(format_str
,
3835 format_str
? " " : "",
3836 permissive
? "-" : "",
3840 free_and_replace(format_str
, tuple
);
3842 r
= bus_read_mount_options(message
, error
, &options
, &format_str
, ":");
3846 r
= sd_bus_message_exit_container(message
);
3850 r
= mount_image_add(&extension_images
, &n_extension_images
,
3853 .mount_options
= options
,
3854 .ignore_enoent
= permissive
,
3855 .type
= MOUNT_IMAGE_EXTENSION
,
3863 r
= sd_bus_message_exit_container(message
);
3867 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3868 if (n_extension_images
== 0) {
3869 c
->extension_images
= mount_image_free_many(c
->extension_images
, &c
->n_extension_images
);
3871 unit_write_settingf(u
, flags
, name
, "%s=", name
);
3873 for (size_t i
= 0; i
< n_extension_images
; ++i
) {
3874 r
= mount_image_add(&c
->extension_images
, &c
->n_extension_images
, &extension_images
[i
]);
3879 unit_write_settingf(u
, flags
|UNIT_ESCAPE_C
|UNIT_ESCAPE_SPECIFIERS
,
3887 extension_images
= mount_image_free_many(extension_images
, &n_extension_images
);
3891 } else if (STR_IN_SET(name
, "StateDirectorySymlink", "RuntimeDirectorySymlink", "CacheDirectorySymlink", "LogsDirectorySymlink")) {
3892 char *source
, *destination
;
3893 ExecDirectory
*directory
;
3894 uint64_t symlink_flags
; /* No flags for now, reserved for future uses. */
3895 ExecDirectoryType i
;
3897 assert_se((i
= exec_directory_type_symlink_from_string(name
)) >= 0);
3898 directory
= c
->directories
+ i
;
3900 r
= sd_bus_message_enter_container(message
, 'a', "(sst)");
3904 while ((r
= sd_bus_message_read(message
, "(sst)", &source
, &destination
, &symlink_flags
)) > 0) {
3905 if (!path_is_valid(source
))
3906 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Source path %s is not valid.", source
);
3907 if (path_is_absolute(source
))
3908 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Source path %s is absolute.", source
);
3909 if (!path_is_normalized(source
))
3910 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Source path %s is not normalized.", source
);
3911 if (!path_is_valid(destination
))
3912 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Destination path %s is not valid.", destination
);
3913 if (path_is_absolute(destination
))
3914 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Destination path %s is absolute.", destination
);
3915 if (!path_is_normalized(destination
))
3916 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Destination path %s is not normalized.", destination
);
3917 if (symlink_flags
!= 0)
3918 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Flags must be zero.");
3920 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3921 _cleanup_free_
char *destination_escaped
= NULL
, *source_escaped
= NULL
;
3923 r
= exec_directory_add(directory
, source
, destination
);
3927 /* Need to store them in the unit with the escapes, so that they can be parsed again */
3928 source_escaped
= xescape(source
, ":");
3929 destination_escaped
= xescape(destination
, ":");
3930 if (!source_escaped
|| !destination_escaped
)
3933 unit_write_settingf(
3934 u
, flags
|UNIT_ESCAPE_SPECIFIERS
, exec_directory_type_to_string(i
),
3936 exec_directory_type_to_string(i
),
3938 destination_escaped
);
3944 exec_directory_sort(directory
);
3946 r
= sd_bus_message_exit_container(message
);
3952 } else if (STR_IN_SET(name
, "RootImagePolicy", "MountImagePolicy", "ExtensionImagePolicy")) {
3953 _cleanup_(image_policy_freep
) ImagePolicy
*p
= NULL
;
3956 r
= sd_bus_message_read(message
, "s", &s
);
3960 r
= image_policy_from_string(s
, &p
);
3962 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Failed to parse image policy string: %s", s
);
3964 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3965 _cleanup_free_
char *t
= NULL
;
3967 streq(name
, "RootImagePolicy") ? &c
->root_image_policy
:
3968 streq(name
, "MountImagePolicy") ? &c
->mount_image_policy
:
3969 &c
->extension_image_policy
;
3971 r
= image_policy_to_string(p
, /* simplify= */ true, &t
);
3975 image_policy_free(*pp
);
3978 unit_write_settingf(
3982 t
); /* no escaping necessary */