]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/core/dbus-execute.c
core/execute: always set $USER and introduce SetLoginEnvironment=
[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),
854eca4a 1276 SD_BUS_PROPERTY("SetLoginEnvironment", "b", bus_property_get_tristate, offsetof(ExecContext, set_login_environment), SD_BUS_VTABLE_PROPERTY_CONST),
00d9ef85 1277 SD_BUS_PROPERTY("RemoveIPC", "b", bus_property_get_bool, offsetof(ExecContext, remove_ipc), SD_BUS_VTABLE_PROPERTY_CONST),
bb0c0d6f 1278 SD_BUS_PROPERTY("SetCredential", "a(say)", property_get_set_credential, 0, SD_BUS_VTABLE_PROPERTY_CONST),
43144be4 1279 SD_BUS_PROPERTY("SetCredentialEncrypted", "a(say)", property_get_set_credential, 0, SD_BUS_VTABLE_PROPERTY_CONST),
bb0c0d6f 1280 SD_BUS_PROPERTY("LoadCredential", "a(ss)", property_get_load_credential, 0, SD_BUS_VTABLE_PROPERTY_CONST),
43144be4 1281 SD_BUS_PROPERTY("LoadCredentialEncrypted", "a(ss)", property_get_load_credential, 0, SD_BUS_VTABLE_PROPERTY_CONST),
fefefcd5 1282 SD_BUS_PROPERTY("ImportCredential", "as", bus_property_get_string_set, offsetof(ExecContext, import_credentials), SD_BUS_VTABLE_PROPERTY_CONST),
556089dc 1283 SD_BUS_PROPERTY("SupplementaryGroups", "as", NULL, offsetof(ExecContext, supplementary_groups), SD_BUS_VTABLE_PROPERTY_CONST),
556089dc 1284 SD_BUS_PROPERTY("PAMName", "s", NULL, offsetof(ExecContext, pam_name), SD_BUS_VTABLE_PROPERTY_CONST),
2a624c36
AP
1285 SD_BUS_PROPERTY("ReadWritePaths", "as", NULL, offsetof(ExecContext, read_write_paths), SD_BUS_VTABLE_PROPERTY_CONST),
1286 SD_BUS_PROPERTY("ReadOnlyPaths", "as", NULL, offsetof(ExecContext, read_only_paths), SD_BUS_VTABLE_PROPERTY_CONST),
1287 SD_BUS_PROPERTY("InaccessiblePaths", "as", NULL, offsetof(ExecContext, inaccessible_paths), SD_BUS_VTABLE_PROPERTY_CONST),
ddc155b2
TM
1288 SD_BUS_PROPERTY("ExecPaths", "as", NULL, offsetof(ExecContext, exec_paths), SD_BUS_VTABLE_PROPERTY_CONST),
1289 SD_BUS_PROPERTY("NoExecPaths", "as", NULL, offsetof(ExecContext, no_exec_paths), SD_BUS_VTABLE_PROPERTY_CONST),
8c35c10d 1290 SD_BUS_PROPERTY("ExecSearchPath", "as", NULL, offsetof(ExecContext, exec_search_path), SD_BUS_VTABLE_PROPERTY_CONST),
874cdcbc 1291 SD_BUS_PROPERTY("MountFlags", "t", bus_property_get_ulong, offsetof(ExecContext, mount_propagation_flag), SD_BUS_VTABLE_PROPERTY_CONST),
556089dc 1292 SD_BUS_PROPERTY("PrivateTmp", "b", bus_property_get_bool, offsetof(ExecContext, private_tmp), SD_BUS_VTABLE_PROPERTY_CONST),
7f112f50 1293 SD_BUS_PROPERTY("PrivateDevices", "b", bus_property_get_bool, offsetof(ExecContext, private_devices), SD_BUS_VTABLE_PROPERTY_CONST),
b8b7b838 1294 SD_BUS_PROPERTY("ProtectClock", "b", bus_property_get_bool, offsetof(ExecContext, protect_clock), SD_BUS_VTABLE_PROPERTY_CONST),
59eeb84b 1295 SD_BUS_PROPERTY("ProtectKernelTunables", "b", bus_property_get_bool, offsetof(ExecContext, protect_kernel_tunables), SD_BUS_VTABLE_PROPERTY_CONST),
502d704e 1296 SD_BUS_PROPERTY("ProtectKernelModules", "b", bus_property_get_bool, offsetof(ExecContext, protect_kernel_modules), SD_BUS_VTABLE_PROPERTY_CONST),
84703040 1297 SD_BUS_PROPERTY("ProtectKernelLogs", "b", bus_property_get_bool, offsetof(ExecContext, protect_kernel_logs), SD_BUS_VTABLE_PROPERTY_CONST),
59eeb84b 1298 SD_BUS_PROPERTY("ProtectControlGroups", "b", bus_property_get_bool, offsetof(ExecContext, protect_control_groups), SD_BUS_VTABLE_PROPERTY_CONST),
d251207d
LP
1299 SD_BUS_PROPERTY("PrivateNetwork", "b", bus_property_get_bool, offsetof(ExecContext, private_network), SD_BUS_VTABLE_PROPERTY_CONST),
1300 SD_BUS_PROPERTY("PrivateUsers", "b", bus_property_get_bool, offsetof(ExecContext, private_users), SD_BUS_VTABLE_PROPERTY_CONST),
24002121 1301 SD_BUS_PROPERTY("PrivateMounts", "b", bus_property_get_tristate, offsetof(ExecContext, private_mounts), SD_BUS_VTABLE_PROPERTY_CONST),
a70581ff 1302 SD_BUS_PROPERTY("PrivateIPC", "b", bus_property_get_bool, offsetof(ExecContext, private_ipc), SD_BUS_VTABLE_PROPERTY_CONST),
73b84e92
YW
1303 SD_BUS_PROPERTY("ProtectHome", "s", property_get_protect_home, offsetof(ExecContext, protect_home), SD_BUS_VTABLE_PROPERTY_CONST),
1304 SD_BUS_PROPERTY("ProtectSystem", "s", property_get_protect_system, offsetof(ExecContext, protect_system), SD_BUS_VTABLE_PROPERTY_CONST),
556089dc
LP
1305 SD_BUS_PROPERTY("SameProcessGroup", "b", bus_property_get_bool, offsetof(ExecContext, same_pgrp), SD_BUS_VTABLE_PROPERTY_CONST),
1306 SD_BUS_PROPERTY("UtmpIdentifier", "s", NULL, offsetof(ExecContext, utmp_id), SD_BUS_VTABLE_PROPERTY_CONST),
023a4f67 1307 SD_BUS_PROPERTY("UtmpMode", "s", property_get_exec_utmp_mode, offsetof(ExecContext, utmp_mode), SD_BUS_VTABLE_PROPERTY_CONST),
5f8640fb 1308 SD_BUS_PROPERTY("SELinuxContext", "(bs)", property_get_selinux_context, 0, SD_BUS_VTABLE_PROPERTY_CONST),
eef65bf3 1309 SD_BUS_PROPERTY("AppArmorProfile", "(bs)", property_get_apparmor_profile, 0, SD_BUS_VTABLE_PROPERTY_CONST),
2ca620c4 1310 SD_BUS_PROPERTY("SmackProcessLabel", "(bs)", property_get_smack_process_label, 0, SD_BUS_VTABLE_PROPERTY_CONST),
556089dc
LP
1311 SD_BUS_PROPERTY("IgnoreSIGPIPE", "b", bus_property_get_bool, offsetof(ExecContext, ignore_sigpipe), SD_BUS_VTABLE_PROPERTY_CONST),
1312 SD_BUS_PROPERTY("NoNewPrivileges", "b", bus_property_get_bool, offsetof(ExecContext, no_new_privileges), SD_BUS_VTABLE_PROPERTY_CONST),
57183d11
LP
1313 SD_BUS_PROPERTY("SystemCallFilter", "(bas)", property_get_syscall_filter, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1314 SD_BUS_PROPERTY("SystemCallArchitectures", "as", property_get_syscall_archs, 0, SD_BUS_VTABLE_PROPERTY_CONST),
cf9d43a8 1315 SD_BUS_PROPERTY("SystemCallErrorNumber", "i", bus_property_get_int, offsetof(ExecContext, syscall_errno), SD_BUS_VTABLE_PROPERTY_CONST),
9df2cdd8 1316 SD_BUS_PROPERTY("SystemCallLog", "(bas)", property_get_syscall_log, 0, SD_BUS_VTABLE_PROPERTY_CONST),
491eecb3 1317 SD_BUS_PROPERTY("Personality", "s", property_get_personality, offsetof(ExecContext, personality), SD_BUS_VTABLE_PROPERTY_CONST),
78e864e5 1318 SD_BUS_PROPERTY("LockPersonality", "b", bus_property_get_bool, offsetof(ExecContext, lock_personality), SD_BUS_VTABLE_PROPERTY_CONST),
4298d0b5 1319 SD_BUS_PROPERTY("RestrictAddressFamilies", "(bas)", property_get_address_families, 0, SD_BUS_VTABLE_PROPERTY_CONST),
211a3d87 1320 SD_BUS_PROPERTY("RuntimeDirectorySymlink", "a(sst)", bus_property_get_exec_dir_symlink, offsetof(ExecContext, directories[EXEC_DIRECTORY_RUNTIME]), SD_BUS_VTABLE_PROPERTY_CONST),
b9c1883a 1321 SD_BUS_PROPERTY("RuntimeDirectoryPreserve", "s", bus_property_get_exec_preserve_mode, offsetof(ExecContext, runtime_directory_preserve_mode), SD_BUS_VTABLE_PROPERTY_CONST),
3536f49e 1322 SD_BUS_PROPERTY("RuntimeDirectoryMode", "u", bus_property_get_mode, offsetof(ExecContext, directories[EXEC_DIRECTORY_RUNTIME].mode), SD_BUS_VTABLE_PROPERTY_CONST),
211a3d87
LB
1323 SD_BUS_PROPERTY("RuntimeDirectory", "as", bus_property_get_exec_dir, offsetof(ExecContext, directories[EXEC_DIRECTORY_RUNTIME]), SD_BUS_VTABLE_PROPERTY_CONST),
1324 SD_BUS_PROPERTY("StateDirectorySymlink", "a(sst)", bus_property_get_exec_dir_symlink, offsetof(ExecContext, directories[EXEC_DIRECTORY_STATE]), SD_BUS_VTABLE_PROPERTY_CONST),
e940c1ef 1325 SD_BUS_PROPERTY("StateDirectoryMode", "u", bus_property_get_mode, offsetof(ExecContext, directories[EXEC_DIRECTORY_STATE].mode), SD_BUS_VTABLE_PROPERTY_CONST),
211a3d87
LB
1326 SD_BUS_PROPERTY("StateDirectory", "as", bus_property_get_exec_dir, offsetof(ExecContext, directories[EXEC_DIRECTORY_STATE]), SD_BUS_VTABLE_PROPERTY_CONST),
1327 SD_BUS_PROPERTY("CacheDirectorySymlink", "a(sst)", bus_property_get_exec_dir_symlink, offsetof(ExecContext, directories[EXEC_DIRECTORY_CACHE]), SD_BUS_VTABLE_PROPERTY_CONST),
3536f49e 1328 SD_BUS_PROPERTY("CacheDirectoryMode", "u", bus_property_get_mode, offsetof(ExecContext, directories[EXEC_DIRECTORY_CACHE].mode), SD_BUS_VTABLE_PROPERTY_CONST),
211a3d87
LB
1329 SD_BUS_PROPERTY("CacheDirectory", "as", bus_property_get_exec_dir, offsetof(ExecContext, directories[EXEC_DIRECTORY_CACHE]), SD_BUS_VTABLE_PROPERTY_CONST),
1330 SD_BUS_PROPERTY("LogsDirectorySymlink", "a(sst)", bus_property_get_exec_dir_symlink, offsetof(ExecContext, directories[EXEC_DIRECTORY_LOGS]), SD_BUS_VTABLE_PROPERTY_CONST),
3536f49e 1331 SD_BUS_PROPERTY("LogsDirectoryMode", "u", bus_property_get_mode, offsetof(ExecContext, directories[EXEC_DIRECTORY_LOGS].mode), SD_BUS_VTABLE_PROPERTY_CONST),
211a3d87 1332 SD_BUS_PROPERTY("LogsDirectory", "as", bus_property_get_exec_dir, offsetof(ExecContext, directories[EXEC_DIRECTORY_LOGS]), SD_BUS_VTABLE_PROPERTY_CONST),
3536f49e 1333 SD_BUS_PROPERTY("ConfigurationDirectoryMode", "u", bus_property_get_mode, offsetof(ExecContext, directories[EXEC_DIRECTORY_CONFIGURATION].mode), SD_BUS_VTABLE_PROPERTY_CONST),
211a3d87 1334 SD_BUS_PROPERTY("ConfigurationDirectory", "as", bus_property_get_exec_dir, offsetof(ExecContext, directories[EXEC_DIRECTORY_CONFIGURATION]), SD_BUS_VTABLE_PROPERTY_CONST),
12213aed 1335 SD_BUS_PROPERTY("TimeoutCleanUSec", "t", bus_property_get_usec, offsetof(ExecContext, timeout_clean_usec), SD_BUS_VTABLE_PROPERTY_CONST),
f3e43635 1336 SD_BUS_PROPERTY("MemoryDenyWriteExecute", "b", bus_property_get_bool, offsetof(ExecContext, memory_deny_write_execute), SD_BUS_VTABLE_PROPERTY_CONST),
f4170c67 1337 SD_BUS_PROPERTY("RestrictRealtime", "b", bus_property_get_bool, offsetof(ExecContext, restrict_realtime), SD_BUS_VTABLE_PROPERTY_CONST),
f69567cb 1338 SD_BUS_PROPERTY("RestrictSUIDSGID", "b", bus_property_get_bool, offsetof(ExecContext, restrict_suid_sgid), SD_BUS_VTABLE_PROPERTY_CONST),
6a8c2d59 1339 SD_BUS_PROPERTY("RestrictNamespaces", "t", bus_property_get_ulong, offsetof(ExecContext, restrict_namespaces), SD_BUS_VTABLE_PROPERTY_CONST),
cc86a278 1340 SD_BUS_PROPERTY("RestrictFileSystems", "(bas)", property_get_restrict_filesystems, 0, SD_BUS_VTABLE_PROPERTY_CONST),
d2d6c096
LP
1341 SD_BUS_PROPERTY("BindPaths", "a(ssbt)", property_get_bind_paths, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1342 SD_BUS_PROPERTY("BindReadOnlyPaths", "a(ssbt)", property_get_bind_paths, 0, SD_BUS_VTABLE_PROPERTY_CONST),
784ad252 1343 SD_BUS_PROPERTY("TemporaryFileSystem", "a(ss)", property_get_temporary_filesystems, 0, SD_BUS_VTABLE_PROPERTY_CONST),
5e98086d 1344 SD_BUS_PROPERTY("MountAPIVFS", "b", property_get_mount_apivfs, 0, SD_BUS_VTABLE_PROPERTY_CONST),
b1edf445 1345 SD_BUS_PROPERTY("KeyringMode", "s", property_get_exec_keyring_mode, offsetof(ExecContext, keyring_mode), SD_BUS_VTABLE_PROPERTY_CONST),
4e399953
LP
1346 SD_BUS_PROPERTY("ProtectProc", "s", property_get_protect_proc, offsetof(ExecContext, protect_proc), SD_BUS_VTABLE_PROPERTY_CONST),
1347 SD_BUS_PROPERTY("ProcSubset", "s", property_get_proc_subset, offsetof(ExecContext, proc_subset), SD_BUS_VTABLE_PROPERTY_CONST),
aecd5ac6 1348 SD_BUS_PROPERTY("ProtectHostname", "b", bus_property_get_bool, offsetof(ExecContext, protect_hostname), SD_BUS_VTABLE_PROPERTY_CONST),
85614c6e 1349 SD_BUS_PROPERTY("MemoryKSM", "b", bus_property_get_tristate, offsetof(ExecContext, memory_ksm), SD_BUS_VTABLE_PROPERTY_CONST),
a8d08f39 1350 SD_BUS_PROPERTY("NetworkNamespacePath", "s", NULL, offsetof(ExecContext, network_namespace_path), SD_BUS_VTABLE_PROPERTY_CONST),
a70581ff 1351 SD_BUS_PROPERTY("IPCNamespacePath", "s", NULL, offsetof(ExecContext, ipc_namespace_path), SD_BUS_VTABLE_PROPERTY_CONST),
84be0c71
LP
1352 SD_BUS_PROPERTY("RootImagePolicy", "s", property_get_image_policy, offsetof(ExecContext, root_image_policy), SD_BUS_VTABLE_PROPERTY_CONST),
1353 SD_BUS_PROPERTY("MountImagePolicy", "s", property_get_image_policy, offsetof(ExecContext, mount_image_policy), SD_BUS_VTABLE_PROPERTY_CONST),
1354 SD_BUS_PROPERTY("ExtensionImagePolicy", "s", property_get_image_policy, offsetof(ExecContext, extension_image_policy), SD_BUS_VTABLE_PROPERTY_CONST),
7f452159
LP
1355
1356 /* Obsolete/redundant properties: */
1357 SD_BUS_PROPERTY("Capabilities", "s", property_get_empty_string, 0, SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN),
1358 SD_BUS_PROPERTY("ReadWriteDirectories", "as", NULL, offsetof(ExecContext, read_write_paths), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN),
1359 SD_BUS_PROPERTY("ReadOnlyDirectories", "as", NULL, offsetof(ExecContext, read_only_paths), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN),
1360 SD_BUS_PROPERTY("InaccessibleDirectories", "as", NULL, offsetof(ExecContext, inaccessible_paths), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN),
1361 SD_BUS_PROPERTY("IOScheduling", "i", property_get_ioprio, 0, SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN),
1362
718db961
LP
1363 SD_BUS_VTABLE_END
1364};
82c121a4 1365
4d4c80d0
LP
1366static int append_exec_command(sd_bus_message *reply, ExecCommand *c) {
1367 int r;
1368
1369 assert(reply);
1370 assert(c);
1371
1372 if (!c->path)
1373 return 0;
1374
1375 r = sd_bus_message_open_container(reply, 'r', "sasbttttuii");
1376 if (r < 0)
1377 return r;
1378
1379 r = sd_bus_message_append(reply, "s", c->path);
1380 if (r < 0)
1381 return r;
1382
1383 r = sd_bus_message_append_strv(reply, c->argv);
1384 if (r < 0)
1385 return r;
1386
1387 r = sd_bus_message_append(reply, "bttttuii",
3ed0cd26 1388 !!(c->flags & EXEC_COMMAND_IGNORE_FAILURE),
4d4c80d0
LP
1389 c->exec_status.start_timestamp.realtime,
1390 c->exec_status.start_timestamp.monotonic,
1391 c->exec_status.exit_timestamp.realtime,
1392 c->exec_status.exit_timestamp.monotonic,
1393 (uint32_t) c->exec_status.pid,
1394 (int32_t) c->exec_status.code,
1395 (int32_t) c->exec_status.status);
1396 if (r < 0)
1397 return r;
1398
1399 return sd_bus_message_close_container(reply);
1400}
1401
b3d59367
AZ
1402static int append_exec_ex_command(sd_bus_message *reply, ExecCommand *c) {
1403 _cleanup_strv_free_ char **ex_opts = NULL;
1404 int r;
1405
1406 assert(reply);
1407 assert(c);
1408
1409 if (!c->path)
1410 return 0;
1411
1412 r = sd_bus_message_open_container(reply, 'r', "sasasttttuii");
1413 if (r < 0)
1414 return r;
1415
1416 r = sd_bus_message_append(reply, "s", c->path);
1417 if (r < 0)
1418 return r;
1419
1420 r = sd_bus_message_append_strv(reply, c->argv);
1421 if (r < 0)
1422 return r;
1423
1424 r = exec_command_flags_to_strv(c->flags, &ex_opts);
1425 if (r < 0)
1426 return r;
1427
1428 r = sd_bus_message_append_strv(reply, ex_opts);
1429 if (r < 0)
1430 return r;
1431
1432 r = sd_bus_message_append(reply, "ttttuii",
1433 c->exec_status.start_timestamp.realtime,
1434 c->exec_status.start_timestamp.monotonic,
1435 c->exec_status.exit_timestamp.realtime,
1436 c->exec_status.exit_timestamp.monotonic,
1437 (uint32_t) c->exec_status.pid,
1438 (int32_t) c->exec_status.code,
1439 (int32_t) c->exec_status.status);
1440 if (r < 0)
1441 return r;
1442
1443 return sd_bus_message_close_container(reply);
1444}
1445
718db961
LP
1446int bus_property_get_exec_command(
1447 sd_bus *bus,
1448 const char *path,
1449 const char *interface,
1450 const char *property,
1451 sd_bus_message *reply,
ebcf1f97
LP
1452 void *userdata,
1453 sd_bus_error *ret_error) {
fe68089d 1454
4d4c80d0 1455 ExecCommand *c = (ExecCommand*) userdata;
718db961 1456 int r;
fe68089d 1457
718db961
LP
1458 assert(bus);
1459 assert(reply);
fe68089d 1460
718db961
LP
1461 r = sd_bus_message_open_container(reply, 'a', "(sasbttttuii)");
1462 if (r < 0)
1463 return r;
fe68089d 1464
4d4c80d0
LP
1465 r = append_exec_command(reply, c);
1466 if (r < 0)
1467 return r;
fe68089d 1468
4d4c80d0
LP
1469 return sd_bus_message_close_container(reply);
1470}
718db961 1471
4d4c80d0
LP
1472int bus_property_get_exec_command_list(
1473 sd_bus *bus,
1474 const char *path,
1475 const char *interface,
1476 const char *property,
1477 sd_bus_message *reply,
1478 void *userdata,
1479 sd_bus_error *ret_error) {
718db961 1480
03677889 1481 ExecCommand *exec_command = *(ExecCommand**) userdata;
4d4c80d0 1482 int r;
718db961 1483
4d4c80d0
LP
1484 assert(bus);
1485 assert(reply);
1486
1487 r = sd_bus_message_open_container(reply, 'a', "(sasbttttuii)");
1488 if (r < 0)
1489 return r;
718db961 1490
03677889 1491 LIST_FOREACH(command, c, exec_command) {
4d4c80d0 1492 r = append_exec_command(reply, c);
718db961
LP
1493 if (r < 0)
1494 return r;
fe68089d
LP
1495 }
1496
718db961 1497 return sd_bus_message_close_container(reply);
8351ceae 1498}
c7040b5d 1499
b3d59367
AZ
1500int bus_property_get_exec_ex_command_list(
1501 sd_bus *bus,
1502 const char *path,
1503 const char *interface,
1504 const char *property,
1505 sd_bus_message *reply,
1506 void *userdata,
1507 sd_bus_error *ret_error) {
1508
03677889 1509 ExecCommand *exec_command = *(ExecCommand**) userdata;
b3d59367
AZ
1510 int r;
1511
1512 assert(bus);
1513 assert(reply);
1514
1515 r = sd_bus_message_open_container(reply, 'a', "(sasasttttuii)");
1516 if (r < 0)
1517 return r;
1518
1519 LIST_FOREACH(command, c, exec_command) {
1520 r = append_exec_ex_command(reply, c);
1521 if (r < 0)
1522 return r;
1523 }
1524
1525 return sd_bus_message_close_container(reply);
1526}
1527
1528static char *exec_command_flags_to_exec_chars(ExecCommandFlags flags) {
a4fc96c8
ZJS
1529 return strjoin(FLAGS_SET(flags, EXEC_COMMAND_IGNORE_FAILURE) ? "-" : "",
1530 FLAGS_SET(flags, EXEC_COMMAND_NO_ENV_EXPAND) ? ":" : "",
1531 FLAGS_SET(flags, EXEC_COMMAND_FULLY_PRIVILEGED) ? "+" : "",
1532 FLAGS_SET(flags, EXEC_COMMAND_NO_SETUID) ? "!" : "",
1533 FLAGS_SET(flags, EXEC_COMMAND_AMBIENT_MAGIC) ? "!!" : "");
b3d59367
AZ
1534}
1535
237f7bcb 1536int bus_set_transient_exec_command(
9c0320e7
YW
1537 Unit *u,
1538 const char *name,
1539 ExecCommand **exec_command,
1540 sd_bus_message *message,
1541 UnitWriteFlags flags,
1542 sd_bus_error *error) {
b3d59367 1543 bool is_ex_prop = endswith(name, "Ex");
9c0320e7
YW
1544 unsigned n = 0;
1545 int r;
1546
0a27d86a
ZJS
1547 /* Drop Ex from the written setting. E.g. ExecStart=, not ExecStartEx=. */
1548 const char *written_name = is_ex_prop ? strndupa(name, strlen(name) - 2) : name;
1549
b3d59367 1550 r = sd_bus_message_enter_container(message, 'a', is_ex_prop ? "(sasas)" : "(sasb)");
9c0320e7
YW
1551 if (r < 0)
1552 return r;
1553
b3d59367
AZ
1554 while ((r = sd_bus_message_enter_container(message, 'r', is_ex_prop ? "sasas" : "sasb")) > 0) {
1555 _cleanup_strv_free_ char **argv = NULL, **ex_opts = NULL;
9c0320e7
YW
1556 const char *path;
1557 int b;
1558
1559 r = sd_bus_message_read(message, "s", &path);
1560 if (r < 0)
1561 return r;
1562
8038b99d
ZJS
1563 if (!path_is_absolute(path) && !filename_is_valid(path))
1564 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS,
1565 "\"%s\" is neither a valid executable name nor an absolute path",
1566 path);
9c0320e7
YW
1567
1568 r = sd_bus_message_read_strv(message, &argv);
1569 if (r < 0)
1570 return r;
1571
29500cf8
HC
1572 if (strv_isempty(argv))
1573 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS,
1574 "\"%s\" argv cannot be empty", name);
1575
b3d59367 1576 r = is_ex_prop ? sd_bus_message_read_strv(message, &ex_opts) : sd_bus_message_read(message, "b", &b);
9c0320e7
YW
1577 if (r < 0)
1578 return r;
1579
1580 r = sd_bus_message_exit_container(message);
1581 if (r < 0)
1582 return r;
1583
1584 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
1585 ExecCommand *c;
1586
1587 c = new0(ExecCommand, 1);
1588 if (!c)
1589 return -ENOMEM;
1590
1591 c->path = strdup(path);
1592 if (!c->path) {
1593 free(c);
1594 return -ENOMEM;
1595 }
1596
ae2a15bc 1597 c->argv = TAKE_PTR(argv);
9c0320e7 1598
b3d59367
AZ
1599 if (is_ex_prop) {
1600 r = exec_command_flags_from_strv(ex_opts, &c->flags);
1601 if (r < 0)
1602 return r;
1603 } else
1604 c->flags = b ? EXEC_COMMAND_IGNORE_FAILURE : 0;
9c0320e7 1605
4ff361cc 1606 path_simplify(c->path);
9c0320e7
YW
1607 exec_command_append_list(exec_command, c);
1608 }
1609
1610 n++;
1611 }
1612 if (r < 0)
1613 return r;
1614
1615 r = sd_bus_message_exit_container(message);
1616 if (r < 0)
1617 return r;
1618
1619 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2485b7e2 1620 _cleanup_(memstream_done) MemStream m = {};
9c0320e7 1621 _cleanup_free_ char *buf = NULL;
2485b7e2 1622 FILE *f;
9c0320e7
YW
1623
1624 if (n == 0)
1625 *exec_command = exec_command_free_list(*exec_command);
1626
2485b7e2 1627 f = memstream_init(&m);
9c0320e7
YW
1628 if (!f)
1629 return -ENOMEM;
1630
0a27d86a 1631 fprintf(f, "%s=\n", written_name);
9c0320e7
YW
1632
1633 LIST_FOREACH(command, c, *exec_command) {
540ac933 1634 _cleanup_free_ char *a = NULL, *exec_chars = NULL;
0a27d86a
ZJS
1635 UnitWriteFlags esc_flags = UNIT_ESCAPE_SPECIFIERS |
1636 (FLAGS_SET(c->flags, EXEC_COMMAND_NO_ENV_EXPAND) ? UNIT_ESCAPE_EXEC_SYNTAX : UNIT_ESCAPE_EXEC_SYNTAX_ENV);
9c0320e7 1637
540ac933
LP
1638 exec_chars = exec_command_flags_to_exec_chars(c->flags);
1639 if (!exec_chars)
9c0320e7
YW
1640 return -ENOMEM;
1641
0a27d86a 1642 a = unit_concat_strv(c->argv, esc_flags);
9c0320e7
YW
1643 if (!a)
1644 return -ENOMEM;
1645
540ac933 1646 if (streq_ptr(c->path, c->argv ? c->argv[0] : NULL))
0a27d86a 1647 fprintf(f, "%s=%s%s\n", written_name, exec_chars, a);
540ac933
LP
1648 else {
1649 _cleanup_free_ char *t = NULL;
1650 const char *p;
1651
0a27d86a 1652 p = unit_escape_setting(c->path, esc_flags, &t);
540ac933
LP
1653 if (!p)
1654 return -ENOMEM;
b3d59367 1655
0a27d86a 1656 fprintf(f, "%s=%s@%s %s\n", written_name, exec_chars, p, a);
540ac933 1657 }
9c0320e7
YW
1658 }
1659
2485b7e2 1660 r = memstream_finalize(&m, &buf, NULL);
9c0320e7
YW
1661 if (r < 0)
1662 return r;
1663
0a27d86a 1664 unit_write_setting(u, flags, written_name, buf);
9c0320e7
YW
1665 }
1666
1667 return 1;
1668}
1669
7e2a3fcc
YW
1670static int parse_personality(const char *s, unsigned long *p) {
1671 unsigned long v;
1672
1673 assert(p);
1674
1675 v = personality_from_string(s);
1676 if (v == PERSONALITY_INVALID)
1677 return -EINVAL;
1678
1679 *p = v;
1680 return 0;
1681}
1682
b205e59a 1683static const char* mount_propagation_flag_to_string_with_check(unsigned long n) {
edac5c46 1684 if (!mount_propagation_flag_is_valid(n))
7e2a3fcc
YW
1685 return NULL;
1686
b205e59a 1687 return mount_propagation_flag_to_string(n);
7e2a3fcc
YW
1688}
1689
1690static BUS_DEFINE_SET_TRANSIENT(nsec, "t", uint64_t, nsec_t, NSEC_FMT);
1691static BUS_DEFINE_SET_TRANSIENT_IS_VALID(log_level, "i", int32_t, int, "%" PRIi32, log_level_is_valid);
aad67b80 1692#if HAVE_SECCOMP
005bfaf1 1693static BUS_DEFINE_SET_TRANSIENT_IS_VALID(errno, "i", int32_t, int, "%" PRIi32, seccomp_errno_or_action_is_valid);
aad67b80 1694#endif
7e2a3fcc
YW
1695static BUS_DEFINE_SET_TRANSIENT_PARSE(std_input, ExecInput, exec_input_from_string);
1696static BUS_DEFINE_SET_TRANSIENT_PARSE(std_output, ExecOutput, exec_output_from_string);
1697static BUS_DEFINE_SET_TRANSIENT_PARSE(utmp_mode, ExecUtmpMode, exec_utmp_mode_from_string);
1e8c7bd5
YW
1698static BUS_DEFINE_SET_TRANSIENT_PARSE(protect_system, ProtectSystem, protect_system_from_string);
1699static BUS_DEFINE_SET_TRANSIENT_PARSE(protect_home, ProtectHome, protect_home_from_string);
7e2a3fcc 1700static BUS_DEFINE_SET_TRANSIENT_PARSE(keyring_mode, ExecKeyringMode, exec_keyring_mode_from_string);
4e399953
LP
1701static BUS_DEFINE_SET_TRANSIENT_PARSE(protect_proc, ProtectProc, protect_proc_from_string);
1702static BUS_DEFINE_SET_TRANSIENT_PARSE(proc_subset, ProcSubset, proc_subset_from_string);
b9c1883a 1703BUS_DEFINE_SET_TRANSIENT_PARSE(exec_preserve_mode, ExecPreserveMode, exec_preserve_mode_from_string);
7e2a3fcc
YW
1704static BUS_DEFINE_SET_TRANSIENT_PARSE_PTR(personality, unsigned long, parse_personality);
1705static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(secure_bits, "i", int32_t, int, "%" PRIi32, secure_bits_to_string_alloc_with_check);
8142d735 1706static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(capability, "t", uint64_t, uint64_t, "%" PRIu64, capability_set_to_string);
86c2a9f1 1707static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(namespace_flag, "t", uint64_t, unsigned long, "%" PRIu64, namespace_flags_to_string);
874cdcbc 1708static BUS_DEFINE_SET_TRANSIENT_TO_STRING(mount_propagation_flag, "t", uint64_t, unsigned long, "%" PRIu64, mount_propagation_flag_to_string_with_check);
7e2a3fcc 1709
c7040b5d
LP
1710int bus_exec_context_set_transient_property(
1711 Unit *u,
1712 ExecContext *c,
1713 const char *name,
1714 sd_bus_message *message,
2e59b241 1715 UnitWriteFlags flags,
c7040b5d
LP
1716 sd_bus_error *error) {
1717
6550c24c
LP
1718 const char *suffix;
1719 int r;
c7040b5d
LP
1720
1721 assert(u);
1722 assert(c);
1723 assert(name);
1724 assert(message);
1725
2e59b241
LP
1726 flags |= UNIT_PRIVATE;
1727
7e2a3fcc 1728 if (streq(name, "User"))
7a8867ab 1729 return bus_set_transient_user_relaxed(u, name, &c->user, message, flags, error);
c7040b5d 1730
7e2a3fcc 1731 if (streq(name, "Group"))
7a8867ab 1732 return bus_set_transient_user_relaxed(u, name, &c->group, message, flags, error);
c7040b5d 1733
854eca4a
MY
1734 if (streq(name, "SetLoginEnvironment"))
1735 return bus_set_transient_tristate(u, name, &c->set_login_environment, message, flags, error);
1736
7e2a3fcc
YW
1737 if (streq(name, "TTYPath"))
1738 return bus_set_transient_path(u, name, &c->tty_path, message, flags, error);
6f3e7985 1739
7e2a3fcc
YW
1740 if (streq(name, "RootImage"))
1741 return bus_set_transient_path(u, name, &c->root_image, message, flags, error);
76736280 1742
18d73705
LB
1743 if (streq(name, "RootImageOptions")) {
1744 _cleanup_(mount_options_free_allp) MountOptions *options = NULL;
1745 _cleanup_free_ char *format_str = NULL;
18d73705 1746
988172ce 1747 r = bus_read_mount_options(message, error, &options, &format_str, " ");
18d73705
LB
1748 if (r < 0)
1749 return r;
1750
1751 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
64903d18 1752 if (options) {
18d73705
LB
1753 LIST_JOIN(mount_options, c->root_image_options, options);
1754 unit_write_settingf(
1755 u, flags|UNIT_ESCAPE_SPECIFIERS, name,
1756 "%s=%s",
1757 name,
1758 format_str);
64903d18
ZJS
1759 } else {
1760 c->root_image_options = mount_options_free_all(c->root_image_options);
1761 unit_write_settingf(u, flags, name, "%s=", name);
18d73705
LB
1762 }
1763 }
1764
1765 return 1;
1766 }
1767
0389f4fa
LB
1768 if (streq(name, "RootHash")) {
1769 const void *roothash_decoded;
1770 size_t roothash_decoded_size;
1771
1772 r = sd_bus_message_read_array(message, 'y', &roothash_decoded, &roothash_decoded_size);
1773 if (r < 0)
1774 return r;
1775
1776 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
1777 _cleanup_free_ char *encoded = NULL;
1778
1779 if (roothash_decoded_size == 0) {
1780 c->root_hash_path = mfree(c->root_hash_path);
1781 c->root_hash = mfree(c->root_hash);
1782 c->root_hash_size = 0;
1783
1784 unit_write_settingf(u, flags, name, "RootHash=");
1785 } else {
c2b2df60 1786 _cleanup_free_ void *p = NULL;
0389f4fa
LB
1787
1788 encoded = hexmem(roothash_decoded, roothash_decoded_size);
1789 if (!encoded)
1790 return -ENOMEM;
1791
1792 p = memdup(roothash_decoded, roothash_decoded_size);
1793 if (!p)
1794 return -ENOMEM;
1795
1796 free_and_replace(c->root_hash, p);
1797 c->root_hash_size = roothash_decoded_size;
1798 c->root_hash_path = mfree(c->root_hash_path);
1799
1800 unit_write_settingf(u, flags, name, "RootHash=%s", encoded);
1801 }
1802 }
1803
1804 return 1;
1805 }
1806
1807 if (streq(name, "RootHashPath")) {
1808 c->root_hash_size = 0;
1809 c->root_hash = mfree(c->root_hash);
1810
1811 return bus_set_transient_path(u, "RootHash", &c->root_hash_path, message, flags, error);
1812 }
1813
d4d55b0d
LB
1814 if (streq(name, "RootHashSignature")) {
1815 const void *roothash_sig_decoded;
1816 size_t roothash_sig_decoded_size;
1817
1818 r = sd_bus_message_read_array(message, 'y', &roothash_sig_decoded, &roothash_sig_decoded_size);
1819 if (r < 0)
1820 return r;
1821
1822 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
1823 _cleanup_free_ char *encoded = NULL;
1824
1825 if (roothash_sig_decoded_size == 0) {
1826 c->root_hash_sig_path = mfree(c->root_hash_sig_path);
1827 c->root_hash_sig = mfree(c->root_hash_sig);
1828 c->root_hash_sig_size = 0;
1829
1830 unit_write_settingf(u, flags, name, "RootHashSignature=");
1831 } else {
c2b2df60 1832 _cleanup_free_ void *p = NULL;
d4d55b0d
LB
1833 ssize_t len;
1834
1835 len = base64mem(roothash_sig_decoded, roothash_sig_decoded_size, &encoded);
1836 if (len < 0)
1837 return -ENOMEM;
1838
1839 p = memdup(roothash_sig_decoded, roothash_sig_decoded_size);
1840 if (!p)
1841 return -ENOMEM;
1842
1843 free_and_replace(c->root_hash_sig, p);
1844 c->root_hash_sig_size = roothash_sig_decoded_size;
1845 c->root_hash_sig_path = mfree(c->root_hash_sig_path);
1846
1847 unit_write_settingf(u, flags, name, "RootHashSignature=base64:%s", encoded);
1848 }
1849 }
1850
1851 return 1;
1852 }
1853
1854 if (streq(name, "RootHashSignaturePath")) {
1855 c->root_hash_sig_size = 0;
1856 c->root_hash_sig = mfree(c->root_hash_sig);
1857
1858 return bus_set_transient_path(u, "RootHashSignature", &c->root_hash_sig_path, message, flags, error);
1859 }
1860
0389f4fa
LB
1861 if (streq(name, "RootVerity"))
1862 return bus_set_transient_path(u, name, &c->root_verity, message, flags, error);
1863
7e2a3fcc
YW
1864 if (streq(name, "RootDirectory"))
1865 return bus_set_transient_path(u, name, &c->root_directory, message, flags, error);
c7040b5d 1866
9c0c6701
DDM
1867 if (streq(name, "RootEphemeral"))
1868 return bus_set_transient_bool(u, name, &c->root_ephemeral, message, flags, error);
1869
7e2a3fcc
YW
1870 if (streq(name, "SyslogIdentifier"))
1871 return bus_set_transient_string(u, name, &c->syslog_identifier, message, flags, error);
c7040b5d 1872
7e2a3fcc
YW
1873 if (streq(name, "LogLevelMax"))
1874 return bus_set_transient_log_level(u, name, &c->log_level_max, message, flags, error);
1875
90fc172e 1876 if (streq(name, "LogRateLimitIntervalUSec"))
5ac1530e 1877 return bus_set_transient_usec(u, name, &c->log_ratelimit_interval_usec, message, flags, error);
90fc172e
AZ
1878
1879 if (streq(name, "LogRateLimitBurst"))
5ac1530e 1880 return bus_set_transient_unsigned(u, name, &c->log_ratelimit_burst, message, flags, error);
90fc172e 1881
523ea123
QD
1882 if (streq(name, "LogFilterPatterns")) {
1883 /* Use _cleanup_free_, not _cleanup_strv_free_, as we don't want the content of the strv
1884 * to be freed. */
1885 _cleanup_free_ char **allow_list = NULL, **deny_list = NULL;
1886 const char *pattern;
1887 int is_allowlist;
1888
1889 r = sd_bus_message_enter_container(message, 'a', "(bs)");
1890 if (r < 0)
1891 return r;
1892
1893 while ((r = sd_bus_message_read(message, "(bs)", &is_allowlist, &pattern)) > 0) {
1894 _cleanup_(pattern_freep) pcre2_code *compiled_pattern = NULL;
1895
1896 if (isempty(pattern))
1897 continue;
1898
1899 r = pattern_compile_and_log(pattern, 0, &compiled_pattern);
1900 if (r < 0)
1901 return r;
1902
1903 r = strv_push(is_allowlist ? &allow_list : &deny_list, (char *)pattern);
1904 if (r < 0)
1905 return r;
1906 }
1907 if (r < 0)
1908 return r;
1909
1910 r = sd_bus_message_exit_container(message);
1911 if (r < 0)
1912 return r;
1913
1914 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
1915 if (strv_isempty(allow_list) && strv_isempty(deny_list)) {
1a572fd0
DT
1916 c->log_filter_allowed_patterns = set_free_free(c->log_filter_allowed_patterns);
1917 c->log_filter_denied_patterns = set_free_free(c->log_filter_denied_patterns);
523ea123
QD
1918 unit_write_settingf(u, flags, name, "%s=", name);
1919 } else {
1920 r = set_put_strdupv(&c->log_filter_allowed_patterns, allow_list);
1921 if (r < 0)
1922 return r;
1923 r = set_put_strdupv(&c->log_filter_denied_patterns, deny_list);
1924 if (r < 0)
1925 return r;
1926
1927 STRV_FOREACH(unit_pattern, allow_list)
1928 unit_write_settingf(u, flags, name, "%s=%s", name, *unit_pattern);
1929 STRV_FOREACH(unit_pattern, deny_list)
1930 unit_write_settingf(u, flags, name, "%s=~%s", name, *unit_pattern);
1931 }
1932 }
1933
1934 return 1;
1935 }
1936
7e2a3fcc
YW
1937 if (streq(name, "Personality"))
1938 return bus_set_transient_personality(u, name, &c->personality, message, flags, error);
1939
7e2a3fcc
YW
1940 if (streq(name, "StandardInput"))
1941 return bus_set_transient_std_input(u, name, &c->std_input, message, flags, error);
1942
1943 if (streq(name, "StandardOutput"))
1944 return bus_set_transient_std_output(u, name, &c->std_output, message, flags, error);
1945
1946 if (streq(name, "StandardError"))
1947 return bus_set_transient_std_output(u, name, &c->std_error, message, flags, error);
1948
1949 if (streq(name, "IgnoreSIGPIPE"))
1950 return bus_set_transient_bool(u, name, &c->ignore_sigpipe, message, flags, error);
1951
1952 if (streq(name, "TTYVHangup"))
1953 return bus_set_transient_bool(u, name, &c->tty_vhangup, message, flags, error);
1954
1955 if (streq(name, "TTYReset"))
1956 return bus_set_transient_bool(u, name, &c->tty_reset, message, flags, error);
1957
1958 if (streq(name, "TTYVTDisallocate"))
1959 return bus_set_transient_bool(u, name, &c->tty_vt_disallocate, message, flags, error);
51462135
DDM
1960
1961 if (streq(name, "TTYRows"))
1962 return bus_set_transient_unsigned(u, name, &c->tty_rows, message, flags, error);
1963
1964 if (streq(name, "TTYColumns"))
1965 return bus_set_transient_unsigned(u, name, &c->tty_cols, message, flags, error);
7e2a3fcc
YW
1966
1967 if (streq(name, "PrivateTmp"))
1968 return bus_set_transient_bool(u, name, &c->private_tmp, message, flags, error);
1969
1970 if (streq(name, "PrivateDevices"))
1971 return bus_set_transient_bool(u, name, &c->private_devices, message, flags, error);
1972
228af36f 1973 if (streq(name, "PrivateMounts"))
24002121 1974 return bus_set_transient_tristate(u, name, &c->private_mounts, message, flags, error);
228af36f 1975
7e2a3fcc
YW
1976 if (streq(name, "PrivateNetwork"))
1977 return bus_set_transient_bool(u, name, &c->private_network, message, flags, error);
1978
a70581ff
XR
1979 if (streq(name, "PrivateIPC"))
1980 return bus_set_transient_bool(u, name, &c->private_ipc, message, flags, error);
1981
7e2a3fcc
YW
1982 if (streq(name, "PrivateUsers"))
1983 return bus_set_transient_bool(u, name, &c->private_users, message, flags, error);
1984
1985 if (streq(name, "NoNewPrivileges"))
1986 return bus_set_transient_bool(u, name, &c->no_new_privileges, message, flags, error);
1987
1988 if (streq(name, "SyslogLevelPrefix"))
1989 return bus_set_transient_bool(u, name, &c->syslog_level_prefix, message, flags, error);
1990
1991 if (streq(name, "MemoryDenyWriteExecute"))
1992 return bus_set_transient_bool(u, name, &c->memory_deny_write_execute, message, flags, error);
1993
1994 if (streq(name, "RestrictRealtime"))
1995 return bus_set_transient_bool(u, name, &c->restrict_realtime, message, flags, error);
1996
f69567cb
LP
1997 if (streq(name, "RestrictSUIDSGID"))
1998 return bus_set_transient_bool(u, name, &c->restrict_suid_sgid, message, flags, error);
1999
7e2a3fcc
YW
2000 if (streq(name, "DynamicUser"))
2001 return bus_set_transient_bool(u, name, &c->dynamic_user, message, flags, error);
2002
2003 if (streq(name, "RemoveIPC"))
2004 return bus_set_transient_bool(u, name, &c->remove_ipc, message, flags, error);
2005
2006 if (streq(name, "ProtectKernelTunables"))
2007 return bus_set_transient_bool(u, name, &c->protect_kernel_tunables, message, flags, error);
2008
2009 if (streq(name, "ProtectKernelModules"))
2010 return bus_set_transient_bool(u, name, &c->protect_kernel_modules, message, flags, error);
2011
84703040
KK
2012 if (streq(name, "ProtectKernelLogs"))
2013 return bus_set_transient_bool(u, name, &c->protect_kernel_logs, message, flags, error);
2014
fc64760d
KK
2015 if (streq(name, "ProtectClock"))
2016 return bus_set_transient_bool(u, name, &c->protect_clock, message, flags, error);
2017
7e2a3fcc
YW
2018 if (streq(name, "ProtectControlGroups"))
2019 return bus_set_transient_bool(u, name, &c->protect_control_groups, message, flags, error);
2020
7e2a3fcc
YW
2021 if (streq(name, "CPUSchedulingResetOnFork"))
2022 return bus_set_transient_bool(u, name, &c->cpu_sched_reset_on_fork, message, flags, error);
2023
2024 if (streq(name, "NonBlocking"))
2025 return bus_set_transient_bool(u, name, &c->non_blocking, message, flags, error);
2026
2027 if (streq(name, "LockPersonality"))
2028 return bus_set_transient_bool(u, name, &c->lock_personality, message, flags, error);
2029
aecd5ac6
TM
2030 if (streq(name, "ProtectHostname"))
2031 return bus_set_transient_bool(u, name, &c->protect_hostname, message, flags, error);
2032
85614c6e
SR
2033 if (streq(name, "MemoryKSM"))
2034 return bus_set_transient_tristate(u, name, &c->memory_ksm, message, flags, error);
2035
7e2a3fcc
YW
2036 if (streq(name, "UtmpIdentifier"))
2037 return bus_set_transient_string(u, name, &c->utmp_id, message, flags, error);
2038
2039 if (streq(name, "UtmpMode"))
2040 return bus_set_transient_utmp_mode(u, name, &c->utmp_mode, message, flags, error);
2041
2042 if (streq(name, "PAMName"))
2043 return bus_set_transient_string(u, name, &c->pam_name, message, flags, error);
2044
2045 if (streq(name, "TimerSlackNSec"))
2046 return bus_set_transient_nsec(u, name, &c->timer_slack_nsec, message, flags, error);
2047
2048 if (streq(name, "ProtectSystem"))
2049 return bus_set_transient_protect_system(u, name, &c->protect_system, message, flags, error);
2050
2051 if (streq(name, "ProtectHome"))
2052 return bus_set_transient_protect_home(u, name, &c->protect_home, message, flags, error);
cffaed83 2053
7e2a3fcc
YW
2054 if (streq(name, "KeyringMode"))
2055 return bus_set_transient_keyring_mode(u, name, &c->keyring_mode, message, flags, error);
2056
4e399953
LP
2057 if (streq(name, "ProtectProc"))
2058 return bus_set_transient_protect_proc(u, name, &c->protect_proc, message, flags, error);
2059
2060 if (streq(name, "ProcSubset"))
2061 return bus_set_transient_proc_subset(u, name, &c->proc_subset, message, flags, error);
2062
7e2a3fcc 2063 if (streq(name, "RuntimeDirectoryPreserve"))
b9c1883a 2064 return bus_set_transient_exec_preserve_mode(u, name, &c->runtime_directory_preserve_mode, message, flags, error);
7e2a3fcc
YW
2065
2066 if (streq(name, "UMask"))
2067 return bus_set_transient_mode_t(u, name, &c->umask, message, flags, error);
2068
2069 if (streq(name, "RuntimeDirectoryMode"))
2070 return bus_set_transient_mode_t(u, name, &c->directories[EXEC_DIRECTORY_RUNTIME].mode, message, flags, error);
2071
2072 if (streq(name, "StateDirectoryMode"))
2073 return bus_set_transient_mode_t(u, name, &c->directories[EXEC_DIRECTORY_STATE].mode, message, flags, error);
2074
2075 if (streq(name, "CacheDirectoryMode"))
2076 return bus_set_transient_mode_t(u, name, &c->directories[EXEC_DIRECTORY_CACHE].mode, message, flags, error);
2077
2078 if (streq(name, "LogsDirectoryMode"))
2079 return bus_set_transient_mode_t(u, name, &c->directories[EXEC_DIRECTORY_LOGS].mode, message, flags, error);
2080
2081 if (streq(name, "ConfigurationDirectoryMode"))
2082 return bus_set_transient_mode_t(u, name, &c->directories[EXEC_DIRECTORY_CONFIGURATION].mode, message, flags, error);
2083
2084 if (streq(name, "SELinuxContext"))
2085 return bus_set_transient_string(u, name, &c->selinux_context, message, flags, error);
2086
2087 if (streq(name, "SecureBits"))
2088 return bus_set_transient_secure_bits(u, name, &c->secure_bits, message, flags, error);
2089
2090 if (streq(name, "CapabilityBoundingSet"))
2091 return bus_set_transient_capability(u, name, &c->capability_bounding_set, message, flags, error);
2092
2093 if (streq(name, "AmbientCapabilities"))
2094 return bus_set_transient_capability(u, name, &c->capability_ambient_set, message, flags, error);
2095
7e2a3fcc
YW
2096 if (streq(name, "RestrictNamespaces"))
2097 return bus_set_transient_namespace_flag(u, name, &c->restrict_namespaces, message, flags, error);
2098
cc86a278
ILG
2099 if (streq(name, "RestrictFileSystems")) {
2100 int allow_list;
2101 _cleanup_strv_free_ char **l = NULL;
2102
2103 r = sd_bus_message_enter_container(message, 'r', "bas");
2104 if (r < 0)
2105 return r;
2106
2107 r = sd_bus_message_read(message, "b", &allow_list);
2108 if (r < 0)
2109 return r;
2110
2111 r = sd_bus_message_read_strv(message, &l);
2112 if (r < 0)
2113 return r;
2114
2115 r = sd_bus_message_exit_container(message);
2116 if (r < 0)
2117 return r;
2118
2119 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2120 _cleanup_free_ char *joined = NULL;
2121 FilesystemParseFlags invert_flag = allow_list ? 0 : FILESYSTEM_PARSE_INVERT;
cc86a278
ILG
2122
2123 if (strv_isempty(l)) {
2124 c->restrict_filesystems_allow_list = false;
1a572fd0 2125 c->restrict_filesystems = set_free_free(c->restrict_filesystems);
cc86a278
ILG
2126
2127 unit_write_setting(u, flags, name, "RestrictFileSystems=");
2128 return 1;
2129 }
2130
2131 if (!c->restrict_filesystems)
2132 c->restrict_filesystems_allow_list = allow_list;
2133
2134 STRV_FOREACH(s, l) {
2135 r = lsm_bpf_parse_filesystem(
2136 *s,
2137 &c->restrict_filesystems,
2138 FILESYSTEM_PARSE_LOG|
2139 (invert_flag ? FILESYSTEM_PARSE_INVERT : 0)|
2140 (c->restrict_filesystems_allow_list ? FILESYSTEM_PARSE_ALLOW_LIST : 0),
2141 u->id, NULL, 0);
2142 if (r < 0)
2143 return r;
2144 }
2145
2146 joined = strv_join(l, " ");
2147 if (!joined)
2148 return -ENOMEM;
2149
2150 unit_write_settingf(u, flags, name, "%s=%s%s", name, allow_list ? "" : "~", joined);
2151 }
2152
2153 return 1;
2154 }
2155
7e2a3fcc 2156 if (streq(name, "MountFlags"))
874cdcbc 2157 return bus_set_transient_mount_propagation_flag(u, name, &c->mount_propagation_flag, message, flags, error);
7e2a3fcc 2158
a8d08f39
LP
2159 if (streq(name, "NetworkNamespacePath"))
2160 return bus_set_transient_path(u, name, &c->network_namespace_path, message, flags, error);
2161
a70581ff
XR
2162 if (streq(name, "IPCNamespacePath"))
2163 return bus_set_transient_path(u, name, &c->ipc_namespace_path, message, flags, error);
2164
7e2a3fcc 2165 if (streq(name, "SupplementaryGroups")) {
cffaed83 2166 _cleanup_strv_free_ char **l = NULL;
cffaed83
YW
2167
2168 r = sd_bus_message_read_strv(message, &l);
2169 if (r < 0)
2170 return r;
2171
d2a23692 2172 STRV_FOREACH(p, l)
7a8867ab 2173 if (!isempty(*p) && !valid_user_group_name(*p, VALID_USER_ALLOW_NUMERIC|VALID_USER_RELAX|VALID_USER_WARN))
d2a23692
ZJS
2174 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS,
2175 "Invalid supplementary group names");
cffaed83 2176
2e59b241 2177 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
7b943bb7 2178 if (strv_isempty(l)) {
cffaed83 2179 c->supplementary_groups = strv_free(c->supplementary_groups);
2e59b241 2180 unit_write_settingf(u, flags, name, "%s=", name);
cffaed83
YW
2181 } else {
2182 _cleanup_free_ char *joined = NULL;
2183
2184 r = strv_extend_strv(&c->supplementary_groups, l, true);
2185 if (r < 0)
2186 return -ENOMEM;
2187
2188 joined = strv_join(c->supplementary_groups, " ");
2189 if (!joined)
2190 return -ENOMEM;
2191
2e59b241 2192 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "%s=%s", name, joined);
cffaed83
YW
2193 }
2194 }
2195
2196 return 1;
2197
43144be4 2198 } else if (STR_IN_SET(name, "SetCredential", "SetCredentialEncrypted")) {
bb0c0d6f
LP
2199 bool isempty = true;
2200
2201 r = sd_bus_message_enter_container(message, 'a', "(say)");
2202 if (r < 0)
2203 return r;
2204
2205 for (;;) {
2206 const char *id;
2207 const void *p;
2208 size_t sz;
2209
2210 r = sd_bus_message_enter_container(message, 'r', "say");
2211 if (r < 0)
2212 return r;
2213 if (r == 0)
2214 break;
2215
2216 r = sd_bus_message_read(message, "s", &id);
2217 if (r < 0)
2218 return r;
2219
2220 r = sd_bus_message_read_array(message, 'y', &p, &sz);
2221 if (r < 0)
2222 return r;
2223
2224 r = sd_bus_message_exit_container(message);
2225 if (r < 0)
2226 return r;
2227
2228 if (!credential_name_valid(id))
2229 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Credential ID is invalid: %s", id);
2230
2231 isempty = false;
2232
2233 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2234 _cleanup_free_ char *a = NULL, *b = NULL;
2235 _cleanup_free_ void *copy = NULL;
2236 ExecSetCredential *old;
2237
2238 copy = memdup(p, sz);
2239 if (!copy)
2240 return -ENOMEM;
2241
2242 old = hashmap_get(c->set_credentials, id);
2243 if (old) {
2244 free_and_replace(old->data, copy);
2245 old->size = sz;
43144be4 2246 old->encrypted = streq(name, "SetCredentialEncrypted");
bb0c0d6f
LP
2247 } else {
2248 _cleanup_(exec_set_credential_freep) ExecSetCredential *sc = NULL;
2249
43144be4 2250 sc = new(ExecSetCredential, 1);
bb0c0d6f
LP
2251 if (!sc)
2252 return -ENOMEM;
2253
43144be4
LP
2254 *sc = (ExecSetCredential) {
2255 .id = strdup(id),
2256 .data = TAKE_PTR(copy),
2257 .size = sz,
2258 .encrypted = streq(name, "SetCredentialEncrypted"),
2259 };
2260
bb0c0d6f
LP
2261 if (!sc->id)
2262 return -ENOMEM;
2263
cf55fe4a 2264 r = hashmap_ensure_put(&c->set_credentials, &exec_set_credential_hash_ops, sc->id, sc);
bb0c0d6f
LP
2265 if (r < 0)
2266 return r;
2267
2268 TAKE_PTR(sc);
2269 }
2270
2271 a = specifier_escape(id);
2272 if (!a)
2273 return -ENOMEM;
2274
2275 b = cescape_length(p, sz);
2276 if (!b)
2277 return -ENOMEM;
2278
2279 (void) unit_write_settingf(u, flags, name, "%s=%s:%s", name, a, b);
2280 }
2281 }
2282
2283 r = sd_bus_message_exit_container(message);
2284 if (r < 0)
2285 return r;
2286
2287 if (!UNIT_WRITE_FLAGS_NOOP(flags) && isempty) {
2288 c->set_credentials = hashmap_free(c->set_credentials);
2289 (void) unit_write_settingf(u, flags, name, "%s=", name);
2290 }
2291
2292 return 1;
2293
43144be4 2294 } else if (STR_IN_SET(name, "LoadCredential", "LoadCredentialEncrypted")) {
bb0c0d6f
LP
2295 bool isempty = true;
2296
2297 r = sd_bus_message_enter_container(message, 'a', "(ss)");
2298 if (r < 0)
2299 return r;
2300
2301 for (;;) {
2302 const char *id, *source;
2303
2304 r = sd_bus_message_read(message, "(ss)", &id, &source);
2305 if (r < 0)
2306 return r;
2307 if (r == 0)
2308 break;
2309
2310 if (!credential_name_valid(id))
2311 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Credential ID is invalid: %s", id);
2312
2313 if (!(path_is_absolute(source) ? path_is_normalized(source) : credential_name_valid(source)))
2314 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Credential source is invalid: %s", source);
2315
2316 isempty = false;
2317
2318 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
bbfb25f4 2319 bool encrypted = streq(name, "LoadCredentialEncrypted");
43144be4 2320
bbfb25f4
DDM
2321 r = hashmap_put_credential(&c->load_credentials, id, source, encrypted);
2322 if (r < 0)
2323 return r;
43144be4 2324
bbfb25f4
DDM
2325 (void) unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "%s=%s:%s", name, id, source);
2326 }
2327 }
43144be4 2328
bbfb25f4
DDM
2329 r = sd_bus_message_exit_container(message);
2330 if (r < 0)
2331 return r;
43144be4 2332
bbfb25f4
DDM
2333 if (!UNIT_WRITE_FLAGS_NOOP(flags) && isempty) {
2334 c->load_credentials = hashmap_free(c->load_credentials);
2335 (void) unit_write_settingf(u, flags, name, "%s=", name);
2336 }
43144be4 2337
bbfb25f4 2338 return 1;
43144be4 2339
bbfb25f4
DDM
2340 } else if (streq(name, "ImportCredential")) {
2341 bool isempty = true;
43144be4 2342
bbfb25f4
DDM
2343 r = sd_bus_message_enter_container(message, 'a', "s");
2344 if (r < 0)
2345 return r;
bb0c0d6f 2346
bbfb25f4
DDM
2347 for (;;) {
2348 const char *s;
2349
2350 r = sd_bus_message_read(message, "s", &s);
2351 if (r < 0)
2352 return r;
2353 if (r == 0)
2354 break;
2355
947c4d39
LP
2356 if (!credential_glob_valid(s))
2357 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Credential name or glob is invalid: %s", s);
bbfb25f4
DDM
2358
2359 isempty = false;
2360
2361 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2362 r = set_put_strdup(&c->import_credentials, s);
2363 if (r < 0)
2364 return r;
2365
2366 (void) unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "%s=%s", name, s);
bb0c0d6f
LP
2367 }
2368 }
2369
2370 r = sd_bus_message_exit_container(message);
2371 if (r < 0)
2372 return r;
2373
2374 if (!UNIT_WRITE_FLAGS_NOOP(flags) && isempty) {
1a572fd0 2375 c->import_credentials = set_free_free(c->import_credentials);
bb0c0d6f
LP
2376 (void) unit_write_settingf(u, flags, name, "%s=", name);
2377 }
2378
2379 return 1;
2380
a8a13575 2381 } else if (streq(name, "SyslogLevel")) {
8d1dd6ab 2382 int32_t level;
a8a13575
EV
2383
2384 r = sd_bus_message_read(message, "i", &level);
2385 if (r < 0)
2386 return r;
2387
e0d6e0fa 2388 if (!log_level_is_valid(level))
1b09b81c 2389 return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Log level value out of range");
e0d6e0fa 2390
2e59b241 2391 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
a8a13575 2392 c->syslog_priority = (c->syslog_priority & LOG_FACMASK) | level;
2e59b241 2393 unit_write_settingf(u, flags, name, "SyslogLevel=%i", level);
a8a13575
EV
2394 }
2395
460ed929 2396 return 1;
7e2a3fcc 2397
460ed929 2398 } else if (streq(name, "SyslogFacility")) {
8d1dd6ab 2399 int32_t facility;
460ed929
EV
2400
2401 r = sd_bus_message_read(message, "i", &facility);
2402 if (r < 0)
2403 return r;
2404
e0d6e0fa 2405 if (!log_facility_unshifted_is_valid(facility))
1b09b81c 2406 return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Log facility value out of range");
e0d6e0fa 2407
2e59b241 2408 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
460ed929 2409 c->syslog_priority = (facility << 3) | LOG_PRI(c->syslog_priority);
2e59b241 2410 unit_write_settingf(u, flags, name, "SyslogFacility=%i", facility);
460ed929
EV
2411 }
2412
cffaed83 2413 return 1;
d3070fbd 2414
91dd5f7c
LP
2415 } else if (streq(name, "LogNamespace")) {
2416 const char *n;
2417
2418 r = sd_bus_message_read(message, "s", &n);
2419 if (r < 0)
2420 return r;
2421
2422 if (!isempty(n) && !log_namespace_name_valid(n))
1b09b81c 2423 return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Log namespace name not valid");
91dd5f7c
LP
2424
2425 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2426
2427 if (isempty(n)) {
2428 c->log_namespace = mfree(c->log_namespace);
2429 unit_write_settingf(u, flags, name, "%s=", name);
2430 } else {
2431 r = free_and_strdup(&c->log_namespace, n);
2432 if (r < 0)
2433 return r;
2434
2435 unit_write_settingf(u, flags, name, "%s=%s", name, n);
2436 }
2437 }
2438
2439 return 1;
2440
d3070fbd
LP
2441 } else if (streq(name, "LogExtraFields")) {
2442 size_t n = 0;
2443
2444 r = sd_bus_message_enter_container(message, 'a', "ay");
2445 if (r < 0)
2446 return r;
2447
2448 for (;;) {
2449 _cleanup_free_ void *copy = NULL;
2450 struct iovec *t;
2451 const char *eq;
2452 const void *p;
2453 size_t sz;
2454
2455 /* Note that we expect a byte array for each field, instead of a string. That's because on the
2456 * lower-level journal fields can actually contain binary data and are not restricted to text,
2457 * and we should not "lose precision" in our types on the way. That said, I am pretty sure
2458 * actually encoding binary data as unit metadata is not a good idea. Hence we actually refuse
2459 * any actual binary data, and only accept UTF-8. This allows us to eventually lift this
7227dd81 2460 * limitation, should a good, valid use case arise. */
d3070fbd
LP
2461
2462 r = sd_bus_message_read_array(message, 'y', &p, &sz);
2463 if (r < 0)
2464 return r;
2465 if (r == 0)
2466 break;
2467
2468 if (memchr(p, 0, sz))
1b09b81c 2469 return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Journal field contains zero byte");
d3070fbd
LP
2470
2471 eq = memchr(p, '=', sz);
2472 if (!eq)
1b09b81c 2473 return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Journal field contains no '=' character");
d3070fbd 2474 if (!journal_field_valid(p, eq - (const char*) p, false))
1b09b81c 2475 return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Journal field invalid");
d3070fbd 2476
2e59b241 2477 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
aa484f35 2478 t = reallocarray(c->log_extra_fields, c->n_log_extra_fields+1, sizeof(struct iovec));
d3070fbd
LP
2479 if (!t)
2480 return -ENOMEM;
2481 c->log_extra_fields = t;
2482 }
2483
2484 copy = malloc(sz + 1);
2485 if (!copy)
2486 return -ENOMEM;
2487
2488 memcpy(copy, p, sz);
2489 ((uint8_t*) copy)[sz] = 0;
2490
2491 if (!utf8_is_valid(copy))
1b09b81c 2492 return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Journal field is not valid UTF-8");
d3070fbd 2493
2e59b241 2494 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
d3070fbd 2495 c->log_extra_fields[c->n_log_extra_fields++] = IOVEC_MAKE(copy, sz);
2e59b241 2496 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS|UNIT_ESCAPE_C, name, "LogExtraFields=%s", (char*) copy);
d3070fbd
LP
2497
2498 copy = NULL;
2499 }
2500
2501 n++;
2502 }
2503
2504 r = sd_bus_message_exit_container(message);
2505 if (r < 0)
2506 return r;
2507
2e59b241 2508 if (!UNIT_WRITE_FLAGS_NOOP(flags) && n == 0) {
d3070fbd 2509 exec_context_free_log_extra_fields(c);
2e59b241 2510 unit_write_setting(u, flags, name, "LogExtraFields=");
d3070fbd
LP
2511 }
2512
2513 return 1;
7e2a3fcc 2514 }
cffaed83 2515
349cc4a5 2516#if HAVE_SECCOMP
cffaed83 2517
7e2a3fcc
YW
2518 if (streq(name, "SystemCallErrorNumber"))
2519 return bus_set_transient_errno(u, name, &c->syscall_errno, message, flags, error);
2520
2521 if (streq(name, "SystemCallFilter")) {
6b000af4 2522 int allow_list;
3f856a28 2523 _cleanup_strv_free_ char **l = NULL;
cffaed83
YW
2524
2525 r = sd_bus_message_enter_container(message, 'r', "bas");
2526 if (r < 0)
2527 return r;
2528
6b000af4 2529 r = sd_bus_message_read(message, "b", &allow_list);
cffaed83
YW
2530 if (r < 0)
2531 return r;
2532
2533 r = sd_bus_message_read_strv(message, &l);
2534 if (r < 0)
2535 return r;
2536
2537 r = sd_bus_message_exit_container(message);
2538 if (r < 0)
2539 return r;
2540
2e59b241 2541 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
cffaed83 2542 _cleanup_free_ char *joined = NULL;
6b000af4 2543 SeccompParseFlags invert_flag = allow_list ? 0 : SECCOMP_PARSE_INVERT;
cffaed83 2544
7b943bb7 2545 if (strv_isempty(l)) {
6b000af4 2546 c->syscall_allow_list = false;
8cfa775f 2547 c->syscall_filter = hashmap_free(c->syscall_filter);
cffaed83 2548
898748d8
YW
2549 unit_write_settingf(u, flags, name, "SystemCallFilter=");
2550 return 1;
2551 }
cffaed83 2552
898748d8
YW
2553 if (!c->syscall_filter) {
2554 c->syscall_filter = hashmap_new(NULL);
2555 if (!c->syscall_filter)
2556 return log_oom();
cffaed83 2557
6b000af4 2558 c->syscall_allow_list = allow_list;
8cfa775f 2559
6b000af4 2560 if (c->syscall_allow_list) {
e7ccdfa8
ZJS
2561 r = seccomp_parse_syscall_filter("@default",
2562 -1,
2563 c->syscall_filter,
72545ae0 2564 SECCOMP_PARSE_PERMISSIVE |
1008d415 2565 SECCOMP_PARSE_ALLOW_LIST,
58f6ab44
ZJS
2566 u->id,
2567 NULL, 0);
8cfa775f
YW
2568 if (r < 0)
2569 return r;
898748d8
YW
2570 }
2571 }
8cfa775f 2572
898748d8
YW
2573 STRV_FOREACH(s, l) {
2574 _cleanup_free_ char *n = NULL;
2575 int e;
cffaed83 2576
898748d8
YW
2577 r = parse_syscall_and_errno(*s, &n, &e);
2578 if (r < 0)
2579 return r;
cffaed83 2580
084a46d7
YW
2581 if (allow_list && e >= 0)
2582 return -EINVAL;
2583
e7ccdfa8
ZJS
2584 r = seccomp_parse_syscall_filter(n,
2585 e,
2586 c->syscall_filter,
72545ae0
AZ
2587 SECCOMP_PARSE_LOG | SECCOMP_PARSE_PERMISSIVE |
2588 invert_flag |
6b000af4 2589 (c->syscall_allow_list ? SECCOMP_PARSE_ALLOW_LIST : 0),
58f6ab44
ZJS
2590 u->id,
2591 NULL, 0);
898748d8
YW
2592 if (r < 0)
2593 return r;
cffaed83
YW
2594 }
2595
2596 joined = strv_join(l, " ");
2597 if (!joined)
2598 return -ENOMEM;
2599
6b000af4 2600 unit_write_settingf(u, flags, name, "SystemCallFilter=%s%s", allow_list ? "" : "~", joined);
cffaed83
YW
2601 }
2602
2603 return 1;
2604
9df2cdd8
TM
2605 } else if (streq(name, "SystemCallLog")) {
2606 int allow_list;
2607 _cleanup_strv_free_ char **l = NULL;
2608
2609 r = sd_bus_message_enter_container(message, 'r', "bas");
2610 if (r < 0)
2611 return r;
2612
2613 r = sd_bus_message_read(message, "b", &allow_list);
2614 if (r < 0)
2615 return r;
2616
2617 r = sd_bus_message_read_strv(message, &l);
2618 if (r < 0)
2619 return r;
2620
2621 r = sd_bus_message_exit_container(message);
2622 if (r < 0)
2623 return r;
2624
2625 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2626 _cleanup_free_ char *joined = NULL;
2627 SeccompParseFlags invert_flag = allow_list ? 0 : SECCOMP_PARSE_INVERT;
9df2cdd8
TM
2628
2629 if (strv_isempty(l)) {
2630 c->syscall_log_allow_list = false;
2631 c->syscall_log = hashmap_free(c->syscall_log);
2632
2633 unit_write_settingf(u, flags, name, "SystemCallLog=");
2634 return 1;
2635 }
2636
2637 if (!c->syscall_log) {
2638 c->syscall_log = hashmap_new(NULL);
2639 if (!c->syscall_log)
2640 return log_oom();
2641
2642 c->syscall_log_allow_list = allow_list;
2643 }
2644
2645 STRV_FOREACH(s, l) {
696a13ba
YW
2646 r = seccomp_parse_syscall_filter(*s,
2647 -1, /* errno not used */
9df2cdd8
TM
2648 c->syscall_log,
2649 SECCOMP_PARSE_LOG | SECCOMP_PARSE_PERMISSIVE |
2650 invert_flag |
2651 (c->syscall_log_allow_list ? SECCOMP_PARSE_ALLOW_LIST : 0),
2652 u->id,
2653 NULL, 0);
2654 if (r < 0)
2655 return r;
2656 }
2657
2658 joined = strv_join(l, " ");
2659 if (!joined)
2660 return -ENOMEM;
2661
2662 unit_write_settingf(u, flags, name, "SystemCallLog=%s%s", allow_list ? "" : "~", joined);
2663 }
2664
2665 return 1;
2666
cffaed83
YW
2667 } else if (streq(name, "SystemCallArchitectures")) {
2668 _cleanup_strv_free_ char **l = NULL;
2669
2670 r = sd_bus_message_read_strv(message, &l);
2671 if (r < 0)
2672 return r;
2673
2e59b241 2674 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
cffaed83
YW
2675 _cleanup_free_ char *joined = NULL;
2676
7b943bb7 2677 if (strv_isempty(l))
cffaed83 2678 c->syscall_archs = set_free(c->syscall_archs);
de010b0b 2679 else
cffaed83
YW
2680 STRV_FOREACH(s, l) {
2681 uint32_t a;
2682
2683 r = seccomp_arch_from_string(*s, &a);
2684 if (r < 0)
2685 return r;
2686
de7fef4b 2687 r = set_ensure_put(&c->syscall_archs, NULL, UINT32_TO_PTR(a + 1));
cffaed83
YW
2688 if (r < 0)
2689 return r;
2690 }
2691
cffaed83
YW
2692 joined = strv_join(l, " ");
2693 if (!joined)
2694 return -ENOMEM;
2695
2e59b241 2696 unit_write_settingf(u, flags, name, "%s=%s", name, joined);
cffaed83
YW
2697 }
2698
2699 return 1;
2700
cffaed83 2701 } else if (streq(name, "RestrictAddressFamilies")) {
3f856a28 2702 _cleanup_strv_free_ char **l = NULL;
4e6c50a5 2703 int allow_list;
cffaed83
YW
2704
2705 r = sd_bus_message_enter_container(message, 'r', "bas");
2706 if (r < 0)
2707 return r;
2708
6b000af4 2709 r = sd_bus_message_read(message, "b", &allow_list);
cffaed83
YW
2710 if (r < 0)
2711 return r;
2712
2713 r = sd_bus_message_read_strv(message, &l);
2714 if (r < 0)
2715 return r;
2716
2717 r = sd_bus_message_exit_container(message);
2718 if (r < 0)
2719 return r;
2720
2e59b241 2721 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
cffaed83
YW
2722 _cleanup_free_ char *joined = NULL;
2723
7b943bb7 2724 if (strv_isempty(l)) {
4e6c50a5 2725 c->address_families_allow_list = allow_list;
cffaed83 2726 c->address_families = set_free(c->address_families);
cffaed83 2727
4e6c50a5
YW
2728 unit_write_settingf(u, flags, name, "RestrictAddressFamilies=%s",
2729 allow_list ? "none" : "");
9ee896d5
YW
2730 return 1;
2731 }
cffaed83 2732
9ee896d5
YW
2733 if (!c->address_families) {
2734 c->address_families = set_new(NULL);
2735 if (!c->address_families)
2736 return log_oom();
cffaed83 2737
6b000af4 2738 c->address_families_allow_list = allow_list;
9ee896d5
YW
2739 }
2740
2741 STRV_FOREACH(s, l) {
2742 int af;
cffaed83 2743
9ee896d5 2744 af = af_from_name(*s);
acf4d158
YW
2745 if (af < 0)
2746 return af;
cffaed83 2747
6b000af4 2748 if (allow_list == c->address_families_allow_list) {
cffaed83
YW
2749 r = set_put(c->address_families, INT_TO_PTR(af));
2750 if (r < 0)
2751 return r;
9ee896d5 2752 } else
4e6c50a5 2753 set_remove(c->address_families, INT_TO_PTR(af));
cffaed83
YW
2754 }
2755
2756 joined = strv_join(l, " ");
2757 if (!joined)
2758 return -ENOMEM;
2759
6b000af4 2760 unit_write_settingf(u, flags, name, "RestrictAddressFamilies=%s%s", allow_list ? "" : "~", joined);
cffaed83
YW
2761 }
2762
2763 return 1;
7e2a3fcc 2764 }
cffaed83 2765#endif
b070c7c0 2766 if (STR_IN_SET(name, "CPUAffinity", "NUMAMask")) {
cffaed83 2767 const void *a;
bd0abfae 2768 size_t n;
b070c7c0 2769 bool affinity = streq(name, "CPUAffinity");
c367f996 2770 _cleanup_(cpu_set_reset) CPUSet set = {};
cffaed83
YW
2771
2772 r = sd_bus_message_read_array(message, 'y', &a, &n);
2773 if (r < 0)
2774 return r;
2775
c367f996
MS
2776 r = cpu_set_from_dbus(a, n, &set);
2777 if (r < 0)
2778 return r;
2779
2e59b241 2780 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
cffaed83 2781 if (n == 0) {
b070c7c0 2782 cpu_set_reset(affinity ? &c->cpu_set : &c->numa_policy.nodes);
2e59b241 2783 unit_write_settingf(u, flags, name, "%s=", name);
cffaed83
YW
2784 } else {
2785 _cleanup_free_ char *str = NULL;
cffaed83 2786
0985c7c4 2787 str = cpu_set_to_string(&set);
a832893f
ZJS
2788 if (!str)
2789 return -ENOMEM;
cffaed83 2790
0985c7c4
ZJS
2791 /* We forego any optimizations here, and always create the structure using
2792 * cpu_set_add_all(), because we don't want to care if the existing size we
2793 * got over dbus is appropriate. */
b070c7c0 2794 r = cpu_set_add_all(affinity ? &c->cpu_set : &c->numa_policy.nodes, &set);
0985c7c4
ZJS
2795 if (r < 0)
2796 return r;
501941aa 2797
2e59b241 2798 unit_write_settingf(u, flags, name, "%s=%s", name, str);
cffaed83
YW
2799 }
2800 }
2801
c7040b5d
LP
2802 return 1;
2803
e2b2fb7f
MS
2804 } else if (streq(name, "CPUAffinityFromNUMA")) {
2805 int q;
2806
2807 r = sd_bus_message_read_basic(message, 'b', &q);
2808 if (r < 0)
2809 return r;
2810
2811 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2812 c->cpu_affinity_from_numa = q;
2813 unit_write_settingf(u, flags, name, "%s=%s", "CPUAffinity", "numa");
2814 }
2815
2816 return 1;
2817
b070c7c0
MS
2818 } else if (streq(name, "NUMAPolicy")) {
2819 int32_t type;
2820
2821 r = sd_bus_message_read(message, "i", &type);
2822 if (r < 0)
2823 return r;
2824
2825 if (!mpol_is_valid(type))
2826 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid NUMAPolicy value: %i", type);
2827
2828 if (!UNIT_WRITE_FLAGS_NOOP(flags))
2829 c->numa_policy.type = type;
2830
2831 return 1;
e2b2fb7f 2832
c250bf67
YW
2833 } else if (streq(name, "Nice")) {
2834 int32_t q;
2835
2836 r = sd_bus_message_read(message, "i", &q);
2837 if (r < 0)
2838 return r;
2839
2840 if (!nice_is_valid(q))
2841 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid Nice value: %i", q);
2842
2843 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2844 c->nice = q;
2845 c->nice_set = true;
2846
2847 unit_write_settingf(u, flags, name, "Nice=%i", q);
2848 }
2849
2850 return 1;
2851
2852 } else if (streq(name, "CPUSchedulingPolicy")) {
2853 int32_t q;
2854
2855 r = sd_bus_message_read(message, "i", &q);
2856 if (r < 0)
2857 return r;
2858
2859 if (!sched_policy_is_valid(q))
2860 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid CPU scheduling policy: %i", q);
2861
2862 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2863 _cleanup_free_ char *s = NULL;
2864
2865 r = sched_policy_to_string_alloc(q, &s);
2866 if (r < 0)
2867 return r;
2868
2869 c->cpu_sched_policy = q;
2870 c->cpu_sched_priority = CLAMP(c->cpu_sched_priority, sched_get_priority_min(q), sched_get_priority_max(q));
2871 c->cpu_sched_set = true;
2872
2873 unit_write_settingf(u, flags, name, "CPUSchedulingPolicy=%s", s);
2874 }
2875
2876 return 1;
2877
2878 } else if (streq(name, "CPUSchedulingPriority")) {
40c05a34 2879 int32_t p;
c250bf67
YW
2880
2881 r = sd_bus_message_read(message, "i", &p);
2882 if (r < 0)
2883 return r;
2884
40c05a34
LB
2885 /* On Linux RR/FIFO range from 1 to 99 and OTHER/BATCH may only be 0. Policy might be set
2886 * later so we do not check the precise range, but only the generic outer bounds. */
2887 if (p < 0 || p > 99)
c250bf67
YW
2888 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid CPU scheduling priority: %i", p);
2889
2890 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2891 c->cpu_sched_priority = p;
2892 c->cpu_sched_set = true;
2893
2894 unit_write_settingf(u, flags, name, "CPUSchedulingPriority=%i", p);
2895 }
2896
2897 return 1;
2898
7f452159
LP
2899 } else if (streq(name, "IOSchedulingClass")) {
2900 int32_t q;
2901
2902 r = sd_bus_message_read(message, "i", &q);
2903 if (r < 0)
2904 return r;
2905
2906 if (!ioprio_class_is_valid(q))
2907 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid IO scheduling class: %i", q);
2908
2e59b241 2909 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
7f452159
LP
2910 _cleanup_free_ char *s = NULL;
2911
2912 r = ioprio_class_to_string_alloc(q, &s);
2913 if (r < 0)
2914 return r;
2915
ba7772fe 2916 c->ioprio = ioprio_normalize(ioprio_prio_value(q, ioprio_prio_data(c->ioprio)));
7f452159
LP
2917 c->ioprio_set = true;
2918
2e59b241 2919 unit_write_settingf(u, flags, name, "IOSchedulingClass=%s", s);
7f452159
LP
2920 }
2921
2922 return 1;
2923
2924 } else if (streq(name, "IOSchedulingPriority")) {
2925 int32_t p;
2926
2927 r = sd_bus_message_read(message, "i", &p);
2928 if (r < 0)
2929 return r;
2930
2931 if (!ioprio_priority_is_valid(p))
2932 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid IO scheduling priority: %i", p);
2933
2e59b241 2934 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
ba7772fe 2935 c->ioprio = ioprio_normalize(ioprio_prio_value(ioprio_prio_class(c->ioprio), p));
7f452159
LP
2936 c->ioprio_set = true;
2937
2e59b241 2938 unit_write_settingf(u, flags, name, "IOSchedulingPriority=%i", p);
7f452159
LP
2939 }
2940
2941 return 1;
2942
5e98086d
ZJS
2943 } else if (streq(name, "MountAPIVFS")) {
2944 bool b;
2945
2946 r = bus_set_transient_bool(u, name, &b, message, flags, error);
2947 if (r < 0)
2948 return r;
2949
2950 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2951 c->mount_apivfs = b;
2952 c->mount_apivfs_set = true;
2953 }
2954
2955 return 1;
2956
5f5d8eab
LP
2957 } else if (streq(name, "WorkingDirectory")) {
2958 const char *s;
2959 bool missing_ok;
2960
2961 r = sd_bus_message_read(message, "s", &s);
2962 if (r < 0)
2963 return r;
2964
2965 if (s[0] == '-') {
2966 missing_ok = true;
2967 s++;
2968 } else
2969 missing_ok = false;
2970
d6ff82d3 2971 if (!isempty(s) && !streq(s, "~") && !path_is_absolute(s))
1b09b81c 2972 return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "WorkingDirectory= expects an absolute path or '~'");
5f5d8eab 2973
2e59b241 2974 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
5f5d8eab
LP
2975 if (streq(s, "~")) {
2976 c->working_directory = mfree(c->working_directory);
2977 c->working_directory_home = true;
2978 } else {
d6ff82d3 2979 r = free_and_strdup(&c->working_directory, empty_to_null(s));
5f5d8eab
LP
2980 if (r < 0)
2981 return r;
2982
2983 c->working_directory_home = false;
2984 }
2985
2986 c->working_directory_missing_ok = missing_ok;
2e59b241 2987 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "WorkingDirectory=%s%s", missing_ok ? "-" : "", s);
5f5d8eab
LP
2988 }
2989
2990 return 1;
2991
52c239d7
LB
2992 } else if (STR_IN_SET(name,
2993 "StandardInputFileDescriptorName", "StandardOutputFileDescriptorName", "StandardErrorFileDescriptorName")) {
2994 const char *s;
2995
2996 r = sd_bus_message_read(message, "s", &s);
2997 if (r < 0)
2998 return r;
2999
d6ff82d3 3000 if (!isempty(s) && !fdname_is_valid(s))
1b09b81c 3001 return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid file descriptor name");
52c239d7 3002
2e59b241 3003 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
5073ff6b 3004
52c239d7 3005 if (streq(name, "StandardInputFileDescriptorName")) {
d6ff82d3 3006 r = free_and_strdup(c->stdio_fdname + STDIN_FILENO, empty_to_null(s));
52c239d7
LB
3007 if (r < 0)
3008 return r;
5073ff6b 3009
0664775c 3010 c->std_input = EXEC_INPUT_NAMED_FD;
2e59b241 3011 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardInput=fd:%s", exec_context_fdname(c, STDIN_FILENO));
5073ff6b 3012
52c239d7 3013 } else if (streq(name, "StandardOutputFileDescriptorName")) {
d6ff82d3 3014 r = free_and_strdup(c->stdio_fdname + STDOUT_FILENO, empty_to_null(s));
52c239d7
LB
3015 if (r < 0)
3016 return r;
5073ff6b 3017
52c239d7 3018 c->std_output = EXEC_OUTPUT_NAMED_FD;
2e59b241 3019 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardOutput=fd:%s", exec_context_fdname(c, STDOUT_FILENO));
0664775c
LP
3020
3021 } else {
3022 assert(streq(name, "StandardErrorFileDescriptorName"));
5073ff6b 3023
d6ff82d3 3024 r = free_and_strdup(&c->stdio_fdname[STDERR_FILENO], empty_to_null(s));
52c239d7
LB
3025 if (r < 0)
3026 return r;
5073ff6b 3027
52c239d7 3028 c->std_error = EXEC_OUTPUT_NAMED_FD;
2e59b241 3029 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardError=fd:%s", exec_context_fdname(c, STDERR_FILENO));
52c239d7
LB
3030 }
3031 }
3032
3033 return 1;
3034
566b7d23
ZD
3035 } else if (STR_IN_SET(name,
3036 "StandardInputFile",
8d7dab1f
LW
3037 "StandardOutputFile", "StandardOutputFileToAppend", "StandardOutputFileToTruncate",
3038 "StandardErrorFile", "StandardErrorFileToAppend", "StandardErrorFileToTruncate")) {
2038c3f5
LP
3039 const char *s;
3040
3041 r = sd_bus_message_read(message, "s", &s);
3042 if (r < 0)
3043 return r;
3044
d6ff82d3
YW
3045 if (!isempty(s)) {
3046 if (!path_is_absolute(s))
3047 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path %s is not absolute", s);
3048 if (!path_is_normalized(s))
3049 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path %s is not normalized", s);
3050 }
2038c3f5 3051
2e59b241 3052 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2038c3f5
LP
3053
3054 if (streq(name, "StandardInputFile")) {
d6ff82d3 3055 r = free_and_strdup(&c->stdio_file[STDIN_FILENO], empty_to_null(s));
52c239d7
LB
3056 if (r < 0)
3057 return r;
2038c3f5
LP
3058
3059 c->std_input = EXEC_INPUT_FILE;
2e59b241 3060 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardInput=file:%s", s);
2038c3f5 3061
8d7dab1f 3062 } else if (STR_IN_SET(name, "StandardOutputFile", "StandardOutputFileToAppend", "StandardOutputFileToTruncate")) {
d6ff82d3 3063 r = free_and_strdup(&c->stdio_file[STDOUT_FILENO], empty_to_null(s));
2038c3f5
LP
3064 if (r < 0)
3065 return r;
3066
566b7d23
ZD
3067 if (streq(name, "StandardOutputFile")) {
3068 c->std_output = EXEC_OUTPUT_FILE;
3069 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardOutput=file:%s", s);
8d7dab1f 3070 } else if (streq(name, "StandardOutputFileToAppend")) {
566b7d23
ZD
3071 c->std_output = EXEC_OUTPUT_FILE_APPEND;
3072 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardOutput=append:%s", s);
8d7dab1f
LW
3073 } else {
3074 assert(streq(name, "StandardOutputFileToTruncate"));
3075 c->std_output = EXEC_OUTPUT_FILE_TRUNCATE;
3076 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardOutput=truncate:%s", s);
566b7d23 3077 }
2038c3f5 3078 } else {
8d7dab1f 3079 assert(STR_IN_SET(name, "StandardErrorFile", "StandardErrorFileToAppend", "StandardErrorFileToTruncate"));
2038c3f5 3080
d6ff82d3 3081 r = free_and_strdup(&c->stdio_file[STDERR_FILENO], empty_to_null(s));
2038c3f5
LP
3082 if (r < 0)
3083 return r;
3084
566b7d23
ZD
3085 if (streq(name, "StandardErrorFile")) {
3086 c->std_error = EXEC_OUTPUT_FILE;
1704fba9 3087 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardError=file:%s", s);
8d7dab1f 3088 } else if (streq(name, "StandardErrorFileToAppend")) {
dbe6c4b6 3089 c->std_error = EXEC_OUTPUT_FILE_APPEND;
1704fba9 3090 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardError=append:%s", s);
8d7dab1f
LW
3091 } else {
3092 assert(streq(name, "StandardErrorFileToTruncate"));
3093 c->std_error = EXEC_OUTPUT_FILE_TRUNCATE;
3094 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardError=truncate:%s", s);
566b7d23 3095 }
2038c3f5
LP
3096 }
3097 }
3098
3099 return 1;
3100
08f3be7a
LP
3101 } else if (streq(name, "StandardInputData")) {
3102 const void *p;
3103 size_t sz;
3104
3105 r = sd_bus_message_read_array(message, 'y', &p, &sz);
3106 if (r < 0)
3107 return r;
3108
2e59b241 3109 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
08f3be7a
LP
3110 _cleanup_free_ char *encoded = NULL;
3111
3112 if (sz == 0) {
3113 c->stdin_data = mfree(c->stdin_data);
3114 c->stdin_data_size = 0;
3115
2e59b241 3116 unit_write_settingf(u, flags, name, "StandardInputData=");
08f3be7a
LP
3117 } else {
3118 void *q;
3119 ssize_t n;
3120
3121 if (c->stdin_data_size + sz < c->stdin_data_size || /* check for overflow */
3122 c->stdin_data_size + sz > EXEC_STDIN_DATA_MAX)
3123 return -E2BIG;
3124
3125 n = base64mem(p, sz, &encoded);
3126 if (n < 0)
3127 return (int) n;
3128
3129 q = realloc(c->stdin_data, c->stdin_data_size + sz);
3130 if (!q)
3131 return -ENOMEM;
3132
3133 memcpy((uint8_t*) q + c->stdin_data_size, p, sz);
3134
3135 c->stdin_data = q;
3136 c->stdin_data_size += sz;
3137
2e59b241 3138 unit_write_settingf(u, flags, name, "StandardInputData=%s", encoded);
52c239d7
LB
3139 }
3140 }
3141
3142 return 1;
3143
c7040b5d
LP
3144 } else if (streq(name, "Environment")) {
3145
6171b822 3146 _cleanup_strv_free_ char **l = NULL;
c7040b5d
LP
3147
3148 r = sd_bus_message_read_strv(message, &l);
3149 if (r < 0)
3150 return r;
3151
6171b822 3152 if (!strv_env_is_valid(l))
1b09b81c 3153 return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid environment block.");
1c68232e 3154
2e59b241 3155 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
7b943bb7 3156 if (strv_isempty(l)) {
e9876fc9 3157 c->environment = strv_free(c->environment);
2e59b241 3158 unit_write_setting(u, flags, name, "Environment=");
e9876fc9 3159 } else {
f900f582
ZJS
3160 _cleanup_free_ char *joined = NULL;
3161 char **e;
3162
2e59b241
LP
3163 joined = unit_concat_strv(l, UNIT_ESCAPE_SPECIFIERS|UNIT_ESCAPE_C);
3164 if (!joined)
3165 return -ENOMEM;
3166
4ab3d29f 3167 e = strv_env_merge(c->environment, l);
e9876fc9
EV
3168 if (!e)
3169 return -ENOMEM;
c7040b5d 3170
130d3d22 3171 strv_free_and_replace(c->environment, e);
2e59b241 3172 unit_write_settingf(u, flags, name, "Environment=%s", joined);
e9876fc9 3173 }
c7040b5d
LP
3174 }
3175
d584f638
LP
3176 return 1;
3177
00819cc1
LP
3178 } else if (streq(name, "UnsetEnvironment")) {
3179
6171b822 3180 _cleanup_strv_free_ char **l = NULL;
00819cc1
LP
3181
3182 r = sd_bus_message_read_strv(message, &l);
3183 if (r < 0)
3184 return r;
3185
6171b822 3186 if (!strv_env_name_or_assignment_is_valid(l))
1b09b81c 3187 return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid UnsetEnvironment= list.");
00819cc1 3188
2e59b241 3189 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
7b943bb7 3190 if (strv_isempty(l)) {
00819cc1 3191 c->unset_environment = strv_free(c->unset_environment);
2e59b241 3192 unit_write_setting(u, flags, name, "UnsetEnvironment=");
00819cc1
LP
3193 } else {
3194 _cleanup_free_ char *joined = NULL;
3195 char **e;
3196
2e59b241
LP
3197 joined = unit_concat_strv(l, UNIT_ESCAPE_SPECIFIERS|UNIT_ESCAPE_C);
3198 if (!joined)
3199 return -ENOMEM;
3200
4ab3d29f 3201 e = strv_env_merge(c->unset_environment, l);
00819cc1
LP
3202 if (!e)
3203 return -ENOMEM;
3204
130d3d22 3205 strv_free_and_replace(c->unset_environment, e);
2e59b241 3206 unit_write_settingf(u, flags, name, "UnsetEnvironment=%s", joined);
00819cc1
LP
3207 }
3208 }
3209
3210 return 1;
3211
6b862936
EV
3212 } else if (streq(name, "OOMScoreAdjust")) {
3213 int oa;
3214
3215 r = sd_bus_message_read(message, "i", &oa);
3216 if (r < 0)
3217 return r;
3218
3219 if (!oom_score_adjust_is_valid(oa))
1b09b81c 3220 return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "OOM score adjust value out of range");
6b862936 3221
2e59b241 3222 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
6b862936
EV
3223 c->oom_score_adjust = oa;
3224 c->oom_score_adjust_set = true;
2e59b241 3225 unit_write_settingf(u, flags, name, "OOMScoreAdjust=%i", oa);
6b862936
EV
3226 }
3227
3228 return 1;
3229
ad21e542
ZJS
3230 } else if (streq(name, "CoredumpFilter")) {
3231 uint64_t f;
3232
3233 r = sd_bus_message_read(message, "t", &f);
3234 if (r < 0)
3235 return r;
3236
3237 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
3238 c->coredump_filter = f;
3239 c->coredump_filter_set = true;
3240 unit_write_settingf(u, flags, name, "CoredumpFilter=0x%"PRIx64, f);
3241 }
3242
3243 return 1;
3244
ceb728cf 3245 } else if (streq(name, "EnvironmentFiles")) {
2485b7e2 3246 _cleanup_(memstream_done) MemStream m = {};
ceb728cf 3247 _cleanup_free_ char *joined = NULL;
9b531f04 3248 _cleanup_strv_free_ char **l = NULL;
2485b7e2 3249 FILE *f;
ceb728cf
NC
3250
3251 r = sd_bus_message_enter_container(message, 'a', "(sb)");
3252 if (r < 0)
3253 return r;
3254
2485b7e2 3255 f = memstream_init(&m);
ceb728cf
NC
3256 if (!f)
3257 return -ENOMEM;
3258
2e59b241
LP
3259 fputs("EnvironmentFile=\n", f);
3260
3261 STRV_FOREACH(i, c->environment_files) {
3262 _cleanup_free_ char *q = NULL;
3263
3264 q = specifier_escape(*i);
3265 if (!q)
3266 return -ENOMEM;
3267
3268 fprintf(f, "EnvironmentFile=%s\n", q);
3269 }
ceb728cf
NC
3270
3271 while ((r = sd_bus_message_enter_container(message, 'r', "sb")) > 0) {
3272 const char *path;
3273 int b;
3274
ceb728cf
NC
3275 r = sd_bus_message_read(message, "sb", &path, &b);
3276 if (r < 0)
3277 return r;
3278
3279 r = sd_bus_message_exit_container(message);
3280 if (r < 0)
3281 return r;
3282
d2d6c096
LP
3283 if (!path_is_absolute(path))
3284 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path %s is not absolute.", path);
ceb728cf 3285
2e59b241 3286 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
6abdec98 3287 _cleanup_free_ char *q = NULL, *buf = NULL;
ceb728cf 3288
605405c6 3289 buf = strjoin(b ? "-" : "", path);
2229f656 3290 if (!buf)
ceb728cf
NC
3291 return -ENOMEM;
3292
2e59b241 3293 q = specifier_escape(buf);
6abdec98 3294 if (!q)
2e59b241 3295 return -ENOMEM;
2e59b241
LP
3296
3297 fprintf(f, "EnvironmentFile=%s\n", q);
ceb728cf 3298
6abdec98 3299 r = strv_consume(&l, TAKE_PTR(buf));
ceb728cf
NC
3300 if (r < 0)
3301 return r;
3302 }
3303 }
3304 if (r < 0)
3305 return r;
3306
b0830e21
LP
3307 r = sd_bus_message_exit_container(message);
3308 if (r < 0)
3309 return r;
3310
2485b7e2 3311 r = memstream_finalize(&m, &joined, NULL);
2229f656
LP
3312 if (r < 0)
3313 return r;
ceb728cf 3314
2e59b241 3315 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2229f656
LP
3316 if (strv_isempty(l)) {
3317 c->environment_files = strv_free(c->environment_files);
2e59b241 3318 unit_write_setting(u, flags, name, "EnvironmentFile=");
2229f656
LP
3319 } else {
3320 r = strv_extend_strv(&c->environment_files, l, true);
3321 if (r < 0)
3322 return r;
3323
2e59b241 3324 unit_write_setting(u, flags, name, joined);
2229f656
LP
3325 }
3326 }
ceb728cf 3327
ceb728cf
NC
3328 return 1;
3329
b4c14404
FB
3330 } else if (streq(name, "PassEnvironment")) {
3331
6171b822 3332 _cleanup_strv_free_ char **l = NULL;
b4c14404
FB
3333
3334 r = sd_bus_message_read_strv(message, &l);
3335 if (r < 0)
3336 return r;
3337
6171b822 3338 if (!strv_env_name_is_valid(l))
1b09b81c 3339 return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid PassEnvironment= block.");
b4c14404 3340
2e59b241 3341 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
b4c14404
FB
3342 if (strv_isempty(l)) {
3343 c->pass_environment = strv_free(c->pass_environment);
2e59b241 3344 unit_write_setting(u, flags, name, "PassEnvironment=");
b4c14404
FB
3345 } else {
3346 _cleanup_free_ char *joined = NULL;
3347
9d4f242a
YW
3348 r = strv_extend_strv(&c->pass_environment, l, true);
3349 if (r < 0)
3350 return r;
3351
41de9cc2 3352 /* We write just the new settings out to file, with unresolved specifiers. */
2e59b241 3353 joined = unit_concat_strv(l, UNIT_ESCAPE_SPECIFIERS);
b4c14404
FB
3354 if (!joined)
3355 return -ENOMEM;
3356
2e59b241 3357 unit_write_settingf(u, flags, name, "PassEnvironment=%s", joined);
b4c14404
FB
3358 }
3359 }
3360
3361 return 1;
3362
2a624c36 3363 } else if (STR_IN_SET(name, "ReadWriteDirectories", "ReadOnlyDirectories", "InaccessibleDirectories",
a07b9926
LB
3364 "ReadWritePaths", "ReadOnlyPaths", "InaccessiblePaths", "ExecPaths", "NoExecPaths",
3365 "ExtensionDirectories")) {
08596068
EV
3366 _cleanup_strv_free_ char **l = NULL;
3367 char ***dirs;
08596068
EV
3368
3369 r = sd_bus_message_read_strv(message, &l);
3370 if (r < 0)
3371 return r;
3372
3373 STRV_FOREACH(p, l) {
e7bcff4e 3374 char *i = *p;
20b7a007
LP
3375 size_t offset;
3376
20b7a007
LP
3377 offset = i[0] == '-';
3378 offset += i[offset] == '+';
3379 if (!path_is_absolute(i + offset))
08596068 3380 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid %s", name);
e7bcff4e 3381
4ff361cc 3382 path_simplify(i + offset);
08596068
EV
3383 }
3384
2e59b241 3385 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
c4b41707
AP
3386 if (STR_IN_SET(name, "ReadWriteDirectories", "ReadWritePaths"))
3387 dirs = &c->read_write_paths;
3388 else if (STR_IN_SET(name, "ReadOnlyDirectories", "ReadOnlyPaths"))
3389 dirs = &c->read_only_paths;
ddc155b2
TM
3390 else if (streq(name, "ExecPaths"))
3391 dirs = &c->exec_paths;
3392 else if (streq(name, "NoExecPaths"))
3393 dirs = &c->no_exec_paths;
a07b9926
LB
3394 else if (streq(name, "ExtensionDirectories"))
3395 dirs = &c->extension_directories;
c4b41707
AP
3396 else /* "InaccessiblePaths" */
3397 dirs = &c->inaccessible_paths;
08596068 3398
7b943bb7 3399 if (strv_isempty(l)) {
08596068 3400 *dirs = strv_free(*dirs);
2e59b241 3401 unit_write_settingf(u, flags, name, "%s=", name);
08596068 3402 } else {
2e59b241 3403 _cleanup_free_ char *joined = NULL;
08596068 3404
2e59b241 3405 joined = unit_concat_strv(l, UNIT_ESCAPE_SPECIFIERS);
08596068
EV
3406 if (!joined)
3407 return -ENOMEM;
3408
2e59b241
LP
3409 r = strv_extend_strv(dirs, l, true);
3410 if (r < 0)
3411 return -ENOMEM;
08596068 3412
2e59b241
LP
3413 unit_write_settingf(u, flags, name, "%s=%s", name, joined);
3414 }
08596068
EV
3415 }
3416
3417 return 1;
3418
8c35c10d 3419 } else if (streq(name, "ExecSearchPath")) {
3420 _cleanup_strv_free_ char **l = NULL;
8c35c10d 3421
3422 r = sd_bus_message_read_strv(message, &l);
3423 if (r < 0)
3424 return r;
3425
de010b0b 3426 STRV_FOREACH(p, l)
8c35c10d 3427 if (!path_is_absolute(*p) || !path_is_normalized(*p) || strchr(*p, ':'))
3428 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid %s", name);
de010b0b 3429
8c35c10d 3430 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
3431 if (strv_isempty(l)) {
3432 c->exec_search_path = strv_free(c->exec_search_path);
3433 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "ExecSearchPath=");
3434 } else {
3435 _cleanup_free_ char *joined = NULL;
3436 r = strv_extend_strv(&c->exec_search_path, l, true);
3437 if (r < 0)
3438 return -ENOMEM;
3439 joined = strv_join(c->exec_search_path, ":");
3440 if (!joined)
3441 return log_oom();
3442 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "ExecSearchPath=%s", joined);
3443 }
3444 }
3445
3446 return 1;
3447
3536f49e 3448 } else if (STR_IN_SET(name, "RuntimeDirectory", "StateDirectory", "CacheDirectory", "LogsDirectory", "ConfigurationDirectory")) {
fa21b5e3 3449 _cleanup_strv_free_ char **l = NULL;
fa21b5e3
EV
3450
3451 r = sd_bus_message_read_strv(message, &l);
3452 if (r < 0)
3453 return r;
3454
3455 STRV_FOREACH(p, l) {
8994a117
YW
3456 if (!path_is_normalized(*p))
3457 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "%s= path is not normalized: %s", name, *p);
3458
3459 if (path_is_absolute(*p))
3460 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "%s= path is absolute: %s", name, *p);
3461
3462 if (path_startswith(*p, "private"))
3463 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "%s= path can't be 'private': %s", name, *p);
fa21b5e3
EV
3464 }
3465
2e59b241 3466 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
3536f49e 3467 ExecDirectoryType i;
b1ea85dc 3468 ExecDirectory *d;
3536f49e 3469
b1ea85dc
LP
3470 assert_se((i = exec_directory_type_from_string(name)) >= 0);
3471 d = c->directories + i;
fa21b5e3
EV
3472
3473 if (strv_isempty(l)) {
211a3d87 3474 exec_directory_done(d);
2e59b241 3475 unit_write_settingf(u, flags, name, "%s=", name);
fa21b5e3 3476 } else {
2e59b241
LP
3477 _cleanup_free_ char *joined = NULL;
3478
211a3d87 3479 STRV_FOREACH(source, l) {
564e5c98 3480 r = exec_directory_add(d, *source, NULL);
211a3d87
LB
3481 if (r < 0)
3482 return log_oom();
3483 }
a2ab603c 3484 exec_directory_sort(d);
fa21b5e3 3485
2e59b241 3486 joined = unit_concat_strv(l, UNIT_ESCAPE_SPECIFIERS);
fa21b5e3
EV
3487 if (!joined)
3488 return -ENOMEM;
3489
2e59b241 3490 unit_write_settingf(u, flags, name, "%s=%s", name, joined);
fa21b5e3
EV
3491 }
3492 }
3493
3494 return 1;
3495
cffaed83
YW
3496 } else if (STR_IN_SET(name, "AppArmorProfile", "SmackProcessLabel")) {
3497 int ignore;
3498 const char *s;
3499
280921f2 3500 r = sd_bus_message_read(message, "(bs)", &ignore, &s);
cffaed83
YW
3501 if (r < 0)
3502 return r;
3503
2e59b241 3504 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
cffaed83
YW
3505 char **p;
3506 bool *b;
3507
3508 if (streq(name, "AppArmorProfile")) {
3509 p = &c->apparmor_profile;
3510 b = &c->apparmor_profile_ignore;
3511 } else { /* "SmackProcessLabel" */
3512 p = &c->smack_process_label;
3513 b = &c->smack_process_label_ignore;
3514 }
3515
3516 if (isempty(s)) {
3517 *p = mfree(*p);
3518 *b = false;
3519 } else {
3520 if (free_and_strdup(p, s) < 0)
3521 return -ENOMEM;
3522 *b = ignore;
3523 }
3524
2e59b241 3525 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "%s=%s%s", name, ignore ? "-" : "", strempty(s));
cffaed83
YW
3526 }
3527
3528 return 1;
3529
d2d6c096 3530 } else if (STR_IN_SET(name, "BindPaths", "BindReadOnlyPaths")) {
ec04aef4 3531 char *source, *destination;
4ff4c98a
YW
3532 int ignore_enoent;
3533 uint64_t mount_flags;
3534 bool empty = true;
d2d6c096
LP
3535
3536 r = sd_bus_message_enter_container(message, 'a', "(ssbt)");
3537 if (r < 0)
3538 return r;
3539
4ff4c98a 3540 while ((r = sd_bus_message_read(message, "(ssbt)", &source, &destination, &ignore_enoent, &mount_flags)) > 0) {
d2d6c096
LP
3541
3542 if (!path_is_absolute(source))
3543 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Source path %s is not absolute.", source);
3544 if (!path_is_absolute(destination))
91d910e3 3545 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Destination path %s is not absolute.", destination);
d2d6c096 3546 if (!IN_SET(mount_flags, 0, MS_REC))
1b09b81c 3547 return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Unknown mount flags.");
d2d6c096 3548
2e59b241 3549 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
d2d6c096
LP
3550 r = bind_mount_add(&c->bind_mounts, &c->n_bind_mounts,
3551 &(BindMount) {
ec04aef4
TM
3552 .source = source,
3553 .destination = destination,
d2d6c096
LP
3554 .read_only = !!strstr(name, "ReadOnly"),
3555 .recursive = !!(mount_flags & MS_REC),
3556 .ignore_enoent = ignore_enoent,
3557 });
3558 if (r < 0)
3559 return r;
3560
2e59b241
LP
3561 unit_write_settingf(
3562 u, flags|UNIT_ESCAPE_SPECIFIERS, name,
d2d6c096
LP
3563 "%s=%s%s:%s:%s",
3564 name,
3565 ignore_enoent ? "-" : "",
3566 source,
3567 destination,
3568 (mount_flags & MS_REC) ? "rbind" : "norbind");
3569 }
3570
3571 empty = false;
3572 }
3573 if (r < 0)
3574 return r;
3575
3576 r = sd_bus_message_exit_container(message);
3577 if (r < 0)
3578 return r;
3579
3580 if (empty) {
3581 bind_mount_free_many(c->bind_mounts, c->n_bind_mounts);
3582 c->bind_mounts = NULL;
3583 c->n_bind_mounts = 0;
2e59b241
LP
3584
3585 unit_write_settingf(u, flags, name, "%s=", name);
d2d6c096
LP
3586 }
3587
784ad252
YW
3588 return 1;
3589
3590 } else if (streq(name, "TemporaryFileSystem")) {
3591 const char *path, *options;
3592 bool empty = true;
3593
3594 r = sd_bus_message_enter_container(message, 'a', "(ss)");
3595 if (r < 0)
3596 return r;
3597
3598 while ((r = sd_bus_message_read(message, "(ss)", &path, &options)) > 0) {
3599
3600 if (!path_is_absolute(path))
3601 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Mount point %s is not absolute.", path);
3602
3603 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
3604 r = temporary_filesystem_add(&c->temporary_filesystems, &c->n_temporary_filesystems, path, options);
3605 if (r < 0)
3606 return r;
3607
3608 unit_write_settingf(
3609 u, flags|UNIT_ESCAPE_SPECIFIERS, name,
3610 "%s=%s:%s",
3611 name,
3612 path,
3613 options);
3614 }
3615
3616 empty = false;
3617 }
3618 if (r < 0)
3619 return r;
3620
3621 r = sd_bus_message_exit_container(message);
3622 if (r < 0)
3623 return r;
3624
3625 if (empty) {
3626 temporary_filesystem_free_many(c->temporary_filesystems, c->n_temporary_filesystems);
3627 c->temporary_filesystems = NULL;
3628 c->n_temporary_filesystems = 0;
3629
3630 unit_write_settingf(u, flags, name, "%s=", name);
3631 }
3632
83555251 3633 return 1;
d2d6c096 3634
6550c24c
LP
3635 } else if ((suffix = startswith(name, "Limit"))) {
3636 const char *soft = NULL;
3637 int ri;
cab2aca3 3638
6550c24c
LP
3639 ri = rlimit_from_string(suffix);
3640 if (ri < 0) {
3641 soft = endswith(suffix, "Soft");
3642 if (soft) {
3643 const char *n;
cab2aca3 3644
2f82562b 3645 n = strndupa_safe(suffix, soft - suffix);
6550c24c
LP
3646 ri = rlimit_from_string(n);
3647 if (ri >= 0)
3648 name = strjoina("Limit", n);
3649 }
cab2aca3 3650 }
d584f638 3651
6550c24c
LP
3652 if (ri >= 0) {
3653 uint64_t rl;
3654 rlim_t x;
d584f638 3655
6550c24c 3656 r = sd_bus_message_read(message, "t", &rl);
cab2aca3
LP
3657 if (r < 0)
3658 return r;
d584f638 3659
f5fbe71d 3660 if (rl == UINT64_MAX)
6550c24c 3661 x = RLIM_INFINITY;
cab2aca3 3662 else {
6550c24c
LP
3663 x = (rlim_t) rl;
3664
3665 if ((uint64_t) x != rl)
3666 return -ERANGE;
d584f638
LP
3667 }
3668
6550c24c
LP
3669 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
3670 _cleanup_free_ char *f = NULL;
3671 struct rlimit nl;
3672
3673 if (c->rlimit[ri]) {
3674 nl = *c->rlimit[ri];
3675
3676 if (soft)
3677 nl.rlim_cur = x;
3678 else
3679 nl.rlim_max = x;
3680 } else
3681 /* When the resource limit is not initialized yet, then assign the value to both fields */
3682 nl = (struct rlimit) {
3683 .rlim_cur = x,
3684 .rlim_max = x,
3685 };
3686
3687 r = rlimit_format(&nl, &f);
3688 if (r < 0)
3689 return r;
3690
3691 if (c->rlimit[ri])
3692 *c->rlimit[ri] = nl;
3693 else {
3694 c->rlimit[ri] = newdup(struct rlimit, &nl, 1);
3695 if (!c->rlimit[ri])
3696 return -ENOMEM;
3697 }
3698
3699 unit_write_settingf(u, flags, name, "%s=%s", name, f);
3700 }
3701
3702 return 1;
d584f638
LP
3703 }
3704
b3d13314
LB
3705 } else if (streq(name, "MountImages")) {
3706 _cleanup_free_ char *format_str = NULL;
3707 MountImage *mount_images = NULL;
3708 size_t n_mount_images = 0;
3709 char *source, *destination;
3710 int permissive;
3711
427353f6 3712 r = sd_bus_message_enter_container(message, 'a', "(ssba(ss))");
b3d13314
LB
3713 if (r < 0)
3714 return r;
3715
427353f6
LB
3716 for (;;) {
3717 _cleanup_(mount_options_free_allp) MountOptions *options = NULL;
3718 _cleanup_free_ char *source_escaped = NULL, *destination_escaped = NULL;
b3d13314
LB
3719 char *tuple;
3720
427353f6
LB
3721 r = sd_bus_message_enter_container(message, 'r', "ssba(ss)");
3722 if (r < 0)
3723 return r;
3724
3725 r = sd_bus_message_read(message, "ssb", &source, &destination, &permissive);
3726 if (r <= 0)
3727 break;
3728
b3d13314
LB
3729 if (!path_is_absolute(source))
3730 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Source path %s is not absolute.", source);
3731 if (!path_is_normalized(source))
3732 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Source path %s is not normalized.", source);
3733 if (!path_is_absolute(destination))
3734 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Destination path %s is not absolute.", destination);
3735 if (!path_is_normalized(destination))
3736 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Destination path %s is not normalized.", destination);
3737
427353f6
LB
3738 /* Need to store them in the unit with the escapes, so that they can be parsed again */
3739 source_escaped = shell_escape(source, ":");
3740 if (!source_escaped)
3741 return -ENOMEM;
3742 destination_escaped = shell_escape(destination, ":");
3743 if (!destination_escaped)
3744 return -ENOMEM;
3745
3746 tuple = strjoin(format_str,
3747 format_str ? " " : "",
3748 permissive ? "-" : "",
3749 source_escaped,
3750 ":",
3751 destination_escaped);
b3d13314
LB
3752 if (!tuple)
3753 return -ENOMEM;
3754 free_and_replace(format_str, tuple);
3755
988172ce 3756 r = bus_read_mount_options(message, error, &options, &format_str, ":");
427353f6
LB
3757 if (r < 0)
3758 return r;
3759
3760 r = sd_bus_message_exit_container(message);
3761 if (r < 0)
3762 return r;
3763
b3d13314
LB
3764 r = mount_image_add(&mount_images, &n_mount_images,
3765 &(MountImage) {
3766 .source = source,
3767 .destination = destination,
427353f6 3768 .mount_options = options,
b3d13314 3769 .ignore_enoent = permissive,
93f59701 3770 .type = MOUNT_IMAGE_DISCRETE,
b3d13314
LB
3771 });
3772 if (r < 0)
3773 return r;
3774 }
3775 if (r < 0)
3776 return r;
3777
3778 r = sd_bus_message_exit_container(message);
3779 if (r < 0)
3780 return r;
3781
3782 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
3783 if (n_mount_images == 0) {
3784 c->mount_images = mount_image_free_many(c->mount_images, &c->n_mount_images);
3785
3786 unit_write_settingf(u, flags, name, "%s=", name);
3787 } else {
3788 for (size_t i = 0; i < n_mount_images; ++i) {
3789 r = mount_image_add(&c->mount_images, &c->n_mount_images, &mount_images[i]);
3790 if (r < 0)
3791 return r;
3792 }
3793
3794 unit_write_settingf(u, flags|UNIT_ESCAPE_C|UNIT_ESCAPE_SPECIFIERS,
3795 name,
3796 "%s=%s",
3797 name,
3798 format_str);
3799 }
3800 }
3801
3802 mount_images = mount_image_free_many(mount_images, &n_mount_images);
3803
93f59701
LB
3804 return 1;
3805 } else if (streq(name, "ExtensionImages")) {
3806 _cleanup_free_ char *format_str = NULL;
3807 MountImage *extension_images = NULL;
3808 size_t n_extension_images = 0;
3809
3810 r = sd_bus_message_enter_container(message, 'a', "(sba(ss))");
3811 if (r < 0)
3812 return r;
3813
3814 for (;;) {
3815 _cleanup_(mount_options_free_allp) MountOptions *options = NULL;
3816 _cleanup_free_ char *source_escaped = NULL;
3817 char *source, *tuple;
3818 int permissive;
3819
3820 r = sd_bus_message_enter_container(message, 'r', "sba(ss)");
3821 if (r < 0)
3822 return r;
3823
3824 r = sd_bus_message_read(message, "sb", &source, &permissive);
3825 if (r <= 0)
3826 break;
3827
3828 if (!path_is_absolute(source))
3829 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Source path %s is not absolute.", source);
3830 if (!path_is_normalized(source))
3831 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Source path %s is not normalized.", source);
3832
3833 /* Need to store them in the unit with the escapes, so that they can be parsed again */
3834 source_escaped = shell_escape(source, ":");
3835 if (!source_escaped)
3836 return -ENOMEM;
3837
3838 tuple = strjoin(format_str,
3839 format_str ? " " : "",
3840 permissive ? "-" : "",
3841 source_escaped);
3842 if (!tuple)
3843 return -ENOMEM;
3844 free_and_replace(format_str, tuple);
3845
3846 r = bus_read_mount_options(message, error, &options, &format_str, ":");
3847 if (r < 0)
3848 return r;
3849
3850 r = sd_bus_message_exit_container(message);
3851 if (r < 0)
3852 return r;
3853
3854 r = mount_image_add(&extension_images, &n_extension_images,
3855 &(MountImage) {
3856 .source = source,
3857 .mount_options = options,
3858 .ignore_enoent = permissive,
3859 .type = MOUNT_IMAGE_EXTENSION,
3860 });
3861 if (r < 0)
3862 return r;
3863 }
3864 if (r < 0)
3865 return r;
3866
3867 r = sd_bus_message_exit_container(message);
3868 if (r < 0)
3869 return r;
3870
3871 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
3872 if (n_extension_images == 0) {
3873 c->extension_images = mount_image_free_many(c->extension_images, &c->n_extension_images);
3874
3875 unit_write_settingf(u, flags, name, "%s=", name);
3876 } else {
3877 for (size_t i = 0; i < n_extension_images; ++i) {
3878 r = mount_image_add(&c->extension_images, &c->n_extension_images, &extension_images[i]);
3879 if (r < 0)
3880 return r;
3881 }
3882
3883 unit_write_settingf(u, flags|UNIT_ESCAPE_C|UNIT_ESCAPE_SPECIFIERS,
3884 name,
3885 "%s=%s",
3886 name,
3887 format_str);
3888 }
3889 }
3890
3891 extension_images = mount_image_free_many(extension_images, &n_extension_images);
3892
b3d13314 3893 return 1;
211a3d87
LB
3894
3895 } else if (STR_IN_SET(name, "StateDirectorySymlink", "RuntimeDirectorySymlink", "CacheDirectorySymlink", "LogsDirectorySymlink")) {
3896 char *source, *destination;
3897 ExecDirectory *directory;
3898 uint64_t symlink_flags; /* No flags for now, reserved for future uses. */
3899 ExecDirectoryType i;
3900
3901 assert_se((i = exec_directory_type_symlink_from_string(name)) >= 0);
3902 directory = c->directories + i;
3903
3904 r = sd_bus_message_enter_container(message, 'a', "(sst)");
3905 if (r < 0)
3906 return r;
3907
3908 while ((r = sd_bus_message_read(message, "(sst)", &source, &destination, &symlink_flags)) > 0) {
3909 if (!path_is_valid(source))
3910 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Source path %s is not valid.", source);
3911 if (path_is_absolute(source))
3912 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Source path %s is absolute.", source);
3913 if (!path_is_normalized(source))
3914 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Source path %s is not normalized.", source);
3915 if (!path_is_valid(destination))
3916 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Destination path %s is not valid.", destination);
3917 if (path_is_absolute(destination))
3918 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Destination path %s is absolute.", destination);
3919 if (!path_is_normalized(destination))
3920 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Destination path %s is not normalized.", destination);
3921 if (symlink_flags != 0)
3922 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Flags must be zero.");
3923
3924 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
3925 _cleanup_free_ char *destination_escaped = NULL, *source_escaped = NULL;
564e5c98
YW
3926
3927 r = exec_directory_add(directory, source, destination);
211a3d87
LB
3928 if (r < 0)
3929 return r;
3930
3931 /* Need to store them in the unit with the escapes, so that they can be parsed again */
3932 source_escaped = xescape(source, ":");
3933 destination_escaped = xescape(destination, ":");
3934 if (!source_escaped || !destination_escaped)
3935 return -ENOMEM;
3936
3937 unit_write_settingf(
3938 u, flags|UNIT_ESCAPE_SPECIFIERS, exec_directory_type_to_string(i),
3939 "%s=%s:%s",
3940 exec_directory_type_to_string(i),
3941 source_escaped,
3942 destination_escaped);
3943 }
3944 }
3945 if (r < 0)
3946 return r;
3947
a2ab603c
YW
3948 exec_directory_sort(directory);
3949
211a3d87
LB
3950 r = sd_bus_message_exit_container(message);
3951 if (r < 0)
3952 return r;
3953
3954 return 1;
3955
84be0c71
LP
3956 } else if (STR_IN_SET(name, "RootImagePolicy", "MountImagePolicy", "ExtensionImagePolicy")) {
3957 _cleanup_(image_policy_freep) ImagePolicy *p = NULL;
3958 const char *s;
3959
3960 r = sd_bus_message_read(message, "s", &s);
3961 if (r < 0)
3962 return r;
3963
3964 r = image_policy_from_string(s, &p);
3965 if (r < 0)
3966 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Failed to parse image policy string: %s", s);
3967
3968 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
3969 _cleanup_free_ char *t = NULL;
3970 ImagePolicy **pp =
3971 streq(name, "RootImagePolicy") ? &c->root_image_policy :
3972 streq(name, "MountImagePolicy") ? &c->mount_image_policy :
3973 &c->extension_image_policy;
3974
3975 r = image_policy_to_string(p, /* simplify= */ true, &t);
3976 if (r < 0)
3977 return r;
3978
3979 image_policy_free(*pp);
3980 *pp = TAKE_PTR(p);
3981
3982 unit_write_settingf(
3983 u, flags, name,
3984 "%s=%s",
3985 name,
3986 t); /* no escaping necessary */
3987 }
3988
3989 return 1;
c7040b5d
LP
3990 }
3991
3992 return 0;
3993}