]>
Commit | Line | Data |
---|---|---|
db9ecf05 | 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
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" |
40af3d02 | 12 | #include "bus-get-properties.h" |
cffaed83 | 13 | #include "cap-list.h" |
d3070fbd | 14 | #include "capability-util.h" |
501941aa | 15 | #include "cpu-set-util.h" |
786d19fd | 16 | #include "creds-util.h" |
3ffd4af2 | 17 | #include "dbus-execute.h" |
7e2a3fcc | 18 | #include "dbus-util.h" |
c7040b5d | 19 | #include "env-util.h" |
cffaed83 | 20 | #include "errno-list.h" |
2e59b241 | 21 | #include "escape.h" |
3ffd4af2 LP |
22 | #include "execute.h" |
23 | #include "fd-util.h" | |
24 | #include "fileio.h" | |
08f3be7a | 25 | #include "hexdecoct.h" |
d3070fbd | 26 | #include "io-util.h" |
adce225a | 27 | #include "journal-file.h" |
5bead76e | 28 | #include "missing_ioprio.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" |
cc86a278 | 40 | #include "stat-util.h" |
6bedfcbb | 41 | #include "strv.h" |
7ccbd1ae | 42 | #include "syslog-util.h" |
f900f582 | 43 | #include "unit-printf.h" |
6f3e7985 | 44 | #include "user-util.h" |
6bedfcbb | 45 | #include "utf8.h" |
57183d11 | 46 | |
718db961 | 47 | BUS_DEFINE_PROPERTY_GET_ENUM(bus_property_get_exec_output, exec_output, ExecOutput); |
718db961 | 48 | static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_input, exec_input, ExecInput); |
023a4f67 | 49 | static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_utmp_mode, exec_utmp_mode, ExecUtmpMode); |
53f47dfc | 50 | static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_preserve_mode, exec_preserve_mode, ExecPreserveMode); |
b1edf445 | 51 | static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_keyring_mode, exec_keyring_mode, ExecKeyringMode); |
4e399953 LP |
52 | static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_protect_proc, protect_proc, ProtectProc); |
53 | static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_proc_subset, proc_subset, ProcSubset); | |
73b84e92 YW |
54 | static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_protect_home, protect_home, ProtectHome); |
55 | static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_protect_system, protect_system, ProtectSystem); | |
491eecb3 | 56 | static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_personality, personality, unsigned long); |
019b34ca | 57 | static BUS_DEFINE_PROPERTY_GET(property_get_ioprio, "i", ExecContext, exec_context_get_effective_ioprio); |
5e98086d | 58 | static BUS_DEFINE_PROPERTY_GET(property_get_mount_apivfs, "b", ExecContext, exec_context_get_effective_mount_apivfs); |
5bead76e ZJS |
59 | static BUS_DEFINE_PROPERTY_GET2(property_get_ioprio_class, "i", ExecContext, exec_context_get_effective_ioprio, ioprio_prio_class); |
60 | static BUS_DEFINE_PROPERTY_GET2(property_get_ioprio_priority, "i", ExecContext, exec_context_get_effective_ioprio, ioprio_prio_data); | |
92c23c5a YW |
61 | static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_empty_string, "s", NULL); |
62 | static BUS_DEFINE_PROPERTY_GET_REF(property_get_syslog_level, "i", int, LOG_PRI); | |
63 | static BUS_DEFINE_PROPERTY_GET_REF(property_get_syslog_facility, "i", int, LOG_FAC); | |
e2b2fb7f MS |
64 | static BUS_DEFINE_PROPERTY_GET(property_get_cpu_affinity_from_numa, "b", ExecContext, exec_context_get_cpu_affinity_from_numa); |
65 | ||
718db961 LP |
66 | static int property_get_environment_files( |
67 | sd_bus *bus, | |
68 | const char *path, | |
69 | const char *interface, | |
70 | const char *property, | |
71 | sd_bus_message *reply, | |
ebcf1f97 LP |
72 | void *userdata, |
73 | sd_bus_error *error) { | |
8c7be95e | 74 | |
718db961 LP |
75 | ExecContext *c = userdata; |
76 | char **j; | |
77 | int r; | |
8c7be95e | 78 | |
718db961 LP |
79 | assert(bus); |
80 | assert(reply); | |
81 | assert(c); | |
82 | ||
83 | r = sd_bus_message_open_container(reply, 'a', "(sb)"); | |
84 | if (r < 0) | |
85 | return r; | |
8c7be95e | 86 | |
718db961 LP |
87 | STRV_FOREACH(j, c->environment_files) { |
88 | const char *fn = *j; | |
8c7be95e | 89 | |
718db961 LP |
90 | r = sd_bus_message_append(reply, "(sb)", fn[0] == '-' ? fn + 1 : fn, fn[0] == '-'); |
91 | if (r < 0) | |
92 | return r; | |
8c7be95e LP |
93 | } |
94 | ||
718db961 LP |
95 | return sd_bus_message_close_container(reply); |
96 | } | |
97 | ||
718db961 LP |
98 | static int property_get_oom_score_adjust( |
99 | sd_bus *bus, | |
100 | const char *path, | |
101 | const char *interface, | |
102 | const char *property, | |
103 | sd_bus_message *reply, | |
ebcf1f97 LP |
104 | void *userdata, |
105 | sd_bus_error *error) { | |
718db961 | 106 | |
718db961 | 107 | ExecContext *c = userdata; |
2c37c613 | 108 | int r, n; |
82c121a4 | 109 | |
718db961 LP |
110 | assert(bus); |
111 | assert(reply); | |
82c121a4 LP |
112 | assert(c); |
113 | ||
dd6c17b1 LP |
114 | if (c->oom_score_adjust_set) |
115 | n = c->oom_score_adjust; | |
82c121a4 | 116 | else { |
82c121a4 | 117 | n = 0; |
2c37c613 | 118 | r = get_oom_score_adjust(&n); |
b94fb74b ZJS |
119 | if (r < 0) |
120 | log_debug_errno(r, "Failed to read /proc/self/oom_score_adj, ignoring: %m"); | |
82c121a4 LP |
121 | } |
122 | ||
718db961 | 123 | return sd_bus_message_append(reply, "i", n); |
82c121a4 LP |
124 | } |
125 | ||
ad21e542 ZJS |
126 | static int property_get_coredump_filter( |
127 | sd_bus *bus, | |
128 | const char *path, | |
129 | const char *interface, | |
130 | const char *property, | |
131 | sd_bus_message *reply, | |
132 | void *userdata, | |
133 | sd_bus_error *error) { | |
134 | ||
135 | ExecContext *c = userdata; | |
136 | uint64_t n; | |
137 | int r; | |
138 | ||
139 | assert(bus); | |
140 | assert(reply); | |
141 | assert(c); | |
142 | ||
143 | if (c->coredump_filter_set) | |
144 | n = c->coredump_filter; | |
145 | else { | |
146 | _cleanup_free_ char *t = NULL; | |
147 | ||
148 | n = COREDUMP_FILTER_MASK_DEFAULT; | |
149 | r = read_one_line_file("/proc/self/coredump_filter", &t); | |
150 | if (r < 0) | |
151 | log_debug_errno(r, "Failed to read /proc/self/coredump_filter, ignoring: %m"); | |
152 | else { | |
153 | r = safe_atoux64(t, &n); | |
154 | if (r < 0) | |
155 | log_debug_errno(r, "Failed to parse \"%s\" from /proc/self/coredump_filter, ignoring: %m", t); | |
156 | } | |
157 | } | |
158 | ||
159 | return sd_bus_message_append(reply, "t", n); | |
160 | } | |
161 | ||
718db961 LP |
162 | static int property_get_nice( |
163 | sd_bus *bus, | |
164 | const char *path, | |
165 | const char *interface, | |
166 | const char *property, | |
167 | sd_bus_message *reply, | |
ebcf1f97 LP |
168 | void *userdata, |
169 | sd_bus_error *error) { | |
718db961 | 170 | |
718db961 | 171 | ExecContext *c = userdata; |
82c121a4 LP |
172 | int32_t n; |
173 | ||
718db961 LP |
174 | assert(bus); |
175 | assert(reply); | |
82c121a4 LP |
176 | assert(c); |
177 | ||
178 | if (c->nice_set) | |
179 | n = c->nice; | |
718db961 LP |
180 | else { |
181 | errno = 0; | |
82c121a4 | 182 | n = getpriority(PRIO_PROCESS, 0); |
b3267152 | 183 | if (errno > 0) |
718db961 LP |
184 | n = 0; |
185 | } | |
82c121a4 | 186 | |
718db961 | 187 | return sd_bus_message_append(reply, "i", n); |
82c121a4 LP |
188 | } |
189 | ||
718db961 LP |
190 | static int property_get_cpu_sched_policy( |
191 | sd_bus *bus, | |
192 | const char *path, | |
193 | const char *interface, | |
194 | const char *property, | |
195 | sd_bus_message *reply, | |
ebcf1f97 LP |
196 | void *userdata, |
197 | sd_bus_error *error) { | |
718db961 LP |
198 | |
199 | ExecContext *c = userdata; | |
82c121a4 LP |
200 | int32_t n; |
201 | ||
718db961 LP |
202 | assert(bus); |
203 | assert(reply); | |
82c121a4 LP |
204 | assert(c); |
205 | ||
206 | if (c->cpu_sched_set) | |
207 | n = c->cpu_sched_policy; | |
718db961 | 208 | else { |
82c121a4 | 209 | n = sched_getscheduler(0); |
718db961 LP |
210 | if (n < 0) |
211 | n = SCHED_OTHER; | |
212 | } | |
82c121a4 | 213 | |
718db961 | 214 | return sd_bus_message_append(reply, "i", n); |
82c121a4 LP |
215 | } |
216 | ||
718db961 LP |
217 | static int property_get_cpu_sched_priority( |
218 | sd_bus *bus, | |
219 | const char *path, | |
220 | const char *interface, | |
221 | const char *property, | |
222 | sd_bus_message *reply, | |
ebcf1f97 LP |
223 | void *userdata, |
224 | sd_bus_error *error) { | |
718db961 LP |
225 | |
226 | ExecContext *c = userdata; | |
82c121a4 LP |
227 | int32_t n; |
228 | ||
718db961 LP |
229 | assert(bus); |
230 | assert(reply); | |
82c121a4 LP |
231 | assert(c); |
232 | ||
233 | if (c->cpu_sched_set) | |
234 | n = c->cpu_sched_priority; | |
235 | else { | |
b92bea5d | 236 | struct sched_param p = {}; |
82c121a4 | 237 | |
82c121a4 LP |
238 | if (sched_getparam(0, &p) >= 0) |
239 | n = p.sched_priority; | |
e62d8c39 ZJS |
240 | else |
241 | n = 0; | |
82c121a4 LP |
242 | } |
243 | ||
718db961 | 244 | return sd_bus_message_append(reply, "i", n); |
82c121a4 LP |
245 | } |
246 | ||
718db961 LP |
247 | static int property_get_cpu_affinity( |
248 | sd_bus *bus, | |
249 | const char *path, | |
250 | const char *interface, | |
251 | const char *property, | |
252 | sd_bus_message *reply, | |
ebcf1f97 LP |
253 | void *userdata, |
254 | sd_bus_error *error) { | |
82c121a4 | 255 | |
718db961 | 256 | ExecContext *c = userdata; |
e2b2fb7f | 257 | _cleanup_(cpu_set_reset) CPUSet s = {}; |
75e40119 MS |
258 | _cleanup_free_ uint8_t *array = NULL; |
259 | size_t allocated; | |
82c121a4 | 260 | |
718db961 LP |
261 | assert(bus); |
262 | assert(reply); | |
263 | assert(c); | |
82c121a4 | 264 | |
e2b2fb7f MS |
265 | if (c->cpu_affinity_from_numa) { |
266 | int r; | |
267 | ||
268 | r = numa_to_cpu_set(&c->numa_policy, &s); | |
269 | if (r < 0) | |
270 | return r; | |
271 | } | |
272 | ||
273 | (void) cpu_set_to_dbus(c->cpu_affinity_from_numa ? &s : &c->cpu_set, &array, &allocated); | |
274 | ||
75e40119 | 275 | return sd_bus_message_append_array(reply, 'y', array, allocated); |
82c121a4 LP |
276 | } |
277 | ||
b070c7c0 MS |
278 | static int property_get_numa_mask( |
279 | sd_bus *bus, | |
280 | const char *path, | |
281 | const char *interface, | |
282 | const char *property, | |
283 | sd_bus_message *reply, | |
284 | void *userdata, | |
285 | sd_bus_error *error) { | |
286 | ||
287 | ExecContext *c = userdata; | |
288 | _cleanup_free_ uint8_t *array = NULL; | |
289 | size_t allocated; | |
290 | ||
291 | assert(bus); | |
292 | assert(reply); | |
293 | assert(c); | |
294 | ||
295 | (void) cpu_set_to_dbus(&c->numa_policy.nodes, &array, &allocated); | |
296 | ||
297 | return sd_bus_message_append_array(reply, 'y', array, allocated); | |
298 | } | |
299 | ||
300 | static int property_get_numa_policy( | |
301 | sd_bus *bus, | |
302 | const char *path, | |
303 | const char *interface, | |
304 | const char *property, | |
305 | sd_bus_message *reply, | |
306 | void *userdata, | |
307 | sd_bus_error *error) { | |
308 | ExecContext *c = userdata; | |
309 | int32_t policy; | |
310 | ||
311 | assert(bus); | |
312 | assert(reply); | |
313 | assert(c); | |
314 | ||
315 | policy = numa_policy_get_type(&c->numa_policy); | |
316 | ||
317 | return sd_bus_message_append_basic(reply, 'i', &policy); | |
318 | } | |
319 | ||
718db961 LP |
320 | static int property_get_timer_slack_nsec( |
321 | sd_bus *bus, | |
322 | const char *path, | |
323 | const char *interface, | |
324 | const char *property, | |
325 | sd_bus_message *reply, | |
ebcf1f97 LP |
326 | void *userdata, |
327 | sd_bus_error *error) { | |
718db961 LP |
328 | |
329 | ExecContext *c = userdata; | |
82c121a4 LP |
330 | uint64_t u; |
331 | ||
718db961 LP |
332 | assert(bus); |
333 | assert(reply); | |
82c121a4 LP |
334 | assert(c); |
335 | ||
3a43da28 | 336 | if (c->timer_slack_nsec != NSEC_INFINITY) |
03fae018 | 337 | u = (uint64_t) c->timer_slack_nsec; |
82c121a4 LP |
338 | else |
339 | u = (uint64_t) prctl(PR_GET_TIMERSLACK); | |
340 | ||
718db961 | 341 | return sd_bus_message_append(reply, "t", u); |
82c121a4 LP |
342 | } |
343 | ||
718db961 LP |
344 | static int property_get_syscall_filter( |
345 | sd_bus *bus, | |
346 | const char *path, | |
347 | const char *interface, | |
348 | const char *property, | |
349 | sd_bus_message *reply, | |
ebcf1f97 LP |
350 | void *userdata, |
351 | sd_bus_error *error) { | |
82c121a4 | 352 | |
17df7223 LP |
353 | ExecContext *c = userdata; |
354 | _cleanup_strv_free_ char **l = NULL; | |
57183d11 LP |
355 | int r; |
356 | ||
349cc4a5 | 357 | #if HAVE_SECCOMP |
8cfa775f | 358 | void *id, *val; |
351a19b1 | 359 | #endif |
17df7223 LP |
360 | |
361 | assert(bus); | |
362 | assert(reply); | |
363 | assert(c); | |
364 | ||
57183d11 LP |
365 | r = sd_bus_message_open_container(reply, 'r', "bas"); |
366 | if (r < 0) | |
367 | return r; | |
368 | ||
6b000af4 | 369 | r = sd_bus_message_append(reply, "b", c->syscall_allow_list); |
57183d11 LP |
370 | if (r < 0) |
371 | return r; | |
372 | ||
349cc4a5 | 373 | #if HAVE_SECCOMP |
90e74a66 | 374 | HASHMAP_FOREACH_KEY(val, id, c->syscall_filter) { |
8cfa775f YW |
375 | _cleanup_free_ char *name = NULL; |
376 | const char *e = NULL; | |
377 | char *s; | |
378 | int num = PTR_TO_INT(val); | |
17df7223 LP |
379 | |
380 | name = seccomp_syscall_resolve_num_arch(SCMP_ARCH_NATIVE, PTR_TO_INT(id) - 1); | |
381 | if (!name) | |
382 | continue; | |
383 | ||
8cfa775f | 384 | if (num >= 0) { |
005bfaf1 | 385 | e = seccomp_errno_or_action_to_string(num); |
8cfa775f YW |
386 | if (e) { |
387 | s = strjoin(name, ":", e); | |
388 | if (!s) | |
389 | return -ENOMEM; | |
390 | } else { | |
391 | r = asprintf(&s, "%s:%d", name, num); | |
392 | if (r < 0) | |
393 | return -ENOMEM; | |
394 | } | |
ae2a15bc LP |
395 | } else |
396 | s = TAKE_PTR(name); | |
8cfa775f YW |
397 | |
398 | r = strv_consume(&l, s); | |
6e18964d ZJS |
399 | if (r < 0) |
400 | return r; | |
17df7223 | 401 | } |
351a19b1 | 402 | #endif |
17df7223 LP |
403 | |
404 | strv_sort(l); | |
405 | ||
57183d11 LP |
406 | r = sd_bus_message_append_strv(reply, l); |
407 | if (r < 0) | |
408 | return r; | |
17df7223 | 409 | |
57183d11 LP |
410 | return sd_bus_message_close_container(reply); |
411 | } | |
17df7223 | 412 | |
9df2cdd8 TM |
413 | static int property_get_syscall_log( |
414 | sd_bus *bus, | |
415 | const char *path, | |
416 | const char *interface, | |
417 | const char *property, | |
418 | sd_bus_message *reply, | |
419 | void *userdata, | |
420 | sd_bus_error *error) { | |
421 | ||
422 | ExecContext *c = userdata; | |
423 | _cleanup_strv_free_ char **l = NULL; | |
424 | int r; | |
425 | ||
426 | #if HAVE_SECCOMP | |
427 | void *id, *val; | |
428 | #endif | |
429 | ||
430 | assert(bus); | |
431 | assert(reply); | |
432 | assert(c); | |
433 | ||
434 | r = sd_bus_message_open_container(reply, 'r', "bas"); | |
435 | if (r < 0) | |
436 | return r; | |
437 | ||
438 | r = sd_bus_message_append(reply, "b", c->syscall_log_allow_list); | |
439 | if (r < 0) | |
440 | return r; | |
441 | ||
442 | #if HAVE_SECCOMP | |
443 | HASHMAP_FOREACH_KEY(val, id, c->syscall_log) { | |
444 | char *name = NULL; | |
445 | ||
446 | name = seccomp_syscall_resolve_num_arch(SCMP_ARCH_NATIVE, PTR_TO_INT(id) - 1); | |
447 | if (!name) | |
448 | continue; | |
449 | ||
450 | r = strv_consume(&l, name); | |
451 | if (r < 0) | |
452 | return r; | |
453 | } | |
454 | #endif | |
455 | ||
456 | strv_sort(l); | |
457 | ||
458 | r = sd_bus_message_append_strv(reply, l); | |
459 | if (r < 0) | |
460 | return r; | |
461 | ||
462 | return sd_bus_message_close_container(reply); | |
463 | } | |
464 | ||
57183d11 LP |
465 | static int property_get_syscall_archs( |
466 | sd_bus *bus, | |
467 | const char *path, | |
468 | const char *interface, | |
469 | const char *property, | |
470 | sd_bus_message *reply, | |
471 | void *userdata, | |
472 | sd_bus_error *error) { | |
473 | ||
474 | ExecContext *c = userdata; | |
475 | _cleanup_strv_free_ char **l = NULL; | |
476 | int r; | |
477 | ||
349cc4a5 | 478 | #if HAVE_SECCOMP |
57183d11 LP |
479 | void *id; |
480 | #endif | |
481 | ||
482 | assert(bus); | |
483 | assert(reply); | |
484 | assert(c); | |
17df7223 | 485 | |
349cc4a5 | 486 | #if HAVE_SECCOMP |
90e74a66 | 487 | SET_FOREACH(id, c->syscall_archs) { |
57183d11 LP |
488 | const char *name; |
489 | ||
490 | name = seccomp_arch_to_string(PTR_TO_UINT32(id) - 1); | |
491 | if (!name) | |
492 | continue; | |
493 | ||
494 | r = strv_extend(&l, name); | |
495 | if (r < 0) | |
496 | return -ENOMEM; | |
17df7223 | 497 | } |
57183d11 LP |
498 | #endif |
499 | ||
500 | strv_sort(l); | |
501 | ||
502 | r = sd_bus_message_append_strv(reply, l); | |
503 | if (r < 0) | |
504 | return r; | |
17df7223 | 505 | |
57183d11 | 506 | return 0; |
17df7223 LP |
507 | } |
508 | ||
5f8640fb LP |
509 | static int property_get_selinux_context( |
510 | sd_bus *bus, | |
511 | const char *path, | |
512 | const char *interface, | |
513 | const char *property, | |
514 | sd_bus_message *reply, | |
515 | void *userdata, | |
516 | sd_bus_error *error) { | |
517 | ||
518 | ExecContext *c = userdata; | |
519 | ||
520 | assert(bus); | |
521 | assert(reply); | |
522 | assert(c); | |
523 | ||
524 | return sd_bus_message_append(reply, "(bs)", c->selinux_context_ignore, c->selinux_context); | |
525 | } | |
526 | ||
eef65bf3 MS |
527 | static int property_get_apparmor_profile( |
528 | sd_bus *bus, | |
529 | const char *path, | |
530 | const char *interface, | |
531 | const char *property, | |
532 | sd_bus_message *reply, | |
533 | void *userdata, | |
534 | sd_bus_error *error) { | |
535 | ||
536 | ExecContext *c = userdata; | |
537 | ||
538 | assert(bus); | |
539 | assert(reply); | |
540 | assert(c); | |
541 | ||
542 | return sd_bus_message_append(reply, "(bs)", c->apparmor_profile_ignore, c->apparmor_profile); | |
543 | } | |
544 | ||
2ca620c4 WC |
545 | static int property_get_smack_process_label( |
546 | sd_bus *bus, | |
547 | const char *path, | |
548 | const char *interface, | |
549 | const char *property, | |
550 | sd_bus_message *reply, | |
551 | void *userdata, | |
552 | sd_bus_error *error) { | |
553 | ||
554 | ExecContext *c = userdata; | |
555 | ||
556 | assert(bus); | |
557 | assert(reply); | |
558 | assert(c); | |
559 | ||
560 | return sd_bus_message_append(reply, "(bs)", c->smack_process_label_ignore, c->smack_process_label); | |
561 | } | |
562 | ||
4298d0b5 LP |
563 | static int property_get_address_families( |
564 | sd_bus *bus, | |
565 | const char *path, | |
566 | const char *interface, | |
567 | const char *property, | |
568 | sd_bus_message *reply, | |
569 | void *userdata, | |
570 | sd_bus_error *error) { | |
571 | ||
572 | ExecContext *c = userdata; | |
573 | _cleanup_strv_free_ char **l = NULL; | |
4298d0b5 LP |
574 | void *af; |
575 | int r; | |
576 | ||
577 | assert(bus); | |
578 | assert(reply); | |
579 | assert(c); | |
580 | ||
581 | r = sd_bus_message_open_container(reply, 'r', "bas"); | |
582 | if (r < 0) | |
583 | return r; | |
584 | ||
6b000af4 | 585 | r = sd_bus_message_append(reply, "b", c->address_families_allow_list); |
4298d0b5 LP |
586 | if (r < 0) |
587 | return r; | |
588 | ||
90e74a66 | 589 | SET_FOREACH(af, c->address_families) { |
4298d0b5 LP |
590 | const char *name; |
591 | ||
592 | name = af_to_name(PTR_TO_INT(af)); | |
593 | if (!name) | |
594 | continue; | |
595 | ||
596 | r = strv_extend(&l, name); | |
597 | if (r < 0) | |
598 | return -ENOMEM; | |
599 | } | |
600 | ||
601 | strv_sort(l); | |
602 | ||
603 | r = sd_bus_message_append_strv(reply, l); | |
604 | if (r < 0) | |
605 | return r; | |
606 | ||
607 | return sd_bus_message_close_container(reply); | |
608 | } | |
609 | ||
5f5d8eab LP |
610 | static int property_get_working_directory( |
611 | sd_bus *bus, | |
612 | const char *path, | |
613 | const char *interface, | |
614 | const char *property, | |
615 | sd_bus_message *reply, | |
616 | void *userdata, | |
617 | sd_bus_error *error) { | |
618 | ||
619 | ExecContext *c = userdata; | |
620 | const char *wd; | |
621 | ||
622 | assert(bus); | |
623 | assert(reply); | |
624 | assert(c); | |
625 | ||
626 | if (c->working_directory_home) | |
627 | wd = "~"; | |
628 | else | |
629 | wd = c->working_directory; | |
630 | ||
631 | if (c->working_directory_missing_ok) | |
632 | wd = strjoina("!", wd); | |
633 | ||
634 | return sd_bus_message_append(reply, "s", wd); | |
635 | } | |
636 | ||
5073ff6b | 637 | static int property_get_stdio_fdname( |
52c239d7 LB |
638 | sd_bus *bus, |
639 | const char *path, | |
640 | const char *interface, | |
641 | const char *property, | |
642 | sd_bus_message *reply, | |
643 | void *userdata, | |
644 | sd_bus_error *error) { | |
645 | ||
646 | ExecContext *c = userdata; | |
5073ff6b | 647 | int fileno; |
52c239d7 LB |
648 | |
649 | assert(bus); | |
650 | assert(c); | |
651 | assert(property); | |
652 | assert(reply); | |
653 | ||
5073ff6b LP |
654 | if (streq(property, "StandardInputFileDescriptorName")) |
655 | fileno = STDIN_FILENO; | |
656 | else if (streq(property, "StandardOutputFileDescriptorName")) | |
657 | fileno = STDOUT_FILENO; | |
658 | else { | |
659 | assert(streq(property, "StandardErrorFileDescriptorName")); | |
660 | fileno = STDERR_FILENO; | |
661 | } | |
52c239d7 | 662 | |
5073ff6b | 663 | return sd_bus_message_append(reply, "s", exec_context_fdname(c, fileno)); |
52c239d7 LB |
664 | } |
665 | ||
08f3be7a | 666 | static int property_get_input_data( |
52c239d7 LB |
667 | sd_bus *bus, |
668 | const char *path, | |
669 | const char *interface, | |
670 | const char *property, | |
671 | sd_bus_message *reply, | |
672 | void *userdata, | |
673 | sd_bus_error *error) { | |
674 | ||
675 | ExecContext *c = userdata; | |
52c239d7 LB |
676 | |
677 | assert(bus); | |
678 | assert(c); | |
679 | assert(property); | |
680 | assert(reply); | |
681 | ||
08f3be7a | 682 | return sd_bus_message_append_array(reply, 'y', c->stdin_data, c->stdin_data_size); |
52c239d7 LB |
683 | } |
684 | ||
cc86a278 ILG |
685 | static int property_get_restrict_filesystems( |
686 | sd_bus *bus, | |
687 | const char *path, | |
688 | const char *interface, | |
689 | const char *property, | |
690 | sd_bus_message *reply, | |
691 | void *userdata, | |
692 | sd_bus_error *error) { | |
693 | ||
694 | ExecContext *c = userdata; | |
695 | _cleanup_free_ char **l = NULL; | |
696 | int r; | |
697 | ||
698 | assert(bus); | |
699 | assert(reply); | |
700 | assert(c); | |
701 | ||
702 | r = sd_bus_message_open_container(reply, 'r', "bas"); | |
703 | if (r < 0) | |
704 | return r; | |
705 | ||
706 | r = sd_bus_message_append(reply, "b", c->restrict_filesystems_allow_list); | |
707 | if (r < 0) | |
708 | return r; | |
709 | ||
710 | #if HAVE_LIBBPF | |
711 | l = set_get_strv(c->restrict_filesystems); | |
712 | if (!l) | |
713 | return -ENOMEM; | |
714 | #endif | |
715 | ||
716 | strv_sort(l); | |
717 | ||
718 | r = sd_bus_message_append_strv(reply, l); | |
719 | if (r < 0) | |
720 | return r; | |
721 | ||
722 | return sd_bus_message_close_container(reply); | |
723 | } | |
724 | ||
d2d6c096 LP |
725 | static int property_get_bind_paths( |
726 | sd_bus *bus, | |
727 | const char *path, | |
728 | const char *interface, | |
729 | const char *property, | |
730 | sd_bus_message *reply, | |
731 | void *userdata, | |
732 | sd_bus_error *error) { | |
733 | ||
734 | ExecContext *c = userdata; | |
d2d6c096 LP |
735 | bool ro; |
736 | int r; | |
737 | ||
738 | assert(bus); | |
739 | assert(c); | |
740 | assert(property); | |
741 | assert(reply); | |
742 | ||
5d904a6a | 743 | ro = strstr(property, "ReadOnly"); |
d2d6c096 LP |
744 | |
745 | r = sd_bus_message_open_container(reply, 'a', "(ssbt)"); | |
746 | if (r < 0) | |
747 | return r; | |
748 | ||
fe96c0f8 | 749 | for (size_t i = 0; i < c->n_bind_mounts; i++) { |
d2d6c096 LP |
750 | |
751 | if (ro != c->bind_mounts[i].read_only) | |
752 | continue; | |
753 | ||
754 | r = sd_bus_message_append( | |
755 | reply, "(ssbt)", | |
756 | c->bind_mounts[i].source, | |
757 | c->bind_mounts[i].destination, | |
758 | c->bind_mounts[i].ignore_enoent, | |
c9b06108 | 759 | c->bind_mounts[i].recursive ? (uint64_t) MS_REC : (uint64_t) 0); |
d2d6c096 LP |
760 | if (r < 0) |
761 | return r; | |
762 | } | |
763 | ||
764 | return sd_bus_message_close_container(reply); | |
765 | } | |
766 | ||
784ad252 YW |
767 | static int property_get_temporary_filesystems( |
768 | sd_bus *bus, | |
769 | const char *path, | |
770 | const char *interface, | |
771 | const char *property, | |
772 | sd_bus_message *reply, | |
773 | void *userdata, | |
774 | sd_bus_error *error) { | |
775 | ||
776 | ExecContext *c = userdata; | |
784ad252 YW |
777 | int r; |
778 | ||
779 | assert(bus); | |
780 | assert(c); | |
781 | assert(property); | |
782 | assert(reply); | |
783 | ||
784 | r = sd_bus_message_open_container(reply, 'a', "(ss)"); | |
785 | if (r < 0) | |
786 | return r; | |
787 | ||
fe96c0f8 | 788 | for (unsigned i = 0; i < c->n_temporary_filesystems; i++) { |
784ad252 YW |
789 | TemporaryFileSystem *t = c->temporary_filesystems + i; |
790 | ||
791 | r = sd_bus_message_append( | |
792 | reply, "(ss)", | |
793 | t->path, | |
794 | t->options); | |
795 | if (r < 0) | |
796 | return r; | |
797 | } | |
798 | ||
799 | return sd_bus_message_close_container(reply); | |
800 | } | |
801 | ||
d3070fbd LP |
802 | static int property_get_log_extra_fields( |
803 | sd_bus *bus, | |
804 | const char *path, | |
805 | const char *interface, | |
806 | const char *property, | |
807 | sd_bus_message *reply, | |
808 | void *userdata, | |
809 | sd_bus_error *error) { | |
810 | ||
811 | ExecContext *c = userdata; | |
d3070fbd LP |
812 | int r; |
813 | ||
814 | assert(bus); | |
815 | assert(c); | |
816 | assert(property); | |
817 | assert(reply); | |
818 | ||
819 | r = sd_bus_message_open_container(reply, 'a', "ay"); | |
820 | if (r < 0) | |
821 | return r; | |
822 | ||
fe96c0f8 | 823 | for (size_t i = 0; i < c->n_log_extra_fields; i++) { |
d3070fbd LP |
824 | r = sd_bus_message_append_array(reply, 'y', c->log_extra_fields[i].iov_base, c->log_extra_fields[i].iov_len); |
825 | if (r < 0) | |
826 | return r; | |
827 | } | |
828 | ||
829 | return sd_bus_message_close_container(reply); | |
830 | } | |
831 | ||
bb0c0d6f LP |
832 | static int property_get_set_credential( |
833 | sd_bus *bus, | |
834 | const char *path, | |
835 | const char *interface, | |
836 | const char *property, | |
837 | sd_bus_message *reply, | |
838 | void *userdata, | |
839 | sd_bus_error *error) { | |
840 | ||
841 | ExecContext *c = userdata; | |
842 | ExecSetCredential *sc; | |
bb0c0d6f LP |
843 | int r; |
844 | ||
845 | assert(bus); | |
846 | assert(c); | |
847 | assert(property); | |
848 | assert(reply); | |
849 | ||
850 | r = sd_bus_message_open_container(reply, 'a', "(say)"); | |
851 | if (r < 0) | |
852 | return r; | |
853 | ||
90e74a66 | 854 | HASHMAP_FOREACH(sc, c->set_credentials) { |
bb0c0d6f | 855 | |
43144be4 LP |
856 | if (sc->encrypted != streq(property, "SetCredentialEncrypted")) |
857 | continue; | |
858 | ||
bb0c0d6f LP |
859 | r = sd_bus_message_open_container(reply, 'r', "say"); |
860 | if (r < 0) | |
861 | return r; | |
862 | ||
863 | r = sd_bus_message_append(reply, "s", sc->id); | |
864 | if (r < 0) | |
865 | return r; | |
866 | ||
867 | r = sd_bus_message_append_array(reply, 'y', sc->data, sc->size); | |
868 | if (r < 0) | |
869 | return r; | |
870 | ||
871 | r = sd_bus_message_close_container(reply); | |
872 | if (r < 0) | |
873 | return r; | |
874 | } | |
875 | ||
876 | return sd_bus_message_close_container(reply); | |
877 | } | |
878 | ||
879 | static int property_get_load_credential( | |
880 | sd_bus *bus, | |
881 | const char *path, | |
882 | const char *interface, | |
883 | const char *property, | |
884 | sd_bus_message *reply, | |
885 | void *userdata, | |
886 | sd_bus_error *error) { | |
887 | ||
888 | ExecContext *c = userdata; | |
43144be4 | 889 | ExecLoadCredential *lc; |
bb0c0d6f LP |
890 | int r; |
891 | ||
892 | assert(bus); | |
893 | assert(c); | |
894 | assert(property); | |
895 | assert(reply); | |
896 | ||
897 | r = sd_bus_message_open_container(reply, 'a', "(ss)"); | |
898 | if (r < 0) | |
899 | return r; | |
900 | ||
43144be4 LP |
901 | HASHMAP_FOREACH(lc, c->load_credentials) { |
902 | ||
903 | if (lc->encrypted != streq(property, "LoadCredentialEncrypted")) | |
904 | continue; | |
905 | ||
906 | r = sd_bus_message_append(reply, "(ss)", lc->id, lc->path); | |
bb0c0d6f LP |
907 | if (r < 0) |
908 | return r; | |
909 | } | |
910 | ||
911 | return sd_bus_message_close_container(reply); | |
912 | } | |
913 | ||
0389f4fa LB |
914 | static int property_get_root_hash( |
915 | sd_bus *bus, | |
916 | const char *path, | |
917 | const char *interface, | |
918 | const char *property, | |
919 | sd_bus_message *reply, | |
920 | void *userdata, | |
921 | sd_bus_error *error) { | |
922 | ||
923 | ExecContext *c = userdata; | |
924 | ||
925 | assert(bus); | |
926 | assert(c); | |
927 | assert(property); | |
928 | assert(reply); | |
929 | ||
930 | return sd_bus_message_append_array(reply, 'y', c->root_hash, c->root_hash_size); | |
931 | } | |
932 | ||
d4d55b0d LB |
933 | static int property_get_root_hash_sig( |
934 | sd_bus *bus, | |
935 | const char *path, | |
936 | const char *interface, | |
937 | const char *property, | |
938 | sd_bus_message *reply, | |
939 | void *userdata, | |
940 | sd_bus_error *error) { | |
941 | ||
942 | ExecContext *c = userdata; | |
943 | ||
944 | assert(bus); | |
945 | assert(c); | |
946 | assert(property); | |
947 | assert(reply); | |
948 | ||
949 | return sd_bus_message_append_array(reply, 'y', c->root_hash_sig, c->root_hash_sig_size); | |
950 | } | |
951 | ||
18d73705 LB |
952 | static int property_get_root_image_options( |
953 | sd_bus *bus, | |
954 | const char *path, | |
955 | const char *interface, | |
956 | const char *property, | |
957 | sd_bus_message *reply, | |
958 | void *userdata, | |
959 | sd_bus_error *error) { | |
960 | ||
961 | ExecContext *c = userdata; | |
962 | MountOptions *m; | |
963 | int r; | |
964 | ||
965 | assert(bus); | |
966 | assert(c); | |
967 | assert(property); | |
968 | assert(reply); | |
969 | ||
9ece6444 | 970 | r = sd_bus_message_open_container(reply, 'a', "(ss)"); |
18d73705 LB |
971 | if (r < 0) |
972 | return r; | |
973 | ||
974 | LIST_FOREACH(mount_options, m, c->root_image_options) { | |
9ece6444 LB |
975 | r = sd_bus_message_append(reply, "(ss)", |
976 | partition_designator_to_string(m->partition_designator), | |
977 | m->options); | |
18d73705 LB |
978 | if (r < 0) |
979 | return r; | |
980 | } | |
981 | ||
982 | return sd_bus_message_close_container(reply); | |
983 | } | |
984 | ||
b3d13314 LB |
985 | static int property_get_mount_images( |
986 | sd_bus *bus, | |
987 | const char *path, | |
988 | const char *interface, | |
989 | const char *property, | |
990 | sd_bus_message *reply, | |
991 | void *userdata, | |
992 | sd_bus_error *error) { | |
993 | ||
994 | ExecContext *c = userdata; | |
995 | int r; | |
996 | ||
997 | assert(bus); | |
998 | assert(c); | |
999 | assert(property); | |
1000 | assert(reply); | |
1001 | ||
427353f6 | 1002 | r = sd_bus_message_open_container(reply, 'a', "(ssba(ss))"); |
b3d13314 LB |
1003 | if (r < 0) |
1004 | return r; | |
1005 | ||
1006 | for (size_t i = 0; i < c->n_mount_images; i++) { | |
427353f6 LB |
1007 | MountOptions *m; |
1008 | ||
1009 | r = sd_bus_message_open_container(reply, SD_BUS_TYPE_STRUCT, "ssba(ss)"); | |
1010 | if (r < 0) | |
1011 | return r; | |
b3d13314 | 1012 | r = sd_bus_message_append( |
427353f6 | 1013 | reply, "ssb", |
b3d13314 LB |
1014 | c->mount_images[i].source, |
1015 | c->mount_images[i].destination, | |
1016 | c->mount_images[i].ignore_enoent); | |
1017 | if (r < 0) | |
1018 | return r; | |
427353f6 LB |
1019 | r = sd_bus_message_open_container(reply, 'a', "(ss)"); |
1020 | if (r < 0) | |
1021 | return r; | |
1022 | LIST_FOREACH(mount_options, m, c->mount_images[i].mount_options) { | |
1023 | r = sd_bus_message_append(reply, "(ss)", | |
1024 | partition_designator_to_string(m->partition_designator), | |
1025 | m->options); | |
1026 | if (r < 0) | |
1027 | return r; | |
1028 | } | |
1029 | r = sd_bus_message_close_container(reply); | |
1030 | if (r < 0) | |
1031 | return r; | |
1032 | r = sd_bus_message_close_container(reply); | |
1033 | if (r < 0) | |
1034 | return r; | |
b3d13314 LB |
1035 | } |
1036 | ||
1037 | return sd_bus_message_close_container(reply); | |
1038 | } | |
1039 | ||
93f59701 LB |
1040 | static int property_get_extension_images( |
1041 | sd_bus *bus, | |
1042 | const char *path, | |
1043 | const char *interface, | |
1044 | const char *property, | |
1045 | sd_bus_message *reply, | |
1046 | void *userdata, | |
1047 | sd_bus_error *error) { | |
1048 | ||
1049 | ExecContext *c = userdata; | |
1050 | int r; | |
1051 | ||
1052 | assert(bus); | |
1053 | assert(c); | |
1054 | assert(property); | |
1055 | assert(reply); | |
1056 | ||
1057 | r = sd_bus_message_open_container(reply, 'a', "(sba(ss))"); | |
1058 | if (r < 0) | |
1059 | return r; | |
1060 | ||
1061 | for (size_t i = 0; i < c->n_extension_images; i++) { | |
1062 | MountOptions *m; | |
1063 | ||
1064 | r = sd_bus_message_open_container(reply, SD_BUS_TYPE_STRUCT, "sba(ss)"); | |
1065 | if (r < 0) | |
1066 | return r; | |
1067 | r = sd_bus_message_append( | |
1068 | reply, "sb", | |
1069 | c->extension_images[i].source, | |
1070 | c->extension_images[i].ignore_enoent); | |
1071 | if (r < 0) | |
1072 | return r; | |
1073 | r = sd_bus_message_open_container(reply, 'a', "(ss)"); | |
1074 | if (r < 0) | |
1075 | return r; | |
1076 | LIST_FOREACH(mount_options, m, c->extension_images[i].mount_options) { | |
1077 | r = sd_bus_message_append(reply, "(ss)", | |
1078 | partition_designator_to_string(m->partition_designator), | |
1079 | m->options); | |
1080 | if (r < 0) | |
1081 | return r; | |
1082 | } | |
1083 | r = sd_bus_message_close_container(reply); | |
1084 | if (r < 0) | |
1085 | return r; | |
1086 | r = sd_bus_message_close_container(reply); | |
1087 | if (r < 0) | |
1088 | return r; | |
1089 | } | |
1090 | ||
1091 | return sd_bus_message_close_container(reply); | |
1092 | } | |
1093 | ||
718db961 LP |
1094 | const sd_bus_vtable bus_exec_vtable[] = { |
1095 | SD_BUS_VTABLE_START(0), | |
556089dc LP |
1096 | SD_BUS_PROPERTY("Environment", "as", NULL, offsetof(ExecContext, environment), SD_BUS_VTABLE_PROPERTY_CONST), |
1097 | SD_BUS_PROPERTY("EnvironmentFiles", "a(sb)", property_get_environment_files, 0, SD_BUS_VTABLE_PROPERTY_CONST), | |
b4c14404 | 1098 | SD_BUS_PROPERTY("PassEnvironment", "as", NULL, offsetof(ExecContext, pass_environment), SD_BUS_VTABLE_PROPERTY_CONST), |
00819cc1 | 1099 | SD_BUS_PROPERTY("UnsetEnvironment", "as", NULL, offsetof(ExecContext, unset_environment), SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc | 1100 | SD_BUS_PROPERTY("UMask", "u", bus_property_get_mode, offsetof(ExecContext, umask), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 1101 | SD_BUS_PROPERTY("LimitCPU", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_CPU]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 1102 | SD_BUS_PROPERTY("LimitCPUSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_CPU]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 1103 | SD_BUS_PROPERTY("LimitFSIZE", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_FSIZE]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 1104 | SD_BUS_PROPERTY("LimitFSIZESoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_FSIZE]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 1105 | SD_BUS_PROPERTY("LimitDATA", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_DATA]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 1106 | SD_BUS_PROPERTY("LimitDATASoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_DATA]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 1107 | SD_BUS_PROPERTY("LimitSTACK", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_STACK]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 1108 | SD_BUS_PROPERTY("LimitSTACKSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_STACK]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 1109 | SD_BUS_PROPERTY("LimitCORE", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_CORE]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 1110 | SD_BUS_PROPERTY("LimitCORESoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_CORE]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 1111 | SD_BUS_PROPERTY("LimitRSS", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RSS]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 1112 | SD_BUS_PROPERTY("LimitRSSSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RSS]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 1113 | SD_BUS_PROPERTY("LimitNOFILE", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NOFILE]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 1114 | SD_BUS_PROPERTY("LimitNOFILESoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NOFILE]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 1115 | SD_BUS_PROPERTY("LimitAS", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_AS]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 1116 | SD_BUS_PROPERTY("LimitASSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_AS]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 1117 | SD_BUS_PROPERTY("LimitNPROC", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NPROC]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 1118 | SD_BUS_PROPERTY("LimitNPROCSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NPROC]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 1119 | SD_BUS_PROPERTY("LimitMEMLOCK", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_MEMLOCK]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 1120 | SD_BUS_PROPERTY("LimitMEMLOCKSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_MEMLOCK]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 1121 | SD_BUS_PROPERTY("LimitLOCKS", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_LOCKS]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 1122 | SD_BUS_PROPERTY("LimitLOCKSSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_LOCKS]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 1123 | SD_BUS_PROPERTY("LimitSIGPENDING", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_SIGPENDING]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 1124 | SD_BUS_PROPERTY("LimitSIGPENDINGSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_SIGPENDING]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 1125 | SD_BUS_PROPERTY("LimitMSGQUEUE", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_MSGQUEUE]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 1126 | SD_BUS_PROPERTY("LimitMSGQUEUESoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_MSGQUEUE]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 1127 | SD_BUS_PROPERTY("LimitNICE", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NICE]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 1128 | SD_BUS_PROPERTY("LimitNICESoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NICE]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 1129 | SD_BUS_PROPERTY("LimitRTPRIO", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RTPRIO]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 1130 | SD_BUS_PROPERTY("LimitRTPRIOSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RTPRIO]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 1131 | SD_BUS_PROPERTY("LimitRTTIME", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RTTIME]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 1132 | SD_BUS_PROPERTY("LimitRTTIMESoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RTTIME]), SD_BUS_VTABLE_PROPERTY_CONST), |
5f5d8eab | 1133 | SD_BUS_PROPERTY("WorkingDirectory", "s", property_get_working_directory, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc | 1134 | SD_BUS_PROPERTY("RootDirectory", "s", NULL, offsetof(ExecContext, root_directory), SD_BUS_VTABLE_PROPERTY_CONST), |
915e6d16 | 1135 | SD_BUS_PROPERTY("RootImage", "s", NULL, offsetof(ExecContext, root_image), SD_BUS_VTABLE_PROPERTY_CONST), |
9ece6444 | 1136 | SD_BUS_PROPERTY("RootImageOptions", "a(ss)", property_get_root_image_options, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
0389f4fa LB |
1137 | SD_BUS_PROPERTY("RootHash", "ay", property_get_root_hash, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
1138 | SD_BUS_PROPERTY("RootHashPath", "s", NULL, offsetof(ExecContext, root_hash_path), SD_BUS_VTABLE_PROPERTY_CONST), | |
d4d55b0d LB |
1139 | SD_BUS_PROPERTY("RootHashSignature", "ay", property_get_root_hash_sig, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
1140 | SD_BUS_PROPERTY("RootHashSignaturePath", "s", NULL, offsetof(ExecContext, root_hash_sig_path), SD_BUS_VTABLE_PROPERTY_CONST), | |
0389f4fa | 1141 | SD_BUS_PROPERTY("RootVerity", "s", NULL, offsetof(ExecContext, root_verity), SD_BUS_VTABLE_PROPERTY_CONST), |
93f59701 | 1142 | SD_BUS_PROPERTY("ExtensionImages", "a(sba(ss))", property_get_extension_images, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
427353f6 | 1143 | SD_BUS_PROPERTY("MountImages", "a(ssba(ss))", property_get_mount_images, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc | 1144 | SD_BUS_PROPERTY("OOMScoreAdjust", "i", property_get_oom_score_adjust, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
ad21e542 | 1145 | SD_BUS_PROPERTY("CoredumpFilter", "t", property_get_coredump_filter, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc | 1146 | SD_BUS_PROPERTY("Nice", "i", property_get_nice, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
7f452159 LP |
1147 | SD_BUS_PROPERTY("IOSchedulingClass", "i", property_get_ioprio_class, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
1148 | SD_BUS_PROPERTY("IOSchedulingPriority", "i", property_get_ioprio_priority, 0, SD_BUS_VTABLE_PROPERTY_CONST), | |
556089dc LP |
1149 | SD_BUS_PROPERTY("CPUSchedulingPolicy", "i", property_get_cpu_sched_policy, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
1150 | SD_BUS_PROPERTY("CPUSchedulingPriority", "i", property_get_cpu_sched_priority, 0, SD_BUS_VTABLE_PROPERTY_CONST), | |
1151 | SD_BUS_PROPERTY("CPUAffinity", "ay", property_get_cpu_affinity, 0, SD_BUS_VTABLE_PROPERTY_CONST), | |
e2b2fb7f | 1152 | SD_BUS_PROPERTY("CPUAffinityFromNUMA", "b", property_get_cpu_affinity_from_numa, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
b070c7c0 MS |
1153 | SD_BUS_PROPERTY("NUMAPolicy", "i", property_get_numa_policy, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
1154 | SD_BUS_PROPERTY("NUMAMask", "ay", property_get_numa_mask, 0, SD_BUS_VTABLE_PROPERTY_CONST), | |
556089dc LP |
1155 | SD_BUS_PROPERTY("TimerSlackNSec", "t", property_get_timer_slack_nsec, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
1156 | SD_BUS_PROPERTY("CPUSchedulingResetOnFork", "b", bus_property_get_bool, offsetof(ExecContext, cpu_sched_reset_on_fork), SD_BUS_VTABLE_PROPERTY_CONST), | |
1157 | SD_BUS_PROPERTY("NonBlocking", "b", bus_property_get_bool, offsetof(ExecContext, non_blocking), SD_BUS_VTABLE_PROPERTY_CONST), | |
1158 | SD_BUS_PROPERTY("StandardInput", "s", property_get_exec_input, offsetof(ExecContext, std_input), SD_BUS_VTABLE_PROPERTY_CONST), | |
5073ff6b | 1159 | SD_BUS_PROPERTY("StandardInputFileDescriptorName", "s", property_get_stdio_fdname, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
08f3be7a | 1160 | SD_BUS_PROPERTY("StandardInputData", "ay", property_get_input_data, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc | 1161 | SD_BUS_PROPERTY("StandardOutput", "s", bus_property_get_exec_output, offsetof(ExecContext, std_output), SD_BUS_VTABLE_PROPERTY_CONST), |
5073ff6b | 1162 | SD_BUS_PROPERTY("StandardOutputFileDescriptorName", "s", property_get_stdio_fdname, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc | 1163 | SD_BUS_PROPERTY("StandardError", "s", bus_property_get_exec_output, offsetof(ExecContext, std_error), SD_BUS_VTABLE_PROPERTY_CONST), |
5073ff6b | 1164 | SD_BUS_PROPERTY("StandardErrorFileDescriptorName", "s", property_get_stdio_fdname, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc LP |
1165 | SD_BUS_PROPERTY("TTYPath", "s", NULL, offsetof(ExecContext, tty_path), SD_BUS_VTABLE_PROPERTY_CONST), |
1166 | SD_BUS_PROPERTY("TTYReset", "b", bus_property_get_bool, offsetof(ExecContext, tty_reset), SD_BUS_VTABLE_PROPERTY_CONST), | |
1167 | SD_BUS_PROPERTY("TTYVHangup", "b", bus_property_get_bool, offsetof(ExecContext, tty_vhangup), SD_BUS_VTABLE_PROPERTY_CONST), | |
1168 | SD_BUS_PROPERTY("TTYVTDisallocate", "b", bus_property_get_bool, offsetof(ExecContext, tty_vt_disallocate), SD_BUS_VTABLE_PROPERTY_CONST), | |
1169 | SD_BUS_PROPERTY("SyslogPriority", "i", bus_property_get_int, offsetof(ExecContext, syslog_priority), SD_BUS_VTABLE_PROPERTY_CONST), | |
1170 | SD_BUS_PROPERTY("SyslogIdentifier", "s", NULL, offsetof(ExecContext, syslog_identifier), SD_BUS_VTABLE_PROPERTY_CONST), | |
1171 | SD_BUS_PROPERTY("SyslogLevelPrefix", "b", bus_property_get_bool, offsetof(ExecContext, syslog_level_prefix), SD_BUS_VTABLE_PROPERTY_CONST), | |
9d5527f2 YW |
1172 | SD_BUS_PROPERTY("SyslogLevel", "i", property_get_syslog_level, offsetof(ExecContext, syslog_priority), SD_BUS_VTABLE_PROPERTY_CONST), |
1173 | SD_BUS_PROPERTY("SyslogFacility", "i", property_get_syslog_facility, offsetof(ExecContext, syslog_priority), SD_BUS_VTABLE_PROPERTY_CONST), | |
d3070fbd | 1174 | SD_BUS_PROPERTY("LogLevelMax", "i", bus_property_get_int, offsetof(ExecContext, log_level_max), SD_BUS_VTABLE_PROPERTY_CONST), |
5ac1530e ZJS |
1175 | SD_BUS_PROPERTY("LogRateLimitIntervalUSec", "t", bus_property_get_usec, offsetof(ExecContext, log_ratelimit_interval_usec), SD_BUS_VTABLE_PROPERTY_CONST), |
1176 | SD_BUS_PROPERTY("LogRateLimitBurst", "u", bus_property_get_unsigned, offsetof(ExecContext, log_ratelimit_burst), SD_BUS_VTABLE_PROPERTY_CONST), | |
d3070fbd | 1177 | SD_BUS_PROPERTY("LogExtraFields", "aay", property_get_log_extra_fields, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
91dd5f7c | 1178 | SD_BUS_PROPERTY("LogNamespace", "s", NULL, offsetof(ExecContext, log_namespace), SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc | 1179 | SD_BUS_PROPERTY("SecureBits", "i", bus_property_get_int, offsetof(ExecContext, secure_bits), SD_BUS_VTABLE_PROPERTY_CONST), |
c0159e20 YW |
1180 | SD_BUS_PROPERTY("CapabilityBoundingSet", "t", NULL, offsetof(ExecContext, capability_bounding_set), SD_BUS_VTABLE_PROPERTY_CONST), |
1181 | SD_BUS_PROPERTY("AmbientCapabilities", "t", NULL, offsetof(ExecContext, capability_ambient_set), SD_BUS_VTABLE_PROPERTY_CONST), | |
556089dc LP |
1182 | SD_BUS_PROPERTY("User", "s", NULL, offsetof(ExecContext, user), SD_BUS_VTABLE_PROPERTY_CONST), |
1183 | SD_BUS_PROPERTY("Group", "s", NULL, offsetof(ExecContext, group), SD_BUS_VTABLE_PROPERTY_CONST), | |
29206d46 | 1184 | SD_BUS_PROPERTY("DynamicUser", "b", bus_property_get_bool, offsetof(ExecContext, dynamic_user), SD_BUS_VTABLE_PROPERTY_CONST), |
00d9ef85 | 1185 | SD_BUS_PROPERTY("RemoveIPC", "b", bus_property_get_bool, offsetof(ExecContext, remove_ipc), SD_BUS_VTABLE_PROPERTY_CONST), |
bb0c0d6f | 1186 | SD_BUS_PROPERTY("SetCredential", "a(say)", property_get_set_credential, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
43144be4 | 1187 | SD_BUS_PROPERTY("SetCredentialEncrypted", "a(say)", property_get_set_credential, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
bb0c0d6f | 1188 | SD_BUS_PROPERTY("LoadCredential", "a(ss)", property_get_load_credential, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
43144be4 | 1189 | SD_BUS_PROPERTY("LoadCredentialEncrypted", "a(ss)", property_get_load_credential, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc | 1190 | SD_BUS_PROPERTY("SupplementaryGroups", "as", NULL, offsetof(ExecContext, supplementary_groups), SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc | 1191 | SD_BUS_PROPERTY("PAMName", "s", NULL, offsetof(ExecContext, pam_name), SD_BUS_VTABLE_PROPERTY_CONST), |
2a624c36 AP |
1192 | SD_BUS_PROPERTY("ReadWritePaths", "as", NULL, offsetof(ExecContext, read_write_paths), SD_BUS_VTABLE_PROPERTY_CONST), |
1193 | SD_BUS_PROPERTY("ReadOnlyPaths", "as", NULL, offsetof(ExecContext, read_only_paths), SD_BUS_VTABLE_PROPERTY_CONST), | |
1194 | SD_BUS_PROPERTY("InaccessiblePaths", "as", NULL, offsetof(ExecContext, inaccessible_paths), SD_BUS_VTABLE_PROPERTY_CONST), | |
ddc155b2 TM |
1195 | SD_BUS_PROPERTY("ExecPaths", "as", NULL, offsetof(ExecContext, exec_paths), SD_BUS_VTABLE_PROPERTY_CONST), |
1196 | SD_BUS_PROPERTY("NoExecPaths", "as", NULL, offsetof(ExecContext, no_exec_paths), SD_BUS_VTABLE_PROPERTY_CONST), | |
8c35c10d | 1197 | SD_BUS_PROPERTY("ExecSearchPath", "as", NULL, offsetof(ExecContext, exec_search_path), SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc LP |
1198 | SD_BUS_PROPERTY("MountFlags", "t", bus_property_get_ulong, offsetof(ExecContext, mount_flags), SD_BUS_VTABLE_PROPERTY_CONST), |
1199 | SD_BUS_PROPERTY("PrivateTmp", "b", bus_property_get_bool, offsetof(ExecContext, private_tmp), SD_BUS_VTABLE_PROPERTY_CONST), | |
7f112f50 | 1200 | SD_BUS_PROPERTY("PrivateDevices", "b", bus_property_get_bool, offsetof(ExecContext, private_devices), SD_BUS_VTABLE_PROPERTY_CONST), |
b8b7b838 | 1201 | SD_BUS_PROPERTY("ProtectClock", "b", bus_property_get_bool, offsetof(ExecContext, protect_clock), SD_BUS_VTABLE_PROPERTY_CONST), |
59eeb84b | 1202 | SD_BUS_PROPERTY("ProtectKernelTunables", "b", bus_property_get_bool, offsetof(ExecContext, protect_kernel_tunables), SD_BUS_VTABLE_PROPERTY_CONST), |
502d704e | 1203 | SD_BUS_PROPERTY("ProtectKernelModules", "b", bus_property_get_bool, offsetof(ExecContext, protect_kernel_modules), SD_BUS_VTABLE_PROPERTY_CONST), |
84703040 | 1204 | SD_BUS_PROPERTY("ProtectKernelLogs", "b", bus_property_get_bool, offsetof(ExecContext, protect_kernel_logs), SD_BUS_VTABLE_PROPERTY_CONST), |
59eeb84b | 1205 | SD_BUS_PROPERTY("ProtectControlGroups", "b", bus_property_get_bool, offsetof(ExecContext, protect_control_groups), SD_BUS_VTABLE_PROPERTY_CONST), |
d251207d LP |
1206 | SD_BUS_PROPERTY("PrivateNetwork", "b", bus_property_get_bool, offsetof(ExecContext, private_network), SD_BUS_VTABLE_PROPERTY_CONST), |
1207 | SD_BUS_PROPERTY("PrivateUsers", "b", bus_property_get_bool, offsetof(ExecContext, private_users), SD_BUS_VTABLE_PROPERTY_CONST), | |
228af36f | 1208 | SD_BUS_PROPERTY("PrivateMounts", "b", bus_property_get_bool, offsetof(ExecContext, private_mounts), SD_BUS_VTABLE_PROPERTY_CONST), |
a70581ff | 1209 | SD_BUS_PROPERTY("PrivateIPC", "b", bus_property_get_bool, offsetof(ExecContext, private_ipc), SD_BUS_VTABLE_PROPERTY_CONST), |
73b84e92 YW |
1210 | SD_BUS_PROPERTY("ProtectHome", "s", property_get_protect_home, offsetof(ExecContext, protect_home), SD_BUS_VTABLE_PROPERTY_CONST), |
1211 | SD_BUS_PROPERTY("ProtectSystem", "s", property_get_protect_system, offsetof(ExecContext, protect_system), SD_BUS_VTABLE_PROPERTY_CONST), | |
556089dc LP |
1212 | SD_BUS_PROPERTY("SameProcessGroup", "b", bus_property_get_bool, offsetof(ExecContext, same_pgrp), SD_BUS_VTABLE_PROPERTY_CONST), |
1213 | SD_BUS_PROPERTY("UtmpIdentifier", "s", NULL, offsetof(ExecContext, utmp_id), SD_BUS_VTABLE_PROPERTY_CONST), | |
023a4f67 | 1214 | SD_BUS_PROPERTY("UtmpMode", "s", property_get_exec_utmp_mode, offsetof(ExecContext, utmp_mode), SD_BUS_VTABLE_PROPERTY_CONST), |
5f8640fb | 1215 | SD_BUS_PROPERTY("SELinuxContext", "(bs)", property_get_selinux_context, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
eef65bf3 | 1216 | SD_BUS_PROPERTY("AppArmorProfile", "(bs)", property_get_apparmor_profile, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
2ca620c4 | 1217 | SD_BUS_PROPERTY("SmackProcessLabel", "(bs)", property_get_smack_process_label, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc LP |
1218 | SD_BUS_PROPERTY("IgnoreSIGPIPE", "b", bus_property_get_bool, offsetof(ExecContext, ignore_sigpipe), SD_BUS_VTABLE_PROPERTY_CONST), |
1219 | SD_BUS_PROPERTY("NoNewPrivileges", "b", bus_property_get_bool, offsetof(ExecContext, no_new_privileges), SD_BUS_VTABLE_PROPERTY_CONST), | |
57183d11 LP |
1220 | SD_BUS_PROPERTY("SystemCallFilter", "(bas)", property_get_syscall_filter, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
1221 | SD_BUS_PROPERTY("SystemCallArchitectures", "as", property_get_syscall_archs, 0, SD_BUS_VTABLE_PROPERTY_CONST), | |
cf9d43a8 | 1222 | SD_BUS_PROPERTY("SystemCallErrorNumber", "i", bus_property_get_int, offsetof(ExecContext, syscall_errno), SD_BUS_VTABLE_PROPERTY_CONST), |
9df2cdd8 | 1223 | SD_BUS_PROPERTY("SystemCallLog", "(bas)", property_get_syscall_log, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
491eecb3 | 1224 | SD_BUS_PROPERTY("Personality", "s", property_get_personality, offsetof(ExecContext, personality), SD_BUS_VTABLE_PROPERTY_CONST), |
78e864e5 | 1225 | SD_BUS_PROPERTY("LockPersonality", "b", bus_property_get_bool, offsetof(ExecContext, lock_personality), SD_BUS_VTABLE_PROPERTY_CONST), |
4298d0b5 | 1226 | SD_BUS_PROPERTY("RestrictAddressFamilies", "(bas)", property_get_address_families, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
53f47dfc | 1227 | SD_BUS_PROPERTY("RuntimeDirectoryPreserve", "s", property_get_exec_preserve_mode, offsetof(ExecContext, runtime_directory_preserve_mode), SD_BUS_VTABLE_PROPERTY_CONST), |
3536f49e YW |
1228 | SD_BUS_PROPERTY("RuntimeDirectoryMode", "u", bus_property_get_mode, offsetof(ExecContext, directories[EXEC_DIRECTORY_RUNTIME].mode), SD_BUS_VTABLE_PROPERTY_CONST), |
1229 | SD_BUS_PROPERTY("RuntimeDirectory", "as", NULL, offsetof(ExecContext, directories[EXEC_DIRECTORY_RUNTIME].paths), SD_BUS_VTABLE_PROPERTY_CONST), | |
e940c1ef YW |
1230 | SD_BUS_PROPERTY("StateDirectoryMode", "u", bus_property_get_mode, offsetof(ExecContext, directories[EXEC_DIRECTORY_STATE].mode), SD_BUS_VTABLE_PROPERTY_CONST), |
1231 | SD_BUS_PROPERTY("StateDirectory", "as", NULL, offsetof(ExecContext, directories[EXEC_DIRECTORY_STATE].paths), SD_BUS_VTABLE_PROPERTY_CONST), | |
3536f49e YW |
1232 | SD_BUS_PROPERTY("CacheDirectoryMode", "u", bus_property_get_mode, offsetof(ExecContext, directories[EXEC_DIRECTORY_CACHE].mode), SD_BUS_VTABLE_PROPERTY_CONST), |
1233 | SD_BUS_PROPERTY("CacheDirectory", "as", NULL, offsetof(ExecContext, directories[EXEC_DIRECTORY_CACHE].paths), SD_BUS_VTABLE_PROPERTY_CONST), | |
1234 | SD_BUS_PROPERTY("LogsDirectoryMode", "u", bus_property_get_mode, offsetof(ExecContext, directories[EXEC_DIRECTORY_LOGS].mode), SD_BUS_VTABLE_PROPERTY_CONST), | |
1235 | SD_BUS_PROPERTY("LogsDirectory", "as", NULL, offsetof(ExecContext, directories[EXEC_DIRECTORY_LOGS].paths), SD_BUS_VTABLE_PROPERTY_CONST), | |
1236 | SD_BUS_PROPERTY("ConfigurationDirectoryMode", "u", bus_property_get_mode, offsetof(ExecContext, directories[EXEC_DIRECTORY_CONFIGURATION].mode), SD_BUS_VTABLE_PROPERTY_CONST), | |
1237 | SD_BUS_PROPERTY("ConfigurationDirectory", "as", NULL, offsetof(ExecContext, directories[EXEC_DIRECTORY_CONFIGURATION].paths), SD_BUS_VTABLE_PROPERTY_CONST), | |
12213aed | 1238 | SD_BUS_PROPERTY("TimeoutCleanUSec", "t", bus_property_get_usec, offsetof(ExecContext, timeout_clean_usec), SD_BUS_VTABLE_PROPERTY_CONST), |
f3e43635 | 1239 | SD_BUS_PROPERTY("MemoryDenyWriteExecute", "b", bus_property_get_bool, offsetof(ExecContext, memory_deny_write_execute), SD_BUS_VTABLE_PROPERTY_CONST), |
f4170c67 | 1240 | SD_BUS_PROPERTY("RestrictRealtime", "b", bus_property_get_bool, offsetof(ExecContext, restrict_realtime), SD_BUS_VTABLE_PROPERTY_CONST), |
f69567cb | 1241 | SD_BUS_PROPERTY("RestrictSUIDSGID", "b", bus_property_get_bool, offsetof(ExecContext, restrict_suid_sgid), SD_BUS_VTABLE_PROPERTY_CONST), |
6a8c2d59 | 1242 | SD_BUS_PROPERTY("RestrictNamespaces", "t", bus_property_get_ulong, offsetof(ExecContext, restrict_namespaces), SD_BUS_VTABLE_PROPERTY_CONST), |
cc86a278 | 1243 | SD_BUS_PROPERTY("RestrictFileSystems", "(bas)", property_get_restrict_filesystems, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
d2d6c096 LP |
1244 | SD_BUS_PROPERTY("BindPaths", "a(ssbt)", property_get_bind_paths, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
1245 | SD_BUS_PROPERTY("BindReadOnlyPaths", "a(ssbt)", property_get_bind_paths, 0, SD_BUS_VTABLE_PROPERTY_CONST), | |
784ad252 | 1246 | SD_BUS_PROPERTY("TemporaryFileSystem", "a(ss)", property_get_temporary_filesystems, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
5e98086d | 1247 | SD_BUS_PROPERTY("MountAPIVFS", "b", property_get_mount_apivfs, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
b1edf445 | 1248 | SD_BUS_PROPERTY("KeyringMode", "s", property_get_exec_keyring_mode, offsetof(ExecContext, keyring_mode), SD_BUS_VTABLE_PROPERTY_CONST), |
4e399953 LP |
1249 | SD_BUS_PROPERTY("ProtectProc", "s", property_get_protect_proc, offsetof(ExecContext, protect_proc), SD_BUS_VTABLE_PROPERTY_CONST), |
1250 | SD_BUS_PROPERTY("ProcSubset", "s", property_get_proc_subset, offsetof(ExecContext, proc_subset), SD_BUS_VTABLE_PROPERTY_CONST), | |
aecd5ac6 | 1251 | SD_BUS_PROPERTY("ProtectHostname", "b", bus_property_get_bool, offsetof(ExecContext, protect_hostname), SD_BUS_VTABLE_PROPERTY_CONST), |
a8d08f39 | 1252 | SD_BUS_PROPERTY("NetworkNamespacePath", "s", NULL, offsetof(ExecContext, network_namespace_path), SD_BUS_VTABLE_PROPERTY_CONST), |
a70581ff | 1253 | SD_BUS_PROPERTY("IPCNamespacePath", "s", NULL, offsetof(ExecContext, ipc_namespace_path), SD_BUS_VTABLE_PROPERTY_CONST), |
7f452159 LP |
1254 | |
1255 | /* Obsolete/redundant properties: */ | |
1256 | SD_BUS_PROPERTY("Capabilities", "s", property_get_empty_string, 0, SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN), | |
1257 | SD_BUS_PROPERTY("ReadWriteDirectories", "as", NULL, offsetof(ExecContext, read_write_paths), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN), | |
1258 | SD_BUS_PROPERTY("ReadOnlyDirectories", "as", NULL, offsetof(ExecContext, read_only_paths), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN), | |
1259 | SD_BUS_PROPERTY("InaccessibleDirectories", "as", NULL, offsetof(ExecContext, inaccessible_paths), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN), | |
1260 | SD_BUS_PROPERTY("IOScheduling", "i", property_get_ioprio, 0, SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN), | |
1261 | ||
718db961 LP |
1262 | SD_BUS_VTABLE_END |
1263 | }; | |
82c121a4 | 1264 | |
4d4c80d0 LP |
1265 | static int append_exec_command(sd_bus_message *reply, ExecCommand *c) { |
1266 | int r; | |
1267 | ||
1268 | assert(reply); | |
1269 | assert(c); | |
1270 | ||
1271 | if (!c->path) | |
1272 | return 0; | |
1273 | ||
1274 | r = sd_bus_message_open_container(reply, 'r', "sasbttttuii"); | |
1275 | if (r < 0) | |
1276 | return r; | |
1277 | ||
1278 | r = sd_bus_message_append(reply, "s", c->path); | |
1279 | if (r < 0) | |
1280 | return r; | |
1281 | ||
1282 | r = sd_bus_message_append_strv(reply, c->argv); | |
1283 | if (r < 0) | |
1284 | return r; | |
1285 | ||
1286 | r = sd_bus_message_append(reply, "bttttuii", | |
3ed0cd26 | 1287 | !!(c->flags & EXEC_COMMAND_IGNORE_FAILURE), |
4d4c80d0 LP |
1288 | c->exec_status.start_timestamp.realtime, |
1289 | c->exec_status.start_timestamp.monotonic, | |
1290 | c->exec_status.exit_timestamp.realtime, | |
1291 | c->exec_status.exit_timestamp.monotonic, | |
1292 | (uint32_t) c->exec_status.pid, | |
1293 | (int32_t) c->exec_status.code, | |
1294 | (int32_t) c->exec_status.status); | |
1295 | if (r < 0) | |
1296 | return r; | |
1297 | ||
1298 | return sd_bus_message_close_container(reply); | |
1299 | } | |
1300 | ||
b3d59367 AZ |
1301 | static int append_exec_ex_command(sd_bus_message *reply, ExecCommand *c) { |
1302 | _cleanup_strv_free_ char **ex_opts = NULL; | |
1303 | int r; | |
1304 | ||
1305 | assert(reply); | |
1306 | assert(c); | |
1307 | ||
1308 | if (!c->path) | |
1309 | return 0; | |
1310 | ||
1311 | r = sd_bus_message_open_container(reply, 'r', "sasasttttuii"); | |
1312 | if (r < 0) | |
1313 | return r; | |
1314 | ||
1315 | r = sd_bus_message_append(reply, "s", c->path); | |
1316 | if (r < 0) | |
1317 | return r; | |
1318 | ||
1319 | r = sd_bus_message_append_strv(reply, c->argv); | |
1320 | if (r < 0) | |
1321 | return r; | |
1322 | ||
1323 | r = exec_command_flags_to_strv(c->flags, &ex_opts); | |
1324 | if (r < 0) | |
1325 | return r; | |
1326 | ||
1327 | r = sd_bus_message_append_strv(reply, ex_opts); | |
1328 | if (r < 0) | |
1329 | return r; | |
1330 | ||
1331 | r = sd_bus_message_append(reply, "ttttuii", | |
1332 | c->exec_status.start_timestamp.realtime, | |
1333 | c->exec_status.start_timestamp.monotonic, | |
1334 | c->exec_status.exit_timestamp.realtime, | |
1335 | c->exec_status.exit_timestamp.monotonic, | |
1336 | (uint32_t) c->exec_status.pid, | |
1337 | (int32_t) c->exec_status.code, | |
1338 | (int32_t) c->exec_status.status); | |
1339 | if (r < 0) | |
1340 | return r; | |
1341 | ||
1342 | return sd_bus_message_close_container(reply); | |
1343 | } | |
1344 | ||
718db961 LP |
1345 | int bus_property_get_exec_command( |
1346 | sd_bus *bus, | |
1347 | const char *path, | |
1348 | const char *interface, | |
1349 | const char *property, | |
1350 | sd_bus_message *reply, | |
ebcf1f97 LP |
1351 | void *userdata, |
1352 | sd_bus_error *ret_error) { | |
fe68089d | 1353 | |
4d4c80d0 | 1354 | ExecCommand *c = (ExecCommand*) userdata; |
718db961 | 1355 | int r; |
fe68089d | 1356 | |
718db961 LP |
1357 | assert(bus); |
1358 | assert(reply); | |
fe68089d | 1359 | |
718db961 LP |
1360 | r = sd_bus_message_open_container(reply, 'a', "(sasbttttuii)"); |
1361 | if (r < 0) | |
1362 | return r; | |
fe68089d | 1363 | |
4d4c80d0 LP |
1364 | r = append_exec_command(reply, c); |
1365 | if (r < 0) | |
1366 | return r; | |
fe68089d | 1367 | |
4d4c80d0 LP |
1368 | return sd_bus_message_close_container(reply); |
1369 | } | |
718db961 | 1370 | |
4d4c80d0 LP |
1371 | int bus_property_get_exec_command_list( |
1372 | sd_bus *bus, | |
1373 | const char *path, | |
1374 | const char *interface, | |
1375 | const char *property, | |
1376 | sd_bus_message *reply, | |
1377 | void *userdata, | |
1378 | sd_bus_error *ret_error) { | |
718db961 | 1379 | |
4d4c80d0 LP |
1380 | ExecCommand *c = *(ExecCommand**) userdata; |
1381 | int r; | |
718db961 | 1382 | |
4d4c80d0 LP |
1383 | assert(bus); |
1384 | assert(reply); | |
1385 | ||
1386 | r = sd_bus_message_open_container(reply, 'a', "(sasbttttuii)"); | |
1387 | if (r < 0) | |
1388 | return r; | |
718db961 | 1389 | |
4d4c80d0 LP |
1390 | LIST_FOREACH(command, c, c) { |
1391 | r = append_exec_command(reply, c); | |
718db961 LP |
1392 | if (r < 0) |
1393 | return r; | |
fe68089d LP |
1394 | } |
1395 | ||
718db961 | 1396 | return sd_bus_message_close_container(reply); |
8351ceae | 1397 | } |
c7040b5d | 1398 | |
b3d59367 AZ |
1399 | int bus_property_get_exec_ex_command_list( |
1400 | sd_bus *bus, | |
1401 | const char *path, | |
1402 | const char *interface, | |
1403 | const char *property, | |
1404 | sd_bus_message *reply, | |
1405 | void *userdata, | |
1406 | sd_bus_error *ret_error) { | |
1407 | ||
1408 | ExecCommand *c, *exec_command = *(ExecCommand**) userdata; | |
1409 | int r; | |
1410 | ||
1411 | assert(bus); | |
1412 | assert(reply); | |
1413 | ||
1414 | r = sd_bus_message_open_container(reply, 'a', "(sasasttttuii)"); | |
1415 | if (r < 0) | |
1416 | return r; | |
1417 | ||
1418 | LIST_FOREACH(command, c, exec_command) { | |
1419 | r = append_exec_ex_command(reply, c); | |
1420 | if (r < 0) | |
1421 | return r; | |
1422 | } | |
1423 | ||
1424 | return sd_bus_message_close_container(reply); | |
1425 | } | |
1426 | ||
1427 | static char *exec_command_flags_to_exec_chars(ExecCommandFlags flags) { | |
a4fc96c8 ZJS |
1428 | return strjoin(FLAGS_SET(flags, EXEC_COMMAND_IGNORE_FAILURE) ? "-" : "", |
1429 | FLAGS_SET(flags, EXEC_COMMAND_NO_ENV_EXPAND) ? ":" : "", | |
1430 | FLAGS_SET(flags, EXEC_COMMAND_FULLY_PRIVILEGED) ? "+" : "", | |
1431 | FLAGS_SET(flags, EXEC_COMMAND_NO_SETUID) ? "!" : "", | |
1432 | FLAGS_SET(flags, EXEC_COMMAND_AMBIENT_MAGIC) ? "!!" : ""); | |
b3d59367 AZ |
1433 | } |
1434 | ||
237f7bcb | 1435 | int bus_set_transient_exec_command( |
9c0320e7 YW |
1436 | Unit *u, |
1437 | const char *name, | |
1438 | ExecCommand **exec_command, | |
1439 | sd_bus_message *message, | |
1440 | UnitWriteFlags flags, | |
1441 | sd_bus_error *error) { | |
b3d59367 | 1442 | bool is_ex_prop = endswith(name, "Ex"); |
9c0320e7 YW |
1443 | unsigned n = 0; |
1444 | int r; | |
1445 | ||
b3d59367 | 1446 | r = sd_bus_message_enter_container(message, 'a', is_ex_prop ? "(sasas)" : "(sasb)"); |
9c0320e7 YW |
1447 | if (r < 0) |
1448 | return r; | |
1449 | ||
b3d59367 AZ |
1450 | while ((r = sd_bus_message_enter_container(message, 'r', is_ex_prop ? "sasas" : "sasb")) > 0) { |
1451 | _cleanup_strv_free_ char **argv = NULL, **ex_opts = NULL; | |
9c0320e7 YW |
1452 | const char *path; |
1453 | int b; | |
1454 | ||
1455 | r = sd_bus_message_read(message, "s", &path); | |
1456 | if (r < 0) | |
1457 | return r; | |
1458 | ||
8038b99d ZJS |
1459 | if (!path_is_absolute(path) && !filename_is_valid(path)) |
1460 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, | |
1461 | "\"%s\" is neither a valid executable name nor an absolute path", | |
1462 | path); | |
9c0320e7 YW |
1463 | |
1464 | r = sd_bus_message_read_strv(message, &argv); | |
1465 | if (r < 0) | |
1466 | return r; | |
1467 | ||
29500cf8 HC |
1468 | if (strv_isempty(argv)) |
1469 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, | |
1470 | "\"%s\" argv cannot be empty", name); | |
1471 | ||
b3d59367 | 1472 | r = is_ex_prop ? sd_bus_message_read_strv(message, &ex_opts) : sd_bus_message_read(message, "b", &b); |
9c0320e7 YW |
1473 | if (r < 0) |
1474 | return r; | |
1475 | ||
1476 | r = sd_bus_message_exit_container(message); | |
1477 | if (r < 0) | |
1478 | return r; | |
1479 | ||
1480 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
1481 | ExecCommand *c; | |
1482 | ||
1483 | c = new0(ExecCommand, 1); | |
1484 | if (!c) | |
1485 | return -ENOMEM; | |
1486 | ||
1487 | c->path = strdup(path); | |
1488 | if (!c->path) { | |
1489 | free(c); | |
1490 | return -ENOMEM; | |
1491 | } | |
1492 | ||
ae2a15bc | 1493 | c->argv = TAKE_PTR(argv); |
9c0320e7 | 1494 | |
b3d59367 AZ |
1495 | if (is_ex_prop) { |
1496 | r = exec_command_flags_from_strv(ex_opts, &c->flags); | |
1497 | if (r < 0) | |
1498 | return r; | |
1499 | } else | |
1500 | c->flags = b ? EXEC_COMMAND_IGNORE_FAILURE : 0; | |
9c0320e7 | 1501 | |
4ff361cc | 1502 | path_simplify(c->path); |
9c0320e7 YW |
1503 | exec_command_append_list(exec_command, c); |
1504 | } | |
1505 | ||
1506 | n++; | |
1507 | } | |
1508 | if (r < 0) | |
1509 | return r; | |
1510 | ||
1511 | r = sd_bus_message_exit_container(message); | |
1512 | if (r < 0) | |
1513 | return r; | |
1514 | ||
1515 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
1516 | _cleanup_free_ char *buf = NULL; | |
1517 | _cleanup_fclose_ FILE *f = NULL; | |
1518 | ExecCommand *c; | |
1519 | size_t size = 0; | |
1520 | ||
1521 | if (n == 0) | |
1522 | *exec_command = exec_command_free_list(*exec_command); | |
1523 | ||
2fe21124 | 1524 | f = open_memstream_unlocked(&buf, &size); |
9c0320e7 YW |
1525 | if (!f) |
1526 | return -ENOMEM; | |
1527 | ||
f14bf013 | 1528 | fprintf(f, "%s=\n", name); |
9c0320e7 YW |
1529 | |
1530 | LIST_FOREACH(command, c, *exec_command) { | |
540ac933 | 1531 | _cleanup_free_ char *a = NULL, *exec_chars = NULL; |
9c0320e7 | 1532 | |
540ac933 LP |
1533 | exec_chars = exec_command_flags_to_exec_chars(c->flags); |
1534 | if (!exec_chars) | |
9c0320e7 YW |
1535 | return -ENOMEM; |
1536 | ||
1537 | a = unit_concat_strv(c->argv, UNIT_ESCAPE_C|UNIT_ESCAPE_SPECIFIERS); | |
1538 | if (!a) | |
1539 | return -ENOMEM; | |
1540 | ||
540ac933 LP |
1541 | if (streq_ptr(c->path, c->argv ? c->argv[0] : NULL)) |
1542 | fprintf(f, "%s=%s%s\n", name, exec_chars, a); | |
1543 | else { | |
1544 | _cleanup_free_ char *t = NULL; | |
1545 | const char *p; | |
1546 | ||
1547 | p = unit_escape_setting(c->path, UNIT_ESCAPE_C|UNIT_ESCAPE_SPECIFIERS, &t); | |
1548 | if (!p) | |
1549 | return -ENOMEM; | |
b3d59367 | 1550 | |
540ac933 LP |
1551 | fprintf(f, "%s=%s@%s %s\n", name, exec_chars, p, a); |
1552 | } | |
9c0320e7 YW |
1553 | } |
1554 | ||
1555 | r = fflush_and_check(f); | |
1556 | if (r < 0) | |
1557 | return r; | |
1558 | ||
1559 | unit_write_setting(u, flags, name, buf); | |
1560 | } | |
1561 | ||
1562 | return 1; | |
1563 | } | |
1564 | ||
7e2a3fcc YW |
1565 | static int parse_personality(const char *s, unsigned long *p) { |
1566 | unsigned long v; | |
1567 | ||
1568 | assert(p); | |
1569 | ||
1570 | v = personality_from_string(s); | |
1571 | if (v == PERSONALITY_INVALID) | |
1572 | return -EINVAL; | |
1573 | ||
1574 | *p = v; | |
1575 | return 0; | |
1576 | } | |
1577 | ||
1578 | static const char* mount_propagation_flags_to_string_with_check(unsigned long n) { | |
1579 | if (!IN_SET(n, 0, MS_SHARED, MS_PRIVATE, MS_SLAVE)) | |
1580 | return NULL; | |
1581 | ||
1582 | return mount_propagation_flags_to_string(n); | |
1583 | } | |
1584 | ||
1585 | static BUS_DEFINE_SET_TRANSIENT(nsec, "t", uint64_t, nsec_t, NSEC_FMT); | |
1586 | static BUS_DEFINE_SET_TRANSIENT_IS_VALID(log_level, "i", int32_t, int, "%" PRIi32, log_level_is_valid); | |
aad67b80 | 1587 | #if HAVE_SECCOMP |
005bfaf1 | 1588 | static BUS_DEFINE_SET_TRANSIENT_IS_VALID(errno, "i", int32_t, int, "%" PRIi32, seccomp_errno_or_action_is_valid); |
aad67b80 | 1589 | #endif |
7e2a3fcc YW |
1590 | static BUS_DEFINE_SET_TRANSIENT_PARSE(std_input, ExecInput, exec_input_from_string); |
1591 | static BUS_DEFINE_SET_TRANSIENT_PARSE(std_output, ExecOutput, exec_output_from_string); | |
1592 | static BUS_DEFINE_SET_TRANSIENT_PARSE(utmp_mode, ExecUtmpMode, exec_utmp_mode_from_string); | |
1e8c7bd5 YW |
1593 | static BUS_DEFINE_SET_TRANSIENT_PARSE(protect_system, ProtectSystem, protect_system_from_string); |
1594 | static BUS_DEFINE_SET_TRANSIENT_PARSE(protect_home, ProtectHome, protect_home_from_string); | |
7e2a3fcc | 1595 | static BUS_DEFINE_SET_TRANSIENT_PARSE(keyring_mode, ExecKeyringMode, exec_keyring_mode_from_string); |
4e399953 LP |
1596 | static BUS_DEFINE_SET_TRANSIENT_PARSE(protect_proc, ProtectProc, protect_proc_from_string); |
1597 | static BUS_DEFINE_SET_TRANSIENT_PARSE(proc_subset, ProcSubset, proc_subset_from_string); | |
7e2a3fcc YW |
1598 | static BUS_DEFINE_SET_TRANSIENT_PARSE(preserve_mode, ExecPreserveMode, exec_preserve_mode_from_string); |
1599 | static BUS_DEFINE_SET_TRANSIENT_PARSE_PTR(personality, unsigned long, parse_personality); | |
1600 | static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(secure_bits, "i", int32_t, int, "%" PRIi32, secure_bits_to_string_alloc_with_check); | |
1601 | static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(capability, "t", uint64_t, uint64_t, "%" PRIu64, capability_set_to_string_alloc); | |
86c2a9f1 | 1602 | static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(namespace_flag, "t", uint64_t, unsigned long, "%" PRIu64, namespace_flags_to_string); |
7e2a3fcc YW |
1603 | static BUS_DEFINE_SET_TRANSIENT_TO_STRING(mount_flags, "t", uint64_t, unsigned long, "%" PRIu64, mount_propagation_flags_to_string_with_check); |
1604 | ||
c7040b5d LP |
1605 | int bus_exec_context_set_transient_property( |
1606 | Unit *u, | |
1607 | ExecContext *c, | |
1608 | const char *name, | |
1609 | sd_bus_message *message, | |
2e59b241 | 1610 | UnitWriteFlags flags, |
c7040b5d LP |
1611 | sd_bus_error *error) { |
1612 | ||
6550c24c LP |
1613 | const char *suffix; |
1614 | int r; | |
c7040b5d LP |
1615 | |
1616 | assert(u); | |
1617 | assert(c); | |
1618 | assert(name); | |
1619 | assert(message); | |
1620 | ||
2e59b241 LP |
1621 | flags |= UNIT_PRIVATE; |
1622 | ||
7e2a3fcc | 1623 | if (streq(name, "User")) |
7a8867ab | 1624 | return bus_set_transient_user_relaxed(u, name, &c->user, message, flags, error); |
c7040b5d | 1625 | |
7e2a3fcc | 1626 | if (streq(name, "Group")) |
7a8867ab | 1627 | return bus_set_transient_user_relaxed(u, name, &c->group, message, flags, error); |
c7040b5d | 1628 | |
7e2a3fcc YW |
1629 | if (streq(name, "TTYPath")) |
1630 | return bus_set_transient_path(u, name, &c->tty_path, message, flags, error); | |
6f3e7985 | 1631 | |
7e2a3fcc YW |
1632 | if (streq(name, "RootImage")) |
1633 | return bus_set_transient_path(u, name, &c->root_image, message, flags, error); | |
76736280 | 1634 | |
18d73705 LB |
1635 | if (streq(name, "RootImageOptions")) { |
1636 | _cleanup_(mount_options_free_allp) MountOptions *options = NULL; | |
1637 | _cleanup_free_ char *format_str = NULL; | |
18d73705 | 1638 | |
988172ce | 1639 | r = bus_read_mount_options(message, error, &options, &format_str, " "); |
18d73705 LB |
1640 | if (r < 0) |
1641 | return r; | |
1642 | ||
1643 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
1644 | if (LIST_IS_EMPTY(options)) { | |
1645 | c->root_image_options = mount_options_free_all(c->root_image_options); | |
1646 | unit_write_settingf(u, flags, name, "%s=", name); | |
1647 | } else { | |
1648 | LIST_JOIN(mount_options, c->root_image_options, options); | |
1649 | unit_write_settingf( | |
1650 | u, flags|UNIT_ESCAPE_SPECIFIERS, name, | |
1651 | "%s=%s", | |
1652 | name, | |
1653 | format_str); | |
1654 | } | |
1655 | } | |
1656 | ||
1657 | return 1; | |
1658 | } | |
1659 | ||
0389f4fa LB |
1660 | if (streq(name, "RootHash")) { |
1661 | const void *roothash_decoded; | |
1662 | size_t roothash_decoded_size; | |
1663 | ||
1664 | r = sd_bus_message_read_array(message, 'y', &roothash_decoded, &roothash_decoded_size); | |
1665 | if (r < 0) | |
1666 | return r; | |
1667 | ||
1668 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
1669 | _cleanup_free_ char *encoded = NULL; | |
1670 | ||
1671 | if (roothash_decoded_size == 0) { | |
1672 | c->root_hash_path = mfree(c->root_hash_path); | |
1673 | c->root_hash = mfree(c->root_hash); | |
1674 | c->root_hash_size = 0; | |
1675 | ||
1676 | unit_write_settingf(u, flags, name, "RootHash="); | |
1677 | } else { | |
c2b2df60 | 1678 | _cleanup_free_ void *p = NULL; |
0389f4fa LB |
1679 | |
1680 | encoded = hexmem(roothash_decoded, roothash_decoded_size); | |
1681 | if (!encoded) | |
1682 | return -ENOMEM; | |
1683 | ||
1684 | p = memdup(roothash_decoded, roothash_decoded_size); | |
1685 | if (!p) | |
1686 | return -ENOMEM; | |
1687 | ||
1688 | free_and_replace(c->root_hash, p); | |
1689 | c->root_hash_size = roothash_decoded_size; | |
1690 | c->root_hash_path = mfree(c->root_hash_path); | |
1691 | ||
1692 | unit_write_settingf(u, flags, name, "RootHash=%s", encoded); | |
1693 | } | |
1694 | } | |
1695 | ||
1696 | return 1; | |
1697 | } | |
1698 | ||
1699 | if (streq(name, "RootHashPath")) { | |
1700 | c->root_hash_size = 0; | |
1701 | c->root_hash = mfree(c->root_hash); | |
1702 | ||
1703 | return bus_set_transient_path(u, "RootHash", &c->root_hash_path, message, flags, error); | |
1704 | } | |
1705 | ||
d4d55b0d LB |
1706 | if (streq(name, "RootHashSignature")) { |
1707 | const void *roothash_sig_decoded; | |
1708 | size_t roothash_sig_decoded_size; | |
1709 | ||
1710 | r = sd_bus_message_read_array(message, 'y', &roothash_sig_decoded, &roothash_sig_decoded_size); | |
1711 | if (r < 0) | |
1712 | return r; | |
1713 | ||
1714 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
1715 | _cleanup_free_ char *encoded = NULL; | |
1716 | ||
1717 | if (roothash_sig_decoded_size == 0) { | |
1718 | c->root_hash_sig_path = mfree(c->root_hash_sig_path); | |
1719 | c->root_hash_sig = mfree(c->root_hash_sig); | |
1720 | c->root_hash_sig_size = 0; | |
1721 | ||
1722 | unit_write_settingf(u, flags, name, "RootHashSignature="); | |
1723 | } else { | |
c2b2df60 | 1724 | _cleanup_free_ void *p = NULL; |
d4d55b0d LB |
1725 | ssize_t len; |
1726 | ||
1727 | len = base64mem(roothash_sig_decoded, roothash_sig_decoded_size, &encoded); | |
1728 | if (len < 0) | |
1729 | return -ENOMEM; | |
1730 | ||
1731 | p = memdup(roothash_sig_decoded, roothash_sig_decoded_size); | |
1732 | if (!p) | |
1733 | return -ENOMEM; | |
1734 | ||
1735 | free_and_replace(c->root_hash_sig, p); | |
1736 | c->root_hash_sig_size = roothash_sig_decoded_size; | |
1737 | c->root_hash_sig_path = mfree(c->root_hash_sig_path); | |
1738 | ||
1739 | unit_write_settingf(u, flags, name, "RootHashSignature=base64:%s", encoded); | |
1740 | } | |
1741 | } | |
1742 | ||
1743 | return 1; | |
1744 | } | |
1745 | ||
1746 | if (streq(name, "RootHashSignaturePath")) { | |
1747 | c->root_hash_sig_size = 0; | |
1748 | c->root_hash_sig = mfree(c->root_hash_sig); | |
1749 | ||
1750 | return bus_set_transient_path(u, "RootHashSignature", &c->root_hash_sig_path, message, flags, error); | |
1751 | } | |
1752 | ||
0389f4fa LB |
1753 | if (streq(name, "RootVerity")) |
1754 | return bus_set_transient_path(u, name, &c->root_verity, message, flags, error); | |
1755 | ||
7e2a3fcc YW |
1756 | if (streq(name, "RootDirectory")) |
1757 | return bus_set_transient_path(u, name, &c->root_directory, message, flags, error); | |
c7040b5d | 1758 | |
7e2a3fcc YW |
1759 | if (streq(name, "SyslogIdentifier")) |
1760 | return bus_set_transient_string(u, name, &c->syslog_identifier, message, flags, error); | |
c7040b5d | 1761 | |
7e2a3fcc YW |
1762 | if (streq(name, "LogLevelMax")) |
1763 | return bus_set_transient_log_level(u, name, &c->log_level_max, message, flags, error); | |
1764 | ||
90fc172e | 1765 | if (streq(name, "LogRateLimitIntervalUSec")) |
5ac1530e | 1766 | return bus_set_transient_usec(u, name, &c->log_ratelimit_interval_usec, message, flags, error); |
90fc172e AZ |
1767 | |
1768 | if (streq(name, "LogRateLimitBurst")) | |
5ac1530e | 1769 | return bus_set_transient_unsigned(u, name, &c->log_ratelimit_burst, message, flags, error); |
90fc172e | 1770 | |
7e2a3fcc YW |
1771 | if (streq(name, "Personality")) |
1772 | return bus_set_transient_personality(u, name, &c->personality, message, flags, error); | |
1773 | ||
7e2a3fcc YW |
1774 | if (streq(name, "StandardInput")) |
1775 | return bus_set_transient_std_input(u, name, &c->std_input, message, flags, error); | |
1776 | ||
1777 | if (streq(name, "StandardOutput")) | |
1778 | return bus_set_transient_std_output(u, name, &c->std_output, message, flags, error); | |
1779 | ||
1780 | if (streq(name, "StandardError")) | |
1781 | return bus_set_transient_std_output(u, name, &c->std_error, message, flags, error); | |
1782 | ||
1783 | if (streq(name, "IgnoreSIGPIPE")) | |
1784 | return bus_set_transient_bool(u, name, &c->ignore_sigpipe, message, flags, error); | |
1785 | ||
1786 | if (streq(name, "TTYVHangup")) | |
1787 | return bus_set_transient_bool(u, name, &c->tty_vhangup, message, flags, error); | |
1788 | ||
1789 | if (streq(name, "TTYReset")) | |
1790 | return bus_set_transient_bool(u, name, &c->tty_reset, message, flags, error); | |
1791 | ||
1792 | if (streq(name, "TTYVTDisallocate")) | |
1793 | return bus_set_transient_bool(u, name, &c->tty_vt_disallocate, message, flags, error); | |
1794 | ||
1795 | if (streq(name, "PrivateTmp")) | |
1796 | return bus_set_transient_bool(u, name, &c->private_tmp, message, flags, error); | |
1797 | ||
1798 | if (streq(name, "PrivateDevices")) | |
1799 | return bus_set_transient_bool(u, name, &c->private_devices, message, flags, error); | |
1800 | ||
228af36f LP |
1801 | if (streq(name, "PrivateMounts")) |
1802 | return bus_set_transient_bool(u, name, &c->private_mounts, message, flags, error); | |
1803 | ||
7e2a3fcc YW |
1804 | if (streq(name, "PrivateNetwork")) |
1805 | return bus_set_transient_bool(u, name, &c->private_network, message, flags, error); | |
1806 | ||
a70581ff XR |
1807 | if (streq(name, "PrivateIPC")) |
1808 | return bus_set_transient_bool(u, name, &c->private_ipc, message, flags, error); | |
1809 | ||
7e2a3fcc YW |
1810 | if (streq(name, "PrivateUsers")) |
1811 | return bus_set_transient_bool(u, name, &c->private_users, message, flags, error); | |
1812 | ||
1813 | if (streq(name, "NoNewPrivileges")) | |
1814 | return bus_set_transient_bool(u, name, &c->no_new_privileges, message, flags, error); | |
1815 | ||
1816 | if (streq(name, "SyslogLevelPrefix")) | |
1817 | return bus_set_transient_bool(u, name, &c->syslog_level_prefix, message, flags, error); | |
1818 | ||
1819 | if (streq(name, "MemoryDenyWriteExecute")) | |
1820 | return bus_set_transient_bool(u, name, &c->memory_deny_write_execute, message, flags, error); | |
1821 | ||
1822 | if (streq(name, "RestrictRealtime")) | |
1823 | return bus_set_transient_bool(u, name, &c->restrict_realtime, message, flags, error); | |
1824 | ||
f69567cb LP |
1825 | if (streq(name, "RestrictSUIDSGID")) |
1826 | return bus_set_transient_bool(u, name, &c->restrict_suid_sgid, message, flags, error); | |
1827 | ||
7e2a3fcc YW |
1828 | if (streq(name, "DynamicUser")) |
1829 | return bus_set_transient_bool(u, name, &c->dynamic_user, message, flags, error); | |
1830 | ||
1831 | if (streq(name, "RemoveIPC")) | |
1832 | return bus_set_transient_bool(u, name, &c->remove_ipc, message, flags, error); | |
1833 | ||
1834 | if (streq(name, "ProtectKernelTunables")) | |
1835 | return bus_set_transient_bool(u, name, &c->protect_kernel_tunables, message, flags, error); | |
1836 | ||
1837 | if (streq(name, "ProtectKernelModules")) | |
1838 | return bus_set_transient_bool(u, name, &c->protect_kernel_modules, message, flags, error); | |
1839 | ||
84703040 KK |
1840 | if (streq(name, "ProtectKernelLogs")) |
1841 | return bus_set_transient_bool(u, name, &c->protect_kernel_logs, message, flags, error); | |
1842 | ||
fc64760d KK |
1843 | if (streq(name, "ProtectClock")) |
1844 | return bus_set_transient_bool(u, name, &c->protect_clock, message, flags, error); | |
1845 | ||
7e2a3fcc YW |
1846 | if (streq(name, "ProtectControlGroups")) |
1847 | return bus_set_transient_bool(u, name, &c->protect_control_groups, message, flags, error); | |
1848 | ||
7e2a3fcc YW |
1849 | if (streq(name, "CPUSchedulingResetOnFork")) |
1850 | return bus_set_transient_bool(u, name, &c->cpu_sched_reset_on_fork, message, flags, error); | |
1851 | ||
1852 | if (streq(name, "NonBlocking")) | |
1853 | return bus_set_transient_bool(u, name, &c->non_blocking, message, flags, error); | |
1854 | ||
1855 | if (streq(name, "LockPersonality")) | |
1856 | return bus_set_transient_bool(u, name, &c->lock_personality, message, flags, error); | |
1857 | ||
aecd5ac6 TM |
1858 | if (streq(name, "ProtectHostname")) |
1859 | return bus_set_transient_bool(u, name, &c->protect_hostname, message, flags, error); | |
1860 | ||
7e2a3fcc YW |
1861 | if (streq(name, "UtmpIdentifier")) |
1862 | return bus_set_transient_string(u, name, &c->utmp_id, message, flags, error); | |
1863 | ||
1864 | if (streq(name, "UtmpMode")) | |
1865 | return bus_set_transient_utmp_mode(u, name, &c->utmp_mode, message, flags, error); | |
1866 | ||
1867 | if (streq(name, "PAMName")) | |
1868 | return bus_set_transient_string(u, name, &c->pam_name, message, flags, error); | |
1869 | ||
1870 | if (streq(name, "TimerSlackNSec")) | |
1871 | return bus_set_transient_nsec(u, name, &c->timer_slack_nsec, message, flags, error); | |
1872 | ||
1873 | if (streq(name, "ProtectSystem")) | |
1874 | return bus_set_transient_protect_system(u, name, &c->protect_system, message, flags, error); | |
1875 | ||
1876 | if (streq(name, "ProtectHome")) | |
1877 | return bus_set_transient_protect_home(u, name, &c->protect_home, message, flags, error); | |
cffaed83 | 1878 | |
7e2a3fcc YW |
1879 | if (streq(name, "KeyringMode")) |
1880 | return bus_set_transient_keyring_mode(u, name, &c->keyring_mode, message, flags, error); | |
1881 | ||
4e399953 LP |
1882 | if (streq(name, "ProtectProc")) |
1883 | return bus_set_transient_protect_proc(u, name, &c->protect_proc, message, flags, error); | |
1884 | ||
1885 | if (streq(name, "ProcSubset")) | |
1886 | return bus_set_transient_proc_subset(u, name, &c->proc_subset, message, flags, error); | |
1887 | ||
7e2a3fcc YW |
1888 | if (streq(name, "RuntimeDirectoryPreserve")) |
1889 | return bus_set_transient_preserve_mode(u, name, &c->runtime_directory_preserve_mode, message, flags, error); | |
1890 | ||
1891 | if (streq(name, "UMask")) | |
1892 | return bus_set_transient_mode_t(u, name, &c->umask, message, flags, error); | |
1893 | ||
1894 | if (streq(name, "RuntimeDirectoryMode")) | |
1895 | return bus_set_transient_mode_t(u, name, &c->directories[EXEC_DIRECTORY_RUNTIME].mode, message, flags, error); | |
1896 | ||
1897 | if (streq(name, "StateDirectoryMode")) | |
1898 | return bus_set_transient_mode_t(u, name, &c->directories[EXEC_DIRECTORY_STATE].mode, message, flags, error); | |
1899 | ||
1900 | if (streq(name, "CacheDirectoryMode")) | |
1901 | return bus_set_transient_mode_t(u, name, &c->directories[EXEC_DIRECTORY_CACHE].mode, message, flags, error); | |
1902 | ||
1903 | if (streq(name, "LogsDirectoryMode")) | |
1904 | return bus_set_transient_mode_t(u, name, &c->directories[EXEC_DIRECTORY_LOGS].mode, message, flags, error); | |
1905 | ||
1906 | if (streq(name, "ConfigurationDirectoryMode")) | |
1907 | return bus_set_transient_mode_t(u, name, &c->directories[EXEC_DIRECTORY_CONFIGURATION].mode, message, flags, error); | |
1908 | ||
1909 | if (streq(name, "SELinuxContext")) | |
1910 | return bus_set_transient_string(u, name, &c->selinux_context, message, flags, error); | |
1911 | ||
1912 | if (streq(name, "SecureBits")) | |
1913 | return bus_set_transient_secure_bits(u, name, &c->secure_bits, message, flags, error); | |
1914 | ||
1915 | if (streq(name, "CapabilityBoundingSet")) | |
1916 | return bus_set_transient_capability(u, name, &c->capability_bounding_set, message, flags, error); | |
1917 | ||
1918 | if (streq(name, "AmbientCapabilities")) | |
1919 | return bus_set_transient_capability(u, name, &c->capability_ambient_set, message, flags, error); | |
1920 | ||
7e2a3fcc YW |
1921 | if (streq(name, "RestrictNamespaces")) |
1922 | return bus_set_transient_namespace_flag(u, name, &c->restrict_namespaces, message, flags, error); | |
1923 | ||
cc86a278 ILG |
1924 | if (streq(name, "RestrictFileSystems")) { |
1925 | int allow_list; | |
1926 | _cleanup_strv_free_ char **l = NULL; | |
1927 | ||
1928 | r = sd_bus_message_enter_container(message, 'r', "bas"); | |
1929 | if (r < 0) | |
1930 | return r; | |
1931 | ||
1932 | r = sd_bus_message_read(message, "b", &allow_list); | |
1933 | if (r < 0) | |
1934 | return r; | |
1935 | ||
1936 | r = sd_bus_message_read_strv(message, &l); | |
1937 | if (r < 0) | |
1938 | return r; | |
1939 | ||
1940 | r = sd_bus_message_exit_container(message); | |
1941 | if (r < 0) | |
1942 | return r; | |
1943 | ||
1944 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
1945 | _cleanup_free_ char *joined = NULL; | |
1946 | FilesystemParseFlags invert_flag = allow_list ? 0 : FILESYSTEM_PARSE_INVERT; | |
1947 | char **s; | |
1948 | ||
1949 | if (strv_isempty(l)) { | |
1950 | c->restrict_filesystems_allow_list = false; | |
1951 | c->restrict_filesystems = set_free(c->restrict_filesystems); | |
1952 | ||
1953 | unit_write_setting(u, flags, name, "RestrictFileSystems="); | |
1954 | return 1; | |
1955 | } | |
1956 | ||
1957 | if (!c->restrict_filesystems) | |
1958 | c->restrict_filesystems_allow_list = allow_list; | |
1959 | ||
1960 | STRV_FOREACH(s, l) { | |
1961 | r = lsm_bpf_parse_filesystem( | |
1962 | *s, | |
1963 | &c->restrict_filesystems, | |
1964 | FILESYSTEM_PARSE_LOG| | |
1965 | (invert_flag ? FILESYSTEM_PARSE_INVERT : 0)| | |
1966 | (c->restrict_filesystems_allow_list ? FILESYSTEM_PARSE_ALLOW_LIST : 0), | |
1967 | u->id, NULL, 0); | |
1968 | if (r < 0) | |
1969 | return r; | |
1970 | } | |
1971 | ||
1972 | joined = strv_join(l, " "); | |
1973 | if (!joined) | |
1974 | return -ENOMEM; | |
1975 | ||
1976 | unit_write_settingf(u, flags, name, "%s=%s%s", name, allow_list ? "" : "~", joined); | |
1977 | } | |
1978 | ||
1979 | return 1; | |
1980 | } | |
1981 | ||
7e2a3fcc YW |
1982 | if (streq(name, "MountFlags")) |
1983 | return bus_set_transient_mount_flags(u, name, &c->mount_flags, message, flags, error); | |
1984 | ||
a8d08f39 LP |
1985 | if (streq(name, "NetworkNamespacePath")) |
1986 | return bus_set_transient_path(u, name, &c->network_namespace_path, message, flags, error); | |
1987 | ||
a70581ff XR |
1988 | if (streq(name, "IPCNamespacePath")) |
1989 | return bus_set_transient_path(u, name, &c->ipc_namespace_path, message, flags, error); | |
1990 | ||
7e2a3fcc | 1991 | if (streq(name, "SupplementaryGroups")) { |
cffaed83 YW |
1992 | _cleanup_strv_free_ char **l = NULL; |
1993 | char **p; | |
1994 | ||
1995 | r = sd_bus_message_read_strv(message, &l); | |
1996 | if (r < 0) | |
1997 | return r; | |
1998 | ||
d2a23692 | 1999 | STRV_FOREACH(p, l) |
7a8867ab | 2000 | if (!isempty(*p) && !valid_user_group_name(*p, VALID_USER_ALLOW_NUMERIC|VALID_USER_RELAX|VALID_USER_WARN)) |
d2a23692 ZJS |
2001 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, |
2002 | "Invalid supplementary group names"); | |
cffaed83 | 2003 | |
2e59b241 | 2004 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
7b943bb7 | 2005 | if (strv_isempty(l)) { |
cffaed83 | 2006 | c->supplementary_groups = strv_free(c->supplementary_groups); |
2e59b241 | 2007 | unit_write_settingf(u, flags, name, "%s=", name); |
cffaed83 YW |
2008 | } else { |
2009 | _cleanup_free_ char *joined = NULL; | |
2010 | ||
2011 | r = strv_extend_strv(&c->supplementary_groups, l, true); | |
2012 | if (r < 0) | |
2013 | return -ENOMEM; | |
2014 | ||
2015 | joined = strv_join(c->supplementary_groups, " "); | |
2016 | if (!joined) | |
2017 | return -ENOMEM; | |
2018 | ||
2e59b241 | 2019 | unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "%s=%s", name, joined); |
cffaed83 YW |
2020 | } |
2021 | } | |
2022 | ||
2023 | return 1; | |
2024 | ||
43144be4 | 2025 | } else if (STR_IN_SET(name, "SetCredential", "SetCredentialEncrypted")) { |
bb0c0d6f LP |
2026 | bool isempty = true; |
2027 | ||
2028 | r = sd_bus_message_enter_container(message, 'a', "(say)"); | |
2029 | if (r < 0) | |
2030 | return r; | |
2031 | ||
2032 | for (;;) { | |
2033 | const char *id; | |
2034 | const void *p; | |
2035 | size_t sz; | |
2036 | ||
2037 | r = sd_bus_message_enter_container(message, 'r', "say"); | |
2038 | if (r < 0) | |
2039 | return r; | |
2040 | if (r == 0) | |
2041 | break; | |
2042 | ||
2043 | r = sd_bus_message_read(message, "s", &id); | |
2044 | if (r < 0) | |
2045 | return r; | |
2046 | ||
2047 | r = sd_bus_message_read_array(message, 'y', &p, &sz); | |
2048 | if (r < 0) | |
2049 | return r; | |
2050 | ||
2051 | r = sd_bus_message_exit_container(message); | |
2052 | if (r < 0) | |
2053 | return r; | |
2054 | ||
2055 | if (!credential_name_valid(id)) | |
2056 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Credential ID is invalid: %s", id); | |
2057 | ||
2058 | isempty = false; | |
2059 | ||
2060 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
2061 | _cleanup_free_ char *a = NULL, *b = NULL; | |
2062 | _cleanup_free_ void *copy = NULL; | |
2063 | ExecSetCredential *old; | |
2064 | ||
2065 | copy = memdup(p, sz); | |
2066 | if (!copy) | |
2067 | return -ENOMEM; | |
2068 | ||
2069 | old = hashmap_get(c->set_credentials, id); | |
2070 | if (old) { | |
2071 | free_and_replace(old->data, copy); | |
2072 | old->size = sz; | |
43144be4 | 2073 | old->encrypted = streq(name, "SetCredentialEncrypted"); |
bb0c0d6f LP |
2074 | } else { |
2075 | _cleanup_(exec_set_credential_freep) ExecSetCredential *sc = NULL; | |
2076 | ||
43144be4 | 2077 | sc = new(ExecSetCredential, 1); |
bb0c0d6f LP |
2078 | if (!sc) |
2079 | return -ENOMEM; | |
2080 | ||
43144be4 LP |
2081 | *sc = (ExecSetCredential) { |
2082 | .id = strdup(id), | |
2083 | .data = TAKE_PTR(copy), | |
2084 | .size = sz, | |
2085 | .encrypted = streq(name, "SetCredentialEncrypted"), | |
2086 | }; | |
2087 | ||
bb0c0d6f LP |
2088 | if (!sc->id) |
2089 | return -ENOMEM; | |
2090 | ||
cf55fe4a | 2091 | r = hashmap_ensure_put(&c->set_credentials, &exec_set_credential_hash_ops, sc->id, sc); |
bb0c0d6f LP |
2092 | if (r < 0) |
2093 | return r; | |
2094 | ||
2095 | TAKE_PTR(sc); | |
2096 | } | |
2097 | ||
2098 | a = specifier_escape(id); | |
2099 | if (!a) | |
2100 | return -ENOMEM; | |
2101 | ||
2102 | b = cescape_length(p, sz); | |
2103 | if (!b) | |
2104 | return -ENOMEM; | |
2105 | ||
2106 | (void) unit_write_settingf(u, flags, name, "%s=%s:%s", name, a, b); | |
2107 | } | |
2108 | } | |
2109 | ||
2110 | r = sd_bus_message_exit_container(message); | |
2111 | if (r < 0) | |
2112 | return r; | |
2113 | ||
2114 | if (!UNIT_WRITE_FLAGS_NOOP(flags) && isempty) { | |
2115 | c->set_credentials = hashmap_free(c->set_credentials); | |
2116 | (void) unit_write_settingf(u, flags, name, "%s=", name); | |
2117 | } | |
2118 | ||
2119 | return 1; | |
2120 | ||
43144be4 | 2121 | } else if (STR_IN_SET(name, "LoadCredential", "LoadCredentialEncrypted")) { |
bb0c0d6f LP |
2122 | bool isempty = true; |
2123 | ||
2124 | r = sd_bus_message_enter_container(message, 'a', "(ss)"); | |
2125 | if (r < 0) | |
2126 | return r; | |
2127 | ||
2128 | for (;;) { | |
2129 | const char *id, *source; | |
2130 | ||
2131 | r = sd_bus_message_read(message, "(ss)", &id, &source); | |
2132 | if (r < 0) | |
2133 | return r; | |
2134 | if (r == 0) | |
2135 | break; | |
2136 | ||
2137 | if (!credential_name_valid(id)) | |
2138 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Credential ID is invalid: %s", id); | |
2139 | ||
2140 | if (!(path_is_absolute(source) ? path_is_normalized(source) : credential_name_valid(source))) | |
2141 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Credential source is invalid: %s", source); | |
2142 | ||
2143 | isempty = false; | |
2144 | ||
2145 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
43144be4 LP |
2146 | _cleanup_free_ char *copy = NULL; |
2147 | ExecLoadCredential *old; | |
2148 | ||
2149 | copy = strdup(source); | |
2150 | if (!copy) | |
2151 | return -ENOMEM; | |
2152 | ||
2153 | old = hashmap_get(c->load_credentials, id); | |
2154 | if (old) { | |
2155 | free_and_replace(old->path, copy); | |
2156 | old->encrypted = streq(name, "LoadCredentialEncrypted"); | |
2157 | } else { | |
2158 | _cleanup_(exec_load_credential_freep) ExecLoadCredential *lc = NULL; | |
2159 | ||
2160 | lc = new(ExecLoadCredential, 1); | |
2161 | if (!lc) | |
2162 | return -ENOMEM; | |
2163 | ||
2164 | *lc = (ExecLoadCredential) { | |
2165 | .id = strdup(id), | |
2166 | .path = TAKE_PTR(copy), | |
2167 | .encrypted = streq(name, "LoadCredentialEncrypted"), | |
2168 | }; | |
2169 | ||
2170 | if (!lc->id) | |
2171 | return -ENOMEM; | |
2172 | ||
2173 | r = hashmap_ensure_put(&c->load_credentials, &exec_load_credential_hash_ops, lc->id, lc); | |
2174 | if (r < 0) | |
2175 | return r; | |
2176 | ||
2177 | TAKE_PTR(lc); | |
2178 | } | |
bb0c0d6f LP |
2179 | |
2180 | (void) unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "%s=%s:%s", name, id, source); | |
2181 | } | |
2182 | } | |
2183 | ||
2184 | r = sd_bus_message_exit_container(message); | |
2185 | if (r < 0) | |
2186 | return r; | |
2187 | ||
2188 | if (!UNIT_WRITE_FLAGS_NOOP(flags) && isempty) { | |
43144be4 | 2189 | c->load_credentials = hashmap_free(c->load_credentials); |
bb0c0d6f LP |
2190 | (void) unit_write_settingf(u, flags, name, "%s=", name); |
2191 | } | |
2192 | ||
2193 | return 1; | |
2194 | ||
a8a13575 | 2195 | } else if (streq(name, "SyslogLevel")) { |
8d1dd6ab | 2196 | int32_t level; |
a8a13575 EV |
2197 | |
2198 | r = sd_bus_message_read(message, "i", &level); | |
2199 | if (r < 0) | |
2200 | return r; | |
2201 | ||
e0d6e0fa | 2202 | if (!log_level_is_valid(level)) |
1b09b81c | 2203 | return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Log level value out of range"); |
e0d6e0fa | 2204 | |
2e59b241 | 2205 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
a8a13575 | 2206 | c->syslog_priority = (c->syslog_priority & LOG_FACMASK) | level; |
2e59b241 | 2207 | unit_write_settingf(u, flags, name, "SyslogLevel=%i", level); |
a8a13575 EV |
2208 | } |
2209 | ||
460ed929 | 2210 | return 1; |
7e2a3fcc | 2211 | |
460ed929 | 2212 | } else if (streq(name, "SyslogFacility")) { |
8d1dd6ab | 2213 | int32_t facility; |
460ed929 EV |
2214 | |
2215 | r = sd_bus_message_read(message, "i", &facility); | |
2216 | if (r < 0) | |
2217 | return r; | |
2218 | ||
e0d6e0fa | 2219 | if (!log_facility_unshifted_is_valid(facility)) |
1b09b81c | 2220 | return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Log facility value out of range"); |
e0d6e0fa | 2221 | |
2e59b241 | 2222 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
460ed929 | 2223 | c->syslog_priority = (facility << 3) | LOG_PRI(c->syslog_priority); |
2e59b241 | 2224 | unit_write_settingf(u, flags, name, "SyslogFacility=%i", facility); |
460ed929 EV |
2225 | } |
2226 | ||
cffaed83 | 2227 | return 1; |
d3070fbd | 2228 | |
91dd5f7c LP |
2229 | } else if (streq(name, "LogNamespace")) { |
2230 | const char *n; | |
2231 | ||
2232 | r = sd_bus_message_read(message, "s", &n); | |
2233 | if (r < 0) | |
2234 | return r; | |
2235 | ||
2236 | if (!isempty(n) && !log_namespace_name_valid(n)) | |
1b09b81c | 2237 | return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Log namespace name not valid"); |
91dd5f7c LP |
2238 | |
2239 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
2240 | ||
2241 | if (isempty(n)) { | |
2242 | c->log_namespace = mfree(c->log_namespace); | |
2243 | unit_write_settingf(u, flags, name, "%s=", name); | |
2244 | } else { | |
2245 | r = free_and_strdup(&c->log_namespace, n); | |
2246 | if (r < 0) | |
2247 | return r; | |
2248 | ||
2249 | unit_write_settingf(u, flags, name, "%s=%s", name, n); | |
2250 | } | |
2251 | } | |
2252 | ||
2253 | return 1; | |
2254 | ||
d3070fbd LP |
2255 | } else if (streq(name, "LogExtraFields")) { |
2256 | size_t n = 0; | |
2257 | ||
2258 | r = sd_bus_message_enter_container(message, 'a', "ay"); | |
2259 | if (r < 0) | |
2260 | return r; | |
2261 | ||
2262 | for (;;) { | |
2263 | _cleanup_free_ void *copy = NULL; | |
2264 | struct iovec *t; | |
2265 | const char *eq; | |
2266 | const void *p; | |
2267 | size_t sz; | |
2268 | ||
2269 | /* Note that we expect a byte array for each field, instead of a string. That's because on the | |
2270 | * lower-level journal fields can actually contain binary data and are not restricted to text, | |
2271 | * and we should not "lose precision" in our types on the way. That said, I am pretty sure | |
2272 | * actually encoding binary data as unit metadata is not a good idea. Hence we actually refuse | |
2273 | * any actual binary data, and only accept UTF-8. This allows us to eventually lift this | |
2274 | * limitation, should a good, valid usecase arise. */ | |
2275 | ||
2276 | r = sd_bus_message_read_array(message, 'y', &p, &sz); | |
2277 | if (r < 0) | |
2278 | return r; | |
2279 | if (r == 0) | |
2280 | break; | |
2281 | ||
2282 | if (memchr(p, 0, sz)) | |
1b09b81c | 2283 | return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Journal field contains zero byte"); |
d3070fbd LP |
2284 | |
2285 | eq = memchr(p, '=', sz); | |
2286 | if (!eq) | |
1b09b81c | 2287 | return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Journal field contains no '=' character"); |
d3070fbd | 2288 | if (!journal_field_valid(p, eq - (const char*) p, false)) |
1b09b81c | 2289 | return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Journal field invalid"); |
d3070fbd | 2290 | |
2e59b241 | 2291 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
aa484f35 | 2292 | t = reallocarray(c->log_extra_fields, c->n_log_extra_fields+1, sizeof(struct iovec)); |
d3070fbd LP |
2293 | if (!t) |
2294 | return -ENOMEM; | |
2295 | c->log_extra_fields = t; | |
2296 | } | |
2297 | ||
2298 | copy = malloc(sz + 1); | |
2299 | if (!copy) | |
2300 | return -ENOMEM; | |
2301 | ||
2302 | memcpy(copy, p, sz); | |
2303 | ((uint8_t*) copy)[sz] = 0; | |
2304 | ||
2305 | if (!utf8_is_valid(copy)) | |
1b09b81c | 2306 | return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Journal field is not valid UTF-8"); |
d3070fbd | 2307 | |
2e59b241 | 2308 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
d3070fbd | 2309 | c->log_extra_fields[c->n_log_extra_fields++] = IOVEC_MAKE(copy, sz); |
2e59b241 | 2310 | unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS|UNIT_ESCAPE_C, name, "LogExtraFields=%s", (char*) copy); |
d3070fbd LP |
2311 | |
2312 | copy = NULL; | |
2313 | } | |
2314 | ||
2315 | n++; | |
2316 | } | |
2317 | ||
2318 | r = sd_bus_message_exit_container(message); | |
2319 | if (r < 0) | |
2320 | return r; | |
2321 | ||
2e59b241 | 2322 | if (!UNIT_WRITE_FLAGS_NOOP(flags) && n == 0) { |
d3070fbd | 2323 | exec_context_free_log_extra_fields(c); |
2e59b241 | 2324 | unit_write_setting(u, flags, name, "LogExtraFields="); |
d3070fbd LP |
2325 | } |
2326 | ||
2327 | return 1; | |
7e2a3fcc | 2328 | } |
cffaed83 | 2329 | |
349cc4a5 | 2330 | #if HAVE_SECCOMP |
cffaed83 | 2331 | |
7e2a3fcc YW |
2332 | if (streq(name, "SystemCallErrorNumber")) |
2333 | return bus_set_transient_errno(u, name, &c->syscall_errno, message, flags, error); | |
2334 | ||
2335 | if (streq(name, "SystemCallFilter")) { | |
6b000af4 | 2336 | int allow_list; |
3f856a28 | 2337 | _cleanup_strv_free_ char **l = NULL; |
cffaed83 YW |
2338 | |
2339 | r = sd_bus_message_enter_container(message, 'r', "bas"); | |
2340 | if (r < 0) | |
2341 | return r; | |
2342 | ||
6b000af4 | 2343 | r = sd_bus_message_read(message, "b", &allow_list); |
cffaed83 YW |
2344 | if (r < 0) |
2345 | return r; | |
2346 | ||
2347 | r = sd_bus_message_read_strv(message, &l); | |
2348 | if (r < 0) | |
2349 | return r; | |
2350 | ||
2351 | r = sd_bus_message_exit_container(message); | |
2352 | if (r < 0) | |
2353 | return r; | |
2354 | ||
2e59b241 | 2355 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
cffaed83 | 2356 | _cleanup_free_ char *joined = NULL; |
6b000af4 | 2357 | SeccompParseFlags invert_flag = allow_list ? 0 : SECCOMP_PARSE_INVERT; |
898748d8 | 2358 | char **s; |
cffaed83 | 2359 | |
7b943bb7 | 2360 | if (strv_isempty(l)) { |
6b000af4 | 2361 | c->syscall_allow_list = false; |
8cfa775f | 2362 | c->syscall_filter = hashmap_free(c->syscall_filter); |
cffaed83 | 2363 | |
898748d8 YW |
2364 | unit_write_settingf(u, flags, name, "SystemCallFilter="); |
2365 | return 1; | |
2366 | } | |
cffaed83 | 2367 | |
898748d8 YW |
2368 | if (!c->syscall_filter) { |
2369 | c->syscall_filter = hashmap_new(NULL); | |
2370 | if (!c->syscall_filter) | |
2371 | return log_oom(); | |
cffaed83 | 2372 | |
6b000af4 | 2373 | c->syscall_allow_list = allow_list; |
8cfa775f | 2374 | |
6b000af4 | 2375 | if (c->syscall_allow_list) { |
e7ccdfa8 ZJS |
2376 | r = seccomp_parse_syscall_filter("@default", |
2377 | -1, | |
2378 | c->syscall_filter, | |
72545ae0 | 2379 | SECCOMP_PARSE_PERMISSIVE | |
6b000af4 | 2380 | SECCOMP_PARSE_ALLOW_LIST | invert_flag, |
58f6ab44 ZJS |
2381 | u->id, |
2382 | NULL, 0); | |
8cfa775f YW |
2383 | if (r < 0) |
2384 | return r; | |
898748d8 YW |
2385 | } |
2386 | } | |
8cfa775f | 2387 | |
898748d8 YW |
2388 | STRV_FOREACH(s, l) { |
2389 | _cleanup_free_ char *n = NULL; | |
2390 | int e; | |
cffaed83 | 2391 | |
898748d8 YW |
2392 | r = parse_syscall_and_errno(*s, &n, &e); |
2393 | if (r < 0) | |
2394 | return r; | |
cffaed83 | 2395 | |
084a46d7 YW |
2396 | if (allow_list && e >= 0) |
2397 | return -EINVAL; | |
2398 | ||
e7ccdfa8 ZJS |
2399 | r = seccomp_parse_syscall_filter(n, |
2400 | e, | |
2401 | c->syscall_filter, | |
72545ae0 AZ |
2402 | SECCOMP_PARSE_LOG | SECCOMP_PARSE_PERMISSIVE | |
2403 | invert_flag | | |
6b000af4 | 2404 | (c->syscall_allow_list ? SECCOMP_PARSE_ALLOW_LIST : 0), |
58f6ab44 ZJS |
2405 | u->id, |
2406 | NULL, 0); | |
898748d8 YW |
2407 | if (r < 0) |
2408 | return r; | |
cffaed83 YW |
2409 | } |
2410 | ||
2411 | joined = strv_join(l, " "); | |
2412 | if (!joined) | |
2413 | return -ENOMEM; | |
2414 | ||
6b000af4 | 2415 | unit_write_settingf(u, flags, name, "SystemCallFilter=%s%s", allow_list ? "" : "~", joined); |
cffaed83 YW |
2416 | } |
2417 | ||
2418 | return 1; | |
2419 | ||
9df2cdd8 TM |
2420 | } else if (streq(name, "SystemCallLog")) { |
2421 | int allow_list; | |
2422 | _cleanup_strv_free_ char **l = NULL; | |
2423 | ||
2424 | r = sd_bus_message_enter_container(message, 'r', "bas"); | |
2425 | if (r < 0) | |
2426 | return r; | |
2427 | ||
2428 | r = sd_bus_message_read(message, "b", &allow_list); | |
2429 | if (r < 0) | |
2430 | return r; | |
2431 | ||
2432 | r = sd_bus_message_read_strv(message, &l); | |
2433 | if (r < 0) | |
2434 | return r; | |
2435 | ||
2436 | r = sd_bus_message_exit_container(message); | |
2437 | if (r < 0) | |
2438 | return r; | |
2439 | ||
2440 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
2441 | _cleanup_free_ char *joined = NULL; | |
2442 | SeccompParseFlags invert_flag = allow_list ? 0 : SECCOMP_PARSE_INVERT; | |
2443 | char **s; | |
2444 | ||
2445 | if (strv_isempty(l)) { | |
2446 | c->syscall_log_allow_list = false; | |
2447 | c->syscall_log = hashmap_free(c->syscall_log); | |
2448 | ||
2449 | unit_write_settingf(u, flags, name, "SystemCallLog="); | |
2450 | return 1; | |
2451 | } | |
2452 | ||
2453 | if (!c->syscall_log) { | |
2454 | c->syscall_log = hashmap_new(NULL); | |
2455 | if (!c->syscall_log) | |
2456 | return log_oom(); | |
2457 | ||
2458 | c->syscall_log_allow_list = allow_list; | |
2459 | } | |
2460 | ||
2461 | STRV_FOREACH(s, l) { | |
696a13ba YW |
2462 | r = seccomp_parse_syscall_filter(*s, |
2463 | -1, /* errno not used */ | |
9df2cdd8 TM |
2464 | c->syscall_log, |
2465 | SECCOMP_PARSE_LOG | SECCOMP_PARSE_PERMISSIVE | | |
2466 | invert_flag | | |
2467 | (c->syscall_log_allow_list ? SECCOMP_PARSE_ALLOW_LIST : 0), | |
2468 | u->id, | |
2469 | NULL, 0); | |
2470 | if (r < 0) | |
2471 | return r; | |
2472 | } | |
2473 | ||
2474 | joined = strv_join(l, " "); | |
2475 | if (!joined) | |
2476 | return -ENOMEM; | |
2477 | ||
2478 | unit_write_settingf(u, flags, name, "SystemCallLog=%s%s", allow_list ? "" : "~", joined); | |
2479 | } | |
2480 | ||
2481 | return 1; | |
2482 | ||
cffaed83 YW |
2483 | } else if (streq(name, "SystemCallArchitectures")) { |
2484 | _cleanup_strv_free_ char **l = NULL; | |
2485 | ||
2486 | r = sd_bus_message_read_strv(message, &l); | |
2487 | if (r < 0) | |
2488 | return r; | |
2489 | ||
2e59b241 | 2490 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
cffaed83 YW |
2491 | _cleanup_free_ char *joined = NULL; |
2492 | ||
7b943bb7 | 2493 | if (strv_isempty(l)) |
cffaed83 YW |
2494 | c->syscall_archs = set_free(c->syscall_archs); |
2495 | else { | |
2496 | char **s; | |
2497 | ||
cffaed83 YW |
2498 | STRV_FOREACH(s, l) { |
2499 | uint32_t a; | |
2500 | ||
2501 | r = seccomp_arch_from_string(*s, &a); | |
2502 | if (r < 0) | |
2503 | return r; | |
2504 | ||
de7fef4b | 2505 | r = set_ensure_put(&c->syscall_archs, NULL, UINT32_TO_PTR(a + 1)); |
cffaed83 YW |
2506 | if (r < 0) |
2507 | return r; | |
2508 | } | |
2509 | ||
2510 | } | |
2511 | ||
2512 | joined = strv_join(l, " "); | |
2513 | if (!joined) | |
2514 | return -ENOMEM; | |
2515 | ||
2e59b241 | 2516 | unit_write_settingf(u, flags, name, "%s=%s", name, joined); |
cffaed83 YW |
2517 | } |
2518 | ||
2519 | return 1; | |
2520 | ||
cffaed83 | 2521 | } else if (streq(name, "RestrictAddressFamilies")) { |
3f856a28 | 2522 | _cleanup_strv_free_ char **l = NULL; |
4e6c50a5 | 2523 | int allow_list; |
cffaed83 YW |
2524 | |
2525 | r = sd_bus_message_enter_container(message, 'r', "bas"); | |
2526 | if (r < 0) | |
2527 | return r; | |
2528 | ||
6b000af4 | 2529 | r = sd_bus_message_read(message, "b", &allow_list); |
cffaed83 YW |
2530 | if (r < 0) |
2531 | return r; | |
2532 | ||
2533 | r = sd_bus_message_read_strv(message, &l); | |
2534 | if (r < 0) | |
2535 | return r; | |
2536 | ||
2537 | r = sd_bus_message_exit_container(message); | |
2538 | if (r < 0) | |
2539 | return r; | |
2540 | ||
2e59b241 | 2541 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
cffaed83 | 2542 | _cleanup_free_ char *joined = NULL; |
9ee896d5 | 2543 | char **s; |
cffaed83 | 2544 | |
7b943bb7 | 2545 | if (strv_isempty(l)) { |
4e6c50a5 | 2546 | c->address_families_allow_list = allow_list; |
cffaed83 | 2547 | c->address_families = set_free(c->address_families); |
cffaed83 | 2548 | |
4e6c50a5 YW |
2549 | unit_write_settingf(u, flags, name, "RestrictAddressFamilies=%s", |
2550 | allow_list ? "none" : ""); | |
9ee896d5 YW |
2551 | return 1; |
2552 | } | |
cffaed83 | 2553 | |
9ee896d5 YW |
2554 | if (!c->address_families) { |
2555 | c->address_families = set_new(NULL); | |
2556 | if (!c->address_families) | |
2557 | return log_oom(); | |
cffaed83 | 2558 | |
6b000af4 | 2559 | c->address_families_allow_list = allow_list; |
9ee896d5 YW |
2560 | } |
2561 | ||
2562 | STRV_FOREACH(s, l) { | |
2563 | int af; | |
cffaed83 | 2564 | |
9ee896d5 | 2565 | af = af_from_name(*s); |
acf4d158 YW |
2566 | if (af < 0) |
2567 | return af; | |
cffaed83 | 2568 | |
6b000af4 | 2569 | if (allow_list == c->address_families_allow_list) { |
cffaed83 YW |
2570 | r = set_put(c->address_families, INT_TO_PTR(af)); |
2571 | if (r < 0) | |
2572 | return r; | |
9ee896d5 | 2573 | } else |
4e6c50a5 | 2574 | set_remove(c->address_families, INT_TO_PTR(af)); |
cffaed83 YW |
2575 | } |
2576 | ||
2577 | joined = strv_join(l, " "); | |
2578 | if (!joined) | |
2579 | return -ENOMEM; | |
2580 | ||
6b000af4 | 2581 | unit_write_settingf(u, flags, name, "RestrictAddressFamilies=%s%s", allow_list ? "" : "~", joined); |
cffaed83 YW |
2582 | } |
2583 | ||
2584 | return 1; | |
7e2a3fcc | 2585 | } |
cffaed83 | 2586 | #endif |
b070c7c0 | 2587 | if (STR_IN_SET(name, "CPUAffinity", "NUMAMask")) { |
cffaed83 | 2588 | const void *a; |
bd0abfae | 2589 | size_t n; |
b070c7c0 | 2590 | bool affinity = streq(name, "CPUAffinity"); |
c367f996 | 2591 | _cleanup_(cpu_set_reset) CPUSet set = {}; |
cffaed83 YW |
2592 | |
2593 | r = sd_bus_message_read_array(message, 'y', &a, &n); | |
2594 | if (r < 0) | |
2595 | return r; | |
2596 | ||
c367f996 MS |
2597 | r = cpu_set_from_dbus(a, n, &set); |
2598 | if (r < 0) | |
2599 | return r; | |
2600 | ||
2e59b241 | 2601 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
cffaed83 | 2602 | if (n == 0) { |
b070c7c0 | 2603 | cpu_set_reset(affinity ? &c->cpu_set : &c->numa_policy.nodes); |
2e59b241 | 2604 | unit_write_settingf(u, flags, name, "%s=", name); |
cffaed83 YW |
2605 | } else { |
2606 | _cleanup_free_ char *str = NULL; | |
cffaed83 | 2607 | |
0985c7c4 | 2608 | str = cpu_set_to_string(&set); |
a832893f ZJS |
2609 | if (!str) |
2610 | return -ENOMEM; | |
cffaed83 | 2611 | |
0985c7c4 ZJS |
2612 | /* We forego any optimizations here, and always create the structure using |
2613 | * cpu_set_add_all(), because we don't want to care if the existing size we | |
2614 | * got over dbus is appropriate. */ | |
b070c7c0 | 2615 | r = cpu_set_add_all(affinity ? &c->cpu_set : &c->numa_policy.nodes, &set); |
0985c7c4 ZJS |
2616 | if (r < 0) |
2617 | return r; | |
501941aa | 2618 | |
2e59b241 | 2619 | unit_write_settingf(u, flags, name, "%s=%s", name, str); |
cffaed83 YW |
2620 | } |
2621 | } | |
2622 | ||
c7040b5d LP |
2623 | return 1; |
2624 | ||
e2b2fb7f MS |
2625 | } else if (streq(name, "CPUAffinityFromNUMA")) { |
2626 | int q; | |
2627 | ||
2628 | r = sd_bus_message_read_basic(message, 'b', &q); | |
2629 | if (r < 0) | |
2630 | return r; | |
2631 | ||
2632 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
2633 | c->cpu_affinity_from_numa = q; | |
2634 | unit_write_settingf(u, flags, name, "%s=%s", "CPUAffinity", "numa"); | |
2635 | } | |
2636 | ||
2637 | return 1; | |
2638 | ||
b070c7c0 MS |
2639 | } else if (streq(name, "NUMAPolicy")) { |
2640 | int32_t type; | |
2641 | ||
2642 | r = sd_bus_message_read(message, "i", &type); | |
2643 | if (r < 0) | |
2644 | return r; | |
2645 | ||
2646 | if (!mpol_is_valid(type)) | |
2647 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid NUMAPolicy value: %i", type); | |
2648 | ||
2649 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) | |
2650 | c->numa_policy.type = type; | |
2651 | ||
2652 | return 1; | |
e2b2fb7f | 2653 | |
c250bf67 YW |
2654 | } else if (streq(name, "Nice")) { |
2655 | int32_t q; | |
2656 | ||
2657 | r = sd_bus_message_read(message, "i", &q); | |
2658 | if (r < 0) | |
2659 | return r; | |
2660 | ||
2661 | if (!nice_is_valid(q)) | |
2662 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid Nice value: %i", q); | |
2663 | ||
2664 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
2665 | c->nice = q; | |
2666 | c->nice_set = true; | |
2667 | ||
2668 | unit_write_settingf(u, flags, name, "Nice=%i", q); | |
2669 | } | |
2670 | ||
2671 | return 1; | |
2672 | ||
2673 | } else if (streq(name, "CPUSchedulingPolicy")) { | |
2674 | int32_t q; | |
2675 | ||
2676 | r = sd_bus_message_read(message, "i", &q); | |
2677 | if (r < 0) | |
2678 | return r; | |
2679 | ||
2680 | if (!sched_policy_is_valid(q)) | |
2681 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid CPU scheduling policy: %i", q); | |
2682 | ||
2683 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
2684 | _cleanup_free_ char *s = NULL; | |
2685 | ||
2686 | r = sched_policy_to_string_alloc(q, &s); | |
2687 | if (r < 0) | |
2688 | return r; | |
2689 | ||
2690 | c->cpu_sched_policy = q; | |
2691 | c->cpu_sched_priority = CLAMP(c->cpu_sched_priority, sched_get_priority_min(q), sched_get_priority_max(q)); | |
2692 | c->cpu_sched_set = true; | |
2693 | ||
2694 | unit_write_settingf(u, flags, name, "CPUSchedulingPolicy=%s", s); | |
2695 | } | |
2696 | ||
2697 | return 1; | |
2698 | ||
2699 | } else if (streq(name, "CPUSchedulingPriority")) { | |
2700 | int32_t p, min, max; | |
2701 | ||
2702 | r = sd_bus_message_read(message, "i", &p); | |
2703 | if (r < 0) | |
2704 | return r; | |
2705 | ||
2706 | min = sched_get_priority_min(c->cpu_sched_policy); | |
2707 | max = sched_get_priority_max(c->cpu_sched_policy); | |
2708 | if (p < min || p > max) | |
2709 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid CPU scheduling priority: %i", p); | |
2710 | ||
2711 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
2712 | c->cpu_sched_priority = p; | |
2713 | c->cpu_sched_set = true; | |
2714 | ||
2715 | unit_write_settingf(u, flags, name, "CPUSchedulingPriority=%i", p); | |
2716 | } | |
2717 | ||
2718 | return 1; | |
2719 | ||
7f452159 LP |
2720 | } else if (streq(name, "IOSchedulingClass")) { |
2721 | int32_t q; | |
2722 | ||
2723 | r = sd_bus_message_read(message, "i", &q); | |
2724 | if (r < 0) | |
2725 | return r; | |
2726 | ||
2727 | if (!ioprio_class_is_valid(q)) | |
2728 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid IO scheduling class: %i", q); | |
2729 | ||
2e59b241 | 2730 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
7f452159 LP |
2731 | _cleanup_free_ char *s = NULL; |
2732 | ||
2733 | r = ioprio_class_to_string_alloc(q, &s); | |
2734 | if (r < 0) | |
2735 | return r; | |
2736 | ||
5bead76e | 2737 | c->ioprio = ioprio_prio_value(q, ioprio_prio_data(c->ioprio)); |
7f452159 LP |
2738 | c->ioprio_set = true; |
2739 | ||
2e59b241 | 2740 | unit_write_settingf(u, flags, name, "IOSchedulingClass=%s", s); |
7f452159 LP |
2741 | } |
2742 | ||
2743 | return 1; | |
2744 | ||
2745 | } else if (streq(name, "IOSchedulingPriority")) { | |
2746 | int32_t p; | |
2747 | ||
2748 | r = sd_bus_message_read(message, "i", &p); | |
2749 | if (r < 0) | |
2750 | return r; | |
2751 | ||
2752 | if (!ioprio_priority_is_valid(p)) | |
2753 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid IO scheduling priority: %i", p); | |
2754 | ||
2e59b241 | 2755 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
5bead76e | 2756 | c->ioprio = ioprio_prio_value(ioprio_prio_class(c->ioprio), p); |
7f452159 LP |
2757 | c->ioprio_set = true; |
2758 | ||
2e59b241 | 2759 | unit_write_settingf(u, flags, name, "IOSchedulingPriority=%i", p); |
7f452159 LP |
2760 | } |
2761 | ||
2762 | return 1; | |
2763 | ||
5e98086d ZJS |
2764 | } else if (streq(name, "MountAPIVFS")) { |
2765 | bool b; | |
2766 | ||
2767 | r = bus_set_transient_bool(u, name, &b, message, flags, error); | |
2768 | if (r < 0) | |
2769 | return r; | |
2770 | ||
2771 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
2772 | c->mount_apivfs = b; | |
2773 | c->mount_apivfs_set = true; | |
2774 | } | |
2775 | ||
2776 | return 1; | |
2777 | ||
5f5d8eab LP |
2778 | } else if (streq(name, "WorkingDirectory")) { |
2779 | const char *s; | |
2780 | bool missing_ok; | |
2781 | ||
2782 | r = sd_bus_message_read(message, "s", &s); | |
2783 | if (r < 0) | |
2784 | return r; | |
2785 | ||
2786 | if (s[0] == '-') { | |
2787 | missing_ok = true; | |
2788 | s++; | |
2789 | } else | |
2790 | missing_ok = false; | |
2791 | ||
d6ff82d3 | 2792 | if (!isempty(s) && !streq(s, "~") && !path_is_absolute(s)) |
1b09b81c | 2793 | return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "WorkingDirectory= expects an absolute path or '~'"); |
5f5d8eab | 2794 | |
2e59b241 | 2795 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
5f5d8eab LP |
2796 | if (streq(s, "~")) { |
2797 | c->working_directory = mfree(c->working_directory); | |
2798 | c->working_directory_home = true; | |
2799 | } else { | |
d6ff82d3 | 2800 | r = free_and_strdup(&c->working_directory, empty_to_null(s)); |
5f5d8eab LP |
2801 | if (r < 0) |
2802 | return r; | |
2803 | ||
2804 | c->working_directory_home = false; | |
2805 | } | |
2806 | ||
2807 | c->working_directory_missing_ok = missing_ok; | |
2e59b241 | 2808 | unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "WorkingDirectory=%s%s", missing_ok ? "-" : "", s); |
5f5d8eab LP |
2809 | } |
2810 | ||
2811 | return 1; | |
2812 | ||
52c239d7 LB |
2813 | } else if (STR_IN_SET(name, |
2814 | "StandardInputFileDescriptorName", "StandardOutputFileDescriptorName", "StandardErrorFileDescriptorName")) { | |
2815 | const char *s; | |
2816 | ||
2817 | r = sd_bus_message_read(message, "s", &s); | |
2818 | if (r < 0) | |
2819 | return r; | |
2820 | ||
d6ff82d3 | 2821 | if (!isempty(s) && !fdname_is_valid(s)) |
1b09b81c | 2822 | return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid file descriptor name"); |
52c239d7 | 2823 | |
2e59b241 | 2824 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
5073ff6b | 2825 | |
52c239d7 | 2826 | if (streq(name, "StandardInputFileDescriptorName")) { |
d6ff82d3 | 2827 | r = free_and_strdup(c->stdio_fdname + STDIN_FILENO, empty_to_null(s)); |
52c239d7 LB |
2828 | if (r < 0) |
2829 | return r; | |
5073ff6b | 2830 | |
0664775c | 2831 | c->std_input = EXEC_INPUT_NAMED_FD; |
2e59b241 | 2832 | unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardInput=fd:%s", exec_context_fdname(c, STDIN_FILENO)); |
5073ff6b | 2833 | |
52c239d7 | 2834 | } else if (streq(name, "StandardOutputFileDescriptorName")) { |
d6ff82d3 | 2835 | r = free_and_strdup(c->stdio_fdname + STDOUT_FILENO, empty_to_null(s)); |
52c239d7 LB |
2836 | if (r < 0) |
2837 | return r; | |
5073ff6b | 2838 | |
52c239d7 | 2839 | c->std_output = EXEC_OUTPUT_NAMED_FD; |
2e59b241 | 2840 | unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardOutput=fd:%s", exec_context_fdname(c, STDOUT_FILENO)); |
0664775c LP |
2841 | |
2842 | } else { | |
2843 | assert(streq(name, "StandardErrorFileDescriptorName")); | |
5073ff6b | 2844 | |
d6ff82d3 | 2845 | r = free_and_strdup(&c->stdio_fdname[STDERR_FILENO], empty_to_null(s)); |
52c239d7 LB |
2846 | if (r < 0) |
2847 | return r; | |
5073ff6b | 2848 | |
52c239d7 | 2849 | c->std_error = EXEC_OUTPUT_NAMED_FD; |
2e59b241 | 2850 | unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardError=fd:%s", exec_context_fdname(c, STDERR_FILENO)); |
52c239d7 LB |
2851 | } |
2852 | } | |
2853 | ||
2854 | return 1; | |
2855 | ||
566b7d23 ZD |
2856 | } else if (STR_IN_SET(name, |
2857 | "StandardInputFile", | |
8d7dab1f LW |
2858 | "StandardOutputFile", "StandardOutputFileToAppend", "StandardOutputFileToTruncate", |
2859 | "StandardErrorFile", "StandardErrorFileToAppend", "StandardErrorFileToTruncate")) { | |
2038c3f5 LP |
2860 | const char *s; |
2861 | ||
2862 | r = sd_bus_message_read(message, "s", &s); | |
2863 | if (r < 0) | |
2864 | return r; | |
2865 | ||
d6ff82d3 YW |
2866 | if (!isempty(s)) { |
2867 | if (!path_is_absolute(s)) | |
2868 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path %s is not absolute", s); | |
2869 | if (!path_is_normalized(s)) | |
2870 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path %s is not normalized", s); | |
2871 | } | |
2038c3f5 | 2872 | |
2e59b241 | 2873 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
2038c3f5 LP |
2874 | |
2875 | if (streq(name, "StandardInputFile")) { | |
d6ff82d3 | 2876 | r = free_and_strdup(&c->stdio_file[STDIN_FILENO], empty_to_null(s)); |
52c239d7 LB |
2877 | if (r < 0) |
2878 | return r; | |
2038c3f5 LP |
2879 | |
2880 | c->std_input = EXEC_INPUT_FILE; | |
2e59b241 | 2881 | unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardInput=file:%s", s); |
2038c3f5 | 2882 | |
8d7dab1f | 2883 | } else if (STR_IN_SET(name, "StandardOutputFile", "StandardOutputFileToAppend", "StandardOutputFileToTruncate")) { |
d6ff82d3 | 2884 | r = free_and_strdup(&c->stdio_file[STDOUT_FILENO], empty_to_null(s)); |
2038c3f5 LP |
2885 | if (r < 0) |
2886 | return r; | |
2887 | ||
566b7d23 ZD |
2888 | if (streq(name, "StandardOutputFile")) { |
2889 | c->std_output = EXEC_OUTPUT_FILE; | |
2890 | unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardOutput=file:%s", s); | |
8d7dab1f | 2891 | } else if (streq(name, "StandardOutputFileToAppend")) { |
566b7d23 ZD |
2892 | c->std_output = EXEC_OUTPUT_FILE_APPEND; |
2893 | unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardOutput=append:%s", s); | |
8d7dab1f LW |
2894 | } else { |
2895 | assert(streq(name, "StandardOutputFileToTruncate")); | |
2896 | c->std_output = EXEC_OUTPUT_FILE_TRUNCATE; | |
2897 | unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardOutput=truncate:%s", s); | |
566b7d23 | 2898 | } |
2038c3f5 | 2899 | } else { |
8d7dab1f | 2900 | assert(STR_IN_SET(name, "StandardErrorFile", "StandardErrorFileToAppend", "StandardErrorFileToTruncate")); |
2038c3f5 | 2901 | |
d6ff82d3 | 2902 | r = free_and_strdup(&c->stdio_file[STDERR_FILENO], empty_to_null(s)); |
2038c3f5 LP |
2903 | if (r < 0) |
2904 | return r; | |
2905 | ||
566b7d23 ZD |
2906 | if (streq(name, "StandardErrorFile")) { |
2907 | c->std_error = EXEC_OUTPUT_FILE; | |
1704fba9 | 2908 | unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardError=file:%s", s); |
8d7dab1f | 2909 | } else if (streq(name, "StandardErrorFileToAppend")) { |
dbe6c4b6 | 2910 | c->std_error = EXEC_OUTPUT_FILE_APPEND; |
1704fba9 | 2911 | unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardError=append:%s", s); |
8d7dab1f LW |
2912 | } else { |
2913 | assert(streq(name, "StandardErrorFileToTruncate")); | |
2914 | c->std_error = EXEC_OUTPUT_FILE_TRUNCATE; | |
2915 | unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardError=truncate:%s", s); | |
566b7d23 | 2916 | } |
2038c3f5 LP |
2917 | } |
2918 | } | |
2919 | ||
2920 | return 1; | |
2921 | ||
08f3be7a LP |
2922 | } else if (streq(name, "StandardInputData")) { |
2923 | const void *p; | |
2924 | size_t sz; | |
2925 | ||
2926 | r = sd_bus_message_read_array(message, 'y', &p, &sz); | |
2927 | if (r < 0) | |
2928 | return r; | |
2929 | ||
2e59b241 | 2930 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
08f3be7a LP |
2931 | _cleanup_free_ char *encoded = NULL; |
2932 | ||
2933 | if (sz == 0) { | |
2934 | c->stdin_data = mfree(c->stdin_data); | |
2935 | c->stdin_data_size = 0; | |
2936 | ||
2e59b241 | 2937 | unit_write_settingf(u, flags, name, "StandardInputData="); |
08f3be7a LP |
2938 | } else { |
2939 | void *q; | |
2940 | ssize_t n; | |
2941 | ||
2942 | if (c->stdin_data_size + sz < c->stdin_data_size || /* check for overflow */ | |
2943 | c->stdin_data_size + sz > EXEC_STDIN_DATA_MAX) | |
2944 | return -E2BIG; | |
2945 | ||
2946 | n = base64mem(p, sz, &encoded); | |
2947 | if (n < 0) | |
2948 | return (int) n; | |
2949 | ||
2950 | q = realloc(c->stdin_data, c->stdin_data_size + sz); | |
2951 | if (!q) | |
2952 | return -ENOMEM; | |
2953 | ||
2954 | memcpy((uint8_t*) q + c->stdin_data_size, p, sz); | |
2955 | ||
2956 | c->stdin_data = q; | |
2957 | c->stdin_data_size += sz; | |
2958 | ||
2e59b241 | 2959 | unit_write_settingf(u, flags, name, "StandardInputData=%s", encoded); |
52c239d7 LB |
2960 | } |
2961 | } | |
2962 | ||
2963 | return 1; | |
2964 | ||
c7040b5d LP |
2965 | } else if (streq(name, "Environment")) { |
2966 | ||
6171b822 | 2967 | _cleanup_strv_free_ char **l = NULL; |
c7040b5d LP |
2968 | |
2969 | r = sd_bus_message_read_strv(message, &l); | |
2970 | if (r < 0) | |
2971 | return r; | |
2972 | ||
6171b822 | 2973 | if (!strv_env_is_valid(l)) |
1b09b81c | 2974 | return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid environment block."); |
1c68232e | 2975 | |
2e59b241 | 2976 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
7b943bb7 | 2977 | if (strv_isempty(l)) { |
e9876fc9 | 2978 | c->environment = strv_free(c->environment); |
2e59b241 | 2979 | unit_write_setting(u, flags, name, "Environment="); |
e9876fc9 | 2980 | } else { |
f900f582 ZJS |
2981 | _cleanup_free_ char *joined = NULL; |
2982 | char **e; | |
2983 | ||
2e59b241 LP |
2984 | joined = unit_concat_strv(l, UNIT_ESCAPE_SPECIFIERS|UNIT_ESCAPE_C); |
2985 | if (!joined) | |
2986 | return -ENOMEM; | |
2987 | ||
4ab3d29f | 2988 | e = strv_env_merge(c->environment, l); |
e9876fc9 EV |
2989 | if (!e) |
2990 | return -ENOMEM; | |
c7040b5d | 2991 | |
130d3d22 | 2992 | strv_free_and_replace(c->environment, e); |
2e59b241 | 2993 | unit_write_settingf(u, flags, name, "Environment=%s", joined); |
e9876fc9 | 2994 | } |
c7040b5d LP |
2995 | } |
2996 | ||
d584f638 LP |
2997 | return 1; |
2998 | ||
00819cc1 LP |
2999 | } else if (streq(name, "UnsetEnvironment")) { |
3000 | ||
6171b822 | 3001 | _cleanup_strv_free_ char **l = NULL; |
00819cc1 LP |
3002 | |
3003 | r = sd_bus_message_read_strv(message, &l); | |
3004 | if (r < 0) | |
3005 | return r; | |
3006 | ||
6171b822 | 3007 | if (!strv_env_name_or_assignment_is_valid(l)) |
1b09b81c | 3008 | return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid UnsetEnvironment= list."); |
00819cc1 | 3009 | |
2e59b241 | 3010 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
7b943bb7 | 3011 | if (strv_isempty(l)) { |
00819cc1 | 3012 | c->unset_environment = strv_free(c->unset_environment); |
2e59b241 | 3013 | unit_write_setting(u, flags, name, "UnsetEnvironment="); |
00819cc1 LP |
3014 | } else { |
3015 | _cleanup_free_ char *joined = NULL; | |
3016 | char **e; | |
3017 | ||
2e59b241 LP |
3018 | joined = unit_concat_strv(l, UNIT_ESCAPE_SPECIFIERS|UNIT_ESCAPE_C); |
3019 | if (!joined) | |
3020 | return -ENOMEM; | |
3021 | ||
4ab3d29f | 3022 | e = strv_env_merge(c->unset_environment, l); |
00819cc1 LP |
3023 | if (!e) |
3024 | return -ENOMEM; | |
3025 | ||
130d3d22 | 3026 | strv_free_and_replace(c->unset_environment, e); |
2e59b241 | 3027 | unit_write_settingf(u, flags, name, "UnsetEnvironment=%s", joined); |
00819cc1 LP |
3028 | } |
3029 | } | |
3030 | ||
3031 | return 1; | |
3032 | ||
6b862936 EV |
3033 | } else if (streq(name, "OOMScoreAdjust")) { |
3034 | int oa; | |
3035 | ||
3036 | r = sd_bus_message_read(message, "i", &oa); | |
3037 | if (r < 0) | |
3038 | return r; | |
3039 | ||
3040 | if (!oom_score_adjust_is_valid(oa)) | |
1b09b81c | 3041 | return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "OOM score adjust value out of range"); |
6b862936 | 3042 | |
2e59b241 | 3043 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
6b862936 EV |
3044 | c->oom_score_adjust = oa; |
3045 | c->oom_score_adjust_set = true; | |
2e59b241 | 3046 | unit_write_settingf(u, flags, name, "OOMScoreAdjust=%i", oa); |
6b862936 EV |
3047 | } |
3048 | ||
3049 | return 1; | |
3050 | ||
ad21e542 ZJS |
3051 | } else if (streq(name, "CoredumpFilter")) { |
3052 | uint64_t f; | |
3053 | ||
3054 | r = sd_bus_message_read(message, "t", &f); | |
3055 | if (r < 0) | |
3056 | return r; | |
3057 | ||
3058 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
3059 | c->coredump_filter = f; | |
3060 | c->coredump_filter_set = true; | |
3061 | unit_write_settingf(u, flags, name, "CoredumpFilter=0x%"PRIx64, f); | |
3062 | } | |
3063 | ||
3064 | return 1; | |
3065 | ||
ceb728cf NC |
3066 | } else if (streq(name, "EnvironmentFiles")) { |
3067 | ||
3068 | _cleanup_free_ char *joined = NULL; | |
3069 | _cleanup_fclose_ FILE *f = NULL; | |
9b531f04 | 3070 | _cleanup_strv_free_ char **l = NULL; |
ceb728cf | 3071 | size_t size = 0; |
2229f656 | 3072 | char **i; |
ceb728cf NC |
3073 | |
3074 | r = sd_bus_message_enter_container(message, 'a', "(sb)"); | |
3075 | if (r < 0) | |
3076 | return r; | |
3077 | ||
2fe21124 | 3078 | f = open_memstream_unlocked(&joined, &size); |
ceb728cf NC |
3079 | if (!f) |
3080 | return -ENOMEM; | |
3081 | ||
2e59b241 LP |
3082 | fputs("EnvironmentFile=\n", f); |
3083 | ||
3084 | STRV_FOREACH(i, c->environment_files) { | |
3085 | _cleanup_free_ char *q = NULL; | |
3086 | ||
3087 | q = specifier_escape(*i); | |
3088 | if (!q) | |
3089 | return -ENOMEM; | |
3090 | ||
3091 | fprintf(f, "EnvironmentFile=%s\n", q); | |
3092 | } | |
ceb728cf NC |
3093 | |
3094 | while ((r = sd_bus_message_enter_container(message, 'r', "sb")) > 0) { | |
3095 | const char *path; | |
3096 | int b; | |
3097 | ||
ceb728cf NC |
3098 | r = sd_bus_message_read(message, "sb", &path, &b); |
3099 | if (r < 0) | |
3100 | return r; | |
3101 | ||
3102 | r = sd_bus_message_exit_container(message); | |
3103 | if (r < 0) | |
3104 | return r; | |
3105 | ||
d2d6c096 LP |
3106 | if (!path_is_absolute(path)) |
3107 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path %s is not absolute.", path); | |
ceb728cf | 3108 | |
2e59b241 | 3109 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
6abdec98 | 3110 | _cleanup_free_ char *q = NULL, *buf = NULL; |
ceb728cf | 3111 | |
605405c6 | 3112 | buf = strjoin(b ? "-" : "", path); |
2229f656 | 3113 | if (!buf) |
ceb728cf NC |
3114 | return -ENOMEM; |
3115 | ||
2e59b241 | 3116 | q = specifier_escape(buf); |
6abdec98 | 3117 | if (!q) |
2e59b241 | 3118 | return -ENOMEM; |
2e59b241 LP |
3119 | |
3120 | fprintf(f, "EnvironmentFile=%s\n", q); | |
ceb728cf | 3121 | |
6abdec98 | 3122 | r = strv_consume(&l, TAKE_PTR(buf)); |
ceb728cf NC |
3123 | if (r < 0) |
3124 | return r; | |
3125 | } | |
3126 | } | |
3127 | if (r < 0) | |
3128 | return r; | |
3129 | ||
b0830e21 LP |
3130 | r = sd_bus_message_exit_container(message); |
3131 | if (r < 0) | |
3132 | return r; | |
3133 | ||
2229f656 LP |
3134 | r = fflush_and_check(f); |
3135 | if (r < 0) | |
3136 | return r; | |
ceb728cf | 3137 | |
2e59b241 | 3138 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
2229f656 LP |
3139 | if (strv_isempty(l)) { |
3140 | c->environment_files = strv_free(c->environment_files); | |
2e59b241 | 3141 | unit_write_setting(u, flags, name, "EnvironmentFile="); |
2229f656 LP |
3142 | } else { |
3143 | r = strv_extend_strv(&c->environment_files, l, true); | |
3144 | if (r < 0) | |
3145 | return r; | |
3146 | ||
2e59b241 | 3147 | unit_write_setting(u, flags, name, joined); |
2229f656 LP |
3148 | } |
3149 | } | |
ceb728cf | 3150 | |
ceb728cf NC |
3151 | return 1; |
3152 | ||
b4c14404 FB |
3153 | } else if (streq(name, "PassEnvironment")) { |
3154 | ||
6171b822 | 3155 | _cleanup_strv_free_ char **l = NULL; |
b4c14404 FB |
3156 | |
3157 | r = sd_bus_message_read_strv(message, &l); | |
3158 | if (r < 0) | |
3159 | return r; | |
3160 | ||
6171b822 | 3161 | if (!strv_env_name_is_valid(l)) |
1b09b81c | 3162 | return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid PassEnvironment= block."); |
b4c14404 | 3163 | |
2e59b241 | 3164 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
b4c14404 FB |
3165 | if (strv_isempty(l)) { |
3166 | c->pass_environment = strv_free(c->pass_environment); | |
2e59b241 | 3167 | unit_write_setting(u, flags, name, "PassEnvironment="); |
b4c14404 FB |
3168 | } else { |
3169 | _cleanup_free_ char *joined = NULL; | |
3170 | ||
9d4f242a YW |
3171 | r = strv_extend_strv(&c->pass_environment, l, true); |
3172 | if (r < 0) | |
3173 | return r; | |
3174 | ||
41de9cc2 | 3175 | /* We write just the new settings out to file, with unresolved specifiers. */ |
2e59b241 | 3176 | joined = unit_concat_strv(l, UNIT_ESCAPE_SPECIFIERS); |
b4c14404 FB |
3177 | if (!joined) |
3178 | return -ENOMEM; | |
3179 | ||
2e59b241 | 3180 | unit_write_settingf(u, flags, name, "PassEnvironment=%s", joined); |
b4c14404 FB |
3181 | } |
3182 | } | |
3183 | ||
3184 | return 1; | |
3185 | ||
2a624c36 | 3186 | } else if (STR_IN_SET(name, "ReadWriteDirectories", "ReadOnlyDirectories", "InaccessibleDirectories", |
ddc155b2 | 3187 | "ReadWritePaths", "ReadOnlyPaths", "InaccessiblePaths", "ExecPaths", "NoExecPaths")) { |
08596068 EV |
3188 | _cleanup_strv_free_ char **l = NULL; |
3189 | char ***dirs; | |
3190 | char **p; | |
3191 | ||
3192 | r = sd_bus_message_read_strv(message, &l); | |
3193 | if (r < 0) | |
3194 | return r; | |
3195 | ||
3196 | STRV_FOREACH(p, l) { | |
e7bcff4e | 3197 | char *i = *p; |
20b7a007 LP |
3198 | size_t offset; |
3199 | ||
20b7a007 LP |
3200 | offset = i[0] == '-'; |
3201 | offset += i[offset] == '+'; | |
3202 | if (!path_is_absolute(i + offset)) | |
08596068 | 3203 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid %s", name); |
e7bcff4e | 3204 | |
4ff361cc | 3205 | path_simplify(i + offset); |
08596068 EV |
3206 | } |
3207 | ||
2e59b241 | 3208 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
c4b41707 AP |
3209 | if (STR_IN_SET(name, "ReadWriteDirectories", "ReadWritePaths")) |
3210 | dirs = &c->read_write_paths; | |
3211 | else if (STR_IN_SET(name, "ReadOnlyDirectories", "ReadOnlyPaths")) | |
3212 | dirs = &c->read_only_paths; | |
ddc155b2 TM |
3213 | else if (streq(name, "ExecPaths")) |
3214 | dirs = &c->exec_paths; | |
3215 | else if (streq(name, "NoExecPaths")) | |
3216 | dirs = &c->no_exec_paths; | |
c4b41707 AP |
3217 | else /* "InaccessiblePaths" */ |
3218 | dirs = &c->inaccessible_paths; | |
08596068 | 3219 | |
7b943bb7 | 3220 | if (strv_isempty(l)) { |
08596068 | 3221 | *dirs = strv_free(*dirs); |
2e59b241 | 3222 | unit_write_settingf(u, flags, name, "%s=", name); |
08596068 | 3223 | } else { |
2e59b241 | 3224 | _cleanup_free_ char *joined = NULL; |
08596068 | 3225 | |
2e59b241 | 3226 | joined = unit_concat_strv(l, UNIT_ESCAPE_SPECIFIERS); |
08596068 EV |
3227 | if (!joined) |
3228 | return -ENOMEM; | |
3229 | ||
2e59b241 LP |
3230 | r = strv_extend_strv(dirs, l, true); |
3231 | if (r < 0) | |
3232 | return -ENOMEM; | |
08596068 | 3233 | |
2e59b241 LP |
3234 | unit_write_settingf(u, flags, name, "%s=%s", name, joined); |
3235 | } | |
08596068 EV |
3236 | } |
3237 | ||
3238 | return 1; | |
3239 | ||
8c35c10d | 3240 | } else if (streq(name, "ExecSearchPath")) { |
3241 | _cleanup_strv_free_ char **l = NULL; | |
3242 | char **p; | |
3243 | ||
3244 | r = sd_bus_message_read_strv(message, &l); | |
3245 | if (r < 0) | |
3246 | return r; | |
3247 | ||
3248 | STRV_FOREACH(p, l) { | |
3249 | if (!path_is_absolute(*p) || !path_is_normalized(*p) || strchr(*p, ':')) | |
3250 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid %s", name); | |
3251 | } | |
3252 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
3253 | if (strv_isempty(l)) { | |
3254 | c->exec_search_path = strv_free(c->exec_search_path); | |
3255 | unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "ExecSearchPath="); | |
3256 | } else { | |
3257 | _cleanup_free_ char *joined = NULL; | |
3258 | r = strv_extend_strv(&c->exec_search_path, l, true); | |
3259 | if (r < 0) | |
3260 | return -ENOMEM; | |
3261 | joined = strv_join(c->exec_search_path, ":"); | |
3262 | if (!joined) | |
3263 | return log_oom(); | |
3264 | unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "ExecSearchPath=%s", joined); | |
3265 | } | |
3266 | } | |
3267 | ||
3268 | return 1; | |
3269 | ||
3536f49e | 3270 | } else if (STR_IN_SET(name, "RuntimeDirectory", "StateDirectory", "CacheDirectory", "LogsDirectory", "ConfigurationDirectory")) { |
fa21b5e3 EV |
3271 | _cleanup_strv_free_ char **l = NULL; |
3272 | char **p; | |
3273 | ||
3274 | r = sd_bus_message_read_strv(message, &l); | |
3275 | if (r < 0) | |
3276 | return r; | |
3277 | ||
3278 | STRV_FOREACH(p, l) { | |
8994a117 YW |
3279 | if (!path_is_normalized(*p)) |
3280 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "%s= path is not normalized: %s", name, *p); | |
3281 | ||
3282 | if (path_is_absolute(*p)) | |
3283 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "%s= path is absolute: %s", name, *p); | |
3284 | ||
3285 | if (path_startswith(*p, "private")) | |
3286 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "%s= path can't be 'private': %s", name, *p); | |
fa21b5e3 EV |
3287 | } |
3288 | ||
2e59b241 | 3289 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
3536f49e | 3290 | ExecDirectoryType i; |
b1ea85dc | 3291 | ExecDirectory *d; |
3536f49e | 3292 | |
b1ea85dc LP |
3293 | assert_se((i = exec_directory_type_from_string(name)) >= 0); |
3294 | d = c->directories + i; | |
fa21b5e3 EV |
3295 | |
3296 | if (strv_isempty(l)) { | |
b1ea85dc | 3297 | d->paths = strv_free(d->paths); |
2e59b241 | 3298 | unit_write_settingf(u, flags, name, "%s=", name); |
fa21b5e3 | 3299 | } else { |
2e59b241 LP |
3300 | _cleanup_free_ char *joined = NULL; |
3301 | ||
b1ea85dc | 3302 | r = strv_extend_strv(&d->paths, l, true); |
fa21b5e3 | 3303 | if (r < 0) |
c425c7c2 | 3304 | return r; |
fa21b5e3 | 3305 | |
2e59b241 | 3306 | joined = unit_concat_strv(l, UNIT_ESCAPE_SPECIFIERS); |
fa21b5e3 EV |
3307 | if (!joined) |
3308 | return -ENOMEM; | |
3309 | ||
2e59b241 | 3310 | unit_write_settingf(u, flags, name, "%s=%s", name, joined); |
fa21b5e3 EV |
3311 | } |
3312 | } | |
3313 | ||
3314 | return 1; | |
3315 | ||
cffaed83 YW |
3316 | } else if (STR_IN_SET(name, "AppArmorProfile", "SmackProcessLabel")) { |
3317 | int ignore; | |
3318 | const char *s; | |
3319 | ||
280921f2 | 3320 | r = sd_bus_message_read(message, "(bs)", &ignore, &s); |
cffaed83 YW |
3321 | if (r < 0) |
3322 | return r; | |
3323 | ||
2e59b241 | 3324 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
cffaed83 YW |
3325 | char **p; |
3326 | bool *b; | |
3327 | ||
3328 | if (streq(name, "AppArmorProfile")) { | |
3329 | p = &c->apparmor_profile; | |
3330 | b = &c->apparmor_profile_ignore; | |
3331 | } else { /* "SmackProcessLabel" */ | |
3332 | p = &c->smack_process_label; | |
3333 | b = &c->smack_process_label_ignore; | |
3334 | } | |
3335 | ||
3336 | if (isempty(s)) { | |
3337 | *p = mfree(*p); | |
3338 | *b = false; | |
3339 | } else { | |
3340 | if (free_and_strdup(p, s) < 0) | |
3341 | return -ENOMEM; | |
3342 | *b = ignore; | |
3343 | } | |
3344 | ||
2e59b241 | 3345 | unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "%s=%s%s", name, ignore ? "-" : "", strempty(s)); |
cffaed83 YW |
3346 | } |
3347 | ||
3348 | return 1; | |
3349 | ||
d2d6c096 | 3350 | } else if (STR_IN_SET(name, "BindPaths", "BindReadOnlyPaths")) { |
ec04aef4 | 3351 | char *source, *destination; |
4ff4c98a YW |
3352 | int ignore_enoent; |
3353 | uint64_t mount_flags; | |
3354 | bool empty = true; | |
d2d6c096 LP |
3355 | |
3356 | r = sd_bus_message_enter_container(message, 'a', "(ssbt)"); | |
3357 | if (r < 0) | |
3358 | return r; | |
3359 | ||
4ff4c98a | 3360 | while ((r = sd_bus_message_read(message, "(ssbt)", &source, &destination, &ignore_enoent, &mount_flags)) > 0) { |
d2d6c096 LP |
3361 | |
3362 | if (!path_is_absolute(source)) | |
3363 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Source path %s is not absolute.", source); | |
3364 | if (!path_is_absolute(destination)) | |
91d910e3 | 3365 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Destination path %s is not absolute.", destination); |
d2d6c096 | 3366 | if (!IN_SET(mount_flags, 0, MS_REC)) |
1b09b81c | 3367 | return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Unknown mount flags."); |
d2d6c096 | 3368 | |
2e59b241 | 3369 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
d2d6c096 LP |
3370 | r = bind_mount_add(&c->bind_mounts, &c->n_bind_mounts, |
3371 | &(BindMount) { | |
ec04aef4 TM |
3372 | .source = source, |
3373 | .destination = destination, | |
d2d6c096 LP |
3374 | .read_only = !!strstr(name, "ReadOnly"), |
3375 | .recursive = !!(mount_flags & MS_REC), | |
3376 | .ignore_enoent = ignore_enoent, | |
3377 | }); | |
3378 | if (r < 0) | |
3379 | return r; | |
3380 | ||
2e59b241 LP |
3381 | unit_write_settingf( |
3382 | u, flags|UNIT_ESCAPE_SPECIFIERS, name, | |
d2d6c096 LP |
3383 | "%s=%s%s:%s:%s", |
3384 | name, | |
3385 | ignore_enoent ? "-" : "", | |
3386 | source, | |
3387 | destination, | |
3388 | (mount_flags & MS_REC) ? "rbind" : "norbind"); | |
3389 | } | |
3390 | ||
3391 | empty = false; | |
3392 | } | |
3393 | if (r < 0) | |
3394 | return r; | |
3395 | ||
3396 | r = sd_bus_message_exit_container(message); | |
3397 | if (r < 0) | |
3398 | return r; | |
3399 | ||
3400 | if (empty) { | |
3401 | bind_mount_free_many(c->bind_mounts, c->n_bind_mounts); | |
3402 | c->bind_mounts = NULL; | |
3403 | c->n_bind_mounts = 0; | |
2e59b241 LP |
3404 | |
3405 | unit_write_settingf(u, flags, name, "%s=", name); | |
d2d6c096 LP |
3406 | } |
3407 | ||
784ad252 YW |
3408 | return 1; |
3409 | ||
3410 | } else if (streq(name, "TemporaryFileSystem")) { | |
3411 | const char *path, *options; | |
3412 | bool empty = true; | |
3413 | ||
3414 | r = sd_bus_message_enter_container(message, 'a', "(ss)"); | |
3415 | if (r < 0) | |
3416 | return r; | |
3417 | ||
3418 | while ((r = sd_bus_message_read(message, "(ss)", &path, &options)) > 0) { | |
3419 | ||
3420 | if (!path_is_absolute(path)) | |
3421 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Mount point %s is not absolute.", path); | |
3422 | ||
3423 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
3424 | r = temporary_filesystem_add(&c->temporary_filesystems, &c->n_temporary_filesystems, path, options); | |
3425 | if (r < 0) | |
3426 | return r; | |
3427 | ||
3428 | unit_write_settingf( | |
3429 | u, flags|UNIT_ESCAPE_SPECIFIERS, name, | |
3430 | "%s=%s:%s", | |
3431 | name, | |
3432 | path, | |
3433 | options); | |
3434 | } | |
3435 | ||
3436 | empty = false; | |
3437 | } | |
3438 | if (r < 0) | |
3439 | return r; | |
3440 | ||
3441 | r = sd_bus_message_exit_container(message); | |
3442 | if (r < 0) | |
3443 | return r; | |
3444 | ||
3445 | if (empty) { | |
3446 | temporary_filesystem_free_many(c->temporary_filesystems, c->n_temporary_filesystems); | |
3447 | c->temporary_filesystems = NULL; | |
3448 | c->n_temporary_filesystems = 0; | |
3449 | ||
3450 | unit_write_settingf(u, flags, name, "%s=", name); | |
3451 | } | |
3452 | ||
83555251 | 3453 | return 1; |
d2d6c096 | 3454 | |
6550c24c LP |
3455 | } else if ((suffix = startswith(name, "Limit"))) { |
3456 | const char *soft = NULL; | |
3457 | int ri; | |
cab2aca3 | 3458 | |
6550c24c LP |
3459 | ri = rlimit_from_string(suffix); |
3460 | if (ri < 0) { | |
3461 | soft = endswith(suffix, "Soft"); | |
3462 | if (soft) { | |
3463 | const char *n; | |
cab2aca3 | 3464 | |
6550c24c LP |
3465 | n = strndupa(suffix, soft - suffix); |
3466 | ri = rlimit_from_string(n); | |
3467 | if (ri >= 0) | |
3468 | name = strjoina("Limit", n); | |
3469 | } | |
cab2aca3 | 3470 | } |
d584f638 | 3471 | |
6550c24c LP |
3472 | if (ri >= 0) { |
3473 | uint64_t rl; | |
3474 | rlim_t x; | |
d584f638 | 3475 | |
6550c24c | 3476 | r = sd_bus_message_read(message, "t", &rl); |
cab2aca3 LP |
3477 | if (r < 0) |
3478 | return r; | |
d584f638 | 3479 | |
f5fbe71d | 3480 | if (rl == UINT64_MAX) |
6550c24c | 3481 | x = RLIM_INFINITY; |
cab2aca3 | 3482 | else { |
6550c24c LP |
3483 | x = (rlim_t) rl; |
3484 | ||
3485 | if ((uint64_t) x != rl) | |
3486 | return -ERANGE; | |
d584f638 LP |
3487 | } |
3488 | ||
6550c24c LP |
3489 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
3490 | _cleanup_free_ char *f = NULL; | |
3491 | struct rlimit nl; | |
3492 | ||
3493 | if (c->rlimit[ri]) { | |
3494 | nl = *c->rlimit[ri]; | |
3495 | ||
3496 | if (soft) | |
3497 | nl.rlim_cur = x; | |
3498 | else | |
3499 | nl.rlim_max = x; | |
3500 | } else | |
3501 | /* When the resource limit is not initialized yet, then assign the value to both fields */ | |
3502 | nl = (struct rlimit) { | |
3503 | .rlim_cur = x, | |
3504 | .rlim_max = x, | |
3505 | }; | |
3506 | ||
3507 | r = rlimit_format(&nl, &f); | |
3508 | if (r < 0) | |
3509 | return r; | |
3510 | ||
3511 | if (c->rlimit[ri]) | |
3512 | *c->rlimit[ri] = nl; | |
3513 | else { | |
3514 | c->rlimit[ri] = newdup(struct rlimit, &nl, 1); | |
3515 | if (!c->rlimit[ri]) | |
3516 | return -ENOMEM; | |
3517 | } | |
3518 | ||
3519 | unit_write_settingf(u, flags, name, "%s=%s", name, f); | |
3520 | } | |
3521 | ||
3522 | return 1; | |
d584f638 LP |
3523 | } |
3524 | ||
b3d13314 LB |
3525 | } else if (streq(name, "MountImages")) { |
3526 | _cleanup_free_ char *format_str = NULL; | |
3527 | MountImage *mount_images = NULL; | |
3528 | size_t n_mount_images = 0; | |
3529 | char *source, *destination; | |
3530 | int permissive; | |
3531 | ||
427353f6 | 3532 | r = sd_bus_message_enter_container(message, 'a', "(ssba(ss))"); |
b3d13314 LB |
3533 | if (r < 0) |
3534 | return r; | |
3535 | ||
427353f6 LB |
3536 | for (;;) { |
3537 | _cleanup_(mount_options_free_allp) MountOptions *options = NULL; | |
3538 | _cleanup_free_ char *source_escaped = NULL, *destination_escaped = NULL; | |
b3d13314 LB |
3539 | char *tuple; |
3540 | ||
427353f6 LB |
3541 | r = sd_bus_message_enter_container(message, 'r', "ssba(ss)"); |
3542 | if (r < 0) | |
3543 | return r; | |
3544 | ||
3545 | r = sd_bus_message_read(message, "ssb", &source, &destination, &permissive); | |
3546 | if (r <= 0) | |
3547 | break; | |
3548 | ||
b3d13314 LB |
3549 | if (!path_is_absolute(source)) |
3550 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Source path %s is not absolute.", source); | |
3551 | if (!path_is_normalized(source)) | |
3552 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Source path %s is not normalized.", source); | |
3553 | if (!path_is_absolute(destination)) | |
3554 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Destination path %s is not absolute.", destination); | |
3555 | if (!path_is_normalized(destination)) | |
3556 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Destination path %s is not normalized.", destination); | |
3557 | ||
427353f6 LB |
3558 | /* Need to store them in the unit with the escapes, so that they can be parsed again */ |
3559 | source_escaped = shell_escape(source, ":"); | |
3560 | if (!source_escaped) | |
3561 | return -ENOMEM; | |
3562 | destination_escaped = shell_escape(destination, ":"); | |
3563 | if (!destination_escaped) | |
3564 | return -ENOMEM; | |
3565 | ||
3566 | tuple = strjoin(format_str, | |
3567 | format_str ? " " : "", | |
3568 | permissive ? "-" : "", | |
3569 | source_escaped, | |
3570 | ":", | |
3571 | destination_escaped); | |
b3d13314 LB |
3572 | if (!tuple) |
3573 | return -ENOMEM; | |
3574 | free_and_replace(format_str, tuple); | |
3575 | ||
988172ce | 3576 | r = bus_read_mount_options(message, error, &options, &format_str, ":"); |
427353f6 LB |
3577 | if (r < 0) |
3578 | return r; | |
3579 | ||
3580 | r = sd_bus_message_exit_container(message); | |
3581 | if (r < 0) | |
3582 | return r; | |
3583 | ||
b3d13314 LB |
3584 | r = mount_image_add(&mount_images, &n_mount_images, |
3585 | &(MountImage) { | |
3586 | .source = source, | |
3587 | .destination = destination, | |
427353f6 | 3588 | .mount_options = options, |
b3d13314 | 3589 | .ignore_enoent = permissive, |
93f59701 | 3590 | .type = MOUNT_IMAGE_DISCRETE, |
b3d13314 LB |
3591 | }); |
3592 | if (r < 0) | |
3593 | return r; | |
3594 | } | |
3595 | if (r < 0) | |
3596 | return r; | |
3597 | ||
3598 | r = sd_bus_message_exit_container(message); | |
3599 | if (r < 0) | |
3600 | return r; | |
3601 | ||
3602 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
3603 | if (n_mount_images == 0) { | |
3604 | c->mount_images = mount_image_free_many(c->mount_images, &c->n_mount_images); | |
3605 | ||
3606 | unit_write_settingf(u, flags, name, "%s=", name); | |
3607 | } else { | |
3608 | for (size_t i = 0; i < n_mount_images; ++i) { | |
3609 | r = mount_image_add(&c->mount_images, &c->n_mount_images, &mount_images[i]); | |
3610 | if (r < 0) | |
3611 | return r; | |
3612 | } | |
3613 | ||
3614 | unit_write_settingf(u, flags|UNIT_ESCAPE_C|UNIT_ESCAPE_SPECIFIERS, | |
3615 | name, | |
3616 | "%s=%s", | |
3617 | name, | |
3618 | format_str); | |
3619 | } | |
3620 | } | |
3621 | ||
3622 | mount_images = mount_image_free_many(mount_images, &n_mount_images); | |
3623 | ||
93f59701 LB |
3624 | return 1; |
3625 | } else if (streq(name, "ExtensionImages")) { | |
3626 | _cleanup_free_ char *format_str = NULL; | |
3627 | MountImage *extension_images = NULL; | |
3628 | size_t n_extension_images = 0; | |
3629 | ||
3630 | r = sd_bus_message_enter_container(message, 'a', "(sba(ss))"); | |
3631 | if (r < 0) | |
3632 | return r; | |
3633 | ||
3634 | for (;;) { | |
3635 | _cleanup_(mount_options_free_allp) MountOptions *options = NULL; | |
3636 | _cleanup_free_ char *source_escaped = NULL; | |
3637 | char *source, *tuple; | |
3638 | int permissive; | |
3639 | ||
3640 | r = sd_bus_message_enter_container(message, 'r', "sba(ss)"); | |
3641 | if (r < 0) | |
3642 | return r; | |
3643 | ||
3644 | r = sd_bus_message_read(message, "sb", &source, &permissive); | |
3645 | if (r <= 0) | |
3646 | break; | |
3647 | ||
3648 | if (!path_is_absolute(source)) | |
3649 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Source path %s is not absolute.", source); | |
3650 | if (!path_is_normalized(source)) | |
3651 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Source path %s is not normalized.", source); | |
3652 | ||
3653 | /* Need to store them in the unit with the escapes, so that they can be parsed again */ | |
3654 | source_escaped = shell_escape(source, ":"); | |
3655 | if (!source_escaped) | |
3656 | return -ENOMEM; | |
3657 | ||
3658 | tuple = strjoin(format_str, | |
3659 | format_str ? " " : "", | |
3660 | permissive ? "-" : "", | |
3661 | source_escaped); | |
3662 | if (!tuple) | |
3663 | return -ENOMEM; | |
3664 | free_and_replace(format_str, tuple); | |
3665 | ||
3666 | r = bus_read_mount_options(message, error, &options, &format_str, ":"); | |
3667 | if (r < 0) | |
3668 | return r; | |
3669 | ||
3670 | r = sd_bus_message_exit_container(message); | |
3671 | if (r < 0) | |
3672 | return r; | |
3673 | ||
3674 | r = mount_image_add(&extension_images, &n_extension_images, | |
3675 | &(MountImage) { | |
3676 | .source = source, | |
3677 | .mount_options = options, | |
3678 | .ignore_enoent = permissive, | |
3679 | .type = MOUNT_IMAGE_EXTENSION, | |
3680 | }); | |
3681 | if (r < 0) | |
3682 | return r; | |
3683 | } | |
3684 | if (r < 0) | |
3685 | return r; | |
3686 | ||
3687 | r = sd_bus_message_exit_container(message); | |
3688 | if (r < 0) | |
3689 | return r; | |
3690 | ||
3691 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
3692 | if (n_extension_images == 0) { | |
3693 | c->extension_images = mount_image_free_many(c->extension_images, &c->n_extension_images); | |
3694 | ||
3695 | unit_write_settingf(u, flags, name, "%s=", name); | |
3696 | } else { | |
3697 | for (size_t i = 0; i < n_extension_images; ++i) { | |
3698 | r = mount_image_add(&c->extension_images, &c->n_extension_images, &extension_images[i]); | |
3699 | if (r < 0) | |
3700 | return r; | |
3701 | } | |
3702 | ||
3703 | unit_write_settingf(u, flags|UNIT_ESCAPE_C|UNIT_ESCAPE_SPECIFIERS, | |
3704 | name, | |
3705 | "%s=%s", | |
3706 | name, | |
3707 | format_str); | |
3708 | } | |
3709 | } | |
3710 | ||
3711 | extension_images = mount_image_free_many(extension_images, &n_extension_images); | |
3712 | ||
b3d13314 | 3713 | return 1; |
c7040b5d LP |
3714 | } |
3715 | ||
3716 | return 0; | |
3717 | } |