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