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