]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/core/dbus-execute.c
Merge pull request #23827 from yuwata/sd-event-process-buffered-inotify-data
[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
1594 a = unit_concat_strv(c->argv, UNIT_ESCAPE_C|UNIT_ESCAPE_SPECIFIERS);
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
1604 p = unit_escape_setting(c->path, UNIT_ESCAPE_C|UNIT_ESCAPE_SPECIFIERS, &t);
1605 if (!p)
1606 return -ENOMEM;
b3d59367 1607
540ac933
LP
1608 fprintf(f, "%s=%s@%s %s\n", name, exec_chars, p, a);
1609 }
9c0320e7
YW
1610 }
1611
1612 r = fflush_and_check(f);
1613 if (r < 0)
1614 return r;
1615
1616 unit_write_setting(u, flags, name, buf);
1617 }
1618
1619 return 1;
1620}
1621
7e2a3fcc
YW
1622static int parse_personality(const char *s, unsigned long *p) {
1623 unsigned long v;
1624
1625 assert(p);
1626
1627 v = personality_from_string(s);
1628 if (v == PERSONALITY_INVALID)
1629 return -EINVAL;
1630
1631 *p = v;
1632 return 0;
1633}
1634
1635static const char* mount_propagation_flags_to_string_with_check(unsigned long n) {
1636 if (!IN_SET(n, 0, MS_SHARED, MS_PRIVATE, MS_SLAVE))
1637 return NULL;
1638
1639 return mount_propagation_flags_to_string(n);
1640}
1641
1642static BUS_DEFINE_SET_TRANSIENT(nsec, "t", uint64_t, nsec_t, NSEC_FMT);
1643static BUS_DEFINE_SET_TRANSIENT_IS_VALID(log_level, "i", int32_t, int, "%" PRIi32, log_level_is_valid);
aad67b80 1644#if HAVE_SECCOMP
005bfaf1 1645static BUS_DEFINE_SET_TRANSIENT_IS_VALID(errno, "i", int32_t, int, "%" PRIi32, seccomp_errno_or_action_is_valid);
aad67b80 1646#endif
7e2a3fcc
YW
1647static BUS_DEFINE_SET_TRANSIENT_PARSE(std_input, ExecInput, exec_input_from_string);
1648static BUS_DEFINE_SET_TRANSIENT_PARSE(std_output, ExecOutput, exec_output_from_string);
1649static BUS_DEFINE_SET_TRANSIENT_PARSE(utmp_mode, ExecUtmpMode, exec_utmp_mode_from_string);
1e8c7bd5
YW
1650static BUS_DEFINE_SET_TRANSIENT_PARSE(protect_system, ProtectSystem, protect_system_from_string);
1651static BUS_DEFINE_SET_TRANSIENT_PARSE(protect_home, ProtectHome, protect_home_from_string);
7e2a3fcc 1652static BUS_DEFINE_SET_TRANSIENT_PARSE(keyring_mode, ExecKeyringMode, exec_keyring_mode_from_string);
4e399953
LP
1653static BUS_DEFINE_SET_TRANSIENT_PARSE(protect_proc, ProtectProc, protect_proc_from_string);
1654static BUS_DEFINE_SET_TRANSIENT_PARSE(proc_subset, ProcSubset, proc_subset_from_string);
7e2a3fcc
YW
1655static BUS_DEFINE_SET_TRANSIENT_PARSE(preserve_mode, ExecPreserveMode, exec_preserve_mode_from_string);
1656static BUS_DEFINE_SET_TRANSIENT_PARSE_PTR(personality, unsigned long, parse_personality);
1657static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(secure_bits, "i", int32_t, int, "%" PRIi32, secure_bits_to_string_alloc_with_check);
1658static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(capability, "t", uint64_t, uint64_t, "%" PRIu64, capability_set_to_string_alloc);
86c2a9f1 1659static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(namespace_flag, "t", uint64_t, unsigned long, "%" PRIu64, namespace_flags_to_string);
7e2a3fcc
YW
1660static BUS_DEFINE_SET_TRANSIENT_TO_STRING(mount_flags, "t", uint64_t, unsigned long, "%" PRIu64, mount_propagation_flags_to_string_with_check);
1661
c7040b5d
LP
1662int bus_exec_context_set_transient_property(
1663 Unit *u,
1664 ExecContext *c,
1665 const char *name,
1666 sd_bus_message *message,
2e59b241 1667 UnitWriteFlags flags,
c7040b5d
LP
1668 sd_bus_error *error) {
1669
6550c24c
LP
1670 const char *suffix;
1671 int r;
c7040b5d
LP
1672
1673 assert(u);
1674 assert(c);
1675 assert(name);
1676 assert(message);
1677
2e59b241
LP
1678 flags |= UNIT_PRIVATE;
1679
7e2a3fcc 1680 if (streq(name, "User"))
7a8867ab 1681 return bus_set_transient_user_relaxed(u, name, &c->user, message, flags, error);
c7040b5d 1682
7e2a3fcc 1683 if (streq(name, "Group"))
7a8867ab 1684 return bus_set_transient_user_relaxed(u, name, &c->group, message, flags, error);
c7040b5d 1685
7e2a3fcc
YW
1686 if (streq(name, "TTYPath"))
1687 return bus_set_transient_path(u, name, &c->tty_path, message, flags, error);
6f3e7985 1688
7e2a3fcc
YW
1689 if (streq(name, "RootImage"))
1690 return bus_set_transient_path(u, name, &c->root_image, message, flags, error);
76736280 1691
18d73705
LB
1692 if (streq(name, "RootImageOptions")) {
1693 _cleanup_(mount_options_free_allp) MountOptions *options = NULL;
1694 _cleanup_free_ char *format_str = NULL;
18d73705 1695
988172ce 1696 r = bus_read_mount_options(message, error, &options, &format_str, " ");
18d73705
LB
1697 if (r < 0)
1698 return r;
1699
1700 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
1701 if (LIST_IS_EMPTY(options)) {
1702 c->root_image_options = mount_options_free_all(c->root_image_options);
1703 unit_write_settingf(u, flags, name, "%s=", name);
1704 } else {
1705 LIST_JOIN(mount_options, c->root_image_options, options);
1706 unit_write_settingf(
1707 u, flags|UNIT_ESCAPE_SPECIFIERS, name,
1708 "%s=%s",
1709 name,
1710 format_str);
1711 }
1712 }
1713
1714 return 1;
1715 }
1716
0389f4fa
LB
1717 if (streq(name, "RootHash")) {
1718 const void *roothash_decoded;
1719 size_t roothash_decoded_size;
1720
1721 r = sd_bus_message_read_array(message, 'y', &roothash_decoded, &roothash_decoded_size);
1722 if (r < 0)
1723 return r;
1724
1725 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
1726 _cleanup_free_ char *encoded = NULL;
1727
1728 if (roothash_decoded_size == 0) {
1729 c->root_hash_path = mfree(c->root_hash_path);
1730 c->root_hash = mfree(c->root_hash);
1731 c->root_hash_size = 0;
1732
1733 unit_write_settingf(u, flags, name, "RootHash=");
1734 } else {
c2b2df60 1735 _cleanup_free_ void *p = NULL;
0389f4fa
LB
1736
1737 encoded = hexmem(roothash_decoded, roothash_decoded_size);
1738 if (!encoded)
1739 return -ENOMEM;
1740
1741 p = memdup(roothash_decoded, roothash_decoded_size);
1742 if (!p)
1743 return -ENOMEM;
1744
1745 free_and_replace(c->root_hash, p);
1746 c->root_hash_size = roothash_decoded_size;
1747 c->root_hash_path = mfree(c->root_hash_path);
1748
1749 unit_write_settingf(u, flags, name, "RootHash=%s", encoded);
1750 }
1751 }
1752
1753 return 1;
1754 }
1755
1756 if (streq(name, "RootHashPath")) {
1757 c->root_hash_size = 0;
1758 c->root_hash = mfree(c->root_hash);
1759
1760 return bus_set_transient_path(u, "RootHash", &c->root_hash_path, message, flags, error);
1761 }
1762
d4d55b0d
LB
1763 if (streq(name, "RootHashSignature")) {
1764 const void *roothash_sig_decoded;
1765 size_t roothash_sig_decoded_size;
1766
1767 r = sd_bus_message_read_array(message, 'y', &roothash_sig_decoded, &roothash_sig_decoded_size);
1768 if (r < 0)
1769 return r;
1770
1771 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
1772 _cleanup_free_ char *encoded = NULL;
1773
1774 if (roothash_sig_decoded_size == 0) {
1775 c->root_hash_sig_path = mfree(c->root_hash_sig_path);
1776 c->root_hash_sig = mfree(c->root_hash_sig);
1777 c->root_hash_sig_size = 0;
1778
1779 unit_write_settingf(u, flags, name, "RootHashSignature=");
1780 } else {
c2b2df60 1781 _cleanup_free_ void *p = NULL;
d4d55b0d
LB
1782 ssize_t len;
1783
1784 len = base64mem(roothash_sig_decoded, roothash_sig_decoded_size, &encoded);
1785 if (len < 0)
1786 return -ENOMEM;
1787
1788 p = memdup(roothash_sig_decoded, roothash_sig_decoded_size);
1789 if (!p)
1790 return -ENOMEM;
1791
1792 free_and_replace(c->root_hash_sig, p);
1793 c->root_hash_sig_size = roothash_sig_decoded_size;
1794 c->root_hash_sig_path = mfree(c->root_hash_sig_path);
1795
1796 unit_write_settingf(u, flags, name, "RootHashSignature=base64:%s", encoded);
1797 }
1798 }
1799
1800 return 1;
1801 }
1802
1803 if (streq(name, "RootHashSignaturePath")) {
1804 c->root_hash_sig_size = 0;
1805 c->root_hash_sig = mfree(c->root_hash_sig);
1806
1807 return bus_set_transient_path(u, "RootHashSignature", &c->root_hash_sig_path, message, flags, error);
1808 }
1809
0389f4fa
LB
1810 if (streq(name, "RootVerity"))
1811 return bus_set_transient_path(u, name, &c->root_verity, message, flags, error);
1812
7e2a3fcc
YW
1813 if (streq(name, "RootDirectory"))
1814 return bus_set_transient_path(u, name, &c->root_directory, message, flags, error);
c7040b5d 1815
7e2a3fcc
YW
1816 if (streq(name, "SyslogIdentifier"))
1817 return bus_set_transient_string(u, name, &c->syslog_identifier, message, flags, error);
c7040b5d 1818
7e2a3fcc
YW
1819 if (streq(name, "LogLevelMax"))
1820 return bus_set_transient_log_level(u, name, &c->log_level_max, message, flags, error);
1821
90fc172e 1822 if (streq(name, "LogRateLimitIntervalUSec"))
5ac1530e 1823 return bus_set_transient_usec(u, name, &c->log_ratelimit_interval_usec, message, flags, error);
90fc172e
AZ
1824
1825 if (streq(name, "LogRateLimitBurst"))
5ac1530e 1826 return bus_set_transient_unsigned(u, name, &c->log_ratelimit_burst, message, flags, error);
90fc172e 1827
7e2a3fcc
YW
1828 if (streq(name, "Personality"))
1829 return bus_set_transient_personality(u, name, &c->personality, message, flags, error);
1830
7e2a3fcc
YW
1831 if (streq(name, "StandardInput"))
1832 return bus_set_transient_std_input(u, name, &c->std_input, message, flags, error);
1833
1834 if (streq(name, "StandardOutput"))
1835 return bus_set_transient_std_output(u, name, &c->std_output, message, flags, error);
1836
1837 if (streq(name, "StandardError"))
1838 return bus_set_transient_std_output(u, name, &c->std_error, message, flags, error);
1839
1840 if (streq(name, "IgnoreSIGPIPE"))
1841 return bus_set_transient_bool(u, name, &c->ignore_sigpipe, message, flags, error);
1842
1843 if (streq(name, "TTYVHangup"))
1844 return bus_set_transient_bool(u, name, &c->tty_vhangup, message, flags, error);
1845
1846 if (streq(name, "TTYReset"))
1847 return bus_set_transient_bool(u, name, &c->tty_reset, message, flags, error);
1848
1849 if (streq(name, "TTYVTDisallocate"))
1850 return bus_set_transient_bool(u, name, &c->tty_vt_disallocate, message, flags, error);
51462135
DDM
1851
1852 if (streq(name, "TTYRows"))
1853 return bus_set_transient_unsigned(u, name, &c->tty_rows, message, flags, error);
1854
1855 if (streq(name, "TTYColumns"))
1856 return bus_set_transient_unsigned(u, name, &c->tty_cols, message, flags, error);
7e2a3fcc
YW
1857
1858 if (streq(name, "PrivateTmp"))
1859 return bus_set_transient_bool(u, name, &c->private_tmp, message, flags, error);
1860
1861 if (streq(name, "PrivateDevices"))
1862 return bus_set_transient_bool(u, name, &c->private_devices, message, flags, error);
1863
228af36f
LP
1864 if (streq(name, "PrivateMounts"))
1865 return bus_set_transient_bool(u, name, &c->private_mounts, message, flags, error);
1866
7e2a3fcc
YW
1867 if (streq(name, "PrivateNetwork"))
1868 return bus_set_transient_bool(u, name, &c->private_network, message, flags, error);
1869
a70581ff
XR
1870 if (streq(name, "PrivateIPC"))
1871 return bus_set_transient_bool(u, name, &c->private_ipc, message, flags, error);
1872
7e2a3fcc
YW
1873 if (streq(name, "PrivateUsers"))
1874 return bus_set_transient_bool(u, name, &c->private_users, message, flags, error);
1875
1876 if (streq(name, "NoNewPrivileges"))
1877 return bus_set_transient_bool(u, name, &c->no_new_privileges, message, flags, error);
1878
1879 if (streq(name, "SyslogLevelPrefix"))
1880 return bus_set_transient_bool(u, name, &c->syslog_level_prefix, message, flags, error);
1881
1882 if (streq(name, "MemoryDenyWriteExecute"))
1883 return bus_set_transient_bool(u, name, &c->memory_deny_write_execute, message, flags, error);
1884
1885 if (streq(name, "RestrictRealtime"))
1886 return bus_set_transient_bool(u, name, &c->restrict_realtime, message, flags, error);
1887
f69567cb
LP
1888 if (streq(name, "RestrictSUIDSGID"))
1889 return bus_set_transient_bool(u, name, &c->restrict_suid_sgid, message, flags, error);
1890
7e2a3fcc
YW
1891 if (streq(name, "DynamicUser"))
1892 return bus_set_transient_bool(u, name, &c->dynamic_user, message, flags, error);
1893
1894 if (streq(name, "RemoveIPC"))
1895 return bus_set_transient_bool(u, name, &c->remove_ipc, message, flags, error);
1896
1897 if (streq(name, "ProtectKernelTunables"))
1898 return bus_set_transient_bool(u, name, &c->protect_kernel_tunables, message, flags, error);
1899
1900 if (streq(name, "ProtectKernelModules"))
1901 return bus_set_transient_bool(u, name, &c->protect_kernel_modules, message, flags, error);
1902
84703040
KK
1903 if (streq(name, "ProtectKernelLogs"))
1904 return bus_set_transient_bool(u, name, &c->protect_kernel_logs, message, flags, error);
1905
fc64760d
KK
1906 if (streq(name, "ProtectClock"))
1907 return bus_set_transient_bool(u, name, &c->protect_clock, message, flags, error);
1908
7e2a3fcc
YW
1909 if (streq(name, "ProtectControlGroups"))
1910 return bus_set_transient_bool(u, name, &c->protect_control_groups, message, flags, error);
1911
7e2a3fcc
YW
1912 if (streq(name, "CPUSchedulingResetOnFork"))
1913 return bus_set_transient_bool(u, name, &c->cpu_sched_reset_on_fork, message, flags, error);
1914
1915 if (streq(name, "NonBlocking"))
1916 return bus_set_transient_bool(u, name, &c->non_blocking, message, flags, error);
1917
1918 if (streq(name, "LockPersonality"))
1919 return bus_set_transient_bool(u, name, &c->lock_personality, message, flags, error);
1920
aecd5ac6
TM
1921 if (streq(name, "ProtectHostname"))
1922 return bus_set_transient_bool(u, name, &c->protect_hostname, message, flags, error);
1923
7e2a3fcc
YW
1924 if (streq(name, "UtmpIdentifier"))
1925 return bus_set_transient_string(u, name, &c->utmp_id, message, flags, error);
1926
1927 if (streq(name, "UtmpMode"))
1928 return bus_set_transient_utmp_mode(u, name, &c->utmp_mode, message, flags, error);
1929
1930 if (streq(name, "PAMName"))
1931 return bus_set_transient_string(u, name, &c->pam_name, message, flags, error);
1932
1933 if (streq(name, "TimerSlackNSec"))
1934 return bus_set_transient_nsec(u, name, &c->timer_slack_nsec, message, flags, error);
1935
1936 if (streq(name, "ProtectSystem"))
1937 return bus_set_transient_protect_system(u, name, &c->protect_system, message, flags, error);
1938
1939 if (streq(name, "ProtectHome"))
1940 return bus_set_transient_protect_home(u, name, &c->protect_home, message, flags, error);
cffaed83 1941
7e2a3fcc
YW
1942 if (streq(name, "KeyringMode"))
1943 return bus_set_transient_keyring_mode(u, name, &c->keyring_mode, message, flags, error);
1944
4e399953
LP
1945 if (streq(name, "ProtectProc"))
1946 return bus_set_transient_protect_proc(u, name, &c->protect_proc, message, flags, error);
1947
1948 if (streq(name, "ProcSubset"))
1949 return bus_set_transient_proc_subset(u, name, &c->proc_subset, message, flags, error);
1950
7e2a3fcc
YW
1951 if (streq(name, "RuntimeDirectoryPreserve"))
1952 return bus_set_transient_preserve_mode(u, name, &c->runtime_directory_preserve_mode, message, flags, error);
1953
1954 if (streq(name, "UMask"))
1955 return bus_set_transient_mode_t(u, name, &c->umask, message, flags, error);
1956
1957 if (streq(name, "RuntimeDirectoryMode"))
1958 return bus_set_transient_mode_t(u, name, &c->directories[EXEC_DIRECTORY_RUNTIME].mode, message, flags, error);
1959
1960 if (streq(name, "StateDirectoryMode"))
1961 return bus_set_transient_mode_t(u, name, &c->directories[EXEC_DIRECTORY_STATE].mode, message, flags, error);
1962
1963 if (streq(name, "CacheDirectoryMode"))
1964 return bus_set_transient_mode_t(u, name, &c->directories[EXEC_DIRECTORY_CACHE].mode, message, flags, error);
1965
1966 if (streq(name, "LogsDirectoryMode"))
1967 return bus_set_transient_mode_t(u, name, &c->directories[EXEC_DIRECTORY_LOGS].mode, message, flags, error);
1968
1969 if (streq(name, "ConfigurationDirectoryMode"))
1970 return bus_set_transient_mode_t(u, name, &c->directories[EXEC_DIRECTORY_CONFIGURATION].mode, message, flags, error);
1971
1972 if (streq(name, "SELinuxContext"))
1973 return bus_set_transient_string(u, name, &c->selinux_context, message, flags, error);
1974
1975 if (streq(name, "SecureBits"))
1976 return bus_set_transient_secure_bits(u, name, &c->secure_bits, message, flags, error);
1977
1978 if (streq(name, "CapabilityBoundingSet"))
1979 return bus_set_transient_capability(u, name, &c->capability_bounding_set, message, flags, error);
1980
1981 if (streq(name, "AmbientCapabilities"))
1982 return bus_set_transient_capability(u, name, &c->capability_ambient_set, message, flags, error);
1983
7e2a3fcc
YW
1984 if (streq(name, "RestrictNamespaces"))
1985 return bus_set_transient_namespace_flag(u, name, &c->restrict_namespaces, message, flags, error);
1986
cc86a278
ILG
1987 if (streq(name, "RestrictFileSystems")) {
1988 int allow_list;
1989 _cleanup_strv_free_ char **l = NULL;
1990
1991 r = sd_bus_message_enter_container(message, 'r', "bas");
1992 if (r < 0)
1993 return r;
1994
1995 r = sd_bus_message_read(message, "b", &allow_list);
1996 if (r < 0)
1997 return r;
1998
1999 r = sd_bus_message_read_strv(message, &l);
2000 if (r < 0)
2001 return r;
2002
2003 r = sd_bus_message_exit_container(message);
2004 if (r < 0)
2005 return r;
2006
2007 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2008 _cleanup_free_ char *joined = NULL;
2009 FilesystemParseFlags invert_flag = allow_list ? 0 : FILESYSTEM_PARSE_INVERT;
cc86a278
ILG
2010
2011 if (strv_isempty(l)) {
2012 c->restrict_filesystems_allow_list = false;
2013 c->restrict_filesystems = set_free(c->restrict_filesystems);
2014
2015 unit_write_setting(u, flags, name, "RestrictFileSystems=");
2016 return 1;
2017 }
2018
2019 if (!c->restrict_filesystems)
2020 c->restrict_filesystems_allow_list = allow_list;
2021
2022 STRV_FOREACH(s, l) {
2023 r = lsm_bpf_parse_filesystem(
2024 *s,
2025 &c->restrict_filesystems,
2026 FILESYSTEM_PARSE_LOG|
2027 (invert_flag ? FILESYSTEM_PARSE_INVERT : 0)|
2028 (c->restrict_filesystems_allow_list ? FILESYSTEM_PARSE_ALLOW_LIST : 0),
2029 u->id, NULL, 0);
2030 if (r < 0)
2031 return r;
2032 }
2033
2034 joined = strv_join(l, " ");
2035 if (!joined)
2036 return -ENOMEM;
2037
2038 unit_write_settingf(u, flags, name, "%s=%s%s", name, allow_list ? "" : "~", joined);
2039 }
2040
2041 return 1;
2042 }
2043
7e2a3fcc
YW
2044 if (streq(name, "MountFlags"))
2045 return bus_set_transient_mount_flags(u, name, &c->mount_flags, message, flags, error);
2046
a8d08f39
LP
2047 if (streq(name, "NetworkNamespacePath"))
2048 return bus_set_transient_path(u, name, &c->network_namespace_path, message, flags, error);
2049
a70581ff
XR
2050 if (streq(name, "IPCNamespacePath"))
2051 return bus_set_transient_path(u, name, &c->ipc_namespace_path, message, flags, error);
2052
7e2a3fcc 2053 if (streq(name, "SupplementaryGroups")) {
cffaed83 2054 _cleanup_strv_free_ char **l = NULL;
cffaed83
YW
2055
2056 r = sd_bus_message_read_strv(message, &l);
2057 if (r < 0)
2058 return r;
2059
d2a23692 2060 STRV_FOREACH(p, l)
7a8867ab 2061 if (!isempty(*p) && !valid_user_group_name(*p, VALID_USER_ALLOW_NUMERIC|VALID_USER_RELAX|VALID_USER_WARN))
d2a23692
ZJS
2062 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS,
2063 "Invalid supplementary group names");
cffaed83 2064
2e59b241 2065 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
7b943bb7 2066 if (strv_isempty(l)) {
cffaed83 2067 c->supplementary_groups = strv_free(c->supplementary_groups);
2e59b241 2068 unit_write_settingf(u, flags, name, "%s=", name);
cffaed83
YW
2069 } else {
2070 _cleanup_free_ char *joined = NULL;
2071
2072 r = strv_extend_strv(&c->supplementary_groups, l, true);
2073 if (r < 0)
2074 return -ENOMEM;
2075
2076 joined = strv_join(c->supplementary_groups, " ");
2077 if (!joined)
2078 return -ENOMEM;
2079
2e59b241 2080 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "%s=%s", name, joined);
cffaed83
YW
2081 }
2082 }
2083
2084 return 1;
2085
43144be4 2086 } else if (STR_IN_SET(name, "SetCredential", "SetCredentialEncrypted")) {
bb0c0d6f
LP
2087 bool isempty = true;
2088
2089 r = sd_bus_message_enter_container(message, 'a', "(say)");
2090 if (r < 0)
2091 return r;
2092
2093 for (;;) {
2094 const char *id;
2095 const void *p;
2096 size_t sz;
2097
2098 r = sd_bus_message_enter_container(message, 'r', "say");
2099 if (r < 0)
2100 return r;
2101 if (r == 0)
2102 break;
2103
2104 r = sd_bus_message_read(message, "s", &id);
2105 if (r < 0)
2106 return r;
2107
2108 r = sd_bus_message_read_array(message, 'y', &p, &sz);
2109 if (r < 0)
2110 return r;
2111
2112 r = sd_bus_message_exit_container(message);
2113 if (r < 0)
2114 return r;
2115
2116 if (!credential_name_valid(id))
2117 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Credential ID is invalid: %s", id);
2118
2119 isempty = false;
2120
2121 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2122 _cleanup_free_ char *a = NULL, *b = NULL;
2123 _cleanup_free_ void *copy = NULL;
2124 ExecSetCredential *old;
2125
2126 copy = memdup(p, sz);
2127 if (!copy)
2128 return -ENOMEM;
2129
2130 old = hashmap_get(c->set_credentials, id);
2131 if (old) {
2132 free_and_replace(old->data, copy);
2133 old->size = sz;
43144be4 2134 old->encrypted = streq(name, "SetCredentialEncrypted");
bb0c0d6f
LP
2135 } else {
2136 _cleanup_(exec_set_credential_freep) ExecSetCredential *sc = NULL;
2137
43144be4 2138 sc = new(ExecSetCredential, 1);
bb0c0d6f
LP
2139 if (!sc)
2140 return -ENOMEM;
2141
43144be4
LP
2142 *sc = (ExecSetCredential) {
2143 .id = strdup(id),
2144 .data = TAKE_PTR(copy),
2145 .size = sz,
2146 .encrypted = streq(name, "SetCredentialEncrypted"),
2147 };
2148
bb0c0d6f
LP
2149 if (!sc->id)
2150 return -ENOMEM;
2151
cf55fe4a 2152 r = hashmap_ensure_put(&c->set_credentials, &exec_set_credential_hash_ops, sc->id, sc);
bb0c0d6f
LP
2153 if (r < 0)
2154 return r;
2155
2156 TAKE_PTR(sc);
2157 }
2158
2159 a = specifier_escape(id);
2160 if (!a)
2161 return -ENOMEM;
2162
2163 b = cescape_length(p, sz);
2164 if (!b)
2165 return -ENOMEM;
2166
2167 (void) unit_write_settingf(u, flags, name, "%s=%s:%s", name, a, b);
2168 }
2169 }
2170
2171 r = sd_bus_message_exit_container(message);
2172 if (r < 0)
2173 return r;
2174
2175 if (!UNIT_WRITE_FLAGS_NOOP(flags) && isempty) {
2176 c->set_credentials = hashmap_free(c->set_credentials);
2177 (void) unit_write_settingf(u, flags, name, "%s=", name);
2178 }
2179
2180 return 1;
2181
43144be4 2182 } else if (STR_IN_SET(name, "LoadCredential", "LoadCredentialEncrypted")) {
bb0c0d6f
LP
2183 bool isempty = true;
2184
2185 r = sd_bus_message_enter_container(message, 'a', "(ss)");
2186 if (r < 0)
2187 return r;
2188
2189 for (;;) {
2190 const char *id, *source;
2191
2192 r = sd_bus_message_read(message, "(ss)", &id, &source);
2193 if (r < 0)
2194 return r;
2195 if (r == 0)
2196 break;
2197
2198 if (!credential_name_valid(id))
2199 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Credential ID is invalid: %s", id);
2200
2201 if (!(path_is_absolute(source) ? path_is_normalized(source) : credential_name_valid(source)))
2202 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Credential source is invalid: %s", source);
2203
2204 isempty = false;
2205
2206 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
43144be4
LP
2207 _cleanup_free_ char *copy = NULL;
2208 ExecLoadCredential *old;
2209
2210 copy = strdup(source);
2211 if (!copy)
2212 return -ENOMEM;
2213
2214 old = hashmap_get(c->load_credentials, id);
2215 if (old) {
2216 free_and_replace(old->path, copy);
2217 old->encrypted = streq(name, "LoadCredentialEncrypted");
2218 } else {
2219 _cleanup_(exec_load_credential_freep) ExecLoadCredential *lc = NULL;
2220
2221 lc = new(ExecLoadCredential, 1);
2222 if (!lc)
2223 return -ENOMEM;
2224
2225 *lc = (ExecLoadCredential) {
2226 .id = strdup(id),
2227 .path = TAKE_PTR(copy),
2228 .encrypted = streq(name, "LoadCredentialEncrypted"),
2229 };
2230
2231 if (!lc->id)
2232 return -ENOMEM;
2233
2234 r = hashmap_ensure_put(&c->load_credentials, &exec_load_credential_hash_ops, lc->id, lc);
2235 if (r < 0)
2236 return r;
2237
2238 TAKE_PTR(lc);
2239 }
bb0c0d6f
LP
2240
2241 (void) unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "%s=%s:%s", name, id, source);
2242 }
2243 }
2244
2245 r = sd_bus_message_exit_container(message);
2246 if (r < 0)
2247 return r;
2248
2249 if (!UNIT_WRITE_FLAGS_NOOP(flags) && isempty) {
43144be4 2250 c->load_credentials = hashmap_free(c->load_credentials);
bb0c0d6f
LP
2251 (void) unit_write_settingf(u, flags, name, "%s=", name);
2252 }
2253
2254 return 1;
2255
a8a13575 2256 } else if (streq(name, "SyslogLevel")) {
8d1dd6ab 2257 int32_t level;
a8a13575
EV
2258
2259 r = sd_bus_message_read(message, "i", &level);
2260 if (r < 0)
2261 return r;
2262
e0d6e0fa 2263 if (!log_level_is_valid(level))
1b09b81c 2264 return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Log level value out of range");
e0d6e0fa 2265
2e59b241 2266 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
a8a13575 2267 c->syslog_priority = (c->syslog_priority & LOG_FACMASK) | level;
2e59b241 2268 unit_write_settingf(u, flags, name, "SyslogLevel=%i", level);
a8a13575
EV
2269 }
2270
460ed929 2271 return 1;
7e2a3fcc 2272
460ed929 2273 } else if (streq(name, "SyslogFacility")) {
8d1dd6ab 2274 int32_t facility;
460ed929
EV
2275
2276 r = sd_bus_message_read(message, "i", &facility);
2277 if (r < 0)
2278 return r;
2279
e0d6e0fa 2280 if (!log_facility_unshifted_is_valid(facility))
1b09b81c 2281 return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Log facility value out of range");
e0d6e0fa 2282
2e59b241 2283 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
460ed929 2284 c->syslog_priority = (facility << 3) | LOG_PRI(c->syslog_priority);
2e59b241 2285 unit_write_settingf(u, flags, name, "SyslogFacility=%i", facility);
460ed929
EV
2286 }
2287
cffaed83 2288 return 1;
d3070fbd 2289
91dd5f7c
LP
2290 } else if (streq(name, "LogNamespace")) {
2291 const char *n;
2292
2293 r = sd_bus_message_read(message, "s", &n);
2294 if (r < 0)
2295 return r;
2296
2297 if (!isempty(n) && !log_namespace_name_valid(n))
1b09b81c 2298 return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Log namespace name not valid");
91dd5f7c
LP
2299
2300 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2301
2302 if (isempty(n)) {
2303 c->log_namespace = mfree(c->log_namespace);
2304 unit_write_settingf(u, flags, name, "%s=", name);
2305 } else {
2306 r = free_and_strdup(&c->log_namespace, n);
2307 if (r < 0)
2308 return r;
2309
2310 unit_write_settingf(u, flags, name, "%s=%s", name, n);
2311 }
2312 }
2313
2314 return 1;
2315
d3070fbd
LP
2316 } else if (streq(name, "LogExtraFields")) {
2317 size_t n = 0;
2318
2319 r = sd_bus_message_enter_container(message, 'a', "ay");
2320 if (r < 0)
2321 return r;
2322
2323 for (;;) {
2324 _cleanup_free_ void *copy = NULL;
2325 struct iovec *t;
2326 const char *eq;
2327 const void *p;
2328 size_t sz;
2329
2330 /* Note that we expect a byte array for each field, instead of a string. That's because on the
2331 * lower-level journal fields can actually contain binary data and are not restricted to text,
2332 * and we should not "lose precision" in our types on the way. That said, I am pretty sure
2333 * actually encoding binary data as unit metadata is not a good idea. Hence we actually refuse
2334 * any actual binary data, and only accept UTF-8. This allows us to eventually lift this
2335 * limitation, should a good, valid usecase arise. */
2336
2337 r = sd_bus_message_read_array(message, 'y', &p, &sz);
2338 if (r < 0)
2339 return r;
2340 if (r == 0)
2341 break;
2342
2343 if (memchr(p, 0, sz))
1b09b81c 2344 return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Journal field contains zero byte");
d3070fbd
LP
2345
2346 eq = memchr(p, '=', sz);
2347 if (!eq)
1b09b81c 2348 return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Journal field contains no '=' character");
d3070fbd 2349 if (!journal_field_valid(p, eq - (const char*) p, false))
1b09b81c 2350 return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Journal field invalid");
d3070fbd 2351
2e59b241 2352 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
aa484f35 2353 t = reallocarray(c->log_extra_fields, c->n_log_extra_fields+1, sizeof(struct iovec));
d3070fbd
LP
2354 if (!t)
2355 return -ENOMEM;
2356 c->log_extra_fields = t;
2357 }
2358
2359 copy = malloc(sz + 1);
2360 if (!copy)
2361 return -ENOMEM;
2362
2363 memcpy(copy, p, sz);
2364 ((uint8_t*) copy)[sz] = 0;
2365
2366 if (!utf8_is_valid(copy))
1b09b81c 2367 return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Journal field is not valid UTF-8");
d3070fbd 2368
2e59b241 2369 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
d3070fbd 2370 c->log_extra_fields[c->n_log_extra_fields++] = IOVEC_MAKE(copy, sz);
2e59b241 2371 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS|UNIT_ESCAPE_C, name, "LogExtraFields=%s", (char*) copy);
d3070fbd
LP
2372
2373 copy = NULL;
2374 }
2375
2376 n++;
2377 }
2378
2379 r = sd_bus_message_exit_container(message);
2380 if (r < 0)
2381 return r;
2382
2e59b241 2383 if (!UNIT_WRITE_FLAGS_NOOP(flags) && n == 0) {
d3070fbd 2384 exec_context_free_log_extra_fields(c);
2e59b241 2385 unit_write_setting(u, flags, name, "LogExtraFields=");
d3070fbd
LP
2386 }
2387
2388 return 1;
7e2a3fcc 2389 }
cffaed83 2390
349cc4a5 2391#if HAVE_SECCOMP
cffaed83 2392
7e2a3fcc
YW
2393 if (streq(name, "SystemCallErrorNumber"))
2394 return bus_set_transient_errno(u, name, &c->syscall_errno, message, flags, error);
2395
2396 if (streq(name, "SystemCallFilter")) {
6b000af4 2397 int allow_list;
3f856a28 2398 _cleanup_strv_free_ char **l = NULL;
cffaed83
YW
2399
2400 r = sd_bus_message_enter_container(message, 'r', "bas");
2401 if (r < 0)
2402 return r;
2403
6b000af4 2404 r = sd_bus_message_read(message, "b", &allow_list);
cffaed83
YW
2405 if (r < 0)
2406 return r;
2407
2408 r = sd_bus_message_read_strv(message, &l);
2409 if (r < 0)
2410 return r;
2411
2412 r = sd_bus_message_exit_container(message);
2413 if (r < 0)
2414 return r;
2415
2e59b241 2416 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
cffaed83 2417 _cleanup_free_ char *joined = NULL;
6b000af4 2418 SeccompParseFlags invert_flag = allow_list ? 0 : SECCOMP_PARSE_INVERT;
cffaed83 2419
7b943bb7 2420 if (strv_isempty(l)) {
6b000af4 2421 c->syscall_allow_list = false;
8cfa775f 2422 c->syscall_filter = hashmap_free(c->syscall_filter);
cffaed83 2423
898748d8
YW
2424 unit_write_settingf(u, flags, name, "SystemCallFilter=");
2425 return 1;
2426 }
cffaed83 2427
898748d8
YW
2428 if (!c->syscall_filter) {
2429 c->syscall_filter = hashmap_new(NULL);
2430 if (!c->syscall_filter)
2431 return log_oom();
cffaed83 2432
6b000af4 2433 c->syscall_allow_list = allow_list;
8cfa775f 2434
6b000af4 2435 if (c->syscall_allow_list) {
e7ccdfa8
ZJS
2436 r = seccomp_parse_syscall_filter("@default",
2437 -1,
2438 c->syscall_filter,
72545ae0 2439 SECCOMP_PARSE_PERMISSIVE |
1008d415 2440 SECCOMP_PARSE_ALLOW_LIST,
58f6ab44
ZJS
2441 u->id,
2442 NULL, 0);
8cfa775f
YW
2443 if (r < 0)
2444 return r;
898748d8
YW
2445 }
2446 }
8cfa775f 2447
898748d8
YW
2448 STRV_FOREACH(s, l) {
2449 _cleanup_free_ char *n = NULL;
2450 int e;
cffaed83 2451
898748d8
YW
2452 r = parse_syscall_and_errno(*s, &n, &e);
2453 if (r < 0)
2454 return r;
cffaed83 2455
084a46d7
YW
2456 if (allow_list && e >= 0)
2457 return -EINVAL;
2458
e7ccdfa8
ZJS
2459 r = seccomp_parse_syscall_filter(n,
2460 e,
2461 c->syscall_filter,
72545ae0
AZ
2462 SECCOMP_PARSE_LOG | SECCOMP_PARSE_PERMISSIVE |
2463 invert_flag |
6b000af4 2464 (c->syscall_allow_list ? SECCOMP_PARSE_ALLOW_LIST : 0),
58f6ab44
ZJS
2465 u->id,
2466 NULL, 0);
898748d8
YW
2467 if (r < 0)
2468 return r;
cffaed83
YW
2469 }
2470
2471 joined = strv_join(l, " ");
2472 if (!joined)
2473 return -ENOMEM;
2474
6b000af4 2475 unit_write_settingf(u, flags, name, "SystemCallFilter=%s%s", allow_list ? "" : "~", joined);
cffaed83
YW
2476 }
2477
2478 return 1;
2479
9df2cdd8
TM
2480 } else if (streq(name, "SystemCallLog")) {
2481 int allow_list;
2482 _cleanup_strv_free_ char **l = NULL;
2483
2484 r = sd_bus_message_enter_container(message, 'r', "bas");
2485 if (r < 0)
2486 return r;
2487
2488 r = sd_bus_message_read(message, "b", &allow_list);
2489 if (r < 0)
2490 return r;
2491
2492 r = sd_bus_message_read_strv(message, &l);
2493 if (r < 0)
2494 return r;
2495
2496 r = sd_bus_message_exit_container(message);
2497 if (r < 0)
2498 return r;
2499
2500 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2501 _cleanup_free_ char *joined = NULL;
2502 SeccompParseFlags invert_flag = allow_list ? 0 : SECCOMP_PARSE_INVERT;
9df2cdd8
TM
2503
2504 if (strv_isempty(l)) {
2505 c->syscall_log_allow_list = false;
2506 c->syscall_log = hashmap_free(c->syscall_log);
2507
2508 unit_write_settingf(u, flags, name, "SystemCallLog=");
2509 return 1;
2510 }
2511
2512 if (!c->syscall_log) {
2513 c->syscall_log = hashmap_new(NULL);
2514 if (!c->syscall_log)
2515 return log_oom();
2516
2517 c->syscall_log_allow_list = allow_list;
2518 }
2519
2520 STRV_FOREACH(s, l) {
696a13ba
YW
2521 r = seccomp_parse_syscall_filter(*s,
2522 -1, /* errno not used */
9df2cdd8
TM
2523 c->syscall_log,
2524 SECCOMP_PARSE_LOG | SECCOMP_PARSE_PERMISSIVE |
2525 invert_flag |
2526 (c->syscall_log_allow_list ? SECCOMP_PARSE_ALLOW_LIST : 0),
2527 u->id,
2528 NULL, 0);
2529 if (r < 0)
2530 return r;
2531 }
2532
2533 joined = strv_join(l, " ");
2534 if (!joined)
2535 return -ENOMEM;
2536
2537 unit_write_settingf(u, flags, name, "SystemCallLog=%s%s", allow_list ? "" : "~", joined);
2538 }
2539
2540 return 1;
2541
cffaed83
YW
2542 } else if (streq(name, "SystemCallArchitectures")) {
2543 _cleanup_strv_free_ char **l = NULL;
2544
2545 r = sd_bus_message_read_strv(message, &l);
2546 if (r < 0)
2547 return r;
2548
2e59b241 2549 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
cffaed83
YW
2550 _cleanup_free_ char *joined = NULL;
2551
7b943bb7 2552 if (strv_isempty(l))
cffaed83 2553 c->syscall_archs = set_free(c->syscall_archs);
de010b0b 2554 else
cffaed83
YW
2555 STRV_FOREACH(s, l) {
2556 uint32_t a;
2557
2558 r = seccomp_arch_from_string(*s, &a);
2559 if (r < 0)
2560 return r;
2561
de7fef4b 2562 r = set_ensure_put(&c->syscall_archs, NULL, UINT32_TO_PTR(a + 1));
cffaed83
YW
2563 if (r < 0)
2564 return r;
2565 }
2566
cffaed83
YW
2567 joined = strv_join(l, " ");
2568 if (!joined)
2569 return -ENOMEM;
2570
2e59b241 2571 unit_write_settingf(u, flags, name, "%s=%s", name, joined);
cffaed83
YW
2572 }
2573
2574 return 1;
2575
cffaed83 2576 } else if (streq(name, "RestrictAddressFamilies")) {
3f856a28 2577 _cleanup_strv_free_ char **l = NULL;
4e6c50a5 2578 int allow_list;
cffaed83
YW
2579
2580 r = sd_bus_message_enter_container(message, 'r', "bas");
2581 if (r < 0)
2582 return r;
2583
6b000af4 2584 r = sd_bus_message_read(message, "b", &allow_list);
cffaed83
YW
2585 if (r < 0)
2586 return r;
2587
2588 r = sd_bus_message_read_strv(message, &l);
2589 if (r < 0)
2590 return r;
2591
2592 r = sd_bus_message_exit_container(message);
2593 if (r < 0)
2594 return r;
2595
2e59b241 2596 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
cffaed83
YW
2597 _cleanup_free_ char *joined = NULL;
2598
7b943bb7 2599 if (strv_isempty(l)) {
4e6c50a5 2600 c->address_families_allow_list = allow_list;
cffaed83 2601 c->address_families = set_free(c->address_families);
cffaed83 2602
4e6c50a5
YW
2603 unit_write_settingf(u, flags, name, "RestrictAddressFamilies=%s",
2604 allow_list ? "none" : "");
9ee896d5
YW
2605 return 1;
2606 }
cffaed83 2607
9ee896d5
YW
2608 if (!c->address_families) {
2609 c->address_families = set_new(NULL);
2610 if (!c->address_families)
2611 return log_oom();
cffaed83 2612
6b000af4 2613 c->address_families_allow_list = allow_list;
9ee896d5
YW
2614 }
2615
2616 STRV_FOREACH(s, l) {
2617 int af;
cffaed83 2618
9ee896d5 2619 af = af_from_name(*s);
acf4d158
YW
2620 if (af < 0)
2621 return af;
cffaed83 2622
6b000af4 2623 if (allow_list == c->address_families_allow_list) {
cffaed83
YW
2624 r = set_put(c->address_families, INT_TO_PTR(af));
2625 if (r < 0)
2626 return r;
9ee896d5 2627 } else
4e6c50a5 2628 set_remove(c->address_families, INT_TO_PTR(af));
cffaed83
YW
2629 }
2630
2631 joined = strv_join(l, " ");
2632 if (!joined)
2633 return -ENOMEM;
2634
6b000af4 2635 unit_write_settingf(u, flags, name, "RestrictAddressFamilies=%s%s", allow_list ? "" : "~", joined);
cffaed83
YW
2636 }
2637
2638 return 1;
7e2a3fcc 2639 }
cffaed83 2640#endif
b070c7c0 2641 if (STR_IN_SET(name, "CPUAffinity", "NUMAMask")) {
cffaed83 2642 const void *a;
bd0abfae 2643 size_t n;
b070c7c0 2644 bool affinity = streq(name, "CPUAffinity");
c367f996 2645 _cleanup_(cpu_set_reset) CPUSet set = {};
cffaed83
YW
2646
2647 r = sd_bus_message_read_array(message, 'y', &a, &n);
2648 if (r < 0)
2649 return r;
2650
c367f996
MS
2651 r = cpu_set_from_dbus(a, n, &set);
2652 if (r < 0)
2653 return r;
2654
2e59b241 2655 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
cffaed83 2656 if (n == 0) {
b070c7c0 2657 cpu_set_reset(affinity ? &c->cpu_set : &c->numa_policy.nodes);
2e59b241 2658 unit_write_settingf(u, flags, name, "%s=", name);
cffaed83
YW
2659 } else {
2660 _cleanup_free_ char *str = NULL;
cffaed83 2661
0985c7c4 2662 str = cpu_set_to_string(&set);
a832893f
ZJS
2663 if (!str)
2664 return -ENOMEM;
cffaed83 2665
0985c7c4
ZJS
2666 /* We forego any optimizations here, and always create the structure using
2667 * cpu_set_add_all(), because we don't want to care if the existing size we
2668 * got over dbus is appropriate. */
b070c7c0 2669 r = cpu_set_add_all(affinity ? &c->cpu_set : &c->numa_policy.nodes, &set);
0985c7c4
ZJS
2670 if (r < 0)
2671 return r;
501941aa 2672
2e59b241 2673 unit_write_settingf(u, flags, name, "%s=%s", name, str);
cffaed83
YW
2674 }
2675 }
2676
c7040b5d
LP
2677 return 1;
2678
e2b2fb7f
MS
2679 } else if (streq(name, "CPUAffinityFromNUMA")) {
2680 int q;
2681
2682 r = sd_bus_message_read_basic(message, 'b', &q);
2683 if (r < 0)
2684 return r;
2685
2686 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2687 c->cpu_affinity_from_numa = q;
2688 unit_write_settingf(u, flags, name, "%s=%s", "CPUAffinity", "numa");
2689 }
2690
2691 return 1;
2692
b070c7c0
MS
2693 } else if (streq(name, "NUMAPolicy")) {
2694 int32_t type;
2695
2696 r = sd_bus_message_read(message, "i", &type);
2697 if (r < 0)
2698 return r;
2699
2700 if (!mpol_is_valid(type))
2701 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid NUMAPolicy value: %i", type);
2702
2703 if (!UNIT_WRITE_FLAGS_NOOP(flags))
2704 c->numa_policy.type = type;
2705
2706 return 1;
e2b2fb7f 2707
c250bf67
YW
2708 } else if (streq(name, "Nice")) {
2709 int32_t q;
2710
2711 r = sd_bus_message_read(message, "i", &q);
2712 if (r < 0)
2713 return r;
2714
2715 if (!nice_is_valid(q))
2716 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid Nice value: %i", q);
2717
2718 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2719 c->nice = q;
2720 c->nice_set = true;
2721
2722 unit_write_settingf(u, flags, name, "Nice=%i", q);
2723 }
2724
2725 return 1;
2726
2727 } else if (streq(name, "CPUSchedulingPolicy")) {
2728 int32_t q;
2729
2730 r = sd_bus_message_read(message, "i", &q);
2731 if (r < 0)
2732 return r;
2733
2734 if (!sched_policy_is_valid(q))
2735 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid CPU scheduling policy: %i", q);
2736
2737 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2738 _cleanup_free_ char *s = NULL;
2739
2740 r = sched_policy_to_string_alloc(q, &s);
2741 if (r < 0)
2742 return r;
2743
2744 c->cpu_sched_policy = q;
2745 c->cpu_sched_priority = CLAMP(c->cpu_sched_priority, sched_get_priority_min(q), sched_get_priority_max(q));
2746 c->cpu_sched_set = true;
2747
2748 unit_write_settingf(u, flags, name, "CPUSchedulingPolicy=%s", s);
2749 }
2750
2751 return 1;
2752
2753 } else if (streq(name, "CPUSchedulingPriority")) {
2754 int32_t p, min, max;
2755
2756 r = sd_bus_message_read(message, "i", &p);
2757 if (r < 0)
2758 return r;
2759
2760 min = sched_get_priority_min(c->cpu_sched_policy);
2761 max = sched_get_priority_max(c->cpu_sched_policy);
2762 if (p < min || p > max)
2763 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid CPU scheduling priority: %i", p);
2764
2765 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2766 c->cpu_sched_priority = p;
2767 c->cpu_sched_set = true;
2768
2769 unit_write_settingf(u, flags, name, "CPUSchedulingPriority=%i", p);
2770 }
2771
2772 return 1;
2773
7f452159
LP
2774 } else if (streq(name, "IOSchedulingClass")) {
2775 int32_t q;
2776
2777 r = sd_bus_message_read(message, "i", &q);
2778 if (r < 0)
2779 return r;
2780
2781 if (!ioprio_class_is_valid(q))
2782 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid IO scheduling class: %i", q);
2783
2e59b241 2784 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
7f452159
LP
2785 _cleanup_free_ char *s = NULL;
2786
2787 r = ioprio_class_to_string_alloc(q, &s);
2788 if (r < 0)
2789 return r;
2790
ba7772fe 2791 c->ioprio = ioprio_normalize(ioprio_prio_value(q, ioprio_prio_data(c->ioprio)));
7f452159
LP
2792 c->ioprio_set = true;
2793
2e59b241 2794 unit_write_settingf(u, flags, name, "IOSchedulingClass=%s", s);
7f452159
LP
2795 }
2796
2797 return 1;
2798
2799 } else if (streq(name, "IOSchedulingPriority")) {
2800 int32_t p;
2801
2802 r = sd_bus_message_read(message, "i", &p);
2803 if (r < 0)
2804 return r;
2805
2806 if (!ioprio_priority_is_valid(p))
2807 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid IO scheduling priority: %i", p);
2808
2e59b241 2809 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
ba7772fe 2810 c->ioprio = ioprio_normalize(ioprio_prio_value(ioprio_prio_class(c->ioprio), p));
7f452159
LP
2811 c->ioprio_set = true;
2812
2e59b241 2813 unit_write_settingf(u, flags, name, "IOSchedulingPriority=%i", p);
7f452159
LP
2814 }
2815
2816 return 1;
2817
5e98086d
ZJS
2818 } else if (streq(name, "MountAPIVFS")) {
2819 bool b;
2820
2821 r = bus_set_transient_bool(u, name, &b, message, flags, error);
2822 if (r < 0)
2823 return r;
2824
2825 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2826 c->mount_apivfs = b;
2827 c->mount_apivfs_set = true;
2828 }
2829
2830 return 1;
2831
5f5d8eab
LP
2832 } else if (streq(name, "WorkingDirectory")) {
2833 const char *s;
2834 bool missing_ok;
2835
2836 r = sd_bus_message_read(message, "s", &s);
2837 if (r < 0)
2838 return r;
2839
2840 if (s[0] == '-') {
2841 missing_ok = true;
2842 s++;
2843 } else
2844 missing_ok = false;
2845
d6ff82d3 2846 if (!isempty(s) && !streq(s, "~") && !path_is_absolute(s))
1b09b81c 2847 return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "WorkingDirectory= expects an absolute path or '~'");
5f5d8eab 2848
2e59b241 2849 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
5f5d8eab
LP
2850 if (streq(s, "~")) {
2851 c->working_directory = mfree(c->working_directory);
2852 c->working_directory_home = true;
2853 } else {
d6ff82d3 2854 r = free_and_strdup(&c->working_directory, empty_to_null(s));
5f5d8eab
LP
2855 if (r < 0)
2856 return r;
2857
2858 c->working_directory_home = false;
2859 }
2860
2861 c->working_directory_missing_ok = missing_ok;
2e59b241 2862 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "WorkingDirectory=%s%s", missing_ok ? "-" : "", s);
5f5d8eab
LP
2863 }
2864
2865 return 1;
2866
52c239d7
LB
2867 } else if (STR_IN_SET(name,
2868 "StandardInputFileDescriptorName", "StandardOutputFileDescriptorName", "StandardErrorFileDescriptorName")) {
2869 const char *s;
2870
2871 r = sd_bus_message_read(message, "s", &s);
2872 if (r < 0)
2873 return r;
2874
d6ff82d3 2875 if (!isempty(s) && !fdname_is_valid(s))
1b09b81c 2876 return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid file descriptor name");
52c239d7 2877
2e59b241 2878 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
5073ff6b 2879
52c239d7 2880 if (streq(name, "StandardInputFileDescriptorName")) {
d6ff82d3 2881 r = free_and_strdup(c->stdio_fdname + STDIN_FILENO, empty_to_null(s));
52c239d7
LB
2882 if (r < 0)
2883 return r;
5073ff6b 2884
0664775c 2885 c->std_input = EXEC_INPUT_NAMED_FD;
2e59b241 2886 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardInput=fd:%s", exec_context_fdname(c, STDIN_FILENO));
5073ff6b 2887
52c239d7 2888 } else if (streq(name, "StandardOutputFileDescriptorName")) {
d6ff82d3 2889 r = free_and_strdup(c->stdio_fdname + STDOUT_FILENO, empty_to_null(s));
52c239d7
LB
2890 if (r < 0)
2891 return r;
5073ff6b 2892
52c239d7 2893 c->std_output = EXEC_OUTPUT_NAMED_FD;
2e59b241 2894 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardOutput=fd:%s", exec_context_fdname(c, STDOUT_FILENO));
0664775c
LP
2895
2896 } else {
2897 assert(streq(name, "StandardErrorFileDescriptorName"));
5073ff6b 2898
d6ff82d3 2899 r = free_and_strdup(&c->stdio_fdname[STDERR_FILENO], empty_to_null(s));
52c239d7
LB
2900 if (r < 0)
2901 return r;
5073ff6b 2902
52c239d7 2903 c->std_error = EXEC_OUTPUT_NAMED_FD;
2e59b241 2904 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardError=fd:%s", exec_context_fdname(c, STDERR_FILENO));
52c239d7
LB
2905 }
2906 }
2907
2908 return 1;
2909
566b7d23
ZD
2910 } else if (STR_IN_SET(name,
2911 "StandardInputFile",
8d7dab1f
LW
2912 "StandardOutputFile", "StandardOutputFileToAppend", "StandardOutputFileToTruncate",
2913 "StandardErrorFile", "StandardErrorFileToAppend", "StandardErrorFileToTruncate")) {
2038c3f5
LP
2914 const char *s;
2915
2916 r = sd_bus_message_read(message, "s", &s);
2917 if (r < 0)
2918 return r;
2919
d6ff82d3
YW
2920 if (!isempty(s)) {
2921 if (!path_is_absolute(s))
2922 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path %s is not absolute", s);
2923 if (!path_is_normalized(s))
2924 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path %s is not normalized", s);
2925 }
2038c3f5 2926
2e59b241 2927 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2038c3f5
LP
2928
2929 if (streq(name, "StandardInputFile")) {
d6ff82d3 2930 r = free_and_strdup(&c->stdio_file[STDIN_FILENO], empty_to_null(s));
52c239d7
LB
2931 if (r < 0)
2932 return r;
2038c3f5
LP
2933
2934 c->std_input = EXEC_INPUT_FILE;
2e59b241 2935 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardInput=file:%s", s);
2038c3f5 2936
8d7dab1f 2937 } else if (STR_IN_SET(name, "StandardOutputFile", "StandardOutputFileToAppend", "StandardOutputFileToTruncate")) {
d6ff82d3 2938 r = free_and_strdup(&c->stdio_file[STDOUT_FILENO], empty_to_null(s));
2038c3f5
LP
2939 if (r < 0)
2940 return r;
2941
566b7d23
ZD
2942 if (streq(name, "StandardOutputFile")) {
2943 c->std_output = EXEC_OUTPUT_FILE;
2944 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardOutput=file:%s", s);
8d7dab1f 2945 } else if (streq(name, "StandardOutputFileToAppend")) {
566b7d23
ZD
2946 c->std_output = EXEC_OUTPUT_FILE_APPEND;
2947 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardOutput=append:%s", s);
8d7dab1f
LW
2948 } else {
2949 assert(streq(name, "StandardOutputFileToTruncate"));
2950 c->std_output = EXEC_OUTPUT_FILE_TRUNCATE;
2951 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardOutput=truncate:%s", s);
566b7d23 2952 }
2038c3f5 2953 } else {
8d7dab1f 2954 assert(STR_IN_SET(name, "StandardErrorFile", "StandardErrorFileToAppend", "StandardErrorFileToTruncate"));
2038c3f5 2955
d6ff82d3 2956 r = free_and_strdup(&c->stdio_file[STDERR_FILENO], empty_to_null(s));
2038c3f5
LP
2957 if (r < 0)
2958 return r;
2959
566b7d23
ZD
2960 if (streq(name, "StandardErrorFile")) {
2961 c->std_error = EXEC_OUTPUT_FILE;
1704fba9 2962 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardError=file:%s", s);
8d7dab1f 2963 } else if (streq(name, "StandardErrorFileToAppend")) {
dbe6c4b6 2964 c->std_error = EXEC_OUTPUT_FILE_APPEND;
1704fba9 2965 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardError=append:%s", s);
8d7dab1f
LW
2966 } else {
2967 assert(streq(name, "StandardErrorFileToTruncate"));
2968 c->std_error = EXEC_OUTPUT_FILE_TRUNCATE;
2969 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardError=truncate:%s", s);
566b7d23 2970 }
2038c3f5
LP
2971 }
2972 }
2973
2974 return 1;
2975
08f3be7a
LP
2976 } else if (streq(name, "StandardInputData")) {
2977 const void *p;
2978 size_t sz;
2979
2980 r = sd_bus_message_read_array(message, 'y', &p, &sz);
2981 if (r < 0)
2982 return r;
2983
2e59b241 2984 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
08f3be7a
LP
2985 _cleanup_free_ char *encoded = NULL;
2986
2987 if (sz == 0) {
2988 c->stdin_data = mfree(c->stdin_data);
2989 c->stdin_data_size = 0;
2990
2e59b241 2991 unit_write_settingf(u, flags, name, "StandardInputData=");
08f3be7a
LP
2992 } else {
2993 void *q;
2994 ssize_t n;
2995
2996 if (c->stdin_data_size + sz < c->stdin_data_size || /* check for overflow */
2997 c->stdin_data_size + sz > EXEC_STDIN_DATA_MAX)
2998 return -E2BIG;
2999
3000 n = base64mem(p, sz, &encoded);
3001 if (n < 0)
3002 return (int) n;
3003
3004 q = realloc(c->stdin_data, c->stdin_data_size + sz);
3005 if (!q)
3006 return -ENOMEM;
3007
3008 memcpy((uint8_t*) q + c->stdin_data_size, p, sz);
3009
3010 c->stdin_data = q;
3011 c->stdin_data_size += sz;
3012
2e59b241 3013 unit_write_settingf(u, flags, name, "StandardInputData=%s", encoded);
52c239d7
LB
3014 }
3015 }
3016
3017 return 1;
3018
c7040b5d
LP
3019 } else if (streq(name, "Environment")) {
3020
6171b822 3021 _cleanup_strv_free_ char **l = NULL;
c7040b5d
LP
3022
3023 r = sd_bus_message_read_strv(message, &l);
3024 if (r < 0)
3025 return r;
3026
6171b822 3027 if (!strv_env_is_valid(l))
1b09b81c 3028 return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid environment block.");
1c68232e 3029
2e59b241 3030 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
7b943bb7 3031 if (strv_isempty(l)) {
e9876fc9 3032 c->environment = strv_free(c->environment);
2e59b241 3033 unit_write_setting(u, flags, name, "Environment=");
e9876fc9 3034 } else {
f900f582
ZJS
3035 _cleanup_free_ char *joined = NULL;
3036 char **e;
3037
2e59b241
LP
3038 joined = unit_concat_strv(l, UNIT_ESCAPE_SPECIFIERS|UNIT_ESCAPE_C);
3039 if (!joined)
3040 return -ENOMEM;
3041
4ab3d29f 3042 e = strv_env_merge(c->environment, l);
e9876fc9
EV
3043 if (!e)
3044 return -ENOMEM;
c7040b5d 3045
130d3d22 3046 strv_free_and_replace(c->environment, e);
2e59b241 3047 unit_write_settingf(u, flags, name, "Environment=%s", joined);
e9876fc9 3048 }
c7040b5d
LP
3049 }
3050
d584f638
LP
3051 return 1;
3052
00819cc1
LP
3053 } else if (streq(name, "UnsetEnvironment")) {
3054
6171b822 3055 _cleanup_strv_free_ char **l = NULL;
00819cc1
LP
3056
3057 r = sd_bus_message_read_strv(message, &l);
3058 if (r < 0)
3059 return r;
3060
6171b822 3061 if (!strv_env_name_or_assignment_is_valid(l))
1b09b81c 3062 return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid UnsetEnvironment= list.");
00819cc1 3063
2e59b241 3064 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
7b943bb7 3065 if (strv_isempty(l)) {
00819cc1 3066 c->unset_environment = strv_free(c->unset_environment);
2e59b241 3067 unit_write_setting(u, flags, name, "UnsetEnvironment=");
00819cc1
LP
3068 } else {
3069 _cleanup_free_ char *joined = NULL;
3070 char **e;
3071
2e59b241
LP
3072 joined = unit_concat_strv(l, UNIT_ESCAPE_SPECIFIERS|UNIT_ESCAPE_C);
3073 if (!joined)
3074 return -ENOMEM;
3075
4ab3d29f 3076 e = strv_env_merge(c->unset_environment, l);
00819cc1
LP
3077 if (!e)
3078 return -ENOMEM;
3079
130d3d22 3080 strv_free_and_replace(c->unset_environment, e);
2e59b241 3081 unit_write_settingf(u, flags, name, "UnsetEnvironment=%s", joined);
00819cc1
LP
3082 }
3083 }
3084
3085 return 1;
3086
6b862936
EV
3087 } else if (streq(name, "OOMScoreAdjust")) {
3088 int oa;
3089
3090 r = sd_bus_message_read(message, "i", &oa);
3091 if (r < 0)
3092 return r;
3093
3094 if (!oom_score_adjust_is_valid(oa))
1b09b81c 3095 return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "OOM score adjust value out of range");
6b862936 3096
2e59b241 3097 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
6b862936
EV
3098 c->oom_score_adjust = oa;
3099 c->oom_score_adjust_set = true;
2e59b241 3100 unit_write_settingf(u, flags, name, "OOMScoreAdjust=%i", oa);
6b862936
EV
3101 }
3102
3103 return 1;
3104
ad21e542
ZJS
3105 } else if (streq(name, "CoredumpFilter")) {
3106 uint64_t f;
3107
3108 r = sd_bus_message_read(message, "t", &f);
3109 if (r < 0)
3110 return r;
3111
3112 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
3113 c->coredump_filter = f;
3114 c->coredump_filter_set = true;
3115 unit_write_settingf(u, flags, name, "CoredumpFilter=0x%"PRIx64, f);
3116 }
3117
3118 return 1;
3119
ceb728cf
NC
3120 } else if (streq(name, "EnvironmentFiles")) {
3121
3122 _cleanup_free_ char *joined = NULL;
3123 _cleanup_fclose_ FILE *f = NULL;
9b531f04 3124 _cleanup_strv_free_ char **l = NULL;
ceb728cf 3125 size_t size = 0;
ceb728cf
NC
3126
3127 r = sd_bus_message_enter_container(message, 'a', "(sb)");
3128 if (r < 0)
3129 return r;
3130
2fe21124 3131 f = open_memstream_unlocked(&joined, &size);
ceb728cf
NC
3132 if (!f)
3133 return -ENOMEM;
3134
2e59b241
LP
3135 fputs("EnvironmentFile=\n", f);
3136
3137 STRV_FOREACH(i, c->environment_files) {
3138 _cleanup_free_ char *q = NULL;
3139
3140 q = specifier_escape(*i);
3141 if (!q)
3142 return -ENOMEM;
3143
3144 fprintf(f, "EnvironmentFile=%s\n", q);
3145 }
ceb728cf
NC
3146
3147 while ((r = sd_bus_message_enter_container(message, 'r', "sb")) > 0) {
3148 const char *path;
3149 int b;
3150
ceb728cf
NC
3151 r = sd_bus_message_read(message, "sb", &path, &b);
3152 if (r < 0)
3153 return r;
3154
3155 r = sd_bus_message_exit_container(message);
3156 if (r < 0)
3157 return r;
3158
d2d6c096
LP
3159 if (!path_is_absolute(path))
3160 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path %s is not absolute.", path);
ceb728cf 3161
2e59b241 3162 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
6abdec98 3163 _cleanup_free_ char *q = NULL, *buf = NULL;
ceb728cf 3164
605405c6 3165 buf = strjoin(b ? "-" : "", path);
2229f656 3166 if (!buf)
ceb728cf
NC
3167 return -ENOMEM;
3168
2e59b241 3169 q = specifier_escape(buf);
6abdec98 3170 if (!q)
2e59b241 3171 return -ENOMEM;
2e59b241
LP
3172
3173 fprintf(f, "EnvironmentFile=%s\n", q);
ceb728cf 3174
6abdec98 3175 r = strv_consume(&l, TAKE_PTR(buf));
ceb728cf
NC
3176 if (r < 0)
3177 return r;
3178 }
3179 }
3180 if (r < 0)
3181 return r;
3182
b0830e21
LP
3183 r = sd_bus_message_exit_container(message);
3184 if (r < 0)
3185 return r;
3186
2229f656
LP
3187 r = fflush_and_check(f);
3188 if (r < 0)
3189 return r;
ceb728cf 3190
2e59b241 3191 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2229f656
LP
3192 if (strv_isempty(l)) {
3193 c->environment_files = strv_free(c->environment_files);
2e59b241 3194 unit_write_setting(u, flags, name, "EnvironmentFile=");
2229f656
LP
3195 } else {
3196 r = strv_extend_strv(&c->environment_files, l, true);
3197 if (r < 0)
3198 return r;
3199
2e59b241 3200 unit_write_setting(u, flags, name, joined);
2229f656
LP
3201 }
3202 }
ceb728cf 3203
ceb728cf
NC
3204 return 1;
3205
b4c14404
FB
3206 } else if (streq(name, "PassEnvironment")) {
3207
6171b822 3208 _cleanup_strv_free_ char **l = NULL;
b4c14404
FB
3209
3210 r = sd_bus_message_read_strv(message, &l);
3211 if (r < 0)
3212 return r;
3213
6171b822 3214 if (!strv_env_name_is_valid(l))
1b09b81c 3215 return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid PassEnvironment= block.");
b4c14404 3216
2e59b241 3217 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
b4c14404
FB
3218 if (strv_isempty(l)) {
3219 c->pass_environment = strv_free(c->pass_environment);
2e59b241 3220 unit_write_setting(u, flags, name, "PassEnvironment=");
b4c14404
FB
3221 } else {
3222 _cleanup_free_ char *joined = NULL;
3223
9d4f242a
YW
3224 r = strv_extend_strv(&c->pass_environment, l, true);
3225 if (r < 0)
3226 return r;
3227
41de9cc2 3228 /* We write just the new settings out to file, with unresolved specifiers. */
2e59b241 3229 joined = unit_concat_strv(l, UNIT_ESCAPE_SPECIFIERS);
b4c14404
FB
3230 if (!joined)
3231 return -ENOMEM;
3232
2e59b241 3233 unit_write_settingf(u, flags, name, "PassEnvironment=%s", joined);
b4c14404
FB
3234 }
3235 }
3236
3237 return 1;
3238
2a624c36 3239 } else if (STR_IN_SET(name, "ReadWriteDirectories", "ReadOnlyDirectories", "InaccessibleDirectories",
a07b9926
LB
3240 "ReadWritePaths", "ReadOnlyPaths", "InaccessiblePaths", "ExecPaths", "NoExecPaths",
3241 "ExtensionDirectories")) {
08596068
EV
3242 _cleanup_strv_free_ char **l = NULL;
3243 char ***dirs;
08596068
EV
3244
3245 r = sd_bus_message_read_strv(message, &l);
3246 if (r < 0)
3247 return r;
3248
3249 STRV_FOREACH(p, l) {
e7bcff4e 3250 char *i = *p;
20b7a007
LP
3251 size_t offset;
3252
20b7a007
LP
3253 offset = i[0] == '-';
3254 offset += i[offset] == '+';
3255 if (!path_is_absolute(i + offset))
08596068 3256 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid %s", name);
e7bcff4e 3257
4ff361cc 3258 path_simplify(i + offset);
08596068
EV
3259 }
3260
2e59b241 3261 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
c4b41707
AP
3262 if (STR_IN_SET(name, "ReadWriteDirectories", "ReadWritePaths"))
3263 dirs = &c->read_write_paths;
3264 else if (STR_IN_SET(name, "ReadOnlyDirectories", "ReadOnlyPaths"))
3265 dirs = &c->read_only_paths;
ddc155b2
TM
3266 else if (streq(name, "ExecPaths"))
3267 dirs = &c->exec_paths;
3268 else if (streq(name, "NoExecPaths"))
3269 dirs = &c->no_exec_paths;
a07b9926
LB
3270 else if (streq(name, "ExtensionDirectories"))
3271 dirs = &c->extension_directories;
c4b41707
AP
3272 else /* "InaccessiblePaths" */
3273 dirs = &c->inaccessible_paths;
08596068 3274
7b943bb7 3275 if (strv_isempty(l)) {
08596068 3276 *dirs = strv_free(*dirs);
2e59b241 3277 unit_write_settingf(u, flags, name, "%s=", name);
08596068 3278 } else {
2e59b241 3279 _cleanup_free_ char *joined = NULL;
08596068 3280
2e59b241 3281 joined = unit_concat_strv(l, UNIT_ESCAPE_SPECIFIERS);
08596068
EV
3282 if (!joined)
3283 return -ENOMEM;
3284
2e59b241
LP
3285 r = strv_extend_strv(dirs, l, true);
3286 if (r < 0)
3287 return -ENOMEM;
08596068 3288
2e59b241
LP
3289 unit_write_settingf(u, flags, name, "%s=%s", name, joined);
3290 }
08596068
EV
3291 }
3292
3293 return 1;
3294
8c35c10d 3295 } else if (streq(name, "ExecSearchPath")) {
3296 _cleanup_strv_free_ char **l = NULL;
8c35c10d 3297
3298 r = sd_bus_message_read_strv(message, &l);
3299 if (r < 0)
3300 return r;
3301
de010b0b 3302 STRV_FOREACH(p, l)
8c35c10d 3303 if (!path_is_absolute(*p) || !path_is_normalized(*p) || strchr(*p, ':'))
3304 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid %s", name);
de010b0b 3305
8c35c10d 3306 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
3307 if (strv_isempty(l)) {
3308 c->exec_search_path = strv_free(c->exec_search_path);
3309 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "ExecSearchPath=");
3310 } else {
3311 _cleanup_free_ char *joined = NULL;
3312 r = strv_extend_strv(&c->exec_search_path, l, true);
3313 if (r < 0)
3314 return -ENOMEM;
3315 joined = strv_join(c->exec_search_path, ":");
3316 if (!joined)
3317 return log_oom();
3318 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "ExecSearchPath=%s", joined);
3319 }
3320 }
3321
3322 return 1;
3323
3536f49e 3324 } else if (STR_IN_SET(name, "RuntimeDirectory", "StateDirectory", "CacheDirectory", "LogsDirectory", "ConfigurationDirectory")) {
fa21b5e3 3325 _cleanup_strv_free_ char **l = NULL;
fa21b5e3
EV
3326
3327 r = sd_bus_message_read_strv(message, &l);
3328 if (r < 0)
3329 return r;
3330
3331 STRV_FOREACH(p, l) {
8994a117
YW
3332 if (!path_is_normalized(*p))
3333 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "%s= path is not normalized: %s", name, *p);
3334
3335 if (path_is_absolute(*p))
3336 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "%s= path is absolute: %s", name, *p);
3337
3338 if (path_startswith(*p, "private"))
3339 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "%s= path can't be 'private': %s", name, *p);
fa21b5e3
EV
3340 }
3341
2e59b241 3342 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
3536f49e 3343 ExecDirectoryType i;
b1ea85dc 3344 ExecDirectory *d;
3536f49e 3345
b1ea85dc
LP
3346 assert_se((i = exec_directory_type_from_string(name)) >= 0);
3347 d = c->directories + i;
fa21b5e3
EV
3348
3349 if (strv_isempty(l)) {
211a3d87 3350 exec_directory_done(d);
2e59b241 3351 unit_write_settingf(u, flags, name, "%s=", name);
fa21b5e3 3352 } else {
2e59b241
LP
3353 _cleanup_free_ char *joined = NULL;
3354
211a3d87
LB
3355 STRV_FOREACH(source, l) {
3356 r = exec_directory_add(&d->items, &d->n_items, *source, NULL);
3357 if (r < 0)
3358 return log_oom();
3359 }
fa21b5e3 3360
2e59b241 3361 joined = unit_concat_strv(l, UNIT_ESCAPE_SPECIFIERS);
fa21b5e3
EV
3362 if (!joined)
3363 return -ENOMEM;
3364
2e59b241 3365 unit_write_settingf(u, flags, name, "%s=%s", name, joined);
fa21b5e3
EV
3366 }
3367 }
3368
3369 return 1;
3370
cffaed83
YW
3371 } else if (STR_IN_SET(name, "AppArmorProfile", "SmackProcessLabel")) {
3372 int ignore;
3373 const char *s;
3374
280921f2 3375 r = sd_bus_message_read(message, "(bs)", &ignore, &s);
cffaed83
YW
3376 if (r < 0)
3377 return r;
3378
2e59b241 3379 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
cffaed83
YW
3380 char **p;
3381 bool *b;
3382
3383 if (streq(name, "AppArmorProfile")) {
3384 p = &c->apparmor_profile;
3385 b = &c->apparmor_profile_ignore;
3386 } else { /* "SmackProcessLabel" */
3387 p = &c->smack_process_label;
3388 b = &c->smack_process_label_ignore;
3389 }
3390
3391 if (isempty(s)) {
3392 *p = mfree(*p);
3393 *b = false;
3394 } else {
3395 if (free_and_strdup(p, s) < 0)
3396 return -ENOMEM;
3397 *b = ignore;
3398 }
3399
2e59b241 3400 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "%s=%s%s", name, ignore ? "-" : "", strempty(s));
cffaed83
YW
3401 }
3402
3403 return 1;
3404
d2d6c096 3405 } else if (STR_IN_SET(name, "BindPaths", "BindReadOnlyPaths")) {
ec04aef4 3406 char *source, *destination;
4ff4c98a
YW
3407 int ignore_enoent;
3408 uint64_t mount_flags;
3409 bool empty = true;
d2d6c096
LP
3410
3411 r = sd_bus_message_enter_container(message, 'a', "(ssbt)");
3412 if (r < 0)
3413 return r;
3414
4ff4c98a 3415 while ((r = sd_bus_message_read(message, "(ssbt)", &source, &destination, &ignore_enoent, &mount_flags)) > 0) {
d2d6c096
LP
3416
3417 if (!path_is_absolute(source))
3418 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Source path %s is not absolute.", source);
3419 if (!path_is_absolute(destination))
91d910e3 3420 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Destination path %s is not absolute.", destination);
d2d6c096 3421 if (!IN_SET(mount_flags, 0, MS_REC))
1b09b81c 3422 return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Unknown mount flags.");
d2d6c096 3423
2e59b241 3424 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
d2d6c096
LP
3425 r = bind_mount_add(&c->bind_mounts, &c->n_bind_mounts,
3426 &(BindMount) {
ec04aef4
TM
3427 .source = source,
3428 .destination = destination,
d2d6c096
LP
3429 .read_only = !!strstr(name, "ReadOnly"),
3430 .recursive = !!(mount_flags & MS_REC),
3431 .ignore_enoent = ignore_enoent,
3432 });
3433 if (r < 0)
3434 return r;
3435
2e59b241
LP
3436 unit_write_settingf(
3437 u, flags|UNIT_ESCAPE_SPECIFIERS, name,
d2d6c096
LP
3438 "%s=%s%s:%s:%s",
3439 name,
3440 ignore_enoent ? "-" : "",
3441 source,
3442 destination,
3443 (mount_flags & MS_REC) ? "rbind" : "norbind");
3444 }
3445
3446 empty = false;
3447 }
3448 if (r < 0)
3449 return r;
3450
3451 r = sd_bus_message_exit_container(message);
3452 if (r < 0)
3453 return r;
3454
3455 if (empty) {
3456 bind_mount_free_many(c->bind_mounts, c->n_bind_mounts);
3457 c->bind_mounts = NULL;
3458 c->n_bind_mounts = 0;
2e59b241
LP
3459
3460 unit_write_settingf(u, flags, name, "%s=", name);
d2d6c096
LP
3461 }
3462
784ad252
YW
3463 return 1;
3464
3465 } else if (streq(name, "TemporaryFileSystem")) {
3466 const char *path, *options;
3467 bool empty = true;
3468
3469 r = sd_bus_message_enter_container(message, 'a', "(ss)");
3470 if (r < 0)
3471 return r;
3472
3473 while ((r = sd_bus_message_read(message, "(ss)", &path, &options)) > 0) {
3474
3475 if (!path_is_absolute(path))
3476 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Mount point %s is not absolute.", path);
3477
3478 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
3479 r = temporary_filesystem_add(&c->temporary_filesystems, &c->n_temporary_filesystems, path, options);
3480 if (r < 0)
3481 return r;
3482
3483 unit_write_settingf(
3484 u, flags|UNIT_ESCAPE_SPECIFIERS, name,
3485 "%s=%s:%s",
3486 name,
3487 path,
3488 options);
3489 }
3490
3491 empty = false;
3492 }
3493 if (r < 0)
3494 return r;
3495
3496 r = sd_bus_message_exit_container(message);
3497 if (r < 0)
3498 return r;
3499
3500 if (empty) {
3501 temporary_filesystem_free_many(c->temporary_filesystems, c->n_temporary_filesystems);
3502 c->temporary_filesystems = NULL;
3503 c->n_temporary_filesystems = 0;
3504
3505 unit_write_settingf(u, flags, name, "%s=", name);
3506 }
3507
83555251 3508 return 1;
d2d6c096 3509
6550c24c
LP
3510 } else if ((suffix = startswith(name, "Limit"))) {
3511 const char *soft = NULL;
3512 int ri;
cab2aca3 3513
6550c24c
LP
3514 ri = rlimit_from_string(suffix);
3515 if (ri < 0) {
3516 soft = endswith(suffix, "Soft");
3517 if (soft) {
3518 const char *n;
cab2aca3 3519
2f82562b 3520 n = strndupa_safe(suffix, soft - suffix);
6550c24c
LP
3521 ri = rlimit_from_string(n);
3522 if (ri >= 0)
3523 name = strjoina("Limit", n);
3524 }
cab2aca3 3525 }
d584f638 3526
6550c24c
LP
3527 if (ri >= 0) {
3528 uint64_t rl;
3529 rlim_t x;
d584f638 3530
6550c24c 3531 r = sd_bus_message_read(message, "t", &rl);
cab2aca3
LP
3532 if (r < 0)
3533 return r;
d584f638 3534
f5fbe71d 3535 if (rl == UINT64_MAX)
6550c24c 3536 x = RLIM_INFINITY;
cab2aca3 3537 else {
6550c24c
LP
3538 x = (rlim_t) rl;
3539
3540 if ((uint64_t) x != rl)
3541 return -ERANGE;
d584f638
LP
3542 }
3543
6550c24c
LP
3544 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
3545 _cleanup_free_ char *f = NULL;
3546 struct rlimit nl;
3547
3548 if (c->rlimit[ri]) {
3549 nl = *c->rlimit[ri];
3550
3551 if (soft)
3552 nl.rlim_cur = x;
3553 else
3554 nl.rlim_max = x;
3555 } else
3556 /* When the resource limit is not initialized yet, then assign the value to both fields */
3557 nl = (struct rlimit) {
3558 .rlim_cur = x,
3559 .rlim_max = x,
3560 };
3561
3562 r = rlimit_format(&nl, &f);
3563 if (r < 0)
3564 return r;
3565
3566 if (c->rlimit[ri])
3567 *c->rlimit[ri] = nl;
3568 else {
3569 c->rlimit[ri] = newdup(struct rlimit, &nl, 1);
3570 if (!c->rlimit[ri])
3571 return -ENOMEM;
3572 }
3573
3574 unit_write_settingf(u, flags, name, "%s=%s", name, f);
3575 }
3576
3577 return 1;
d584f638
LP
3578 }
3579
b3d13314
LB
3580 } else if (streq(name, "MountImages")) {
3581 _cleanup_free_ char *format_str = NULL;
3582 MountImage *mount_images = NULL;
3583 size_t n_mount_images = 0;
3584 char *source, *destination;
3585 int permissive;
3586
427353f6 3587 r = sd_bus_message_enter_container(message, 'a', "(ssba(ss))");
b3d13314
LB
3588 if (r < 0)
3589 return r;
3590
427353f6
LB
3591 for (;;) {
3592 _cleanup_(mount_options_free_allp) MountOptions *options = NULL;
3593 _cleanup_free_ char *source_escaped = NULL, *destination_escaped = NULL;
b3d13314
LB
3594 char *tuple;
3595
427353f6
LB
3596 r = sd_bus_message_enter_container(message, 'r', "ssba(ss)");
3597 if (r < 0)
3598 return r;
3599
3600 r = sd_bus_message_read(message, "ssb", &source, &destination, &permissive);
3601 if (r <= 0)
3602 break;
3603
b3d13314
LB
3604 if (!path_is_absolute(source))
3605 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Source path %s is not absolute.", source);
3606 if (!path_is_normalized(source))
3607 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Source path %s is not normalized.", source);
3608 if (!path_is_absolute(destination))
3609 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Destination path %s is not absolute.", destination);
3610 if (!path_is_normalized(destination))
3611 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Destination path %s is not normalized.", destination);
3612
427353f6
LB
3613 /* Need to store them in the unit with the escapes, so that they can be parsed again */
3614 source_escaped = shell_escape(source, ":");
3615 if (!source_escaped)
3616 return -ENOMEM;
3617 destination_escaped = shell_escape(destination, ":");
3618 if (!destination_escaped)
3619 return -ENOMEM;
3620
3621 tuple = strjoin(format_str,
3622 format_str ? " " : "",
3623 permissive ? "-" : "",
3624 source_escaped,
3625 ":",
3626 destination_escaped);
b3d13314
LB
3627 if (!tuple)
3628 return -ENOMEM;
3629 free_and_replace(format_str, tuple);
3630
988172ce 3631 r = bus_read_mount_options(message, error, &options, &format_str, ":");
427353f6
LB
3632 if (r < 0)
3633 return r;
3634
3635 r = sd_bus_message_exit_container(message);
3636 if (r < 0)
3637 return r;
3638
b3d13314
LB
3639 r = mount_image_add(&mount_images, &n_mount_images,
3640 &(MountImage) {
3641 .source = source,
3642 .destination = destination,
427353f6 3643 .mount_options = options,
b3d13314 3644 .ignore_enoent = permissive,
93f59701 3645 .type = MOUNT_IMAGE_DISCRETE,
b3d13314
LB
3646 });
3647 if (r < 0)
3648 return r;
3649 }
3650 if (r < 0)
3651 return r;
3652
3653 r = sd_bus_message_exit_container(message);
3654 if (r < 0)
3655 return r;
3656
3657 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
3658 if (n_mount_images == 0) {
3659 c->mount_images = mount_image_free_many(c->mount_images, &c->n_mount_images);
3660
3661 unit_write_settingf(u, flags, name, "%s=", name);
3662 } else {
3663 for (size_t i = 0; i < n_mount_images; ++i) {
3664 r = mount_image_add(&c->mount_images, &c->n_mount_images, &mount_images[i]);
3665 if (r < 0)
3666 return r;
3667 }
3668
3669 unit_write_settingf(u, flags|UNIT_ESCAPE_C|UNIT_ESCAPE_SPECIFIERS,
3670 name,
3671 "%s=%s",
3672 name,
3673 format_str);
3674 }
3675 }
3676
3677 mount_images = mount_image_free_many(mount_images, &n_mount_images);
3678
93f59701
LB
3679 return 1;
3680 } else if (streq(name, "ExtensionImages")) {
3681 _cleanup_free_ char *format_str = NULL;
3682 MountImage *extension_images = NULL;
3683 size_t n_extension_images = 0;
3684
3685 r = sd_bus_message_enter_container(message, 'a', "(sba(ss))");
3686 if (r < 0)
3687 return r;
3688
3689 for (;;) {
3690 _cleanup_(mount_options_free_allp) MountOptions *options = NULL;
3691 _cleanup_free_ char *source_escaped = NULL;
3692 char *source, *tuple;
3693 int permissive;
3694
3695 r = sd_bus_message_enter_container(message, 'r', "sba(ss)");
3696 if (r < 0)
3697 return r;
3698
3699 r = sd_bus_message_read(message, "sb", &source, &permissive);
3700 if (r <= 0)
3701 break;
3702
3703 if (!path_is_absolute(source))
3704 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Source path %s is not absolute.", source);
3705 if (!path_is_normalized(source))
3706 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Source path %s is not normalized.", source);
3707
3708 /* Need to store them in the unit with the escapes, so that they can be parsed again */
3709 source_escaped = shell_escape(source, ":");
3710 if (!source_escaped)
3711 return -ENOMEM;
3712
3713 tuple = strjoin(format_str,
3714 format_str ? " " : "",
3715 permissive ? "-" : "",
3716 source_escaped);
3717 if (!tuple)
3718 return -ENOMEM;
3719 free_and_replace(format_str, tuple);
3720
3721 r = bus_read_mount_options(message, error, &options, &format_str, ":");
3722 if (r < 0)
3723 return r;
3724
3725 r = sd_bus_message_exit_container(message);
3726 if (r < 0)
3727 return r;
3728
3729 r = mount_image_add(&extension_images, &n_extension_images,
3730 &(MountImage) {
3731 .source = source,
3732 .mount_options = options,
3733 .ignore_enoent = permissive,
3734 .type = MOUNT_IMAGE_EXTENSION,
3735 });
3736 if (r < 0)
3737 return r;
3738 }
3739 if (r < 0)
3740 return r;
3741
3742 r = sd_bus_message_exit_container(message);
3743 if (r < 0)
3744 return r;
3745
3746 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
3747 if (n_extension_images == 0) {
3748 c->extension_images = mount_image_free_many(c->extension_images, &c->n_extension_images);
3749
3750 unit_write_settingf(u, flags, name, "%s=", name);
3751 } else {
3752 for (size_t i = 0; i < n_extension_images; ++i) {
3753 r = mount_image_add(&c->extension_images, &c->n_extension_images, &extension_images[i]);
3754 if (r < 0)
3755 return r;
3756 }
3757
3758 unit_write_settingf(u, flags|UNIT_ESCAPE_C|UNIT_ESCAPE_SPECIFIERS,
3759 name,
3760 "%s=%s",
3761 name,
3762 format_str);
3763 }
3764 }
3765
3766 extension_images = mount_image_free_many(extension_images, &n_extension_images);
3767
b3d13314 3768 return 1;
211a3d87
LB
3769
3770 } else if (STR_IN_SET(name, "StateDirectorySymlink", "RuntimeDirectorySymlink", "CacheDirectorySymlink", "LogsDirectorySymlink")) {
3771 char *source, *destination;
3772 ExecDirectory *directory;
3773 uint64_t symlink_flags; /* No flags for now, reserved for future uses. */
3774 ExecDirectoryType i;
3775
3776 assert_se((i = exec_directory_type_symlink_from_string(name)) >= 0);
3777 directory = c->directories + i;
3778
3779 r = sd_bus_message_enter_container(message, 'a', "(sst)");
3780 if (r < 0)
3781 return r;
3782
3783 while ((r = sd_bus_message_read(message, "(sst)", &source, &destination, &symlink_flags)) > 0) {
3784 if (!path_is_valid(source))
3785 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Source path %s is not valid.", source);
3786 if (path_is_absolute(source))
3787 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Source path %s is absolute.", source);
3788 if (!path_is_normalized(source))
3789 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Source path %s is not normalized.", source);
3790 if (!path_is_valid(destination))
3791 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Destination path %s is not valid.", destination);
3792 if (path_is_absolute(destination))
3793 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Destination path %s is absolute.", destination);
3794 if (!path_is_normalized(destination))
3795 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Destination path %s is not normalized.", destination);
3796 if (symlink_flags != 0)
3797 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Flags must be zero.");
3798
3799 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
3800 _cleanup_free_ char *destination_escaped = NULL, *source_escaped = NULL;
3801 ExecDirectoryItem *item = NULL;
3802
3803 /* Adding new directories is supported from both *DirectorySymlink methods and the
3804 * older ones, so try to find an existing configuration first and create it if it's
3805 * not there yet. */
3806 for (size_t j = 0; j < directory->n_items; ++j)
3807 if (path_equal(source, directory->items[j].path)) {
3808 item = &directory->items[j];
3809 break;
3810 }
3811
3812 if (item)
3813 r = strv_extend(&item->symlinks, destination);
3814 else
3815 r = exec_directory_add(&directory->items, &directory->n_items, source, STRV_MAKE(destination));
3816 if (r < 0)
3817 return r;
3818
3819 /* Need to store them in the unit with the escapes, so that they can be parsed again */
3820 source_escaped = xescape(source, ":");
3821 destination_escaped = xescape(destination, ":");
3822 if (!source_escaped || !destination_escaped)
3823 return -ENOMEM;
3824
3825 unit_write_settingf(
3826 u, flags|UNIT_ESCAPE_SPECIFIERS, exec_directory_type_to_string(i),
3827 "%s=%s:%s",
3828 exec_directory_type_to_string(i),
3829 source_escaped,
3830 destination_escaped);
3831 }
3832 }
3833 if (r < 0)
3834 return r;
3835
3836 r = sd_bus_message_exit_container(message);
3837 if (r < 0)
3838 return r;
3839
3840 return 1;
3841
c7040b5d
LP
3842 }
3843
3844 return 0;
3845}