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