]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/core/dbus-execute.c
core: new feature MountImages
[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-get-properties.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 static int property_get_root_image_options(
788 sd_bus *bus,
789 const char *path,
790 const char *interface,
791 const char *property,
792 sd_bus_message *reply,
793 void *userdata,
794 sd_bus_error *error) {
795
796 ExecContext *c = userdata;
797 MountOptions *m;
798 int r;
799
800 assert(bus);
801 assert(c);
802 assert(property);
803 assert(reply);
804
805 r = sd_bus_message_open_container(reply, 'a', "(us)");
806 if (r < 0)
807 return r;
808
809 LIST_FOREACH(mount_options, m, c->root_image_options) {
810 r = sd_bus_message_append(reply, "(us)", m->partition_number, m->options);
811 if (r < 0)
812 return r;
813 }
814
815 return sd_bus_message_close_container(reply);
816 }
817
818 static int property_get_mount_images(
819 sd_bus *bus,
820 const char *path,
821 const char *interface,
822 const char *property,
823 sd_bus_message *reply,
824 void *userdata,
825 sd_bus_error *error) {
826
827 ExecContext *c = userdata;
828 int r;
829
830 assert(bus);
831 assert(c);
832 assert(property);
833 assert(reply);
834
835 r = sd_bus_message_open_container(reply, 'a', "(ssb)");
836 if (r < 0)
837 return r;
838
839 for (size_t i = 0; i < c->n_mount_images; i++) {
840 r = sd_bus_message_append(
841 reply, "(ssb)",
842 c->mount_images[i].source,
843 c->mount_images[i].destination,
844 c->mount_images[i].ignore_enoent);
845 if (r < 0)
846 return r;
847 }
848
849 return sd_bus_message_close_container(reply);
850 }
851
852 const sd_bus_vtable bus_exec_vtable[] = {
853 SD_BUS_VTABLE_START(0),
854 SD_BUS_PROPERTY("Environment", "as", NULL, offsetof(ExecContext, environment), SD_BUS_VTABLE_PROPERTY_CONST),
855 SD_BUS_PROPERTY("EnvironmentFiles", "a(sb)", property_get_environment_files, 0, SD_BUS_VTABLE_PROPERTY_CONST),
856 SD_BUS_PROPERTY("PassEnvironment", "as", NULL, offsetof(ExecContext, pass_environment), SD_BUS_VTABLE_PROPERTY_CONST),
857 SD_BUS_PROPERTY("UnsetEnvironment", "as", NULL, offsetof(ExecContext, unset_environment), SD_BUS_VTABLE_PROPERTY_CONST),
858 SD_BUS_PROPERTY("UMask", "u", bus_property_get_mode, offsetof(ExecContext, umask), SD_BUS_VTABLE_PROPERTY_CONST),
859 SD_BUS_PROPERTY("LimitCPU", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_CPU]), SD_BUS_VTABLE_PROPERTY_CONST),
860 SD_BUS_PROPERTY("LimitCPUSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_CPU]), SD_BUS_VTABLE_PROPERTY_CONST),
861 SD_BUS_PROPERTY("LimitFSIZE", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_FSIZE]), SD_BUS_VTABLE_PROPERTY_CONST),
862 SD_BUS_PROPERTY("LimitFSIZESoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_FSIZE]), SD_BUS_VTABLE_PROPERTY_CONST),
863 SD_BUS_PROPERTY("LimitDATA", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_DATA]), SD_BUS_VTABLE_PROPERTY_CONST),
864 SD_BUS_PROPERTY("LimitDATASoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_DATA]), SD_BUS_VTABLE_PROPERTY_CONST),
865 SD_BUS_PROPERTY("LimitSTACK", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_STACK]), SD_BUS_VTABLE_PROPERTY_CONST),
866 SD_BUS_PROPERTY("LimitSTACKSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_STACK]), SD_BUS_VTABLE_PROPERTY_CONST),
867 SD_BUS_PROPERTY("LimitCORE", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_CORE]), SD_BUS_VTABLE_PROPERTY_CONST),
868 SD_BUS_PROPERTY("LimitCORESoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_CORE]), SD_BUS_VTABLE_PROPERTY_CONST),
869 SD_BUS_PROPERTY("LimitRSS", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RSS]), SD_BUS_VTABLE_PROPERTY_CONST),
870 SD_BUS_PROPERTY("LimitRSSSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RSS]), SD_BUS_VTABLE_PROPERTY_CONST),
871 SD_BUS_PROPERTY("LimitNOFILE", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NOFILE]), SD_BUS_VTABLE_PROPERTY_CONST),
872 SD_BUS_PROPERTY("LimitNOFILESoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NOFILE]), SD_BUS_VTABLE_PROPERTY_CONST),
873 SD_BUS_PROPERTY("LimitAS", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_AS]), SD_BUS_VTABLE_PROPERTY_CONST),
874 SD_BUS_PROPERTY("LimitASSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_AS]), SD_BUS_VTABLE_PROPERTY_CONST),
875 SD_BUS_PROPERTY("LimitNPROC", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NPROC]), SD_BUS_VTABLE_PROPERTY_CONST),
876 SD_BUS_PROPERTY("LimitNPROCSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NPROC]), SD_BUS_VTABLE_PROPERTY_CONST),
877 SD_BUS_PROPERTY("LimitMEMLOCK", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_MEMLOCK]), SD_BUS_VTABLE_PROPERTY_CONST),
878 SD_BUS_PROPERTY("LimitMEMLOCKSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_MEMLOCK]), SD_BUS_VTABLE_PROPERTY_CONST),
879 SD_BUS_PROPERTY("LimitLOCKS", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_LOCKS]), SD_BUS_VTABLE_PROPERTY_CONST),
880 SD_BUS_PROPERTY("LimitLOCKSSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_LOCKS]), SD_BUS_VTABLE_PROPERTY_CONST),
881 SD_BUS_PROPERTY("LimitSIGPENDING", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_SIGPENDING]), SD_BUS_VTABLE_PROPERTY_CONST),
882 SD_BUS_PROPERTY("LimitSIGPENDINGSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_SIGPENDING]), SD_BUS_VTABLE_PROPERTY_CONST),
883 SD_BUS_PROPERTY("LimitMSGQUEUE", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_MSGQUEUE]), SD_BUS_VTABLE_PROPERTY_CONST),
884 SD_BUS_PROPERTY("LimitMSGQUEUESoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_MSGQUEUE]), SD_BUS_VTABLE_PROPERTY_CONST),
885 SD_BUS_PROPERTY("LimitNICE", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NICE]), SD_BUS_VTABLE_PROPERTY_CONST),
886 SD_BUS_PROPERTY("LimitNICESoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NICE]), SD_BUS_VTABLE_PROPERTY_CONST),
887 SD_BUS_PROPERTY("LimitRTPRIO", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RTPRIO]), SD_BUS_VTABLE_PROPERTY_CONST),
888 SD_BUS_PROPERTY("LimitRTPRIOSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RTPRIO]), SD_BUS_VTABLE_PROPERTY_CONST),
889 SD_BUS_PROPERTY("LimitRTTIME", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RTTIME]), SD_BUS_VTABLE_PROPERTY_CONST),
890 SD_BUS_PROPERTY("LimitRTTIMESoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RTTIME]), SD_BUS_VTABLE_PROPERTY_CONST),
891 SD_BUS_PROPERTY("WorkingDirectory", "s", property_get_working_directory, 0, SD_BUS_VTABLE_PROPERTY_CONST),
892 SD_BUS_PROPERTY("RootDirectory", "s", NULL, offsetof(ExecContext, root_directory), SD_BUS_VTABLE_PROPERTY_CONST),
893 SD_BUS_PROPERTY("RootImage", "s", NULL, offsetof(ExecContext, root_image), SD_BUS_VTABLE_PROPERTY_CONST),
894 SD_BUS_PROPERTY("RootImageOptions", "a(us)", property_get_root_image_options, 0, SD_BUS_VTABLE_PROPERTY_CONST),
895 SD_BUS_PROPERTY("RootHash", "ay", property_get_root_hash, 0, SD_BUS_VTABLE_PROPERTY_CONST),
896 SD_BUS_PROPERTY("RootHashPath", "s", NULL, offsetof(ExecContext, root_hash_path), SD_BUS_VTABLE_PROPERTY_CONST),
897 SD_BUS_PROPERTY("RootHashSignature", "ay", property_get_root_hash_sig, 0, SD_BUS_VTABLE_PROPERTY_CONST),
898 SD_BUS_PROPERTY("RootHashSignaturePath", "s", NULL, offsetof(ExecContext, root_hash_sig_path), SD_BUS_VTABLE_PROPERTY_CONST),
899 SD_BUS_PROPERTY("RootVerity", "s", NULL, offsetof(ExecContext, root_verity), SD_BUS_VTABLE_PROPERTY_CONST),
900 SD_BUS_PROPERTY("MountImages", "a(ssb)", property_get_mount_images, 0, SD_BUS_VTABLE_PROPERTY_CONST),
901 SD_BUS_PROPERTY("OOMScoreAdjust", "i", property_get_oom_score_adjust, 0, SD_BUS_VTABLE_PROPERTY_CONST),
902 SD_BUS_PROPERTY("CoredumpFilter", "t", property_get_coredump_filter, 0, SD_BUS_VTABLE_PROPERTY_CONST),
903 SD_BUS_PROPERTY("Nice", "i", property_get_nice, 0, SD_BUS_VTABLE_PROPERTY_CONST),
904 SD_BUS_PROPERTY("IOSchedulingClass", "i", property_get_ioprio_class, 0, SD_BUS_VTABLE_PROPERTY_CONST),
905 SD_BUS_PROPERTY("IOSchedulingPriority", "i", property_get_ioprio_priority, 0, SD_BUS_VTABLE_PROPERTY_CONST),
906 SD_BUS_PROPERTY("CPUSchedulingPolicy", "i", property_get_cpu_sched_policy, 0, SD_BUS_VTABLE_PROPERTY_CONST),
907 SD_BUS_PROPERTY("CPUSchedulingPriority", "i", property_get_cpu_sched_priority, 0, SD_BUS_VTABLE_PROPERTY_CONST),
908 SD_BUS_PROPERTY("CPUAffinity", "ay", property_get_cpu_affinity, 0, SD_BUS_VTABLE_PROPERTY_CONST),
909 SD_BUS_PROPERTY("CPUAffinityFromNUMA", "b", property_get_cpu_affinity_from_numa, 0, SD_BUS_VTABLE_PROPERTY_CONST),
910 SD_BUS_PROPERTY("NUMAPolicy", "i", property_get_numa_policy, 0, SD_BUS_VTABLE_PROPERTY_CONST),
911 SD_BUS_PROPERTY("NUMAMask", "ay", property_get_numa_mask, 0, SD_BUS_VTABLE_PROPERTY_CONST),
912 SD_BUS_PROPERTY("TimerSlackNSec", "t", property_get_timer_slack_nsec, 0, SD_BUS_VTABLE_PROPERTY_CONST),
913 SD_BUS_PROPERTY("CPUSchedulingResetOnFork", "b", bus_property_get_bool, offsetof(ExecContext, cpu_sched_reset_on_fork), SD_BUS_VTABLE_PROPERTY_CONST),
914 SD_BUS_PROPERTY("NonBlocking", "b", bus_property_get_bool, offsetof(ExecContext, non_blocking), SD_BUS_VTABLE_PROPERTY_CONST),
915 SD_BUS_PROPERTY("StandardInput", "s", property_get_exec_input, offsetof(ExecContext, std_input), SD_BUS_VTABLE_PROPERTY_CONST),
916 SD_BUS_PROPERTY("StandardInputFileDescriptorName", "s", property_get_stdio_fdname, 0, SD_BUS_VTABLE_PROPERTY_CONST),
917 SD_BUS_PROPERTY("StandardInputData", "ay", property_get_input_data, 0, SD_BUS_VTABLE_PROPERTY_CONST),
918 SD_BUS_PROPERTY("StandardOutput", "s", bus_property_get_exec_output, offsetof(ExecContext, std_output), SD_BUS_VTABLE_PROPERTY_CONST),
919 SD_BUS_PROPERTY("StandardOutputFileDescriptorName", "s", property_get_stdio_fdname, 0, SD_BUS_VTABLE_PROPERTY_CONST),
920 SD_BUS_PROPERTY("StandardError", "s", bus_property_get_exec_output, offsetof(ExecContext, std_error), SD_BUS_VTABLE_PROPERTY_CONST),
921 SD_BUS_PROPERTY("StandardErrorFileDescriptorName", "s", property_get_stdio_fdname, 0, SD_BUS_VTABLE_PROPERTY_CONST),
922 SD_BUS_PROPERTY("TTYPath", "s", NULL, offsetof(ExecContext, tty_path), SD_BUS_VTABLE_PROPERTY_CONST),
923 SD_BUS_PROPERTY("TTYReset", "b", bus_property_get_bool, offsetof(ExecContext, tty_reset), SD_BUS_VTABLE_PROPERTY_CONST),
924 SD_BUS_PROPERTY("TTYVHangup", "b", bus_property_get_bool, offsetof(ExecContext, tty_vhangup), SD_BUS_VTABLE_PROPERTY_CONST),
925 SD_BUS_PROPERTY("TTYVTDisallocate", "b", bus_property_get_bool, offsetof(ExecContext, tty_vt_disallocate), SD_BUS_VTABLE_PROPERTY_CONST),
926 SD_BUS_PROPERTY("SyslogPriority", "i", bus_property_get_int, offsetof(ExecContext, syslog_priority), SD_BUS_VTABLE_PROPERTY_CONST),
927 SD_BUS_PROPERTY("SyslogIdentifier", "s", NULL, offsetof(ExecContext, syslog_identifier), SD_BUS_VTABLE_PROPERTY_CONST),
928 SD_BUS_PROPERTY("SyslogLevelPrefix", "b", bus_property_get_bool, offsetof(ExecContext, syslog_level_prefix), SD_BUS_VTABLE_PROPERTY_CONST),
929 SD_BUS_PROPERTY("SyslogLevel", "i", property_get_syslog_level, offsetof(ExecContext, syslog_priority), SD_BUS_VTABLE_PROPERTY_CONST),
930 SD_BUS_PROPERTY("SyslogFacility", "i", property_get_syslog_facility, offsetof(ExecContext, syslog_priority), SD_BUS_VTABLE_PROPERTY_CONST),
931 SD_BUS_PROPERTY("LogLevelMax", "i", bus_property_get_int, offsetof(ExecContext, log_level_max), SD_BUS_VTABLE_PROPERTY_CONST),
932 SD_BUS_PROPERTY("LogRateLimitIntervalUSec", "t", bus_property_get_usec, offsetof(ExecContext, log_ratelimit_interval_usec), SD_BUS_VTABLE_PROPERTY_CONST),
933 SD_BUS_PROPERTY("LogRateLimitBurst", "u", bus_property_get_unsigned, offsetof(ExecContext, log_ratelimit_burst), SD_BUS_VTABLE_PROPERTY_CONST),
934 SD_BUS_PROPERTY("LogExtraFields", "aay", property_get_log_extra_fields, 0, SD_BUS_VTABLE_PROPERTY_CONST),
935 SD_BUS_PROPERTY("LogNamespace", "s", NULL, offsetof(ExecContext, log_namespace), SD_BUS_VTABLE_PROPERTY_CONST),
936 SD_BUS_PROPERTY("SecureBits", "i", bus_property_get_int, offsetof(ExecContext, secure_bits), SD_BUS_VTABLE_PROPERTY_CONST),
937 SD_BUS_PROPERTY("CapabilityBoundingSet", "t", NULL, offsetof(ExecContext, capability_bounding_set), SD_BUS_VTABLE_PROPERTY_CONST),
938 SD_BUS_PROPERTY("AmbientCapabilities", "t", NULL, offsetof(ExecContext, capability_ambient_set), SD_BUS_VTABLE_PROPERTY_CONST),
939 SD_BUS_PROPERTY("User", "s", NULL, offsetof(ExecContext, user), SD_BUS_VTABLE_PROPERTY_CONST),
940 SD_BUS_PROPERTY("Group", "s", NULL, offsetof(ExecContext, group), SD_BUS_VTABLE_PROPERTY_CONST),
941 SD_BUS_PROPERTY("DynamicUser", "b", bus_property_get_bool, offsetof(ExecContext, dynamic_user), SD_BUS_VTABLE_PROPERTY_CONST),
942 SD_BUS_PROPERTY("RemoveIPC", "b", bus_property_get_bool, offsetof(ExecContext, remove_ipc), SD_BUS_VTABLE_PROPERTY_CONST),
943 SD_BUS_PROPERTY("SupplementaryGroups", "as", NULL, offsetof(ExecContext, supplementary_groups), SD_BUS_VTABLE_PROPERTY_CONST),
944 SD_BUS_PROPERTY("PAMName", "s", NULL, offsetof(ExecContext, pam_name), SD_BUS_VTABLE_PROPERTY_CONST),
945 SD_BUS_PROPERTY("ReadWritePaths", "as", NULL, offsetof(ExecContext, read_write_paths), SD_BUS_VTABLE_PROPERTY_CONST),
946 SD_BUS_PROPERTY("ReadOnlyPaths", "as", NULL, offsetof(ExecContext, read_only_paths), SD_BUS_VTABLE_PROPERTY_CONST),
947 SD_BUS_PROPERTY("InaccessiblePaths", "as", NULL, offsetof(ExecContext, inaccessible_paths), SD_BUS_VTABLE_PROPERTY_CONST),
948 SD_BUS_PROPERTY("MountFlags", "t", bus_property_get_ulong, offsetof(ExecContext, mount_flags), SD_BUS_VTABLE_PROPERTY_CONST),
949 SD_BUS_PROPERTY("PrivateTmp", "b", bus_property_get_bool, offsetof(ExecContext, private_tmp), SD_BUS_VTABLE_PROPERTY_CONST),
950 SD_BUS_PROPERTY("PrivateDevices", "b", bus_property_get_bool, offsetof(ExecContext, private_devices), SD_BUS_VTABLE_PROPERTY_CONST),
951 SD_BUS_PROPERTY("ProtectClock", "b", bus_property_get_bool, offsetof(ExecContext, protect_clock), SD_BUS_VTABLE_PROPERTY_CONST),
952 SD_BUS_PROPERTY("ProtectKernelTunables", "b", bus_property_get_bool, offsetof(ExecContext, protect_kernel_tunables), SD_BUS_VTABLE_PROPERTY_CONST),
953 SD_BUS_PROPERTY("ProtectKernelModules", "b", bus_property_get_bool, offsetof(ExecContext, protect_kernel_modules), SD_BUS_VTABLE_PROPERTY_CONST),
954 SD_BUS_PROPERTY("ProtectKernelLogs", "b", bus_property_get_bool, offsetof(ExecContext, protect_kernel_logs), SD_BUS_VTABLE_PROPERTY_CONST),
955 SD_BUS_PROPERTY("ProtectControlGroups", "b", bus_property_get_bool, offsetof(ExecContext, protect_control_groups), SD_BUS_VTABLE_PROPERTY_CONST),
956 SD_BUS_PROPERTY("PrivateNetwork", "b", bus_property_get_bool, offsetof(ExecContext, private_network), SD_BUS_VTABLE_PROPERTY_CONST),
957 SD_BUS_PROPERTY("PrivateUsers", "b", bus_property_get_bool, offsetof(ExecContext, private_users), SD_BUS_VTABLE_PROPERTY_CONST),
958 SD_BUS_PROPERTY("PrivateMounts", "b", bus_property_get_bool, offsetof(ExecContext, private_mounts), SD_BUS_VTABLE_PROPERTY_CONST),
959 SD_BUS_PROPERTY("ProtectHome", "s", property_get_protect_home, offsetof(ExecContext, protect_home), SD_BUS_VTABLE_PROPERTY_CONST),
960 SD_BUS_PROPERTY("ProtectSystem", "s", property_get_protect_system, offsetof(ExecContext, protect_system), SD_BUS_VTABLE_PROPERTY_CONST),
961 SD_BUS_PROPERTY("SameProcessGroup", "b", bus_property_get_bool, offsetof(ExecContext, same_pgrp), SD_BUS_VTABLE_PROPERTY_CONST),
962 SD_BUS_PROPERTY("UtmpIdentifier", "s", NULL, offsetof(ExecContext, utmp_id), SD_BUS_VTABLE_PROPERTY_CONST),
963 SD_BUS_PROPERTY("UtmpMode", "s", property_get_exec_utmp_mode, offsetof(ExecContext, utmp_mode), SD_BUS_VTABLE_PROPERTY_CONST),
964 SD_BUS_PROPERTY("SELinuxContext", "(bs)", property_get_selinux_context, 0, SD_BUS_VTABLE_PROPERTY_CONST),
965 SD_BUS_PROPERTY("AppArmorProfile", "(bs)", property_get_apparmor_profile, 0, SD_BUS_VTABLE_PROPERTY_CONST),
966 SD_BUS_PROPERTY("SmackProcessLabel", "(bs)", property_get_smack_process_label, 0, SD_BUS_VTABLE_PROPERTY_CONST),
967 SD_BUS_PROPERTY("IgnoreSIGPIPE", "b", bus_property_get_bool, offsetof(ExecContext, ignore_sigpipe), SD_BUS_VTABLE_PROPERTY_CONST),
968 SD_BUS_PROPERTY("NoNewPrivileges", "b", bus_property_get_bool, offsetof(ExecContext, no_new_privileges), SD_BUS_VTABLE_PROPERTY_CONST),
969 SD_BUS_PROPERTY("SystemCallFilter", "(bas)", property_get_syscall_filter, 0, SD_BUS_VTABLE_PROPERTY_CONST),
970 SD_BUS_PROPERTY("SystemCallArchitectures", "as", property_get_syscall_archs, 0, SD_BUS_VTABLE_PROPERTY_CONST),
971 SD_BUS_PROPERTY("SystemCallErrorNumber", "i", bus_property_get_int, offsetof(ExecContext, syscall_errno), SD_BUS_VTABLE_PROPERTY_CONST),
972 SD_BUS_PROPERTY("Personality", "s", property_get_personality, offsetof(ExecContext, personality), SD_BUS_VTABLE_PROPERTY_CONST),
973 SD_BUS_PROPERTY("LockPersonality", "b", bus_property_get_bool, offsetof(ExecContext, lock_personality), SD_BUS_VTABLE_PROPERTY_CONST),
974 SD_BUS_PROPERTY("RestrictAddressFamilies", "(bas)", property_get_address_families, 0, SD_BUS_VTABLE_PROPERTY_CONST),
975 SD_BUS_PROPERTY("RuntimeDirectoryPreserve", "s", property_get_exec_preserve_mode, offsetof(ExecContext, runtime_directory_preserve_mode), SD_BUS_VTABLE_PROPERTY_CONST),
976 SD_BUS_PROPERTY("RuntimeDirectoryMode", "u", bus_property_get_mode, offsetof(ExecContext, directories[EXEC_DIRECTORY_RUNTIME].mode), SD_BUS_VTABLE_PROPERTY_CONST),
977 SD_BUS_PROPERTY("RuntimeDirectory", "as", NULL, offsetof(ExecContext, directories[EXEC_DIRECTORY_RUNTIME].paths), SD_BUS_VTABLE_PROPERTY_CONST),
978 SD_BUS_PROPERTY("StateDirectoryMode", "u", bus_property_get_mode, offsetof(ExecContext, directories[EXEC_DIRECTORY_STATE].mode), SD_BUS_VTABLE_PROPERTY_CONST),
979 SD_BUS_PROPERTY("StateDirectory", "as", NULL, offsetof(ExecContext, directories[EXEC_DIRECTORY_STATE].paths), SD_BUS_VTABLE_PROPERTY_CONST),
980 SD_BUS_PROPERTY("CacheDirectoryMode", "u", bus_property_get_mode, offsetof(ExecContext, directories[EXEC_DIRECTORY_CACHE].mode), SD_BUS_VTABLE_PROPERTY_CONST),
981 SD_BUS_PROPERTY("CacheDirectory", "as", NULL, offsetof(ExecContext, directories[EXEC_DIRECTORY_CACHE].paths), SD_BUS_VTABLE_PROPERTY_CONST),
982 SD_BUS_PROPERTY("LogsDirectoryMode", "u", bus_property_get_mode, offsetof(ExecContext, directories[EXEC_DIRECTORY_LOGS].mode), SD_BUS_VTABLE_PROPERTY_CONST),
983 SD_BUS_PROPERTY("LogsDirectory", "as", NULL, offsetof(ExecContext, directories[EXEC_DIRECTORY_LOGS].paths), SD_BUS_VTABLE_PROPERTY_CONST),
984 SD_BUS_PROPERTY("ConfigurationDirectoryMode", "u", bus_property_get_mode, offsetof(ExecContext, directories[EXEC_DIRECTORY_CONFIGURATION].mode), SD_BUS_VTABLE_PROPERTY_CONST),
985 SD_BUS_PROPERTY("ConfigurationDirectory", "as", NULL, offsetof(ExecContext, directories[EXEC_DIRECTORY_CONFIGURATION].paths), SD_BUS_VTABLE_PROPERTY_CONST),
986 SD_BUS_PROPERTY("TimeoutCleanUSec", "t", bus_property_get_usec, offsetof(ExecContext, timeout_clean_usec), SD_BUS_VTABLE_PROPERTY_CONST),
987 SD_BUS_PROPERTY("MemoryDenyWriteExecute", "b", bus_property_get_bool, offsetof(ExecContext, memory_deny_write_execute), SD_BUS_VTABLE_PROPERTY_CONST),
988 SD_BUS_PROPERTY("RestrictRealtime", "b", bus_property_get_bool, offsetof(ExecContext, restrict_realtime), SD_BUS_VTABLE_PROPERTY_CONST),
989 SD_BUS_PROPERTY("RestrictSUIDSGID", "b", bus_property_get_bool, offsetof(ExecContext, restrict_suid_sgid), SD_BUS_VTABLE_PROPERTY_CONST),
990 SD_BUS_PROPERTY("RestrictNamespaces", "t", bus_property_get_ulong, offsetof(ExecContext, restrict_namespaces), SD_BUS_VTABLE_PROPERTY_CONST),
991 SD_BUS_PROPERTY("BindPaths", "a(ssbt)", property_get_bind_paths, 0, SD_BUS_VTABLE_PROPERTY_CONST),
992 SD_BUS_PROPERTY("BindReadOnlyPaths", "a(ssbt)", property_get_bind_paths, 0, SD_BUS_VTABLE_PROPERTY_CONST),
993 SD_BUS_PROPERTY("TemporaryFileSystem", "a(ss)", property_get_temporary_filesystems, 0, SD_BUS_VTABLE_PROPERTY_CONST),
994 SD_BUS_PROPERTY("MountAPIVFS", "b", bus_property_get_bool, offsetof(ExecContext, mount_apivfs), SD_BUS_VTABLE_PROPERTY_CONST),
995 SD_BUS_PROPERTY("KeyringMode", "s", property_get_exec_keyring_mode, offsetof(ExecContext, keyring_mode), SD_BUS_VTABLE_PROPERTY_CONST),
996 SD_BUS_PROPERTY("ProtectHostname", "b", bus_property_get_bool, offsetof(ExecContext, protect_hostname), SD_BUS_VTABLE_PROPERTY_CONST),
997 SD_BUS_PROPERTY("NetworkNamespacePath", "s", NULL, offsetof(ExecContext, network_namespace_path), SD_BUS_VTABLE_PROPERTY_CONST),
998
999 /* Obsolete/redundant properties: */
1000 SD_BUS_PROPERTY("Capabilities", "s", property_get_empty_string, 0, SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN),
1001 SD_BUS_PROPERTY("ReadWriteDirectories", "as", NULL, offsetof(ExecContext, read_write_paths), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN),
1002 SD_BUS_PROPERTY("ReadOnlyDirectories", "as", NULL, offsetof(ExecContext, read_only_paths), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN),
1003 SD_BUS_PROPERTY("InaccessibleDirectories", "as", NULL, offsetof(ExecContext, inaccessible_paths), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN),
1004 SD_BUS_PROPERTY("IOScheduling", "i", property_get_ioprio, 0, SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN),
1005
1006 SD_BUS_VTABLE_END
1007 };
1008
1009 static int append_exec_command(sd_bus_message *reply, ExecCommand *c) {
1010 int r;
1011
1012 assert(reply);
1013 assert(c);
1014
1015 if (!c->path)
1016 return 0;
1017
1018 r = sd_bus_message_open_container(reply, 'r', "sasbttttuii");
1019 if (r < 0)
1020 return r;
1021
1022 r = sd_bus_message_append(reply, "s", c->path);
1023 if (r < 0)
1024 return r;
1025
1026 r = sd_bus_message_append_strv(reply, c->argv);
1027 if (r < 0)
1028 return r;
1029
1030 r = sd_bus_message_append(reply, "bttttuii",
1031 !!(c->flags & EXEC_COMMAND_IGNORE_FAILURE),
1032 c->exec_status.start_timestamp.realtime,
1033 c->exec_status.start_timestamp.monotonic,
1034 c->exec_status.exit_timestamp.realtime,
1035 c->exec_status.exit_timestamp.monotonic,
1036 (uint32_t) c->exec_status.pid,
1037 (int32_t) c->exec_status.code,
1038 (int32_t) c->exec_status.status);
1039 if (r < 0)
1040 return r;
1041
1042 return sd_bus_message_close_container(reply);
1043 }
1044
1045 static int append_exec_ex_command(sd_bus_message *reply, ExecCommand *c) {
1046 _cleanup_strv_free_ char **ex_opts = NULL;
1047 int r;
1048
1049 assert(reply);
1050 assert(c);
1051
1052 if (!c->path)
1053 return 0;
1054
1055 r = sd_bus_message_open_container(reply, 'r', "sasasttttuii");
1056 if (r < 0)
1057 return r;
1058
1059 r = sd_bus_message_append(reply, "s", c->path);
1060 if (r < 0)
1061 return r;
1062
1063 r = sd_bus_message_append_strv(reply, c->argv);
1064 if (r < 0)
1065 return r;
1066
1067 r = exec_command_flags_to_strv(c->flags, &ex_opts);
1068 if (r < 0)
1069 return r;
1070
1071 r = sd_bus_message_append_strv(reply, ex_opts);
1072 if (r < 0)
1073 return r;
1074
1075 r = sd_bus_message_append(reply, "ttttuii",
1076 c->exec_status.start_timestamp.realtime,
1077 c->exec_status.start_timestamp.monotonic,
1078 c->exec_status.exit_timestamp.realtime,
1079 c->exec_status.exit_timestamp.monotonic,
1080 (uint32_t) c->exec_status.pid,
1081 (int32_t) c->exec_status.code,
1082 (int32_t) c->exec_status.status);
1083 if (r < 0)
1084 return r;
1085
1086 return sd_bus_message_close_container(reply);
1087 }
1088
1089 int bus_property_get_exec_command(
1090 sd_bus *bus,
1091 const char *path,
1092 const char *interface,
1093 const char *property,
1094 sd_bus_message *reply,
1095 void *userdata,
1096 sd_bus_error *ret_error) {
1097
1098 ExecCommand *c = (ExecCommand*) userdata;
1099 int r;
1100
1101 assert(bus);
1102 assert(reply);
1103
1104 r = sd_bus_message_open_container(reply, 'a', "(sasbttttuii)");
1105 if (r < 0)
1106 return r;
1107
1108 r = append_exec_command(reply, c);
1109 if (r < 0)
1110 return r;
1111
1112 return sd_bus_message_close_container(reply);
1113 }
1114
1115 int bus_property_get_exec_command_list(
1116 sd_bus *bus,
1117 const char *path,
1118 const char *interface,
1119 const char *property,
1120 sd_bus_message *reply,
1121 void *userdata,
1122 sd_bus_error *ret_error) {
1123
1124 ExecCommand *c = *(ExecCommand**) userdata;
1125 int r;
1126
1127 assert(bus);
1128 assert(reply);
1129
1130 r = sd_bus_message_open_container(reply, 'a', "(sasbttttuii)");
1131 if (r < 0)
1132 return r;
1133
1134 LIST_FOREACH(command, c, c) {
1135 r = append_exec_command(reply, c);
1136 if (r < 0)
1137 return r;
1138 }
1139
1140 return sd_bus_message_close_container(reply);
1141 }
1142
1143 int bus_property_get_exec_ex_command_list(
1144 sd_bus *bus,
1145 const char *path,
1146 const char *interface,
1147 const char *property,
1148 sd_bus_message *reply,
1149 void *userdata,
1150 sd_bus_error *ret_error) {
1151
1152 ExecCommand *c, *exec_command = *(ExecCommand**) userdata;
1153 int r;
1154
1155 assert(bus);
1156 assert(reply);
1157
1158 r = sd_bus_message_open_container(reply, 'a', "(sasasttttuii)");
1159 if (r < 0)
1160 return r;
1161
1162 LIST_FOREACH(command, c, exec_command) {
1163 r = append_exec_ex_command(reply, c);
1164 if (r < 0)
1165 return r;
1166 }
1167
1168 return sd_bus_message_close_container(reply);
1169 }
1170
1171 static char *exec_command_flags_to_exec_chars(ExecCommandFlags flags) {
1172 return strjoin(FLAGS_SET(flags, EXEC_COMMAND_IGNORE_FAILURE) ? "-" : "",
1173 FLAGS_SET(flags, EXEC_COMMAND_NO_ENV_EXPAND) ? ":" : "",
1174 FLAGS_SET(flags, EXEC_COMMAND_FULLY_PRIVILEGED) ? "+" : "",
1175 FLAGS_SET(flags, EXEC_COMMAND_NO_SETUID) ? "!" : "",
1176 FLAGS_SET(flags, EXEC_COMMAND_AMBIENT_MAGIC) ? "!!" : "");
1177 }
1178
1179 int bus_set_transient_exec_command(
1180 Unit *u,
1181 const char *name,
1182 ExecCommand **exec_command,
1183 sd_bus_message *message,
1184 UnitWriteFlags flags,
1185 sd_bus_error *error) {
1186 bool is_ex_prop = endswith(name, "Ex");
1187 unsigned n = 0;
1188 int r;
1189
1190 r = sd_bus_message_enter_container(message, 'a', is_ex_prop ? "(sasas)" : "(sasb)");
1191 if (r < 0)
1192 return r;
1193
1194 while ((r = sd_bus_message_enter_container(message, 'r', is_ex_prop ? "sasas" : "sasb")) > 0) {
1195 _cleanup_strv_free_ char **argv = NULL, **ex_opts = NULL;
1196 const char *path;
1197 int b;
1198
1199 r = sd_bus_message_read(message, "s", &path);
1200 if (r < 0)
1201 return r;
1202
1203 if (!path_is_absolute(path))
1204 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path %s is not absolute.", path);
1205
1206 r = sd_bus_message_read_strv(message, &argv);
1207 if (r < 0)
1208 return r;
1209
1210 r = is_ex_prop ? sd_bus_message_read_strv(message, &ex_opts) : sd_bus_message_read(message, "b", &b);
1211 if (r < 0)
1212 return r;
1213
1214 r = sd_bus_message_exit_container(message);
1215 if (r < 0)
1216 return r;
1217
1218 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
1219 ExecCommand *c;
1220
1221 c = new0(ExecCommand, 1);
1222 if (!c)
1223 return -ENOMEM;
1224
1225 c->path = strdup(path);
1226 if (!c->path) {
1227 free(c);
1228 return -ENOMEM;
1229 }
1230
1231 c->argv = TAKE_PTR(argv);
1232
1233 if (is_ex_prop) {
1234 r = exec_command_flags_from_strv(ex_opts, &c->flags);
1235 if (r < 0)
1236 return r;
1237 } else
1238 c->flags = b ? EXEC_COMMAND_IGNORE_FAILURE : 0;
1239
1240 path_simplify(c->path, false);
1241 exec_command_append_list(exec_command, c);
1242 }
1243
1244 n++;
1245 }
1246 if (r < 0)
1247 return r;
1248
1249 r = sd_bus_message_exit_container(message);
1250 if (r < 0)
1251 return r;
1252
1253 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
1254 _cleanup_free_ char *buf = NULL;
1255 _cleanup_fclose_ FILE *f = NULL;
1256 ExecCommand *c;
1257 size_t size = 0;
1258
1259 if (n == 0)
1260 *exec_command = exec_command_free_list(*exec_command);
1261
1262 f = open_memstream_unlocked(&buf, &size);
1263 if (!f)
1264 return -ENOMEM;
1265
1266 fprintf(f, "%s=\n", name);
1267
1268 LIST_FOREACH(command, c, *exec_command) {
1269 _cleanup_free_ char *a = NULL, *exec_chars = NULL;
1270
1271 exec_chars = exec_command_flags_to_exec_chars(c->flags);
1272 if (!exec_chars)
1273 return -ENOMEM;
1274
1275 a = unit_concat_strv(c->argv, UNIT_ESCAPE_C|UNIT_ESCAPE_SPECIFIERS);
1276 if (!a)
1277 return -ENOMEM;
1278
1279 if (streq_ptr(c->path, c->argv ? c->argv[0] : NULL))
1280 fprintf(f, "%s=%s%s\n", name, exec_chars, a);
1281 else {
1282 _cleanup_free_ char *t = NULL;
1283 const char *p;
1284
1285 p = unit_escape_setting(c->path, UNIT_ESCAPE_C|UNIT_ESCAPE_SPECIFIERS, &t);
1286 if (!p)
1287 return -ENOMEM;
1288
1289 fprintf(f, "%s=%s@%s %s\n", name, exec_chars, p, a);
1290 }
1291 }
1292
1293 r = fflush_and_check(f);
1294 if (r < 0)
1295 return r;
1296
1297 unit_write_setting(u, flags, name, buf);
1298 }
1299
1300 return 1;
1301 }
1302
1303 static int parse_personality(const char *s, unsigned long *p) {
1304 unsigned long v;
1305
1306 assert(p);
1307
1308 v = personality_from_string(s);
1309 if (v == PERSONALITY_INVALID)
1310 return -EINVAL;
1311
1312 *p = v;
1313 return 0;
1314 }
1315
1316 static const char* mount_propagation_flags_to_string_with_check(unsigned long n) {
1317 if (!IN_SET(n, 0, MS_SHARED, MS_PRIVATE, MS_SLAVE))
1318 return NULL;
1319
1320 return mount_propagation_flags_to_string(n);
1321 }
1322
1323 static BUS_DEFINE_SET_TRANSIENT(nsec, "t", uint64_t, nsec_t, NSEC_FMT);
1324 static BUS_DEFINE_SET_TRANSIENT_IS_VALID(log_level, "i", int32_t, int, "%" PRIi32, log_level_is_valid);
1325 #if HAVE_SECCOMP
1326 static BUS_DEFINE_SET_TRANSIENT_IS_VALID(errno, "i", int32_t, int, "%" PRIi32, errno_is_valid);
1327 #endif
1328 static BUS_DEFINE_SET_TRANSIENT_PARSE(std_input, ExecInput, exec_input_from_string);
1329 static BUS_DEFINE_SET_TRANSIENT_PARSE(std_output, ExecOutput, exec_output_from_string);
1330 static BUS_DEFINE_SET_TRANSIENT_PARSE(utmp_mode, ExecUtmpMode, exec_utmp_mode_from_string);
1331 static BUS_DEFINE_SET_TRANSIENT_PARSE(protect_system, ProtectSystem, protect_system_from_string);
1332 static BUS_DEFINE_SET_TRANSIENT_PARSE(protect_home, ProtectHome, protect_home_from_string);
1333 static BUS_DEFINE_SET_TRANSIENT_PARSE(keyring_mode, ExecKeyringMode, exec_keyring_mode_from_string);
1334 static BUS_DEFINE_SET_TRANSIENT_PARSE(preserve_mode, ExecPreserveMode, exec_preserve_mode_from_string);
1335 static BUS_DEFINE_SET_TRANSIENT_PARSE_PTR(personality, unsigned long, parse_personality);
1336 static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(secure_bits, "i", int32_t, int, "%" PRIi32, secure_bits_to_string_alloc_with_check);
1337 static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(capability, "t", uint64_t, uint64_t, "%" PRIu64, capability_set_to_string_alloc);
1338 static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(namespace_flag, "t", uint64_t, unsigned long, "%" PRIu64, namespace_flags_to_string);
1339 static BUS_DEFINE_SET_TRANSIENT_TO_STRING(mount_flags, "t", uint64_t, unsigned long, "%" PRIu64, mount_propagation_flags_to_string_with_check);
1340
1341 int bus_exec_context_set_transient_property(
1342 Unit *u,
1343 ExecContext *c,
1344 const char *name,
1345 sd_bus_message *message,
1346 UnitWriteFlags flags,
1347 sd_bus_error *error) {
1348
1349 const char *suffix;
1350 int r;
1351
1352 assert(u);
1353 assert(c);
1354 assert(name);
1355 assert(message);
1356
1357 flags |= UNIT_PRIVATE;
1358
1359 if (streq(name, "User"))
1360 return bus_set_transient_user_relaxed(u, name, &c->user, message, flags, error);
1361
1362 if (streq(name, "Group"))
1363 return bus_set_transient_user_relaxed(u, name, &c->group, message, flags, error);
1364
1365 if (streq(name, "TTYPath"))
1366 return bus_set_transient_path(u, name, &c->tty_path, message, flags, error);
1367
1368 if (streq(name, "RootImage"))
1369 return bus_set_transient_path(u, name, &c->root_image, message, flags, error);
1370
1371 if (streq(name, "RootImageOptions")) {
1372 _cleanup_(mount_options_free_allp) MountOptions *options = NULL;
1373 _cleanup_free_ char *format_str = NULL;
1374 const char *mount_options;
1375 unsigned partition_number;
1376
1377 r = sd_bus_message_enter_container(message, 'a', "(us)");
1378 if (r < 0)
1379 return r;
1380
1381 while ((r = sd_bus_message_read(message, "(us)", &partition_number, &mount_options)) > 0) {
1382 _cleanup_free_ char *previous = TAKE_PTR(format_str);
1383 _cleanup_free_ MountOptions *o = NULL;
1384
1385 if (chars_intersect(mount_options, WHITESPACE))
1386 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS,
1387 "Invalid mount options string, contains whitespace character(s): %s", mount_options);
1388
1389 if (asprintf(&format_str, "%s%s%u:%s", strempty(previous), previous ? " " : "", partition_number, mount_options) < 0)
1390 return -ENOMEM;
1391
1392 o = new(MountOptions, 1);
1393 if (!o)
1394 return -ENOMEM;
1395 *o = (MountOptions) {
1396 .partition_number = partition_number,
1397 .options = strdup(mount_options),
1398 };
1399 if (!o->options)
1400 return -ENOMEM;
1401 LIST_APPEND(mount_options, options, TAKE_PTR(o));
1402 }
1403 if (r < 0)
1404 return r;
1405
1406 r = sd_bus_message_exit_container(message);
1407 if (r < 0)
1408 return r;
1409
1410 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
1411 if (LIST_IS_EMPTY(options)) {
1412 c->root_image_options = mount_options_free_all(c->root_image_options);
1413 unit_write_settingf(u, flags, name, "%s=", name);
1414 } else {
1415 LIST_JOIN(mount_options, c->root_image_options, options);
1416 unit_write_settingf(
1417 u, flags|UNIT_ESCAPE_SPECIFIERS, name,
1418 "%s=%s",
1419 name,
1420 format_str);
1421 }
1422 }
1423
1424 return 1;
1425 }
1426
1427 if (streq(name, "RootHash")) {
1428 const void *roothash_decoded;
1429 size_t roothash_decoded_size;
1430
1431 r = sd_bus_message_read_array(message, 'y', &roothash_decoded, &roothash_decoded_size);
1432 if (r < 0)
1433 return r;
1434
1435 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
1436 _cleanup_free_ char *encoded = NULL;
1437
1438 if (roothash_decoded_size == 0) {
1439 c->root_hash_path = mfree(c->root_hash_path);
1440 c->root_hash = mfree(c->root_hash);
1441 c->root_hash_size = 0;
1442
1443 unit_write_settingf(u, flags, name, "RootHash=");
1444 } else {
1445 _cleanup_free_ void *p;
1446
1447 encoded = hexmem(roothash_decoded, roothash_decoded_size);
1448 if (!encoded)
1449 return -ENOMEM;
1450
1451 p = memdup(roothash_decoded, roothash_decoded_size);
1452 if (!p)
1453 return -ENOMEM;
1454
1455 free_and_replace(c->root_hash, p);
1456 c->root_hash_size = roothash_decoded_size;
1457 c->root_hash_path = mfree(c->root_hash_path);
1458
1459 unit_write_settingf(u, flags, name, "RootHash=%s", encoded);
1460 }
1461 }
1462
1463 return 1;
1464 }
1465
1466 if (streq(name, "RootHashPath")) {
1467 c->root_hash_size = 0;
1468 c->root_hash = mfree(c->root_hash);
1469
1470 return bus_set_transient_path(u, "RootHash", &c->root_hash_path, message, flags, error);
1471 }
1472
1473 if (streq(name, "RootHashSignature")) {
1474 const void *roothash_sig_decoded;
1475 size_t roothash_sig_decoded_size;
1476
1477 r = sd_bus_message_read_array(message, 'y', &roothash_sig_decoded, &roothash_sig_decoded_size);
1478 if (r < 0)
1479 return r;
1480
1481 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
1482 _cleanup_free_ char *encoded = NULL;
1483
1484 if (roothash_sig_decoded_size == 0) {
1485 c->root_hash_sig_path = mfree(c->root_hash_sig_path);
1486 c->root_hash_sig = mfree(c->root_hash_sig);
1487 c->root_hash_sig_size = 0;
1488
1489 unit_write_settingf(u, flags, name, "RootHashSignature=");
1490 } else {
1491 _cleanup_free_ void *p;
1492 ssize_t len;
1493
1494 len = base64mem(roothash_sig_decoded, roothash_sig_decoded_size, &encoded);
1495 if (len < 0)
1496 return -ENOMEM;
1497
1498 p = memdup(roothash_sig_decoded, roothash_sig_decoded_size);
1499 if (!p)
1500 return -ENOMEM;
1501
1502 free_and_replace(c->root_hash_sig, p);
1503 c->root_hash_sig_size = roothash_sig_decoded_size;
1504 c->root_hash_sig_path = mfree(c->root_hash_sig_path);
1505
1506 unit_write_settingf(u, flags, name, "RootHashSignature=base64:%s", encoded);
1507 }
1508 }
1509
1510 return 1;
1511 }
1512
1513 if (streq(name, "RootHashSignaturePath")) {
1514 c->root_hash_sig_size = 0;
1515 c->root_hash_sig = mfree(c->root_hash_sig);
1516
1517 return bus_set_transient_path(u, "RootHashSignature", &c->root_hash_sig_path, message, flags, error);
1518 }
1519
1520 if (streq(name, "RootVerity"))
1521 return bus_set_transient_path(u, name, &c->root_verity, message, flags, error);
1522
1523 if (streq(name, "RootDirectory"))
1524 return bus_set_transient_path(u, name, &c->root_directory, message, flags, error);
1525
1526 if (streq(name, "SyslogIdentifier"))
1527 return bus_set_transient_string(u, name, &c->syslog_identifier, message, flags, error);
1528
1529 if (streq(name, "LogLevelMax"))
1530 return bus_set_transient_log_level(u, name, &c->log_level_max, message, flags, error);
1531
1532 if (streq(name, "LogRateLimitIntervalUSec"))
1533 return bus_set_transient_usec(u, name, &c->log_ratelimit_interval_usec, message, flags, error);
1534
1535 if (streq(name, "LogRateLimitBurst"))
1536 return bus_set_transient_unsigned(u, name, &c->log_ratelimit_burst, message, flags, error);
1537
1538 if (streq(name, "Personality"))
1539 return bus_set_transient_personality(u, name, &c->personality, message, flags, error);
1540
1541 if (streq(name, "StandardInput"))
1542 return bus_set_transient_std_input(u, name, &c->std_input, message, flags, error);
1543
1544 if (streq(name, "StandardOutput"))
1545 return bus_set_transient_std_output(u, name, &c->std_output, message, flags, error);
1546
1547 if (streq(name, "StandardError"))
1548 return bus_set_transient_std_output(u, name, &c->std_error, message, flags, error);
1549
1550 if (streq(name, "IgnoreSIGPIPE"))
1551 return bus_set_transient_bool(u, name, &c->ignore_sigpipe, message, flags, error);
1552
1553 if (streq(name, "TTYVHangup"))
1554 return bus_set_transient_bool(u, name, &c->tty_vhangup, message, flags, error);
1555
1556 if (streq(name, "TTYReset"))
1557 return bus_set_transient_bool(u, name, &c->tty_reset, message, flags, error);
1558
1559 if (streq(name, "TTYVTDisallocate"))
1560 return bus_set_transient_bool(u, name, &c->tty_vt_disallocate, message, flags, error);
1561
1562 if (streq(name, "PrivateTmp"))
1563 return bus_set_transient_bool(u, name, &c->private_tmp, message, flags, error);
1564
1565 if (streq(name, "PrivateDevices"))
1566 return bus_set_transient_bool(u, name, &c->private_devices, message, flags, error);
1567
1568 if (streq(name, "PrivateMounts"))
1569 return bus_set_transient_bool(u, name, &c->private_mounts, message, flags, error);
1570
1571 if (streq(name, "PrivateNetwork"))
1572 return bus_set_transient_bool(u, name, &c->private_network, message, flags, error);
1573
1574 if (streq(name, "PrivateUsers"))
1575 return bus_set_transient_bool(u, name, &c->private_users, message, flags, error);
1576
1577 if (streq(name, "NoNewPrivileges"))
1578 return bus_set_transient_bool(u, name, &c->no_new_privileges, message, flags, error);
1579
1580 if (streq(name, "SyslogLevelPrefix"))
1581 return bus_set_transient_bool(u, name, &c->syslog_level_prefix, message, flags, error);
1582
1583 if (streq(name, "MemoryDenyWriteExecute"))
1584 return bus_set_transient_bool(u, name, &c->memory_deny_write_execute, message, flags, error);
1585
1586 if (streq(name, "RestrictRealtime"))
1587 return bus_set_transient_bool(u, name, &c->restrict_realtime, message, flags, error);
1588
1589 if (streq(name, "RestrictSUIDSGID"))
1590 return bus_set_transient_bool(u, name, &c->restrict_suid_sgid, message, flags, error);
1591
1592 if (streq(name, "DynamicUser"))
1593 return bus_set_transient_bool(u, name, &c->dynamic_user, message, flags, error);
1594
1595 if (streq(name, "RemoveIPC"))
1596 return bus_set_transient_bool(u, name, &c->remove_ipc, message, flags, error);
1597
1598 if (streq(name, "ProtectKernelTunables"))
1599 return bus_set_transient_bool(u, name, &c->protect_kernel_tunables, message, flags, error);
1600
1601 if (streq(name, "ProtectKernelModules"))
1602 return bus_set_transient_bool(u, name, &c->protect_kernel_modules, message, flags, error);
1603
1604 if (streq(name, "ProtectKernelLogs"))
1605 return bus_set_transient_bool(u, name, &c->protect_kernel_logs, message, flags, error);
1606
1607 if (streq(name, "ProtectClock"))
1608 return bus_set_transient_bool(u, name, &c->protect_clock, message, flags, error);
1609
1610 if (streq(name, "ProtectControlGroups"))
1611 return bus_set_transient_bool(u, name, &c->protect_control_groups, message, flags, error);
1612
1613 if (streq(name, "MountAPIVFS"))
1614 return bus_set_transient_bool(u, name, &c->mount_apivfs, message, flags, error);
1615
1616 if (streq(name, "CPUSchedulingResetOnFork"))
1617 return bus_set_transient_bool(u, name, &c->cpu_sched_reset_on_fork, message, flags, error);
1618
1619 if (streq(name, "NonBlocking"))
1620 return bus_set_transient_bool(u, name, &c->non_blocking, message, flags, error);
1621
1622 if (streq(name, "LockPersonality"))
1623 return bus_set_transient_bool(u, name, &c->lock_personality, message, flags, error);
1624
1625 if (streq(name, "ProtectHostname"))
1626 return bus_set_transient_bool(u, name, &c->protect_hostname, message, flags, error);
1627
1628 if (streq(name, "UtmpIdentifier"))
1629 return bus_set_transient_string(u, name, &c->utmp_id, message, flags, error);
1630
1631 if (streq(name, "UtmpMode"))
1632 return bus_set_transient_utmp_mode(u, name, &c->utmp_mode, message, flags, error);
1633
1634 if (streq(name, "PAMName"))
1635 return bus_set_transient_string(u, name, &c->pam_name, message, flags, error);
1636
1637 if (streq(name, "TimerSlackNSec"))
1638 return bus_set_transient_nsec(u, name, &c->timer_slack_nsec, message, flags, error);
1639
1640 if (streq(name, "ProtectSystem"))
1641 return bus_set_transient_protect_system(u, name, &c->protect_system, message, flags, error);
1642
1643 if (streq(name, "ProtectHome"))
1644 return bus_set_transient_protect_home(u, name, &c->protect_home, message, flags, error);
1645
1646 if (streq(name, "KeyringMode"))
1647 return bus_set_transient_keyring_mode(u, name, &c->keyring_mode, message, flags, error);
1648
1649 if (streq(name, "RuntimeDirectoryPreserve"))
1650 return bus_set_transient_preserve_mode(u, name, &c->runtime_directory_preserve_mode, message, flags, error);
1651
1652 if (streq(name, "UMask"))
1653 return bus_set_transient_mode_t(u, name, &c->umask, message, flags, error);
1654
1655 if (streq(name, "RuntimeDirectoryMode"))
1656 return bus_set_transient_mode_t(u, name, &c->directories[EXEC_DIRECTORY_RUNTIME].mode, message, flags, error);
1657
1658 if (streq(name, "StateDirectoryMode"))
1659 return bus_set_transient_mode_t(u, name, &c->directories[EXEC_DIRECTORY_STATE].mode, message, flags, error);
1660
1661 if (streq(name, "CacheDirectoryMode"))
1662 return bus_set_transient_mode_t(u, name, &c->directories[EXEC_DIRECTORY_CACHE].mode, message, flags, error);
1663
1664 if (streq(name, "LogsDirectoryMode"))
1665 return bus_set_transient_mode_t(u, name, &c->directories[EXEC_DIRECTORY_LOGS].mode, message, flags, error);
1666
1667 if (streq(name, "ConfigurationDirectoryMode"))
1668 return bus_set_transient_mode_t(u, name, &c->directories[EXEC_DIRECTORY_CONFIGURATION].mode, message, flags, error);
1669
1670 if (streq(name, "SELinuxContext"))
1671 return bus_set_transient_string(u, name, &c->selinux_context, message, flags, error);
1672
1673 if (streq(name, "SecureBits"))
1674 return bus_set_transient_secure_bits(u, name, &c->secure_bits, message, flags, error);
1675
1676 if (streq(name, "CapabilityBoundingSet"))
1677 return bus_set_transient_capability(u, name, &c->capability_bounding_set, message, flags, error);
1678
1679 if (streq(name, "AmbientCapabilities"))
1680 return bus_set_transient_capability(u, name, &c->capability_ambient_set, message, flags, error);
1681
1682 if (streq(name, "RestrictNamespaces"))
1683 return bus_set_transient_namespace_flag(u, name, &c->restrict_namespaces, message, flags, error);
1684
1685 if (streq(name, "MountFlags"))
1686 return bus_set_transient_mount_flags(u, name, &c->mount_flags, message, flags, error);
1687
1688 if (streq(name, "NetworkNamespacePath"))
1689 return bus_set_transient_path(u, name, &c->network_namespace_path, message, flags, error);
1690
1691 if (streq(name, "SupplementaryGroups")) {
1692 _cleanup_strv_free_ char **l = NULL;
1693 char **p;
1694
1695 r = sd_bus_message_read_strv(message, &l);
1696 if (r < 0)
1697 return r;
1698
1699 STRV_FOREACH(p, l)
1700 if (!isempty(*p) && !valid_user_group_name(*p, VALID_USER_ALLOW_NUMERIC|VALID_USER_RELAX|VALID_USER_WARN))
1701 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS,
1702 "Invalid supplementary group names");
1703
1704 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
1705 if (strv_isempty(l)) {
1706 c->supplementary_groups = strv_free(c->supplementary_groups);
1707 unit_write_settingf(u, flags, name, "%s=", name);
1708 } else {
1709 _cleanup_free_ char *joined = NULL;
1710
1711 r = strv_extend_strv(&c->supplementary_groups, l, true);
1712 if (r < 0)
1713 return -ENOMEM;
1714
1715 joined = strv_join(c->supplementary_groups, " ");
1716 if (!joined)
1717 return -ENOMEM;
1718
1719 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "%s=%s", name, joined);
1720 }
1721 }
1722
1723 return 1;
1724
1725 } else if (streq(name, "SyslogLevel")) {
1726 int32_t level;
1727
1728 r = sd_bus_message_read(message, "i", &level);
1729 if (r < 0)
1730 return r;
1731
1732 if (!log_level_is_valid(level))
1733 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Log level value out of range");
1734
1735 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
1736 c->syslog_priority = (c->syslog_priority & LOG_FACMASK) | level;
1737 unit_write_settingf(u, flags, name, "SyslogLevel=%i", level);
1738 }
1739
1740 return 1;
1741
1742 } else if (streq(name, "SyslogFacility")) {
1743 int32_t facility;
1744
1745 r = sd_bus_message_read(message, "i", &facility);
1746 if (r < 0)
1747 return r;
1748
1749 if (!log_facility_unshifted_is_valid(facility))
1750 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Log facility value out of range");
1751
1752 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
1753 c->syslog_priority = (facility << 3) | LOG_PRI(c->syslog_priority);
1754 unit_write_settingf(u, flags, name, "SyslogFacility=%i", facility);
1755 }
1756
1757 return 1;
1758
1759 } else if (streq(name, "LogNamespace")) {
1760 const char *n;
1761
1762 r = sd_bus_message_read(message, "s", &n);
1763 if (r < 0)
1764 return r;
1765
1766 if (!isempty(n) && !log_namespace_name_valid(n))
1767 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Log namespace name not valid");
1768
1769 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
1770
1771 if (isempty(n)) {
1772 c->log_namespace = mfree(c->log_namespace);
1773 unit_write_settingf(u, flags, name, "%s=", name);
1774 } else {
1775 r = free_and_strdup(&c->log_namespace, n);
1776 if (r < 0)
1777 return r;
1778
1779 unit_write_settingf(u, flags, name, "%s=%s", name, n);
1780 }
1781 }
1782
1783 return 1;
1784
1785 } else if (streq(name, "LogExtraFields")) {
1786 size_t n = 0;
1787
1788 r = sd_bus_message_enter_container(message, 'a', "ay");
1789 if (r < 0)
1790 return r;
1791
1792 for (;;) {
1793 _cleanup_free_ void *copy = NULL;
1794 struct iovec *t;
1795 const char *eq;
1796 const void *p;
1797 size_t sz;
1798
1799 /* Note that we expect a byte array for each field, instead of a string. That's because on the
1800 * lower-level journal fields can actually contain binary data and are not restricted to text,
1801 * and we should not "lose precision" in our types on the way. That said, I am pretty sure
1802 * actually encoding binary data as unit metadata is not a good idea. Hence we actually refuse
1803 * any actual binary data, and only accept UTF-8. This allows us to eventually lift this
1804 * limitation, should a good, valid usecase arise. */
1805
1806 r = sd_bus_message_read_array(message, 'y', &p, &sz);
1807 if (r < 0)
1808 return r;
1809 if (r == 0)
1810 break;
1811
1812 if (memchr(p, 0, sz))
1813 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Journal field contains zero byte");
1814
1815 eq = memchr(p, '=', sz);
1816 if (!eq)
1817 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Journal field contains no '=' character");
1818 if (!journal_field_valid(p, eq - (const char*) p, false))
1819 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Journal field invalid");
1820
1821 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
1822 t = reallocarray(c->log_extra_fields, c->n_log_extra_fields+1, sizeof(struct iovec));
1823 if (!t)
1824 return -ENOMEM;
1825 c->log_extra_fields = t;
1826 }
1827
1828 copy = malloc(sz + 1);
1829 if (!copy)
1830 return -ENOMEM;
1831
1832 memcpy(copy, p, sz);
1833 ((uint8_t*) copy)[sz] = 0;
1834
1835 if (!utf8_is_valid(copy))
1836 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Journal field is not valid UTF-8");
1837
1838 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
1839 c->log_extra_fields[c->n_log_extra_fields++] = IOVEC_MAKE(copy, sz);
1840 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS|UNIT_ESCAPE_C, name, "LogExtraFields=%s", (char*) copy);
1841
1842 copy = NULL;
1843 }
1844
1845 n++;
1846 }
1847
1848 r = sd_bus_message_exit_container(message);
1849 if (r < 0)
1850 return r;
1851
1852 if (!UNIT_WRITE_FLAGS_NOOP(flags) && n == 0) {
1853 exec_context_free_log_extra_fields(c);
1854 unit_write_setting(u, flags, name, "LogExtraFields=");
1855 }
1856
1857 return 1;
1858 }
1859
1860 #if HAVE_SECCOMP
1861
1862 if (streq(name, "SystemCallErrorNumber"))
1863 return bus_set_transient_errno(u, name, &c->syscall_errno, message, flags, error);
1864
1865 if (streq(name, "SystemCallFilter")) {
1866 int allow_list;
1867 _cleanup_strv_free_ char **l = NULL;
1868
1869 r = sd_bus_message_enter_container(message, 'r', "bas");
1870 if (r < 0)
1871 return r;
1872
1873 r = sd_bus_message_read(message, "b", &allow_list);
1874 if (r < 0)
1875 return r;
1876
1877 r = sd_bus_message_read_strv(message, &l);
1878 if (r < 0)
1879 return r;
1880
1881 r = sd_bus_message_exit_container(message);
1882 if (r < 0)
1883 return r;
1884
1885 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
1886 _cleanup_free_ char *joined = NULL;
1887 SeccompParseFlags invert_flag = allow_list ? 0 : SECCOMP_PARSE_INVERT;
1888 char **s;
1889
1890 if (strv_isempty(l)) {
1891 c->syscall_allow_list = false;
1892 c->syscall_filter = hashmap_free(c->syscall_filter);
1893
1894 unit_write_settingf(u, flags, name, "SystemCallFilter=");
1895 return 1;
1896 }
1897
1898 if (!c->syscall_filter) {
1899 c->syscall_filter = hashmap_new(NULL);
1900 if (!c->syscall_filter)
1901 return log_oom();
1902
1903 c->syscall_allow_list = allow_list;
1904
1905 if (c->syscall_allow_list) {
1906 r = seccomp_parse_syscall_filter("@default",
1907 -1,
1908 c->syscall_filter,
1909 SECCOMP_PARSE_PERMISSIVE |
1910 SECCOMP_PARSE_ALLOW_LIST | invert_flag,
1911 u->id,
1912 NULL, 0);
1913 if (r < 0)
1914 return r;
1915 }
1916 }
1917
1918 STRV_FOREACH(s, l) {
1919 _cleanup_free_ char *n = NULL;
1920 int e;
1921
1922 r = parse_syscall_and_errno(*s, &n, &e);
1923 if (r < 0)
1924 return r;
1925
1926 r = seccomp_parse_syscall_filter(n,
1927 e,
1928 c->syscall_filter,
1929 SECCOMP_PARSE_LOG | SECCOMP_PARSE_PERMISSIVE |
1930 invert_flag |
1931 (c->syscall_allow_list ? SECCOMP_PARSE_ALLOW_LIST : 0),
1932 u->id,
1933 NULL, 0);
1934 if (r < 0)
1935 return r;
1936 }
1937
1938 joined = strv_join(l, " ");
1939 if (!joined)
1940 return -ENOMEM;
1941
1942 unit_write_settingf(u, flags, name, "SystemCallFilter=%s%s", allow_list ? "" : "~", joined);
1943 }
1944
1945 return 1;
1946
1947 } else if (streq(name, "SystemCallArchitectures")) {
1948 _cleanup_strv_free_ char **l = NULL;
1949
1950 r = sd_bus_message_read_strv(message, &l);
1951 if (r < 0)
1952 return r;
1953
1954 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
1955 _cleanup_free_ char *joined = NULL;
1956
1957 if (strv_isempty(l))
1958 c->syscall_archs = set_free(c->syscall_archs);
1959 else {
1960 char **s;
1961
1962 STRV_FOREACH(s, l) {
1963 uint32_t a;
1964
1965 r = seccomp_arch_from_string(*s, &a);
1966 if (r < 0)
1967 return r;
1968
1969 r = set_ensure_put(&c->syscall_archs, NULL, UINT32_TO_PTR(a + 1));
1970 if (r < 0)
1971 return r;
1972 }
1973
1974 }
1975
1976 joined = strv_join(l, " ");
1977 if (!joined)
1978 return -ENOMEM;
1979
1980 unit_write_settingf(u, flags, name, "%s=%s", name, joined);
1981 }
1982
1983 return 1;
1984
1985 } else if (streq(name, "RestrictAddressFamilies")) {
1986 int allow_list;
1987 _cleanup_strv_free_ char **l = NULL;
1988
1989 r = sd_bus_message_enter_container(message, 'r', "bas");
1990 if (r < 0)
1991 return r;
1992
1993 r = sd_bus_message_read(message, "b", &allow_list);
1994 if (r < 0)
1995 return r;
1996
1997 r = sd_bus_message_read_strv(message, &l);
1998 if (r < 0)
1999 return r;
2000
2001 r = sd_bus_message_exit_container(message);
2002 if (r < 0)
2003 return r;
2004
2005 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2006 _cleanup_free_ char *joined = NULL;
2007 char **s;
2008
2009 if (strv_isempty(l)) {
2010 c->address_families_allow_list = false;
2011 c->address_families = set_free(c->address_families);
2012
2013 unit_write_settingf(u, flags, name, "RestrictAddressFamilies=");
2014 return 1;
2015 }
2016
2017 if (!c->address_families) {
2018 c->address_families = set_new(NULL);
2019 if (!c->address_families)
2020 return log_oom();
2021
2022 c->address_families_allow_list = allow_list;
2023 }
2024
2025 STRV_FOREACH(s, l) {
2026 int af;
2027
2028 af = af_from_name(*s);
2029 if (af < 0)
2030 return af;
2031
2032 if (allow_list == c->address_families_allow_list) {
2033 r = set_put(c->address_families, INT_TO_PTR(af));
2034 if (r < 0)
2035 return r;
2036 } else
2037 (void) set_remove(c->address_families, INT_TO_PTR(af));
2038 }
2039
2040 joined = strv_join(l, " ");
2041 if (!joined)
2042 return -ENOMEM;
2043
2044 unit_write_settingf(u, flags, name, "RestrictAddressFamilies=%s%s", allow_list ? "" : "~", joined);
2045 }
2046
2047 return 1;
2048 }
2049 #endif
2050 if (STR_IN_SET(name, "CPUAffinity", "NUMAMask")) {
2051 const void *a;
2052 size_t n;
2053 bool affinity = streq(name, "CPUAffinity");
2054 _cleanup_(cpu_set_reset) CPUSet set = {};
2055
2056 r = sd_bus_message_read_array(message, 'y', &a, &n);
2057 if (r < 0)
2058 return r;
2059
2060 r = cpu_set_from_dbus(a, n, &set);
2061 if (r < 0)
2062 return r;
2063
2064 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2065 if (n == 0) {
2066 cpu_set_reset(affinity ? &c->cpu_set : &c->numa_policy.nodes);
2067 unit_write_settingf(u, flags, name, "%s=", name);
2068 } else {
2069 _cleanup_free_ char *str = NULL;
2070
2071 str = cpu_set_to_string(&set);
2072 if (!str)
2073 return -ENOMEM;
2074
2075 /* We forego any optimizations here, and always create the structure using
2076 * cpu_set_add_all(), because we don't want to care if the existing size we
2077 * got over dbus is appropriate. */
2078 r = cpu_set_add_all(affinity ? &c->cpu_set : &c->numa_policy.nodes, &set);
2079 if (r < 0)
2080 return r;
2081
2082 unit_write_settingf(u, flags, name, "%s=%s", name, str);
2083 }
2084 }
2085
2086 return 1;
2087
2088 } else if (streq(name, "CPUAffinityFromNUMA")) {
2089 int q;
2090
2091 r = sd_bus_message_read_basic(message, 'b', &q);
2092 if (r < 0)
2093 return r;
2094
2095 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2096 c->cpu_affinity_from_numa = q;
2097 unit_write_settingf(u, flags, name, "%s=%s", "CPUAffinity", "numa");
2098 }
2099
2100 return 1;
2101
2102 } else if (streq(name, "NUMAPolicy")) {
2103 int32_t type;
2104
2105 r = sd_bus_message_read(message, "i", &type);
2106 if (r < 0)
2107 return r;
2108
2109 if (!mpol_is_valid(type))
2110 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid NUMAPolicy value: %i", type);
2111
2112 if (!UNIT_WRITE_FLAGS_NOOP(flags))
2113 c->numa_policy.type = type;
2114
2115 return 1;
2116
2117 } else if (streq(name, "Nice")) {
2118 int32_t q;
2119
2120 r = sd_bus_message_read(message, "i", &q);
2121 if (r < 0)
2122 return r;
2123
2124 if (!nice_is_valid(q))
2125 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid Nice value: %i", q);
2126
2127 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2128 c->nice = q;
2129 c->nice_set = true;
2130
2131 unit_write_settingf(u, flags, name, "Nice=%i", q);
2132 }
2133
2134 return 1;
2135
2136 } else if (streq(name, "CPUSchedulingPolicy")) {
2137 int32_t q;
2138
2139 r = sd_bus_message_read(message, "i", &q);
2140 if (r < 0)
2141 return r;
2142
2143 if (!sched_policy_is_valid(q))
2144 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid CPU scheduling policy: %i", q);
2145
2146 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2147 _cleanup_free_ char *s = NULL;
2148
2149 r = sched_policy_to_string_alloc(q, &s);
2150 if (r < 0)
2151 return r;
2152
2153 c->cpu_sched_policy = q;
2154 c->cpu_sched_priority = CLAMP(c->cpu_sched_priority, sched_get_priority_min(q), sched_get_priority_max(q));
2155 c->cpu_sched_set = true;
2156
2157 unit_write_settingf(u, flags, name, "CPUSchedulingPolicy=%s", s);
2158 }
2159
2160 return 1;
2161
2162 } else if (streq(name, "CPUSchedulingPriority")) {
2163 int32_t p, min, max;
2164
2165 r = sd_bus_message_read(message, "i", &p);
2166 if (r < 0)
2167 return r;
2168
2169 min = sched_get_priority_min(c->cpu_sched_policy);
2170 max = sched_get_priority_max(c->cpu_sched_policy);
2171 if (p < min || p > max)
2172 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid CPU scheduling priority: %i", p);
2173
2174 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2175 c->cpu_sched_priority = p;
2176 c->cpu_sched_set = true;
2177
2178 unit_write_settingf(u, flags, name, "CPUSchedulingPriority=%i", p);
2179 }
2180
2181 return 1;
2182
2183 } else if (streq(name, "IOSchedulingClass")) {
2184 int32_t q;
2185
2186 r = sd_bus_message_read(message, "i", &q);
2187 if (r < 0)
2188 return r;
2189
2190 if (!ioprio_class_is_valid(q))
2191 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid IO scheduling class: %i", q);
2192
2193 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2194 _cleanup_free_ char *s = NULL;
2195
2196 r = ioprio_class_to_string_alloc(q, &s);
2197 if (r < 0)
2198 return r;
2199
2200 c->ioprio = IOPRIO_PRIO_VALUE(q, IOPRIO_PRIO_DATA(c->ioprio));
2201 c->ioprio_set = true;
2202
2203 unit_write_settingf(u, flags, name, "IOSchedulingClass=%s", s);
2204 }
2205
2206 return 1;
2207
2208 } else if (streq(name, "IOSchedulingPriority")) {
2209 int32_t p;
2210
2211 r = sd_bus_message_read(message, "i", &p);
2212 if (r < 0)
2213 return r;
2214
2215 if (!ioprio_priority_is_valid(p))
2216 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid IO scheduling priority: %i", p);
2217
2218 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2219 c->ioprio = IOPRIO_PRIO_VALUE(IOPRIO_PRIO_CLASS(c->ioprio), p);
2220 c->ioprio_set = true;
2221
2222 unit_write_settingf(u, flags, name, "IOSchedulingPriority=%i", p);
2223 }
2224
2225 return 1;
2226
2227 } else if (streq(name, "WorkingDirectory")) {
2228 const char *s;
2229 bool missing_ok;
2230
2231 r = sd_bus_message_read(message, "s", &s);
2232 if (r < 0)
2233 return r;
2234
2235 if (s[0] == '-') {
2236 missing_ok = true;
2237 s++;
2238 } else
2239 missing_ok = false;
2240
2241 if (!isempty(s) && !streq(s, "~") && !path_is_absolute(s))
2242 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "WorkingDirectory= expects an absolute path or '~'");
2243
2244 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2245 if (streq(s, "~")) {
2246 c->working_directory = mfree(c->working_directory);
2247 c->working_directory_home = true;
2248 } else {
2249 r = free_and_strdup(&c->working_directory, empty_to_null(s));
2250 if (r < 0)
2251 return r;
2252
2253 c->working_directory_home = false;
2254 }
2255
2256 c->working_directory_missing_ok = missing_ok;
2257 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "WorkingDirectory=%s%s", missing_ok ? "-" : "", s);
2258 }
2259
2260 return 1;
2261
2262 } else if (STR_IN_SET(name,
2263 "StandardInputFileDescriptorName", "StandardOutputFileDescriptorName", "StandardErrorFileDescriptorName")) {
2264 const char *s;
2265
2266 r = sd_bus_message_read(message, "s", &s);
2267 if (r < 0)
2268 return r;
2269
2270 if (!isempty(s) && !fdname_is_valid(s))
2271 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid file descriptor name");
2272
2273 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2274
2275 if (streq(name, "StandardInputFileDescriptorName")) {
2276 r = free_and_strdup(c->stdio_fdname + STDIN_FILENO, empty_to_null(s));
2277 if (r < 0)
2278 return r;
2279
2280 c->std_input = EXEC_INPUT_NAMED_FD;
2281 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardInput=fd:%s", exec_context_fdname(c, STDIN_FILENO));
2282
2283 } else if (streq(name, "StandardOutputFileDescriptorName")) {
2284 r = free_and_strdup(c->stdio_fdname + STDOUT_FILENO, empty_to_null(s));
2285 if (r < 0)
2286 return r;
2287
2288 c->std_output = EXEC_OUTPUT_NAMED_FD;
2289 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardOutput=fd:%s", exec_context_fdname(c, STDOUT_FILENO));
2290
2291 } else {
2292 assert(streq(name, "StandardErrorFileDescriptorName"));
2293
2294 r = free_and_strdup(&c->stdio_fdname[STDERR_FILENO], empty_to_null(s));
2295 if (r < 0)
2296 return r;
2297
2298 c->std_error = EXEC_OUTPUT_NAMED_FD;
2299 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardError=fd:%s", exec_context_fdname(c, STDERR_FILENO));
2300 }
2301 }
2302
2303 return 1;
2304
2305 } else if (STR_IN_SET(name,
2306 "StandardInputFile",
2307 "StandardOutputFile", "StandardOutputFileToAppend",
2308 "StandardErrorFile", "StandardErrorFileToAppend")) {
2309 const char *s;
2310
2311 r = sd_bus_message_read(message, "s", &s);
2312 if (r < 0)
2313 return r;
2314
2315 if (!isempty(s)) {
2316 if (!path_is_absolute(s))
2317 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path %s is not absolute", s);
2318 if (!path_is_normalized(s))
2319 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path %s is not normalized", s);
2320 }
2321
2322 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2323
2324 if (streq(name, "StandardInputFile")) {
2325 r = free_and_strdup(&c->stdio_file[STDIN_FILENO], empty_to_null(s));
2326 if (r < 0)
2327 return r;
2328
2329 c->std_input = EXEC_INPUT_FILE;
2330 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardInput=file:%s", s);
2331
2332 } else if (STR_IN_SET(name, "StandardOutputFile", "StandardOutputFileToAppend")) {
2333 r = free_and_strdup(&c->stdio_file[STDOUT_FILENO], empty_to_null(s));
2334 if (r < 0)
2335 return r;
2336
2337 if (streq(name, "StandardOutputFile")) {
2338 c->std_output = EXEC_OUTPUT_FILE;
2339 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardOutput=file:%s", s);
2340 } else {
2341 assert(streq(name, "StandardOutputFileToAppend"));
2342 c->std_output = EXEC_OUTPUT_FILE_APPEND;
2343 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardOutput=append:%s", s);
2344 }
2345 } else {
2346 assert(STR_IN_SET(name, "StandardErrorFile", "StandardErrorFileToAppend"));
2347
2348 r = free_and_strdup(&c->stdio_file[STDERR_FILENO], empty_to_null(s));
2349 if (r < 0)
2350 return r;
2351
2352 if (streq(name, "StandardErrorFile")) {
2353 c->std_error = EXEC_OUTPUT_FILE;
2354 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardError=file:%s", s);
2355 } else {
2356 assert(streq(name, "StandardErrorFileToAppend"));
2357 c->std_error = EXEC_OUTPUT_FILE_APPEND;
2358 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardError=append:%s", s);
2359 }
2360 }
2361 }
2362
2363 return 1;
2364
2365 } else if (streq(name, "StandardInputData")) {
2366 const void *p;
2367 size_t sz;
2368
2369 r = sd_bus_message_read_array(message, 'y', &p, &sz);
2370 if (r < 0)
2371 return r;
2372
2373 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2374 _cleanup_free_ char *encoded = NULL;
2375
2376 if (sz == 0) {
2377 c->stdin_data = mfree(c->stdin_data);
2378 c->stdin_data_size = 0;
2379
2380 unit_write_settingf(u, flags, name, "StandardInputData=");
2381 } else {
2382 void *q;
2383 ssize_t n;
2384
2385 if (c->stdin_data_size + sz < c->stdin_data_size || /* check for overflow */
2386 c->stdin_data_size + sz > EXEC_STDIN_DATA_MAX)
2387 return -E2BIG;
2388
2389 n = base64mem(p, sz, &encoded);
2390 if (n < 0)
2391 return (int) n;
2392
2393 q = realloc(c->stdin_data, c->stdin_data_size + sz);
2394 if (!q)
2395 return -ENOMEM;
2396
2397 memcpy((uint8_t*) q + c->stdin_data_size, p, sz);
2398
2399 c->stdin_data = q;
2400 c->stdin_data_size += sz;
2401
2402 unit_write_settingf(u, flags, name, "StandardInputData=%s", encoded);
2403 }
2404 }
2405
2406 return 1;
2407
2408 } else if (streq(name, "Environment")) {
2409
2410 _cleanup_strv_free_ char **l = NULL;
2411
2412 r = sd_bus_message_read_strv(message, &l);
2413 if (r < 0)
2414 return r;
2415
2416 if (!strv_env_is_valid(l))
2417 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid environment block.");
2418
2419 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2420 if (strv_isempty(l)) {
2421 c->environment = strv_free(c->environment);
2422 unit_write_setting(u, flags, name, "Environment=");
2423 } else {
2424 _cleanup_free_ char *joined = NULL;
2425 char **e;
2426
2427 joined = unit_concat_strv(l, UNIT_ESCAPE_SPECIFIERS|UNIT_ESCAPE_C);
2428 if (!joined)
2429 return -ENOMEM;
2430
2431 e = strv_env_merge(2, c->environment, l);
2432 if (!e)
2433 return -ENOMEM;
2434
2435 strv_free_and_replace(c->environment, e);
2436 unit_write_settingf(u, flags, name, "Environment=%s", joined);
2437 }
2438 }
2439
2440 return 1;
2441
2442 } else if (streq(name, "UnsetEnvironment")) {
2443
2444 _cleanup_strv_free_ char **l = NULL;
2445
2446 r = sd_bus_message_read_strv(message, &l);
2447 if (r < 0)
2448 return r;
2449
2450 if (!strv_env_name_or_assignment_is_valid(l))
2451 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid UnsetEnvironment= list.");
2452
2453 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2454 if (strv_isempty(l)) {
2455 c->unset_environment = strv_free(c->unset_environment);
2456 unit_write_setting(u, flags, name, "UnsetEnvironment=");
2457 } else {
2458 _cleanup_free_ char *joined = NULL;
2459 char **e;
2460
2461 joined = unit_concat_strv(l, UNIT_ESCAPE_SPECIFIERS|UNIT_ESCAPE_C);
2462 if (!joined)
2463 return -ENOMEM;
2464
2465 e = strv_env_merge(2, c->unset_environment, l);
2466 if (!e)
2467 return -ENOMEM;
2468
2469 strv_free_and_replace(c->unset_environment, e);
2470 unit_write_settingf(u, flags, name, "UnsetEnvironment=%s", joined);
2471 }
2472 }
2473
2474 return 1;
2475
2476 } else if (streq(name, "OOMScoreAdjust")) {
2477 int oa;
2478
2479 r = sd_bus_message_read(message, "i", &oa);
2480 if (r < 0)
2481 return r;
2482
2483 if (!oom_score_adjust_is_valid(oa))
2484 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "OOM score adjust value out of range");
2485
2486 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2487 c->oom_score_adjust = oa;
2488 c->oom_score_adjust_set = true;
2489 unit_write_settingf(u, flags, name, "OOMScoreAdjust=%i", oa);
2490 }
2491
2492 return 1;
2493
2494 } else if (streq(name, "CoredumpFilter")) {
2495 uint64_t f;
2496
2497 r = sd_bus_message_read(message, "t", &f);
2498 if (r < 0)
2499 return r;
2500
2501 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2502 c->coredump_filter = f;
2503 c->coredump_filter_set = true;
2504 unit_write_settingf(u, flags, name, "CoredumpFilter=0x%"PRIx64, f);
2505 }
2506
2507 return 1;
2508
2509 } else if (streq(name, "EnvironmentFiles")) {
2510
2511 _cleanup_free_ char *joined = NULL;
2512 _cleanup_fclose_ FILE *f = NULL;
2513 _cleanup_strv_free_ char **l = NULL;
2514 size_t size = 0;
2515 char **i;
2516
2517 r = sd_bus_message_enter_container(message, 'a', "(sb)");
2518 if (r < 0)
2519 return r;
2520
2521 f = open_memstream_unlocked(&joined, &size);
2522 if (!f)
2523 return -ENOMEM;
2524
2525 fputs("EnvironmentFile=\n", f);
2526
2527 STRV_FOREACH(i, c->environment_files) {
2528 _cleanup_free_ char *q = NULL;
2529
2530 q = specifier_escape(*i);
2531 if (!q)
2532 return -ENOMEM;
2533
2534 fprintf(f, "EnvironmentFile=%s\n", q);
2535 }
2536
2537 while ((r = sd_bus_message_enter_container(message, 'r', "sb")) > 0) {
2538 const char *path;
2539 int b;
2540
2541 r = sd_bus_message_read(message, "sb", &path, &b);
2542 if (r < 0)
2543 return r;
2544
2545 r = sd_bus_message_exit_container(message);
2546 if (r < 0)
2547 return r;
2548
2549 if (!path_is_absolute(path))
2550 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path %s is not absolute.", path);
2551
2552 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2553 _cleanup_free_ char *q = NULL, *buf = NULL;
2554
2555 buf = strjoin(b ? "-" : "", path);
2556 if (!buf)
2557 return -ENOMEM;
2558
2559 q = specifier_escape(buf);
2560 if (!q)
2561 return -ENOMEM;
2562
2563 fprintf(f, "EnvironmentFile=%s\n", q);
2564
2565 r = strv_consume(&l, TAKE_PTR(buf));
2566 if (r < 0)
2567 return r;
2568 }
2569 }
2570 if (r < 0)
2571 return r;
2572
2573 r = sd_bus_message_exit_container(message);
2574 if (r < 0)
2575 return r;
2576
2577 r = fflush_and_check(f);
2578 if (r < 0)
2579 return r;
2580
2581 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2582 if (strv_isempty(l)) {
2583 c->environment_files = strv_free(c->environment_files);
2584 unit_write_setting(u, flags, name, "EnvironmentFile=");
2585 } else {
2586 r = strv_extend_strv(&c->environment_files, l, true);
2587 if (r < 0)
2588 return r;
2589
2590 unit_write_setting(u, flags, name, joined);
2591 }
2592 }
2593
2594 return 1;
2595
2596 } else if (streq(name, "PassEnvironment")) {
2597
2598 _cleanup_strv_free_ char **l = NULL;
2599
2600 r = sd_bus_message_read_strv(message, &l);
2601 if (r < 0)
2602 return r;
2603
2604 if (!strv_env_name_is_valid(l))
2605 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid PassEnvironment= block.");
2606
2607 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2608 if (strv_isempty(l)) {
2609 c->pass_environment = strv_free(c->pass_environment);
2610 unit_write_setting(u, flags, name, "PassEnvironment=");
2611 } else {
2612 _cleanup_free_ char *joined = NULL;
2613
2614 r = strv_extend_strv(&c->pass_environment, l, true);
2615 if (r < 0)
2616 return r;
2617
2618 /* We write just the new settings out to file, with unresolved specifiers. */
2619 joined = unit_concat_strv(l, UNIT_ESCAPE_SPECIFIERS);
2620 if (!joined)
2621 return -ENOMEM;
2622
2623 unit_write_settingf(u, flags, name, "PassEnvironment=%s", joined);
2624 }
2625 }
2626
2627 return 1;
2628
2629 } else if (STR_IN_SET(name, "ReadWriteDirectories", "ReadOnlyDirectories", "InaccessibleDirectories",
2630 "ReadWritePaths", "ReadOnlyPaths", "InaccessiblePaths")) {
2631 _cleanup_strv_free_ char **l = NULL;
2632 char ***dirs;
2633 char **p;
2634
2635 r = sd_bus_message_read_strv(message, &l);
2636 if (r < 0)
2637 return r;
2638
2639 STRV_FOREACH(p, l) {
2640 char *i = *p;
2641 size_t offset;
2642
2643 offset = i[0] == '-';
2644 offset += i[offset] == '+';
2645 if (!path_is_absolute(i + offset))
2646 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid %s", name);
2647
2648 path_simplify(i + offset, false);
2649 }
2650
2651 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2652 if (STR_IN_SET(name, "ReadWriteDirectories", "ReadWritePaths"))
2653 dirs = &c->read_write_paths;
2654 else if (STR_IN_SET(name, "ReadOnlyDirectories", "ReadOnlyPaths"))
2655 dirs = &c->read_only_paths;
2656 else /* "InaccessiblePaths" */
2657 dirs = &c->inaccessible_paths;
2658
2659 if (strv_isempty(l)) {
2660 *dirs = strv_free(*dirs);
2661 unit_write_settingf(u, flags, name, "%s=", name);
2662 } else {
2663 _cleanup_free_ char *joined = NULL;
2664
2665 joined = unit_concat_strv(l, UNIT_ESCAPE_SPECIFIERS);
2666 if (!joined)
2667 return -ENOMEM;
2668
2669 r = strv_extend_strv(dirs, l, true);
2670 if (r < 0)
2671 return -ENOMEM;
2672
2673 unit_write_settingf(u, flags, name, "%s=%s", name, joined);
2674 }
2675 }
2676
2677 return 1;
2678
2679 } else if (STR_IN_SET(name, "RuntimeDirectory", "StateDirectory", "CacheDirectory", "LogsDirectory", "ConfigurationDirectory")) {
2680 _cleanup_strv_free_ char **l = NULL;
2681 char **p;
2682
2683 r = sd_bus_message_read_strv(message, &l);
2684 if (r < 0)
2685 return r;
2686
2687 STRV_FOREACH(p, l) {
2688 if (!path_is_normalized(*p))
2689 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "%s= path is not normalized: %s", name, *p);
2690
2691 if (path_is_absolute(*p))
2692 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "%s= path is absolute: %s", name, *p);
2693
2694 if (path_startswith(*p, "private"))
2695 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "%s= path can't be 'private': %s", name, *p);
2696 }
2697
2698 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2699 ExecDirectoryType i;
2700 ExecDirectory *d;
2701
2702 assert_se((i = exec_directory_type_from_string(name)) >= 0);
2703 d = c->directories + i;
2704
2705 if (strv_isempty(l)) {
2706 d->paths = strv_free(d->paths);
2707 unit_write_settingf(u, flags, name, "%s=", name);
2708 } else {
2709 _cleanup_free_ char *joined = NULL;
2710
2711 r = strv_extend_strv(&d->paths, l, true);
2712 if (r < 0)
2713 return r;
2714
2715 joined = unit_concat_strv(l, UNIT_ESCAPE_SPECIFIERS);
2716 if (!joined)
2717 return -ENOMEM;
2718
2719 unit_write_settingf(u, flags, name, "%s=%s", name, joined);
2720 }
2721 }
2722
2723 return 1;
2724
2725 } else if (STR_IN_SET(name, "AppArmorProfile", "SmackProcessLabel")) {
2726 int ignore;
2727 const char *s;
2728
2729 r = sd_bus_message_read(message, "(bs)", &ignore, &s);
2730 if (r < 0)
2731 return r;
2732
2733 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2734 char **p;
2735 bool *b;
2736
2737 if (streq(name, "AppArmorProfile")) {
2738 p = &c->apparmor_profile;
2739 b = &c->apparmor_profile_ignore;
2740 } else { /* "SmackProcessLabel" */
2741 p = &c->smack_process_label;
2742 b = &c->smack_process_label_ignore;
2743 }
2744
2745 if (isempty(s)) {
2746 *p = mfree(*p);
2747 *b = false;
2748 } else {
2749 if (free_and_strdup(p, s) < 0)
2750 return -ENOMEM;
2751 *b = ignore;
2752 }
2753
2754 unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "%s=%s%s", name, ignore ? "-" : "", strempty(s));
2755 }
2756
2757 return 1;
2758
2759 } else if (STR_IN_SET(name, "BindPaths", "BindReadOnlyPaths")) {
2760 char *source, *destination;
2761 int ignore_enoent;
2762 uint64_t mount_flags;
2763 bool empty = true;
2764
2765 r = sd_bus_message_enter_container(message, 'a', "(ssbt)");
2766 if (r < 0)
2767 return r;
2768
2769 while ((r = sd_bus_message_read(message, "(ssbt)", &source, &destination, &ignore_enoent, &mount_flags)) > 0) {
2770
2771 if (!path_is_absolute(source))
2772 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Source path %s is not absolute.", source);
2773 if (!path_is_absolute(destination))
2774 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Destination path %s is not absolute.", destination);
2775 if (!IN_SET(mount_flags, 0, MS_REC))
2776 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Unknown mount flags.");
2777
2778 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2779 r = bind_mount_add(&c->bind_mounts, &c->n_bind_mounts,
2780 &(BindMount) {
2781 .source = source,
2782 .destination = destination,
2783 .read_only = !!strstr(name, "ReadOnly"),
2784 .recursive = !!(mount_flags & MS_REC),
2785 .ignore_enoent = ignore_enoent,
2786 });
2787 if (r < 0)
2788 return r;
2789
2790 unit_write_settingf(
2791 u, flags|UNIT_ESCAPE_SPECIFIERS, name,
2792 "%s=%s%s:%s:%s",
2793 name,
2794 ignore_enoent ? "-" : "",
2795 source,
2796 destination,
2797 (mount_flags & MS_REC) ? "rbind" : "norbind");
2798 }
2799
2800 empty = false;
2801 }
2802 if (r < 0)
2803 return r;
2804
2805 r = sd_bus_message_exit_container(message);
2806 if (r < 0)
2807 return r;
2808
2809 if (empty) {
2810 bind_mount_free_many(c->bind_mounts, c->n_bind_mounts);
2811 c->bind_mounts = NULL;
2812 c->n_bind_mounts = 0;
2813
2814 unit_write_settingf(u, flags, name, "%s=", name);
2815 }
2816
2817 return 1;
2818
2819 } else if (streq(name, "TemporaryFileSystem")) {
2820 const char *path, *options;
2821 bool empty = true;
2822
2823 r = sd_bus_message_enter_container(message, 'a', "(ss)");
2824 if (r < 0)
2825 return r;
2826
2827 while ((r = sd_bus_message_read(message, "(ss)", &path, &options)) > 0) {
2828
2829 if (!path_is_absolute(path))
2830 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Mount point %s is not absolute.", path);
2831
2832 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2833 r = temporary_filesystem_add(&c->temporary_filesystems, &c->n_temporary_filesystems, path, options);
2834 if (r < 0)
2835 return r;
2836
2837 unit_write_settingf(
2838 u, flags|UNIT_ESCAPE_SPECIFIERS, name,
2839 "%s=%s:%s",
2840 name,
2841 path,
2842 options);
2843 }
2844
2845 empty = false;
2846 }
2847 if (r < 0)
2848 return r;
2849
2850 r = sd_bus_message_exit_container(message);
2851 if (r < 0)
2852 return r;
2853
2854 if (empty) {
2855 temporary_filesystem_free_many(c->temporary_filesystems, c->n_temporary_filesystems);
2856 c->temporary_filesystems = NULL;
2857 c->n_temporary_filesystems = 0;
2858
2859 unit_write_settingf(u, flags, name, "%s=", name);
2860 }
2861
2862 return 1;
2863
2864 } else if ((suffix = startswith(name, "Limit"))) {
2865 const char *soft = NULL;
2866 int ri;
2867
2868 ri = rlimit_from_string(suffix);
2869 if (ri < 0) {
2870 soft = endswith(suffix, "Soft");
2871 if (soft) {
2872 const char *n;
2873
2874 n = strndupa(suffix, soft - suffix);
2875 ri = rlimit_from_string(n);
2876 if (ri >= 0)
2877 name = strjoina("Limit", n);
2878 }
2879 }
2880
2881 if (ri >= 0) {
2882 uint64_t rl;
2883 rlim_t x;
2884
2885 r = sd_bus_message_read(message, "t", &rl);
2886 if (r < 0)
2887 return r;
2888
2889 if (rl == (uint64_t) -1)
2890 x = RLIM_INFINITY;
2891 else {
2892 x = (rlim_t) rl;
2893
2894 if ((uint64_t) x != rl)
2895 return -ERANGE;
2896 }
2897
2898 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2899 _cleanup_free_ char *f = NULL;
2900 struct rlimit nl;
2901
2902 if (c->rlimit[ri]) {
2903 nl = *c->rlimit[ri];
2904
2905 if (soft)
2906 nl.rlim_cur = x;
2907 else
2908 nl.rlim_max = x;
2909 } else
2910 /* When the resource limit is not initialized yet, then assign the value to both fields */
2911 nl = (struct rlimit) {
2912 .rlim_cur = x,
2913 .rlim_max = x,
2914 };
2915
2916 r = rlimit_format(&nl, &f);
2917 if (r < 0)
2918 return r;
2919
2920 if (c->rlimit[ri])
2921 *c->rlimit[ri] = nl;
2922 else {
2923 c->rlimit[ri] = newdup(struct rlimit, &nl, 1);
2924 if (!c->rlimit[ri])
2925 return -ENOMEM;
2926 }
2927
2928 unit_write_settingf(u, flags, name, "%s=%s", name, f);
2929 }
2930
2931 return 1;
2932 }
2933
2934 } else if (streq(name, "MountImages")) {
2935 _cleanup_free_ char *format_str = NULL;
2936 MountImage *mount_images = NULL;
2937 size_t n_mount_images = 0;
2938 char *source, *destination;
2939 int permissive;
2940
2941 r = sd_bus_message_enter_container(message, 'a', "(ssb)");
2942 if (r < 0)
2943 return r;
2944
2945 while ((r = sd_bus_message_read(message, "(ssb)", &source, &destination, &permissive)) > 0) {
2946 char *tuple;
2947
2948 if (!path_is_absolute(source))
2949 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Source path %s is not absolute.", source);
2950 if (!path_is_normalized(source))
2951 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Source path %s is not normalized.", source);
2952 if (!path_is_absolute(destination))
2953 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Destination path %s is not absolute.", destination);
2954 if (!path_is_normalized(destination))
2955 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Destination path %s is not normalized.", destination);
2956
2957 tuple = strjoin(format_str, format_str ? " " : "", permissive ? "-" : "", source, ":", destination);
2958 if (!tuple)
2959 return -ENOMEM;
2960 free_and_replace(format_str, tuple);
2961
2962 r = mount_image_add(&mount_images, &n_mount_images,
2963 &(MountImage) {
2964 .source = source,
2965 .destination = destination,
2966 .ignore_enoent = permissive,
2967 });
2968 if (r < 0)
2969 return r;
2970 }
2971 if (r < 0)
2972 return r;
2973
2974 r = sd_bus_message_exit_container(message);
2975 if (r < 0)
2976 return r;
2977
2978 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2979 if (n_mount_images == 0) {
2980 c->mount_images = mount_image_free_many(c->mount_images, &c->n_mount_images);
2981
2982 unit_write_settingf(u, flags, name, "%s=", name);
2983 } else {
2984 for (size_t i = 0; i < n_mount_images; ++i) {
2985 r = mount_image_add(&c->mount_images, &c->n_mount_images, &mount_images[i]);
2986 if (r < 0)
2987 return r;
2988 }
2989
2990 unit_write_settingf(u, flags|UNIT_ESCAPE_C|UNIT_ESCAPE_SPECIFIERS,
2991 name,
2992 "%s=%s",
2993 name,
2994 format_str);
2995 }
2996 }
2997
2998 mount_images = mount_image_free_many(mount_images, &n_mount_images);
2999
3000 return 1;
3001 }
3002
3003 return 0;
3004 }