2 This file is part of systemd.
4 Copyright 2010 Lennart Poettering
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 #include <sys/prctl.h>
27 #include "alloc-util.h"
29 #include "capability-util.h"
31 #include "dbus-execute.h"
33 #include "errno-list.h"
39 #include "mount-util.h"
40 #include "namespace.h"
41 #include "parse-util.h"
42 #include "path-util.h"
43 #include "process-util.h"
44 #include "rlimit-util.h"
46 #include "seccomp-util.h"
48 #include "securebits-util.h"
50 #include "syslog-util.h"
51 #include "unit-printf.h"
52 #include "user-util.h"
55 BUS_DEFINE_PROPERTY_GET_ENUM(bus_property_get_exec_output
, exec_output
, ExecOutput
);
56 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_input
, exec_input
, ExecInput
);
58 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_utmp_mode
, exec_utmp_mode
, ExecUtmpMode
);
59 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_preserve_mode
, exec_preserve_mode
, ExecPreserveMode
);
60 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_keyring_mode
, exec_keyring_mode
, ExecKeyringMode
);
62 static BUS_DEFINE_PROPERTY_GET_ENUM(bus_property_get_protect_home
, protect_home
, ProtectHome
);
63 static BUS_DEFINE_PROPERTY_GET_ENUM(bus_property_get_protect_system
, protect_system
, ProtectSystem
);
65 static int property_get_environment_files(
68 const char *interface
,
70 sd_bus_message
*reply
,
72 sd_bus_error
*error
) {
74 ExecContext
*c
= userdata
;
82 r
= sd_bus_message_open_container(reply
, 'a', "(sb)");
86 STRV_FOREACH(j
, c
->environment_files
) {
89 r
= sd_bus_message_append(reply
, "(sb)", fn
[0] == '-' ? fn
+ 1 : fn
, fn
[0] == '-');
94 return sd_bus_message_close_container(reply
);
97 static int property_get_oom_score_adjust(
100 const char *interface
,
101 const char *property
,
102 sd_bus_message
*reply
,
104 sd_bus_error
*error
) {
107 ExecContext
*c
= userdata
;
114 if (c
->oom_score_adjust_set
)
115 n
= c
->oom_score_adjust
;
117 _cleanup_free_
char *t
= NULL
;
120 if (read_one_line_file("/proc/self/oom_score_adj", &t
) >= 0)
124 return sd_bus_message_append(reply
, "i", n
);
127 static int property_get_nice(
130 const char *interface
,
131 const char *property
,
132 sd_bus_message
*reply
,
134 sd_bus_error
*error
) {
137 ExecContext
*c
= userdata
;
148 n
= getpriority(PRIO_PROCESS
, 0);
153 return sd_bus_message_append(reply
, "i", n
);
156 static int property_get_ioprio(
159 const char *interface
,
160 const char *property
,
161 sd_bus_message
*reply
,
163 sd_bus_error
*error
) {
166 ExecContext
*c
= userdata
;
172 return sd_bus_message_append(reply
, "i", exec_context_get_effective_ioprio(c
));
175 static int property_get_ioprio_class(
178 const char *interface
,
179 const char *property
,
180 sd_bus_message
*reply
,
182 sd_bus_error
*error
) {
185 ExecContext
*c
= userdata
;
191 return sd_bus_message_append(reply
, "i", IOPRIO_PRIO_CLASS(exec_context_get_effective_ioprio(c
)));
194 static int property_get_ioprio_priority(
197 const char *interface
,
198 const char *property
,
199 sd_bus_message
*reply
,
201 sd_bus_error
*error
) {
204 ExecContext
*c
= userdata
;
210 return sd_bus_message_append(reply
, "i", IOPRIO_PRIO_DATA(exec_context_get_effective_ioprio(c
)));
213 static int property_get_cpu_sched_policy(
216 const char *interface
,
217 const char *property
,
218 sd_bus_message
*reply
,
220 sd_bus_error
*error
) {
222 ExecContext
*c
= userdata
;
229 if (c
->cpu_sched_set
)
230 n
= c
->cpu_sched_policy
;
232 n
= sched_getscheduler(0);
237 return sd_bus_message_append(reply
, "i", n
);
240 static int property_get_cpu_sched_priority(
243 const char *interface
,
244 const char *property
,
245 sd_bus_message
*reply
,
247 sd_bus_error
*error
) {
249 ExecContext
*c
= userdata
;
256 if (c
->cpu_sched_set
)
257 n
= c
->cpu_sched_priority
;
259 struct sched_param p
= {};
261 if (sched_getparam(0, &p
) >= 0)
262 n
= p
.sched_priority
;
267 return sd_bus_message_append(reply
, "i", n
);
270 static int property_get_cpu_affinity(
273 const char *interface
,
274 const char *property
,
275 sd_bus_message
*reply
,
277 sd_bus_error
*error
) {
279 ExecContext
*c
= userdata
;
286 return sd_bus_message_append_array(reply
, 'y', c
->cpuset
, CPU_ALLOC_SIZE(c
->cpuset_ncpus
));
288 return sd_bus_message_append_array(reply
, 'y', NULL
, 0);
291 static int property_get_timer_slack_nsec(
294 const char *interface
,
295 const char *property
,
296 sd_bus_message
*reply
,
298 sd_bus_error
*error
) {
300 ExecContext
*c
= userdata
;
307 if (c
->timer_slack_nsec
!= NSEC_INFINITY
)
308 u
= (uint64_t) c
->timer_slack_nsec
;
310 u
= (uint64_t) prctl(PR_GET_TIMERSLACK
);
312 return sd_bus_message_append(reply
, "t", u
);
315 static int property_get_capability_bounding_set(
318 const char *interface
,
319 const char *property
,
320 sd_bus_message
*reply
,
322 sd_bus_error
*error
) {
324 ExecContext
*c
= userdata
;
330 return sd_bus_message_append(reply
, "t", c
->capability_bounding_set
);
333 static int property_get_ambient_capabilities(
336 const char *interface
,
337 const char *property
,
338 sd_bus_message
*reply
,
340 sd_bus_error
*error
) {
342 ExecContext
*c
= userdata
;
348 return sd_bus_message_append(reply
, "t", c
->capability_ambient_set
);
351 static int property_get_empty_string(
354 const char *interface
,
355 const char *property
,
356 sd_bus_message
*reply
,
358 sd_bus_error
*error
) {
363 return sd_bus_message_append(reply
, "s", "");
366 static int property_get_syscall_filter(
369 const char *interface
,
370 const char *property
,
371 sd_bus_message
*reply
,
373 sd_bus_error
*error
) {
375 ExecContext
*c
= userdata
;
376 _cleanup_strv_free_
char **l
= NULL
;
388 r
= sd_bus_message_open_container(reply
, 'r', "bas");
392 r
= sd_bus_message_append(reply
, "b", c
->syscall_whitelist
);
397 SET_FOREACH(id
, c
->syscall_filter
, i
) {
400 name
= seccomp_syscall_resolve_num_arch(SCMP_ARCH_NATIVE
, PTR_TO_INT(id
) - 1);
404 r
= strv_consume(&l
, name
);
412 r
= sd_bus_message_append_strv(reply
, l
);
416 return sd_bus_message_close_container(reply
);
419 static int property_get_syscall_archs(
422 const char *interface
,
423 const char *property
,
424 sd_bus_message
*reply
,
426 sd_bus_error
*error
) {
428 ExecContext
*c
= userdata
;
429 _cleanup_strv_free_
char **l
= NULL
;
442 SET_FOREACH(id
, c
->syscall_archs
, i
) {
445 name
= seccomp_arch_to_string(PTR_TO_UINT32(id
) - 1);
449 r
= strv_extend(&l
, name
);
457 r
= sd_bus_message_append_strv(reply
, l
);
464 static int property_get_syscall_errno(
467 const char *interface
,
468 const char *property
,
469 sd_bus_message
*reply
,
471 sd_bus_error
*error
) {
473 ExecContext
*c
= userdata
;
479 return sd_bus_message_append(reply
, "i", (int32_t) c
->syscall_errno
);
482 static int property_get_selinux_context(
485 const char *interface
,
486 const char *property
,
487 sd_bus_message
*reply
,
489 sd_bus_error
*error
) {
491 ExecContext
*c
= userdata
;
497 return sd_bus_message_append(reply
, "(bs)", c
->selinux_context_ignore
, c
->selinux_context
);
500 static int property_get_apparmor_profile(
503 const char *interface
,
504 const char *property
,
505 sd_bus_message
*reply
,
507 sd_bus_error
*error
) {
509 ExecContext
*c
= userdata
;
515 return sd_bus_message_append(reply
, "(bs)", c
->apparmor_profile_ignore
, c
->apparmor_profile
);
518 static int property_get_smack_process_label(
521 const char *interface
,
522 const char *property
,
523 sd_bus_message
*reply
,
525 sd_bus_error
*error
) {
527 ExecContext
*c
= userdata
;
533 return sd_bus_message_append(reply
, "(bs)", c
->smack_process_label_ignore
, c
->smack_process_label
);
536 static int property_get_personality(
539 const char *interface
,
540 const char *property
,
541 sd_bus_message
*reply
,
543 sd_bus_error
*error
) {
545 ExecContext
*c
= userdata
;
551 return sd_bus_message_append(reply
, "s", personality_to_string(c
->personality
));
554 static int property_get_address_families(
557 const char *interface
,
558 const char *property
,
559 sd_bus_message
*reply
,
561 sd_bus_error
*error
) {
563 ExecContext
*c
= userdata
;
564 _cleanup_strv_free_
char **l
= NULL
;
573 r
= sd_bus_message_open_container(reply
, 'r', "bas");
577 r
= sd_bus_message_append(reply
, "b", c
->address_families_whitelist
);
581 SET_FOREACH(af
, c
->address_families
, i
) {
584 name
= af_to_name(PTR_TO_INT(af
));
588 r
= strv_extend(&l
, name
);
595 r
= sd_bus_message_append_strv(reply
, l
);
599 return sd_bus_message_close_container(reply
);
602 static int property_get_working_directory(
605 const char *interface
,
606 const char *property
,
607 sd_bus_message
*reply
,
609 sd_bus_error
*error
) {
611 ExecContext
*c
= userdata
;
618 if (c
->working_directory_home
)
621 wd
= c
->working_directory
;
623 if (c
->working_directory_missing_ok
)
624 wd
= strjoina("!", wd
);
626 return sd_bus_message_append(reply
, "s", wd
);
629 static int property_get_syslog_level(
632 const char *interface
,
633 const char *property
,
634 sd_bus_message
*reply
,
636 sd_bus_error
*error
) {
638 ExecContext
*c
= userdata
;
644 return sd_bus_message_append(reply
, "i", LOG_PRI(c
->syslog_priority
));
647 static int property_get_syslog_facility(
650 const char *interface
,
651 const char *property
,
652 sd_bus_message
*reply
,
654 sd_bus_error
*error
) {
656 ExecContext
*c
= userdata
;
662 return sd_bus_message_append(reply
, "i", LOG_FAC(c
->syslog_priority
));
665 static int property_get_input_fdname(
668 const char *interface
,
669 const char *property
,
670 sd_bus_message
*reply
,
672 sd_bus_error
*error
) {
674 ExecContext
*c
= userdata
;
682 name
= exec_context_fdname(c
, STDIN_FILENO
);
684 return sd_bus_message_append(reply
, "s", name
);
687 static int property_get_output_fdname(
690 const char *interface
,
691 const char *property
,
692 sd_bus_message
*reply
,
694 sd_bus_error
*error
) {
696 ExecContext
*c
= userdata
;
697 const char *name
= NULL
;
704 if (c
->std_output
== EXEC_OUTPUT_NAMED_FD
&& streq(property
, "StandardOutputFileDescriptorName"))
705 name
= exec_context_fdname(c
, STDOUT_FILENO
);
706 else if (c
->std_error
== EXEC_OUTPUT_NAMED_FD
&& streq(property
, "StandardErrorFileDescriptorName"))
707 name
= exec_context_fdname(c
, STDERR_FILENO
);
709 return sd_bus_message_append(reply
, "s", name
);
712 static int property_get_bind_paths(
715 const char *interface
,
716 const char *property
,
717 sd_bus_message
*reply
,
719 sd_bus_error
*error
) {
721 ExecContext
*c
= userdata
;
731 ro
= !!strstr(property
, "ReadOnly");
733 r
= sd_bus_message_open_container(reply
, 'a', "(ssbt)");
737 for (i
= 0; i
< c
->n_bind_mounts
; i
++) {
739 if (ro
!= c
->bind_mounts
[i
].read_only
)
742 r
= sd_bus_message_append(
744 c
->bind_mounts
[i
].source
,
745 c
->bind_mounts
[i
].destination
,
746 c
->bind_mounts
[i
].ignore_enoent
,
747 c
->bind_mounts
[i
].recursive
? (uint64_t) MS_REC
: (uint64_t) 0);
752 return sd_bus_message_close_container(reply
);
755 const sd_bus_vtable bus_exec_vtable
[] = {
756 SD_BUS_VTABLE_START(0),
757 SD_BUS_PROPERTY("Environment", "as", NULL
, offsetof(ExecContext
, environment
), SD_BUS_VTABLE_PROPERTY_CONST
),
758 SD_BUS_PROPERTY("EnvironmentFiles", "a(sb)", property_get_environment_files
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
759 SD_BUS_PROPERTY("PassEnvironment", "as", NULL
, offsetof(ExecContext
, pass_environment
), SD_BUS_VTABLE_PROPERTY_CONST
),
760 SD_BUS_PROPERTY("UnsetEnvironment", "as", NULL
, offsetof(ExecContext
, unset_environment
), SD_BUS_VTABLE_PROPERTY_CONST
),
761 SD_BUS_PROPERTY("UMask", "u", bus_property_get_mode
, offsetof(ExecContext
, umask
), SD_BUS_VTABLE_PROPERTY_CONST
),
762 SD_BUS_PROPERTY("LimitCPU", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_CPU
]), SD_BUS_VTABLE_PROPERTY_CONST
),
763 SD_BUS_PROPERTY("LimitCPUSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_CPU
]), SD_BUS_VTABLE_PROPERTY_CONST
),
764 SD_BUS_PROPERTY("LimitFSIZE", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_FSIZE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
765 SD_BUS_PROPERTY("LimitFSIZESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_FSIZE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
766 SD_BUS_PROPERTY("LimitDATA", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_DATA
]), SD_BUS_VTABLE_PROPERTY_CONST
),
767 SD_BUS_PROPERTY("LimitDATASoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_DATA
]), SD_BUS_VTABLE_PROPERTY_CONST
),
768 SD_BUS_PROPERTY("LimitSTACK", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_STACK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
769 SD_BUS_PROPERTY("LimitSTACKSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_STACK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
770 SD_BUS_PROPERTY("LimitCORE", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_CORE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
771 SD_BUS_PROPERTY("LimitCORESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_CORE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
772 SD_BUS_PROPERTY("LimitRSS", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RSS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
773 SD_BUS_PROPERTY("LimitRSSSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RSS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
774 SD_BUS_PROPERTY("LimitNOFILE", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NOFILE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
775 SD_BUS_PROPERTY("LimitNOFILESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NOFILE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
776 SD_BUS_PROPERTY("LimitAS", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_AS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
777 SD_BUS_PROPERTY("LimitASSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_AS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
778 SD_BUS_PROPERTY("LimitNPROC", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NPROC
]), SD_BUS_VTABLE_PROPERTY_CONST
),
779 SD_BUS_PROPERTY("LimitNPROCSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NPROC
]), SD_BUS_VTABLE_PROPERTY_CONST
),
780 SD_BUS_PROPERTY("LimitMEMLOCK", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_MEMLOCK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
781 SD_BUS_PROPERTY("LimitMEMLOCKSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_MEMLOCK
]), SD_BUS_VTABLE_PROPERTY_CONST
),
782 SD_BUS_PROPERTY("LimitLOCKS", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_LOCKS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
783 SD_BUS_PROPERTY("LimitLOCKSSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_LOCKS
]), SD_BUS_VTABLE_PROPERTY_CONST
),
784 SD_BUS_PROPERTY("LimitSIGPENDING", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_SIGPENDING
]), SD_BUS_VTABLE_PROPERTY_CONST
),
785 SD_BUS_PROPERTY("LimitSIGPENDINGSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_SIGPENDING
]), SD_BUS_VTABLE_PROPERTY_CONST
),
786 SD_BUS_PROPERTY("LimitMSGQUEUE", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_MSGQUEUE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
787 SD_BUS_PROPERTY("LimitMSGQUEUESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_MSGQUEUE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
788 SD_BUS_PROPERTY("LimitNICE", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NICE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
789 SD_BUS_PROPERTY("LimitNICESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_NICE
]), SD_BUS_VTABLE_PROPERTY_CONST
),
790 SD_BUS_PROPERTY("LimitRTPRIO", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RTPRIO
]), SD_BUS_VTABLE_PROPERTY_CONST
),
791 SD_BUS_PROPERTY("LimitRTPRIOSoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RTPRIO
]), SD_BUS_VTABLE_PROPERTY_CONST
),
792 SD_BUS_PROPERTY("LimitRTTIME", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RTTIME
]), SD_BUS_VTABLE_PROPERTY_CONST
),
793 SD_BUS_PROPERTY("LimitRTTIMESoft", "t", bus_property_get_rlimit
, offsetof(ExecContext
, rlimit
[RLIMIT_RTTIME
]), SD_BUS_VTABLE_PROPERTY_CONST
),
794 SD_BUS_PROPERTY("WorkingDirectory", "s", property_get_working_directory
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
795 SD_BUS_PROPERTY("RootDirectory", "s", NULL
, offsetof(ExecContext
, root_directory
), SD_BUS_VTABLE_PROPERTY_CONST
),
796 SD_BUS_PROPERTY("RootImage", "s", NULL
, offsetof(ExecContext
, root_image
), SD_BUS_VTABLE_PROPERTY_CONST
),
797 SD_BUS_PROPERTY("OOMScoreAdjust", "i", property_get_oom_score_adjust
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
798 SD_BUS_PROPERTY("Nice", "i", property_get_nice
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
799 SD_BUS_PROPERTY("IOSchedulingClass", "i", property_get_ioprio_class
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
800 SD_BUS_PROPERTY("IOSchedulingPriority", "i", property_get_ioprio_priority
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
801 SD_BUS_PROPERTY("CPUSchedulingPolicy", "i", property_get_cpu_sched_policy
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
802 SD_BUS_PROPERTY("CPUSchedulingPriority", "i", property_get_cpu_sched_priority
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
803 SD_BUS_PROPERTY("CPUAffinity", "ay", property_get_cpu_affinity
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
804 SD_BUS_PROPERTY("TimerSlackNSec", "t", property_get_timer_slack_nsec
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
805 SD_BUS_PROPERTY("CPUSchedulingResetOnFork", "b", bus_property_get_bool
, offsetof(ExecContext
, cpu_sched_reset_on_fork
), SD_BUS_VTABLE_PROPERTY_CONST
),
806 SD_BUS_PROPERTY("NonBlocking", "b", bus_property_get_bool
, offsetof(ExecContext
, non_blocking
), SD_BUS_VTABLE_PROPERTY_CONST
),
807 SD_BUS_PROPERTY("StandardInput", "s", property_get_exec_input
, offsetof(ExecContext
, std_input
), SD_BUS_VTABLE_PROPERTY_CONST
),
808 SD_BUS_PROPERTY("StandardInputFileDescriptorName", "s", property_get_input_fdname
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
809 SD_BUS_PROPERTY("StandardOutput", "s", bus_property_get_exec_output
, offsetof(ExecContext
, std_output
), SD_BUS_VTABLE_PROPERTY_CONST
),
810 SD_BUS_PROPERTY("StandardOutputFileDescriptorName", "s", property_get_output_fdname
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
811 SD_BUS_PROPERTY("StandardError", "s", bus_property_get_exec_output
, offsetof(ExecContext
, std_error
), SD_BUS_VTABLE_PROPERTY_CONST
),
812 SD_BUS_PROPERTY("StandardErrorFileDescriptorName", "s", property_get_output_fdname
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
813 SD_BUS_PROPERTY("TTYPath", "s", NULL
, offsetof(ExecContext
, tty_path
), SD_BUS_VTABLE_PROPERTY_CONST
),
814 SD_BUS_PROPERTY("TTYReset", "b", bus_property_get_bool
, offsetof(ExecContext
, tty_reset
), SD_BUS_VTABLE_PROPERTY_CONST
),
815 SD_BUS_PROPERTY("TTYVHangup", "b", bus_property_get_bool
, offsetof(ExecContext
, tty_vhangup
), SD_BUS_VTABLE_PROPERTY_CONST
),
816 SD_BUS_PROPERTY("TTYVTDisallocate", "b", bus_property_get_bool
, offsetof(ExecContext
, tty_vt_disallocate
), SD_BUS_VTABLE_PROPERTY_CONST
),
817 SD_BUS_PROPERTY("SyslogPriority", "i", bus_property_get_int
, offsetof(ExecContext
, syslog_priority
), SD_BUS_VTABLE_PROPERTY_CONST
),
818 SD_BUS_PROPERTY("SyslogIdentifier", "s", NULL
, offsetof(ExecContext
, syslog_identifier
), SD_BUS_VTABLE_PROPERTY_CONST
),
819 SD_BUS_PROPERTY("SyslogLevelPrefix", "b", bus_property_get_bool
, offsetof(ExecContext
, syslog_level_prefix
), SD_BUS_VTABLE_PROPERTY_CONST
),
820 SD_BUS_PROPERTY("SyslogLevel", "i", property_get_syslog_level
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
821 SD_BUS_PROPERTY("SyslogFacility", "i", property_get_syslog_facility
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
822 SD_BUS_PROPERTY("SecureBits", "i", bus_property_get_int
, offsetof(ExecContext
, secure_bits
), SD_BUS_VTABLE_PROPERTY_CONST
),
823 SD_BUS_PROPERTY("CapabilityBoundingSet", "t", property_get_capability_bounding_set
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
824 SD_BUS_PROPERTY("AmbientCapabilities", "t", property_get_ambient_capabilities
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
825 SD_BUS_PROPERTY("User", "s", NULL
, offsetof(ExecContext
, user
), SD_BUS_VTABLE_PROPERTY_CONST
),
826 SD_BUS_PROPERTY("Group", "s", NULL
, offsetof(ExecContext
, group
), SD_BUS_VTABLE_PROPERTY_CONST
),
827 SD_BUS_PROPERTY("DynamicUser", "b", bus_property_get_bool
, offsetof(ExecContext
, dynamic_user
), SD_BUS_VTABLE_PROPERTY_CONST
),
828 SD_BUS_PROPERTY("RemoveIPC", "b", bus_property_get_bool
, offsetof(ExecContext
, remove_ipc
), SD_BUS_VTABLE_PROPERTY_CONST
),
829 SD_BUS_PROPERTY("SupplementaryGroups", "as", NULL
, offsetof(ExecContext
, supplementary_groups
), SD_BUS_VTABLE_PROPERTY_CONST
),
830 SD_BUS_PROPERTY("PAMName", "s", NULL
, offsetof(ExecContext
, pam_name
), SD_BUS_VTABLE_PROPERTY_CONST
),
831 SD_BUS_PROPERTY("ReadWritePaths", "as", NULL
, offsetof(ExecContext
, read_write_paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
832 SD_BUS_PROPERTY("ReadOnlyPaths", "as", NULL
, offsetof(ExecContext
, read_only_paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
833 SD_BUS_PROPERTY("InaccessiblePaths", "as", NULL
, offsetof(ExecContext
, inaccessible_paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
834 SD_BUS_PROPERTY("MountFlags", "t", bus_property_get_ulong
, offsetof(ExecContext
, mount_flags
), SD_BUS_VTABLE_PROPERTY_CONST
),
835 SD_BUS_PROPERTY("PrivateTmp", "b", bus_property_get_bool
, offsetof(ExecContext
, private_tmp
), SD_BUS_VTABLE_PROPERTY_CONST
),
836 SD_BUS_PROPERTY("PrivateDevices", "b", bus_property_get_bool
, offsetof(ExecContext
, private_devices
), SD_BUS_VTABLE_PROPERTY_CONST
),
837 SD_BUS_PROPERTY("ProtectKernelTunables", "b", bus_property_get_bool
, offsetof(ExecContext
, protect_kernel_tunables
), SD_BUS_VTABLE_PROPERTY_CONST
),
838 SD_BUS_PROPERTY("ProtectKernelModules", "b", bus_property_get_bool
, offsetof(ExecContext
, protect_kernel_modules
), SD_BUS_VTABLE_PROPERTY_CONST
),
839 SD_BUS_PROPERTY("ProtectControlGroups", "b", bus_property_get_bool
, offsetof(ExecContext
, protect_control_groups
), SD_BUS_VTABLE_PROPERTY_CONST
),
840 SD_BUS_PROPERTY("PrivateNetwork", "b", bus_property_get_bool
, offsetof(ExecContext
, private_network
), SD_BUS_VTABLE_PROPERTY_CONST
),
841 SD_BUS_PROPERTY("PrivateUsers", "b", bus_property_get_bool
, offsetof(ExecContext
, private_users
), SD_BUS_VTABLE_PROPERTY_CONST
),
842 SD_BUS_PROPERTY("ProtectHome", "s", bus_property_get_protect_home
, offsetof(ExecContext
, protect_home
), SD_BUS_VTABLE_PROPERTY_CONST
),
843 SD_BUS_PROPERTY("ProtectSystem", "s", bus_property_get_protect_system
, offsetof(ExecContext
, protect_system
), SD_BUS_VTABLE_PROPERTY_CONST
),
844 SD_BUS_PROPERTY("SameProcessGroup", "b", bus_property_get_bool
, offsetof(ExecContext
, same_pgrp
), SD_BUS_VTABLE_PROPERTY_CONST
),
845 SD_BUS_PROPERTY("UtmpIdentifier", "s", NULL
, offsetof(ExecContext
, utmp_id
), SD_BUS_VTABLE_PROPERTY_CONST
),
846 SD_BUS_PROPERTY("UtmpMode", "s", property_get_exec_utmp_mode
, offsetof(ExecContext
, utmp_mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
847 SD_BUS_PROPERTY("SELinuxContext", "(bs)", property_get_selinux_context
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
848 SD_BUS_PROPERTY("AppArmorProfile", "(bs)", property_get_apparmor_profile
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
849 SD_BUS_PROPERTY("SmackProcessLabel", "(bs)", property_get_smack_process_label
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
850 SD_BUS_PROPERTY("IgnoreSIGPIPE", "b", bus_property_get_bool
, offsetof(ExecContext
, ignore_sigpipe
), SD_BUS_VTABLE_PROPERTY_CONST
),
851 SD_BUS_PROPERTY("NoNewPrivileges", "b", bus_property_get_bool
, offsetof(ExecContext
, no_new_privileges
), SD_BUS_VTABLE_PROPERTY_CONST
),
852 SD_BUS_PROPERTY("SystemCallFilter", "(bas)", property_get_syscall_filter
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
853 SD_BUS_PROPERTY("SystemCallArchitectures", "as", property_get_syscall_archs
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
854 SD_BUS_PROPERTY("SystemCallErrorNumber", "i", property_get_syscall_errno
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
855 SD_BUS_PROPERTY("Personality", "s", property_get_personality
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
856 SD_BUS_PROPERTY("LockPersonality", "b", bus_property_get_bool
, offsetof(ExecContext
, lock_personality
), SD_BUS_VTABLE_PROPERTY_CONST
),
857 SD_BUS_PROPERTY("RestrictAddressFamilies", "(bas)", property_get_address_families
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
858 SD_BUS_PROPERTY("RuntimeDirectoryPreserve", "s", property_get_exec_preserve_mode
, offsetof(ExecContext
, runtime_directory_preserve_mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
859 SD_BUS_PROPERTY("RuntimeDirectoryMode", "u", bus_property_get_mode
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_RUNTIME
].mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
860 SD_BUS_PROPERTY("RuntimeDirectory", "as", NULL
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_RUNTIME
].paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
861 SD_BUS_PROPERTY("StateDirectoryMode", "u", bus_property_get_mode
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_STATE
].mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
862 SD_BUS_PROPERTY("StateDirectory", "as", NULL
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_STATE
].paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
863 SD_BUS_PROPERTY("CacheDirectoryMode", "u", bus_property_get_mode
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_CACHE
].mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
864 SD_BUS_PROPERTY("CacheDirectory", "as", NULL
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_CACHE
].paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
865 SD_BUS_PROPERTY("LogsDirectoryMode", "u", bus_property_get_mode
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_LOGS
].mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
866 SD_BUS_PROPERTY("LogsDirectory", "as", NULL
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_LOGS
].paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
867 SD_BUS_PROPERTY("ConfigurationDirectoryMode", "u", bus_property_get_mode
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_CONFIGURATION
].mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
868 SD_BUS_PROPERTY("ConfigurationDirectory", "as", NULL
, offsetof(ExecContext
, directories
[EXEC_DIRECTORY_CONFIGURATION
].paths
), SD_BUS_VTABLE_PROPERTY_CONST
),
869 SD_BUS_PROPERTY("MemoryDenyWriteExecute", "b", bus_property_get_bool
, offsetof(ExecContext
, memory_deny_write_execute
), SD_BUS_VTABLE_PROPERTY_CONST
),
870 SD_BUS_PROPERTY("RestrictRealtime", "b", bus_property_get_bool
, offsetof(ExecContext
, restrict_realtime
), SD_BUS_VTABLE_PROPERTY_CONST
),
871 SD_BUS_PROPERTY("RestrictNamespaces", "t", bus_property_get_ulong
, offsetof(ExecContext
, restrict_namespaces
), SD_BUS_VTABLE_PROPERTY_CONST
),
872 SD_BUS_PROPERTY("BindPaths", "a(ssbt)", property_get_bind_paths
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
873 SD_BUS_PROPERTY("BindReadOnlyPaths", "a(ssbt)", property_get_bind_paths
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
874 SD_BUS_PROPERTY("MountAPIVFS", "b", bus_property_get_bool
, offsetof(ExecContext
, mount_apivfs
), SD_BUS_VTABLE_PROPERTY_CONST
),
875 SD_BUS_PROPERTY("KeyringMode", "s", property_get_exec_keyring_mode
, offsetof(ExecContext
, keyring_mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
877 /* Obsolete/redundant properties: */
878 SD_BUS_PROPERTY("Capabilities", "s", property_get_empty_string
, 0, SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
879 SD_BUS_PROPERTY("ReadWriteDirectories", "as", NULL
, offsetof(ExecContext
, read_write_paths
), SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
880 SD_BUS_PROPERTY("ReadOnlyDirectories", "as", NULL
, offsetof(ExecContext
, read_only_paths
), SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
881 SD_BUS_PROPERTY("InaccessibleDirectories", "as", NULL
, offsetof(ExecContext
, inaccessible_paths
), SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
882 SD_BUS_PROPERTY("IOScheduling", "i", property_get_ioprio
, 0, SD_BUS_VTABLE_PROPERTY_CONST
|SD_BUS_VTABLE_HIDDEN
),
887 static int append_exec_command(sd_bus_message
*reply
, ExecCommand
*c
) {
896 r
= sd_bus_message_open_container(reply
, 'r', "sasbttttuii");
900 r
= sd_bus_message_append(reply
, "s", c
->path
);
904 r
= sd_bus_message_append_strv(reply
, c
->argv
);
908 r
= sd_bus_message_append(reply
, "bttttuii",
909 !!(c
->flags
& EXEC_COMMAND_IGNORE_FAILURE
),
910 c
->exec_status
.start_timestamp
.realtime
,
911 c
->exec_status
.start_timestamp
.monotonic
,
912 c
->exec_status
.exit_timestamp
.realtime
,
913 c
->exec_status
.exit_timestamp
.monotonic
,
914 (uint32_t) c
->exec_status
.pid
,
915 (int32_t) c
->exec_status
.code
,
916 (int32_t) c
->exec_status
.status
);
920 return sd_bus_message_close_container(reply
);
923 int bus_property_get_exec_command(
926 const char *interface
,
927 const char *property
,
928 sd_bus_message
*reply
,
930 sd_bus_error
*ret_error
) {
932 ExecCommand
*c
= (ExecCommand
*) userdata
;
938 r
= sd_bus_message_open_container(reply
, 'a', "(sasbttttuii)");
942 r
= append_exec_command(reply
, c
);
946 return sd_bus_message_close_container(reply
);
949 int bus_property_get_exec_command_list(
952 const char *interface
,
953 const char *property
,
954 sd_bus_message
*reply
,
956 sd_bus_error
*ret_error
) {
958 ExecCommand
*c
= *(ExecCommand
**) userdata
;
964 r
= sd_bus_message_open_container(reply
, 'a', "(sasbttttuii)");
968 LIST_FOREACH(command
, c
, c
) {
969 r
= append_exec_command(reply
, c
);
974 return sd_bus_message_close_container(reply
);
977 int bus_exec_context_set_transient_property(
981 sd_bus_message
*message
,
982 UnitSetPropertiesMode mode
,
983 sd_bus_error
*error
) {
985 const char *soft
= NULL
;
993 if (streq(name
, "User")) {
996 r
= sd_bus_message_read(message
, "s", &uu
);
1000 if (!isempty(uu
) && !valid_user_group_name_or_id(uu
))
1001 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid user name: %s", uu
);
1003 if (mode
!= UNIT_CHECK
) {
1006 c
->user
= mfree(c
->user
);
1007 else if (free_and_strdup(&c
->user
, uu
) < 0)
1010 unit_write_drop_in_private_format(u
, mode
, name
, "User=%s", uu
);
1015 } else if (streq(name
, "Group")) {
1018 r
= sd_bus_message_read(message
, "s", &gg
);
1022 if (!isempty(gg
) && !valid_user_group_name_or_id(gg
))
1023 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid group name: %s", gg
);
1025 if (mode
!= UNIT_CHECK
) {
1028 c
->group
= mfree(c
->group
);
1029 else if (free_and_strdup(&c
->group
, gg
) < 0)
1032 unit_write_drop_in_private_format(u
, mode
, name
, "Group=%s", gg
);
1037 } else if (streq(name
, "SupplementaryGroups")) {
1038 _cleanup_strv_free_
char **l
= NULL
;
1041 r
= sd_bus_message_read_strv(message
, &l
);
1045 STRV_FOREACH(p
, l
) {
1046 if (!isempty(*p
) && !valid_user_group_name_or_id(*p
))
1047 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid supplementary group names");
1050 if (mode
!= UNIT_CHECK
) {
1051 if (strv_length(l
) == 0) {
1052 c
->supplementary_groups
= strv_free(c
->supplementary_groups
);
1053 unit_write_drop_in_private_format(u
, mode
, name
, "%s=", name
);
1055 _cleanup_free_
char *joined
= NULL
;
1057 r
= strv_extend_strv(&c
->supplementary_groups
, l
, true);
1061 joined
= strv_join(c
->supplementary_groups
, " ");
1065 unit_write_drop_in_private_format(u
, mode
, name
, "%s=%s", name
, joined
);
1071 } else if (streq(name
, "SyslogIdentifier")) {
1074 r
= sd_bus_message_read(message
, "s", &id
);
1078 if (mode
!= UNIT_CHECK
) {
1081 c
->syslog_identifier
= mfree(c
->syslog_identifier
);
1082 else if (free_and_strdup(&c
->syslog_identifier
, id
) < 0)
1085 unit_write_drop_in_private_format(u
, mode
, name
, "SyslogIdentifier=%s", id
);
1089 } else if (streq(name
, "SyslogLevel")) {
1092 r
= sd_bus_message_read(message
, "i", &level
);
1096 if (!log_level_is_valid(level
))
1097 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Log level value out of range");
1099 if (mode
!= UNIT_CHECK
) {
1100 c
->syslog_priority
= (c
->syslog_priority
& LOG_FACMASK
) | level
;
1101 unit_write_drop_in_private_format(u
, mode
, name
, "SyslogLevel=%i", level
);
1105 } else if (streq(name
, "SyslogFacility")) {
1108 r
= sd_bus_message_read(message
, "i", &facility
);
1112 if (!log_facility_unshifted_is_valid(facility
))
1113 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Log facility value out of range");
1115 if (mode
!= UNIT_CHECK
) {
1116 c
->syslog_priority
= (facility
<< 3) | LOG_PRI(c
->syslog_priority
);
1117 unit_write_drop_in_private_format(u
, mode
, name
, "SyslogFacility=%i", facility
);
1121 } else if (streq(name
, "SecureBits")) {
1124 r
= sd_bus_message_read(message
, "i", &n
);
1128 if (!secure_bits_is_valid(n
))
1129 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid secure bits");
1131 if (mode
!= UNIT_CHECK
) {
1132 _cleanup_free_
char *str
= NULL
;
1135 r
= secure_bits_to_string_alloc(n
, &str
);
1139 unit_write_drop_in_private_format(u
, mode
, name
, "SecureBits=%s", str
);
1143 } else if (STR_IN_SET(name
, "CapabilityBoundingSet", "AmbientCapabilities")) {
1146 r
= sd_bus_message_read(message
, "t", &n
);
1150 if (mode
!= UNIT_CHECK
) {
1151 _cleanup_free_
char *str
= NULL
;
1153 if (streq(name
, "CapabilityBoundingSet"))
1154 c
->capability_bounding_set
= n
;
1155 else /* "AmbientCapabilities" */
1156 c
->capability_ambient_set
= n
;
1158 r
= capability_set_to_string_alloc(n
, &str
);
1162 unit_write_drop_in_private_format(u
, mode
, name
, "%s=%s", name
, str
);
1167 } else if (streq(name
, "Personality")) {
1171 r
= sd_bus_message_read(message
, "s", &s
);
1175 p
= personality_from_string(s
);
1176 if (p
== PERSONALITY_INVALID
)
1177 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid personality");
1179 if (mode
!= UNIT_CHECK
) {
1180 _cleanup_free_
char *str
= NULL
;
1183 unit_write_drop_in_private_format(u
, mode
, name
, "%s=%s", name
, s
);
1190 } else if (streq(name
, "SystemCallFilter")) {
1192 _cleanup_strv_free_
char **l
;
1194 r
= sd_bus_message_enter_container(message
, 'r', "bas");
1198 r
= sd_bus_message_read(message
, "b", &whitelist
);
1202 r
= sd_bus_message_read_strv(message
, &l
);
1206 r
= sd_bus_message_exit_container(message
);
1210 if (mode
!= UNIT_CHECK
) {
1211 _cleanup_free_
char *joined
= NULL
;
1213 if (strv_length(l
) == 0) {
1214 c
->syscall_whitelist
= false;
1215 c
->syscall_filter
= set_free(c
->syscall_filter
);
1219 c
->syscall_whitelist
= whitelist
;
1221 r
= set_ensure_allocated(&c
->syscall_filter
, NULL
);
1225 STRV_FOREACH(s
, l
) {
1227 const SyscallFilterSet
*set
;
1230 set
= syscall_filter_set_find(*s
);
1234 NULSTR_FOREACH(i
, set
->value
) {
1237 id
= seccomp_syscall_resolve_name(i
);
1238 if (id
== __NR_SCMP_ERROR
)
1241 r
= set_put(c
->address_families
, INT_TO_PTR(id
+ 1));
1249 id
= seccomp_syscall_resolve_name(*s
);
1250 if (id
== __NR_SCMP_ERROR
)
1253 r
= set_put(c
->address_families
, INT_TO_PTR(id
+ 1));
1260 joined
= strv_join(l
, " ");
1264 unit_write_drop_in_private_format(u
, mode
, name
, "SystemCallFilter=%s%s", whitelist
? "" : "~", joined
);
1269 } else if (streq(name
, "SystemCallArchitectures")) {
1270 _cleanup_strv_free_
char **l
= NULL
;
1272 r
= sd_bus_message_read_strv(message
, &l
);
1276 if (mode
!= UNIT_CHECK
) {
1277 _cleanup_free_
char *joined
= NULL
;
1279 if (strv_length(l
) == 0)
1280 c
->syscall_archs
= set_free(c
->syscall_archs
);
1284 r
= set_ensure_allocated(&c
->syscall_archs
, NULL
);
1288 STRV_FOREACH(s
, l
) {
1291 r
= seccomp_arch_from_string(*s
, &a
);
1295 r
= set_put(c
->syscall_archs
, UINT32_TO_PTR(a
+ 1));
1302 joined
= strv_join(l
, " ");
1306 unit_write_drop_in_private_format(u
, mode
, name
, "%s=%s", name
, joined
);
1311 } else if (streq(name
, "SystemCallErrorNumber")) {
1315 r
= sd_bus_message_read(message
, "i", &n
);
1319 str
= errno_to_name(n
);
1321 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid SystemCallErrorNumber");
1323 if (mode
!= UNIT_CHECK
) {
1324 c
->syscall_errno
= n
;
1326 unit_write_drop_in_private_format(u
, mode
, name
, "SystemCallErrorNumber=%s", str
);
1331 } else if (streq(name
, "RestrictAddressFamilies")) {
1333 _cleanup_strv_free_
char **l
;
1335 r
= sd_bus_message_enter_container(message
, 'r', "bas");
1339 r
= sd_bus_message_read(message
, "b", &whitelist
);
1343 r
= sd_bus_message_read_strv(message
, &l
);
1347 r
= sd_bus_message_exit_container(message
);
1351 if (mode
!= UNIT_CHECK
) {
1352 _cleanup_free_
char *joined
= NULL
;
1354 if (strv_length(l
) == 0) {
1355 c
->address_families_whitelist
= false;
1356 c
->address_families
= set_free(c
->address_families
);
1360 c
->address_families_whitelist
= whitelist
;
1362 r
= set_ensure_allocated(&c
->address_families
, NULL
);
1366 STRV_FOREACH(s
, l
) {
1369 af
= af_from_name(*s
);
1373 r
= set_put(c
->address_families
, INT_TO_PTR(af
));
1379 joined
= strv_join(l
, " ");
1383 unit_write_drop_in_private_format(u
, mode
, name
, "RestrictAddressFamilies=%s%s", whitelist
? "" : "~", joined
);
1389 } else if (streq(name
, "CPUSchedulingPolicy")) {
1392 r
= sd_bus_message_read(message
, "i", &n
);
1396 if (!sched_policy_is_valid(n
))
1397 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid CPU scheduling policy");
1399 if (mode
!= UNIT_CHECK
) {
1400 _cleanup_free_
char *str
= NULL
;
1402 c
->cpu_sched_policy
= n
;
1403 r
= sched_policy_to_string_alloc(n
, &str
);
1407 unit_write_drop_in_private_format(u
, mode
, name
, "CPUSchedulingPolicy=%s", str
);
1412 } else if (streq(name
, "CPUSchedulingPriority")) {
1415 r
= sd_bus_message_read(message
, "i", &n
);
1419 if (!ioprio_priority_is_valid(n
))
1420 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid CPU scheduling priority");
1422 if (mode
!= UNIT_CHECK
) {
1423 c
->cpu_sched_priority
= n
;
1424 unit_write_drop_in_private_format(u
, mode
, name
, "CPUSchedulingPriority=%i", n
);
1429 } else if (streq(name
, "CPUAffinity")) {
1433 r
= sd_bus_message_read_array(message
, 'y', &a
, &n
);
1437 if (mode
!= UNIT_CHECK
) {
1439 c
->cpuset
= mfree(c
->cpuset
);
1440 unit_write_drop_in_private_format(u
, mode
, name
, "%s=", name
);
1442 _cleanup_free_
char *str
= NULL
;
1444 size_t allocated
= 0, len
= 0, i
;
1446 c
->cpuset
= (cpu_set_t
*) memdup(a
, sizeof(cpu_set_t
) * n
);
1451 for (i
= 0; i
< n
; i
++) {
1452 _cleanup_free_
char *p
= NULL
;
1455 r
= asprintf(&p
, "%hhi", l
[i
]);
1461 if (GREEDY_REALLOC(str
, allocated
, len
+ add
+ 2))
1464 strcpy(mempcpy(str
+ len
, p
, add
), " ");
1469 str
[len
- 1] = '\0';
1471 unit_write_drop_in_private_format(u
, mode
, name
, "%s=%s", name
, str
);
1476 } else if (streq(name
, "Nice")) {
1479 r
= sd_bus_message_read(message
, "i", &n
);
1483 if (!nice_is_valid(n
))
1484 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Nice value out of range");
1486 if (mode
!= UNIT_CHECK
) {
1488 unit_write_drop_in_private_format(u
, mode
, name
, "Nice=%i", n
);
1493 } else if (streq(name
, "IOSchedulingClass")) {
1496 r
= sd_bus_message_read(message
, "i", &q
);
1500 if (!ioprio_class_is_valid(q
))
1501 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid IO scheduling class: %i", q
);
1503 if (mode
!= UNIT_CHECK
) {
1504 _cleanup_free_
char *s
= NULL
;
1506 r
= ioprio_class_to_string_alloc(q
, &s
);
1510 c
->ioprio
= IOPRIO_PRIO_VALUE(q
, IOPRIO_PRIO_DATA(c
->ioprio
));
1511 c
->ioprio_set
= true;
1513 unit_write_drop_in_private_format(u
, mode
, name
, "IOSchedulingClass=%s", s
);
1518 } else if (streq(name
, "IOSchedulingPriority")) {
1521 r
= sd_bus_message_read(message
, "i", &p
);
1525 if (!ioprio_priority_is_valid(p
))
1526 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid IO scheduling priority: %i", p
);
1528 if (mode
!= UNIT_CHECK
) {
1529 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_PRIO_CLASS(c
->ioprio
), p
);
1530 c
->ioprio_set
= true;
1532 unit_write_drop_in_private_format(u
, mode
, name
, "IOSchedulingPriority=%i", p
);
1537 } else if (STR_IN_SET(name
, "TTYPath", "RootDirectory", "RootImage")) {
1540 r
= sd_bus_message_read(message
, "s", &s
);
1544 if (!path_is_absolute(s
))
1545 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "%s takes an absolute path", name
);
1547 if (mode
!= UNIT_CHECK
) {
1548 if (streq(name
, "TTYPath"))
1549 r
= free_and_strdup(&c
->tty_path
, s
);
1550 else if (streq(name
, "RootImage"))
1551 r
= free_and_strdup(&c
->root_image
, s
);
1553 assert(streq(name
, "RootDirectory"));
1554 r
= free_and_strdup(&c
->root_directory
, s
);
1559 unit_write_drop_in_private_format(u
, mode
, name
, "%s=%s", name
, s
);
1564 } else if (streq(name
, "WorkingDirectory")) {
1568 r
= sd_bus_message_read(message
, "s", &s
);
1578 if (!streq(s
, "~") && !path_is_absolute(s
))
1579 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "WorkingDirectory= expects an absolute path or '~'");
1581 if (mode
!= UNIT_CHECK
) {
1582 if (streq(s
, "~")) {
1583 c
->working_directory
= mfree(c
->working_directory
);
1584 c
->working_directory_home
= true;
1586 r
= free_and_strdup(&c
->working_directory
, s
);
1590 c
->working_directory_home
= false;
1593 c
->working_directory_missing_ok
= missing_ok
;
1594 unit_write_drop_in_private_format(u
, mode
, name
, "WorkingDirectory=%s%s", missing_ok
? "-" : "", s
);
1599 } else if (streq(name
, "StandardInput")) {
1603 r
= sd_bus_message_read(message
, "s", &s
);
1607 p
= exec_input_from_string(s
);
1609 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid standard input name");
1611 if (mode
!= UNIT_CHECK
) {
1614 unit_write_drop_in_private_format(u
, mode
, name
, "StandardInput=%s", exec_input_to_string(p
));
1619 } else if (streq(name
, "StandardOutput")) {
1623 r
= sd_bus_message_read(message
, "s", &s
);
1627 p
= exec_output_from_string(s
);
1629 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid standard output name");
1631 if (mode
!= UNIT_CHECK
) {
1634 unit_write_drop_in_private_format(u
, mode
, name
, "StandardOutput=%s", exec_output_to_string(p
));
1639 } else if (streq(name
, "StandardError")) {
1643 r
= sd_bus_message_read(message
, "s", &s
);
1647 p
= exec_output_from_string(s
);
1649 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid standard error name");
1651 if (mode
!= UNIT_CHECK
) {
1654 unit_write_drop_in_private_format(u
, mode
, name
, "StandardError=%s", exec_output_to_string(p
));
1659 } else if (STR_IN_SET(name
,
1660 "StandardInputFileDescriptorName", "StandardOutputFileDescriptorName", "StandardErrorFileDescriptorName")) {
1663 r
= sd_bus_message_read(message
, "s", &s
);
1667 if (!fdname_is_valid(s
))
1668 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid file descriptor name");
1670 if (mode
!= UNIT_CHECK
) {
1671 if (streq(name
, "StandardInputFileDescriptorName")) {
1672 c
->std_input
= EXEC_INPUT_NAMED_FD
;
1673 r
= free_and_strdup(&c
->stdio_fdname
[STDIN_FILENO
], s
);
1676 unit_write_drop_in_private_format(u
, mode
, name
, "StandardInput=fd:%s", s
);
1677 } else if (streq(name
, "StandardOutputFileDescriptorName")) {
1678 c
->std_output
= EXEC_OUTPUT_NAMED_FD
;
1679 r
= free_and_strdup(&c
->stdio_fdname
[STDOUT_FILENO
], s
);
1682 unit_write_drop_in_private_format(u
, mode
, name
, "StandardOutput=fd:%s", s
);
1683 } else if (streq(name
, "StandardErrorFileDescriptorName")) {
1684 c
->std_error
= EXEC_OUTPUT_NAMED_FD
;
1685 r
= free_and_strdup(&c
->stdio_fdname
[STDERR_FILENO
], s
);
1688 unit_write_drop_in_private_format(u
, mode
, name
, "StandardError=fd:%s", s
);
1694 } else if (STR_IN_SET(name
,
1695 "IgnoreSIGPIPE", "TTYVHangup", "TTYReset", "TTYVTDisallocate",
1696 "PrivateTmp", "PrivateDevices", "PrivateNetwork", "PrivateUsers",
1697 "NoNewPrivileges", "SyslogLevelPrefix", "MemoryDenyWriteExecute",
1698 "RestrictRealtime", "DynamicUser", "RemoveIPC", "ProtectKernelTunables",
1699 "ProtectKernelModules", "ProtectControlGroups", "MountAPIVFS",
1700 "CPUSchedulingResetOnFork", "NonBlocking", "LockPersonality")) {
1703 r
= sd_bus_message_read(message
, "b", &b
);
1707 if (mode
!= UNIT_CHECK
) {
1708 if (streq(name
, "IgnoreSIGPIPE"))
1709 c
->ignore_sigpipe
= b
;
1710 else if (streq(name
, "TTYVHangup"))
1712 else if (streq(name
, "TTYReset"))
1714 else if (streq(name
, "TTYVTDisallocate"))
1715 c
->tty_vt_disallocate
= b
;
1716 else if (streq(name
, "PrivateTmp"))
1718 else if (streq(name
, "PrivateDevices"))
1719 c
->private_devices
= b
;
1720 else if (streq(name
, "PrivateNetwork"))
1721 c
->private_network
= b
;
1722 else if (streq(name
, "PrivateUsers"))
1723 c
->private_users
= b
;
1724 else if (streq(name
, "NoNewPrivileges"))
1725 c
->no_new_privileges
= b
;
1726 else if (streq(name
, "SyslogLevelPrefix"))
1727 c
->syslog_level_prefix
= b
;
1728 else if (streq(name
, "MemoryDenyWriteExecute"))
1729 c
->memory_deny_write_execute
= b
;
1730 else if (streq(name
, "RestrictRealtime"))
1731 c
->restrict_realtime
= b
;
1732 else if (streq(name
, "DynamicUser"))
1733 c
->dynamic_user
= b
;
1734 else if (streq(name
, "RemoveIPC"))
1736 else if (streq(name
, "ProtectKernelTunables"))
1737 c
->protect_kernel_tunables
= b
;
1738 else if (streq(name
, "ProtectKernelModules"))
1739 c
->protect_kernel_modules
= b
;
1740 else if (streq(name
, "ProtectControlGroups"))
1741 c
->protect_control_groups
= b
;
1742 else if (streq(name
, "MountAPIVFS"))
1743 c
->mount_apivfs
= b
;
1744 else if (streq(name
, "CPUSchedulingResetOnFork"))
1745 c
->cpu_sched_reset_on_fork
= b
;
1746 else if (streq(name
, "NonBlocking"))
1747 c
->non_blocking
= b
;
1748 else if (streq(name
, "LockPersonality"))
1749 c
->lock_personality
= b
;
1751 unit_write_drop_in_private_format(u
, mode
, name
, "%s=%s", name
, yes_no(b
));
1756 } else if (streq(name
, "UtmpIdentifier")) {
1759 r
= sd_bus_message_read(message
, "s", &id
);
1763 if (mode
!= UNIT_CHECK
) {
1765 c
->utmp_id
= mfree(c
->utmp_id
);
1766 else if (free_and_strdup(&c
->utmp_id
, id
) < 0)
1769 unit_write_drop_in_private_format(u
, mode
, name
, "UtmpIdentifier=%s", strempty(id
));
1774 } else if (streq(name
, "UtmpMode")) {
1778 r
= sd_bus_message_read(message
, "s", &s
);
1782 m
= exec_utmp_mode_from_string(s
);
1784 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid utmp mode");
1786 if (mode
!= UNIT_CHECK
) {
1789 unit_write_drop_in_private_format(u
, mode
, name
, "UtmpMode=%s", exec_utmp_mode_to_string(m
));
1794 } else if (streq(name
, "PAMName")) {
1797 r
= sd_bus_message_read(message
, "s", &n
);
1801 if (mode
!= UNIT_CHECK
) {
1803 c
->pam_name
= mfree(c
->pam_name
);
1804 else if (free_and_strdup(&c
->pam_name
, n
) < 0)
1807 unit_write_drop_in_private_format(u
, mode
, name
, "PAMName=%s", strempty(n
));
1812 } else if (streq(name
, "Environment")) {
1814 _cleanup_strv_free_
char **l
= NULL
, **q
= NULL
;
1816 r
= sd_bus_message_read_strv(message
, &l
);
1820 r
= unit_full_printf_strv(u
, l
, &q
);
1824 if (!strv_env_is_valid(q
))
1825 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid environment block.");
1827 if (mode
!= UNIT_CHECK
) {
1828 if (strv_length(q
) == 0) {
1829 c
->environment
= strv_free(c
->environment
);
1830 unit_write_drop_in_private_format(u
, mode
, name
, "Environment=");
1832 _cleanup_free_
char *joined
= NULL
;
1835 e
= strv_env_merge(2, c
->environment
, q
);
1839 strv_free(c
->environment
);
1842 /* We write just the new settings out to file, with unresolved specifiers */
1843 joined
= strv_join_quoted(l
);
1847 unit_write_drop_in_private_format(u
, mode
, name
, "Environment=%s", joined
);
1853 } else if (streq(name
, "UnsetEnvironment")) {
1855 _cleanup_strv_free_
char **l
= NULL
, **q
= NULL
;
1857 r
= sd_bus_message_read_strv(message
, &l
);
1861 r
= unit_full_printf_strv(u
, l
, &q
);
1865 if (!strv_env_name_or_assignment_is_valid(q
))
1866 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid UnsetEnvironment= list.");
1868 if (mode
!= UNIT_CHECK
) {
1869 if (strv_length(q
) == 0) {
1870 c
->unset_environment
= strv_free(c
->unset_environment
);
1871 unit_write_drop_in_private_format(u
, mode
, name
, "UnsetEnvironment=");
1873 _cleanup_free_
char *joined
= NULL
;
1876 e
= strv_env_merge(2, c
->unset_environment
, q
);
1880 strv_free(c
->unset_environment
);
1881 c
->unset_environment
= e
;
1883 /* We write just the new settings out to file, with unresolved specifiers */
1884 joined
= strv_join_quoted(l
);
1888 unit_write_drop_in_private_format(u
, mode
, name
, "UnsetEnvironment=%s", joined
);
1894 } else if (streq(name
, "TimerSlackNSec")) {
1898 r
= sd_bus_message_read(message
, "t", &n
);
1902 if (mode
!= UNIT_CHECK
) {
1903 c
->timer_slack_nsec
= n
;
1904 unit_write_drop_in_private_format(u
, mode
, name
, "TimerSlackNSec=" NSEC_FMT
, n
);
1909 } else if (streq(name
, "OOMScoreAdjust")) {
1912 r
= sd_bus_message_read(message
, "i", &oa
);
1916 if (!oom_score_adjust_is_valid(oa
))
1917 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "OOM score adjust value out of range");
1919 if (mode
!= UNIT_CHECK
) {
1920 c
->oom_score_adjust
= oa
;
1921 c
->oom_score_adjust_set
= true;
1922 unit_write_drop_in_private_format(u
, mode
, name
, "OOMScoreAdjust=%i", oa
);
1927 } else if (streq(name
, "EnvironmentFiles")) {
1929 _cleanup_free_
char *joined
= NULL
;
1930 _cleanup_fclose_
FILE *f
= NULL
;
1931 _cleanup_strv_free_
char **l
= NULL
;
1935 r
= sd_bus_message_enter_container(message
, 'a', "(sb)");
1939 f
= open_memstream(&joined
, &size
);
1943 STRV_FOREACH(i
, c
->environment_files
)
1944 fprintf(f
, "EnvironmentFile=%s", *i
);
1946 while ((r
= sd_bus_message_enter_container(message
, 'r', "sb")) > 0) {
1950 r
= sd_bus_message_read(message
, "sb", &path
, &b
);
1954 r
= sd_bus_message_exit_container(message
);
1958 if (!path_is_absolute(path
))
1959 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Path %s is not absolute.", path
);
1961 if (mode
!= UNIT_CHECK
) {
1964 buf
= strjoin(b
? "-" : "", path
);
1968 fprintf(f
, "EnvironmentFile=%s", buf
);
1970 r
= strv_consume(&l
, buf
);
1978 r
= sd_bus_message_exit_container(message
);
1982 r
= fflush_and_check(f
);
1986 if (mode
!= UNIT_CHECK
) {
1987 if (strv_isempty(l
)) {
1988 c
->environment_files
= strv_free(c
->environment_files
);
1989 unit_write_drop_in_private(u
, mode
, name
, "EnvironmentFile=");
1991 r
= strv_extend_strv(&c
->environment_files
, l
, true);
1995 unit_write_drop_in_private(u
, mode
, name
, joined
);
2001 } else if (streq(name
, "PassEnvironment")) {
2003 _cleanup_strv_free_
char **l
= NULL
, **q
= NULL
;
2005 r
= sd_bus_message_read_strv(message
, &l
);
2009 r
= unit_full_printf_strv(u
, l
, &q
);
2013 if (!strv_env_name_is_valid(q
))
2014 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid PassEnvironment= block.");
2016 if (mode
!= UNIT_CHECK
) {
2017 if (strv_isempty(l
)) {
2018 c
->pass_environment
= strv_free(c
->pass_environment
);
2019 unit_write_drop_in_private_format(u
, mode
, name
, "PassEnvironment=");
2021 _cleanup_free_
char *joined
= NULL
;
2023 r
= strv_extend_strv(&c
->pass_environment
, q
, true);
2027 /* We write just the new settings out to file, with unresolved specifiers. */
2028 joined
= strv_join_quoted(l
);
2032 unit_write_drop_in_private_format(u
, mode
, name
, "PassEnvironment=%s", joined
);
2038 } else if (STR_IN_SET(name
, "ReadWriteDirectories", "ReadOnlyDirectories", "InaccessibleDirectories",
2039 "ReadWritePaths", "ReadOnlyPaths", "InaccessiblePaths")) {
2040 _cleanup_strv_free_
char **l
= NULL
;
2044 r
= sd_bus_message_read_strv(message
, &l
);
2048 STRV_FOREACH(p
, l
) {
2052 if (!utf8_is_valid(i
))
2053 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid %s", name
);
2055 offset
= i
[0] == '-';
2056 offset
+= i
[offset
] == '+';
2057 if (!path_is_absolute(i
+ offset
))
2058 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid %s", name
);
2061 if (mode
!= UNIT_CHECK
) {
2062 _cleanup_free_
char *joined
= NULL
;
2064 if (STR_IN_SET(name
, "ReadWriteDirectories", "ReadWritePaths"))
2065 dirs
= &c
->read_write_paths
;
2066 else if (STR_IN_SET(name
, "ReadOnlyDirectories", "ReadOnlyPaths"))
2067 dirs
= &c
->read_only_paths
;
2068 else /* "InaccessiblePaths" */
2069 dirs
= &c
->inaccessible_paths
;
2071 if (strv_length(l
) == 0) {
2072 *dirs
= strv_free(*dirs
);
2073 unit_write_drop_in_private_format(u
, mode
, name
, "%s=", name
);
2075 r
= strv_extend_strv(dirs
, l
, true);
2079 joined
= strv_join_quoted(*dirs
);
2083 unit_write_drop_in_private_format(u
, mode
, name
, "%s=%s", name
, joined
);
2090 } else if (streq(name
, "ProtectSystem")) {
2094 r
= sd_bus_message_read(message
, "s", &s
);
2098 r
= parse_boolean(s
);
2100 ps
= PROTECT_SYSTEM_YES
;
2102 ps
= PROTECT_SYSTEM_NO
;
2104 ps
= protect_system_from_string(s
);
2106 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Failed to parse protect system value");
2109 if (mode
!= UNIT_CHECK
) {
2110 c
->protect_system
= ps
;
2111 unit_write_drop_in_private_format(u
, mode
, name
, "%s=%s", name
, s
);
2116 } else if (streq(name
, "ProtectHome")) {
2120 r
= sd_bus_message_read(message
, "s", &s
);
2124 r
= parse_boolean(s
);
2126 ph
= PROTECT_HOME_YES
;
2128 ph
= PROTECT_HOME_NO
;
2130 ph
= protect_home_from_string(s
);
2132 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Failed to parse protect home value");
2135 if (mode
!= UNIT_CHECK
) {
2136 c
->protect_home
= ph
;
2137 unit_write_drop_in_private_format(u
, mode
, name
, "%s=%s", name
, s
);
2142 } else if (streq(name
, "KeyringMode")) {
2147 r
= sd_bus_message_read(message
, "s", &s
);
2151 m
= exec_keyring_mode_from_string(s
);
2153 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid keyring mode");
2155 if (mode
!= UNIT_CHECK
) {
2156 c
->keyring_mode
= m
;
2158 unit_write_drop_in_private_format(u
, mode
, name
, "KeyringMode=%s", exec_keyring_mode_to_string(m
));
2163 } else if (streq(name
, "RuntimeDirectoryPreserve")) {
2167 r
= sd_bus_message_read(message
, "s", &s
);
2171 m
= exec_preserve_mode_from_string(s
);
2173 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Invalid preserve mode");
2175 if (mode
!= UNIT_CHECK
) {
2176 c
->runtime_directory_preserve_mode
= m
;
2178 unit_write_drop_in_private_format(u
, mode
, name
, "RuntimeDirectoryPreserve=%s", exec_preserve_mode_to_string(m
));
2183 } else if (STR_IN_SET(name
, "RuntimeDirectoryMode", "StateDirectoryMode", "CacheDirectoryMode", "LogsDirectoryMode", "ConfigurationDirectoryMode", "UMask")) {
2186 r
= sd_bus_message_read(message
, "u", &m
);
2190 if (mode
!= UNIT_CHECK
) {
2191 ExecDirectoryType i
;
2193 if (streq(name
, "UMask"))
2196 for (i
= 0; i
< _EXEC_DIRECTORY_MAX
; i
++)
2197 if (startswith(name
, exec_directory_type_to_string(i
))) {
2198 c
->directories
[i
].mode
= m
;
2202 unit_write_drop_in_private_format(u
, mode
, name
, "%s=%040o", name
, m
);
2207 } else if (STR_IN_SET(name
, "RuntimeDirectory", "StateDirectory", "CacheDirectory", "LogsDirectory", "ConfigurationDirectory")) {
2208 _cleanup_strv_free_
char **l
= NULL
;
2211 r
= sd_bus_message_read_strv(message
, &l
);
2215 STRV_FOREACH(p
, l
) {
2216 if (!filename_is_valid(*p
))
2217 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "%s is not valid %s", name
, *p
);
2220 if (mode
!= UNIT_CHECK
) {
2221 _cleanup_free_
char *joined
= NULL
;
2222 char ***dirs
= NULL
;
2223 ExecDirectoryType i
;
2225 for (i
= 0; i
< _EXEC_DIRECTORY_MAX
; i
++)
2226 if (streq(name
, exec_directory_type_to_string(i
))) {
2227 dirs
= &c
->directories
[i
].paths
;
2233 if (strv_isempty(l
)) {
2234 *dirs
= strv_free(*dirs
);
2235 unit_write_drop_in_private_format(u
, mode
, name
, "%s=", name
);
2237 r
= strv_extend_strv(dirs
, l
, true);
2242 joined
= strv_join_quoted(*dirs
);
2246 unit_write_drop_in_private_format(u
, mode
, name
, "%s=%s", name
, joined
);
2252 } else if (streq(name
, "SELinuxContext")) {
2254 r
= sd_bus_message_read(message
, "s", &s
);
2258 if (mode
!= UNIT_CHECK
) {
2260 c
->selinux_context
= mfree(c
->selinux_context
);
2261 else if (free_and_strdup(&c
->selinux_context
, s
) < 0)
2264 unit_write_drop_in_private_format(u
, mode
, name
, "%s=%s", name
, strempty(s
));
2269 } else if (STR_IN_SET(name
, "AppArmorProfile", "SmackProcessLabel")) {
2273 r
= sd_bus_message_enter_container(message
, 'r', "bs");
2277 r
= sd_bus_message_read(message
, "bs", &ignore
, &s
);
2281 if (mode
!= UNIT_CHECK
) {
2285 if (streq(name
, "AppArmorProfile")) {
2286 p
= &c
->apparmor_profile
;
2287 b
= &c
->apparmor_profile_ignore
;
2288 } else { /* "SmackProcessLabel" */
2289 p
= &c
->smack_process_label
;
2290 b
= &c
->smack_process_label_ignore
;
2297 if (free_and_strdup(p
, s
) < 0)
2302 unit_write_drop_in_private_format(u
, mode
, name
, "%s=%s%s", name
, ignore
? "-" : "", strempty(s
));
2307 } else if (streq(name
, "RestrictNamespaces")) {
2310 r
= sd_bus_message_read(message
, "t", &flags
);
2313 if ((flags
& NAMESPACE_FLAGS_ALL
) != flags
)
2314 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Unknown namespace types");
2316 if (mode
!= UNIT_CHECK
) {
2317 _cleanup_free_
char *s
= NULL
;
2319 r
= namespace_flag_to_string_many(flags
, &s
);
2323 c
->restrict_namespaces
= flags
;
2324 unit_write_drop_in_private_format(u
, mode
, name
, "%s=%s", name
, s
);
2328 } else if (streq(name
, "MountFlags")) {
2331 r
= sd_bus_message_read(message
, "t", &flags
);
2334 if (!IN_SET(flags
, 0, MS_SHARED
, MS_PRIVATE
, MS_SLAVE
))
2335 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Unknown mount propagation flags");
2337 if (mode
!= UNIT_CHECK
) {
2338 c
->mount_flags
= flags
;
2340 unit_write_drop_in_private_format(u
, mode
, name
, "%s=%s", name
, mount_propagation_flags_to_string(flags
));
2344 } else if (STR_IN_SET(name
, "BindPaths", "BindReadOnlyPaths")) {
2345 unsigned empty
= true;
2347 r
= sd_bus_message_enter_container(message
, 'a', "(ssbt)");
2351 while ((r
= sd_bus_message_enter_container(message
, 'r', "ssbt")) > 0) {
2352 const char *source
, *destination
;
2354 uint64_t mount_flags
;
2356 r
= sd_bus_message_read(message
, "ssbt", &source
, &destination
, &ignore_enoent
, &mount_flags
);
2360 r
= sd_bus_message_exit_container(message
);
2364 if (!path_is_absolute(source
))
2365 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Source path %s is not absolute.", source
);
2366 if (!path_is_absolute(destination
))
2367 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Destination path %s is not absolute.", destination
);
2368 if (!IN_SET(mount_flags
, 0, MS_REC
))
2369 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Unknown mount flags.");
2371 if (mode
!= UNIT_CHECK
) {
2372 r
= bind_mount_add(&c
->bind_mounts
, &c
->n_bind_mounts
,
2374 .source
= strdup(source
),
2375 .destination
= strdup(destination
),
2376 .read_only
= !!strstr(name
, "ReadOnly"),
2377 .recursive
= !!(mount_flags
& MS_REC
),
2378 .ignore_enoent
= ignore_enoent
,
2383 unit_write_drop_in_private_format(
2387 ignore_enoent
? "-" : "",
2390 (mount_flags
& MS_REC
) ? "rbind" : "norbind");
2398 r
= sd_bus_message_exit_container(message
);
2403 bind_mount_free_many(c
->bind_mounts
, c
->n_bind_mounts
);
2404 c
->bind_mounts
= NULL
;
2405 c
->n_bind_mounts
= 0;
2411 ri
= rlimit_from_string(name
);
2413 soft
= endswith(name
, "Soft");
2417 n
= strndupa(name
, soft
- name
);
2418 ri
= rlimit_from_string(n
);
2429 r
= sd_bus_message_read(message
, "t", &rl
);
2433 if (rl
== (uint64_t) -1)
2438 if ((uint64_t) x
!= rl
)
2442 if (mode
!= UNIT_CHECK
) {
2443 _cleanup_free_
char *f
= NULL
;
2446 if (c
->rlimit
[ri
]) {
2447 nl
= *c
->rlimit
[ri
];
2454 /* When the resource limit is not initialized yet, then assign the value to both fields */
2455 nl
= (struct rlimit
) {
2460 r
= rlimit_format(&nl
, &f
);
2465 *c
->rlimit
[ri
] = nl
;
2467 c
->rlimit
[ri
] = newdup(struct rlimit
, &nl
, 1);
2472 unit_write_drop_in_private_format(u
, mode
, name
, "%s=%s", name
, f
);