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