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