1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
11 #include "alloc-util.h"
12 #include "bus-get-properties.h"
15 #include "capability-util.h"
16 #include "cpu-set-util.h"
17 #include "creds-util.h"
18 #include "dbus-execute.h"
19 #include "dbus-util.h"
21 #include "errno-list.h"
26 #include "hexdecoct.h"
28 #include "ioprio-util.h"
29 #include "journal-file.h"
30 #include "load-fragment.h"
31 #include "memstream-util.h"
32 #include "missing_ioprio.h"
33 #include "mountpoint-util.h"
34 #include "namespace.h"
35 #include "parse-util.h"
36 #include "path-util.h"
37 #include "pcre2-util.h"
38 #include "process-util.h"
39 #include "rlimit-util.h"
41 #include "seccomp-util.h"
43 #include "securebits-util.h"
44 #include "specifier.h"
45 #include "stat-util.h"
47 #include "syslog-util.h"
48 #include "unit-printf.h"
49 #include "user-util.h"
52 BUS_DEFINE_PROPERTY_GET_ENUM(bus_property_get_exec_output
, exec_output
, ExecOutput
);
53 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_input
, exec_input
, ExecInput
);
54 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_utmp_mode
, exec_utmp_mode
, ExecUtmpMode
);
55 BUS_DEFINE_PROPERTY_GET_ENUM(bus_property_get_exec_preserve_mode
, exec_preserve_mode
, ExecPreserveMode
);
56 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_keyring_mode
, exec_keyring_mode
, ExecKeyringMode
);
57 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_protect_proc
, protect_proc
, ProtectProc
);
58 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_proc_subset
, proc_subset
, ProcSubset
);
59 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_protect_home
, protect_home
, ProtectHome
);
60 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_protect_system
, protect_system
, ProtectSystem
);
61 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_personality
, personality
, unsigned long);
62 static BUS_DEFINE_PROPERTY_GET(property_get_ioprio
, "i", ExecContext
, exec_context_get_effective_ioprio
);
63 static BUS_DEFINE_PROPERTY_GET(property_get_mount_apivfs
, "b", ExecContext
, exec_context_get_effective_mount_apivfs
);
64 static BUS_DEFINE_PROPERTY_GET2(property_get_ioprio_class
, "i", ExecContext
, exec_context_get_effective_ioprio
, ioprio_prio_class
);
65 static BUS_DEFINE_PROPERTY_GET2(property_get_ioprio_priority
, "i", ExecContext
, exec_context_get_effective_ioprio
, ioprio_prio_data
);
66 static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_empty_string
, "s", NULL
);
67 static BUS_DEFINE_PROPERTY_GET_REF(property_get_syslog_level
, "i", int, LOG_PRI
);
68 static BUS_DEFINE_PROPERTY_GET_REF(property_get_syslog_facility
, "i", int, LOG_FAC
);
69 static BUS_DEFINE_PROPERTY_GET(property_get_cpu_affinity_from_numa
, "b", ExecContext
, exec_context_get_cpu_affinity_from_numa
);
71 static int property_get_environment_files(
74 const char *interface
,
76 sd_bus_message
*reply
,
78 sd_bus_error
*error
) {
80 ExecContext
*c
= ASSERT_PTR(userdata
);
86 r
= sd_bus_message_open_container(reply
, 'a', "(sb)");
90 STRV_FOREACH(j
, c
->environment_files
) {
93 r
= sd_bus_message_append(reply
, "(sb)", fn
[0] == '-' ? fn
+ 1 : fn
, fn
[0] == '-');
98 return sd_bus_message_close_container(reply
);
101 static int property_get_oom_score_adjust(
104 const char *interface
,
105 const char *property
,
106 sd_bus_message
*reply
,
108 sd_bus_error
*error
) {
110 ExecContext
*c
= ASSERT_PTR(userdata
);
116 if (c
->oom_score_adjust_set
)
117 n
= c
->oom_score_adjust
;
120 r
= get_oom_score_adjust(&n
);
122 log_debug_errno(r
, "Failed to read /proc/self/oom_score_adj, ignoring: %m");
125 return sd_bus_message_append(reply
, "i", n
);
128 static int property_get_coredump_filter(
131 const char *interface
,
132 const char *property
,
133 sd_bus_message
*reply
,
135 sd_bus_error
*error
) {
137 ExecContext
*c
= ASSERT_PTR(userdata
);
144 if (c
->coredump_filter_set
)
145 n
= c
->coredump_filter
;
147 _cleanup_free_
char *t
= NULL
;
149 n
= COREDUMP_FILTER_MASK_DEFAULT
;
150 r
= read_one_line_file("/proc/self/coredump_filter", &t
);
152 log_debug_errno(r
, "Failed to read /proc/self/coredump_filter, ignoring: %m");
154 r
= safe_atoux64(t
, &n
);
156 log_debug_errno(r
, "Failed to parse \"%s\" from /proc/self/coredump_filter, ignoring: %m", t
);
160 return sd_bus_message_append(reply
, "t", n
);
163 static int property_get_nice(
166 const char *interface
,
167 const char *property
,
168 sd_bus_message
*reply
,
170 sd_bus_error
*error
) {
172 ExecContext
*c
= ASSERT_PTR(userdata
);
182 n
= getpriority(PRIO_PROCESS
, 0);
187 return sd_bus_message_append(reply
, "i", n
);
190 static int property_get_cpu_sched_policy(
193 const char *interface
,
194 const char *property
,
195 sd_bus_message
*reply
,
197 sd_bus_error
*error
) {
199 ExecContext
*c
= ASSERT_PTR(userdata
);
205 if (c
->cpu_sched_set
)
206 n
= c
->cpu_sched_policy
;
208 n
= sched_getscheduler(0);
213 return sd_bus_message_append(reply
, "i", n
);
216 static int property_get_cpu_sched_priority(
219 const char *interface
,
220 const char *property
,
221 sd_bus_message
*reply
,
223 sd_bus_error
*error
) {
225 ExecContext
*c
= ASSERT_PTR(userdata
);
231 if (c
->cpu_sched_set
)
232 n
= c
->cpu_sched_priority
;
234 struct sched_param p
= {};
236 if (sched_getparam(0, &p
) >= 0)
237 n
= p
.sched_priority
;
242 return sd_bus_message_append(reply
, "i", n
);
245 static int property_get_cpu_affinity(
248 const char *interface
,
249 const char *property
,
250 sd_bus_message
*reply
,
252 sd_bus_error
*error
) {
254 ExecContext
*c
= ASSERT_PTR(userdata
);
255 _cleanup_(cpu_set_reset
) CPUSet s
= {};
256 _cleanup_free_
uint8_t *array
= NULL
;
262 if (c
->cpu_affinity_from_numa
) {
265 r
= numa_to_cpu_set(&c
->numa_policy
, &s
);
270 (void) cpu_set_to_dbus(c
->cpu_affinity_from_numa
? &s
: &c
->cpu_set
, &array
, &allocated
);
272 return sd_bus_message_append_array(reply
, 'y', array
, allocated
);
275 static int property_get_numa_mask(
278 const char *interface
,
279 const char *property
,
280 sd_bus_message
*reply
,
282 sd_bus_error
*error
) {
284 ExecContext
*c
= ASSERT_PTR(userdata
);
285 _cleanup_free_
uint8_t *array
= NULL
;
291 (void) cpu_set_to_dbus(&c
->numa_policy
.nodes
, &array
, &allocated
);
293 return sd_bus_message_append_array(reply
, 'y', array
, allocated
);
296 static int property_get_numa_policy(
299 const char *interface
,
300 const char *property
,
301 sd_bus_message
*reply
,
303 sd_bus_error
*error
) {
304 ExecContext
*c
= ASSERT_PTR(userdata
);
310 policy
= numa_policy_get_type(&c
->numa_policy
);
312 return sd_bus_message_append_basic(reply
, 'i', &policy
);
315 static int property_get_timer_slack_nsec(
318 const char *interface
,
319 const char *property
,
320 sd_bus_message
*reply
,
322 sd_bus_error
*error
) {
324 ExecContext
*c
= ASSERT_PTR(userdata
);
330 if (c
->timer_slack_nsec
!= NSEC_INFINITY
)
331 u
= (uint64_t) c
->timer_slack_nsec
;
333 u
= (uint64_t) prctl(PR_GET_TIMERSLACK
);
335 return sd_bus_message_append(reply
, "t", u
);
338 static int property_get_syscall_filter(
341 const char *interface
,
342 const char *property
,
343 sd_bus_message
*reply
,
345 sd_bus_error
*error
) {
347 ExecContext
*c
= ASSERT_PTR(userdata
);
348 _cleanup_strv_free_
char **l
= NULL
;
354 r
= sd_bus_message_open_container(reply
, 'r', "bas");
358 r
= sd_bus_message_append(reply
, "b", c
->syscall_allow_list
);
364 HASHMAP_FOREACH_KEY(val
, id
, c
->syscall_filter
) {
365 _cleanup_free_
char *name
= NULL
;
366 const char *e
= NULL
;
368 int num
= PTR_TO_INT(val
);
370 if (c
->syscall_allow_list
&& num
>= 0)
371 /* syscall with num >= 0 in allow-list is denied. */
374 name
= seccomp_syscall_resolve_num_arch(SCMP_ARCH_NATIVE
, PTR_TO_INT(id
) - 1);
379 e
= seccomp_errno_or_action_to_string(num
);
381 s
= strjoin(name
, ":", e
);
385 r
= asprintf(&s
, "%s:%d", name
, num
);
392 r
= strv_consume(&l
, s
);
400 r
= sd_bus_message_append_strv(reply
, l
);
404 return sd_bus_message_close_container(reply
);
407 static int property_get_syscall_log(
410 const char *interface
,
411 const char *property
,
412 sd_bus_message
*reply
,
414 sd_bus_error
*error
) {
416 ExecContext
*c
= ASSERT_PTR(userdata
);
417 _cleanup_strv_free_
char **l
= NULL
;
423 r
= sd_bus_message_open_container(reply
, 'r', "bas");
427 r
= sd_bus_message_append(reply
, "b", c
->syscall_log_allow_list
);
433 HASHMAP_FOREACH_KEY(val
, id
, c
->syscall_log
) {
436 name
= seccomp_syscall_resolve_num_arch(SCMP_ARCH_NATIVE
, PTR_TO_INT(id
) - 1);
440 r
= strv_consume(&l
, name
);
448 r
= sd_bus_message_append_strv(reply
, l
);
452 return sd_bus_message_close_container(reply
);
455 static int property_get_syscall_archs(
458 const char *interface
,
459 const char *property
,
460 sd_bus_message
*reply
,
462 sd_bus_error
*error
) {
464 _cleanup_strv_free_
char **l
= NULL
;
472 SET_FOREACH(id
, ASSERT_PTR((ExecContext
*) userdata
)->syscall_archs
) {
475 name
= seccomp_arch_to_string(PTR_TO_UINT32(id
) - 1);
479 r
= strv_extend(&l
, name
);
487 r
= sd_bus_message_append_strv(reply
, l
);
494 static int property_get_selinux_context(
497 const char *interface
,
498 const char *property
,
499 sd_bus_message
*reply
,
501 sd_bus_error
*error
) {
503 ExecContext
*c
= ASSERT_PTR(userdata
);
508 return sd_bus_message_append(reply
, "(bs)", c
->selinux_context_ignore
, c
->selinux_context
);
511 static int property_get_apparmor_profile(
514 const char *interface
,
515 const char *property
,
516 sd_bus_message
*reply
,
518 sd_bus_error
*error
) {
520 ExecContext
*c
= ASSERT_PTR(userdata
);
525 return sd_bus_message_append(reply
, "(bs)", c
->apparmor_profile_ignore
, c
->apparmor_profile
);
528 static int property_get_smack_process_label(
531 const char *interface
,
532 const char *property
,
533 sd_bus_message
*reply
,
535 sd_bus_error
*error
) {
537 ExecContext
*c
= ASSERT_PTR(userdata
);
542 return sd_bus_message_append(reply
, "(bs)", c
->smack_process_label_ignore
, c
->smack_process_label
);
545 static int property_get_address_families(
548 const char *interface
,
549 const char *property
,
550 sd_bus_message
*reply
,
552 sd_bus_error
*error
) {
554 ExecContext
*c
= ASSERT_PTR(userdata
);
555 _cleanup_strv_free_
char **l
= NULL
;
562 r
= sd_bus_message_open_container(reply
, 'r', "bas");
566 r
= sd_bus_message_append(reply
, "b", c
->address_families_allow_list
);
570 SET_FOREACH(af
, c
->address_families
) {
573 name
= af_to_name(PTR_TO_INT(af
));
577 r
= strv_extend(&l
, name
);
584 r
= sd_bus_message_append_strv(reply
, l
);
588 return sd_bus_message_close_container(reply
);
591 static int property_get_working_directory(
594 const char *interface
,
595 const char *property
,
596 sd_bus_message
*reply
,
598 sd_bus_error
*error
) {
600 ExecContext
*c
= ASSERT_PTR(userdata
);
606 if (c
->working_directory_home
)
609 wd
= c
->working_directory
;
611 if (c
->working_directory_missing_ok
)
612 wd
= strjoina("!", wd
);
614 return sd_bus_message_append(reply
, "s", wd
);
617 static int property_get_stdio_fdname(
620 const char *interface
,
621 const char *property
,
622 sd_bus_message
*reply
,
624 sd_bus_error
*error
) {
626 ExecContext
*c
= ASSERT_PTR(userdata
);
633 if (streq(property
, "StandardInputFileDescriptorName"))
634 fileno
= STDIN_FILENO
;
635 else if (streq(property
, "StandardOutputFileDescriptorName"))
636 fileno
= STDOUT_FILENO
;
638 assert(streq(property
, "StandardErrorFileDescriptorName"));
639 fileno
= STDERR_FILENO
;
642 return sd_bus_message_append(reply
, "s", exec_context_fdname(c
, fileno
));
645 static int property_get_input_data(
648 const char *interface
,
649 const char *property
,
650 sd_bus_message
*reply
,
652 sd_bus_error
*error
) {
654 ExecContext
*c
= ASSERT_PTR(userdata
);
660 return sd_bus_message_append_array(reply
, 'y', c
->stdin_data
, c
->stdin_data_size
);
663 static int property_get_restrict_filesystems(
666 const char *interface
,
667 const char *property
,
668 sd_bus_message
*reply
,
670 sd_bus_error
*error
) {
672 ExecContext
*c
= ASSERT_PTR(userdata
);
673 _cleanup_free_
char **l
= NULL
;
679 r
= sd_bus_message_open_container(reply
, 'r', "bas");
683 r
= sd_bus_message_append(reply
, "b", c
->restrict_filesystems_allow_list
);
688 l
= set_get_strv(c
->restrict_filesystems
);
695 r
= sd_bus_message_append_strv(reply
, l
);
699 return sd_bus_message_close_container(reply
);
702 static int property_get_bind_paths(
705 const char *interface
,
706 const char *property
,
707 sd_bus_message
*reply
,
709 sd_bus_error
*error
) {
711 ExecContext
*c
= ASSERT_PTR(userdata
);
719 ro
= strstr(property
, "ReadOnly");
721 r
= sd_bus_message_open_container(reply
, 'a', "(ssbt)");
725 for (size_t i
= 0; i
< c
->n_bind_mounts
; i
++) {
727 if (ro
!= c
->bind_mounts
[i
].read_only
)
730 r
= sd_bus_message_append(
732 c
->bind_mounts
[i
].source
,
733 c
->bind_mounts
[i
].destination
,
734 c
->bind_mounts
[i
].ignore_enoent
,
735 c
->bind_mounts
[i
].recursive
? (uint64_t) MS_REC
: (uint64_t) 0);
740 return sd_bus_message_close_container(reply
);
743 static int property_get_temporary_filesystems(
746 const char *interface
,
747 const char *property
,
748 sd_bus_message
*reply
,
750 sd_bus_error
*error
) {
752 ExecContext
*c
= ASSERT_PTR(userdata
);
759 r
= sd_bus_message_open_container(reply
, 'a', "(ss)");
763 for (unsigned i
= 0; i
< c
->n_temporary_filesystems
; i
++) {
764 TemporaryFileSystem
*t
= c
->temporary_filesystems
+ i
;
766 r
= sd_bus_message_append(
774 return sd_bus_message_close_container(reply
);
777 static int property_get_log_extra_fields(
780 const char *interface
,
781 const char *property
,
782 sd_bus_message
*reply
,
784 sd_bus_error
*error
) {
786 ExecContext
*c
= ASSERT_PTR(userdata
);
793 r
= sd_bus_message_open_container(reply
, 'a', "ay");
797 for (size_t i
= 0; i
< c
->n_log_extra_fields
; i
++) {
798 r
= sd_bus_message_append_array(reply
, 'y', c
->log_extra_fields
[i
].iov_base
, c
->log_extra_fields
[i
].iov_len
);
803 return sd_bus_message_close_container(reply
);
806 static int sd_bus_message_append_log_filter_patterns(sd_bus_message
*reply
, Set
*patterns
, bool is_allowlist
) {
812 SET_FOREACH(pattern
, patterns
) {
813 r
= sd_bus_message_append(reply
, "(bs)", is_allowlist
, pattern
);
821 static int property_get_log_filter_patterns(
824 const char *interface
,
825 const char *property
,
826 sd_bus_message
*reply
,
828 sd_bus_error
*error
) {
830 ExecContext
*c
= userdata
;
836 r
= sd_bus_message_open_container(reply
, 'a', "(bs)");
840 r
= sd_bus_message_append_log_filter_patterns(reply
, c
->log_filter_allowed_patterns
,
841 /* is_allowlist = */ true);
845 r
= sd_bus_message_append_log_filter_patterns(reply
, c
->log_filter_denied_patterns
,
846 /* is_allowlist = */ false);
850 return sd_bus_message_close_container(reply
);
853 static int property_get_set_credential(
856 const char *interface
,
857 const char *property
,
858 sd_bus_message
*reply
,
860 sd_bus_error
*error
) {
862 ExecContext
*c
= ASSERT_PTR(userdata
);
863 ExecSetCredential
*sc
;
870 r
= sd_bus_message_open_container(reply
, 'a', "(say)");
874 HASHMAP_FOREACH(sc
, c
->set_credentials
) {
876 if (sc
->encrypted
!= streq(property
, "SetCredentialEncrypted"))
879 r
= sd_bus_message_open_container(reply
, 'r', "say");
883 r
= sd_bus_message_append(reply
, "s", sc
->id
);
887 r
= sd_bus_message_append_array(reply
, 'y', sc
->data
, sc
->size
);
891 r
= sd_bus_message_close_container(reply
);
896 return sd_bus_message_close_container(reply
);
899 static int property_get_load_credential(
902 const char *interface
,
903 const char *property
,
904 sd_bus_message
*reply
,
906 sd_bus_error
*error
) {
908 ExecContext
*c
= ASSERT_PTR(userdata
);
909 ExecLoadCredential
*lc
;
916 r
= sd_bus_message_open_container(reply
, 'a', "(ss)");
920 HASHMAP_FOREACH(lc
, c
->load_credentials
) {
922 if (lc
->encrypted
!= streq(property
, "LoadCredentialEncrypted"))
925 r
= sd_bus_message_append(reply
, "(ss)", lc
->id
, lc
->path
);
930 return sd_bus_message_close_container(reply
);
933 static int property_get_root_hash(
936 const char *interface
,
937 const char *property
,
938 sd_bus_message
*reply
,
940 sd_bus_error
*error
) {
942 ExecContext
*c
= ASSERT_PTR(userdata
);
948 return sd_bus_message_append_array(reply
, 'y', c
->root_hash
, c
->root_hash_size
);
951 static int property_get_root_hash_sig(
954 const char *interface
,
955 const char *property
,
956 sd_bus_message
*reply
,
958 sd_bus_error
*error
) {
960 ExecContext
*c
= ASSERT_PTR(userdata
);
966 return sd_bus_message_append_array(reply
, 'y', c
->root_hash_sig
, c
->root_hash_sig_size
);
969 static int property_get_root_image_options(
972 const char *interface
,
973 const char *property
,
974 sd_bus_message
*reply
,
976 sd_bus_error
*error
) {
978 ExecContext
*c
= ASSERT_PTR(userdata
);
985 r
= sd_bus_message_open_container(reply
, 'a', "(ss)");
989 LIST_FOREACH(mount_options
, m
, c
->root_image_options
) {
990 r
= sd_bus_message_append(reply
, "(ss)",
991 partition_designator_to_string(m
->partition_designator
),
997 return sd_bus_message_close_container(reply
);
1000 static int property_get_mount_images(
1003 const char *interface
,
1004 const char *property
,
1005 sd_bus_message
*reply
,
1007 sd_bus_error
*error
) {
1009 ExecContext
*c
= ASSERT_PTR(userdata
);
1016 r
= sd_bus_message_open_container(reply
, 'a', "(ssba(ss))");
1020 for (size_t i
= 0; i
< c
->n_mount_images
; i
++) {
1021 r
= sd_bus_message_open_container(reply
, SD_BUS_TYPE_STRUCT
, "ssba(ss)");
1024 r
= sd_bus_message_append(
1026 c
->mount_images
[i
].source
,
1027 c
->mount_images
[i
].destination
,
1028 c
->mount_images
[i
].ignore_enoent
);
1031 r
= sd_bus_message_open_container(reply
, 'a', "(ss)");
1034 LIST_FOREACH(mount_options
, m
, c
->mount_images
[i
].mount_options
) {
1035 r
= sd_bus_message_append(reply
, "(ss)",
1036 partition_designator_to_string(m
->partition_designator
),
1041 r
= sd_bus_message_close_container(reply
);
1044 r
= sd_bus_message_close_container(reply
);
1049 return sd_bus_message_close_container(reply
);
1052 static int property_get_extension_images(
1055 const char *interface
,
1056 const char *property
,
1057 sd_bus_message
*reply
,
1059 sd_bus_error
*error
) {
1061 ExecContext
*c
= ASSERT_PTR(userdata
);
1068 r
= sd_bus_message_open_container(reply
, 'a', "(sba(ss))");
1072 for (size_t i
= 0; i
< c
->n_extension_images
; i
++) {
1073 r
= sd_bus_message_open_container(reply
, SD_BUS_TYPE_STRUCT
, "sba(ss)");
1076 r
= sd_bus_message_append(
1078 c
->extension_images
[i
].source
,
1079 c
->extension_images
[i
].ignore_enoent
);
1082 r
= sd_bus_message_open_container(reply
, 'a', "(ss)");
1085 LIST_FOREACH(mount_options
, m
, c
->extension_images
[i
].mount_options
) {
1086 r
= sd_bus_message_append(reply
, "(ss)",
1087 partition_designator_to_string(m
->partition_designator
),
1092 r
= sd_bus_message_close_container(reply
);
1095 r
= sd_bus_message_close_container(reply
);
1100 return sd_bus_message_close_container(reply
);
1103 static int bus_property_get_exec_dir(
1106 const char *interface
,
1107 const char *property
,
1108 sd_bus_message
*reply
,
1110 sd_bus_error
*error
) {
1112 ExecDirectory
*d
= ASSERT_PTR(userdata
);
1119 r
= sd_bus_message_open_container(reply
, 'a', "s");
1123 for (size_t i
= 0; i
< d
->n_items
; i
++) {
1124 r
= sd_bus_message_append_basic(reply
, 's', d
->items
[i
].path
);
1129 return sd_bus_message_close_container(reply
);
1132 static int bus_property_get_exec_dir_symlink(
1135 const char *interface
,
1136 const char *property
,
1137 sd_bus_message
*reply
,
1139 sd_bus_error
*error
) {
1141 ExecDirectory
*d
= ASSERT_PTR(userdata
);
1148 r
= sd_bus_message_open_container(reply
, 'a', "(sst)");
1152 for (size_t i
= 0; i
< d
->n_items
; i
++)
1153 STRV_FOREACH(dst
, d
->items
[i
].symlinks
) {
1154 r
= sd_bus_message_append(reply
, "(sst)", d
->items
[i
].path
, *dst
, 0 /* flags, unused for now */);
1159 return sd_bus_message_close_container(reply
);
1162 static int property_get_image_policy(
1165 const char *interface
,
1166 const char *property
,
1167 sd_bus_message
*reply
,
1169 sd_bus_error
*error
) {
1171 ImagePolicy
**pp
= ASSERT_PTR(userdata
);
1172 _cleanup_free_
char *s
= NULL
;
1179 r
= image_policy_to_string(*pp
?: &image_policy_service
, /* simplify= */ true, &s
);
1183 return sd_bus_message_append(reply
, "s", s
);
1186 const sd_bus_vtable bus_exec_vtable
[] = {
1187 SD_BUS_VTABLE_START(0),
1188 SD_BUS_PROPERTY("Environment", "as", NULL
, offsetof(ExecContext
, environment
), SD_BUS_VTABLE_PROPERTY_CONST
),
1189 SD_BUS_PROPERTY("EnvironmentFiles", "a(sb)", property_get_environment_files
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1190 SD_BUS_PROPERTY("PassEnvironment", "as", NULL
, offsetof(ExecContext
, pass_environment
), SD_BUS_VTABLE_PROPERTY_CONST
),
1191 SD_BUS_PROPERTY("UnsetEnvironment", "as", NULL
, offsetof(ExecContext
, unset_environment
), SD_BUS_VTABLE_PROPERTY_CONST
),
1192 SD_BUS_PROPERTY("UMask", "u", bus_property_get_mode
, offsetof(ExecContext
, umask
), SD_BUS_VTABLE_PROPERTY_CONST
),
1193 SD_BUS_PROPERTY("LimitCPU", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_CPU
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1194 SD_BUS_PROPERTY("LimitCPUSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_CPU
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1195 SD_BUS_PROPERTY("LimitFSIZE", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_FSIZE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1196 SD_BUS_PROPERTY("LimitFSIZESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_FSIZE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1197 SD_BUS_PROPERTY("LimitDATA", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_DATA
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1198 SD_BUS_PROPERTY("LimitDATASoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_DATA
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1199 SD_BUS_PROPERTY("LimitSTACK", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_STACK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1200 SD_BUS_PROPERTY("LimitSTACKSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_STACK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1201 SD_BUS_PROPERTY("LimitCORE", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_CORE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1202 SD_BUS_PROPERTY("LimitCORESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_CORE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1203 SD_BUS_PROPERTY("LimitRSS", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RSS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1204 SD_BUS_PROPERTY("LimitRSSSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RSS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1205 SD_BUS_PROPERTY("LimitNOFILE", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NOFILE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1206 SD_BUS_PROPERTY("LimitNOFILESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NOFILE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1207 SD_BUS_PROPERTY("LimitAS", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_AS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1208 SD_BUS_PROPERTY("LimitASSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_AS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1209 SD_BUS_PROPERTY("LimitNPROC", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NPROC
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1210 SD_BUS_PROPERTY("LimitNPROCSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NPROC
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1211 SD_BUS_PROPERTY("LimitMEMLOCK", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_MEMLOCK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1212 SD_BUS_PROPERTY("LimitMEMLOCKSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_MEMLOCK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1213 SD_BUS_PROPERTY("LimitLOCKS", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_LOCKS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1214 SD_BUS_PROPERTY("LimitLOCKSSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_LOCKS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1215 SD_BUS_PROPERTY("LimitSIGPENDING", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_SIGPENDING
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1216 SD_BUS_PROPERTY("LimitSIGPENDINGSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_SIGPENDING
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1217 SD_BUS_PROPERTY("LimitMSGQUEUE", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_MSGQUEUE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1218 SD_BUS_PROPERTY("LimitMSGQUEUESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_MSGQUEUE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1219 SD_BUS_PROPERTY("LimitNICE", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NICE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1220 SD_BUS_PROPERTY("LimitNICESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NICE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1221 SD_BUS_PROPERTY("LimitRTPRIO", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RTPRIO
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1222 SD_BUS_PROPERTY("LimitRTPRIOSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RTPRIO
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1223 SD_BUS_PROPERTY("LimitRTTIME", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RTTIME
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1224 SD_BUS_PROPERTY("LimitRTTIMESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RTTIME
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1225 SD_BUS_PROPERTY("WorkingDirectory", "s", property_get_working_directory
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1226 SD_BUS_PROPERTY("RootDirectory", "s", NULL
, offsetof(ExecContext
, root_directory
), SD_BUS_VTABLE_PROPERTY_CONST
),
1227 SD_BUS_PROPERTY("RootImage", "s", NULL
, offsetof(ExecContext
, root_image
), SD_BUS_VTABLE_PROPERTY_CONST
),
1228 SD_BUS_PROPERTY("RootImageOptions", "a(ss)", property_get_root_image_options
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1229 SD_BUS_PROPERTY("RootHash", "ay", property_get_root_hash
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1230 SD_BUS_PROPERTY("RootHashPath", "s", NULL
, offsetof(ExecContext
, root_hash_path
), SD_BUS_VTABLE_PROPERTY_CONST
),
1231 SD_BUS_PROPERTY("RootHashSignature", "ay", property_get_root_hash_sig
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1232 SD_BUS_PROPERTY("RootHashSignaturePath", "s", NULL
, offsetof(ExecContext
, root_hash_sig_path
), SD_BUS_VTABLE_PROPERTY_CONST
),
1233 SD_BUS_PROPERTY("RootVerity", "s", NULL
, offsetof(ExecContext
, root_verity
), SD_BUS_VTABLE_PROPERTY_CONST
),
1234 SD_BUS_PROPERTY("RootEphemeral", "b", bus_property_get_bool
, offsetof(ExecContext
, root_ephemeral
), SD_BUS_VTABLE_PROPERTY_CONST
),
1235 SD_BUS_PROPERTY("ExtensionDirectories", "as", NULL
, offsetof(ExecContext
, extension_directories
), SD_BUS_VTABLE_PROPERTY_CONST
),
1236 SD_BUS_PROPERTY("ExtensionImages", "a(sba(ss))", property_get_extension_images
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1237 SD_BUS_PROPERTY("MountImages", "a(ssba(ss))", property_get_mount_images
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1238 SD_BUS_PROPERTY("OOMScoreAdjust", "i", property_get_oom_score_adjust
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1239 SD_BUS_PROPERTY("CoredumpFilter", "t", property_get_coredump_filter
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1240 SD_BUS_PROPERTY("Nice", "i", property_get_nice
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1241 SD_BUS_PROPERTY("IOSchedulingClass", "i", property_get_ioprio_class
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1242 SD_BUS_PROPERTY("IOSchedulingPriority", "i", property_get_ioprio_priority
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1243 SD_BUS_PROPERTY("CPUSchedulingPolicy", "i", property_get_cpu_sched_policy
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1244 SD_BUS_PROPERTY("CPUSchedulingPriority", "i", property_get_cpu_sched_priority
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1245 SD_BUS_PROPERTY("CPUAffinity", "ay", property_get_cpu_affinity
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1246 SD_BUS_PROPERTY("CPUAffinityFromNUMA", "b", property_get_cpu_affinity_from_numa
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1247 SD_BUS_PROPERTY("NUMAPolicy", "i", property_get_numa_policy
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1248 SD_BUS_PROPERTY("NUMAMask", "ay", property_get_numa_mask
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1249 SD_BUS_PROPERTY("TimerSlackNSec", "t", property_get_timer_slack_nsec
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1250 SD_BUS_PROPERTY("CPUSchedulingResetOnFork", "b", bus_property_get_bool
, offsetof(ExecContext
, cpu_sched_reset_on_fork
), SD_BUS_VTABLE_PROPERTY_CONST
),
1251 SD_BUS_PROPERTY("NonBlocking", "b", bus_property_get_bool
, offsetof(ExecContext
, non_blocking
), SD_BUS_VTABLE_PROPERTY_CONST
),
1252 SD_BUS_PROPERTY("StandardInput", "s", property_get_exec_input
, offsetof(ExecContext
, std_input
), SD_BUS_VTABLE_PROPERTY_CONST
),
1253 SD_BUS_PROPERTY("StandardInputFileDescriptorName", "s", property_get_stdio_fdname
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1254 SD_BUS_PROPERTY("StandardInputData", "ay", property_get_input_data
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1255 SD_BUS_PROPERTY("StandardOutput", "s", bus_property_get_exec_output
, offsetof(ExecContext
, std_output
), SD_BUS_VTABLE_PROPERTY_CONST
),
1256 SD_BUS_PROPERTY("StandardOutputFileDescriptorName", "s", property_get_stdio_fdname
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1257 SD_BUS_PROPERTY("StandardError", "s", bus_property_get_exec_output
, offsetof(ExecContext
, std_error
), SD_BUS_VTABLE_PROPERTY_CONST
),
1258 SD_BUS_PROPERTY("StandardErrorFileDescriptorName", "s", property_get_stdio_fdname
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1259 SD_BUS_PROPERTY("TTYPath", "s", NULL
, offsetof(ExecContext
, tty_path
), SD_BUS_VTABLE_PROPERTY_CONST
),
1260 SD_BUS_PROPERTY("TTYReset", "b", bus_property_get_bool
, offsetof(ExecContext
, tty_reset
), SD_BUS_VTABLE_PROPERTY_CONST
),
1261 SD_BUS_PROPERTY("TTYVHangup", "b", bus_property_get_bool
, offsetof(ExecContext
, tty_vhangup
), SD_BUS_VTABLE_PROPERTY_CONST
),
1262 SD_BUS_PROPERTY("TTYVTDisallocate", "b", bus_property_get_bool
, offsetof(ExecContext
, tty_vt_disallocate
), SD_BUS_VTABLE_PROPERTY_CONST
),
1263 SD_BUS_PROPERTY("TTYRows", "q", bus_property_get_unsigned
, offsetof(ExecContext
, tty_rows
), SD_BUS_VTABLE_PROPERTY_CONST
),
1264 SD_BUS_PROPERTY("TTYColumns", "q", bus_property_get_unsigned
, offsetof(ExecContext
, tty_cols
), SD_BUS_VTABLE_PROPERTY_CONST
),
1265 SD_BUS_PROPERTY("SyslogPriority", "i", bus_property_get_int
, offsetof(ExecContext
, syslog_priority
), SD_BUS_VTABLE_PROPERTY_CONST
),
1266 SD_BUS_PROPERTY("SyslogIdentifier", "s", NULL
, offsetof(ExecContext
, syslog_identifier
), SD_BUS_VTABLE_PROPERTY_CONST
),
1267 SD_BUS_PROPERTY("SyslogLevelPrefix", "b", bus_property_get_bool
, offsetof(ExecContext
, syslog_level_prefix
), SD_BUS_VTABLE_PROPERTY_CONST
),
1268 SD_BUS_PROPERTY("SyslogLevel", "i", property_get_syslog_level
, offsetof(ExecContext
, syslog_priority
), SD_BUS_VTABLE_PROPERTY_CONST
),
1269 SD_BUS_PROPERTY("SyslogFacility", "i", property_get_syslog_facility
, offsetof(ExecContext
, syslog_priority
), SD_BUS_VTABLE_PROPERTY_CONST
),
1270 SD_BUS_PROPERTY("LogLevelMax", "i", bus_property_get_int
, offsetof(ExecContext
, log_level_max
), SD_BUS_VTABLE_PROPERTY_CONST
),
1271 SD_BUS_PROPERTY("LogRateLimitIntervalUSec", "t", bus_property_get_usec
, offsetof(ExecContext
, log_ratelimit_interval_usec
), SD_BUS_VTABLE_PROPERTY_CONST
),
1272 SD_BUS_PROPERTY("LogRateLimitBurst", "u", bus_property_get_unsigned
, offsetof(ExecContext
, log_ratelimit_burst
), SD_BUS_VTABLE_PROPERTY_CONST
),
1273 SD_BUS_PROPERTY("LogExtraFields", "aay", property_get_log_extra_fields
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1274 SD_BUS_PROPERTY("LogFilterPatterns", "a(bs)", property_get_log_filter_patterns
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1275 SD_BUS_PROPERTY("LogNamespace", "s", NULL
, offsetof(ExecContext
, log_namespace
), SD_BUS_VTABLE_PROPERTY_CONST
),
1276 SD_BUS_PROPERTY("SecureBits", "i", bus_property_get_int
, offsetof(ExecContext
, secure_bits
), SD_BUS_VTABLE_PROPERTY_CONST
),
1277 SD_BUS_PROPERTY("CapabilityBoundingSet", "t", NULL
, offsetof(ExecContext
, capability_bounding_set
), SD_BUS_VTABLE_PROPERTY_CONST
),
1278 SD_BUS_PROPERTY("AmbientCapabilities", "t", NULL
, offsetof(ExecContext
, capability_ambient_set
), SD_BUS_VTABLE_PROPERTY_CONST
),
1279 SD_BUS_PROPERTY("User", "s", NULL
, offsetof(ExecContext
, user
), SD_BUS_VTABLE_PROPERTY_CONST
),
1280 SD_BUS_PROPERTY("Group", "s", NULL
, offsetof(ExecContext
, group
), SD_BUS_VTABLE_PROPERTY_CONST
),
1281 SD_BUS_PROPERTY("DynamicUser", "b", bus_property_get_bool
, offsetof(ExecContext
, dynamic_user
), SD_BUS_VTABLE_PROPERTY_CONST
),
1282 SD_BUS_PROPERTY("RemoveIPC", "b", bus_property_get_bool
, offsetof(ExecContext
, remove_ipc
), SD_BUS_VTABLE_PROPERTY_CONST
),
1283 SD_BUS_PROPERTY("SetCredential", "a(say)", property_get_set_credential
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1284 SD_BUS_PROPERTY("SetCredentialEncrypted", "a(say)", property_get_set_credential
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1285 SD_BUS_PROPERTY("LoadCredential", "a(ss)", property_get_load_credential
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1286 SD_BUS_PROPERTY("LoadCredentialEncrypted", "a(ss)", property_get_load_credential
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1287 SD_BUS_PROPERTY("ImportCredential", "as", bus_property_get_string_set
, offsetof(ExecContext
, import_credentials
), SD_BUS_VTABLE_PROPERTY_CONST
),
1288 SD_BUS_PROPERTY("SupplementaryGroups", "as", NULL
, offsetof(ExecContext
, supplementary_groups
), SD_BUS_VTABLE_PROPERTY_CONST
),
1289 SD_BUS_PROPERTY("PAMName", "s", NULL
, offsetof(ExecContext
, pam_name
), SD_BUS_VTABLE_PROPERTY_CONST
),
1290 SD_BUS_PROPERTY("ReadWritePaths", "as", NULL
, offsetof(ExecContext
, read_write_paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
1291 SD_BUS_PROPERTY("ReadOnlyPaths", "as", NULL
, offsetof(ExecContext
, read_only_paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
1292 SD_BUS_PROPERTY("InaccessiblePaths", "as", NULL
, offsetof(ExecContext
, inaccessible_paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
1293 SD_BUS_PROPERTY("ExecPaths", "as", NULL
, offsetof(ExecContext
, exec_paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
1294 SD_BUS_PROPERTY("NoExecPaths", "as", NULL
, offsetof(ExecContext
, no_exec_paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
1295 SD_BUS_PROPERTY("ExecSearchPath", "as", NULL
, offsetof(ExecContext
, exec_search_path
), SD_BUS_VTABLE_PROPERTY_CONST
),
1296 SD_BUS_PROPERTY("MountFlags", "t", bus_property_get_ulong
, offsetof(ExecContext
, mount_propagation_flag
), SD_BUS_VTABLE_PROPERTY_CONST
),
1297 SD_BUS_PROPERTY("PrivateTmp", "b", bus_property_get_bool
, offsetof(ExecContext
, private_tmp
), SD_BUS_VTABLE_PROPERTY_CONST
),
1298 SD_BUS_PROPERTY("PrivateDevices", "b", bus_property_get_bool
, offsetof(ExecContext
, private_devices
), SD_BUS_VTABLE_PROPERTY_CONST
),
1299 SD_BUS_PROPERTY("ProtectClock", "b", bus_property_get_bool
, offsetof(ExecContext
, protect_clock
), SD_BUS_VTABLE_PROPERTY_CONST
),
1300 SD_BUS_PROPERTY("ProtectKernelTunables", "b", bus_property_get_bool
, offsetof(ExecContext
, protect_kernel_tunables
), SD_BUS_VTABLE_PROPERTY_CONST
),
1301 SD_BUS_PROPERTY("ProtectKernelModules", "b", bus_property_get_bool
, offsetof(ExecContext
, protect_kernel_modules
), SD_BUS_VTABLE_PROPERTY_CONST
),
1302 SD_BUS_PROPERTY("ProtectKernelLogs", "b", bus_property_get_bool
, offsetof(ExecContext
, protect_kernel_logs
), SD_BUS_VTABLE_PROPERTY_CONST
),
1303 SD_BUS_PROPERTY("ProtectControlGroups", "b", bus_property_get_bool
, offsetof(ExecContext
, protect_control_groups
), SD_BUS_VTABLE_PROPERTY_CONST
),
1304 SD_BUS_PROPERTY("PrivateNetwork", "b", bus_property_get_bool
, offsetof(ExecContext
, private_network
), SD_BUS_VTABLE_PROPERTY_CONST
),
1305 SD_BUS_PROPERTY("PrivateUsers", "b", bus_property_get_bool
, offsetof(ExecContext
, private_users
), SD_BUS_VTABLE_PROPERTY_CONST
),
1306 SD_BUS_PROPERTY("PrivateMounts", "b", bus_property_get_tristate
, offsetof(ExecContext
, private_mounts
), SD_BUS_VTABLE_PROPERTY_CONST
),
1307 SD_BUS_PROPERTY("PrivateIPC", "b", bus_property_get_bool
, offsetof(ExecContext
, private_ipc
), SD_BUS_VTABLE_PROPERTY_CONST
),
1308 SD_BUS_PROPERTY("ProtectHome", "s", property_get_protect_home
, offsetof(ExecContext
, protect_home
), SD_BUS_VTABLE_PROPERTY_CONST
),
1309 SD_BUS_PROPERTY("ProtectSystem", "s", property_get_protect_system
, offsetof(ExecContext
, protect_system
), SD_BUS_VTABLE_PROPERTY_CONST
),
1310 SD_BUS_PROPERTY("SameProcessGroup", "b", bus_property_get_bool
, offsetof(ExecContext
, same_pgrp
), SD_BUS_VTABLE_PROPERTY_CONST
),
1311 SD_BUS_PROPERTY("UtmpIdentifier", "s", NULL
, offsetof(ExecContext
, utmp_id
), SD_BUS_VTABLE_PROPERTY_CONST
),
1312 SD_BUS_PROPERTY("UtmpMode", "s", property_get_exec_utmp_mode
, offsetof(ExecContext
, utmp_mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
1313 SD_BUS_PROPERTY("SELinuxContext", "(bs)", property_get_selinux_context
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1314 SD_BUS_PROPERTY("AppArmorProfile", "(bs)", property_get_apparmor_profile
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1315 SD_BUS_PROPERTY("SmackProcessLabel", "(bs)", property_get_smack_process_label
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1316 SD_BUS_PROPERTY("IgnoreSIGPIPE", "b", bus_property_get_bool
, offsetof(ExecContext
, ignore_sigpipe
), SD_BUS_VTABLE_PROPERTY_CONST
),
1317 SD_BUS_PROPERTY("NoNewPrivileges", "b", bus_property_get_bool
, offsetof(ExecContext
, no_new_privileges
), SD_BUS_VTABLE_PROPERTY_CONST
),
1318 SD_BUS_PROPERTY("SystemCallFilter", "(bas)", property_get_syscall_filter
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1319 SD_BUS_PROPERTY("SystemCallArchitectures", "as", property_get_syscall_archs
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1320 SD_BUS_PROPERTY("SystemCallErrorNumber", "i", bus_property_get_int
, offsetof(ExecContext
, syscall_errno
), SD_BUS_VTABLE_PROPERTY_CONST
),
1321 SD_BUS_PROPERTY("SystemCallLog", "(bas)", property_get_syscall_log
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1322 SD_BUS_PROPERTY("Personality", "s", property_get_personality
, offsetof(ExecContext
, personality
), SD_BUS_VTABLE_PROPERTY_CONST
),
1323 SD_BUS_PROPERTY("LockPersonality", "b", bus_property_get_bool
, offsetof(ExecContext
, lock_personality
), SD_BUS_VTABLE_PROPERTY_CONST
),
1324 SD_BUS_PROPERTY("RestrictAddressFamilies", "(bas)", property_get_address_families
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1325 SD_BUS_PROPERTY("RuntimeDirectorySymlink", "a(sst)", bus_property_get_exec_dir_symlink
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_RUNTIME
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1326 SD_BUS_PROPERTY("RuntimeDirectoryPreserve", "s", bus_property_get_exec_preserve_mode
, offsetof(ExecContext
, runtime_directory_preserve_mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
1327 SD_BUS_PROPERTY("RuntimeDirectoryMode", "u", bus_property_get_mode
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_RUNTIME
].mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
1328 SD_BUS_PROPERTY("RuntimeDirectory", "as", bus_property_get_exec_dir
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_RUNTIME
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1329 SD_BUS_PROPERTY("StateDirectorySymlink", "a(sst)", bus_property_get_exec_dir_symlink
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_STATE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1330 SD_BUS_PROPERTY("StateDirectoryMode", "u", bus_property_get_mode
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_STATE
].mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
1331 SD_BUS_PROPERTY("StateDirectory", "as", bus_property_get_exec_dir
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_STATE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1332 SD_BUS_PROPERTY("CacheDirectorySymlink", "a(sst)", bus_property_get_exec_dir_symlink
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_CACHE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1333 SD_BUS_PROPERTY("CacheDirectoryMode", "u", bus_property_get_mode
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_CACHE
].mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
1334 SD_BUS_PROPERTY("CacheDirectory", "as", bus_property_get_exec_dir
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_CACHE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1335 SD_BUS_PROPERTY("LogsDirectorySymlink", "a(sst)", bus_property_get_exec_dir_symlink
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_LOGS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1336 SD_BUS_PROPERTY("LogsDirectoryMode", "u", bus_property_get_mode
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_LOGS
].mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
1337 SD_BUS_PROPERTY("LogsDirectory", "as", bus_property_get_exec_dir
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_LOGS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1338 SD_BUS_PROPERTY("ConfigurationDirectoryMode", "u", bus_property_get_mode
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_CONFIGURATION
].mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
1339 SD_BUS_PROPERTY("ConfigurationDirectory", "as", bus_property_get_exec_dir
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_CONFIGURATION
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1340 SD_BUS_PROPERTY("TimeoutCleanUSec", "t", bus_property_get_usec
, offsetof(ExecContext
, timeout_clean_usec
), SD_BUS_VTABLE_PROPERTY_CONST
),
1341 SD_BUS_PROPERTY("MemoryDenyWriteExecute", "b", bus_property_get_bool
, offsetof(ExecContext
, memory_deny_write_execute
), SD_BUS_VTABLE_PROPERTY_CONST
),
1342 SD_BUS_PROPERTY("RestrictRealtime", "b", bus_property_get_bool
, offsetof(ExecContext
, restrict_realtime
), SD_BUS_VTABLE_PROPERTY_CONST
),
1343 SD_BUS_PROPERTY("RestrictSUIDSGID", "b", bus_property_get_bool
, offsetof(ExecContext
, restrict_suid_sgid
), SD_BUS_VTABLE_PROPERTY_CONST
),
1344 SD_BUS_PROPERTY("RestrictNamespaces", "t", bus_property_get_ulong
, offsetof(ExecContext
, restrict_namespaces
), SD_BUS_VTABLE_PROPERTY_CONST
),
1345 SD_BUS_PROPERTY("RestrictFileSystems", "(bas)", property_get_restrict_filesystems
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1346 SD_BUS_PROPERTY("BindPaths", "a(ssbt)", property_get_bind_paths
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1347 SD_BUS_PROPERTY("BindReadOnlyPaths", "a(ssbt)", property_get_bind_paths
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1348 SD_BUS_PROPERTY("TemporaryFileSystem", "a(ss)", property_get_temporary_filesystems
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1349 SD_BUS_PROPERTY("MountAPIVFS", "b", property_get_mount_apivfs
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1350 SD_BUS_PROPERTY("KeyringMode", "s", property_get_exec_keyring_mode
, offsetof(ExecContext
, keyring_mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
1351 SD_BUS_PROPERTY("ProtectProc", "s", property_get_protect_proc
, offsetof(ExecContext
, protect_proc
), SD_BUS_VTABLE_PROPERTY_CONST
),
1352 SD_BUS_PROPERTY("ProcSubset", "s", property_get_proc_subset
, offsetof(ExecContext
, proc_subset
), SD_BUS_VTABLE_PROPERTY_CONST
),
1353 SD_BUS_PROPERTY("ProtectHostname", "b", bus_property_get_bool
, offsetof(ExecContext
, protect_hostname
), SD_BUS_VTABLE_PROPERTY_CONST
),
1354 SD_BUS_PROPERTY("MemoryKSM", "b", bus_property_get_tristate
, offsetof(ExecContext
, memory_ksm
), SD_BUS_VTABLE_PROPERTY_CONST
),
1355 SD_BUS_PROPERTY("NetworkNamespacePath", "s", NULL
, offsetof(ExecContext
, network_namespace_path
), SD_BUS_VTABLE_PROPERTY_CONST
),
1356 SD_BUS_PROPERTY("IPCNamespacePath", "s", NULL
, offsetof(ExecContext
, ipc_namespace_path
), SD_BUS_VTABLE_PROPERTY_CONST
),
1357 SD_BUS_PROPERTY("RootImagePolicy", "s", property_get_image_policy
, offsetof(ExecContext
, root_image_policy
), SD_BUS_VTABLE_PROPERTY_CONST
),
1358 SD_BUS_PROPERTY("MountImagePolicy", "s", property_get_image_policy
, offsetof(ExecContext
, mount_image_policy
), SD_BUS_VTABLE_PROPERTY_CONST
),
1359 SD_BUS_PROPERTY("ExtensionImagePolicy", "s", property_get_image_policy
, offsetof(ExecContext
, extension_image_policy
), SD_BUS_VTABLE_PROPERTY_CONST
),
1361 /* Obsolete/redundant properties: */
1362 SD_BUS_PROPERTY("Capabilities", "s", property_get_empty_string
, 0, SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
1363 SD_BUS_PROPERTY("ReadWriteDirectories", "as", NULL
, offsetof(ExecContext
, read_write_paths
), SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
1364 SD_BUS_PROPERTY("ReadOnlyDirectories", "as", NULL
, offsetof(ExecContext
, read_only_paths
), SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
1365 SD_BUS_PROPERTY("InaccessibleDirectories", "as", NULL
, offsetof(ExecContext
, inaccessible_paths
), SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
1366 SD_BUS_PROPERTY("IOScheduling", "i", property_get_ioprio
, 0, SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
1371 static int append_exec_command(sd_bus_message
*reply
, ExecCommand
*c
) {
1380 r
= sd_bus_message_open_container(reply
, 'r', "sasbttttuii");
1384 r
= sd_bus_message_append(reply
, "s", c
->path
);
1388 r
= sd_bus_message_append_strv(reply
, c
->argv
);
1392 r
= sd_bus_message_append(reply
, "bttttuii",
1393 !!(c
->flags
& EXEC_COMMAND_IGNORE_FAILURE
),
1394 c
->exec_status
.start_timestamp
.realtime
,
1395 c
->exec_status
.start_timestamp
.monotonic
,
1396 c
->exec_status
.exit_timestamp
.realtime
,
1397 c
->exec_status
.exit_timestamp
.monotonic
,
1398 (uint32_t) c
->exec_status
.pid
,
1399 (int32_t) c
->exec_status
.code
,
1400 (int32_t) c
->exec_status
.status
);
1404 return sd_bus_message_close_container(reply
);
1407 static int append_exec_ex_command(sd_bus_message
*reply
, ExecCommand
*c
) {
1408 _cleanup_strv_free_
char **ex_opts
= NULL
;
1417 r
= sd_bus_message_open_container(reply
, 'r', "sasasttttuii");
1421 r
= sd_bus_message_append(reply
, "s", c
->path
);
1425 r
= sd_bus_message_append_strv(reply
, c
->argv
);
1429 r
= exec_command_flags_to_strv(c
->flags
, &ex_opts
);
1433 r
= sd_bus_message_append_strv(reply
, ex_opts
);
1437 r
= sd_bus_message_append(reply
, "ttttuii",
1438 c
->exec_status
.start_timestamp
.realtime
,
1439 c
->exec_status
.start_timestamp
.monotonic
,
1440 c
->exec_status
.exit_timestamp
.realtime
,
1441 c
->exec_status
.exit_timestamp
.monotonic
,
1442 (uint32_t) c
->exec_status
.pid
,
1443 (int32_t) c
->exec_status
.code
,
1444 (int32_t) c
->exec_status
.status
);
1448 return sd_bus_message_close_container(reply
);
1451 int bus_property_get_exec_command(
1454 const char *interface
,
1455 const char *property
,
1456 sd_bus_message
*reply
,
1458 sd_bus_error
*ret_error
) {
1460 ExecCommand
*c
= (ExecCommand
*) userdata
;
1466 r
= sd_bus_message_open_container(reply
, 'a', "(sasbttttuii)");
1470 r
= append_exec_command(reply
, c
);
1474 return sd_bus_message_close_container(reply
);
1477 int bus_property_get_exec_command_list(
1480 const char *interface
,
1481 const char *property
,
1482 sd_bus_message
*reply
,
1484 sd_bus_error
*ret_error
) {
1486 ExecCommand
*exec_command
= *(ExecCommand
**) userdata
;
1492 r
= sd_bus_message_open_container(reply
, 'a', "(sasbttttuii)");
1496 LIST_FOREACH(command
, c
, exec_command
) {
1497 r
= append_exec_command(reply
, c
);
1502 return sd_bus_message_close_container(reply
);
1505 int bus_property_get_exec_ex_command_list(
1508 const char *interface
,
1509 const char *property
,
1510 sd_bus_message
*reply
,
1512 sd_bus_error
*ret_error
) {
1514 ExecCommand
*exec_command
= *(ExecCommand
**) userdata
;
1520 r
= sd_bus_message_open_container(reply
, 'a', "(sasasttttuii)");
1524 LIST_FOREACH(command
, c
, exec_command
) {
1525 r
= append_exec_ex_command(reply
, c
);
1530 return sd_bus_message_close_container(reply
);
1533 static char *exec_command_flags_to_exec_chars(ExecCommandFlags flags
) {
1534 return strjoin(FLAGS_SET(flags
, EXEC_COMMAND_IGNORE_FAILURE
) ? "-" : "",
1535 FLAGS_SET(flags
, EXEC_COMMAND_NO_ENV_EXPAND
) ? ":" : "",
1536 FLAGS_SET(flags
, EXEC_COMMAND_FULLY_PRIVILEGED
) ? "+" : "",
1537 FLAGS_SET(flags
, EXEC_COMMAND_NO_SETUID
) ? "!" : "",
1538 FLAGS_SET(flags
, EXEC_COMMAND_AMBIENT_MAGIC
) ? "!!" : "");
1541 int bus_set_transient_exec_command(
1544 ExecCommand
**exec_command
,
1545 sd_bus_message
*message
,
1546 UnitWriteFlags flags
,
1547 sd_bus_error
*error
) {
1548 bool is_ex_prop
= endswith(name
, "Ex");
1552 /* Drop Ex from the written setting. E.g. ExecStart=, not ExecStartEx=. */
1553 const char *written_name
= is_ex_prop
? strndupa(name
, strlen(name
) - 2) : name
;
1555 r
= sd_bus_message_enter_container(message
, 'a', is_ex_prop
? "(sasas)" : "(sasb)");
1559 while ((r
= sd_bus_message_enter_container(message
, 'r', is_ex_prop
? "sasas" : "sasb")) > 0) {
1560 _cleanup_strv_free_
char **argv
= NULL
, **ex_opts
= NULL
;
1564 r
= sd_bus_message_read(message
, "s", &path
);
1568 if (!path_is_absolute(path
) && !filename_is_valid(path
))
1569 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
,
1570 "\"%s\" is neither a valid executable name nor an absolute path",
1573 r
= sd_bus_message_read_strv(message
, &argv
);
1577 if (strv_isempty(argv
))
1578 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
,
1579 "\"%s\" argv cannot be empty", name
);
1581 r
= is_ex_prop
? sd_bus_message_read_strv(message
, &ex_opts
) : sd_bus_message_read(message
, "b", &b
);
1585 r
= sd_bus_message_exit_container(message
);
1589 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1592 c
= new0(ExecCommand
, 1);
1596 c
->path
= strdup(path
);
1602 c
->argv
= TAKE_PTR(argv
);
1605 r
= exec_command_flags_from_strv(ex_opts
, &c
->flags
);
1609 c
->flags
= b
? EXEC_COMMAND_IGNORE_FAILURE
: 0;
1611 path_simplify(c
->path
);
1612 exec_command_append_list(exec_command
, c
);
1620 r
= sd_bus_message_exit_container(message
);
1624 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1625 _cleanup_(memstream_done
) MemStream m
= {};
1626 _cleanup_free_
char *buf
= NULL
;
1630 *exec_command
= exec_command_free_list(*exec_command
);
1632 f
= memstream_init(&m
);
1636 fprintf(f
, "%s=\n", written_name
);
1638 LIST_FOREACH(command
, c
, *exec_command
) {
1639 _cleanup_free_
char *a
= NULL
, *exec_chars
= NULL
;
1640 UnitWriteFlags esc_flags
= UNIT_ESCAPE_SPECIFIERS
|
1641 (FLAGS_SET(c
->flags
, EXEC_COMMAND_NO_ENV_EXPAND
) ? UNIT_ESCAPE_EXEC_SYNTAX
: UNIT_ESCAPE_EXEC_SYNTAX_ENV
);
1643 exec_chars
= exec_command_flags_to_exec_chars(c
->flags
);
1647 a
= unit_concat_strv(c
->argv
, esc_flags
);
1651 if (streq_ptr(c
->path
, c
->argv
? c
->argv
[0] : NULL
))
1652 fprintf(f
, "%s=%s%s\n", written_name
, exec_chars
, a
);
1654 _cleanup_free_
char *t
= NULL
;
1657 p
= unit_escape_setting(c
->path
, esc_flags
, &t
);
1661 fprintf(f
, "%s=%s@%s %s\n", written_name
, exec_chars
, p
, a
);
1665 r
= memstream_finalize(&m
, &buf
, NULL
);
1669 unit_write_setting(u
, flags
, written_name
, buf
);
1675 static int parse_personality(const char *s
, unsigned long *p
) {
1680 v
= personality_from_string(s
);
1681 if (v
== PERSONALITY_INVALID
)
1688 static const char* mount_propagation_flag_to_string_with_check(unsigned long n
) {
1689 if (!mount_propagation_flag_is_valid(n
))
1692 return mount_propagation_flag_to_string(n
);
1695 static BUS_DEFINE_SET_TRANSIENT(nsec
, "t", uint64_t, nsec_t
, NSEC_FMT
);
1696 static BUS_DEFINE_SET_TRANSIENT_IS_VALID(log_level
, "i", int32_t, int, "%" PRIi32
, log_level_is_valid
);
1698 static BUS_DEFINE_SET_TRANSIENT_IS_VALID(errno
, "i", int32_t, int, "%" PRIi32
, seccomp_errno_or_action_is_valid
);
1700 static BUS_DEFINE_SET_TRANSIENT_PARSE(std_input
, ExecInput
, exec_input_from_string
);
1701 static BUS_DEFINE_SET_TRANSIENT_PARSE(std_output
, ExecOutput
, exec_output_from_string
);
1702 static BUS_DEFINE_SET_TRANSIENT_PARSE(utmp_mode
, ExecUtmpMode
, exec_utmp_mode_from_string
);
1703 static BUS_DEFINE_SET_TRANSIENT_PARSE(protect_system
, ProtectSystem
, protect_system_from_string
);
1704 static BUS_DEFINE_SET_TRANSIENT_PARSE(protect_home
, ProtectHome
, protect_home_from_string
);
1705 static BUS_DEFINE_SET_TRANSIENT_PARSE(keyring_mode
, ExecKeyringMode
, exec_keyring_mode_from_string
);
1706 static BUS_DEFINE_SET_TRANSIENT_PARSE(protect_proc
, ProtectProc
, protect_proc_from_string
);
1707 static BUS_DEFINE_SET_TRANSIENT_PARSE(proc_subset
, ProcSubset
, proc_subset_from_string
);
1708 BUS_DEFINE_SET_TRANSIENT_PARSE(exec_preserve_mode
, ExecPreserveMode
, exec_preserve_mode_from_string
);
1709 static BUS_DEFINE_SET_TRANSIENT_PARSE_PTR(personality
, unsigned long, parse_personality
);
1710 static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(secure_bits
, "i", int32_t, int, "%" PRIi32
, secure_bits_to_string_alloc_with_check
);
1711 static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(capability
, "t", uint64_t, uint64_t, "%" PRIu64
, capability_set_to_string
);
1712 static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(namespace_flag
, "t", uint64_t, unsigned long, "%" PRIu64
, namespace_flags_to_string
);
1713 static BUS_DEFINE_SET_TRANSIENT_TO_STRING(mount_propagation_flag
, "t", uint64_t, unsigned long, "%" PRIu64
, mount_propagation_flag_to_string_with_check
);
1715 int bus_exec_context_set_transient_property(
1719 sd_bus_message
*message
,
1720 UnitWriteFlags flags
,
1721 sd_bus_error
*error
) {
1731 flags
|= UNIT_PRIVATE
;
1733 if (streq(name
, "User"))
1734 return bus_set_transient_user_relaxed(u
, name
, &c
->user
, message
, flags
, error
);
1736 if (streq(name
, "Group"))
1737 return bus_set_transient_user_relaxed(u
, name
, &c
->group
, message
, flags
, error
);
1739 if (streq(name
, "TTYPath"))
1740 return bus_set_transient_path(u
, name
, &c
->tty_path
, message
, flags
, error
);
1742 if (streq(name
, "RootImage"))
1743 return bus_set_transient_path(u
, name
, &c
->root_image
, message
, flags
, error
);
1745 if (streq(name
, "RootImageOptions")) {
1746 _cleanup_(mount_options_free_allp
) MountOptions
*options
= NULL
;
1747 _cleanup_free_
char *format_str
= NULL
;
1749 r
= bus_read_mount_options(message
, error
, &options
, &format_str
, " ");
1753 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1755 LIST_JOIN(mount_options
, c
->root_image_options
, options
);
1756 unit_write_settingf(
1757 u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
,
1762 c
->root_image_options
= mount_options_free_all(c
->root_image_options
);
1763 unit_write_settingf(u
, flags
, name
, "%s=", name
);
1770 if (streq(name
, "RootHash")) {
1771 const void *roothash_decoded
;
1772 size_t roothash_decoded_size
;
1774 r
= sd_bus_message_read_array(message
, 'y', &roothash_decoded
, &roothash_decoded_size
);
1778 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1779 _cleanup_free_
char *encoded
= NULL
;
1781 if (roothash_decoded_size
== 0) {
1782 c
->root_hash_path
= mfree(c
->root_hash_path
);
1783 c
->root_hash
= mfree(c
->root_hash
);
1784 c
->root_hash_size
= 0;
1786 unit_write_settingf(u
, flags
, name
, "RootHash=");
1788 _cleanup_free_
void *p
= NULL
;
1790 encoded
= hexmem(roothash_decoded
, roothash_decoded_size
);
1794 p
= memdup(roothash_decoded
, roothash_decoded_size
);
1798 free_and_replace(c
->root_hash
, p
);
1799 c
->root_hash_size
= roothash_decoded_size
;
1800 c
->root_hash_path
= mfree(c
->root_hash_path
);
1802 unit_write_settingf(u
, flags
, name
, "RootHash=%s", encoded
);
1809 if (streq(name
, "RootHashPath")) {
1810 c
->root_hash_size
= 0;
1811 c
->root_hash
= mfree(c
->root_hash
);
1813 return bus_set_transient_path(u
, "RootHash", &c
->root_hash_path
, message
, flags
, error
);
1816 if (streq(name
, "RootHashSignature")) {
1817 const void *roothash_sig_decoded
;
1818 size_t roothash_sig_decoded_size
;
1820 r
= sd_bus_message_read_array(message
, 'y', &roothash_sig_decoded
, &roothash_sig_decoded_size
);
1824 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1825 _cleanup_free_
char *encoded
= NULL
;
1827 if (roothash_sig_decoded_size
== 0) {
1828 c
->root_hash_sig_path
= mfree(c
->root_hash_sig_path
);
1829 c
->root_hash_sig
= mfree(c
->root_hash_sig
);
1830 c
->root_hash_sig_size
= 0;
1832 unit_write_settingf(u
, flags
, name
, "RootHashSignature=");
1834 _cleanup_free_
void *p
= NULL
;
1837 len
= base64mem(roothash_sig_decoded
, roothash_sig_decoded_size
, &encoded
);
1841 p
= memdup(roothash_sig_decoded
, roothash_sig_decoded_size
);
1845 free_and_replace(c
->root_hash_sig
, p
);
1846 c
->root_hash_sig_size
= roothash_sig_decoded_size
;
1847 c
->root_hash_sig_path
= mfree(c
->root_hash_sig_path
);
1849 unit_write_settingf(u
, flags
, name
, "RootHashSignature=base64:%s", encoded
);
1856 if (streq(name
, "RootHashSignaturePath")) {
1857 c
->root_hash_sig_size
= 0;
1858 c
->root_hash_sig
= mfree(c
->root_hash_sig
);
1860 return bus_set_transient_path(u
, "RootHashSignature", &c
->root_hash_sig_path
, message
, flags
, error
);
1863 if (streq(name
, "RootVerity"))
1864 return bus_set_transient_path(u
, name
, &c
->root_verity
, message
, flags
, error
);
1866 if (streq(name
, "RootDirectory"))
1867 return bus_set_transient_path(u
, name
, &c
->root_directory
, message
, flags
, error
);
1869 if (streq(name
, "RootEphemeral"))
1870 return bus_set_transient_bool(u
, name
, &c
->root_ephemeral
, message
, flags
, error
);
1872 if (streq(name
, "SyslogIdentifier"))
1873 return bus_set_transient_string(u
, name
, &c
->syslog_identifier
, message
, flags
, error
);
1875 if (streq(name
, "LogLevelMax"))
1876 return bus_set_transient_log_level(u
, name
, &c
->log_level_max
, message
, flags
, error
);
1878 if (streq(name
, "LogRateLimitIntervalUSec"))
1879 return bus_set_transient_usec(u
, name
, &c
->log_ratelimit_interval_usec
, message
, flags
, error
);
1881 if (streq(name
, "LogRateLimitBurst"))
1882 return bus_set_transient_unsigned(u
, name
, &c
->log_ratelimit_burst
, message
, flags
, error
);
1884 if (streq(name
, "LogFilterPatterns")) {
1885 /* Use _cleanup_free_, not _cleanup_strv_free_, as we don't want the content of the strv
1887 _cleanup_free_
char **allow_list
= NULL
, **deny_list
= NULL
;
1888 const char *pattern
;
1891 r
= sd_bus_message_enter_container(message
, 'a', "(bs)");
1895 while ((r
= sd_bus_message_read(message
, "(bs)", &is_allowlist
, &pattern
)) > 0) {
1896 _cleanup_(pattern_freep
) pcre2_code
*compiled_pattern
= NULL
;
1898 if (isempty(pattern
))
1901 r
= pattern_compile_and_log(pattern
, 0, &compiled_pattern
);
1905 r
= strv_push(is_allowlist
? &allow_list
: &deny_list
, (char *)pattern
);
1912 r
= sd_bus_message_exit_container(message
);
1916 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1917 if (strv_isempty(allow_list
) && strv_isempty(deny_list
)) {
1918 c
->log_filter_allowed_patterns
= set_free_free(c
->log_filter_allowed_patterns
);
1919 c
->log_filter_denied_patterns
= set_free_free(c
->log_filter_denied_patterns
);
1920 unit_write_settingf(u
, flags
, name
, "%s=", name
);
1922 r
= set_put_strdupv(&c
->log_filter_allowed_patterns
, allow_list
);
1925 r
= set_put_strdupv(&c
->log_filter_denied_patterns
, deny_list
);
1929 STRV_FOREACH(unit_pattern
, allow_list
)
1930 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, *unit_pattern
);
1931 STRV_FOREACH(unit_pattern
, deny_list
)
1932 unit_write_settingf(u
, flags
, name
, "%s=~%s", name
, *unit_pattern
);
1939 if (streq(name
, "Personality"))
1940 return bus_set_transient_personality(u
, name
, &c
->personality
, message
, flags
, error
);
1942 if (streq(name
, "StandardInput"))
1943 return bus_set_transient_std_input(u
, name
, &c
->std_input
, message
, flags
, error
);
1945 if (streq(name
, "StandardOutput"))
1946 return bus_set_transient_std_output(u
, name
, &c
->std_output
, message
, flags
, error
);
1948 if (streq(name
, "StandardError"))
1949 return bus_set_transient_std_output(u
, name
, &c
->std_error
, message
, flags
, error
);
1951 if (streq(name
, "IgnoreSIGPIPE"))
1952 return bus_set_transient_bool(u
, name
, &c
->ignore_sigpipe
, message
, flags
, error
);
1954 if (streq(name
, "TTYVHangup"))
1955 return bus_set_transient_bool(u
, name
, &c
->tty_vhangup
, message
, flags
, error
);
1957 if (streq(name
, "TTYReset"))
1958 return bus_set_transient_bool(u
, name
, &c
->tty_reset
, message
, flags
, error
);
1960 if (streq(name
, "TTYVTDisallocate"))
1961 return bus_set_transient_bool(u
, name
, &c
->tty_vt_disallocate
, message
, flags
, error
);
1963 if (streq(name
, "TTYRows"))
1964 return bus_set_transient_unsigned(u
, name
, &c
->tty_rows
, message
, flags
, error
);
1966 if (streq(name
, "TTYColumns"))
1967 return bus_set_transient_unsigned(u
, name
, &c
->tty_cols
, message
, flags
, error
);
1969 if (streq(name
, "PrivateTmp"))
1970 return bus_set_transient_bool(u
, name
, &c
->private_tmp
, message
, flags
, error
);
1972 if (streq(name
, "PrivateDevices"))
1973 return bus_set_transient_bool(u
, name
, &c
->private_devices
, message
, flags
, error
);
1975 if (streq(name
, "PrivateMounts"))
1976 return bus_set_transient_tristate(u
, name
, &c
->private_mounts
, message
, flags
, error
);
1978 if (streq(name
, "PrivateNetwork"))
1979 return bus_set_transient_bool(u
, name
, &c
->private_network
, message
, flags
, error
);
1981 if (streq(name
, "PrivateIPC"))
1982 return bus_set_transient_bool(u
, name
, &c
->private_ipc
, message
, flags
, error
);
1984 if (streq(name
, "PrivateUsers"))
1985 return bus_set_transient_bool(u
, name
, &c
->private_users
, message
, flags
, error
);
1987 if (streq(name
, "NoNewPrivileges"))
1988 return bus_set_transient_bool(u
, name
, &c
->no_new_privileges
, message
, flags
, error
);
1990 if (streq(name
, "SyslogLevelPrefix"))
1991 return bus_set_transient_bool(u
, name
, &c
->syslog_level_prefix
, message
, flags
, error
);
1993 if (streq(name
, "MemoryDenyWriteExecute"))
1994 return bus_set_transient_bool(u
, name
, &c
->memory_deny_write_execute
, message
, flags
, error
);
1996 if (streq(name
, "RestrictRealtime"))
1997 return bus_set_transient_bool(u
, name
, &c
->restrict_realtime
, message
, flags
, error
);
1999 if (streq(name
, "RestrictSUIDSGID"))
2000 return bus_set_transient_bool(u
, name
, &c
->restrict_suid_sgid
, message
, flags
, error
);
2002 if (streq(name
, "DynamicUser"))
2003 return bus_set_transient_bool(u
, name
, &c
->dynamic_user
, message
, flags
, error
);
2005 if (streq(name
, "RemoveIPC"))
2006 return bus_set_transient_bool(u
, name
, &c
->remove_ipc
, message
, flags
, error
);
2008 if (streq(name
, "ProtectKernelTunables"))
2009 return bus_set_transient_bool(u
, name
, &c
->protect_kernel_tunables
, message
, flags
, error
);
2011 if (streq(name
, "ProtectKernelModules"))
2012 return bus_set_transient_bool(u
, name
, &c
->protect_kernel_modules
, message
, flags
, error
);
2014 if (streq(name
, "ProtectKernelLogs"))
2015 return bus_set_transient_bool(u
, name
, &c
->protect_kernel_logs
, message
, flags
, error
);
2017 if (streq(name
, "ProtectClock"))
2018 return bus_set_transient_bool(u
, name
, &c
->protect_clock
, message
, flags
, error
);
2020 if (streq(name
, "ProtectControlGroups"))
2021 return bus_set_transient_bool(u
, name
, &c
->protect_control_groups
, message
, flags
, error
);
2023 if (streq(name
, "CPUSchedulingResetOnFork"))
2024 return bus_set_transient_bool(u
, name
, &c
->cpu_sched_reset_on_fork
, message
, flags
, error
);
2026 if (streq(name
, "NonBlocking"))
2027 return bus_set_transient_bool(u
, name
, &c
->non_blocking
, message
, flags
, error
);
2029 if (streq(name
, "LockPersonality"))
2030 return bus_set_transient_bool(u
, name
, &c
->lock_personality
, message
, flags
, error
);
2032 if (streq(name
, "ProtectHostname"))
2033 return bus_set_transient_bool(u
, name
, &c
->protect_hostname
, message
, flags
, error
);
2035 if (streq(name
, "MemoryKSM"))
2036 return bus_set_transient_tristate(u
, name
, &c
->memory_ksm
, message
, flags
, error
);
2038 if (streq(name
, "UtmpIdentifier"))
2039 return bus_set_transient_string(u
, name
, &c
->utmp_id
, message
, flags
, error
);
2041 if (streq(name
, "UtmpMode"))
2042 return bus_set_transient_utmp_mode(u
, name
, &c
->utmp_mode
, message
, flags
, error
);
2044 if (streq(name
, "PAMName"))
2045 return bus_set_transient_string(u
, name
, &c
->pam_name
, message
, flags
, error
);
2047 if (streq(name
, "TimerSlackNSec"))
2048 return bus_set_transient_nsec(u
, name
, &c
->timer_slack_nsec
, message
, flags
, error
);
2050 if (streq(name
, "ProtectSystem"))
2051 return bus_set_transient_protect_system(u
, name
, &c
->protect_system
, message
, flags
, error
);
2053 if (streq(name
, "ProtectHome"))
2054 return bus_set_transient_protect_home(u
, name
, &c
->protect_home
, message
, flags
, error
);
2056 if (streq(name
, "KeyringMode"))
2057 return bus_set_transient_keyring_mode(u
, name
, &c
->keyring_mode
, message
, flags
, error
);
2059 if (streq(name
, "ProtectProc"))
2060 return bus_set_transient_protect_proc(u
, name
, &c
->protect_proc
, message
, flags
, error
);
2062 if (streq(name
, "ProcSubset"))
2063 return bus_set_transient_proc_subset(u
, name
, &c
->proc_subset
, message
, flags
, error
);
2065 if (streq(name
, "RuntimeDirectoryPreserve"))
2066 return bus_set_transient_exec_preserve_mode(u
, name
, &c
->runtime_directory_preserve_mode
, message
, flags
, error
);
2068 if (streq(name
, "UMask"))
2069 return bus_set_transient_mode_t(u
, name
, &c
->umask
, message
, flags
, error
);
2071 if (streq(name
, "RuntimeDirectoryMode"))
2072 return bus_set_transient_mode_t(u
, name
, &c
->directories
[EXEC_DIRECTORY_RUNTIME
].mode
, message
, flags
, error
);
2074 if (streq(name
, "StateDirectoryMode"))
2075 return bus_set_transient_mode_t(u
, name
, &c
->directories
[EXEC_DIRECTORY_STATE
].mode
, message
, flags
, error
);
2077 if (streq(name
, "CacheDirectoryMode"))
2078 return bus_set_transient_mode_t(u
, name
, &c
->directories
[EXEC_DIRECTORY_CACHE
].mode
, message
, flags
, error
);
2080 if (streq(name
, "LogsDirectoryMode"))
2081 return bus_set_transient_mode_t(u
, name
, &c
->directories
[EXEC_DIRECTORY_LOGS
].mode
, message
, flags
, error
);
2083 if (streq(name
, "ConfigurationDirectoryMode"))
2084 return bus_set_transient_mode_t(u
, name
, &c
->directories
[EXEC_DIRECTORY_CONFIGURATION
].mode
, message
, flags
, error
);
2086 if (streq(name
, "SELinuxContext"))
2087 return bus_set_transient_string(u
, name
, &c
->selinux_context
, message
, flags
, error
);
2089 if (streq(name
, "SecureBits"))
2090 return bus_set_transient_secure_bits(u
, name
, &c
->secure_bits
, message
, flags
, error
);
2092 if (streq(name
, "CapabilityBoundingSet"))
2093 return bus_set_transient_capability(u
, name
, &c
->capability_bounding_set
, message
, flags
, error
);
2095 if (streq(name
, "AmbientCapabilities"))
2096 return bus_set_transient_capability(u
, name
, &c
->capability_ambient_set
, message
, flags
, error
);
2098 if (streq(name
, "RestrictNamespaces"))
2099 return bus_set_transient_namespace_flag(u
, name
, &c
->restrict_namespaces
, message
, flags
, error
);
2101 if (streq(name
, "RestrictFileSystems")) {
2103 _cleanup_strv_free_
char **l
= NULL
;
2105 r
= sd_bus_message_enter_container(message
, 'r', "bas");
2109 r
= sd_bus_message_read(message
, "b", &allow_list
);
2113 r
= sd_bus_message_read_strv(message
, &l
);
2117 r
= sd_bus_message_exit_container(message
);
2121 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2122 _cleanup_free_
char *joined
= NULL
;
2123 FilesystemParseFlags invert_flag
= allow_list
? 0 : FILESYSTEM_PARSE_INVERT
;
2125 if (strv_isempty(l
)) {
2126 c
->restrict_filesystems_allow_list
= false;
2127 c
->restrict_filesystems
= set_free_free(c
->restrict_filesystems
);
2129 unit_write_setting(u
, flags
, name
, "RestrictFileSystems=");
2133 if (!c
->restrict_filesystems
)
2134 c
->restrict_filesystems_allow_list
= allow_list
;
2136 STRV_FOREACH(s
, l
) {
2137 r
= lsm_bpf_parse_filesystem(
2139 &c
->restrict_filesystems
,
2140 FILESYSTEM_PARSE_LOG
|
2141 (invert_flag
? FILESYSTEM_PARSE_INVERT
: 0)|
2142 (c
->restrict_filesystems_allow_list
? FILESYSTEM_PARSE_ALLOW_LIST
: 0),
2148 joined
= strv_join(l
, " ");
2152 unit_write_settingf(u
, flags
, name
, "%s=%s%s", name
, allow_list
? "" : "~", joined
);
2158 if (streq(name
, "MountFlags"))
2159 return bus_set_transient_mount_propagation_flag(u
, name
, &c
->mount_propagation_flag
, message
, flags
, error
);
2161 if (streq(name
, "NetworkNamespacePath"))
2162 return bus_set_transient_path(u
, name
, &c
->network_namespace_path
, message
, flags
, error
);
2164 if (streq(name
, "IPCNamespacePath"))
2165 return bus_set_transient_path(u
, name
, &c
->ipc_namespace_path
, message
, flags
, error
);
2167 if (streq(name
, "SupplementaryGroups")) {
2168 _cleanup_strv_free_
char **l
= NULL
;
2170 r
= sd_bus_message_read_strv(message
, &l
);
2175 if (!isempty(*p
) && !valid_user_group_name(*p
, VALID_USER_ALLOW_NUMERIC
|VALID_USER_RELAX
|VALID_USER_WARN
))
2176 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
,
2177 "Invalid supplementary group names");
2179 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2180 if (strv_isempty(l
)) {
2181 c
->supplementary_groups
= strv_free(c
->supplementary_groups
);
2182 unit_write_settingf(u
, flags
, name
, "%s=", name
);
2184 _cleanup_free_
char *joined
= NULL
;
2186 r
= strv_extend_strv(&c
->supplementary_groups
, l
, true);
2190 joined
= strv_join(c
->supplementary_groups
, " ");
2194 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "%s=%s", name
, joined
);
2200 } else if (STR_IN_SET(name
, "SetCredential", "SetCredentialEncrypted")) {
2201 bool isempty
= true;
2203 r
= sd_bus_message_enter_container(message
, 'a', "(say)");
2212 r
= sd_bus_message_enter_container(message
, 'r', "say");
2218 r
= sd_bus_message_read(message
, "s", &id
);
2222 r
= sd_bus_message_read_array(message
, 'y', &p
, &sz
);
2226 r
= sd_bus_message_exit_container(message
);
2230 if (!credential_name_valid(id
))
2231 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Credential ID is invalid: %s", id
);
2235 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2236 _cleanup_free_
char *a
= NULL
, *b
= NULL
;
2237 _cleanup_free_
void *copy
= NULL
;
2238 ExecSetCredential
*old
;
2240 copy
= memdup(p
, sz
);
2244 old
= hashmap_get(c
->set_credentials
, id
);
2246 free_and_replace(old
->data
, copy
);
2248 old
->encrypted
= streq(name
, "SetCredentialEncrypted");
2250 _cleanup_(exec_set_credential_freep
) ExecSetCredential
*sc
= NULL
;
2252 sc
= new(ExecSetCredential
, 1);
2256 *sc
= (ExecSetCredential
) {
2258 .data
= TAKE_PTR(copy
),
2260 .encrypted
= streq(name
, "SetCredentialEncrypted"),
2266 r
= hashmap_ensure_put(&c
->set_credentials
, &exec_set_credential_hash_ops
, sc
->id
, sc
);
2273 a
= specifier_escape(id
);
2277 b
= cescape_length(p
, sz
);
2281 (void) unit_write_settingf(u
, flags
, name
, "%s=%s:%s", name
, a
, b
);
2285 r
= sd_bus_message_exit_container(message
);
2289 if (!UNIT_WRITE_FLAGS_NOOP(flags
) && isempty
) {
2290 c
->set_credentials
= hashmap_free(c
->set_credentials
);
2291 (void) unit_write_settingf(u
, flags
, name
, "%s=", name
);
2296 } else if (STR_IN_SET(name
, "LoadCredential", "LoadCredentialEncrypted")) {
2297 bool isempty
= true;
2299 r
= sd_bus_message_enter_container(message
, 'a', "(ss)");
2304 const char *id
, *source
;
2306 r
= sd_bus_message_read(message
, "(ss)", &id
, &source
);
2312 if (!credential_name_valid(id
))
2313 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Credential ID is invalid: %s", id
);
2315 if (!(path_is_absolute(source
) ? path_is_normalized(source
) : credential_name_valid(source
)))
2316 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Credential source is invalid: %s", source
);
2320 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2321 bool encrypted
= streq(name
, "LoadCredentialEncrypted");
2323 r
= hashmap_put_credential(&c
->load_credentials
, id
, source
, encrypted
);
2327 (void) unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "%s=%s:%s", name
, id
, source
);
2331 r
= sd_bus_message_exit_container(message
);
2335 if (!UNIT_WRITE_FLAGS_NOOP(flags
) && isempty
) {
2336 c
->load_credentials
= hashmap_free(c
->load_credentials
);
2337 (void) unit_write_settingf(u
, flags
, name
, "%s=", name
);
2342 } else if (streq(name
, "ImportCredential")) {
2343 bool isempty
= true;
2345 r
= sd_bus_message_enter_container(message
, 'a', "s");
2352 r
= sd_bus_message_read(message
, "s", &s
);
2358 if (!credential_glob_valid(s
))
2359 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Credential name or glob is invalid: %s", s
);
2363 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2364 r
= set_put_strdup(&c
->import_credentials
, s
);
2368 (void) unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "%s=%s", name
, s
);
2372 r
= sd_bus_message_exit_container(message
);
2376 if (!UNIT_WRITE_FLAGS_NOOP(flags
) && isempty
) {
2377 c
->import_credentials
= set_free_free(c
->import_credentials
);
2378 (void) unit_write_settingf(u
, flags
, name
, "%s=", name
);
2383 } else if (streq(name
, "SyslogLevel")) {
2386 r
= sd_bus_message_read(message
, "i", &level
);
2390 if (!log_level_is_valid(level
))
2391 return sd_bus_error_set(error
, SD_BUS_ERROR_INVALID_ARGS
, "Log level value out of range");
2393 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2394 c
->syslog_priority
= (c
->syslog_priority
& LOG_FACMASK
) | level
;
2395 unit_write_settingf(u
, flags
, name
, "SyslogLevel=%i", level
);
2400 } else if (streq(name
, "SyslogFacility")) {
2403 r
= sd_bus_message_read(message
, "i", &facility
);
2407 if (!log_facility_unshifted_is_valid(facility
))
2408 return sd_bus_error_set(error
, SD_BUS_ERROR_INVALID_ARGS
, "Log facility value out of range");
2410 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2411 c
->syslog_priority
= (facility
<< 3) | LOG_PRI(c
->syslog_priority
);
2412 unit_write_settingf(u
, flags
, name
, "SyslogFacility=%i", facility
);
2417 } else if (streq(name
, "LogNamespace")) {
2420 r
= sd_bus_message_read(message
, "s", &n
);
2424 if (!isempty(n
) && !log_namespace_name_valid(n
))
2425 return sd_bus_error_set(error
, SD_BUS_ERROR_INVALID_ARGS
, "Log namespace name not valid");
2427 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2430 c
->log_namespace
= mfree(c
->log_namespace
);
2431 unit_write_settingf(u
, flags
, name
, "%s=", name
);
2433 r
= free_and_strdup(&c
->log_namespace
, n
);
2437 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, n
);
2443 } else if (streq(name
, "LogExtraFields")) {
2446 r
= sd_bus_message_enter_container(message
, 'a', "ay");
2451 _cleanup_free_
void *copy
= NULL
;
2457 /* Note that we expect a byte array for each field, instead of a string. That's because on the
2458 * lower-level journal fields can actually contain binary data and are not restricted to text,
2459 * and we should not "lose precision" in our types on the way. That said, I am pretty sure
2460 * actually encoding binary data as unit metadata is not a good idea. Hence we actually refuse
2461 * any actual binary data, and only accept UTF-8. This allows us to eventually lift this
2462 * limitation, should a good, valid use case arise. */
2464 r
= sd_bus_message_read_array(message
, 'y', &p
, &sz
);
2470 if (memchr(p
, 0, sz
))
2471 return sd_bus_error_set(error
, SD_BUS_ERROR_INVALID_ARGS
, "Journal field contains zero byte");
2473 eq
= memchr(p
, '=', sz
);
2475 return sd_bus_error_set(error
, SD_BUS_ERROR_INVALID_ARGS
, "Journal field contains no '=' character");
2476 if (!journal_field_valid(p
, eq
- (const char*) p
, false))
2477 return sd_bus_error_set(error
, SD_BUS_ERROR_INVALID_ARGS
, "Journal field invalid");
2479 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2480 t
= reallocarray(c
->log_extra_fields
, c
->n_log_extra_fields
+1, sizeof(struct iovec
));
2483 c
->log_extra_fields
= t
;
2486 copy
= malloc(sz
+ 1);
2490 memcpy(copy
, p
, sz
);
2491 ((uint8_t*) copy
)[sz
] = 0;
2493 if (!utf8_is_valid(copy
))
2494 return sd_bus_error_set(error
, SD_BUS_ERROR_INVALID_ARGS
, "Journal field is not valid UTF-8");
2496 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2497 c
->log_extra_fields
[c
->n_log_extra_fields
++] = IOVEC_MAKE(copy
, sz
);
2498 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
|UNIT_ESCAPE_C
, name
, "LogExtraFields=%s", (char*) copy
);
2506 r
= sd_bus_message_exit_container(message
);
2510 if (!UNIT_WRITE_FLAGS_NOOP(flags
) && n
== 0) {
2511 exec_context_free_log_extra_fields(c
);
2512 unit_write_setting(u
, flags
, name
, "LogExtraFields=");
2520 if (streq(name
, "SystemCallErrorNumber"))
2521 return bus_set_transient_errno(u
, name
, &c
->syscall_errno
, message
, flags
, error
);
2523 if (streq(name
, "SystemCallFilter")) {
2525 _cleanup_strv_free_
char **l
= NULL
;
2527 r
= sd_bus_message_enter_container(message
, 'r', "bas");
2531 r
= sd_bus_message_read(message
, "b", &allow_list
);
2535 r
= sd_bus_message_read_strv(message
, &l
);
2539 r
= sd_bus_message_exit_container(message
);
2543 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2544 _cleanup_free_
char *joined
= NULL
;
2545 SeccompParseFlags invert_flag
= allow_list
? 0 : SECCOMP_PARSE_INVERT
;
2547 if (strv_isempty(l
)) {
2548 c
->syscall_allow_list
= false;
2549 c
->syscall_filter
= hashmap_free(c
->syscall_filter
);
2551 unit_write_settingf(u
, flags
, name
, "SystemCallFilter=");
2555 if (!c
->syscall_filter
) {
2556 c
->syscall_filter
= hashmap_new(NULL
);
2557 if (!c
->syscall_filter
)
2560 c
->syscall_allow_list
= allow_list
;
2562 if (c
->syscall_allow_list
) {
2563 r
= seccomp_parse_syscall_filter("@default",
2566 SECCOMP_PARSE_PERMISSIVE
|
2567 SECCOMP_PARSE_ALLOW_LIST
,
2575 STRV_FOREACH(s
, l
) {
2576 _cleanup_free_
char *n
= NULL
;
2579 r
= parse_syscall_and_errno(*s
, &n
, &e
);
2583 if (allow_list
&& e
>= 0)
2586 r
= seccomp_parse_syscall_filter(n
,
2589 SECCOMP_PARSE_LOG
| SECCOMP_PARSE_PERMISSIVE
|
2591 (c
->syscall_allow_list
? SECCOMP_PARSE_ALLOW_LIST
: 0),
2598 joined
= strv_join(l
, " ");
2602 unit_write_settingf(u
, flags
, name
, "SystemCallFilter=%s%s", allow_list
? "" : "~", joined
);
2607 } else if (streq(name
, "SystemCallLog")) {
2609 _cleanup_strv_free_
char **l
= NULL
;
2611 r
= sd_bus_message_enter_container(message
, 'r', "bas");
2615 r
= sd_bus_message_read(message
, "b", &allow_list
);
2619 r
= sd_bus_message_read_strv(message
, &l
);
2623 r
= sd_bus_message_exit_container(message
);
2627 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2628 _cleanup_free_
char *joined
= NULL
;
2629 SeccompParseFlags invert_flag
= allow_list
? 0 : SECCOMP_PARSE_INVERT
;
2631 if (strv_isempty(l
)) {
2632 c
->syscall_log_allow_list
= false;
2633 c
->syscall_log
= hashmap_free(c
->syscall_log
);
2635 unit_write_settingf(u
, flags
, name
, "SystemCallLog=");
2639 if (!c
->syscall_log
) {
2640 c
->syscall_log
= hashmap_new(NULL
);
2641 if (!c
->syscall_log
)
2644 c
->syscall_log_allow_list
= allow_list
;
2647 STRV_FOREACH(s
, l
) {
2648 r
= seccomp_parse_syscall_filter(*s
,
2649 -1, /* errno not used */
2651 SECCOMP_PARSE_LOG
| SECCOMP_PARSE_PERMISSIVE
|
2653 (c
->syscall_log_allow_list
? SECCOMP_PARSE_ALLOW_LIST
: 0),
2660 joined
= strv_join(l
, " ");
2664 unit_write_settingf(u
, flags
, name
, "SystemCallLog=%s%s", allow_list
? "" : "~", joined
);
2669 } else if (streq(name
, "SystemCallArchitectures")) {
2670 _cleanup_strv_free_
char **l
= NULL
;
2672 r
= sd_bus_message_read_strv(message
, &l
);
2676 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2677 _cleanup_free_
char *joined
= NULL
;
2679 if (strv_isempty(l
))
2680 c
->syscall_archs
= set_free(c
->syscall_archs
);
2682 STRV_FOREACH(s
, l
) {
2685 r
= seccomp_arch_from_string(*s
, &a
);
2689 r
= set_ensure_put(&c
->syscall_archs
, NULL
, UINT32_TO_PTR(a
+ 1));
2694 joined
= strv_join(l
, " ");
2698 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, joined
);
2703 } else if (streq(name
, "RestrictAddressFamilies")) {
2704 _cleanup_strv_free_
char **l
= NULL
;
2707 r
= sd_bus_message_enter_container(message
, 'r', "bas");
2711 r
= sd_bus_message_read(message
, "b", &allow_list
);
2715 r
= sd_bus_message_read_strv(message
, &l
);
2719 r
= sd_bus_message_exit_container(message
);
2723 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2724 _cleanup_free_
char *joined
= NULL
;
2726 if (strv_isempty(l
)) {
2727 c
->address_families_allow_list
= allow_list
;
2728 c
->address_families
= set_free(c
->address_families
);
2730 unit_write_settingf(u
, flags
, name
, "RestrictAddressFamilies=%s",
2731 allow_list
? "none" : "");
2735 if (!c
->address_families
) {
2736 c
->address_families
= set_new(NULL
);
2737 if (!c
->address_families
)
2740 c
->address_families_allow_list
= allow_list
;
2743 STRV_FOREACH(s
, l
) {
2746 af
= af_from_name(*s
);
2750 if (allow_list
== c
->address_families_allow_list
) {
2751 r
= set_put(c
->address_families
, INT_TO_PTR(af
));
2755 set_remove(c
->address_families
, INT_TO_PTR(af
));
2758 joined
= strv_join(l
, " ");
2762 unit_write_settingf(u
, flags
, name
, "RestrictAddressFamilies=%s%s", allow_list
? "" : "~", joined
);
2768 if (STR_IN_SET(name
, "CPUAffinity", "NUMAMask")) {
2771 bool affinity
= streq(name
, "CPUAffinity");
2772 _cleanup_(cpu_set_reset
) CPUSet set
= {};
2774 r
= sd_bus_message_read_array(message
, 'y', &a
, &n
);
2778 r
= cpu_set_from_dbus(a
, n
, &set
);
2782 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2784 cpu_set_reset(affinity
? &c
->cpu_set
: &c
->numa_policy
.nodes
);
2785 unit_write_settingf(u
, flags
, name
, "%s=", name
);
2787 _cleanup_free_
char *str
= NULL
;
2789 str
= cpu_set_to_string(&set
);
2793 /* We forego any optimizations here, and always create the structure using
2794 * cpu_set_add_all(), because we don't want to care if the existing size we
2795 * got over dbus is appropriate. */
2796 r
= cpu_set_add_all(affinity
? &c
->cpu_set
: &c
->numa_policy
.nodes
, &set
);
2800 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, str
);
2806 } else if (streq(name
, "CPUAffinityFromNUMA")) {
2809 r
= sd_bus_message_read_basic(message
, 'b', &q
);
2813 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2814 c
->cpu_affinity_from_numa
= q
;
2815 unit_write_settingf(u
, flags
, name
, "%s=%s", "CPUAffinity", "numa");
2820 } else if (streq(name
, "NUMAPolicy")) {
2823 r
= sd_bus_message_read(message
, "i", &type
);
2827 if (!mpol_is_valid(type
))
2828 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid NUMAPolicy value: %i", type
);
2830 if (!UNIT_WRITE_FLAGS_NOOP(flags
))
2831 c
->numa_policy
.type
= type
;
2835 } else if (streq(name
, "Nice")) {
2838 r
= sd_bus_message_read(message
, "i", &q
);
2842 if (!nice_is_valid(q
))
2843 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid Nice value: %i", q
);
2845 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2849 unit_write_settingf(u
, flags
, name
, "Nice=%i", q
);
2854 } else if (streq(name
, "CPUSchedulingPolicy")) {
2857 r
= sd_bus_message_read(message
, "i", &q
);
2861 if (!sched_policy_is_valid(q
))
2862 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid CPU scheduling policy: %i", q
);
2864 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2865 _cleanup_free_
char *s
= NULL
;
2867 r
= sched_policy_to_string_alloc(q
, &s
);
2871 c
->cpu_sched_policy
= q
;
2872 c
->cpu_sched_priority
= CLAMP(c
->cpu_sched_priority
, sched_get_priority_min(q
), sched_get_priority_max(q
));
2873 c
->cpu_sched_set
= true;
2875 unit_write_settingf(u
, flags
, name
, "CPUSchedulingPolicy=%s", s
);
2880 } else if (streq(name
, "CPUSchedulingPriority")) {
2883 r
= sd_bus_message_read(message
, "i", &p
);
2887 /* On Linux RR/FIFO range from 1 to 99 and OTHER/BATCH may only be 0. Policy might be set
2888 * later so we do not check the precise range, but only the generic outer bounds. */
2889 if (p
< 0 || p
> 99)
2890 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid CPU scheduling priority: %i", p
);
2892 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2893 c
->cpu_sched_priority
= p
;
2894 c
->cpu_sched_set
= true;
2896 unit_write_settingf(u
, flags
, name
, "CPUSchedulingPriority=%i", p
);
2901 } else if (streq(name
, "IOSchedulingClass")) {
2904 r
= sd_bus_message_read(message
, "i", &q
);
2908 if (!ioprio_class_is_valid(q
))
2909 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid IO scheduling class: %i", q
);
2911 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2912 _cleanup_free_
char *s
= NULL
;
2914 r
= ioprio_class_to_string_alloc(q
, &s
);
2918 c
->ioprio
= ioprio_normalize(ioprio_prio_value(q
, ioprio_prio_data(c
->ioprio
)));
2919 c
->ioprio_set
= true;
2921 unit_write_settingf(u
, flags
, name
, "IOSchedulingClass=%s", s
);
2926 } else if (streq(name
, "IOSchedulingPriority")) {
2929 r
= sd_bus_message_read(message
, "i", &p
);
2933 if (!ioprio_priority_is_valid(p
))
2934 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid IO scheduling priority: %i", p
);
2936 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2937 c
->ioprio
= ioprio_normalize(ioprio_prio_value(ioprio_prio_class(c
->ioprio
), p
));
2938 c
->ioprio_set
= true;
2940 unit_write_settingf(u
, flags
, name
, "IOSchedulingPriority=%i", p
);
2945 } else if (streq(name
, "MountAPIVFS")) {
2948 r
= bus_set_transient_bool(u
, name
, &b
, message
, flags
, error
);
2952 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2953 c
->mount_apivfs
= b
;
2954 c
->mount_apivfs_set
= true;
2959 } else if (streq(name
, "WorkingDirectory")) {
2963 r
= sd_bus_message_read(message
, "s", &s
);
2973 if (!isempty(s
) && !streq(s
, "~") && !path_is_absolute(s
))
2974 return sd_bus_error_set(error
, SD_BUS_ERROR_INVALID_ARGS
, "WorkingDirectory= expects an absolute path or '~'");
2976 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2977 if (streq(s
, "~")) {
2978 c
->working_directory
= mfree(c
->working_directory
);
2979 c
->working_directory_home
= true;
2981 r
= free_and_strdup(&c
->working_directory
, empty_to_null(s
));
2985 c
->working_directory_home
= false;
2988 c
->working_directory_missing_ok
= missing_ok
;
2989 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "WorkingDirectory=%s%s", missing_ok
? "-" : "", s
);
2994 } else if (STR_IN_SET(name
,
2995 "StandardInputFileDescriptorName", "StandardOutputFileDescriptorName", "StandardErrorFileDescriptorName")) {
2998 r
= sd_bus_message_read(message
, "s", &s
);
3002 if (!isempty(s
) && !fdname_is_valid(s
))
3003 return sd_bus_error_set(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid file descriptor name");
3005 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3007 if (streq(name
, "StandardInputFileDescriptorName")) {
3008 r
= free_and_strdup(c
->stdio_fdname
+ STDIN_FILENO
, empty_to_null(s
));
3012 c
->std_input
= EXEC_INPUT_NAMED_FD
;
3013 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardInput=fd:%s", exec_context_fdname(c
, STDIN_FILENO
));
3015 } else if (streq(name
, "StandardOutputFileDescriptorName")) {
3016 r
= free_and_strdup(c
->stdio_fdname
+ STDOUT_FILENO
, empty_to_null(s
));
3020 c
->std_output
= EXEC_OUTPUT_NAMED_FD
;
3021 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardOutput=fd:%s", exec_context_fdname(c
, STDOUT_FILENO
));
3024 assert(streq(name
, "StandardErrorFileDescriptorName"));
3026 r
= free_and_strdup(&c
->stdio_fdname
[STDERR_FILENO
], empty_to_null(s
));
3030 c
->std_error
= EXEC_OUTPUT_NAMED_FD
;
3031 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardError=fd:%s", exec_context_fdname(c
, STDERR_FILENO
));
3037 } else if (STR_IN_SET(name
,
3038 "StandardInputFile",
3039 "StandardOutputFile", "StandardOutputFileToAppend", "StandardOutputFileToTruncate",
3040 "StandardErrorFile", "StandardErrorFileToAppend", "StandardErrorFileToTruncate")) {
3043 r
= sd_bus_message_read(message
, "s", &s
);
3048 if (!path_is_absolute(s
))
3049 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Path %s is not absolute", s
);
3050 if (!path_is_normalized(s
))
3051 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Path %s is not normalized", s
);
3054 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3056 if (streq(name
, "StandardInputFile")) {
3057 r
= free_and_strdup(&c
->stdio_file
[STDIN_FILENO
], empty_to_null(s
));
3061 c
->std_input
= EXEC_INPUT_FILE
;
3062 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardInput=file:%s", s
);
3064 } else if (STR_IN_SET(name
, "StandardOutputFile", "StandardOutputFileToAppend", "StandardOutputFileToTruncate")) {
3065 r
= free_and_strdup(&c
->stdio_file
[STDOUT_FILENO
], empty_to_null(s
));
3069 if (streq(name
, "StandardOutputFile")) {
3070 c
->std_output
= EXEC_OUTPUT_FILE
;
3071 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardOutput=file:%s", s
);
3072 } else if (streq(name
, "StandardOutputFileToAppend")) {
3073 c
->std_output
= EXEC_OUTPUT_FILE_APPEND
;
3074 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardOutput=append:%s", s
);
3076 assert(streq(name
, "StandardOutputFileToTruncate"));
3077 c
->std_output
= EXEC_OUTPUT_FILE_TRUNCATE
;
3078 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardOutput=truncate:%s", s
);
3081 assert(STR_IN_SET(name
, "StandardErrorFile", "StandardErrorFileToAppend", "StandardErrorFileToTruncate"));
3083 r
= free_and_strdup(&c
->stdio_file
[STDERR_FILENO
], empty_to_null(s
));
3087 if (streq(name
, "StandardErrorFile")) {
3088 c
->std_error
= EXEC_OUTPUT_FILE
;
3089 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardError=file:%s", s
);
3090 } else if (streq(name
, "StandardErrorFileToAppend")) {
3091 c
->std_error
= EXEC_OUTPUT_FILE_APPEND
;
3092 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardError=append:%s", s
);
3094 assert(streq(name
, "StandardErrorFileToTruncate"));
3095 c
->std_error
= EXEC_OUTPUT_FILE_TRUNCATE
;
3096 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardError=truncate:%s", s
);
3103 } else if (streq(name
, "StandardInputData")) {
3107 r
= sd_bus_message_read_array(message
, 'y', &p
, &sz
);
3111 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3112 _cleanup_free_
char *encoded
= NULL
;
3115 c
->stdin_data
= mfree(c
->stdin_data
);
3116 c
->stdin_data_size
= 0;
3118 unit_write_settingf(u
, flags
, name
, "StandardInputData=");
3123 if (c
->stdin_data_size
+ sz
< c
->stdin_data_size
|| /* check for overflow */
3124 c
->stdin_data_size
+ sz
> EXEC_STDIN_DATA_MAX
)
3127 n
= base64mem(p
, sz
, &encoded
);
3131 q
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
);
3135 memcpy((uint8_t*) q
+ c
->stdin_data_size
, p
, sz
);
3138 c
->stdin_data_size
+= sz
;
3140 unit_write_settingf(u
, flags
, name
, "StandardInputData=%s", encoded
);
3146 } else if (streq(name
, "Environment")) {
3148 _cleanup_strv_free_
char **l
= NULL
;
3150 r
= sd_bus_message_read_strv(message
, &l
);
3154 if (!strv_env_is_valid(l
))
3155 return sd_bus_error_set(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid environment block.");
3157 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3158 if (strv_isempty(l
)) {
3159 c
->environment
= strv_free(c
->environment
);
3160 unit_write_setting(u
, flags
, name
, "Environment=");
3162 _cleanup_free_
char *joined
= NULL
;
3165 joined
= unit_concat_strv(l
, UNIT_ESCAPE_SPECIFIERS
|UNIT_ESCAPE_C
);
3169 e
= strv_env_merge(c
->environment
, l
);
3173 strv_free_and_replace(c
->environment
, e
);
3174 unit_write_settingf(u
, flags
, name
, "Environment=%s", joined
);
3180 } else if (streq(name
, "UnsetEnvironment")) {
3182 _cleanup_strv_free_
char **l
= NULL
;
3184 r
= sd_bus_message_read_strv(message
, &l
);
3188 if (!strv_env_name_or_assignment_is_valid(l
))
3189 return sd_bus_error_set(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid UnsetEnvironment= list.");
3191 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3192 if (strv_isempty(l
)) {
3193 c
->unset_environment
= strv_free(c
->unset_environment
);
3194 unit_write_setting(u
, flags
, name
, "UnsetEnvironment=");
3196 _cleanup_free_
char *joined
= NULL
;
3199 joined
= unit_concat_strv(l
, UNIT_ESCAPE_SPECIFIERS
|UNIT_ESCAPE_C
);
3203 e
= strv_env_merge(c
->unset_environment
, l
);
3207 strv_free_and_replace(c
->unset_environment
, e
);
3208 unit_write_settingf(u
, flags
, name
, "UnsetEnvironment=%s", joined
);
3214 } else if (streq(name
, "OOMScoreAdjust")) {
3217 r
= sd_bus_message_read(message
, "i", &oa
);
3221 if (!oom_score_adjust_is_valid(oa
))
3222 return sd_bus_error_set(error
, SD_BUS_ERROR_INVALID_ARGS
, "OOM score adjust value out of range");
3224 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3225 c
->oom_score_adjust
= oa
;
3226 c
->oom_score_adjust_set
= true;
3227 unit_write_settingf(u
, flags
, name
, "OOMScoreAdjust=%i", oa
);
3232 } else if (streq(name
, "CoredumpFilter")) {
3235 r
= sd_bus_message_read(message
, "t", &f
);
3239 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3240 c
->coredump_filter
= f
;
3241 c
->coredump_filter_set
= true;
3242 unit_write_settingf(u
, flags
, name
, "CoredumpFilter=0x%"PRIx64
, f
);
3247 } else if (streq(name
, "EnvironmentFiles")) {
3248 _cleanup_(memstream_done
) MemStream m
= {};
3249 _cleanup_free_
char *joined
= NULL
;
3250 _cleanup_strv_free_
char **l
= NULL
;
3253 r
= sd_bus_message_enter_container(message
, 'a', "(sb)");
3257 f
= memstream_init(&m
);
3261 fputs("EnvironmentFile=\n", f
);
3263 STRV_FOREACH(i
, c
->environment_files
) {
3264 _cleanup_free_
char *q
= NULL
;
3266 q
= specifier_escape(*i
);
3270 fprintf(f
, "EnvironmentFile=%s\n", q
);
3273 while ((r
= sd_bus_message_enter_container(message
, 'r', "sb")) > 0) {
3277 r
= sd_bus_message_read(message
, "sb", &path
, &b
);
3281 r
= sd_bus_message_exit_container(message
);
3285 if (!path_is_absolute(path
))
3286 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Path %s is not absolute.", path
);
3288 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3289 _cleanup_free_
char *q
= NULL
, *buf
= NULL
;
3291 buf
= strjoin(b
? "-" : "", path
);
3295 q
= specifier_escape(buf
);
3299 fprintf(f
, "EnvironmentFile=%s\n", q
);
3301 r
= strv_consume(&l
, TAKE_PTR(buf
));
3309 r
= sd_bus_message_exit_container(message
);
3313 r
= memstream_finalize(&m
, &joined
, NULL
);
3317 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3318 if (strv_isempty(l
)) {
3319 c
->environment_files
= strv_free(c
->environment_files
);
3320 unit_write_setting(u
, flags
, name
, "EnvironmentFile=");
3322 r
= strv_extend_strv(&c
->environment_files
, l
, true);
3326 unit_write_setting(u
, flags
, name
, joined
);
3332 } else if (streq(name
, "PassEnvironment")) {
3334 _cleanup_strv_free_
char **l
= NULL
;
3336 r
= sd_bus_message_read_strv(message
, &l
);
3340 if (!strv_env_name_is_valid(l
))
3341 return sd_bus_error_set(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid PassEnvironment= block.");
3343 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3344 if (strv_isempty(l
)) {
3345 c
->pass_environment
= strv_free(c
->pass_environment
);
3346 unit_write_setting(u
, flags
, name
, "PassEnvironment=");
3348 _cleanup_free_
char *joined
= NULL
;
3350 r
= strv_extend_strv(&c
->pass_environment
, l
, true);
3354 /* We write just the new settings out to file, with unresolved specifiers. */
3355 joined
= unit_concat_strv(l
, UNIT_ESCAPE_SPECIFIERS
);
3359 unit_write_settingf(u
, flags
, name
, "PassEnvironment=%s", joined
);
3365 } else if (STR_IN_SET(name
, "ReadWriteDirectories", "ReadOnlyDirectories", "InaccessibleDirectories",
3366 "ReadWritePaths", "ReadOnlyPaths", "InaccessiblePaths", "ExecPaths", "NoExecPaths",
3367 "ExtensionDirectories")) {
3368 _cleanup_strv_free_
char **l
= NULL
;
3371 r
= sd_bus_message_read_strv(message
, &l
);
3375 STRV_FOREACH(p
, l
) {
3379 offset
= i
[0] == '-';
3380 offset
+= i
[offset
] == '+';
3381 if (!path_is_absolute(i
+ offset
))
3382 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid %s", name
);
3384 path_simplify(i
+ offset
);
3387 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3388 if (STR_IN_SET(name
, "ReadWriteDirectories", "ReadWritePaths"))
3389 dirs
= &c
->read_write_paths
;
3390 else if (STR_IN_SET(name
, "ReadOnlyDirectories", "ReadOnlyPaths"))
3391 dirs
= &c
->read_only_paths
;
3392 else if (streq(name
, "ExecPaths"))
3393 dirs
= &c
->exec_paths
;
3394 else if (streq(name
, "NoExecPaths"))
3395 dirs
= &c
->no_exec_paths
;
3396 else if (streq(name
, "ExtensionDirectories"))
3397 dirs
= &c
->extension_directories
;
3398 else /* "InaccessiblePaths" */
3399 dirs
= &c
->inaccessible_paths
;
3401 if (strv_isempty(l
)) {
3402 *dirs
= strv_free(*dirs
);
3403 unit_write_settingf(u
, flags
, name
, "%s=", name
);
3405 _cleanup_free_
char *joined
= NULL
;
3407 joined
= unit_concat_strv(l
, UNIT_ESCAPE_SPECIFIERS
);
3411 r
= strv_extend_strv(dirs
, l
, true);
3415 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, joined
);
3421 } else if (streq(name
, "ExecSearchPath")) {
3422 _cleanup_strv_free_
char **l
= NULL
;
3424 r
= sd_bus_message_read_strv(message
, &l
);
3429 if (!path_is_absolute(*p
) || !path_is_normalized(*p
) || strchr(*p
, ':'))
3430 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid %s", name
);
3432 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3433 if (strv_isempty(l
)) {
3434 c
->exec_search_path
= strv_free(c
->exec_search_path
);
3435 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "ExecSearchPath=");
3437 _cleanup_free_
char *joined
= NULL
;
3438 r
= strv_extend_strv(&c
->exec_search_path
, l
, true);
3441 joined
= strv_join(c
->exec_search_path
, ":");
3444 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "ExecSearchPath=%s", joined
);
3450 } else if (STR_IN_SET(name
, "RuntimeDirectory", "StateDirectory", "CacheDirectory", "LogsDirectory", "ConfigurationDirectory")) {
3451 _cleanup_strv_free_
char **l
= NULL
;
3453 r
= sd_bus_message_read_strv(message
, &l
);
3457 STRV_FOREACH(p
, l
) {
3458 if (!path_is_normalized(*p
))
3459 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "%s= path is not normalized: %s", name
, *p
);
3461 if (path_is_absolute(*p
))
3462 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "%s= path is absolute: %s", name
, *p
);
3464 if (path_startswith(*p
, "private"))
3465 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "%s= path can't be 'private': %s", name
, *p
);
3468 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3469 ExecDirectoryType i
;
3472 assert_se((i
= exec_directory_type_from_string(name
)) >= 0);
3473 d
= c
->directories
+ i
;
3475 if (strv_isempty(l
)) {
3476 exec_directory_done(d
);
3477 unit_write_settingf(u
, flags
, name
, "%s=", name
);
3479 _cleanup_free_
char *joined
= NULL
;
3481 STRV_FOREACH(source
, l
) {
3482 r
= exec_directory_add(d
, *source
, NULL
);
3486 exec_directory_sort(d
);
3488 joined
= unit_concat_strv(l
, UNIT_ESCAPE_SPECIFIERS
);
3492 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, joined
);
3498 } else if (STR_IN_SET(name
, "AppArmorProfile", "SmackProcessLabel")) {
3502 r
= sd_bus_message_read(message
, "(bs)", &ignore
, &s
);
3506 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3510 if (streq(name
, "AppArmorProfile")) {
3511 p
= &c
->apparmor_profile
;
3512 b
= &c
->apparmor_profile_ignore
;
3513 } else { /* "SmackProcessLabel" */
3514 p
= &c
->smack_process_label
;
3515 b
= &c
->smack_process_label_ignore
;
3522 if (free_and_strdup(p
, s
) < 0)
3527 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "%s=%s%s", name
, ignore
? "-" : "", strempty(s
));
3532 } else if (STR_IN_SET(name
, "BindPaths", "BindReadOnlyPaths")) {
3533 char *source
, *destination
;
3535 uint64_t mount_flags
;
3538 r
= sd_bus_message_enter_container(message
, 'a', "(ssbt)");
3542 while ((r
= sd_bus_message_read(message
, "(ssbt)", &source
, &destination
, &ignore_enoent
, &mount_flags
)) > 0) {
3544 if (!path_is_absolute(source
))
3545 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Source path %s is not absolute.", source
);
3546 if (!path_is_absolute(destination
))
3547 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Destination path %s is not absolute.", destination
);
3548 if (!IN_SET(mount_flags
, 0, MS_REC
))
3549 return sd_bus_error_set(error
, SD_BUS_ERROR_INVALID_ARGS
, "Unknown mount flags.");
3551 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3552 r
= bind_mount_add(&c
->bind_mounts
, &c
->n_bind_mounts
,
3555 .destination
= destination
,
3556 .read_only
= !!strstr(name
, "ReadOnly"),
3557 .recursive
= !!(mount_flags
& MS_REC
),
3558 .ignore_enoent
= ignore_enoent
,
3563 unit_write_settingf(
3564 u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
,
3567 ignore_enoent
? "-" : "",
3570 (mount_flags
& MS_REC
) ? "rbind" : "norbind");
3578 r
= sd_bus_message_exit_container(message
);
3583 bind_mount_free_many(c
->bind_mounts
, c
->n_bind_mounts
);
3584 c
->bind_mounts
= NULL
;
3585 c
->n_bind_mounts
= 0;
3587 unit_write_settingf(u
, flags
, name
, "%s=", name
);
3592 } else if (streq(name
, "TemporaryFileSystem")) {
3593 const char *path
, *options
;
3596 r
= sd_bus_message_enter_container(message
, 'a', "(ss)");
3600 while ((r
= sd_bus_message_read(message
, "(ss)", &path
, &options
)) > 0) {
3602 if (!path_is_absolute(path
))
3603 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Mount point %s is not absolute.", path
);
3605 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3606 r
= temporary_filesystem_add(&c
->temporary_filesystems
, &c
->n_temporary_filesystems
, path
, options
);
3610 unit_write_settingf(
3611 u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
,
3623 r
= sd_bus_message_exit_container(message
);
3628 temporary_filesystem_free_many(c
->temporary_filesystems
, c
->n_temporary_filesystems
);
3629 c
->temporary_filesystems
= NULL
;
3630 c
->n_temporary_filesystems
= 0;
3632 unit_write_settingf(u
, flags
, name
, "%s=", name
);
3637 } else if ((suffix
= startswith(name
, "Limit"))) {
3638 const char *soft
= NULL
;
3641 ri
= rlimit_from_string(suffix
);
3643 soft
= endswith(suffix
, "Soft");
3647 n
= strndupa_safe(suffix
, soft
- suffix
);
3648 ri
= rlimit_from_string(n
);
3650 name
= strjoina("Limit", n
);
3658 r
= sd_bus_message_read(message
, "t", &rl
);
3662 if (rl
== UINT64_MAX
)
3667 if ((uint64_t) x
!= rl
)
3671 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3672 _cleanup_free_
char *f
= NULL
;
3675 if (c
->rlimit
[ri
]) {
3676 nl
= *c
->rlimit
[ri
];
3683 /* When the resource limit is not initialized yet, then assign the value to both fields */
3684 nl
= (struct rlimit
) {
3689 r
= rlimit_format(&nl
, &f
);
3694 *c
->rlimit
[ri
] = nl
;
3696 c
->rlimit
[ri
] = newdup(struct rlimit
, &nl
, 1);
3701 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, f
);
3707 } else if (streq(name
, "MountImages")) {
3708 _cleanup_free_
char *format_str
= NULL
;
3709 MountImage
*mount_images
= NULL
;
3710 size_t n_mount_images
= 0;
3711 char *source
, *destination
;
3714 r
= sd_bus_message_enter_container(message
, 'a', "(ssba(ss))");
3719 _cleanup_(mount_options_free_allp
) MountOptions
*options
= NULL
;
3720 _cleanup_free_
char *source_escaped
= NULL
, *destination_escaped
= NULL
;
3723 r
= sd_bus_message_enter_container(message
, 'r', "ssba(ss)");
3727 r
= sd_bus_message_read(message
, "ssb", &source
, &destination
, &permissive
);
3731 if (!path_is_absolute(source
))
3732 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Source path %s is not absolute.", source
);
3733 if (!path_is_normalized(source
))
3734 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Source path %s is not normalized.", source
);
3735 if (!path_is_absolute(destination
))
3736 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Destination path %s is not absolute.", destination
);
3737 if (!path_is_normalized(destination
))
3738 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Destination path %s is not normalized.", destination
);
3740 /* Need to store them in the unit with the escapes, so that they can be parsed again */
3741 source_escaped
= shell_escape(source
, ":");
3742 if (!source_escaped
)
3744 destination_escaped
= shell_escape(destination
, ":");
3745 if (!destination_escaped
)
3748 tuple
= strjoin(format_str
,
3749 format_str
? " " : "",
3750 permissive
? "-" : "",
3753 destination_escaped
);
3756 free_and_replace(format_str
, tuple
);
3758 r
= bus_read_mount_options(message
, error
, &options
, &format_str
, ":");
3762 r
= sd_bus_message_exit_container(message
);
3766 r
= mount_image_add(&mount_images
, &n_mount_images
,
3769 .destination
= destination
,
3770 .mount_options
= options
,
3771 .ignore_enoent
= permissive
,
3772 .type
= MOUNT_IMAGE_DISCRETE
,
3780 r
= sd_bus_message_exit_container(message
);
3784 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3785 if (n_mount_images
== 0) {
3786 c
->mount_images
= mount_image_free_many(c
->mount_images
, &c
->n_mount_images
);
3788 unit_write_settingf(u
, flags
, name
, "%s=", name
);
3790 for (size_t i
= 0; i
< n_mount_images
; ++i
) {
3791 r
= mount_image_add(&c
->mount_images
, &c
->n_mount_images
, &mount_images
[i
]);
3796 unit_write_settingf(u
, flags
|UNIT_ESCAPE_C
|UNIT_ESCAPE_SPECIFIERS
,
3804 mount_images
= mount_image_free_many(mount_images
, &n_mount_images
);
3807 } else if (streq(name
, "ExtensionImages")) {
3808 _cleanup_free_
char *format_str
= NULL
;
3809 MountImage
*extension_images
= NULL
;
3810 size_t n_extension_images
= 0;
3812 r
= sd_bus_message_enter_container(message
, 'a', "(sba(ss))");
3817 _cleanup_(mount_options_free_allp
) MountOptions
*options
= NULL
;
3818 _cleanup_free_
char *source_escaped
= NULL
;
3819 char *source
, *tuple
;
3822 r
= sd_bus_message_enter_container(message
, 'r', "sba(ss)");
3826 r
= sd_bus_message_read(message
, "sb", &source
, &permissive
);
3830 if (!path_is_absolute(source
))
3831 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Source path %s is not absolute.", source
);
3832 if (!path_is_normalized(source
))
3833 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Source path %s is not normalized.", source
);
3835 /* Need to store them in the unit with the escapes, so that they can be parsed again */
3836 source_escaped
= shell_escape(source
, ":");
3837 if (!source_escaped
)
3840 tuple
= strjoin(format_str
,
3841 format_str
? " " : "",
3842 permissive
? "-" : "",
3846 free_and_replace(format_str
, tuple
);
3848 r
= bus_read_mount_options(message
, error
, &options
, &format_str
, ":");
3852 r
= sd_bus_message_exit_container(message
);
3856 r
= mount_image_add(&extension_images
, &n_extension_images
,
3859 .mount_options
= options
,
3860 .ignore_enoent
= permissive
,
3861 .type
= MOUNT_IMAGE_EXTENSION
,
3869 r
= sd_bus_message_exit_container(message
);
3873 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3874 if (n_extension_images
== 0) {
3875 c
->extension_images
= mount_image_free_many(c
->extension_images
, &c
->n_extension_images
);
3877 unit_write_settingf(u
, flags
, name
, "%s=", name
);
3879 for (size_t i
= 0; i
< n_extension_images
; ++i
) {
3880 r
= mount_image_add(&c
->extension_images
, &c
->n_extension_images
, &extension_images
[i
]);
3885 unit_write_settingf(u
, flags
|UNIT_ESCAPE_C
|UNIT_ESCAPE_SPECIFIERS
,
3893 extension_images
= mount_image_free_many(extension_images
, &n_extension_images
);
3897 } else if (STR_IN_SET(name
, "StateDirectorySymlink", "RuntimeDirectorySymlink", "CacheDirectorySymlink", "LogsDirectorySymlink")) {
3898 char *source
, *destination
;
3899 ExecDirectory
*directory
;
3900 uint64_t symlink_flags
; /* No flags for now, reserved for future uses. */
3901 ExecDirectoryType i
;
3903 assert_se((i
= exec_directory_type_symlink_from_string(name
)) >= 0);
3904 directory
= c
->directories
+ i
;
3906 r
= sd_bus_message_enter_container(message
, 'a', "(sst)");
3910 while ((r
= sd_bus_message_read(message
, "(sst)", &source
, &destination
, &symlink_flags
)) > 0) {
3911 if (!path_is_valid(source
))
3912 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Source path %s is not valid.", source
);
3913 if (path_is_absolute(source
))
3914 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Source path %s is absolute.", source
);
3915 if (!path_is_normalized(source
))
3916 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Source path %s is not normalized.", source
);
3917 if (!path_is_valid(destination
))
3918 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Destination path %s is not valid.", destination
);
3919 if (path_is_absolute(destination
))
3920 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Destination path %s is absolute.", destination
);
3921 if (!path_is_normalized(destination
))
3922 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Destination path %s is not normalized.", destination
);
3923 if (symlink_flags
!= 0)
3924 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Flags must be zero.");
3926 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3927 _cleanup_free_
char *destination_escaped
= NULL
, *source_escaped
= NULL
;
3929 r
= exec_directory_add(directory
, source
, destination
);
3933 /* Need to store them in the unit with the escapes, so that they can be parsed again */
3934 source_escaped
= xescape(source
, ":");
3935 destination_escaped
= xescape(destination
, ":");
3936 if (!source_escaped
|| !destination_escaped
)
3939 unit_write_settingf(
3940 u
, flags
|UNIT_ESCAPE_SPECIFIERS
, exec_directory_type_to_string(i
),
3942 exec_directory_type_to_string(i
),
3944 destination_escaped
);
3950 exec_directory_sort(directory
);
3952 r
= sd_bus_message_exit_container(message
);
3958 } else if (STR_IN_SET(name
, "RootImagePolicy", "MountImagePolicy", "ExtensionImagePolicy")) {
3959 _cleanup_(image_policy_freep
) ImagePolicy
*p
= NULL
;
3962 r
= sd_bus_message_read(message
, "s", &s
);
3966 r
= image_policy_from_string(s
, &p
);
3968 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Failed to parse image policy string: %s", s
);
3970 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3971 _cleanup_free_
char *t
= NULL
;
3973 streq(name
, "RootImagePolicy") ? &c
->root_image_policy
:
3974 streq(name
, "MountImagePolicy") ? &c
->mount_image_policy
:
3975 &c
->extension_image_policy
;
3977 r
= image_policy_to_string(p
, /* simplify= */ true, &t
);
3981 image_policy_free(*pp
);
3984 unit_write_settingf(
3988 t
); /* no escaping necessary */