]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/core/dbus-execute.c
service: add new RootImageOptions feature
[thirdparty/systemd.git] / src / core / dbus-execute.c
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
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"
3ffd4af2 16#include "dbus-execute.h"
7e2a3fcc 17#include "dbus-util.h"
c7040b5d 18#include "env-util.h"
cffaed83 19#include "errno-list.h"
2e59b241 20#include "escape.h"
3ffd4af2
LP
21#include "execute.h"
22#include "fd-util.h"
23#include "fileio.h"
08f3be7a 24#include "hexdecoct.h"
d3070fbd 25#include "io-util.h"
3ffd4af2 26#include "ioprio.h"
d3070fbd 27#include "journal-util.h"
049af8ad 28#include "mountpoint-util.h"
417116f2 29#include "namespace.h"
6bedfcbb 30#include "parse-util.h"
9b15b784 31#include "path-util.h"
7b3e062c 32#include "process-util.h"
78f22b97 33#include "rlimit-util.h"
349cc4a5 34#if HAVE_SECCOMP
57183d11
LP
35#include "seccomp-util.h"
36#endif
cffaed83 37#include "securebits-util.h"
2e59b241 38#include "specifier.h"
6bedfcbb 39#include "strv.h"
7ccbd1ae 40#include "syslog-util.h"
f900f582 41#include "unit-printf.h"
6f3e7985 42#include "user-util.h"
6bedfcbb 43#include "utf8.h"
57183d11 44
718db961 45BUS_DEFINE_PROPERTY_GET_ENUM(bus_property_get_exec_output, exec_output, ExecOutput);
718db961 46static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_input, exec_input, ExecInput);
023a4f67 47static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_utmp_mode, exec_utmp_mode, ExecUtmpMode);
53f47dfc 48static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_preserve_mode, exec_preserve_mode, ExecPreserveMode);
b1edf445 49static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_keyring_mode, exec_keyring_mode, ExecKeyringMode);
73b84e92
YW
50static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_protect_home, protect_home, ProtectHome);
51static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_protect_system, protect_system, ProtectSystem);
491eecb3 52static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_personality, personality, unsigned long);
019b34ca
YW
53static BUS_DEFINE_PROPERTY_GET(property_get_ioprio, "i", ExecContext, exec_context_get_effective_ioprio);
54static BUS_DEFINE_PROPERTY_GET2(property_get_ioprio_class, "i", ExecContext, exec_context_get_effective_ioprio, IOPRIO_PRIO_CLASS);
55static BUS_DEFINE_PROPERTY_GET2(property_get_ioprio_priority, "i", ExecContext, exec_context_get_effective_ioprio, IOPRIO_PRIO_DATA);
92c23c5a
YW
56static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_empty_string, "s", NULL);
57static BUS_DEFINE_PROPERTY_GET_REF(property_get_syslog_level, "i", int, LOG_PRI);
58static BUS_DEFINE_PROPERTY_GET_REF(property_get_syslog_facility, "i", int, LOG_FAC);
e2b2fb7f
MS
59static BUS_DEFINE_PROPERTY_GET(property_get_cpu_affinity_from_numa, "b", ExecContext, exec_context_get_cpu_affinity_from_numa);
60
718db961
LP
61static int property_get_environment_files(
62 sd_bus *bus,
63 const char *path,
64 const char *interface,
65 const char *property,
66 sd_bus_message *reply,
ebcf1f97
LP
67 void *userdata,
68 sd_bus_error *error) {
8c7be95e 69
718db961
LP
70 ExecContext *c = userdata;
71 char **j;
72 int r;
8c7be95e 73
718db961
LP
74 assert(bus);
75 assert(reply);
76 assert(c);
77
78 r = sd_bus_message_open_container(reply, 'a', "(sb)");
79 if (r < 0)
80 return r;
8c7be95e 81
718db961
LP
82 STRV_FOREACH(j, c->environment_files) {
83 const char *fn = *j;
8c7be95e 84
718db961
LP
85 r = sd_bus_message_append(reply, "(sb)", fn[0] == '-' ? fn + 1 : fn, fn[0] == '-');
86 if (r < 0)
87 return r;
8c7be95e
LP
88 }
89
718db961
LP
90 return sd_bus_message_close_container(reply);
91}
92
718db961
LP
93static int property_get_oom_score_adjust(
94 sd_bus *bus,
95 const char *path,
96 const char *interface,
97 const char *property,
98 sd_bus_message *reply,
ebcf1f97
LP
99 void *userdata,
100 sd_bus_error *error) {
718db961 101
718db961 102 ExecContext *c = userdata;
82c121a4 103 int32_t n;
b94fb74b 104 int r;
82c121a4 105
718db961
LP
106 assert(bus);
107 assert(reply);
82c121a4
LP
108 assert(c);
109
dd6c17b1
LP
110 if (c->oom_score_adjust_set)
111 n = c->oom_score_adjust;
82c121a4 112 else {
68eda4bd 113 _cleanup_free_ char *t = NULL;
82c121a4
LP
114
115 n = 0;
b94fb74b
ZJS
116 r = read_one_line_file("/proc/self/oom_score_adj", &t);
117 if (r < 0)
118 log_debug_errno(r, "Failed to read /proc/self/oom_score_adj, ignoring: %m");
119 else {
120 r = safe_atoi32(t, &n);
121 if (r < 0)
122 log_debug_errno(r, "Failed to parse \"%s\" from /proc/self/oom_score_adj, ignoring: %m", t);
123 }
82c121a4
LP
124 }
125
718db961 126 return sd_bus_message_append(reply, "i", n);
82c121a4
LP
127}
128
ad21e542
ZJS
129static int property_get_coredump_filter(
130 sd_bus *bus,
131 const char *path,
132 const char *interface,
133 const char *property,
134 sd_bus_message *reply,
135 void *userdata,
136 sd_bus_error *error) {
137
138 ExecContext *c = userdata;
139 uint64_t n;
140 int r;
141
142 assert(bus);
143 assert(reply);
144 assert(c);
145
146 if (c->coredump_filter_set)
147 n = c->coredump_filter;
148 else {
149 _cleanup_free_ char *t = NULL;
150
151 n = COREDUMP_FILTER_MASK_DEFAULT;
152 r = read_one_line_file("/proc/self/coredump_filter", &t);
153 if (r < 0)
154 log_debug_errno(r, "Failed to read /proc/self/coredump_filter, ignoring: %m");
155 else {
156 r = safe_atoux64(t, &n);
157 if (r < 0)
158 log_debug_errno(r, "Failed to parse \"%s\" from /proc/self/coredump_filter, ignoring: %m", t);
159 }
160 }
161
162 return sd_bus_message_append(reply, "t", n);
163}
164
718db961
LP
165static int property_get_nice(
166 sd_bus *bus,
167 const char *path,
168 const char *interface,
169 const char *property,
170 sd_bus_message *reply,
ebcf1f97
LP
171 void *userdata,
172 sd_bus_error *error) {
718db961 173
718db961 174 ExecContext *c = userdata;
82c121a4
LP
175 int32_t n;
176
718db961
LP
177 assert(bus);
178 assert(reply);
82c121a4
LP
179 assert(c);
180
181 if (c->nice_set)
182 n = c->nice;
718db961
LP
183 else {
184 errno = 0;
82c121a4 185 n = getpriority(PRIO_PROCESS, 0);
b3267152 186 if (errno > 0)
718db961
LP
187 n = 0;
188 }
82c121a4 189
718db961 190 return sd_bus_message_append(reply, "i", n);
82c121a4
LP
191}
192
718db961
LP
193static int property_get_cpu_sched_policy(
194 sd_bus *bus,
195 const char *path,
196 const char *interface,
197 const char *property,
198 sd_bus_message *reply,
ebcf1f97
LP
199 void *userdata,
200 sd_bus_error *error) {
718db961
LP
201
202 ExecContext *c = userdata;
82c121a4
LP
203 int32_t n;
204
718db961
LP
205 assert(bus);
206 assert(reply);
82c121a4
LP
207 assert(c);
208
209 if (c->cpu_sched_set)
210 n = c->cpu_sched_policy;
718db961 211 else {
82c121a4 212 n = sched_getscheduler(0);
718db961
LP
213 if (n < 0)
214 n = SCHED_OTHER;
215 }
82c121a4 216
718db961 217 return sd_bus_message_append(reply, "i", n);
82c121a4
LP
218}
219
718db961
LP
220static int property_get_cpu_sched_priority(
221 sd_bus *bus,
222 const char *path,
223 const char *interface,
224 const char *property,
225 sd_bus_message *reply,
ebcf1f97
LP
226 void *userdata,
227 sd_bus_error *error) {
718db961
LP
228
229 ExecContext *c = userdata;
82c121a4
LP
230 int32_t n;
231
718db961
LP
232 assert(bus);
233 assert(reply);
82c121a4
LP
234 assert(c);
235
236 if (c->cpu_sched_set)
237 n = c->cpu_sched_priority;
238 else {
b92bea5d 239 struct sched_param p = {};
82c121a4 240
82c121a4
LP
241 if (sched_getparam(0, &p) >= 0)
242 n = p.sched_priority;
e62d8c39
ZJS
243 else
244 n = 0;
82c121a4
LP
245 }
246
718db961 247 return sd_bus_message_append(reply, "i", n);
82c121a4
LP
248}
249
718db961
LP
250static int property_get_cpu_affinity(
251 sd_bus *bus,
252 const char *path,
253 const char *interface,
254 const char *property,
255 sd_bus_message *reply,
ebcf1f97
LP
256 void *userdata,
257 sd_bus_error *error) {
82c121a4 258
718db961 259 ExecContext *c = userdata;
e2b2fb7f 260 _cleanup_(cpu_set_reset) CPUSet s = {};
75e40119
MS
261 _cleanup_free_ uint8_t *array = NULL;
262 size_t allocated;
82c121a4 263
718db961
LP
264 assert(bus);
265 assert(reply);
266 assert(c);
82c121a4 267
e2b2fb7f
MS
268 if (c->cpu_affinity_from_numa) {
269 int r;
270
271 r = numa_to_cpu_set(&c->numa_policy, &s);
272 if (r < 0)
273 return r;
274 }
275
276 (void) cpu_set_to_dbus(c->cpu_affinity_from_numa ? &s : &c->cpu_set, &array, &allocated);
277
75e40119 278 return sd_bus_message_append_array(reply, 'y', array, allocated);
82c121a4
LP
279}
280
b070c7c0
MS
281static int property_get_numa_mask(
282 sd_bus *bus,
283 const char *path,
284 const char *interface,
285 const char *property,
286 sd_bus_message *reply,
287 void *userdata,
288 sd_bus_error *error) {
289
290 ExecContext *c = userdata;
291 _cleanup_free_ uint8_t *array = NULL;
292 size_t allocated;
293
294 assert(bus);
295 assert(reply);
296 assert(c);
297
298 (void) cpu_set_to_dbus(&c->numa_policy.nodes, &array, &allocated);
299
300 return sd_bus_message_append_array(reply, 'y', array, allocated);
301}
302
303static int property_get_numa_policy(
304 sd_bus *bus,
305 const char *path,
306 const char *interface,
307 const char *property,
308 sd_bus_message *reply,
309 void *userdata,
310 sd_bus_error *error) {
311 ExecContext *c = userdata;
312 int32_t policy;
313
314 assert(bus);
315 assert(reply);
316 assert(c);
317
318 policy = numa_policy_get_type(&c->numa_policy);
319
320 return sd_bus_message_append_basic(reply, 'i', &policy);
321}
322
718db961
LP
323static int property_get_timer_slack_nsec(
324 sd_bus *bus,
325 const char *path,
326 const char *interface,
327 const char *property,
328 sd_bus_message *reply,
ebcf1f97
LP
329 void *userdata,
330 sd_bus_error *error) {
718db961
LP
331
332 ExecContext *c = userdata;
82c121a4
LP
333 uint64_t u;
334
718db961
LP
335 assert(bus);
336 assert(reply);
82c121a4
LP
337 assert(c);
338
3a43da28 339 if (c->timer_slack_nsec != NSEC_INFINITY)
03fae018 340 u = (uint64_t) c->timer_slack_nsec;
82c121a4
LP
341 else
342 u = (uint64_t) prctl(PR_GET_TIMERSLACK);
343
718db961 344 return sd_bus_message_append(reply, "t", u);
82c121a4
LP
345}
346
718db961
LP
347static int property_get_syscall_filter(
348 sd_bus *bus,
349 const char *path,
350 const char *interface,
351 const char *property,
352 sd_bus_message *reply,
ebcf1f97
LP
353 void *userdata,
354 sd_bus_error *error) {
82c121a4 355
17df7223
LP
356 ExecContext *c = userdata;
357 _cleanup_strv_free_ char **l = NULL;
57183d11
LP
358 int r;
359
349cc4a5 360#if HAVE_SECCOMP
17df7223 361 Iterator i;
8cfa775f 362 void *id, *val;
351a19b1 363#endif
17df7223
LP
364
365 assert(bus);
366 assert(reply);
367 assert(c);
368
57183d11
LP
369 r = sd_bus_message_open_container(reply, 'r', "bas");
370 if (r < 0)
371 return r;
372
6b000af4 373 r = sd_bus_message_append(reply, "b", c->syscall_allow_list);
57183d11
LP
374 if (r < 0)
375 return r;
376
349cc4a5 377#if HAVE_SECCOMP
8cfa775f
YW
378 HASHMAP_FOREACH_KEY(val, id, c->syscall_filter, i) {
379 _cleanup_free_ char *name = NULL;
380 const char *e = NULL;
381 char *s;
382 int num = PTR_TO_INT(val);
17df7223
LP
383
384 name = seccomp_syscall_resolve_num_arch(SCMP_ARCH_NATIVE, PTR_TO_INT(id) - 1);
385 if (!name)
386 continue;
387
8cfa775f
YW
388 if (num >= 0) {
389 e = errno_to_name(num);
390 if (e) {
391 s = strjoin(name, ":", e);
392 if (!s)
393 return -ENOMEM;
394 } else {
395 r = asprintf(&s, "%s:%d", name, num);
396 if (r < 0)
397 return -ENOMEM;
398 }
ae2a15bc
LP
399 } else
400 s = TAKE_PTR(name);
8cfa775f
YW
401
402 r = strv_consume(&l, s);
6e18964d
ZJS
403 if (r < 0)
404 return r;
17df7223 405 }
351a19b1 406#endif
17df7223
LP
407
408 strv_sort(l);
409
57183d11
LP
410 r = sd_bus_message_append_strv(reply, l);
411 if (r < 0)
412 return r;
17df7223 413
57183d11
LP
414 return sd_bus_message_close_container(reply);
415}
17df7223 416
57183d11
LP
417static int property_get_syscall_archs(
418 sd_bus *bus,
419 const char *path,
420 const char *interface,
421 const char *property,
422 sd_bus_message *reply,
423 void *userdata,
424 sd_bus_error *error) {
425
426 ExecContext *c = userdata;
427 _cleanup_strv_free_ char **l = NULL;
428 int r;
429
349cc4a5 430#if HAVE_SECCOMP
57183d11
LP
431 Iterator i;
432 void *id;
433#endif
434
435 assert(bus);
436 assert(reply);
437 assert(c);
17df7223 438
349cc4a5 439#if HAVE_SECCOMP
57183d11
LP
440 SET_FOREACH(id, c->syscall_archs, i) {
441 const char *name;
442
443 name = seccomp_arch_to_string(PTR_TO_UINT32(id) - 1);
444 if (!name)
445 continue;
446
447 r = strv_extend(&l, name);
448 if (r < 0)
449 return -ENOMEM;
17df7223 450 }
57183d11
LP
451#endif
452
453 strv_sort(l);
454
455 r = sd_bus_message_append_strv(reply, l);
456 if (r < 0)
457 return r;
17df7223 458
57183d11 459 return 0;
17df7223
LP
460}
461
5f8640fb
LP
462static int property_get_selinux_context(
463 sd_bus *bus,
464 const char *path,
465 const char *interface,
466 const char *property,
467 sd_bus_message *reply,
468 void *userdata,
469 sd_bus_error *error) {
470
471 ExecContext *c = userdata;
472
473 assert(bus);
474 assert(reply);
475 assert(c);
476
477 return sd_bus_message_append(reply, "(bs)", c->selinux_context_ignore, c->selinux_context);
478}
479
eef65bf3
MS
480static int property_get_apparmor_profile(
481 sd_bus *bus,
482 const char *path,
483 const char *interface,
484 const char *property,
485 sd_bus_message *reply,
486 void *userdata,
487 sd_bus_error *error) {
488
489 ExecContext *c = userdata;
490
491 assert(bus);
492 assert(reply);
493 assert(c);
494
495 return sd_bus_message_append(reply, "(bs)", c->apparmor_profile_ignore, c->apparmor_profile);
496}
497
2ca620c4
WC
498static int property_get_smack_process_label(
499 sd_bus *bus,
500 const char *path,
501 const char *interface,
502 const char *property,
503 sd_bus_message *reply,
504 void *userdata,
505 sd_bus_error *error) {
506
507 ExecContext *c = userdata;
508
509 assert(bus);
510 assert(reply);
511 assert(c);
512
513 return sd_bus_message_append(reply, "(bs)", c->smack_process_label_ignore, c->smack_process_label);
514}
515
4298d0b5
LP
516static int property_get_address_families(
517 sd_bus *bus,
518 const char *path,
519 const char *interface,
520 const char *property,
521 sd_bus_message *reply,
522 void *userdata,
523 sd_bus_error *error) {
524
525 ExecContext *c = userdata;
526 _cleanup_strv_free_ char **l = NULL;
527 Iterator i;
528 void *af;
529 int r;
530
531 assert(bus);
532 assert(reply);
533 assert(c);
534
535 r = sd_bus_message_open_container(reply, 'r', "bas");
536 if (r < 0)
537 return r;
538
6b000af4 539 r = sd_bus_message_append(reply, "b", c->address_families_allow_list);
4298d0b5
LP
540 if (r < 0)
541 return r;
542
543 SET_FOREACH(af, c->address_families, i) {
544 const char *name;
545
546 name = af_to_name(PTR_TO_INT(af));
547 if (!name)
548 continue;
549
550 r = strv_extend(&l, name);
551 if (r < 0)
552 return -ENOMEM;
553 }
554
555 strv_sort(l);
556
557 r = sd_bus_message_append_strv(reply, l);
558 if (r < 0)
559 return r;
560
561 return sd_bus_message_close_container(reply);
562}
563
5f5d8eab
LP
564static int property_get_working_directory(
565 sd_bus *bus,
566 const char *path,
567 const char *interface,
568 const char *property,
569 sd_bus_message *reply,
570 void *userdata,
571 sd_bus_error *error) {
572
573 ExecContext *c = userdata;
574 const char *wd;
575
576 assert(bus);
577 assert(reply);
578 assert(c);
579
580 if (c->working_directory_home)
581 wd = "~";
582 else
583 wd = c->working_directory;
584
585 if (c->working_directory_missing_ok)
586 wd = strjoina("!", wd);
587
588 return sd_bus_message_append(reply, "s", wd);
589}
590
5073ff6b 591static int property_get_stdio_fdname(
52c239d7
LB
592 sd_bus *bus,
593 const char *path,
594 const char *interface,
595 const char *property,
596 sd_bus_message *reply,
597 void *userdata,
598 sd_bus_error *error) {
599
600 ExecContext *c = userdata;
5073ff6b 601 int fileno;
52c239d7
LB
602
603 assert(bus);
604 assert(c);
605 assert(property);
606 assert(reply);
607
5073ff6b
LP
608 if (streq(property, "StandardInputFileDescriptorName"))
609 fileno = STDIN_FILENO;
610 else if (streq(property, "StandardOutputFileDescriptorName"))
611 fileno = STDOUT_FILENO;
612 else {
613 assert(streq(property, "StandardErrorFileDescriptorName"));
614 fileno = STDERR_FILENO;
615 }
52c239d7 616
5073ff6b 617 return sd_bus_message_append(reply, "s", exec_context_fdname(c, fileno));
52c239d7
LB
618}
619
08f3be7a 620static int property_get_input_data(
52c239d7
LB
621 sd_bus *bus,
622 const char *path,
623 const char *interface,
624 const char *property,
625 sd_bus_message *reply,
626 void *userdata,
627 sd_bus_error *error) {
628
629 ExecContext *c = userdata;
52c239d7
LB
630
631 assert(bus);
632 assert(c);
633 assert(property);
634 assert(reply);
635
08f3be7a 636 return sd_bus_message_append_array(reply, 'y', c->stdin_data, c->stdin_data_size);
52c239d7
LB
637}
638
d2d6c096
LP
639static int property_get_bind_paths(
640 sd_bus *bus,
641 const char *path,
642 const char *interface,
643 const char *property,
644 sd_bus_message *reply,
645 void *userdata,
646 sd_bus_error *error) {
647
648 ExecContext *c = userdata;
649 unsigned i;
650 bool ro;
651 int r;
652
653 assert(bus);
654 assert(c);
655 assert(property);
656 assert(reply);
657
5d904a6a 658 ro = strstr(property, "ReadOnly");
d2d6c096
LP
659
660 r = sd_bus_message_open_container(reply, 'a', "(ssbt)");
661 if (r < 0)
662 return r;
663
664 for (i = 0; i < c->n_bind_mounts; i++) {
665
666 if (ro != c->bind_mounts[i].read_only)
667 continue;
668
669 r = sd_bus_message_append(
670 reply, "(ssbt)",
671 c->bind_mounts[i].source,
672 c->bind_mounts[i].destination,
673 c->bind_mounts[i].ignore_enoent,
c9b06108 674 c->bind_mounts[i].recursive ? (uint64_t) MS_REC : (uint64_t) 0);
d2d6c096
LP
675 if (r < 0)
676 return r;
677 }
678
679 return sd_bus_message_close_container(reply);
680}
681
784ad252
YW
682static int property_get_temporary_filesystems(
683 sd_bus *bus,
684 const char *path,
685 const char *interface,
686 const char *property,
687 sd_bus_message *reply,
688 void *userdata,
689 sd_bus_error *error) {
690
691 ExecContext *c = userdata;
692 unsigned i;
693 int r;
694
695 assert(bus);
696 assert(c);
697 assert(property);
698 assert(reply);
699
700 r = sd_bus_message_open_container(reply, 'a', "(ss)");
701 if (r < 0)
702 return r;
703
704 for (i = 0; i < c->n_temporary_filesystems; i++) {
705 TemporaryFileSystem *t = c->temporary_filesystems + i;
706
707 r = sd_bus_message_append(
708 reply, "(ss)",
709 t->path,
710 t->options);
711 if (r < 0)
712 return r;
713 }
714
715 return sd_bus_message_close_container(reply);
716}
717
d3070fbd
LP
718static int property_get_log_extra_fields(
719 sd_bus *bus,
720 const char *path,
721 const char *interface,
722 const char *property,
723 sd_bus_message *reply,
724 void *userdata,
725 sd_bus_error *error) {
726
727 ExecContext *c = userdata;
728 size_t i;
729 int r;
730
731 assert(bus);
732 assert(c);
733 assert(property);
734 assert(reply);
735
736 r = sd_bus_message_open_container(reply, 'a', "ay");
737 if (r < 0)
738 return r;
739
740 for (i = 0; i < c->n_log_extra_fields; i++) {
741 r = sd_bus_message_append_array(reply, 'y', c->log_extra_fields[i].iov_base, c->log_extra_fields[i].iov_len);
742 if (r < 0)
743 return r;
744 }
745
746 return sd_bus_message_close_container(reply);
747}
748
0389f4fa
LB
749static int property_get_root_hash(
750 sd_bus *bus,
751 const char *path,
752 const char *interface,
753 const char *property,
754 sd_bus_message *reply,
755 void *userdata,
756 sd_bus_error *error) {
757
758 ExecContext *c = userdata;
759
760 assert(bus);
761 assert(c);
762 assert(property);
763 assert(reply);
764
765 return sd_bus_message_append_array(reply, 'y', c->root_hash, c->root_hash_size);
766}
767
d4d55b0d
LB
768static int property_get_root_hash_sig(
769 sd_bus *bus,
770 const char *path,
771 const char *interface,
772 const char *property,
773 sd_bus_message *reply,
774 void *userdata,
775 sd_bus_error *error) {
776
777 ExecContext *c = userdata;
778
779 assert(bus);
780 assert(c);
781 assert(property);
782 assert(reply);
783
784 return sd_bus_message_append_array(reply, 'y', c->root_hash_sig, c->root_hash_sig_size);
785}
786
18d73705
LB
787static int property_get_root_image_options(
788 sd_bus *bus,
789 const char *path,
790 const char *interface,
791 const char *property,
792 sd_bus_message *reply,
793 void *userdata,
794 sd_bus_error *error) {
795
796 ExecContext *c = userdata;
797 MountOptions *m;
798 int r;
799
800 assert(bus);
801 assert(c);
802 assert(property);
803 assert(reply);
804
805 r = sd_bus_message_open_container(reply, 'a', "(us)");
806 if (r < 0)
807 return r;
808
809 LIST_FOREACH(mount_options, m, c->root_image_options) {
810 r = sd_bus_message_append(reply, "(us)", m->partition_number, m->options);
811 if (r < 0)
812 return r;
813 }
814
815 return sd_bus_message_close_container(reply);
816}
817
718db961
LP
818const sd_bus_vtable bus_exec_vtable[] = {
819 SD_BUS_VTABLE_START(0),
556089dc
LP
820 SD_BUS_PROPERTY("Environment", "as", NULL, offsetof(ExecContext, environment), SD_BUS_VTABLE_PROPERTY_CONST),
821 SD_BUS_PROPERTY("EnvironmentFiles", "a(sb)", property_get_environment_files, 0, SD_BUS_VTABLE_PROPERTY_CONST),
b4c14404 822 SD_BUS_PROPERTY("PassEnvironment", "as", NULL, offsetof(ExecContext, pass_environment), SD_BUS_VTABLE_PROPERTY_CONST),
00819cc1 823 SD_BUS_PROPERTY("UnsetEnvironment", "as", NULL, offsetof(ExecContext, unset_environment), SD_BUS_VTABLE_PROPERTY_CONST),
556089dc 824 SD_BUS_PROPERTY("UMask", "u", bus_property_get_mode, offsetof(ExecContext, umask), SD_BUS_VTABLE_PROPERTY_CONST),
c9d031c3 825 SD_BUS_PROPERTY("LimitCPU", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_CPU]), SD_BUS_VTABLE_PROPERTY_CONST),
147f6858 826 SD_BUS_PROPERTY("LimitCPUSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_CPU]), SD_BUS_VTABLE_PROPERTY_CONST),
c9d031c3 827 SD_BUS_PROPERTY("LimitFSIZE", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_FSIZE]), SD_BUS_VTABLE_PROPERTY_CONST),
147f6858 828 SD_BUS_PROPERTY("LimitFSIZESoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_FSIZE]), SD_BUS_VTABLE_PROPERTY_CONST),
c9d031c3 829 SD_BUS_PROPERTY("LimitDATA", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_DATA]), SD_BUS_VTABLE_PROPERTY_CONST),
147f6858 830 SD_BUS_PROPERTY("LimitDATASoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_DATA]), SD_BUS_VTABLE_PROPERTY_CONST),
c9d031c3 831 SD_BUS_PROPERTY("LimitSTACK", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_STACK]), SD_BUS_VTABLE_PROPERTY_CONST),
147f6858 832 SD_BUS_PROPERTY("LimitSTACKSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_STACK]), SD_BUS_VTABLE_PROPERTY_CONST),
c9d031c3 833 SD_BUS_PROPERTY("LimitCORE", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_CORE]), SD_BUS_VTABLE_PROPERTY_CONST),
147f6858 834 SD_BUS_PROPERTY("LimitCORESoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_CORE]), SD_BUS_VTABLE_PROPERTY_CONST),
c9d031c3 835 SD_BUS_PROPERTY("LimitRSS", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RSS]), SD_BUS_VTABLE_PROPERTY_CONST),
147f6858 836 SD_BUS_PROPERTY("LimitRSSSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RSS]), SD_BUS_VTABLE_PROPERTY_CONST),
c9d031c3 837 SD_BUS_PROPERTY("LimitNOFILE", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NOFILE]), SD_BUS_VTABLE_PROPERTY_CONST),
147f6858 838 SD_BUS_PROPERTY("LimitNOFILESoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NOFILE]), SD_BUS_VTABLE_PROPERTY_CONST),
c9d031c3 839 SD_BUS_PROPERTY("LimitAS", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_AS]), SD_BUS_VTABLE_PROPERTY_CONST),
147f6858 840 SD_BUS_PROPERTY("LimitASSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_AS]), SD_BUS_VTABLE_PROPERTY_CONST),
c9d031c3 841 SD_BUS_PROPERTY("LimitNPROC", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NPROC]), SD_BUS_VTABLE_PROPERTY_CONST),
147f6858 842 SD_BUS_PROPERTY("LimitNPROCSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NPROC]), SD_BUS_VTABLE_PROPERTY_CONST),
c9d031c3 843 SD_BUS_PROPERTY("LimitMEMLOCK", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_MEMLOCK]), SD_BUS_VTABLE_PROPERTY_CONST),
147f6858 844 SD_BUS_PROPERTY("LimitMEMLOCKSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_MEMLOCK]), SD_BUS_VTABLE_PROPERTY_CONST),
c9d031c3 845 SD_BUS_PROPERTY("LimitLOCKS", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_LOCKS]), SD_BUS_VTABLE_PROPERTY_CONST),
147f6858 846 SD_BUS_PROPERTY("LimitLOCKSSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_LOCKS]), SD_BUS_VTABLE_PROPERTY_CONST),
c9d031c3 847 SD_BUS_PROPERTY("LimitSIGPENDING", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_SIGPENDING]), SD_BUS_VTABLE_PROPERTY_CONST),
147f6858 848 SD_BUS_PROPERTY("LimitSIGPENDINGSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_SIGPENDING]), SD_BUS_VTABLE_PROPERTY_CONST),
c9d031c3 849 SD_BUS_PROPERTY("LimitMSGQUEUE", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_MSGQUEUE]), SD_BUS_VTABLE_PROPERTY_CONST),
147f6858 850 SD_BUS_PROPERTY("LimitMSGQUEUESoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_MSGQUEUE]), SD_BUS_VTABLE_PROPERTY_CONST),
c9d031c3 851 SD_BUS_PROPERTY("LimitNICE", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NICE]), SD_BUS_VTABLE_PROPERTY_CONST),
147f6858 852 SD_BUS_PROPERTY("LimitNICESoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NICE]), SD_BUS_VTABLE_PROPERTY_CONST),
c9d031c3 853 SD_BUS_PROPERTY("LimitRTPRIO", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RTPRIO]), SD_BUS_VTABLE_PROPERTY_CONST),
147f6858 854 SD_BUS_PROPERTY("LimitRTPRIOSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RTPRIO]), SD_BUS_VTABLE_PROPERTY_CONST),
c9d031c3 855 SD_BUS_PROPERTY("LimitRTTIME", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RTTIME]), SD_BUS_VTABLE_PROPERTY_CONST),
147f6858 856 SD_BUS_PROPERTY("LimitRTTIMESoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RTTIME]), SD_BUS_VTABLE_PROPERTY_CONST),
5f5d8eab 857 SD_BUS_PROPERTY("WorkingDirectory", "s", property_get_working_directory, 0, SD_BUS_VTABLE_PROPERTY_CONST),
556089dc 858 SD_BUS_PROPERTY("RootDirectory", "s", NULL, offsetof(ExecContext, root_directory), SD_BUS_VTABLE_PROPERTY_CONST),
915e6d16 859 SD_BUS_PROPERTY("RootImage", "s", NULL, offsetof(ExecContext, root_image), SD_BUS_VTABLE_PROPERTY_CONST),
18d73705 860 SD_BUS_PROPERTY("RootImageOptions", "a(us)", property_get_root_image_options, 0, SD_BUS_VTABLE_PROPERTY_CONST),
0389f4fa
LB
861 SD_BUS_PROPERTY("RootHash", "ay", property_get_root_hash, 0, SD_BUS_VTABLE_PROPERTY_CONST),
862 SD_BUS_PROPERTY("RootHashPath", "s", NULL, offsetof(ExecContext, root_hash_path), SD_BUS_VTABLE_PROPERTY_CONST),
d4d55b0d
LB
863 SD_BUS_PROPERTY("RootHashSignature", "ay", property_get_root_hash_sig, 0, SD_BUS_VTABLE_PROPERTY_CONST),
864 SD_BUS_PROPERTY("RootHashSignaturePath", "s", NULL, offsetof(ExecContext, root_hash_sig_path), SD_BUS_VTABLE_PROPERTY_CONST),
0389f4fa 865 SD_BUS_PROPERTY("RootVerity", "s", NULL, offsetof(ExecContext, root_verity), SD_BUS_VTABLE_PROPERTY_CONST),
556089dc 866 SD_BUS_PROPERTY("OOMScoreAdjust", "i", property_get_oom_score_adjust, 0, SD_BUS_VTABLE_PROPERTY_CONST),
ad21e542 867 SD_BUS_PROPERTY("CoredumpFilter", "t", property_get_coredump_filter, 0, SD_BUS_VTABLE_PROPERTY_CONST),
556089dc 868 SD_BUS_PROPERTY("Nice", "i", property_get_nice, 0, SD_BUS_VTABLE_PROPERTY_CONST),
7f452159
LP
869 SD_BUS_PROPERTY("IOSchedulingClass", "i", property_get_ioprio_class, 0, SD_BUS_VTABLE_PROPERTY_CONST),
870 SD_BUS_PROPERTY("IOSchedulingPriority", "i", property_get_ioprio_priority, 0, SD_BUS_VTABLE_PROPERTY_CONST),
556089dc
LP
871 SD_BUS_PROPERTY("CPUSchedulingPolicy", "i", property_get_cpu_sched_policy, 0, SD_BUS_VTABLE_PROPERTY_CONST),
872 SD_BUS_PROPERTY("CPUSchedulingPriority", "i", property_get_cpu_sched_priority, 0, SD_BUS_VTABLE_PROPERTY_CONST),
873 SD_BUS_PROPERTY("CPUAffinity", "ay", property_get_cpu_affinity, 0, SD_BUS_VTABLE_PROPERTY_CONST),
e2b2fb7f 874 SD_BUS_PROPERTY("CPUAffinityFromNUMA", "b", property_get_cpu_affinity_from_numa, 0, SD_BUS_VTABLE_PROPERTY_CONST),
b070c7c0
MS
875 SD_BUS_PROPERTY("NUMAPolicy", "i", property_get_numa_policy, 0, SD_BUS_VTABLE_PROPERTY_CONST),
876 SD_BUS_PROPERTY("NUMAMask", "ay", property_get_numa_mask, 0, SD_BUS_VTABLE_PROPERTY_CONST),
556089dc
LP
877 SD_BUS_PROPERTY("TimerSlackNSec", "t", property_get_timer_slack_nsec, 0, SD_BUS_VTABLE_PROPERTY_CONST),
878 SD_BUS_PROPERTY("CPUSchedulingResetOnFork", "b", bus_property_get_bool, offsetof(ExecContext, cpu_sched_reset_on_fork), SD_BUS_VTABLE_PROPERTY_CONST),
879 SD_BUS_PROPERTY("NonBlocking", "b", bus_property_get_bool, offsetof(ExecContext, non_blocking), SD_BUS_VTABLE_PROPERTY_CONST),
880 SD_BUS_PROPERTY("StandardInput", "s", property_get_exec_input, offsetof(ExecContext, std_input), SD_BUS_VTABLE_PROPERTY_CONST),
5073ff6b 881 SD_BUS_PROPERTY("StandardInputFileDescriptorName", "s", property_get_stdio_fdname, 0, SD_BUS_VTABLE_PROPERTY_CONST),
08f3be7a 882 SD_BUS_PROPERTY("StandardInputData", "ay", property_get_input_data, 0, SD_BUS_VTABLE_PROPERTY_CONST),
556089dc 883 SD_BUS_PROPERTY("StandardOutput", "s", bus_property_get_exec_output, offsetof(ExecContext, std_output), SD_BUS_VTABLE_PROPERTY_CONST),
5073ff6b 884 SD_BUS_PROPERTY("StandardOutputFileDescriptorName", "s", property_get_stdio_fdname, 0, SD_BUS_VTABLE_PROPERTY_CONST),
556089dc 885 SD_BUS_PROPERTY("StandardError", "s", bus_property_get_exec_output, offsetof(ExecContext, std_error), SD_BUS_VTABLE_PROPERTY_CONST),
5073ff6b 886 SD_BUS_PROPERTY("StandardErrorFileDescriptorName", "s", property_get_stdio_fdname, 0, SD_BUS_VTABLE_PROPERTY_CONST),
556089dc
LP
887 SD_BUS_PROPERTY("TTYPath", "s", NULL, offsetof(ExecContext, tty_path), SD_BUS_VTABLE_PROPERTY_CONST),
888 SD_BUS_PROPERTY("TTYReset", "b", bus_property_get_bool, offsetof(ExecContext, tty_reset), SD_BUS_VTABLE_PROPERTY_CONST),
889 SD_BUS_PROPERTY("TTYVHangup", "b", bus_property_get_bool, offsetof(ExecContext, tty_vhangup), SD_BUS_VTABLE_PROPERTY_CONST),
890 SD_BUS_PROPERTY("TTYVTDisallocate", "b", bus_property_get_bool, offsetof(ExecContext, tty_vt_disallocate), SD_BUS_VTABLE_PROPERTY_CONST),
891 SD_BUS_PROPERTY("SyslogPriority", "i", bus_property_get_int, offsetof(ExecContext, syslog_priority), SD_BUS_VTABLE_PROPERTY_CONST),
892 SD_BUS_PROPERTY("SyslogIdentifier", "s", NULL, offsetof(ExecContext, syslog_identifier), SD_BUS_VTABLE_PROPERTY_CONST),
893 SD_BUS_PROPERTY("SyslogLevelPrefix", "b", bus_property_get_bool, offsetof(ExecContext, syslog_level_prefix), SD_BUS_VTABLE_PROPERTY_CONST),
9d5527f2
YW
894 SD_BUS_PROPERTY("SyslogLevel", "i", property_get_syslog_level, offsetof(ExecContext, syslog_priority), SD_BUS_VTABLE_PROPERTY_CONST),
895 SD_BUS_PROPERTY("SyslogFacility", "i", property_get_syslog_facility, offsetof(ExecContext, syslog_priority), SD_BUS_VTABLE_PROPERTY_CONST),
d3070fbd 896 SD_BUS_PROPERTY("LogLevelMax", "i", bus_property_get_int, offsetof(ExecContext, log_level_max), SD_BUS_VTABLE_PROPERTY_CONST),
5ac1530e
ZJS
897 SD_BUS_PROPERTY("LogRateLimitIntervalUSec", "t", bus_property_get_usec, offsetof(ExecContext, log_ratelimit_interval_usec), SD_BUS_VTABLE_PROPERTY_CONST),
898 SD_BUS_PROPERTY("LogRateLimitBurst", "u", bus_property_get_unsigned, offsetof(ExecContext, log_ratelimit_burst), SD_BUS_VTABLE_PROPERTY_CONST),
d3070fbd 899 SD_BUS_PROPERTY("LogExtraFields", "aay", property_get_log_extra_fields, 0, SD_BUS_VTABLE_PROPERTY_CONST),
91dd5f7c 900 SD_BUS_PROPERTY("LogNamespace", "s", NULL, offsetof(ExecContext, log_namespace), SD_BUS_VTABLE_PROPERTY_CONST),
556089dc 901 SD_BUS_PROPERTY("SecureBits", "i", bus_property_get_int, offsetof(ExecContext, secure_bits), SD_BUS_VTABLE_PROPERTY_CONST),
c0159e20
YW
902 SD_BUS_PROPERTY("CapabilityBoundingSet", "t", NULL, offsetof(ExecContext, capability_bounding_set), SD_BUS_VTABLE_PROPERTY_CONST),
903 SD_BUS_PROPERTY("AmbientCapabilities", "t", NULL, offsetof(ExecContext, capability_ambient_set), SD_BUS_VTABLE_PROPERTY_CONST),
556089dc
LP
904 SD_BUS_PROPERTY("User", "s", NULL, offsetof(ExecContext, user), SD_BUS_VTABLE_PROPERTY_CONST),
905 SD_BUS_PROPERTY("Group", "s", NULL, offsetof(ExecContext, group), SD_BUS_VTABLE_PROPERTY_CONST),
29206d46 906 SD_BUS_PROPERTY("DynamicUser", "b", bus_property_get_bool, offsetof(ExecContext, dynamic_user), SD_BUS_VTABLE_PROPERTY_CONST),
00d9ef85 907 SD_BUS_PROPERTY("RemoveIPC", "b", bus_property_get_bool, offsetof(ExecContext, remove_ipc), SD_BUS_VTABLE_PROPERTY_CONST),
556089dc 908 SD_BUS_PROPERTY("SupplementaryGroups", "as", NULL, offsetof(ExecContext, supplementary_groups), SD_BUS_VTABLE_PROPERTY_CONST),
556089dc 909 SD_BUS_PROPERTY("PAMName", "s", NULL, offsetof(ExecContext, pam_name), SD_BUS_VTABLE_PROPERTY_CONST),
2a624c36
AP
910 SD_BUS_PROPERTY("ReadWritePaths", "as", NULL, offsetof(ExecContext, read_write_paths), SD_BUS_VTABLE_PROPERTY_CONST),
911 SD_BUS_PROPERTY("ReadOnlyPaths", "as", NULL, offsetof(ExecContext, read_only_paths), SD_BUS_VTABLE_PROPERTY_CONST),
912 SD_BUS_PROPERTY("InaccessiblePaths", "as", NULL, offsetof(ExecContext, inaccessible_paths), SD_BUS_VTABLE_PROPERTY_CONST),
556089dc
LP
913 SD_BUS_PROPERTY("MountFlags", "t", bus_property_get_ulong, offsetof(ExecContext, mount_flags), SD_BUS_VTABLE_PROPERTY_CONST),
914 SD_BUS_PROPERTY("PrivateTmp", "b", bus_property_get_bool, offsetof(ExecContext, private_tmp), SD_BUS_VTABLE_PROPERTY_CONST),
7f112f50 915 SD_BUS_PROPERTY("PrivateDevices", "b", bus_property_get_bool, offsetof(ExecContext, private_devices), SD_BUS_VTABLE_PROPERTY_CONST),
b8b7b838 916 SD_BUS_PROPERTY("ProtectClock", "b", bus_property_get_bool, offsetof(ExecContext, protect_clock), SD_BUS_VTABLE_PROPERTY_CONST),
59eeb84b 917 SD_BUS_PROPERTY("ProtectKernelTunables", "b", bus_property_get_bool, offsetof(ExecContext, protect_kernel_tunables), SD_BUS_VTABLE_PROPERTY_CONST),
502d704e 918 SD_BUS_PROPERTY("ProtectKernelModules", "b", bus_property_get_bool, offsetof(ExecContext, protect_kernel_modules), SD_BUS_VTABLE_PROPERTY_CONST),
84703040 919 SD_BUS_PROPERTY("ProtectKernelLogs", "b", bus_property_get_bool, offsetof(ExecContext, protect_kernel_logs), SD_BUS_VTABLE_PROPERTY_CONST),
59eeb84b 920 SD_BUS_PROPERTY("ProtectControlGroups", "b", bus_property_get_bool, offsetof(ExecContext, protect_control_groups), SD_BUS_VTABLE_PROPERTY_CONST),
d251207d
LP
921 SD_BUS_PROPERTY("PrivateNetwork", "b", bus_property_get_bool, offsetof(ExecContext, private_network), SD_BUS_VTABLE_PROPERTY_CONST),
922 SD_BUS_PROPERTY("PrivateUsers", "b", bus_property_get_bool, offsetof(ExecContext, private_users), SD_BUS_VTABLE_PROPERTY_CONST),
228af36f 923 SD_BUS_PROPERTY("PrivateMounts", "b", bus_property_get_bool, offsetof(ExecContext, private_mounts), SD_BUS_VTABLE_PROPERTY_CONST),
73b84e92
YW
924 SD_BUS_PROPERTY("ProtectHome", "s", property_get_protect_home, offsetof(ExecContext, protect_home), SD_BUS_VTABLE_PROPERTY_CONST),
925 SD_BUS_PROPERTY("ProtectSystem", "s", property_get_protect_system, offsetof(ExecContext, protect_system), SD_BUS_VTABLE_PROPERTY_CONST),
556089dc
LP
926 SD_BUS_PROPERTY("SameProcessGroup", "b", bus_property_get_bool, offsetof(ExecContext, same_pgrp), SD_BUS_VTABLE_PROPERTY_CONST),
927 SD_BUS_PROPERTY("UtmpIdentifier", "s", NULL, offsetof(ExecContext, utmp_id), SD_BUS_VTABLE_PROPERTY_CONST),
023a4f67 928 SD_BUS_PROPERTY("UtmpMode", "s", property_get_exec_utmp_mode, offsetof(ExecContext, utmp_mode), SD_BUS_VTABLE_PROPERTY_CONST),
5f8640fb 929 SD_BUS_PROPERTY("SELinuxContext", "(bs)", property_get_selinux_context, 0, SD_BUS_VTABLE_PROPERTY_CONST),
eef65bf3 930 SD_BUS_PROPERTY("AppArmorProfile", "(bs)", property_get_apparmor_profile, 0, SD_BUS_VTABLE_PROPERTY_CONST),
2ca620c4 931 SD_BUS_PROPERTY("SmackProcessLabel", "(bs)", property_get_smack_process_label, 0, SD_BUS_VTABLE_PROPERTY_CONST),
556089dc
LP
932 SD_BUS_PROPERTY("IgnoreSIGPIPE", "b", bus_property_get_bool, offsetof(ExecContext, ignore_sigpipe), SD_BUS_VTABLE_PROPERTY_CONST),
933 SD_BUS_PROPERTY("NoNewPrivileges", "b", bus_property_get_bool, offsetof(ExecContext, no_new_privileges), SD_BUS_VTABLE_PROPERTY_CONST),
57183d11
LP
934 SD_BUS_PROPERTY("SystemCallFilter", "(bas)", property_get_syscall_filter, 0, SD_BUS_VTABLE_PROPERTY_CONST),
935 SD_BUS_PROPERTY("SystemCallArchitectures", "as", property_get_syscall_archs, 0, SD_BUS_VTABLE_PROPERTY_CONST),
cf9d43a8 936 SD_BUS_PROPERTY("SystemCallErrorNumber", "i", bus_property_get_int, offsetof(ExecContext, syscall_errno), SD_BUS_VTABLE_PROPERTY_CONST),
491eecb3 937 SD_BUS_PROPERTY("Personality", "s", property_get_personality, offsetof(ExecContext, personality), SD_BUS_VTABLE_PROPERTY_CONST),
78e864e5 938 SD_BUS_PROPERTY("LockPersonality", "b", bus_property_get_bool, offsetof(ExecContext, lock_personality), SD_BUS_VTABLE_PROPERTY_CONST),
4298d0b5 939 SD_BUS_PROPERTY("RestrictAddressFamilies", "(bas)", property_get_address_families, 0, SD_BUS_VTABLE_PROPERTY_CONST),
53f47dfc 940 SD_BUS_PROPERTY("RuntimeDirectoryPreserve", "s", property_get_exec_preserve_mode, offsetof(ExecContext, runtime_directory_preserve_mode), SD_BUS_VTABLE_PROPERTY_CONST),
3536f49e
YW
941 SD_BUS_PROPERTY("RuntimeDirectoryMode", "u", bus_property_get_mode, offsetof(ExecContext, directories[EXEC_DIRECTORY_RUNTIME].mode), SD_BUS_VTABLE_PROPERTY_CONST),
942 SD_BUS_PROPERTY("RuntimeDirectory", "as", NULL, offsetof(ExecContext, directories[EXEC_DIRECTORY_RUNTIME].paths), SD_BUS_VTABLE_PROPERTY_CONST),
e940c1ef
YW
943 SD_BUS_PROPERTY("StateDirectoryMode", "u", bus_property_get_mode, offsetof(ExecContext, directories[EXEC_DIRECTORY_STATE].mode), SD_BUS_VTABLE_PROPERTY_CONST),
944 SD_BUS_PROPERTY("StateDirectory", "as", NULL, offsetof(ExecContext, directories[EXEC_DIRECTORY_STATE].paths), SD_BUS_VTABLE_PROPERTY_CONST),
3536f49e
YW
945 SD_BUS_PROPERTY("CacheDirectoryMode", "u", bus_property_get_mode, offsetof(ExecContext, directories[EXEC_DIRECTORY_CACHE].mode), SD_BUS_VTABLE_PROPERTY_CONST),
946 SD_BUS_PROPERTY("CacheDirectory", "as", NULL, offsetof(ExecContext, directories[EXEC_DIRECTORY_CACHE].paths), SD_BUS_VTABLE_PROPERTY_CONST),
947 SD_BUS_PROPERTY("LogsDirectoryMode", "u", bus_property_get_mode, offsetof(ExecContext, directories[EXEC_DIRECTORY_LOGS].mode), SD_BUS_VTABLE_PROPERTY_CONST),
948 SD_BUS_PROPERTY("LogsDirectory", "as", NULL, offsetof(ExecContext, directories[EXEC_DIRECTORY_LOGS].paths), SD_BUS_VTABLE_PROPERTY_CONST),
949 SD_BUS_PROPERTY("ConfigurationDirectoryMode", "u", bus_property_get_mode, offsetof(ExecContext, directories[EXEC_DIRECTORY_CONFIGURATION].mode), SD_BUS_VTABLE_PROPERTY_CONST),
950 SD_BUS_PROPERTY("ConfigurationDirectory", "as", NULL, offsetof(ExecContext, directories[EXEC_DIRECTORY_CONFIGURATION].paths), SD_BUS_VTABLE_PROPERTY_CONST),
12213aed 951 SD_BUS_PROPERTY("TimeoutCleanUSec", "t", bus_property_get_usec, offsetof(ExecContext, timeout_clean_usec), SD_BUS_VTABLE_PROPERTY_CONST),
f3e43635 952 SD_BUS_PROPERTY("MemoryDenyWriteExecute", "b", bus_property_get_bool, offsetof(ExecContext, memory_deny_write_execute), SD_BUS_VTABLE_PROPERTY_CONST),
f4170c67 953 SD_BUS_PROPERTY("RestrictRealtime", "b", bus_property_get_bool, offsetof(ExecContext, restrict_realtime), SD_BUS_VTABLE_PROPERTY_CONST),
f69567cb 954 SD_BUS_PROPERTY("RestrictSUIDSGID", "b", bus_property_get_bool, offsetof(ExecContext, restrict_suid_sgid), SD_BUS_VTABLE_PROPERTY_CONST),
6a8c2d59 955 SD_BUS_PROPERTY("RestrictNamespaces", "t", bus_property_get_ulong, offsetof(ExecContext, restrict_namespaces), SD_BUS_VTABLE_PROPERTY_CONST),
d2d6c096
LP
956 SD_BUS_PROPERTY("BindPaths", "a(ssbt)", property_get_bind_paths, 0, SD_BUS_VTABLE_PROPERTY_CONST),
957 SD_BUS_PROPERTY("BindReadOnlyPaths", "a(ssbt)", property_get_bind_paths, 0, SD_BUS_VTABLE_PROPERTY_CONST),
784ad252 958 SD_BUS_PROPERTY("TemporaryFileSystem", "a(ss)", property_get_temporary_filesystems, 0, SD_BUS_VTABLE_PROPERTY_CONST),
5d997827 959 SD_BUS_PROPERTY("MountAPIVFS", "b", bus_property_get_bool, offsetof(ExecContext, mount_apivfs), SD_BUS_VTABLE_PROPERTY_CONST),
b1edf445 960 SD_BUS_PROPERTY("KeyringMode", "s", property_get_exec_keyring_mode, offsetof(ExecContext, keyring_mode), SD_BUS_VTABLE_PROPERTY_CONST),
aecd5ac6 961 SD_BUS_PROPERTY("ProtectHostname", "b", bus_property_get_bool, offsetof(ExecContext, protect_hostname), SD_BUS_VTABLE_PROPERTY_CONST),
a8d08f39 962 SD_BUS_PROPERTY("NetworkNamespacePath", "s", NULL, offsetof(ExecContext, network_namespace_path), SD_BUS_VTABLE_PROPERTY_CONST),
7f452159
LP
963
964 /* Obsolete/redundant properties: */
965 SD_BUS_PROPERTY("Capabilities", "s", property_get_empty_string, 0, SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN),
966 SD_BUS_PROPERTY("ReadWriteDirectories", "as", NULL, offsetof(ExecContext, read_write_paths), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN),
967 SD_BUS_PROPERTY("ReadOnlyDirectories", "as", NULL, offsetof(ExecContext, read_only_paths), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN),
968 SD_BUS_PROPERTY("InaccessibleDirectories", "as", NULL, offsetof(ExecContext, inaccessible_paths), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN),
969 SD_BUS_PROPERTY("IOScheduling", "i", property_get_ioprio, 0, SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN),
970
718db961
LP
971 SD_BUS_VTABLE_END
972};
82c121a4 973
4d4c80d0
LP
974static int append_exec_command(sd_bus_message *reply, ExecCommand *c) {
975 int r;
976
977 assert(reply);
978 assert(c);
979
980 if (!c->path)
981 return 0;
982
983 r = sd_bus_message_open_container(reply, 'r', "sasbttttuii");
984 if (r < 0)
985 return r;
986
987 r = sd_bus_message_append(reply, "s", c->path);
988 if (r < 0)
989 return r;
990
991 r = sd_bus_message_append_strv(reply, c->argv);
992 if (r < 0)
993 return r;
994
995 r = sd_bus_message_append(reply, "bttttuii",
3ed0cd26 996 !!(c->flags & EXEC_COMMAND_IGNORE_FAILURE),
4d4c80d0
LP
997 c->exec_status.start_timestamp.realtime,
998 c->exec_status.start_timestamp.monotonic,
999 c->exec_status.exit_timestamp.realtime,
1000 c->exec_status.exit_timestamp.monotonic,
1001 (uint32_t) c->exec_status.pid,
1002 (int32_t) c->exec_status.code,
1003 (int32_t) c->exec_status.status);
1004 if (r < 0)
1005 return r;
1006
1007 return sd_bus_message_close_container(reply);
1008}
1009
b3d59367
AZ
1010static int append_exec_ex_command(sd_bus_message *reply, ExecCommand *c) {
1011 _cleanup_strv_free_ char **ex_opts = NULL;
1012 int r;
1013
1014 assert(reply);
1015 assert(c);
1016
1017 if (!c->path)
1018 return 0;
1019
1020 r = sd_bus_message_open_container(reply, 'r', "sasasttttuii");
1021 if (r < 0)
1022 return r;
1023
1024 r = sd_bus_message_append(reply, "s", c->path);
1025 if (r < 0)
1026 return r;
1027
1028 r = sd_bus_message_append_strv(reply, c->argv);
1029 if (r < 0)
1030 return r;
1031
1032 r = exec_command_flags_to_strv(c->flags, &ex_opts);
1033 if (r < 0)
1034 return r;
1035
1036 r = sd_bus_message_append_strv(reply, ex_opts);
1037 if (r < 0)
1038 return r;
1039
1040 r = sd_bus_message_append(reply, "ttttuii",
1041 c->exec_status.start_timestamp.realtime,
1042 c->exec_status.start_timestamp.monotonic,
1043 c->exec_status.exit_timestamp.realtime,
1044 c->exec_status.exit_timestamp.monotonic,
1045 (uint32_t) c->exec_status.pid,
1046 (int32_t) c->exec_status.code,
1047 (int32_t) c->exec_status.status);
1048 if (r < 0)
1049 return r;
1050
1051 return sd_bus_message_close_container(reply);
1052}
1053
718db961
LP
1054int bus_property_get_exec_command(
1055 sd_bus *bus,
1056 const char *path,
1057 const char *interface,
1058 const char *property,
1059 sd_bus_message *reply,
ebcf1f97
LP
1060 void *userdata,
1061 sd_bus_error *ret_error) {
fe68089d 1062
4d4c80d0 1063 ExecCommand *c = (ExecCommand*) userdata;
718db961 1064 int r;
fe68089d 1065
718db961
LP
1066 assert(bus);
1067 assert(reply);
fe68089d 1068
718db961
LP
1069 r = sd_bus_message_open_container(reply, 'a', "(sasbttttuii)");
1070 if (r < 0)
1071 return r;
fe68089d 1072
4d4c80d0
LP
1073 r = append_exec_command(reply, c);
1074 if (r < 0)
1075 return r;
fe68089d 1076
4d4c80d0
LP
1077 return sd_bus_message_close_container(reply);
1078}
718db961 1079
4d4c80d0
LP
1080int bus_property_get_exec_command_list(
1081 sd_bus *bus,
1082 const char *path,
1083 const char *interface,
1084 const char *property,
1085 sd_bus_message *reply,
1086 void *userdata,
1087 sd_bus_error *ret_error) {
718db961 1088
4d4c80d0
LP
1089 ExecCommand *c = *(ExecCommand**) userdata;
1090 int r;
718db961 1091
4d4c80d0
LP
1092 assert(bus);
1093 assert(reply);
1094
1095 r = sd_bus_message_open_container(reply, 'a', "(sasbttttuii)");
1096 if (r < 0)
1097 return r;
718db961 1098
4d4c80d0
LP
1099 LIST_FOREACH(command, c, c) {
1100 r = append_exec_command(reply, c);
718db961
LP
1101 if (r < 0)
1102 return r;
fe68089d
LP
1103 }
1104
718db961 1105 return sd_bus_message_close_container(reply);
8351ceae 1106}
c7040b5d 1107
b3d59367
AZ
1108int bus_property_get_exec_ex_command_list(
1109 sd_bus *bus,
1110 const char *path,
1111 const char *interface,
1112 const char *property,
1113 sd_bus_message *reply,
1114 void *userdata,
1115 sd_bus_error *ret_error) {
1116
1117 ExecCommand *c, *exec_command = *(ExecCommand**) userdata;
1118 int r;
1119
1120 assert(bus);
1121 assert(reply);
1122
1123 r = sd_bus_message_open_container(reply, 'a', "(sasasttttuii)");
1124 if (r < 0)
1125 return r;
1126
1127 LIST_FOREACH(command, c, exec_command) {
1128 r = append_exec_ex_command(reply, c);
1129 if (r < 0)
1130 return r;
1131 }
1132
1133 return sd_bus_message_close_container(reply);
1134}
1135
1136static char *exec_command_flags_to_exec_chars(ExecCommandFlags flags) {
a4fc96c8
ZJS
1137 return strjoin(FLAGS_SET(flags, EXEC_COMMAND_IGNORE_FAILURE) ? "-" : "",
1138 FLAGS_SET(flags, EXEC_COMMAND_NO_ENV_EXPAND) ? ":" : "",
1139 FLAGS_SET(flags, EXEC_COMMAND_FULLY_PRIVILEGED) ? "+" : "",
1140 FLAGS_SET(flags, EXEC_COMMAND_NO_SETUID) ? "!" : "",
1141 FLAGS_SET(flags, EXEC_COMMAND_AMBIENT_MAGIC) ? "!!" : "");
b3d59367
AZ
1142}
1143
237f7bcb 1144int bus_set_transient_exec_command(
9c0320e7
YW
1145 Unit *u,
1146 const char *name,
1147 ExecCommand **exec_command,
1148 sd_bus_message *message,
1149 UnitWriteFlags flags,
1150 sd_bus_error *error) {
b3d59367 1151 bool is_ex_prop = endswith(name, "Ex");
9c0320e7
YW
1152 unsigned n = 0;
1153 int r;
1154
b3d59367 1155 r = sd_bus_message_enter_container(message, 'a', is_ex_prop ? "(sasas)" : "(sasb)");
9c0320e7
YW
1156 if (r < 0)
1157 return r;
1158
b3d59367
AZ
1159 while ((r = sd_bus_message_enter_container(message, 'r', is_ex_prop ? "sasas" : "sasb")) > 0) {
1160 _cleanup_strv_free_ char **argv = NULL, **ex_opts = NULL;
9c0320e7
YW
1161 const char *path;
1162 int b;
1163
1164 r = sd_bus_message_read(message, "s", &path);
1165 if (r < 0)
1166 return r;
1167
1168 if (!path_is_absolute(path))
1169 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path %s is not absolute.", path);
1170
1171 r = sd_bus_message_read_strv(message, &argv);
1172 if (r < 0)
1173 return r;
1174
b3d59367 1175 r = is_ex_prop ? sd_bus_message_read_strv(message, &ex_opts) : sd_bus_message_read(message, "b", &b);
9c0320e7
YW
1176 if (r < 0)
1177 return r;
1178
1179 r = sd_bus_message_exit_container(message);
1180 if (r < 0)
1181 return r;
1182
1183 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
1184 ExecCommand *c;
1185
1186 c = new0(ExecCommand, 1);
1187 if (!c)
1188 return -ENOMEM;
1189
1190 c->path = strdup(path);
1191 if (!c->path) {
1192 free(c);
1193 return -ENOMEM;
1194 }
1195
ae2a15bc 1196 c->argv = TAKE_PTR(argv);
9c0320e7 1197
b3d59367
AZ
1198 if (is_ex_prop) {
1199 r = exec_command_flags_from_strv(ex_opts, &c->flags);
1200 if (r < 0)
1201 return r;
1202 } else
1203 c->flags = b ? EXEC_COMMAND_IGNORE_FAILURE : 0;
9c0320e7 1204
858d36c1 1205 path_simplify(c->path, false);
9c0320e7
YW
1206 exec_command_append_list(exec_command, c);
1207 }
1208
1209 n++;
1210 }
1211 if (r < 0)
1212 return r;
1213
1214 r = sd_bus_message_exit_container(message);
1215 if (r < 0)
1216 return r;
1217
1218 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
1219 _cleanup_free_ char *buf = NULL;
1220 _cleanup_fclose_ FILE *f = NULL;
1221 ExecCommand *c;
1222 size_t size = 0;
1223
1224 if (n == 0)
1225 *exec_command = exec_command_free_list(*exec_command);
1226
2fe21124 1227 f = open_memstream_unlocked(&buf, &size);
9c0320e7
YW
1228 if (!f)
1229 return -ENOMEM;
1230
f14bf013 1231 fprintf(f, "%s=\n", name);
9c0320e7
YW
1232
1233 LIST_FOREACH(command, c, *exec_command) {
540ac933 1234 _cleanup_free_ char *a = NULL, *exec_chars = NULL;
9c0320e7 1235
540ac933
LP
1236 exec_chars = exec_command_flags_to_exec_chars(c->flags);
1237 if (!exec_chars)
9c0320e7
YW
1238 return -ENOMEM;
1239
1240 a = unit_concat_strv(c->argv, UNIT_ESCAPE_C|UNIT_ESCAPE_SPECIFIERS);
1241 if (!a)
1242 return -ENOMEM;
1243
540ac933
LP
1244 if (streq_ptr(c->path, c->argv ? c->argv[0] : NULL))
1245 fprintf(f, "%s=%s%s\n", name, exec_chars, a);
1246 else {
1247 _cleanup_free_ char *t = NULL;
1248 const char *p;
1249
1250 p = unit_escape_setting(c->path, UNIT_ESCAPE_C|UNIT_ESCAPE_SPECIFIERS, &t);
1251 if (!p)
1252 return -ENOMEM;
b3d59367 1253
540ac933
LP
1254 fprintf(f, "%s=%s@%s %s\n", name, exec_chars, p, a);
1255 }
9c0320e7
YW
1256 }
1257
1258 r = fflush_and_check(f);
1259 if (r < 0)
1260 return r;
1261
1262 unit_write_setting(u, flags, name, buf);
1263 }
1264
1265 return 1;
1266}
1267
7e2a3fcc
YW
1268static int parse_personality(const char *s, unsigned long *p) {
1269 unsigned long v;
1270
1271 assert(p);
1272
1273 v = personality_from_string(s);
1274 if (v == PERSONALITY_INVALID)
1275 return -EINVAL;
1276
1277 *p = v;
1278 return 0;
1279}
1280
1281static const char* mount_propagation_flags_to_string_with_check(unsigned long n) {
1282 if (!IN_SET(n, 0, MS_SHARED, MS_PRIVATE, MS_SLAVE))
1283 return NULL;
1284
1285 return mount_propagation_flags_to_string(n);
1286}
1287
1288static BUS_DEFINE_SET_TRANSIENT(nsec, "t", uint64_t, nsec_t, NSEC_FMT);
1289static BUS_DEFINE_SET_TRANSIENT_IS_VALID(log_level, "i", int32_t, int, "%" PRIi32, log_level_is_valid);
aad67b80 1290#if HAVE_SECCOMP
7e2a3fcc 1291static BUS_DEFINE_SET_TRANSIENT_IS_VALID(errno, "i", int32_t, int, "%" PRIi32, errno_is_valid);
aad67b80 1292#endif
7e2a3fcc
YW
1293static BUS_DEFINE_SET_TRANSIENT_PARSE(std_input, ExecInput, exec_input_from_string);
1294static BUS_DEFINE_SET_TRANSIENT_PARSE(std_output, ExecOutput, exec_output_from_string);
1295static BUS_DEFINE_SET_TRANSIENT_PARSE(utmp_mode, ExecUtmpMode, exec_utmp_mode_from_string);
1e8c7bd5
YW
1296static BUS_DEFINE_SET_TRANSIENT_PARSE(protect_system, ProtectSystem, protect_system_from_string);
1297static BUS_DEFINE_SET_TRANSIENT_PARSE(protect_home, ProtectHome, protect_home_from_string);
7e2a3fcc
YW
1298static BUS_DEFINE_SET_TRANSIENT_PARSE(keyring_mode, ExecKeyringMode, exec_keyring_mode_from_string);
1299static BUS_DEFINE_SET_TRANSIENT_PARSE(preserve_mode, ExecPreserveMode, exec_preserve_mode_from_string);
1300static BUS_DEFINE_SET_TRANSIENT_PARSE_PTR(personality, unsigned long, parse_personality);
1301static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(secure_bits, "i", int32_t, int, "%" PRIi32, secure_bits_to_string_alloc_with_check);
1302static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(capability, "t", uint64_t, uint64_t, "%" PRIu64, capability_set_to_string_alloc);
86c2a9f1 1303static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(namespace_flag, "t", uint64_t, unsigned long, "%" PRIu64, namespace_flags_to_string);
7e2a3fcc
YW
1304static BUS_DEFINE_SET_TRANSIENT_TO_STRING(mount_flags, "t", uint64_t, unsigned long, "%" PRIu64, mount_propagation_flags_to_string_with_check);
1305
c7040b5d
LP
1306int bus_exec_context_set_transient_property(
1307 Unit *u,
1308 ExecContext *c,
1309 const char *name,
1310 sd_bus_message *message,
2e59b241 1311 UnitWriteFlags flags,
c7040b5d
LP
1312 sd_bus_error *error) {
1313
6550c24c
LP
1314 const char *suffix;
1315 int r;
c7040b5d
LP
1316
1317 assert(u);
1318 assert(c);
1319 assert(name);
1320 assert(message);
1321
2e59b241
LP
1322 flags |= UNIT_PRIVATE;
1323
7e2a3fcc 1324 if (streq(name, "User"))
7a8867ab 1325 return bus_set_transient_user_relaxed(u, name, &c->user, message, flags, error);
c7040b5d 1326
7e2a3fcc 1327 if (streq(name, "Group"))
7a8867ab 1328 return bus_set_transient_user_relaxed(u, name, &c->group, message, flags, error);
c7040b5d 1329
7e2a3fcc
YW
1330 if (streq(name, "TTYPath"))
1331 return bus_set_transient_path(u, name, &c->tty_path, message, flags, error);
6f3e7985 1332
7e2a3fcc
YW
1333 if (streq(name, "RootImage"))
1334 return bus_set_transient_path(u, name, &c->root_image, message, flags, error);
76736280 1335
18d73705
LB
1336 if (streq(name, "RootImageOptions")) {
1337 _cleanup_(mount_options_free_allp) MountOptions *options = NULL;
1338 _cleanup_free_ char *format_str = NULL;
1339 const char *mount_options;
1340 unsigned partition_number;
1341
1342 r = sd_bus_message_enter_container(message, 'a', "(us)");
1343 if (r < 0)
1344 return r;
1345
1346 while ((r = sd_bus_message_read(message, "(us)", &partition_number, &mount_options)) > 0) {
1347 _cleanup_free_ char *previous = TAKE_PTR(format_str);
1348 _cleanup_free_ MountOptions *o = NULL;
1349
1350 if (chars_intersect(mount_options, WHITESPACE))
1351 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS,
1352 "Invalid mount options string, contains whitespace character(s): %s", mount_options);
1353
1354 if (asprintf(&format_str, "%s%s%u:%s", strempty(previous), previous ? " " : "", partition_number, mount_options) < 0)
1355 return -ENOMEM;
1356
1357 o = new(MountOptions, 1);
1358 if (!o)
1359 return -ENOMEM;
1360 *o = (MountOptions) {
1361 .partition_number = partition_number,
1362 .options = strdup(mount_options),
1363 };
1364 if (!o->options)
1365 return -ENOMEM;
1366 LIST_APPEND(mount_options, options, TAKE_PTR(o));
1367 }
1368 if (r < 0)
1369 return r;
1370
1371 r = sd_bus_message_exit_container(message);
1372 if (r < 0)
1373 return r;
1374
1375 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
1376 if (LIST_IS_EMPTY(options)) {
1377 c->root_image_options = mount_options_free_all(c->root_image_options);
1378 unit_write_settingf(u, flags, name, "%s=", name);
1379 } else {
1380 LIST_JOIN(mount_options, c->root_image_options, options);
1381 unit_write_settingf(
1382 u, flags|UNIT_ESCAPE_SPECIFIERS, name,
1383 "%s=%s",
1384 name,
1385 format_str);
1386 }
1387 }
1388
1389 return 1;
1390 }
1391
0389f4fa
LB
1392 if (streq(name, "RootHash")) {
1393 const void *roothash_decoded;
1394 size_t roothash_decoded_size;
1395
1396 r = sd_bus_message_read_array(message, 'y', &roothash_decoded, &roothash_decoded_size);
1397 if (r < 0)
1398 return r;
1399
1400 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
1401 _cleanup_free_ char *encoded = NULL;
1402
1403 if (roothash_decoded_size == 0) {
1404 c->root_hash_path = mfree(c->root_hash_path);
1405 c->root_hash = mfree(c->root_hash);
1406 c->root_hash_size = 0;
1407
1408 unit_write_settingf(u, flags, name, "RootHash=");
1409 } else {
1410 _cleanup_free_ void *p;
1411
1412 encoded = hexmem(roothash_decoded, roothash_decoded_size);
1413 if (!encoded)
1414 return -ENOMEM;
1415
1416 p = memdup(roothash_decoded, roothash_decoded_size);
1417 if (!p)
1418 return -ENOMEM;
1419
1420 free_and_replace(c->root_hash, p);
1421 c->root_hash_size = roothash_decoded_size;
1422 c->root_hash_path = mfree(c->root_hash_path);
1423
1424 unit_write_settingf(u, flags, name, "RootHash=%s", encoded);
1425 }
1426 }
1427
1428 return 1;
1429 }
1430
1431 if (streq(name, "RootHashPath")) {
1432 c->root_hash_size = 0;
1433 c->root_hash = mfree(c->root_hash);
1434
1435 return bus_set_transient_path(u, "RootHash", &c->root_hash_path, message, flags, error);
1436 }
1437
d4d55b0d
LB
1438 if (streq(name, "RootHashSignature")) {
1439 const void *roothash_sig_decoded;
1440 size_t roothash_sig_decoded_size;
1441
1442 r = sd_bus_message_read_array(message, 'y', &roothash_sig_decoded, &roothash_sig_decoded_size);
1443 if (r < 0)
1444 return r;
1445
1446 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
1447 _cleanup_free_ char *encoded = NULL;
1448
1449 if (roothash_sig_decoded_size == 0) {
1450 c->root_hash_sig_path = mfree(c->root_hash_sig_path);
1451 c->root_hash_sig = mfree(c->root_hash_sig);
1452 c->root_hash_sig_size = 0;
1453
1454 unit_write_settingf(u, flags, name, "RootHashSignature=");
1455 } else {
1456 _cleanup_free_ void *p;
1457 ssize_t len;
1458
1459 len = base64mem(roothash_sig_decoded, roothash_sig_decoded_size, &encoded);
1460 if (len < 0)
1461 return -ENOMEM;
1462
1463 p = memdup(roothash_sig_decoded, roothash_sig_decoded_size);
1464 if (!p)
1465 return -ENOMEM;
1466
1467 free_and_replace(c->root_hash_sig, p);
1468 c->root_hash_sig_size = roothash_sig_decoded_size;
1469 c->root_hash_sig_path = mfree(c->root_hash_sig_path);
1470
1471 unit_write_settingf(u, flags, name, "RootHashSignature=base64:%s", encoded);
1472 }
1473 }
1474
1475 return 1;
1476 }
1477
1478 if (streq(name, "RootHashSignaturePath")) {
1479 c->root_hash_sig_size = 0;
1480 c->root_hash_sig = mfree(c->root_hash_sig);
1481
1482 return bus_set_transient_path(u, "RootHashSignature", &c->root_hash_sig_path, message, flags, error);
1483 }
1484
0389f4fa
LB
1485 if (streq(name, "RootVerity"))
1486 return bus_set_transient_path(u, name, &c->root_verity, message, flags, error);
1487
7e2a3fcc
YW
1488 if (streq(name, "RootDirectory"))
1489 return bus_set_transient_path(u, name, &c->root_directory, message, flags, error);
c7040b5d 1490
7e2a3fcc
YW
1491 if (streq(name, "SyslogIdentifier"))
1492 return bus_set_transient_string(u, name, &c->syslog_identifier, message, flags, error);
c7040b5d 1493
7e2a3fcc
YW
1494 if (streq(name, "LogLevelMax"))
1495 return bus_set_transient_log_level(u, name, &c->log_level_max, message, flags, error);
1496
90fc172e 1497 if (streq(name, "LogRateLimitIntervalUSec"))
5ac1530e 1498 return bus_set_transient_usec(u, name, &c->log_ratelimit_interval_usec, message, flags, error);
90fc172e
AZ
1499
1500 if (streq(name, "LogRateLimitBurst"))
5ac1530e 1501 return bus_set_transient_unsigned(u, name, &c->log_ratelimit_burst, message, flags, error);
90fc172e 1502
7e2a3fcc
YW
1503 if (streq(name, "Personality"))
1504 return bus_set_transient_personality(u, name, &c->personality, message, flags, error);
1505
7e2a3fcc
YW
1506 if (streq(name, "StandardInput"))
1507 return bus_set_transient_std_input(u, name, &c->std_input, message, flags, error);
1508
1509 if (streq(name, "StandardOutput"))
1510 return bus_set_transient_std_output(u, name, &c->std_output, message, flags, error);
1511
1512 if (streq(name, "StandardError"))
1513 return bus_set_transient_std_output(u, name, &c->std_error, message, flags, error);
1514
1515 if (streq(name, "IgnoreSIGPIPE"))
1516 return bus_set_transient_bool(u, name, &c->ignore_sigpipe, message, flags, error);
1517
1518 if (streq(name, "TTYVHangup"))
1519 return bus_set_transient_bool(u, name, &c->tty_vhangup, message, flags, error);
1520
1521 if (streq(name, "TTYReset"))
1522 return bus_set_transient_bool(u, name, &c->tty_reset, message, flags, error);
1523
1524 if (streq(name, "TTYVTDisallocate"))
1525 return bus_set_transient_bool(u, name, &c->tty_vt_disallocate, message, flags, error);
1526
1527 if (streq(name, "PrivateTmp"))
1528 return bus_set_transient_bool(u, name, &c->private_tmp, message, flags, error);
1529
1530 if (streq(name, "PrivateDevices"))
1531 return bus_set_transient_bool(u, name, &c->private_devices, message, flags, error);
1532
228af36f
LP
1533 if (streq(name, "PrivateMounts"))
1534 return bus_set_transient_bool(u, name, &c->private_mounts, message, flags, error);
1535
7e2a3fcc
YW
1536 if (streq(name, "PrivateNetwork"))
1537 return bus_set_transient_bool(u, name, &c->private_network, message, flags, error);
1538
1539 if (streq(name, "PrivateUsers"))
1540 return bus_set_transient_bool(u, name, &c->private_users, message, flags, error);
1541
1542 if (streq(name, "NoNewPrivileges"))
1543 return bus_set_transient_bool(u, name, &c->no_new_privileges, message, flags, error);
1544
1545 if (streq(name, "SyslogLevelPrefix"))
1546 return bus_set_transient_bool(u, name, &c->syslog_level_prefix, message, flags, error);
1547
1548 if (streq(name, "MemoryDenyWriteExecute"))
1549 return bus_set_transient_bool(u, name, &c->memory_deny_write_execute, message, flags, error);
1550
1551 if (streq(name, "RestrictRealtime"))
1552 return bus_set_transient_bool(u, name, &c->restrict_realtime, message, flags, error);
1553
f69567cb
LP
1554 if (streq(name, "RestrictSUIDSGID"))
1555 return bus_set_transient_bool(u, name, &c->restrict_suid_sgid, message, flags, error);
1556
7e2a3fcc
YW
1557 if (streq(name, "DynamicUser"))
1558 return bus_set_transient_bool(u, name, &c->dynamic_user, message, flags, error);
1559
1560 if (streq(name, "RemoveIPC"))
1561 return bus_set_transient_bool(u, name, &c->remove_ipc, message, flags, error);
1562
1563 if (streq(name, "ProtectKernelTunables"))
1564 return bus_set_transient_bool(u, name, &c->protect_kernel_tunables, message, flags, error);
1565
1566 if (streq(name, "ProtectKernelModules"))
1567 return bus_set_transient_bool(u, name, &c->protect_kernel_modules, message, flags, error);
1568
84703040
KK
1569 if (streq(name, "ProtectKernelLogs"))
1570 return bus_set_transient_bool(u, name, &c->protect_kernel_logs, message, flags, error);
1571
fc64760d
KK
1572 if (streq(name, "ProtectClock"))
1573 return bus_set_transient_bool(u, name, &c->protect_clock, message, flags, error);
1574
7e2a3fcc
YW
1575 if (streq(name, "ProtectControlGroups"))
1576 return bus_set_transient_bool(u, name, &c->protect_control_groups, message, flags, error);
1577
1578 if (streq(name, "MountAPIVFS"))
1579 return bus_set_transient_bool(u, name, &c->mount_apivfs, message, flags, error);
1580
1581 if (streq(name, "CPUSchedulingResetOnFork"))
1582 return bus_set_transient_bool(u, name, &c->cpu_sched_reset_on_fork, message, flags, error);
1583
1584 if (streq(name, "NonBlocking"))
1585 return bus_set_transient_bool(u, name, &c->non_blocking, message, flags, error);
1586
1587 if (streq(name, "LockPersonality"))
1588 return bus_set_transient_bool(u, name, &c->lock_personality, message, flags, error);
1589
aecd5ac6
TM
1590 if (streq(name, "ProtectHostname"))
1591 return bus_set_transient_bool(u, name, &c->protect_hostname, message, flags, error);
1592
7e2a3fcc
YW
1593 if (streq(name, "UtmpIdentifier"))
1594 return bus_set_transient_string(u, name, &c->utmp_id, message, flags, error);
1595
1596 if (streq(name, "UtmpMode"))
1597 return bus_set_transient_utmp_mode(u, name, &c->utmp_mode, message, flags, error);
1598
1599 if (streq(name, "PAMName"))
1600 return bus_set_transient_string(u, name, &c->pam_name, message, flags, error);
1601
1602 if (streq(name, "TimerSlackNSec"))
1603 return bus_set_transient_nsec(u, name, &c->timer_slack_nsec, message, flags, error);
1604
1605 if (streq(name, "ProtectSystem"))
1606 return bus_set_transient_protect_system(u, name, &c->protect_system, message, flags, error);
1607
1608 if (streq(name, "ProtectHome"))
1609 return bus_set_transient_protect_home(u, name, &c->protect_home, message, flags, error);
cffaed83 1610
7e2a3fcc
YW
1611 if (streq(name, "KeyringMode"))
1612 return bus_set_transient_keyring_mode(u, name, &c->keyring_mode, message, flags, error);
1613
1614 if (streq(name, "RuntimeDirectoryPreserve"))
1615 return bus_set_transient_preserve_mode(u, name, &c->runtime_directory_preserve_mode, message, flags, error);
1616
1617 if (streq(name, "UMask"))
1618 return bus_set_transient_mode_t(u, name, &c->umask, message, flags, error);
1619
1620 if (streq(name, "RuntimeDirectoryMode"))
1621 return bus_set_transient_mode_t(u, name, &c->directories[EXEC_DIRECTORY_RUNTIME].mode, message, flags, error);
1622
1623 if (streq(name, "StateDirectoryMode"))
1624 return bus_set_transient_mode_t(u, name, &c->directories[EXEC_DIRECTORY_STATE].mode, message, flags, error);
1625
1626 if (streq(name, "CacheDirectoryMode"))
1627 return bus_set_transient_mode_t(u, name, &c->directories[EXEC_DIRECTORY_CACHE].mode, message, flags, error);
1628
1629 if (streq(name, "LogsDirectoryMode"))
1630 return bus_set_transient_mode_t(u, name, &c->directories[EXEC_DIRECTORY_LOGS].mode, message, flags, error);
1631
1632 if (streq(name, "ConfigurationDirectoryMode"))
1633 return bus_set_transient_mode_t(u, name, &c->directories[EXEC_DIRECTORY_CONFIGURATION].mode, message, flags, error);
1634
1635 if (streq(name, "SELinuxContext"))
1636 return bus_set_transient_string(u, name, &c->selinux_context, message, flags, error);
1637
1638 if (streq(name, "SecureBits"))
1639 return bus_set_transient_secure_bits(u, name, &c->secure_bits, message, flags, error);
1640
1641 if (streq(name, "CapabilityBoundingSet"))
1642 return bus_set_transient_capability(u, name, &c->capability_bounding_set, message, flags, error);
1643
1644 if (streq(name, "AmbientCapabilities"))
1645 return bus_set_transient_capability(u, name, &c->capability_ambient_set, message, flags, error);
1646
7e2a3fcc
YW
1647 if (streq(name, "RestrictNamespaces"))
1648 return bus_set_transient_namespace_flag(u, name, &c->restrict_namespaces, message, flags, error);
1649
1650 if (streq(name, "MountFlags"))
1651 return bus_set_transient_mount_flags(u, name, &c->mount_flags, message, flags, error);
1652
a8d08f39
LP
1653 if (streq(name, "NetworkNamespacePath"))
1654 return bus_set_transient_path(u, name, &c->network_namespace_path, message, flags, error);
1655
7e2a3fcc 1656 if (streq(name, "SupplementaryGroups")) {
cffaed83
YW
1657 _cleanup_strv_free_ char **l = NULL;
1658 char **p;
1659
1660 r = sd_bus_message_read_strv(message, &l);
1661 if (r < 0)
1662 return r;
1663
d2a23692 1664 STRV_FOREACH(p, l)
7a8867ab 1665 if (!isempty(*p) && !valid_user_group_name(*p, VALID_USER_ALLOW_NUMERIC|VALID_USER_RELAX|VALID_USER_WARN))
d2a23692
ZJS
1666 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS,
1667 "Invalid supplementary group names");
cffaed83 1668
2e59b241 1669 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
7b943bb7 1670 if (strv_isempty(l)) {
cffaed83 1671 c->supplementary_groups = strv_free(c->supplementary_groups);
2e59b241 1672 unit_write_settingf(u, flags, name, "%s=", name);
cffaed83
YW
1673 } else {
1674 _cleanup_free_ char *joined = NULL;
1675
1676 r = strv_extend_strv(&c->supplementary_groups, l, true);
1677 if (r < 0)
1678 return -ENOMEM;
1679
1680 joined = strv_join(c->supplementary_groups, " ");
1681 if (!joined)
1682 return -ENOMEM;
1683
2e59b241 1684 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "%s=%s", name, joined);
cffaed83
YW
1685 }
1686 }
1687
1688 return 1;
1689
a8a13575 1690 } else if (streq(name, "SyslogLevel")) {
8d1dd6ab 1691 int32_t level;
a8a13575
EV
1692
1693 r = sd_bus_message_read(message, "i", &level);
1694 if (r < 0)
1695 return r;
1696
e0d6e0fa
EV
1697 if (!log_level_is_valid(level))
1698 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Log level value out of range");
1699
2e59b241 1700 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
a8a13575 1701 c->syslog_priority = (c->syslog_priority & LOG_FACMASK) | level;
2e59b241 1702 unit_write_settingf(u, flags, name, "SyslogLevel=%i", level);
a8a13575
EV
1703 }
1704
460ed929 1705 return 1;
7e2a3fcc 1706
460ed929 1707 } else if (streq(name, "SyslogFacility")) {
8d1dd6ab 1708 int32_t facility;
460ed929
EV
1709
1710 r = sd_bus_message_read(message, "i", &facility);
1711 if (r < 0)
1712 return r;
1713
e0d6e0fa
EV
1714 if (!log_facility_unshifted_is_valid(facility))
1715 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Log facility value out of range");
1716
2e59b241 1717 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
460ed929 1718 c->syslog_priority = (facility << 3) | LOG_PRI(c->syslog_priority);
2e59b241 1719 unit_write_settingf(u, flags, name, "SyslogFacility=%i", facility);
460ed929
EV
1720 }
1721
cffaed83 1722 return 1;
d3070fbd 1723
91dd5f7c
LP
1724 } else if (streq(name, "LogNamespace")) {
1725 const char *n;
1726
1727 r = sd_bus_message_read(message, "s", &n);
1728 if (r < 0)
1729 return r;
1730
1731 if (!isempty(n) && !log_namespace_name_valid(n))
1732 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Log namespace name not valid");
1733
1734 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
1735
1736 if (isempty(n)) {
1737 c->log_namespace = mfree(c->log_namespace);
1738 unit_write_settingf(u, flags, name, "%s=", name);
1739 } else {
1740 r = free_and_strdup(&c->log_namespace, n);
1741 if (r < 0)
1742 return r;
1743
1744 unit_write_settingf(u, flags, name, "%s=%s", name, n);
1745 }
1746 }
1747
1748 return 1;
1749
d3070fbd
LP
1750 } else if (streq(name, "LogExtraFields")) {
1751 size_t n = 0;
1752
1753 r = sd_bus_message_enter_container(message, 'a', "ay");
1754 if (r < 0)
1755 return r;
1756
1757 for (;;) {
1758 _cleanup_free_ void *copy = NULL;
1759 struct iovec *t;
1760 const char *eq;
1761 const void *p;
1762 size_t sz;
1763
1764 /* Note that we expect a byte array for each field, instead of a string. That's because on the
1765 * lower-level journal fields can actually contain binary data and are not restricted to text,
1766 * and we should not "lose precision" in our types on the way. That said, I am pretty sure
1767 * actually encoding binary data as unit metadata is not a good idea. Hence we actually refuse
1768 * any actual binary data, and only accept UTF-8. This allows us to eventually lift this
1769 * limitation, should a good, valid usecase arise. */
1770
1771 r = sd_bus_message_read_array(message, 'y', &p, &sz);
1772 if (r < 0)
1773 return r;
1774 if (r == 0)
1775 break;
1776
1777 if (memchr(p, 0, sz))
1778 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Journal field contains zero byte");
1779
1780 eq = memchr(p, '=', sz);
1781 if (!eq)
1782 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Journal field contains no '=' character");
1783 if (!journal_field_valid(p, eq - (const char*) p, false))
1784 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Journal field invalid");
1785
2e59b241 1786 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
aa484f35 1787 t = reallocarray(c->log_extra_fields, c->n_log_extra_fields+1, sizeof(struct iovec));
d3070fbd
LP
1788 if (!t)
1789 return -ENOMEM;
1790 c->log_extra_fields = t;
1791 }
1792
1793 copy = malloc(sz + 1);
1794 if (!copy)
1795 return -ENOMEM;
1796
1797 memcpy(copy, p, sz);
1798 ((uint8_t*) copy)[sz] = 0;
1799
1800 if (!utf8_is_valid(copy))
1801 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Journal field is not valid UTF-8");
1802
2e59b241 1803 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
d3070fbd 1804 c->log_extra_fields[c->n_log_extra_fields++] = IOVEC_MAKE(copy, sz);
2e59b241 1805 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS|UNIT_ESCAPE_C, name, "LogExtraFields=%s", (char*) copy);
d3070fbd
LP
1806
1807 copy = NULL;
1808 }
1809
1810 n++;
1811 }
1812
1813 r = sd_bus_message_exit_container(message);
1814 if (r < 0)
1815 return r;
1816
2e59b241 1817 if (!UNIT_WRITE_FLAGS_NOOP(flags) && n == 0) {
d3070fbd 1818 exec_context_free_log_extra_fields(c);
2e59b241 1819 unit_write_setting(u, flags, name, "LogExtraFields=");
d3070fbd
LP
1820 }
1821
1822 return 1;
7e2a3fcc 1823 }
cffaed83 1824
349cc4a5 1825#if HAVE_SECCOMP
cffaed83 1826
7e2a3fcc
YW
1827 if (streq(name, "SystemCallErrorNumber"))
1828 return bus_set_transient_errno(u, name, &c->syscall_errno, message, flags, error);
1829
1830 if (streq(name, "SystemCallFilter")) {
6b000af4 1831 int allow_list;
3f856a28 1832 _cleanup_strv_free_ char **l = NULL;
cffaed83
YW
1833
1834 r = sd_bus_message_enter_container(message, 'r', "bas");
1835 if (r < 0)
1836 return r;
1837
6b000af4 1838 r = sd_bus_message_read(message, "b", &allow_list);
cffaed83
YW
1839 if (r < 0)
1840 return r;
1841
1842 r = sd_bus_message_read_strv(message, &l);
1843 if (r < 0)
1844 return r;
1845
1846 r = sd_bus_message_exit_container(message);
1847 if (r < 0)
1848 return r;
1849
2e59b241 1850 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
cffaed83 1851 _cleanup_free_ char *joined = NULL;
6b000af4 1852 SeccompParseFlags invert_flag = allow_list ? 0 : SECCOMP_PARSE_INVERT;
898748d8 1853 char **s;
cffaed83 1854
7b943bb7 1855 if (strv_isempty(l)) {
6b000af4 1856 c->syscall_allow_list = false;
8cfa775f 1857 c->syscall_filter = hashmap_free(c->syscall_filter);
cffaed83 1858
898748d8
YW
1859 unit_write_settingf(u, flags, name, "SystemCallFilter=");
1860 return 1;
1861 }
cffaed83 1862
898748d8
YW
1863 if (!c->syscall_filter) {
1864 c->syscall_filter = hashmap_new(NULL);
1865 if (!c->syscall_filter)
1866 return log_oom();
cffaed83 1867
6b000af4 1868 c->syscall_allow_list = allow_list;
8cfa775f 1869
6b000af4 1870 if (c->syscall_allow_list) {
e7ccdfa8
ZJS
1871 r = seccomp_parse_syscall_filter("@default",
1872 -1,
1873 c->syscall_filter,
72545ae0 1874 SECCOMP_PARSE_PERMISSIVE |
6b000af4 1875 SECCOMP_PARSE_ALLOW_LIST | invert_flag,
58f6ab44
ZJS
1876 u->id,
1877 NULL, 0);
8cfa775f
YW
1878 if (r < 0)
1879 return r;
898748d8
YW
1880 }
1881 }
8cfa775f 1882
898748d8
YW
1883 STRV_FOREACH(s, l) {
1884 _cleanup_free_ char *n = NULL;
1885 int e;
cffaed83 1886
898748d8
YW
1887 r = parse_syscall_and_errno(*s, &n, &e);
1888 if (r < 0)
1889 return r;
cffaed83 1890
e7ccdfa8
ZJS
1891 r = seccomp_parse_syscall_filter(n,
1892 e,
1893 c->syscall_filter,
72545ae0
AZ
1894 SECCOMP_PARSE_LOG | SECCOMP_PARSE_PERMISSIVE |
1895 invert_flag |
6b000af4 1896 (c->syscall_allow_list ? SECCOMP_PARSE_ALLOW_LIST : 0),
58f6ab44
ZJS
1897 u->id,
1898 NULL, 0);
898748d8
YW
1899 if (r < 0)
1900 return r;
cffaed83
YW
1901 }
1902
1903 joined = strv_join(l, " ");
1904 if (!joined)
1905 return -ENOMEM;
1906
6b000af4 1907 unit_write_settingf(u, flags, name, "SystemCallFilter=%s%s", allow_list ? "" : "~", joined);
cffaed83
YW
1908 }
1909
1910 return 1;
1911
1912 } else if (streq(name, "SystemCallArchitectures")) {
1913 _cleanup_strv_free_ char **l = NULL;
1914
1915 r = sd_bus_message_read_strv(message, &l);
1916 if (r < 0)
1917 return r;
1918
2e59b241 1919 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
cffaed83
YW
1920 _cleanup_free_ char *joined = NULL;
1921
7b943bb7 1922 if (strv_isempty(l))
cffaed83
YW
1923 c->syscall_archs = set_free(c->syscall_archs);
1924 else {
1925 char **s;
1926
cffaed83
YW
1927 STRV_FOREACH(s, l) {
1928 uint32_t a;
1929
1930 r = seccomp_arch_from_string(*s, &a);
1931 if (r < 0)
1932 return r;
1933
de7fef4b 1934 r = set_ensure_put(&c->syscall_archs, NULL, UINT32_TO_PTR(a + 1));
cffaed83
YW
1935 if (r < 0)
1936 return r;
1937 }
1938
1939 }
1940
1941 joined = strv_join(l, " ");
1942 if (!joined)
1943 return -ENOMEM;
1944
2e59b241 1945 unit_write_settingf(u, flags, name, "%s=%s", name, joined);
cffaed83
YW
1946 }
1947
1948 return 1;
1949
cffaed83 1950 } else if (streq(name, "RestrictAddressFamilies")) {
6b000af4 1951 int allow_list;
3f856a28 1952 _cleanup_strv_free_ char **l = NULL;
cffaed83
YW
1953
1954 r = sd_bus_message_enter_container(message, 'r', "bas");
1955 if (r < 0)
1956 return r;
1957
6b000af4 1958 r = sd_bus_message_read(message, "b", &allow_list);
cffaed83
YW
1959 if (r < 0)
1960 return r;
1961
1962 r = sd_bus_message_read_strv(message, &l);
1963 if (r < 0)
1964 return r;
1965
1966 r = sd_bus_message_exit_container(message);
1967 if (r < 0)
1968 return r;
1969
2e59b241 1970 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
cffaed83 1971 _cleanup_free_ char *joined = NULL;
9ee896d5 1972 char **s;
cffaed83 1973
7b943bb7 1974 if (strv_isempty(l)) {
6b000af4 1975 c->address_families_allow_list = false;
cffaed83 1976 c->address_families = set_free(c->address_families);
cffaed83 1977
9ee896d5
YW
1978 unit_write_settingf(u, flags, name, "RestrictAddressFamilies=");
1979 return 1;
1980 }
cffaed83 1981
9ee896d5
YW
1982 if (!c->address_families) {
1983 c->address_families = set_new(NULL);
1984 if (!c->address_families)
1985 return log_oom();
cffaed83 1986
6b000af4 1987 c->address_families_allow_list = allow_list;
9ee896d5
YW
1988 }
1989
1990 STRV_FOREACH(s, l) {
1991 int af;
cffaed83 1992
9ee896d5 1993 af = af_from_name(*s);
acf4d158
YW
1994 if (af < 0)
1995 return af;
cffaed83 1996
6b000af4 1997 if (allow_list == c->address_families_allow_list) {
cffaed83
YW
1998 r = set_put(c->address_families, INT_TO_PTR(af));
1999 if (r < 0)
2000 return r;
9ee896d5
YW
2001 } else
2002 (void) set_remove(c->address_families, INT_TO_PTR(af));
cffaed83
YW
2003 }
2004
2005 joined = strv_join(l, " ");
2006 if (!joined)
2007 return -ENOMEM;
2008
6b000af4 2009 unit_write_settingf(u, flags, name, "RestrictAddressFamilies=%s%s", allow_list ? "" : "~", joined);
cffaed83
YW
2010 }
2011
2012 return 1;
7e2a3fcc 2013 }
cffaed83 2014#endif
b070c7c0 2015 if (STR_IN_SET(name, "CPUAffinity", "NUMAMask")) {
cffaed83 2016 const void *a;
bd0abfae 2017 size_t n;
b070c7c0 2018 bool affinity = streq(name, "CPUAffinity");
c367f996 2019 _cleanup_(cpu_set_reset) CPUSet set = {};
cffaed83
YW
2020
2021 r = sd_bus_message_read_array(message, 'y', &a, &n);
2022 if (r < 0)
2023 return r;
2024
c367f996
MS
2025 r = cpu_set_from_dbus(a, n, &set);
2026 if (r < 0)
2027 return r;
2028
2e59b241 2029 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
cffaed83 2030 if (n == 0) {
b070c7c0 2031 cpu_set_reset(affinity ? &c->cpu_set : &c->numa_policy.nodes);
2e59b241 2032 unit_write_settingf(u, flags, name, "%s=", name);
cffaed83
YW
2033 } else {
2034 _cleanup_free_ char *str = NULL;
cffaed83 2035
0985c7c4 2036 str = cpu_set_to_string(&set);
a832893f
ZJS
2037 if (!str)
2038 return -ENOMEM;
cffaed83 2039
0985c7c4
ZJS
2040 /* We forego any optimizations here, and always create the structure using
2041 * cpu_set_add_all(), because we don't want to care if the existing size we
2042 * got over dbus is appropriate. */
b070c7c0 2043 r = cpu_set_add_all(affinity ? &c->cpu_set : &c->numa_policy.nodes, &set);
0985c7c4
ZJS
2044 if (r < 0)
2045 return r;
501941aa 2046
2e59b241 2047 unit_write_settingf(u, flags, name, "%s=%s", name, str);
cffaed83
YW
2048 }
2049 }
2050
c7040b5d
LP
2051 return 1;
2052
e2b2fb7f
MS
2053 } else if (streq(name, "CPUAffinityFromNUMA")) {
2054 int q;
2055
2056 r = sd_bus_message_read_basic(message, 'b', &q);
2057 if (r < 0)
2058 return r;
2059
2060 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2061 c->cpu_affinity_from_numa = q;
2062 unit_write_settingf(u, flags, name, "%s=%s", "CPUAffinity", "numa");
2063 }
2064
2065 return 1;
2066
b070c7c0
MS
2067 } else if (streq(name, "NUMAPolicy")) {
2068 int32_t type;
2069
2070 r = sd_bus_message_read(message, "i", &type);
2071 if (r < 0)
2072 return r;
2073
2074 if (!mpol_is_valid(type))
2075 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid NUMAPolicy value: %i", type);
2076
2077 if (!UNIT_WRITE_FLAGS_NOOP(flags))
2078 c->numa_policy.type = type;
2079
2080 return 1;
e2b2fb7f 2081
c250bf67
YW
2082 } else if (streq(name, "Nice")) {
2083 int32_t q;
2084
2085 r = sd_bus_message_read(message, "i", &q);
2086 if (r < 0)
2087 return r;
2088
2089 if (!nice_is_valid(q))
2090 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid Nice value: %i", q);
2091
2092 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2093 c->nice = q;
2094 c->nice_set = true;
2095
2096 unit_write_settingf(u, flags, name, "Nice=%i", q);
2097 }
2098
2099 return 1;
2100
2101 } else if (streq(name, "CPUSchedulingPolicy")) {
2102 int32_t q;
2103
2104 r = sd_bus_message_read(message, "i", &q);
2105 if (r < 0)
2106 return r;
2107
2108 if (!sched_policy_is_valid(q))
2109 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid CPU scheduling policy: %i", q);
2110
2111 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2112 _cleanup_free_ char *s = NULL;
2113
2114 r = sched_policy_to_string_alloc(q, &s);
2115 if (r < 0)
2116 return r;
2117
2118 c->cpu_sched_policy = q;
2119 c->cpu_sched_priority = CLAMP(c->cpu_sched_priority, sched_get_priority_min(q), sched_get_priority_max(q));
2120 c->cpu_sched_set = true;
2121
2122 unit_write_settingf(u, flags, name, "CPUSchedulingPolicy=%s", s);
2123 }
2124
2125 return 1;
2126
2127 } else if (streq(name, "CPUSchedulingPriority")) {
2128 int32_t p, min, max;
2129
2130 r = sd_bus_message_read(message, "i", &p);
2131 if (r < 0)
2132 return r;
2133
2134 min = sched_get_priority_min(c->cpu_sched_policy);
2135 max = sched_get_priority_max(c->cpu_sched_policy);
2136 if (p < min || p > max)
2137 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid CPU scheduling priority: %i", p);
2138
2139 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2140 c->cpu_sched_priority = p;
2141 c->cpu_sched_set = true;
2142
2143 unit_write_settingf(u, flags, name, "CPUSchedulingPriority=%i", p);
2144 }
2145
2146 return 1;
2147
7f452159
LP
2148 } else if (streq(name, "IOSchedulingClass")) {
2149 int32_t q;
2150
2151 r = sd_bus_message_read(message, "i", &q);
2152 if (r < 0)
2153 return r;
2154
2155 if (!ioprio_class_is_valid(q))
2156 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid IO scheduling class: %i", q);
2157
2e59b241 2158 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
7f452159
LP
2159 _cleanup_free_ char *s = NULL;
2160
2161 r = ioprio_class_to_string_alloc(q, &s);
2162 if (r < 0)
2163 return r;
2164
2165 c->ioprio = IOPRIO_PRIO_VALUE(q, IOPRIO_PRIO_DATA(c->ioprio));
2166 c->ioprio_set = true;
2167
2e59b241 2168 unit_write_settingf(u, flags, name, "IOSchedulingClass=%s", s);
7f452159
LP
2169 }
2170
2171 return 1;
2172
2173 } else if (streq(name, "IOSchedulingPriority")) {
2174 int32_t p;
2175
2176 r = sd_bus_message_read(message, "i", &p);
2177 if (r < 0)
2178 return r;
2179
2180 if (!ioprio_priority_is_valid(p))
2181 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid IO scheduling priority: %i", p);
2182
2e59b241 2183 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
7f452159
LP
2184 c->ioprio = IOPRIO_PRIO_VALUE(IOPRIO_PRIO_CLASS(c->ioprio), p);
2185 c->ioprio_set = true;
2186
2e59b241 2187 unit_write_settingf(u, flags, name, "IOSchedulingPriority=%i", p);
7f452159
LP
2188 }
2189
2190 return 1;
2191
5f5d8eab
LP
2192 } else if (streq(name, "WorkingDirectory")) {
2193 const char *s;
2194 bool missing_ok;
2195
2196 r = sd_bus_message_read(message, "s", &s);
2197 if (r < 0)
2198 return r;
2199
2200 if (s[0] == '-') {
2201 missing_ok = true;
2202 s++;
2203 } else
2204 missing_ok = false;
2205
d6ff82d3 2206 if (!isempty(s) && !streq(s, "~") && !path_is_absolute(s))
5f5d8eab
LP
2207 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "WorkingDirectory= expects an absolute path or '~'");
2208
2e59b241 2209 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
5f5d8eab
LP
2210 if (streq(s, "~")) {
2211 c->working_directory = mfree(c->working_directory);
2212 c->working_directory_home = true;
2213 } else {
d6ff82d3 2214 r = free_and_strdup(&c->working_directory, empty_to_null(s));
5f5d8eab
LP
2215 if (r < 0)
2216 return r;
2217
2218 c->working_directory_home = false;
2219 }
2220
2221 c->working_directory_missing_ok = missing_ok;
2e59b241 2222 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "WorkingDirectory=%s%s", missing_ok ? "-" : "", s);
5f5d8eab
LP
2223 }
2224
2225 return 1;
2226
52c239d7
LB
2227 } else if (STR_IN_SET(name,
2228 "StandardInputFileDescriptorName", "StandardOutputFileDescriptorName", "StandardErrorFileDescriptorName")) {
2229 const char *s;
2230
2231 r = sd_bus_message_read(message, "s", &s);
2232 if (r < 0)
2233 return r;
2234
d6ff82d3 2235 if (!isempty(s) && !fdname_is_valid(s))
52c239d7
LB
2236 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid file descriptor name");
2237
2e59b241 2238 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
5073ff6b 2239
52c239d7 2240 if (streq(name, "StandardInputFileDescriptorName")) {
d6ff82d3 2241 r = free_and_strdup(c->stdio_fdname + STDIN_FILENO, empty_to_null(s));
52c239d7
LB
2242 if (r < 0)
2243 return r;
5073ff6b 2244
0664775c 2245 c->std_input = EXEC_INPUT_NAMED_FD;
2e59b241 2246 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardInput=fd:%s", exec_context_fdname(c, STDIN_FILENO));
5073ff6b 2247
52c239d7 2248 } else if (streq(name, "StandardOutputFileDescriptorName")) {
d6ff82d3 2249 r = free_and_strdup(c->stdio_fdname + STDOUT_FILENO, empty_to_null(s));
52c239d7
LB
2250 if (r < 0)
2251 return r;
5073ff6b 2252
52c239d7 2253 c->std_output = EXEC_OUTPUT_NAMED_FD;
2e59b241 2254 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardOutput=fd:%s", exec_context_fdname(c, STDOUT_FILENO));
0664775c
LP
2255
2256 } else {
2257 assert(streq(name, "StandardErrorFileDescriptorName"));
5073ff6b 2258
d6ff82d3 2259 r = free_and_strdup(&c->stdio_fdname[STDERR_FILENO], empty_to_null(s));
52c239d7
LB
2260 if (r < 0)
2261 return r;
5073ff6b 2262
52c239d7 2263 c->std_error = EXEC_OUTPUT_NAMED_FD;
2e59b241 2264 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardError=fd:%s", exec_context_fdname(c, STDERR_FILENO));
52c239d7
LB
2265 }
2266 }
2267
2268 return 1;
2269
566b7d23
ZD
2270 } else if (STR_IN_SET(name,
2271 "StandardInputFile",
922ce049
LP
2272 "StandardOutputFile", "StandardOutputFileToAppend",
2273 "StandardErrorFile", "StandardErrorFileToAppend")) {
2038c3f5
LP
2274 const char *s;
2275
2276 r = sd_bus_message_read(message, "s", &s);
2277 if (r < 0)
2278 return r;
2279
d6ff82d3
YW
2280 if (!isempty(s)) {
2281 if (!path_is_absolute(s))
2282 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path %s is not absolute", s);
2283 if (!path_is_normalized(s))
2284 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path %s is not normalized", s);
2285 }
2038c3f5 2286
2e59b241 2287 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2038c3f5
LP
2288
2289 if (streq(name, "StandardInputFile")) {
d6ff82d3 2290 r = free_and_strdup(&c->stdio_file[STDIN_FILENO], empty_to_null(s));
52c239d7
LB
2291 if (r < 0)
2292 return r;
2038c3f5
LP
2293
2294 c->std_input = EXEC_INPUT_FILE;
2e59b241 2295 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardInput=file:%s", s);
2038c3f5 2296
566b7d23 2297 } else if (STR_IN_SET(name, "StandardOutputFile", "StandardOutputFileToAppend")) {
d6ff82d3 2298 r = free_and_strdup(&c->stdio_file[STDOUT_FILENO], empty_to_null(s));
2038c3f5
LP
2299 if (r < 0)
2300 return r;
2301
566b7d23
ZD
2302 if (streq(name, "StandardOutputFile")) {
2303 c->std_output = EXEC_OUTPUT_FILE;
2304 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardOutput=file:%s", s);
2305 } else {
2306 assert(streq(name, "StandardOutputFileToAppend"));
2307 c->std_output = EXEC_OUTPUT_FILE_APPEND;
2308 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardOutput=append:%s", s);
2309 }
2038c3f5 2310 } else {
566b7d23 2311 assert(STR_IN_SET(name, "StandardErrorFile", "StandardErrorFileToAppend"));
2038c3f5 2312
d6ff82d3 2313 r = free_and_strdup(&c->stdio_file[STDERR_FILENO], empty_to_null(s));
2038c3f5
LP
2314 if (r < 0)
2315 return r;
2316
566b7d23
ZD
2317 if (streq(name, "StandardErrorFile")) {
2318 c->std_error = EXEC_OUTPUT_FILE;
1704fba9 2319 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardError=file:%s", s);
566b7d23 2320 } else {
dbe6c4b6
LP
2321 assert(streq(name, "StandardErrorFileToAppend"));
2322 c->std_error = EXEC_OUTPUT_FILE_APPEND;
1704fba9 2323 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardError=append:%s", s);
566b7d23 2324 }
2038c3f5
LP
2325 }
2326 }
2327
2328 return 1;
2329
08f3be7a
LP
2330 } else if (streq(name, "StandardInputData")) {
2331 const void *p;
2332 size_t sz;
2333
2334 r = sd_bus_message_read_array(message, 'y', &p, &sz);
2335 if (r < 0)
2336 return r;
2337
2e59b241 2338 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
08f3be7a
LP
2339 _cleanup_free_ char *encoded = NULL;
2340
2341 if (sz == 0) {
2342 c->stdin_data = mfree(c->stdin_data);
2343 c->stdin_data_size = 0;
2344
2e59b241 2345 unit_write_settingf(u, flags, name, "StandardInputData=");
08f3be7a
LP
2346 } else {
2347 void *q;
2348 ssize_t n;
2349
2350 if (c->stdin_data_size + sz < c->stdin_data_size || /* check for overflow */
2351 c->stdin_data_size + sz > EXEC_STDIN_DATA_MAX)
2352 return -E2BIG;
2353
2354 n = base64mem(p, sz, &encoded);
2355 if (n < 0)
2356 return (int) n;
2357
2358 q = realloc(c->stdin_data, c->stdin_data_size + sz);
2359 if (!q)
2360 return -ENOMEM;
2361
2362 memcpy((uint8_t*) q + c->stdin_data_size, p, sz);
2363
2364 c->stdin_data = q;
2365 c->stdin_data_size += sz;
2366
2e59b241 2367 unit_write_settingf(u, flags, name, "StandardInputData=%s", encoded);
52c239d7
LB
2368 }
2369 }
2370
2371 return 1;
2372
c7040b5d
LP
2373 } else if (streq(name, "Environment")) {
2374
6171b822 2375 _cleanup_strv_free_ char **l = NULL;
c7040b5d
LP
2376
2377 r = sd_bus_message_read_strv(message, &l);
2378 if (r < 0)
2379 return r;
2380
6171b822 2381 if (!strv_env_is_valid(l))
1c68232e
LP
2382 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid environment block.");
2383
2e59b241 2384 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
7b943bb7 2385 if (strv_isempty(l)) {
e9876fc9 2386 c->environment = strv_free(c->environment);
2e59b241 2387 unit_write_setting(u, flags, name, "Environment=");
e9876fc9 2388 } else {
f900f582
ZJS
2389 _cleanup_free_ char *joined = NULL;
2390 char **e;
2391
2e59b241
LP
2392 joined = unit_concat_strv(l, UNIT_ESCAPE_SPECIFIERS|UNIT_ESCAPE_C);
2393 if (!joined)
2394 return -ENOMEM;
2395
6171b822 2396 e = strv_env_merge(2, c->environment, l);
e9876fc9
EV
2397 if (!e)
2398 return -ENOMEM;
c7040b5d 2399
130d3d22 2400 strv_free_and_replace(c->environment, e);
2e59b241 2401 unit_write_settingf(u, flags, name, "Environment=%s", joined);
e9876fc9 2402 }
c7040b5d
LP
2403 }
2404
d584f638
LP
2405 return 1;
2406
00819cc1
LP
2407 } else if (streq(name, "UnsetEnvironment")) {
2408
6171b822 2409 _cleanup_strv_free_ char **l = NULL;
00819cc1
LP
2410
2411 r = sd_bus_message_read_strv(message, &l);
2412 if (r < 0)
2413 return r;
2414
6171b822 2415 if (!strv_env_name_or_assignment_is_valid(l))
00819cc1
LP
2416 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid UnsetEnvironment= list.");
2417
2e59b241 2418 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
7b943bb7 2419 if (strv_isempty(l)) {
00819cc1 2420 c->unset_environment = strv_free(c->unset_environment);
2e59b241 2421 unit_write_setting(u, flags, name, "UnsetEnvironment=");
00819cc1
LP
2422 } else {
2423 _cleanup_free_ char *joined = NULL;
2424 char **e;
2425
2e59b241
LP
2426 joined = unit_concat_strv(l, UNIT_ESCAPE_SPECIFIERS|UNIT_ESCAPE_C);
2427 if (!joined)
2428 return -ENOMEM;
2429
6171b822 2430 e = strv_env_merge(2, c->unset_environment, l);
00819cc1
LP
2431 if (!e)
2432 return -ENOMEM;
2433
130d3d22 2434 strv_free_and_replace(c->unset_environment, e);
2e59b241 2435 unit_write_settingf(u, flags, name, "UnsetEnvironment=%s", joined);
00819cc1
LP
2436 }
2437 }
2438
2439 return 1;
2440
6b862936
EV
2441 } else if (streq(name, "OOMScoreAdjust")) {
2442 int oa;
2443
2444 r = sd_bus_message_read(message, "i", &oa);
2445 if (r < 0)
2446 return r;
2447
2448 if (!oom_score_adjust_is_valid(oa))
2449 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "OOM score adjust value out of range");
2450
2e59b241 2451 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
6b862936
EV
2452 c->oom_score_adjust = oa;
2453 c->oom_score_adjust_set = true;
2e59b241 2454 unit_write_settingf(u, flags, name, "OOMScoreAdjust=%i", oa);
6b862936
EV
2455 }
2456
2457 return 1;
2458
ad21e542
ZJS
2459 } else if (streq(name, "CoredumpFilter")) {
2460 uint64_t f;
2461
2462 r = sd_bus_message_read(message, "t", &f);
2463 if (r < 0)
2464 return r;
2465
2466 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2467 c->coredump_filter = f;
2468 c->coredump_filter_set = true;
2469 unit_write_settingf(u, flags, name, "CoredumpFilter=0x%"PRIx64, f);
2470 }
2471
2472 return 1;
2473
ceb728cf
NC
2474 } else if (streq(name, "EnvironmentFiles")) {
2475
2476 _cleanup_free_ char *joined = NULL;
2477 _cleanup_fclose_ FILE *f = NULL;
9b531f04 2478 _cleanup_strv_free_ char **l = NULL;
ceb728cf 2479 size_t size = 0;
2229f656 2480 char **i;
ceb728cf
NC
2481
2482 r = sd_bus_message_enter_container(message, 'a', "(sb)");
2483 if (r < 0)
2484 return r;
2485
2fe21124 2486 f = open_memstream_unlocked(&joined, &size);
ceb728cf
NC
2487 if (!f)
2488 return -ENOMEM;
2489
2e59b241
LP
2490 fputs("EnvironmentFile=\n", f);
2491
2492 STRV_FOREACH(i, c->environment_files) {
2493 _cleanup_free_ char *q = NULL;
2494
2495 q = specifier_escape(*i);
2496 if (!q)
2497 return -ENOMEM;
2498
2499 fprintf(f, "EnvironmentFile=%s\n", q);
2500 }
ceb728cf
NC
2501
2502 while ((r = sd_bus_message_enter_container(message, 'r', "sb")) > 0) {
2503 const char *path;
2504 int b;
2505
ceb728cf
NC
2506 r = sd_bus_message_read(message, "sb", &path, &b);
2507 if (r < 0)
2508 return r;
2509
2510 r = sd_bus_message_exit_container(message);
2511 if (r < 0)
2512 return r;
2513
d2d6c096
LP
2514 if (!path_is_absolute(path))
2515 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path %s is not absolute.", path);
ceb728cf 2516
2e59b241 2517 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
6abdec98 2518 _cleanup_free_ char *q = NULL, *buf = NULL;
ceb728cf 2519
605405c6 2520 buf = strjoin(b ? "-" : "", path);
2229f656 2521 if (!buf)
ceb728cf
NC
2522 return -ENOMEM;
2523
2e59b241 2524 q = specifier_escape(buf);
6abdec98 2525 if (!q)
2e59b241 2526 return -ENOMEM;
2e59b241
LP
2527
2528 fprintf(f, "EnvironmentFile=%s\n", q);
ceb728cf 2529
6abdec98 2530 r = strv_consume(&l, TAKE_PTR(buf));
ceb728cf
NC
2531 if (r < 0)
2532 return r;
2533 }
2534 }
2535 if (r < 0)
2536 return r;
2537
b0830e21
LP
2538 r = sd_bus_message_exit_container(message);
2539 if (r < 0)
2540 return r;
2541
2229f656
LP
2542 r = fflush_and_check(f);
2543 if (r < 0)
2544 return r;
ceb728cf 2545
2e59b241 2546 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2229f656
LP
2547 if (strv_isempty(l)) {
2548 c->environment_files = strv_free(c->environment_files);
2e59b241 2549 unit_write_setting(u, flags, name, "EnvironmentFile=");
2229f656
LP
2550 } else {
2551 r = strv_extend_strv(&c->environment_files, l, true);
2552 if (r < 0)
2553 return r;
2554
2e59b241 2555 unit_write_setting(u, flags, name, joined);
2229f656
LP
2556 }
2557 }
ceb728cf 2558
ceb728cf
NC
2559 return 1;
2560
b4c14404
FB
2561 } else if (streq(name, "PassEnvironment")) {
2562
6171b822 2563 _cleanup_strv_free_ char **l = NULL;
b4c14404
FB
2564
2565 r = sd_bus_message_read_strv(message, &l);
2566 if (r < 0)
2567 return r;
2568
6171b822 2569 if (!strv_env_name_is_valid(l))
00819cc1 2570 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid PassEnvironment= block.");
b4c14404 2571
2e59b241 2572 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
b4c14404
FB
2573 if (strv_isempty(l)) {
2574 c->pass_environment = strv_free(c->pass_environment);
2e59b241 2575 unit_write_setting(u, flags, name, "PassEnvironment=");
b4c14404
FB
2576 } else {
2577 _cleanup_free_ char *joined = NULL;
2578
9d4f242a
YW
2579 r = strv_extend_strv(&c->pass_environment, l, true);
2580 if (r < 0)
2581 return r;
2582
41de9cc2 2583 /* We write just the new settings out to file, with unresolved specifiers. */
2e59b241 2584 joined = unit_concat_strv(l, UNIT_ESCAPE_SPECIFIERS);
b4c14404
FB
2585 if (!joined)
2586 return -ENOMEM;
2587
2e59b241 2588 unit_write_settingf(u, flags, name, "PassEnvironment=%s", joined);
b4c14404
FB
2589 }
2590 }
2591
2592 return 1;
2593
2a624c36
AP
2594 } else if (STR_IN_SET(name, "ReadWriteDirectories", "ReadOnlyDirectories", "InaccessibleDirectories",
2595 "ReadWritePaths", "ReadOnlyPaths", "InaccessiblePaths")) {
08596068
EV
2596 _cleanup_strv_free_ char **l = NULL;
2597 char ***dirs;
2598 char **p;
2599
2600 r = sd_bus_message_read_strv(message, &l);
2601 if (r < 0)
2602 return r;
2603
2604 STRV_FOREACH(p, l) {
e7bcff4e 2605 char *i = *p;
20b7a007
LP
2606 size_t offset;
2607
20b7a007
LP
2608 offset = i[0] == '-';
2609 offset += i[offset] == '+';
2610 if (!path_is_absolute(i + offset))
08596068 2611 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid %s", name);
e7bcff4e 2612
858d36c1 2613 path_simplify(i + offset, false);
08596068
EV
2614 }
2615
2e59b241 2616 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
c4b41707
AP
2617 if (STR_IN_SET(name, "ReadWriteDirectories", "ReadWritePaths"))
2618 dirs = &c->read_write_paths;
2619 else if (STR_IN_SET(name, "ReadOnlyDirectories", "ReadOnlyPaths"))
2620 dirs = &c->read_only_paths;
2621 else /* "InaccessiblePaths" */
2622 dirs = &c->inaccessible_paths;
08596068 2623
7b943bb7 2624 if (strv_isempty(l)) {
08596068 2625 *dirs = strv_free(*dirs);
2e59b241 2626 unit_write_settingf(u, flags, name, "%s=", name);
08596068 2627 } else {
2e59b241 2628 _cleanup_free_ char *joined = NULL;
08596068 2629
2e59b241 2630 joined = unit_concat_strv(l, UNIT_ESCAPE_SPECIFIERS);
08596068
EV
2631 if (!joined)
2632 return -ENOMEM;
2633
2e59b241
LP
2634 r = strv_extend_strv(dirs, l, true);
2635 if (r < 0)
2636 return -ENOMEM;
08596068 2637
2e59b241
LP
2638 unit_write_settingf(u, flags, name, "%s=%s", name, joined);
2639 }
08596068
EV
2640 }
2641
2642 return 1;
2643
3536f49e 2644 } else if (STR_IN_SET(name, "RuntimeDirectory", "StateDirectory", "CacheDirectory", "LogsDirectory", "ConfigurationDirectory")) {
fa21b5e3
EV
2645 _cleanup_strv_free_ char **l = NULL;
2646 char **p;
2647
2648 r = sd_bus_message_read_strv(message, &l);
2649 if (r < 0)
2650 return r;
2651
2652 STRV_FOREACH(p, l) {
8994a117
YW
2653 if (!path_is_normalized(*p))
2654 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "%s= path is not normalized: %s", name, *p);
2655
2656 if (path_is_absolute(*p))
2657 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "%s= path is absolute: %s", name, *p);
2658
2659 if (path_startswith(*p, "private"))
2660 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "%s= path can't be 'private': %s", name, *p);
fa21b5e3
EV
2661 }
2662
2e59b241 2663 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
3536f49e 2664 ExecDirectoryType i;
b1ea85dc 2665 ExecDirectory *d;
3536f49e 2666
b1ea85dc
LP
2667 assert_se((i = exec_directory_type_from_string(name)) >= 0);
2668 d = c->directories + i;
fa21b5e3
EV
2669
2670 if (strv_isempty(l)) {
b1ea85dc 2671 d->paths = strv_free(d->paths);
2e59b241 2672 unit_write_settingf(u, flags, name, "%s=", name);
fa21b5e3 2673 } else {
2e59b241
LP
2674 _cleanup_free_ char *joined = NULL;
2675
b1ea85dc 2676 r = strv_extend_strv(&d->paths, l, true);
fa21b5e3 2677 if (r < 0)
c425c7c2 2678 return r;
fa21b5e3 2679
2e59b241 2680 joined = unit_concat_strv(l, UNIT_ESCAPE_SPECIFIERS);
fa21b5e3
EV
2681 if (!joined)
2682 return -ENOMEM;
2683
2e59b241 2684 unit_write_settingf(u, flags, name, "%s=%s", name, joined);
fa21b5e3
EV
2685 }
2686 }
2687
2688 return 1;
2689
cffaed83
YW
2690 } else if (STR_IN_SET(name, "AppArmorProfile", "SmackProcessLabel")) {
2691 int ignore;
2692 const char *s;
2693
280921f2 2694 r = sd_bus_message_read(message, "(bs)", &ignore, &s);
cffaed83
YW
2695 if (r < 0)
2696 return r;
2697
2e59b241 2698 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
cffaed83
YW
2699 char **p;
2700 bool *b;
2701
2702 if (streq(name, "AppArmorProfile")) {
2703 p = &c->apparmor_profile;
2704 b = &c->apparmor_profile_ignore;
2705 } else { /* "SmackProcessLabel" */
2706 p = &c->smack_process_label;
2707 b = &c->smack_process_label_ignore;
2708 }
2709
2710 if (isempty(s)) {
2711 *p = mfree(*p);
2712 *b = false;
2713 } else {
2714 if (free_and_strdup(p, s) < 0)
2715 return -ENOMEM;
2716 *b = ignore;
2717 }
2718
2e59b241 2719 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "%s=%s%s", name, ignore ? "-" : "", strempty(s));
cffaed83
YW
2720 }
2721
2722 return 1;
2723
d2d6c096 2724 } else if (STR_IN_SET(name, "BindPaths", "BindReadOnlyPaths")) {
ec04aef4 2725 char *source, *destination;
4ff4c98a
YW
2726 int ignore_enoent;
2727 uint64_t mount_flags;
2728 bool empty = true;
d2d6c096
LP
2729
2730 r = sd_bus_message_enter_container(message, 'a', "(ssbt)");
2731 if (r < 0)
2732 return r;
2733
4ff4c98a 2734 while ((r = sd_bus_message_read(message, "(ssbt)", &source, &destination, &ignore_enoent, &mount_flags)) > 0) {
d2d6c096
LP
2735
2736 if (!path_is_absolute(source))
2737 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Source path %s is not absolute.", source);
2738 if (!path_is_absolute(destination))
91d910e3 2739 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Destination path %s is not absolute.", destination);
d2d6c096
LP
2740 if (!IN_SET(mount_flags, 0, MS_REC))
2741 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Unknown mount flags.");
2742
2e59b241 2743 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
d2d6c096
LP
2744 r = bind_mount_add(&c->bind_mounts, &c->n_bind_mounts,
2745 &(BindMount) {
ec04aef4
TM
2746 .source = source,
2747 .destination = destination,
d2d6c096
LP
2748 .read_only = !!strstr(name, "ReadOnly"),
2749 .recursive = !!(mount_flags & MS_REC),
2750 .ignore_enoent = ignore_enoent,
2751 });
2752 if (r < 0)
2753 return r;
2754
2e59b241
LP
2755 unit_write_settingf(
2756 u, flags|UNIT_ESCAPE_SPECIFIERS, name,
d2d6c096
LP
2757 "%s=%s%s:%s:%s",
2758 name,
2759 ignore_enoent ? "-" : "",
2760 source,
2761 destination,
2762 (mount_flags & MS_REC) ? "rbind" : "norbind");
2763 }
2764
2765 empty = false;
2766 }
2767 if (r < 0)
2768 return r;
2769
2770 r = sd_bus_message_exit_container(message);
2771 if (r < 0)
2772 return r;
2773
2774 if (empty) {
2775 bind_mount_free_many(c->bind_mounts, c->n_bind_mounts);
2776 c->bind_mounts = NULL;
2777 c->n_bind_mounts = 0;
2e59b241
LP
2778
2779 unit_write_settingf(u, flags, name, "%s=", name);
d2d6c096
LP
2780 }
2781
784ad252
YW
2782 return 1;
2783
2784 } else if (streq(name, "TemporaryFileSystem")) {
2785 const char *path, *options;
2786 bool empty = true;
2787
2788 r = sd_bus_message_enter_container(message, 'a', "(ss)");
2789 if (r < 0)
2790 return r;
2791
2792 while ((r = sd_bus_message_read(message, "(ss)", &path, &options)) > 0) {
2793
2794 if (!path_is_absolute(path))
2795 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Mount point %s is not absolute.", path);
2796
2797 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2798 r = temporary_filesystem_add(&c->temporary_filesystems, &c->n_temporary_filesystems, path, options);
2799 if (r < 0)
2800 return r;
2801
2802 unit_write_settingf(
2803 u, flags|UNIT_ESCAPE_SPECIFIERS, name,
2804 "%s=%s:%s",
2805 name,
2806 path,
2807 options);
2808 }
2809
2810 empty = false;
2811 }
2812 if (r < 0)
2813 return r;
2814
2815 r = sd_bus_message_exit_container(message);
2816 if (r < 0)
2817 return r;
2818
2819 if (empty) {
2820 temporary_filesystem_free_many(c->temporary_filesystems, c->n_temporary_filesystems);
2821 c->temporary_filesystems = NULL;
2822 c->n_temporary_filesystems = 0;
2823
2824 unit_write_settingf(u, flags, name, "%s=", name);
2825 }
2826
83555251 2827 return 1;
d2d6c096 2828
6550c24c
LP
2829 } else if ((suffix = startswith(name, "Limit"))) {
2830 const char *soft = NULL;
2831 int ri;
cab2aca3 2832
6550c24c
LP
2833 ri = rlimit_from_string(suffix);
2834 if (ri < 0) {
2835 soft = endswith(suffix, "Soft");
2836 if (soft) {
2837 const char *n;
cab2aca3 2838
6550c24c
LP
2839 n = strndupa(suffix, soft - suffix);
2840 ri = rlimit_from_string(n);
2841 if (ri >= 0)
2842 name = strjoina("Limit", n);
2843 }
cab2aca3 2844 }
d584f638 2845
6550c24c
LP
2846 if (ri >= 0) {
2847 uint64_t rl;
2848 rlim_t x;
d584f638 2849
6550c24c 2850 r = sd_bus_message_read(message, "t", &rl);
cab2aca3
LP
2851 if (r < 0)
2852 return r;
d584f638 2853
6550c24c
LP
2854 if (rl == (uint64_t) -1)
2855 x = RLIM_INFINITY;
cab2aca3 2856 else {
6550c24c
LP
2857 x = (rlim_t) rl;
2858
2859 if ((uint64_t) x != rl)
2860 return -ERANGE;
d584f638
LP
2861 }
2862
6550c24c
LP
2863 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2864 _cleanup_free_ char *f = NULL;
2865 struct rlimit nl;
2866
2867 if (c->rlimit[ri]) {
2868 nl = *c->rlimit[ri];
2869
2870 if (soft)
2871 nl.rlim_cur = x;
2872 else
2873 nl.rlim_max = x;
2874 } else
2875 /* When the resource limit is not initialized yet, then assign the value to both fields */
2876 nl = (struct rlimit) {
2877 .rlim_cur = x,
2878 .rlim_max = x,
2879 };
2880
2881 r = rlimit_format(&nl, &f);
2882 if (r < 0)
2883 return r;
2884
2885 if (c->rlimit[ri])
2886 *c->rlimit[ri] = nl;
2887 else {
2888 c->rlimit[ri] = newdup(struct rlimit, &nl, 1);
2889 if (!c->rlimit[ri])
2890 return -ENOMEM;
2891 }
2892
2893 unit_write_settingf(u, flags, name, "%s=%s", name, f);
2894 }
2895
2896 return 1;
d584f638
LP
2897 }
2898
c7040b5d
LP
2899 }
2900
2901 return 0;
2902}