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