]>
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" |
032b3afb | 27 | #include "ioprio-util.h" |
adce225a | 28 | #include "journal-file.h" |
5bead76e | 29 | #include "missing_ioprio.h" |
049af8ad | 30 | #include "mountpoint-util.h" |
417116f2 | 31 | #include "namespace.h" |
6bedfcbb | 32 | #include "parse-util.h" |
9b15b784 | 33 | #include "path-util.h" |
7b3e062c | 34 | #include "process-util.h" |
78f22b97 | 35 | #include "rlimit-util.h" |
349cc4a5 | 36 | #if HAVE_SECCOMP |
57183d11 LP |
37 | #include "seccomp-util.h" |
38 | #endif | |
cffaed83 | 39 | #include "securebits-util.h" |
2e59b241 | 40 | #include "specifier.h" |
cc86a278 | 41 | #include "stat-util.h" |
6bedfcbb | 42 | #include "strv.h" |
7ccbd1ae | 43 | #include "syslog-util.h" |
f900f582 | 44 | #include "unit-printf.h" |
6f3e7985 | 45 | #include "user-util.h" |
6bedfcbb | 46 | #include "utf8.h" |
57183d11 | 47 | |
718db961 | 48 | BUS_DEFINE_PROPERTY_GET_ENUM(bus_property_get_exec_output, exec_output, ExecOutput); |
718db961 | 49 | static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_input, exec_input, ExecInput); |
023a4f67 | 50 | static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_utmp_mode, exec_utmp_mode, ExecUtmpMode); |
53f47dfc | 51 | static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_preserve_mode, exec_preserve_mode, ExecPreserveMode); |
b1edf445 | 52 | static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_keyring_mode, exec_keyring_mode, ExecKeyringMode); |
4e399953 LP |
53 | static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_protect_proc, protect_proc, ProtectProc); |
54 | static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_proc_subset, proc_subset, ProcSubset); | |
73b84e92 YW |
55 | static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_protect_home, protect_home, ProtectHome); |
56 | static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_protect_system, protect_system, ProtectSystem); | |
491eecb3 | 57 | static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_personality, personality, unsigned long); |
019b34ca | 58 | static BUS_DEFINE_PROPERTY_GET(property_get_ioprio, "i", ExecContext, exec_context_get_effective_ioprio); |
5e98086d | 59 | static BUS_DEFINE_PROPERTY_GET(property_get_mount_apivfs, "b", ExecContext, exec_context_get_effective_mount_apivfs); |
5bead76e ZJS |
60 | static BUS_DEFINE_PROPERTY_GET2(property_get_ioprio_class, "i", ExecContext, exec_context_get_effective_ioprio, ioprio_prio_class); |
61 | static BUS_DEFINE_PROPERTY_GET2(property_get_ioprio_priority, "i", ExecContext, exec_context_get_effective_ioprio, ioprio_prio_data); | |
92c23c5a YW |
62 | static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_empty_string, "s", NULL); |
63 | static BUS_DEFINE_PROPERTY_GET_REF(property_get_syslog_level, "i", int, LOG_PRI); | |
64 | static BUS_DEFINE_PROPERTY_GET_REF(property_get_syslog_facility, "i", int, LOG_FAC); | |
e2b2fb7f MS |
65 | static BUS_DEFINE_PROPERTY_GET(property_get_cpu_affinity_from_numa, "b", ExecContext, exec_context_get_cpu_affinity_from_numa); |
66 | ||
718db961 LP |
67 | static int property_get_environment_files( |
68 | sd_bus *bus, | |
69 | const char *path, | |
70 | const char *interface, | |
71 | const char *property, | |
72 | sd_bus_message *reply, | |
ebcf1f97 LP |
73 | void *userdata, |
74 | sd_bus_error *error) { | |
8c7be95e | 75 | |
718db961 | 76 | ExecContext *c = userdata; |
718db961 | 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; | |
18d73705 LB |
962 | int r; |
963 | ||
964 | assert(bus); | |
965 | assert(c); | |
966 | assert(property); | |
967 | assert(reply); | |
968 | ||
9ece6444 | 969 | r = sd_bus_message_open_container(reply, 'a', "(ss)"); |
18d73705 LB |
970 | if (r < 0) |
971 | return r; | |
972 | ||
973 | LIST_FOREACH(mount_options, m, c->root_image_options) { | |
9ece6444 LB |
974 | r = sd_bus_message_append(reply, "(ss)", |
975 | partition_designator_to_string(m->partition_designator), | |
976 | m->options); | |
18d73705 LB |
977 | if (r < 0) |
978 | return r; | |
979 | } | |
980 | ||
981 | return sd_bus_message_close_container(reply); | |
982 | } | |
983 | ||
b3d13314 LB |
984 | static int property_get_mount_images( |
985 | sd_bus *bus, | |
986 | const char *path, | |
987 | const char *interface, | |
988 | const char *property, | |
989 | sd_bus_message *reply, | |
990 | void *userdata, | |
991 | sd_bus_error *error) { | |
992 | ||
993 | ExecContext *c = userdata; | |
994 | int r; | |
995 | ||
996 | assert(bus); | |
997 | assert(c); | |
998 | assert(property); | |
999 | assert(reply); | |
1000 | ||
427353f6 | 1001 | r = sd_bus_message_open_container(reply, 'a', "(ssba(ss))"); |
b3d13314 LB |
1002 | if (r < 0) |
1003 | return r; | |
1004 | ||
1005 | for (size_t i = 0; i < c->n_mount_images; i++) { | |
427353f6 LB |
1006 | r = sd_bus_message_open_container(reply, SD_BUS_TYPE_STRUCT, "ssba(ss)"); |
1007 | if (r < 0) | |
1008 | return r; | |
b3d13314 | 1009 | r = sd_bus_message_append( |
427353f6 | 1010 | reply, "ssb", |
b3d13314 LB |
1011 | c->mount_images[i].source, |
1012 | c->mount_images[i].destination, | |
1013 | c->mount_images[i].ignore_enoent); | |
1014 | if (r < 0) | |
1015 | return r; | |
427353f6 LB |
1016 | r = sd_bus_message_open_container(reply, 'a', "(ss)"); |
1017 | if (r < 0) | |
1018 | return r; | |
1019 | LIST_FOREACH(mount_options, m, c->mount_images[i].mount_options) { | |
1020 | r = sd_bus_message_append(reply, "(ss)", | |
1021 | partition_designator_to_string(m->partition_designator), | |
1022 | m->options); | |
1023 | if (r < 0) | |
1024 | return r; | |
1025 | } | |
1026 | r = sd_bus_message_close_container(reply); | |
1027 | if (r < 0) | |
1028 | return r; | |
1029 | r = sd_bus_message_close_container(reply); | |
1030 | if (r < 0) | |
1031 | return r; | |
b3d13314 LB |
1032 | } |
1033 | ||
1034 | return sd_bus_message_close_container(reply); | |
1035 | } | |
1036 | ||
93f59701 LB |
1037 | static int property_get_extension_images( |
1038 | sd_bus *bus, | |
1039 | const char *path, | |
1040 | const char *interface, | |
1041 | const char *property, | |
1042 | sd_bus_message *reply, | |
1043 | void *userdata, | |
1044 | sd_bus_error *error) { | |
1045 | ||
1046 | ExecContext *c = userdata; | |
1047 | int r; | |
1048 | ||
1049 | assert(bus); | |
1050 | assert(c); | |
1051 | assert(property); | |
1052 | assert(reply); | |
1053 | ||
1054 | r = sd_bus_message_open_container(reply, 'a', "(sba(ss))"); | |
1055 | if (r < 0) | |
1056 | return r; | |
1057 | ||
1058 | for (size_t i = 0; i < c->n_extension_images; i++) { | |
93f59701 LB |
1059 | r = sd_bus_message_open_container(reply, SD_BUS_TYPE_STRUCT, "sba(ss)"); |
1060 | if (r < 0) | |
1061 | return r; | |
1062 | r = sd_bus_message_append( | |
1063 | reply, "sb", | |
1064 | c->extension_images[i].source, | |
1065 | c->extension_images[i].ignore_enoent); | |
1066 | if (r < 0) | |
1067 | return r; | |
1068 | r = sd_bus_message_open_container(reply, 'a', "(ss)"); | |
1069 | if (r < 0) | |
1070 | return r; | |
1071 | LIST_FOREACH(mount_options, m, c->extension_images[i].mount_options) { | |
1072 | r = sd_bus_message_append(reply, "(ss)", | |
1073 | partition_designator_to_string(m->partition_designator), | |
1074 | m->options); | |
1075 | if (r < 0) | |
1076 | return r; | |
1077 | } | |
1078 | r = sd_bus_message_close_container(reply); | |
1079 | if (r < 0) | |
1080 | return r; | |
1081 | r = sd_bus_message_close_container(reply); | |
1082 | if (r < 0) | |
1083 | return r; | |
1084 | } | |
1085 | ||
1086 | return sd_bus_message_close_container(reply); | |
1087 | } | |
1088 | ||
211a3d87 LB |
1089 | static int bus_property_get_exec_dir( |
1090 | sd_bus *bus, | |
1091 | const char *path, | |
1092 | const char *interface, | |
1093 | const char *property, | |
1094 | sd_bus_message *reply, | |
1095 | void *userdata, | |
1096 | sd_bus_error *error) { | |
1097 | ||
1098 | ExecDirectory *d = userdata; | |
1099 | int r; | |
1100 | ||
1101 | assert(bus); | |
1102 | assert(d); | |
1103 | assert(property); | |
1104 | assert(reply); | |
1105 | ||
1106 | r = sd_bus_message_open_container(reply, 'a', "s"); | |
1107 | if (r < 0) | |
1108 | return r; | |
1109 | ||
1110 | for (size_t i = 0; i < d->n_items; i++) { | |
1111 | r = sd_bus_message_append_basic(reply, 's', d->items[i].path); | |
1112 | if (r < 0) | |
1113 | return r; | |
1114 | } | |
1115 | ||
1116 | return sd_bus_message_close_container(reply); | |
1117 | } | |
1118 | ||
1119 | static int bus_property_get_exec_dir_symlink( | |
1120 | sd_bus *bus, | |
1121 | const char *path, | |
1122 | const char *interface, | |
1123 | const char *property, | |
1124 | sd_bus_message *reply, | |
1125 | void *userdata, | |
1126 | sd_bus_error *error) { | |
1127 | ||
1128 | ExecDirectory *d = userdata; | |
1129 | int r; | |
1130 | ||
1131 | assert(bus); | |
1132 | assert(d); | |
1133 | assert(property); | |
1134 | assert(reply); | |
1135 | ||
1136 | r = sd_bus_message_open_container(reply, 'a', "(sst)"); | |
1137 | if (r < 0) | |
1138 | return r; | |
1139 | ||
de010b0b | 1140 | for (size_t i = 0; i < d->n_items; i++) |
211a3d87 LB |
1141 | STRV_FOREACH(dst, d->items[i].symlinks) { |
1142 | r = sd_bus_message_append(reply, "(sst)", d->items[i].path, *dst, 0 /* flags, unused for now */); | |
1143 | if (r < 0) | |
1144 | return r; | |
1145 | } | |
211a3d87 LB |
1146 | |
1147 | return sd_bus_message_close_container(reply); | |
1148 | } | |
1149 | ||
718db961 LP |
1150 | const sd_bus_vtable bus_exec_vtable[] = { |
1151 | SD_BUS_VTABLE_START(0), | |
556089dc LP |
1152 | SD_BUS_PROPERTY("Environment", "as", NULL, offsetof(ExecContext, environment), SD_BUS_VTABLE_PROPERTY_CONST), |
1153 | SD_BUS_PROPERTY("EnvironmentFiles", "a(sb)", property_get_environment_files, 0, SD_BUS_VTABLE_PROPERTY_CONST), | |
b4c14404 | 1154 | SD_BUS_PROPERTY("PassEnvironment", "as", NULL, offsetof(ExecContext, pass_environment), SD_BUS_VTABLE_PROPERTY_CONST), |
00819cc1 | 1155 | SD_BUS_PROPERTY("UnsetEnvironment", "as", NULL, offsetof(ExecContext, unset_environment), SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc | 1156 | SD_BUS_PROPERTY("UMask", "u", bus_property_get_mode, offsetof(ExecContext, umask), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 1157 | SD_BUS_PROPERTY("LimitCPU", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_CPU]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 1158 | SD_BUS_PROPERTY("LimitCPUSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_CPU]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 1159 | SD_BUS_PROPERTY("LimitFSIZE", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_FSIZE]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 1160 | SD_BUS_PROPERTY("LimitFSIZESoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_FSIZE]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 1161 | SD_BUS_PROPERTY("LimitDATA", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_DATA]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 1162 | SD_BUS_PROPERTY("LimitDATASoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_DATA]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 1163 | SD_BUS_PROPERTY("LimitSTACK", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_STACK]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 1164 | SD_BUS_PROPERTY("LimitSTACKSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_STACK]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 1165 | SD_BUS_PROPERTY("LimitCORE", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_CORE]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 1166 | SD_BUS_PROPERTY("LimitCORESoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_CORE]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 1167 | SD_BUS_PROPERTY("LimitRSS", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RSS]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 1168 | SD_BUS_PROPERTY("LimitRSSSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RSS]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 1169 | SD_BUS_PROPERTY("LimitNOFILE", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NOFILE]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 1170 | SD_BUS_PROPERTY("LimitNOFILESoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NOFILE]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 1171 | SD_BUS_PROPERTY("LimitAS", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_AS]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 1172 | SD_BUS_PROPERTY("LimitASSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_AS]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 1173 | SD_BUS_PROPERTY("LimitNPROC", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NPROC]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 1174 | SD_BUS_PROPERTY("LimitNPROCSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NPROC]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 1175 | SD_BUS_PROPERTY("LimitMEMLOCK", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_MEMLOCK]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 1176 | SD_BUS_PROPERTY("LimitMEMLOCKSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_MEMLOCK]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 1177 | SD_BUS_PROPERTY("LimitLOCKS", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_LOCKS]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 1178 | SD_BUS_PROPERTY("LimitLOCKSSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_LOCKS]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 1179 | SD_BUS_PROPERTY("LimitSIGPENDING", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_SIGPENDING]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 1180 | SD_BUS_PROPERTY("LimitSIGPENDINGSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_SIGPENDING]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 1181 | SD_BUS_PROPERTY("LimitMSGQUEUE", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_MSGQUEUE]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 1182 | SD_BUS_PROPERTY("LimitMSGQUEUESoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_MSGQUEUE]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 1183 | SD_BUS_PROPERTY("LimitNICE", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NICE]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 1184 | SD_BUS_PROPERTY("LimitNICESoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NICE]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 1185 | SD_BUS_PROPERTY("LimitRTPRIO", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RTPRIO]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 1186 | SD_BUS_PROPERTY("LimitRTPRIOSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RTPRIO]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 1187 | SD_BUS_PROPERTY("LimitRTTIME", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RTTIME]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 1188 | SD_BUS_PROPERTY("LimitRTTIMESoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RTTIME]), SD_BUS_VTABLE_PROPERTY_CONST), |
5f5d8eab | 1189 | SD_BUS_PROPERTY("WorkingDirectory", "s", property_get_working_directory, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc | 1190 | SD_BUS_PROPERTY("RootDirectory", "s", NULL, offsetof(ExecContext, root_directory), SD_BUS_VTABLE_PROPERTY_CONST), |
915e6d16 | 1191 | SD_BUS_PROPERTY("RootImage", "s", NULL, offsetof(ExecContext, root_image), SD_BUS_VTABLE_PROPERTY_CONST), |
9ece6444 | 1192 | SD_BUS_PROPERTY("RootImageOptions", "a(ss)", property_get_root_image_options, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
0389f4fa LB |
1193 | SD_BUS_PROPERTY("RootHash", "ay", property_get_root_hash, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
1194 | SD_BUS_PROPERTY("RootHashPath", "s", NULL, offsetof(ExecContext, root_hash_path), SD_BUS_VTABLE_PROPERTY_CONST), | |
d4d55b0d LB |
1195 | SD_BUS_PROPERTY("RootHashSignature", "ay", property_get_root_hash_sig, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
1196 | SD_BUS_PROPERTY("RootHashSignaturePath", "s", NULL, offsetof(ExecContext, root_hash_sig_path), SD_BUS_VTABLE_PROPERTY_CONST), | |
0389f4fa | 1197 | SD_BUS_PROPERTY("RootVerity", "s", NULL, offsetof(ExecContext, root_verity), SD_BUS_VTABLE_PROPERTY_CONST), |
a07b9926 | 1198 | SD_BUS_PROPERTY("ExtensionDirectories", "as", NULL, offsetof(ExecContext, extension_directories), SD_BUS_VTABLE_PROPERTY_CONST), |
93f59701 | 1199 | SD_BUS_PROPERTY("ExtensionImages", "a(sba(ss))", property_get_extension_images, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
427353f6 | 1200 | SD_BUS_PROPERTY("MountImages", "a(ssba(ss))", property_get_mount_images, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc | 1201 | SD_BUS_PROPERTY("OOMScoreAdjust", "i", property_get_oom_score_adjust, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
ad21e542 | 1202 | SD_BUS_PROPERTY("CoredumpFilter", "t", property_get_coredump_filter, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc | 1203 | SD_BUS_PROPERTY("Nice", "i", property_get_nice, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
7f452159 LP |
1204 | SD_BUS_PROPERTY("IOSchedulingClass", "i", property_get_ioprio_class, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
1205 | SD_BUS_PROPERTY("IOSchedulingPriority", "i", property_get_ioprio_priority, 0, SD_BUS_VTABLE_PROPERTY_CONST), | |
556089dc LP |
1206 | SD_BUS_PROPERTY("CPUSchedulingPolicy", "i", property_get_cpu_sched_policy, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
1207 | SD_BUS_PROPERTY("CPUSchedulingPriority", "i", property_get_cpu_sched_priority, 0, SD_BUS_VTABLE_PROPERTY_CONST), | |
1208 | SD_BUS_PROPERTY("CPUAffinity", "ay", property_get_cpu_affinity, 0, SD_BUS_VTABLE_PROPERTY_CONST), | |
e2b2fb7f | 1209 | SD_BUS_PROPERTY("CPUAffinityFromNUMA", "b", property_get_cpu_affinity_from_numa, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
b070c7c0 MS |
1210 | SD_BUS_PROPERTY("NUMAPolicy", "i", property_get_numa_policy, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
1211 | SD_BUS_PROPERTY("NUMAMask", "ay", property_get_numa_mask, 0, SD_BUS_VTABLE_PROPERTY_CONST), | |
556089dc LP |
1212 | SD_BUS_PROPERTY("TimerSlackNSec", "t", property_get_timer_slack_nsec, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
1213 | SD_BUS_PROPERTY("CPUSchedulingResetOnFork", "b", bus_property_get_bool, offsetof(ExecContext, cpu_sched_reset_on_fork), SD_BUS_VTABLE_PROPERTY_CONST), | |
1214 | SD_BUS_PROPERTY("NonBlocking", "b", bus_property_get_bool, offsetof(ExecContext, non_blocking), SD_BUS_VTABLE_PROPERTY_CONST), | |
1215 | SD_BUS_PROPERTY("StandardInput", "s", property_get_exec_input, offsetof(ExecContext, std_input), SD_BUS_VTABLE_PROPERTY_CONST), | |
5073ff6b | 1216 | SD_BUS_PROPERTY("StandardInputFileDescriptorName", "s", property_get_stdio_fdname, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
08f3be7a | 1217 | SD_BUS_PROPERTY("StandardInputData", "ay", property_get_input_data, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc | 1218 | SD_BUS_PROPERTY("StandardOutput", "s", bus_property_get_exec_output, offsetof(ExecContext, std_output), SD_BUS_VTABLE_PROPERTY_CONST), |
5073ff6b | 1219 | SD_BUS_PROPERTY("StandardOutputFileDescriptorName", "s", property_get_stdio_fdname, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc | 1220 | SD_BUS_PROPERTY("StandardError", "s", bus_property_get_exec_output, offsetof(ExecContext, std_error), SD_BUS_VTABLE_PROPERTY_CONST), |
5073ff6b | 1221 | SD_BUS_PROPERTY("StandardErrorFileDescriptorName", "s", property_get_stdio_fdname, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc LP |
1222 | SD_BUS_PROPERTY("TTYPath", "s", NULL, offsetof(ExecContext, tty_path), SD_BUS_VTABLE_PROPERTY_CONST), |
1223 | SD_BUS_PROPERTY("TTYReset", "b", bus_property_get_bool, offsetof(ExecContext, tty_reset), SD_BUS_VTABLE_PROPERTY_CONST), | |
1224 | SD_BUS_PROPERTY("TTYVHangup", "b", bus_property_get_bool, offsetof(ExecContext, tty_vhangup), SD_BUS_VTABLE_PROPERTY_CONST), | |
1225 | SD_BUS_PROPERTY("TTYVTDisallocate", "b", bus_property_get_bool, offsetof(ExecContext, tty_vt_disallocate), SD_BUS_VTABLE_PROPERTY_CONST), | |
51462135 DDM |
1226 | SD_BUS_PROPERTY("TTYRows", "q", bus_property_get_unsigned, offsetof(ExecContext, tty_rows), SD_BUS_VTABLE_PROPERTY_CONST), |
1227 | SD_BUS_PROPERTY("TTYColumns", "q", bus_property_get_unsigned, offsetof(ExecContext, tty_cols), SD_BUS_VTABLE_PROPERTY_CONST), | |
556089dc LP |
1228 | SD_BUS_PROPERTY("SyslogPriority", "i", bus_property_get_int, offsetof(ExecContext, syslog_priority), SD_BUS_VTABLE_PROPERTY_CONST), |
1229 | SD_BUS_PROPERTY("SyslogIdentifier", "s", NULL, offsetof(ExecContext, syslog_identifier), SD_BUS_VTABLE_PROPERTY_CONST), | |
1230 | SD_BUS_PROPERTY("SyslogLevelPrefix", "b", bus_property_get_bool, offsetof(ExecContext, syslog_level_prefix), SD_BUS_VTABLE_PROPERTY_CONST), | |
9d5527f2 YW |
1231 | SD_BUS_PROPERTY("SyslogLevel", "i", property_get_syslog_level, offsetof(ExecContext, syslog_priority), SD_BUS_VTABLE_PROPERTY_CONST), |
1232 | SD_BUS_PROPERTY("SyslogFacility", "i", property_get_syslog_facility, offsetof(ExecContext, syslog_priority), SD_BUS_VTABLE_PROPERTY_CONST), | |
d3070fbd | 1233 | SD_BUS_PROPERTY("LogLevelMax", "i", bus_property_get_int, offsetof(ExecContext, log_level_max), SD_BUS_VTABLE_PROPERTY_CONST), |
5ac1530e ZJS |
1234 | SD_BUS_PROPERTY("LogRateLimitIntervalUSec", "t", bus_property_get_usec, offsetof(ExecContext, log_ratelimit_interval_usec), SD_BUS_VTABLE_PROPERTY_CONST), |
1235 | SD_BUS_PROPERTY("LogRateLimitBurst", "u", bus_property_get_unsigned, offsetof(ExecContext, log_ratelimit_burst), SD_BUS_VTABLE_PROPERTY_CONST), | |
d3070fbd | 1236 | SD_BUS_PROPERTY("LogExtraFields", "aay", property_get_log_extra_fields, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
91dd5f7c | 1237 | SD_BUS_PROPERTY("LogNamespace", "s", NULL, offsetof(ExecContext, log_namespace), SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc | 1238 | SD_BUS_PROPERTY("SecureBits", "i", bus_property_get_int, offsetof(ExecContext, secure_bits), SD_BUS_VTABLE_PROPERTY_CONST), |
c0159e20 YW |
1239 | SD_BUS_PROPERTY("CapabilityBoundingSet", "t", NULL, offsetof(ExecContext, capability_bounding_set), SD_BUS_VTABLE_PROPERTY_CONST), |
1240 | SD_BUS_PROPERTY("AmbientCapabilities", "t", NULL, offsetof(ExecContext, capability_ambient_set), SD_BUS_VTABLE_PROPERTY_CONST), | |
556089dc LP |
1241 | SD_BUS_PROPERTY("User", "s", NULL, offsetof(ExecContext, user), SD_BUS_VTABLE_PROPERTY_CONST), |
1242 | SD_BUS_PROPERTY("Group", "s", NULL, offsetof(ExecContext, group), SD_BUS_VTABLE_PROPERTY_CONST), | |
29206d46 | 1243 | SD_BUS_PROPERTY("DynamicUser", "b", bus_property_get_bool, offsetof(ExecContext, dynamic_user), SD_BUS_VTABLE_PROPERTY_CONST), |
00d9ef85 | 1244 | SD_BUS_PROPERTY("RemoveIPC", "b", bus_property_get_bool, offsetof(ExecContext, remove_ipc), SD_BUS_VTABLE_PROPERTY_CONST), |
bb0c0d6f | 1245 | SD_BUS_PROPERTY("SetCredential", "a(say)", property_get_set_credential, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
43144be4 | 1246 | SD_BUS_PROPERTY("SetCredentialEncrypted", "a(say)", property_get_set_credential, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
bb0c0d6f | 1247 | SD_BUS_PROPERTY("LoadCredential", "a(ss)", property_get_load_credential, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
43144be4 | 1248 | SD_BUS_PROPERTY("LoadCredentialEncrypted", "a(ss)", property_get_load_credential, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc | 1249 | SD_BUS_PROPERTY("SupplementaryGroups", "as", NULL, offsetof(ExecContext, supplementary_groups), SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc | 1250 | SD_BUS_PROPERTY("PAMName", "s", NULL, offsetof(ExecContext, pam_name), SD_BUS_VTABLE_PROPERTY_CONST), |
2a624c36 AP |
1251 | SD_BUS_PROPERTY("ReadWritePaths", "as", NULL, offsetof(ExecContext, read_write_paths), SD_BUS_VTABLE_PROPERTY_CONST), |
1252 | SD_BUS_PROPERTY("ReadOnlyPaths", "as", NULL, offsetof(ExecContext, read_only_paths), SD_BUS_VTABLE_PROPERTY_CONST), | |
1253 | SD_BUS_PROPERTY("InaccessiblePaths", "as", NULL, offsetof(ExecContext, inaccessible_paths), SD_BUS_VTABLE_PROPERTY_CONST), | |
ddc155b2 TM |
1254 | SD_BUS_PROPERTY("ExecPaths", "as", NULL, offsetof(ExecContext, exec_paths), SD_BUS_VTABLE_PROPERTY_CONST), |
1255 | SD_BUS_PROPERTY("NoExecPaths", "as", NULL, offsetof(ExecContext, no_exec_paths), SD_BUS_VTABLE_PROPERTY_CONST), | |
8c35c10d | 1256 | SD_BUS_PROPERTY("ExecSearchPath", "as", NULL, offsetof(ExecContext, exec_search_path), SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc LP |
1257 | SD_BUS_PROPERTY("MountFlags", "t", bus_property_get_ulong, offsetof(ExecContext, mount_flags), SD_BUS_VTABLE_PROPERTY_CONST), |
1258 | SD_BUS_PROPERTY("PrivateTmp", "b", bus_property_get_bool, offsetof(ExecContext, private_tmp), SD_BUS_VTABLE_PROPERTY_CONST), | |
7f112f50 | 1259 | SD_BUS_PROPERTY("PrivateDevices", "b", bus_property_get_bool, offsetof(ExecContext, private_devices), SD_BUS_VTABLE_PROPERTY_CONST), |
b8b7b838 | 1260 | SD_BUS_PROPERTY("ProtectClock", "b", bus_property_get_bool, offsetof(ExecContext, protect_clock), SD_BUS_VTABLE_PROPERTY_CONST), |
59eeb84b | 1261 | SD_BUS_PROPERTY("ProtectKernelTunables", "b", bus_property_get_bool, offsetof(ExecContext, protect_kernel_tunables), SD_BUS_VTABLE_PROPERTY_CONST), |
502d704e | 1262 | SD_BUS_PROPERTY("ProtectKernelModules", "b", bus_property_get_bool, offsetof(ExecContext, protect_kernel_modules), SD_BUS_VTABLE_PROPERTY_CONST), |
84703040 | 1263 | SD_BUS_PROPERTY("ProtectKernelLogs", "b", bus_property_get_bool, offsetof(ExecContext, protect_kernel_logs), SD_BUS_VTABLE_PROPERTY_CONST), |
59eeb84b | 1264 | SD_BUS_PROPERTY("ProtectControlGroups", "b", bus_property_get_bool, offsetof(ExecContext, protect_control_groups), SD_BUS_VTABLE_PROPERTY_CONST), |
d251207d LP |
1265 | SD_BUS_PROPERTY("PrivateNetwork", "b", bus_property_get_bool, offsetof(ExecContext, private_network), SD_BUS_VTABLE_PROPERTY_CONST), |
1266 | SD_BUS_PROPERTY("PrivateUsers", "b", bus_property_get_bool, offsetof(ExecContext, private_users), SD_BUS_VTABLE_PROPERTY_CONST), | |
228af36f | 1267 | SD_BUS_PROPERTY("PrivateMounts", "b", bus_property_get_bool, offsetof(ExecContext, private_mounts), SD_BUS_VTABLE_PROPERTY_CONST), |
a70581ff | 1268 | SD_BUS_PROPERTY("PrivateIPC", "b", bus_property_get_bool, offsetof(ExecContext, private_ipc), SD_BUS_VTABLE_PROPERTY_CONST), |
73b84e92 YW |
1269 | SD_BUS_PROPERTY("ProtectHome", "s", property_get_protect_home, offsetof(ExecContext, protect_home), SD_BUS_VTABLE_PROPERTY_CONST), |
1270 | SD_BUS_PROPERTY("ProtectSystem", "s", property_get_protect_system, offsetof(ExecContext, protect_system), SD_BUS_VTABLE_PROPERTY_CONST), | |
556089dc LP |
1271 | SD_BUS_PROPERTY("SameProcessGroup", "b", bus_property_get_bool, offsetof(ExecContext, same_pgrp), SD_BUS_VTABLE_PROPERTY_CONST), |
1272 | SD_BUS_PROPERTY("UtmpIdentifier", "s", NULL, offsetof(ExecContext, utmp_id), SD_BUS_VTABLE_PROPERTY_CONST), | |
023a4f67 | 1273 | SD_BUS_PROPERTY("UtmpMode", "s", property_get_exec_utmp_mode, offsetof(ExecContext, utmp_mode), SD_BUS_VTABLE_PROPERTY_CONST), |
5f8640fb | 1274 | SD_BUS_PROPERTY("SELinuxContext", "(bs)", property_get_selinux_context, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
eef65bf3 | 1275 | SD_BUS_PROPERTY("AppArmorProfile", "(bs)", property_get_apparmor_profile, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
2ca620c4 | 1276 | SD_BUS_PROPERTY("SmackProcessLabel", "(bs)", property_get_smack_process_label, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc LP |
1277 | SD_BUS_PROPERTY("IgnoreSIGPIPE", "b", bus_property_get_bool, offsetof(ExecContext, ignore_sigpipe), SD_BUS_VTABLE_PROPERTY_CONST), |
1278 | SD_BUS_PROPERTY("NoNewPrivileges", "b", bus_property_get_bool, offsetof(ExecContext, no_new_privileges), SD_BUS_VTABLE_PROPERTY_CONST), | |
57183d11 LP |
1279 | SD_BUS_PROPERTY("SystemCallFilter", "(bas)", property_get_syscall_filter, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
1280 | SD_BUS_PROPERTY("SystemCallArchitectures", "as", property_get_syscall_archs, 0, SD_BUS_VTABLE_PROPERTY_CONST), | |
cf9d43a8 | 1281 | SD_BUS_PROPERTY("SystemCallErrorNumber", "i", bus_property_get_int, offsetof(ExecContext, syscall_errno), SD_BUS_VTABLE_PROPERTY_CONST), |
9df2cdd8 | 1282 | SD_BUS_PROPERTY("SystemCallLog", "(bas)", property_get_syscall_log, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
491eecb3 | 1283 | SD_BUS_PROPERTY("Personality", "s", property_get_personality, offsetof(ExecContext, personality), SD_BUS_VTABLE_PROPERTY_CONST), |
78e864e5 | 1284 | SD_BUS_PROPERTY("LockPersonality", "b", bus_property_get_bool, offsetof(ExecContext, lock_personality), SD_BUS_VTABLE_PROPERTY_CONST), |
4298d0b5 | 1285 | SD_BUS_PROPERTY("RestrictAddressFamilies", "(bas)", property_get_address_families, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
211a3d87 | 1286 | SD_BUS_PROPERTY("RuntimeDirectorySymlink", "a(sst)", bus_property_get_exec_dir_symlink, offsetof(ExecContext, directories[EXEC_DIRECTORY_RUNTIME]), SD_BUS_VTABLE_PROPERTY_CONST), |
53f47dfc | 1287 | SD_BUS_PROPERTY("RuntimeDirectoryPreserve", "s", property_get_exec_preserve_mode, offsetof(ExecContext, runtime_directory_preserve_mode), SD_BUS_VTABLE_PROPERTY_CONST), |
3536f49e | 1288 | SD_BUS_PROPERTY("RuntimeDirectoryMode", "u", bus_property_get_mode, offsetof(ExecContext, directories[EXEC_DIRECTORY_RUNTIME].mode), SD_BUS_VTABLE_PROPERTY_CONST), |
211a3d87 LB |
1289 | SD_BUS_PROPERTY("RuntimeDirectory", "as", bus_property_get_exec_dir, offsetof(ExecContext, directories[EXEC_DIRECTORY_RUNTIME]), SD_BUS_VTABLE_PROPERTY_CONST), |
1290 | SD_BUS_PROPERTY("StateDirectorySymlink", "a(sst)", bus_property_get_exec_dir_symlink, offsetof(ExecContext, directories[EXEC_DIRECTORY_STATE]), SD_BUS_VTABLE_PROPERTY_CONST), | |
e940c1ef | 1291 | SD_BUS_PROPERTY("StateDirectoryMode", "u", bus_property_get_mode, offsetof(ExecContext, directories[EXEC_DIRECTORY_STATE].mode), SD_BUS_VTABLE_PROPERTY_CONST), |
211a3d87 LB |
1292 | SD_BUS_PROPERTY("StateDirectory", "as", bus_property_get_exec_dir, offsetof(ExecContext, directories[EXEC_DIRECTORY_STATE]), SD_BUS_VTABLE_PROPERTY_CONST), |
1293 | SD_BUS_PROPERTY("CacheDirectorySymlink", "a(sst)", bus_property_get_exec_dir_symlink, offsetof(ExecContext, directories[EXEC_DIRECTORY_CACHE]), SD_BUS_VTABLE_PROPERTY_CONST), | |
3536f49e | 1294 | SD_BUS_PROPERTY("CacheDirectoryMode", "u", bus_property_get_mode, offsetof(ExecContext, directories[EXEC_DIRECTORY_CACHE].mode), SD_BUS_VTABLE_PROPERTY_CONST), |
211a3d87 LB |
1295 | SD_BUS_PROPERTY("CacheDirectory", "as", bus_property_get_exec_dir, offsetof(ExecContext, directories[EXEC_DIRECTORY_CACHE]), SD_BUS_VTABLE_PROPERTY_CONST), |
1296 | SD_BUS_PROPERTY("LogsDirectorySymlink", "a(sst)", bus_property_get_exec_dir_symlink, offsetof(ExecContext, directories[EXEC_DIRECTORY_LOGS]), SD_BUS_VTABLE_PROPERTY_CONST), | |
3536f49e | 1297 | SD_BUS_PROPERTY("LogsDirectoryMode", "u", bus_property_get_mode, offsetof(ExecContext, directories[EXEC_DIRECTORY_LOGS].mode), SD_BUS_VTABLE_PROPERTY_CONST), |
211a3d87 | 1298 | SD_BUS_PROPERTY("LogsDirectory", "as", bus_property_get_exec_dir, offsetof(ExecContext, directories[EXEC_DIRECTORY_LOGS]), SD_BUS_VTABLE_PROPERTY_CONST), |
3536f49e | 1299 | SD_BUS_PROPERTY("ConfigurationDirectoryMode", "u", bus_property_get_mode, offsetof(ExecContext, directories[EXEC_DIRECTORY_CONFIGURATION].mode), SD_BUS_VTABLE_PROPERTY_CONST), |
211a3d87 | 1300 | SD_BUS_PROPERTY("ConfigurationDirectory", "as", bus_property_get_exec_dir, offsetof(ExecContext, directories[EXEC_DIRECTORY_CONFIGURATION]), SD_BUS_VTABLE_PROPERTY_CONST), |
12213aed | 1301 | SD_BUS_PROPERTY("TimeoutCleanUSec", "t", bus_property_get_usec, offsetof(ExecContext, timeout_clean_usec), SD_BUS_VTABLE_PROPERTY_CONST), |
f3e43635 | 1302 | SD_BUS_PROPERTY("MemoryDenyWriteExecute", "b", bus_property_get_bool, offsetof(ExecContext, memory_deny_write_execute), SD_BUS_VTABLE_PROPERTY_CONST), |
f4170c67 | 1303 | SD_BUS_PROPERTY("RestrictRealtime", "b", bus_property_get_bool, offsetof(ExecContext, restrict_realtime), SD_BUS_VTABLE_PROPERTY_CONST), |
f69567cb | 1304 | SD_BUS_PROPERTY("RestrictSUIDSGID", "b", bus_property_get_bool, offsetof(ExecContext, restrict_suid_sgid), SD_BUS_VTABLE_PROPERTY_CONST), |
6a8c2d59 | 1305 | SD_BUS_PROPERTY("RestrictNamespaces", "t", bus_property_get_ulong, offsetof(ExecContext, restrict_namespaces), SD_BUS_VTABLE_PROPERTY_CONST), |
cc86a278 | 1306 | SD_BUS_PROPERTY("RestrictFileSystems", "(bas)", property_get_restrict_filesystems, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
d2d6c096 LP |
1307 | SD_BUS_PROPERTY("BindPaths", "a(ssbt)", property_get_bind_paths, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
1308 | SD_BUS_PROPERTY("BindReadOnlyPaths", "a(ssbt)", property_get_bind_paths, 0, SD_BUS_VTABLE_PROPERTY_CONST), | |
784ad252 | 1309 | SD_BUS_PROPERTY("TemporaryFileSystem", "a(ss)", property_get_temporary_filesystems, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
5e98086d | 1310 | SD_BUS_PROPERTY("MountAPIVFS", "b", property_get_mount_apivfs, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
b1edf445 | 1311 | SD_BUS_PROPERTY("KeyringMode", "s", property_get_exec_keyring_mode, offsetof(ExecContext, keyring_mode), SD_BUS_VTABLE_PROPERTY_CONST), |
4e399953 LP |
1312 | SD_BUS_PROPERTY("ProtectProc", "s", property_get_protect_proc, offsetof(ExecContext, protect_proc), SD_BUS_VTABLE_PROPERTY_CONST), |
1313 | SD_BUS_PROPERTY("ProcSubset", "s", property_get_proc_subset, offsetof(ExecContext, proc_subset), SD_BUS_VTABLE_PROPERTY_CONST), | |
aecd5ac6 | 1314 | SD_BUS_PROPERTY("ProtectHostname", "b", bus_property_get_bool, offsetof(ExecContext, protect_hostname), SD_BUS_VTABLE_PROPERTY_CONST), |
a8d08f39 | 1315 | SD_BUS_PROPERTY("NetworkNamespacePath", "s", NULL, offsetof(ExecContext, network_namespace_path), SD_BUS_VTABLE_PROPERTY_CONST), |
a70581ff | 1316 | SD_BUS_PROPERTY("IPCNamespacePath", "s", NULL, offsetof(ExecContext, ipc_namespace_path), SD_BUS_VTABLE_PROPERTY_CONST), |
7f452159 LP |
1317 | |
1318 | /* Obsolete/redundant properties: */ | |
1319 | SD_BUS_PROPERTY("Capabilities", "s", property_get_empty_string, 0, SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN), | |
1320 | SD_BUS_PROPERTY("ReadWriteDirectories", "as", NULL, offsetof(ExecContext, read_write_paths), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN), | |
1321 | SD_BUS_PROPERTY("ReadOnlyDirectories", "as", NULL, offsetof(ExecContext, read_only_paths), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN), | |
1322 | SD_BUS_PROPERTY("InaccessibleDirectories", "as", NULL, offsetof(ExecContext, inaccessible_paths), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN), | |
1323 | SD_BUS_PROPERTY("IOScheduling", "i", property_get_ioprio, 0, SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN), | |
1324 | ||
718db961 LP |
1325 | SD_BUS_VTABLE_END |
1326 | }; | |
82c121a4 | 1327 | |
4d4c80d0 LP |
1328 | static int append_exec_command(sd_bus_message *reply, ExecCommand *c) { |
1329 | int r; | |
1330 | ||
1331 | assert(reply); | |
1332 | assert(c); | |
1333 | ||
1334 | if (!c->path) | |
1335 | return 0; | |
1336 | ||
1337 | r = sd_bus_message_open_container(reply, 'r', "sasbttttuii"); | |
1338 | if (r < 0) | |
1339 | return r; | |
1340 | ||
1341 | r = sd_bus_message_append(reply, "s", c->path); | |
1342 | if (r < 0) | |
1343 | return r; | |
1344 | ||
1345 | r = sd_bus_message_append_strv(reply, c->argv); | |
1346 | if (r < 0) | |
1347 | return r; | |
1348 | ||
1349 | r = sd_bus_message_append(reply, "bttttuii", | |
3ed0cd26 | 1350 | !!(c->flags & EXEC_COMMAND_IGNORE_FAILURE), |
4d4c80d0 LP |
1351 | c->exec_status.start_timestamp.realtime, |
1352 | c->exec_status.start_timestamp.monotonic, | |
1353 | c->exec_status.exit_timestamp.realtime, | |
1354 | c->exec_status.exit_timestamp.monotonic, | |
1355 | (uint32_t) c->exec_status.pid, | |
1356 | (int32_t) c->exec_status.code, | |
1357 | (int32_t) c->exec_status.status); | |
1358 | if (r < 0) | |
1359 | return r; | |
1360 | ||
1361 | return sd_bus_message_close_container(reply); | |
1362 | } | |
1363 | ||
b3d59367 AZ |
1364 | static int append_exec_ex_command(sd_bus_message *reply, ExecCommand *c) { |
1365 | _cleanup_strv_free_ char **ex_opts = NULL; | |
1366 | int r; | |
1367 | ||
1368 | assert(reply); | |
1369 | assert(c); | |
1370 | ||
1371 | if (!c->path) | |
1372 | return 0; | |
1373 | ||
1374 | r = sd_bus_message_open_container(reply, 'r', "sasasttttuii"); | |
1375 | if (r < 0) | |
1376 | return r; | |
1377 | ||
1378 | r = sd_bus_message_append(reply, "s", c->path); | |
1379 | if (r < 0) | |
1380 | return r; | |
1381 | ||
1382 | r = sd_bus_message_append_strv(reply, c->argv); | |
1383 | if (r < 0) | |
1384 | return r; | |
1385 | ||
1386 | r = exec_command_flags_to_strv(c->flags, &ex_opts); | |
1387 | if (r < 0) | |
1388 | return r; | |
1389 | ||
1390 | r = sd_bus_message_append_strv(reply, ex_opts); | |
1391 | if (r < 0) | |
1392 | return r; | |
1393 | ||
1394 | r = sd_bus_message_append(reply, "ttttuii", | |
1395 | c->exec_status.start_timestamp.realtime, | |
1396 | c->exec_status.start_timestamp.monotonic, | |
1397 | c->exec_status.exit_timestamp.realtime, | |
1398 | c->exec_status.exit_timestamp.monotonic, | |
1399 | (uint32_t) c->exec_status.pid, | |
1400 | (int32_t) c->exec_status.code, | |
1401 | (int32_t) c->exec_status.status); | |
1402 | if (r < 0) | |
1403 | return r; | |
1404 | ||
1405 | return sd_bus_message_close_container(reply); | |
1406 | } | |
1407 | ||
718db961 LP |
1408 | int bus_property_get_exec_command( |
1409 | sd_bus *bus, | |
1410 | const char *path, | |
1411 | const char *interface, | |
1412 | const char *property, | |
1413 | sd_bus_message *reply, | |
ebcf1f97 LP |
1414 | void *userdata, |
1415 | sd_bus_error *ret_error) { | |
fe68089d | 1416 | |
4d4c80d0 | 1417 | ExecCommand *c = (ExecCommand*) userdata; |
718db961 | 1418 | int r; |
fe68089d | 1419 | |
718db961 LP |
1420 | assert(bus); |
1421 | assert(reply); | |
fe68089d | 1422 | |
718db961 LP |
1423 | r = sd_bus_message_open_container(reply, 'a', "(sasbttttuii)"); |
1424 | if (r < 0) | |
1425 | return r; | |
fe68089d | 1426 | |
4d4c80d0 LP |
1427 | r = append_exec_command(reply, c); |
1428 | if (r < 0) | |
1429 | return r; | |
fe68089d | 1430 | |
4d4c80d0 LP |
1431 | return sd_bus_message_close_container(reply); |
1432 | } | |
718db961 | 1433 | |
4d4c80d0 LP |
1434 | int bus_property_get_exec_command_list( |
1435 | sd_bus *bus, | |
1436 | const char *path, | |
1437 | const char *interface, | |
1438 | const char *property, | |
1439 | sd_bus_message *reply, | |
1440 | void *userdata, | |
1441 | sd_bus_error *ret_error) { | |
718db961 | 1442 | |
03677889 | 1443 | ExecCommand *exec_command = *(ExecCommand**) userdata; |
4d4c80d0 | 1444 | int r; |
718db961 | 1445 | |
4d4c80d0 LP |
1446 | assert(bus); |
1447 | assert(reply); | |
1448 | ||
1449 | r = sd_bus_message_open_container(reply, 'a', "(sasbttttuii)"); | |
1450 | if (r < 0) | |
1451 | return r; | |
718db961 | 1452 | |
03677889 | 1453 | LIST_FOREACH(command, c, exec_command) { |
4d4c80d0 | 1454 | r = append_exec_command(reply, c); |
718db961 LP |
1455 | if (r < 0) |
1456 | return r; | |
fe68089d LP |
1457 | } |
1458 | ||
718db961 | 1459 | return sd_bus_message_close_container(reply); |
8351ceae | 1460 | } |
c7040b5d | 1461 | |
b3d59367 AZ |
1462 | int bus_property_get_exec_ex_command_list( |
1463 | sd_bus *bus, | |
1464 | const char *path, | |
1465 | const char *interface, | |
1466 | const char *property, | |
1467 | sd_bus_message *reply, | |
1468 | void *userdata, | |
1469 | sd_bus_error *ret_error) { | |
1470 | ||
03677889 | 1471 | ExecCommand *exec_command = *(ExecCommand**) userdata; |
b3d59367 AZ |
1472 | int r; |
1473 | ||
1474 | assert(bus); | |
1475 | assert(reply); | |
1476 | ||
1477 | r = sd_bus_message_open_container(reply, 'a', "(sasasttttuii)"); | |
1478 | if (r < 0) | |
1479 | return r; | |
1480 | ||
1481 | LIST_FOREACH(command, c, exec_command) { | |
1482 | r = append_exec_ex_command(reply, c); | |
1483 | if (r < 0) | |
1484 | return r; | |
1485 | } | |
1486 | ||
1487 | return sd_bus_message_close_container(reply); | |
1488 | } | |
1489 | ||
1490 | static char *exec_command_flags_to_exec_chars(ExecCommandFlags flags) { | |
a4fc96c8 ZJS |
1491 | return strjoin(FLAGS_SET(flags, EXEC_COMMAND_IGNORE_FAILURE) ? "-" : "", |
1492 | FLAGS_SET(flags, EXEC_COMMAND_NO_ENV_EXPAND) ? ":" : "", | |
1493 | FLAGS_SET(flags, EXEC_COMMAND_FULLY_PRIVILEGED) ? "+" : "", | |
1494 | FLAGS_SET(flags, EXEC_COMMAND_NO_SETUID) ? "!" : "", | |
1495 | FLAGS_SET(flags, EXEC_COMMAND_AMBIENT_MAGIC) ? "!!" : ""); | |
b3d59367 AZ |
1496 | } |
1497 | ||
237f7bcb | 1498 | int bus_set_transient_exec_command( |
9c0320e7 YW |
1499 | Unit *u, |
1500 | const char *name, | |
1501 | ExecCommand **exec_command, | |
1502 | sd_bus_message *message, | |
1503 | UnitWriteFlags flags, | |
1504 | sd_bus_error *error) { | |
b3d59367 | 1505 | bool is_ex_prop = endswith(name, "Ex"); |
9c0320e7 YW |
1506 | unsigned n = 0; |
1507 | int r; | |
1508 | ||
b3d59367 | 1509 | r = sd_bus_message_enter_container(message, 'a', is_ex_prop ? "(sasas)" : "(sasb)"); |
9c0320e7 YW |
1510 | if (r < 0) |
1511 | return r; | |
1512 | ||
b3d59367 AZ |
1513 | while ((r = sd_bus_message_enter_container(message, 'r', is_ex_prop ? "sasas" : "sasb")) > 0) { |
1514 | _cleanup_strv_free_ char **argv = NULL, **ex_opts = NULL; | |
9c0320e7 YW |
1515 | const char *path; |
1516 | int b; | |
1517 | ||
1518 | r = sd_bus_message_read(message, "s", &path); | |
1519 | if (r < 0) | |
1520 | return r; | |
1521 | ||
8038b99d ZJS |
1522 | if (!path_is_absolute(path) && !filename_is_valid(path)) |
1523 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, | |
1524 | "\"%s\" is neither a valid executable name nor an absolute path", | |
1525 | path); | |
9c0320e7 YW |
1526 | |
1527 | r = sd_bus_message_read_strv(message, &argv); | |
1528 | if (r < 0) | |
1529 | return r; | |
1530 | ||
29500cf8 HC |
1531 | if (strv_isempty(argv)) |
1532 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, | |
1533 | "\"%s\" argv cannot be empty", name); | |
1534 | ||
b3d59367 | 1535 | r = is_ex_prop ? sd_bus_message_read_strv(message, &ex_opts) : sd_bus_message_read(message, "b", &b); |
9c0320e7 YW |
1536 | if (r < 0) |
1537 | return r; | |
1538 | ||
1539 | r = sd_bus_message_exit_container(message); | |
1540 | if (r < 0) | |
1541 | return r; | |
1542 | ||
1543 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
1544 | ExecCommand *c; | |
1545 | ||
1546 | c = new0(ExecCommand, 1); | |
1547 | if (!c) | |
1548 | return -ENOMEM; | |
1549 | ||
1550 | c->path = strdup(path); | |
1551 | if (!c->path) { | |
1552 | free(c); | |
1553 | return -ENOMEM; | |
1554 | } | |
1555 | ||
ae2a15bc | 1556 | c->argv = TAKE_PTR(argv); |
9c0320e7 | 1557 | |
b3d59367 AZ |
1558 | if (is_ex_prop) { |
1559 | r = exec_command_flags_from_strv(ex_opts, &c->flags); | |
1560 | if (r < 0) | |
1561 | return r; | |
1562 | } else | |
1563 | c->flags = b ? EXEC_COMMAND_IGNORE_FAILURE : 0; | |
9c0320e7 | 1564 | |
4ff361cc | 1565 | path_simplify(c->path); |
9c0320e7 YW |
1566 | exec_command_append_list(exec_command, c); |
1567 | } | |
1568 | ||
1569 | n++; | |
1570 | } | |
1571 | if (r < 0) | |
1572 | return r; | |
1573 | ||
1574 | r = sd_bus_message_exit_container(message); | |
1575 | if (r < 0) | |
1576 | return r; | |
1577 | ||
1578 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
1579 | _cleanup_free_ char *buf = NULL; | |
1580 | _cleanup_fclose_ FILE *f = NULL; | |
9c0320e7 YW |
1581 | size_t size = 0; |
1582 | ||
1583 | if (n == 0) | |
1584 | *exec_command = exec_command_free_list(*exec_command); | |
1585 | ||
2fe21124 | 1586 | f = open_memstream_unlocked(&buf, &size); |
9c0320e7 YW |
1587 | if (!f) |
1588 | return -ENOMEM; | |
1589 | ||
f14bf013 | 1590 | fprintf(f, "%s=\n", name); |
9c0320e7 YW |
1591 | |
1592 | LIST_FOREACH(command, c, *exec_command) { | |
540ac933 | 1593 | _cleanup_free_ char *a = NULL, *exec_chars = NULL; |
9c0320e7 | 1594 | |
540ac933 LP |
1595 | exec_chars = exec_command_flags_to_exec_chars(c->flags); |
1596 | if (!exec_chars) | |
9c0320e7 YW |
1597 | return -ENOMEM; |
1598 | ||
1599 | a = unit_concat_strv(c->argv, UNIT_ESCAPE_C|UNIT_ESCAPE_SPECIFIERS); | |
1600 | if (!a) | |
1601 | return -ENOMEM; | |
1602 | ||
540ac933 LP |
1603 | if (streq_ptr(c->path, c->argv ? c->argv[0] : NULL)) |
1604 | fprintf(f, "%s=%s%s\n", name, exec_chars, a); | |
1605 | else { | |
1606 | _cleanup_free_ char *t = NULL; | |
1607 | const char *p; | |
1608 | ||
1609 | p = unit_escape_setting(c->path, UNIT_ESCAPE_C|UNIT_ESCAPE_SPECIFIERS, &t); | |
1610 | if (!p) | |
1611 | return -ENOMEM; | |
b3d59367 | 1612 | |
540ac933 LP |
1613 | fprintf(f, "%s=%s@%s %s\n", name, exec_chars, p, a); |
1614 | } | |
9c0320e7 YW |
1615 | } |
1616 | ||
1617 | r = fflush_and_check(f); | |
1618 | if (r < 0) | |
1619 | return r; | |
1620 | ||
1621 | unit_write_setting(u, flags, name, buf); | |
1622 | } | |
1623 | ||
1624 | return 1; | |
1625 | } | |
1626 | ||
7e2a3fcc YW |
1627 | static int parse_personality(const char *s, unsigned long *p) { |
1628 | unsigned long v; | |
1629 | ||
1630 | assert(p); | |
1631 | ||
1632 | v = personality_from_string(s); | |
1633 | if (v == PERSONALITY_INVALID) | |
1634 | return -EINVAL; | |
1635 | ||
1636 | *p = v; | |
1637 | return 0; | |
1638 | } | |
1639 | ||
1640 | static const char* mount_propagation_flags_to_string_with_check(unsigned long n) { | |
1641 | if (!IN_SET(n, 0, MS_SHARED, MS_PRIVATE, MS_SLAVE)) | |
1642 | return NULL; | |
1643 | ||
1644 | return mount_propagation_flags_to_string(n); | |
1645 | } | |
1646 | ||
1647 | static BUS_DEFINE_SET_TRANSIENT(nsec, "t", uint64_t, nsec_t, NSEC_FMT); | |
1648 | static BUS_DEFINE_SET_TRANSIENT_IS_VALID(log_level, "i", int32_t, int, "%" PRIi32, log_level_is_valid); | |
aad67b80 | 1649 | #if HAVE_SECCOMP |
005bfaf1 | 1650 | static BUS_DEFINE_SET_TRANSIENT_IS_VALID(errno, "i", int32_t, int, "%" PRIi32, seccomp_errno_or_action_is_valid); |
aad67b80 | 1651 | #endif |
7e2a3fcc YW |
1652 | static BUS_DEFINE_SET_TRANSIENT_PARSE(std_input, ExecInput, exec_input_from_string); |
1653 | static BUS_DEFINE_SET_TRANSIENT_PARSE(std_output, ExecOutput, exec_output_from_string); | |
1654 | static BUS_DEFINE_SET_TRANSIENT_PARSE(utmp_mode, ExecUtmpMode, exec_utmp_mode_from_string); | |
1e8c7bd5 YW |
1655 | static BUS_DEFINE_SET_TRANSIENT_PARSE(protect_system, ProtectSystem, protect_system_from_string); |
1656 | static BUS_DEFINE_SET_TRANSIENT_PARSE(protect_home, ProtectHome, protect_home_from_string); | |
7e2a3fcc | 1657 | static BUS_DEFINE_SET_TRANSIENT_PARSE(keyring_mode, ExecKeyringMode, exec_keyring_mode_from_string); |
4e399953 LP |
1658 | static BUS_DEFINE_SET_TRANSIENT_PARSE(protect_proc, ProtectProc, protect_proc_from_string); |
1659 | static BUS_DEFINE_SET_TRANSIENT_PARSE(proc_subset, ProcSubset, proc_subset_from_string); | |
7e2a3fcc YW |
1660 | static BUS_DEFINE_SET_TRANSIENT_PARSE(preserve_mode, ExecPreserveMode, exec_preserve_mode_from_string); |
1661 | static BUS_DEFINE_SET_TRANSIENT_PARSE_PTR(personality, unsigned long, parse_personality); | |
1662 | static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(secure_bits, "i", int32_t, int, "%" PRIi32, secure_bits_to_string_alloc_with_check); | |
1663 | static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(capability, "t", uint64_t, uint64_t, "%" PRIu64, capability_set_to_string_alloc); | |
86c2a9f1 | 1664 | static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(namespace_flag, "t", uint64_t, unsigned long, "%" PRIu64, namespace_flags_to_string); |
7e2a3fcc YW |
1665 | static BUS_DEFINE_SET_TRANSIENT_TO_STRING(mount_flags, "t", uint64_t, unsigned long, "%" PRIu64, mount_propagation_flags_to_string_with_check); |
1666 | ||
c7040b5d LP |
1667 | int bus_exec_context_set_transient_property( |
1668 | Unit *u, | |
1669 | ExecContext *c, | |
1670 | const char *name, | |
1671 | sd_bus_message *message, | |
2e59b241 | 1672 | UnitWriteFlags flags, |
c7040b5d LP |
1673 | sd_bus_error *error) { |
1674 | ||
6550c24c LP |
1675 | const char *suffix; |
1676 | int r; | |
c7040b5d LP |
1677 | |
1678 | assert(u); | |
1679 | assert(c); | |
1680 | assert(name); | |
1681 | assert(message); | |
1682 | ||
2e59b241 LP |
1683 | flags |= UNIT_PRIVATE; |
1684 | ||
7e2a3fcc | 1685 | if (streq(name, "User")) |
7a8867ab | 1686 | return bus_set_transient_user_relaxed(u, name, &c->user, message, flags, error); |
c7040b5d | 1687 | |
7e2a3fcc | 1688 | if (streq(name, "Group")) |
7a8867ab | 1689 | return bus_set_transient_user_relaxed(u, name, &c->group, message, flags, error); |
c7040b5d | 1690 | |
7e2a3fcc YW |
1691 | if (streq(name, "TTYPath")) |
1692 | return bus_set_transient_path(u, name, &c->tty_path, message, flags, error); | |
6f3e7985 | 1693 | |
7e2a3fcc YW |
1694 | if (streq(name, "RootImage")) |
1695 | return bus_set_transient_path(u, name, &c->root_image, message, flags, error); | |
76736280 | 1696 | |
18d73705 LB |
1697 | if (streq(name, "RootImageOptions")) { |
1698 | _cleanup_(mount_options_free_allp) MountOptions *options = NULL; | |
1699 | _cleanup_free_ char *format_str = NULL; | |
18d73705 | 1700 | |
988172ce | 1701 | r = bus_read_mount_options(message, error, &options, &format_str, " "); |
18d73705 LB |
1702 | if (r < 0) |
1703 | return r; | |
1704 | ||
1705 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
1706 | if (LIST_IS_EMPTY(options)) { | |
1707 | c->root_image_options = mount_options_free_all(c->root_image_options); | |
1708 | unit_write_settingf(u, flags, name, "%s=", name); | |
1709 | } else { | |
1710 | LIST_JOIN(mount_options, c->root_image_options, options); | |
1711 | unit_write_settingf( | |
1712 | u, flags|UNIT_ESCAPE_SPECIFIERS, name, | |
1713 | "%s=%s", | |
1714 | name, | |
1715 | format_str); | |
1716 | } | |
1717 | } | |
1718 | ||
1719 | return 1; | |
1720 | } | |
1721 | ||
0389f4fa LB |
1722 | if (streq(name, "RootHash")) { |
1723 | const void *roothash_decoded; | |
1724 | size_t roothash_decoded_size; | |
1725 | ||
1726 | r = sd_bus_message_read_array(message, 'y', &roothash_decoded, &roothash_decoded_size); | |
1727 | if (r < 0) | |
1728 | return r; | |
1729 | ||
1730 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
1731 | _cleanup_free_ char *encoded = NULL; | |
1732 | ||
1733 | if (roothash_decoded_size == 0) { | |
1734 | c->root_hash_path = mfree(c->root_hash_path); | |
1735 | c->root_hash = mfree(c->root_hash); | |
1736 | c->root_hash_size = 0; | |
1737 | ||
1738 | unit_write_settingf(u, flags, name, "RootHash="); | |
1739 | } else { | |
c2b2df60 | 1740 | _cleanup_free_ void *p = NULL; |
0389f4fa LB |
1741 | |
1742 | encoded = hexmem(roothash_decoded, roothash_decoded_size); | |
1743 | if (!encoded) | |
1744 | return -ENOMEM; | |
1745 | ||
1746 | p = memdup(roothash_decoded, roothash_decoded_size); | |
1747 | if (!p) | |
1748 | return -ENOMEM; | |
1749 | ||
1750 | free_and_replace(c->root_hash, p); | |
1751 | c->root_hash_size = roothash_decoded_size; | |
1752 | c->root_hash_path = mfree(c->root_hash_path); | |
1753 | ||
1754 | unit_write_settingf(u, flags, name, "RootHash=%s", encoded); | |
1755 | } | |
1756 | } | |
1757 | ||
1758 | return 1; | |
1759 | } | |
1760 | ||
1761 | if (streq(name, "RootHashPath")) { | |
1762 | c->root_hash_size = 0; | |
1763 | c->root_hash = mfree(c->root_hash); | |
1764 | ||
1765 | return bus_set_transient_path(u, "RootHash", &c->root_hash_path, message, flags, error); | |
1766 | } | |
1767 | ||
d4d55b0d LB |
1768 | if (streq(name, "RootHashSignature")) { |
1769 | const void *roothash_sig_decoded; | |
1770 | size_t roothash_sig_decoded_size; | |
1771 | ||
1772 | r = sd_bus_message_read_array(message, 'y', &roothash_sig_decoded, &roothash_sig_decoded_size); | |
1773 | if (r < 0) | |
1774 | return r; | |
1775 | ||
1776 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
1777 | _cleanup_free_ char *encoded = NULL; | |
1778 | ||
1779 | if (roothash_sig_decoded_size == 0) { | |
1780 | c->root_hash_sig_path = mfree(c->root_hash_sig_path); | |
1781 | c->root_hash_sig = mfree(c->root_hash_sig); | |
1782 | c->root_hash_sig_size = 0; | |
1783 | ||
1784 | unit_write_settingf(u, flags, name, "RootHashSignature="); | |
1785 | } else { | |
c2b2df60 | 1786 | _cleanup_free_ void *p = NULL; |
d4d55b0d LB |
1787 | ssize_t len; |
1788 | ||
1789 | len = base64mem(roothash_sig_decoded, roothash_sig_decoded_size, &encoded); | |
1790 | if (len < 0) | |
1791 | return -ENOMEM; | |
1792 | ||
1793 | p = memdup(roothash_sig_decoded, roothash_sig_decoded_size); | |
1794 | if (!p) | |
1795 | return -ENOMEM; | |
1796 | ||
1797 | free_and_replace(c->root_hash_sig, p); | |
1798 | c->root_hash_sig_size = roothash_sig_decoded_size; | |
1799 | c->root_hash_sig_path = mfree(c->root_hash_sig_path); | |
1800 | ||
1801 | unit_write_settingf(u, flags, name, "RootHashSignature=base64:%s", encoded); | |
1802 | } | |
1803 | } | |
1804 | ||
1805 | return 1; | |
1806 | } | |
1807 | ||
1808 | if (streq(name, "RootHashSignaturePath")) { | |
1809 | c->root_hash_sig_size = 0; | |
1810 | c->root_hash_sig = mfree(c->root_hash_sig); | |
1811 | ||
1812 | return bus_set_transient_path(u, "RootHashSignature", &c->root_hash_sig_path, message, flags, error); | |
1813 | } | |
1814 | ||
0389f4fa LB |
1815 | if (streq(name, "RootVerity")) |
1816 | return bus_set_transient_path(u, name, &c->root_verity, message, flags, error); | |
1817 | ||
7e2a3fcc YW |
1818 | if (streq(name, "RootDirectory")) |
1819 | return bus_set_transient_path(u, name, &c->root_directory, message, flags, error); | |
c7040b5d | 1820 | |
7e2a3fcc YW |
1821 | if (streq(name, "SyslogIdentifier")) |
1822 | return bus_set_transient_string(u, name, &c->syslog_identifier, message, flags, error); | |
c7040b5d | 1823 | |
7e2a3fcc YW |
1824 | if (streq(name, "LogLevelMax")) |
1825 | return bus_set_transient_log_level(u, name, &c->log_level_max, message, flags, error); | |
1826 | ||
90fc172e | 1827 | if (streq(name, "LogRateLimitIntervalUSec")) |
5ac1530e | 1828 | return bus_set_transient_usec(u, name, &c->log_ratelimit_interval_usec, message, flags, error); |
90fc172e AZ |
1829 | |
1830 | if (streq(name, "LogRateLimitBurst")) | |
5ac1530e | 1831 | return bus_set_transient_unsigned(u, name, &c->log_ratelimit_burst, message, flags, error); |
90fc172e | 1832 | |
7e2a3fcc YW |
1833 | if (streq(name, "Personality")) |
1834 | return bus_set_transient_personality(u, name, &c->personality, message, flags, error); | |
1835 | ||
7e2a3fcc YW |
1836 | if (streq(name, "StandardInput")) |
1837 | return bus_set_transient_std_input(u, name, &c->std_input, message, flags, error); | |
1838 | ||
1839 | if (streq(name, "StandardOutput")) | |
1840 | return bus_set_transient_std_output(u, name, &c->std_output, message, flags, error); | |
1841 | ||
1842 | if (streq(name, "StandardError")) | |
1843 | return bus_set_transient_std_output(u, name, &c->std_error, message, flags, error); | |
1844 | ||
1845 | if (streq(name, "IgnoreSIGPIPE")) | |
1846 | return bus_set_transient_bool(u, name, &c->ignore_sigpipe, message, flags, error); | |
1847 | ||
1848 | if (streq(name, "TTYVHangup")) | |
1849 | return bus_set_transient_bool(u, name, &c->tty_vhangup, message, flags, error); | |
1850 | ||
1851 | if (streq(name, "TTYReset")) | |
1852 | return bus_set_transient_bool(u, name, &c->tty_reset, message, flags, error); | |
1853 | ||
1854 | if (streq(name, "TTYVTDisallocate")) | |
1855 | return bus_set_transient_bool(u, name, &c->tty_vt_disallocate, message, flags, error); | |
51462135 DDM |
1856 | |
1857 | if (streq(name, "TTYRows")) | |
1858 | return bus_set_transient_unsigned(u, name, &c->tty_rows, message, flags, error); | |
1859 | ||
1860 | if (streq(name, "TTYColumns")) | |
1861 | return bus_set_transient_unsigned(u, name, &c->tty_cols, message, flags, error); | |
7e2a3fcc YW |
1862 | |
1863 | if (streq(name, "PrivateTmp")) | |
1864 | return bus_set_transient_bool(u, name, &c->private_tmp, message, flags, error); | |
1865 | ||
1866 | if (streq(name, "PrivateDevices")) | |
1867 | return bus_set_transient_bool(u, name, &c->private_devices, message, flags, error); | |
1868 | ||
228af36f LP |
1869 | if (streq(name, "PrivateMounts")) |
1870 | return bus_set_transient_bool(u, name, &c->private_mounts, message, flags, error); | |
1871 | ||
7e2a3fcc YW |
1872 | if (streq(name, "PrivateNetwork")) |
1873 | return bus_set_transient_bool(u, name, &c->private_network, message, flags, error); | |
1874 | ||
a70581ff XR |
1875 | if (streq(name, "PrivateIPC")) |
1876 | return bus_set_transient_bool(u, name, &c->private_ipc, message, flags, error); | |
1877 | ||
7e2a3fcc YW |
1878 | if (streq(name, "PrivateUsers")) |
1879 | return bus_set_transient_bool(u, name, &c->private_users, message, flags, error); | |
1880 | ||
1881 | if (streq(name, "NoNewPrivileges")) | |
1882 | return bus_set_transient_bool(u, name, &c->no_new_privileges, message, flags, error); | |
1883 | ||
1884 | if (streq(name, "SyslogLevelPrefix")) | |
1885 | return bus_set_transient_bool(u, name, &c->syslog_level_prefix, message, flags, error); | |
1886 | ||
1887 | if (streq(name, "MemoryDenyWriteExecute")) | |
1888 | return bus_set_transient_bool(u, name, &c->memory_deny_write_execute, message, flags, error); | |
1889 | ||
1890 | if (streq(name, "RestrictRealtime")) | |
1891 | return bus_set_transient_bool(u, name, &c->restrict_realtime, message, flags, error); | |
1892 | ||
f69567cb LP |
1893 | if (streq(name, "RestrictSUIDSGID")) |
1894 | return bus_set_transient_bool(u, name, &c->restrict_suid_sgid, message, flags, error); | |
1895 | ||
7e2a3fcc YW |
1896 | if (streq(name, "DynamicUser")) |
1897 | return bus_set_transient_bool(u, name, &c->dynamic_user, message, flags, error); | |
1898 | ||
1899 | if (streq(name, "RemoveIPC")) | |
1900 | return bus_set_transient_bool(u, name, &c->remove_ipc, message, flags, error); | |
1901 | ||
1902 | if (streq(name, "ProtectKernelTunables")) | |
1903 | return bus_set_transient_bool(u, name, &c->protect_kernel_tunables, message, flags, error); | |
1904 | ||
1905 | if (streq(name, "ProtectKernelModules")) | |
1906 | return bus_set_transient_bool(u, name, &c->protect_kernel_modules, message, flags, error); | |
1907 | ||
84703040 KK |
1908 | if (streq(name, "ProtectKernelLogs")) |
1909 | return bus_set_transient_bool(u, name, &c->protect_kernel_logs, message, flags, error); | |
1910 | ||
fc64760d KK |
1911 | if (streq(name, "ProtectClock")) |
1912 | return bus_set_transient_bool(u, name, &c->protect_clock, message, flags, error); | |
1913 | ||
7e2a3fcc YW |
1914 | if (streq(name, "ProtectControlGroups")) |
1915 | return bus_set_transient_bool(u, name, &c->protect_control_groups, message, flags, error); | |
1916 | ||
7e2a3fcc YW |
1917 | if (streq(name, "CPUSchedulingResetOnFork")) |
1918 | return bus_set_transient_bool(u, name, &c->cpu_sched_reset_on_fork, message, flags, error); | |
1919 | ||
1920 | if (streq(name, "NonBlocking")) | |
1921 | return bus_set_transient_bool(u, name, &c->non_blocking, message, flags, error); | |
1922 | ||
1923 | if (streq(name, "LockPersonality")) | |
1924 | return bus_set_transient_bool(u, name, &c->lock_personality, message, flags, error); | |
1925 | ||
aecd5ac6 TM |
1926 | if (streq(name, "ProtectHostname")) |
1927 | return bus_set_transient_bool(u, name, &c->protect_hostname, message, flags, error); | |
1928 | ||
7e2a3fcc YW |
1929 | if (streq(name, "UtmpIdentifier")) |
1930 | return bus_set_transient_string(u, name, &c->utmp_id, message, flags, error); | |
1931 | ||
1932 | if (streq(name, "UtmpMode")) | |
1933 | return bus_set_transient_utmp_mode(u, name, &c->utmp_mode, message, flags, error); | |
1934 | ||
1935 | if (streq(name, "PAMName")) | |
1936 | return bus_set_transient_string(u, name, &c->pam_name, message, flags, error); | |
1937 | ||
1938 | if (streq(name, "TimerSlackNSec")) | |
1939 | return bus_set_transient_nsec(u, name, &c->timer_slack_nsec, message, flags, error); | |
1940 | ||
1941 | if (streq(name, "ProtectSystem")) | |
1942 | return bus_set_transient_protect_system(u, name, &c->protect_system, message, flags, error); | |
1943 | ||
1944 | if (streq(name, "ProtectHome")) | |
1945 | return bus_set_transient_protect_home(u, name, &c->protect_home, message, flags, error); | |
cffaed83 | 1946 | |
7e2a3fcc YW |
1947 | if (streq(name, "KeyringMode")) |
1948 | return bus_set_transient_keyring_mode(u, name, &c->keyring_mode, message, flags, error); | |
1949 | ||
4e399953 LP |
1950 | if (streq(name, "ProtectProc")) |
1951 | return bus_set_transient_protect_proc(u, name, &c->protect_proc, message, flags, error); | |
1952 | ||
1953 | if (streq(name, "ProcSubset")) | |
1954 | return bus_set_transient_proc_subset(u, name, &c->proc_subset, message, flags, error); | |
1955 | ||
7e2a3fcc YW |
1956 | if (streq(name, "RuntimeDirectoryPreserve")) |
1957 | return bus_set_transient_preserve_mode(u, name, &c->runtime_directory_preserve_mode, message, flags, error); | |
1958 | ||
1959 | if (streq(name, "UMask")) | |
1960 | return bus_set_transient_mode_t(u, name, &c->umask, message, flags, error); | |
1961 | ||
1962 | if (streq(name, "RuntimeDirectoryMode")) | |
1963 | return bus_set_transient_mode_t(u, name, &c->directories[EXEC_DIRECTORY_RUNTIME].mode, message, flags, error); | |
1964 | ||
1965 | if (streq(name, "StateDirectoryMode")) | |
1966 | return bus_set_transient_mode_t(u, name, &c->directories[EXEC_DIRECTORY_STATE].mode, message, flags, error); | |
1967 | ||
1968 | if (streq(name, "CacheDirectoryMode")) | |
1969 | return bus_set_transient_mode_t(u, name, &c->directories[EXEC_DIRECTORY_CACHE].mode, message, flags, error); | |
1970 | ||
1971 | if (streq(name, "LogsDirectoryMode")) | |
1972 | return bus_set_transient_mode_t(u, name, &c->directories[EXEC_DIRECTORY_LOGS].mode, message, flags, error); | |
1973 | ||
1974 | if (streq(name, "ConfigurationDirectoryMode")) | |
1975 | return bus_set_transient_mode_t(u, name, &c->directories[EXEC_DIRECTORY_CONFIGURATION].mode, message, flags, error); | |
1976 | ||
1977 | if (streq(name, "SELinuxContext")) | |
1978 | return bus_set_transient_string(u, name, &c->selinux_context, message, flags, error); | |
1979 | ||
1980 | if (streq(name, "SecureBits")) | |
1981 | return bus_set_transient_secure_bits(u, name, &c->secure_bits, message, flags, error); | |
1982 | ||
1983 | if (streq(name, "CapabilityBoundingSet")) | |
1984 | return bus_set_transient_capability(u, name, &c->capability_bounding_set, message, flags, error); | |
1985 | ||
1986 | if (streq(name, "AmbientCapabilities")) | |
1987 | return bus_set_transient_capability(u, name, &c->capability_ambient_set, message, flags, error); | |
1988 | ||
7e2a3fcc YW |
1989 | if (streq(name, "RestrictNamespaces")) |
1990 | return bus_set_transient_namespace_flag(u, name, &c->restrict_namespaces, message, flags, error); | |
1991 | ||
cc86a278 ILG |
1992 | if (streq(name, "RestrictFileSystems")) { |
1993 | int allow_list; | |
1994 | _cleanup_strv_free_ char **l = NULL; | |
1995 | ||
1996 | r = sd_bus_message_enter_container(message, 'r', "bas"); | |
1997 | if (r < 0) | |
1998 | return r; | |
1999 | ||
2000 | r = sd_bus_message_read(message, "b", &allow_list); | |
2001 | if (r < 0) | |
2002 | return r; | |
2003 | ||
2004 | r = sd_bus_message_read_strv(message, &l); | |
2005 | if (r < 0) | |
2006 | return r; | |
2007 | ||
2008 | r = sd_bus_message_exit_container(message); | |
2009 | if (r < 0) | |
2010 | return r; | |
2011 | ||
2012 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
2013 | _cleanup_free_ char *joined = NULL; | |
2014 | FilesystemParseFlags invert_flag = allow_list ? 0 : FILESYSTEM_PARSE_INVERT; | |
cc86a278 ILG |
2015 | |
2016 | if (strv_isempty(l)) { | |
2017 | c->restrict_filesystems_allow_list = false; | |
2018 | c->restrict_filesystems = set_free(c->restrict_filesystems); | |
2019 | ||
2020 | unit_write_setting(u, flags, name, "RestrictFileSystems="); | |
2021 | return 1; | |
2022 | } | |
2023 | ||
2024 | if (!c->restrict_filesystems) | |
2025 | c->restrict_filesystems_allow_list = allow_list; | |
2026 | ||
2027 | STRV_FOREACH(s, l) { | |
2028 | r = lsm_bpf_parse_filesystem( | |
2029 | *s, | |
2030 | &c->restrict_filesystems, | |
2031 | FILESYSTEM_PARSE_LOG| | |
2032 | (invert_flag ? FILESYSTEM_PARSE_INVERT : 0)| | |
2033 | (c->restrict_filesystems_allow_list ? FILESYSTEM_PARSE_ALLOW_LIST : 0), | |
2034 | u->id, NULL, 0); | |
2035 | if (r < 0) | |
2036 | return r; | |
2037 | } | |
2038 | ||
2039 | joined = strv_join(l, " "); | |
2040 | if (!joined) | |
2041 | return -ENOMEM; | |
2042 | ||
2043 | unit_write_settingf(u, flags, name, "%s=%s%s", name, allow_list ? "" : "~", joined); | |
2044 | } | |
2045 | ||
2046 | return 1; | |
2047 | } | |
2048 | ||
7e2a3fcc YW |
2049 | if (streq(name, "MountFlags")) |
2050 | return bus_set_transient_mount_flags(u, name, &c->mount_flags, message, flags, error); | |
2051 | ||
a8d08f39 LP |
2052 | if (streq(name, "NetworkNamespacePath")) |
2053 | return bus_set_transient_path(u, name, &c->network_namespace_path, message, flags, error); | |
2054 | ||
a70581ff XR |
2055 | if (streq(name, "IPCNamespacePath")) |
2056 | return bus_set_transient_path(u, name, &c->ipc_namespace_path, message, flags, error); | |
2057 | ||
7e2a3fcc | 2058 | if (streq(name, "SupplementaryGroups")) { |
cffaed83 | 2059 | _cleanup_strv_free_ char **l = NULL; |
cffaed83 YW |
2060 | |
2061 | r = sd_bus_message_read_strv(message, &l); | |
2062 | if (r < 0) | |
2063 | return r; | |
2064 | ||
d2a23692 | 2065 | STRV_FOREACH(p, l) |
7a8867ab | 2066 | if (!isempty(*p) && !valid_user_group_name(*p, VALID_USER_ALLOW_NUMERIC|VALID_USER_RELAX|VALID_USER_WARN)) |
d2a23692 ZJS |
2067 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, |
2068 | "Invalid supplementary group names"); | |
cffaed83 | 2069 | |
2e59b241 | 2070 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
7b943bb7 | 2071 | if (strv_isempty(l)) { |
cffaed83 | 2072 | c->supplementary_groups = strv_free(c->supplementary_groups); |
2e59b241 | 2073 | unit_write_settingf(u, flags, name, "%s=", name); |
cffaed83 YW |
2074 | } else { |
2075 | _cleanup_free_ char *joined = NULL; | |
2076 | ||
2077 | r = strv_extend_strv(&c->supplementary_groups, l, true); | |
2078 | if (r < 0) | |
2079 | return -ENOMEM; | |
2080 | ||
2081 | joined = strv_join(c->supplementary_groups, " "); | |
2082 | if (!joined) | |
2083 | return -ENOMEM; | |
2084 | ||
2e59b241 | 2085 | unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "%s=%s", name, joined); |
cffaed83 YW |
2086 | } |
2087 | } | |
2088 | ||
2089 | return 1; | |
2090 | ||
43144be4 | 2091 | } else if (STR_IN_SET(name, "SetCredential", "SetCredentialEncrypted")) { |
bb0c0d6f LP |
2092 | bool isempty = true; |
2093 | ||
2094 | r = sd_bus_message_enter_container(message, 'a', "(say)"); | |
2095 | if (r < 0) | |
2096 | return r; | |
2097 | ||
2098 | for (;;) { | |
2099 | const char *id; | |
2100 | const void *p; | |
2101 | size_t sz; | |
2102 | ||
2103 | r = sd_bus_message_enter_container(message, 'r', "say"); | |
2104 | if (r < 0) | |
2105 | return r; | |
2106 | if (r == 0) | |
2107 | break; | |
2108 | ||
2109 | r = sd_bus_message_read(message, "s", &id); | |
2110 | if (r < 0) | |
2111 | return r; | |
2112 | ||
2113 | r = sd_bus_message_read_array(message, 'y', &p, &sz); | |
2114 | if (r < 0) | |
2115 | return r; | |
2116 | ||
2117 | r = sd_bus_message_exit_container(message); | |
2118 | if (r < 0) | |
2119 | return r; | |
2120 | ||
2121 | if (!credential_name_valid(id)) | |
2122 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Credential ID is invalid: %s", id); | |
2123 | ||
2124 | isempty = false; | |
2125 | ||
2126 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
2127 | _cleanup_free_ char *a = NULL, *b = NULL; | |
2128 | _cleanup_free_ void *copy = NULL; | |
2129 | ExecSetCredential *old; | |
2130 | ||
2131 | copy = memdup(p, sz); | |
2132 | if (!copy) | |
2133 | return -ENOMEM; | |
2134 | ||
2135 | old = hashmap_get(c->set_credentials, id); | |
2136 | if (old) { | |
2137 | free_and_replace(old->data, copy); | |
2138 | old->size = sz; | |
43144be4 | 2139 | old->encrypted = streq(name, "SetCredentialEncrypted"); |
bb0c0d6f LP |
2140 | } else { |
2141 | _cleanup_(exec_set_credential_freep) ExecSetCredential *sc = NULL; | |
2142 | ||
43144be4 | 2143 | sc = new(ExecSetCredential, 1); |
bb0c0d6f LP |
2144 | if (!sc) |
2145 | return -ENOMEM; | |
2146 | ||
43144be4 LP |
2147 | *sc = (ExecSetCredential) { |
2148 | .id = strdup(id), | |
2149 | .data = TAKE_PTR(copy), | |
2150 | .size = sz, | |
2151 | .encrypted = streq(name, "SetCredentialEncrypted"), | |
2152 | }; | |
2153 | ||
bb0c0d6f LP |
2154 | if (!sc->id) |
2155 | return -ENOMEM; | |
2156 | ||
cf55fe4a | 2157 | r = hashmap_ensure_put(&c->set_credentials, &exec_set_credential_hash_ops, sc->id, sc); |
bb0c0d6f LP |
2158 | if (r < 0) |
2159 | return r; | |
2160 | ||
2161 | TAKE_PTR(sc); | |
2162 | } | |
2163 | ||
2164 | a = specifier_escape(id); | |
2165 | if (!a) | |
2166 | return -ENOMEM; | |
2167 | ||
2168 | b = cescape_length(p, sz); | |
2169 | if (!b) | |
2170 | return -ENOMEM; | |
2171 | ||
2172 | (void) unit_write_settingf(u, flags, name, "%s=%s:%s", name, a, b); | |
2173 | } | |
2174 | } | |
2175 | ||
2176 | r = sd_bus_message_exit_container(message); | |
2177 | if (r < 0) | |
2178 | return r; | |
2179 | ||
2180 | if (!UNIT_WRITE_FLAGS_NOOP(flags) && isempty) { | |
2181 | c->set_credentials = hashmap_free(c->set_credentials); | |
2182 | (void) unit_write_settingf(u, flags, name, "%s=", name); | |
2183 | } | |
2184 | ||
2185 | return 1; | |
2186 | ||
43144be4 | 2187 | } else if (STR_IN_SET(name, "LoadCredential", "LoadCredentialEncrypted")) { |
bb0c0d6f LP |
2188 | bool isempty = true; |
2189 | ||
2190 | r = sd_bus_message_enter_container(message, 'a', "(ss)"); | |
2191 | if (r < 0) | |
2192 | return r; | |
2193 | ||
2194 | for (;;) { | |
2195 | const char *id, *source; | |
2196 | ||
2197 | r = sd_bus_message_read(message, "(ss)", &id, &source); | |
2198 | if (r < 0) | |
2199 | return r; | |
2200 | if (r == 0) | |
2201 | break; | |
2202 | ||
2203 | if (!credential_name_valid(id)) | |
2204 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Credential ID is invalid: %s", id); | |
2205 | ||
2206 | if (!(path_is_absolute(source) ? path_is_normalized(source) : credential_name_valid(source))) | |
2207 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Credential source is invalid: %s", source); | |
2208 | ||
2209 | isempty = false; | |
2210 | ||
2211 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
43144be4 LP |
2212 | _cleanup_free_ char *copy = NULL; |
2213 | ExecLoadCredential *old; | |
2214 | ||
2215 | copy = strdup(source); | |
2216 | if (!copy) | |
2217 | return -ENOMEM; | |
2218 | ||
2219 | old = hashmap_get(c->load_credentials, id); | |
2220 | if (old) { | |
2221 | free_and_replace(old->path, copy); | |
2222 | old->encrypted = streq(name, "LoadCredentialEncrypted"); | |
2223 | } else { | |
2224 | _cleanup_(exec_load_credential_freep) ExecLoadCredential *lc = NULL; | |
2225 | ||
2226 | lc = new(ExecLoadCredential, 1); | |
2227 | if (!lc) | |
2228 | return -ENOMEM; | |
2229 | ||
2230 | *lc = (ExecLoadCredential) { | |
2231 | .id = strdup(id), | |
2232 | .path = TAKE_PTR(copy), | |
2233 | .encrypted = streq(name, "LoadCredentialEncrypted"), | |
2234 | }; | |
2235 | ||
2236 | if (!lc->id) | |
2237 | return -ENOMEM; | |
2238 | ||
2239 | r = hashmap_ensure_put(&c->load_credentials, &exec_load_credential_hash_ops, lc->id, lc); | |
2240 | if (r < 0) | |
2241 | return r; | |
2242 | ||
2243 | TAKE_PTR(lc); | |
2244 | } | |
bb0c0d6f LP |
2245 | |
2246 | (void) unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "%s=%s:%s", name, id, source); | |
2247 | } | |
2248 | } | |
2249 | ||
2250 | r = sd_bus_message_exit_container(message); | |
2251 | if (r < 0) | |
2252 | return r; | |
2253 | ||
2254 | if (!UNIT_WRITE_FLAGS_NOOP(flags) && isempty) { | |
43144be4 | 2255 | c->load_credentials = hashmap_free(c->load_credentials); |
bb0c0d6f LP |
2256 | (void) unit_write_settingf(u, flags, name, "%s=", name); |
2257 | } | |
2258 | ||
2259 | return 1; | |
2260 | ||
a8a13575 | 2261 | } else if (streq(name, "SyslogLevel")) { |
8d1dd6ab | 2262 | int32_t level; |
a8a13575 EV |
2263 | |
2264 | r = sd_bus_message_read(message, "i", &level); | |
2265 | if (r < 0) | |
2266 | return r; | |
2267 | ||
e0d6e0fa | 2268 | if (!log_level_is_valid(level)) |
1b09b81c | 2269 | return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Log level value out of range"); |
e0d6e0fa | 2270 | |
2e59b241 | 2271 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
a8a13575 | 2272 | c->syslog_priority = (c->syslog_priority & LOG_FACMASK) | level; |
2e59b241 | 2273 | unit_write_settingf(u, flags, name, "SyslogLevel=%i", level); |
a8a13575 EV |
2274 | } |
2275 | ||
460ed929 | 2276 | return 1; |
7e2a3fcc | 2277 | |
460ed929 | 2278 | } else if (streq(name, "SyslogFacility")) { |
8d1dd6ab | 2279 | int32_t facility; |
460ed929 EV |
2280 | |
2281 | r = sd_bus_message_read(message, "i", &facility); | |
2282 | if (r < 0) | |
2283 | return r; | |
2284 | ||
e0d6e0fa | 2285 | if (!log_facility_unshifted_is_valid(facility)) |
1b09b81c | 2286 | return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Log facility value out of range"); |
e0d6e0fa | 2287 | |
2e59b241 | 2288 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
460ed929 | 2289 | c->syslog_priority = (facility << 3) | LOG_PRI(c->syslog_priority); |
2e59b241 | 2290 | unit_write_settingf(u, flags, name, "SyslogFacility=%i", facility); |
460ed929 EV |
2291 | } |
2292 | ||
cffaed83 | 2293 | return 1; |
d3070fbd | 2294 | |
91dd5f7c LP |
2295 | } else if (streq(name, "LogNamespace")) { |
2296 | const char *n; | |
2297 | ||
2298 | r = sd_bus_message_read(message, "s", &n); | |
2299 | if (r < 0) | |
2300 | return r; | |
2301 | ||
2302 | if (!isempty(n) && !log_namespace_name_valid(n)) | |
1b09b81c | 2303 | return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Log namespace name not valid"); |
91dd5f7c LP |
2304 | |
2305 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
2306 | ||
2307 | if (isempty(n)) { | |
2308 | c->log_namespace = mfree(c->log_namespace); | |
2309 | unit_write_settingf(u, flags, name, "%s=", name); | |
2310 | } else { | |
2311 | r = free_and_strdup(&c->log_namespace, n); | |
2312 | if (r < 0) | |
2313 | return r; | |
2314 | ||
2315 | unit_write_settingf(u, flags, name, "%s=%s", name, n); | |
2316 | } | |
2317 | } | |
2318 | ||
2319 | return 1; | |
2320 | ||
d3070fbd LP |
2321 | } else if (streq(name, "LogExtraFields")) { |
2322 | size_t n = 0; | |
2323 | ||
2324 | r = sd_bus_message_enter_container(message, 'a', "ay"); | |
2325 | if (r < 0) | |
2326 | return r; | |
2327 | ||
2328 | for (;;) { | |
2329 | _cleanup_free_ void *copy = NULL; | |
2330 | struct iovec *t; | |
2331 | const char *eq; | |
2332 | const void *p; | |
2333 | size_t sz; | |
2334 | ||
2335 | /* Note that we expect a byte array for each field, instead of a string. That's because on the | |
2336 | * lower-level journal fields can actually contain binary data and are not restricted to text, | |
2337 | * and we should not "lose precision" in our types on the way. That said, I am pretty sure | |
2338 | * actually encoding binary data as unit metadata is not a good idea. Hence we actually refuse | |
2339 | * any actual binary data, and only accept UTF-8. This allows us to eventually lift this | |
2340 | * limitation, should a good, valid usecase arise. */ | |
2341 | ||
2342 | r = sd_bus_message_read_array(message, 'y', &p, &sz); | |
2343 | if (r < 0) | |
2344 | return r; | |
2345 | if (r == 0) | |
2346 | break; | |
2347 | ||
2348 | if (memchr(p, 0, sz)) | |
1b09b81c | 2349 | return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Journal field contains zero byte"); |
d3070fbd LP |
2350 | |
2351 | eq = memchr(p, '=', sz); | |
2352 | if (!eq) | |
1b09b81c | 2353 | return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Journal field contains no '=' character"); |
d3070fbd | 2354 | if (!journal_field_valid(p, eq - (const char*) p, false)) |
1b09b81c | 2355 | return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Journal field invalid"); |
d3070fbd | 2356 | |
2e59b241 | 2357 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
aa484f35 | 2358 | t = reallocarray(c->log_extra_fields, c->n_log_extra_fields+1, sizeof(struct iovec)); |
d3070fbd LP |
2359 | if (!t) |
2360 | return -ENOMEM; | |
2361 | c->log_extra_fields = t; | |
2362 | } | |
2363 | ||
2364 | copy = malloc(sz + 1); | |
2365 | if (!copy) | |
2366 | return -ENOMEM; | |
2367 | ||
2368 | memcpy(copy, p, sz); | |
2369 | ((uint8_t*) copy)[sz] = 0; | |
2370 | ||
2371 | if (!utf8_is_valid(copy)) | |
1b09b81c | 2372 | return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Journal field is not valid UTF-8"); |
d3070fbd | 2373 | |
2e59b241 | 2374 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
d3070fbd | 2375 | c->log_extra_fields[c->n_log_extra_fields++] = IOVEC_MAKE(copy, sz); |
2e59b241 | 2376 | unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS|UNIT_ESCAPE_C, name, "LogExtraFields=%s", (char*) copy); |
d3070fbd LP |
2377 | |
2378 | copy = NULL; | |
2379 | } | |
2380 | ||
2381 | n++; | |
2382 | } | |
2383 | ||
2384 | r = sd_bus_message_exit_container(message); | |
2385 | if (r < 0) | |
2386 | return r; | |
2387 | ||
2e59b241 | 2388 | if (!UNIT_WRITE_FLAGS_NOOP(flags) && n == 0) { |
d3070fbd | 2389 | exec_context_free_log_extra_fields(c); |
2e59b241 | 2390 | unit_write_setting(u, flags, name, "LogExtraFields="); |
d3070fbd LP |
2391 | } |
2392 | ||
2393 | return 1; | |
7e2a3fcc | 2394 | } |
cffaed83 | 2395 | |
349cc4a5 | 2396 | #if HAVE_SECCOMP |
cffaed83 | 2397 | |
7e2a3fcc YW |
2398 | if (streq(name, "SystemCallErrorNumber")) |
2399 | return bus_set_transient_errno(u, name, &c->syscall_errno, message, flags, error); | |
2400 | ||
2401 | if (streq(name, "SystemCallFilter")) { | |
6b000af4 | 2402 | int allow_list; |
3f856a28 | 2403 | _cleanup_strv_free_ char **l = NULL; |
cffaed83 YW |
2404 | |
2405 | r = sd_bus_message_enter_container(message, 'r', "bas"); | |
2406 | if (r < 0) | |
2407 | return r; | |
2408 | ||
6b000af4 | 2409 | r = sd_bus_message_read(message, "b", &allow_list); |
cffaed83 YW |
2410 | if (r < 0) |
2411 | return r; | |
2412 | ||
2413 | r = sd_bus_message_read_strv(message, &l); | |
2414 | if (r < 0) | |
2415 | return r; | |
2416 | ||
2417 | r = sd_bus_message_exit_container(message); | |
2418 | if (r < 0) | |
2419 | return r; | |
2420 | ||
2e59b241 | 2421 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
cffaed83 | 2422 | _cleanup_free_ char *joined = NULL; |
6b000af4 | 2423 | SeccompParseFlags invert_flag = allow_list ? 0 : SECCOMP_PARSE_INVERT; |
cffaed83 | 2424 | |
7b943bb7 | 2425 | if (strv_isempty(l)) { |
6b000af4 | 2426 | c->syscall_allow_list = false; |
8cfa775f | 2427 | c->syscall_filter = hashmap_free(c->syscall_filter); |
cffaed83 | 2428 | |
898748d8 YW |
2429 | unit_write_settingf(u, flags, name, "SystemCallFilter="); |
2430 | return 1; | |
2431 | } | |
cffaed83 | 2432 | |
898748d8 YW |
2433 | if (!c->syscall_filter) { |
2434 | c->syscall_filter = hashmap_new(NULL); | |
2435 | if (!c->syscall_filter) | |
2436 | return log_oom(); | |
cffaed83 | 2437 | |
6b000af4 | 2438 | c->syscall_allow_list = allow_list; |
8cfa775f | 2439 | |
6b000af4 | 2440 | if (c->syscall_allow_list) { |
e7ccdfa8 ZJS |
2441 | r = seccomp_parse_syscall_filter("@default", |
2442 | -1, | |
2443 | c->syscall_filter, | |
72545ae0 | 2444 | SECCOMP_PARSE_PERMISSIVE | |
6b000af4 | 2445 | SECCOMP_PARSE_ALLOW_LIST | invert_flag, |
58f6ab44 ZJS |
2446 | u->id, |
2447 | NULL, 0); | |
8cfa775f YW |
2448 | if (r < 0) |
2449 | return r; | |
898748d8 YW |
2450 | } |
2451 | } | |
8cfa775f | 2452 | |
898748d8 YW |
2453 | STRV_FOREACH(s, l) { |
2454 | _cleanup_free_ char *n = NULL; | |
2455 | int e; | |
cffaed83 | 2456 | |
898748d8 YW |
2457 | r = parse_syscall_and_errno(*s, &n, &e); |
2458 | if (r < 0) | |
2459 | return r; | |
cffaed83 | 2460 | |
084a46d7 YW |
2461 | if (allow_list && e >= 0) |
2462 | return -EINVAL; | |
2463 | ||
e7ccdfa8 ZJS |
2464 | r = seccomp_parse_syscall_filter(n, |
2465 | e, | |
2466 | c->syscall_filter, | |
72545ae0 AZ |
2467 | SECCOMP_PARSE_LOG | SECCOMP_PARSE_PERMISSIVE | |
2468 | invert_flag | | |
6b000af4 | 2469 | (c->syscall_allow_list ? SECCOMP_PARSE_ALLOW_LIST : 0), |
58f6ab44 ZJS |
2470 | u->id, |
2471 | NULL, 0); | |
898748d8 YW |
2472 | if (r < 0) |
2473 | return r; | |
cffaed83 YW |
2474 | } |
2475 | ||
2476 | joined = strv_join(l, " "); | |
2477 | if (!joined) | |
2478 | return -ENOMEM; | |
2479 | ||
6b000af4 | 2480 | unit_write_settingf(u, flags, name, "SystemCallFilter=%s%s", allow_list ? "" : "~", joined); |
cffaed83 YW |
2481 | } |
2482 | ||
2483 | return 1; | |
2484 | ||
9df2cdd8 TM |
2485 | } else if (streq(name, "SystemCallLog")) { |
2486 | int allow_list; | |
2487 | _cleanup_strv_free_ char **l = NULL; | |
2488 | ||
2489 | r = sd_bus_message_enter_container(message, 'r', "bas"); | |
2490 | if (r < 0) | |
2491 | return r; | |
2492 | ||
2493 | r = sd_bus_message_read(message, "b", &allow_list); | |
2494 | if (r < 0) | |
2495 | return r; | |
2496 | ||
2497 | r = sd_bus_message_read_strv(message, &l); | |
2498 | if (r < 0) | |
2499 | return r; | |
2500 | ||
2501 | r = sd_bus_message_exit_container(message); | |
2502 | if (r < 0) | |
2503 | return r; | |
2504 | ||
2505 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
2506 | _cleanup_free_ char *joined = NULL; | |
2507 | SeccompParseFlags invert_flag = allow_list ? 0 : SECCOMP_PARSE_INVERT; | |
9df2cdd8 TM |
2508 | |
2509 | if (strv_isempty(l)) { | |
2510 | c->syscall_log_allow_list = false; | |
2511 | c->syscall_log = hashmap_free(c->syscall_log); | |
2512 | ||
2513 | unit_write_settingf(u, flags, name, "SystemCallLog="); | |
2514 | return 1; | |
2515 | } | |
2516 | ||
2517 | if (!c->syscall_log) { | |
2518 | c->syscall_log = hashmap_new(NULL); | |
2519 | if (!c->syscall_log) | |
2520 | return log_oom(); | |
2521 | ||
2522 | c->syscall_log_allow_list = allow_list; | |
2523 | } | |
2524 | ||
2525 | STRV_FOREACH(s, l) { | |
696a13ba YW |
2526 | r = seccomp_parse_syscall_filter(*s, |
2527 | -1, /* errno not used */ | |
9df2cdd8 TM |
2528 | c->syscall_log, |
2529 | SECCOMP_PARSE_LOG | SECCOMP_PARSE_PERMISSIVE | | |
2530 | invert_flag | | |
2531 | (c->syscall_log_allow_list ? SECCOMP_PARSE_ALLOW_LIST : 0), | |
2532 | u->id, | |
2533 | NULL, 0); | |
2534 | if (r < 0) | |
2535 | return r; | |
2536 | } | |
2537 | ||
2538 | joined = strv_join(l, " "); | |
2539 | if (!joined) | |
2540 | return -ENOMEM; | |
2541 | ||
2542 | unit_write_settingf(u, flags, name, "SystemCallLog=%s%s", allow_list ? "" : "~", joined); | |
2543 | } | |
2544 | ||
2545 | return 1; | |
2546 | ||
cffaed83 YW |
2547 | } else if (streq(name, "SystemCallArchitectures")) { |
2548 | _cleanup_strv_free_ char **l = NULL; | |
2549 | ||
2550 | r = sd_bus_message_read_strv(message, &l); | |
2551 | if (r < 0) | |
2552 | return r; | |
2553 | ||
2e59b241 | 2554 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
cffaed83 YW |
2555 | _cleanup_free_ char *joined = NULL; |
2556 | ||
7b943bb7 | 2557 | if (strv_isempty(l)) |
cffaed83 | 2558 | c->syscall_archs = set_free(c->syscall_archs); |
de010b0b | 2559 | else |
cffaed83 YW |
2560 | STRV_FOREACH(s, l) { |
2561 | uint32_t a; | |
2562 | ||
2563 | r = seccomp_arch_from_string(*s, &a); | |
2564 | if (r < 0) | |
2565 | return r; | |
2566 | ||
de7fef4b | 2567 | r = set_ensure_put(&c->syscall_archs, NULL, UINT32_TO_PTR(a + 1)); |
cffaed83 YW |
2568 | if (r < 0) |
2569 | return r; | |
2570 | } | |
2571 | ||
cffaed83 YW |
2572 | joined = strv_join(l, " "); |
2573 | if (!joined) | |
2574 | return -ENOMEM; | |
2575 | ||
2e59b241 | 2576 | unit_write_settingf(u, flags, name, "%s=%s", name, joined); |
cffaed83 YW |
2577 | } |
2578 | ||
2579 | return 1; | |
2580 | ||
cffaed83 | 2581 | } else if (streq(name, "RestrictAddressFamilies")) { |
3f856a28 | 2582 | _cleanup_strv_free_ char **l = NULL; |
4e6c50a5 | 2583 | int allow_list; |
cffaed83 YW |
2584 | |
2585 | r = sd_bus_message_enter_container(message, 'r', "bas"); | |
2586 | if (r < 0) | |
2587 | return r; | |
2588 | ||
6b000af4 | 2589 | r = sd_bus_message_read(message, "b", &allow_list); |
cffaed83 YW |
2590 | if (r < 0) |
2591 | return r; | |
2592 | ||
2593 | r = sd_bus_message_read_strv(message, &l); | |
2594 | if (r < 0) | |
2595 | return r; | |
2596 | ||
2597 | r = sd_bus_message_exit_container(message); | |
2598 | if (r < 0) | |
2599 | return r; | |
2600 | ||
2e59b241 | 2601 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
cffaed83 YW |
2602 | _cleanup_free_ char *joined = NULL; |
2603 | ||
7b943bb7 | 2604 | if (strv_isempty(l)) { |
4e6c50a5 | 2605 | c->address_families_allow_list = allow_list; |
cffaed83 | 2606 | c->address_families = set_free(c->address_families); |
cffaed83 | 2607 | |
4e6c50a5 YW |
2608 | unit_write_settingf(u, flags, name, "RestrictAddressFamilies=%s", |
2609 | allow_list ? "none" : ""); | |
9ee896d5 YW |
2610 | return 1; |
2611 | } | |
cffaed83 | 2612 | |
9ee896d5 YW |
2613 | if (!c->address_families) { |
2614 | c->address_families = set_new(NULL); | |
2615 | if (!c->address_families) | |
2616 | return log_oom(); | |
cffaed83 | 2617 | |
6b000af4 | 2618 | c->address_families_allow_list = allow_list; |
9ee896d5 YW |
2619 | } |
2620 | ||
2621 | STRV_FOREACH(s, l) { | |
2622 | int af; | |
cffaed83 | 2623 | |
9ee896d5 | 2624 | af = af_from_name(*s); |
acf4d158 YW |
2625 | if (af < 0) |
2626 | return af; | |
cffaed83 | 2627 | |
6b000af4 | 2628 | if (allow_list == c->address_families_allow_list) { |
cffaed83 YW |
2629 | r = set_put(c->address_families, INT_TO_PTR(af)); |
2630 | if (r < 0) | |
2631 | return r; | |
9ee896d5 | 2632 | } else |
4e6c50a5 | 2633 | set_remove(c->address_families, INT_TO_PTR(af)); |
cffaed83 YW |
2634 | } |
2635 | ||
2636 | joined = strv_join(l, " "); | |
2637 | if (!joined) | |
2638 | return -ENOMEM; | |
2639 | ||
6b000af4 | 2640 | unit_write_settingf(u, flags, name, "RestrictAddressFamilies=%s%s", allow_list ? "" : "~", joined); |
cffaed83 YW |
2641 | } |
2642 | ||
2643 | return 1; | |
7e2a3fcc | 2644 | } |
cffaed83 | 2645 | #endif |
b070c7c0 | 2646 | if (STR_IN_SET(name, "CPUAffinity", "NUMAMask")) { |
cffaed83 | 2647 | const void *a; |
bd0abfae | 2648 | size_t n; |
b070c7c0 | 2649 | bool affinity = streq(name, "CPUAffinity"); |
c367f996 | 2650 | _cleanup_(cpu_set_reset) CPUSet set = {}; |
cffaed83 YW |
2651 | |
2652 | r = sd_bus_message_read_array(message, 'y', &a, &n); | |
2653 | if (r < 0) | |
2654 | return r; | |
2655 | ||
c367f996 MS |
2656 | r = cpu_set_from_dbus(a, n, &set); |
2657 | if (r < 0) | |
2658 | return r; | |
2659 | ||
2e59b241 | 2660 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
cffaed83 | 2661 | if (n == 0) { |
b070c7c0 | 2662 | cpu_set_reset(affinity ? &c->cpu_set : &c->numa_policy.nodes); |
2e59b241 | 2663 | unit_write_settingf(u, flags, name, "%s=", name); |
cffaed83 YW |
2664 | } else { |
2665 | _cleanup_free_ char *str = NULL; | |
cffaed83 | 2666 | |
0985c7c4 | 2667 | str = cpu_set_to_string(&set); |
a832893f ZJS |
2668 | if (!str) |
2669 | return -ENOMEM; | |
cffaed83 | 2670 | |
0985c7c4 ZJS |
2671 | /* We forego any optimizations here, and always create the structure using |
2672 | * cpu_set_add_all(), because we don't want to care if the existing size we | |
2673 | * got over dbus is appropriate. */ | |
b070c7c0 | 2674 | r = cpu_set_add_all(affinity ? &c->cpu_set : &c->numa_policy.nodes, &set); |
0985c7c4 ZJS |
2675 | if (r < 0) |
2676 | return r; | |
501941aa | 2677 | |
2e59b241 | 2678 | unit_write_settingf(u, flags, name, "%s=%s", name, str); |
cffaed83 YW |
2679 | } |
2680 | } | |
2681 | ||
c7040b5d LP |
2682 | return 1; |
2683 | ||
e2b2fb7f MS |
2684 | } else if (streq(name, "CPUAffinityFromNUMA")) { |
2685 | int q; | |
2686 | ||
2687 | r = sd_bus_message_read_basic(message, 'b', &q); | |
2688 | if (r < 0) | |
2689 | return r; | |
2690 | ||
2691 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
2692 | c->cpu_affinity_from_numa = q; | |
2693 | unit_write_settingf(u, flags, name, "%s=%s", "CPUAffinity", "numa"); | |
2694 | } | |
2695 | ||
2696 | return 1; | |
2697 | ||
b070c7c0 MS |
2698 | } else if (streq(name, "NUMAPolicy")) { |
2699 | int32_t type; | |
2700 | ||
2701 | r = sd_bus_message_read(message, "i", &type); | |
2702 | if (r < 0) | |
2703 | return r; | |
2704 | ||
2705 | if (!mpol_is_valid(type)) | |
2706 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid NUMAPolicy value: %i", type); | |
2707 | ||
2708 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) | |
2709 | c->numa_policy.type = type; | |
2710 | ||
2711 | return 1; | |
e2b2fb7f | 2712 | |
c250bf67 YW |
2713 | } else if (streq(name, "Nice")) { |
2714 | int32_t q; | |
2715 | ||
2716 | r = sd_bus_message_read(message, "i", &q); | |
2717 | if (r < 0) | |
2718 | return r; | |
2719 | ||
2720 | if (!nice_is_valid(q)) | |
2721 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid Nice value: %i", q); | |
2722 | ||
2723 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
2724 | c->nice = q; | |
2725 | c->nice_set = true; | |
2726 | ||
2727 | unit_write_settingf(u, flags, name, "Nice=%i", q); | |
2728 | } | |
2729 | ||
2730 | return 1; | |
2731 | ||
2732 | } else if (streq(name, "CPUSchedulingPolicy")) { | |
2733 | int32_t q; | |
2734 | ||
2735 | r = sd_bus_message_read(message, "i", &q); | |
2736 | if (r < 0) | |
2737 | return r; | |
2738 | ||
2739 | if (!sched_policy_is_valid(q)) | |
2740 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid CPU scheduling policy: %i", q); | |
2741 | ||
2742 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
2743 | _cleanup_free_ char *s = NULL; | |
2744 | ||
2745 | r = sched_policy_to_string_alloc(q, &s); | |
2746 | if (r < 0) | |
2747 | return r; | |
2748 | ||
2749 | c->cpu_sched_policy = q; | |
2750 | c->cpu_sched_priority = CLAMP(c->cpu_sched_priority, sched_get_priority_min(q), sched_get_priority_max(q)); | |
2751 | c->cpu_sched_set = true; | |
2752 | ||
2753 | unit_write_settingf(u, flags, name, "CPUSchedulingPolicy=%s", s); | |
2754 | } | |
2755 | ||
2756 | return 1; | |
2757 | ||
2758 | } else if (streq(name, "CPUSchedulingPriority")) { | |
2759 | int32_t p, min, max; | |
2760 | ||
2761 | r = sd_bus_message_read(message, "i", &p); | |
2762 | if (r < 0) | |
2763 | return r; | |
2764 | ||
2765 | min = sched_get_priority_min(c->cpu_sched_policy); | |
2766 | max = sched_get_priority_max(c->cpu_sched_policy); | |
2767 | if (p < min || p > max) | |
2768 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid CPU scheduling priority: %i", p); | |
2769 | ||
2770 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
2771 | c->cpu_sched_priority = p; | |
2772 | c->cpu_sched_set = true; | |
2773 | ||
2774 | unit_write_settingf(u, flags, name, "CPUSchedulingPriority=%i", p); | |
2775 | } | |
2776 | ||
2777 | return 1; | |
2778 | ||
7f452159 LP |
2779 | } else if (streq(name, "IOSchedulingClass")) { |
2780 | int32_t q; | |
2781 | ||
2782 | r = sd_bus_message_read(message, "i", &q); | |
2783 | if (r < 0) | |
2784 | return r; | |
2785 | ||
2786 | if (!ioprio_class_is_valid(q)) | |
2787 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid IO scheduling class: %i", q); | |
2788 | ||
2e59b241 | 2789 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
7f452159 LP |
2790 | _cleanup_free_ char *s = NULL; |
2791 | ||
2792 | r = ioprio_class_to_string_alloc(q, &s); | |
2793 | if (r < 0) | |
2794 | return r; | |
2795 | ||
ba7772fe | 2796 | c->ioprio = ioprio_normalize(ioprio_prio_value(q, ioprio_prio_data(c->ioprio))); |
7f452159 LP |
2797 | c->ioprio_set = true; |
2798 | ||
2e59b241 | 2799 | unit_write_settingf(u, flags, name, "IOSchedulingClass=%s", s); |
7f452159 LP |
2800 | } |
2801 | ||
2802 | return 1; | |
2803 | ||
2804 | } else if (streq(name, "IOSchedulingPriority")) { | |
2805 | int32_t p; | |
2806 | ||
2807 | r = sd_bus_message_read(message, "i", &p); | |
2808 | if (r < 0) | |
2809 | return r; | |
2810 | ||
2811 | if (!ioprio_priority_is_valid(p)) | |
2812 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid IO scheduling priority: %i", p); | |
2813 | ||
2e59b241 | 2814 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
ba7772fe | 2815 | c->ioprio = ioprio_normalize(ioprio_prio_value(ioprio_prio_class(c->ioprio), p)); |
7f452159 LP |
2816 | c->ioprio_set = true; |
2817 | ||
2e59b241 | 2818 | unit_write_settingf(u, flags, name, "IOSchedulingPriority=%i", p); |
7f452159 LP |
2819 | } |
2820 | ||
2821 | return 1; | |
2822 | ||
5e98086d ZJS |
2823 | } else if (streq(name, "MountAPIVFS")) { |
2824 | bool b; | |
2825 | ||
2826 | r = bus_set_transient_bool(u, name, &b, message, flags, error); | |
2827 | if (r < 0) | |
2828 | return r; | |
2829 | ||
2830 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
2831 | c->mount_apivfs = b; | |
2832 | c->mount_apivfs_set = true; | |
2833 | } | |
2834 | ||
2835 | return 1; | |
2836 | ||
5f5d8eab LP |
2837 | } else if (streq(name, "WorkingDirectory")) { |
2838 | const char *s; | |
2839 | bool missing_ok; | |
2840 | ||
2841 | r = sd_bus_message_read(message, "s", &s); | |
2842 | if (r < 0) | |
2843 | return r; | |
2844 | ||
2845 | if (s[0] == '-') { | |
2846 | missing_ok = true; | |
2847 | s++; | |
2848 | } else | |
2849 | missing_ok = false; | |
2850 | ||
d6ff82d3 | 2851 | if (!isempty(s) && !streq(s, "~") && !path_is_absolute(s)) |
1b09b81c | 2852 | return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "WorkingDirectory= expects an absolute path or '~'"); |
5f5d8eab | 2853 | |
2e59b241 | 2854 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
5f5d8eab LP |
2855 | if (streq(s, "~")) { |
2856 | c->working_directory = mfree(c->working_directory); | |
2857 | c->working_directory_home = true; | |
2858 | } else { | |
d6ff82d3 | 2859 | r = free_and_strdup(&c->working_directory, empty_to_null(s)); |
5f5d8eab LP |
2860 | if (r < 0) |
2861 | return r; | |
2862 | ||
2863 | c->working_directory_home = false; | |
2864 | } | |
2865 | ||
2866 | c->working_directory_missing_ok = missing_ok; | |
2e59b241 | 2867 | unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "WorkingDirectory=%s%s", missing_ok ? "-" : "", s); |
5f5d8eab LP |
2868 | } |
2869 | ||
2870 | return 1; | |
2871 | ||
52c239d7 LB |
2872 | } else if (STR_IN_SET(name, |
2873 | "StandardInputFileDescriptorName", "StandardOutputFileDescriptorName", "StandardErrorFileDescriptorName")) { | |
2874 | const char *s; | |
2875 | ||
2876 | r = sd_bus_message_read(message, "s", &s); | |
2877 | if (r < 0) | |
2878 | return r; | |
2879 | ||
d6ff82d3 | 2880 | if (!isempty(s) && !fdname_is_valid(s)) |
1b09b81c | 2881 | return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid file descriptor name"); |
52c239d7 | 2882 | |
2e59b241 | 2883 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
5073ff6b | 2884 | |
52c239d7 | 2885 | if (streq(name, "StandardInputFileDescriptorName")) { |
d6ff82d3 | 2886 | r = free_and_strdup(c->stdio_fdname + STDIN_FILENO, empty_to_null(s)); |
52c239d7 LB |
2887 | if (r < 0) |
2888 | return r; | |
5073ff6b | 2889 | |
0664775c | 2890 | c->std_input = EXEC_INPUT_NAMED_FD; |
2e59b241 | 2891 | unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardInput=fd:%s", exec_context_fdname(c, STDIN_FILENO)); |
5073ff6b | 2892 | |
52c239d7 | 2893 | } else if (streq(name, "StandardOutputFileDescriptorName")) { |
d6ff82d3 | 2894 | r = free_and_strdup(c->stdio_fdname + STDOUT_FILENO, empty_to_null(s)); |
52c239d7 LB |
2895 | if (r < 0) |
2896 | return r; | |
5073ff6b | 2897 | |
52c239d7 | 2898 | c->std_output = EXEC_OUTPUT_NAMED_FD; |
2e59b241 | 2899 | unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardOutput=fd:%s", exec_context_fdname(c, STDOUT_FILENO)); |
0664775c LP |
2900 | |
2901 | } else { | |
2902 | assert(streq(name, "StandardErrorFileDescriptorName")); | |
5073ff6b | 2903 | |
d6ff82d3 | 2904 | r = free_and_strdup(&c->stdio_fdname[STDERR_FILENO], empty_to_null(s)); |
52c239d7 LB |
2905 | if (r < 0) |
2906 | return r; | |
5073ff6b | 2907 | |
52c239d7 | 2908 | c->std_error = EXEC_OUTPUT_NAMED_FD; |
2e59b241 | 2909 | unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardError=fd:%s", exec_context_fdname(c, STDERR_FILENO)); |
52c239d7 LB |
2910 | } |
2911 | } | |
2912 | ||
2913 | return 1; | |
2914 | ||
566b7d23 ZD |
2915 | } else if (STR_IN_SET(name, |
2916 | "StandardInputFile", | |
8d7dab1f LW |
2917 | "StandardOutputFile", "StandardOutputFileToAppend", "StandardOutputFileToTruncate", |
2918 | "StandardErrorFile", "StandardErrorFileToAppend", "StandardErrorFileToTruncate")) { | |
2038c3f5 LP |
2919 | const char *s; |
2920 | ||
2921 | r = sd_bus_message_read(message, "s", &s); | |
2922 | if (r < 0) | |
2923 | return r; | |
2924 | ||
d6ff82d3 YW |
2925 | if (!isempty(s)) { |
2926 | if (!path_is_absolute(s)) | |
2927 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path %s is not absolute", s); | |
2928 | if (!path_is_normalized(s)) | |
2929 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path %s is not normalized", s); | |
2930 | } | |
2038c3f5 | 2931 | |
2e59b241 | 2932 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
2038c3f5 LP |
2933 | |
2934 | if (streq(name, "StandardInputFile")) { | |
d6ff82d3 | 2935 | r = free_and_strdup(&c->stdio_file[STDIN_FILENO], empty_to_null(s)); |
52c239d7 LB |
2936 | if (r < 0) |
2937 | return r; | |
2038c3f5 LP |
2938 | |
2939 | c->std_input = EXEC_INPUT_FILE; | |
2e59b241 | 2940 | unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardInput=file:%s", s); |
2038c3f5 | 2941 | |
8d7dab1f | 2942 | } else if (STR_IN_SET(name, "StandardOutputFile", "StandardOutputFileToAppend", "StandardOutputFileToTruncate")) { |
d6ff82d3 | 2943 | r = free_and_strdup(&c->stdio_file[STDOUT_FILENO], empty_to_null(s)); |
2038c3f5 LP |
2944 | if (r < 0) |
2945 | return r; | |
2946 | ||
566b7d23 ZD |
2947 | if (streq(name, "StandardOutputFile")) { |
2948 | c->std_output = EXEC_OUTPUT_FILE; | |
2949 | unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardOutput=file:%s", s); | |
8d7dab1f | 2950 | } else if (streq(name, "StandardOutputFileToAppend")) { |
566b7d23 ZD |
2951 | c->std_output = EXEC_OUTPUT_FILE_APPEND; |
2952 | unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardOutput=append:%s", s); | |
8d7dab1f LW |
2953 | } else { |
2954 | assert(streq(name, "StandardOutputFileToTruncate")); | |
2955 | c->std_output = EXEC_OUTPUT_FILE_TRUNCATE; | |
2956 | unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardOutput=truncate:%s", s); | |
566b7d23 | 2957 | } |
2038c3f5 | 2958 | } else { |
8d7dab1f | 2959 | assert(STR_IN_SET(name, "StandardErrorFile", "StandardErrorFileToAppend", "StandardErrorFileToTruncate")); |
2038c3f5 | 2960 | |
d6ff82d3 | 2961 | r = free_and_strdup(&c->stdio_file[STDERR_FILENO], empty_to_null(s)); |
2038c3f5 LP |
2962 | if (r < 0) |
2963 | return r; | |
2964 | ||
566b7d23 ZD |
2965 | if (streq(name, "StandardErrorFile")) { |
2966 | c->std_error = EXEC_OUTPUT_FILE; | |
1704fba9 | 2967 | unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardError=file:%s", s); |
8d7dab1f | 2968 | } else if (streq(name, "StandardErrorFileToAppend")) { |
dbe6c4b6 | 2969 | c->std_error = EXEC_OUTPUT_FILE_APPEND; |
1704fba9 | 2970 | unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardError=append:%s", s); |
8d7dab1f LW |
2971 | } else { |
2972 | assert(streq(name, "StandardErrorFileToTruncate")); | |
2973 | c->std_error = EXEC_OUTPUT_FILE_TRUNCATE; | |
2974 | unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardError=truncate:%s", s); | |
566b7d23 | 2975 | } |
2038c3f5 LP |
2976 | } |
2977 | } | |
2978 | ||
2979 | return 1; | |
2980 | ||
08f3be7a LP |
2981 | } else if (streq(name, "StandardInputData")) { |
2982 | const void *p; | |
2983 | size_t sz; | |
2984 | ||
2985 | r = sd_bus_message_read_array(message, 'y', &p, &sz); | |
2986 | if (r < 0) | |
2987 | return r; | |
2988 | ||
2e59b241 | 2989 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
08f3be7a LP |
2990 | _cleanup_free_ char *encoded = NULL; |
2991 | ||
2992 | if (sz == 0) { | |
2993 | c->stdin_data = mfree(c->stdin_data); | |
2994 | c->stdin_data_size = 0; | |
2995 | ||
2e59b241 | 2996 | unit_write_settingf(u, flags, name, "StandardInputData="); |
08f3be7a LP |
2997 | } else { |
2998 | void *q; | |
2999 | ssize_t n; | |
3000 | ||
3001 | if (c->stdin_data_size + sz < c->stdin_data_size || /* check for overflow */ | |
3002 | c->stdin_data_size + sz > EXEC_STDIN_DATA_MAX) | |
3003 | return -E2BIG; | |
3004 | ||
3005 | n = base64mem(p, sz, &encoded); | |
3006 | if (n < 0) | |
3007 | return (int) n; | |
3008 | ||
3009 | q = realloc(c->stdin_data, c->stdin_data_size + sz); | |
3010 | if (!q) | |
3011 | return -ENOMEM; | |
3012 | ||
3013 | memcpy((uint8_t*) q + c->stdin_data_size, p, sz); | |
3014 | ||
3015 | c->stdin_data = q; | |
3016 | c->stdin_data_size += sz; | |
3017 | ||
2e59b241 | 3018 | unit_write_settingf(u, flags, name, "StandardInputData=%s", encoded); |
52c239d7 LB |
3019 | } |
3020 | } | |
3021 | ||
3022 | return 1; | |
3023 | ||
c7040b5d LP |
3024 | } else if (streq(name, "Environment")) { |
3025 | ||
6171b822 | 3026 | _cleanup_strv_free_ char **l = NULL; |
c7040b5d LP |
3027 | |
3028 | r = sd_bus_message_read_strv(message, &l); | |
3029 | if (r < 0) | |
3030 | return r; | |
3031 | ||
6171b822 | 3032 | if (!strv_env_is_valid(l)) |
1b09b81c | 3033 | return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid environment block."); |
1c68232e | 3034 | |
2e59b241 | 3035 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
7b943bb7 | 3036 | if (strv_isempty(l)) { |
e9876fc9 | 3037 | c->environment = strv_free(c->environment); |
2e59b241 | 3038 | unit_write_setting(u, flags, name, "Environment="); |
e9876fc9 | 3039 | } else { |
f900f582 ZJS |
3040 | _cleanup_free_ char *joined = NULL; |
3041 | char **e; | |
3042 | ||
2e59b241 LP |
3043 | joined = unit_concat_strv(l, UNIT_ESCAPE_SPECIFIERS|UNIT_ESCAPE_C); |
3044 | if (!joined) | |
3045 | return -ENOMEM; | |
3046 | ||
4ab3d29f | 3047 | e = strv_env_merge(c->environment, l); |
e9876fc9 EV |
3048 | if (!e) |
3049 | return -ENOMEM; | |
c7040b5d | 3050 | |
130d3d22 | 3051 | strv_free_and_replace(c->environment, e); |
2e59b241 | 3052 | unit_write_settingf(u, flags, name, "Environment=%s", joined); |
e9876fc9 | 3053 | } |
c7040b5d LP |
3054 | } |
3055 | ||
d584f638 LP |
3056 | return 1; |
3057 | ||
00819cc1 LP |
3058 | } else if (streq(name, "UnsetEnvironment")) { |
3059 | ||
6171b822 | 3060 | _cleanup_strv_free_ char **l = NULL; |
00819cc1 LP |
3061 | |
3062 | r = sd_bus_message_read_strv(message, &l); | |
3063 | if (r < 0) | |
3064 | return r; | |
3065 | ||
6171b822 | 3066 | if (!strv_env_name_or_assignment_is_valid(l)) |
1b09b81c | 3067 | return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid UnsetEnvironment= list."); |
00819cc1 | 3068 | |
2e59b241 | 3069 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
7b943bb7 | 3070 | if (strv_isempty(l)) { |
00819cc1 | 3071 | c->unset_environment = strv_free(c->unset_environment); |
2e59b241 | 3072 | unit_write_setting(u, flags, name, "UnsetEnvironment="); |
00819cc1 LP |
3073 | } else { |
3074 | _cleanup_free_ char *joined = NULL; | |
3075 | char **e; | |
3076 | ||
2e59b241 LP |
3077 | joined = unit_concat_strv(l, UNIT_ESCAPE_SPECIFIERS|UNIT_ESCAPE_C); |
3078 | if (!joined) | |
3079 | return -ENOMEM; | |
3080 | ||
4ab3d29f | 3081 | e = strv_env_merge(c->unset_environment, l); |
00819cc1 LP |
3082 | if (!e) |
3083 | return -ENOMEM; | |
3084 | ||
130d3d22 | 3085 | strv_free_and_replace(c->unset_environment, e); |
2e59b241 | 3086 | unit_write_settingf(u, flags, name, "UnsetEnvironment=%s", joined); |
00819cc1 LP |
3087 | } |
3088 | } | |
3089 | ||
3090 | return 1; | |
3091 | ||
6b862936 EV |
3092 | } else if (streq(name, "OOMScoreAdjust")) { |
3093 | int oa; | |
3094 | ||
3095 | r = sd_bus_message_read(message, "i", &oa); | |
3096 | if (r < 0) | |
3097 | return r; | |
3098 | ||
3099 | if (!oom_score_adjust_is_valid(oa)) | |
1b09b81c | 3100 | return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "OOM score adjust value out of range"); |
6b862936 | 3101 | |
2e59b241 | 3102 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
6b862936 EV |
3103 | c->oom_score_adjust = oa; |
3104 | c->oom_score_adjust_set = true; | |
2e59b241 | 3105 | unit_write_settingf(u, flags, name, "OOMScoreAdjust=%i", oa); |
6b862936 EV |
3106 | } |
3107 | ||
3108 | return 1; | |
3109 | ||
ad21e542 ZJS |
3110 | } else if (streq(name, "CoredumpFilter")) { |
3111 | uint64_t f; | |
3112 | ||
3113 | r = sd_bus_message_read(message, "t", &f); | |
3114 | if (r < 0) | |
3115 | return r; | |
3116 | ||
3117 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
3118 | c->coredump_filter = f; | |
3119 | c->coredump_filter_set = true; | |
3120 | unit_write_settingf(u, flags, name, "CoredumpFilter=0x%"PRIx64, f); | |
3121 | } | |
3122 | ||
3123 | return 1; | |
3124 | ||
ceb728cf NC |
3125 | } else if (streq(name, "EnvironmentFiles")) { |
3126 | ||
3127 | _cleanup_free_ char *joined = NULL; | |
3128 | _cleanup_fclose_ FILE *f = NULL; | |
9b531f04 | 3129 | _cleanup_strv_free_ char **l = NULL; |
ceb728cf | 3130 | size_t size = 0; |
ceb728cf NC |
3131 | |
3132 | r = sd_bus_message_enter_container(message, 'a', "(sb)"); | |
3133 | if (r < 0) | |
3134 | return r; | |
3135 | ||
2fe21124 | 3136 | f = open_memstream_unlocked(&joined, &size); |
ceb728cf NC |
3137 | if (!f) |
3138 | return -ENOMEM; | |
3139 | ||
2e59b241 LP |
3140 | fputs("EnvironmentFile=\n", f); |
3141 | ||
3142 | STRV_FOREACH(i, c->environment_files) { | |
3143 | _cleanup_free_ char *q = NULL; | |
3144 | ||
3145 | q = specifier_escape(*i); | |
3146 | if (!q) | |
3147 | return -ENOMEM; | |
3148 | ||
3149 | fprintf(f, "EnvironmentFile=%s\n", q); | |
3150 | } | |
ceb728cf NC |
3151 | |
3152 | while ((r = sd_bus_message_enter_container(message, 'r', "sb")) > 0) { | |
3153 | const char *path; | |
3154 | int b; | |
3155 | ||
ceb728cf NC |
3156 | r = sd_bus_message_read(message, "sb", &path, &b); |
3157 | if (r < 0) | |
3158 | return r; | |
3159 | ||
3160 | r = sd_bus_message_exit_container(message); | |
3161 | if (r < 0) | |
3162 | return r; | |
3163 | ||
d2d6c096 LP |
3164 | if (!path_is_absolute(path)) |
3165 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path %s is not absolute.", path); | |
ceb728cf | 3166 | |
2e59b241 | 3167 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
6abdec98 | 3168 | _cleanup_free_ char *q = NULL, *buf = NULL; |
ceb728cf | 3169 | |
605405c6 | 3170 | buf = strjoin(b ? "-" : "", path); |
2229f656 | 3171 | if (!buf) |
ceb728cf NC |
3172 | return -ENOMEM; |
3173 | ||
2e59b241 | 3174 | q = specifier_escape(buf); |
6abdec98 | 3175 | if (!q) |
2e59b241 | 3176 | return -ENOMEM; |
2e59b241 LP |
3177 | |
3178 | fprintf(f, "EnvironmentFile=%s\n", q); | |
ceb728cf | 3179 | |
6abdec98 | 3180 | r = strv_consume(&l, TAKE_PTR(buf)); |
ceb728cf NC |
3181 | if (r < 0) |
3182 | return r; | |
3183 | } | |
3184 | } | |
3185 | if (r < 0) | |
3186 | return r; | |
3187 | ||
b0830e21 LP |
3188 | r = sd_bus_message_exit_container(message); |
3189 | if (r < 0) | |
3190 | return r; | |
3191 | ||
2229f656 LP |
3192 | r = fflush_and_check(f); |
3193 | if (r < 0) | |
3194 | return r; | |
ceb728cf | 3195 | |
2e59b241 | 3196 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
2229f656 LP |
3197 | if (strv_isempty(l)) { |
3198 | c->environment_files = strv_free(c->environment_files); | |
2e59b241 | 3199 | unit_write_setting(u, flags, name, "EnvironmentFile="); |
2229f656 LP |
3200 | } else { |
3201 | r = strv_extend_strv(&c->environment_files, l, true); | |
3202 | if (r < 0) | |
3203 | return r; | |
3204 | ||
2e59b241 | 3205 | unit_write_setting(u, flags, name, joined); |
2229f656 LP |
3206 | } |
3207 | } | |
ceb728cf | 3208 | |
ceb728cf NC |
3209 | return 1; |
3210 | ||
b4c14404 FB |
3211 | } else if (streq(name, "PassEnvironment")) { |
3212 | ||
6171b822 | 3213 | _cleanup_strv_free_ char **l = NULL; |
b4c14404 FB |
3214 | |
3215 | r = sd_bus_message_read_strv(message, &l); | |
3216 | if (r < 0) | |
3217 | return r; | |
3218 | ||
6171b822 | 3219 | if (!strv_env_name_is_valid(l)) |
1b09b81c | 3220 | return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid PassEnvironment= block."); |
b4c14404 | 3221 | |
2e59b241 | 3222 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
b4c14404 FB |
3223 | if (strv_isempty(l)) { |
3224 | c->pass_environment = strv_free(c->pass_environment); | |
2e59b241 | 3225 | unit_write_setting(u, flags, name, "PassEnvironment="); |
b4c14404 FB |
3226 | } else { |
3227 | _cleanup_free_ char *joined = NULL; | |
3228 | ||
9d4f242a YW |
3229 | r = strv_extend_strv(&c->pass_environment, l, true); |
3230 | if (r < 0) | |
3231 | return r; | |
3232 | ||
41de9cc2 | 3233 | /* We write just the new settings out to file, with unresolved specifiers. */ |
2e59b241 | 3234 | joined = unit_concat_strv(l, UNIT_ESCAPE_SPECIFIERS); |
b4c14404 FB |
3235 | if (!joined) |
3236 | return -ENOMEM; | |
3237 | ||
2e59b241 | 3238 | unit_write_settingf(u, flags, name, "PassEnvironment=%s", joined); |
b4c14404 FB |
3239 | } |
3240 | } | |
3241 | ||
3242 | return 1; | |
3243 | ||
2a624c36 | 3244 | } else if (STR_IN_SET(name, "ReadWriteDirectories", "ReadOnlyDirectories", "InaccessibleDirectories", |
a07b9926 LB |
3245 | "ReadWritePaths", "ReadOnlyPaths", "InaccessiblePaths", "ExecPaths", "NoExecPaths", |
3246 | "ExtensionDirectories")) { | |
08596068 EV |
3247 | _cleanup_strv_free_ char **l = NULL; |
3248 | char ***dirs; | |
08596068 EV |
3249 | |
3250 | r = sd_bus_message_read_strv(message, &l); | |
3251 | if (r < 0) | |
3252 | return r; | |
3253 | ||
3254 | STRV_FOREACH(p, l) { | |
e7bcff4e | 3255 | char *i = *p; |
20b7a007 LP |
3256 | size_t offset; |
3257 | ||
20b7a007 LP |
3258 | offset = i[0] == '-'; |
3259 | offset += i[offset] == '+'; | |
3260 | if (!path_is_absolute(i + offset)) | |
08596068 | 3261 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid %s", name); |
e7bcff4e | 3262 | |
4ff361cc | 3263 | path_simplify(i + offset); |
08596068 EV |
3264 | } |
3265 | ||
2e59b241 | 3266 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
c4b41707 AP |
3267 | if (STR_IN_SET(name, "ReadWriteDirectories", "ReadWritePaths")) |
3268 | dirs = &c->read_write_paths; | |
3269 | else if (STR_IN_SET(name, "ReadOnlyDirectories", "ReadOnlyPaths")) | |
3270 | dirs = &c->read_only_paths; | |
ddc155b2 TM |
3271 | else if (streq(name, "ExecPaths")) |
3272 | dirs = &c->exec_paths; | |
3273 | else if (streq(name, "NoExecPaths")) | |
3274 | dirs = &c->no_exec_paths; | |
a07b9926 LB |
3275 | else if (streq(name, "ExtensionDirectories")) |
3276 | dirs = &c->extension_directories; | |
c4b41707 AP |
3277 | else /* "InaccessiblePaths" */ |
3278 | dirs = &c->inaccessible_paths; | |
08596068 | 3279 | |
7b943bb7 | 3280 | if (strv_isempty(l)) { |
08596068 | 3281 | *dirs = strv_free(*dirs); |
2e59b241 | 3282 | unit_write_settingf(u, flags, name, "%s=", name); |
08596068 | 3283 | } else { |
2e59b241 | 3284 | _cleanup_free_ char *joined = NULL; |
08596068 | 3285 | |
2e59b241 | 3286 | joined = unit_concat_strv(l, UNIT_ESCAPE_SPECIFIERS); |
08596068 EV |
3287 | if (!joined) |
3288 | return -ENOMEM; | |
3289 | ||
2e59b241 LP |
3290 | r = strv_extend_strv(dirs, l, true); |
3291 | if (r < 0) | |
3292 | return -ENOMEM; | |
08596068 | 3293 | |
2e59b241 LP |
3294 | unit_write_settingf(u, flags, name, "%s=%s", name, joined); |
3295 | } | |
08596068 EV |
3296 | } |
3297 | ||
3298 | return 1; | |
3299 | ||
8c35c10d | 3300 | } else if (streq(name, "ExecSearchPath")) { |
3301 | _cleanup_strv_free_ char **l = NULL; | |
8c35c10d | 3302 | |
3303 | r = sd_bus_message_read_strv(message, &l); | |
3304 | if (r < 0) | |
3305 | return r; | |
3306 | ||
de010b0b | 3307 | STRV_FOREACH(p, l) |
8c35c10d | 3308 | if (!path_is_absolute(*p) || !path_is_normalized(*p) || strchr(*p, ':')) |
3309 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid %s", name); | |
de010b0b | 3310 | |
8c35c10d | 3311 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
3312 | if (strv_isempty(l)) { | |
3313 | c->exec_search_path = strv_free(c->exec_search_path); | |
3314 | unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "ExecSearchPath="); | |
3315 | } else { | |
3316 | _cleanup_free_ char *joined = NULL; | |
3317 | r = strv_extend_strv(&c->exec_search_path, l, true); | |
3318 | if (r < 0) | |
3319 | return -ENOMEM; | |
3320 | joined = strv_join(c->exec_search_path, ":"); | |
3321 | if (!joined) | |
3322 | return log_oom(); | |
3323 | unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "ExecSearchPath=%s", joined); | |
3324 | } | |
3325 | } | |
3326 | ||
3327 | return 1; | |
3328 | ||
3536f49e | 3329 | } else if (STR_IN_SET(name, "RuntimeDirectory", "StateDirectory", "CacheDirectory", "LogsDirectory", "ConfigurationDirectory")) { |
fa21b5e3 | 3330 | _cleanup_strv_free_ char **l = NULL; |
fa21b5e3 EV |
3331 | |
3332 | r = sd_bus_message_read_strv(message, &l); | |
3333 | if (r < 0) | |
3334 | return r; | |
3335 | ||
3336 | STRV_FOREACH(p, l) { | |
8994a117 YW |
3337 | if (!path_is_normalized(*p)) |
3338 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "%s= path is not normalized: %s", name, *p); | |
3339 | ||
3340 | if (path_is_absolute(*p)) | |
3341 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "%s= path is absolute: %s", name, *p); | |
3342 | ||
3343 | if (path_startswith(*p, "private")) | |
3344 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "%s= path can't be 'private': %s", name, *p); | |
fa21b5e3 EV |
3345 | } |
3346 | ||
2e59b241 | 3347 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
3536f49e | 3348 | ExecDirectoryType i; |
b1ea85dc | 3349 | ExecDirectory *d; |
3536f49e | 3350 | |
b1ea85dc LP |
3351 | assert_se((i = exec_directory_type_from_string(name)) >= 0); |
3352 | d = c->directories + i; | |
fa21b5e3 EV |
3353 | |
3354 | if (strv_isempty(l)) { | |
211a3d87 | 3355 | exec_directory_done(d); |
2e59b241 | 3356 | unit_write_settingf(u, flags, name, "%s=", name); |
fa21b5e3 | 3357 | } else { |
2e59b241 LP |
3358 | _cleanup_free_ char *joined = NULL; |
3359 | ||
211a3d87 LB |
3360 | STRV_FOREACH(source, l) { |
3361 | r = exec_directory_add(&d->items, &d->n_items, *source, NULL); | |
3362 | if (r < 0) | |
3363 | return log_oom(); | |
3364 | } | |
fa21b5e3 | 3365 | |
2e59b241 | 3366 | joined = unit_concat_strv(l, UNIT_ESCAPE_SPECIFIERS); |
fa21b5e3 EV |
3367 | if (!joined) |
3368 | return -ENOMEM; | |
3369 | ||
2e59b241 | 3370 | unit_write_settingf(u, flags, name, "%s=%s", name, joined); |
fa21b5e3 EV |
3371 | } |
3372 | } | |
3373 | ||
3374 | return 1; | |
3375 | ||
cffaed83 YW |
3376 | } else if (STR_IN_SET(name, "AppArmorProfile", "SmackProcessLabel")) { |
3377 | int ignore; | |
3378 | const char *s; | |
3379 | ||
280921f2 | 3380 | r = sd_bus_message_read(message, "(bs)", &ignore, &s); |
cffaed83 YW |
3381 | if (r < 0) |
3382 | return r; | |
3383 | ||
2e59b241 | 3384 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
cffaed83 YW |
3385 | char **p; |
3386 | bool *b; | |
3387 | ||
3388 | if (streq(name, "AppArmorProfile")) { | |
3389 | p = &c->apparmor_profile; | |
3390 | b = &c->apparmor_profile_ignore; | |
3391 | } else { /* "SmackProcessLabel" */ | |
3392 | p = &c->smack_process_label; | |
3393 | b = &c->smack_process_label_ignore; | |
3394 | } | |
3395 | ||
3396 | if (isempty(s)) { | |
3397 | *p = mfree(*p); | |
3398 | *b = false; | |
3399 | } else { | |
3400 | if (free_and_strdup(p, s) < 0) | |
3401 | return -ENOMEM; | |
3402 | *b = ignore; | |
3403 | } | |
3404 | ||
2e59b241 | 3405 | unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "%s=%s%s", name, ignore ? "-" : "", strempty(s)); |
cffaed83 YW |
3406 | } |
3407 | ||
3408 | return 1; | |
3409 | ||
d2d6c096 | 3410 | } else if (STR_IN_SET(name, "BindPaths", "BindReadOnlyPaths")) { |
ec04aef4 | 3411 | char *source, *destination; |
4ff4c98a YW |
3412 | int ignore_enoent; |
3413 | uint64_t mount_flags; | |
3414 | bool empty = true; | |
d2d6c096 LP |
3415 | |
3416 | r = sd_bus_message_enter_container(message, 'a', "(ssbt)"); | |
3417 | if (r < 0) | |
3418 | return r; | |
3419 | ||
4ff4c98a | 3420 | while ((r = sd_bus_message_read(message, "(ssbt)", &source, &destination, &ignore_enoent, &mount_flags)) > 0) { |
d2d6c096 LP |
3421 | |
3422 | if (!path_is_absolute(source)) | |
3423 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Source path %s is not absolute.", source); | |
3424 | if (!path_is_absolute(destination)) | |
91d910e3 | 3425 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Destination path %s is not absolute.", destination); |
d2d6c096 | 3426 | if (!IN_SET(mount_flags, 0, MS_REC)) |
1b09b81c | 3427 | return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Unknown mount flags."); |
d2d6c096 | 3428 | |
2e59b241 | 3429 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
d2d6c096 LP |
3430 | r = bind_mount_add(&c->bind_mounts, &c->n_bind_mounts, |
3431 | &(BindMount) { | |
ec04aef4 TM |
3432 | .source = source, |
3433 | .destination = destination, | |
d2d6c096 LP |
3434 | .read_only = !!strstr(name, "ReadOnly"), |
3435 | .recursive = !!(mount_flags & MS_REC), | |
3436 | .ignore_enoent = ignore_enoent, | |
3437 | }); | |
3438 | if (r < 0) | |
3439 | return r; | |
3440 | ||
2e59b241 LP |
3441 | unit_write_settingf( |
3442 | u, flags|UNIT_ESCAPE_SPECIFIERS, name, | |
d2d6c096 LP |
3443 | "%s=%s%s:%s:%s", |
3444 | name, | |
3445 | ignore_enoent ? "-" : "", | |
3446 | source, | |
3447 | destination, | |
3448 | (mount_flags & MS_REC) ? "rbind" : "norbind"); | |
3449 | } | |
3450 | ||
3451 | empty = false; | |
3452 | } | |
3453 | if (r < 0) | |
3454 | return r; | |
3455 | ||
3456 | r = sd_bus_message_exit_container(message); | |
3457 | if (r < 0) | |
3458 | return r; | |
3459 | ||
3460 | if (empty) { | |
3461 | bind_mount_free_many(c->bind_mounts, c->n_bind_mounts); | |
3462 | c->bind_mounts = NULL; | |
3463 | c->n_bind_mounts = 0; | |
2e59b241 LP |
3464 | |
3465 | unit_write_settingf(u, flags, name, "%s=", name); | |
d2d6c096 LP |
3466 | } |
3467 | ||
784ad252 YW |
3468 | return 1; |
3469 | ||
3470 | } else if (streq(name, "TemporaryFileSystem")) { | |
3471 | const char *path, *options; | |
3472 | bool empty = true; | |
3473 | ||
3474 | r = sd_bus_message_enter_container(message, 'a', "(ss)"); | |
3475 | if (r < 0) | |
3476 | return r; | |
3477 | ||
3478 | while ((r = sd_bus_message_read(message, "(ss)", &path, &options)) > 0) { | |
3479 | ||
3480 | if (!path_is_absolute(path)) | |
3481 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Mount point %s is not absolute.", path); | |
3482 | ||
3483 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
3484 | r = temporary_filesystem_add(&c->temporary_filesystems, &c->n_temporary_filesystems, path, options); | |
3485 | if (r < 0) | |
3486 | return r; | |
3487 | ||
3488 | unit_write_settingf( | |
3489 | u, flags|UNIT_ESCAPE_SPECIFIERS, name, | |
3490 | "%s=%s:%s", | |
3491 | name, | |
3492 | path, | |
3493 | options); | |
3494 | } | |
3495 | ||
3496 | empty = false; | |
3497 | } | |
3498 | if (r < 0) | |
3499 | return r; | |
3500 | ||
3501 | r = sd_bus_message_exit_container(message); | |
3502 | if (r < 0) | |
3503 | return r; | |
3504 | ||
3505 | if (empty) { | |
3506 | temporary_filesystem_free_many(c->temporary_filesystems, c->n_temporary_filesystems); | |
3507 | c->temporary_filesystems = NULL; | |
3508 | c->n_temporary_filesystems = 0; | |
3509 | ||
3510 | unit_write_settingf(u, flags, name, "%s=", name); | |
3511 | } | |
3512 | ||
83555251 | 3513 | return 1; |
d2d6c096 | 3514 | |
6550c24c LP |
3515 | } else if ((suffix = startswith(name, "Limit"))) { |
3516 | const char *soft = NULL; | |
3517 | int ri; | |
cab2aca3 | 3518 | |
6550c24c LP |
3519 | ri = rlimit_from_string(suffix); |
3520 | if (ri < 0) { | |
3521 | soft = endswith(suffix, "Soft"); | |
3522 | if (soft) { | |
3523 | const char *n; | |
cab2aca3 | 3524 | |
2f82562b | 3525 | n = strndupa_safe(suffix, soft - suffix); |
6550c24c LP |
3526 | ri = rlimit_from_string(n); |
3527 | if (ri >= 0) | |
3528 | name = strjoina("Limit", n); | |
3529 | } | |
cab2aca3 | 3530 | } |
d584f638 | 3531 | |
6550c24c LP |
3532 | if (ri >= 0) { |
3533 | uint64_t rl; | |
3534 | rlim_t x; | |
d584f638 | 3535 | |
6550c24c | 3536 | r = sd_bus_message_read(message, "t", &rl); |
cab2aca3 LP |
3537 | if (r < 0) |
3538 | return r; | |
d584f638 | 3539 | |
f5fbe71d | 3540 | if (rl == UINT64_MAX) |
6550c24c | 3541 | x = RLIM_INFINITY; |
cab2aca3 | 3542 | else { |
6550c24c LP |
3543 | x = (rlim_t) rl; |
3544 | ||
3545 | if ((uint64_t) x != rl) | |
3546 | return -ERANGE; | |
d584f638 LP |
3547 | } |
3548 | ||
6550c24c LP |
3549 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
3550 | _cleanup_free_ char *f = NULL; | |
3551 | struct rlimit nl; | |
3552 | ||
3553 | if (c->rlimit[ri]) { | |
3554 | nl = *c->rlimit[ri]; | |
3555 | ||
3556 | if (soft) | |
3557 | nl.rlim_cur = x; | |
3558 | else | |
3559 | nl.rlim_max = x; | |
3560 | } else | |
3561 | /* When the resource limit is not initialized yet, then assign the value to both fields */ | |
3562 | nl = (struct rlimit) { | |
3563 | .rlim_cur = x, | |
3564 | .rlim_max = x, | |
3565 | }; | |
3566 | ||
3567 | r = rlimit_format(&nl, &f); | |
3568 | if (r < 0) | |
3569 | return r; | |
3570 | ||
3571 | if (c->rlimit[ri]) | |
3572 | *c->rlimit[ri] = nl; | |
3573 | else { | |
3574 | c->rlimit[ri] = newdup(struct rlimit, &nl, 1); | |
3575 | if (!c->rlimit[ri]) | |
3576 | return -ENOMEM; | |
3577 | } | |
3578 | ||
3579 | unit_write_settingf(u, flags, name, "%s=%s", name, f); | |
3580 | } | |
3581 | ||
3582 | return 1; | |
d584f638 LP |
3583 | } |
3584 | ||
b3d13314 LB |
3585 | } else if (streq(name, "MountImages")) { |
3586 | _cleanup_free_ char *format_str = NULL; | |
3587 | MountImage *mount_images = NULL; | |
3588 | size_t n_mount_images = 0; | |
3589 | char *source, *destination; | |
3590 | int permissive; | |
3591 | ||
427353f6 | 3592 | r = sd_bus_message_enter_container(message, 'a', "(ssba(ss))"); |
b3d13314 LB |
3593 | if (r < 0) |
3594 | return r; | |
3595 | ||
427353f6 LB |
3596 | for (;;) { |
3597 | _cleanup_(mount_options_free_allp) MountOptions *options = NULL; | |
3598 | _cleanup_free_ char *source_escaped = NULL, *destination_escaped = NULL; | |
b3d13314 LB |
3599 | char *tuple; |
3600 | ||
427353f6 LB |
3601 | r = sd_bus_message_enter_container(message, 'r', "ssba(ss)"); |
3602 | if (r < 0) | |
3603 | return r; | |
3604 | ||
3605 | r = sd_bus_message_read(message, "ssb", &source, &destination, &permissive); | |
3606 | if (r <= 0) | |
3607 | break; | |
3608 | ||
b3d13314 LB |
3609 | if (!path_is_absolute(source)) |
3610 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Source path %s is not absolute.", source); | |
3611 | if (!path_is_normalized(source)) | |
3612 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Source path %s is not normalized.", source); | |
3613 | if (!path_is_absolute(destination)) | |
3614 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Destination path %s is not absolute.", destination); | |
3615 | if (!path_is_normalized(destination)) | |
3616 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Destination path %s is not normalized.", destination); | |
3617 | ||
427353f6 LB |
3618 | /* Need to store them in the unit with the escapes, so that they can be parsed again */ |
3619 | source_escaped = shell_escape(source, ":"); | |
3620 | if (!source_escaped) | |
3621 | return -ENOMEM; | |
3622 | destination_escaped = shell_escape(destination, ":"); | |
3623 | if (!destination_escaped) | |
3624 | return -ENOMEM; | |
3625 | ||
3626 | tuple = strjoin(format_str, | |
3627 | format_str ? " " : "", | |
3628 | permissive ? "-" : "", | |
3629 | source_escaped, | |
3630 | ":", | |
3631 | destination_escaped); | |
b3d13314 LB |
3632 | if (!tuple) |
3633 | return -ENOMEM; | |
3634 | free_and_replace(format_str, tuple); | |
3635 | ||
988172ce | 3636 | r = bus_read_mount_options(message, error, &options, &format_str, ":"); |
427353f6 LB |
3637 | if (r < 0) |
3638 | return r; | |
3639 | ||
3640 | r = sd_bus_message_exit_container(message); | |
3641 | if (r < 0) | |
3642 | return r; | |
3643 | ||
b3d13314 LB |
3644 | r = mount_image_add(&mount_images, &n_mount_images, |
3645 | &(MountImage) { | |
3646 | .source = source, | |
3647 | .destination = destination, | |
427353f6 | 3648 | .mount_options = options, |
b3d13314 | 3649 | .ignore_enoent = permissive, |
93f59701 | 3650 | .type = MOUNT_IMAGE_DISCRETE, |
b3d13314 LB |
3651 | }); |
3652 | if (r < 0) | |
3653 | return r; | |
3654 | } | |
3655 | if (r < 0) | |
3656 | return r; | |
3657 | ||
3658 | r = sd_bus_message_exit_container(message); | |
3659 | if (r < 0) | |
3660 | return r; | |
3661 | ||
3662 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
3663 | if (n_mount_images == 0) { | |
3664 | c->mount_images = mount_image_free_many(c->mount_images, &c->n_mount_images); | |
3665 | ||
3666 | unit_write_settingf(u, flags, name, "%s=", name); | |
3667 | } else { | |
3668 | for (size_t i = 0; i < n_mount_images; ++i) { | |
3669 | r = mount_image_add(&c->mount_images, &c->n_mount_images, &mount_images[i]); | |
3670 | if (r < 0) | |
3671 | return r; | |
3672 | } | |
3673 | ||
3674 | unit_write_settingf(u, flags|UNIT_ESCAPE_C|UNIT_ESCAPE_SPECIFIERS, | |
3675 | name, | |
3676 | "%s=%s", | |
3677 | name, | |
3678 | format_str); | |
3679 | } | |
3680 | } | |
3681 | ||
3682 | mount_images = mount_image_free_many(mount_images, &n_mount_images); | |
3683 | ||
93f59701 LB |
3684 | return 1; |
3685 | } else if (streq(name, "ExtensionImages")) { | |
3686 | _cleanup_free_ char *format_str = NULL; | |
3687 | MountImage *extension_images = NULL; | |
3688 | size_t n_extension_images = 0; | |
3689 | ||
3690 | r = sd_bus_message_enter_container(message, 'a', "(sba(ss))"); | |
3691 | if (r < 0) | |
3692 | return r; | |
3693 | ||
3694 | for (;;) { | |
3695 | _cleanup_(mount_options_free_allp) MountOptions *options = NULL; | |
3696 | _cleanup_free_ char *source_escaped = NULL; | |
3697 | char *source, *tuple; | |
3698 | int permissive; | |
3699 | ||
3700 | r = sd_bus_message_enter_container(message, 'r', "sba(ss)"); | |
3701 | if (r < 0) | |
3702 | return r; | |
3703 | ||
3704 | r = sd_bus_message_read(message, "sb", &source, &permissive); | |
3705 | if (r <= 0) | |
3706 | break; | |
3707 | ||
3708 | if (!path_is_absolute(source)) | |
3709 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Source path %s is not absolute.", source); | |
3710 | if (!path_is_normalized(source)) | |
3711 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Source path %s is not normalized.", source); | |
3712 | ||
3713 | /* Need to store them in the unit with the escapes, so that they can be parsed again */ | |
3714 | source_escaped = shell_escape(source, ":"); | |
3715 | if (!source_escaped) | |
3716 | return -ENOMEM; | |
3717 | ||
3718 | tuple = strjoin(format_str, | |
3719 | format_str ? " " : "", | |
3720 | permissive ? "-" : "", | |
3721 | source_escaped); | |
3722 | if (!tuple) | |
3723 | return -ENOMEM; | |
3724 | free_and_replace(format_str, tuple); | |
3725 | ||
3726 | r = bus_read_mount_options(message, error, &options, &format_str, ":"); | |
3727 | if (r < 0) | |
3728 | return r; | |
3729 | ||
3730 | r = sd_bus_message_exit_container(message); | |
3731 | if (r < 0) | |
3732 | return r; | |
3733 | ||
3734 | r = mount_image_add(&extension_images, &n_extension_images, | |
3735 | &(MountImage) { | |
3736 | .source = source, | |
3737 | .mount_options = options, | |
3738 | .ignore_enoent = permissive, | |
3739 | .type = MOUNT_IMAGE_EXTENSION, | |
3740 | }); | |
3741 | if (r < 0) | |
3742 | return r; | |
3743 | } | |
3744 | if (r < 0) | |
3745 | return r; | |
3746 | ||
3747 | r = sd_bus_message_exit_container(message); | |
3748 | if (r < 0) | |
3749 | return r; | |
3750 | ||
3751 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
3752 | if (n_extension_images == 0) { | |
3753 | c->extension_images = mount_image_free_many(c->extension_images, &c->n_extension_images); | |
3754 | ||
3755 | unit_write_settingf(u, flags, name, "%s=", name); | |
3756 | } else { | |
3757 | for (size_t i = 0; i < n_extension_images; ++i) { | |
3758 | r = mount_image_add(&c->extension_images, &c->n_extension_images, &extension_images[i]); | |
3759 | if (r < 0) | |
3760 | return r; | |
3761 | } | |
3762 | ||
3763 | unit_write_settingf(u, flags|UNIT_ESCAPE_C|UNIT_ESCAPE_SPECIFIERS, | |
3764 | name, | |
3765 | "%s=%s", | |
3766 | name, | |
3767 | format_str); | |
3768 | } | |
3769 | } | |
3770 | ||
3771 | extension_images = mount_image_free_many(extension_images, &n_extension_images); | |
3772 | ||
b3d13314 | 3773 | return 1; |
211a3d87 LB |
3774 | |
3775 | } else if (STR_IN_SET(name, "StateDirectorySymlink", "RuntimeDirectorySymlink", "CacheDirectorySymlink", "LogsDirectorySymlink")) { | |
3776 | char *source, *destination; | |
3777 | ExecDirectory *directory; | |
3778 | uint64_t symlink_flags; /* No flags for now, reserved for future uses. */ | |
3779 | ExecDirectoryType i; | |
3780 | ||
3781 | assert_se((i = exec_directory_type_symlink_from_string(name)) >= 0); | |
3782 | directory = c->directories + i; | |
3783 | ||
3784 | r = sd_bus_message_enter_container(message, 'a', "(sst)"); | |
3785 | if (r < 0) | |
3786 | return r; | |
3787 | ||
3788 | while ((r = sd_bus_message_read(message, "(sst)", &source, &destination, &symlink_flags)) > 0) { | |
3789 | if (!path_is_valid(source)) | |
3790 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Source path %s is not valid.", source); | |
3791 | if (path_is_absolute(source)) | |
3792 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Source path %s is absolute.", source); | |
3793 | if (!path_is_normalized(source)) | |
3794 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Source path %s is not normalized.", source); | |
3795 | if (!path_is_valid(destination)) | |
3796 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Destination path %s is not valid.", destination); | |
3797 | if (path_is_absolute(destination)) | |
3798 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Destination path %s is absolute.", destination); | |
3799 | if (!path_is_normalized(destination)) | |
3800 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Destination path %s is not normalized.", destination); | |
3801 | if (symlink_flags != 0) | |
3802 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Flags must be zero."); | |
3803 | ||
3804 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
3805 | _cleanup_free_ char *destination_escaped = NULL, *source_escaped = NULL; | |
3806 | ExecDirectoryItem *item = NULL; | |
3807 | ||
3808 | /* Adding new directories is supported from both *DirectorySymlink methods and the | |
3809 | * older ones, so try to find an existing configuration first and create it if it's | |
3810 | * not there yet. */ | |
3811 | for (size_t j = 0; j < directory->n_items; ++j) | |
3812 | if (path_equal(source, directory->items[j].path)) { | |
3813 | item = &directory->items[j]; | |
3814 | break; | |
3815 | } | |
3816 | ||
3817 | if (item) | |
3818 | r = strv_extend(&item->symlinks, destination); | |
3819 | else | |
3820 | r = exec_directory_add(&directory->items, &directory->n_items, source, STRV_MAKE(destination)); | |
3821 | if (r < 0) | |
3822 | return r; | |
3823 | ||
3824 | /* Need to store them in the unit with the escapes, so that they can be parsed again */ | |
3825 | source_escaped = xescape(source, ":"); | |
3826 | destination_escaped = xescape(destination, ":"); | |
3827 | if (!source_escaped || !destination_escaped) | |
3828 | return -ENOMEM; | |
3829 | ||
3830 | unit_write_settingf( | |
3831 | u, flags|UNIT_ESCAPE_SPECIFIERS, exec_directory_type_to_string(i), | |
3832 | "%s=%s:%s", | |
3833 | exec_directory_type_to_string(i), | |
3834 | source_escaped, | |
3835 | destination_escaped); | |
3836 | } | |
3837 | } | |
3838 | if (r < 0) | |
3839 | return r; | |
3840 | ||
3841 | r = sd_bus_message_exit_container(message); | |
3842 | if (r < 0) | |
3843 | return r; | |
3844 | ||
3845 | return 1; | |
3846 | ||
c7040b5d LP |
3847 | } |
3848 | ||
3849 | return 0; | |
3850 | } |