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