]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/core/dbus-execute.c
Merge pull request #23087 from yuwata/udev-watch
[thirdparty/systemd.git] / src / core / dbus-execute.c
CommitLineData
db9ecf05 1/* SPDX-License-Identifier: LGPL-2.1-or-later */
4139c1b2 2
227b8a76 3#include <sys/mount.h>
82c121a4 4#include <sys/prctl.h>
4139c1b2 5
349cc4a5 6#if HAVE_SECCOMP
57183d11
LP
7#include <seccomp.h>
8#endif
9
3ffd4af2 10#include "af-list.h"
b5efdb8a 11#include "alloc-util.h"
40af3d02 12#include "bus-get-properties.h"
cffaed83 13#include "cap-list.h"
d3070fbd 14#include "capability-util.h"
501941aa 15#include "cpu-set-util.h"
786d19fd 16#include "creds-util.h"
3ffd4af2 17#include "dbus-execute.h"
7e2a3fcc 18#include "dbus-util.h"
c7040b5d 19#include "env-util.h"
cffaed83 20#include "errno-list.h"
2e59b241 21#include "escape.h"
3ffd4af2
LP
22#include "execute.h"
23#include "fd-util.h"
24#include "fileio.h"
08f3be7a 25#include "hexdecoct.h"
d3070fbd 26#include "io-util.h"
032b3afb 27#include "ioprio-util.h"
adce225a 28#include "journal-file.h"
5bead76e 29#include "missing_ioprio.h"
049af8ad 30#include "mountpoint-util.h"
417116f2 31#include "namespace.h"
6bedfcbb 32#include "parse-util.h"
9b15b784 33#include "path-util.h"
7b3e062c 34#include "process-util.h"
78f22b97 35#include "rlimit-util.h"
349cc4a5 36#if HAVE_SECCOMP
57183d11
LP
37#include "seccomp-util.h"
38#endif
cffaed83 39#include "securebits-util.h"
2e59b241 40#include "specifier.h"
cc86a278 41#include "stat-util.h"
6bedfcbb 42#include "strv.h"
7ccbd1ae 43#include "syslog-util.h"
f900f582 44#include "unit-printf.h"
6f3e7985 45#include "user-util.h"
6bedfcbb 46#include "utf8.h"
57183d11 47
718db961 48BUS_DEFINE_PROPERTY_GET_ENUM(bus_property_get_exec_output, exec_output, ExecOutput);
718db961 49static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_input, exec_input, ExecInput);
023a4f67 50static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_utmp_mode, exec_utmp_mode, ExecUtmpMode);
53f47dfc 51static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_preserve_mode, exec_preserve_mode, ExecPreserveMode);
b1edf445 52static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_keyring_mode, exec_keyring_mode, ExecKeyringMode);
4e399953
LP
53static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_protect_proc, protect_proc, ProtectProc);
54static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_proc_subset, proc_subset, ProcSubset);
73b84e92
YW
55static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_protect_home, protect_home, ProtectHome);
56static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_protect_system, protect_system, ProtectSystem);
491eecb3 57static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_personality, personality, unsigned long);
019b34ca 58static BUS_DEFINE_PROPERTY_GET(property_get_ioprio, "i", ExecContext, exec_context_get_effective_ioprio);
5e98086d 59static BUS_DEFINE_PROPERTY_GET(property_get_mount_apivfs, "b", ExecContext, exec_context_get_effective_mount_apivfs);
5bead76e
ZJS
60static BUS_DEFINE_PROPERTY_GET2(property_get_ioprio_class, "i", ExecContext, exec_context_get_effective_ioprio, ioprio_prio_class);
61static BUS_DEFINE_PROPERTY_GET2(property_get_ioprio_priority, "i", ExecContext, exec_context_get_effective_ioprio, ioprio_prio_data);
92c23c5a
YW
62static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_empty_string, "s", NULL);
63static BUS_DEFINE_PROPERTY_GET_REF(property_get_syslog_level, "i", int, LOG_PRI);
64static BUS_DEFINE_PROPERTY_GET_REF(property_get_syslog_facility, "i", int, LOG_FAC);
e2b2fb7f
MS
65static BUS_DEFINE_PROPERTY_GET(property_get_cpu_affinity_from_numa, "b", ExecContext, exec_context_get_cpu_affinity_from_numa);
66
718db961
LP
67static int property_get_environment_files(
68 sd_bus *bus,
69 const char *path,
70 const char *interface,
71 const char *property,
72 sd_bus_message *reply,
ebcf1f97
LP
73 void *userdata,
74 sd_bus_error *error) {
8c7be95e 75
718db961 76 ExecContext *c = userdata;
718db961 77 int r;
8c7be95e 78
718db961
LP
79 assert(bus);
80 assert(reply);
81 assert(c);
82
83 r = sd_bus_message_open_container(reply, 'a', "(sb)");
84 if (r < 0)
85 return r;
8c7be95e 86
718db961
LP
87 STRV_FOREACH(j, c->environment_files) {
88 const char *fn = *j;
8c7be95e 89
718db961
LP
90 r = sd_bus_message_append(reply, "(sb)", fn[0] == '-' ? fn + 1 : fn, fn[0] == '-');
91 if (r < 0)
92 return r;
8c7be95e
LP
93 }
94
718db961
LP
95 return sd_bus_message_close_container(reply);
96}
97
718db961
LP
98static int property_get_oom_score_adjust(
99 sd_bus *bus,
100 const char *path,
101 const char *interface,
102 const char *property,
103 sd_bus_message *reply,
ebcf1f97
LP
104 void *userdata,
105 sd_bus_error *error) {
718db961 106
718db961 107 ExecContext *c = userdata;
2c37c613 108 int r, n;
82c121a4 109
718db961
LP
110 assert(bus);
111 assert(reply);
82c121a4
LP
112 assert(c);
113
dd6c17b1
LP
114 if (c->oom_score_adjust_set)
115 n = c->oom_score_adjust;
82c121a4 116 else {
82c121a4 117 n = 0;
2c37c613 118 r = get_oom_score_adjust(&n);
b94fb74b
ZJS
119 if (r < 0)
120 log_debug_errno(r, "Failed to read /proc/self/oom_score_adj, ignoring: %m");
82c121a4
LP
121 }
122
718db961 123 return sd_bus_message_append(reply, "i", n);
82c121a4
LP
124}
125
ad21e542
ZJS
126static int property_get_coredump_filter(
127 sd_bus *bus,
128 const char *path,
129 const char *interface,
130 const char *property,
131 sd_bus_message *reply,
132 void *userdata,
133 sd_bus_error *error) {
134
135 ExecContext *c = userdata;
136 uint64_t n;
137 int r;
138
139 assert(bus);
140 assert(reply);
141 assert(c);
142
143 if (c->coredump_filter_set)
144 n = c->coredump_filter;
145 else {
146 _cleanup_free_ char *t = NULL;
147
148 n = COREDUMP_FILTER_MASK_DEFAULT;
149 r = read_one_line_file("/proc/self/coredump_filter", &t);
150 if (r < 0)
151 log_debug_errno(r, "Failed to read /proc/self/coredump_filter, ignoring: %m");
152 else {
153 r = safe_atoux64(t, &n);
154 if (r < 0)
155 log_debug_errno(r, "Failed to parse \"%s\" from /proc/self/coredump_filter, ignoring: %m", t);
156 }
157 }
158
159 return sd_bus_message_append(reply, "t", n);
160}
161
718db961
LP
162static int property_get_nice(
163 sd_bus *bus,
164 const char *path,
165 const char *interface,
166 const char *property,
167 sd_bus_message *reply,
ebcf1f97
LP
168 void *userdata,
169 sd_bus_error *error) {
718db961 170
718db961 171 ExecContext *c = userdata;
82c121a4
LP
172 int32_t n;
173
718db961
LP
174 assert(bus);
175 assert(reply);
82c121a4
LP
176 assert(c);
177
178 if (c->nice_set)
179 n = c->nice;
718db961
LP
180 else {
181 errno = 0;
82c121a4 182 n = getpriority(PRIO_PROCESS, 0);
b3267152 183 if (errno > 0)
718db961
LP
184 n = 0;
185 }
82c121a4 186
718db961 187 return sd_bus_message_append(reply, "i", n);
82c121a4
LP
188}
189
718db961
LP
190static int property_get_cpu_sched_policy(
191 sd_bus *bus,
192 const char *path,
193 const char *interface,
194 const char *property,
195 sd_bus_message *reply,
ebcf1f97
LP
196 void *userdata,
197 sd_bus_error *error) {
718db961
LP
198
199 ExecContext *c = userdata;
82c121a4
LP
200 int32_t n;
201
718db961
LP
202 assert(bus);
203 assert(reply);
82c121a4
LP
204 assert(c);
205
206 if (c->cpu_sched_set)
207 n = c->cpu_sched_policy;
718db961 208 else {
82c121a4 209 n = sched_getscheduler(0);
718db961
LP
210 if (n < 0)
211 n = SCHED_OTHER;
212 }
82c121a4 213
718db961 214 return sd_bus_message_append(reply, "i", n);
82c121a4
LP
215}
216
718db961
LP
217static int property_get_cpu_sched_priority(
218 sd_bus *bus,
219 const char *path,
220 const char *interface,
221 const char *property,
222 sd_bus_message *reply,
ebcf1f97
LP
223 void *userdata,
224 sd_bus_error *error) {
718db961
LP
225
226 ExecContext *c = userdata;
82c121a4
LP
227 int32_t n;
228
718db961
LP
229 assert(bus);
230 assert(reply);
82c121a4
LP
231 assert(c);
232
233 if (c->cpu_sched_set)
234 n = c->cpu_sched_priority;
235 else {
b92bea5d 236 struct sched_param p = {};
82c121a4 237
82c121a4
LP
238 if (sched_getparam(0, &p) >= 0)
239 n = p.sched_priority;
e62d8c39
ZJS
240 else
241 n = 0;
82c121a4
LP
242 }
243
718db961 244 return sd_bus_message_append(reply, "i", n);
82c121a4
LP
245}
246
718db961
LP
247static int property_get_cpu_affinity(
248 sd_bus *bus,
249 const char *path,
250 const char *interface,
251 const char *property,
252 sd_bus_message *reply,
ebcf1f97
LP
253 void *userdata,
254 sd_bus_error *error) {
82c121a4 255
718db961 256 ExecContext *c = userdata;
e2b2fb7f 257 _cleanup_(cpu_set_reset) CPUSet s = {};
75e40119
MS
258 _cleanup_free_ uint8_t *array = NULL;
259 size_t allocated;
82c121a4 260
718db961
LP
261 assert(bus);
262 assert(reply);
263 assert(c);
82c121a4 264
e2b2fb7f
MS
265 if (c->cpu_affinity_from_numa) {
266 int r;
267
268 r = numa_to_cpu_set(&c->numa_policy, &s);
269 if (r < 0)
270 return r;
271 }
272
273 (void) cpu_set_to_dbus(c->cpu_affinity_from_numa ? &s : &c->cpu_set, &array, &allocated);
274
75e40119 275 return sd_bus_message_append_array(reply, 'y', array, allocated);
82c121a4
LP
276}
277
b070c7c0
MS
278static int property_get_numa_mask(
279 sd_bus *bus,
280 const char *path,
281 const char *interface,
282 const char *property,
283 sd_bus_message *reply,
284 void *userdata,
285 sd_bus_error *error) {
286
287 ExecContext *c = userdata;
288 _cleanup_free_ uint8_t *array = NULL;
289 size_t allocated;
290
291 assert(bus);
292 assert(reply);
293 assert(c);
294
295 (void) cpu_set_to_dbus(&c->numa_policy.nodes, &array, &allocated);
296
297 return sd_bus_message_append_array(reply, 'y', array, allocated);
298}
299
300static int property_get_numa_policy(
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 ExecContext *c = userdata;
309 int32_t policy;
310
311 assert(bus);
312 assert(reply);
313 assert(c);
314
315 policy = numa_policy_get_type(&c->numa_policy);
316
317 return sd_bus_message_append_basic(reply, 'i', &policy);
318}
319
718db961
LP
320static int property_get_timer_slack_nsec(
321 sd_bus *bus,
322 const char *path,
323 const char *interface,
324 const char *property,
325 sd_bus_message *reply,
ebcf1f97
LP
326 void *userdata,
327 sd_bus_error *error) {
718db961
LP
328
329 ExecContext *c = userdata;
82c121a4
LP
330 uint64_t u;
331
718db961
LP
332 assert(bus);
333 assert(reply);
82c121a4
LP
334 assert(c);
335
3a43da28 336 if (c->timer_slack_nsec != NSEC_INFINITY)
03fae018 337 u = (uint64_t) c->timer_slack_nsec;
82c121a4
LP
338 else
339 u = (uint64_t) prctl(PR_GET_TIMERSLACK);
340
718db961 341 return sd_bus_message_append(reply, "t", u);
82c121a4
LP
342}
343
718db961
LP
344static int property_get_syscall_filter(
345 sd_bus *bus,
346 const char *path,
347 const char *interface,
348 const char *property,
349 sd_bus_message *reply,
ebcf1f97
LP
350 void *userdata,
351 sd_bus_error *error) {
82c121a4 352
17df7223
LP
353 ExecContext *c = userdata;
354 _cleanup_strv_free_ char **l = NULL;
57183d11
LP
355 int r;
356
17df7223
LP
357 assert(bus);
358 assert(reply);
359 assert(c);
360
57183d11
LP
361 r = sd_bus_message_open_container(reply, 'r', "bas");
362 if (r < 0)
363 return r;
364
6b000af4 365 r = sd_bus_message_append(reply, "b", c->syscall_allow_list);
57183d11
LP
366 if (r < 0)
367 return r;
368
349cc4a5 369#if HAVE_SECCOMP
d5a99b7c 370 void *id, *val;
90e74a66 371 HASHMAP_FOREACH_KEY(val, id, c->syscall_filter) {
8cfa775f
YW
372 _cleanup_free_ char *name = NULL;
373 const char *e = NULL;
374 char *s;
375 int num = PTR_TO_INT(val);
17df7223 376
8c93ebbd
YW
377 if (c->syscall_allow_list && num >= 0)
378 /* syscall with num >= 0 in allow-list is denied. */
379 continue;
380
17df7223
LP
381 name = seccomp_syscall_resolve_num_arch(SCMP_ARCH_NATIVE, PTR_TO_INT(id) - 1);
382 if (!name)
383 continue;
384
8cfa775f 385 if (num >= 0) {
005bfaf1 386 e = seccomp_errno_or_action_to_string(num);
8cfa775f
YW
387 if (e) {
388 s = strjoin(name, ":", e);
389 if (!s)
390 return -ENOMEM;
391 } else {
392 r = asprintf(&s, "%s:%d", name, num);
393 if (r < 0)
394 return -ENOMEM;
395 }
ae2a15bc
LP
396 } else
397 s = TAKE_PTR(name);
8cfa775f
YW
398
399 r = strv_consume(&l, s);
6e18964d
ZJS
400 if (r < 0)
401 return r;
17df7223 402 }
351a19b1 403#endif
17df7223
LP
404
405 strv_sort(l);
406
57183d11
LP
407 r = sd_bus_message_append_strv(reply, l);
408 if (r < 0)
409 return r;
17df7223 410
57183d11
LP
411 return sd_bus_message_close_container(reply);
412}
17df7223 413
9df2cdd8
TM
414static int property_get_syscall_log(
415 sd_bus *bus,
416 const char *path,
417 const char *interface,
418 const char *property,
419 sd_bus_message *reply,
420 void *userdata,
421 sd_bus_error *error) {
422
423 ExecContext *c = userdata;
424 _cleanup_strv_free_ char **l = NULL;
425 int r;
426
9df2cdd8
TM
427 assert(bus);
428 assert(reply);
429 assert(c);
430
431 r = sd_bus_message_open_container(reply, 'r', "bas");
432 if (r < 0)
433 return r;
434
435 r = sd_bus_message_append(reply, "b", c->syscall_log_allow_list);
436 if (r < 0)
437 return r;
438
439#if HAVE_SECCOMP
d5a99b7c 440 void *id, *val;
9df2cdd8
TM
441 HASHMAP_FOREACH_KEY(val, id, c->syscall_log) {
442 char *name = NULL;
443
444 name = seccomp_syscall_resolve_num_arch(SCMP_ARCH_NATIVE, PTR_TO_INT(id) - 1);
445 if (!name)
446 continue;
447
448 r = strv_consume(&l, name);
449 if (r < 0)
450 return r;
451 }
452#endif
453
454 strv_sort(l);
455
456 r = sd_bus_message_append_strv(reply, l);
457 if (r < 0)
458 return r;
459
460 return sd_bus_message_close_container(reply);
461}
462
57183d11
LP
463static int property_get_syscall_archs(
464 sd_bus *bus,
465 const char *path,
466 const char *interface,
467 const char *property,
468 sd_bus_message *reply,
469 void *userdata,
470 sd_bus_error *error) {
471
472 ExecContext *c = userdata;
473 _cleanup_strv_free_ char **l = NULL;
474 int r;
475
57183d11
LP
476 assert(bus);
477 assert(reply);
478 assert(c);
17df7223 479
349cc4a5 480#if HAVE_SECCOMP
d5a99b7c 481 void *id;
90e74a66 482 SET_FOREACH(id, c->syscall_archs) {
57183d11
LP
483 const char *name;
484
485 name = seccomp_arch_to_string(PTR_TO_UINT32(id) - 1);
486 if (!name)
487 continue;
488
489 r = strv_extend(&l, name);
490 if (r < 0)
491 return -ENOMEM;
17df7223 492 }
57183d11
LP
493#endif
494
495 strv_sort(l);
496
497 r = sd_bus_message_append_strv(reply, l);
498 if (r < 0)
499 return r;
17df7223 500
57183d11 501 return 0;
17df7223
LP
502}
503
5f8640fb
LP
504static int property_get_selinux_context(
505 sd_bus *bus,
506 const char *path,
507 const char *interface,
508 const char *property,
509 sd_bus_message *reply,
510 void *userdata,
511 sd_bus_error *error) {
512
513 ExecContext *c = userdata;
514
515 assert(bus);
516 assert(reply);
517 assert(c);
518
519 return sd_bus_message_append(reply, "(bs)", c->selinux_context_ignore, c->selinux_context);
520}
521
eef65bf3
MS
522static int property_get_apparmor_profile(
523 sd_bus *bus,
524 const char *path,
525 const char *interface,
526 const char *property,
527 sd_bus_message *reply,
528 void *userdata,
529 sd_bus_error *error) {
530
531 ExecContext *c = userdata;
532
533 assert(bus);
534 assert(reply);
535 assert(c);
536
537 return sd_bus_message_append(reply, "(bs)", c->apparmor_profile_ignore, c->apparmor_profile);
538}
539
2ca620c4
WC
540static int property_get_smack_process_label(
541 sd_bus *bus,
542 const char *path,
543 const char *interface,
544 const char *property,
545 sd_bus_message *reply,
546 void *userdata,
547 sd_bus_error *error) {
548
549 ExecContext *c = userdata;
550
551 assert(bus);
552 assert(reply);
553 assert(c);
554
555 return sd_bus_message_append(reply, "(bs)", c->smack_process_label_ignore, c->smack_process_label);
556}
557
4298d0b5
LP
558static int property_get_address_families(
559 sd_bus *bus,
560 const char *path,
561 const char *interface,
562 const char *property,
563 sd_bus_message *reply,
564 void *userdata,
565 sd_bus_error *error) {
566
567 ExecContext *c = userdata;
568 _cleanup_strv_free_ char **l = NULL;
4298d0b5
LP
569 void *af;
570 int r;
571
572 assert(bus);
573 assert(reply);
574 assert(c);
575
576 r = sd_bus_message_open_container(reply, 'r', "bas");
577 if (r < 0)
578 return r;
579
6b000af4 580 r = sd_bus_message_append(reply, "b", c->address_families_allow_list);
4298d0b5
LP
581 if (r < 0)
582 return r;
583
90e74a66 584 SET_FOREACH(af, c->address_families) {
4298d0b5
LP
585 const char *name;
586
587 name = af_to_name(PTR_TO_INT(af));
588 if (!name)
589 continue;
590
591 r = strv_extend(&l, name);
592 if (r < 0)
593 return -ENOMEM;
594 }
595
596 strv_sort(l);
597
598 r = sd_bus_message_append_strv(reply, l);
599 if (r < 0)
600 return r;
601
602 return sd_bus_message_close_container(reply);
603}
604
5f5d8eab
LP
605static int property_get_working_directory(
606 sd_bus *bus,
607 const char *path,
608 const char *interface,
609 const char *property,
610 sd_bus_message *reply,
611 void *userdata,
612 sd_bus_error *error) {
613
614 ExecContext *c = userdata;
615 const char *wd;
616
617 assert(bus);
618 assert(reply);
619 assert(c);
620
621 if (c->working_directory_home)
622 wd = "~";
623 else
624 wd = c->working_directory;
625
626 if (c->working_directory_missing_ok)
627 wd = strjoina("!", wd);
628
629 return sd_bus_message_append(reply, "s", wd);
630}
631
5073ff6b 632static int property_get_stdio_fdname(
52c239d7
LB
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;
5073ff6b 642 int fileno;
52c239d7
LB
643
644 assert(bus);
645 assert(c);
646 assert(property);
647 assert(reply);
648
5073ff6b
LP
649 if (streq(property, "StandardInputFileDescriptorName"))
650 fileno = STDIN_FILENO;
651 else if (streq(property, "StandardOutputFileDescriptorName"))
652 fileno = STDOUT_FILENO;
653 else {
654 assert(streq(property, "StandardErrorFileDescriptorName"));
655 fileno = STDERR_FILENO;
656 }
52c239d7 657
5073ff6b 658 return sd_bus_message_append(reply, "s", exec_context_fdname(c, fileno));
52c239d7
LB
659}
660
08f3be7a 661static int property_get_input_data(
52c239d7
LB
662 sd_bus *bus,
663 const char *path,
664 const char *interface,
665 const char *property,
666 sd_bus_message *reply,
667 void *userdata,
668 sd_bus_error *error) {
669
670 ExecContext *c = userdata;
52c239d7
LB
671
672 assert(bus);
673 assert(c);
674 assert(property);
675 assert(reply);
676
08f3be7a 677 return sd_bus_message_append_array(reply, 'y', c->stdin_data, c->stdin_data_size);
52c239d7
LB
678}
679
cc86a278
ILG
680static int property_get_restrict_filesystems(
681 sd_bus *bus,
682 const char *path,
683 const char *interface,
684 const char *property,
685 sd_bus_message *reply,
686 void *userdata,
687 sd_bus_error *error) {
688
689 ExecContext *c = userdata;
690 _cleanup_free_ char **l = NULL;
691 int r;
692
693 assert(bus);
694 assert(reply);
695 assert(c);
696
697 r = sd_bus_message_open_container(reply, 'r', "bas");
698 if (r < 0)
699 return r;
700
701 r = sd_bus_message_append(reply, "b", c->restrict_filesystems_allow_list);
702 if (r < 0)
703 return r;
704
705#if HAVE_LIBBPF
706 l = set_get_strv(c->restrict_filesystems);
707 if (!l)
708 return -ENOMEM;
709#endif
710
711 strv_sort(l);
712
713 r = sd_bus_message_append_strv(reply, l);
714 if (r < 0)
715 return r;
716
717 return sd_bus_message_close_container(reply);
718}
719
d2d6c096
LP
720static int property_get_bind_paths(
721 sd_bus *bus,
722 const char *path,
723 const char *interface,
724 const char *property,
725 sd_bus_message *reply,
726 void *userdata,
727 sd_bus_error *error) {
728
729 ExecContext *c = userdata;
d2d6c096
LP
730 bool ro;
731 int r;
732
733 assert(bus);
734 assert(c);
735 assert(property);
736 assert(reply);
737
5d904a6a 738 ro = strstr(property, "ReadOnly");
d2d6c096
LP
739
740 r = sd_bus_message_open_container(reply, 'a', "(ssbt)");
741 if (r < 0)
742 return r;
743
fe96c0f8 744 for (size_t i = 0; i < c->n_bind_mounts; i++) {
d2d6c096
LP
745
746 if (ro != c->bind_mounts[i].read_only)
747 continue;
748
749 r = sd_bus_message_append(
750 reply, "(ssbt)",
751 c->bind_mounts[i].source,
752 c->bind_mounts[i].destination,
753 c->bind_mounts[i].ignore_enoent,
c9b06108 754 c->bind_mounts[i].recursive ? (uint64_t) MS_REC : (uint64_t) 0);
d2d6c096
LP
755 if (r < 0)
756 return r;
757 }
758
759 return sd_bus_message_close_container(reply);
760}
761
784ad252
YW
762static int property_get_temporary_filesystems(
763 sd_bus *bus,
764 const char *path,
765 const char *interface,
766 const char *property,
767 sd_bus_message *reply,
768 void *userdata,
769 sd_bus_error *error) {
770
771 ExecContext *c = userdata;
784ad252
YW
772 int r;
773
774 assert(bus);
775 assert(c);
776 assert(property);
777 assert(reply);
778
779 r = sd_bus_message_open_container(reply, 'a', "(ss)");
780 if (r < 0)
781 return r;
782
fe96c0f8 783 for (unsigned i = 0; i < c->n_temporary_filesystems; i++) {
784ad252
YW
784 TemporaryFileSystem *t = c->temporary_filesystems + i;
785
786 r = sd_bus_message_append(
787 reply, "(ss)",
788 t->path,
789 t->options);
790 if (r < 0)
791 return r;
792 }
793
794 return sd_bus_message_close_container(reply);
795}
796
d3070fbd
LP
797static int property_get_log_extra_fields(
798 sd_bus *bus,
799 const char *path,
800 const char *interface,
801 const char *property,
802 sd_bus_message *reply,
803 void *userdata,
804 sd_bus_error *error) {
805
806 ExecContext *c = userdata;
d3070fbd
LP
807 int r;
808
809 assert(bus);
810 assert(c);
811 assert(property);
812 assert(reply);
813
814 r = sd_bus_message_open_container(reply, 'a', "ay");
815 if (r < 0)
816 return r;
817
fe96c0f8 818 for (size_t i = 0; i < c->n_log_extra_fields; i++) {
d3070fbd
LP
819 r = sd_bus_message_append_array(reply, 'y', c->log_extra_fields[i].iov_base, c->log_extra_fields[i].iov_len);
820 if (r < 0)
821 return r;
822 }
823
824 return sd_bus_message_close_container(reply);
825}
826
bb0c0d6f
LP
827static int property_get_set_credential(
828 sd_bus *bus,
829 const char *path,
830 const char *interface,
831 const char *property,
832 sd_bus_message *reply,
833 void *userdata,
834 sd_bus_error *error) {
835
836 ExecContext *c = userdata;
837 ExecSetCredential *sc;
bb0c0d6f
LP
838 int r;
839
840 assert(bus);
841 assert(c);
842 assert(property);
843 assert(reply);
844
845 r = sd_bus_message_open_container(reply, 'a', "(say)");
846 if (r < 0)
847 return r;
848
90e74a66 849 HASHMAP_FOREACH(sc, c->set_credentials) {
bb0c0d6f 850
43144be4
LP
851 if (sc->encrypted != streq(property, "SetCredentialEncrypted"))
852 continue;
853
bb0c0d6f
LP
854 r = sd_bus_message_open_container(reply, 'r', "say");
855 if (r < 0)
856 return r;
857
858 r = sd_bus_message_append(reply, "s", sc->id);
859 if (r < 0)
860 return r;
861
862 r = sd_bus_message_append_array(reply, 'y', sc->data, sc->size);
863 if (r < 0)
864 return r;
865
866 r = sd_bus_message_close_container(reply);
867 if (r < 0)
868 return r;
869 }
870
871 return sd_bus_message_close_container(reply);
872}
873
874static int property_get_load_credential(
875 sd_bus *bus,
876 const char *path,
877 const char *interface,
878 const char *property,
879 sd_bus_message *reply,
880 void *userdata,
881 sd_bus_error *error) {
882
883 ExecContext *c = userdata;
43144be4 884 ExecLoadCredential *lc;
bb0c0d6f
LP
885 int r;
886
887 assert(bus);
888 assert(c);
889 assert(property);
890 assert(reply);
891
892 r = sd_bus_message_open_container(reply, 'a', "(ss)");
893 if (r < 0)
894 return r;
895
43144be4
LP
896 HASHMAP_FOREACH(lc, c->load_credentials) {
897
898 if (lc->encrypted != streq(property, "LoadCredentialEncrypted"))
899 continue;
900
901 r = sd_bus_message_append(reply, "(ss)", lc->id, lc->path);
bb0c0d6f
LP
902 if (r < 0)
903 return r;
904 }
905
906 return sd_bus_message_close_container(reply);
907}
908
0389f4fa
LB
909static int property_get_root_hash(
910 sd_bus *bus,
911 const char *path,
912 const char *interface,
913 const char *property,
914 sd_bus_message *reply,
915 void *userdata,
916 sd_bus_error *error) {
917
918 ExecContext *c = userdata;
919
920 assert(bus);
921 assert(c);
922 assert(property);
923 assert(reply);
924
925 return sd_bus_message_append_array(reply, 'y', c->root_hash, c->root_hash_size);
926}
927
d4d55b0d
LB
928static int property_get_root_hash_sig(
929 sd_bus *bus,
930 const char *path,
931 const char *interface,
932 const char *property,
933 sd_bus_message *reply,
934 void *userdata,
935 sd_bus_error *error) {
936
937 ExecContext *c = userdata;
938
939 assert(bus);
940 assert(c);
941 assert(property);
942 assert(reply);
943
944 return sd_bus_message_append_array(reply, 'y', c->root_hash_sig, c->root_hash_sig_size);
945}
946
18d73705
LB
947static int property_get_root_image_options(
948 sd_bus *bus,
949 const char *path,
950 const char *interface,
951 const char *property,
952 sd_bus_message *reply,
953 void *userdata,
954 sd_bus_error *error) {
955
956 ExecContext *c = userdata;
18d73705
LB
957 int r;
958
959 assert(bus);
960 assert(c);
961 assert(property);
962 assert(reply);
963
9ece6444 964 r = sd_bus_message_open_container(reply, 'a', "(ss)");
18d73705
LB
965 if (r < 0)
966 return r;
967
968 LIST_FOREACH(mount_options, m, c->root_image_options) {
9ece6444
LB
969 r = sd_bus_message_append(reply, "(ss)",
970 partition_designator_to_string(m->partition_designator),
971 m->options);
18d73705
LB
972 if (r < 0)
973 return r;
974 }
975
976 return sd_bus_message_close_container(reply);
977}
978
b3d13314
LB
979static int property_get_mount_images(
980 sd_bus *bus,
981 const char *path,
982 const char *interface,
983 const char *property,
984 sd_bus_message *reply,
985 void *userdata,
986 sd_bus_error *error) {
987
988 ExecContext *c = userdata;
989 int r;
990
991 assert(bus);
992 assert(c);
993 assert(property);
994 assert(reply);
995
427353f6 996 r = sd_bus_message_open_container(reply, 'a', "(ssba(ss))");
b3d13314
LB
997 if (r < 0)
998 return r;
999
1000 for (size_t i = 0; i < c->n_mount_images; i++) {
427353f6
LB
1001 r = sd_bus_message_open_container(reply, SD_BUS_TYPE_STRUCT, "ssba(ss)");
1002 if (r < 0)
1003 return r;
b3d13314 1004 r = sd_bus_message_append(
427353f6 1005 reply, "ssb",
b3d13314
LB
1006 c->mount_images[i].source,
1007 c->mount_images[i].destination,
1008 c->mount_images[i].ignore_enoent);
1009 if (r < 0)
1010 return r;
427353f6
LB
1011 r = sd_bus_message_open_container(reply, 'a', "(ss)");
1012 if (r < 0)
1013 return r;
1014 LIST_FOREACH(mount_options, m, c->mount_images[i].mount_options) {
1015 r = sd_bus_message_append(reply, "(ss)",
1016 partition_designator_to_string(m->partition_designator),
1017 m->options);
1018 if (r < 0)
1019 return r;
1020 }
1021 r = sd_bus_message_close_container(reply);
1022 if (r < 0)
1023 return r;
1024 r = sd_bus_message_close_container(reply);
1025 if (r < 0)
1026 return r;
b3d13314
LB
1027 }
1028
1029 return sd_bus_message_close_container(reply);
1030}
1031
93f59701
LB
1032static int property_get_extension_images(
1033 sd_bus *bus,
1034 const char *path,
1035 const char *interface,
1036 const char *property,
1037 sd_bus_message *reply,
1038 void *userdata,
1039 sd_bus_error *error) {
1040
1041 ExecContext *c = userdata;
1042 int r;
1043
1044 assert(bus);
1045 assert(c);
1046 assert(property);
1047 assert(reply);
1048
1049 r = sd_bus_message_open_container(reply, 'a', "(sba(ss))");
1050 if (r < 0)
1051 return r;
1052
1053 for (size_t i = 0; i < c->n_extension_images; i++) {
93f59701
LB
1054 r = sd_bus_message_open_container(reply, SD_BUS_TYPE_STRUCT, "sba(ss)");
1055 if (r < 0)
1056 return r;
1057 r = sd_bus_message_append(
1058 reply, "sb",
1059 c->extension_images[i].source,
1060 c->extension_images[i].ignore_enoent);
1061 if (r < 0)
1062 return r;
1063 r = sd_bus_message_open_container(reply, 'a', "(ss)");
1064 if (r < 0)
1065 return r;
1066 LIST_FOREACH(mount_options, m, c->extension_images[i].mount_options) {
1067 r = sd_bus_message_append(reply, "(ss)",
1068 partition_designator_to_string(m->partition_designator),
1069 m->options);
1070 if (r < 0)
1071 return r;
1072 }
1073 r = sd_bus_message_close_container(reply);
1074 if (r < 0)
1075 return r;
1076 r = sd_bus_message_close_container(reply);
1077 if (r < 0)
1078 return r;
1079 }
1080
1081 return sd_bus_message_close_container(reply);
1082}
1083
211a3d87
LB
1084static int bus_property_get_exec_dir(
1085 sd_bus *bus,
1086 const char *path,
1087 const char *interface,
1088 const char *property,
1089 sd_bus_message *reply,
1090 void *userdata,
1091 sd_bus_error *error) {
1092
1093 ExecDirectory *d = userdata;
1094 int r;
1095
1096 assert(bus);
1097 assert(d);
1098 assert(property);
1099 assert(reply);
1100
1101 r = sd_bus_message_open_container(reply, 'a', "s");
1102 if (r < 0)
1103 return r;
1104
1105 for (size_t i = 0; i < d->n_items; i++) {
1106 r = sd_bus_message_append_basic(reply, 's', d->items[i].path);
1107 if (r < 0)
1108 return r;
1109 }
1110
1111 return sd_bus_message_close_container(reply);
1112}
1113
1114static int bus_property_get_exec_dir_symlink(
1115 sd_bus *bus,
1116 const char *path,
1117 const char *interface,
1118 const char *property,
1119 sd_bus_message *reply,
1120 void *userdata,
1121 sd_bus_error *error) {
1122
1123 ExecDirectory *d = userdata;
1124 int r;
1125
1126 assert(bus);
1127 assert(d);
1128 assert(property);
1129 assert(reply);
1130
1131 r = sd_bus_message_open_container(reply, 'a', "(sst)");
1132 if (r < 0)
1133 return r;
1134
de010b0b 1135 for (size_t i = 0; i < d->n_items; i++)
211a3d87
LB
1136 STRV_FOREACH(dst, d->items[i].symlinks) {
1137 r = sd_bus_message_append(reply, "(sst)", d->items[i].path, *dst, 0 /* flags, unused for now */);
1138 if (r < 0)
1139 return r;
1140 }
211a3d87
LB
1141
1142 return sd_bus_message_close_container(reply);
1143}
1144
718db961
LP
1145const sd_bus_vtable bus_exec_vtable[] = {
1146 SD_BUS_VTABLE_START(0),
556089dc
LP
1147 SD_BUS_PROPERTY("Environment", "as", NULL, offsetof(ExecContext, environment), SD_BUS_VTABLE_PROPERTY_CONST),
1148 SD_BUS_PROPERTY("EnvironmentFiles", "a(sb)", property_get_environment_files, 0, SD_BUS_VTABLE_PROPERTY_CONST),
b4c14404 1149 SD_BUS_PROPERTY("PassEnvironment", "as", NULL, offsetof(ExecContext, pass_environment), SD_BUS_VTABLE_PROPERTY_CONST),
00819cc1 1150 SD_BUS_PROPERTY("UnsetEnvironment", "as", NULL, offsetof(ExecContext, unset_environment), SD_BUS_VTABLE_PROPERTY_CONST),
556089dc 1151 SD_BUS_PROPERTY("UMask", "u", bus_property_get_mode, offsetof(ExecContext, umask), SD_BUS_VTABLE_PROPERTY_CONST),
c9d031c3 1152 SD_BUS_PROPERTY("LimitCPU", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_CPU]), SD_BUS_VTABLE_PROPERTY_CONST),
147f6858 1153 SD_BUS_PROPERTY("LimitCPUSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_CPU]), SD_BUS_VTABLE_PROPERTY_CONST),
c9d031c3 1154 SD_BUS_PROPERTY("LimitFSIZE", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_FSIZE]), SD_BUS_VTABLE_PROPERTY_CONST),
147f6858 1155 SD_BUS_PROPERTY("LimitFSIZESoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_FSIZE]), SD_BUS_VTABLE_PROPERTY_CONST),
c9d031c3 1156 SD_BUS_PROPERTY("LimitDATA", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_DATA]), SD_BUS_VTABLE_PROPERTY_CONST),
147f6858 1157 SD_BUS_PROPERTY("LimitDATASoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_DATA]), SD_BUS_VTABLE_PROPERTY_CONST),
c9d031c3 1158 SD_BUS_PROPERTY("LimitSTACK", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_STACK]), SD_BUS_VTABLE_PROPERTY_CONST),
147f6858 1159 SD_BUS_PROPERTY("LimitSTACKSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_STACK]), SD_BUS_VTABLE_PROPERTY_CONST),
c9d031c3 1160 SD_BUS_PROPERTY("LimitCORE", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_CORE]), SD_BUS_VTABLE_PROPERTY_CONST),
147f6858 1161 SD_BUS_PROPERTY("LimitCORESoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_CORE]), SD_BUS_VTABLE_PROPERTY_CONST),
c9d031c3 1162 SD_BUS_PROPERTY("LimitRSS", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RSS]), SD_BUS_VTABLE_PROPERTY_CONST),
147f6858 1163 SD_BUS_PROPERTY("LimitRSSSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RSS]), SD_BUS_VTABLE_PROPERTY_CONST),
c9d031c3 1164 SD_BUS_PROPERTY("LimitNOFILE", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NOFILE]), SD_BUS_VTABLE_PROPERTY_CONST),
147f6858 1165 SD_BUS_PROPERTY("LimitNOFILESoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NOFILE]), SD_BUS_VTABLE_PROPERTY_CONST),
c9d031c3 1166 SD_BUS_PROPERTY("LimitAS", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_AS]), SD_BUS_VTABLE_PROPERTY_CONST),
147f6858 1167 SD_BUS_PROPERTY("LimitASSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_AS]), SD_BUS_VTABLE_PROPERTY_CONST),
c9d031c3 1168 SD_BUS_PROPERTY("LimitNPROC", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NPROC]), SD_BUS_VTABLE_PROPERTY_CONST),
147f6858 1169 SD_BUS_PROPERTY("LimitNPROCSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NPROC]), SD_BUS_VTABLE_PROPERTY_CONST),
c9d031c3 1170 SD_BUS_PROPERTY("LimitMEMLOCK", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_MEMLOCK]), SD_BUS_VTABLE_PROPERTY_CONST),
147f6858 1171 SD_BUS_PROPERTY("LimitMEMLOCKSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_MEMLOCK]), SD_BUS_VTABLE_PROPERTY_CONST),
c9d031c3 1172 SD_BUS_PROPERTY("LimitLOCKS", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_LOCKS]), SD_BUS_VTABLE_PROPERTY_CONST),
147f6858 1173 SD_BUS_PROPERTY("LimitLOCKSSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_LOCKS]), SD_BUS_VTABLE_PROPERTY_CONST),
c9d031c3 1174 SD_BUS_PROPERTY("LimitSIGPENDING", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_SIGPENDING]), SD_BUS_VTABLE_PROPERTY_CONST),
147f6858 1175 SD_BUS_PROPERTY("LimitSIGPENDINGSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_SIGPENDING]), SD_BUS_VTABLE_PROPERTY_CONST),
c9d031c3 1176 SD_BUS_PROPERTY("LimitMSGQUEUE", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_MSGQUEUE]), SD_BUS_VTABLE_PROPERTY_CONST),
147f6858 1177 SD_BUS_PROPERTY("LimitMSGQUEUESoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_MSGQUEUE]), SD_BUS_VTABLE_PROPERTY_CONST),
c9d031c3 1178 SD_BUS_PROPERTY("LimitNICE", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NICE]), SD_BUS_VTABLE_PROPERTY_CONST),
147f6858 1179 SD_BUS_PROPERTY("LimitNICESoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NICE]), SD_BUS_VTABLE_PROPERTY_CONST),
c9d031c3 1180 SD_BUS_PROPERTY("LimitRTPRIO", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RTPRIO]), SD_BUS_VTABLE_PROPERTY_CONST),
147f6858 1181 SD_BUS_PROPERTY("LimitRTPRIOSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RTPRIO]), SD_BUS_VTABLE_PROPERTY_CONST),
c9d031c3 1182 SD_BUS_PROPERTY("LimitRTTIME", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RTTIME]), SD_BUS_VTABLE_PROPERTY_CONST),
147f6858 1183 SD_BUS_PROPERTY("LimitRTTIMESoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RTTIME]), SD_BUS_VTABLE_PROPERTY_CONST),
5f5d8eab 1184 SD_BUS_PROPERTY("WorkingDirectory", "s", property_get_working_directory, 0, SD_BUS_VTABLE_PROPERTY_CONST),
556089dc 1185 SD_BUS_PROPERTY("RootDirectory", "s", NULL, offsetof(ExecContext, root_directory), SD_BUS_VTABLE_PROPERTY_CONST),
915e6d16 1186 SD_BUS_PROPERTY("RootImage", "s", NULL, offsetof(ExecContext, root_image), SD_BUS_VTABLE_PROPERTY_CONST),
9ece6444 1187 SD_BUS_PROPERTY("RootImageOptions", "a(ss)", property_get_root_image_options, 0, SD_BUS_VTABLE_PROPERTY_CONST),
0389f4fa
LB
1188 SD_BUS_PROPERTY("RootHash", "ay", property_get_root_hash, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1189 SD_BUS_PROPERTY("RootHashPath", "s", NULL, offsetof(ExecContext, root_hash_path), SD_BUS_VTABLE_PROPERTY_CONST),
d4d55b0d
LB
1190 SD_BUS_PROPERTY("RootHashSignature", "ay", property_get_root_hash_sig, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1191 SD_BUS_PROPERTY("RootHashSignaturePath", "s", NULL, offsetof(ExecContext, root_hash_sig_path), SD_BUS_VTABLE_PROPERTY_CONST),
0389f4fa 1192 SD_BUS_PROPERTY("RootVerity", "s", NULL, offsetof(ExecContext, root_verity), SD_BUS_VTABLE_PROPERTY_CONST),
a07b9926 1193 SD_BUS_PROPERTY("ExtensionDirectories", "as", NULL, offsetof(ExecContext, extension_directories), SD_BUS_VTABLE_PROPERTY_CONST),
93f59701 1194 SD_BUS_PROPERTY("ExtensionImages", "a(sba(ss))", property_get_extension_images, 0, SD_BUS_VTABLE_PROPERTY_CONST),
427353f6 1195 SD_BUS_PROPERTY("MountImages", "a(ssba(ss))", property_get_mount_images, 0, SD_BUS_VTABLE_PROPERTY_CONST),
556089dc 1196 SD_BUS_PROPERTY("OOMScoreAdjust", "i", property_get_oom_score_adjust, 0, SD_BUS_VTABLE_PROPERTY_CONST),
ad21e542 1197 SD_BUS_PROPERTY("CoredumpFilter", "t", property_get_coredump_filter, 0, SD_BUS_VTABLE_PROPERTY_CONST),
556089dc 1198 SD_BUS_PROPERTY("Nice", "i", property_get_nice, 0, SD_BUS_VTABLE_PROPERTY_CONST),
7f452159
LP
1199 SD_BUS_PROPERTY("IOSchedulingClass", "i", property_get_ioprio_class, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1200 SD_BUS_PROPERTY("IOSchedulingPriority", "i", property_get_ioprio_priority, 0, SD_BUS_VTABLE_PROPERTY_CONST),
556089dc
LP
1201 SD_BUS_PROPERTY("CPUSchedulingPolicy", "i", property_get_cpu_sched_policy, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1202 SD_BUS_PROPERTY("CPUSchedulingPriority", "i", property_get_cpu_sched_priority, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1203 SD_BUS_PROPERTY("CPUAffinity", "ay", property_get_cpu_affinity, 0, SD_BUS_VTABLE_PROPERTY_CONST),
e2b2fb7f 1204 SD_BUS_PROPERTY("CPUAffinityFromNUMA", "b", property_get_cpu_affinity_from_numa, 0, SD_BUS_VTABLE_PROPERTY_CONST),
b070c7c0
MS
1205 SD_BUS_PROPERTY("NUMAPolicy", "i", property_get_numa_policy, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1206 SD_BUS_PROPERTY("NUMAMask", "ay", property_get_numa_mask, 0, SD_BUS_VTABLE_PROPERTY_CONST),
556089dc
LP
1207 SD_BUS_PROPERTY("TimerSlackNSec", "t", property_get_timer_slack_nsec, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1208 SD_BUS_PROPERTY("CPUSchedulingResetOnFork", "b", bus_property_get_bool, offsetof(ExecContext, cpu_sched_reset_on_fork), SD_BUS_VTABLE_PROPERTY_CONST),
1209 SD_BUS_PROPERTY("NonBlocking", "b", bus_property_get_bool, offsetof(ExecContext, non_blocking), SD_BUS_VTABLE_PROPERTY_CONST),
1210 SD_BUS_PROPERTY("StandardInput", "s", property_get_exec_input, offsetof(ExecContext, std_input), SD_BUS_VTABLE_PROPERTY_CONST),
5073ff6b 1211 SD_BUS_PROPERTY("StandardInputFileDescriptorName", "s", property_get_stdio_fdname, 0, SD_BUS_VTABLE_PROPERTY_CONST),
08f3be7a 1212 SD_BUS_PROPERTY("StandardInputData", "ay", property_get_input_data, 0, SD_BUS_VTABLE_PROPERTY_CONST),
556089dc 1213 SD_BUS_PROPERTY("StandardOutput", "s", bus_property_get_exec_output, offsetof(ExecContext, std_output), SD_BUS_VTABLE_PROPERTY_CONST),
5073ff6b 1214 SD_BUS_PROPERTY("StandardOutputFileDescriptorName", "s", property_get_stdio_fdname, 0, SD_BUS_VTABLE_PROPERTY_CONST),
556089dc 1215 SD_BUS_PROPERTY("StandardError", "s", bus_property_get_exec_output, offsetof(ExecContext, std_error), SD_BUS_VTABLE_PROPERTY_CONST),
5073ff6b 1216 SD_BUS_PROPERTY("StandardErrorFileDescriptorName", "s", property_get_stdio_fdname, 0, SD_BUS_VTABLE_PROPERTY_CONST),
556089dc
LP
1217 SD_BUS_PROPERTY("TTYPath", "s", NULL, offsetof(ExecContext, tty_path), SD_BUS_VTABLE_PROPERTY_CONST),
1218 SD_BUS_PROPERTY("TTYReset", "b", bus_property_get_bool, offsetof(ExecContext, tty_reset), SD_BUS_VTABLE_PROPERTY_CONST),
1219 SD_BUS_PROPERTY("TTYVHangup", "b", bus_property_get_bool, offsetof(ExecContext, tty_vhangup), SD_BUS_VTABLE_PROPERTY_CONST),
1220 SD_BUS_PROPERTY("TTYVTDisallocate", "b", bus_property_get_bool, offsetof(ExecContext, tty_vt_disallocate), SD_BUS_VTABLE_PROPERTY_CONST),
51462135
DDM
1221 SD_BUS_PROPERTY("TTYRows", "q", bus_property_get_unsigned, offsetof(ExecContext, tty_rows), SD_BUS_VTABLE_PROPERTY_CONST),
1222 SD_BUS_PROPERTY("TTYColumns", "q", bus_property_get_unsigned, offsetof(ExecContext, tty_cols), SD_BUS_VTABLE_PROPERTY_CONST),
556089dc
LP
1223 SD_BUS_PROPERTY("SyslogPriority", "i", bus_property_get_int, offsetof(ExecContext, syslog_priority), SD_BUS_VTABLE_PROPERTY_CONST),
1224 SD_BUS_PROPERTY("SyslogIdentifier", "s", NULL, offsetof(ExecContext, syslog_identifier), SD_BUS_VTABLE_PROPERTY_CONST),
1225 SD_BUS_PROPERTY("SyslogLevelPrefix", "b", bus_property_get_bool, offsetof(ExecContext, syslog_level_prefix), SD_BUS_VTABLE_PROPERTY_CONST),
9d5527f2
YW
1226 SD_BUS_PROPERTY("SyslogLevel", "i", property_get_syslog_level, offsetof(ExecContext, syslog_priority), SD_BUS_VTABLE_PROPERTY_CONST),
1227 SD_BUS_PROPERTY("SyslogFacility", "i", property_get_syslog_facility, offsetof(ExecContext, syslog_priority), SD_BUS_VTABLE_PROPERTY_CONST),
d3070fbd 1228 SD_BUS_PROPERTY("LogLevelMax", "i", bus_property_get_int, offsetof(ExecContext, log_level_max), SD_BUS_VTABLE_PROPERTY_CONST),
5ac1530e
ZJS
1229 SD_BUS_PROPERTY("LogRateLimitIntervalUSec", "t", bus_property_get_usec, offsetof(ExecContext, log_ratelimit_interval_usec), SD_BUS_VTABLE_PROPERTY_CONST),
1230 SD_BUS_PROPERTY("LogRateLimitBurst", "u", bus_property_get_unsigned, offsetof(ExecContext, log_ratelimit_burst), SD_BUS_VTABLE_PROPERTY_CONST),
d3070fbd 1231 SD_BUS_PROPERTY("LogExtraFields", "aay", property_get_log_extra_fields, 0, SD_BUS_VTABLE_PROPERTY_CONST),
91dd5f7c 1232 SD_BUS_PROPERTY("LogNamespace", "s", NULL, offsetof(ExecContext, log_namespace), SD_BUS_VTABLE_PROPERTY_CONST),
556089dc 1233 SD_BUS_PROPERTY("SecureBits", "i", bus_property_get_int, offsetof(ExecContext, secure_bits), SD_BUS_VTABLE_PROPERTY_CONST),
c0159e20
YW
1234 SD_BUS_PROPERTY("CapabilityBoundingSet", "t", NULL, offsetof(ExecContext, capability_bounding_set), SD_BUS_VTABLE_PROPERTY_CONST),
1235 SD_BUS_PROPERTY("AmbientCapabilities", "t", NULL, offsetof(ExecContext, capability_ambient_set), SD_BUS_VTABLE_PROPERTY_CONST),
556089dc
LP
1236 SD_BUS_PROPERTY("User", "s", NULL, offsetof(ExecContext, user), SD_BUS_VTABLE_PROPERTY_CONST),
1237 SD_BUS_PROPERTY("Group", "s", NULL, offsetof(ExecContext, group), SD_BUS_VTABLE_PROPERTY_CONST),
29206d46 1238 SD_BUS_PROPERTY("DynamicUser", "b", bus_property_get_bool, offsetof(ExecContext, dynamic_user), SD_BUS_VTABLE_PROPERTY_CONST),
00d9ef85 1239 SD_BUS_PROPERTY("RemoveIPC", "b", bus_property_get_bool, offsetof(ExecContext, remove_ipc), SD_BUS_VTABLE_PROPERTY_CONST),
bb0c0d6f 1240 SD_BUS_PROPERTY("SetCredential", "a(say)", property_get_set_credential, 0, SD_BUS_VTABLE_PROPERTY_CONST),
43144be4 1241 SD_BUS_PROPERTY("SetCredentialEncrypted", "a(say)", property_get_set_credential, 0, SD_BUS_VTABLE_PROPERTY_CONST),
bb0c0d6f 1242 SD_BUS_PROPERTY("LoadCredential", "a(ss)", property_get_load_credential, 0, SD_BUS_VTABLE_PROPERTY_CONST),
43144be4 1243 SD_BUS_PROPERTY("LoadCredentialEncrypted", "a(ss)", property_get_load_credential, 0, SD_BUS_VTABLE_PROPERTY_CONST),
556089dc 1244 SD_BUS_PROPERTY("SupplementaryGroups", "as", NULL, offsetof(ExecContext, supplementary_groups), SD_BUS_VTABLE_PROPERTY_CONST),
556089dc 1245 SD_BUS_PROPERTY("PAMName", "s", NULL, offsetof(ExecContext, pam_name), SD_BUS_VTABLE_PROPERTY_CONST),
2a624c36
AP
1246 SD_BUS_PROPERTY("ReadWritePaths", "as", NULL, offsetof(ExecContext, read_write_paths), SD_BUS_VTABLE_PROPERTY_CONST),
1247 SD_BUS_PROPERTY("ReadOnlyPaths", "as", NULL, offsetof(ExecContext, read_only_paths), SD_BUS_VTABLE_PROPERTY_CONST),
1248 SD_BUS_PROPERTY("InaccessiblePaths", "as", NULL, offsetof(ExecContext, inaccessible_paths), SD_BUS_VTABLE_PROPERTY_CONST),
ddc155b2
TM
1249 SD_BUS_PROPERTY("ExecPaths", "as", NULL, offsetof(ExecContext, exec_paths), SD_BUS_VTABLE_PROPERTY_CONST),
1250 SD_BUS_PROPERTY("NoExecPaths", "as", NULL, offsetof(ExecContext, no_exec_paths), SD_BUS_VTABLE_PROPERTY_CONST),
8c35c10d 1251 SD_BUS_PROPERTY("ExecSearchPath", "as", NULL, offsetof(ExecContext, exec_search_path), SD_BUS_VTABLE_PROPERTY_CONST),
556089dc
LP
1252 SD_BUS_PROPERTY("MountFlags", "t", bus_property_get_ulong, offsetof(ExecContext, mount_flags), SD_BUS_VTABLE_PROPERTY_CONST),
1253 SD_BUS_PROPERTY("PrivateTmp", "b", bus_property_get_bool, offsetof(ExecContext, private_tmp), SD_BUS_VTABLE_PROPERTY_CONST),
7f112f50 1254 SD_BUS_PROPERTY("PrivateDevices", "b", bus_property_get_bool, offsetof(ExecContext, private_devices), SD_BUS_VTABLE_PROPERTY_CONST),
b8b7b838 1255 SD_BUS_PROPERTY("ProtectClock", "b", bus_property_get_bool, offsetof(ExecContext, protect_clock), SD_BUS_VTABLE_PROPERTY_CONST),
59eeb84b 1256 SD_BUS_PROPERTY("ProtectKernelTunables", "b", bus_property_get_bool, offsetof(ExecContext, protect_kernel_tunables), SD_BUS_VTABLE_PROPERTY_CONST),
502d704e 1257 SD_BUS_PROPERTY("ProtectKernelModules", "b", bus_property_get_bool, offsetof(ExecContext, protect_kernel_modules), SD_BUS_VTABLE_PROPERTY_CONST),
84703040 1258 SD_BUS_PROPERTY("ProtectKernelLogs", "b", bus_property_get_bool, offsetof(ExecContext, protect_kernel_logs), SD_BUS_VTABLE_PROPERTY_CONST),
59eeb84b 1259 SD_BUS_PROPERTY("ProtectControlGroups", "b", bus_property_get_bool, offsetof(ExecContext, protect_control_groups), SD_BUS_VTABLE_PROPERTY_CONST),
d251207d
LP
1260 SD_BUS_PROPERTY("PrivateNetwork", "b", bus_property_get_bool, offsetof(ExecContext, private_network), SD_BUS_VTABLE_PROPERTY_CONST),
1261 SD_BUS_PROPERTY("PrivateUsers", "b", bus_property_get_bool, offsetof(ExecContext, private_users), SD_BUS_VTABLE_PROPERTY_CONST),
228af36f 1262 SD_BUS_PROPERTY("PrivateMounts", "b", bus_property_get_bool, offsetof(ExecContext, private_mounts), SD_BUS_VTABLE_PROPERTY_CONST),
a70581ff 1263 SD_BUS_PROPERTY("PrivateIPC", "b", bus_property_get_bool, offsetof(ExecContext, private_ipc), SD_BUS_VTABLE_PROPERTY_CONST),
73b84e92
YW
1264 SD_BUS_PROPERTY("ProtectHome", "s", property_get_protect_home, offsetof(ExecContext, protect_home), SD_BUS_VTABLE_PROPERTY_CONST),
1265 SD_BUS_PROPERTY("ProtectSystem", "s", property_get_protect_system, offsetof(ExecContext, protect_system), SD_BUS_VTABLE_PROPERTY_CONST),
556089dc
LP
1266 SD_BUS_PROPERTY("SameProcessGroup", "b", bus_property_get_bool, offsetof(ExecContext, same_pgrp), SD_BUS_VTABLE_PROPERTY_CONST),
1267 SD_BUS_PROPERTY("UtmpIdentifier", "s", NULL, offsetof(ExecContext, utmp_id), SD_BUS_VTABLE_PROPERTY_CONST),
023a4f67 1268 SD_BUS_PROPERTY("UtmpMode", "s", property_get_exec_utmp_mode, offsetof(ExecContext, utmp_mode), SD_BUS_VTABLE_PROPERTY_CONST),
5f8640fb 1269 SD_BUS_PROPERTY("SELinuxContext", "(bs)", property_get_selinux_context, 0, SD_BUS_VTABLE_PROPERTY_CONST),
eef65bf3 1270 SD_BUS_PROPERTY("AppArmorProfile", "(bs)", property_get_apparmor_profile, 0, SD_BUS_VTABLE_PROPERTY_CONST),
2ca620c4 1271 SD_BUS_PROPERTY("SmackProcessLabel", "(bs)", property_get_smack_process_label, 0, SD_BUS_VTABLE_PROPERTY_CONST),
556089dc
LP
1272 SD_BUS_PROPERTY("IgnoreSIGPIPE", "b", bus_property_get_bool, offsetof(ExecContext, ignore_sigpipe), SD_BUS_VTABLE_PROPERTY_CONST),
1273 SD_BUS_PROPERTY("NoNewPrivileges", "b", bus_property_get_bool, offsetof(ExecContext, no_new_privileges), SD_BUS_VTABLE_PROPERTY_CONST),
57183d11
LP
1274 SD_BUS_PROPERTY("SystemCallFilter", "(bas)", property_get_syscall_filter, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1275 SD_BUS_PROPERTY("SystemCallArchitectures", "as", property_get_syscall_archs, 0, SD_BUS_VTABLE_PROPERTY_CONST),
cf9d43a8 1276 SD_BUS_PROPERTY("SystemCallErrorNumber", "i", bus_property_get_int, offsetof(ExecContext, syscall_errno), SD_BUS_VTABLE_PROPERTY_CONST),
9df2cdd8 1277 SD_BUS_PROPERTY("SystemCallLog", "(bas)", property_get_syscall_log, 0, SD_BUS_VTABLE_PROPERTY_CONST),
491eecb3 1278 SD_BUS_PROPERTY("Personality", "s", property_get_personality, offsetof(ExecContext, personality), SD_BUS_VTABLE_PROPERTY_CONST),
78e864e5 1279 SD_BUS_PROPERTY("LockPersonality", "b", bus_property_get_bool, offsetof(ExecContext, lock_personality), SD_BUS_VTABLE_PROPERTY_CONST),
4298d0b5 1280 SD_BUS_PROPERTY("RestrictAddressFamilies", "(bas)", property_get_address_families, 0, SD_BUS_VTABLE_PROPERTY_CONST),
211a3d87 1281 SD_BUS_PROPERTY("RuntimeDirectorySymlink", "a(sst)", bus_property_get_exec_dir_symlink, offsetof(ExecContext, directories[EXEC_DIRECTORY_RUNTIME]), SD_BUS_VTABLE_PROPERTY_CONST),
53f47dfc 1282 SD_BUS_PROPERTY("RuntimeDirectoryPreserve", "s", property_get_exec_preserve_mode, offsetof(ExecContext, runtime_directory_preserve_mode), SD_BUS_VTABLE_PROPERTY_CONST),
3536f49e 1283 SD_BUS_PROPERTY("RuntimeDirectoryMode", "u", bus_property_get_mode, offsetof(ExecContext, directories[EXEC_DIRECTORY_RUNTIME].mode), SD_BUS_VTABLE_PROPERTY_CONST),
211a3d87
LB
1284 SD_BUS_PROPERTY("RuntimeDirectory", "as", bus_property_get_exec_dir, offsetof(ExecContext, directories[EXEC_DIRECTORY_RUNTIME]), SD_BUS_VTABLE_PROPERTY_CONST),
1285 SD_BUS_PROPERTY("StateDirectorySymlink", "a(sst)", bus_property_get_exec_dir_symlink, offsetof(ExecContext, directories[EXEC_DIRECTORY_STATE]), SD_BUS_VTABLE_PROPERTY_CONST),
e940c1ef 1286 SD_BUS_PROPERTY("StateDirectoryMode", "u", bus_property_get_mode, offsetof(ExecContext, directories[EXEC_DIRECTORY_STATE].mode), SD_BUS_VTABLE_PROPERTY_CONST),
211a3d87
LB
1287 SD_BUS_PROPERTY("StateDirectory", "as", bus_property_get_exec_dir, offsetof(ExecContext, directories[EXEC_DIRECTORY_STATE]), SD_BUS_VTABLE_PROPERTY_CONST),
1288 SD_BUS_PROPERTY("CacheDirectorySymlink", "a(sst)", bus_property_get_exec_dir_symlink, offsetof(ExecContext, directories[EXEC_DIRECTORY_CACHE]), SD_BUS_VTABLE_PROPERTY_CONST),
3536f49e 1289 SD_BUS_PROPERTY("CacheDirectoryMode", "u", bus_property_get_mode, offsetof(ExecContext, directories[EXEC_DIRECTORY_CACHE].mode), SD_BUS_VTABLE_PROPERTY_CONST),
211a3d87
LB
1290 SD_BUS_PROPERTY("CacheDirectory", "as", bus_property_get_exec_dir, offsetof(ExecContext, directories[EXEC_DIRECTORY_CACHE]), SD_BUS_VTABLE_PROPERTY_CONST),
1291 SD_BUS_PROPERTY("LogsDirectorySymlink", "a(sst)", bus_property_get_exec_dir_symlink, offsetof(ExecContext, directories[EXEC_DIRECTORY_LOGS]), SD_BUS_VTABLE_PROPERTY_CONST),
3536f49e 1292 SD_BUS_PROPERTY("LogsDirectoryMode", "u", bus_property_get_mode, offsetof(ExecContext, directories[EXEC_DIRECTORY_LOGS].mode), SD_BUS_VTABLE_PROPERTY_CONST),
211a3d87 1293 SD_BUS_PROPERTY("LogsDirectory", "as", bus_property_get_exec_dir, offsetof(ExecContext, directories[EXEC_DIRECTORY_LOGS]), SD_BUS_VTABLE_PROPERTY_CONST),
3536f49e 1294 SD_BUS_PROPERTY("ConfigurationDirectoryMode", "u", bus_property_get_mode, offsetof(ExecContext, directories[EXEC_DIRECTORY_CONFIGURATION].mode), SD_BUS_VTABLE_PROPERTY_CONST),
211a3d87 1295 SD_BUS_PROPERTY("ConfigurationDirectory", "as", bus_property_get_exec_dir, offsetof(ExecContext, directories[EXEC_DIRECTORY_CONFIGURATION]), SD_BUS_VTABLE_PROPERTY_CONST),
12213aed 1296 SD_BUS_PROPERTY("TimeoutCleanUSec", "t", bus_property_get_usec, offsetof(ExecContext, timeout_clean_usec), SD_BUS_VTABLE_PROPERTY_CONST),
f3e43635 1297 SD_BUS_PROPERTY("MemoryDenyWriteExecute", "b", bus_property_get_bool, offsetof(ExecContext, memory_deny_write_execute), SD_BUS_VTABLE_PROPERTY_CONST),
f4170c67 1298 SD_BUS_PROPERTY("RestrictRealtime", "b", bus_property_get_bool, offsetof(ExecContext, restrict_realtime), SD_BUS_VTABLE_PROPERTY_CONST),
f69567cb 1299 SD_BUS_PROPERTY("RestrictSUIDSGID", "b", bus_property_get_bool, offsetof(ExecContext, restrict_suid_sgid), SD_BUS_VTABLE_PROPERTY_CONST),
6a8c2d59 1300 SD_BUS_PROPERTY("RestrictNamespaces", "t", bus_property_get_ulong, offsetof(ExecContext, restrict_namespaces), SD_BUS_VTABLE_PROPERTY_CONST),
cc86a278 1301 SD_BUS_PROPERTY("RestrictFileSystems", "(bas)", property_get_restrict_filesystems, 0, SD_BUS_VTABLE_PROPERTY_CONST),
d2d6c096
LP
1302 SD_BUS_PROPERTY("BindPaths", "a(ssbt)", property_get_bind_paths, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1303 SD_BUS_PROPERTY("BindReadOnlyPaths", "a(ssbt)", property_get_bind_paths, 0, SD_BUS_VTABLE_PROPERTY_CONST),
784ad252 1304 SD_BUS_PROPERTY("TemporaryFileSystem", "a(ss)", property_get_temporary_filesystems, 0, SD_BUS_VTABLE_PROPERTY_CONST),
5e98086d 1305 SD_BUS_PROPERTY("MountAPIVFS", "b", property_get_mount_apivfs, 0, SD_BUS_VTABLE_PROPERTY_CONST),
b1edf445 1306 SD_BUS_PROPERTY("KeyringMode", "s", property_get_exec_keyring_mode, offsetof(ExecContext, keyring_mode), SD_BUS_VTABLE_PROPERTY_CONST),
4e399953
LP
1307 SD_BUS_PROPERTY("ProtectProc", "s", property_get_protect_proc, offsetof(ExecContext, protect_proc), SD_BUS_VTABLE_PROPERTY_CONST),
1308 SD_BUS_PROPERTY("ProcSubset", "s", property_get_proc_subset, offsetof(ExecContext, proc_subset), SD_BUS_VTABLE_PROPERTY_CONST),
aecd5ac6 1309 SD_BUS_PROPERTY("ProtectHostname", "b", bus_property_get_bool, offsetof(ExecContext, protect_hostname), SD_BUS_VTABLE_PROPERTY_CONST),
a8d08f39 1310 SD_BUS_PROPERTY("NetworkNamespacePath", "s", NULL, offsetof(ExecContext, network_namespace_path), SD_BUS_VTABLE_PROPERTY_CONST),
a70581ff 1311 SD_BUS_PROPERTY("IPCNamespacePath", "s", NULL, offsetof(ExecContext, ipc_namespace_path), SD_BUS_VTABLE_PROPERTY_CONST),
7f452159
LP
1312
1313 /* Obsolete/redundant properties: */
1314 SD_BUS_PROPERTY("Capabilities", "s", property_get_empty_string, 0, SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN),
1315 SD_BUS_PROPERTY("ReadWriteDirectories", "as", NULL, offsetof(ExecContext, read_write_paths), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN),
1316 SD_BUS_PROPERTY("ReadOnlyDirectories", "as", NULL, offsetof(ExecContext, read_only_paths), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN),
1317 SD_BUS_PROPERTY("InaccessibleDirectories", "as", NULL, offsetof(ExecContext, inaccessible_paths), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN),
1318 SD_BUS_PROPERTY("IOScheduling", "i", property_get_ioprio, 0, SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN),
1319
718db961
LP
1320 SD_BUS_VTABLE_END
1321};
82c121a4 1322
4d4c80d0
LP
1323static int append_exec_command(sd_bus_message *reply, ExecCommand *c) {
1324 int r;
1325
1326 assert(reply);
1327 assert(c);
1328
1329 if (!c->path)
1330 return 0;
1331
1332 r = sd_bus_message_open_container(reply, 'r', "sasbttttuii");
1333 if (r < 0)
1334 return r;
1335
1336 r = sd_bus_message_append(reply, "s", c->path);
1337 if (r < 0)
1338 return r;
1339
1340 r = sd_bus_message_append_strv(reply, c->argv);
1341 if (r < 0)
1342 return r;
1343
1344 r = sd_bus_message_append(reply, "bttttuii",
3ed0cd26 1345 !!(c->flags & EXEC_COMMAND_IGNORE_FAILURE),
4d4c80d0
LP
1346 c->exec_status.start_timestamp.realtime,
1347 c->exec_status.start_timestamp.monotonic,
1348 c->exec_status.exit_timestamp.realtime,
1349 c->exec_status.exit_timestamp.monotonic,
1350 (uint32_t) c->exec_status.pid,
1351 (int32_t) c->exec_status.code,
1352 (int32_t) c->exec_status.status);
1353 if (r < 0)
1354 return r;
1355
1356 return sd_bus_message_close_container(reply);
1357}
1358
b3d59367
AZ
1359static int append_exec_ex_command(sd_bus_message *reply, ExecCommand *c) {
1360 _cleanup_strv_free_ char **ex_opts = NULL;
1361 int r;
1362
1363 assert(reply);
1364 assert(c);
1365
1366 if (!c->path)
1367 return 0;
1368
1369 r = sd_bus_message_open_container(reply, 'r', "sasasttttuii");
1370 if (r < 0)
1371 return r;
1372
1373 r = sd_bus_message_append(reply, "s", c->path);
1374 if (r < 0)
1375 return r;
1376
1377 r = sd_bus_message_append_strv(reply, c->argv);
1378 if (r < 0)
1379 return r;
1380
1381 r = exec_command_flags_to_strv(c->flags, &ex_opts);
1382 if (r < 0)
1383 return r;
1384
1385 r = sd_bus_message_append_strv(reply, ex_opts);
1386 if (r < 0)
1387 return r;
1388
1389 r = sd_bus_message_append(reply, "ttttuii",
1390 c->exec_status.start_timestamp.realtime,
1391 c->exec_status.start_timestamp.monotonic,
1392 c->exec_status.exit_timestamp.realtime,
1393 c->exec_status.exit_timestamp.monotonic,
1394 (uint32_t) c->exec_status.pid,
1395 (int32_t) c->exec_status.code,
1396 (int32_t) c->exec_status.status);
1397 if (r < 0)
1398 return r;
1399
1400 return sd_bus_message_close_container(reply);
1401}
1402
718db961
LP
1403int bus_property_get_exec_command(
1404 sd_bus *bus,
1405 const char *path,
1406 const char *interface,
1407 const char *property,
1408 sd_bus_message *reply,
ebcf1f97
LP
1409 void *userdata,
1410 sd_bus_error *ret_error) {
fe68089d 1411
4d4c80d0 1412 ExecCommand *c = (ExecCommand*) userdata;
718db961 1413 int r;
fe68089d 1414
718db961
LP
1415 assert(bus);
1416 assert(reply);
fe68089d 1417
718db961
LP
1418 r = sd_bus_message_open_container(reply, 'a', "(sasbttttuii)");
1419 if (r < 0)
1420 return r;
fe68089d 1421
4d4c80d0
LP
1422 r = append_exec_command(reply, c);
1423 if (r < 0)
1424 return r;
fe68089d 1425
4d4c80d0
LP
1426 return sd_bus_message_close_container(reply);
1427}
718db961 1428
4d4c80d0
LP
1429int bus_property_get_exec_command_list(
1430 sd_bus *bus,
1431 const char *path,
1432 const char *interface,
1433 const char *property,
1434 sd_bus_message *reply,
1435 void *userdata,
1436 sd_bus_error *ret_error) {
718db961 1437
03677889 1438 ExecCommand *exec_command = *(ExecCommand**) userdata;
4d4c80d0 1439 int r;
718db961 1440
4d4c80d0
LP
1441 assert(bus);
1442 assert(reply);
1443
1444 r = sd_bus_message_open_container(reply, 'a', "(sasbttttuii)");
1445 if (r < 0)
1446 return r;
718db961 1447
03677889 1448 LIST_FOREACH(command, c, exec_command) {
4d4c80d0 1449 r = append_exec_command(reply, c);
718db961
LP
1450 if (r < 0)
1451 return r;
fe68089d
LP
1452 }
1453
718db961 1454 return sd_bus_message_close_container(reply);
8351ceae 1455}
c7040b5d 1456
b3d59367
AZ
1457int bus_property_get_exec_ex_command_list(
1458 sd_bus *bus,
1459 const char *path,
1460 const char *interface,
1461 const char *property,
1462 sd_bus_message *reply,
1463 void *userdata,
1464 sd_bus_error *ret_error) {
1465
03677889 1466 ExecCommand *exec_command = *(ExecCommand**) userdata;
b3d59367
AZ
1467 int r;
1468
1469 assert(bus);
1470 assert(reply);
1471
1472 r = sd_bus_message_open_container(reply, 'a', "(sasasttttuii)");
1473 if (r < 0)
1474 return r;
1475
1476 LIST_FOREACH(command, c, exec_command) {
1477 r = append_exec_ex_command(reply, c);
1478 if (r < 0)
1479 return r;
1480 }
1481
1482 return sd_bus_message_close_container(reply);
1483}
1484
1485static char *exec_command_flags_to_exec_chars(ExecCommandFlags flags) {
a4fc96c8
ZJS
1486 return strjoin(FLAGS_SET(flags, EXEC_COMMAND_IGNORE_FAILURE) ? "-" : "",
1487 FLAGS_SET(flags, EXEC_COMMAND_NO_ENV_EXPAND) ? ":" : "",
1488 FLAGS_SET(flags, EXEC_COMMAND_FULLY_PRIVILEGED) ? "+" : "",
1489 FLAGS_SET(flags, EXEC_COMMAND_NO_SETUID) ? "!" : "",
1490 FLAGS_SET(flags, EXEC_COMMAND_AMBIENT_MAGIC) ? "!!" : "");
b3d59367
AZ
1491}
1492
237f7bcb 1493int bus_set_transient_exec_command(
9c0320e7
YW
1494 Unit *u,
1495 const char *name,
1496 ExecCommand **exec_command,
1497 sd_bus_message *message,
1498 UnitWriteFlags flags,
1499 sd_bus_error *error) {
b3d59367 1500 bool is_ex_prop = endswith(name, "Ex");
9c0320e7
YW
1501 unsigned n = 0;
1502 int r;
1503
b3d59367 1504 r = sd_bus_message_enter_container(message, 'a', is_ex_prop ? "(sasas)" : "(sasb)");
9c0320e7
YW
1505 if (r < 0)
1506 return r;
1507
b3d59367
AZ
1508 while ((r = sd_bus_message_enter_container(message, 'r', is_ex_prop ? "sasas" : "sasb")) > 0) {
1509 _cleanup_strv_free_ char **argv = NULL, **ex_opts = NULL;
9c0320e7
YW
1510 const char *path;
1511 int b;
1512
1513 r = sd_bus_message_read(message, "s", &path);
1514 if (r < 0)
1515 return r;
1516
8038b99d
ZJS
1517 if (!path_is_absolute(path) && !filename_is_valid(path))
1518 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS,
1519 "\"%s\" is neither a valid executable name nor an absolute path",
1520 path);
9c0320e7
YW
1521
1522 r = sd_bus_message_read_strv(message, &argv);
1523 if (r < 0)
1524 return r;
1525
29500cf8
HC
1526 if (strv_isempty(argv))
1527 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS,
1528 "\"%s\" argv cannot be empty", name);
1529
b3d59367 1530 r = is_ex_prop ? sd_bus_message_read_strv(message, &ex_opts) : sd_bus_message_read(message, "b", &b);
9c0320e7
YW
1531 if (r < 0)
1532 return r;
1533
1534 r = sd_bus_message_exit_container(message);
1535 if (r < 0)
1536 return r;
1537
1538 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
1539 ExecCommand *c;
1540
1541 c = new0(ExecCommand, 1);
1542 if (!c)
1543 return -ENOMEM;
1544
1545 c->path = strdup(path);
1546 if (!c->path) {
1547 free(c);
1548 return -ENOMEM;
1549 }
1550
ae2a15bc 1551 c->argv = TAKE_PTR(argv);
9c0320e7 1552
b3d59367
AZ
1553 if (is_ex_prop) {
1554 r = exec_command_flags_from_strv(ex_opts, &c->flags);
1555 if (r < 0)
1556 return r;
1557 } else
1558 c->flags = b ? EXEC_COMMAND_IGNORE_FAILURE : 0;
9c0320e7 1559
4ff361cc 1560 path_simplify(c->path);
9c0320e7
YW
1561 exec_command_append_list(exec_command, c);
1562 }
1563
1564 n++;
1565 }
1566 if (r < 0)
1567 return r;
1568
1569 r = sd_bus_message_exit_container(message);
1570 if (r < 0)
1571 return r;
1572
1573 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
1574 _cleanup_free_ char *buf = NULL;
1575 _cleanup_fclose_ FILE *f = NULL;
9c0320e7
YW
1576 size_t size = 0;
1577
1578 if (n == 0)
1579 *exec_command = exec_command_free_list(*exec_command);
1580
2fe21124 1581 f = open_memstream_unlocked(&buf, &size);
9c0320e7
YW
1582 if (!f)
1583 return -ENOMEM;
1584
f14bf013 1585 fprintf(f, "%s=\n", name);
9c0320e7
YW
1586
1587 LIST_FOREACH(command, c, *exec_command) {
540ac933 1588 _cleanup_free_ char *a = NULL, *exec_chars = NULL;
9c0320e7 1589
540ac933
LP
1590 exec_chars = exec_command_flags_to_exec_chars(c->flags);
1591 if (!exec_chars)
9c0320e7
YW
1592 return -ENOMEM;
1593
24536beb 1594 a = unit_concat_strv(c->argv, UNIT_ESCAPE_SPECIFIERS|UNIT_ESCAPE_EXEC_SYNTAX);
9c0320e7
YW
1595 if (!a)
1596 return -ENOMEM;
1597
540ac933
LP
1598 if (streq_ptr(c->path, c->argv ? c->argv[0] : NULL))
1599 fprintf(f, "%s=%s%s\n", name, exec_chars, a);
1600 else {
1601 _cleanup_free_ char *t = NULL;
1602 const char *p;
1603
24536beb
ZJS
1604 p = unit_escape_setting(c->path,
1605 UNIT_ESCAPE_SPECIFIERS|UNIT_ESCAPE_EXEC_SYNTAX, &t);
540ac933
LP
1606 if (!p)
1607 return -ENOMEM;
b3d59367 1608
540ac933
LP
1609 fprintf(f, "%s=%s@%s %s\n", name, exec_chars, p, a);
1610 }
9c0320e7
YW
1611 }
1612
1613 r = fflush_and_check(f);
1614 if (r < 0)
1615 return r;
1616
1617 unit_write_setting(u, flags, name, buf);
1618 }
1619
1620 return 1;
1621}
1622
7e2a3fcc
YW
1623static int parse_personality(const char *s, unsigned long *p) {
1624 unsigned long v;
1625
1626 assert(p);
1627
1628 v = personality_from_string(s);
1629 if (v == PERSONALITY_INVALID)
1630 return -EINVAL;
1631
1632 *p = v;
1633 return 0;
1634}
1635
1636static const char* mount_propagation_flags_to_string_with_check(unsigned long n) {
1637 if (!IN_SET(n, 0, MS_SHARED, MS_PRIVATE, MS_SLAVE))
1638 return NULL;
1639
1640 return mount_propagation_flags_to_string(n);
1641}
1642
1643static BUS_DEFINE_SET_TRANSIENT(nsec, "t", uint64_t, nsec_t, NSEC_FMT);
1644static BUS_DEFINE_SET_TRANSIENT_IS_VALID(log_level, "i", int32_t, int, "%" PRIi32, log_level_is_valid);
aad67b80 1645#if HAVE_SECCOMP
005bfaf1 1646static BUS_DEFINE_SET_TRANSIENT_IS_VALID(errno, "i", int32_t, int, "%" PRIi32, seccomp_errno_or_action_is_valid);
aad67b80 1647#endif
7e2a3fcc
YW
1648static BUS_DEFINE_SET_TRANSIENT_PARSE(std_input, ExecInput, exec_input_from_string);
1649static BUS_DEFINE_SET_TRANSIENT_PARSE(std_output, ExecOutput, exec_output_from_string);
1650static BUS_DEFINE_SET_TRANSIENT_PARSE(utmp_mode, ExecUtmpMode, exec_utmp_mode_from_string);
1e8c7bd5
YW
1651static BUS_DEFINE_SET_TRANSIENT_PARSE(protect_system, ProtectSystem, protect_system_from_string);
1652static BUS_DEFINE_SET_TRANSIENT_PARSE(protect_home, ProtectHome, protect_home_from_string);
7e2a3fcc 1653static BUS_DEFINE_SET_TRANSIENT_PARSE(keyring_mode, ExecKeyringMode, exec_keyring_mode_from_string);
4e399953
LP
1654static BUS_DEFINE_SET_TRANSIENT_PARSE(protect_proc, ProtectProc, protect_proc_from_string);
1655static BUS_DEFINE_SET_TRANSIENT_PARSE(proc_subset, ProcSubset, proc_subset_from_string);
7e2a3fcc
YW
1656static BUS_DEFINE_SET_TRANSIENT_PARSE(preserve_mode, ExecPreserveMode, exec_preserve_mode_from_string);
1657static BUS_DEFINE_SET_TRANSIENT_PARSE_PTR(personality, unsigned long, parse_personality);
1658static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(secure_bits, "i", int32_t, int, "%" PRIi32, secure_bits_to_string_alloc_with_check);
1659static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(capability, "t", uint64_t, uint64_t, "%" PRIu64, capability_set_to_string_alloc);
86c2a9f1 1660static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(namespace_flag, "t", uint64_t, unsigned long, "%" PRIu64, namespace_flags_to_string);
7e2a3fcc
YW
1661static BUS_DEFINE_SET_TRANSIENT_TO_STRING(mount_flags, "t", uint64_t, unsigned long, "%" PRIu64, mount_propagation_flags_to_string_with_check);
1662
c7040b5d
LP
1663int bus_exec_context_set_transient_property(
1664 Unit *u,
1665 ExecContext *c,
1666 const char *name,
1667 sd_bus_message *message,
2e59b241 1668 UnitWriteFlags flags,
c7040b5d
LP
1669 sd_bus_error *error) {
1670
6550c24c
LP
1671 const char *suffix;
1672 int r;
c7040b5d
LP
1673
1674 assert(u);
1675 assert(c);
1676 assert(name);
1677 assert(message);
1678
2e59b241
LP
1679 flags |= UNIT_PRIVATE;
1680
7e2a3fcc 1681 if (streq(name, "User"))
7a8867ab 1682 return bus_set_transient_user_relaxed(u, name, &c->user, message, flags, error);
c7040b5d 1683
7e2a3fcc 1684 if (streq(name, "Group"))
7a8867ab 1685 return bus_set_transient_user_relaxed(u, name, &c->group, message, flags, error);
c7040b5d 1686
7e2a3fcc
YW
1687 if (streq(name, "TTYPath"))
1688 return bus_set_transient_path(u, name, &c->tty_path, message, flags, error);
6f3e7985 1689
7e2a3fcc
YW
1690 if (streq(name, "RootImage"))
1691 return bus_set_transient_path(u, name, &c->root_image, message, flags, error);
76736280 1692
18d73705
LB
1693 if (streq(name, "RootImageOptions")) {
1694 _cleanup_(mount_options_free_allp) MountOptions *options = NULL;
1695 _cleanup_free_ char *format_str = NULL;
18d73705 1696
988172ce 1697 r = bus_read_mount_options(message, error, &options, &format_str, " ");
18d73705
LB
1698 if (r < 0)
1699 return r;
1700
1701 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
64903d18 1702 if (options) {
18d73705
LB
1703 LIST_JOIN(mount_options, c->root_image_options, options);
1704 unit_write_settingf(
1705 u, flags|UNIT_ESCAPE_SPECIFIERS, name,
1706 "%s=%s",
1707 name,
1708 format_str);
64903d18
ZJS
1709 } else {
1710 c->root_image_options = mount_options_free_all(c->root_image_options);
1711 unit_write_settingf(u, flags, name, "%s=", name);
18d73705
LB
1712 }
1713 }
1714
1715 return 1;
1716 }
1717
0389f4fa
LB
1718 if (streq(name, "RootHash")) {
1719 const void *roothash_decoded;
1720 size_t roothash_decoded_size;
1721
1722 r = sd_bus_message_read_array(message, 'y', &roothash_decoded, &roothash_decoded_size);
1723 if (r < 0)
1724 return r;
1725
1726 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
1727 _cleanup_free_ char *encoded = NULL;
1728
1729 if (roothash_decoded_size == 0) {
1730 c->root_hash_path = mfree(c->root_hash_path);
1731 c->root_hash = mfree(c->root_hash);
1732 c->root_hash_size = 0;
1733
1734 unit_write_settingf(u, flags, name, "RootHash=");
1735 } else {
c2b2df60 1736 _cleanup_free_ void *p = NULL;
0389f4fa
LB
1737
1738 encoded = hexmem(roothash_decoded, roothash_decoded_size);
1739 if (!encoded)
1740 return -ENOMEM;
1741
1742 p = memdup(roothash_decoded, roothash_decoded_size);
1743 if (!p)
1744 return -ENOMEM;
1745
1746 free_and_replace(c->root_hash, p);
1747 c->root_hash_size = roothash_decoded_size;
1748 c->root_hash_path = mfree(c->root_hash_path);
1749
1750 unit_write_settingf(u, flags, name, "RootHash=%s", encoded);
1751 }
1752 }
1753
1754 return 1;
1755 }
1756
1757 if (streq(name, "RootHashPath")) {
1758 c->root_hash_size = 0;
1759 c->root_hash = mfree(c->root_hash);
1760
1761 return bus_set_transient_path(u, "RootHash", &c->root_hash_path, message, flags, error);
1762 }
1763
d4d55b0d
LB
1764 if (streq(name, "RootHashSignature")) {
1765 const void *roothash_sig_decoded;
1766 size_t roothash_sig_decoded_size;
1767
1768 r = sd_bus_message_read_array(message, 'y', &roothash_sig_decoded, &roothash_sig_decoded_size);
1769 if (r < 0)
1770 return r;
1771
1772 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
1773 _cleanup_free_ char *encoded = NULL;
1774
1775 if (roothash_sig_decoded_size == 0) {
1776 c->root_hash_sig_path = mfree(c->root_hash_sig_path);
1777 c->root_hash_sig = mfree(c->root_hash_sig);
1778 c->root_hash_sig_size = 0;
1779
1780 unit_write_settingf(u, flags, name, "RootHashSignature=");
1781 } else {
c2b2df60 1782 _cleanup_free_ void *p = NULL;
d4d55b0d
LB
1783 ssize_t len;
1784
1785 len = base64mem(roothash_sig_decoded, roothash_sig_decoded_size, &encoded);
1786 if (len < 0)
1787 return -ENOMEM;
1788
1789 p = memdup(roothash_sig_decoded, roothash_sig_decoded_size);
1790 if (!p)
1791 return -ENOMEM;
1792
1793 free_and_replace(c->root_hash_sig, p);
1794 c->root_hash_sig_size = roothash_sig_decoded_size;
1795 c->root_hash_sig_path = mfree(c->root_hash_sig_path);
1796
1797 unit_write_settingf(u, flags, name, "RootHashSignature=base64:%s", encoded);
1798 }
1799 }
1800
1801 return 1;
1802 }
1803
1804 if (streq(name, "RootHashSignaturePath")) {
1805 c->root_hash_sig_size = 0;
1806 c->root_hash_sig = mfree(c->root_hash_sig);
1807
1808 return bus_set_transient_path(u, "RootHashSignature", &c->root_hash_sig_path, message, flags, error);
1809 }
1810
0389f4fa
LB
1811 if (streq(name, "RootVerity"))
1812 return bus_set_transient_path(u, name, &c->root_verity, message, flags, error);
1813
7e2a3fcc
YW
1814 if (streq(name, "RootDirectory"))
1815 return bus_set_transient_path(u, name, &c->root_directory, message, flags, error);
c7040b5d 1816
7e2a3fcc
YW
1817 if (streq(name, "SyslogIdentifier"))
1818 return bus_set_transient_string(u, name, &c->syslog_identifier, message, flags, error);
c7040b5d 1819
7e2a3fcc
YW
1820 if (streq(name, "LogLevelMax"))
1821 return bus_set_transient_log_level(u, name, &c->log_level_max, message, flags, error);
1822
90fc172e 1823 if (streq(name, "LogRateLimitIntervalUSec"))
5ac1530e 1824 return bus_set_transient_usec(u, name, &c->log_ratelimit_interval_usec, message, flags, error);
90fc172e
AZ
1825
1826 if (streq(name, "LogRateLimitBurst"))
5ac1530e 1827 return bus_set_transient_unsigned(u, name, &c->log_ratelimit_burst, message, flags, error);
90fc172e 1828
7e2a3fcc
YW
1829 if (streq(name, "Personality"))
1830 return bus_set_transient_personality(u, name, &c->personality, message, flags, error);
1831
7e2a3fcc
YW
1832 if (streq(name, "StandardInput"))
1833 return bus_set_transient_std_input(u, name, &c->std_input, message, flags, error);
1834
1835 if (streq(name, "StandardOutput"))
1836 return bus_set_transient_std_output(u, name, &c->std_output, message, flags, error);
1837
1838 if (streq(name, "StandardError"))
1839 return bus_set_transient_std_output(u, name, &c->std_error, message, flags, error);
1840
1841 if (streq(name, "IgnoreSIGPIPE"))
1842 return bus_set_transient_bool(u, name, &c->ignore_sigpipe, message, flags, error);
1843
1844 if (streq(name, "TTYVHangup"))
1845 return bus_set_transient_bool(u, name, &c->tty_vhangup, message, flags, error);
1846
1847 if (streq(name, "TTYReset"))
1848 return bus_set_transient_bool(u, name, &c->tty_reset, message, flags, error);
1849
1850 if (streq(name, "TTYVTDisallocate"))
1851 return bus_set_transient_bool(u, name, &c->tty_vt_disallocate, message, flags, error);
51462135
DDM
1852
1853 if (streq(name, "TTYRows"))
1854 return bus_set_transient_unsigned(u, name, &c->tty_rows, message, flags, error);
1855
1856 if (streq(name, "TTYColumns"))
1857 return bus_set_transient_unsigned(u, name, &c->tty_cols, message, flags, error);
7e2a3fcc
YW
1858
1859 if (streq(name, "PrivateTmp"))
1860 return bus_set_transient_bool(u, name, &c->private_tmp, message, flags, error);
1861
1862 if (streq(name, "PrivateDevices"))
1863 return bus_set_transient_bool(u, name, &c->private_devices, message, flags, error);
1864
228af36f
LP
1865 if (streq(name, "PrivateMounts"))
1866 return bus_set_transient_bool(u, name, &c->private_mounts, message, flags, error);
1867
7e2a3fcc
YW
1868 if (streq(name, "PrivateNetwork"))
1869 return bus_set_transient_bool(u, name, &c->private_network, message, flags, error);
1870
a70581ff
XR
1871 if (streq(name, "PrivateIPC"))
1872 return bus_set_transient_bool(u, name, &c->private_ipc, message, flags, error);
1873
7e2a3fcc
YW
1874 if (streq(name, "PrivateUsers"))
1875 return bus_set_transient_bool(u, name, &c->private_users, message, flags, error);
1876
1877 if (streq(name, "NoNewPrivileges"))
1878 return bus_set_transient_bool(u, name, &c->no_new_privileges, message, flags, error);
1879
1880 if (streq(name, "SyslogLevelPrefix"))
1881 return bus_set_transient_bool(u, name, &c->syslog_level_prefix, message, flags, error);
1882
1883 if (streq(name, "MemoryDenyWriteExecute"))
1884 return bus_set_transient_bool(u, name, &c->memory_deny_write_execute, message, flags, error);
1885
1886 if (streq(name, "RestrictRealtime"))
1887 return bus_set_transient_bool(u, name, &c->restrict_realtime, message, flags, error);
1888
f69567cb
LP
1889 if (streq(name, "RestrictSUIDSGID"))
1890 return bus_set_transient_bool(u, name, &c->restrict_suid_sgid, message, flags, error);
1891
7e2a3fcc
YW
1892 if (streq(name, "DynamicUser"))
1893 return bus_set_transient_bool(u, name, &c->dynamic_user, message, flags, error);
1894
1895 if (streq(name, "RemoveIPC"))
1896 return bus_set_transient_bool(u, name, &c->remove_ipc, message, flags, error);
1897
1898 if (streq(name, "ProtectKernelTunables"))
1899 return bus_set_transient_bool(u, name, &c->protect_kernel_tunables, message, flags, error);
1900
1901 if (streq(name, "ProtectKernelModules"))
1902 return bus_set_transient_bool(u, name, &c->protect_kernel_modules, message, flags, error);
1903
84703040
KK
1904 if (streq(name, "ProtectKernelLogs"))
1905 return bus_set_transient_bool(u, name, &c->protect_kernel_logs, message, flags, error);
1906
fc64760d
KK
1907 if (streq(name, "ProtectClock"))
1908 return bus_set_transient_bool(u, name, &c->protect_clock, message, flags, error);
1909
7e2a3fcc
YW
1910 if (streq(name, "ProtectControlGroups"))
1911 return bus_set_transient_bool(u, name, &c->protect_control_groups, message, flags, error);
1912
7e2a3fcc
YW
1913 if (streq(name, "CPUSchedulingResetOnFork"))
1914 return bus_set_transient_bool(u, name, &c->cpu_sched_reset_on_fork, message, flags, error);
1915
1916 if (streq(name, "NonBlocking"))
1917 return bus_set_transient_bool(u, name, &c->non_blocking, message, flags, error);
1918
1919 if (streq(name, "LockPersonality"))
1920 return bus_set_transient_bool(u, name, &c->lock_personality, message, flags, error);
1921
aecd5ac6
TM
1922 if (streq(name, "ProtectHostname"))
1923 return bus_set_transient_bool(u, name, &c->protect_hostname, message, flags, error);
1924
7e2a3fcc
YW
1925 if (streq(name, "UtmpIdentifier"))
1926 return bus_set_transient_string(u, name, &c->utmp_id, message, flags, error);
1927
1928 if (streq(name, "UtmpMode"))
1929 return bus_set_transient_utmp_mode(u, name, &c->utmp_mode, message, flags, error);
1930
1931 if (streq(name, "PAMName"))
1932 return bus_set_transient_string(u, name, &c->pam_name, message, flags, error);
1933
1934 if (streq(name, "TimerSlackNSec"))
1935 return bus_set_transient_nsec(u, name, &c->timer_slack_nsec, message, flags, error);
1936
1937 if (streq(name, "ProtectSystem"))
1938 return bus_set_transient_protect_system(u, name, &c->protect_system, message, flags, error);
1939
1940 if (streq(name, "ProtectHome"))
1941 return bus_set_transient_protect_home(u, name, &c->protect_home, message, flags, error);
cffaed83 1942
7e2a3fcc
YW
1943 if (streq(name, "KeyringMode"))
1944 return bus_set_transient_keyring_mode(u, name, &c->keyring_mode, message, flags, error);
1945
4e399953
LP
1946 if (streq(name, "ProtectProc"))
1947 return bus_set_transient_protect_proc(u, name, &c->protect_proc, message, flags, error);
1948
1949 if (streq(name, "ProcSubset"))
1950 return bus_set_transient_proc_subset(u, name, &c->proc_subset, message, flags, error);
1951
7e2a3fcc
YW
1952 if (streq(name, "RuntimeDirectoryPreserve"))
1953 return bus_set_transient_preserve_mode(u, name, &c->runtime_directory_preserve_mode, message, flags, error);
1954
1955 if (streq(name, "UMask"))
1956 return bus_set_transient_mode_t(u, name, &c->umask, message, flags, error);
1957
1958 if (streq(name, "RuntimeDirectoryMode"))
1959 return bus_set_transient_mode_t(u, name, &c->directories[EXEC_DIRECTORY_RUNTIME].mode, message, flags, error);
1960
1961 if (streq(name, "StateDirectoryMode"))
1962 return bus_set_transient_mode_t(u, name, &c->directories[EXEC_DIRECTORY_STATE].mode, message, flags, error);
1963
1964 if (streq(name, "CacheDirectoryMode"))
1965 return bus_set_transient_mode_t(u, name, &c->directories[EXEC_DIRECTORY_CACHE].mode, message, flags, error);
1966
1967 if (streq(name, "LogsDirectoryMode"))
1968 return bus_set_transient_mode_t(u, name, &c->directories[EXEC_DIRECTORY_LOGS].mode, message, flags, error);
1969
1970 if (streq(name, "ConfigurationDirectoryMode"))
1971 return bus_set_transient_mode_t(u, name, &c->directories[EXEC_DIRECTORY_CONFIGURATION].mode, message, flags, error);
1972
1973 if (streq(name, "SELinuxContext"))
1974 return bus_set_transient_string(u, name, &c->selinux_context, message, flags, error);
1975
1976 if (streq(name, "SecureBits"))
1977 return bus_set_transient_secure_bits(u, name, &c->secure_bits, message, flags, error);
1978
1979 if (streq(name, "CapabilityBoundingSet"))
1980 return bus_set_transient_capability(u, name, &c->capability_bounding_set, message, flags, error);
1981
1982 if (streq(name, "AmbientCapabilities"))
1983 return bus_set_transient_capability(u, name, &c->capability_ambient_set, message, flags, error);
1984
7e2a3fcc
YW
1985 if (streq(name, "RestrictNamespaces"))
1986 return bus_set_transient_namespace_flag(u, name, &c->restrict_namespaces, message, flags, error);
1987
cc86a278
ILG
1988 if (streq(name, "RestrictFileSystems")) {
1989 int allow_list;
1990 _cleanup_strv_free_ char **l = NULL;
1991
1992 r = sd_bus_message_enter_container(message, 'r', "bas");
1993 if (r < 0)
1994 return r;
1995
1996 r = sd_bus_message_read(message, "b", &allow_list);
1997 if (r < 0)
1998 return r;
1999
2000 r = sd_bus_message_read_strv(message, &l);
2001 if (r < 0)
2002 return r;
2003
2004 r = sd_bus_message_exit_container(message);
2005 if (r < 0)
2006 return r;
2007
2008 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2009 _cleanup_free_ char *joined = NULL;
2010 FilesystemParseFlags invert_flag = allow_list ? 0 : FILESYSTEM_PARSE_INVERT;
cc86a278
ILG
2011
2012 if (strv_isempty(l)) {
2013 c->restrict_filesystems_allow_list = false;
2014 c->restrict_filesystems = set_free(c->restrict_filesystems);
2015
2016 unit_write_setting(u, flags, name, "RestrictFileSystems=");
2017 return 1;
2018 }
2019
2020 if (!c->restrict_filesystems)
2021 c->restrict_filesystems_allow_list = allow_list;
2022
2023 STRV_FOREACH(s, l) {
2024 r = lsm_bpf_parse_filesystem(
2025 *s,
2026 &c->restrict_filesystems,
2027 FILESYSTEM_PARSE_LOG|
2028 (invert_flag ? FILESYSTEM_PARSE_INVERT : 0)|
2029 (c->restrict_filesystems_allow_list ? FILESYSTEM_PARSE_ALLOW_LIST : 0),
2030 u->id, NULL, 0);
2031 if (r < 0)
2032 return r;
2033 }
2034
2035 joined = strv_join(l, " ");
2036 if (!joined)
2037 return -ENOMEM;
2038
2039 unit_write_settingf(u, flags, name, "%s=%s%s", name, allow_list ? "" : "~", joined);
2040 }
2041
2042 return 1;
2043 }
2044
7e2a3fcc
YW
2045 if (streq(name, "MountFlags"))
2046 return bus_set_transient_mount_flags(u, name, &c->mount_flags, message, flags, error);
2047
a8d08f39
LP
2048 if (streq(name, "NetworkNamespacePath"))
2049 return bus_set_transient_path(u, name, &c->network_namespace_path, message, flags, error);
2050
a70581ff
XR
2051 if (streq(name, "IPCNamespacePath"))
2052 return bus_set_transient_path(u, name, &c->ipc_namespace_path, message, flags, error);
2053
7e2a3fcc 2054 if (streq(name, "SupplementaryGroups")) {
cffaed83 2055 _cleanup_strv_free_ char **l = NULL;
cffaed83
YW
2056
2057 r = sd_bus_message_read_strv(message, &l);
2058 if (r < 0)
2059 return r;
2060
d2a23692 2061 STRV_FOREACH(p, l)
7a8867ab 2062 if (!isempty(*p) && !valid_user_group_name(*p, VALID_USER_ALLOW_NUMERIC|VALID_USER_RELAX|VALID_USER_WARN))
d2a23692
ZJS
2063 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS,
2064 "Invalid supplementary group names");
cffaed83 2065
2e59b241 2066 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
7b943bb7 2067 if (strv_isempty(l)) {
cffaed83 2068 c->supplementary_groups = strv_free(c->supplementary_groups);
2e59b241 2069 unit_write_settingf(u, flags, name, "%s=", name);
cffaed83
YW
2070 } else {
2071 _cleanup_free_ char *joined = NULL;
2072
2073 r = strv_extend_strv(&c->supplementary_groups, l, true);
2074 if (r < 0)
2075 return -ENOMEM;
2076
2077 joined = strv_join(c->supplementary_groups, " ");
2078 if (!joined)
2079 return -ENOMEM;
2080
2e59b241 2081 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "%s=%s", name, joined);
cffaed83
YW
2082 }
2083 }
2084
2085 return 1;
2086
43144be4 2087 } else if (STR_IN_SET(name, "SetCredential", "SetCredentialEncrypted")) {
bb0c0d6f
LP
2088 bool isempty = true;
2089
2090 r = sd_bus_message_enter_container(message, 'a', "(say)");
2091 if (r < 0)
2092 return r;
2093
2094 for (;;) {
2095 const char *id;
2096 const void *p;
2097 size_t sz;
2098
2099 r = sd_bus_message_enter_container(message, 'r', "say");
2100 if (r < 0)
2101 return r;
2102 if (r == 0)
2103 break;
2104
2105 r = sd_bus_message_read(message, "s", &id);
2106 if (r < 0)
2107 return r;
2108
2109 r = sd_bus_message_read_array(message, 'y', &p, &sz);
2110 if (r < 0)
2111 return r;
2112
2113 r = sd_bus_message_exit_container(message);
2114 if (r < 0)
2115 return r;
2116
2117 if (!credential_name_valid(id))
2118 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Credential ID is invalid: %s", id);
2119
2120 isempty = false;
2121
2122 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2123 _cleanup_free_ char *a = NULL, *b = NULL;
2124 _cleanup_free_ void *copy = NULL;
2125 ExecSetCredential *old;
2126
2127 copy = memdup(p, sz);
2128 if (!copy)
2129 return -ENOMEM;
2130
2131 old = hashmap_get(c->set_credentials, id);
2132 if (old) {
2133 free_and_replace(old->data, copy);
2134 old->size = sz;
43144be4 2135 old->encrypted = streq(name, "SetCredentialEncrypted");
bb0c0d6f
LP
2136 } else {
2137 _cleanup_(exec_set_credential_freep) ExecSetCredential *sc = NULL;
2138
43144be4 2139 sc = new(ExecSetCredential, 1);
bb0c0d6f
LP
2140 if (!sc)
2141 return -ENOMEM;
2142
43144be4
LP
2143 *sc = (ExecSetCredential) {
2144 .id = strdup(id),
2145 .data = TAKE_PTR(copy),
2146 .size = sz,
2147 .encrypted = streq(name, "SetCredentialEncrypted"),
2148 };
2149
bb0c0d6f
LP
2150 if (!sc->id)
2151 return -ENOMEM;
2152
cf55fe4a 2153 r = hashmap_ensure_put(&c->set_credentials, &exec_set_credential_hash_ops, sc->id, sc);
bb0c0d6f
LP
2154 if (r < 0)
2155 return r;
2156
2157 TAKE_PTR(sc);
2158 }
2159
2160 a = specifier_escape(id);
2161 if (!a)
2162 return -ENOMEM;
2163
2164 b = cescape_length(p, sz);
2165 if (!b)
2166 return -ENOMEM;
2167
2168 (void) unit_write_settingf(u, flags, name, "%s=%s:%s", name, a, b);
2169 }
2170 }
2171
2172 r = sd_bus_message_exit_container(message);
2173 if (r < 0)
2174 return r;
2175
2176 if (!UNIT_WRITE_FLAGS_NOOP(flags) && isempty) {
2177 c->set_credentials = hashmap_free(c->set_credentials);
2178 (void) unit_write_settingf(u, flags, name, "%s=", name);
2179 }
2180
2181 return 1;
2182
43144be4 2183 } else if (STR_IN_SET(name, "LoadCredential", "LoadCredentialEncrypted")) {
bb0c0d6f
LP
2184 bool isempty = true;
2185
2186 r = sd_bus_message_enter_container(message, 'a', "(ss)");
2187 if (r < 0)
2188 return r;
2189
2190 for (;;) {
2191 const char *id, *source;
2192
2193 r = sd_bus_message_read(message, "(ss)", &id, &source);
2194 if (r < 0)
2195 return r;
2196 if (r == 0)
2197 break;
2198
2199 if (!credential_name_valid(id))
2200 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Credential ID is invalid: %s", id);
2201
2202 if (!(path_is_absolute(source) ? path_is_normalized(source) : credential_name_valid(source)))
2203 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Credential source is invalid: %s", source);
2204
2205 isempty = false;
2206
2207 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
43144be4
LP
2208 _cleanup_free_ char *copy = NULL;
2209 ExecLoadCredential *old;
2210
2211 copy = strdup(source);
2212 if (!copy)
2213 return -ENOMEM;
2214
2215 old = hashmap_get(c->load_credentials, id);
2216 if (old) {
2217 free_and_replace(old->path, copy);
2218 old->encrypted = streq(name, "LoadCredentialEncrypted");
2219 } else {
2220 _cleanup_(exec_load_credential_freep) ExecLoadCredential *lc = NULL;
2221
2222 lc = new(ExecLoadCredential, 1);
2223 if (!lc)
2224 return -ENOMEM;
2225
2226 *lc = (ExecLoadCredential) {
2227 .id = strdup(id),
2228 .path = TAKE_PTR(copy),
2229 .encrypted = streq(name, "LoadCredentialEncrypted"),
2230 };
2231
2232 if (!lc->id)
2233 return -ENOMEM;
2234
2235 r = hashmap_ensure_put(&c->load_credentials, &exec_load_credential_hash_ops, lc->id, lc);
2236 if (r < 0)
2237 return r;
2238
2239 TAKE_PTR(lc);
2240 }
bb0c0d6f
LP
2241
2242 (void) unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "%s=%s:%s", name, id, source);
2243 }
2244 }
2245
2246 r = sd_bus_message_exit_container(message);
2247 if (r < 0)
2248 return r;
2249
2250 if (!UNIT_WRITE_FLAGS_NOOP(flags) && isempty) {
43144be4 2251 c->load_credentials = hashmap_free(c->load_credentials);
bb0c0d6f
LP
2252 (void) unit_write_settingf(u, flags, name, "%s=", name);
2253 }
2254
2255 return 1;
2256
a8a13575 2257 } else if (streq(name, "SyslogLevel")) {
8d1dd6ab 2258 int32_t level;
a8a13575
EV
2259
2260 r = sd_bus_message_read(message, "i", &level);
2261 if (r < 0)
2262 return r;
2263
e0d6e0fa 2264 if (!log_level_is_valid(level))
1b09b81c 2265 return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Log level value out of range");
e0d6e0fa 2266
2e59b241 2267 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
a8a13575 2268 c->syslog_priority = (c->syslog_priority & LOG_FACMASK) | level;
2e59b241 2269 unit_write_settingf(u, flags, name, "SyslogLevel=%i", level);
a8a13575
EV
2270 }
2271
460ed929 2272 return 1;
7e2a3fcc 2273
460ed929 2274 } else if (streq(name, "SyslogFacility")) {
8d1dd6ab 2275 int32_t facility;
460ed929
EV
2276
2277 r = sd_bus_message_read(message, "i", &facility);
2278 if (r < 0)
2279 return r;
2280
e0d6e0fa 2281 if (!log_facility_unshifted_is_valid(facility))
1b09b81c 2282 return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Log facility value out of range");
e0d6e0fa 2283
2e59b241 2284 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
460ed929 2285 c->syslog_priority = (facility << 3) | LOG_PRI(c->syslog_priority);
2e59b241 2286 unit_write_settingf(u, flags, name, "SyslogFacility=%i", facility);
460ed929
EV
2287 }
2288
cffaed83 2289 return 1;
d3070fbd 2290
91dd5f7c
LP
2291 } else if (streq(name, "LogNamespace")) {
2292 const char *n;
2293
2294 r = sd_bus_message_read(message, "s", &n);
2295 if (r < 0)
2296 return r;
2297
2298 if (!isempty(n) && !log_namespace_name_valid(n))
1b09b81c 2299 return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Log namespace name not valid");
91dd5f7c
LP
2300
2301 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2302
2303 if (isempty(n)) {
2304 c->log_namespace = mfree(c->log_namespace);
2305 unit_write_settingf(u, flags, name, "%s=", name);
2306 } else {
2307 r = free_and_strdup(&c->log_namespace, n);
2308 if (r < 0)
2309 return r;
2310
2311 unit_write_settingf(u, flags, name, "%s=%s", name, n);
2312 }
2313 }
2314
2315 return 1;
2316
d3070fbd
LP
2317 } else if (streq(name, "LogExtraFields")) {
2318 size_t n = 0;
2319
2320 r = sd_bus_message_enter_container(message, 'a', "ay");
2321 if (r < 0)
2322 return r;
2323
2324 for (;;) {
2325 _cleanup_free_ void *copy = NULL;
2326 struct iovec *t;
2327 const char *eq;
2328 const void *p;
2329 size_t sz;
2330
2331 /* Note that we expect a byte array for each field, instead of a string. That's because on the
2332 * lower-level journal fields can actually contain binary data and are not restricted to text,
2333 * and we should not "lose precision" in our types on the way. That said, I am pretty sure
2334 * actually encoding binary data as unit metadata is not a good idea. Hence we actually refuse
2335 * any actual binary data, and only accept UTF-8. This allows us to eventually lift this
2336 * limitation, should a good, valid usecase arise. */
2337
2338 r = sd_bus_message_read_array(message, 'y', &p, &sz);
2339 if (r < 0)
2340 return r;
2341 if (r == 0)
2342 break;
2343
2344 if (memchr(p, 0, sz))
1b09b81c 2345 return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Journal field contains zero byte");
d3070fbd
LP
2346
2347 eq = memchr(p, '=', sz);
2348 if (!eq)
1b09b81c 2349 return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Journal field contains no '=' character");
d3070fbd 2350 if (!journal_field_valid(p, eq - (const char*) p, false))
1b09b81c 2351 return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Journal field invalid");
d3070fbd 2352
2e59b241 2353 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
aa484f35 2354 t = reallocarray(c->log_extra_fields, c->n_log_extra_fields+1, sizeof(struct iovec));
d3070fbd
LP
2355 if (!t)
2356 return -ENOMEM;
2357 c->log_extra_fields = t;
2358 }
2359
2360 copy = malloc(sz + 1);
2361 if (!copy)
2362 return -ENOMEM;
2363
2364 memcpy(copy, p, sz);
2365 ((uint8_t*) copy)[sz] = 0;
2366
2367 if (!utf8_is_valid(copy))
1b09b81c 2368 return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Journal field is not valid UTF-8");
d3070fbd 2369
2e59b241 2370 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
d3070fbd 2371 c->log_extra_fields[c->n_log_extra_fields++] = IOVEC_MAKE(copy, sz);
2e59b241 2372 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS|UNIT_ESCAPE_C, name, "LogExtraFields=%s", (char*) copy);
d3070fbd
LP
2373
2374 copy = NULL;
2375 }
2376
2377 n++;
2378 }
2379
2380 r = sd_bus_message_exit_container(message);
2381 if (r < 0)
2382 return r;
2383
2e59b241 2384 if (!UNIT_WRITE_FLAGS_NOOP(flags) && n == 0) {
d3070fbd 2385 exec_context_free_log_extra_fields(c);
2e59b241 2386 unit_write_setting(u, flags, name, "LogExtraFields=");
d3070fbd
LP
2387 }
2388
2389 return 1;
7e2a3fcc 2390 }
cffaed83 2391
349cc4a5 2392#if HAVE_SECCOMP
cffaed83 2393
7e2a3fcc
YW
2394 if (streq(name, "SystemCallErrorNumber"))
2395 return bus_set_transient_errno(u, name, &c->syscall_errno, message, flags, error);
2396
2397 if (streq(name, "SystemCallFilter")) {
6b000af4 2398 int allow_list;
3f856a28 2399 _cleanup_strv_free_ char **l = NULL;
cffaed83
YW
2400
2401 r = sd_bus_message_enter_container(message, 'r', "bas");
2402 if (r < 0)
2403 return r;
2404
6b000af4 2405 r = sd_bus_message_read(message, "b", &allow_list);
cffaed83
YW
2406 if (r < 0)
2407 return r;
2408
2409 r = sd_bus_message_read_strv(message, &l);
2410 if (r < 0)
2411 return r;
2412
2413 r = sd_bus_message_exit_container(message);
2414 if (r < 0)
2415 return r;
2416
2e59b241 2417 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
cffaed83 2418 _cleanup_free_ char *joined = NULL;
6b000af4 2419 SeccompParseFlags invert_flag = allow_list ? 0 : SECCOMP_PARSE_INVERT;
cffaed83 2420
7b943bb7 2421 if (strv_isempty(l)) {
6b000af4 2422 c->syscall_allow_list = false;
8cfa775f 2423 c->syscall_filter = hashmap_free(c->syscall_filter);
cffaed83 2424
898748d8
YW
2425 unit_write_settingf(u, flags, name, "SystemCallFilter=");
2426 return 1;
2427 }
cffaed83 2428
898748d8
YW
2429 if (!c->syscall_filter) {
2430 c->syscall_filter = hashmap_new(NULL);
2431 if (!c->syscall_filter)
2432 return log_oom();
cffaed83 2433
6b000af4 2434 c->syscall_allow_list = allow_list;
8cfa775f 2435
6b000af4 2436 if (c->syscall_allow_list) {
e7ccdfa8
ZJS
2437 r = seccomp_parse_syscall_filter("@default",
2438 -1,
2439 c->syscall_filter,
72545ae0 2440 SECCOMP_PARSE_PERMISSIVE |
1008d415 2441 SECCOMP_PARSE_ALLOW_LIST,
58f6ab44
ZJS
2442 u->id,
2443 NULL, 0);
8cfa775f
YW
2444 if (r < 0)
2445 return r;
898748d8
YW
2446 }
2447 }
8cfa775f 2448
898748d8
YW
2449 STRV_FOREACH(s, l) {
2450 _cleanup_free_ char *n = NULL;
2451 int e;
cffaed83 2452
898748d8
YW
2453 r = parse_syscall_and_errno(*s, &n, &e);
2454 if (r < 0)
2455 return r;
cffaed83 2456
084a46d7
YW
2457 if (allow_list && e >= 0)
2458 return -EINVAL;
2459
e7ccdfa8
ZJS
2460 r = seccomp_parse_syscall_filter(n,
2461 e,
2462 c->syscall_filter,
72545ae0
AZ
2463 SECCOMP_PARSE_LOG | SECCOMP_PARSE_PERMISSIVE |
2464 invert_flag |
6b000af4 2465 (c->syscall_allow_list ? SECCOMP_PARSE_ALLOW_LIST : 0),
58f6ab44
ZJS
2466 u->id,
2467 NULL, 0);
898748d8
YW
2468 if (r < 0)
2469 return r;
cffaed83
YW
2470 }
2471
2472 joined = strv_join(l, " ");
2473 if (!joined)
2474 return -ENOMEM;
2475
6b000af4 2476 unit_write_settingf(u, flags, name, "SystemCallFilter=%s%s", allow_list ? "" : "~", joined);
cffaed83
YW
2477 }
2478
2479 return 1;
2480
9df2cdd8
TM
2481 } else if (streq(name, "SystemCallLog")) {
2482 int allow_list;
2483 _cleanup_strv_free_ char **l = NULL;
2484
2485 r = sd_bus_message_enter_container(message, 'r', "bas");
2486 if (r < 0)
2487 return r;
2488
2489 r = sd_bus_message_read(message, "b", &allow_list);
2490 if (r < 0)
2491 return r;
2492
2493 r = sd_bus_message_read_strv(message, &l);
2494 if (r < 0)
2495 return r;
2496
2497 r = sd_bus_message_exit_container(message);
2498 if (r < 0)
2499 return r;
2500
2501 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2502 _cleanup_free_ char *joined = NULL;
2503 SeccompParseFlags invert_flag = allow_list ? 0 : SECCOMP_PARSE_INVERT;
9df2cdd8
TM
2504
2505 if (strv_isempty(l)) {
2506 c->syscall_log_allow_list = false;
2507 c->syscall_log = hashmap_free(c->syscall_log);
2508
2509 unit_write_settingf(u, flags, name, "SystemCallLog=");
2510 return 1;
2511 }
2512
2513 if (!c->syscall_log) {
2514 c->syscall_log = hashmap_new(NULL);
2515 if (!c->syscall_log)
2516 return log_oom();
2517
2518 c->syscall_log_allow_list = allow_list;
2519 }
2520
2521 STRV_FOREACH(s, l) {
696a13ba
YW
2522 r = seccomp_parse_syscall_filter(*s,
2523 -1, /* errno not used */
9df2cdd8
TM
2524 c->syscall_log,
2525 SECCOMP_PARSE_LOG | SECCOMP_PARSE_PERMISSIVE |
2526 invert_flag |
2527 (c->syscall_log_allow_list ? SECCOMP_PARSE_ALLOW_LIST : 0),
2528 u->id,
2529 NULL, 0);
2530 if (r < 0)
2531 return r;
2532 }
2533
2534 joined = strv_join(l, " ");
2535 if (!joined)
2536 return -ENOMEM;
2537
2538 unit_write_settingf(u, flags, name, "SystemCallLog=%s%s", allow_list ? "" : "~", joined);
2539 }
2540
2541 return 1;
2542
cffaed83
YW
2543 } else if (streq(name, "SystemCallArchitectures")) {
2544 _cleanup_strv_free_ char **l = NULL;
2545
2546 r = sd_bus_message_read_strv(message, &l);
2547 if (r < 0)
2548 return r;
2549
2e59b241 2550 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
cffaed83
YW
2551 _cleanup_free_ char *joined = NULL;
2552
7b943bb7 2553 if (strv_isempty(l))
cffaed83 2554 c->syscall_archs = set_free(c->syscall_archs);
de010b0b 2555 else
cffaed83
YW
2556 STRV_FOREACH(s, l) {
2557 uint32_t a;
2558
2559 r = seccomp_arch_from_string(*s, &a);
2560 if (r < 0)
2561 return r;
2562
de7fef4b 2563 r = set_ensure_put(&c->syscall_archs, NULL, UINT32_TO_PTR(a + 1));
cffaed83
YW
2564 if (r < 0)
2565 return r;
2566 }
2567
cffaed83
YW
2568 joined = strv_join(l, " ");
2569 if (!joined)
2570 return -ENOMEM;
2571
2e59b241 2572 unit_write_settingf(u, flags, name, "%s=%s", name, joined);
cffaed83
YW
2573 }
2574
2575 return 1;
2576
cffaed83 2577 } else if (streq(name, "RestrictAddressFamilies")) {
3f856a28 2578 _cleanup_strv_free_ char **l = NULL;
4e6c50a5 2579 int allow_list;
cffaed83
YW
2580
2581 r = sd_bus_message_enter_container(message, 'r', "bas");
2582 if (r < 0)
2583 return r;
2584
6b000af4 2585 r = sd_bus_message_read(message, "b", &allow_list);
cffaed83
YW
2586 if (r < 0)
2587 return r;
2588
2589 r = sd_bus_message_read_strv(message, &l);
2590 if (r < 0)
2591 return r;
2592
2593 r = sd_bus_message_exit_container(message);
2594 if (r < 0)
2595 return r;
2596
2e59b241 2597 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
cffaed83
YW
2598 _cleanup_free_ char *joined = NULL;
2599
7b943bb7 2600 if (strv_isempty(l)) {
4e6c50a5 2601 c->address_families_allow_list = allow_list;
cffaed83 2602 c->address_families = set_free(c->address_families);
cffaed83 2603
4e6c50a5
YW
2604 unit_write_settingf(u, flags, name, "RestrictAddressFamilies=%s",
2605 allow_list ? "none" : "");
9ee896d5
YW
2606 return 1;
2607 }
cffaed83 2608
9ee896d5
YW
2609 if (!c->address_families) {
2610 c->address_families = set_new(NULL);
2611 if (!c->address_families)
2612 return log_oom();
cffaed83 2613
6b000af4 2614 c->address_families_allow_list = allow_list;
9ee896d5
YW
2615 }
2616
2617 STRV_FOREACH(s, l) {
2618 int af;
cffaed83 2619
9ee896d5 2620 af = af_from_name(*s);
acf4d158
YW
2621 if (af < 0)
2622 return af;
cffaed83 2623
6b000af4 2624 if (allow_list == c->address_families_allow_list) {
cffaed83
YW
2625 r = set_put(c->address_families, INT_TO_PTR(af));
2626 if (r < 0)
2627 return r;
9ee896d5 2628 } else
4e6c50a5 2629 set_remove(c->address_families, INT_TO_PTR(af));
cffaed83
YW
2630 }
2631
2632 joined = strv_join(l, " ");
2633 if (!joined)
2634 return -ENOMEM;
2635
6b000af4 2636 unit_write_settingf(u, flags, name, "RestrictAddressFamilies=%s%s", allow_list ? "" : "~", joined);
cffaed83
YW
2637 }
2638
2639 return 1;
7e2a3fcc 2640 }
cffaed83 2641#endif
b070c7c0 2642 if (STR_IN_SET(name, "CPUAffinity", "NUMAMask")) {
cffaed83 2643 const void *a;
bd0abfae 2644 size_t n;
b070c7c0 2645 bool affinity = streq(name, "CPUAffinity");
c367f996 2646 _cleanup_(cpu_set_reset) CPUSet set = {};
cffaed83
YW
2647
2648 r = sd_bus_message_read_array(message, 'y', &a, &n);
2649 if (r < 0)
2650 return r;
2651
c367f996
MS
2652 r = cpu_set_from_dbus(a, n, &set);
2653 if (r < 0)
2654 return r;
2655
2e59b241 2656 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
cffaed83 2657 if (n == 0) {
b070c7c0 2658 cpu_set_reset(affinity ? &c->cpu_set : &c->numa_policy.nodes);
2e59b241 2659 unit_write_settingf(u, flags, name, "%s=", name);
cffaed83
YW
2660 } else {
2661 _cleanup_free_ char *str = NULL;
cffaed83 2662
0985c7c4 2663 str = cpu_set_to_string(&set);
a832893f
ZJS
2664 if (!str)
2665 return -ENOMEM;
cffaed83 2666
0985c7c4
ZJS
2667 /* We forego any optimizations here, and always create the structure using
2668 * cpu_set_add_all(), because we don't want to care if the existing size we
2669 * got over dbus is appropriate. */
b070c7c0 2670 r = cpu_set_add_all(affinity ? &c->cpu_set : &c->numa_policy.nodes, &set);
0985c7c4
ZJS
2671 if (r < 0)
2672 return r;
501941aa 2673
2e59b241 2674 unit_write_settingf(u, flags, name, "%s=%s", name, str);
cffaed83
YW
2675 }
2676 }
2677
c7040b5d
LP
2678 return 1;
2679
e2b2fb7f
MS
2680 } else if (streq(name, "CPUAffinityFromNUMA")) {
2681 int q;
2682
2683 r = sd_bus_message_read_basic(message, 'b', &q);
2684 if (r < 0)
2685 return r;
2686
2687 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2688 c->cpu_affinity_from_numa = q;
2689 unit_write_settingf(u, flags, name, "%s=%s", "CPUAffinity", "numa");
2690 }
2691
2692 return 1;
2693
b070c7c0
MS
2694 } else if (streq(name, "NUMAPolicy")) {
2695 int32_t type;
2696
2697 r = sd_bus_message_read(message, "i", &type);
2698 if (r < 0)
2699 return r;
2700
2701 if (!mpol_is_valid(type))
2702 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid NUMAPolicy value: %i", type);
2703
2704 if (!UNIT_WRITE_FLAGS_NOOP(flags))
2705 c->numa_policy.type = type;
2706
2707 return 1;
e2b2fb7f 2708
c250bf67
YW
2709 } else if (streq(name, "Nice")) {
2710 int32_t q;
2711
2712 r = sd_bus_message_read(message, "i", &q);
2713 if (r < 0)
2714 return r;
2715
2716 if (!nice_is_valid(q))
2717 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid Nice value: %i", q);
2718
2719 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2720 c->nice = q;
2721 c->nice_set = true;
2722
2723 unit_write_settingf(u, flags, name, "Nice=%i", q);
2724 }
2725
2726 return 1;
2727
2728 } else if (streq(name, "CPUSchedulingPolicy")) {
2729 int32_t q;
2730
2731 r = sd_bus_message_read(message, "i", &q);
2732 if (r < 0)
2733 return r;
2734
2735 if (!sched_policy_is_valid(q))
2736 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid CPU scheduling policy: %i", q);
2737
2738 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2739 _cleanup_free_ char *s = NULL;
2740
2741 r = sched_policy_to_string_alloc(q, &s);
2742 if (r < 0)
2743 return r;
2744
2745 c->cpu_sched_policy = q;
2746 c->cpu_sched_priority = CLAMP(c->cpu_sched_priority, sched_get_priority_min(q), sched_get_priority_max(q));
2747 c->cpu_sched_set = true;
2748
2749 unit_write_settingf(u, flags, name, "CPUSchedulingPolicy=%s", s);
2750 }
2751
2752 return 1;
2753
2754 } else if (streq(name, "CPUSchedulingPriority")) {
2755 int32_t p, min, max;
2756
2757 r = sd_bus_message_read(message, "i", &p);
2758 if (r < 0)
2759 return r;
2760
2761 min = sched_get_priority_min(c->cpu_sched_policy);
2762 max = sched_get_priority_max(c->cpu_sched_policy);
2763 if (p < min || p > max)
2764 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid CPU scheduling priority: %i", p);
2765
2766 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2767 c->cpu_sched_priority = p;
2768 c->cpu_sched_set = true;
2769
2770 unit_write_settingf(u, flags, name, "CPUSchedulingPriority=%i", p);
2771 }
2772
2773 return 1;
2774
7f452159
LP
2775 } else if (streq(name, "IOSchedulingClass")) {
2776 int32_t q;
2777
2778 r = sd_bus_message_read(message, "i", &q);
2779 if (r < 0)
2780 return r;
2781
2782 if (!ioprio_class_is_valid(q))
2783 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid IO scheduling class: %i", q);
2784
2e59b241 2785 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
7f452159
LP
2786 _cleanup_free_ char *s = NULL;
2787
2788 r = ioprio_class_to_string_alloc(q, &s);
2789 if (r < 0)
2790 return r;
2791
ba7772fe 2792 c->ioprio = ioprio_normalize(ioprio_prio_value(q, ioprio_prio_data(c->ioprio)));
7f452159
LP
2793 c->ioprio_set = true;
2794
2e59b241 2795 unit_write_settingf(u, flags, name, "IOSchedulingClass=%s", s);
7f452159
LP
2796 }
2797
2798 return 1;
2799
2800 } else if (streq(name, "IOSchedulingPriority")) {
2801 int32_t p;
2802
2803 r = sd_bus_message_read(message, "i", &p);
2804 if (r < 0)
2805 return r;
2806
2807 if (!ioprio_priority_is_valid(p))
2808 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid IO scheduling priority: %i", p);
2809
2e59b241 2810 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
ba7772fe 2811 c->ioprio = ioprio_normalize(ioprio_prio_value(ioprio_prio_class(c->ioprio), p));
7f452159
LP
2812 c->ioprio_set = true;
2813
2e59b241 2814 unit_write_settingf(u, flags, name, "IOSchedulingPriority=%i", p);
7f452159
LP
2815 }
2816
2817 return 1;
2818
5e98086d
ZJS
2819 } else if (streq(name, "MountAPIVFS")) {
2820 bool b;
2821
2822 r = bus_set_transient_bool(u, name, &b, message, flags, error);
2823 if (r < 0)
2824 return r;
2825
2826 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2827 c->mount_apivfs = b;
2828 c->mount_apivfs_set = true;
2829 }
2830
2831 return 1;
2832
5f5d8eab
LP
2833 } else if (streq(name, "WorkingDirectory")) {
2834 const char *s;
2835 bool missing_ok;
2836
2837 r = sd_bus_message_read(message, "s", &s);
2838 if (r < 0)
2839 return r;
2840
2841 if (s[0] == '-') {
2842 missing_ok = true;
2843 s++;
2844 } else
2845 missing_ok = false;
2846
d6ff82d3 2847 if (!isempty(s) && !streq(s, "~") && !path_is_absolute(s))
1b09b81c 2848 return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "WorkingDirectory= expects an absolute path or '~'");
5f5d8eab 2849
2e59b241 2850 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
5f5d8eab
LP
2851 if (streq(s, "~")) {
2852 c->working_directory = mfree(c->working_directory);
2853 c->working_directory_home = true;
2854 } else {
d6ff82d3 2855 r = free_and_strdup(&c->working_directory, empty_to_null(s));
5f5d8eab
LP
2856 if (r < 0)
2857 return r;
2858
2859 c->working_directory_home = false;
2860 }
2861
2862 c->working_directory_missing_ok = missing_ok;
2e59b241 2863 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "WorkingDirectory=%s%s", missing_ok ? "-" : "", s);
5f5d8eab
LP
2864 }
2865
2866 return 1;
2867
52c239d7
LB
2868 } else if (STR_IN_SET(name,
2869 "StandardInputFileDescriptorName", "StandardOutputFileDescriptorName", "StandardErrorFileDescriptorName")) {
2870 const char *s;
2871
2872 r = sd_bus_message_read(message, "s", &s);
2873 if (r < 0)
2874 return r;
2875
d6ff82d3 2876 if (!isempty(s) && !fdname_is_valid(s))
1b09b81c 2877 return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid file descriptor name");
52c239d7 2878
2e59b241 2879 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
5073ff6b 2880
52c239d7 2881 if (streq(name, "StandardInputFileDescriptorName")) {
d6ff82d3 2882 r = free_and_strdup(c->stdio_fdname + STDIN_FILENO, empty_to_null(s));
52c239d7
LB
2883 if (r < 0)
2884 return r;
5073ff6b 2885
0664775c 2886 c->std_input = EXEC_INPUT_NAMED_FD;
2e59b241 2887 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardInput=fd:%s", exec_context_fdname(c, STDIN_FILENO));
5073ff6b 2888
52c239d7 2889 } else if (streq(name, "StandardOutputFileDescriptorName")) {
d6ff82d3 2890 r = free_and_strdup(c->stdio_fdname + STDOUT_FILENO, empty_to_null(s));
52c239d7
LB
2891 if (r < 0)
2892 return r;
5073ff6b 2893
52c239d7 2894 c->std_output = EXEC_OUTPUT_NAMED_FD;
2e59b241 2895 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardOutput=fd:%s", exec_context_fdname(c, STDOUT_FILENO));
0664775c
LP
2896
2897 } else {
2898 assert(streq(name, "StandardErrorFileDescriptorName"));
5073ff6b 2899
d6ff82d3 2900 r = free_and_strdup(&c->stdio_fdname[STDERR_FILENO], empty_to_null(s));
52c239d7
LB
2901 if (r < 0)
2902 return r;
5073ff6b 2903
52c239d7 2904 c->std_error = EXEC_OUTPUT_NAMED_FD;
2e59b241 2905 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardError=fd:%s", exec_context_fdname(c, STDERR_FILENO));
52c239d7
LB
2906 }
2907 }
2908
2909 return 1;
2910
566b7d23
ZD
2911 } else if (STR_IN_SET(name,
2912 "StandardInputFile",
8d7dab1f
LW
2913 "StandardOutputFile", "StandardOutputFileToAppend", "StandardOutputFileToTruncate",
2914 "StandardErrorFile", "StandardErrorFileToAppend", "StandardErrorFileToTruncate")) {
2038c3f5
LP
2915 const char *s;
2916
2917 r = sd_bus_message_read(message, "s", &s);
2918 if (r < 0)
2919 return r;
2920
d6ff82d3
YW
2921 if (!isempty(s)) {
2922 if (!path_is_absolute(s))
2923 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path %s is not absolute", s);
2924 if (!path_is_normalized(s))
2925 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path %s is not normalized", s);
2926 }
2038c3f5 2927
2e59b241 2928 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2038c3f5
LP
2929
2930 if (streq(name, "StandardInputFile")) {
d6ff82d3 2931 r = free_and_strdup(&c->stdio_file[STDIN_FILENO], empty_to_null(s));
52c239d7
LB
2932 if (r < 0)
2933 return r;
2038c3f5
LP
2934
2935 c->std_input = EXEC_INPUT_FILE;
2e59b241 2936 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardInput=file:%s", s);
2038c3f5 2937
8d7dab1f 2938 } else if (STR_IN_SET(name, "StandardOutputFile", "StandardOutputFileToAppend", "StandardOutputFileToTruncate")) {
d6ff82d3 2939 r = free_and_strdup(&c->stdio_file[STDOUT_FILENO], empty_to_null(s));
2038c3f5
LP
2940 if (r < 0)
2941 return r;
2942
566b7d23
ZD
2943 if (streq(name, "StandardOutputFile")) {
2944 c->std_output = EXEC_OUTPUT_FILE;
2945 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardOutput=file:%s", s);
8d7dab1f 2946 } else if (streq(name, "StandardOutputFileToAppend")) {
566b7d23
ZD
2947 c->std_output = EXEC_OUTPUT_FILE_APPEND;
2948 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardOutput=append:%s", s);
8d7dab1f
LW
2949 } else {
2950 assert(streq(name, "StandardOutputFileToTruncate"));
2951 c->std_output = EXEC_OUTPUT_FILE_TRUNCATE;
2952 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardOutput=truncate:%s", s);
566b7d23 2953 }
2038c3f5 2954 } else {
8d7dab1f 2955 assert(STR_IN_SET(name, "StandardErrorFile", "StandardErrorFileToAppend", "StandardErrorFileToTruncate"));
2038c3f5 2956
d6ff82d3 2957 r = free_and_strdup(&c->stdio_file[STDERR_FILENO], empty_to_null(s));
2038c3f5
LP
2958 if (r < 0)
2959 return r;
2960
566b7d23
ZD
2961 if (streq(name, "StandardErrorFile")) {
2962 c->std_error = EXEC_OUTPUT_FILE;
1704fba9 2963 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardError=file:%s", s);
8d7dab1f 2964 } else if (streq(name, "StandardErrorFileToAppend")) {
dbe6c4b6 2965 c->std_error = EXEC_OUTPUT_FILE_APPEND;
1704fba9 2966 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardError=append:%s", s);
8d7dab1f
LW
2967 } else {
2968 assert(streq(name, "StandardErrorFileToTruncate"));
2969 c->std_error = EXEC_OUTPUT_FILE_TRUNCATE;
2970 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardError=truncate:%s", s);
566b7d23 2971 }
2038c3f5
LP
2972 }
2973 }
2974
2975 return 1;
2976
08f3be7a
LP
2977 } else if (streq(name, "StandardInputData")) {
2978 const void *p;
2979 size_t sz;
2980
2981 r = sd_bus_message_read_array(message, 'y', &p, &sz);
2982 if (r < 0)
2983 return r;
2984
2e59b241 2985 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
08f3be7a
LP
2986 _cleanup_free_ char *encoded = NULL;
2987
2988 if (sz == 0) {
2989 c->stdin_data = mfree(c->stdin_data);
2990 c->stdin_data_size = 0;
2991
2e59b241 2992 unit_write_settingf(u, flags, name, "StandardInputData=");
08f3be7a
LP
2993 } else {
2994 void *q;
2995 ssize_t n;
2996
2997 if (c->stdin_data_size + sz < c->stdin_data_size || /* check for overflow */
2998 c->stdin_data_size + sz > EXEC_STDIN_DATA_MAX)
2999 return -E2BIG;
3000
3001 n = base64mem(p, sz, &encoded);
3002 if (n < 0)
3003 return (int) n;
3004
3005 q = realloc(c->stdin_data, c->stdin_data_size + sz);
3006 if (!q)
3007 return -ENOMEM;
3008
3009 memcpy((uint8_t*) q + c->stdin_data_size, p, sz);
3010
3011 c->stdin_data = q;
3012 c->stdin_data_size += sz;
3013
2e59b241 3014 unit_write_settingf(u, flags, name, "StandardInputData=%s", encoded);
52c239d7
LB
3015 }
3016 }
3017
3018 return 1;
3019
c7040b5d
LP
3020 } else if (streq(name, "Environment")) {
3021
6171b822 3022 _cleanup_strv_free_ char **l = NULL;
c7040b5d
LP
3023
3024 r = sd_bus_message_read_strv(message, &l);
3025 if (r < 0)
3026 return r;
3027
6171b822 3028 if (!strv_env_is_valid(l))
1b09b81c 3029 return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid environment block.");
1c68232e 3030
2e59b241 3031 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
7b943bb7 3032 if (strv_isempty(l)) {
e9876fc9 3033 c->environment = strv_free(c->environment);
2e59b241 3034 unit_write_setting(u, flags, name, "Environment=");
e9876fc9 3035 } else {
f900f582
ZJS
3036 _cleanup_free_ char *joined = NULL;
3037 char **e;
3038
2e59b241
LP
3039 joined = unit_concat_strv(l, UNIT_ESCAPE_SPECIFIERS|UNIT_ESCAPE_C);
3040 if (!joined)
3041 return -ENOMEM;
3042
4ab3d29f 3043 e = strv_env_merge(c->environment, l);
e9876fc9
EV
3044 if (!e)
3045 return -ENOMEM;
c7040b5d 3046
130d3d22 3047 strv_free_and_replace(c->environment, e);
2e59b241 3048 unit_write_settingf(u, flags, name, "Environment=%s", joined);
e9876fc9 3049 }
c7040b5d
LP
3050 }
3051
d584f638
LP
3052 return 1;
3053
00819cc1
LP
3054 } else if (streq(name, "UnsetEnvironment")) {
3055
6171b822 3056 _cleanup_strv_free_ char **l = NULL;
00819cc1
LP
3057
3058 r = sd_bus_message_read_strv(message, &l);
3059 if (r < 0)
3060 return r;
3061
6171b822 3062 if (!strv_env_name_or_assignment_is_valid(l))
1b09b81c 3063 return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid UnsetEnvironment= list.");
00819cc1 3064
2e59b241 3065 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
7b943bb7 3066 if (strv_isempty(l)) {
00819cc1 3067 c->unset_environment = strv_free(c->unset_environment);
2e59b241 3068 unit_write_setting(u, flags, name, "UnsetEnvironment=");
00819cc1
LP
3069 } else {
3070 _cleanup_free_ char *joined = NULL;
3071 char **e;
3072
2e59b241
LP
3073 joined = unit_concat_strv(l, UNIT_ESCAPE_SPECIFIERS|UNIT_ESCAPE_C);
3074 if (!joined)
3075 return -ENOMEM;
3076
4ab3d29f 3077 e = strv_env_merge(c->unset_environment, l);
00819cc1
LP
3078 if (!e)
3079 return -ENOMEM;
3080
130d3d22 3081 strv_free_and_replace(c->unset_environment, e);
2e59b241 3082 unit_write_settingf(u, flags, name, "UnsetEnvironment=%s", joined);
00819cc1
LP
3083 }
3084 }
3085
3086 return 1;
3087
6b862936
EV
3088 } else if (streq(name, "OOMScoreAdjust")) {
3089 int oa;
3090
3091 r = sd_bus_message_read(message, "i", &oa);
3092 if (r < 0)
3093 return r;
3094
3095 if (!oom_score_adjust_is_valid(oa))
1b09b81c 3096 return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "OOM score adjust value out of range");
6b862936 3097
2e59b241 3098 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
6b862936
EV
3099 c->oom_score_adjust = oa;
3100 c->oom_score_adjust_set = true;
2e59b241 3101 unit_write_settingf(u, flags, name, "OOMScoreAdjust=%i", oa);
6b862936
EV
3102 }
3103
3104 return 1;
3105
ad21e542
ZJS
3106 } else if (streq(name, "CoredumpFilter")) {
3107 uint64_t f;
3108
3109 r = sd_bus_message_read(message, "t", &f);
3110 if (r < 0)
3111 return r;
3112
3113 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
3114 c->coredump_filter = f;
3115 c->coredump_filter_set = true;
3116 unit_write_settingf(u, flags, name, "CoredumpFilter=0x%"PRIx64, f);
3117 }
3118
3119 return 1;
3120
ceb728cf
NC
3121 } else if (streq(name, "EnvironmentFiles")) {
3122
3123 _cleanup_free_ char *joined = NULL;
3124 _cleanup_fclose_ FILE *f = NULL;
9b531f04 3125 _cleanup_strv_free_ char **l = NULL;
ceb728cf 3126 size_t size = 0;
ceb728cf
NC
3127
3128 r = sd_bus_message_enter_container(message, 'a', "(sb)");
3129 if (r < 0)
3130 return r;
3131
2fe21124 3132 f = open_memstream_unlocked(&joined, &size);
ceb728cf
NC
3133 if (!f)
3134 return -ENOMEM;
3135
2e59b241
LP
3136 fputs("EnvironmentFile=\n", f);
3137
3138 STRV_FOREACH(i, c->environment_files) {
3139 _cleanup_free_ char *q = NULL;
3140
3141 q = specifier_escape(*i);
3142 if (!q)
3143 return -ENOMEM;
3144
3145 fprintf(f, "EnvironmentFile=%s\n", q);
3146 }
ceb728cf
NC
3147
3148 while ((r = sd_bus_message_enter_container(message, 'r', "sb")) > 0) {
3149 const char *path;
3150 int b;
3151
ceb728cf
NC
3152 r = sd_bus_message_read(message, "sb", &path, &b);
3153 if (r < 0)
3154 return r;
3155
3156 r = sd_bus_message_exit_container(message);
3157 if (r < 0)
3158 return r;
3159
d2d6c096
LP
3160 if (!path_is_absolute(path))
3161 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path %s is not absolute.", path);
ceb728cf 3162
2e59b241 3163 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
6abdec98 3164 _cleanup_free_ char *q = NULL, *buf = NULL;
ceb728cf 3165
605405c6 3166 buf = strjoin(b ? "-" : "", path);
2229f656 3167 if (!buf)
ceb728cf
NC
3168 return -ENOMEM;
3169
2e59b241 3170 q = specifier_escape(buf);
6abdec98 3171 if (!q)
2e59b241 3172 return -ENOMEM;
2e59b241
LP
3173
3174 fprintf(f, "EnvironmentFile=%s\n", q);
ceb728cf 3175
6abdec98 3176 r = strv_consume(&l, TAKE_PTR(buf));
ceb728cf
NC
3177 if (r < 0)
3178 return r;
3179 }
3180 }
3181 if (r < 0)
3182 return r;
3183
b0830e21
LP
3184 r = sd_bus_message_exit_container(message);
3185 if (r < 0)
3186 return r;
3187
2229f656
LP
3188 r = fflush_and_check(f);
3189 if (r < 0)
3190 return r;
ceb728cf 3191
2e59b241 3192 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2229f656
LP
3193 if (strv_isempty(l)) {
3194 c->environment_files = strv_free(c->environment_files);
2e59b241 3195 unit_write_setting(u, flags, name, "EnvironmentFile=");
2229f656
LP
3196 } else {
3197 r = strv_extend_strv(&c->environment_files, l, true);
3198 if (r < 0)
3199 return r;
3200
2e59b241 3201 unit_write_setting(u, flags, name, joined);
2229f656
LP
3202 }
3203 }
ceb728cf 3204
ceb728cf
NC
3205 return 1;
3206
b4c14404
FB
3207 } else if (streq(name, "PassEnvironment")) {
3208
6171b822 3209 _cleanup_strv_free_ char **l = NULL;
b4c14404
FB
3210
3211 r = sd_bus_message_read_strv(message, &l);
3212 if (r < 0)
3213 return r;
3214
6171b822 3215 if (!strv_env_name_is_valid(l))
1b09b81c 3216 return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid PassEnvironment= block.");
b4c14404 3217
2e59b241 3218 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
b4c14404
FB
3219 if (strv_isempty(l)) {
3220 c->pass_environment = strv_free(c->pass_environment);
2e59b241 3221 unit_write_setting(u, flags, name, "PassEnvironment=");
b4c14404
FB
3222 } else {
3223 _cleanup_free_ char *joined = NULL;
3224
9d4f242a
YW
3225 r = strv_extend_strv(&c->pass_environment, l, true);
3226 if (r < 0)
3227 return r;
3228
41de9cc2 3229 /* We write just the new settings out to file, with unresolved specifiers. */
2e59b241 3230 joined = unit_concat_strv(l, UNIT_ESCAPE_SPECIFIERS);
b4c14404
FB
3231 if (!joined)
3232 return -ENOMEM;
3233
2e59b241 3234 unit_write_settingf(u, flags, name, "PassEnvironment=%s", joined);
b4c14404
FB
3235 }
3236 }
3237
3238 return 1;
3239
2a624c36 3240 } else if (STR_IN_SET(name, "ReadWriteDirectories", "ReadOnlyDirectories", "InaccessibleDirectories",
a07b9926
LB
3241 "ReadWritePaths", "ReadOnlyPaths", "InaccessiblePaths", "ExecPaths", "NoExecPaths",
3242 "ExtensionDirectories")) {
08596068
EV
3243 _cleanup_strv_free_ char **l = NULL;
3244 char ***dirs;
08596068
EV
3245
3246 r = sd_bus_message_read_strv(message, &l);
3247 if (r < 0)
3248 return r;
3249
3250 STRV_FOREACH(p, l) {
e7bcff4e 3251 char *i = *p;
20b7a007
LP
3252 size_t offset;
3253
20b7a007
LP
3254 offset = i[0] == '-';
3255 offset += i[offset] == '+';
3256 if (!path_is_absolute(i + offset))
08596068 3257 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid %s", name);
e7bcff4e 3258
4ff361cc 3259 path_simplify(i + offset);
08596068
EV
3260 }
3261
2e59b241 3262 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
c4b41707
AP
3263 if (STR_IN_SET(name, "ReadWriteDirectories", "ReadWritePaths"))
3264 dirs = &c->read_write_paths;
3265 else if (STR_IN_SET(name, "ReadOnlyDirectories", "ReadOnlyPaths"))
3266 dirs = &c->read_only_paths;
ddc155b2
TM
3267 else if (streq(name, "ExecPaths"))
3268 dirs = &c->exec_paths;
3269 else if (streq(name, "NoExecPaths"))
3270 dirs = &c->no_exec_paths;
a07b9926
LB
3271 else if (streq(name, "ExtensionDirectories"))
3272 dirs = &c->extension_directories;
c4b41707
AP
3273 else /* "InaccessiblePaths" */
3274 dirs = &c->inaccessible_paths;
08596068 3275
7b943bb7 3276 if (strv_isempty(l)) {
08596068 3277 *dirs = strv_free(*dirs);
2e59b241 3278 unit_write_settingf(u, flags, name, "%s=", name);
08596068 3279 } else {
2e59b241 3280 _cleanup_free_ char *joined = NULL;
08596068 3281
2e59b241 3282 joined = unit_concat_strv(l, UNIT_ESCAPE_SPECIFIERS);
08596068
EV
3283 if (!joined)
3284 return -ENOMEM;
3285
2e59b241
LP
3286 r = strv_extend_strv(dirs, l, true);
3287 if (r < 0)
3288 return -ENOMEM;
08596068 3289
2e59b241
LP
3290 unit_write_settingf(u, flags, name, "%s=%s", name, joined);
3291 }
08596068
EV
3292 }
3293
3294 return 1;
3295
8c35c10d 3296 } else if (streq(name, "ExecSearchPath")) {
3297 _cleanup_strv_free_ char **l = NULL;
8c35c10d 3298
3299 r = sd_bus_message_read_strv(message, &l);
3300 if (r < 0)
3301 return r;
3302
de010b0b 3303 STRV_FOREACH(p, l)
8c35c10d 3304 if (!path_is_absolute(*p) || !path_is_normalized(*p) || strchr(*p, ':'))
3305 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid %s", name);
de010b0b 3306
8c35c10d 3307 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
3308 if (strv_isempty(l)) {
3309 c->exec_search_path = strv_free(c->exec_search_path);
3310 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "ExecSearchPath=");
3311 } else {
3312 _cleanup_free_ char *joined = NULL;
3313 r = strv_extend_strv(&c->exec_search_path, l, true);
3314 if (r < 0)
3315 return -ENOMEM;
3316 joined = strv_join(c->exec_search_path, ":");
3317 if (!joined)
3318 return log_oom();
3319 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "ExecSearchPath=%s", joined);
3320 }
3321 }
3322
3323 return 1;
3324
3536f49e 3325 } else if (STR_IN_SET(name, "RuntimeDirectory", "StateDirectory", "CacheDirectory", "LogsDirectory", "ConfigurationDirectory")) {
fa21b5e3 3326 _cleanup_strv_free_ char **l = NULL;
fa21b5e3
EV
3327
3328 r = sd_bus_message_read_strv(message, &l);
3329 if (r < 0)
3330 return r;
3331
3332 STRV_FOREACH(p, l) {
8994a117
YW
3333 if (!path_is_normalized(*p))
3334 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "%s= path is not normalized: %s", name, *p);
3335
3336 if (path_is_absolute(*p))
3337 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "%s= path is absolute: %s", name, *p);
3338
3339 if (path_startswith(*p, "private"))
3340 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "%s= path can't be 'private': %s", name, *p);
fa21b5e3
EV
3341 }
3342
2e59b241 3343 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
3536f49e 3344 ExecDirectoryType i;
b1ea85dc 3345 ExecDirectory *d;
3536f49e 3346
b1ea85dc
LP
3347 assert_se((i = exec_directory_type_from_string(name)) >= 0);
3348 d = c->directories + i;
fa21b5e3
EV
3349
3350 if (strv_isempty(l)) {
211a3d87 3351 exec_directory_done(d);
2e59b241 3352 unit_write_settingf(u, flags, name, "%s=", name);
fa21b5e3 3353 } else {
2e59b241
LP
3354 _cleanup_free_ char *joined = NULL;
3355
211a3d87
LB
3356 STRV_FOREACH(source, l) {
3357 r = exec_directory_add(&d->items, &d->n_items, *source, NULL);
3358 if (r < 0)
3359 return log_oom();
3360 }
fa21b5e3 3361
2e59b241 3362 joined = unit_concat_strv(l, UNIT_ESCAPE_SPECIFIERS);
fa21b5e3
EV
3363 if (!joined)
3364 return -ENOMEM;
3365
2e59b241 3366 unit_write_settingf(u, flags, name, "%s=%s", name, joined);
fa21b5e3
EV
3367 }
3368 }
3369
3370 return 1;
3371
cffaed83
YW
3372 } else if (STR_IN_SET(name, "AppArmorProfile", "SmackProcessLabel")) {
3373 int ignore;
3374 const char *s;
3375
280921f2 3376 r = sd_bus_message_read(message, "(bs)", &ignore, &s);
cffaed83
YW
3377 if (r < 0)
3378 return r;
3379
2e59b241 3380 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
cffaed83
YW
3381 char **p;
3382 bool *b;
3383
3384 if (streq(name, "AppArmorProfile")) {
3385 p = &c->apparmor_profile;
3386 b = &c->apparmor_profile_ignore;
3387 } else { /* "SmackProcessLabel" */
3388 p = &c->smack_process_label;
3389 b = &c->smack_process_label_ignore;
3390 }
3391
3392 if (isempty(s)) {
3393 *p = mfree(*p);
3394 *b = false;
3395 } else {
3396 if (free_and_strdup(p, s) < 0)
3397 return -ENOMEM;
3398 *b = ignore;
3399 }
3400
2e59b241 3401 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "%s=%s%s", name, ignore ? "-" : "", strempty(s));
cffaed83
YW
3402 }
3403
3404 return 1;
3405
d2d6c096 3406 } else if (STR_IN_SET(name, "BindPaths", "BindReadOnlyPaths")) {
ec04aef4 3407 char *source, *destination;
4ff4c98a
YW
3408 int ignore_enoent;
3409 uint64_t mount_flags;
3410 bool empty = true;
d2d6c096
LP
3411
3412 r = sd_bus_message_enter_container(message, 'a', "(ssbt)");
3413 if (r < 0)
3414 return r;
3415
4ff4c98a 3416 while ((r = sd_bus_message_read(message, "(ssbt)", &source, &destination, &ignore_enoent, &mount_flags)) > 0) {
d2d6c096
LP
3417
3418 if (!path_is_absolute(source))
3419 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Source path %s is not absolute.", source);
3420 if (!path_is_absolute(destination))
91d910e3 3421 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Destination path %s is not absolute.", destination);
d2d6c096 3422 if (!IN_SET(mount_flags, 0, MS_REC))
1b09b81c 3423 return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Unknown mount flags.");
d2d6c096 3424
2e59b241 3425 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
d2d6c096
LP
3426 r = bind_mount_add(&c->bind_mounts, &c->n_bind_mounts,
3427 &(BindMount) {
ec04aef4
TM
3428 .source = source,
3429 .destination = destination,
d2d6c096
LP
3430 .read_only = !!strstr(name, "ReadOnly"),
3431 .recursive = !!(mount_flags & MS_REC),
3432 .ignore_enoent = ignore_enoent,
3433 });
3434 if (r < 0)
3435 return r;
3436
2e59b241
LP
3437 unit_write_settingf(
3438 u, flags|UNIT_ESCAPE_SPECIFIERS, name,
d2d6c096
LP
3439 "%s=%s%s:%s:%s",
3440 name,
3441 ignore_enoent ? "-" : "",
3442 source,
3443 destination,
3444 (mount_flags & MS_REC) ? "rbind" : "norbind");
3445 }
3446
3447 empty = false;
3448 }
3449 if (r < 0)
3450 return r;
3451
3452 r = sd_bus_message_exit_container(message);
3453 if (r < 0)
3454 return r;
3455
3456 if (empty) {
3457 bind_mount_free_many(c->bind_mounts, c->n_bind_mounts);
3458 c->bind_mounts = NULL;
3459 c->n_bind_mounts = 0;
2e59b241
LP
3460
3461 unit_write_settingf(u, flags, name, "%s=", name);
d2d6c096
LP
3462 }
3463
784ad252
YW
3464 return 1;
3465
3466 } else if (streq(name, "TemporaryFileSystem")) {
3467 const char *path, *options;
3468 bool empty = true;
3469
3470 r = sd_bus_message_enter_container(message, 'a', "(ss)");
3471 if (r < 0)
3472 return r;
3473
3474 while ((r = sd_bus_message_read(message, "(ss)", &path, &options)) > 0) {
3475
3476 if (!path_is_absolute(path))
3477 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Mount point %s is not absolute.", path);
3478
3479 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
3480 r = temporary_filesystem_add(&c->temporary_filesystems, &c->n_temporary_filesystems, path, options);
3481 if (r < 0)
3482 return r;
3483
3484 unit_write_settingf(
3485 u, flags|UNIT_ESCAPE_SPECIFIERS, name,
3486 "%s=%s:%s",
3487 name,
3488 path,
3489 options);
3490 }
3491
3492 empty = false;
3493 }
3494 if (r < 0)
3495 return r;
3496
3497 r = sd_bus_message_exit_container(message);
3498 if (r < 0)
3499 return r;
3500
3501 if (empty) {
3502 temporary_filesystem_free_many(c->temporary_filesystems, c->n_temporary_filesystems);
3503 c->temporary_filesystems = NULL;
3504 c->n_temporary_filesystems = 0;
3505
3506 unit_write_settingf(u, flags, name, "%s=", name);
3507 }
3508
83555251 3509 return 1;
d2d6c096 3510
6550c24c
LP
3511 } else if ((suffix = startswith(name, "Limit"))) {
3512 const char *soft = NULL;
3513 int ri;
cab2aca3 3514
6550c24c
LP
3515 ri = rlimit_from_string(suffix);
3516 if (ri < 0) {
3517 soft = endswith(suffix, "Soft");
3518 if (soft) {
3519 const char *n;
cab2aca3 3520
2f82562b 3521 n = strndupa_safe(suffix, soft - suffix);
6550c24c
LP
3522 ri = rlimit_from_string(n);
3523 if (ri >= 0)
3524 name = strjoina("Limit", n);
3525 }
cab2aca3 3526 }
d584f638 3527
6550c24c
LP
3528 if (ri >= 0) {
3529 uint64_t rl;
3530 rlim_t x;
d584f638 3531
6550c24c 3532 r = sd_bus_message_read(message, "t", &rl);
cab2aca3
LP
3533 if (r < 0)
3534 return r;
d584f638 3535
f5fbe71d 3536 if (rl == UINT64_MAX)
6550c24c 3537 x = RLIM_INFINITY;
cab2aca3 3538 else {
6550c24c
LP
3539 x = (rlim_t) rl;
3540
3541 if ((uint64_t) x != rl)
3542 return -ERANGE;
d584f638
LP
3543 }
3544
6550c24c
LP
3545 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
3546 _cleanup_free_ char *f = NULL;
3547 struct rlimit nl;
3548
3549 if (c->rlimit[ri]) {
3550 nl = *c->rlimit[ri];
3551
3552 if (soft)
3553 nl.rlim_cur = x;
3554 else
3555 nl.rlim_max = x;
3556 } else
3557 /* When the resource limit is not initialized yet, then assign the value to both fields */
3558 nl = (struct rlimit) {
3559 .rlim_cur = x,
3560 .rlim_max = x,
3561 };
3562
3563 r = rlimit_format(&nl, &f);
3564 if (r < 0)
3565 return r;
3566
3567 if (c->rlimit[ri])
3568 *c->rlimit[ri] = nl;
3569 else {
3570 c->rlimit[ri] = newdup(struct rlimit, &nl, 1);
3571 if (!c->rlimit[ri])
3572 return -ENOMEM;
3573 }
3574
3575 unit_write_settingf(u, flags, name, "%s=%s", name, f);
3576 }
3577
3578 return 1;
d584f638
LP
3579 }
3580
b3d13314
LB
3581 } else if (streq(name, "MountImages")) {
3582 _cleanup_free_ char *format_str = NULL;
3583 MountImage *mount_images = NULL;
3584 size_t n_mount_images = 0;
3585 char *source, *destination;
3586 int permissive;
3587
427353f6 3588 r = sd_bus_message_enter_container(message, 'a', "(ssba(ss))");
b3d13314
LB
3589 if (r < 0)
3590 return r;
3591
427353f6
LB
3592 for (;;) {
3593 _cleanup_(mount_options_free_allp) MountOptions *options = NULL;
3594 _cleanup_free_ char *source_escaped = NULL, *destination_escaped = NULL;
b3d13314
LB
3595 char *tuple;
3596
427353f6
LB
3597 r = sd_bus_message_enter_container(message, 'r', "ssba(ss)");
3598 if (r < 0)
3599 return r;
3600
3601 r = sd_bus_message_read(message, "ssb", &source, &destination, &permissive);
3602 if (r <= 0)
3603 break;
3604
b3d13314
LB
3605 if (!path_is_absolute(source))
3606 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Source path %s is not absolute.", source);
3607 if (!path_is_normalized(source))
3608 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Source path %s is not normalized.", source);
3609 if (!path_is_absolute(destination))
3610 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Destination path %s is not absolute.", destination);
3611 if (!path_is_normalized(destination))
3612 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Destination path %s is not normalized.", destination);
3613
427353f6
LB
3614 /* Need to store them in the unit with the escapes, so that they can be parsed again */
3615 source_escaped = shell_escape(source, ":");
3616 if (!source_escaped)
3617 return -ENOMEM;
3618 destination_escaped = shell_escape(destination, ":");
3619 if (!destination_escaped)
3620 return -ENOMEM;
3621
3622 tuple = strjoin(format_str,
3623 format_str ? " " : "",
3624 permissive ? "-" : "",
3625 source_escaped,
3626 ":",
3627 destination_escaped);
b3d13314
LB
3628 if (!tuple)
3629 return -ENOMEM;
3630 free_and_replace(format_str, tuple);
3631
988172ce 3632 r = bus_read_mount_options(message, error, &options, &format_str, ":");
427353f6
LB
3633 if (r < 0)
3634 return r;
3635
3636 r = sd_bus_message_exit_container(message);
3637 if (r < 0)
3638 return r;
3639
b3d13314
LB
3640 r = mount_image_add(&mount_images, &n_mount_images,
3641 &(MountImage) {
3642 .source = source,
3643 .destination = destination,
427353f6 3644 .mount_options = options,
b3d13314 3645 .ignore_enoent = permissive,
93f59701 3646 .type = MOUNT_IMAGE_DISCRETE,
b3d13314
LB
3647 });
3648 if (r < 0)
3649 return r;
3650 }
3651 if (r < 0)
3652 return r;
3653
3654 r = sd_bus_message_exit_container(message);
3655 if (r < 0)
3656 return r;
3657
3658 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
3659 if (n_mount_images == 0) {
3660 c->mount_images = mount_image_free_many(c->mount_images, &c->n_mount_images);
3661
3662 unit_write_settingf(u, flags, name, "%s=", name);
3663 } else {
3664 for (size_t i = 0; i < n_mount_images; ++i) {
3665 r = mount_image_add(&c->mount_images, &c->n_mount_images, &mount_images[i]);
3666 if (r < 0)
3667 return r;
3668 }
3669
3670 unit_write_settingf(u, flags|UNIT_ESCAPE_C|UNIT_ESCAPE_SPECIFIERS,
3671 name,
3672 "%s=%s",
3673 name,
3674 format_str);
3675 }
3676 }
3677
3678 mount_images = mount_image_free_many(mount_images, &n_mount_images);
3679
93f59701
LB
3680 return 1;
3681 } else if (streq(name, "ExtensionImages")) {
3682 _cleanup_free_ char *format_str = NULL;
3683 MountImage *extension_images = NULL;
3684 size_t n_extension_images = 0;
3685
3686 r = sd_bus_message_enter_container(message, 'a', "(sba(ss))");
3687 if (r < 0)
3688 return r;
3689
3690 for (;;) {
3691 _cleanup_(mount_options_free_allp) MountOptions *options = NULL;
3692 _cleanup_free_ char *source_escaped = NULL;
3693 char *source, *tuple;
3694 int permissive;
3695
3696 r = sd_bus_message_enter_container(message, 'r', "sba(ss)");
3697 if (r < 0)
3698 return r;
3699
3700 r = sd_bus_message_read(message, "sb", &source, &permissive);
3701 if (r <= 0)
3702 break;
3703
3704 if (!path_is_absolute(source))
3705 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Source path %s is not absolute.", source);
3706 if (!path_is_normalized(source))
3707 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Source path %s is not normalized.", source);
3708
3709 /* Need to store them in the unit with the escapes, so that they can be parsed again */
3710 source_escaped = shell_escape(source, ":");
3711 if (!source_escaped)
3712 return -ENOMEM;
3713
3714 tuple = strjoin(format_str,
3715 format_str ? " " : "",
3716 permissive ? "-" : "",
3717 source_escaped);
3718 if (!tuple)
3719 return -ENOMEM;
3720 free_and_replace(format_str, tuple);
3721
3722 r = bus_read_mount_options(message, error, &options, &format_str, ":");
3723 if (r < 0)
3724 return r;
3725
3726 r = sd_bus_message_exit_container(message);
3727 if (r < 0)
3728 return r;
3729
3730 r = mount_image_add(&extension_images, &n_extension_images,
3731 &(MountImage) {
3732 .source = source,
3733 .mount_options = options,
3734 .ignore_enoent = permissive,
3735 .type = MOUNT_IMAGE_EXTENSION,
3736 });
3737 if (r < 0)
3738 return r;
3739 }
3740 if (r < 0)
3741 return r;
3742
3743 r = sd_bus_message_exit_container(message);
3744 if (r < 0)
3745 return r;
3746
3747 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
3748 if (n_extension_images == 0) {
3749 c->extension_images = mount_image_free_many(c->extension_images, &c->n_extension_images);
3750
3751 unit_write_settingf(u, flags, name, "%s=", name);
3752 } else {
3753 for (size_t i = 0; i < n_extension_images; ++i) {
3754 r = mount_image_add(&c->extension_images, &c->n_extension_images, &extension_images[i]);
3755 if (r < 0)
3756 return r;
3757 }
3758
3759 unit_write_settingf(u, flags|UNIT_ESCAPE_C|UNIT_ESCAPE_SPECIFIERS,
3760 name,
3761 "%s=%s",
3762 name,
3763 format_str);
3764 }
3765 }
3766
3767 extension_images = mount_image_free_many(extension_images, &n_extension_images);
3768
b3d13314 3769 return 1;
211a3d87
LB
3770
3771 } else if (STR_IN_SET(name, "StateDirectorySymlink", "RuntimeDirectorySymlink", "CacheDirectorySymlink", "LogsDirectorySymlink")) {
3772 char *source, *destination;
3773 ExecDirectory *directory;
3774 uint64_t symlink_flags; /* No flags for now, reserved for future uses. */
3775 ExecDirectoryType i;
3776
3777 assert_se((i = exec_directory_type_symlink_from_string(name)) >= 0);
3778 directory = c->directories + i;
3779
3780 r = sd_bus_message_enter_container(message, 'a', "(sst)");
3781 if (r < 0)
3782 return r;
3783
3784 while ((r = sd_bus_message_read(message, "(sst)", &source, &destination, &symlink_flags)) > 0) {
3785 if (!path_is_valid(source))
3786 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Source path %s is not valid.", source);
3787 if (path_is_absolute(source))
3788 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Source path %s is absolute.", source);
3789 if (!path_is_normalized(source))
3790 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Source path %s is not normalized.", source);
3791 if (!path_is_valid(destination))
3792 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Destination path %s is not valid.", destination);
3793 if (path_is_absolute(destination))
3794 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Destination path %s is absolute.", destination);
3795 if (!path_is_normalized(destination))
3796 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Destination path %s is not normalized.", destination);
3797 if (symlink_flags != 0)
3798 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Flags must be zero.");
3799
3800 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
3801 _cleanup_free_ char *destination_escaped = NULL, *source_escaped = NULL;
3802 ExecDirectoryItem *item = NULL;
3803
3804 /* Adding new directories is supported from both *DirectorySymlink methods and the
3805 * older ones, so try to find an existing configuration first and create it if it's
3806 * not there yet. */
3807 for (size_t j = 0; j < directory->n_items; ++j)
3808 if (path_equal(source, directory->items[j].path)) {
3809 item = &directory->items[j];
3810 break;
3811 }
3812
3813 if (item)
3814 r = strv_extend(&item->symlinks, destination);
3815 else
3816 r = exec_directory_add(&directory->items, &directory->n_items, source, STRV_MAKE(destination));
3817 if (r < 0)
3818 return r;
3819
3820 /* Need to store them in the unit with the escapes, so that they can be parsed again */
3821 source_escaped = xescape(source, ":");
3822 destination_escaped = xescape(destination, ":");
3823 if (!source_escaped || !destination_escaped)
3824 return -ENOMEM;
3825
3826 unit_write_settingf(
3827 u, flags|UNIT_ESCAPE_SPECIFIERS, exec_directory_type_to_string(i),
3828 "%s=%s:%s",
3829 exec_directory_type_to_string(i),
3830 source_escaped,
3831 destination_escaped);
3832 }
3833 }
3834 if (r < 0)
3835 return r;
3836
3837 r = sd_bus_message_exit_container(message);
3838 if (r < 0)
3839 return r;
3840
3841 return 1;
3842
c7040b5d
LP
3843 }
3844
3845 return 0;
3846}