1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
8 #include "alloc-util.h"
9 #include "bpf-restrict-fs.h"
10 #include "bus-get-properties.h"
11 #include "bus-unit-util.h"
13 #include "cpu-set-util.h"
14 #include "creds-util.h"
15 #include "dbus-execute.h"
16 #include "dbus-util.h"
17 #include "dissect-image.h"
20 #include "exec-credential.h"
23 #include "hexdecoct.h"
24 #include "hostname-util.h"
25 #include "image-policy.h"
26 #include "ioprio-util.h"
27 #include "iovec-util.h"
28 #include "journal-file.h"
29 #include "memstream-util.h"
30 #include "mountpoint-util.h"
31 #include "namespace.h"
33 #include "ordered-set.h"
34 #include "path-util.h"
35 #include "pcre2-util.h"
36 #include "process-util.h"
37 #include "rlimit-util.h"
38 #include "seccomp-util.h"
39 #include "securebits-util.h"
41 #include "specifier.h"
43 #include "syslog-util.h"
45 #include "user-util.h"
48 BUS_DEFINE_PROPERTY_GET_ENUM(bus_property_get_exec_output
, exec_output
, ExecOutput
);
49 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_input
, exec_input
, ExecInput
);
50 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_utmp_mode
, exec_utmp_mode
, ExecUtmpMode
);
51 BUS_DEFINE_PROPERTY_GET_ENUM(bus_property_get_exec_preserve_mode
, exec_preserve_mode
, ExecPreserveMode
);
52 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_keyring_mode
, exec_keyring_mode
, ExecKeyringMode
);
53 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_protect_proc
, protect_proc
, ProtectProc
);
54 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_proc_subset
, proc_subset
, ProcSubset
);
55 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_protect_home
, protect_home
, ProtectHome
);
56 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_protect_system
, protect_system
, ProtectSystem
);
57 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_personality
, personality
, unsigned long);
58 static BUS_DEFINE_PROPERTY_GET(property_get_ioprio
, "i", ExecContext
, exec_context_get_effective_ioprio
);
59 static BUS_DEFINE_PROPERTY_GET(property_get_mount_apivfs
, "b", ExecContext
, exec_context_get_effective_mount_apivfs
);
60 static BUS_DEFINE_PROPERTY_GET(property_get_bind_log_sockets
, "b", ExecContext
, exec_context_get_effective_bind_log_sockets
);
61 static BUS_DEFINE_PROPERTY_GET2(property_get_ioprio_class
, "i", ExecContext
, exec_context_get_effective_ioprio
, ioprio_prio_class
);
62 static BUS_DEFINE_PROPERTY_GET2(property_get_ioprio_priority
, "i", ExecContext
, exec_context_get_effective_ioprio
, ioprio_prio_data
);
63 static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_empty_string
, "s", NULL
);
64 static BUS_DEFINE_PROPERTY_GET_REF(property_get_private_tmp_ex
, "s", PrivateTmp
, private_tmp_to_string
);
65 static BUS_DEFINE_PROPERTY_GET_REF(property_get_private_users_ex
, "s", PrivateUsers
, private_users_to_string
);
66 static BUS_DEFINE_PROPERTY_GET_REF(property_get_protect_control_groups_ex
, "s", ProtectControlGroups
, protect_control_groups_to_string
);
67 static BUS_DEFINE_PROPERTY_GET_REF(property_get_private_pids
, "s", PrivatePIDs
, private_pids_to_string
);
68 static BUS_DEFINE_PROPERTY_GET_REF(property_get_syslog_level
, "i", int, LOG_PRI
);
69 static BUS_DEFINE_PROPERTY_GET_REF(property_get_syslog_facility
, "i", int, LOG_FAC
);
70 static BUS_DEFINE_PROPERTY_GET(property_get_cpu_affinity_from_numa
, "b", ExecContext
, exec_context_get_cpu_affinity_from_numa
);
71 static BUS_DEFINE_PROPERTY_GET(property_get_oom_score_adjust
, "i", ExecContext
, exec_context_get_oom_score_adjust
);
72 static BUS_DEFINE_PROPERTY_GET(property_get_nice
, "i", ExecContext
, exec_context_get_nice
);
73 static BUS_DEFINE_PROPERTY_GET(property_get_cpu_sched_policy
, "i", ExecContext
, exec_context_get_cpu_sched_policy
);
74 static BUS_DEFINE_PROPERTY_GET(property_get_cpu_sched_priority
, "i", ExecContext
, exec_context_get_cpu_sched_priority
);
75 static BUS_DEFINE_PROPERTY_GET(property_get_coredump_filter
, "t", ExecContext
, exec_context_get_coredump_filter
);
76 static BUS_DEFINE_PROPERTY_GET(property_get_timer_slack_nsec
, "t", ExecContext
, exec_context_get_timer_slack_nsec
);
77 static BUS_DEFINE_PROPERTY_GET(property_get_set_login_environment
, "b", ExecContext
, exec_context_get_set_login_environment
);
79 static int property_get_environment_files(
82 const char *interface
,
84 sd_bus_message
*reply
,
86 sd_bus_error
*error
) {
88 ExecContext
*c
= ASSERT_PTR(userdata
);
94 r
= sd_bus_message_open_container(reply
, 'a', "(sb)");
98 STRV_FOREACH(j
, c
->environment_files
) {
101 r
= sd_bus_message_append(reply
, "(sb)", fn
[0] == '-' ? fn
+ 1 : fn
, fn
[0] == '-');
106 return sd_bus_message_close_container(reply
);
109 static int property_get_cpu_affinity(
112 const char *interface
,
113 const char *property
,
114 sd_bus_message
*reply
,
116 sd_bus_error
*error
) {
118 ExecContext
*c
= ASSERT_PTR(userdata
);
119 _cleanup_(cpu_set_done
) CPUSet s
= {};
120 _cleanup_free_
uint8_t *array
= NULL
;
126 if (c
->cpu_affinity_from_numa
) {
129 r
= numa_to_cpu_set(&c
->numa_policy
, &s
);
134 (void) cpu_set_to_dbus(c
->cpu_affinity_from_numa
? &s
: &c
->cpu_set
, &array
, &allocated
);
136 return sd_bus_message_append_array(reply
, 'y', array
, allocated
);
139 static int property_get_numa_mask(
142 const char *interface
,
143 const char *property
,
144 sd_bus_message
*reply
,
146 sd_bus_error
*error
) {
148 ExecContext
*c
= ASSERT_PTR(userdata
);
149 _cleanup_free_
uint8_t *array
= NULL
;
155 (void) cpu_set_to_dbus(&c
->numa_policy
.nodes
, &array
, &allocated
);
157 return sd_bus_message_append_array(reply
, 'y', array
, allocated
);
160 static int property_get_numa_policy(
163 const char *interface
,
164 const char *property
,
165 sd_bus_message
*reply
,
167 sd_bus_error
*error
) {
168 ExecContext
*c
= ASSERT_PTR(userdata
);
174 policy
= numa_policy_get_type(&c
->numa_policy
);
176 return sd_bus_message_append_basic(reply
, 'i', &policy
);
179 static int property_get_syscall_filter(
182 const char *interface
,
183 const char *property
,
184 sd_bus_message
*reply
,
186 sd_bus_error
*error
) {
188 ExecContext
*c
= ASSERT_PTR(userdata
);
189 _cleanup_strv_free_
char **l
= NULL
;
195 r
= sd_bus_message_open_container(reply
, 'r', "bas");
199 r
= sd_bus_message_append(reply
, "b", c
->syscall_allow_list
);
203 l
= exec_context_get_syscall_filter(c
);
207 r
= sd_bus_message_append_strv(reply
, l
);
211 return sd_bus_message_close_container(reply
);
214 static int property_get_syscall_log(
217 const char *interface
,
218 const char *property
,
219 sd_bus_message
*reply
,
221 sd_bus_error
*error
) {
223 ExecContext
*c
= ASSERT_PTR(userdata
);
224 _cleanup_strv_free_
char **l
= NULL
;
230 r
= sd_bus_message_open_container(reply
, 'r', "bas");
234 r
= sd_bus_message_append(reply
, "b", c
->syscall_log_allow_list
);
238 l
= exec_context_get_syscall_log(c
);
242 r
= sd_bus_message_append_strv(reply
, l
);
246 return sd_bus_message_close_container(reply
);
249 static int property_get_syscall_archs(
252 const char *interface
,
253 const char *property
,
254 sd_bus_message
*reply
,
256 sd_bus_error
*error
) {
258 ExecContext
*c
= ASSERT_PTR(userdata
);
259 _cleanup_strv_free_
char **l
= NULL
;
265 l
= exec_context_get_syscall_archs(c
);
269 r
= sd_bus_message_append_strv(reply
, l
);
276 static int property_get_selinux_context(
279 const char *interface
,
280 const char *property
,
281 sd_bus_message
*reply
,
283 sd_bus_error
*error
) {
285 ExecContext
*c
= ASSERT_PTR(userdata
);
290 return sd_bus_message_append(reply
, "(bs)", c
->selinux_context_ignore
, c
->selinux_context
);
293 static int property_get_apparmor_profile(
296 const char *interface
,
297 const char *property
,
298 sd_bus_message
*reply
,
300 sd_bus_error
*error
) {
302 ExecContext
*c
= ASSERT_PTR(userdata
);
307 return sd_bus_message_append(reply
, "(bs)", c
->apparmor_profile_ignore
, c
->apparmor_profile
);
310 static int property_get_smack_process_label(
313 const char *interface
,
314 const char *property
,
315 sd_bus_message
*reply
,
317 sd_bus_error
*error
) {
319 ExecContext
*c
= ASSERT_PTR(userdata
);
324 return sd_bus_message_append(reply
, "(bs)", c
->smack_process_label_ignore
, c
->smack_process_label
);
327 static int property_get_address_families(
330 const char *interface
,
331 const char *property
,
332 sd_bus_message
*reply
,
334 sd_bus_error
*error
) {
336 ExecContext
*c
= ASSERT_PTR(userdata
);
337 _cleanup_strv_free_
char **l
= NULL
;
343 r
= sd_bus_message_open_container(reply
, 'r', "bas");
347 r
= sd_bus_message_append(reply
, "b", c
->address_families_allow_list
);
351 l
= exec_context_get_address_families(c
);
355 r
= sd_bus_message_append_strv(reply
, l
);
359 return sd_bus_message_close_container(reply
);
362 static int property_get_working_directory(
365 const char *interface
,
366 const char *property
,
367 sd_bus_message
*reply
,
369 sd_bus_error
*error
) {
371 ExecContext
*c
= ASSERT_PTR(userdata
);
377 if (c
->working_directory_home
)
380 wd
= c
->working_directory
;
382 if (c
->working_directory_missing_ok
)
383 wd
= strjoina("!", wd
);
385 return sd_bus_message_append(reply
, "s", wd
);
388 static int property_get_stdio_fdname(
391 const char *interface
,
392 const char *property
,
393 sd_bus_message
*reply
,
395 sd_bus_error
*error
) {
397 ExecContext
*c
= ASSERT_PTR(userdata
);
404 if (streq(property
, "StandardInputFileDescriptorName"))
405 fileno
= STDIN_FILENO
;
406 else if (streq(property
, "StandardOutputFileDescriptorName"))
407 fileno
= STDOUT_FILENO
;
409 assert(streq(property
, "StandardErrorFileDescriptorName"));
410 fileno
= STDERR_FILENO
;
413 return sd_bus_message_append(reply
, "s", exec_context_fdname(c
, fileno
));
416 static int property_get_input_data(
419 const char *interface
,
420 const char *property
,
421 sd_bus_message
*reply
,
423 sd_bus_error
*error
) {
425 ExecContext
*c
= ASSERT_PTR(userdata
);
431 return sd_bus_message_append_array(reply
, 'y', c
->stdin_data
, c
->stdin_data_size
);
434 static int property_get_restrict_filesystems(
437 const char *interface
,
438 const char *property
,
439 sd_bus_message
*reply
,
441 sd_bus_error
*error
) {
443 ExecContext
*c
= ASSERT_PTR(userdata
);
444 _cleanup_free_
char **l
= NULL
; /* Strings are owned by 'c->restrict_filesystems'! */
450 r
= sd_bus_message_open_container(reply
, 'r', "bas");
454 r
= sd_bus_message_append(reply
, "b", c
->restrict_filesystems_allow_list
);
458 l
= exec_context_get_restrict_filesystems(c
);
462 r
= sd_bus_message_append_strv(reply
, l
);
466 return sd_bus_message_close_container(reply
);
469 static int property_get_bind_paths(
472 const char *interface
,
473 const char *property
,
474 sd_bus_message
*reply
,
476 sd_bus_error
*error
) {
478 ExecContext
*c
= ASSERT_PTR(userdata
);
486 ro
= strstr(property
, "ReadOnly");
488 r
= sd_bus_message_open_container(reply
, 'a', "(ssbt)");
492 FOREACH_ARRAY(i
, c
->bind_mounts
, c
->n_bind_mounts
) {
493 if (ro
!= i
->read_only
)
496 r
= sd_bus_message_append(
501 i
->recursive
? (uint64_t) MS_REC
: UINT64_C(0));
506 return sd_bus_message_close_container(reply
);
509 static int property_get_temporary_filesystems(
512 const char *interface
,
513 const char *property
,
514 sd_bus_message
*reply
,
516 sd_bus_error
*error
) {
518 ExecContext
*c
= ASSERT_PTR(userdata
);
525 r
= sd_bus_message_open_container(reply
, 'a', "(ss)");
529 FOREACH_ARRAY(t
, c
->temporary_filesystems
, c
->n_temporary_filesystems
) {
530 r
= sd_bus_message_append(
538 return sd_bus_message_close_container(reply
);
541 static int property_get_log_extra_fields(
544 const char *interface
,
545 const char *property
,
546 sd_bus_message
*reply
,
548 sd_bus_error
*error
) {
550 ExecContext
*c
= ASSERT_PTR(userdata
);
557 r
= sd_bus_message_open_container(reply
, 'a', "ay");
561 FOREACH_ARRAY(i
, c
->log_extra_fields
, c
->n_log_extra_fields
) {
562 r
= sd_bus_message_append_array(reply
, 'y', i
->iov_base
, i
->iov_len
);
567 return sd_bus_message_close_container(reply
);
570 static int sd_bus_message_append_log_filter_patterns(sd_bus_message
*reply
, Set
*patterns
, bool is_allowlist
) {
576 SET_FOREACH(pattern
, patterns
) {
577 r
= sd_bus_message_append(reply
, "(bs)", is_allowlist
, pattern
);
585 static int property_get_log_filter_patterns(
588 const char *interface
,
589 const char *property
,
590 sd_bus_message
*reply
,
592 sd_bus_error
*error
) {
594 ExecContext
*c
= userdata
;
600 r
= sd_bus_message_open_container(reply
, 'a', "(bs)");
604 r
= sd_bus_message_append_log_filter_patterns(reply
, c
->log_filter_allowed_patterns
,
605 /* is_allowlist = */ true);
609 r
= sd_bus_message_append_log_filter_patterns(reply
, c
->log_filter_denied_patterns
,
610 /* is_allowlist = */ false);
614 return sd_bus_message_close_container(reply
);
617 static int property_get_set_credential(
620 const char *interface
,
621 const char *property
,
622 sd_bus_message
*reply
,
624 sd_bus_error
*error
) {
626 ExecContext
*c
= ASSERT_PTR(userdata
);
627 ExecSetCredential
*sc
;
634 r
= sd_bus_message_open_container(reply
, 'a', "(say)");
638 HASHMAP_FOREACH(sc
, c
->set_credentials
) {
640 if (sc
->encrypted
!= streq(property
, "SetCredentialEncrypted"))
643 r
= sd_bus_message_open_container(reply
, 'r', "say");
647 r
= sd_bus_message_append(reply
, "s", sc
->id
);
651 r
= sd_bus_message_append_array(reply
, 'y', sc
->data
, sc
->size
);
655 r
= sd_bus_message_close_container(reply
);
660 return sd_bus_message_close_container(reply
);
663 static int property_get_load_credential(
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 ExecLoadCredential
*lc
;
680 r
= sd_bus_message_open_container(reply
, 'a', "(ss)");
684 HASHMAP_FOREACH(lc
, c
->load_credentials
) {
686 if (lc
->encrypted
!= streq(property
, "LoadCredentialEncrypted"))
689 r
= sd_bus_message_append(reply
, "(ss)", lc
->id
, lc
->path
);
694 return sd_bus_message_close_container(reply
);
697 static int property_get_import_credential(
700 const char *interface
,
701 const char *property
,
702 sd_bus_message
*reply
,
704 sd_bus_error
*error
) {
706 ExecContext
*c
= ASSERT_PTR(userdata
);
707 ExecImportCredential
*ic
;
714 r
= sd_bus_message_open_container(reply
, 'a', "s");
718 ORDERED_SET_FOREACH(ic
, c
->import_credentials
) {
719 r
= sd_bus_message_append(reply
, "s", ic
->glob
);
724 return sd_bus_message_close_container(reply
);
727 static int property_get_import_credential_ex(
730 const char *interface
,
731 const char *property
,
732 sd_bus_message
*reply
,
734 sd_bus_error
*error
) {
736 ExecContext
*c
= ASSERT_PTR(userdata
);
737 ExecImportCredential
*ic
;
744 r
= sd_bus_message_open_container(reply
, 'a', "(ss)");
748 ORDERED_SET_FOREACH(ic
, c
->import_credentials
) {
749 r
= sd_bus_message_append(reply
, "(ss)", ic
->glob
, ic
->rename
);
754 return sd_bus_message_close_container(reply
);
757 static int property_get_root_hash(
760 const char *interface
,
761 const char *property
,
762 sd_bus_message
*reply
,
764 sd_bus_error
*error
) {
766 ExecContext
*c
= ASSERT_PTR(userdata
);
772 return sd_bus_message_append_array(reply
, 'y', c
->root_hash
, c
->root_hash_size
);
775 static int property_get_root_hash_sig(
778 const char *interface
,
779 const char *property
,
780 sd_bus_message
*reply
,
782 sd_bus_error
*error
) {
784 ExecContext
*c
= ASSERT_PTR(userdata
);
790 return sd_bus_message_append_array(reply
, 'y', c
->root_hash_sig
, c
->root_hash_sig_size
);
793 static int property_get_root_image_options(
796 const char *interface
,
797 const char *property
,
798 sd_bus_message
*reply
,
800 sd_bus_error
*error
) {
802 ExecContext
*c
= ASSERT_PTR(userdata
);
809 r
= sd_bus_message_open_container(reply
, 'a', "(ss)");
813 LIST_FOREACH(mount_options
, m
, c
->root_image_options
) {
814 r
= sd_bus_message_append(reply
, "(ss)",
815 partition_designator_to_string(m
->partition_designator
),
821 return sd_bus_message_close_container(reply
);
824 static int property_get_mount_images(
827 const char *interface
,
828 const char *property
,
829 sd_bus_message
*reply
,
831 sd_bus_error
*error
) {
833 ExecContext
*c
= ASSERT_PTR(userdata
);
840 r
= sd_bus_message_open_container(reply
, 'a', "(ssba(ss))");
844 FOREACH_ARRAY(i
, c
->mount_images
, c
->n_mount_images
) {
845 r
= sd_bus_message_open_container(reply
, SD_BUS_TYPE_STRUCT
, "ssba(ss)");
849 r
= sd_bus_message_append(
857 r
= sd_bus_message_open_container(reply
, 'a', "(ss)");
861 LIST_FOREACH(mount_options
, m
, i
->mount_options
) {
862 r
= sd_bus_message_append(reply
, "(ss)",
863 partition_designator_to_string(m
->partition_designator
),
869 r
= sd_bus_message_close_container(reply
);
873 r
= sd_bus_message_close_container(reply
);
878 return sd_bus_message_close_container(reply
);
881 static int property_get_extension_images(
884 const char *interface
,
885 const char *property
,
886 sd_bus_message
*reply
,
888 sd_bus_error
*error
) {
890 ExecContext
*c
= ASSERT_PTR(userdata
);
897 r
= sd_bus_message_open_container(reply
, 'a', "(sba(ss))");
901 FOREACH_ARRAY(i
, c
->extension_images
, c
->n_extension_images
) {
902 r
= sd_bus_message_open_container(reply
, SD_BUS_TYPE_STRUCT
, "sba(ss)");
906 r
= sd_bus_message_append(
913 r
= sd_bus_message_open_container(reply
, 'a', "(ss)");
917 LIST_FOREACH(mount_options
, m
, i
->mount_options
) {
918 r
= sd_bus_message_append(reply
, "(ss)",
919 partition_designator_to_string(m
->partition_designator
),
925 r
= sd_bus_message_close_container(reply
);
929 r
= sd_bus_message_close_container(reply
);
934 return sd_bus_message_close_container(reply
);
937 static int property_get_exec_dir(
940 const char *interface
,
941 const char *property
,
942 sd_bus_message
*reply
,
944 sd_bus_error
*error
) {
946 ExecDirectory
*d
= ASSERT_PTR(userdata
);
953 r
= sd_bus_message_open_container(reply
, 'a', "s");
957 FOREACH_ARRAY(i
, d
->items
, d
->n_items
) {
958 r
= sd_bus_message_append_basic(reply
, 's', i
->path
);
963 return sd_bus_message_close_container(reply
);
966 static int property_get_exec_dir_symlink(
969 const char *interface
,
970 const char *property
,
971 sd_bus_message
*reply
,
973 sd_bus_error
*error
) {
975 ExecDirectory
*d
= ASSERT_PTR(userdata
);
982 r
= sd_bus_message_open_container(reply
, 'a', "(sst)");
986 FOREACH_ARRAY(i
, d
->items
, d
->n_items
)
987 if (strv_isempty(i
->symlinks
)) {
988 /* The old exec directory properties cannot represent flags, so list them here with no
990 r
= sd_bus_message_append(reply
, "(sst)", i
->path
, "", (uint64_t) (i
->flags
& _EXEC_DIRECTORY_FLAGS_PUBLIC
));
994 STRV_FOREACH(dst
, i
->symlinks
) {
995 r
= sd_bus_message_append(reply
, "(sst)", i
->path
, *dst
, (uint64_t) (i
->flags
& _EXEC_DIRECTORY_FLAGS_PUBLIC
));
1000 return sd_bus_message_close_container(reply
);
1003 static int property_get_image_policy(
1006 const char *interface
,
1007 const char *property
,
1008 sd_bus_message
*reply
,
1010 sd_bus_error
*error
) {
1012 ImagePolicy
**pp
= ASSERT_PTR(userdata
);
1013 _cleanup_free_
char *s
= NULL
;
1020 r
= image_policy_to_string(*pp
?: &image_policy_service
, /* simplify= */ true, &s
);
1024 return sd_bus_message_append(reply
, "s", s
);
1027 static int property_get_private_tmp(
1030 const char *interface
,
1031 const char *property
,
1032 sd_bus_message
*reply
,
1034 sd_bus_error
*error
) {
1036 PrivateTmp
*p
= ASSERT_PTR(userdata
);
1037 int b
= *p
!= PRIVATE_TMP_NO
;
1039 return sd_bus_message_append_basic(reply
, 'b', &b
);
1042 static int property_get_private_users(
1045 const char *interface
,
1046 const char *property
,
1047 sd_bus_message
*reply
,
1049 sd_bus_error
*error
) {
1051 PrivateUsers
*p
= ASSERT_PTR(userdata
);
1052 int b
= *p
!= PRIVATE_USERS_NO
;
1054 return sd_bus_message_append_basic(reply
, 'b', &b
);
1057 static int property_get_protect_control_groups(
1060 const char *interface
,
1061 const char *property
,
1062 sd_bus_message
*reply
,
1064 sd_bus_error
*error
) {
1066 ProtectControlGroups
*p
= ASSERT_PTR(userdata
);
1067 int b
= *p
!= PROTECT_CONTROL_GROUPS_NO
;
1069 return sd_bus_message_append_basic(reply
, 'b', &b
);
1072 static int property_get_protect_hostname(
1075 const char *interface
,
1076 const char *property
,
1077 sd_bus_message
*reply
,
1079 sd_bus_error
*error
) {
1081 ProtectHostname
*p
= ASSERT_PTR(userdata
);
1082 int b
= *p
!= PROTECT_HOSTNAME_NO
;
1084 return sd_bus_message_append_basic(reply
, 'b', &b
);
1087 static int property_get_protect_hostname_ex(
1090 const char *interface
,
1091 const char *property
,
1092 sd_bus_message
*reply
,
1094 sd_bus_error
*error
) {
1096 ExecContext
*c
= ASSERT_PTR(userdata
);
1098 return sd_bus_message_append(reply
, "(ss)", protect_hostname_to_string(c
->protect_hostname
), c
->private_hostname
);
1101 static int property_get_unsigned_as_uint16(
1104 const char *interface
,
1105 const char *property
,
1106 sd_bus_message
*reply
,
1108 sd_bus_error
*error
) {
1110 unsigned *value
= ASSERT_PTR(userdata
);
1112 /* Returns an unsigned as a D-Bus "q" type, i.e. as 16-bit value, even if unsigned is 32-bit. We'll saturate if it doesn't fit. */
1114 uint16_t q
= *value
>= UINT16_MAX
? UINT16_MAX
: (uint16_t) *value
;
1115 return sd_bus_message_append_basic(reply
, 'q', &q
);
1118 const sd_bus_vtable bus_exec_vtable
[] = {
1119 SD_BUS_VTABLE_START(0),
1120 SD_BUS_PROPERTY("Environment", "as", NULL
, offsetof(ExecContext
, environment
), SD_BUS_VTABLE_PROPERTY_CONST
),
1121 SD_BUS_PROPERTY("EnvironmentFiles", "a(sb)", property_get_environment_files
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1122 SD_BUS_PROPERTY("PassEnvironment", "as", NULL
, offsetof(ExecContext
, pass_environment
), SD_BUS_VTABLE_PROPERTY_CONST
),
1123 SD_BUS_PROPERTY("UnsetEnvironment", "as", NULL
, offsetof(ExecContext
, unset_environment
), SD_BUS_VTABLE_PROPERTY_CONST
),
1124 SD_BUS_PROPERTY("UMask", "u", bus_property_get_mode
, offsetof(ExecContext
, umask
), SD_BUS_VTABLE_PROPERTY_CONST
),
1125 SD_BUS_PROPERTY("LimitCPU", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_CPU
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1126 SD_BUS_PROPERTY("LimitCPUSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_CPU
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1127 SD_BUS_PROPERTY("LimitFSIZE", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_FSIZE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1128 SD_BUS_PROPERTY("LimitFSIZESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_FSIZE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1129 SD_BUS_PROPERTY("LimitDATA", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_DATA
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1130 SD_BUS_PROPERTY("LimitDATASoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_DATA
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1131 SD_BUS_PROPERTY("LimitSTACK", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_STACK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1132 SD_BUS_PROPERTY("LimitSTACKSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_STACK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1133 SD_BUS_PROPERTY("LimitCORE", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_CORE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1134 SD_BUS_PROPERTY("LimitCORESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_CORE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1135 SD_BUS_PROPERTY("LimitRSS", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RSS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1136 SD_BUS_PROPERTY("LimitRSSSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RSS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1137 SD_BUS_PROPERTY("LimitNOFILE", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NOFILE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1138 SD_BUS_PROPERTY("LimitNOFILESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NOFILE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1139 SD_BUS_PROPERTY("LimitAS", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_AS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1140 SD_BUS_PROPERTY("LimitASSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_AS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1141 SD_BUS_PROPERTY("LimitNPROC", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NPROC
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1142 SD_BUS_PROPERTY("LimitNPROCSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NPROC
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1143 SD_BUS_PROPERTY("LimitMEMLOCK", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_MEMLOCK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1144 SD_BUS_PROPERTY("LimitMEMLOCKSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_MEMLOCK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1145 SD_BUS_PROPERTY("LimitLOCKS", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_LOCKS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1146 SD_BUS_PROPERTY("LimitLOCKSSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_LOCKS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1147 SD_BUS_PROPERTY("LimitSIGPENDING", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_SIGPENDING
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1148 SD_BUS_PROPERTY("LimitSIGPENDINGSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_SIGPENDING
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1149 SD_BUS_PROPERTY("LimitMSGQUEUE", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_MSGQUEUE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1150 SD_BUS_PROPERTY("LimitMSGQUEUESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_MSGQUEUE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1151 SD_BUS_PROPERTY("LimitNICE", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NICE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1152 SD_BUS_PROPERTY("LimitNICESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NICE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1153 SD_BUS_PROPERTY("LimitRTPRIO", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RTPRIO
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1154 SD_BUS_PROPERTY("LimitRTPRIOSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RTPRIO
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1155 SD_BUS_PROPERTY("LimitRTTIME", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RTTIME
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1156 SD_BUS_PROPERTY("LimitRTTIMESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RTTIME
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1157 SD_BUS_PROPERTY("WorkingDirectory", "s", property_get_working_directory
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1158 SD_BUS_PROPERTY("RootDirectory", "s", NULL
, offsetof(ExecContext
, root_directory
), SD_BUS_VTABLE_PROPERTY_CONST
),
1159 SD_BUS_PROPERTY("RootImage", "s", NULL
, offsetof(ExecContext
, root_image
), SD_BUS_VTABLE_PROPERTY_CONST
),
1160 SD_BUS_PROPERTY("RootImageOptions", "a(ss)", property_get_root_image_options
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1161 SD_BUS_PROPERTY("RootHash", "ay", property_get_root_hash
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1162 SD_BUS_PROPERTY("RootHashPath", "s", NULL
, offsetof(ExecContext
, root_hash_path
), SD_BUS_VTABLE_PROPERTY_CONST
),
1163 SD_BUS_PROPERTY("RootHashSignature", "ay", property_get_root_hash_sig
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1164 SD_BUS_PROPERTY("RootHashSignaturePath", "s", NULL
, offsetof(ExecContext
, root_hash_sig_path
), SD_BUS_VTABLE_PROPERTY_CONST
),
1165 SD_BUS_PROPERTY("RootVerity", "s", NULL
, offsetof(ExecContext
, root_verity
), SD_BUS_VTABLE_PROPERTY_CONST
),
1166 SD_BUS_PROPERTY("RootEphemeral", "b", bus_property_get_bool
, offsetof(ExecContext
, root_ephemeral
), SD_BUS_VTABLE_PROPERTY_CONST
),
1167 SD_BUS_PROPERTY("ExtensionDirectories", "as", NULL
, offsetof(ExecContext
, extension_directories
), SD_BUS_VTABLE_PROPERTY_CONST
),
1168 SD_BUS_PROPERTY("ExtensionImages", "a(sba(ss))", property_get_extension_images
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1169 SD_BUS_PROPERTY("MountImages", "a(ssba(ss))", property_get_mount_images
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1170 SD_BUS_PROPERTY("OOMScoreAdjust", "i", property_get_oom_score_adjust
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1171 SD_BUS_PROPERTY("CoredumpFilter", "t", property_get_coredump_filter
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1172 SD_BUS_PROPERTY("Nice", "i", property_get_nice
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1173 SD_BUS_PROPERTY("IOSchedulingClass", "i", property_get_ioprio_class
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1174 SD_BUS_PROPERTY("IOSchedulingPriority", "i", property_get_ioprio_priority
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1175 SD_BUS_PROPERTY("CPUSchedulingPolicy", "i", property_get_cpu_sched_policy
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1176 SD_BUS_PROPERTY("CPUSchedulingPriority", "i", property_get_cpu_sched_priority
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1177 SD_BUS_PROPERTY("CPUAffinity", "ay", property_get_cpu_affinity
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1178 SD_BUS_PROPERTY("CPUAffinityFromNUMA", "b", property_get_cpu_affinity_from_numa
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1179 SD_BUS_PROPERTY("NUMAPolicy", "i", property_get_numa_policy
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1180 SD_BUS_PROPERTY("NUMAMask", "ay", property_get_numa_mask
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1181 SD_BUS_PROPERTY("TimerSlackNSec", "t", property_get_timer_slack_nsec
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1182 SD_BUS_PROPERTY("CPUSchedulingResetOnFork", "b", bus_property_get_bool
, offsetof(ExecContext
, cpu_sched_reset_on_fork
), SD_BUS_VTABLE_PROPERTY_CONST
),
1183 SD_BUS_PROPERTY("NonBlocking", "b", bus_property_get_bool
, offsetof(ExecContext
, non_blocking
), SD_BUS_VTABLE_PROPERTY_CONST
),
1184 SD_BUS_PROPERTY("StandardInput", "s", property_get_exec_input
, offsetof(ExecContext
, std_input
), SD_BUS_VTABLE_PROPERTY_CONST
),
1185 SD_BUS_PROPERTY("StandardInputFileDescriptorName", "s", property_get_stdio_fdname
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1186 SD_BUS_PROPERTY("StandardInputData", "ay", property_get_input_data
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1187 SD_BUS_PROPERTY("StandardOutput", "s", bus_property_get_exec_output
, offsetof(ExecContext
, std_output
), SD_BUS_VTABLE_PROPERTY_CONST
),
1188 SD_BUS_PROPERTY("StandardOutputFileDescriptorName", "s", property_get_stdio_fdname
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1189 SD_BUS_PROPERTY("StandardError", "s", bus_property_get_exec_output
, offsetof(ExecContext
, std_error
), SD_BUS_VTABLE_PROPERTY_CONST
),
1190 SD_BUS_PROPERTY("StandardErrorFileDescriptorName", "s", property_get_stdio_fdname
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1191 SD_BUS_PROPERTY("TTYPath", "s", NULL
, offsetof(ExecContext
, tty_path
), SD_BUS_VTABLE_PROPERTY_CONST
),
1192 SD_BUS_PROPERTY("TTYReset", "b", bus_property_get_bool
, offsetof(ExecContext
, tty_reset
), SD_BUS_VTABLE_PROPERTY_CONST
),
1193 SD_BUS_PROPERTY("TTYVHangup", "b", bus_property_get_bool
, offsetof(ExecContext
, tty_vhangup
), SD_BUS_VTABLE_PROPERTY_CONST
),
1194 SD_BUS_PROPERTY("TTYVTDisallocate", "b", bus_property_get_bool
, offsetof(ExecContext
, tty_vt_disallocate
), SD_BUS_VTABLE_PROPERTY_CONST
),
1195 SD_BUS_PROPERTY("TTYRows", "q", property_get_unsigned_as_uint16
, offsetof(ExecContext
, tty_rows
), SD_BUS_VTABLE_PROPERTY_CONST
),
1196 SD_BUS_PROPERTY("TTYColumns", "q", property_get_unsigned_as_uint16
, offsetof(ExecContext
, tty_cols
), SD_BUS_VTABLE_PROPERTY_CONST
),
1197 SD_BUS_PROPERTY("SyslogPriority", "i", bus_property_get_int
, offsetof(ExecContext
, syslog_priority
), SD_BUS_VTABLE_PROPERTY_CONST
),
1198 SD_BUS_PROPERTY("SyslogIdentifier", "s", NULL
, offsetof(ExecContext
, syslog_identifier
), SD_BUS_VTABLE_PROPERTY_CONST
),
1199 SD_BUS_PROPERTY("SyslogLevelPrefix", "b", bus_property_get_bool
, offsetof(ExecContext
, syslog_level_prefix
), SD_BUS_VTABLE_PROPERTY_CONST
),
1200 SD_BUS_PROPERTY("SyslogLevel", "i", property_get_syslog_level
, offsetof(ExecContext
, syslog_priority
), SD_BUS_VTABLE_PROPERTY_CONST
),
1201 SD_BUS_PROPERTY("SyslogFacility", "i", property_get_syslog_facility
, offsetof(ExecContext
, syslog_priority
), SD_BUS_VTABLE_PROPERTY_CONST
),
1202 SD_BUS_PROPERTY("LogLevelMax", "i", bus_property_get_int
, offsetof(ExecContext
, log_level_max
), SD_BUS_VTABLE_PROPERTY_CONST
),
1203 SD_BUS_PROPERTY("LogRateLimitIntervalUSec", "t", bus_property_get_usec
, offsetof(ExecContext
, log_ratelimit
.interval
), SD_BUS_VTABLE_PROPERTY_CONST
),
1204 SD_BUS_PROPERTY("LogRateLimitBurst", "u", bus_property_get_unsigned
, offsetof(ExecContext
, log_ratelimit
.burst
), SD_BUS_VTABLE_PROPERTY_CONST
),
1205 SD_BUS_PROPERTY("LogExtraFields", "aay", property_get_log_extra_fields
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1206 SD_BUS_PROPERTY("LogFilterPatterns", "a(bs)", property_get_log_filter_patterns
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1207 SD_BUS_PROPERTY("LogNamespace", "s", NULL
, offsetof(ExecContext
, log_namespace
), SD_BUS_VTABLE_PROPERTY_CONST
),
1208 SD_BUS_PROPERTY("SecureBits", "i", bus_property_get_int
, offsetof(ExecContext
, secure_bits
), SD_BUS_VTABLE_PROPERTY_CONST
),
1209 SD_BUS_PROPERTY("CapabilityBoundingSet", "t", NULL
, offsetof(ExecContext
, capability_bounding_set
), SD_BUS_VTABLE_PROPERTY_CONST
),
1210 SD_BUS_PROPERTY("AmbientCapabilities", "t", NULL
, offsetof(ExecContext
, capability_ambient_set
), SD_BUS_VTABLE_PROPERTY_CONST
),
1211 SD_BUS_PROPERTY("User", "s", NULL
, offsetof(ExecContext
, user
), SD_BUS_VTABLE_PROPERTY_CONST
),
1212 SD_BUS_PROPERTY("Group", "s", NULL
, offsetof(ExecContext
, group
), SD_BUS_VTABLE_PROPERTY_CONST
),
1213 SD_BUS_PROPERTY("DynamicUser", "b", bus_property_get_bool
, offsetof(ExecContext
, dynamic_user
), SD_BUS_VTABLE_PROPERTY_CONST
),
1214 SD_BUS_PROPERTY("SetLoginEnvironment", "b", property_get_set_login_environment
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1215 SD_BUS_PROPERTY("RemoveIPC", "b", bus_property_get_bool
, offsetof(ExecContext
, remove_ipc
), SD_BUS_VTABLE_PROPERTY_CONST
),
1216 SD_BUS_PROPERTY("SetCredential", "a(say)", property_get_set_credential
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1217 SD_BUS_PROPERTY("SetCredentialEncrypted", "a(say)", property_get_set_credential
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1218 SD_BUS_PROPERTY("LoadCredential", "a(ss)", property_get_load_credential
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1219 SD_BUS_PROPERTY("LoadCredentialEncrypted", "a(ss)", property_get_load_credential
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1220 SD_BUS_PROPERTY("ImportCredential", "as", property_get_import_credential
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1221 SD_BUS_PROPERTY("ImportCredentialEx", "a(ss)", property_get_import_credential_ex
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1222 SD_BUS_PROPERTY("SupplementaryGroups", "as", NULL
, offsetof(ExecContext
, supplementary_groups
), SD_BUS_VTABLE_PROPERTY_CONST
),
1223 SD_BUS_PROPERTY("PAMName", "s", NULL
, offsetof(ExecContext
, pam_name
), SD_BUS_VTABLE_PROPERTY_CONST
),
1224 SD_BUS_PROPERTY("ReadWritePaths", "as", NULL
, offsetof(ExecContext
, read_write_paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
1225 SD_BUS_PROPERTY("ReadOnlyPaths", "as", NULL
, offsetof(ExecContext
, read_only_paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
1226 SD_BUS_PROPERTY("InaccessiblePaths", "as", NULL
, offsetof(ExecContext
, inaccessible_paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
1227 SD_BUS_PROPERTY("ExecPaths", "as", NULL
, offsetof(ExecContext
, exec_paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
1228 SD_BUS_PROPERTY("NoExecPaths", "as", NULL
, offsetof(ExecContext
, no_exec_paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
1229 SD_BUS_PROPERTY("ExecSearchPath", "as", NULL
, offsetof(ExecContext
, exec_search_path
), SD_BUS_VTABLE_PROPERTY_CONST
),
1230 SD_BUS_PROPERTY("MountFlags", "t", bus_property_get_ulong
, offsetof(ExecContext
, mount_propagation_flag
), SD_BUS_VTABLE_PROPERTY_CONST
),
1231 SD_BUS_PROPERTY("PrivateTmp", "b", property_get_private_tmp
, offsetof(ExecContext
, private_tmp
), SD_BUS_VTABLE_PROPERTY_CONST
),
1232 SD_BUS_PROPERTY("PrivateTmpEx", "s", property_get_private_tmp_ex
, offsetof(ExecContext
, private_tmp
), SD_BUS_VTABLE_PROPERTY_CONST
),
1233 SD_BUS_PROPERTY("PrivateDevices", "b", bus_property_get_bool
, offsetof(ExecContext
, private_devices
), SD_BUS_VTABLE_PROPERTY_CONST
),
1234 SD_BUS_PROPERTY("ProtectClock", "b", bus_property_get_bool
, offsetof(ExecContext
, protect_clock
), SD_BUS_VTABLE_PROPERTY_CONST
),
1235 SD_BUS_PROPERTY("ProtectKernelTunables", "b", bus_property_get_bool
, offsetof(ExecContext
, protect_kernel_tunables
), SD_BUS_VTABLE_PROPERTY_CONST
),
1236 SD_BUS_PROPERTY("ProtectKernelModules", "b", bus_property_get_bool
, offsetof(ExecContext
, protect_kernel_modules
), SD_BUS_VTABLE_PROPERTY_CONST
),
1237 SD_BUS_PROPERTY("ProtectKernelLogs", "b", bus_property_get_bool
, offsetof(ExecContext
, protect_kernel_logs
), SD_BUS_VTABLE_PROPERTY_CONST
),
1238 SD_BUS_PROPERTY("ProtectControlGroups", "b", property_get_protect_control_groups
, offsetof(ExecContext
, protect_control_groups
), SD_BUS_VTABLE_PROPERTY_CONST
),
1239 SD_BUS_PROPERTY("ProtectControlGroupsEx", "s", property_get_protect_control_groups_ex
, offsetof(ExecContext
, protect_control_groups
), SD_BUS_VTABLE_PROPERTY_CONST
),
1240 SD_BUS_PROPERTY("PrivateNetwork", "b", bus_property_get_bool
, offsetof(ExecContext
, private_network
), SD_BUS_VTABLE_PROPERTY_CONST
),
1241 SD_BUS_PROPERTY("PrivateUsers", "b", property_get_private_users
, offsetof(ExecContext
, private_users
), SD_BUS_VTABLE_PROPERTY_CONST
),
1242 SD_BUS_PROPERTY("PrivateUsersEx", "s", property_get_private_users_ex
, offsetof(ExecContext
, private_users
), SD_BUS_VTABLE_PROPERTY_CONST
),
1243 SD_BUS_PROPERTY("PrivateMounts", "b", bus_property_get_tristate
, offsetof(ExecContext
, private_mounts
), SD_BUS_VTABLE_PROPERTY_CONST
),
1244 SD_BUS_PROPERTY("PrivateIPC", "b", bus_property_get_bool
, offsetof(ExecContext
, private_ipc
), SD_BUS_VTABLE_PROPERTY_CONST
),
1245 SD_BUS_PROPERTY("PrivatePIDs", "s", property_get_private_pids
, offsetof(ExecContext
, private_pids
), SD_BUS_VTABLE_PROPERTY_CONST
),
1246 SD_BUS_PROPERTY("ProtectHome", "s", property_get_protect_home
, offsetof(ExecContext
, protect_home
), SD_BUS_VTABLE_PROPERTY_CONST
),
1247 SD_BUS_PROPERTY("ProtectSystem", "s", property_get_protect_system
, offsetof(ExecContext
, protect_system
), SD_BUS_VTABLE_PROPERTY_CONST
),
1248 SD_BUS_PROPERTY("SameProcessGroup", "b", bus_property_get_bool
, offsetof(ExecContext
, same_pgrp
), SD_BUS_VTABLE_PROPERTY_CONST
),
1249 SD_BUS_PROPERTY("UtmpIdentifier", "s", NULL
, offsetof(ExecContext
, utmp_id
), SD_BUS_VTABLE_PROPERTY_CONST
),
1250 SD_BUS_PROPERTY("UtmpMode", "s", property_get_exec_utmp_mode
, offsetof(ExecContext
, utmp_mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
1251 SD_BUS_PROPERTY("SELinuxContext", "(bs)", property_get_selinux_context
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1252 SD_BUS_PROPERTY("AppArmorProfile", "(bs)", property_get_apparmor_profile
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1253 SD_BUS_PROPERTY("SmackProcessLabel", "(bs)", property_get_smack_process_label
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1254 SD_BUS_PROPERTY("IgnoreSIGPIPE", "b", bus_property_get_bool
, offsetof(ExecContext
, ignore_sigpipe
), SD_BUS_VTABLE_PROPERTY_CONST
),
1255 SD_BUS_PROPERTY("NoNewPrivileges", "b", bus_property_get_bool
, offsetof(ExecContext
, no_new_privileges
), SD_BUS_VTABLE_PROPERTY_CONST
),
1256 SD_BUS_PROPERTY("SystemCallFilter", "(bas)", property_get_syscall_filter
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1257 SD_BUS_PROPERTY("SystemCallArchitectures", "as", property_get_syscall_archs
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1258 SD_BUS_PROPERTY("SystemCallErrorNumber", "i", bus_property_get_int
, offsetof(ExecContext
, syscall_errno
), SD_BUS_VTABLE_PROPERTY_CONST
),
1259 SD_BUS_PROPERTY("SystemCallLog", "(bas)", property_get_syscall_log
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1260 SD_BUS_PROPERTY("Personality", "s", property_get_personality
, offsetof(ExecContext
, personality
), SD_BUS_VTABLE_PROPERTY_CONST
),
1261 SD_BUS_PROPERTY("LockPersonality", "b", bus_property_get_bool
, offsetof(ExecContext
, lock_personality
), SD_BUS_VTABLE_PROPERTY_CONST
),
1262 SD_BUS_PROPERTY("RestrictAddressFamilies", "(bas)", property_get_address_families
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1263 SD_BUS_PROPERTY("RuntimeDirectorySymlink", "a(sst)", property_get_exec_dir_symlink
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_RUNTIME
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1264 SD_BUS_PROPERTY("RuntimeDirectoryPreserve", "s", bus_property_get_exec_preserve_mode
, offsetof(ExecContext
, runtime_directory_preserve_mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
1265 SD_BUS_PROPERTY("RuntimeDirectoryMode", "u", bus_property_get_mode
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_RUNTIME
].mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
1266 SD_BUS_PROPERTY("RuntimeDirectory", "as", property_get_exec_dir
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_RUNTIME
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1267 SD_BUS_PROPERTY("StateDirectorySymlink", "a(sst)", property_get_exec_dir_symlink
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_STATE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1268 SD_BUS_PROPERTY("StateDirectoryMode", "u", bus_property_get_mode
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_STATE
].mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
1269 SD_BUS_PROPERTY("StateDirectory", "as", property_get_exec_dir
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_STATE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1270 SD_BUS_PROPERTY("CacheDirectorySymlink", "a(sst)", property_get_exec_dir_symlink
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_CACHE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1271 SD_BUS_PROPERTY("CacheDirectoryMode", "u", bus_property_get_mode
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_CACHE
].mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
1272 SD_BUS_PROPERTY("CacheDirectory", "as", property_get_exec_dir
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_CACHE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1273 SD_BUS_PROPERTY("LogsDirectorySymlink", "a(sst)", property_get_exec_dir_symlink
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_LOGS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1274 SD_BUS_PROPERTY("LogsDirectoryMode", "u", bus_property_get_mode
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_LOGS
].mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
1275 SD_BUS_PROPERTY("LogsDirectory", "as", property_get_exec_dir
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_LOGS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1276 SD_BUS_PROPERTY("ConfigurationDirectoryMode", "u", bus_property_get_mode
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_CONFIGURATION
].mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
1277 SD_BUS_PROPERTY("ConfigurationDirectory", "as", property_get_exec_dir
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_CONFIGURATION
]), SD_BUS_VTABLE_PROPERTY_CONST
),
1278 SD_BUS_PROPERTY("TimeoutCleanUSec", "t", bus_property_get_usec
, offsetof(ExecContext
, timeout_clean_usec
), SD_BUS_VTABLE_PROPERTY_CONST
),
1279 SD_BUS_PROPERTY("MemoryDenyWriteExecute", "b", bus_property_get_bool
, offsetof(ExecContext
, memory_deny_write_execute
), SD_BUS_VTABLE_PROPERTY_CONST
),
1280 SD_BUS_PROPERTY("RestrictRealtime", "b", bus_property_get_bool
, offsetof(ExecContext
, restrict_realtime
), SD_BUS_VTABLE_PROPERTY_CONST
),
1281 SD_BUS_PROPERTY("RestrictSUIDSGID", "b", bus_property_get_bool
, offsetof(ExecContext
, restrict_suid_sgid
), SD_BUS_VTABLE_PROPERTY_CONST
),
1282 SD_BUS_PROPERTY("RestrictNamespaces", "t", bus_property_get_ulong
, offsetof(ExecContext
, restrict_namespaces
), SD_BUS_VTABLE_PROPERTY_CONST
),
1283 SD_BUS_PROPERTY("DelegateNamespaces", "t", bus_property_get_ulong
, offsetof(ExecContext
, delegate_namespaces
), SD_BUS_VTABLE_PROPERTY_CONST
),
1284 SD_BUS_PROPERTY("RestrictFileSystems", "(bas)", property_get_restrict_filesystems
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1285 SD_BUS_PROPERTY("BindPaths", "a(ssbt)", property_get_bind_paths
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1286 SD_BUS_PROPERTY("BindReadOnlyPaths", "a(ssbt)", property_get_bind_paths
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1287 SD_BUS_PROPERTY("TemporaryFileSystem", "a(ss)", property_get_temporary_filesystems
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1288 SD_BUS_PROPERTY("MountAPIVFS", "b", property_get_mount_apivfs
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1289 SD_BUS_PROPERTY("BindLogSockets", "b", property_get_bind_log_sockets
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1290 SD_BUS_PROPERTY("KeyringMode", "s", property_get_exec_keyring_mode
, offsetof(ExecContext
, keyring_mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
1291 SD_BUS_PROPERTY("ProtectProc", "s", property_get_protect_proc
, offsetof(ExecContext
, protect_proc
), SD_BUS_VTABLE_PROPERTY_CONST
),
1292 SD_BUS_PROPERTY("ProcSubset", "s", property_get_proc_subset
, offsetof(ExecContext
, proc_subset
), SD_BUS_VTABLE_PROPERTY_CONST
),
1293 SD_BUS_PROPERTY("ProtectHostname", "b", property_get_protect_hostname
, offsetof(ExecContext
, protect_hostname
), SD_BUS_VTABLE_PROPERTY_CONST
),
1294 SD_BUS_PROPERTY("ProtectHostnameEx", "(ss)", property_get_protect_hostname_ex
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
1295 SD_BUS_PROPERTY("MemoryKSM", "b", bus_property_get_tristate
, offsetof(ExecContext
, memory_ksm
), SD_BUS_VTABLE_PROPERTY_CONST
),
1296 SD_BUS_PROPERTY("NetworkNamespacePath", "s", NULL
, offsetof(ExecContext
, network_namespace_path
), SD_BUS_VTABLE_PROPERTY_CONST
),
1297 SD_BUS_PROPERTY("IPCNamespacePath", "s", NULL
, offsetof(ExecContext
, ipc_namespace_path
), SD_BUS_VTABLE_PROPERTY_CONST
),
1298 SD_BUS_PROPERTY("RootImagePolicy", "s", property_get_image_policy
, offsetof(ExecContext
, root_image_policy
), SD_BUS_VTABLE_PROPERTY_CONST
),
1299 SD_BUS_PROPERTY("MountImagePolicy", "s", property_get_image_policy
, offsetof(ExecContext
, mount_image_policy
), SD_BUS_VTABLE_PROPERTY_CONST
),
1300 SD_BUS_PROPERTY("ExtensionImagePolicy", "s", property_get_image_policy
, offsetof(ExecContext
, extension_image_policy
), SD_BUS_VTABLE_PROPERTY_CONST
),
1302 /* Obsolete/redundant properties: */
1303 SD_BUS_PROPERTY("Capabilities", "s", property_get_empty_string
, 0, SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
1304 SD_BUS_PROPERTY("ReadWriteDirectories", "as", NULL
, offsetof(ExecContext
, read_write_paths
), SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
1305 SD_BUS_PROPERTY("ReadOnlyDirectories", "as", NULL
, offsetof(ExecContext
, read_only_paths
), SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
1306 SD_BUS_PROPERTY("InaccessibleDirectories", "as", NULL
, offsetof(ExecContext
, inaccessible_paths
), SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
1307 SD_BUS_PROPERTY("IOScheduling", "i", property_get_ioprio
, 0, SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
1312 static int append_exec_command(sd_bus_message
*reply
, ExecCommand
*c
) {
1321 r
= sd_bus_message_open_container(reply
, 'r', "sasbttttuii");
1325 r
= sd_bus_message_append(reply
, "s", c
->path
);
1329 r
= sd_bus_message_append_strv(reply
, c
->argv
);
1333 r
= sd_bus_message_append(reply
, "bttttuii",
1334 !!(c
->flags
& EXEC_COMMAND_IGNORE_FAILURE
),
1335 c
->exec_status
.start_timestamp
.realtime
,
1336 c
->exec_status
.start_timestamp
.monotonic
,
1337 c
->exec_status
.exit_timestamp
.realtime
,
1338 c
->exec_status
.exit_timestamp
.monotonic
,
1339 (uint32_t) c
->exec_status
.pid
,
1340 (int32_t) c
->exec_status
.code
,
1341 (int32_t) c
->exec_status
.status
);
1345 return sd_bus_message_close_container(reply
);
1348 static int append_exec_ex_command(sd_bus_message
*reply
, ExecCommand
*c
) {
1349 _cleanup_strv_free_
char **ex_opts
= NULL
;
1358 r
= sd_bus_message_open_container(reply
, 'r', "sasasttttuii");
1362 r
= sd_bus_message_append(reply
, "s", c
->path
);
1366 r
= sd_bus_message_append_strv(reply
, c
->argv
);
1370 r
= exec_command_flags_to_strv(c
->flags
, &ex_opts
);
1374 r
= sd_bus_message_append_strv(reply
, ex_opts
);
1378 r
= sd_bus_message_append(reply
, "ttttuii",
1379 c
->exec_status
.start_timestamp
.realtime
,
1380 c
->exec_status
.start_timestamp
.monotonic
,
1381 c
->exec_status
.exit_timestamp
.realtime
,
1382 c
->exec_status
.exit_timestamp
.monotonic
,
1383 (uint32_t) c
->exec_status
.pid
,
1384 (int32_t) c
->exec_status
.code
,
1385 (int32_t) c
->exec_status
.status
);
1389 return sd_bus_message_close_container(reply
);
1392 int bus_property_get_exec_command(
1395 const char *interface
,
1396 const char *property
,
1397 sd_bus_message
*reply
,
1399 sd_bus_error
*ret_error
) {
1401 ExecCommand
*c
= (ExecCommand
*) userdata
;
1407 r
= sd_bus_message_open_container(reply
, 'a', "(sasbttttuii)");
1411 r
= append_exec_command(reply
, c
);
1415 return sd_bus_message_close_container(reply
);
1418 int bus_property_get_exec_command_list(
1421 const char *interface
,
1422 const char *property
,
1423 sd_bus_message
*reply
,
1425 sd_bus_error
*ret_error
) {
1427 ExecCommand
*exec_command
= *(ExecCommand
**) userdata
;
1433 r
= sd_bus_message_open_container(reply
, 'a', "(sasbttttuii)");
1437 LIST_FOREACH(command
, c
, exec_command
) {
1438 r
= append_exec_command(reply
, c
);
1443 return sd_bus_message_close_container(reply
);
1446 int bus_property_get_exec_ex_command_list(
1449 const char *interface
,
1450 const char *property
,
1451 sd_bus_message
*reply
,
1453 sd_bus_error
*ret_error
) {
1455 ExecCommand
*exec_command
= *(ExecCommand
**) userdata
;
1461 r
= sd_bus_message_open_container(reply
, 'a', "(sasasttttuii)");
1465 LIST_FOREACH(command
, c
, exec_command
) {
1466 r
= append_exec_ex_command(reply
, c
);
1471 return sd_bus_message_close_container(reply
);
1474 static char* exec_command_flags_to_exec_chars(ExecCommandFlags flags
) {
1475 return strjoin(FLAGS_SET(flags
, EXEC_COMMAND_IGNORE_FAILURE
) ? "-" : "",
1476 FLAGS_SET(flags
, EXEC_COMMAND_NO_ENV_EXPAND
) ? ":" : "",
1477 FLAGS_SET(flags
, EXEC_COMMAND_FULLY_PRIVILEGED
) ? "+" : "",
1478 FLAGS_SET(flags
, EXEC_COMMAND_NO_SETUID
) ? "!" : "",
1479 FLAGS_SET(flags
, EXEC_COMMAND_VIA_SHELL
) ? "|" : "");
1482 int bus_set_transient_exec_command(
1485 ExecCommand
**exec_command
,
1486 sd_bus_message
*message
,
1487 UnitWriteFlags flags
,
1488 sd_bus_error
*error
) {
1490 const char *ex_prop
= endswith(ASSERT_PTR(name
), "Ex");
1495 assert(exec_command
);
1499 /* Drop Ex from the written setting. E.g. ExecStart=, not ExecStartEx=. */
1500 const char *written_name
= ex_prop
? strndupa_safe(name
, ex_prop
- name
) : name
;
1502 r
= sd_bus_message_enter_container(message
, 'a', ex_prop
? "(sasas)" : "(sasb)");
1506 while ((r
= sd_bus_message_enter_container(message
, 'r', ex_prop
? "sasas" : "sasb")) > 0) {
1507 _cleanup_strv_free_
char **argv
= NULL
;
1509 ExecCommandFlags command_flags
;
1511 r
= sd_bus_message_read(message
, "s", &path
);
1515 r
= sd_bus_message_read_strv(message
, &argv
);
1520 _cleanup_strv_free_
char **ex_opts
= NULL
;
1522 r
= sd_bus_message_read_strv(message
, &ex_opts
);
1526 r
= exec_command_flags_from_strv(ex_opts
, &command_flags
);
1532 r
= sd_bus_message_read(message
, "b", &b
);
1536 command_flags
= b
? EXEC_COMMAND_IGNORE_FAILURE
: 0;
1539 if (!FLAGS_SET(command_flags
, EXEC_COMMAND_VIA_SHELL
)) {
1540 if (!filename_or_absolute_path_is_valid(path
))
1541 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
,
1542 "\"%s\" is neither a valid executable name nor an absolute path",
1545 if (strv_isempty(argv
))
1546 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
,
1547 "\"%s\" argv cannot be empty", name
);
1549 /* Always normalize path and argv0 to be "sh" */
1550 path
= _PATH_BSHELL
;
1552 if (strv_isempty(argv
))
1553 r
= strv_extend(&argv
, "sh");
1555 r
= free_and_strdup(&argv
[0], argv
[0][0] == '-' ? "-sh" : "sh");
1560 r
= sd_bus_message_exit_container(message
);
1564 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1565 _cleanup_(exec_command_freep
) ExecCommand
*c
= NULL
;
1567 c
= new(ExecCommand
, 1);
1571 *c
= (ExecCommand
) {
1572 .argv
= TAKE_PTR(argv
),
1573 .flags
= command_flags
,
1576 r
= path_simplify_alloc(path
, &c
->path
);
1580 exec_command_append_list(exec_command
, TAKE_PTR(c
));
1588 r
= sd_bus_message_exit_container(message
);
1592 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1593 _cleanup_(memstream_done
) MemStream m
= {};
1594 _cleanup_free_
char *buf
= NULL
;
1598 *exec_command
= exec_command_free_list(*exec_command
);
1600 f
= memstream_init(&m
);
1604 fprintf(f
, "%s=\n", written_name
);
1606 LIST_FOREACH(command
, c
, *exec_command
) {
1607 _cleanup_free_
char *a
= NULL
, *exec_chars
= NULL
;
1608 UnitWriteFlags esc_flags
= UNIT_ESCAPE_SPECIFIERS
|
1609 (FLAGS_SET(c
->flags
, EXEC_COMMAND_NO_ENV_EXPAND
) ? UNIT_ESCAPE_EXEC_SYNTAX
: UNIT_ESCAPE_EXEC_SYNTAX_ENV
);
1610 bool via_shell
= FLAGS_SET(c
->flags
, EXEC_COMMAND_VIA_SHELL
);
1612 exec_chars
= exec_command_flags_to_exec_chars(c
->flags
);
1616 a
= unit_concat_strv(via_shell
? strv_skip(c
->argv
, 1) : c
->argv
, esc_flags
);
1620 if (via_shell
|| streq(c
->path
, c
->argv
[0]))
1621 fprintf(f
, "%s=%s%s%s\n",
1622 written_name
, exec_chars
, via_shell
&& c
->argv
[0][0] == '-' ? "@" : "", a
);
1624 _cleanup_free_
char *t
= NULL
;
1627 p
= unit_escape_setting(c
->path
, esc_flags
, &t
);
1631 fprintf(f
, "%s=%s@%s %s\n", written_name
, exec_chars
, p
, a
);
1635 r
= memstream_finalize(&m
, &buf
, NULL
);
1639 unit_write_setting(u
, flags
, written_name
, buf
);
1645 static int parse_personality(const char *s
, unsigned long *p
) {
1650 v
= personality_from_string(s
);
1651 if (v
== PERSONALITY_INVALID
)
1658 static const char* mount_propagation_flag_to_string_with_check(unsigned long n
) {
1659 if (!mount_propagation_flag_is_valid(n
))
1662 return mount_propagation_flag_to_string(n
);
1665 static BUS_DEFINE_SET_TRANSIENT(nsec
, "t", uint64_t, nsec_t
, NSEC_FMT
);
1666 static BUS_DEFINE_SET_TRANSIENT_IS_VALID(log_level
, "i", int32_t, int, "%" PRIi32
, log_level_is_valid
);
1668 static BUS_DEFINE_SET_TRANSIENT_IS_VALID(errno
, "i", int32_t, int, "%" PRIi32
, seccomp_errno_or_action_is_valid
);
1670 static BUS_DEFINE_SET_TRANSIENT_PARSE(std_input
, ExecInput
, exec_input_from_string
);
1671 static BUS_DEFINE_SET_TRANSIENT_PARSE(std_output
, ExecOutput
, exec_output_from_string
);
1672 static BUS_DEFINE_SET_TRANSIENT_PARSE(utmp_mode
, ExecUtmpMode
, exec_utmp_mode_from_string
);
1673 static BUS_DEFINE_SET_TRANSIENT_PARSE(protect_system
, ProtectSystem
, protect_system_from_string
);
1674 static BUS_DEFINE_SET_TRANSIENT_PARSE(protect_home
, ProtectHome
, protect_home_from_string
);
1675 static BUS_DEFINE_SET_TRANSIENT_PARSE(keyring_mode
, ExecKeyringMode
, exec_keyring_mode_from_string
);
1676 static BUS_DEFINE_SET_TRANSIENT_PARSE(protect_proc
, ProtectProc
, protect_proc_from_string
);
1677 static BUS_DEFINE_SET_TRANSIENT_PARSE(proc_subset
, ProcSubset
, proc_subset_from_string
);
1678 BUS_DEFINE_SET_TRANSIENT_PARSE(exec_preserve_mode
, ExecPreserveMode
, exec_preserve_mode_from_string
);
1679 static BUS_DEFINE_SET_TRANSIENT_PARSE_PTR(personality
, unsigned long, parse_personality
);
1680 static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(secure_bits
, "i", int32_t, int, "%" PRIi32
, secure_bits_to_string_alloc_with_check
);
1681 static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(capability
, "t", uint64_t, uint64_t, "%" PRIu64
, capability_set_to_string
);
1682 static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(namespace_flag
, "t", uint64_t, unsigned long, "%" PRIu64
, namespace_flags_to_string
);
1683 static BUS_DEFINE_SET_TRANSIENT_TO_STRING(mount_propagation_flag
, "t", uint64_t, unsigned long, "%" PRIu64
, mount_propagation_flag_to_string_with_check
);
1685 int bus_exec_context_set_transient_property(
1689 sd_bus_message
*message
,
1690 UnitWriteFlags flags
,
1691 sd_bus_error
*error
) {
1701 flags
|= UNIT_PRIVATE
;
1703 if (streq(name
, "User"))
1704 return bus_set_transient_user_relaxed(u
, name
, &c
->user
, message
, flags
, error
);
1706 if (streq(name
, "Group"))
1707 return bus_set_transient_user_relaxed(u
, name
, &c
->group
, message
, flags
, error
);
1709 if (streq(name
, "SetLoginEnvironment"))
1710 return bus_set_transient_tristate(u
, name
, &c
->set_login_environment
, message
, flags
, error
);
1712 if (streq(name
, "TTYPath"))
1713 return bus_set_transient_path(u
, name
, &c
->tty_path
, message
, flags
, error
);
1715 if (streq(name
, "RootImage"))
1716 return bus_set_transient_path(u
, name
, &c
->root_image
, message
, flags
, error
);
1718 if (streq(name
, "RootImageOptions")) {
1719 _cleanup_(mount_options_free_allp
) MountOptions
*options
= NULL
;
1720 _cleanup_free_
char *format_str
= NULL
;
1722 r
= bus_read_mount_options(message
, error
, &options
, &format_str
, " ");
1726 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1728 LIST_JOIN(mount_options
, c
->root_image_options
, options
);
1729 unit_write_settingf(
1730 u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
,
1735 c
->root_image_options
= mount_options_free_all(c
->root_image_options
);
1736 unit_write_settingf(u
, flags
, name
, "%s=", name
);
1743 if (streq(name
, "RootHash")) {
1744 const void *roothash_decoded
;
1745 size_t roothash_decoded_size
;
1747 r
= sd_bus_message_read_array(message
, 'y', &roothash_decoded
, &roothash_decoded_size
);
1751 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1752 _cleanup_free_
char *encoded
= NULL
;
1754 if (roothash_decoded_size
== 0) {
1755 c
->root_hash_path
= mfree(c
->root_hash_path
);
1756 c
->root_hash
= mfree(c
->root_hash
);
1757 c
->root_hash_size
= 0;
1759 unit_write_settingf(u
, flags
, name
, "RootHash=");
1761 _cleanup_free_
void *p
= NULL
;
1763 encoded
= hexmem(roothash_decoded
, roothash_decoded_size
);
1767 p
= memdup(roothash_decoded
, roothash_decoded_size
);
1771 free_and_replace(c
->root_hash
, p
);
1772 c
->root_hash_size
= roothash_decoded_size
;
1773 c
->root_hash_path
= mfree(c
->root_hash_path
);
1775 unit_write_settingf(u
, flags
, name
, "RootHash=%s", encoded
);
1782 if (streq(name
, "RootHashPath")) {
1783 c
->root_hash_size
= 0;
1784 c
->root_hash
= mfree(c
->root_hash
);
1786 return bus_set_transient_path(u
, "RootHash", &c
->root_hash_path
, message
, flags
, error
);
1789 if (streq(name
, "RootHashSignature")) {
1790 const void *roothash_sig_decoded
;
1791 size_t roothash_sig_decoded_size
;
1793 r
= sd_bus_message_read_array(message
, 'y', &roothash_sig_decoded
, &roothash_sig_decoded_size
);
1797 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1798 _cleanup_free_
char *encoded
= NULL
;
1800 if (roothash_sig_decoded_size
== 0) {
1801 c
->root_hash_sig_path
= mfree(c
->root_hash_sig_path
);
1802 c
->root_hash_sig
= mfree(c
->root_hash_sig
);
1803 c
->root_hash_sig_size
= 0;
1805 unit_write_settingf(u
, flags
, name
, "RootHashSignature=");
1807 _cleanup_free_
void *p
= NULL
;
1810 len
= base64mem(roothash_sig_decoded
, roothash_sig_decoded_size
, &encoded
);
1814 p
= memdup(roothash_sig_decoded
, roothash_sig_decoded_size
);
1818 free_and_replace(c
->root_hash_sig
, p
);
1819 c
->root_hash_sig_size
= roothash_sig_decoded_size
;
1820 c
->root_hash_sig_path
= mfree(c
->root_hash_sig_path
);
1822 unit_write_settingf(u
, flags
, name
, "RootHashSignature=base64:%s", encoded
);
1829 if (streq(name
, "RootHashSignaturePath")) {
1830 c
->root_hash_sig_size
= 0;
1831 c
->root_hash_sig
= mfree(c
->root_hash_sig
);
1833 return bus_set_transient_path(u
, "RootHashSignature", &c
->root_hash_sig_path
, message
, flags
, error
);
1836 if (streq(name
, "RootVerity"))
1837 return bus_set_transient_path(u
, name
, &c
->root_verity
, message
, flags
, error
);
1839 if (streq(name
, "RootDirectory"))
1840 return bus_set_transient_path(u
, name
, &c
->root_directory
, message
, flags
, error
);
1842 if (streq(name
, "RootEphemeral"))
1843 return bus_set_transient_bool(u
, name
, &c
->root_ephemeral
, message
, flags
, error
);
1845 if (streq(name
, "SyslogIdentifier"))
1846 return bus_set_transient_string(u
, name
, &c
->syslog_identifier
, message
, flags
, error
);
1848 if (streq(name
, "LogLevelMax"))
1849 return bus_set_transient_log_level(u
, name
, &c
->log_level_max
, message
, flags
, error
);
1851 if (streq(name
, "LogRateLimitIntervalUSec"))
1852 return bus_set_transient_usec(u
, name
, &c
->log_ratelimit
.interval
, message
, flags
, error
);
1854 if (streq(name
, "LogRateLimitBurst"))
1855 return bus_set_transient_unsigned(u
, name
, &c
->log_ratelimit
.burst
, message
, flags
, error
);
1857 if (streq(name
, "LogFilterPatterns")) {
1858 /* Use _cleanup_free_, not _cleanup_strv_free_, as we don't want the content of the strv
1860 _cleanup_free_
char **allow_list
= NULL
, **deny_list
= NULL
;
1861 const char *pattern
;
1864 r
= sd_bus_message_enter_container(message
, 'a', "(bs)");
1868 while ((r
= sd_bus_message_read(message
, "(bs)", &is_allowlist
, &pattern
)) > 0) {
1869 _cleanup_(pattern_freep
) pcre2_code
*compiled_pattern
= NULL
;
1871 if (isempty(pattern
))
1874 r
= pattern_compile_and_log(pattern
, 0, &compiled_pattern
);
1878 r
= strv_push(is_allowlist
? &allow_list
: &deny_list
, (char *)pattern
);
1885 r
= sd_bus_message_exit_container(message
);
1889 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1890 if (strv_isempty(allow_list
) && strv_isempty(deny_list
)) {
1891 c
->log_filter_allowed_patterns
= set_free(c
->log_filter_allowed_patterns
);
1892 c
->log_filter_denied_patterns
= set_free(c
->log_filter_denied_patterns
);
1893 unit_write_settingf(u
, flags
, name
, "%s=", name
);
1895 r
= set_put_strdupv(&c
->log_filter_allowed_patterns
, allow_list
);
1898 r
= set_put_strdupv(&c
->log_filter_denied_patterns
, deny_list
);
1902 STRV_FOREACH(unit_pattern
, allow_list
)
1903 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, *unit_pattern
);
1904 STRV_FOREACH(unit_pattern
, deny_list
)
1905 unit_write_settingf(u
, flags
, name
, "%s=~%s", name
, *unit_pattern
);
1912 if (streq(name
, "Personality"))
1913 return bus_set_transient_personality(u
, name
, &c
->personality
, message
, flags
, error
);
1915 if (streq(name
, "StandardInput"))
1916 return bus_set_transient_std_input(u
, name
, &c
->std_input
, message
, flags
, error
);
1918 if (streq(name
, "StandardOutput"))
1919 return bus_set_transient_std_output(u
, name
, &c
->std_output
, message
, flags
, error
);
1921 if (streq(name
, "StandardError"))
1922 return bus_set_transient_std_output(u
, name
, &c
->std_error
, message
, flags
, error
);
1924 if (streq(name
, "IgnoreSIGPIPE"))
1925 return bus_set_transient_bool(u
, name
, &c
->ignore_sigpipe
, message
, flags
, error
);
1927 if (streq(name
, "TTYVHangup"))
1928 return bus_set_transient_bool(u
, name
, &c
->tty_vhangup
, message
, flags
, error
);
1930 if (streq(name
, "TTYReset"))
1931 return bus_set_transient_bool(u
, name
, &c
->tty_reset
, message
, flags
, error
);
1933 if (streq(name
, "TTYVTDisallocate"))
1934 return bus_set_transient_bool(u
, name
, &c
->tty_vt_disallocate
, message
, flags
, error
);
1936 if (streq(name
, "TTYRows"))
1937 return bus_set_transient_unsigned(u
, name
, &c
->tty_rows
, message
, flags
, error
);
1939 if (streq(name
, "TTYColumns"))
1940 return bus_set_transient_unsigned(u
, name
, &c
->tty_cols
, message
, flags
, error
);
1942 if (streq(name
, "PrivateTmp")) {
1945 r
= sd_bus_message_read(message
, "b", &v
);
1949 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1950 c
->private_tmp
= v
? PRIVATE_TMP_CONNECTED
: PRIVATE_TMP_NO
;
1951 (void) unit_write_settingf(u
, flags
, name
, "%s=%s", name
, yes_no(v
));
1956 } else if (streq(name
, "PrivateTmpEx")) {
1960 r
= sd_bus_message_read(message
, "s", &s
);
1964 t
= private_tmp_from_string(s
);
1966 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid %s setting: %s", name
, s
);
1968 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1970 (void) unit_write_settingf(u
, flags
, name
, "PrivateTmp=%s",
1971 private_tmp_to_string(c
->private_tmp
));
1977 if (streq(name
, "PrivateUsers")) {
1980 r
= sd_bus_message_read(message
, "b", &v
);
1984 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1985 c
->private_users
= v
? PRIVATE_USERS_SELF
: PRIVATE_USERS_NO
;
1986 (void) unit_write_settingf(u
, flags
, name
, "%s=%s", name
, yes_no(v
));
1991 } else if (streq(name
, "PrivateUsersEx")) {
1995 r
= sd_bus_message_read(message
, "s", &s
);
1999 t
= private_users_from_string(s
);
2001 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid %s setting: %s", name
, s
);
2003 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2004 c
->private_users
= t
;
2005 (void) unit_write_settingf(u
, flags
, name
, "PrivateUsers=%s",
2006 private_users_to_string(c
->private_users
));
2012 if (streq(name
, "ProtectControlGroups")) {
2015 r
= sd_bus_message_read(message
, "b", &v
);
2019 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2020 c
->protect_control_groups
= v
? PROTECT_CONTROL_GROUPS_YES
: PROTECT_CONTROL_GROUPS_NO
;
2021 (void) unit_write_settingf(u
, flags
, name
, "%s=%s", name
, yes_no(v
));
2027 if (streq(name
, "ProtectControlGroupsEx")) {
2029 ProtectControlGroups t
;
2031 r
= sd_bus_message_read(message
, "s", &s
);
2035 t
= protect_control_groups_from_string(s
);
2037 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid %s setting: %s", name
, s
);
2039 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2040 c
->protect_control_groups
= t
;
2041 (void) unit_write_settingf(u
, flags
, name
, "ProtectControlGroups=%s",
2042 protect_control_groups_to_string(c
->protect_control_groups
));
2048 if (streq(name
, "PrivatePIDs")) {
2052 r
= sd_bus_message_read(message
, "s", &s
);
2056 t
= private_pids_from_string(s
);
2058 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid %s setting: %s", name
, s
);
2060 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2061 c
->private_pids
= t
;
2062 (void) unit_write_settingf(u
, flags
, name
, "%s=%s",
2063 name
, private_pids_to_string(c
->private_pids
));
2069 if (streq(name
, "ProtectHostname")) {
2072 r
= sd_bus_message_read(message
, "b", &v
);
2076 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2077 c
->protect_hostname
= v
? PROTECT_HOSTNAME_YES
: PROTECT_HOSTNAME_NO
;
2078 (void) unit_write_settingf(u
, flags
, name
, "%s=%s", name
, yes_no(v
));
2085 if (streq(name
, "ProtectHostnameEx")) {
2086 const char *s
, *h
= NULL
;
2088 r
= sd_bus_message_read(message
, "(ss)", &s
, &h
);
2092 if (!isempty(h
) && !hostname_is_valid(h
, /* flags = */ 0))
2093 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid hostname in %s setting: %s", name
, h
);
2095 ProtectHostname t
= protect_hostname_from_string(s
);
2096 if (t
< 0 || (t
== PROTECT_HOSTNAME_NO
&& !isempty(h
)))
2097 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid %s setting: %s", name
, s
);
2099 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2100 c
->protect_hostname
= t
;
2101 r
= free_and_strdup(&c
->private_hostname
, empty_to_null(h
));
2105 (void) unit_write_settingf(u
, flags
, name
, "ProtectHostname=%s%s%s",
2106 protect_hostname_to_string(c
->protect_hostname
),
2107 c
->private_hostname
? ":" : "",
2108 strempty(c
->private_hostname
));
2114 if (streq(name
, "PrivateDevices"))
2115 return bus_set_transient_bool(u
, name
, &c
->private_devices
, message
, flags
, error
);
2117 if (streq(name
, "PrivateMounts"))
2118 return bus_set_transient_tristate(u
, name
, &c
->private_mounts
, message
, flags
, error
);
2120 if (streq(name
, "MountAPIVFS"))
2121 return bus_set_transient_tristate(u
, name
, &c
->mount_apivfs
, message
, flags
, error
);
2123 if (streq(name
, "BindLogSockets"))
2124 return bus_set_transient_tristate(u
, name
, &c
->bind_log_sockets
, message
, flags
, error
);
2126 if (streq(name
, "PrivateNetwork"))
2127 return bus_set_transient_bool(u
, name
, &c
->private_network
, message
, flags
, error
);
2129 if (streq(name
, "PrivateIPC"))
2130 return bus_set_transient_bool(u
, name
, &c
->private_ipc
, message
, flags
, error
);
2132 if (streq(name
, "NoNewPrivileges"))
2133 return bus_set_transient_bool(u
, name
, &c
->no_new_privileges
, message
, flags
, error
);
2135 if (streq(name
, "SyslogLevelPrefix"))
2136 return bus_set_transient_bool(u
, name
, &c
->syslog_level_prefix
, message
, flags
, error
);
2138 if (streq(name
, "MemoryDenyWriteExecute"))
2139 return bus_set_transient_bool(u
, name
, &c
->memory_deny_write_execute
, message
, flags
, error
);
2141 if (streq(name
, "RestrictRealtime"))
2142 return bus_set_transient_bool(u
, name
, &c
->restrict_realtime
, message
, flags
, error
);
2144 if (streq(name
, "RestrictSUIDSGID"))
2145 return bus_set_transient_bool(u
, name
, &c
->restrict_suid_sgid
, message
, flags
, error
);
2147 if (streq(name
, "DynamicUser"))
2148 return bus_set_transient_bool(u
, name
, &c
->dynamic_user
, message
, flags
, error
);
2150 if (streq(name
, "RemoveIPC"))
2151 return bus_set_transient_bool(u
, name
, &c
->remove_ipc
, message
, flags
, error
);
2153 if (streq(name
, "ProtectKernelTunables"))
2154 return bus_set_transient_bool(u
, name
, &c
->protect_kernel_tunables
, message
, flags
, error
);
2156 if (streq(name
, "ProtectKernelModules"))
2157 return bus_set_transient_bool(u
, name
, &c
->protect_kernel_modules
, message
, flags
, error
);
2159 if (streq(name
, "ProtectKernelLogs"))
2160 return bus_set_transient_bool(u
, name
, &c
->protect_kernel_logs
, message
, flags
, error
);
2162 if (streq(name
, "ProtectClock"))
2163 return bus_set_transient_bool(u
, name
, &c
->protect_clock
, message
, flags
, error
);
2165 if (streq(name
, "CPUSchedulingResetOnFork"))
2166 return bus_set_transient_bool(u
, name
, &c
->cpu_sched_reset_on_fork
, message
, flags
, error
);
2168 if (streq(name
, "NonBlocking"))
2169 return bus_set_transient_bool(u
, name
, &c
->non_blocking
, message
, flags
, error
);
2171 if (streq(name
, "LockPersonality"))
2172 return bus_set_transient_bool(u
, name
, &c
->lock_personality
, message
, flags
, error
);
2174 if (streq(name
, "MemoryKSM"))
2175 return bus_set_transient_tristate(u
, name
, &c
->memory_ksm
, message
, flags
, error
);
2177 if (streq(name
, "UtmpIdentifier"))
2178 return bus_set_transient_string(u
, name
, &c
->utmp_id
, message
, flags
, error
);
2180 if (streq(name
, "UtmpMode"))
2181 return bus_set_transient_utmp_mode(u
, name
, &c
->utmp_mode
, message
, flags
, error
);
2183 if (streq(name
, "PAMName"))
2184 return bus_set_transient_string(u
, name
, &c
->pam_name
, message
, flags
, error
);
2186 if (streq(name
, "TimerSlackNSec"))
2187 return bus_set_transient_nsec(u
, name
, &c
->timer_slack_nsec
, message
, flags
, error
);
2189 if (streq(name
, "ProtectSystem"))
2190 return bus_set_transient_protect_system(u
, name
, &c
->protect_system
, message
, flags
, error
);
2192 if (streq(name
, "ProtectHome"))
2193 return bus_set_transient_protect_home(u
, name
, &c
->protect_home
, message
, flags
, error
);
2195 if (streq(name
, "KeyringMode"))
2196 return bus_set_transient_keyring_mode(u
, name
, &c
->keyring_mode
, message
, flags
, error
);
2198 if (streq(name
, "ProtectProc"))
2199 return bus_set_transient_protect_proc(u
, name
, &c
->protect_proc
, message
, flags
, error
);
2201 if (streq(name
, "ProcSubset"))
2202 return bus_set_transient_proc_subset(u
, name
, &c
->proc_subset
, message
, flags
, error
);
2204 if (streq(name
, "RuntimeDirectoryPreserve"))
2205 return bus_set_transient_exec_preserve_mode(u
, name
, &c
->runtime_directory_preserve_mode
, message
, flags
, error
);
2207 if (streq(name
, "UMask"))
2208 return bus_set_transient_mode_t(u
, name
, &c
->umask
, message
, flags
, error
);
2210 if (streq(name
, "RuntimeDirectoryMode"))
2211 return bus_set_transient_mode_t(u
, name
, &c
->directories
[EXEC_DIRECTORY_RUNTIME
].mode
, message
, flags
, error
);
2213 if (streq(name
, "StateDirectoryMode"))
2214 return bus_set_transient_mode_t(u
, name
, &c
->directories
[EXEC_DIRECTORY_STATE
].mode
, message
, flags
, error
);
2216 if (streq(name
, "CacheDirectoryMode"))
2217 return bus_set_transient_mode_t(u
, name
, &c
->directories
[EXEC_DIRECTORY_CACHE
].mode
, message
, flags
, error
);
2219 if (streq(name
, "LogsDirectoryMode"))
2220 return bus_set_transient_mode_t(u
, name
, &c
->directories
[EXEC_DIRECTORY_LOGS
].mode
, message
, flags
, error
);
2222 if (streq(name
, "ConfigurationDirectoryMode"))
2223 return bus_set_transient_mode_t(u
, name
, &c
->directories
[EXEC_DIRECTORY_CONFIGURATION
].mode
, message
, flags
, error
);
2225 if (streq(name
, "SELinuxContext"))
2226 return bus_set_transient_string(u
, name
, &c
->selinux_context
, message
, flags
, error
);
2228 if (streq(name
, "SecureBits"))
2229 return bus_set_transient_secure_bits(u
, name
, &c
->secure_bits
, message
, flags
, error
);
2231 if (streq(name
, "CapabilityBoundingSet"))
2232 return bus_set_transient_capability(u
, name
, &c
->capability_bounding_set
, message
, flags
, error
);
2234 if (streq(name
, "AmbientCapabilities"))
2235 return bus_set_transient_capability(u
, name
, &c
->capability_ambient_set
, message
, flags
, error
);
2237 if (streq(name
, "RestrictNamespaces"))
2238 return bus_set_transient_namespace_flag(u
, name
, &c
->restrict_namespaces
, message
, flags
, error
);
2240 if (streq(name
, "DelegateNamespaces"))
2241 return bus_set_transient_namespace_flag(u
, name
, &c
->delegate_namespaces
, message
, flags
, error
);
2243 if (streq(name
, "RestrictFileSystems")) {
2245 _cleanup_strv_free_
char **l
= NULL
;
2247 r
= sd_bus_message_enter_container(message
, 'r', "bas");
2251 r
= sd_bus_message_read(message
, "b", &allow_list
);
2255 r
= sd_bus_message_read_strv(message
, &l
);
2259 r
= sd_bus_message_exit_container(message
);
2263 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2264 _cleanup_free_
char *joined
= NULL
;
2265 FilesystemParseFlags invert_flag
= allow_list
? 0 : FILESYSTEM_PARSE_INVERT
;
2267 if (strv_isempty(l
)) {
2268 c
->restrict_filesystems_allow_list
= false;
2269 c
->restrict_filesystems
= set_free(c
->restrict_filesystems
);
2271 unit_write_setting(u
, flags
, name
, "RestrictFileSystems=");
2275 if (!c
->restrict_filesystems
)
2276 c
->restrict_filesystems_allow_list
= allow_list
;
2278 STRV_FOREACH(s
, l
) {
2279 r
= bpf_restrict_fs_parse_filesystem(
2281 &c
->restrict_filesystems
,
2282 FILESYSTEM_PARSE_LOG
|
2283 (invert_flag
? FILESYSTEM_PARSE_INVERT
: 0)|
2284 (c
->restrict_filesystems_allow_list
? FILESYSTEM_PARSE_ALLOW_LIST
: 0),
2290 joined
= strv_join(l
, " ");
2294 unit_write_settingf(u
, flags
, name
, "%s=%s%s", name
, allow_list
? "" : "~", joined
);
2300 if (streq(name
, "MountFlags"))
2301 return bus_set_transient_mount_propagation_flag(u
, name
, &c
->mount_propagation_flag
, message
, flags
, error
);
2303 if (streq(name
, "NetworkNamespacePath"))
2304 return bus_set_transient_path(u
, name
, &c
->network_namespace_path
, message
, flags
, error
);
2306 if (streq(name
, "IPCNamespacePath"))
2307 return bus_set_transient_path(u
, name
, &c
->ipc_namespace_path
, message
, flags
, error
);
2309 if (streq(name
, "SupplementaryGroups")) {
2310 _cleanup_strv_free_
char **l
= NULL
;
2312 r
= sd_bus_message_read_strv(message
, &l
);
2317 if (!isempty(*p
) && !valid_user_group_name(*p
, VALID_USER_ALLOW_NUMERIC
|VALID_USER_RELAX
|VALID_USER_WARN
))
2318 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
,
2319 "Invalid supplementary group names");
2321 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2322 if (strv_isempty(l
)) {
2323 c
->supplementary_groups
= strv_free(c
->supplementary_groups
);
2324 unit_write_settingf(u
, flags
, name
, "%s=", name
);
2326 _cleanup_free_
char *joined
= NULL
;
2328 r
= strv_extend_strv(&c
->supplementary_groups
, l
, true);
2332 joined
= strv_join(c
->supplementary_groups
, " ");
2336 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "%s=%s", name
, joined
);
2342 } else if (STR_IN_SET(name
, "SetCredential", "SetCredentialEncrypted")) {
2343 bool isempty
= true;
2345 r
= sd_bus_message_enter_container(message
, 'a', "(say)");
2354 r
= sd_bus_message_enter_container(message
, 'r', "say");
2360 r
= sd_bus_message_read(message
, "s", &id
);
2364 r
= sd_bus_message_read_array(message
, 'y', &p
, &sz
);
2368 r
= sd_bus_message_exit_container(message
);
2372 if (!credential_name_valid(id
))
2373 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Credential ID is invalid: %s", id
);
2377 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2378 bool encrypted
= endswith(name
, "Encrypted");
2379 _cleanup_free_
char *a
= NULL
, *b
= NULL
;
2380 _cleanup_free_
void *copy
= NULL
;
2382 copy
= memdup(p
, sz
);
2386 a
= specifier_escape(id
);
2390 b
= cescape_length(p
, sz
);
2394 r
= exec_context_put_set_credential(c
, id
, TAKE_PTR(copy
), sz
, encrypted
);
2398 (void) unit_write_settingf(u
, flags
, name
, "%s=%s:%s", name
, a
, b
);
2402 r
= sd_bus_message_exit_container(message
);
2406 if (!UNIT_WRITE_FLAGS_NOOP(flags
) && isempty
) {
2407 c
->set_credentials
= hashmap_free(c
->set_credentials
);
2408 (void) unit_write_settingf(u
, flags
, name
, "%s=", name
);
2413 } else if (STR_IN_SET(name
, "LoadCredential", "LoadCredentialEncrypted")) {
2414 bool isempty
= true;
2416 r
= sd_bus_message_enter_container(message
, 'a', "(ss)");
2421 const char *id
, *source
;
2423 r
= sd_bus_message_read(message
, "(ss)", &id
, &source
);
2429 if (!credential_name_valid(id
))
2430 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Credential ID is invalid: %s", id
);
2432 if (!(path_is_absolute(source
) ? path_is_normalized(source
) : credential_name_valid(source
)))
2433 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Credential source is invalid: %s", source
);
2437 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2438 bool encrypted
= endswith(name
, "Encrypted");
2440 r
= exec_context_put_load_credential(c
, id
, source
, encrypted
);
2444 (void) unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "%s=%s:%s", name
, id
, source
);
2448 r
= sd_bus_message_exit_container(message
);
2452 if (!UNIT_WRITE_FLAGS_NOOP(flags
) && isempty
) {
2453 c
->load_credentials
= hashmap_free(c
->load_credentials
);
2454 (void) unit_write_settingf(u
, flags
, name
, "%s=", name
);
2459 } else if (STR_IN_SET(name
, "ImportCredential", "ImportCredentialEx")) {
2460 bool empty
= true, ex
= streq(name
, "ImportCredentialEx");
2462 r
= sd_bus_message_enter_container(message
, 'a', ex
? "(ss)" : "s");
2467 const char *glob
, *rename
= NULL
;
2470 r
= sd_bus_message_read(message
, "(ss)", &glob
, &rename
);
2472 r
= sd_bus_message_read(message
, "s", &glob
);
2478 if (!credential_glob_valid(glob
))
2479 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Credential name or glob is invalid: %s", glob
);
2481 rename
= empty_to_null(rename
);
2483 if (rename
&& !credential_name_valid(rename
))
2484 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Credential name is invalid: %s", rename
);
2488 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2489 r
= exec_context_put_import_credential(c
, glob
, rename
);
2493 (void) unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
,
2494 "ImportCredential=%s%s%s",
2495 glob
, rename
? ":" : "", strempty(rename
));
2499 r
= sd_bus_message_exit_container(message
);
2503 if (!UNIT_WRITE_FLAGS_NOOP(flags
) && empty
) {
2504 c
->import_credentials
= ordered_set_free(c
->import_credentials
);
2505 (void) unit_write_settingf(u
, flags
, name
, "%s=", name
);
2510 } else if (streq(name
, "SyslogLevel")) {
2513 r
= sd_bus_message_read(message
, "i", &level
);
2517 if (!log_level_is_valid(level
))
2518 return sd_bus_error_set(error
, SD_BUS_ERROR_INVALID_ARGS
, "Log level value out of range");
2520 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2521 c
->syslog_priority
= (c
->syslog_priority
& LOG_FACMASK
) | level
;
2522 unit_write_settingf(u
, flags
, name
, "SyslogLevel=%i", level
);
2527 } else if (streq(name
, "SyslogFacility")) {
2530 r
= sd_bus_message_read(message
, "i", &facility
);
2534 if (!log_facility_unshifted_is_valid(facility
))
2535 return sd_bus_error_set(error
, SD_BUS_ERROR_INVALID_ARGS
, "Log facility value out of range");
2537 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2538 c
->syslog_priority
= (facility
<< 3) | LOG_PRI(c
->syslog_priority
);
2539 unit_write_settingf(u
, flags
, name
, "SyslogFacility=%i", facility
);
2544 } else if (streq(name
, "LogNamespace")) {
2547 r
= sd_bus_message_read(message
, "s", &n
);
2551 if (!isempty(n
) && !log_namespace_name_valid(n
))
2552 return sd_bus_error_set(error
, SD_BUS_ERROR_INVALID_ARGS
, "Log namespace name not valid");
2554 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2557 c
->log_namespace
= mfree(c
->log_namespace
);
2558 unit_write_settingf(u
, flags
, name
, "%s=", name
);
2560 r
= free_and_strdup(&c
->log_namespace
, n
);
2564 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, n
);
2570 } else if (streq(name
, "LogExtraFields")) {
2573 r
= sd_bus_message_enter_container(message
, 'a', "ay");
2578 _cleanup_free_
void *copy
= NULL
;
2583 /* Note that we expect a byte array for each field, instead of a string. That's because on the
2584 * lower-level journal fields can actually contain binary data and are not restricted to text,
2585 * and we should not "lose precision" in our types on the way. That said, I am pretty sure
2586 * actually encoding binary data as unit metadata is not a good idea. Hence we actually refuse
2587 * any actual binary data, and only accept UTF-8. This allows us to eventually lift this
2588 * limitation, should a good, valid use case arise. */
2590 r
= sd_bus_message_read_array(message
, 'y', &p
, &sz
);
2596 if (memchr(p
, 0, sz
))
2597 return sd_bus_error_set(error
, SD_BUS_ERROR_INVALID_ARGS
, "Journal field contains zero byte");
2599 eq
= memchr(p
, '=', sz
);
2601 return sd_bus_error_set(error
, SD_BUS_ERROR_INVALID_ARGS
, "Journal field contains no '=' character");
2602 if (!journal_field_valid(p
, eq
- (const char*) p
, false))
2603 return sd_bus_error_set(error
, SD_BUS_ERROR_INVALID_ARGS
, "Journal field invalid");
2605 copy
= memdup_suffix0(p
, sz
);
2609 if (!utf8_is_valid(copy
))
2610 return sd_bus_error_set(error
, SD_BUS_ERROR_INVALID_ARGS
, "Journal field is not valid UTF-8");
2612 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2613 if (!GREEDY_REALLOC(c
->log_extra_fields
, c
->n_log_extra_fields
+ 1))
2616 c
->log_extra_fields
[c
->n_log_extra_fields
++] = IOVEC_MAKE(copy
, sz
);
2617 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
|UNIT_ESCAPE_C
, name
, "LogExtraFields=%s", (char*) copy
);
2624 r
= sd_bus_message_exit_container(message
);
2628 if (!UNIT_WRITE_FLAGS_NOOP(flags
) && n
== 0) {
2629 exec_context_free_log_extra_fields(c
);
2630 unit_write_setting(u
, flags
, name
, "LogExtraFields=");
2638 if (streq(name
, "SystemCallErrorNumber"))
2639 return bus_set_transient_errno(u
, name
, &c
->syscall_errno
, message
, flags
, error
);
2641 if (streq(name
, "SystemCallFilter")) {
2643 _cleanup_strv_free_
char **l
= NULL
;
2645 r
= sd_bus_message_enter_container(message
, 'r', "bas");
2649 r
= sd_bus_message_read(message
, "b", &allow_list
);
2653 r
= sd_bus_message_read_strv(message
, &l
);
2657 r
= sd_bus_message_exit_container(message
);
2661 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2662 _cleanup_free_
char *joined
= NULL
;
2663 SeccompParseFlags invert_flag
= allow_list
? 0 : SECCOMP_PARSE_INVERT
;
2665 if (strv_isempty(l
)) {
2666 c
->syscall_allow_list
= false;
2667 c
->syscall_filter
= hashmap_free(c
->syscall_filter
);
2669 unit_write_settingf(u
, flags
, name
, "SystemCallFilter=");
2673 if (!c
->syscall_filter
) {
2674 c
->syscall_filter
= hashmap_new(NULL
);
2675 if (!c
->syscall_filter
)
2678 c
->syscall_allow_list
= allow_list
;
2680 if (c
->syscall_allow_list
) {
2681 r
= seccomp_parse_syscall_filter("@default",
2684 SECCOMP_PARSE_PERMISSIVE
|
2685 SECCOMP_PARSE_ALLOW_LIST
,
2693 STRV_FOREACH(s
, l
) {
2694 _cleanup_free_
char *n
= NULL
;
2697 r
= parse_syscall_and_errno(*s
, &n
, &e
);
2701 if (allow_list
&& e
>= 0)
2704 r
= seccomp_parse_syscall_filter(n
,
2707 SECCOMP_PARSE_LOG
| SECCOMP_PARSE_PERMISSIVE
|
2709 (c
->syscall_allow_list
? SECCOMP_PARSE_ALLOW_LIST
: 0),
2716 joined
= strv_join(l
, " ");
2720 unit_write_settingf(u
, flags
, name
, "SystemCallFilter=%s%s", allow_list
? "" : "~", joined
);
2725 } else if (streq(name
, "SystemCallLog")) {
2727 _cleanup_strv_free_
char **l
= NULL
;
2729 r
= sd_bus_message_enter_container(message
, 'r', "bas");
2733 r
= sd_bus_message_read(message
, "b", &allow_list
);
2737 r
= sd_bus_message_read_strv(message
, &l
);
2741 r
= sd_bus_message_exit_container(message
);
2745 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2746 _cleanup_free_
char *joined
= NULL
;
2747 SeccompParseFlags invert_flag
= allow_list
? 0 : SECCOMP_PARSE_INVERT
;
2749 if (strv_isempty(l
)) {
2750 c
->syscall_log_allow_list
= false;
2751 c
->syscall_log
= hashmap_free(c
->syscall_log
);
2753 unit_write_settingf(u
, flags
, name
, "SystemCallLog=");
2757 if (!c
->syscall_log
) {
2758 c
->syscall_log
= hashmap_new(NULL
);
2759 if (!c
->syscall_log
)
2762 c
->syscall_log_allow_list
= allow_list
;
2765 STRV_FOREACH(s
, l
) {
2766 r
= seccomp_parse_syscall_filter(*s
,
2767 -1, /* errno not used */
2769 SECCOMP_PARSE_LOG
| SECCOMP_PARSE_PERMISSIVE
|
2771 (c
->syscall_log_allow_list
? SECCOMP_PARSE_ALLOW_LIST
: 0),
2778 joined
= strv_join(l
, " ");
2782 unit_write_settingf(u
, flags
, name
, "SystemCallLog=%s%s", allow_list
? "" : "~", joined
);
2787 } else if (streq(name
, "SystemCallArchitectures")) {
2788 _cleanup_strv_free_
char **l
= NULL
;
2790 r
= sd_bus_message_read_strv(message
, &l
);
2794 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2795 _cleanup_free_
char *joined
= NULL
;
2797 if (strv_isempty(l
))
2798 c
->syscall_archs
= set_free(c
->syscall_archs
);
2800 r
= parse_syscall_archs(l
, &c
->syscall_archs
);
2805 joined
= strv_join(l
, " ");
2809 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, joined
);
2814 } else if (streq(name
, "RestrictAddressFamilies")) {
2815 _cleanup_strv_free_
char **l
= NULL
;
2818 r
= sd_bus_message_enter_container(message
, 'r', "bas");
2822 r
= sd_bus_message_read(message
, "b", &allow_list
);
2826 r
= sd_bus_message_read_strv(message
, &l
);
2830 r
= sd_bus_message_exit_container(message
);
2834 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2835 _cleanup_free_
char *joined
= NULL
;
2837 if (strv_isempty(l
)) {
2838 c
->address_families_allow_list
= allow_list
;
2839 c
->address_families
= set_free(c
->address_families
);
2841 unit_write_settingf(u
, flags
, name
, "RestrictAddressFamilies=%s",
2842 allow_list
? "none" : "");
2846 if (!c
->address_families
) {
2847 c
->address_families
= set_new(NULL
);
2848 if (!c
->address_families
)
2851 c
->address_families_allow_list
= allow_list
;
2854 STRV_FOREACH(s
, l
) {
2857 af
= af_from_name(*s
);
2861 if (allow_list
== c
->address_families_allow_list
) {
2862 r
= set_put(c
->address_families
, INT_TO_PTR(af
));
2866 set_remove(c
->address_families
, INT_TO_PTR(af
));
2869 joined
= strv_join(l
, " ");
2873 unit_write_settingf(u
, flags
, name
, "RestrictAddressFamilies=%s%s", allow_list
? "" : "~", joined
);
2879 if (STR_IN_SET(name
, "CPUAffinity", "NUMAMask")) {
2880 _cleanup_(cpu_set_done
) CPUSet set
= {};
2884 r
= sd_bus_message_read_array(message
, 'y', &a
, &n
);
2888 r
= cpu_set_from_dbus(a
, n
, &set
);
2892 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2893 CPUSet
*cpuset
= streq(name
, "CPUAffinity") ? &c
->cpu_set
: &c
->numa_policy
.nodes
;
2896 cpu_set_done(cpuset
);
2897 unit_write_settingf(u
, flags
, name
, "%s=", name
);
2899 _cleanup_free_
char *str
= NULL
;
2901 str
= cpu_set_to_string(&set
);
2905 /* We forego any optimizations here, and always create the structure using
2906 * cpu_set_add_set(), because we don't want to care if the existing size we
2907 * got over dbus is appropriate. */
2908 r
= cpu_set_add_set(cpuset
, &set
);
2912 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, str
);
2918 } else if (streq(name
, "CPUAffinityFromNUMA")) {
2921 r
= sd_bus_message_read_basic(message
, 'b', &q
);
2925 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2926 c
->cpu_affinity_from_numa
= q
;
2927 unit_write_settingf(u
, flags
, name
, "%s=%s", "CPUAffinity", "numa");
2932 } else if (streq(name
, "NUMAPolicy")) {
2935 r
= sd_bus_message_read(message
, "i", &type
);
2939 if (!mpol_is_valid(type
))
2940 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid NUMAPolicy value: %i", type
);
2942 if (!UNIT_WRITE_FLAGS_NOOP(flags
))
2943 c
->numa_policy
.type
= type
;
2947 } else if (streq(name
, "Nice")) {
2950 r
= sd_bus_message_read(message
, "i", &q
);
2954 if (!nice_is_valid(q
))
2955 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid Nice value: %i", q
);
2957 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2961 unit_write_settingf(u
, flags
, name
, "Nice=%i", q
);
2966 } else if (streq(name
, "CPUSchedulingPolicy")) {
2969 r
= sd_bus_message_read(message
, "i", &q
);
2973 if (!sched_policy_is_valid(q
))
2974 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid CPU scheduling policy: %i", q
);
2976 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
2977 _cleanup_free_
char *s
= NULL
;
2979 r
= sched_policy_to_string_alloc(q
, &s
);
2983 c
->cpu_sched_policy
= q
;
2984 c
->cpu_sched_priority
= CLAMP(c
->cpu_sched_priority
, sched_get_priority_min(q
), sched_get_priority_max(q
));
2985 c
->cpu_sched_set
= true;
2987 unit_write_settingf(u
, flags
, name
, "CPUSchedulingPolicy=%s", s
);
2992 } else if (streq(name
, "CPUSchedulingPriority")) {
2995 r
= sd_bus_message_read(message
, "i", &p
);
2999 /* On Linux RR/FIFO range from 1 to 99 and OTHER/BATCH may only be 0. Policy might be set
3000 * later so we do not check the precise range, but only the generic outer bounds. */
3001 if (p
< 0 || p
> 99)
3002 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid CPU scheduling priority: %i", p
);
3004 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3005 c
->cpu_sched_priority
= p
;
3006 c
->cpu_sched_set
= true;
3008 unit_write_settingf(u
, flags
, name
, "CPUSchedulingPriority=%i", p
);
3013 } else if (streq(name
, "IOSchedulingClass")) {
3016 r
= sd_bus_message_read(message
, "i", &q
);
3020 if (!ioprio_class_is_valid(q
))
3021 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid IO scheduling class: %i", q
);
3023 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3024 _cleanup_free_
char *s
= NULL
;
3026 r
= ioprio_class_to_string_alloc(q
, &s
);
3030 c
->ioprio
= ioprio_normalize(ioprio_prio_value(q
, ioprio_prio_data(c
->ioprio
)));
3031 c
->ioprio_set
= true;
3033 unit_write_settingf(u
, flags
, name
, "IOSchedulingClass=%s", s
);
3038 } else if (streq(name
, "IOSchedulingPriority")) {
3041 r
= sd_bus_message_read(message
, "i", &p
);
3045 if (!ioprio_priority_is_valid(p
))
3046 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid IO scheduling priority: %i", p
);
3048 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3049 c
->ioprio
= ioprio_normalize(ioprio_prio_value(ioprio_prio_class(c
->ioprio
), p
));
3050 c
->ioprio_set
= true;
3052 unit_write_settingf(u
, flags
, name
, "IOSchedulingPriority=%i", p
);
3057 } else if (streq(name
, "WorkingDirectory")) {
3058 _cleanup_free_
char *simplified
= NULL
;
3059 bool missing_ok
= false, is_home
= false;
3062 r
= sd_bus_message_read(message
, "s", &s
);
3075 if (!path_is_absolute(s
))
3076 return sd_bus_error_set(error
, SD_BUS_ERROR_INVALID_ARGS
,
3077 "WorkingDirectory= expects an absolute path or '~'");
3079 r
= path_simplify_alloc(s
, &simplified
);
3083 if (!path_is_normalized(simplified
))
3084 return sd_bus_error_set(error
, SD_BUS_ERROR_INVALID_ARGS
,
3085 "WorkingDirectory= expects a normalized path or '~'");
3089 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3090 free_and_replace(c
->working_directory
, simplified
);
3091 c
->working_directory_home
= is_home
;
3092 c
->working_directory_missing_ok
= missing_ok
;
3094 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
,
3095 "WorkingDirectory=%s%s",
3096 c
->working_directory_missing_ok
? "-" : "",
3097 c
->working_directory_home
? "~" : strempty(c
->working_directory
));
3102 } else if (STR_IN_SET(name
,
3103 "StandardInputFileDescriptorName", "StandardOutputFileDescriptorName", "StandardErrorFileDescriptorName")) {
3106 r
= sd_bus_message_read(message
, "s", &s
);
3110 if (!isempty(s
) && !fdname_is_valid(s
))
3111 return sd_bus_error_set(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid file descriptor name");
3113 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3115 if (streq(name
, "StandardInputFileDescriptorName")) {
3116 r
= free_and_strdup(c
->stdio_fdname
+ STDIN_FILENO
, empty_to_null(s
));
3120 c
->std_input
= EXEC_INPUT_NAMED_FD
;
3121 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardInput=fd:%s", exec_context_fdname(c
, STDIN_FILENO
));
3123 } else if (streq(name
, "StandardOutputFileDescriptorName")) {
3124 r
= free_and_strdup(c
->stdio_fdname
+ STDOUT_FILENO
, empty_to_null(s
));
3128 c
->std_output
= EXEC_OUTPUT_NAMED_FD
;
3129 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardOutput=fd:%s", exec_context_fdname(c
, STDOUT_FILENO
));
3132 assert(streq(name
, "StandardErrorFileDescriptorName"));
3134 r
= free_and_strdup(&c
->stdio_fdname
[STDERR_FILENO
], empty_to_null(s
));
3138 c
->std_error
= EXEC_OUTPUT_NAMED_FD
;
3139 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardError=fd:%s", exec_context_fdname(c
, STDERR_FILENO
));
3145 } else if (STR_IN_SET(name
,
3146 "StandardInputFile",
3147 "StandardOutputFile", "StandardOutputFileToAppend", "StandardOutputFileToTruncate",
3148 "StandardErrorFile", "StandardErrorFileToAppend", "StandardErrorFileToTruncate")) {
3151 r
= sd_bus_message_read(message
, "s", &s
);
3156 if (!path_is_absolute(s
))
3157 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Path %s is not absolute", s
);
3158 if (!path_is_normalized(s
))
3159 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Path %s is not normalized", s
);
3162 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3164 if (streq(name
, "StandardInputFile")) {
3165 r
= free_and_strdup(&c
->stdio_file
[STDIN_FILENO
], empty_to_null(s
));
3169 c
->std_input
= EXEC_INPUT_FILE
;
3170 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardInput=file:%s", s
);
3172 } else if (STR_IN_SET(name
, "StandardOutputFile", "StandardOutputFileToAppend", "StandardOutputFileToTruncate")) {
3173 r
= free_and_strdup(&c
->stdio_file
[STDOUT_FILENO
], empty_to_null(s
));
3177 if (streq(name
, "StandardOutputFile")) {
3178 c
->std_output
= EXEC_OUTPUT_FILE
;
3179 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardOutput=file:%s", s
);
3180 } else if (streq(name
, "StandardOutputFileToAppend")) {
3181 c
->std_output
= EXEC_OUTPUT_FILE_APPEND
;
3182 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardOutput=append:%s", s
);
3184 assert(streq(name
, "StandardOutputFileToTruncate"));
3185 c
->std_output
= EXEC_OUTPUT_FILE_TRUNCATE
;
3186 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardOutput=truncate:%s", s
);
3189 assert(STR_IN_SET(name
, "StandardErrorFile", "StandardErrorFileToAppend", "StandardErrorFileToTruncate"));
3191 r
= free_and_strdup(&c
->stdio_file
[STDERR_FILENO
], empty_to_null(s
));
3195 if (streq(name
, "StandardErrorFile")) {
3196 c
->std_error
= EXEC_OUTPUT_FILE
;
3197 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardError=file:%s", s
);
3198 } else if (streq(name
, "StandardErrorFileToAppend")) {
3199 c
->std_error
= EXEC_OUTPUT_FILE_APPEND
;
3200 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardError=append:%s", s
);
3202 assert(streq(name
, "StandardErrorFileToTruncate"));
3203 c
->std_error
= EXEC_OUTPUT_FILE_TRUNCATE
;
3204 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "StandardError=truncate:%s", s
);
3211 } else if (streq(name
, "StandardInputData")) {
3215 r
= sd_bus_message_read_array(message
, 'y', &p
, &sz
);
3219 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3220 _cleanup_free_
char *encoded
= NULL
;
3223 c
->stdin_data
= mfree(c
->stdin_data
);
3224 c
->stdin_data_size
= 0;
3226 unit_write_settingf(u
, flags
, name
, "StandardInputData=");
3231 if (c
->stdin_data_size
+ sz
< c
->stdin_data_size
|| /* check for overflow */
3232 c
->stdin_data_size
+ sz
> EXEC_STDIN_DATA_MAX
)
3235 n
= base64mem(p
, sz
, &encoded
);
3239 q
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
);
3243 memcpy((uint8_t*) q
+ c
->stdin_data_size
, p
, sz
);
3246 c
->stdin_data_size
+= sz
;
3248 unit_write_settingf(u
, flags
, name
, "StandardInputData=%s", encoded
);
3254 } else if (streq(name
, "Environment")) {
3256 _cleanup_strv_free_
char **l
= NULL
;
3258 r
= sd_bus_message_read_strv(message
, &l
);
3262 if (!strv_env_is_valid(l
))
3263 return sd_bus_error_set(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid environment block.");
3265 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3266 if (strv_isempty(l
)) {
3267 c
->environment
= strv_free(c
->environment
);
3268 unit_write_setting(u
, flags
, name
, "Environment=");
3270 _cleanup_free_
char *joined
= NULL
;
3273 joined
= unit_concat_strv(l
, UNIT_ESCAPE_SPECIFIERS
|UNIT_ESCAPE_C
);
3277 e
= strv_env_merge(c
->environment
, l
);
3281 strv_free_and_replace(c
->environment
, e
);
3282 unit_write_settingf(u
, flags
, name
, "Environment=%s", joined
);
3288 } else if (streq(name
, "UnsetEnvironment")) {
3290 _cleanup_strv_free_
char **l
= NULL
;
3292 r
= sd_bus_message_read_strv(message
, &l
);
3296 if (!strv_env_name_or_assignment_is_valid(l
))
3297 return sd_bus_error_set(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid UnsetEnvironment= list.");
3299 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3300 if (strv_isempty(l
)) {
3301 c
->unset_environment
= strv_free(c
->unset_environment
);
3302 unit_write_setting(u
, flags
, name
, "UnsetEnvironment=");
3304 _cleanup_free_
char *joined
= NULL
;
3307 joined
= unit_concat_strv(l
, UNIT_ESCAPE_SPECIFIERS
|UNIT_ESCAPE_C
);
3311 e
= strv_env_merge(c
->unset_environment
, l
);
3315 strv_free_and_replace(c
->unset_environment
, e
);
3316 unit_write_settingf(u
, flags
, name
, "UnsetEnvironment=%s", joined
);
3322 } else if (streq(name
, "OOMScoreAdjust")) {
3325 r
= sd_bus_message_read(message
, "i", &oa
);
3329 if (!oom_score_adjust_is_valid(oa
))
3330 return sd_bus_error_set(error
, SD_BUS_ERROR_INVALID_ARGS
, "OOM score adjust value out of range");
3332 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3333 c
->oom_score_adjust
= oa
;
3334 c
->oom_score_adjust_set
= true;
3335 unit_write_settingf(u
, flags
, name
, "OOMScoreAdjust=%i", oa
);
3340 } else if (streq(name
, "CoredumpFilter")) {
3343 r
= sd_bus_message_read(message
, "t", &f
);
3347 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3348 c
->coredump_filter
= f
;
3349 c
->coredump_filter_set
= true;
3350 unit_write_settingf(u
, flags
, name
, "CoredumpFilter=0x%"PRIx64
, f
);
3355 } else if (streq(name
, "EnvironmentFiles")) {
3356 _cleanup_(memstream_done
) MemStream m
= {};
3357 _cleanup_free_
char *joined
= NULL
;
3358 _cleanup_strv_free_
char **l
= NULL
;
3361 r
= sd_bus_message_enter_container(message
, 'a', "(sb)");
3365 f
= memstream_init(&m
);
3369 fputs("EnvironmentFile=\n", f
);
3371 STRV_FOREACH(i
, c
->environment_files
) {
3372 _cleanup_free_
char *q
= NULL
;
3374 q
= specifier_escape(*i
);
3378 fprintf(f
, "EnvironmentFile=%s\n", q
);
3381 while ((r
= sd_bus_message_enter_container(message
, 'r', "sb")) > 0) {
3385 r
= sd_bus_message_read(message
, "sb", &path
, &b
);
3389 r
= sd_bus_message_exit_container(message
);
3393 if (!path_is_absolute(path
))
3394 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Path %s is not absolute.", path
);
3396 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3397 _cleanup_free_
char *q
= NULL
, *buf
= NULL
;
3399 buf
= strjoin(b
? "-" : "", path
);
3403 q
= specifier_escape(buf
);
3407 fprintf(f
, "EnvironmentFile=%s\n", q
);
3409 r
= strv_consume(&l
, TAKE_PTR(buf
));
3417 r
= sd_bus_message_exit_container(message
);
3421 r
= memstream_finalize(&m
, &joined
, NULL
);
3425 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3426 if (strv_isempty(l
)) {
3427 c
->environment_files
= strv_free(c
->environment_files
);
3428 unit_write_setting(u
, flags
, name
, "EnvironmentFile=");
3430 r
= strv_extend_strv(&c
->environment_files
, l
, true);
3434 unit_write_setting(u
, flags
, name
, joined
);
3440 } else if (streq(name
, "PassEnvironment")) {
3442 _cleanup_strv_free_
char **l
= NULL
;
3444 r
= sd_bus_message_read_strv(message
, &l
);
3448 if (!strv_env_name_is_valid(l
))
3449 return sd_bus_error_set(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid PassEnvironment= block.");
3451 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3452 if (strv_isempty(l
)) {
3453 c
->pass_environment
= strv_free(c
->pass_environment
);
3454 unit_write_setting(u
, flags
, name
, "PassEnvironment=");
3456 _cleanup_free_
char *joined
= NULL
;
3458 r
= strv_extend_strv(&c
->pass_environment
, l
, true);
3462 /* We write just the new settings out to file, with unresolved specifiers. */
3463 joined
= unit_concat_strv(l
, UNIT_ESCAPE_SPECIFIERS
);
3467 unit_write_settingf(u
, flags
, name
, "PassEnvironment=%s", joined
);
3473 } else if (STR_IN_SET(name
, "ReadWriteDirectories", "ReadOnlyDirectories", "InaccessibleDirectories",
3474 "ReadWritePaths", "ReadOnlyPaths", "InaccessiblePaths", "ExecPaths", "NoExecPaths",
3475 "ExtensionDirectories")) {
3476 _cleanup_strv_free_
char **l
= NULL
;
3479 r
= sd_bus_message_read_strv(message
, &l
);
3483 STRV_FOREACH(p
, l
) {
3487 offset
= i
[0] == '-';
3488 offset
+= i
[offset
] == '+';
3489 if (!path_is_absolute(i
+ offset
))
3490 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid %s", name
);
3492 path_simplify(i
+ offset
);
3495 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3496 if (STR_IN_SET(name
, "ReadWriteDirectories", "ReadWritePaths"))
3497 dirs
= &c
->read_write_paths
;
3498 else if (STR_IN_SET(name
, "ReadOnlyDirectories", "ReadOnlyPaths"))
3499 dirs
= &c
->read_only_paths
;
3500 else if (streq(name
, "ExecPaths"))
3501 dirs
= &c
->exec_paths
;
3502 else if (streq(name
, "NoExecPaths"))
3503 dirs
= &c
->no_exec_paths
;
3504 else if (streq(name
, "ExtensionDirectories"))
3505 dirs
= &c
->extension_directories
;
3506 else /* "InaccessiblePaths" */
3507 dirs
= &c
->inaccessible_paths
;
3509 if (strv_isempty(l
)) {
3510 *dirs
= strv_free(*dirs
);
3511 unit_write_settingf(u
, flags
, name
, "%s=", name
);
3513 _cleanup_free_
char *joined
= NULL
;
3515 joined
= unit_concat_strv(l
, UNIT_ESCAPE_SPECIFIERS
);
3519 r
= strv_extend_strv(dirs
, l
, true);
3523 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, joined
);
3529 } else if (streq(name
, "ExecSearchPath")) {
3530 _cleanup_strv_free_
char **l
= NULL
;
3532 r
= sd_bus_message_read_strv(message
, &l
);
3537 if (!path_is_absolute(*p
) || !path_is_normalized(*p
) || strchr(*p
, ':'))
3538 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid %s", name
);
3540 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3541 if (strv_isempty(l
)) {
3542 c
->exec_search_path
= strv_free(c
->exec_search_path
);
3543 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "ExecSearchPath=");
3545 _cleanup_free_
char *joined
= NULL
;
3546 r
= strv_extend_strv(&c
->exec_search_path
, l
, true);
3549 joined
= strv_join(c
->exec_search_path
, ":");
3552 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "ExecSearchPath=%s", joined
);
3558 } else if (STR_IN_SET(name
, "RuntimeDirectory", "StateDirectory", "CacheDirectory", "LogsDirectory", "ConfigurationDirectory")) {
3559 _cleanup_strv_free_
char **l
= NULL
;
3561 r
= sd_bus_message_read_strv(message
, &l
);
3565 STRV_FOREACH(p
, l
) {
3566 if (!path_is_normalized(*p
))
3567 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "%s= path is not normalized: %s", name
, *p
);
3569 if (path_is_absolute(*p
))
3570 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "%s= path is absolute: %s", name
, *p
);
3572 if (path_startswith(*p
, "private"))
3573 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "%s= path can't be 'private': %s", name
, *p
);
3576 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3577 ExecDirectoryType i
;
3580 assert_se((i
= exec_directory_type_from_string(name
)) >= 0);
3581 d
= c
->directories
+ i
;
3583 if (strv_isempty(l
)) {
3584 exec_directory_done(d
);
3585 unit_write_settingf(u
, flags
, name
, "%s=", name
);
3587 _cleanup_free_
char *joined
= NULL
;
3589 STRV_FOREACH(source
, l
) {
3590 r
= exec_directory_add(d
, *source
, /* symlink= */ NULL
, /* flags= */ 0);
3594 exec_directory_sort(d
);
3596 joined
= unit_concat_strv(l
, UNIT_ESCAPE_SPECIFIERS
);
3600 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, joined
);
3606 } else if (STR_IN_SET(name
, "AppArmorProfile", "SmackProcessLabel")) {
3610 r
= sd_bus_message_read(message
, "(bs)", &ignore
, &s
);
3614 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3618 if (streq(name
, "AppArmorProfile")) {
3619 p
= &c
->apparmor_profile
;
3620 b
= &c
->apparmor_profile_ignore
;
3621 } else { /* "SmackProcessLabel" */
3622 p
= &c
->smack_process_label
;
3623 b
= &c
->smack_process_label_ignore
;
3630 if (free_and_strdup(p
, s
) < 0)
3635 unit_write_settingf(u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "%s=%s%s", name
, ignore
? "-" : "", strempty(s
));
3640 } else if (STR_IN_SET(name
, "BindPaths", "BindReadOnlyPaths")) {
3641 char *source
, *destination
;
3643 uint64_t mount_flags
;
3646 r
= sd_bus_message_enter_container(message
, 'a', "(ssbt)");
3650 while ((r
= sd_bus_message_read(message
, "(ssbt)", &source
, &destination
, &ignore_enoent
, &mount_flags
)) > 0) {
3652 if (!path_is_absolute(source
))
3653 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Source path %s is not absolute.", source
);
3654 if (!path_is_absolute(destination
))
3655 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Destination path %s is not absolute.", destination
);
3656 if (!IN_SET(mount_flags
, 0, MS_REC
))
3657 return sd_bus_error_set(error
, SD_BUS_ERROR_INVALID_ARGS
, "Unknown mount flags.");
3659 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3660 r
= bind_mount_add(&c
->bind_mounts
, &c
->n_bind_mounts
,
3663 .destination
= destination
,
3664 .read_only
= !!strstr(name
, "ReadOnly"),
3665 .recursive
= !!(mount_flags
& MS_REC
),
3666 .ignore_enoent
= ignore_enoent
,
3671 unit_write_settingf(
3672 u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
,
3675 ignore_enoent
? "-" : "",
3678 (mount_flags
& MS_REC
) ? "rbind" : "norbind");
3686 r
= sd_bus_message_exit_container(message
);
3691 bind_mount_free_many(c
->bind_mounts
, c
->n_bind_mounts
);
3692 c
->bind_mounts
= NULL
;
3693 c
->n_bind_mounts
= 0;
3695 unit_write_settingf(u
, flags
, name
, "%s=", name
);
3700 } else if (streq(name
, "TemporaryFileSystem")) {
3701 const char *path
, *options
;
3704 r
= sd_bus_message_enter_container(message
, 'a', "(ss)");
3708 while ((r
= sd_bus_message_read(message
, "(ss)", &path
, &options
)) > 0) {
3710 if (!path_is_absolute(path
))
3711 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Mount point %s is not absolute.", path
);
3713 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3714 r
= temporary_filesystem_add(&c
->temporary_filesystems
, &c
->n_temporary_filesystems
, path
, options
);
3718 unit_write_settingf(
3719 u
, flags
|UNIT_ESCAPE_SPECIFIERS
, name
,
3731 r
= sd_bus_message_exit_container(message
);
3736 temporary_filesystem_free_many(c
->temporary_filesystems
, c
->n_temporary_filesystems
);
3737 c
->temporary_filesystems
= NULL
;
3738 c
->n_temporary_filesystems
= 0;
3740 unit_write_settingf(u
, flags
, name
, "%s=", name
);
3745 } else if ((suffix
= startswith(name
, "Limit"))) {
3746 const char *soft
= NULL
;
3749 ri
= rlimit_from_string(suffix
);
3751 soft
= endswith(suffix
, "Soft");
3755 n
= strndupa_safe(suffix
, soft
- suffix
);
3756 ri
= rlimit_from_string(n
);
3758 name
= strjoina("Limit", n
);
3766 r
= sd_bus_message_read(message
, "t", &rl
);
3770 if (rl
== UINT64_MAX
)
3775 if ((uint64_t) x
!= rl
)
3779 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3780 _cleanup_free_
char *f
= NULL
;
3783 if (c
->rlimit
[ri
]) {
3784 nl
= *c
->rlimit
[ri
];
3791 /* When the resource limit is not initialized yet, then assign the value to both fields */
3792 nl
= (struct rlimit
) {
3797 r
= rlimit_format(&nl
, &f
);
3802 *c
->rlimit
[ri
] = nl
;
3804 c
->rlimit
[ri
] = newdup(struct rlimit
, &nl
, 1);
3809 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, f
);
3815 } else if (streq(name
, "MountImages")) {
3816 _cleanup_free_
char *format_str
= NULL
;
3817 MountImage
*mount_images
= NULL
;
3818 size_t n_mount_images
= 0;
3819 char *source
, *destination
;
3822 r
= sd_bus_message_enter_container(message
, 'a', "(ssba(ss))");
3827 _cleanup_(mount_options_free_allp
) MountOptions
*options
= NULL
;
3828 _cleanup_free_
char *source_escaped
= NULL
, *destination_escaped
= NULL
;
3831 r
= sd_bus_message_enter_container(message
, 'r', "ssba(ss)");
3835 r
= sd_bus_message_read(message
, "ssb", &source
, &destination
, &permissive
);
3839 if (!path_is_absolute(source
))
3840 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Source path %s is not absolute.", source
);
3841 if (!path_is_normalized(source
))
3842 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Source path %s is not normalized.", source
);
3843 if (!path_is_absolute(destination
))
3844 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Destination path %s is not absolute.", destination
);
3845 if (!path_is_normalized(destination
))
3846 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Destination path %s is not normalized.", destination
);
3848 /* Need to store them in the unit with the escapes, so that they can be parsed again */
3849 source_escaped
= shell_escape(source
, ":");
3850 if (!source_escaped
)
3852 destination_escaped
= shell_escape(destination
, ":");
3853 if (!destination_escaped
)
3856 tuple
= strjoin(format_str
,
3857 format_str
? " " : "",
3858 permissive
? "-" : "",
3861 destination_escaped
);
3864 free_and_replace(format_str
, tuple
);
3866 r
= bus_read_mount_options(message
, error
, &options
, &format_str
, ":");
3870 r
= sd_bus_message_exit_container(message
);
3874 r
= mount_image_add(&mount_images
, &n_mount_images
,
3877 .destination
= destination
,
3878 .mount_options
= options
,
3879 .ignore_enoent
= permissive
,
3880 .type
= MOUNT_IMAGE_DISCRETE
,
3888 r
= sd_bus_message_exit_container(message
);
3892 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3893 if (n_mount_images
== 0) {
3894 c
->mount_images
= mount_image_free_many(c
->mount_images
, &c
->n_mount_images
);
3896 unit_write_settingf(u
, flags
, name
, "%s=", name
);
3898 for (size_t i
= 0; i
< n_mount_images
; ++i
) {
3899 r
= mount_image_add(&c
->mount_images
, &c
->n_mount_images
, &mount_images
[i
]);
3904 unit_write_settingf(u
, flags
|UNIT_ESCAPE_C
|UNIT_ESCAPE_SPECIFIERS
,
3912 mount_images
= mount_image_free_many(mount_images
, &n_mount_images
);
3915 } else if (streq(name
, "ExtensionImages")) {
3916 _cleanup_free_
char *format_str
= NULL
;
3917 MountImage
*extension_images
= NULL
;
3918 size_t n_extension_images
= 0;
3920 r
= sd_bus_message_enter_container(message
, 'a', "(sba(ss))");
3925 _cleanup_(mount_options_free_allp
) MountOptions
*options
= NULL
;
3926 _cleanup_free_
char *source_escaped
= NULL
;
3927 char *source
, *tuple
;
3930 r
= sd_bus_message_enter_container(message
, 'r', "sba(ss)");
3934 r
= sd_bus_message_read(message
, "sb", &source
, &permissive
);
3938 if (!path_is_absolute(source
))
3939 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Source path %s is not absolute.", source
);
3940 if (!path_is_normalized(source
))
3941 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Source path %s is not normalized.", source
);
3943 /* Need to store them in the unit with the escapes, so that they can be parsed again */
3944 source_escaped
= shell_escape(source
, ":");
3945 if (!source_escaped
)
3948 tuple
= strjoin(format_str
,
3949 format_str
? " " : "",
3950 permissive
? "-" : "",
3954 free_and_replace(format_str
, tuple
);
3956 r
= bus_read_mount_options(message
, error
, &options
, &format_str
, ":");
3960 r
= sd_bus_message_exit_container(message
);
3964 r
= mount_image_add(&extension_images
, &n_extension_images
,
3967 .mount_options
= options
,
3968 .ignore_enoent
= permissive
,
3969 .type
= MOUNT_IMAGE_EXTENSION
,
3977 r
= sd_bus_message_exit_container(message
);
3981 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
3982 if (n_extension_images
== 0) {
3983 c
->extension_images
= mount_image_free_many(c
->extension_images
, &c
->n_extension_images
);
3985 unit_write_settingf(u
, flags
, name
, "%s=", name
);
3987 for (size_t i
= 0; i
< n_extension_images
; ++i
) {
3988 r
= mount_image_add(&c
->extension_images
, &c
->n_extension_images
, &extension_images
[i
]);
3993 unit_write_settingf(u
, flags
|UNIT_ESCAPE_C
|UNIT_ESCAPE_SPECIFIERS
,
4001 extension_images
= mount_image_free_many(extension_images
, &n_extension_images
);
4005 } else if (STR_IN_SET(name
, "StateDirectorySymlink", "RuntimeDirectorySymlink", "CacheDirectorySymlink", "LogsDirectorySymlink")) {
4006 char *source
, *destination
;
4007 ExecDirectory
*directory
;
4008 uint64_t symlink_flags
;
4009 ExecDirectoryType i
;
4011 assert_se((i
= exec_directory_type_symlink_from_string(name
)) >= 0);
4012 directory
= c
->directories
+ i
;
4014 r
= sd_bus_message_enter_container(message
, 'a', "(sst)");
4018 while ((r
= sd_bus_message_read(message
, "(sst)", &source
, &destination
, &symlink_flags
)) > 0) {
4019 if ((symlink_flags
& ~_EXEC_DIRECTORY_FLAGS_PUBLIC
) != 0)
4020 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid 'flags' parameter '%" PRIu64
"'", symlink_flags
);
4021 if (!path_is_valid(source
))
4022 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Source path %s is not valid.", source
);
4023 if (path_is_absolute(source
))
4024 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Source path %s is absolute.", source
);
4025 if (!path_is_normalized(source
))
4026 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Source path %s is not normalized.", source
);
4027 if (isempty(destination
))
4030 if (!path_is_valid(destination
))
4031 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Destination path %s is not valid.", destination
);
4032 if (path_is_absolute(destination
))
4033 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Destination path %s is absolute.", destination
);
4034 if (!path_is_normalized(destination
))
4035 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Destination path %s is not normalized.", destination
);
4038 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
4039 _cleanup_free_
char *destination_escaped
= NULL
, *source_escaped
= NULL
;
4041 r
= exec_directory_add(directory
, source
, destination
, symlink_flags
);
4045 /* Need to store them in the unit with the escapes, so that they can be parsed again */
4046 source_escaped
= xescape(source
, ":");
4047 if (!source_escaped
)
4050 destination_escaped
= xescape(destination
, ":");
4051 if (!destination_escaped
)
4055 unit_write_settingf(
4056 u
, flags
|UNIT_ESCAPE_SPECIFIERS
, exec_directory_type_to_string(i
),
4058 exec_directory_type_to_string(i
),
4060 destination_escaped
|| FLAGS_SET(symlink_flags
, EXEC_DIRECTORY_READ_ONLY
) ? ":" : "",
4061 destination_escaped
,
4062 FLAGS_SET(symlink_flags
, EXEC_DIRECTORY_READ_ONLY
) ? ":ro" : "");
4068 exec_directory_sort(directory
);
4070 r
= sd_bus_message_exit_container(message
);
4076 } else if (STR_IN_SET(name
, "RootImagePolicy", "MountImagePolicy", "ExtensionImagePolicy")) {
4077 _cleanup_(image_policy_freep
) ImagePolicy
*p
= NULL
;
4080 r
= sd_bus_message_read(message
, "s", &s
);
4084 r
= image_policy_from_string(s
, &p
);
4086 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Failed to parse image policy string: %s", s
);
4088 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
4089 _cleanup_free_
char *t
= NULL
;
4091 streq(name
, "RootImagePolicy") ? &c
->root_image_policy
:
4092 streq(name
, "MountImagePolicy") ? &c
->mount_image_policy
:
4093 &c
->extension_image_policy
;
4095 r
= image_policy_to_string(p
, /* simplify= */ true, &t
);
4099 image_policy_free(*pp
);
4102 unit_write_settingf(
4106 t
); /* no escaping necessary */