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