]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/core/dbus-execute.c
meson: stop setting the linker (#6182)
[thirdparty/systemd.git] / src / core / dbus-execute.c
CommitLineData
4139c1b2
LP
1/***
2 This file is part of systemd.
3
4 Copyright 2010 Lennart Poettering
5
6 systemd is free software; you can redistribute it and/or modify it
5430f7f2
LP
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
4139c1b2
LP
9 (at your option) any later version.
10
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
5430f7f2 14 Lesser General Public License for more details.
4139c1b2 15
5430f7f2 16 You should have received a copy of the GNU Lesser General Public License
4139c1b2
LP
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
18***/
19
82c121a4 20#include <sys/prctl.h>
4139c1b2 21
57183d11
LP
22#ifdef HAVE_SECCOMP
23#include <seccomp.h>
24#endif
25
3ffd4af2 26#include "af-list.h"
b5efdb8a 27#include "alloc-util.h"
718db961 28#include "bus-util.h"
430f0182 29#include "capability-util.h"
3ffd4af2 30#include "dbus-execute.h"
c7040b5d 31#include "env-util.h"
3ffd4af2
LP
32#include "execute.h"
33#include "fd-util.h"
34#include "fileio.h"
35#include "ioprio.h"
36#include "missing.h"
83555251 37#include "mount-util.h"
417116f2 38#include "namespace.h"
6bedfcbb 39#include "parse-util.h"
9b15b784 40#include "path-util.h"
7b3e062c 41#include "process-util.h"
78f22b97 42#include "rlimit-util.h"
57183d11
LP
43#ifdef HAVE_SECCOMP
44#include "seccomp-util.h"
45#endif
6bedfcbb 46#include "strv.h"
7ccbd1ae 47#include "syslog-util.h"
f900f582 48#include "unit-printf.h"
6f3e7985 49#include "user-util.h"
6bedfcbb 50#include "utf8.h"
57183d11 51
718db961 52BUS_DEFINE_PROPERTY_GET_ENUM(bus_property_get_exec_output, exec_output, ExecOutput);
82c121a4 53
718db961 54static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_input, exec_input, ExecInput);
8c7be95e 55
023a4f67
LP
56static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_utmp_mode, exec_utmp_mode, ExecUtmpMode);
57
1b8689f9
LP
58static BUS_DEFINE_PROPERTY_GET_ENUM(bus_property_get_protect_home, protect_home, ProtectHome);
59static BUS_DEFINE_PROPERTY_GET_ENUM(bus_property_get_protect_system, protect_system, ProtectSystem);
417116f2 60
718db961
LP
61static int property_get_environment_files(
62 sd_bus *bus,
63 const char *path,
64 const char *interface,
65 const char *property,
66 sd_bus_message *reply,
ebcf1f97
LP
67 void *userdata,
68 sd_bus_error *error) {
8c7be95e 69
718db961
LP
70 ExecContext *c = userdata;
71 char **j;
72 int r;
8c7be95e 73
718db961
LP
74 assert(bus);
75 assert(reply);
76 assert(c);
77
78 r = sd_bus_message_open_container(reply, 'a', "(sb)");
79 if (r < 0)
80 return r;
8c7be95e 81
718db961
LP
82 STRV_FOREACH(j, c->environment_files) {
83 const char *fn = *j;
8c7be95e 84
718db961
LP
85 r = sd_bus_message_append(reply, "(sb)", fn[0] == '-' ? fn + 1 : fn, fn[0] == '-');
86 if (r < 0)
87 return r;
8c7be95e
LP
88 }
89
718db961
LP
90 return sd_bus_message_close_container(reply);
91}
92
718db961
LP
93static int property_get_oom_score_adjust(
94 sd_bus *bus,
95 const char *path,
96 const char *interface,
97 const char *property,
98 sd_bus_message *reply,
ebcf1f97
LP
99 void *userdata,
100 sd_bus_error *error) {
718db961
LP
101
102
103 ExecContext *c = userdata;
82c121a4
LP
104 int32_t n;
105
718db961
LP
106 assert(bus);
107 assert(reply);
82c121a4
LP
108 assert(c);
109
dd6c17b1
LP
110 if (c->oom_score_adjust_set)
111 n = c->oom_score_adjust;
82c121a4 112 else {
68eda4bd 113 _cleanup_free_ char *t = NULL;
82c121a4
LP
114
115 n = 0;
718db961 116 if (read_one_line_file("/proc/self/oom_score_adj", &t) >= 0)
e4e73a63 117 safe_atoi32(t, &n);
82c121a4
LP
118 }
119
718db961 120 return sd_bus_message_append(reply, "i", n);
82c121a4
LP
121}
122
718db961
LP
123static int property_get_nice(
124 sd_bus *bus,
125 const char *path,
126 const char *interface,
127 const char *property,
128 sd_bus_message *reply,
ebcf1f97
LP
129 void *userdata,
130 sd_bus_error *error) {
718db961
LP
131
132
133 ExecContext *c = userdata;
82c121a4
LP
134 int32_t n;
135
718db961
LP
136 assert(bus);
137 assert(reply);
82c121a4
LP
138 assert(c);
139
140 if (c->nice_set)
141 n = c->nice;
718db961
LP
142 else {
143 errno = 0;
82c121a4 144 n = getpriority(PRIO_PROCESS, 0);
b3267152 145 if (errno > 0)
718db961
LP
146 n = 0;
147 }
82c121a4 148
718db961 149 return sd_bus_message_append(reply, "i", n);
82c121a4
LP
150}
151
718db961
LP
152static int property_get_ioprio(
153 sd_bus *bus,
154 const char *path,
155 const char *interface,
156 const char *property,
157 sd_bus_message *reply,
ebcf1f97
LP
158 void *userdata,
159 sd_bus_error *error) {
718db961
LP
160
161
162 ExecContext *c = userdata;
82c121a4
LP
163 int32_t n;
164
718db961
LP
165 assert(bus);
166 assert(reply);
82c121a4
LP
167 assert(c);
168
169 if (c->ioprio_set)
170 n = c->ioprio;
718db961 171 else {
82c121a4 172 n = ioprio_get(IOPRIO_WHO_PROCESS, 0);
718db961
LP
173 if (n < 0)
174 n = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 4);
175 }
82c121a4 176
718db961 177 return sd_bus_message_append(reply, "i", n);
82c121a4
LP
178}
179
718db961
LP
180static int property_get_cpu_sched_policy(
181 sd_bus *bus,
182 const char *path,
183 const char *interface,
184 const char *property,
185 sd_bus_message *reply,
ebcf1f97
LP
186 void *userdata,
187 sd_bus_error *error) {
718db961
LP
188
189 ExecContext *c = userdata;
82c121a4
LP
190 int32_t n;
191
718db961
LP
192 assert(bus);
193 assert(reply);
82c121a4
LP
194 assert(c);
195
196 if (c->cpu_sched_set)
197 n = c->cpu_sched_policy;
718db961 198 else {
82c121a4 199 n = sched_getscheduler(0);
718db961
LP
200 if (n < 0)
201 n = SCHED_OTHER;
202 }
82c121a4 203
718db961 204 return sd_bus_message_append(reply, "i", n);
82c121a4
LP
205}
206
718db961
LP
207static int property_get_cpu_sched_priority(
208 sd_bus *bus,
209 const char *path,
210 const char *interface,
211 const char *property,
212 sd_bus_message *reply,
ebcf1f97
LP
213 void *userdata,
214 sd_bus_error *error) {
718db961
LP
215
216 ExecContext *c = userdata;
82c121a4
LP
217 int32_t n;
218
718db961
LP
219 assert(bus);
220 assert(reply);
82c121a4
LP
221 assert(c);
222
223 if (c->cpu_sched_set)
224 n = c->cpu_sched_priority;
225 else {
b92bea5d 226 struct sched_param p = {};
82c121a4 227
82c121a4
LP
228 if (sched_getparam(0, &p) >= 0)
229 n = p.sched_priority;
e62d8c39
ZJS
230 else
231 n = 0;
82c121a4
LP
232 }
233
718db961 234 return sd_bus_message_append(reply, "i", n);
82c121a4
LP
235}
236
718db961
LP
237static int property_get_cpu_affinity(
238 sd_bus *bus,
239 const char *path,
240 const char *interface,
241 const char *property,
242 sd_bus_message *reply,
ebcf1f97
LP
243 void *userdata,
244 sd_bus_error *error) {
82c121a4 245
718db961 246 ExecContext *c = userdata;
82c121a4 247
718db961
LP
248 assert(bus);
249 assert(reply);
250 assert(c);
82c121a4
LP
251
252 if (c->cpuset)
718db961 253 return sd_bus_message_append_array(reply, 'y', c->cpuset, CPU_ALLOC_SIZE(c->cpuset_ncpus));
82c121a4 254 else
718db961 255 return sd_bus_message_append_array(reply, 'y', NULL, 0);
82c121a4
LP
256}
257
718db961
LP
258static int property_get_timer_slack_nsec(
259 sd_bus *bus,
260 const char *path,
261 const char *interface,
262 const char *property,
263 sd_bus_message *reply,
ebcf1f97
LP
264 void *userdata,
265 sd_bus_error *error) {
718db961
LP
266
267 ExecContext *c = userdata;
82c121a4
LP
268 uint64_t u;
269
718db961
LP
270 assert(bus);
271 assert(reply);
82c121a4
LP
272 assert(c);
273
3a43da28 274 if (c->timer_slack_nsec != NSEC_INFINITY)
03fae018 275 u = (uint64_t) c->timer_slack_nsec;
82c121a4
LP
276 else
277 u = (uint64_t) prctl(PR_GET_TIMERSLACK);
278
718db961 279 return sd_bus_message_append(reply, "t", u);
82c121a4
LP
280}
281
718db961
LP
282static int property_get_capability_bounding_set(
283 sd_bus *bus,
284 const char *path,
285 const char *interface,
286 const char *property,
287 sd_bus_message *reply,
ebcf1f97
LP
288 void *userdata,
289 sd_bus_error *error) {
260abb78 290
718db961
LP
291 ExecContext *c = userdata;
292
293 assert(bus);
294 assert(reply);
260abb78
LP
295 assert(c);
296
a103496c 297 return sd_bus_message_append(reply, "t", c->capability_bounding_set);
260abb78
LP
298}
299
755d4b67
IP
300static int property_get_ambient_capabilities(
301 sd_bus *bus,
302 const char *path,
303 const char *interface,
304 const char *property,
305 sd_bus_message *reply,
306 void *userdata,
307 sd_bus_error *error) {
308
309 ExecContext *c = userdata;
310
311 assert(bus);
312 assert(reply);
313 assert(c);
314
315 return sd_bus_message_append(reply, "t", c->capability_ambient_set);
316}
317
479050b3 318static int property_get_empty_string(
718db961
LP
319 sd_bus *bus,
320 const char *path,
321 const char *interface,
322 const char *property,
323 sd_bus_message *reply,
ebcf1f97
LP
324 void *userdata,
325 sd_bus_error *error) {
718db961 326
718db961
LP
327 assert(bus);
328 assert(reply);
82c121a4 329
479050b3 330 return sd_bus_message_append(reply, "s", "");
82c121a4
LP
331}
332
718db961
LP
333static int property_get_syscall_filter(
334 sd_bus *bus,
335 const char *path,
336 const char *interface,
337 const char *property,
338 sd_bus_message *reply,
ebcf1f97
LP
339 void *userdata,
340 sd_bus_error *error) {
82c121a4 341
17df7223
LP
342 ExecContext *c = userdata;
343 _cleanup_strv_free_ char **l = NULL;
57183d11
LP
344 int r;
345
351a19b1 346#ifdef HAVE_SECCOMP
17df7223
LP
347 Iterator i;
348 void *id;
351a19b1 349#endif
17df7223
LP
350
351 assert(bus);
352 assert(reply);
353 assert(c);
354
57183d11
LP
355 r = sd_bus_message_open_container(reply, 'r', "bas");
356 if (r < 0)
357 return r;
358
359 r = sd_bus_message_append(reply, "b", c->syscall_whitelist);
360 if (r < 0)
361 return r;
362
351a19b1 363#ifdef HAVE_SECCOMP
17df7223
LP
364 SET_FOREACH(id, c->syscall_filter, i) {
365 char *name;
366
367 name = seccomp_syscall_resolve_num_arch(SCMP_ARCH_NATIVE, PTR_TO_INT(id) - 1);
368 if (!name)
369 continue;
370
6e18964d
ZJS
371 r = strv_consume(&l, name);
372 if (r < 0)
373 return r;
17df7223 374 }
351a19b1 375#endif
17df7223
LP
376
377 strv_sort(l);
378
57183d11
LP
379 r = sd_bus_message_append_strv(reply, l);
380 if (r < 0)
381 return r;
17df7223 382
57183d11
LP
383 return sd_bus_message_close_container(reply);
384}
17df7223 385
57183d11
LP
386static int property_get_syscall_archs(
387 sd_bus *bus,
388 const char *path,
389 const char *interface,
390 const char *property,
391 sd_bus_message *reply,
392 void *userdata,
393 sd_bus_error *error) {
394
395 ExecContext *c = userdata;
396 _cleanup_strv_free_ char **l = NULL;
397 int r;
398
399#ifdef HAVE_SECCOMP
400 Iterator i;
401 void *id;
402#endif
403
404 assert(bus);
405 assert(reply);
406 assert(c);
17df7223 407
57183d11
LP
408#ifdef HAVE_SECCOMP
409 SET_FOREACH(id, c->syscall_archs, i) {
410 const char *name;
411
412 name = seccomp_arch_to_string(PTR_TO_UINT32(id) - 1);
413 if (!name)
414 continue;
415
416 r = strv_extend(&l, name);
417 if (r < 0)
418 return -ENOMEM;
17df7223 419 }
57183d11
LP
420#endif
421
422 strv_sort(l);
423
424 r = sd_bus_message_append_strv(reply, l);
425 if (r < 0)
426 return r;
17df7223 427
57183d11 428 return 0;
17df7223
LP
429}
430
431static int property_get_syscall_errno(
432 sd_bus *bus,
433 const char *path,
434 const char *interface,
435 const char *property,
436 sd_bus_message *reply,
437 void *userdata,
438 sd_bus_error *error) {
439
718db961 440 ExecContext *c = userdata;
82c121a4 441
718db961
LP
442 assert(bus);
443 assert(reply);
444 assert(c);
82c121a4 445
17df7223 446 return sd_bus_message_append(reply, "i", (int32_t) c->syscall_errno);
718db961 447}
82c121a4 448
5f8640fb
LP
449static int property_get_selinux_context(
450 sd_bus *bus,
451 const char *path,
452 const char *interface,
453 const char *property,
454 sd_bus_message *reply,
455 void *userdata,
456 sd_bus_error *error) {
457
458 ExecContext *c = userdata;
459
460 assert(bus);
461 assert(reply);
462 assert(c);
463
464 return sd_bus_message_append(reply, "(bs)", c->selinux_context_ignore, c->selinux_context);
465}
466
eef65bf3
MS
467static int property_get_apparmor_profile(
468 sd_bus *bus,
469 const char *path,
470 const char *interface,
471 const char *property,
472 sd_bus_message *reply,
473 void *userdata,
474 sd_bus_error *error) {
475
476 ExecContext *c = userdata;
477
478 assert(bus);
479 assert(reply);
480 assert(c);
481
482 return sd_bus_message_append(reply, "(bs)", c->apparmor_profile_ignore, c->apparmor_profile);
483}
484
2ca620c4
WC
485static int property_get_smack_process_label(
486 sd_bus *bus,
487 const char *path,
488 const char *interface,
489 const char *property,
490 sd_bus_message *reply,
491 void *userdata,
492 sd_bus_error *error) {
493
494 ExecContext *c = userdata;
495
496 assert(bus);
497 assert(reply);
498 assert(c);
499
500 return sd_bus_message_append(reply, "(bs)", c->smack_process_label_ignore, c->smack_process_label);
501}
502
ac45f971
LP
503static int property_get_personality(
504 sd_bus *bus,
505 const char *path,
506 const char *interface,
507 const char *property,
508 sd_bus_message *reply,
509 void *userdata,
510 sd_bus_error *error) {
511
512 ExecContext *c = userdata;
513
514 assert(bus);
515 assert(reply);
516 assert(c);
517
518 return sd_bus_message_append(reply, "s", personality_to_string(c->personality));
519}
520
4298d0b5
LP
521static int property_get_address_families(
522 sd_bus *bus,
523 const char *path,
524 const char *interface,
525 const char *property,
526 sd_bus_message *reply,
527 void *userdata,
528 sd_bus_error *error) {
529
530 ExecContext *c = userdata;
531 _cleanup_strv_free_ char **l = NULL;
532 Iterator i;
533 void *af;
534 int r;
535
536 assert(bus);
537 assert(reply);
538 assert(c);
539
540 r = sd_bus_message_open_container(reply, 'r', "bas");
541 if (r < 0)
542 return r;
543
544 r = sd_bus_message_append(reply, "b", c->address_families_whitelist);
545 if (r < 0)
546 return r;
547
548 SET_FOREACH(af, c->address_families, i) {
549 const char *name;
550
551 name = af_to_name(PTR_TO_INT(af));
552 if (!name)
553 continue;
554
555 r = strv_extend(&l, name);
556 if (r < 0)
557 return -ENOMEM;
558 }
559
560 strv_sort(l);
561
562 r = sd_bus_message_append_strv(reply, l);
563 if (r < 0)
564 return r;
565
566 return sd_bus_message_close_container(reply);
567}
568
5f5d8eab
LP
569static int property_get_working_directory(
570 sd_bus *bus,
571 const char *path,
572 const char *interface,
573 const char *property,
574 sd_bus_message *reply,
575 void *userdata,
576 sd_bus_error *error) {
577
578 ExecContext *c = userdata;
579 const char *wd;
580
581 assert(bus);
582 assert(reply);
583 assert(c);
584
585 if (c->working_directory_home)
586 wd = "~";
587 else
588 wd = c->working_directory;
589
590 if (c->working_directory_missing_ok)
591 wd = strjoina("!", wd);
592
593 return sd_bus_message_append(reply, "s", wd);
594}
595
06f2ccf9
EV
596static int property_get_syslog_level(
597 sd_bus *bus,
598 const char *path,
599 const char *interface,
600 const char *property,
601 sd_bus_message *reply,
602 void *userdata,
603 sd_bus_error *error) {
604
605 ExecContext *c = userdata;
606
607 assert(bus);
608 assert(reply);
609 assert(c);
610
611 return sd_bus_message_append(reply, "i", LOG_PRI(c->syslog_priority));
612}
613
614static int property_get_syslog_facility(
615 sd_bus *bus,
616 const char *path,
617 const char *interface,
618 const char *property,
619 sd_bus_message *reply,
620 void *userdata,
621 sd_bus_error *error) {
622
623 ExecContext *c = userdata;
624
625 assert(bus);
626 assert(reply);
627 assert(c);
628
629 return sd_bus_message_append(reply, "i", LOG_FAC(c->syslog_priority));
630}
631
52c239d7
LB
632static int property_get_input_fdname(
633 sd_bus *bus,
634 const char *path,
635 const char *interface,
636 const char *property,
637 sd_bus_message *reply,
638 void *userdata,
639 sd_bus_error *error) {
640
641 ExecContext *c = userdata;
642 const char *name;
643
644 assert(bus);
645 assert(c);
646 assert(property);
647 assert(reply);
648
649 name = exec_context_fdname(c, STDIN_FILENO);
650
651 return sd_bus_message_append(reply, "s", name);
652}
653
654static int property_get_output_fdname(
655 sd_bus *bus,
656 const char *path,
657 const char *interface,
658 const char *property,
659 sd_bus_message *reply,
660 void *userdata,
661 sd_bus_error *error) {
662
663 ExecContext *c = userdata;
664 const char *name = NULL;
665
666 assert(bus);
667 assert(c);
668 assert(property);
669 assert(reply);
670
671 if (c->std_output == EXEC_OUTPUT_NAMED_FD && streq(property, "StandardOutputFileDescriptorName"))
672 name = exec_context_fdname(c, STDOUT_FILENO);
673 else if (c->std_error == EXEC_OUTPUT_NAMED_FD && streq(property, "StandardErrorFileDescriptorName"))
674 name = exec_context_fdname(c, STDERR_FILENO);
675
676 return sd_bus_message_append(reply, "s", name);
677}
678
d2d6c096
LP
679static int property_get_bind_paths(
680 sd_bus *bus,
681 const char *path,
682 const char *interface,
683 const char *property,
684 sd_bus_message *reply,
685 void *userdata,
686 sd_bus_error *error) {
687
688 ExecContext *c = userdata;
689 unsigned i;
690 bool ro;
691 int r;
692
693 assert(bus);
694 assert(c);
695 assert(property);
696 assert(reply);
697
698 ro = !!strstr(property, "ReadOnly");
699
700 r = sd_bus_message_open_container(reply, 'a', "(ssbt)");
701 if (r < 0)
702 return r;
703
704 for (i = 0; i < c->n_bind_mounts; i++) {
705
706 if (ro != c->bind_mounts[i].read_only)
707 continue;
708
709 r = sd_bus_message_append(
710 reply, "(ssbt)",
711 c->bind_mounts[i].source,
712 c->bind_mounts[i].destination,
713 c->bind_mounts[i].ignore_enoent,
c9b06108 714 c->bind_mounts[i].recursive ? (uint64_t) MS_REC : (uint64_t) 0);
d2d6c096
LP
715 if (r < 0)
716 return r;
717 }
718
719 return sd_bus_message_close_container(reply);
720}
721
718db961
LP
722const sd_bus_vtable bus_exec_vtable[] = {
723 SD_BUS_VTABLE_START(0),
556089dc
LP
724 SD_BUS_PROPERTY("Environment", "as", NULL, offsetof(ExecContext, environment), SD_BUS_VTABLE_PROPERTY_CONST),
725 SD_BUS_PROPERTY("EnvironmentFiles", "a(sb)", property_get_environment_files, 0, SD_BUS_VTABLE_PROPERTY_CONST),
b4c14404 726 SD_BUS_PROPERTY("PassEnvironment", "as", NULL, offsetof(ExecContext, pass_environment), SD_BUS_VTABLE_PROPERTY_CONST),
556089dc 727 SD_BUS_PROPERTY("UMask", "u", bus_property_get_mode, offsetof(ExecContext, umask), SD_BUS_VTABLE_PROPERTY_CONST),
c9d031c3 728 SD_BUS_PROPERTY("LimitCPU", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_CPU]), SD_BUS_VTABLE_PROPERTY_CONST),
147f6858 729 SD_BUS_PROPERTY("LimitCPUSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_CPU]), SD_BUS_VTABLE_PROPERTY_CONST),
c9d031c3 730 SD_BUS_PROPERTY("LimitFSIZE", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_FSIZE]), SD_BUS_VTABLE_PROPERTY_CONST),
147f6858 731 SD_BUS_PROPERTY("LimitFSIZESoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_FSIZE]), SD_BUS_VTABLE_PROPERTY_CONST),
c9d031c3 732 SD_BUS_PROPERTY("LimitDATA", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_DATA]), SD_BUS_VTABLE_PROPERTY_CONST),
147f6858 733 SD_BUS_PROPERTY("LimitDATASoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_DATA]), SD_BUS_VTABLE_PROPERTY_CONST),
c9d031c3 734 SD_BUS_PROPERTY("LimitSTACK", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_STACK]), SD_BUS_VTABLE_PROPERTY_CONST),
147f6858 735 SD_BUS_PROPERTY("LimitSTACKSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_STACK]), SD_BUS_VTABLE_PROPERTY_CONST),
c9d031c3 736 SD_BUS_PROPERTY("LimitCORE", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_CORE]), SD_BUS_VTABLE_PROPERTY_CONST),
147f6858 737 SD_BUS_PROPERTY("LimitCORESoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_CORE]), SD_BUS_VTABLE_PROPERTY_CONST),
c9d031c3 738 SD_BUS_PROPERTY("LimitRSS", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RSS]), SD_BUS_VTABLE_PROPERTY_CONST),
147f6858 739 SD_BUS_PROPERTY("LimitRSSSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RSS]), SD_BUS_VTABLE_PROPERTY_CONST),
c9d031c3 740 SD_BUS_PROPERTY("LimitNOFILE", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NOFILE]), SD_BUS_VTABLE_PROPERTY_CONST),
147f6858 741 SD_BUS_PROPERTY("LimitNOFILESoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NOFILE]), SD_BUS_VTABLE_PROPERTY_CONST),
c9d031c3 742 SD_BUS_PROPERTY("LimitAS", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_AS]), SD_BUS_VTABLE_PROPERTY_CONST),
147f6858 743 SD_BUS_PROPERTY("LimitASSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_AS]), SD_BUS_VTABLE_PROPERTY_CONST),
c9d031c3 744 SD_BUS_PROPERTY("LimitNPROC", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NPROC]), SD_BUS_VTABLE_PROPERTY_CONST),
147f6858 745 SD_BUS_PROPERTY("LimitNPROCSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NPROC]), SD_BUS_VTABLE_PROPERTY_CONST),
c9d031c3 746 SD_BUS_PROPERTY("LimitMEMLOCK", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_MEMLOCK]), SD_BUS_VTABLE_PROPERTY_CONST),
147f6858 747 SD_BUS_PROPERTY("LimitMEMLOCKSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_MEMLOCK]), SD_BUS_VTABLE_PROPERTY_CONST),
c9d031c3 748 SD_BUS_PROPERTY("LimitLOCKS", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_LOCKS]), SD_BUS_VTABLE_PROPERTY_CONST),
147f6858 749 SD_BUS_PROPERTY("LimitLOCKSSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_LOCKS]), SD_BUS_VTABLE_PROPERTY_CONST),
c9d031c3 750 SD_BUS_PROPERTY("LimitSIGPENDING", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_SIGPENDING]), SD_BUS_VTABLE_PROPERTY_CONST),
147f6858 751 SD_BUS_PROPERTY("LimitSIGPENDINGSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_SIGPENDING]), SD_BUS_VTABLE_PROPERTY_CONST),
c9d031c3 752 SD_BUS_PROPERTY("LimitMSGQUEUE", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_MSGQUEUE]), SD_BUS_VTABLE_PROPERTY_CONST),
147f6858 753 SD_BUS_PROPERTY("LimitMSGQUEUESoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_MSGQUEUE]), SD_BUS_VTABLE_PROPERTY_CONST),
c9d031c3 754 SD_BUS_PROPERTY("LimitNICE", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NICE]), SD_BUS_VTABLE_PROPERTY_CONST),
147f6858 755 SD_BUS_PROPERTY("LimitNICESoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NICE]), SD_BUS_VTABLE_PROPERTY_CONST),
c9d031c3 756 SD_BUS_PROPERTY("LimitRTPRIO", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RTPRIO]), SD_BUS_VTABLE_PROPERTY_CONST),
147f6858 757 SD_BUS_PROPERTY("LimitRTPRIOSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RTPRIO]), SD_BUS_VTABLE_PROPERTY_CONST),
c9d031c3 758 SD_BUS_PROPERTY("LimitRTTIME", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RTTIME]), SD_BUS_VTABLE_PROPERTY_CONST),
147f6858 759 SD_BUS_PROPERTY("LimitRTTIMESoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RTTIME]), SD_BUS_VTABLE_PROPERTY_CONST),
5f5d8eab 760 SD_BUS_PROPERTY("WorkingDirectory", "s", property_get_working_directory, 0, SD_BUS_VTABLE_PROPERTY_CONST),
556089dc 761 SD_BUS_PROPERTY("RootDirectory", "s", NULL, offsetof(ExecContext, root_directory), SD_BUS_VTABLE_PROPERTY_CONST),
915e6d16 762 SD_BUS_PROPERTY("RootImage", "s", NULL, offsetof(ExecContext, root_image), SD_BUS_VTABLE_PROPERTY_CONST),
556089dc
LP
763 SD_BUS_PROPERTY("OOMScoreAdjust", "i", property_get_oom_score_adjust, 0, SD_BUS_VTABLE_PROPERTY_CONST),
764 SD_BUS_PROPERTY("Nice", "i", property_get_nice, 0, SD_BUS_VTABLE_PROPERTY_CONST),
765 SD_BUS_PROPERTY("IOScheduling", "i", property_get_ioprio, 0, SD_BUS_VTABLE_PROPERTY_CONST),
766 SD_BUS_PROPERTY("CPUSchedulingPolicy", "i", property_get_cpu_sched_policy, 0, SD_BUS_VTABLE_PROPERTY_CONST),
767 SD_BUS_PROPERTY("CPUSchedulingPriority", "i", property_get_cpu_sched_priority, 0, SD_BUS_VTABLE_PROPERTY_CONST),
768 SD_BUS_PROPERTY("CPUAffinity", "ay", property_get_cpu_affinity, 0, SD_BUS_VTABLE_PROPERTY_CONST),
769 SD_BUS_PROPERTY("TimerSlackNSec", "t", property_get_timer_slack_nsec, 0, SD_BUS_VTABLE_PROPERTY_CONST),
770 SD_BUS_PROPERTY("CPUSchedulingResetOnFork", "b", bus_property_get_bool, offsetof(ExecContext, cpu_sched_reset_on_fork), SD_BUS_VTABLE_PROPERTY_CONST),
771 SD_BUS_PROPERTY("NonBlocking", "b", bus_property_get_bool, offsetof(ExecContext, non_blocking), SD_BUS_VTABLE_PROPERTY_CONST),
772 SD_BUS_PROPERTY("StandardInput", "s", property_get_exec_input, offsetof(ExecContext, std_input), SD_BUS_VTABLE_PROPERTY_CONST),
52c239d7 773 SD_BUS_PROPERTY("StandardInputFileDescriptorName", "s", property_get_input_fdname, 0, SD_BUS_VTABLE_PROPERTY_CONST),
556089dc 774 SD_BUS_PROPERTY("StandardOutput", "s", bus_property_get_exec_output, offsetof(ExecContext, std_output), SD_BUS_VTABLE_PROPERTY_CONST),
52c239d7 775 SD_BUS_PROPERTY("StandardOutputFileDescriptorName", "s", property_get_output_fdname, 0, SD_BUS_VTABLE_PROPERTY_CONST),
556089dc 776 SD_BUS_PROPERTY("StandardError", "s", bus_property_get_exec_output, offsetof(ExecContext, std_error), SD_BUS_VTABLE_PROPERTY_CONST),
52c239d7 777 SD_BUS_PROPERTY("StandardErrorFileDescriptorName", "s", property_get_output_fdname, 0, SD_BUS_VTABLE_PROPERTY_CONST),
556089dc
LP
778 SD_BUS_PROPERTY("TTYPath", "s", NULL, offsetof(ExecContext, tty_path), SD_BUS_VTABLE_PROPERTY_CONST),
779 SD_BUS_PROPERTY("TTYReset", "b", bus_property_get_bool, offsetof(ExecContext, tty_reset), SD_BUS_VTABLE_PROPERTY_CONST),
780 SD_BUS_PROPERTY("TTYVHangup", "b", bus_property_get_bool, offsetof(ExecContext, tty_vhangup), SD_BUS_VTABLE_PROPERTY_CONST),
781 SD_BUS_PROPERTY("TTYVTDisallocate", "b", bus_property_get_bool, offsetof(ExecContext, tty_vt_disallocate), SD_BUS_VTABLE_PROPERTY_CONST),
782 SD_BUS_PROPERTY("SyslogPriority", "i", bus_property_get_int, offsetof(ExecContext, syslog_priority), SD_BUS_VTABLE_PROPERTY_CONST),
783 SD_BUS_PROPERTY("SyslogIdentifier", "s", NULL, offsetof(ExecContext, syslog_identifier), SD_BUS_VTABLE_PROPERTY_CONST),
784 SD_BUS_PROPERTY("SyslogLevelPrefix", "b", bus_property_get_bool, offsetof(ExecContext, syslog_level_prefix), SD_BUS_VTABLE_PROPERTY_CONST),
06f2ccf9
EV
785 SD_BUS_PROPERTY("SyslogLevel", "i", property_get_syslog_level, 0, SD_BUS_VTABLE_PROPERTY_CONST),
786 SD_BUS_PROPERTY("SyslogFacility", "i", property_get_syslog_facility, 0, SD_BUS_VTABLE_PROPERTY_CONST),
479050b3 787 SD_BUS_PROPERTY("Capabilities", "s", property_get_empty_string, 0, SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN),
556089dc
LP
788 SD_BUS_PROPERTY("SecureBits", "i", bus_property_get_int, offsetof(ExecContext, secure_bits), SD_BUS_VTABLE_PROPERTY_CONST),
789 SD_BUS_PROPERTY("CapabilityBoundingSet", "t", property_get_capability_bounding_set, 0, SD_BUS_VTABLE_PROPERTY_CONST),
755d4b67 790 SD_BUS_PROPERTY("AmbientCapabilities", "t", property_get_ambient_capabilities, 0, SD_BUS_VTABLE_PROPERTY_CONST),
556089dc
LP
791 SD_BUS_PROPERTY("User", "s", NULL, offsetof(ExecContext, user), SD_BUS_VTABLE_PROPERTY_CONST),
792 SD_BUS_PROPERTY("Group", "s", NULL, offsetof(ExecContext, group), SD_BUS_VTABLE_PROPERTY_CONST),
29206d46 793 SD_BUS_PROPERTY("DynamicUser", "b", bus_property_get_bool, offsetof(ExecContext, dynamic_user), SD_BUS_VTABLE_PROPERTY_CONST),
00d9ef85 794 SD_BUS_PROPERTY("RemoveIPC", "b", bus_property_get_bool, offsetof(ExecContext, remove_ipc), SD_BUS_VTABLE_PROPERTY_CONST),
556089dc 795 SD_BUS_PROPERTY("SupplementaryGroups", "as", NULL, offsetof(ExecContext, supplementary_groups), SD_BUS_VTABLE_PROPERTY_CONST),
556089dc 796 SD_BUS_PROPERTY("PAMName", "s", NULL, offsetof(ExecContext, pam_name), SD_BUS_VTABLE_PROPERTY_CONST),
d724118e
LP
797 SD_BUS_PROPERTY("ReadWriteDirectories", "as", NULL, offsetof(ExecContext, read_write_paths), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN),
798 SD_BUS_PROPERTY("ReadOnlyDirectories", "as", NULL, offsetof(ExecContext, read_only_paths), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN),
799 SD_BUS_PROPERTY("InaccessibleDirectories", "as", NULL, offsetof(ExecContext, inaccessible_paths), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN),
2a624c36
AP
800 SD_BUS_PROPERTY("ReadWritePaths", "as", NULL, offsetof(ExecContext, read_write_paths), SD_BUS_VTABLE_PROPERTY_CONST),
801 SD_BUS_PROPERTY("ReadOnlyPaths", "as", NULL, offsetof(ExecContext, read_only_paths), SD_BUS_VTABLE_PROPERTY_CONST),
802 SD_BUS_PROPERTY("InaccessiblePaths", "as", NULL, offsetof(ExecContext, inaccessible_paths), SD_BUS_VTABLE_PROPERTY_CONST),
556089dc
LP
803 SD_BUS_PROPERTY("MountFlags", "t", bus_property_get_ulong, offsetof(ExecContext, mount_flags), SD_BUS_VTABLE_PROPERTY_CONST),
804 SD_BUS_PROPERTY("PrivateTmp", "b", bus_property_get_bool, offsetof(ExecContext, private_tmp), SD_BUS_VTABLE_PROPERTY_CONST),
7f112f50 805 SD_BUS_PROPERTY("PrivateDevices", "b", bus_property_get_bool, offsetof(ExecContext, private_devices), SD_BUS_VTABLE_PROPERTY_CONST),
59eeb84b 806 SD_BUS_PROPERTY("ProtectKernelTunables", "b", bus_property_get_bool, offsetof(ExecContext, protect_kernel_tunables), SD_BUS_VTABLE_PROPERTY_CONST),
502d704e 807 SD_BUS_PROPERTY("ProtectKernelModules", "b", bus_property_get_bool, offsetof(ExecContext, protect_kernel_modules), SD_BUS_VTABLE_PROPERTY_CONST),
59eeb84b 808 SD_BUS_PROPERTY("ProtectControlGroups", "b", bus_property_get_bool, offsetof(ExecContext, protect_control_groups), SD_BUS_VTABLE_PROPERTY_CONST),
d251207d
LP
809 SD_BUS_PROPERTY("PrivateNetwork", "b", bus_property_get_bool, offsetof(ExecContext, private_network), SD_BUS_VTABLE_PROPERTY_CONST),
810 SD_BUS_PROPERTY("PrivateUsers", "b", bus_property_get_bool, offsetof(ExecContext, private_users), SD_BUS_VTABLE_PROPERTY_CONST),
1b8689f9
LP
811 SD_BUS_PROPERTY("ProtectHome", "s", bus_property_get_protect_home, offsetof(ExecContext, protect_home), SD_BUS_VTABLE_PROPERTY_CONST),
812 SD_BUS_PROPERTY("ProtectSystem", "s", bus_property_get_protect_system, offsetof(ExecContext, protect_system), SD_BUS_VTABLE_PROPERTY_CONST),
556089dc
LP
813 SD_BUS_PROPERTY("SameProcessGroup", "b", bus_property_get_bool, offsetof(ExecContext, same_pgrp), SD_BUS_VTABLE_PROPERTY_CONST),
814 SD_BUS_PROPERTY("UtmpIdentifier", "s", NULL, offsetof(ExecContext, utmp_id), SD_BUS_VTABLE_PROPERTY_CONST),
023a4f67 815 SD_BUS_PROPERTY("UtmpMode", "s", property_get_exec_utmp_mode, offsetof(ExecContext, utmp_mode), SD_BUS_VTABLE_PROPERTY_CONST),
5f8640fb 816 SD_BUS_PROPERTY("SELinuxContext", "(bs)", property_get_selinux_context, 0, SD_BUS_VTABLE_PROPERTY_CONST),
eef65bf3 817 SD_BUS_PROPERTY("AppArmorProfile", "(bs)", property_get_apparmor_profile, 0, SD_BUS_VTABLE_PROPERTY_CONST),
2ca620c4 818 SD_BUS_PROPERTY("SmackProcessLabel", "(bs)", property_get_smack_process_label, 0, SD_BUS_VTABLE_PROPERTY_CONST),
556089dc
LP
819 SD_BUS_PROPERTY("IgnoreSIGPIPE", "b", bus_property_get_bool, offsetof(ExecContext, ignore_sigpipe), SD_BUS_VTABLE_PROPERTY_CONST),
820 SD_BUS_PROPERTY("NoNewPrivileges", "b", bus_property_get_bool, offsetof(ExecContext, no_new_privileges), SD_BUS_VTABLE_PROPERTY_CONST),
57183d11
LP
821 SD_BUS_PROPERTY("SystemCallFilter", "(bas)", property_get_syscall_filter, 0, SD_BUS_VTABLE_PROPERTY_CONST),
822 SD_BUS_PROPERTY("SystemCallArchitectures", "as", property_get_syscall_archs, 0, SD_BUS_VTABLE_PROPERTY_CONST),
17df7223 823 SD_BUS_PROPERTY("SystemCallErrorNumber", "i", property_get_syscall_errno, 0, SD_BUS_VTABLE_PROPERTY_CONST),
ac45f971 824 SD_BUS_PROPERTY("Personality", "s", property_get_personality, 0, SD_BUS_VTABLE_PROPERTY_CONST),
4298d0b5 825 SD_BUS_PROPERTY("RestrictAddressFamilies", "(bas)", property_get_address_families, 0, SD_BUS_VTABLE_PROPERTY_CONST),
e66cf1a3
LP
826 SD_BUS_PROPERTY("RuntimeDirectoryMode", "u", bus_property_get_mode, offsetof(ExecContext, runtime_directory_mode), SD_BUS_VTABLE_PROPERTY_CONST),
827 SD_BUS_PROPERTY("RuntimeDirectory", "as", NULL, offsetof(ExecContext, runtime_directory), SD_BUS_VTABLE_PROPERTY_CONST),
f3e43635 828 SD_BUS_PROPERTY("MemoryDenyWriteExecute", "b", bus_property_get_bool, offsetof(ExecContext, memory_deny_write_execute), SD_BUS_VTABLE_PROPERTY_CONST),
f4170c67 829 SD_BUS_PROPERTY("RestrictRealtime", "b", bus_property_get_bool, offsetof(ExecContext, restrict_realtime), SD_BUS_VTABLE_PROPERTY_CONST),
6a8c2d59 830 SD_BUS_PROPERTY("RestrictNamespaces", "t", bus_property_get_ulong, offsetof(ExecContext, restrict_namespaces), SD_BUS_VTABLE_PROPERTY_CONST),
d2d6c096
LP
831 SD_BUS_PROPERTY("BindPaths", "a(ssbt)", property_get_bind_paths, 0, SD_BUS_VTABLE_PROPERTY_CONST),
832 SD_BUS_PROPERTY("BindReadOnlyPaths", "a(ssbt)", property_get_bind_paths, 0, SD_BUS_VTABLE_PROPERTY_CONST),
5d997827 833 SD_BUS_PROPERTY("MountAPIVFS", "b", bus_property_get_bool, offsetof(ExecContext, mount_apivfs), SD_BUS_VTABLE_PROPERTY_CONST),
718db961
LP
834 SD_BUS_VTABLE_END
835};
82c121a4 836
4d4c80d0
LP
837static int append_exec_command(sd_bus_message *reply, ExecCommand *c) {
838 int r;
839
840 assert(reply);
841 assert(c);
842
843 if (!c->path)
844 return 0;
845
846 r = sd_bus_message_open_container(reply, 'r', "sasbttttuii");
847 if (r < 0)
848 return r;
849
850 r = sd_bus_message_append(reply, "s", c->path);
851 if (r < 0)
852 return r;
853
854 r = sd_bus_message_append_strv(reply, c->argv);
855 if (r < 0)
856 return r;
857
858 r = sd_bus_message_append(reply, "bttttuii",
859 c->ignore,
860 c->exec_status.start_timestamp.realtime,
861 c->exec_status.start_timestamp.monotonic,
862 c->exec_status.exit_timestamp.realtime,
863 c->exec_status.exit_timestamp.monotonic,
864 (uint32_t) c->exec_status.pid,
865 (int32_t) c->exec_status.code,
866 (int32_t) c->exec_status.status);
867 if (r < 0)
868 return r;
869
870 return sd_bus_message_close_container(reply);
871}
872
718db961
LP
873int bus_property_get_exec_command(
874 sd_bus *bus,
875 const char *path,
876 const char *interface,
877 const char *property,
878 sd_bus_message *reply,
ebcf1f97
LP
879 void *userdata,
880 sd_bus_error *ret_error) {
fe68089d 881
4d4c80d0 882 ExecCommand *c = (ExecCommand*) userdata;
718db961 883 int r;
fe68089d 884
718db961
LP
885 assert(bus);
886 assert(reply);
fe68089d 887
718db961
LP
888 r = sd_bus_message_open_container(reply, 'a', "(sasbttttuii)");
889 if (r < 0)
890 return r;
fe68089d 891
4d4c80d0
LP
892 r = append_exec_command(reply, c);
893 if (r < 0)
894 return r;
fe68089d 895
4d4c80d0
LP
896 return sd_bus_message_close_container(reply);
897}
718db961 898
4d4c80d0
LP
899int bus_property_get_exec_command_list(
900 sd_bus *bus,
901 const char *path,
902 const char *interface,
903 const char *property,
904 sd_bus_message *reply,
905 void *userdata,
906 sd_bus_error *ret_error) {
718db961 907
4d4c80d0
LP
908 ExecCommand *c = *(ExecCommand**) userdata;
909 int r;
718db961 910
4d4c80d0
LP
911 assert(bus);
912 assert(reply);
913
914 r = sd_bus_message_open_container(reply, 'a', "(sasbttttuii)");
915 if (r < 0)
916 return r;
718db961 917
4d4c80d0
LP
918 LIST_FOREACH(command, c, c) {
919 r = append_exec_command(reply, c);
718db961
LP
920 if (r < 0)
921 return r;
fe68089d
LP
922 }
923
718db961 924 return sd_bus_message_close_container(reply);
8351ceae 925}
c7040b5d
LP
926
927int bus_exec_context_set_transient_property(
928 Unit *u,
929 ExecContext *c,
930 const char *name,
931 sd_bus_message *message,
932 UnitSetPropertiesMode mode,
933 sd_bus_error *error) {
934
cab2aca3
LP
935 const char *soft = NULL;
936 int r, ri;
c7040b5d
LP
937
938 assert(u);
939 assert(c);
940 assert(name);
941 assert(message);
942
943 if (streq(name, "User")) {
944 const char *uu;
945
946 r = sd_bus_message_read(message, "s", &uu);
947 if (r < 0)
948 return r;
949
6f3e7985
LP
950 if (!isempty(uu) && !valid_user_group_name_or_id(uu))
951 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid user name: %s", uu);
952
c7040b5d 953 if (mode != UNIT_CHECK) {
76736280
LP
954
955 if (isempty(uu))
956 c->user = mfree(c->user);
957 else if (free_and_strdup(&c->user, uu) < 0)
958 return -ENOMEM;
c7040b5d 959
b27b4b51 960 unit_write_drop_in_private_format(u, mode, name, "User=%s", uu);
c7040b5d
LP
961 }
962
963 return 1;
964
965 } else if (streq(name, "Group")) {
966 const char *gg;
967
968 r = sd_bus_message_read(message, "s", &gg);
969 if (r < 0)
970 return r;
971
6f3e7985
LP
972 if (!isempty(gg) && !valid_user_group_name_or_id(gg))
973 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid group name: %s", gg);
974
c7040b5d 975 if (mode != UNIT_CHECK) {
76736280
LP
976
977 if (isempty(gg))
978 c->group = mfree(c->group);
979 else if (free_and_strdup(&c->group, gg) < 0)
980 return -ENOMEM;
c7040b5d 981
b27b4b51 982 unit_write_drop_in_private_format(u, mode, name, "Group=%s", gg);
c7040b5d
LP
983 }
984
985 return 1;
de53c417
EV
986 } else if (streq(name, "SyslogIdentifier")) {
987 const char *id;
c7040b5d 988
de53c417
EV
989 r = sd_bus_message_read(message, "s", &id);
990 if (r < 0)
991 return r;
992
993 if (mode != UNIT_CHECK) {
76736280
LP
994
995 if (isempty(id))
996 c->syslog_identifier = mfree(c->syslog_identifier);
997 else if (free_and_strdup(&c->syslog_identifier, id) < 0)
998 return -ENOMEM;
de53c417 999
b27b4b51 1000 unit_write_drop_in_private_format(u, mode, name, "SyslogIdentifier=%s", id);
de53c417
EV
1001 }
1002
a8a13575
EV
1003 return 1;
1004 } else if (streq(name, "SyslogLevel")) {
1005 int level;
1006
1007 r = sd_bus_message_read(message, "i", &level);
1008 if (r < 0)
1009 return r;
1010
e0d6e0fa
EV
1011 if (!log_level_is_valid(level))
1012 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Log level value out of range");
1013
a8a13575
EV
1014 if (mode != UNIT_CHECK) {
1015 c->syslog_priority = (c->syslog_priority & LOG_FACMASK) | level;
b27b4b51 1016 unit_write_drop_in_private_format(u, mode, name, "SyslogLevel=%i", level);
a8a13575
EV
1017 }
1018
460ed929
EV
1019 return 1;
1020 } else if (streq(name, "SyslogFacility")) {
1021 int facility;
1022
1023 r = sd_bus_message_read(message, "i", &facility);
1024 if (r < 0)
1025 return r;
1026
e0d6e0fa
EV
1027 if (!log_facility_unshifted_is_valid(facility))
1028 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Log facility value out of range");
1029
460ed929
EV
1030 if (mode != UNIT_CHECK) {
1031 c->syslog_priority = (facility << 3) | LOG_PRI(c->syslog_priority);
b27b4b51 1032 unit_write_drop_in_private_format(u, mode, name, "SyslogFacility=%i", facility);
460ed929
EV
1033 }
1034
de53c417 1035 return 1;
c7040b5d
LP
1036 } else if (streq(name, "Nice")) {
1037 int n;
1038
1039 r = sd_bus_message_read(message, "i", &n);
1040 if (r < 0)
1041 return r;
1042
41bf0590 1043 if (!nice_is_valid(n))
c7040b5d
LP
1044 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Nice value out of range");
1045
1046 if (mode != UNIT_CHECK) {
1047 c->nice = n;
b27b4b51 1048 unit_write_drop_in_private_format(u, mode, name, "Nice=%i", n);
c7040b5d
LP
1049 }
1050
1051 return 1;
1052
915e6d16 1053 } else if (STR_IN_SET(name, "TTYPath", "RootDirectory", "RootImage")) {
602b8355 1054 const char *s;
9b15b784 1055
602b8355 1056 r = sd_bus_message_read(message, "s", &s);
9b15b784
LP
1057 if (r < 0)
1058 return r;
1059
602b8355
NC
1060 if (!path_is_absolute(s))
1061 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "%s takes an absolute path", name);
9b15b784
LP
1062
1063 if (mode != UNIT_CHECK) {
5f5d8eab
LP
1064 if (streq(name, "TTYPath"))
1065 r = free_and_strdup(&c->tty_path, s);
915e6d16
LP
1066 else if (streq(name, "RootImage"))
1067 r = free_and_strdup(&c->root_image, s);
5f5d8eab
LP
1068 else {
1069 assert(streq(name, "RootDirectory"));
1070 r = free_and_strdup(&c->root_directory, s);
602b8355 1071 }
5f5d8eab
LP
1072 if (r < 0)
1073 return r;
9b15b784 1074
b27b4b51 1075 unit_write_drop_in_private_format(u, mode, name, "%s=%s", name, s);
9b15b784
LP
1076 }
1077
1078 return 1;
1079
5f5d8eab
LP
1080 } else if (streq(name, "WorkingDirectory")) {
1081 const char *s;
1082 bool missing_ok;
1083
1084 r = sd_bus_message_read(message, "s", &s);
1085 if (r < 0)
1086 return r;
1087
1088 if (s[0] == '-') {
1089 missing_ok = true;
1090 s++;
1091 } else
1092 missing_ok = false;
1093
1094 if (!streq(s, "~") && !path_is_absolute(s))
1095 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "WorkingDirectory= expects an absolute path or '~'");
1096
1097 if (mode != UNIT_CHECK) {
1098 if (streq(s, "~")) {
1099 c->working_directory = mfree(c->working_directory);
1100 c->working_directory_home = true;
1101 } else {
1102 r = free_and_strdup(&c->working_directory, s);
1103 if (r < 0)
1104 return r;
1105
1106 c->working_directory_home = false;
1107 }
1108
1109 c->working_directory_missing_ok = missing_ok;
b27b4b51 1110 unit_write_drop_in_private_format(u, mode, name, "WorkingDirectory=%s%s", missing_ok ? "-" : "", s);
5f5d8eab
LP
1111 }
1112
1113 return 1;
1114
9b15b784
LP
1115 } else if (streq(name, "StandardInput")) {
1116 const char *s;
1117 ExecInput p;
1118
1119 r = sd_bus_message_read(message, "s", &s);
1120 if (r < 0)
1121 return r;
1122
1123 p = exec_input_from_string(s);
1124 if (p < 0)
1125 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid standard input name");
1126
1127 if (mode != UNIT_CHECK) {
1128 c->std_input = p;
1129
b27b4b51 1130 unit_write_drop_in_private_format(u, mode, name, "StandardInput=%s", exec_input_to_string(p));
9b15b784
LP
1131 }
1132
1133 return 1;
1134
9b15b784
LP
1135 } else if (streq(name, "StandardOutput")) {
1136 const char *s;
1137 ExecOutput p;
1138
1139 r = sd_bus_message_read(message, "s", &s);
1140 if (r < 0)
1141 return r;
1142
1143 p = exec_output_from_string(s);
1144 if (p < 0)
1145 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid standard output name");
1146
1147 if (mode != UNIT_CHECK) {
1148 c->std_output = p;
1149
b27b4b51 1150 unit_write_drop_in_private_format(u, mode, name, "StandardOutput=%s", exec_output_to_string(p));
9b15b784
LP
1151 }
1152
1153 return 1;
1154
1155 } else if (streq(name, "StandardError")) {
1156 const char *s;
1157 ExecOutput p;
1158
1159 r = sd_bus_message_read(message, "s", &s);
1160 if (r < 0)
1161 return r;
1162
1163 p = exec_output_from_string(s);
1164 if (p < 0)
1165 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid standard error name");
1166
1167 if (mode != UNIT_CHECK) {
1168 c->std_error = p;
1169
b27b4b51 1170 unit_write_drop_in_private_format(u, mode, name, "StandardError=%s", exec_output_to_string(p));
9b15b784
LP
1171 }
1172
1173 return 1;
1174
52c239d7
LB
1175 } else if (STR_IN_SET(name,
1176 "StandardInputFileDescriptorName", "StandardOutputFileDescriptorName", "StandardErrorFileDescriptorName")) {
1177 const char *s;
1178
1179 r = sd_bus_message_read(message, "s", &s);
1180 if (r < 0)
1181 return r;
1182
1183 if (!fdname_is_valid(s))
1184 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid file descriptor name");
1185
1186 if (mode != UNIT_CHECK) {
1187 if (streq(name, "StandardInputFileDescriptorName")) {
1188 c->std_input = EXEC_INPUT_NAMED_FD;
1189 r = free_and_strdup(&c->stdio_fdname[STDIN_FILENO], s);
1190 if (r < 0)
1191 return r;
1192 unit_write_drop_in_private_format(u, mode, name, "StandardInput=fd:%s", s);
1193 } else if (streq(name, "StandardOutputFileDescriptorName")) {
1194 c->std_output = EXEC_OUTPUT_NAMED_FD;
1195 r = free_and_strdup(&c->stdio_fdname[STDOUT_FILENO], s);
1196 if (r < 0)
1197 return r;
1198 unit_write_drop_in_private_format(u, mode, name, "StandardOutput=fd:%s", s);
1199 } else if (streq(name, "StandardErrorFileDescriptorName")) {
1200 c->std_error = EXEC_OUTPUT_NAMED_FD;
1201 r = free_and_strdup(&c->stdio_fdname[STDERR_FILENO], s);
1202 if (r < 0)
1203 return r;
1204 unit_write_drop_in_private_format(u, mode, name, "StandardError=fd:%s", s);
1205 }
1206 }
1207
1208 return 1;
1209
b9c50073
GP
1210 } else if (STR_IN_SET(name,
1211 "IgnoreSIGPIPE", "TTYVHangup", "TTYReset",
d251207d 1212 "PrivateTmp", "PrivateDevices", "PrivateNetwork", "PrivateUsers",
29206d46 1213 "NoNewPrivileges", "SyslogLevelPrefix", "MemoryDenyWriteExecute",
59eeb84b 1214 "RestrictRealtime", "DynamicUser", "RemoveIPC", "ProtectKernelTunables",
5d997827 1215 "ProtectKernelModules", "ProtectControlGroups", "MountAPIVFS")) {
506711fd
LP
1216 int b;
1217
1218 r = sd_bus_message_read(message, "b", &b);
1219 if (r < 0)
1220 return r;
1221
1222 if (mode != UNIT_CHECK) {
b9c50073
GP
1223 if (streq(name, "IgnoreSIGPIPE"))
1224 c->ignore_sigpipe = b;
1225 else if (streq(name, "TTYVHangup"))
1226 c->tty_vhangup = b;
1227 else if (streq(name, "TTYReset"))
1228 c->tty_reset = b;
1229 else if (streq(name, "PrivateTmp"))
1230 c->private_tmp = b;
1231 else if (streq(name, "PrivateDevices"))
1232 c->private_devices = b;
1233 else if (streq(name, "PrivateNetwork"))
1234 c->private_network = b;
d251207d
LP
1235 else if (streq(name, "PrivateUsers"))
1236 c->private_users = b;
b9c50073
GP
1237 else if (streq(name, "NoNewPrivileges"))
1238 c->no_new_privileges = b;
047d9933
EV
1239 else if (streq(name, "SyslogLevelPrefix"))
1240 c->syslog_level_prefix = b;
f3e43635
TM
1241 else if (streq(name, "MemoryDenyWriteExecute"))
1242 c->memory_deny_write_execute = b;
f4170c67
LP
1243 else if (streq(name, "RestrictRealtime"))
1244 c->restrict_realtime = b;
29206d46
LP
1245 else if (streq(name, "DynamicUser"))
1246 c->dynamic_user = b;
00d9ef85
LP
1247 else if (streq(name, "RemoveIPC"))
1248 c->remove_ipc = b;
59eeb84b
LP
1249 else if (streq(name, "ProtectKernelTunables"))
1250 c->protect_kernel_tunables = b;
502d704e
DH
1251 else if (streq(name, "ProtectKernelModules"))
1252 c->protect_kernel_modules = b;
59eeb84b
LP
1253 else if (streq(name, "ProtectControlGroups"))
1254 c->protect_control_groups = b;
5d997827
LP
1255 else if (streq(name, "MountAPIVFS"))
1256 c->mount_apivfs = b;
b9c50073 1257
b27b4b51 1258 unit_write_drop_in_private_format(u, mode, name, "%s=%s", name, yes_no(b));
506711fd
LP
1259 }
1260
1261 return 1;
1262
1263 } else if (streq(name, "UtmpIdentifier")) {
1264 const char *id;
1265
1266 r = sd_bus_message_read(message, "s", &id);
1267 if (r < 0)
1268 return r;
1269
1270 if (mode != UNIT_CHECK) {
76736280
LP
1271 if (isempty(id))
1272 c->utmp_id = mfree(c->utmp_id);
1273 else if (free_and_strdup(&c->utmp_id, id) < 0)
1274 return -ENOMEM;
506711fd 1275
b27b4b51 1276 unit_write_drop_in_private_format(u, mode, name, "UtmpIdentifier=%s", strempty(id));
506711fd
LP
1277 }
1278
1279 return 1;
1280
1281 } else if (streq(name, "UtmpMode")) {
1282 const char *s;
1283 ExecUtmpMode m;
1284
1285 r = sd_bus_message_read(message, "s", &s);
1286 if (r < 0)
1287 return r;
1288
1289 m = exec_utmp_mode_from_string(s);
1290 if (m < 0)
1291 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid utmp mode");
1292
1293 if (mode != UNIT_CHECK) {
1294 c->utmp_mode = m;
1295
b27b4b51 1296 unit_write_drop_in_private_format(u, mode, name, "UtmpMode=%s", exec_utmp_mode_to_string(m));
506711fd
LP
1297 }
1298
1299 return 1;
1300
1301 } else if (streq(name, "PAMName")) {
1302 const char *n;
1303
1304 r = sd_bus_message_read(message, "s", &n);
1305 if (r < 0)
1306 return r;
1307
1308 if (mode != UNIT_CHECK) {
76736280
LP
1309 if (isempty(n))
1310 c->pam_name = mfree(c->pam_name);
1311 else if (free_and_strdup(&c->pam_name, n) < 0)
1312 return -ENOMEM;
506711fd 1313
b27b4b51 1314 unit_write_drop_in_private_format(u, mode, name, "PAMName=%s", strempty(n));
506711fd
LP
1315 }
1316
1317 return 1;
1318
c7040b5d
LP
1319 } else if (streq(name, "Environment")) {
1320
f900f582 1321 _cleanup_strv_free_ char **l = NULL, **q = NULL;
c7040b5d
LP
1322
1323 r = sd_bus_message_read_strv(message, &l);
1324 if (r < 0)
1325 return r;
1326
1327 if (!strv_env_is_valid(l))
1328 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid environment block.");
1329
f900f582
ZJS
1330 r = unit_full_printf_strv(u, l, &q);
1331 if (r < 0)
1332 return r;
c7040b5d 1333
f900f582
ZJS
1334 if (mode != UNIT_CHECK) {
1335 if (strv_length(q) == 0) {
e9876fc9 1336 c->environment = strv_free(c->environment);
b27b4b51 1337 unit_write_drop_in_private_format(u, mode, name, "Environment=");
e9876fc9 1338 } else {
f900f582
ZJS
1339 _cleanup_free_ char *joined = NULL;
1340 char **e;
1341
1342 e = strv_env_merge(2, c->environment, q);
e9876fc9
EV
1343 if (!e)
1344 return -ENOMEM;
c7040b5d 1345
e9876fc9
EV
1346 strv_free(c->environment);
1347 c->environment = e;
c7040b5d 1348
f900f582
ZJS
1349 /* We write just the new settings out to file, with unresolved specifiers */
1350 joined = strv_join_quoted(q);
e9876fc9
EV
1351 if (!joined)
1352 return -ENOMEM;
1353
b27b4b51 1354 unit_write_drop_in_private_format(u, mode, name, "Environment=%s", joined);
e9876fc9 1355 }
c7040b5d
LP
1356 }
1357
d584f638
LP
1358 return 1;
1359
f1db3327
EV
1360 } else if (streq(name, "TimerSlackNSec")) {
1361
1362 nsec_t n;
1363
1364 r = sd_bus_message_read(message, "t", &n);
1365 if (r < 0)
1366 return r;
1367
1368 if (mode != UNIT_CHECK) {
1369 c->timer_slack_nsec = n;
b27b4b51 1370 unit_write_drop_in_private_format(u, mode, name, "TimerSlackNSec=" NSEC_FMT, n);
f1db3327
EV
1371 }
1372
1373 return 1;
1374
6b862936
EV
1375 } else if (streq(name, "OOMScoreAdjust")) {
1376 int oa;
1377
1378 r = sd_bus_message_read(message, "i", &oa);
1379 if (r < 0)
1380 return r;
1381
1382 if (!oom_score_adjust_is_valid(oa))
1383 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "OOM score adjust value out of range");
1384
1385 if (mode != UNIT_CHECK) {
1386 c->oom_score_adjust = oa;
1387 c->oom_score_adjust_set = true;
b27b4b51 1388 unit_write_drop_in_private_format(u, mode, name, "OOMScoreAdjust=%i", oa);
6b862936
EV
1389 }
1390
1391 return 1;
1392
ceb728cf
NC
1393 } else if (streq(name, "EnvironmentFiles")) {
1394
1395 _cleanup_free_ char *joined = NULL;
1396 _cleanup_fclose_ FILE *f = NULL;
9b531f04 1397 _cleanup_strv_free_ char **l = NULL;
ceb728cf 1398 size_t size = 0;
2229f656 1399 char **i;
ceb728cf
NC
1400
1401 r = sd_bus_message_enter_container(message, 'a', "(sb)");
1402 if (r < 0)
1403 return r;
1404
1405 f = open_memstream(&joined, &size);
1406 if (!f)
1407 return -ENOMEM;
1408
2229f656 1409 STRV_FOREACH(i, c->environment_files)
b27b4b51 1410 fprintf(f, "EnvironmentFile=%s", *i);
ceb728cf
NC
1411
1412 while ((r = sd_bus_message_enter_container(message, 'r', "sb")) > 0) {
1413 const char *path;
1414 int b;
1415
ceb728cf
NC
1416 r = sd_bus_message_read(message, "sb", &path, &b);
1417 if (r < 0)
1418 return r;
1419
1420 r = sd_bus_message_exit_container(message);
1421 if (r < 0)
1422 return r;
1423
d2d6c096
LP
1424 if (!path_is_absolute(path))
1425 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path %s is not absolute.", path);
ceb728cf
NC
1426
1427 if (mode != UNIT_CHECK) {
ceb728cf
NC
1428 char *buf = NULL;
1429
605405c6 1430 buf = strjoin(b ? "-" : "", path);
2229f656 1431 if (!buf)
ceb728cf
NC
1432 return -ENOMEM;
1433
b27b4b51 1434 fprintf(f, "EnvironmentFile=%s", buf);
ceb728cf 1435
2229f656 1436 r = strv_consume(&l, buf);
ceb728cf
NC
1437 if (r < 0)
1438 return r;
1439 }
1440 }
1441 if (r < 0)
1442 return r;
1443
b0830e21
LP
1444 r = sd_bus_message_exit_container(message);
1445 if (r < 0)
1446 return r;
1447
2229f656
LP
1448 r = fflush_and_check(f);
1449 if (r < 0)
1450 return r;
ceb728cf 1451
2229f656
LP
1452 if (mode != UNIT_CHECK) {
1453 if (strv_isempty(l)) {
1454 c->environment_files = strv_free(c->environment_files);
b27b4b51 1455 unit_write_drop_in_private(u, mode, name, "EnvironmentFile=");
2229f656
LP
1456 } else {
1457 r = strv_extend_strv(&c->environment_files, l, true);
1458 if (r < 0)
1459 return r;
1460
ceb728cf 1461 unit_write_drop_in_private(u, mode, name, joined);
2229f656
LP
1462 }
1463 }
ceb728cf 1464
ceb728cf
NC
1465 return 1;
1466
b4c14404
FB
1467 } else if (streq(name, "PassEnvironment")) {
1468
1469 _cleanup_strv_free_ char **l = NULL;
1470
1471 r = sd_bus_message_read_strv(message, &l);
1472 if (r < 0)
1473 return r;
1474
1475 if (!strv_env_name_is_valid(l))
1476 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid PassEnvironment block.");
1477
1478 if (mode != UNIT_CHECK) {
1479 if (strv_isempty(l)) {
1480 c->pass_environment = strv_free(c->pass_environment);
b27b4b51 1481 unit_write_drop_in_private_format(u, mode, name, "PassEnvironment=");
b4c14404
FB
1482 } else {
1483 _cleanup_free_ char *joined = NULL;
1484
1485 r = strv_extend_strv(&c->pass_environment, l, true);
1486 if (r < 0)
1487 return r;
1488
1489 joined = strv_join_quoted(c->pass_environment);
1490 if (!joined)
1491 return -ENOMEM;
1492
b27b4b51 1493 unit_write_drop_in_private_format(u, mode, name, "PassEnvironment=%s", joined);
b4c14404
FB
1494 }
1495 }
1496
1497 return 1;
1498
2a624c36
AP
1499 } else if (STR_IN_SET(name, "ReadWriteDirectories", "ReadOnlyDirectories", "InaccessibleDirectories",
1500 "ReadWritePaths", "ReadOnlyPaths", "InaccessiblePaths")) {
08596068
EV
1501 _cleanup_strv_free_ char **l = NULL;
1502 char ***dirs;
1503 char **p;
1504
1505 r = sd_bus_message_read_strv(message, &l);
1506 if (r < 0)
1507 return r;
1508
1509 STRV_FOREACH(p, l) {
20b7a007
LP
1510 const char *i = *p;
1511 size_t offset;
1512
1513 if (!utf8_is_valid(i))
08596068
EV
1514 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid %s", name);
1515
20b7a007
LP
1516 offset = i[0] == '-';
1517 offset += i[offset] == '+';
1518 if (!path_is_absolute(i + offset))
08596068
EV
1519 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid %s", name);
1520 }
1521
1522 if (mode != UNIT_CHECK) {
1523 _cleanup_free_ char *joined = NULL;
1524
c4b41707
AP
1525 if (STR_IN_SET(name, "ReadWriteDirectories", "ReadWritePaths"))
1526 dirs = &c->read_write_paths;
1527 else if (STR_IN_SET(name, "ReadOnlyDirectories", "ReadOnlyPaths"))
1528 dirs = &c->read_only_paths;
1529 else /* "InaccessiblePaths" */
1530 dirs = &c->inaccessible_paths;
08596068
EV
1531
1532 if (strv_length(l) == 0) {
1533 *dirs = strv_free(*dirs);
b27b4b51 1534 unit_write_drop_in_private_format(u, mode, name, "%s=", name);
08596068
EV
1535 } else {
1536 r = strv_extend_strv(dirs, l, true);
08596068
EV
1537 if (r < 0)
1538 return -ENOMEM;
1539
1540 joined = strv_join_quoted(*dirs);
1541 if (!joined)
1542 return -ENOMEM;
1543
b27b4b51 1544 unit_write_drop_in_private_format(u, mode, name, "%s=%s", name, joined);
08596068
EV
1545 }
1546
1547 }
1548
1549 return 1;
1550
5664e6cf
EV
1551 } else if (streq(name, "ProtectSystem")) {
1552 const char *s;
1553 ProtectSystem ps;
1554
1555 r = sd_bus_message_read(message, "s", &s);
1556 if (r < 0)
1557 return r;
1558
1559 r = parse_boolean(s);
1560 if (r > 0)
1561 ps = PROTECT_SYSTEM_YES;
1562 else if (r == 0)
1563 ps = PROTECT_SYSTEM_NO;
1564 else {
1565 ps = protect_system_from_string(s);
1566 if (ps < 0)
1567 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Failed to parse protect system value");
1568 }
1569
1570 if (mode != UNIT_CHECK) {
1571 c->protect_system = ps;
b27b4b51 1572 unit_write_drop_in_private_format(u, mode, name, "%s=%s", name, s);
5664e6cf
EV
1573 }
1574
1575 return 1;
1576
eff58074
EV
1577 } else if (streq(name, "ProtectHome")) {
1578 const char *s;
1579 ProtectHome ph;
1580
1581 r = sd_bus_message_read(message, "s", &s);
1582 if (r < 0)
1583 return r;
1584
1585 r = parse_boolean(s);
1586 if (r > 0)
1587 ph = PROTECT_HOME_YES;
1588 else if (r == 0)
1589 ph = PROTECT_HOME_NO;
1590 else {
1591 ph = protect_home_from_string(s);
1592 if (ph < 0)
1593 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Failed to parse protect home value");
1594 }
1595
1596 if (mode != UNIT_CHECK) {
1597 c->protect_home = ph;
b27b4b51 1598 unit_write_drop_in_private_format(u, mode, name, "%s=%s", name, s);
eff58074
EV
1599 }
1600
1601 return 1;
1602
fa21b5e3
EV
1603 } else if (streq(name, "RuntimeDirectory")) {
1604 _cleanup_strv_free_ char **l = NULL;
1605 char **p;
1606
1607 r = sd_bus_message_read_strv(message, &l);
1608 if (r < 0)
1609 return r;
1610
1611 STRV_FOREACH(p, l) {
1612 if (!filename_is_valid(*p))
1613 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Runtime directory is not valid %s", *p);
1614 }
1615
1616 if (mode != UNIT_CHECK) {
1617 _cleanup_free_ char *joined = NULL;
1618
1619 if (strv_isempty(l)) {
1620 c->runtime_directory = strv_free(c->runtime_directory);
b27b4b51 1621 unit_write_drop_in_private_format(u, mode, name, "%s=", name);
fa21b5e3
EV
1622 } else {
1623 r = strv_extend_strv(&c->runtime_directory, l, true);
1624
1625 if (r < 0)
1626 return -ENOMEM;
1627
1628 joined = strv_join_quoted(c->runtime_directory);
1629 if (!joined)
1630 return -ENOMEM;
1631
b27b4b51 1632 unit_write_drop_in_private_format(u, mode, name, "%s=%s", name, joined);
fa21b5e3
EV
1633 }
1634 }
1635
1636 return 1;
1637
186ad4b1
JB
1638 } else if (streq(name, "SELinuxContext")) {
1639 const char *s;
1640
1641 r = sd_bus_message_read(message, "s", &s);
1642 if (r < 0)
1643 return r;
1644
1645 if (mode != UNIT_CHECK) {
4e282d11
JB
1646 if (isempty(s))
1647 c->selinux_context = mfree(c->selinux_context);
1648 else if (free_and_strdup(&c->selinux_context, s) < 0)
1649 return -ENOMEM;
186ad4b1 1650
b27b4b51 1651 unit_write_drop_in_private_format(u, mode, name, "%s=%s", name, strempty(s));
186ad4b1
JB
1652 }
1653
1654 return 1;
add00535
LP
1655 } else if (streq(name, "RestrictNamespaces")) {
1656 uint64_t flags;
186ad4b1 1657
add00535
LP
1658 r = sd_bus_message_read(message, "t", &flags);
1659 if (r < 0)
1660 return r;
1661 if ((flags & NAMESPACE_FLAGS_ALL) != flags)
1662 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Unknown namespace types");
1663
1664 if (mode != UNIT_CHECK) {
1665 _cleanup_free_ char *s = NULL;
1666
1667 r = namespace_flag_to_string_many(flags, &s);
1668 if (r < 0)
1669 return r;
1670
1671 c->restrict_namespaces = flags;
1672 unit_write_drop_in_private_format(u, mode, name, "%s=%s", name, s);
1673 }
1674
1675 return 1;
83555251
LP
1676 } else if (streq(name, "MountFlags")) {
1677 uint64_t flags;
1678
1679 r = sd_bus_message_read(message, "t", &flags);
1680 if (r < 0)
1681 return r;
1682 if (!IN_SET(flags, 0, MS_SHARED, MS_PRIVATE, MS_SLAVE))
1683 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Unknown mount propagation flags");
cab2aca3 1684
83555251
LP
1685 if (mode != UNIT_CHECK) {
1686 c->mount_flags = flags;
1687
c7383828 1688 unit_write_drop_in_private_format(u, mode, name, "%s=%s", name, mount_propagation_flags_to_string(flags));
83555251
LP
1689 }
1690
d2d6c096
LP
1691 return 1;
1692 } else if (STR_IN_SET(name, "BindPaths", "BindReadOnlyPaths")) {
1693 unsigned empty = true;
1694
1695 r = sd_bus_message_enter_container(message, 'a', "(ssbt)");
1696 if (r < 0)
1697 return r;
1698
1699 while ((r = sd_bus_message_enter_container(message, 'r', "ssbt")) > 0) {
1700 const char *source, *destination;
1701 int ignore_enoent;
1702 uint64_t mount_flags;
1703
1704 r = sd_bus_message_read(message, "ssbt", &source, &destination, &ignore_enoent, &mount_flags);
1705 if (r < 0)
1706 return r;
1707
1708 r = sd_bus_message_exit_container(message);
1709 if (r < 0)
1710 return r;
1711
1712 if (!path_is_absolute(source))
1713 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Source path %s is not absolute.", source);
1714 if (!path_is_absolute(destination))
91d910e3 1715 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Destination path %s is not absolute.", destination);
d2d6c096
LP
1716 if (!IN_SET(mount_flags, 0, MS_REC))
1717 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Unknown mount flags.");
1718
1719 if (mode != UNIT_CHECK) {
1720 r = bind_mount_add(&c->bind_mounts, &c->n_bind_mounts,
1721 &(BindMount) {
1722 .source = strdup(source),
1723 .destination = strdup(destination),
1724 .read_only = !!strstr(name, "ReadOnly"),
1725 .recursive = !!(mount_flags & MS_REC),
1726 .ignore_enoent = ignore_enoent,
1727 });
1728 if (r < 0)
1729 return r;
1730
1731 unit_write_drop_in_private_format(
1732 u, mode, name,
1733 "%s=%s%s:%s:%s",
1734 name,
1735 ignore_enoent ? "-" : "",
1736 source,
1737 destination,
1738 (mount_flags & MS_REC) ? "rbind" : "norbind");
1739 }
1740
1741 empty = false;
1742 }
1743 if (r < 0)
1744 return r;
1745
1746 r = sd_bus_message_exit_container(message);
1747 if (r < 0)
1748 return r;
1749
1750 if (empty) {
1751 bind_mount_free_many(c->bind_mounts, c->n_bind_mounts);
1752 c->bind_mounts = NULL;
1753 c->n_bind_mounts = 0;
1754 }
1755
83555251
LP
1756 return 1;
1757 }
d2d6c096 1758
cab2aca3
LP
1759 ri = rlimit_from_string(name);
1760 if (ri < 0) {
1761 soft = endswith(name, "Soft");
1762 if (soft) {
1763 const char *n;
1764
1765 n = strndupa(name, soft - name);
1766 ri = rlimit_from_string(n);
1767 if (ri >= 0)
1768 name = n;
1769
1770 }
1771 }
1772
1773 if (ri >= 0) {
d584f638
LP
1774 uint64_t rl;
1775 rlim_t x;
1776
1777 r = sd_bus_message_read(message, "t", &rl);
1778 if (r < 0)
1779 return r;
1780
1781 if (rl == (uint64_t) -1)
1782 x = RLIM_INFINITY;
1783 else {
1784 x = (rlim_t) rl;
1785
1786 if ((uint64_t) x != rl)
1787 return -ERANGE;
1788 }
1789
1790 if (mode != UNIT_CHECK) {
cab2aca3
LP
1791 _cleanup_free_ char *f = NULL;
1792 struct rlimit nl;
1793
1794 if (c->rlimit[ri]) {
1795 nl = *c->rlimit[ri];
1796
1797 if (soft)
1798 nl.rlim_cur = x;
1799 else
1800 nl.rlim_max = x;
1801 } else
1802 /* When the resource limit is not initialized yet, then assign the value to both fields */
1803 nl = (struct rlimit) {
1804 .rlim_cur = x,
1805 .rlim_max = x,
1806 };
1807
1808 r = rlimit_format(&nl, &f);
1809 if (r < 0)
1810 return r;
d584f638 1811
cab2aca3
LP
1812 if (c->rlimit[ri])
1813 *c->rlimit[ri] = nl;
1814 else {
1815 c->rlimit[ri] = newdup(struct rlimit, &nl, 1);
1816 if (!c->rlimit[ri])
d584f638
LP
1817 return -ENOMEM;
1818 }
1819
b27b4b51 1820 unit_write_drop_in_private_format(u, mode, name, "%s=%s", name, f);
d584f638
LP
1821 }
1822
c7040b5d
LP
1823 return 1;
1824 }
1825
1826 return 0;
1827}