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