]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
4139c1b2 | 2 | |
227b8a76 | 3 | #include <sys/mount.h> |
82c121a4 | 4 | #include <sys/prctl.h> |
4139c1b2 | 5 | |
349cc4a5 | 6 | #if HAVE_SECCOMP |
57183d11 LP |
7 | #include <seccomp.h> |
8 | #endif | |
9 | ||
3ffd4af2 | 10 | #include "af-list.h" |
b5efdb8a | 11 | #include "alloc-util.h" |
718db961 | 12 | #include "bus-util.h" |
cffaed83 | 13 | #include "cap-list.h" |
d3070fbd | 14 | #include "capability-util.h" |
501941aa | 15 | #include "cpu-set-util.h" |
3ffd4af2 | 16 | #include "dbus-execute.h" |
7e2a3fcc | 17 | #include "dbus-util.h" |
c7040b5d | 18 | #include "env-util.h" |
cffaed83 | 19 | #include "errno-list.h" |
2e59b241 | 20 | #include "escape.h" |
3ffd4af2 LP |
21 | #include "execute.h" |
22 | #include "fd-util.h" | |
23 | #include "fileio.h" | |
08f3be7a | 24 | #include "hexdecoct.h" |
d3070fbd | 25 | #include "io-util.h" |
3ffd4af2 | 26 | #include "ioprio.h" |
d3070fbd | 27 | #include "journal-util.h" |
049af8ad | 28 | #include "mountpoint-util.h" |
417116f2 | 29 | #include "namespace.h" |
6bedfcbb | 30 | #include "parse-util.h" |
9b15b784 | 31 | #include "path-util.h" |
7b3e062c | 32 | #include "process-util.h" |
78f22b97 | 33 | #include "rlimit-util.h" |
349cc4a5 | 34 | #if HAVE_SECCOMP |
57183d11 LP |
35 | #include "seccomp-util.h" |
36 | #endif | |
cffaed83 | 37 | #include "securebits-util.h" |
2e59b241 | 38 | #include "specifier.h" |
6bedfcbb | 39 | #include "strv.h" |
7ccbd1ae | 40 | #include "syslog-util.h" |
f900f582 | 41 | #include "unit-printf.h" |
6f3e7985 | 42 | #include "user-util.h" |
6bedfcbb | 43 | #include "utf8.h" |
57183d11 | 44 | |
718db961 | 45 | BUS_DEFINE_PROPERTY_GET_ENUM(bus_property_get_exec_output, exec_output, ExecOutput); |
718db961 | 46 | static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_input, exec_input, ExecInput); |
023a4f67 | 47 | static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_utmp_mode, exec_utmp_mode, ExecUtmpMode); |
53f47dfc | 48 | static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_preserve_mode, exec_preserve_mode, ExecPreserveMode); |
b1edf445 | 49 | static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_keyring_mode, exec_keyring_mode, ExecKeyringMode); |
73b84e92 YW |
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); | |
491eecb3 | 52 | static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_personality, personality, unsigned long); |
019b34ca YW |
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); | |
92c23c5a YW |
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); | |
e2b2fb7f MS |
59 | static BUS_DEFINE_PROPERTY_GET(property_get_cpu_affinity_from_numa, "b", ExecContext, exec_context_get_cpu_affinity_from_numa); |
60 | ||
718db961 LP |
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, | |
ebcf1f97 LP |
67 | void *userdata, |
68 | sd_bus_error *error) { | |
8c7be95e | 69 | |
718db961 LP |
70 | ExecContext *c = userdata; |
71 | char **j; | |
72 | int r; | |
8c7be95e | 73 | |
718db961 LP |
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; | |
8c7be95e | 81 | |
718db961 LP |
82 | STRV_FOREACH(j, c->environment_files) { |
83 | const char *fn = *j; | |
8c7be95e | 84 | |
718db961 LP |
85 | r = sd_bus_message_append(reply, "(sb)", fn[0] == '-' ? fn + 1 : fn, fn[0] == '-'); |
86 | if (r < 0) | |
87 | return r; | |
8c7be95e LP |
88 | } |
89 | ||
718db961 LP |
90 | return sd_bus_message_close_container(reply); |
91 | } | |
92 | ||
718db961 LP |
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, | |
ebcf1f97 LP |
99 | void *userdata, |
100 | sd_bus_error *error) { | |
718db961 | 101 | |
718db961 | 102 | ExecContext *c = userdata; |
82c121a4 | 103 | int32_t n; |
b94fb74b | 104 | int r; |
82c121a4 | 105 | |
718db961 LP |
106 | assert(bus); |
107 | assert(reply); | |
82c121a4 LP |
108 | assert(c); |
109 | ||
dd6c17b1 LP |
110 | if (c->oom_score_adjust_set) |
111 | n = c->oom_score_adjust; | |
82c121a4 | 112 | else { |
68eda4bd | 113 | _cleanup_free_ char *t = NULL; |
82c121a4 LP |
114 | |
115 | n = 0; | |
b94fb74b ZJS |
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 | } | |
82c121a4 LP |
124 | } |
125 | ||
718db961 | 126 | return sd_bus_message_append(reply, "i", n); |
82c121a4 LP |
127 | } |
128 | ||
ad21e542 ZJS |
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 | ||
718db961 LP |
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, | |
ebcf1f97 LP |
171 | void *userdata, |
172 | sd_bus_error *error) { | |
718db961 | 173 | |
718db961 | 174 | ExecContext *c = userdata; |
82c121a4 LP |
175 | int32_t n; |
176 | ||
718db961 LP |
177 | assert(bus); |
178 | assert(reply); | |
82c121a4 LP |
179 | assert(c); |
180 | ||
181 | if (c->nice_set) | |
182 | n = c->nice; | |
718db961 LP |
183 | else { |
184 | errno = 0; | |
82c121a4 | 185 | n = getpriority(PRIO_PROCESS, 0); |
b3267152 | 186 | if (errno > 0) |
718db961 LP |
187 | n = 0; |
188 | } | |
82c121a4 | 189 | |
718db961 | 190 | return sd_bus_message_append(reply, "i", n); |
82c121a4 LP |
191 | } |
192 | ||
718db961 LP |
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, | |
ebcf1f97 LP |
199 | void *userdata, |
200 | sd_bus_error *error) { | |
718db961 LP |
201 | |
202 | ExecContext *c = userdata; | |
82c121a4 LP |
203 | int32_t n; |
204 | ||
718db961 LP |
205 | assert(bus); |
206 | assert(reply); | |
82c121a4 LP |
207 | assert(c); |
208 | ||
209 | if (c->cpu_sched_set) | |
210 | n = c->cpu_sched_policy; | |
718db961 | 211 | else { |
82c121a4 | 212 | n = sched_getscheduler(0); |
718db961 LP |
213 | if (n < 0) |
214 | n = SCHED_OTHER; | |
215 | } | |
82c121a4 | 216 | |
718db961 | 217 | return sd_bus_message_append(reply, "i", n); |
82c121a4 LP |
218 | } |
219 | ||
718db961 LP |
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, | |
ebcf1f97 LP |
226 | void *userdata, |
227 | sd_bus_error *error) { | |
718db961 LP |
228 | |
229 | ExecContext *c = userdata; | |
82c121a4 LP |
230 | int32_t n; |
231 | ||
718db961 LP |
232 | assert(bus); |
233 | assert(reply); | |
82c121a4 LP |
234 | assert(c); |
235 | ||
236 | if (c->cpu_sched_set) | |
237 | n = c->cpu_sched_priority; | |
238 | else { | |
b92bea5d | 239 | struct sched_param p = {}; |
82c121a4 | 240 | |
82c121a4 LP |
241 | if (sched_getparam(0, &p) >= 0) |
242 | n = p.sched_priority; | |
e62d8c39 ZJS |
243 | else |
244 | n = 0; | |
82c121a4 LP |
245 | } |
246 | ||
718db961 | 247 | return sd_bus_message_append(reply, "i", n); |
82c121a4 LP |
248 | } |
249 | ||
718db961 LP |
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, | |
ebcf1f97 LP |
256 | void *userdata, |
257 | sd_bus_error *error) { | |
82c121a4 | 258 | |
718db961 | 259 | ExecContext *c = userdata; |
e2b2fb7f | 260 | _cleanup_(cpu_set_reset) CPUSet s = {}; |
75e40119 MS |
261 | _cleanup_free_ uint8_t *array = NULL; |
262 | size_t allocated; | |
82c121a4 | 263 | |
718db961 LP |
264 | assert(bus); |
265 | assert(reply); | |
266 | assert(c); | |
82c121a4 | 267 | |
e2b2fb7f MS |
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 | ||
75e40119 | 278 | return sd_bus_message_append_array(reply, 'y', array, allocated); |
82c121a4 LP |
279 | } |
280 | ||
b070c7c0 MS |
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 | ||
718db961 LP |
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, | |
ebcf1f97 LP |
329 | void *userdata, |
330 | sd_bus_error *error) { | |
718db961 LP |
331 | |
332 | ExecContext *c = userdata; | |
82c121a4 LP |
333 | uint64_t u; |
334 | ||
718db961 LP |
335 | assert(bus); |
336 | assert(reply); | |
82c121a4 LP |
337 | assert(c); |
338 | ||
3a43da28 | 339 | if (c->timer_slack_nsec != NSEC_INFINITY) |
03fae018 | 340 | u = (uint64_t) c->timer_slack_nsec; |
82c121a4 LP |
341 | else |
342 | u = (uint64_t) prctl(PR_GET_TIMERSLACK); | |
343 | ||
718db961 | 344 | return sd_bus_message_append(reply, "t", u); |
82c121a4 LP |
345 | } |
346 | ||
718db961 LP |
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, | |
ebcf1f97 LP |
353 | void *userdata, |
354 | sd_bus_error *error) { | |
82c121a4 | 355 | |
17df7223 LP |
356 | ExecContext *c = userdata; |
357 | _cleanup_strv_free_ char **l = NULL; | |
57183d11 LP |
358 | int r; |
359 | ||
349cc4a5 | 360 | #if HAVE_SECCOMP |
17df7223 | 361 | Iterator i; |
8cfa775f | 362 | void *id, *val; |
351a19b1 | 363 | #endif |
17df7223 LP |
364 | |
365 | assert(bus); | |
366 | assert(reply); | |
367 | assert(c); | |
368 | ||
57183d11 LP |
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_whitelist); | |
374 | if (r < 0) | |
375 | return r; | |
376 | ||
349cc4a5 | 377 | #if HAVE_SECCOMP |
8cfa775f YW |
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); | |
17df7223 LP |
383 | |
384 | name = seccomp_syscall_resolve_num_arch(SCMP_ARCH_NATIVE, PTR_TO_INT(id) - 1); | |
385 | if (!name) | |
386 | continue; | |
387 | ||
8cfa775f YW |
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 | } | |
ae2a15bc LP |
399 | } else |
400 | s = TAKE_PTR(name); | |
8cfa775f YW |
401 | |
402 | r = strv_consume(&l, s); | |
6e18964d ZJS |
403 | if (r < 0) |
404 | return r; | |
17df7223 | 405 | } |
351a19b1 | 406 | #endif |
17df7223 LP |
407 | |
408 | strv_sort(l); | |
409 | ||
57183d11 LP |
410 | r = sd_bus_message_append_strv(reply, l); |
411 | if (r < 0) | |
412 | return r; | |
17df7223 | 413 | |
57183d11 LP |
414 | return sd_bus_message_close_container(reply); |
415 | } | |
17df7223 | 416 | |
57183d11 LP |
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 | ||
349cc4a5 | 430 | #if HAVE_SECCOMP |
57183d11 LP |
431 | Iterator i; |
432 | void *id; | |
433 | #endif | |
434 | ||
435 | assert(bus); | |
436 | assert(reply); | |
437 | assert(c); | |
17df7223 | 438 | |
349cc4a5 | 439 | #if HAVE_SECCOMP |
57183d11 LP |
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; | |
17df7223 | 450 | } |
57183d11 LP |
451 | #endif |
452 | ||
453 | strv_sort(l); | |
454 | ||
455 | r = sd_bus_message_append_strv(reply, l); | |
456 | if (r < 0) | |
457 | return r; | |
17df7223 | 458 | |
57183d11 | 459 | return 0; |
17df7223 LP |
460 | } |
461 | ||
5f8640fb LP |
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 | ||
eef65bf3 MS |
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 | ||
2ca620c4 WC |
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 | ||
4298d0b5 LP |
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_whitelist); | |
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 | ||
5f5d8eab LP |
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 | ||
5073ff6b | 591 | static int property_get_stdio_fdname( |
52c239d7 LB |
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; | |
5073ff6b | 601 | int fileno; |
52c239d7 LB |
602 | |
603 | assert(bus); | |
604 | assert(c); | |
605 | assert(property); | |
606 | assert(reply); | |
607 | ||
5073ff6b LP |
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 | } | |
52c239d7 | 616 | |
5073ff6b | 617 | return sd_bus_message_append(reply, "s", exec_context_fdname(c, fileno)); |
52c239d7 LB |
618 | } |
619 | ||
08f3be7a | 620 | static int property_get_input_data( |
52c239d7 LB |
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; | |
52c239d7 LB |
630 | |
631 | assert(bus); | |
632 | assert(c); | |
633 | assert(property); | |
634 | assert(reply); | |
635 | ||
08f3be7a | 636 | return sd_bus_message_append_array(reply, 'y', c->stdin_data, c->stdin_data_size); |
52c239d7 LB |
637 | } |
638 | ||
d2d6c096 LP |
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 | ||
5d904a6a | 658 | ro = strstr(property, "ReadOnly"); |
d2d6c096 LP |
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, | |
c9b06108 | 674 | c->bind_mounts[i].recursive ? (uint64_t) MS_REC : (uint64_t) 0); |
d2d6c096 LP |
675 | if (r < 0) |
676 | return r; | |
677 | } | |
678 | ||
679 | return sd_bus_message_close_container(reply); | |
680 | } | |
681 | ||
784ad252 YW |
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 | ||
d3070fbd LP |
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 | ||
0389f4fa LB |
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 | ||
718db961 LP |
768 | const sd_bus_vtable bus_exec_vtable[] = { |
769 | SD_BUS_VTABLE_START(0), | |
556089dc LP |
770 | SD_BUS_PROPERTY("Environment", "as", NULL, offsetof(ExecContext, environment), SD_BUS_VTABLE_PROPERTY_CONST), |
771 | SD_BUS_PROPERTY("EnvironmentFiles", "a(sb)", property_get_environment_files, 0, SD_BUS_VTABLE_PROPERTY_CONST), | |
b4c14404 | 772 | SD_BUS_PROPERTY("PassEnvironment", "as", NULL, offsetof(ExecContext, pass_environment), SD_BUS_VTABLE_PROPERTY_CONST), |
00819cc1 | 773 | SD_BUS_PROPERTY("UnsetEnvironment", "as", NULL, offsetof(ExecContext, unset_environment), SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc | 774 | SD_BUS_PROPERTY("UMask", "u", bus_property_get_mode, offsetof(ExecContext, umask), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 775 | SD_BUS_PROPERTY("LimitCPU", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_CPU]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 776 | SD_BUS_PROPERTY("LimitCPUSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_CPU]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 777 | SD_BUS_PROPERTY("LimitFSIZE", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_FSIZE]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 778 | SD_BUS_PROPERTY("LimitFSIZESoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_FSIZE]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 779 | SD_BUS_PROPERTY("LimitDATA", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_DATA]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 780 | SD_BUS_PROPERTY("LimitDATASoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_DATA]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 781 | SD_BUS_PROPERTY("LimitSTACK", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_STACK]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 782 | SD_BUS_PROPERTY("LimitSTACKSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_STACK]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 783 | SD_BUS_PROPERTY("LimitCORE", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_CORE]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 784 | SD_BUS_PROPERTY("LimitCORESoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_CORE]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 785 | SD_BUS_PROPERTY("LimitRSS", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RSS]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 786 | SD_BUS_PROPERTY("LimitRSSSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RSS]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 787 | SD_BUS_PROPERTY("LimitNOFILE", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NOFILE]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 788 | SD_BUS_PROPERTY("LimitNOFILESoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NOFILE]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 789 | SD_BUS_PROPERTY("LimitAS", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_AS]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 790 | SD_BUS_PROPERTY("LimitASSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_AS]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 791 | SD_BUS_PROPERTY("LimitNPROC", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NPROC]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 792 | SD_BUS_PROPERTY("LimitNPROCSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NPROC]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 793 | SD_BUS_PROPERTY("LimitMEMLOCK", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_MEMLOCK]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 794 | SD_BUS_PROPERTY("LimitMEMLOCKSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_MEMLOCK]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 795 | SD_BUS_PROPERTY("LimitLOCKS", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_LOCKS]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 796 | SD_BUS_PROPERTY("LimitLOCKSSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_LOCKS]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 797 | SD_BUS_PROPERTY("LimitSIGPENDING", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_SIGPENDING]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 798 | SD_BUS_PROPERTY("LimitSIGPENDINGSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_SIGPENDING]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 799 | SD_BUS_PROPERTY("LimitMSGQUEUE", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_MSGQUEUE]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 800 | SD_BUS_PROPERTY("LimitMSGQUEUESoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_MSGQUEUE]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 801 | SD_BUS_PROPERTY("LimitNICE", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NICE]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 802 | SD_BUS_PROPERTY("LimitNICESoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NICE]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 803 | SD_BUS_PROPERTY("LimitRTPRIO", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RTPRIO]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 804 | SD_BUS_PROPERTY("LimitRTPRIOSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RTPRIO]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 805 | SD_BUS_PROPERTY("LimitRTTIME", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RTTIME]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 806 | SD_BUS_PROPERTY("LimitRTTIMESoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RTTIME]), SD_BUS_VTABLE_PROPERTY_CONST), |
5f5d8eab | 807 | SD_BUS_PROPERTY("WorkingDirectory", "s", property_get_working_directory, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc | 808 | SD_BUS_PROPERTY("RootDirectory", "s", NULL, offsetof(ExecContext, root_directory), SD_BUS_VTABLE_PROPERTY_CONST), |
915e6d16 | 809 | SD_BUS_PROPERTY("RootImage", "s", NULL, offsetof(ExecContext, root_image), SD_BUS_VTABLE_PROPERTY_CONST), |
0389f4fa LB |
810 | SD_BUS_PROPERTY("RootHash", "ay", property_get_root_hash, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
811 | SD_BUS_PROPERTY("RootHashPath", "s", NULL, offsetof(ExecContext, root_hash_path), SD_BUS_VTABLE_PROPERTY_CONST), | |
812 | SD_BUS_PROPERTY("RootVerity", "s", NULL, offsetof(ExecContext, root_verity), SD_BUS_VTABLE_PROPERTY_CONST), | |
556089dc | 813 | SD_BUS_PROPERTY("OOMScoreAdjust", "i", property_get_oom_score_adjust, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
ad21e542 | 814 | SD_BUS_PROPERTY("CoredumpFilter", "t", property_get_coredump_filter, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc | 815 | SD_BUS_PROPERTY("Nice", "i", property_get_nice, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
7f452159 LP |
816 | SD_BUS_PROPERTY("IOSchedulingClass", "i", property_get_ioprio_class, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
817 | SD_BUS_PROPERTY("IOSchedulingPriority", "i", property_get_ioprio_priority, 0, SD_BUS_VTABLE_PROPERTY_CONST), | |
556089dc LP |
818 | SD_BUS_PROPERTY("CPUSchedulingPolicy", "i", property_get_cpu_sched_policy, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
819 | SD_BUS_PROPERTY("CPUSchedulingPriority", "i", property_get_cpu_sched_priority, 0, SD_BUS_VTABLE_PROPERTY_CONST), | |
820 | SD_BUS_PROPERTY("CPUAffinity", "ay", property_get_cpu_affinity, 0, SD_BUS_VTABLE_PROPERTY_CONST), | |
e2b2fb7f | 821 | SD_BUS_PROPERTY("CPUAffinityFromNUMA", "b", property_get_cpu_affinity_from_numa, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
b070c7c0 MS |
822 | SD_BUS_PROPERTY("NUMAPolicy", "i", property_get_numa_policy, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
823 | SD_BUS_PROPERTY("NUMAMask", "ay", property_get_numa_mask, 0, SD_BUS_VTABLE_PROPERTY_CONST), | |
556089dc LP |
824 | SD_BUS_PROPERTY("TimerSlackNSec", "t", property_get_timer_slack_nsec, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
825 | SD_BUS_PROPERTY("CPUSchedulingResetOnFork", "b", bus_property_get_bool, offsetof(ExecContext, cpu_sched_reset_on_fork), SD_BUS_VTABLE_PROPERTY_CONST), | |
826 | SD_BUS_PROPERTY("NonBlocking", "b", bus_property_get_bool, offsetof(ExecContext, non_blocking), SD_BUS_VTABLE_PROPERTY_CONST), | |
827 | SD_BUS_PROPERTY("StandardInput", "s", property_get_exec_input, offsetof(ExecContext, std_input), SD_BUS_VTABLE_PROPERTY_CONST), | |
5073ff6b | 828 | SD_BUS_PROPERTY("StandardInputFileDescriptorName", "s", property_get_stdio_fdname, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
08f3be7a | 829 | SD_BUS_PROPERTY("StandardInputData", "ay", property_get_input_data, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc | 830 | SD_BUS_PROPERTY("StandardOutput", "s", bus_property_get_exec_output, offsetof(ExecContext, std_output), SD_BUS_VTABLE_PROPERTY_CONST), |
5073ff6b | 831 | SD_BUS_PROPERTY("StandardOutputFileDescriptorName", "s", property_get_stdio_fdname, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc | 832 | SD_BUS_PROPERTY("StandardError", "s", bus_property_get_exec_output, offsetof(ExecContext, std_error), SD_BUS_VTABLE_PROPERTY_CONST), |
5073ff6b | 833 | SD_BUS_PROPERTY("StandardErrorFileDescriptorName", "s", property_get_stdio_fdname, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc LP |
834 | SD_BUS_PROPERTY("TTYPath", "s", NULL, offsetof(ExecContext, tty_path), SD_BUS_VTABLE_PROPERTY_CONST), |
835 | SD_BUS_PROPERTY("TTYReset", "b", bus_property_get_bool, offsetof(ExecContext, tty_reset), SD_BUS_VTABLE_PROPERTY_CONST), | |
836 | SD_BUS_PROPERTY("TTYVHangup", "b", bus_property_get_bool, offsetof(ExecContext, tty_vhangup), SD_BUS_VTABLE_PROPERTY_CONST), | |
837 | SD_BUS_PROPERTY("TTYVTDisallocate", "b", bus_property_get_bool, offsetof(ExecContext, tty_vt_disallocate), SD_BUS_VTABLE_PROPERTY_CONST), | |
838 | SD_BUS_PROPERTY("SyslogPriority", "i", bus_property_get_int, offsetof(ExecContext, syslog_priority), SD_BUS_VTABLE_PROPERTY_CONST), | |
839 | SD_BUS_PROPERTY("SyslogIdentifier", "s", NULL, offsetof(ExecContext, syslog_identifier), SD_BUS_VTABLE_PROPERTY_CONST), | |
840 | SD_BUS_PROPERTY("SyslogLevelPrefix", "b", bus_property_get_bool, offsetof(ExecContext, syslog_level_prefix), SD_BUS_VTABLE_PROPERTY_CONST), | |
9d5527f2 YW |
841 | SD_BUS_PROPERTY("SyslogLevel", "i", property_get_syslog_level, offsetof(ExecContext, syslog_priority), SD_BUS_VTABLE_PROPERTY_CONST), |
842 | SD_BUS_PROPERTY("SyslogFacility", "i", property_get_syslog_facility, offsetof(ExecContext, syslog_priority), SD_BUS_VTABLE_PROPERTY_CONST), | |
d3070fbd | 843 | SD_BUS_PROPERTY("LogLevelMax", "i", bus_property_get_int, offsetof(ExecContext, log_level_max), SD_BUS_VTABLE_PROPERTY_CONST), |
5ac1530e ZJS |
844 | SD_BUS_PROPERTY("LogRateLimitIntervalUSec", "t", bus_property_get_usec, offsetof(ExecContext, log_ratelimit_interval_usec), SD_BUS_VTABLE_PROPERTY_CONST), |
845 | SD_BUS_PROPERTY("LogRateLimitBurst", "u", bus_property_get_unsigned, offsetof(ExecContext, log_ratelimit_burst), SD_BUS_VTABLE_PROPERTY_CONST), | |
d3070fbd | 846 | SD_BUS_PROPERTY("LogExtraFields", "aay", property_get_log_extra_fields, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
91dd5f7c | 847 | SD_BUS_PROPERTY("LogNamespace", "s", NULL, offsetof(ExecContext, log_namespace), SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc | 848 | SD_BUS_PROPERTY("SecureBits", "i", bus_property_get_int, offsetof(ExecContext, secure_bits), SD_BUS_VTABLE_PROPERTY_CONST), |
c0159e20 YW |
849 | SD_BUS_PROPERTY("CapabilityBoundingSet", "t", NULL, offsetof(ExecContext, capability_bounding_set), SD_BUS_VTABLE_PROPERTY_CONST), |
850 | SD_BUS_PROPERTY("AmbientCapabilities", "t", NULL, offsetof(ExecContext, capability_ambient_set), SD_BUS_VTABLE_PROPERTY_CONST), | |
556089dc LP |
851 | SD_BUS_PROPERTY("User", "s", NULL, offsetof(ExecContext, user), SD_BUS_VTABLE_PROPERTY_CONST), |
852 | SD_BUS_PROPERTY("Group", "s", NULL, offsetof(ExecContext, group), SD_BUS_VTABLE_PROPERTY_CONST), | |
29206d46 | 853 | SD_BUS_PROPERTY("DynamicUser", "b", bus_property_get_bool, offsetof(ExecContext, dynamic_user), SD_BUS_VTABLE_PROPERTY_CONST), |
00d9ef85 | 854 | SD_BUS_PROPERTY("RemoveIPC", "b", bus_property_get_bool, offsetof(ExecContext, remove_ipc), SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc | 855 | SD_BUS_PROPERTY("SupplementaryGroups", "as", NULL, offsetof(ExecContext, supplementary_groups), SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc | 856 | SD_BUS_PROPERTY("PAMName", "s", NULL, offsetof(ExecContext, pam_name), SD_BUS_VTABLE_PROPERTY_CONST), |
2a624c36 AP |
857 | SD_BUS_PROPERTY("ReadWritePaths", "as", NULL, offsetof(ExecContext, read_write_paths), SD_BUS_VTABLE_PROPERTY_CONST), |
858 | SD_BUS_PROPERTY("ReadOnlyPaths", "as", NULL, offsetof(ExecContext, read_only_paths), SD_BUS_VTABLE_PROPERTY_CONST), | |
859 | SD_BUS_PROPERTY("InaccessiblePaths", "as", NULL, offsetof(ExecContext, inaccessible_paths), SD_BUS_VTABLE_PROPERTY_CONST), | |
556089dc LP |
860 | SD_BUS_PROPERTY("MountFlags", "t", bus_property_get_ulong, offsetof(ExecContext, mount_flags), SD_BUS_VTABLE_PROPERTY_CONST), |
861 | SD_BUS_PROPERTY("PrivateTmp", "b", bus_property_get_bool, offsetof(ExecContext, private_tmp), SD_BUS_VTABLE_PROPERTY_CONST), | |
7f112f50 | 862 | SD_BUS_PROPERTY("PrivateDevices", "b", bus_property_get_bool, offsetof(ExecContext, private_devices), SD_BUS_VTABLE_PROPERTY_CONST), |
b8b7b838 | 863 | SD_BUS_PROPERTY("ProtectClock", "b", bus_property_get_bool, offsetof(ExecContext, protect_clock), SD_BUS_VTABLE_PROPERTY_CONST), |
59eeb84b | 864 | SD_BUS_PROPERTY("ProtectKernelTunables", "b", bus_property_get_bool, offsetof(ExecContext, protect_kernel_tunables), SD_BUS_VTABLE_PROPERTY_CONST), |
502d704e | 865 | SD_BUS_PROPERTY("ProtectKernelModules", "b", bus_property_get_bool, offsetof(ExecContext, protect_kernel_modules), SD_BUS_VTABLE_PROPERTY_CONST), |
84703040 | 866 | SD_BUS_PROPERTY("ProtectKernelLogs", "b", bus_property_get_bool, offsetof(ExecContext, protect_kernel_logs), SD_BUS_VTABLE_PROPERTY_CONST), |
59eeb84b | 867 | SD_BUS_PROPERTY("ProtectControlGroups", "b", bus_property_get_bool, offsetof(ExecContext, protect_control_groups), SD_BUS_VTABLE_PROPERTY_CONST), |
d251207d LP |
868 | SD_BUS_PROPERTY("PrivateNetwork", "b", bus_property_get_bool, offsetof(ExecContext, private_network), SD_BUS_VTABLE_PROPERTY_CONST), |
869 | SD_BUS_PROPERTY("PrivateUsers", "b", bus_property_get_bool, offsetof(ExecContext, private_users), SD_BUS_VTABLE_PROPERTY_CONST), | |
228af36f | 870 | SD_BUS_PROPERTY("PrivateMounts", "b", bus_property_get_bool, offsetof(ExecContext, private_mounts), SD_BUS_VTABLE_PROPERTY_CONST), |
73b84e92 YW |
871 | SD_BUS_PROPERTY("ProtectHome", "s", property_get_protect_home, offsetof(ExecContext, protect_home), SD_BUS_VTABLE_PROPERTY_CONST), |
872 | SD_BUS_PROPERTY("ProtectSystem", "s", property_get_protect_system, offsetof(ExecContext, protect_system), SD_BUS_VTABLE_PROPERTY_CONST), | |
556089dc LP |
873 | SD_BUS_PROPERTY("SameProcessGroup", "b", bus_property_get_bool, offsetof(ExecContext, same_pgrp), SD_BUS_VTABLE_PROPERTY_CONST), |
874 | SD_BUS_PROPERTY("UtmpIdentifier", "s", NULL, offsetof(ExecContext, utmp_id), SD_BUS_VTABLE_PROPERTY_CONST), | |
023a4f67 | 875 | SD_BUS_PROPERTY("UtmpMode", "s", property_get_exec_utmp_mode, offsetof(ExecContext, utmp_mode), SD_BUS_VTABLE_PROPERTY_CONST), |
5f8640fb | 876 | SD_BUS_PROPERTY("SELinuxContext", "(bs)", property_get_selinux_context, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
eef65bf3 | 877 | SD_BUS_PROPERTY("AppArmorProfile", "(bs)", property_get_apparmor_profile, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
2ca620c4 | 878 | SD_BUS_PROPERTY("SmackProcessLabel", "(bs)", property_get_smack_process_label, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc LP |
879 | SD_BUS_PROPERTY("IgnoreSIGPIPE", "b", bus_property_get_bool, offsetof(ExecContext, ignore_sigpipe), SD_BUS_VTABLE_PROPERTY_CONST), |
880 | SD_BUS_PROPERTY("NoNewPrivileges", "b", bus_property_get_bool, offsetof(ExecContext, no_new_privileges), SD_BUS_VTABLE_PROPERTY_CONST), | |
57183d11 LP |
881 | SD_BUS_PROPERTY("SystemCallFilter", "(bas)", property_get_syscall_filter, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
882 | SD_BUS_PROPERTY("SystemCallArchitectures", "as", property_get_syscall_archs, 0, SD_BUS_VTABLE_PROPERTY_CONST), | |
cf9d43a8 | 883 | SD_BUS_PROPERTY("SystemCallErrorNumber", "i", bus_property_get_int, offsetof(ExecContext, syscall_errno), SD_BUS_VTABLE_PROPERTY_CONST), |
491eecb3 | 884 | SD_BUS_PROPERTY("Personality", "s", property_get_personality, offsetof(ExecContext, personality), SD_BUS_VTABLE_PROPERTY_CONST), |
78e864e5 | 885 | SD_BUS_PROPERTY("LockPersonality", "b", bus_property_get_bool, offsetof(ExecContext, lock_personality), SD_BUS_VTABLE_PROPERTY_CONST), |
4298d0b5 | 886 | SD_BUS_PROPERTY("RestrictAddressFamilies", "(bas)", property_get_address_families, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
53f47dfc | 887 | SD_BUS_PROPERTY("RuntimeDirectoryPreserve", "s", property_get_exec_preserve_mode, offsetof(ExecContext, runtime_directory_preserve_mode), SD_BUS_VTABLE_PROPERTY_CONST), |
3536f49e YW |
888 | SD_BUS_PROPERTY("RuntimeDirectoryMode", "u", bus_property_get_mode, offsetof(ExecContext, directories[EXEC_DIRECTORY_RUNTIME].mode), SD_BUS_VTABLE_PROPERTY_CONST), |
889 | SD_BUS_PROPERTY("RuntimeDirectory", "as", NULL, offsetof(ExecContext, directories[EXEC_DIRECTORY_RUNTIME].paths), SD_BUS_VTABLE_PROPERTY_CONST), | |
e940c1ef YW |
890 | SD_BUS_PROPERTY("StateDirectoryMode", "u", bus_property_get_mode, offsetof(ExecContext, directories[EXEC_DIRECTORY_STATE].mode), SD_BUS_VTABLE_PROPERTY_CONST), |
891 | SD_BUS_PROPERTY("StateDirectory", "as", NULL, offsetof(ExecContext, directories[EXEC_DIRECTORY_STATE].paths), SD_BUS_VTABLE_PROPERTY_CONST), | |
3536f49e YW |
892 | SD_BUS_PROPERTY("CacheDirectoryMode", "u", bus_property_get_mode, offsetof(ExecContext, directories[EXEC_DIRECTORY_CACHE].mode), SD_BUS_VTABLE_PROPERTY_CONST), |
893 | SD_BUS_PROPERTY("CacheDirectory", "as", NULL, offsetof(ExecContext, directories[EXEC_DIRECTORY_CACHE].paths), SD_BUS_VTABLE_PROPERTY_CONST), | |
894 | SD_BUS_PROPERTY("LogsDirectoryMode", "u", bus_property_get_mode, offsetof(ExecContext, directories[EXEC_DIRECTORY_LOGS].mode), SD_BUS_VTABLE_PROPERTY_CONST), | |
895 | SD_BUS_PROPERTY("LogsDirectory", "as", NULL, offsetof(ExecContext, directories[EXEC_DIRECTORY_LOGS].paths), SD_BUS_VTABLE_PROPERTY_CONST), | |
896 | SD_BUS_PROPERTY("ConfigurationDirectoryMode", "u", bus_property_get_mode, offsetof(ExecContext, directories[EXEC_DIRECTORY_CONFIGURATION].mode), SD_BUS_VTABLE_PROPERTY_CONST), | |
897 | SD_BUS_PROPERTY("ConfigurationDirectory", "as", NULL, offsetof(ExecContext, directories[EXEC_DIRECTORY_CONFIGURATION].paths), SD_BUS_VTABLE_PROPERTY_CONST), | |
12213aed | 898 | SD_BUS_PROPERTY("TimeoutCleanUSec", "t", bus_property_get_usec, offsetof(ExecContext, timeout_clean_usec), SD_BUS_VTABLE_PROPERTY_CONST), |
f3e43635 | 899 | SD_BUS_PROPERTY("MemoryDenyWriteExecute", "b", bus_property_get_bool, offsetof(ExecContext, memory_deny_write_execute), SD_BUS_VTABLE_PROPERTY_CONST), |
f4170c67 | 900 | SD_BUS_PROPERTY("RestrictRealtime", "b", bus_property_get_bool, offsetof(ExecContext, restrict_realtime), SD_BUS_VTABLE_PROPERTY_CONST), |
f69567cb | 901 | SD_BUS_PROPERTY("RestrictSUIDSGID", "b", bus_property_get_bool, offsetof(ExecContext, restrict_suid_sgid), SD_BUS_VTABLE_PROPERTY_CONST), |
6a8c2d59 | 902 | SD_BUS_PROPERTY("RestrictNamespaces", "t", bus_property_get_ulong, offsetof(ExecContext, restrict_namespaces), SD_BUS_VTABLE_PROPERTY_CONST), |
d2d6c096 LP |
903 | SD_BUS_PROPERTY("BindPaths", "a(ssbt)", property_get_bind_paths, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
904 | SD_BUS_PROPERTY("BindReadOnlyPaths", "a(ssbt)", property_get_bind_paths, 0, SD_BUS_VTABLE_PROPERTY_CONST), | |
784ad252 | 905 | SD_BUS_PROPERTY("TemporaryFileSystem", "a(ss)", property_get_temporary_filesystems, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
5d997827 | 906 | SD_BUS_PROPERTY("MountAPIVFS", "b", bus_property_get_bool, offsetof(ExecContext, mount_apivfs), SD_BUS_VTABLE_PROPERTY_CONST), |
b1edf445 | 907 | SD_BUS_PROPERTY("KeyringMode", "s", property_get_exec_keyring_mode, offsetof(ExecContext, keyring_mode), SD_BUS_VTABLE_PROPERTY_CONST), |
aecd5ac6 | 908 | SD_BUS_PROPERTY("ProtectHostname", "b", bus_property_get_bool, offsetof(ExecContext, protect_hostname), SD_BUS_VTABLE_PROPERTY_CONST), |
a8d08f39 | 909 | SD_BUS_PROPERTY("NetworkNamespacePath", "s", NULL, offsetof(ExecContext, network_namespace_path), SD_BUS_VTABLE_PROPERTY_CONST), |
7f452159 LP |
910 | |
911 | /* Obsolete/redundant properties: */ | |
912 | SD_BUS_PROPERTY("Capabilities", "s", property_get_empty_string, 0, SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN), | |
913 | SD_BUS_PROPERTY("ReadWriteDirectories", "as", NULL, offsetof(ExecContext, read_write_paths), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN), | |
914 | SD_BUS_PROPERTY("ReadOnlyDirectories", "as", NULL, offsetof(ExecContext, read_only_paths), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN), | |
915 | SD_BUS_PROPERTY("InaccessibleDirectories", "as", NULL, offsetof(ExecContext, inaccessible_paths), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN), | |
916 | SD_BUS_PROPERTY("IOScheduling", "i", property_get_ioprio, 0, SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN), | |
917 | ||
718db961 LP |
918 | SD_BUS_VTABLE_END |
919 | }; | |
82c121a4 | 920 | |
4d4c80d0 LP |
921 | static int append_exec_command(sd_bus_message *reply, ExecCommand *c) { |
922 | int r; | |
923 | ||
924 | assert(reply); | |
925 | assert(c); | |
926 | ||
927 | if (!c->path) | |
928 | return 0; | |
929 | ||
930 | r = sd_bus_message_open_container(reply, 'r', "sasbttttuii"); | |
931 | if (r < 0) | |
932 | return r; | |
933 | ||
934 | r = sd_bus_message_append(reply, "s", c->path); | |
935 | if (r < 0) | |
936 | return r; | |
937 | ||
938 | r = sd_bus_message_append_strv(reply, c->argv); | |
939 | if (r < 0) | |
940 | return r; | |
941 | ||
942 | r = sd_bus_message_append(reply, "bttttuii", | |
3ed0cd26 | 943 | !!(c->flags & EXEC_COMMAND_IGNORE_FAILURE), |
4d4c80d0 LP |
944 | c->exec_status.start_timestamp.realtime, |
945 | c->exec_status.start_timestamp.monotonic, | |
946 | c->exec_status.exit_timestamp.realtime, | |
947 | c->exec_status.exit_timestamp.monotonic, | |
948 | (uint32_t) c->exec_status.pid, | |
949 | (int32_t) c->exec_status.code, | |
950 | (int32_t) c->exec_status.status); | |
951 | if (r < 0) | |
952 | return r; | |
953 | ||
954 | return sd_bus_message_close_container(reply); | |
955 | } | |
956 | ||
b3d59367 AZ |
957 | static int append_exec_ex_command(sd_bus_message *reply, ExecCommand *c) { |
958 | _cleanup_strv_free_ char **ex_opts = NULL; | |
959 | int r; | |
960 | ||
961 | assert(reply); | |
962 | assert(c); | |
963 | ||
964 | if (!c->path) | |
965 | return 0; | |
966 | ||
967 | r = sd_bus_message_open_container(reply, 'r', "sasasttttuii"); | |
968 | if (r < 0) | |
969 | return r; | |
970 | ||
971 | r = sd_bus_message_append(reply, "s", c->path); | |
972 | if (r < 0) | |
973 | return r; | |
974 | ||
975 | r = sd_bus_message_append_strv(reply, c->argv); | |
976 | if (r < 0) | |
977 | return r; | |
978 | ||
979 | r = exec_command_flags_to_strv(c->flags, &ex_opts); | |
980 | if (r < 0) | |
981 | return r; | |
982 | ||
983 | r = sd_bus_message_append_strv(reply, ex_opts); | |
984 | if (r < 0) | |
985 | return r; | |
986 | ||
987 | r = sd_bus_message_append(reply, "ttttuii", | |
988 | c->exec_status.start_timestamp.realtime, | |
989 | c->exec_status.start_timestamp.monotonic, | |
990 | c->exec_status.exit_timestamp.realtime, | |
991 | c->exec_status.exit_timestamp.monotonic, | |
992 | (uint32_t) c->exec_status.pid, | |
993 | (int32_t) c->exec_status.code, | |
994 | (int32_t) c->exec_status.status); | |
995 | if (r < 0) | |
996 | return r; | |
997 | ||
998 | return sd_bus_message_close_container(reply); | |
999 | } | |
1000 | ||
718db961 LP |
1001 | int bus_property_get_exec_command( |
1002 | sd_bus *bus, | |
1003 | const char *path, | |
1004 | const char *interface, | |
1005 | const char *property, | |
1006 | sd_bus_message *reply, | |
ebcf1f97 LP |
1007 | void *userdata, |
1008 | sd_bus_error *ret_error) { | |
fe68089d | 1009 | |
4d4c80d0 | 1010 | ExecCommand *c = (ExecCommand*) userdata; |
718db961 | 1011 | int r; |
fe68089d | 1012 | |
718db961 LP |
1013 | assert(bus); |
1014 | assert(reply); | |
fe68089d | 1015 | |
718db961 LP |
1016 | r = sd_bus_message_open_container(reply, 'a', "(sasbttttuii)"); |
1017 | if (r < 0) | |
1018 | return r; | |
fe68089d | 1019 | |
4d4c80d0 LP |
1020 | r = append_exec_command(reply, c); |
1021 | if (r < 0) | |
1022 | return r; | |
fe68089d | 1023 | |
4d4c80d0 LP |
1024 | return sd_bus_message_close_container(reply); |
1025 | } | |
718db961 | 1026 | |
4d4c80d0 LP |
1027 | int bus_property_get_exec_command_list( |
1028 | sd_bus *bus, | |
1029 | const char *path, | |
1030 | const char *interface, | |
1031 | const char *property, | |
1032 | sd_bus_message *reply, | |
1033 | void *userdata, | |
1034 | sd_bus_error *ret_error) { | |
718db961 | 1035 | |
4d4c80d0 LP |
1036 | ExecCommand *c = *(ExecCommand**) userdata; |
1037 | int r; | |
718db961 | 1038 | |
4d4c80d0 LP |
1039 | assert(bus); |
1040 | assert(reply); | |
1041 | ||
1042 | r = sd_bus_message_open_container(reply, 'a', "(sasbttttuii)"); | |
1043 | if (r < 0) | |
1044 | return r; | |
718db961 | 1045 | |
4d4c80d0 LP |
1046 | LIST_FOREACH(command, c, c) { |
1047 | r = append_exec_command(reply, c); | |
718db961 LP |
1048 | if (r < 0) |
1049 | return r; | |
fe68089d LP |
1050 | } |
1051 | ||
718db961 | 1052 | return sd_bus_message_close_container(reply); |
8351ceae | 1053 | } |
c7040b5d | 1054 | |
b3d59367 AZ |
1055 | int bus_property_get_exec_ex_command_list( |
1056 | sd_bus *bus, | |
1057 | const char *path, | |
1058 | const char *interface, | |
1059 | const char *property, | |
1060 | sd_bus_message *reply, | |
1061 | void *userdata, | |
1062 | sd_bus_error *ret_error) { | |
1063 | ||
1064 | ExecCommand *c, *exec_command = *(ExecCommand**) userdata; | |
1065 | int r; | |
1066 | ||
1067 | assert(bus); | |
1068 | assert(reply); | |
1069 | ||
1070 | r = sd_bus_message_open_container(reply, 'a', "(sasasttttuii)"); | |
1071 | if (r < 0) | |
1072 | return r; | |
1073 | ||
1074 | LIST_FOREACH(command, c, exec_command) { | |
1075 | r = append_exec_ex_command(reply, c); | |
1076 | if (r < 0) | |
1077 | return r; | |
1078 | } | |
1079 | ||
1080 | return sd_bus_message_close_container(reply); | |
1081 | } | |
1082 | ||
1083 | static char *exec_command_flags_to_exec_chars(ExecCommandFlags flags) { | |
a4fc96c8 ZJS |
1084 | return strjoin(FLAGS_SET(flags, EXEC_COMMAND_IGNORE_FAILURE) ? "-" : "", |
1085 | FLAGS_SET(flags, EXEC_COMMAND_NO_ENV_EXPAND) ? ":" : "", | |
1086 | FLAGS_SET(flags, EXEC_COMMAND_FULLY_PRIVILEGED) ? "+" : "", | |
1087 | FLAGS_SET(flags, EXEC_COMMAND_NO_SETUID) ? "!" : "", | |
1088 | FLAGS_SET(flags, EXEC_COMMAND_AMBIENT_MAGIC) ? "!!" : ""); | |
b3d59367 AZ |
1089 | } |
1090 | ||
237f7bcb | 1091 | int bus_set_transient_exec_command( |
9c0320e7 YW |
1092 | Unit *u, |
1093 | const char *name, | |
1094 | ExecCommand **exec_command, | |
1095 | sd_bus_message *message, | |
1096 | UnitWriteFlags flags, | |
1097 | sd_bus_error *error) { | |
b3d59367 | 1098 | bool is_ex_prop = endswith(name, "Ex"); |
9c0320e7 YW |
1099 | unsigned n = 0; |
1100 | int r; | |
1101 | ||
b3d59367 | 1102 | r = sd_bus_message_enter_container(message, 'a', is_ex_prop ? "(sasas)" : "(sasb)"); |
9c0320e7 YW |
1103 | if (r < 0) |
1104 | return r; | |
1105 | ||
b3d59367 AZ |
1106 | while ((r = sd_bus_message_enter_container(message, 'r', is_ex_prop ? "sasas" : "sasb")) > 0) { |
1107 | _cleanup_strv_free_ char **argv = NULL, **ex_opts = NULL; | |
9c0320e7 YW |
1108 | const char *path; |
1109 | int b; | |
1110 | ||
1111 | r = sd_bus_message_read(message, "s", &path); | |
1112 | if (r < 0) | |
1113 | return r; | |
1114 | ||
1115 | if (!path_is_absolute(path)) | |
1116 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path %s is not absolute.", path); | |
1117 | ||
1118 | r = sd_bus_message_read_strv(message, &argv); | |
1119 | if (r < 0) | |
1120 | return r; | |
1121 | ||
b3d59367 | 1122 | r = is_ex_prop ? sd_bus_message_read_strv(message, &ex_opts) : sd_bus_message_read(message, "b", &b); |
9c0320e7 YW |
1123 | if (r < 0) |
1124 | return r; | |
1125 | ||
1126 | r = sd_bus_message_exit_container(message); | |
1127 | if (r < 0) | |
1128 | return r; | |
1129 | ||
1130 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
1131 | ExecCommand *c; | |
1132 | ||
1133 | c = new0(ExecCommand, 1); | |
1134 | if (!c) | |
1135 | return -ENOMEM; | |
1136 | ||
1137 | c->path = strdup(path); | |
1138 | if (!c->path) { | |
1139 | free(c); | |
1140 | return -ENOMEM; | |
1141 | } | |
1142 | ||
ae2a15bc | 1143 | c->argv = TAKE_PTR(argv); |
9c0320e7 | 1144 | |
b3d59367 AZ |
1145 | if (is_ex_prop) { |
1146 | r = exec_command_flags_from_strv(ex_opts, &c->flags); | |
1147 | if (r < 0) | |
1148 | return r; | |
1149 | } else | |
1150 | c->flags = b ? EXEC_COMMAND_IGNORE_FAILURE : 0; | |
9c0320e7 | 1151 | |
858d36c1 | 1152 | path_simplify(c->path, false); |
9c0320e7 YW |
1153 | exec_command_append_list(exec_command, c); |
1154 | } | |
1155 | ||
1156 | n++; | |
1157 | } | |
1158 | if (r < 0) | |
1159 | return r; | |
1160 | ||
1161 | r = sd_bus_message_exit_container(message); | |
1162 | if (r < 0) | |
1163 | return r; | |
1164 | ||
1165 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
1166 | _cleanup_free_ char *buf = NULL; | |
1167 | _cleanup_fclose_ FILE *f = NULL; | |
1168 | ExecCommand *c; | |
1169 | size_t size = 0; | |
1170 | ||
1171 | if (n == 0) | |
1172 | *exec_command = exec_command_free_list(*exec_command); | |
1173 | ||
2fe21124 | 1174 | f = open_memstream_unlocked(&buf, &size); |
9c0320e7 YW |
1175 | if (!f) |
1176 | return -ENOMEM; | |
1177 | ||
f14bf013 | 1178 | fprintf(f, "%s=\n", name); |
9c0320e7 YW |
1179 | |
1180 | LIST_FOREACH(command, c, *exec_command) { | |
540ac933 | 1181 | _cleanup_free_ char *a = NULL, *exec_chars = NULL; |
9c0320e7 | 1182 | |
540ac933 LP |
1183 | exec_chars = exec_command_flags_to_exec_chars(c->flags); |
1184 | if (!exec_chars) | |
9c0320e7 YW |
1185 | return -ENOMEM; |
1186 | ||
1187 | a = unit_concat_strv(c->argv, UNIT_ESCAPE_C|UNIT_ESCAPE_SPECIFIERS); | |
1188 | if (!a) | |
1189 | return -ENOMEM; | |
1190 | ||
540ac933 LP |
1191 | if (streq_ptr(c->path, c->argv ? c->argv[0] : NULL)) |
1192 | fprintf(f, "%s=%s%s\n", name, exec_chars, a); | |
1193 | else { | |
1194 | _cleanup_free_ char *t = NULL; | |
1195 | const char *p; | |
1196 | ||
1197 | p = unit_escape_setting(c->path, UNIT_ESCAPE_C|UNIT_ESCAPE_SPECIFIERS, &t); | |
1198 | if (!p) | |
1199 | return -ENOMEM; | |
b3d59367 | 1200 | |
540ac933 LP |
1201 | fprintf(f, "%s=%s@%s %s\n", name, exec_chars, p, a); |
1202 | } | |
9c0320e7 YW |
1203 | } |
1204 | ||
1205 | r = fflush_and_check(f); | |
1206 | if (r < 0) | |
1207 | return r; | |
1208 | ||
1209 | unit_write_setting(u, flags, name, buf); | |
1210 | } | |
1211 | ||
1212 | return 1; | |
1213 | } | |
1214 | ||
7e2a3fcc YW |
1215 | static int parse_personality(const char *s, unsigned long *p) { |
1216 | unsigned long v; | |
1217 | ||
1218 | assert(p); | |
1219 | ||
1220 | v = personality_from_string(s); | |
1221 | if (v == PERSONALITY_INVALID) | |
1222 | return -EINVAL; | |
1223 | ||
1224 | *p = v; | |
1225 | return 0; | |
1226 | } | |
1227 | ||
1228 | static const char* mount_propagation_flags_to_string_with_check(unsigned long n) { | |
1229 | if (!IN_SET(n, 0, MS_SHARED, MS_PRIVATE, MS_SLAVE)) | |
1230 | return NULL; | |
1231 | ||
1232 | return mount_propagation_flags_to_string(n); | |
1233 | } | |
1234 | ||
1235 | static BUS_DEFINE_SET_TRANSIENT(nsec, "t", uint64_t, nsec_t, NSEC_FMT); | |
1236 | static BUS_DEFINE_SET_TRANSIENT_IS_VALID(log_level, "i", int32_t, int, "%" PRIi32, log_level_is_valid); | |
aad67b80 | 1237 | #if HAVE_SECCOMP |
7e2a3fcc | 1238 | static BUS_DEFINE_SET_TRANSIENT_IS_VALID(errno, "i", int32_t, int, "%" PRIi32, errno_is_valid); |
aad67b80 | 1239 | #endif |
7e2a3fcc YW |
1240 | static BUS_DEFINE_SET_TRANSIENT_PARSE(std_input, ExecInput, exec_input_from_string); |
1241 | static BUS_DEFINE_SET_TRANSIENT_PARSE(std_output, ExecOutput, exec_output_from_string); | |
1242 | static BUS_DEFINE_SET_TRANSIENT_PARSE(utmp_mode, ExecUtmpMode, exec_utmp_mode_from_string); | |
1e8c7bd5 YW |
1243 | static BUS_DEFINE_SET_TRANSIENT_PARSE(protect_system, ProtectSystem, protect_system_from_string); |
1244 | static BUS_DEFINE_SET_TRANSIENT_PARSE(protect_home, ProtectHome, protect_home_from_string); | |
7e2a3fcc YW |
1245 | static BUS_DEFINE_SET_TRANSIENT_PARSE(keyring_mode, ExecKeyringMode, exec_keyring_mode_from_string); |
1246 | static BUS_DEFINE_SET_TRANSIENT_PARSE(preserve_mode, ExecPreserveMode, exec_preserve_mode_from_string); | |
1247 | static BUS_DEFINE_SET_TRANSIENT_PARSE_PTR(personality, unsigned long, parse_personality); | |
1248 | static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(secure_bits, "i", int32_t, int, "%" PRIi32, secure_bits_to_string_alloc_with_check); | |
1249 | static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(capability, "t", uint64_t, uint64_t, "%" PRIu64, capability_set_to_string_alloc); | |
86c2a9f1 | 1250 | static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(namespace_flag, "t", uint64_t, unsigned long, "%" PRIu64, namespace_flags_to_string); |
7e2a3fcc YW |
1251 | static BUS_DEFINE_SET_TRANSIENT_TO_STRING(mount_flags, "t", uint64_t, unsigned long, "%" PRIu64, mount_propagation_flags_to_string_with_check); |
1252 | ||
c7040b5d LP |
1253 | int bus_exec_context_set_transient_property( |
1254 | Unit *u, | |
1255 | ExecContext *c, | |
1256 | const char *name, | |
1257 | sd_bus_message *message, | |
2e59b241 | 1258 | UnitWriteFlags flags, |
c7040b5d LP |
1259 | sd_bus_error *error) { |
1260 | ||
6550c24c LP |
1261 | const char *suffix; |
1262 | int r; | |
c7040b5d LP |
1263 | |
1264 | assert(u); | |
1265 | assert(c); | |
1266 | assert(name); | |
1267 | assert(message); | |
1268 | ||
2e59b241 LP |
1269 | flags |= UNIT_PRIVATE; |
1270 | ||
7e2a3fcc | 1271 | if (streq(name, "User")) |
7a8867ab | 1272 | return bus_set_transient_user_relaxed(u, name, &c->user, message, flags, error); |
c7040b5d | 1273 | |
7e2a3fcc | 1274 | if (streq(name, "Group")) |
7a8867ab | 1275 | return bus_set_transient_user_relaxed(u, name, &c->group, message, flags, error); |
c7040b5d | 1276 | |
7e2a3fcc YW |
1277 | if (streq(name, "TTYPath")) |
1278 | return bus_set_transient_path(u, name, &c->tty_path, message, flags, error); | |
6f3e7985 | 1279 | |
7e2a3fcc YW |
1280 | if (streq(name, "RootImage")) |
1281 | return bus_set_transient_path(u, name, &c->root_image, message, flags, error); | |
76736280 | 1282 | |
0389f4fa LB |
1283 | if (streq(name, "RootHash")) { |
1284 | const void *roothash_decoded; | |
1285 | size_t roothash_decoded_size; | |
1286 | ||
1287 | r = sd_bus_message_read_array(message, 'y', &roothash_decoded, &roothash_decoded_size); | |
1288 | if (r < 0) | |
1289 | return r; | |
1290 | ||
1291 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
1292 | _cleanup_free_ char *encoded = NULL; | |
1293 | ||
1294 | if (roothash_decoded_size == 0) { | |
1295 | c->root_hash_path = mfree(c->root_hash_path); | |
1296 | c->root_hash = mfree(c->root_hash); | |
1297 | c->root_hash_size = 0; | |
1298 | ||
1299 | unit_write_settingf(u, flags, name, "RootHash="); | |
1300 | } else { | |
1301 | _cleanup_free_ void *p; | |
1302 | ||
1303 | encoded = hexmem(roothash_decoded, roothash_decoded_size); | |
1304 | if (!encoded) | |
1305 | return -ENOMEM; | |
1306 | ||
1307 | p = memdup(roothash_decoded, roothash_decoded_size); | |
1308 | if (!p) | |
1309 | return -ENOMEM; | |
1310 | ||
1311 | free_and_replace(c->root_hash, p); | |
1312 | c->root_hash_size = roothash_decoded_size; | |
1313 | c->root_hash_path = mfree(c->root_hash_path); | |
1314 | ||
1315 | unit_write_settingf(u, flags, name, "RootHash=%s", encoded); | |
1316 | } | |
1317 | } | |
1318 | ||
1319 | return 1; | |
1320 | } | |
1321 | ||
1322 | if (streq(name, "RootHashPath")) { | |
1323 | c->root_hash_size = 0; | |
1324 | c->root_hash = mfree(c->root_hash); | |
1325 | ||
1326 | return bus_set_transient_path(u, "RootHash", &c->root_hash_path, message, flags, error); | |
1327 | } | |
1328 | ||
1329 | if (streq(name, "RootVerity")) | |
1330 | return bus_set_transient_path(u, name, &c->root_verity, message, flags, error); | |
1331 | ||
7e2a3fcc YW |
1332 | if (streq(name, "RootDirectory")) |
1333 | return bus_set_transient_path(u, name, &c->root_directory, message, flags, error); | |
c7040b5d | 1334 | |
7e2a3fcc YW |
1335 | if (streq(name, "SyslogIdentifier")) |
1336 | return bus_set_transient_string(u, name, &c->syslog_identifier, message, flags, error); | |
c7040b5d | 1337 | |
7e2a3fcc YW |
1338 | if (streq(name, "LogLevelMax")) |
1339 | return bus_set_transient_log_level(u, name, &c->log_level_max, message, flags, error); | |
1340 | ||
90fc172e | 1341 | if (streq(name, "LogRateLimitIntervalUSec")) |
5ac1530e | 1342 | return bus_set_transient_usec(u, name, &c->log_ratelimit_interval_usec, message, flags, error); |
90fc172e AZ |
1343 | |
1344 | if (streq(name, "LogRateLimitBurst")) | |
5ac1530e | 1345 | return bus_set_transient_unsigned(u, name, &c->log_ratelimit_burst, message, flags, error); |
90fc172e | 1346 | |
7e2a3fcc YW |
1347 | if (streq(name, "Personality")) |
1348 | return bus_set_transient_personality(u, name, &c->personality, message, flags, error); | |
1349 | ||
7e2a3fcc YW |
1350 | if (streq(name, "StandardInput")) |
1351 | return bus_set_transient_std_input(u, name, &c->std_input, message, flags, error); | |
1352 | ||
1353 | if (streq(name, "StandardOutput")) | |
1354 | return bus_set_transient_std_output(u, name, &c->std_output, message, flags, error); | |
1355 | ||
1356 | if (streq(name, "StandardError")) | |
1357 | return bus_set_transient_std_output(u, name, &c->std_error, message, flags, error); | |
1358 | ||
1359 | if (streq(name, "IgnoreSIGPIPE")) | |
1360 | return bus_set_transient_bool(u, name, &c->ignore_sigpipe, message, flags, error); | |
1361 | ||
1362 | if (streq(name, "TTYVHangup")) | |
1363 | return bus_set_transient_bool(u, name, &c->tty_vhangup, message, flags, error); | |
1364 | ||
1365 | if (streq(name, "TTYReset")) | |
1366 | return bus_set_transient_bool(u, name, &c->tty_reset, message, flags, error); | |
1367 | ||
1368 | if (streq(name, "TTYVTDisallocate")) | |
1369 | return bus_set_transient_bool(u, name, &c->tty_vt_disallocate, message, flags, error); | |
1370 | ||
1371 | if (streq(name, "PrivateTmp")) | |
1372 | return bus_set_transient_bool(u, name, &c->private_tmp, message, flags, error); | |
1373 | ||
1374 | if (streq(name, "PrivateDevices")) | |
1375 | return bus_set_transient_bool(u, name, &c->private_devices, message, flags, error); | |
1376 | ||
228af36f LP |
1377 | if (streq(name, "PrivateMounts")) |
1378 | return bus_set_transient_bool(u, name, &c->private_mounts, message, flags, error); | |
1379 | ||
7e2a3fcc YW |
1380 | if (streq(name, "PrivateNetwork")) |
1381 | return bus_set_transient_bool(u, name, &c->private_network, message, flags, error); | |
1382 | ||
1383 | if (streq(name, "PrivateUsers")) | |
1384 | return bus_set_transient_bool(u, name, &c->private_users, message, flags, error); | |
1385 | ||
1386 | if (streq(name, "NoNewPrivileges")) | |
1387 | return bus_set_transient_bool(u, name, &c->no_new_privileges, message, flags, error); | |
1388 | ||
1389 | if (streq(name, "SyslogLevelPrefix")) | |
1390 | return bus_set_transient_bool(u, name, &c->syslog_level_prefix, message, flags, error); | |
1391 | ||
1392 | if (streq(name, "MemoryDenyWriteExecute")) | |
1393 | return bus_set_transient_bool(u, name, &c->memory_deny_write_execute, message, flags, error); | |
1394 | ||
1395 | if (streq(name, "RestrictRealtime")) | |
1396 | return bus_set_transient_bool(u, name, &c->restrict_realtime, message, flags, error); | |
1397 | ||
f69567cb LP |
1398 | if (streq(name, "RestrictSUIDSGID")) |
1399 | return bus_set_transient_bool(u, name, &c->restrict_suid_sgid, message, flags, error); | |
1400 | ||
7e2a3fcc YW |
1401 | if (streq(name, "DynamicUser")) |
1402 | return bus_set_transient_bool(u, name, &c->dynamic_user, message, flags, error); | |
1403 | ||
1404 | if (streq(name, "RemoveIPC")) | |
1405 | return bus_set_transient_bool(u, name, &c->remove_ipc, message, flags, error); | |
1406 | ||
1407 | if (streq(name, "ProtectKernelTunables")) | |
1408 | return bus_set_transient_bool(u, name, &c->protect_kernel_tunables, message, flags, error); | |
1409 | ||
1410 | if (streq(name, "ProtectKernelModules")) | |
1411 | return bus_set_transient_bool(u, name, &c->protect_kernel_modules, message, flags, error); | |
1412 | ||
84703040 KK |
1413 | if (streq(name, "ProtectKernelLogs")) |
1414 | return bus_set_transient_bool(u, name, &c->protect_kernel_logs, message, flags, error); | |
1415 | ||
fc64760d KK |
1416 | if (streq(name, "ProtectClock")) |
1417 | return bus_set_transient_bool(u, name, &c->protect_clock, message, flags, error); | |
1418 | ||
7e2a3fcc YW |
1419 | if (streq(name, "ProtectControlGroups")) |
1420 | return bus_set_transient_bool(u, name, &c->protect_control_groups, message, flags, error); | |
1421 | ||
1422 | if (streq(name, "MountAPIVFS")) | |
1423 | return bus_set_transient_bool(u, name, &c->mount_apivfs, message, flags, error); | |
1424 | ||
1425 | if (streq(name, "CPUSchedulingResetOnFork")) | |
1426 | return bus_set_transient_bool(u, name, &c->cpu_sched_reset_on_fork, message, flags, error); | |
1427 | ||
1428 | if (streq(name, "NonBlocking")) | |
1429 | return bus_set_transient_bool(u, name, &c->non_blocking, message, flags, error); | |
1430 | ||
1431 | if (streq(name, "LockPersonality")) | |
1432 | return bus_set_transient_bool(u, name, &c->lock_personality, message, flags, error); | |
1433 | ||
aecd5ac6 TM |
1434 | if (streq(name, "ProtectHostname")) |
1435 | return bus_set_transient_bool(u, name, &c->protect_hostname, message, flags, error); | |
1436 | ||
7e2a3fcc YW |
1437 | if (streq(name, "UtmpIdentifier")) |
1438 | return bus_set_transient_string(u, name, &c->utmp_id, message, flags, error); | |
1439 | ||
1440 | if (streq(name, "UtmpMode")) | |
1441 | return bus_set_transient_utmp_mode(u, name, &c->utmp_mode, message, flags, error); | |
1442 | ||
1443 | if (streq(name, "PAMName")) | |
1444 | return bus_set_transient_string(u, name, &c->pam_name, message, flags, error); | |
1445 | ||
1446 | if (streq(name, "TimerSlackNSec")) | |
1447 | return bus_set_transient_nsec(u, name, &c->timer_slack_nsec, message, flags, error); | |
1448 | ||
1449 | if (streq(name, "ProtectSystem")) | |
1450 | return bus_set_transient_protect_system(u, name, &c->protect_system, message, flags, error); | |
1451 | ||
1452 | if (streq(name, "ProtectHome")) | |
1453 | return bus_set_transient_protect_home(u, name, &c->protect_home, message, flags, error); | |
cffaed83 | 1454 | |
7e2a3fcc YW |
1455 | if (streq(name, "KeyringMode")) |
1456 | return bus_set_transient_keyring_mode(u, name, &c->keyring_mode, message, flags, error); | |
1457 | ||
1458 | if (streq(name, "RuntimeDirectoryPreserve")) | |
1459 | return bus_set_transient_preserve_mode(u, name, &c->runtime_directory_preserve_mode, message, flags, error); | |
1460 | ||
1461 | if (streq(name, "UMask")) | |
1462 | return bus_set_transient_mode_t(u, name, &c->umask, message, flags, error); | |
1463 | ||
1464 | if (streq(name, "RuntimeDirectoryMode")) | |
1465 | return bus_set_transient_mode_t(u, name, &c->directories[EXEC_DIRECTORY_RUNTIME].mode, message, flags, error); | |
1466 | ||
1467 | if (streq(name, "StateDirectoryMode")) | |
1468 | return bus_set_transient_mode_t(u, name, &c->directories[EXEC_DIRECTORY_STATE].mode, message, flags, error); | |
1469 | ||
1470 | if (streq(name, "CacheDirectoryMode")) | |
1471 | return bus_set_transient_mode_t(u, name, &c->directories[EXEC_DIRECTORY_CACHE].mode, message, flags, error); | |
1472 | ||
1473 | if (streq(name, "LogsDirectoryMode")) | |
1474 | return bus_set_transient_mode_t(u, name, &c->directories[EXEC_DIRECTORY_LOGS].mode, message, flags, error); | |
1475 | ||
1476 | if (streq(name, "ConfigurationDirectoryMode")) | |
1477 | return bus_set_transient_mode_t(u, name, &c->directories[EXEC_DIRECTORY_CONFIGURATION].mode, message, flags, error); | |
1478 | ||
1479 | if (streq(name, "SELinuxContext")) | |
1480 | return bus_set_transient_string(u, name, &c->selinux_context, message, flags, error); | |
1481 | ||
1482 | if (streq(name, "SecureBits")) | |
1483 | return bus_set_transient_secure_bits(u, name, &c->secure_bits, message, flags, error); | |
1484 | ||
1485 | if (streq(name, "CapabilityBoundingSet")) | |
1486 | return bus_set_transient_capability(u, name, &c->capability_bounding_set, message, flags, error); | |
1487 | ||
1488 | if (streq(name, "AmbientCapabilities")) | |
1489 | return bus_set_transient_capability(u, name, &c->capability_ambient_set, message, flags, error); | |
1490 | ||
7e2a3fcc YW |
1491 | if (streq(name, "RestrictNamespaces")) |
1492 | return bus_set_transient_namespace_flag(u, name, &c->restrict_namespaces, message, flags, error); | |
1493 | ||
1494 | if (streq(name, "MountFlags")) | |
1495 | return bus_set_transient_mount_flags(u, name, &c->mount_flags, message, flags, error); | |
1496 | ||
a8d08f39 LP |
1497 | if (streq(name, "NetworkNamespacePath")) |
1498 | return bus_set_transient_path(u, name, &c->network_namespace_path, message, flags, error); | |
1499 | ||
7e2a3fcc | 1500 | if (streq(name, "SupplementaryGroups")) { |
cffaed83 YW |
1501 | _cleanup_strv_free_ char **l = NULL; |
1502 | char **p; | |
1503 | ||
1504 | r = sd_bus_message_read_strv(message, &l); | |
1505 | if (r < 0) | |
1506 | return r; | |
1507 | ||
d2a23692 | 1508 | STRV_FOREACH(p, l) |
7a8867ab | 1509 | if (!isempty(*p) && !valid_user_group_name(*p, VALID_USER_ALLOW_NUMERIC|VALID_USER_RELAX|VALID_USER_WARN)) |
d2a23692 ZJS |
1510 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, |
1511 | "Invalid supplementary group names"); | |
cffaed83 | 1512 | |
2e59b241 | 1513 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
7b943bb7 | 1514 | if (strv_isempty(l)) { |
cffaed83 | 1515 | c->supplementary_groups = strv_free(c->supplementary_groups); |
2e59b241 | 1516 | unit_write_settingf(u, flags, name, "%s=", name); |
cffaed83 YW |
1517 | } else { |
1518 | _cleanup_free_ char *joined = NULL; | |
1519 | ||
1520 | r = strv_extend_strv(&c->supplementary_groups, l, true); | |
1521 | if (r < 0) | |
1522 | return -ENOMEM; | |
1523 | ||
1524 | joined = strv_join(c->supplementary_groups, " "); | |
1525 | if (!joined) | |
1526 | return -ENOMEM; | |
1527 | ||
2e59b241 | 1528 | unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "%s=%s", name, joined); |
cffaed83 YW |
1529 | } |
1530 | } | |
1531 | ||
1532 | return 1; | |
1533 | ||
a8a13575 | 1534 | } else if (streq(name, "SyslogLevel")) { |
8d1dd6ab | 1535 | int32_t level; |
a8a13575 EV |
1536 | |
1537 | r = sd_bus_message_read(message, "i", &level); | |
1538 | if (r < 0) | |
1539 | return r; | |
1540 | ||
e0d6e0fa EV |
1541 | if (!log_level_is_valid(level)) |
1542 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Log level value out of range"); | |
1543 | ||
2e59b241 | 1544 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
a8a13575 | 1545 | c->syslog_priority = (c->syslog_priority & LOG_FACMASK) | level; |
2e59b241 | 1546 | unit_write_settingf(u, flags, name, "SyslogLevel=%i", level); |
a8a13575 EV |
1547 | } |
1548 | ||
460ed929 | 1549 | return 1; |
7e2a3fcc | 1550 | |
460ed929 | 1551 | } else if (streq(name, "SyslogFacility")) { |
8d1dd6ab | 1552 | int32_t facility; |
460ed929 EV |
1553 | |
1554 | r = sd_bus_message_read(message, "i", &facility); | |
1555 | if (r < 0) | |
1556 | return r; | |
1557 | ||
e0d6e0fa EV |
1558 | if (!log_facility_unshifted_is_valid(facility)) |
1559 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Log facility value out of range"); | |
1560 | ||
2e59b241 | 1561 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
460ed929 | 1562 | c->syslog_priority = (facility << 3) | LOG_PRI(c->syslog_priority); |
2e59b241 | 1563 | unit_write_settingf(u, flags, name, "SyslogFacility=%i", facility); |
460ed929 EV |
1564 | } |
1565 | ||
cffaed83 | 1566 | return 1; |
d3070fbd | 1567 | |
91dd5f7c LP |
1568 | } else if (streq(name, "LogNamespace")) { |
1569 | const char *n; | |
1570 | ||
1571 | r = sd_bus_message_read(message, "s", &n); | |
1572 | if (r < 0) | |
1573 | return r; | |
1574 | ||
1575 | if (!isempty(n) && !log_namespace_name_valid(n)) | |
1576 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Log namespace name not valid"); | |
1577 | ||
1578 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
1579 | ||
1580 | if (isempty(n)) { | |
1581 | c->log_namespace = mfree(c->log_namespace); | |
1582 | unit_write_settingf(u, flags, name, "%s=", name); | |
1583 | } else { | |
1584 | r = free_and_strdup(&c->log_namespace, n); | |
1585 | if (r < 0) | |
1586 | return r; | |
1587 | ||
1588 | unit_write_settingf(u, flags, name, "%s=%s", name, n); | |
1589 | } | |
1590 | } | |
1591 | ||
1592 | return 1; | |
1593 | ||
d3070fbd LP |
1594 | } else if (streq(name, "LogExtraFields")) { |
1595 | size_t n = 0; | |
1596 | ||
1597 | r = sd_bus_message_enter_container(message, 'a', "ay"); | |
1598 | if (r < 0) | |
1599 | return r; | |
1600 | ||
1601 | for (;;) { | |
1602 | _cleanup_free_ void *copy = NULL; | |
1603 | struct iovec *t; | |
1604 | const char *eq; | |
1605 | const void *p; | |
1606 | size_t sz; | |
1607 | ||
1608 | /* Note that we expect a byte array for each field, instead of a string. That's because on the | |
1609 | * lower-level journal fields can actually contain binary data and are not restricted to text, | |
1610 | * and we should not "lose precision" in our types on the way. That said, I am pretty sure | |
1611 | * actually encoding binary data as unit metadata is not a good idea. Hence we actually refuse | |
1612 | * any actual binary data, and only accept UTF-8. This allows us to eventually lift this | |
1613 | * limitation, should a good, valid usecase arise. */ | |
1614 | ||
1615 | r = sd_bus_message_read_array(message, 'y', &p, &sz); | |
1616 | if (r < 0) | |
1617 | return r; | |
1618 | if (r == 0) | |
1619 | break; | |
1620 | ||
1621 | if (memchr(p, 0, sz)) | |
1622 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Journal field contains zero byte"); | |
1623 | ||
1624 | eq = memchr(p, '=', sz); | |
1625 | if (!eq) | |
1626 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Journal field contains no '=' character"); | |
1627 | if (!journal_field_valid(p, eq - (const char*) p, false)) | |
1628 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Journal field invalid"); | |
1629 | ||
2e59b241 | 1630 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
aa484f35 | 1631 | t = reallocarray(c->log_extra_fields, c->n_log_extra_fields+1, sizeof(struct iovec)); |
d3070fbd LP |
1632 | if (!t) |
1633 | return -ENOMEM; | |
1634 | c->log_extra_fields = t; | |
1635 | } | |
1636 | ||
1637 | copy = malloc(sz + 1); | |
1638 | if (!copy) | |
1639 | return -ENOMEM; | |
1640 | ||
1641 | memcpy(copy, p, sz); | |
1642 | ((uint8_t*) copy)[sz] = 0; | |
1643 | ||
1644 | if (!utf8_is_valid(copy)) | |
1645 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Journal field is not valid UTF-8"); | |
1646 | ||
2e59b241 | 1647 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
d3070fbd | 1648 | c->log_extra_fields[c->n_log_extra_fields++] = IOVEC_MAKE(copy, sz); |
2e59b241 | 1649 | unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS|UNIT_ESCAPE_C, name, "LogExtraFields=%s", (char*) copy); |
d3070fbd LP |
1650 | |
1651 | copy = NULL; | |
1652 | } | |
1653 | ||
1654 | n++; | |
1655 | } | |
1656 | ||
1657 | r = sd_bus_message_exit_container(message); | |
1658 | if (r < 0) | |
1659 | return r; | |
1660 | ||
2e59b241 | 1661 | if (!UNIT_WRITE_FLAGS_NOOP(flags) && n == 0) { |
d3070fbd | 1662 | exec_context_free_log_extra_fields(c); |
2e59b241 | 1663 | unit_write_setting(u, flags, name, "LogExtraFields="); |
d3070fbd LP |
1664 | } |
1665 | ||
1666 | return 1; | |
7e2a3fcc | 1667 | } |
cffaed83 | 1668 | |
349cc4a5 | 1669 | #if HAVE_SECCOMP |
cffaed83 | 1670 | |
7e2a3fcc YW |
1671 | if (streq(name, "SystemCallErrorNumber")) |
1672 | return bus_set_transient_errno(u, name, &c->syscall_errno, message, flags, error); | |
1673 | ||
1674 | if (streq(name, "SystemCallFilter")) { | |
cffaed83 | 1675 | int whitelist; |
3f856a28 | 1676 | _cleanup_strv_free_ char **l = NULL; |
cffaed83 YW |
1677 | |
1678 | r = sd_bus_message_enter_container(message, 'r', "bas"); | |
1679 | if (r < 0) | |
1680 | return r; | |
1681 | ||
1682 | r = sd_bus_message_read(message, "b", &whitelist); | |
1683 | if (r < 0) | |
1684 | return r; | |
1685 | ||
1686 | r = sd_bus_message_read_strv(message, &l); | |
1687 | if (r < 0) | |
1688 | return r; | |
1689 | ||
1690 | r = sd_bus_message_exit_container(message); | |
1691 | if (r < 0) | |
1692 | return r; | |
1693 | ||
2e59b241 | 1694 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
cffaed83 | 1695 | _cleanup_free_ char *joined = NULL; |
e7ccdfa8 | 1696 | SeccompParseFlags invert_flag = whitelist ? 0 : SECCOMP_PARSE_INVERT; |
898748d8 | 1697 | char **s; |
cffaed83 | 1698 | |
7b943bb7 | 1699 | if (strv_isempty(l)) { |
cffaed83 | 1700 | c->syscall_whitelist = false; |
8cfa775f | 1701 | c->syscall_filter = hashmap_free(c->syscall_filter); |
cffaed83 | 1702 | |
898748d8 YW |
1703 | unit_write_settingf(u, flags, name, "SystemCallFilter="); |
1704 | return 1; | |
1705 | } | |
cffaed83 | 1706 | |
898748d8 YW |
1707 | if (!c->syscall_filter) { |
1708 | c->syscall_filter = hashmap_new(NULL); | |
1709 | if (!c->syscall_filter) | |
1710 | return log_oom(); | |
cffaed83 | 1711 | |
898748d8 | 1712 | c->syscall_whitelist = whitelist; |
8cfa775f | 1713 | |
898748d8 | 1714 | if (c->syscall_whitelist) { |
e7ccdfa8 ZJS |
1715 | r = seccomp_parse_syscall_filter("@default", |
1716 | -1, | |
1717 | c->syscall_filter, | |
72545ae0 | 1718 | SECCOMP_PARSE_PERMISSIVE | |
58f6ab44 ZJS |
1719 | SECCOMP_PARSE_WHITELIST | invert_flag, |
1720 | u->id, | |
1721 | NULL, 0); | |
8cfa775f YW |
1722 | if (r < 0) |
1723 | return r; | |
898748d8 YW |
1724 | } |
1725 | } | |
8cfa775f | 1726 | |
898748d8 YW |
1727 | STRV_FOREACH(s, l) { |
1728 | _cleanup_free_ char *n = NULL; | |
1729 | int e; | |
cffaed83 | 1730 | |
898748d8 YW |
1731 | r = parse_syscall_and_errno(*s, &n, &e); |
1732 | if (r < 0) | |
1733 | return r; | |
cffaed83 | 1734 | |
e7ccdfa8 ZJS |
1735 | r = seccomp_parse_syscall_filter(n, |
1736 | e, | |
1737 | c->syscall_filter, | |
72545ae0 AZ |
1738 | SECCOMP_PARSE_LOG | SECCOMP_PARSE_PERMISSIVE | |
1739 | invert_flag | | |
1740 | (c->syscall_whitelist ? SECCOMP_PARSE_WHITELIST : 0), | |
58f6ab44 ZJS |
1741 | u->id, |
1742 | NULL, 0); | |
898748d8 YW |
1743 | if (r < 0) |
1744 | return r; | |
cffaed83 YW |
1745 | } |
1746 | ||
1747 | joined = strv_join(l, " "); | |
1748 | if (!joined) | |
1749 | return -ENOMEM; | |
1750 | ||
2e59b241 | 1751 | unit_write_settingf(u, flags, name, "SystemCallFilter=%s%s", whitelist ? "" : "~", joined); |
cffaed83 YW |
1752 | } |
1753 | ||
1754 | return 1; | |
1755 | ||
1756 | } else if (streq(name, "SystemCallArchitectures")) { | |
1757 | _cleanup_strv_free_ char **l = NULL; | |
1758 | ||
1759 | r = sd_bus_message_read_strv(message, &l); | |
1760 | if (r < 0) | |
1761 | return r; | |
1762 | ||
2e59b241 | 1763 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
cffaed83 YW |
1764 | _cleanup_free_ char *joined = NULL; |
1765 | ||
7b943bb7 | 1766 | if (strv_isempty(l)) |
cffaed83 YW |
1767 | c->syscall_archs = set_free(c->syscall_archs); |
1768 | else { | |
1769 | char **s; | |
1770 | ||
cffaed83 YW |
1771 | STRV_FOREACH(s, l) { |
1772 | uint32_t a; | |
1773 | ||
1774 | r = seccomp_arch_from_string(*s, &a); | |
1775 | if (r < 0) | |
1776 | return r; | |
1777 | ||
de7fef4b | 1778 | r = set_ensure_put(&c->syscall_archs, NULL, UINT32_TO_PTR(a + 1)); |
cffaed83 YW |
1779 | if (r < 0) |
1780 | return r; | |
1781 | } | |
1782 | ||
1783 | } | |
1784 | ||
1785 | joined = strv_join(l, " "); | |
1786 | if (!joined) | |
1787 | return -ENOMEM; | |
1788 | ||
2e59b241 | 1789 | unit_write_settingf(u, flags, name, "%s=%s", name, joined); |
cffaed83 YW |
1790 | } |
1791 | ||
1792 | return 1; | |
1793 | ||
cffaed83 YW |
1794 | } else if (streq(name, "RestrictAddressFamilies")) { |
1795 | int whitelist; | |
3f856a28 | 1796 | _cleanup_strv_free_ char **l = NULL; |
cffaed83 YW |
1797 | |
1798 | r = sd_bus_message_enter_container(message, 'r', "bas"); | |
1799 | if (r < 0) | |
1800 | return r; | |
1801 | ||
1802 | r = sd_bus_message_read(message, "b", &whitelist); | |
1803 | if (r < 0) | |
1804 | return r; | |
1805 | ||
1806 | r = sd_bus_message_read_strv(message, &l); | |
1807 | if (r < 0) | |
1808 | return r; | |
1809 | ||
1810 | r = sd_bus_message_exit_container(message); | |
1811 | if (r < 0) | |
1812 | return r; | |
1813 | ||
2e59b241 | 1814 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
cffaed83 | 1815 | _cleanup_free_ char *joined = NULL; |
9ee896d5 | 1816 | char **s; |
cffaed83 | 1817 | |
7b943bb7 | 1818 | if (strv_isempty(l)) { |
cffaed83 YW |
1819 | c->address_families_whitelist = false; |
1820 | c->address_families = set_free(c->address_families); | |
cffaed83 | 1821 | |
9ee896d5 YW |
1822 | unit_write_settingf(u, flags, name, "RestrictAddressFamilies="); |
1823 | return 1; | |
1824 | } | |
cffaed83 | 1825 | |
9ee896d5 YW |
1826 | if (!c->address_families) { |
1827 | c->address_families = set_new(NULL); | |
1828 | if (!c->address_families) | |
1829 | return log_oom(); | |
cffaed83 | 1830 | |
9ee896d5 YW |
1831 | c->address_families_whitelist = whitelist; |
1832 | } | |
1833 | ||
1834 | STRV_FOREACH(s, l) { | |
1835 | int af; | |
cffaed83 | 1836 | |
9ee896d5 | 1837 | af = af_from_name(*s); |
acf4d158 YW |
1838 | if (af < 0) |
1839 | return af; | |
cffaed83 | 1840 | |
e7ccdfa8 | 1841 | if (whitelist == c->address_families_whitelist) { |
cffaed83 YW |
1842 | r = set_put(c->address_families, INT_TO_PTR(af)); |
1843 | if (r < 0) | |
1844 | return r; | |
9ee896d5 YW |
1845 | } else |
1846 | (void) set_remove(c->address_families, INT_TO_PTR(af)); | |
cffaed83 YW |
1847 | } |
1848 | ||
1849 | joined = strv_join(l, " "); | |
1850 | if (!joined) | |
1851 | return -ENOMEM; | |
1852 | ||
2e59b241 | 1853 | unit_write_settingf(u, flags, name, "RestrictAddressFamilies=%s%s", whitelist ? "" : "~", joined); |
cffaed83 YW |
1854 | } |
1855 | ||
1856 | return 1; | |
7e2a3fcc | 1857 | } |
cffaed83 | 1858 | #endif |
b070c7c0 | 1859 | if (STR_IN_SET(name, "CPUAffinity", "NUMAMask")) { |
cffaed83 | 1860 | const void *a; |
bd0abfae | 1861 | size_t n; |
b070c7c0 | 1862 | bool affinity = streq(name, "CPUAffinity"); |
c367f996 | 1863 | _cleanup_(cpu_set_reset) CPUSet set = {}; |
cffaed83 YW |
1864 | |
1865 | r = sd_bus_message_read_array(message, 'y', &a, &n); | |
1866 | if (r < 0) | |
1867 | return r; | |
1868 | ||
c367f996 MS |
1869 | r = cpu_set_from_dbus(a, n, &set); |
1870 | if (r < 0) | |
1871 | return r; | |
1872 | ||
2e59b241 | 1873 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
cffaed83 | 1874 | if (n == 0) { |
b070c7c0 | 1875 | cpu_set_reset(affinity ? &c->cpu_set : &c->numa_policy.nodes); |
2e59b241 | 1876 | unit_write_settingf(u, flags, name, "%s=", name); |
cffaed83 YW |
1877 | } else { |
1878 | _cleanup_free_ char *str = NULL; | |
cffaed83 | 1879 | |
0985c7c4 | 1880 | str = cpu_set_to_string(&set); |
a832893f ZJS |
1881 | if (!str) |
1882 | return -ENOMEM; | |
cffaed83 | 1883 | |
0985c7c4 ZJS |
1884 | /* We forego any optimizations here, and always create the structure using |
1885 | * cpu_set_add_all(), because we don't want to care if the existing size we | |
1886 | * got over dbus is appropriate. */ | |
b070c7c0 | 1887 | r = cpu_set_add_all(affinity ? &c->cpu_set : &c->numa_policy.nodes, &set); |
0985c7c4 ZJS |
1888 | if (r < 0) |
1889 | return r; | |
501941aa | 1890 | |
2e59b241 | 1891 | unit_write_settingf(u, flags, name, "%s=%s", name, str); |
cffaed83 YW |
1892 | } |
1893 | } | |
1894 | ||
c7040b5d LP |
1895 | return 1; |
1896 | ||
e2b2fb7f MS |
1897 | } else if (streq(name, "CPUAffinityFromNUMA")) { |
1898 | int q; | |
1899 | ||
1900 | r = sd_bus_message_read_basic(message, 'b', &q); | |
1901 | if (r < 0) | |
1902 | return r; | |
1903 | ||
1904 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
1905 | c->cpu_affinity_from_numa = q; | |
1906 | unit_write_settingf(u, flags, name, "%s=%s", "CPUAffinity", "numa"); | |
1907 | } | |
1908 | ||
1909 | return 1; | |
1910 | ||
b070c7c0 MS |
1911 | } else if (streq(name, "NUMAPolicy")) { |
1912 | int32_t type; | |
1913 | ||
1914 | r = sd_bus_message_read(message, "i", &type); | |
1915 | if (r < 0) | |
1916 | return r; | |
1917 | ||
1918 | if (!mpol_is_valid(type)) | |
1919 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid NUMAPolicy value: %i", type); | |
1920 | ||
1921 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) | |
1922 | c->numa_policy.type = type; | |
1923 | ||
1924 | return 1; | |
e2b2fb7f | 1925 | |
c250bf67 YW |
1926 | } else if (streq(name, "Nice")) { |
1927 | int32_t q; | |
1928 | ||
1929 | r = sd_bus_message_read(message, "i", &q); | |
1930 | if (r < 0) | |
1931 | return r; | |
1932 | ||
1933 | if (!nice_is_valid(q)) | |
1934 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid Nice value: %i", q); | |
1935 | ||
1936 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
1937 | c->nice = q; | |
1938 | c->nice_set = true; | |
1939 | ||
1940 | unit_write_settingf(u, flags, name, "Nice=%i", q); | |
1941 | } | |
1942 | ||
1943 | return 1; | |
1944 | ||
1945 | } else if (streq(name, "CPUSchedulingPolicy")) { | |
1946 | int32_t q; | |
1947 | ||
1948 | r = sd_bus_message_read(message, "i", &q); | |
1949 | if (r < 0) | |
1950 | return r; | |
1951 | ||
1952 | if (!sched_policy_is_valid(q)) | |
1953 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid CPU scheduling policy: %i", q); | |
1954 | ||
1955 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
1956 | _cleanup_free_ char *s = NULL; | |
1957 | ||
1958 | r = sched_policy_to_string_alloc(q, &s); | |
1959 | if (r < 0) | |
1960 | return r; | |
1961 | ||
1962 | c->cpu_sched_policy = q; | |
1963 | c->cpu_sched_priority = CLAMP(c->cpu_sched_priority, sched_get_priority_min(q), sched_get_priority_max(q)); | |
1964 | c->cpu_sched_set = true; | |
1965 | ||
1966 | unit_write_settingf(u, flags, name, "CPUSchedulingPolicy=%s", s); | |
1967 | } | |
1968 | ||
1969 | return 1; | |
1970 | ||
1971 | } else if (streq(name, "CPUSchedulingPriority")) { | |
1972 | int32_t p, min, max; | |
1973 | ||
1974 | r = sd_bus_message_read(message, "i", &p); | |
1975 | if (r < 0) | |
1976 | return r; | |
1977 | ||
1978 | min = sched_get_priority_min(c->cpu_sched_policy); | |
1979 | max = sched_get_priority_max(c->cpu_sched_policy); | |
1980 | if (p < min || p > max) | |
1981 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid CPU scheduling priority: %i", p); | |
1982 | ||
1983 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
1984 | c->cpu_sched_priority = p; | |
1985 | c->cpu_sched_set = true; | |
1986 | ||
1987 | unit_write_settingf(u, flags, name, "CPUSchedulingPriority=%i", p); | |
1988 | } | |
1989 | ||
1990 | return 1; | |
1991 | ||
7f452159 LP |
1992 | } else if (streq(name, "IOSchedulingClass")) { |
1993 | int32_t q; | |
1994 | ||
1995 | r = sd_bus_message_read(message, "i", &q); | |
1996 | if (r < 0) | |
1997 | return r; | |
1998 | ||
1999 | if (!ioprio_class_is_valid(q)) | |
2000 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid IO scheduling class: %i", q); | |
2001 | ||
2e59b241 | 2002 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
7f452159 LP |
2003 | _cleanup_free_ char *s = NULL; |
2004 | ||
2005 | r = ioprio_class_to_string_alloc(q, &s); | |
2006 | if (r < 0) | |
2007 | return r; | |
2008 | ||
2009 | c->ioprio = IOPRIO_PRIO_VALUE(q, IOPRIO_PRIO_DATA(c->ioprio)); | |
2010 | c->ioprio_set = true; | |
2011 | ||
2e59b241 | 2012 | unit_write_settingf(u, flags, name, "IOSchedulingClass=%s", s); |
7f452159 LP |
2013 | } |
2014 | ||
2015 | return 1; | |
2016 | ||
2017 | } else if (streq(name, "IOSchedulingPriority")) { | |
2018 | int32_t p; | |
2019 | ||
2020 | r = sd_bus_message_read(message, "i", &p); | |
2021 | if (r < 0) | |
2022 | return r; | |
2023 | ||
2024 | if (!ioprio_priority_is_valid(p)) | |
2025 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid IO scheduling priority: %i", p); | |
2026 | ||
2e59b241 | 2027 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
7f452159 LP |
2028 | c->ioprio = IOPRIO_PRIO_VALUE(IOPRIO_PRIO_CLASS(c->ioprio), p); |
2029 | c->ioprio_set = true; | |
2030 | ||
2e59b241 | 2031 | unit_write_settingf(u, flags, name, "IOSchedulingPriority=%i", p); |
7f452159 LP |
2032 | } |
2033 | ||
2034 | return 1; | |
2035 | ||
5f5d8eab LP |
2036 | } else if (streq(name, "WorkingDirectory")) { |
2037 | const char *s; | |
2038 | bool missing_ok; | |
2039 | ||
2040 | r = sd_bus_message_read(message, "s", &s); | |
2041 | if (r < 0) | |
2042 | return r; | |
2043 | ||
2044 | if (s[0] == '-') { | |
2045 | missing_ok = true; | |
2046 | s++; | |
2047 | } else | |
2048 | missing_ok = false; | |
2049 | ||
d6ff82d3 | 2050 | if (!isempty(s) && !streq(s, "~") && !path_is_absolute(s)) |
5f5d8eab LP |
2051 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "WorkingDirectory= expects an absolute path or '~'"); |
2052 | ||
2e59b241 | 2053 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
5f5d8eab LP |
2054 | if (streq(s, "~")) { |
2055 | c->working_directory = mfree(c->working_directory); | |
2056 | c->working_directory_home = true; | |
2057 | } else { | |
d6ff82d3 | 2058 | r = free_and_strdup(&c->working_directory, empty_to_null(s)); |
5f5d8eab LP |
2059 | if (r < 0) |
2060 | return r; | |
2061 | ||
2062 | c->working_directory_home = false; | |
2063 | } | |
2064 | ||
2065 | c->working_directory_missing_ok = missing_ok; | |
2e59b241 | 2066 | unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "WorkingDirectory=%s%s", missing_ok ? "-" : "", s); |
5f5d8eab LP |
2067 | } |
2068 | ||
2069 | return 1; | |
2070 | ||
52c239d7 LB |
2071 | } else if (STR_IN_SET(name, |
2072 | "StandardInputFileDescriptorName", "StandardOutputFileDescriptorName", "StandardErrorFileDescriptorName")) { | |
2073 | const char *s; | |
2074 | ||
2075 | r = sd_bus_message_read(message, "s", &s); | |
2076 | if (r < 0) | |
2077 | return r; | |
2078 | ||
d6ff82d3 | 2079 | if (!isempty(s) && !fdname_is_valid(s)) |
52c239d7 LB |
2080 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid file descriptor name"); |
2081 | ||
2e59b241 | 2082 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
5073ff6b | 2083 | |
52c239d7 | 2084 | if (streq(name, "StandardInputFileDescriptorName")) { |
d6ff82d3 | 2085 | r = free_and_strdup(c->stdio_fdname + STDIN_FILENO, empty_to_null(s)); |
52c239d7 LB |
2086 | if (r < 0) |
2087 | return r; | |
5073ff6b | 2088 | |
0664775c | 2089 | c->std_input = EXEC_INPUT_NAMED_FD; |
2e59b241 | 2090 | unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardInput=fd:%s", exec_context_fdname(c, STDIN_FILENO)); |
5073ff6b | 2091 | |
52c239d7 | 2092 | } else if (streq(name, "StandardOutputFileDescriptorName")) { |
d6ff82d3 | 2093 | r = free_and_strdup(c->stdio_fdname + STDOUT_FILENO, empty_to_null(s)); |
52c239d7 LB |
2094 | if (r < 0) |
2095 | return r; | |
5073ff6b | 2096 | |
52c239d7 | 2097 | c->std_output = EXEC_OUTPUT_NAMED_FD; |
2e59b241 | 2098 | unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardOutput=fd:%s", exec_context_fdname(c, STDOUT_FILENO)); |
0664775c LP |
2099 | |
2100 | } else { | |
2101 | assert(streq(name, "StandardErrorFileDescriptorName")); | |
5073ff6b | 2102 | |
d6ff82d3 | 2103 | r = free_and_strdup(&c->stdio_fdname[STDERR_FILENO], empty_to_null(s)); |
52c239d7 LB |
2104 | if (r < 0) |
2105 | return r; | |
5073ff6b | 2106 | |
52c239d7 | 2107 | c->std_error = EXEC_OUTPUT_NAMED_FD; |
2e59b241 | 2108 | unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardError=fd:%s", exec_context_fdname(c, STDERR_FILENO)); |
52c239d7 LB |
2109 | } |
2110 | } | |
2111 | ||
2112 | return 1; | |
2113 | ||
566b7d23 ZD |
2114 | } else if (STR_IN_SET(name, |
2115 | "StandardInputFile", | |
922ce049 LP |
2116 | "StandardOutputFile", "StandardOutputFileToAppend", |
2117 | "StandardErrorFile", "StandardErrorFileToAppend")) { | |
2038c3f5 LP |
2118 | const char *s; |
2119 | ||
2120 | r = sd_bus_message_read(message, "s", &s); | |
2121 | if (r < 0) | |
2122 | return r; | |
2123 | ||
d6ff82d3 YW |
2124 | if (!isempty(s)) { |
2125 | if (!path_is_absolute(s)) | |
2126 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path %s is not absolute", s); | |
2127 | if (!path_is_normalized(s)) | |
2128 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path %s is not normalized", s); | |
2129 | } | |
2038c3f5 | 2130 | |
2e59b241 | 2131 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
2038c3f5 LP |
2132 | |
2133 | if (streq(name, "StandardInputFile")) { | |
d6ff82d3 | 2134 | r = free_and_strdup(&c->stdio_file[STDIN_FILENO], empty_to_null(s)); |
52c239d7 LB |
2135 | if (r < 0) |
2136 | return r; | |
2038c3f5 LP |
2137 | |
2138 | c->std_input = EXEC_INPUT_FILE; | |
2e59b241 | 2139 | unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardInput=file:%s", s); |
2038c3f5 | 2140 | |
566b7d23 | 2141 | } else if (STR_IN_SET(name, "StandardOutputFile", "StandardOutputFileToAppend")) { |
d6ff82d3 | 2142 | r = free_and_strdup(&c->stdio_file[STDOUT_FILENO], empty_to_null(s)); |
2038c3f5 LP |
2143 | if (r < 0) |
2144 | return r; | |
2145 | ||
566b7d23 ZD |
2146 | if (streq(name, "StandardOutputFile")) { |
2147 | c->std_output = EXEC_OUTPUT_FILE; | |
2148 | unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardOutput=file:%s", s); | |
2149 | } else { | |
2150 | assert(streq(name, "StandardOutputFileToAppend")); | |
2151 | c->std_output = EXEC_OUTPUT_FILE_APPEND; | |
2152 | unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardOutput=append:%s", s); | |
2153 | } | |
2038c3f5 | 2154 | } else { |
566b7d23 | 2155 | assert(STR_IN_SET(name, "StandardErrorFile", "StandardErrorFileToAppend")); |
2038c3f5 | 2156 | |
d6ff82d3 | 2157 | r = free_and_strdup(&c->stdio_file[STDERR_FILENO], empty_to_null(s)); |
2038c3f5 LP |
2158 | if (r < 0) |
2159 | return r; | |
2160 | ||
566b7d23 ZD |
2161 | if (streq(name, "StandardErrorFile")) { |
2162 | c->std_error = EXEC_OUTPUT_FILE; | |
1704fba9 | 2163 | unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardError=file:%s", s); |
566b7d23 | 2164 | } else { |
dbe6c4b6 LP |
2165 | assert(streq(name, "StandardErrorFileToAppend")); |
2166 | c->std_error = EXEC_OUTPUT_FILE_APPEND; | |
1704fba9 | 2167 | unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardError=append:%s", s); |
566b7d23 | 2168 | } |
2038c3f5 LP |
2169 | } |
2170 | } | |
2171 | ||
2172 | return 1; | |
2173 | ||
08f3be7a LP |
2174 | } else if (streq(name, "StandardInputData")) { |
2175 | const void *p; | |
2176 | size_t sz; | |
2177 | ||
2178 | r = sd_bus_message_read_array(message, 'y', &p, &sz); | |
2179 | if (r < 0) | |
2180 | return r; | |
2181 | ||
2e59b241 | 2182 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
08f3be7a LP |
2183 | _cleanup_free_ char *encoded = NULL; |
2184 | ||
2185 | if (sz == 0) { | |
2186 | c->stdin_data = mfree(c->stdin_data); | |
2187 | c->stdin_data_size = 0; | |
2188 | ||
2e59b241 | 2189 | unit_write_settingf(u, flags, name, "StandardInputData="); |
08f3be7a LP |
2190 | } else { |
2191 | void *q; | |
2192 | ssize_t n; | |
2193 | ||
2194 | if (c->stdin_data_size + sz < c->stdin_data_size || /* check for overflow */ | |
2195 | c->stdin_data_size + sz > EXEC_STDIN_DATA_MAX) | |
2196 | return -E2BIG; | |
2197 | ||
2198 | n = base64mem(p, sz, &encoded); | |
2199 | if (n < 0) | |
2200 | return (int) n; | |
2201 | ||
2202 | q = realloc(c->stdin_data, c->stdin_data_size + sz); | |
2203 | if (!q) | |
2204 | return -ENOMEM; | |
2205 | ||
2206 | memcpy((uint8_t*) q + c->stdin_data_size, p, sz); | |
2207 | ||
2208 | c->stdin_data = q; | |
2209 | c->stdin_data_size += sz; | |
2210 | ||
2e59b241 | 2211 | unit_write_settingf(u, flags, name, "StandardInputData=%s", encoded); |
52c239d7 LB |
2212 | } |
2213 | } | |
2214 | ||
2215 | return 1; | |
2216 | ||
c7040b5d LP |
2217 | } else if (streq(name, "Environment")) { |
2218 | ||
6171b822 | 2219 | _cleanup_strv_free_ char **l = NULL; |
c7040b5d LP |
2220 | |
2221 | r = sd_bus_message_read_strv(message, &l); | |
2222 | if (r < 0) | |
2223 | return r; | |
2224 | ||
6171b822 | 2225 | if (!strv_env_is_valid(l)) |
1c68232e LP |
2226 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid environment block."); |
2227 | ||
2e59b241 | 2228 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
7b943bb7 | 2229 | if (strv_isempty(l)) { |
e9876fc9 | 2230 | c->environment = strv_free(c->environment); |
2e59b241 | 2231 | unit_write_setting(u, flags, name, "Environment="); |
e9876fc9 | 2232 | } else { |
f900f582 ZJS |
2233 | _cleanup_free_ char *joined = NULL; |
2234 | char **e; | |
2235 | ||
2e59b241 LP |
2236 | joined = unit_concat_strv(l, UNIT_ESCAPE_SPECIFIERS|UNIT_ESCAPE_C); |
2237 | if (!joined) | |
2238 | return -ENOMEM; | |
2239 | ||
6171b822 | 2240 | e = strv_env_merge(2, c->environment, l); |
e9876fc9 EV |
2241 | if (!e) |
2242 | return -ENOMEM; | |
c7040b5d | 2243 | |
130d3d22 | 2244 | strv_free_and_replace(c->environment, e); |
2e59b241 | 2245 | unit_write_settingf(u, flags, name, "Environment=%s", joined); |
e9876fc9 | 2246 | } |
c7040b5d LP |
2247 | } |
2248 | ||
d584f638 LP |
2249 | return 1; |
2250 | ||
00819cc1 LP |
2251 | } else if (streq(name, "UnsetEnvironment")) { |
2252 | ||
6171b822 | 2253 | _cleanup_strv_free_ char **l = NULL; |
00819cc1 LP |
2254 | |
2255 | r = sd_bus_message_read_strv(message, &l); | |
2256 | if (r < 0) | |
2257 | return r; | |
2258 | ||
6171b822 | 2259 | if (!strv_env_name_or_assignment_is_valid(l)) |
00819cc1 LP |
2260 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid UnsetEnvironment= list."); |
2261 | ||
2e59b241 | 2262 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
7b943bb7 | 2263 | if (strv_isempty(l)) { |
00819cc1 | 2264 | c->unset_environment = strv_free(c->unset_environment); |
2e59b241 | 2265 | unit_write_setting(u, flags, name, "UnsetEnvironment="); |
00819cc1 LP |
2266 | } else { |
2267 | _cleanup_free_ char *joined = NULL; | |
2268 | char **e; | |
2269 | ||
2e59b241 LP |
2270 | joined = unit_concat_strv(l, UNIT_ESCAPE_SPECIFIERS|UNIT_ESCAPE_C); |
2271 | if (!joined) | |
2272 | return -ENOMEM; | |
2273 | ||
6171b822 | 2274 | e = strv_env_merge(2, c->unset_environment, l); |
00819cc1 LP |
2275 | if (!e) |
2276 | return -ENOMEM; | |
2277 | ||
130d3d22 | 2278 | strv_free_and_replace(c->unset_environment, e); |
2e59b241 | 2279 | unit_write_settingf(u, flags, name, "UnsetEnvironment=%s", joined); |
00819cc1 LP |
2280 | } |
2281 | } | |
2282 | ||
2283 | return 1; | |
2284 | ||
6b862936 EV |
2285 | } else if (streq(name, "OOMScoreAdjust")) { |
2286 | int oa; | |
2287 | ||
2288 | r = sd_bus_message_read(message, "i", &oa); | |
2289 | if (r < 0) | |
2290 | return r; | |
2291 | ||
2292 | if (!oom_score_adjust_is_valid(oa)) | |
2293 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "OOM score adjust value out of range"); | |
2294 | ||
2e59b241 | 2295 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
6b862936 EV |
2296 | c->oom_score_adjust = oa; |
2297 | c->oom_score_adjust_set = true; | |
2e59b241 | 2298 | unit_write_settingf(u, flags, name, "OOMScoreAdjust=%i", oa); |
6b862936 EV |
2299 | } |
2300 | ||
2301 | return 1; | |
2302 | ||
ad21e542 ZJS |
2303 | } else if (streq(name, "CoredumpFilter")) { |
2304 | uint64_t f; | |
2305 | ||
2306 | r = sd_bus_message_read(message, "t", &f); | |
2307 | if (r < 0) | |
2308 | return r; | |
2309 | ||
2310 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
2311 | c->coredump_filter = f; | |
2312 | c->coredump_filter_set = true; | |
2313 | unit_write_settingf(u, flags, name, "CoredumpFilter=0x%"PRIx64, f); | |
2314 | } | |
2315 | ||
2316 | return 1; | |
2317 | ||
ceb728cf NC |
2318 | } else if (streq(name, "EnvironmentFiles")) { |
2319 | ||
2320 | _cleanup_free_ char *joined = NULL; | |
2321 | _cleanup_fclose_ FILE *f = NULL; | |
9b531f04 | 2322 | _cleanup_strv_free_ char **l = NULL; |
ceb728cf | 2323 | size_t size = 0; |
2229f656 | 2324 | char **i; |
ceb728cf NC |
2325 | |
2326 | r = sd_bus_message_enter_container(message, 'a', "(sb)"); | |
2327 | if (r < 0) | |
2328 | return r; | |
2329 | ||
2fe21124 | 2330 | f = open_memstream_unlocked(&joined, &size); |
ceb728cf NC |
2331 | if (!f) |
2332 | return -ENOMEM; | |
2333 | ||
2e59b241 LP |
2334 | fputs("EnvironmentFile=\n", f); |
2335 | ||
2336 | STRV_FOREACH(i, c->environment_files) { | |
2337 | _cleanup_free_ char *q = NULL; | |
2338 | ||
2339 | q = specifier_escape(*i); | |
2340 | if (!q) | |
2341 | return -ENOMEM; | |
2342 | ||
2343 | fprintf(f, "EnvironmentFile=%s\n", q); | |
2344 | } | |
ceb728cf NC |
2345 | |
2346 | while ((r = sd_bus_message_enter_container(message, 'r', "sb")) > 0) { | |
2347 | const char *path; | |
2348 | int b; | |
2349 | ||
ceb728cf NC |
2350 | r = sd_bus_message_read(message, "sb", &path, &b); |
2351 | if (r < 0) | |
2352 | return r; | |
2353 | ||
2354 | r = sd_bus_message_exit_container(message); | |
2355 | if (r < 0) | |
2356 | return r; | |
2357 | ||
d2d6c096 LP |
2358 | if (!path_is_absolute(path)) |
2359 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path %s is not absolute.", path); | |
ceb728cf | 2360 | |
2e59b241 | 2361 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
6abdec98 | 2362 | _cleanup_free_ char *q = NULL, *buf = NULL; |
ceb728cf | 2363 | |
605405c6 | 2364 | buf = strjoin(b ? "-" : "", path); |
2229f656 | 2365 | if (!buf) |
ceb728cf NC |
2366 | return -ENOMEM; |
2367 | ||
2e59b241 | 2368 | q = specifier_escape(buf); |
6abdec98 | 2369 | if (!q) |
2e59b241 | 2370 | return -ENOMEM; |
2e59b241 LP |
2371 | |
2372 | fprintf(f, "EnvironmentFile=%s\n", q); | |
ceb728cf | 2373 | |
6abdec98 | 2374 | r = strv_consume(&l, TAKE_PTR(buf)); |
ceb728cf NC |
2375 | if (r < 0) |
2376 | return r; | |
2377 | } | |
2378 | } | |
2379 | if (r < 0) | |
2380 | return r; | |
2381 | ||
b0830e21 LP |
2382 | r = sd_bus_message_exit_container(message); |
2383 | if (r < 0) | |
2384 | return r; | |
2385 | ||
2229f656 LP |
2386 | r = fflush_and_check(f); |
2387 | if (r < 0) | |
2388 | return r; | |
ceb728cf | 2389 | |
2e59b241 | 2390 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
2229f656 LP |
2391 | if (strv_isempty(l)) { |
2392 | c->environment_files = strv_free(c->environment_files); | |
2e59b241 | 2393 | unit_write_setting(u, flags, name, "EnvironmentFile="); |
2229f656 LP |
2394 | } else { |
2395 | r = strv_extend_strv(&c->environment_files, l, true); | |
2396 | if (r < 0) | |
2397 | return r; | |
2398 | ||
2e59b241 | 2399 | unit_write_setting(u, flags, name, joined); |
2229f656 LP |
2400 | } |
2401 | } | |
ceb728cf | 2402 | |
ceb728cf NC |
2403 | return 1; |
2404 | ||
b4c14404 FB |
2405 | } else if (streq(name, "PassEnvironment")) { |
2406 | ||
6171b822 | 2407 | _cleanup_strv_free_ char **l = NULL; |
b4c14404 FB |
2408 | |
2409 | r = sd_bus_message_read_strv(message, &l); | |
2410 | if (r < 0) | |
2411 | return r; | |
2412 | ||
6171b822 | 2413 | if (!strv_env_name_is_valid(l)) |
00819cc1 | 2414 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid PassEnvironment= block."); |
b4c14404 | 2415 | |
2e59b241 | 2416 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
b4c14404 FB |
2417 | if (strv_isempty(l)) { |
2418 | c->pass_environment = strv_free(c->pass_environment); | |
2e59b241 | 2419 | unit_write_setting(u, flags, name, "PassEnvironment="); |
b4c14404 FB |
2420 | } else { |
2421 | _cleanup_free_ char *joined = NULL; | |
2422 | ||
9d4f242a YW |
2423 | r = strv_extend_strv(&c->pass_environment, l, true); |
2424 | if (r < 0) | |
2425 | return r; | |
2426 | ||
41de9cc2 | 2427 | /* We write just the new settings out to file, with unresolved specifiers. */ |
2e59b241 | 2428 | joined = unit_concat_strv(l, UNIT_ESCAPE_SPECIFIERS); |
b4c14404 FB |
2429 | if (!joined) |
2430 | return -ENOMEM; | |
2431 | ||
2e59b241 | 2432 | unit_write_settingf(u, flags, name, "PassEnvironment=%s", joined); |
b4c14404 FB |
2433 | } |
2434 | } | |
2435 | ||
2436 | return 1; | |
2437 | ||
2a624c36 AP |
2438 | } else if (STR_IN_SET(name, "ReadWriteDirectories", "ReadOnlyDirectories", "InaccessibleDirectories", |
2439 | "ReadWritePaths", "ReadOnlyPaths", "InaccessiblePaths")) { | |
08596068 EV |
2440 | _cleanup_strv_free_ char **l = NULL; |
2441 | char ***dirs; | |
2442 | char **p; | |
2443 | ||
2444 | r = sd_bus_message_read_strv(message, &l); | |
2445 | if (r < 0) | |
2446 | return r; | |
2447 | ||
2448 | STRV_FOREACH(p, l) { | |
e7bcff4e | 2449 | char *i = *p; |
20b7a007 LP |
2450 | size_t offset; |
2451 | ||
20b7a007 LP |
2452 | offset = i[0] == '-'; |
2453 | offset += i[offset] == '+'; | |
2454 | if (!path_is_absolute(i + offset)) | |
08596068 | 2455 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid %s", name); |
e7bcff4e | 2456 | |
858d36c1 | 2457 | path_simplify(i + offset, false); |
08596068 EV |
2458 | } |
2459 | ||
2e59b241 | 2460 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
c4b41707 AP |
2461 | if (STR_IN_SET(name, "ReadWriteDirectories", "ReadWritePaths")) |
2462 | dirs = &c->read_write_paths; | |
2463 | else if (STR_IN_SET(name, "ReadOnlyDirectories", "ReadOnlyPaths")) | |
2464 | dirs = &c->read_only_paths; | |
2465 | else /* "InaccessiblePaths" */ | |
2466 | dirs = &c->inaccessible_paths; | |
08596068 | 2467 | |
7b943bb7 | 2468 | if (strv_isempty(l)) { |
08596068 | 2469 | *dirs = strv_free(*dirs); |
2e59b241 | 2470 | unit_write_settingf(u, flags, name, "%s=", name); |
08596068 | 2471 | } else { |
2e59b241 | 2472 | _cleanup_free_ char *joined = NULL; |
08596068 | 2473 | |
2e59b241 | 2474 | joined = unit_concat_strv(l, UNIT_ESCAPE_SPECIFIERS); |
08596068 EV |
2475 | if (!joined) |
2476 | return -ENOMEM; | |
2477 | ||
2e59b241 LP |
2478 | r = strv_extend_strv(dirs, l, true); |
2479 | if (r < 0) | |
2480 | return -ENOMEM; | |
08596068 | 2481 | |
2e59b241 LP |
2482 | unit_write_settingf(u, flags, name, "%s=%s", name, joined); |
2483 | } | |
08596068 EV |
2484 | } |
2485 | ||
2486 | return 1; | |
2487 | ||
3536f49e | 2488 | } else if (STR_IN_SET(name, "RuntimeDirectory", "StateDirectory", "CacheDirectory", "LogsDirectory", "ConfigurationDirectory")) { |
fa21b5e3 EV |
2489 | _cleanup_strv_free_ char **l = NULL; |
2490 | char **p; | |
2491 | ||
2492 | r = sd_bus_message_read_strv(message, &l); | |
2493 | if (r < 0) | |
2494 | return r; | |
2495 | ||
2496 | STRV_FOREACH(p, l) { | |
8994a117 YW |
2497 | if (!path_is_normalized(*p)) |
2498 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "%s= path is not normalized: %s", name, *p); | |
2499 | ||
2500 | if (path_is_absolute(*p)) | |
2501 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "%s= path is absolute: %s", name, *p); | |
2502 | ||
2503 | if (path_startswith(*p, "private")) | |
2504 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "%s= path can't be 'private': %s", name, *p); | |
fa21b5e3 EV |
2505 | } |
2506 | ||
2e59b241 | 2507 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
3536f49e | 2508 | ExecDirectoryType i; |
b1ea85dc | 2509 | ExecDirectory *d; |
3536f49e | 2510 | |
b1ea85dc LP |
2511 | assert_se((i = exec_directory_type_from_string(name)) >= 0); |
2512 | d = c->directories + i; | |
fa21b5e3 EV |
2513 | |
2514 | if (strv_isempty(l)) { | |
b1ea85dc | 2515 | d->paths = strv_free(d->paths); |
2e59b241 | 2516 | unit_write_settingf(u, flags, name, "%s=", name); |
fa21b5e3 | 2517 | } else { |
2e59b241 LP |
2518 | _cleanup_free_ char *joined = NULL; |
2519 | ||
b1ea85dc | 2520 | r = strv_extend_strv(&d->paths, l, true); |
fa21b5e3 | 2521 | if (r < 0) |
c425c7c2 | 2522 | return r; |
fa21b5e3 | 2523 | |
2e59b241 | 2524 | joined = unit_concat_strv(l, UNIT_ESCAPE_SPECIFIERS); |
fa21b5e3 EV |
2525 | if (!joined) |
2526 | return -ENOMEM; | |
2527 | ||
2e59b241 | 2528 | unit_write_settingf(u, flags, name, "%s=%s", name, joined); |
fa21b5e3 EV |
2529 | } |
2530 | } | |
2531 | ||
2532 | return 1; | |
2533 | ||
cffaed83 YW |
2534 | } else if (STR_IN_SET(name, "AppArmorProfile", "SmackProcessLabel")) { |
2535 | int ignore; | |
2536 | const char *s; | |
2537 | ||
280921f2 | 2538 | r = sd_bus_message_read(message, "(bs)", &ignore, &s); |
cffaed83 YW |
2539 | if (r < 0) |
2540 | return r; | |
2541 | ||
2e59b241 | 2542 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
cffaed83 YW |
2543 | char **p; |
2544 | bool *b; | |
2545 | ||
2546 | if (streq(name, "AppArmorProfile")) { | |
2547 | p = &c->apparmor_profile; | |
2548 | b = &c->apparmor_profile_ignore; | |
2549 | } else { /* "SmackProcessLabel" */ | |
2550 | p = &c->smack_process_label; | |
2551 | b = &c->smack_process_label_ignore; | |
2552 | } | |
2553 | ||
2554 | if (isempty(s)) { | |
2555 | *p = mfree(*p); | |
2556 | *b = false; | |
2557 | } else { | |
2558 | if (free_and_strdup(p, s) < 0) | |
2559 | return -ENOMEM; | |
2560 | *b = ignore; | |
2561 | } | |
2562 | ||
2e59b241 | 2563 | unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "%s=%s%s", name, ignore ? "-" : "", strempty(s)); |
cffaed83 YW |
2564 | } |
2565 | ||
2566 | return 1; | |
2567 | ||
d2d6c096 | 2568 | } else if (STR_IN_SET(name, "BindPaths", "BindReadOnlyPaths")) { |
ec04aef4 | 2569 | char *source, *destination; |
4ff4c98a YW |
2570 | int ignore_enoent; |
2571 | uint64_t mount_flags; | |
2572 | bool empty = true; | |
d2d6c096 LP |
2573 | |
2574 | r = sd_bus_message_enter_container(message, 'a', "(ssbt)"); | |
2575 | if (r < 0) | |
2576 | return r; | |
2577 | ||
4ff4c98a | 2578 | while ((r = sd_bus_message_read(message, "(ssbt)", &source, &destination, &ignore_enoent, &mount_flags)) > 0) { |
d2d6c096 LP |
2579 | |
2580 | if (!path_is_absolute(source)) | |
2581 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Source path %s is not absolute.", source); | |
2582 | if (!path_is_absolute(destination)) | |
91d910e3 | 2583 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Destination path %s is not absolute.", destination); |
d2d6c096 LP |
2584 | if (!IN_SET(mount_flags, 0, MS_REC)) |
2585 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Unknown mount flags."); | |
2586 | ||
2e59b241 | 2587 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
d2d6c096 LP |
2588 | r = bind_mount_add(&c->bind_mounts, &c->n_bind_mounts, |
2589 | &(BindMount) { | |
ec04aef4 TM |
2590 | .source = source, |
2591 | .destination = destination, | |
d2d6c096 LP |
2592 | .read_only = !!strstr(name, "ReadOnly"), |
2593 | .recursive = !!(mount_flags & MS_REC), | |
2594 | .ignore_enoent = ignore_enoent, | |
2595 | }); | |
2596 | if (r < 0) | |
2597 | return r; | |
2598 | ||
2e59b241 LP |
2599 | unit_write_settingf( |
2600 | u, flags|UNIT_ESCAPE_SPECIFIERS, name, | |
d2d6c096 LP |
2601 | "%s=%s%s:%s:%s", |
2602 | name, | |
2603 | ignore_enoent ? "-" : "", | |
2604 | source, | |
2605 | destination, | |
2606 | (mount_flags & MS_REC) ? "rbind" : "norbind"); | |
2607 | } | |
2608 | ||
2609 | empty = false; | |
2610 | } | |
2611 | if (r < 0) | |
2612 | return r; | |
2613 | ||
2614 | r = sd_bus_message_exit_container(message); | |
2615 | if (r < 0) | |
2616 | return r; | |
2617 | ||
2618 | if (empty) { | |
2619 | bind_mount_free_many(c->bind_mounts, c->n_bind_mounts); | |
2620 | c->bind_mounts = NULL; | |
2621 | c->n_bind_mounts = 0; | |
2e59b241 LP |
2622 | |
2623 | unit_write_settingf(u, flags, name, "%s=", name); | |
d2d6c096 LP |
2624 | } |
2625 | ||
784ad252 YW |
2626 | return 1; |
2627 | ||
2628 | } else if (streq(name, "TemporaryFileSystem")) { | |
2629 | const char *path, *options; | |
2630 | bool empty = true; | |
2631 | ||
2632 | r = sd_bus_message_enter_container(message, 'a', "(ss)"); | |
2633 | if (r < 0) | |
2634 | return r; | |
2635 | ||
2636 | while ((r = sd_bus_message_read(message, "(ss)", &path, &options)) > 0) { | |
2637 | ||
2638 | if (!path_is_absolute(path)) | |
2639 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Mount point %s is not absolute.", path); | |
2640 | ||
2641 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
2642 | r = temporary_filesystem_add(&c->temporary_filesystems, &c->n_temporary_filesystems, path, options); | |
2643 | if (r < 0) | |
2644 | return r; | |
2645 | ||
2646 | unit_write_settingf( | |
2647 | u, flags|UNIT_ESCAPE_SPECIFIERS, name, | |
2648 | "%s=%s:%s", | |
2649 | name, | |
2650 | path, | |
2651 | options); | |
2652 | } | |
2653 | ||
2654 | empty = false; | |
2655 | } | |
2656 | if (r < 0) | |
2657 | return r; | |
2658 | ||
2659 | r = sd_bus_message_exit_container(message); | |
2660 | if (r < 0) | |
2661 | return r; | |
2662 | ||
2663 | if (empty) { | |
2664 | temporary_filesystem_free_many(c->temporary_filesystems, c->n_temporary_filesystems); | |
2665 | c->temporary_filesystems = NULL; | |
2666 | c->n_temporary_filesystems = 0; | |
2667 | ||
2668 | unit_write_settingf(u, flags, name, "%s=", name); | |
2669 | } | |
2670 | ||
83555251 | 2671 | return 1; |
d2d6c096 | 2672 | |
6550c24c LP |
2673 | } else if ((suffix = startswith(name, "Limit"))) { |
2674 | const char *soft = NULL; | |
2675 | int ri; | |
cab2aca3 | 2676 | |
6550c24c LP |
2677 | ri = rlimit_from_string(suffix); |
2678 | if (ri < 0) { | |
2679 | soft = endswith(suffix, "Soft"); | |
2680 | if (soft) { | |
2681 | const char *n; | |
cab2aca3 | 2682 | |
6550c24c LP |
2683 | n = strndupa(suffix, soft - suffix); |
2684 | ri = rlimit_from_string(n); | |
2685 | if (ri >= 0) | |
2686 | name = strjoina("Limit", n); | |
2687 | } | |
cab2aca3 | 2688 | } |
d584f638 | 2689 | |
6550c24c LP |
2690 | if (ri >= 0) { |
2691 | uint64_t rl; | |
2692 | rlim_t x; | |
d584f638 | 2693 | |
6550c24c | 2694 | r = sd_bus_message_read(message, "t", &rl); |
cab2aca3 LP |
2695 | if (r < 0) |
2696 | return r; | |
d584f638 | 2697 | |
6550c24c LP |
2698 | if (rl == (uint64_t) -1) |
2699 | x = RLIM_INFINITY; | |
cab2aca3 | 2700 | else { |
6550c24c LP |
2701 | x = (rlim_t) rl; |
2702 | ||
2703 | if ((uint64_t) x != rl) | |
2704 | return -ERANGE; | |
d584f638 LP |
2705 | } |
2706 | ||
6550c24c LP |
2707 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
2708 | _cleanup_free_ char *f = NULL; | |
2709 | struct rlimit nl; | |
2710 | ||
2711 | if (c->rlimit[ri]) { | |
2712 | nl = *c->rlimit[ri]; | |
2713 | ||
2714 | if (soft) | |
2715 | nl.rlim_cur = x; | |
2716 | else | |
2717 | nl.rlim_max = x; | |
2718 | } else | |
2719 | /* When the resource limit is not initialized yet, then assign the value to both fields */ | |
2720 | nl = (struct rlimit) { | |
2721 | .rlim_cur = x, | |
2722 | .rlim_max = x, | |
2723 | }; | |
2724 | ||
2725 | r = rlimit_format(&nl, &f); | |
2726 | if (r < 0) | |
2727 | return r; | |
2728 | ||
2729 | if (c->rlimit[ri]) | |
2730 | *c->rlimit[ri] = nl; | |
2731 | else { | |
2732 | c->rlimit[ri] = newdup(struct rlimit, &nl, 1); | |
2733 | if (!c->rlimit[ri]) | |
2734 | return -ENOMEM; | |
2735 | } | |
2736 | ||
2737 | unit_write_settingf(u, flags, name, "%s=%s", name, f); | |
2738 | } | |
2739 | ||
2740 | return 1; | |
d584f638 LP |
2741 | } |
2742 | ||
c7040b5d LP |
2743 | } |
2744 | ||
2745 | return 0; | |
2746 | } |