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