]>
Commit | Line | Data |
---|---|---|
4139c1b2 LP |
1 | /*** |
2 | This file is part of systemd. | |
3 | ||
4 | Copyright 2010 Lennart Poettering | |
5 | ||
6 | systemd is free software; you can redistribute it and/or modify it | |
5430f7f2 LP |
7 | under the terms of the GNU Lesser General Public License as published by |
8 | the Free Software Foundation; either version 2.1 of the License, or | |
4139c1b2 LP |
9 | (at your option) any later version. |
10 | ||
11 | systemd is distributed in the hope that it will be useful, but | |
12 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
5430f7f2 | 14 | Lesser General Public License for more details. |
4139c1b2 | 15 | |
5430f7f2 | 16 | You should have received a copy of the GNU Lesser General Public License |
4139c1b2 LP |
17 | along with systemd; If not, see <http://www.gnu.org/licenses/>. |
18 | ***/ | |
19 | ||
82c121a4 | 20 | #include <sys/prctl.h> |
4139c1b2 | 21 | |
57183d11 LP |
22 | #ifdef HAVE_SECCOMP |
23 | #include <seccomp.h> | |
24 | #endif | |
25 | ||
3ffd4af2 | 26 | #include "af-list.h" |
b5efdb8a | 27 | #include "alloc-util.h" |
718db961 | 28 | #include "bus-util.h" |
430f0182 | 29 | #include "capability-util.h" |
3ffd4af2 | 30 | #include "dbus-execute.h" |
c7040b5d | 31 | #include "env-util.h" |
3ffd4af2 LP |
32 | #include "execute.h" |
33 | #include "fd-util.h" | |
34 | #include "fileio.h" | |
35 | #include "ioprio.h" | |
36 | #include "missing.h" | |
83555251 | 37 | #include "mount-util.h" |
417116f2 | 38 | #include "namespace.h" |
6bedfcbb | 39 | #include "parse-util.h" |
9b15b784 | 40 | #include "path-util.h" |
7b3e062c | 41 | #include "process-util.h" |
78f22b97 | 42 | #include "rlimit-util.h" |
57183d11 LP |
43 | #ifdef HAVE_SECCOMP |
44 | #include "seccomp-util.h" | |
45 | #endif | |
6bedfcbb | 46 | #include "strv.h" |
7ccbd1ae | 47 | #include "syslog-util.h" |
6f3e7985 | 48 | #include "user-util.h" |
6bedfcbb | 49 | #include "utf8.h" |
57183d11 | 50 | |
718db961 | 51 | BUS_DEFINE_PROPERTY_GET_ENUM(bus_property_get_exec_output, exec_output, ExecOutput); |
82c121a4 | 52 | |
718db961 | 53 | static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_input, exec_input, ExecInput); |
8c7be95e | 54 | |
023a4f67 LP |
55 | static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_utmp_mode, exec_utmp_mode, ExecUtmpMode); |
56 | ||
1b8689f9 LP |
57 | static BUS_DEFINE_PROPERTY_GET_ENUM(bus_property_get_protect_home, protect_home, ProtectHome); |
58 | static BUS_DEFINE_PROPERTY_GET_ENUM(bus_property_get_protect_system, protect_system, ProtectSystem); | |
417116f2 | 59 | |
718db961 LP |
60 | static int property_get_environment_files( |
61 | sd_bus *bus, | |
62 | const char *path, | |
63 | const char *interface, | |
64 | const char *property, | |
65 | sd_bus_message *reply, | |
ebcf1f97 LP |
66 | void *userdata, |
67 | sd_bus_error *error) { | |
8c7be95e | 68 | |
718db961 LP |
69 | ExecContext *c = userdata; |
70 | char **j; | |
71 | int r; | |
8c7be95e | 72 | |
718db961 LP |
73 | assert(bus); |
74 | assert(reply); | |
75 | assert(c); | |
76 | ||
77 | r = sd_bus_message_open_container(reply, 'a', "(sb)"); | |
78 | if (r < 0) | |
79 | return r; | |
8c7be95e | 80 | |
718db961 LP |
81 | STRV_FOREACH(j, c->environment_files) { |
82 | const char *fn = *j; | |
8c7be95e | 83 | |
718db961 LP |
84 | r = sd_bus_message_append(reply, "(sb)", fn[0] == '-' ? fn + 1 : fn, fn[0] == '-'); |
85 | if (r < 0) | |
86 | return r; | |
8c7be95e LP |
87 | } |
88 | ||
718db961 LP |
89 | return sd_bus_message_close_container(reply); |
90 | } | |
91 | ||
718db961 LP |
92 | static int property_get_oom_score_adjust( |
93 | sd_bus *bus, | |
94 | const char *path, | |
95 | const char *interface, | |
96 | const char *property, | |
97 | sd_bus_message *reply, | |
ebcf1f97 LP |
98 | void *userdata, |
99 | sd_bus_error *error) { | |
718db961 LP |
100 | |
101 | ||
102 | ExecContext *c = userdata; | |
82c121a4 LP |
103 | int32_t n; |
104 | ||
718db961 LP |
105 | assert(bus); |
106 | assert(reply); | |
82c121a4 LP |
107 | assert(c); |
108 | ||
dd6c17b1 LP |
109 | if (c->oom_score_adjust_set) |
110 | n = c->oom_score_adjust; | |
82c121a4 | 111 | else { |
68eda4bd | 112 | _cleanup_free_ char *t = NULL; |
82c121a4 LP |
113 | |
114 | n = 0; | |
718db961 | 115 | if (read_one_line_file("/proc/self/oom_score_adj", &t) >= 0) |
e4e73a63 | 116 | safe_atoi32(t, &n); |
82c121a4 LP |
117 | } |
118 | ||
718db961 | 119 | return sd_bus_message_append(reply, "i", n); |
82c121a4 LP |
120 | } |
121 | ||
718db961 LP |
122 | static int property_get_nice( |
123 | sd_bus *bus, | |
124 | const char *path, | |
125 | const char *interface, | |
126 | const char *property, | |
127 | sd_bus_message *reply, | |
ebcf1f97 LP |
128 | void *userdata, |
129 | sd_bus_error *error) { | |
718db961 LP |
130 | |
131 | ||
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_ioprio( |
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 | ||
161 | ExecContext *c = userdata; | |
82c121a4 LP |
162 | int32_t n; |
163 | ||
718db961 LP |
164 | assert(bus); |
165 | assert(reply); | |
82c121a4 LP |
166 | assert(c); |
167 | ||
168 | if (c->ioprio_set) | |
169 | n = c->ioprio; | |
718db961 | 170 | else { |
82c121a4 | 171 | n = ioprio_get(IOPRIO_WHO_PROCESS, 0); |
718db961 LP |
172 | if (n < 0) |
173 | n = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 4); | |
174 | } | |
82c121a4 | 175 | |
718db961 | 176 | return sd_bus_message_append(reply, "i", n); |
82c121a4 LP |
177 | } |
178 | ||
718db961 LP |
179 | static int property_get_cpu_sched_policy( |
180 | sd_bus *bus, | |
181 | const char *path, | |
182 | const char *interface, | |
183 | const char *property, | |
184 | sd_bus_message *reply, | |
ebcf1f97 LP |
185 | void *userdata, |
186 | sd_bus_error *error) { | |
718db961 LP |
187 | |
188 | ExecContext *c = userdata; | |
82c121a4 LP |
189 | int32_t n; |
190 | ||
718db961 LP |
191 | assert(bus); |
192 | assert(reply); | |
82c121a4 LP |
193 | assert(c); |
194 | ||
195 | if (c->cpu_sched_set) | |
196 | n = c->cpu_sched_policy; | |
718db961 | 197 | else { |
82c121a4 | 198 | n = sched_getscheduler(0); |
718db961 LP |
199 | if (n < 0) |
200 | n = SCHED_OTHER; | |
201 | } | |
82c121a4 | 202 | |
718db961 | 203 | return sd_bus_message_append(reply, "i", n); |
82c121a4 LP |
204 | } |
205 | ||
718db961 LP |
206 | static int property_get_cpu_sched_priority( |
207 | sd_bus *bus, | |
208 | const char *path, | |
209 | const char *interface, | |
210 | const char *property, | |
211 | sd_bus_message *reply, | |
ebcf1f97 LP |
212 | void *userdata, |
213 | sd_bus_error *error) { | |
718db961 LP |
214 | |
215 | ExecContext *c = userdata; | |
82c121a4 LP |
216 | int32_t n; |
217 | ||
718db961 LP |
218 | assert(bus); |
219 | assert(reply); | |
82c121a4 LP |
220 | assert(c); |
221 | ||
222 | if (c->cpu_sched_set) | |
223 | n = c->cpu_sched_priority; | |
224 | else { | |
b92bea5d | 225 | struct sched_param p = {}; |
82c121a4 | 226 | |
82c121a4 LP |
227 | if (sched_getparam(0, &p) >= 0) |
228 | n = p.sched_priority; | |
e62d8c39 ZJS |
229 | else |
230 | n = 0; | |
82c121a4 LP |
231 | } |
232 | ||
718db961 | 233 | return sd_bus_message_append(reply, "i", n); |
82c121a4 LP |
234 | } |
235 | ||
718db961 LP |
236 | static int property_get_cpu_affinity( |
237 | sd_bus *bus, | |
238 | const char *path, | |
239 | const char *interface, | |
240 | const char *property, | |
241 | sd_bus_message *reply, | |
ebcf1f97 LP |
242 | void *userdata, |
243 | sd_bus_error *error) { | |
82c121a4 | 244 | |
718db961 | 245 | ExecContext *c = userdata; |
82c121a4 | 246 | |
718db961 LP |
247 | assert(bus); |
248 | assert(reply); | |
249 | assert(c); | |
82c121a4 LP |
250 | |
251 | if (c->cpuset) | |
718db961 | 252 | return sd_bus_message_append_array(reply, 'y', c->cpuset, CPU_ALLOC_SIZE(c->cpuset_ncpus)); |
82c121a4 | 253 | else |
718db961 | 254 | return sd_bus_message_append_array(reply, 'y', NULL, 0); |
82c121a4 LP |
255 | } |
256 | ||
718db961 LP |
257 | static int property_get_timer_slack_nsec( |
258 | sd_bus *bus, | |
259 | const char *path, | |
260 | const char *interface, | |
261 | const char *property, | |
262 | sd_bus_message *reply, | |
ebcf1f97 LP |
263 | void *userdata, |
264 | sd_bus_error *error) { | |
718db961 LP |
265 | |
266 | ExecContext *c = userdata; | |
82c121a4 LP |
267 | uint64_t u; |
268 | ||
718db961 LP |
269 | assert(bus); |
270 | assert(reply); | |
82c121a4 LP |
271 | assert(c); |
272 | ||
3a43da28 | 273 | if (c->timer_slack_nsec != NSEC_INFINITY) |
03fae018 | 274 | u = (uint64_t) c->timer_slack_nsec; |
82c121a4 LP |
275 | else |
276 | u = (uint64_t) prctl(PR_GET_TIMERSLACK); | |
277 | ||
718db961 | 278 | return sd_bus_message_append(reply, "t", u); |
82c121a4 LP |
279 | } |
280 | ||
718db961 LP |
281 | static int property_get_capability_bounding_set( |
282 | sd_bus *bus, | |
283 | const char *path, | |
284 | const char *interface, | |
285 | const char *property, | |
286 | sd_bus_message *reply, | |
ebcf1f97 LP |
287 | void *userdata, |
288 | sd_bus_error *error) { | |
260abb78 | 289 | |
718db961 LP |
290 | ExecContext *c = userdata; |
291 | ||
292 | assert(bus); | |
293 | assert(reply); | |
260abb78 LP |
294 | assert(c); |
295 | ||
a103496c | 296 | return sd_bus_message_append(reply, "t", c->capability_bounding_set); |
260abb78 LP |
297 | } |
298 | ||
755d4b67 IP |
299 | static int property_get_ambient_capabilities( |
300 | sd_bus *bus, | |
301 | const char *path, | |
302 | const char *interface, | |
303 | const char *property, | |
304 | sd_bus_message *reply, | |
305 | void *userdata, | |
306 | sd_bus_error *error) { | |
307 | ||
308 | ExecContext *c = userdata; | |
309 | ||
310 | assert(bus); | |
311 | assert(reply); | |
312 | assert(c); | |
313 | ||
314 | return sd_bus_message_append(reply, "t", c->capability_ambient_set); | |
315 | } | |
316 | ||
479050b3 | 317 | static int property_get_empty_string( |
718db961 LP |
318 | sd_bus *bus, |
319 | const char *path, | |
320 | const char *interface, | |
321 | const char *property, | |
322 | sd_bus_message *reply, | |
ebcf1f97 LP |
323 | void *userdata, |
324 | sd_bus_error *error) { | |
718db961 | 325 | |
718db961 LP |
326 | assert(bus); |
327 | assert(reply); | |
82c121a4 | 328 | |
479050b3 | 329 | return sd_bus_message_append(reply, "s", ""); |
82c121a4 LP |
330 | } |
331 | ||
718db961 LP |
332 | static int property_get_syscall_filter( |
333 | sd_bus *bus, | |
334 | const char *path, | |
335 | const char *interface, | |
336 | const char *property, | |
337 | sd_bus_message *reply, | |
ebcf1f97 LP |
338 | void *userdata, |
339 | sd_bus_error *error) { | |
82c121a4 | 340 | |
17df7223 LP |
341 | ExecContext *c = userdata; |
342 | _cleanup_strv_free_ char **l = NULL; | |
57183d11 LP |
343 | int r; |
344 | ||
351a19b1 | 345 | #ifdef HAVE_SECCOMP |
17df7223 LP |
346 | Iterator i; |
347 | void *id; | |
351a19b1 | 348 | #endif |
17df7223 LP |
349 | |
350 | assert(bus); | |
351 | assert(reply); | |
352 | assert(c); | |
353 | ||
57183d11 LP |
354 | r = sd_bus_message_open_container(reply, 'r', "bas"); |
355 | if (r < 0) | |
356 | return r; | |
357 | ||
358 | r = sd_bus_message_append(reply, "b", c->syscall_whitelist); | |
359 | if (r < 0) | |
360 | return r; | |
361 | ||
351a19b1 | 362 | #ifdef HAVE_SECCOMP |
17df7223 LP |
363 | SET_FOREACH(id, c->syscall_filter, i) { |
364 | char *name; | |
365 | ||
366 | name = seccomp_syscall_resolve_num_arch(SCMP_ARCH_NATIVE, PTR_TO_INT(id) - 1); | |
367 | if (!name) | |
368 | continue; | |
369 | ||
6e18964d ZJS |
370 | r = strv_consume(&l, name); |
371 | if (r < 0) | |
372 | return r; | |
17df7223 | 373 | } |
351a19b1 | 374 | #endif |
17df7223 LP |
375 | |
376 | strv_sort(l); | |
377 | ||
57183d11 LP |
378 | r = sd_bus_message_append_strv(reply, l); |
379 | if (r < 0) | |
380 | return r; | |
17df7223 | 381 | |
57183d11 LP |
382 | return sd_bus_message_close_container(reply); |
383 | } | |
17df7223 | 384 | |
57183d11 LP |
385 | static int property_get_syscall_archs( |
386 | sd_bus *bus, | |
387 | const char *path, | |
388 | const char *interface, | |
389 | const char *property, | |
390 | sd_bus_message *reply, | |
391 | void *userdata, | |
392 | sd_bus_error *error) { | |
393 | ||
394 | ExecContext *c = userdata; | |
395 | _cleanup_strv_free_ char **l = NULL; | |
396 | int r; | |
397 | ||
398 | #ifdef HAVE_SECCOMP | |
399 | Iterator i; | |
400 | void *id; | |
401 | #endif | |
402 | ||
403 | assert(bus); | |
404 | assert(reply); | |
405 | assert(c); | |
17df7223 | 406 | |
57183d11 LP |
407 | #ifdef HAVE_SECCOMP |
408 | SET_FOREACH(id, c->syscall_archs, i) { | |
409 | const char *name; | |
410 | ||
411 | name = seccomp_arch_to_string(PTR_TO_UINT32(id) - 1); | |
412 | if (!name) | |
413 | continue; | |
414 | ||
415 | r = strv_extend(&l, name); | |
416 | if (r < 0) | |
417 | return -ENOMEM; | |
17df7223 | 418 | } |
57183d11 LP |
419 | #endif |
420 | ||
421 | strv_sort(l); | |
422 | ||
423 | r = sd_bus_message_append_strv(reply, l); | |
424 | if (r < 0) | |
425 | return r; | |
17df7223 | 426 | |
57183d11 | 427 | return 0; |
17df7223 LP |
428 | } |
429 | ||
430 | static int property_get_syscall_errno( | |
431 | sd_bus *bus, | |
432 | const char *path, | |
433 | const char *interface, | |
434 | const char *property, | |
435 | sd_bus_message *reply, | |
436 | void *userdata, | |
437 | sd_bus_error *error) { | |
438 | ||
718db961 | 439 | ExecContext *c = userdata; |
82c121a4 | 440 | |
718db961 LP |
441 | assert(bus); |
442 | assert(reply); | |
443 | assert(c); | |
82c121a4 | 444 | |
17df7223 | 445 | return sd_bus_message_append(reply, "i", (int32_t) c->syscall_errno); |
718db961 | 446 | } |
82c121a4 | 447 | |
5f8640fb LP |
448 | static int property_get_selinux_context( |
449 | sd_bus *bus, | |
450 | const char *path, | |
451 | const char *interface, | |
452 | const char *property, | |
453 | sd_bus_message *reply, | |
454 | void *userdata, | |
455 | sd_bus_error *error) { | |
456 | ||
457 | ExecContext *c = userdata; | |
458 | ||
459 | assert(bus); | |
460 | assert(reply); | |
461 | assert(c); | |
462 | ||
463 | return sd_bus_message_append(reply, "(bs)", c->selinux_context_ignore, c->selinux_context); | |
464 | } | |
465 | ||
eef65bf3 MS |
466 | static int property_get_apparmor_profile( |
467 | sd_bus *bus, | |
468 | const char *path, | |
469 | const char *interface, | |
470 | const char *property, | |
471 | sd_bus_message *reply, | |
472 | void *userdata, | |
473 | sd_bus_error *error) { | |
474 | ||
475 | ExecContext *c = userdata; | |
476 | ||
477 | assert(bus); | |
478 | assert(reply); | |
479 | assert(c); | |
480 | ||
481 | return sd_bus_message_append(reply, "(bs)", c->apparmor_profile_ignore, c->apparmor_profile); | |
482 | } | |
483 | ||
2ca620c4 WC |
484 | static int property_get_smack_process_label( |
485 | sd_bus *bus, | |
486 | const char *path, | |
487 | const char *interface, | |
488 | const char *property, | |
489 | sd_bus_message *reply, | |
490 | void *userdata, | |
491 | sd_bus_error *error) { | |
492 | ||
493 | ExecContext *c = userdata; | |
494 | ||
495 | assert(bus); | |
496 | assert(reply); | |
497 | assert(c); | |
498 | ||
499 | return sd_bus_message_append(reply, "(bs)", c->smack_process_label_ignore, c->smack_process_label); | |
500 | } | |
501 | ||
ac45f971 LP |
502 | static int property_get_personality( |
503 | sd_bus *bus, | |
504 | const char *path, | |
505 | const char *interface, | |
506 | const char *property, | |
507 | sd_bus_message *reply, | |
508 | void *userdata, | |
509 | sd_bus_error *error) { | |
510 | ||
511 | ExecContext *c = userdata; | |
512 | ||
513 | assert(bus); | |
514 | assert(reply); | |
515 | assert(c); | |
516 | ||
517 | return sd_bus_message_append(reply, "s", personality_to_string(c->personality)); | |
518 | } | |
519 | ||
4298d0b5 LP |
520 | static int property_get_address_families( |
521 | sd_bus *bus, | |
522 | const char *path, | |
523 | const char *interface, | |
524 | const char *property, | |
525 | sd_bus_message *reply, | |
526 | void *userdata, | |
527 | sd_bus_error *error) { | |
528 | ||
529 | ExecContext *c = userdata; | |
530 | _cleanup_strv_free_ char **l = NULL; | |
531 | Iterator i; | |
532 | void *af; | |
533 | int r; | |
534 | ||
535 | assert(bus); | |
536 | assert(reply); | |
537 | assert(c); | |
538 | ||
539 | r = sd_bus_message_open_container(reply, 'r', "bas"); | |
540 | if (r < 0) | |
541 | return r; | |
542 | ||
543 | r = sd_bus_message_append(reply, "b", c->address_families_whitelist); | |
544 | if (r < 0) | |
545 | return r; | |
546 | ||
547 | SET_FOREACH(af, c->address_families, i) { | |
548 | const char *name; | |
549 | ||
550 | name = af_to_name(PTR_TO_INT(af)); | |
551 | if (!name) | |
552 | continue; | |
553 | ||
554 | r = strv_extend(&l, name); | |
555 | if (r < 0) | |
556 | return -ENOMEM; | |
557 | } | |
558 | ||
559 | strv_sort(l); | |
560 | ||
561 | r = sd_bus_message_append_strv(reply, l); | |
562 | if (r < 0) | |
563 | return r; | |
564 | ||
565 | return sd_bus_message_close_container(reply); | |
566 | } | |
567 | ||
5f5d8eab LP |
568 | static int property_get_working_directory( |
569 | sd_bus *bus, | |
570 | const char *path, | |
571 | const char *interface, | |
572 | const char *property, | |
573 | sd_bus_message *reply, | |
574 | void *userdata, | |
575 | sd_bus_error *error) { | |
576 | ||
577 | ExecContext *c = userdata; | |
578 | const char *wd; | |
579 | ||
580 | assert(bus); | |
581 | assert(reply); | |
582 | assert(c); | |
583 | ||
584 | if (c->working_directory_home) | |
585 | wd = "~"; | |
586 | else | |
587 | wd = c->working_directory; | |
588 | ||
589 | if (c->working_directory_missing_ok) | |
590 | wd = strjoina("!", wd); | |
591 | ||
592 | return sd_bus_message_append(reply, "s", wd); | |
593 | } | |
594 | ||
06f2ccf9 EV |
595 | static int property_get_syslog_level( |
596 | sd_bus *bus, | |
597 | const char *path, | |
598 | const char *interface, | |
599 | const char *property, | |
600 | sd_bus_message *reply, | |
601 | void *userdata, | |
602 | sd_bus_error *error) { | |
603 | ||
604 | ExecContext *c = userdata; | |
605 | ||
606 | assert(bus); | |
607 | assert(reply); | |
608 | assert(c); | |
609 | ||
610 | return sd_bus_message_append(reply, "i", LOG_PRI(c->syslog_priority)); | |
611 | } | |
612 | ||
613 | static int property_get_syslog_facility( | |
614 | sd_bus *bus, | |
615 | const char *path, | |
616 | const char *interface, | |
617 | const char *property, | |
618 | sd_bus_message *reply, | |
619 | void *userdata, | |
620 | sd_bus_error *error) { | |
621 | ||
622 | ExecContext *c = userdata; | |
623 | ||
624 | assert(bus); | |
625 | assert(reply); | |
626 | assert(c); | |
627 | ||
628 | return sd_bus_message_append(reply, "i", LOG_FAC(c->syslog_priority)); | |
629 | } | |
630 | ||
52c239d7 LB |
631 | static int property_get_input_fdname( |
632 | sd_bus *bus, | |
633 | const char *path, | |
634 | const char *interface, | |
635 | const char *property, | |
636 | sd_bus_message *reply, | |
637 | void *userdata, | |
638 | sd_bus_error *error) { | |
639 | ||
640 | ExecContext *c = userdata; | |
641 | const char *name; | |
642 | ||
643 | assert(bus); | |
644 | assert(c); | |
645 | assert(property); | |
646 | assert(reply); | |
647 | ||
648 | name = exec_context_fdname(c, STDIN_FILENO); | |
649 | ||
650 | return sd_bus_message_append(reply, "s", name); | |
651 | } | |
652 | ||
653 | static int property_get_output_fdname( | |
654 | sd_bus *bus, | |
655 | const char *path, | |
656 | const char *interface, | |
657 | const char *property, | |
658 | sd_bus_message *reply, | |
659 | void *userdata, | |
660 | sd_bus_error *error) { | |
661 | ||
662 | ExecContext *c = userdata; | |
663 | const char *name = NULL; | |
664 | ||
665 | assert(bus); | |
666 | assert(c); | |
667 | assert(property); | |
668 | assert(reply); | |
669 | ||
670 | if (c->std_output == EXEC_OUTPUT_NAMED_FD && streq(property, "StandardOutputFileDescriptorName")) | |
671 | name = exec_context_fdname(c, STDOUT_FILENO); | |
672 | else if (c->std_error == EXEC_OUTPUT_NAMED_FD && streq(property, "StandardErrorFileDescriptorName")) | |
673 | name = exec_context_fdname(c, STDERR_FILENO); | |
674 | ||
675 | return sd_bus_message_append(reply, "s", name); | |
676 | } | |
677 | ||
d2d6c096 LP |
678 | static int property_get_bind_paths( |
679 | sd_bus *bus, | |
680 | const char *path, | |
681 | const char *interface, | |
682 | const char *property, | |
683 | sd_bus_message *reply, | |
684 | void *userdata, | |
685 | sd_bus_error *error) { | |
686 | ||
687 | ExecContext *c = userdata; | |
688 | unsigned i; | |
689 | bool ro; | |
690 | int r; | |
691 | ||
692 | assert(bus); | |
693 | assert(c); | |
694 | assert(property); | |
695 | assert(reply); | |
696 | ||
697 | ro = !!strstr(property, "ReadOnly"); | |
698 | ||
699 | r = sd_bus_message_open_container(reply, 'a', "(ssbt)"); | |
700 | if (r < 0) | |
701 | return r; | |
702 | ||
703 | for (i = 0; i < c->n_bind_mounts; i++) { | |
704 | ||
705 | if (ro != c->bind_mounts[i].read_only) | |
706 | continue; | |
707 | ||
708 | r = sd_bus_message_append( | |
709 | reply, "(ssbt)", | |
710 | c->bind_mounts[i].source, | |
711 | c->bind_mounts[i].destination, | |
712 | c->bind_mounts[i].ignore_enoent, | |
713 | c->bind_mounts[i].recursive ? MS_REC : 0); | |
714 | if (r < 0) | |
715 | return r; | |
716 | } | |
717 | ||
718 | return sd_bus_message_close_container(reply); | |
719 | } | |
720 | ||
718db961 LP |
721 | const sd_bus_vtable bus_exec_vtable[] = { |
722 | SD_BUS_VTABLE_START(0), | |
556089dc LP |
723 | SD_BUS_PROPERTY("Environment", "as", NULL, offsetof(ExecContext, environment), SD_BUS_VTABLE_PROPERTY_CONST), |
724 | SD_BUS_PROPERTY("EnvironmentFiles", "a(sb)", property_get_environment_files, 0, SD_BUS_VTABLE_PROPERTY_CONST), | |
b4c14404 | 725 | SD_BUS_PROPERTY("PassEnvironment", "as", NULL, offsetof(ExecContext, pass_environment), SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc | 726 | SD_BUS_PROPERTY("UMask", "u", bus_property_get_mode, offsetof(ExecContext, umask), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 727 | SD_BUS_PROPERTY("LimitCPU", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_CPU]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 728 | SD_BUS_PROPERTY("LimitCPUSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_CPU]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 729 | SD_BUS_PROPERTY("LimitFSIZE", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_FSIZE]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 730 | SD_BUS_PROPERTY("LimitFSIZESoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_FSIZE]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 731 | SD_BUS_PROPERTY("LimitDATA", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_DATA]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 732 | SD_BUS_PROPERTY("LimitDATASoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_DATA]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 733 | SD_BUS_PROPERTY("LimitSTACK", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_STACK]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 734 | SD_BUS_PROPERTY("LimitSTACKSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_STACK]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 735 | SD_BUS_PROPERTY("LimitCORE", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_CORE]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 736 | SD_BUS_PROPERTY("LimitCORESoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_CORE]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 737 | SD_BUS_PROPERTY("LimitRSS", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RSS]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 738 | SD_BUS_PROPERTY("LimitRSSSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RSS]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 739 | SD_BUS_PROPERTY("LimitNOFILE", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NOFILE]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 740 | SD_BUS_PROPERTY("LimitNOFILESoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NOFILE]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 741 | SD_BUS_PROPERTY("LimitAS", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_AS]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 742 | SD_BUS_PROPERTY("LimitASSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_AS]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 743 | SD_BUS_PROPERTY("LimitNPROC", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NPROC]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 744 | SD_BUS_PROPERTY("LimitNPROCSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NPROC]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 745 | SD_BUS_PROPERTY("LimitMEMLOCK", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_MEMLOCK]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 746 | SD_BUS_PROPERTY("LimitMEMLOCKSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_MEMLOCK]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 747 | SD_BUS_PROPERTY("LimitLOCKS", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_LOCKS]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 748 | SD_BUS_PROPERTY("LimitLOCKSSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_LOCKS]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 749 | SD_BUS_PROPERTY("LimitSIGPENDING", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_SIGPENDING]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 750 | SD_BUS_PROPERTY("LimitSIGPENDINGSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_SIGPENDING]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 751 | SD_BUS_PROPERTY("LimitMSGQUEUE", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_MSGQUEUE]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 752 | SD_BUS_PROPERTY("LimitMSGQUEUESoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_MSGQUEUE]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 753 | SD_BUS_PROPERTY("LimitNICE", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NICE]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 754 | SD_BUS_PROPERTY("LimitNICESoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NICE]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 755 | SD_BUS_PROPERTY("LimitRTPRIO", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RTPRIO]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 756 | SD_BUS_PROPERTY("LimitRTPRIOSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RTPRIO]), SD_BUS_VTABLE_PROPERTY_CONST), |
c9d031c3 | 757 | SD_BUS_PROPERTY("LimitRTTIME", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RTTIME]), SD_BUS_VTABLE_PROPERTY_CONST), |
147f6858 | 758 | SD_BUS_PROPERTY("LimitRTTIMESoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RTTIME]), SD_BUS_VTABLE_PROPERTY_CONST), |
5f5d8eab | 759 | SD_BUS_PROPERTY("WorkingDirectory", "s", property_get_working_directory, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc LP |
760 | SD_BUS_PROPERTY("RootDirectory", "s", NULL, offsetof(ExecContext, root_directory), SD_BUS_VTABLE_PROPERTY_CONST), |
761 | SD_BUS_PROPERTY("OOMScoreAdjust", "i", property_get_oom_score_adjust, 0, SD_BUS_VTABLE_PROPERTY_CONST), | |
762 | SD_BUS_PROPERTY("Nice", "i", property_get_nice, 0, SD_BUS_VTABLE_PROPERTY_CONST), | |
763 | SD_BUS_PROPERTY("IOScheduling", "i", property_get_ioprio, 0, SD_BUS_VTABLE_PROPERTY_CONST), | |
764 | SD_BUS_PROPERTY("CPUSchedulingPolicy", "i", property_get_cpu_sched_policy, 0, SD_BUS_VTABLE_PROPERTY_CONST), | |
765 | SD_BUS_PROPERTY("CPUSchedulingPriority", "i", property_get_cpu_sched_priority, 0, SD_BUS_VTABLE_PROPERTY_CONST), | |
766 | SD_BUS_PROPERTY("CPUAffinity", "ay", property_get_cpu_affinity, 0, SD_BUS_VTABLE_PROPERTY_CONST), | |
767 | SD_BUS_PROPERTY("TimerSlackNSec", "t", property_get_timer_slack_nsec, 0, SD_BUS_VTABLE_PROPERTY_CONST), | |
768 | SD_BUS_PROPERTY("CPUSchedulingResetOnFork", "b", bus_property_get_bool, offsetof(ExecContext, cpu_sched_reset_on_fork), SD_BUS_VTABLE_PROPERTY_CONST), | |
769 | SD_BUS_PROPERTY("NonBlocking", "b", bus_property_get_bool, offsetof(ExecContext, non_blocking), SD_BUS_VTABLE_PROPERTY_CONST), | |
770 | SD_BUS_PROPERTY("StandardInput", "s", property_get_exec_input, offsetof(ExecContext, std_input), SD_BUS_VTABLE_PROPERTY_CONST), | |
52c239d7 | 771 | SD_BUS_PROPERTY("StandardInputFileDescriptorName", "s", property_get_input_fdname, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc | 772 | SD_BUS_PROPERTY("StandardOutput", "s", bus_property_get_exec_output, offsetof(ExecContext, std_output), SD_BUS_VTABLE_PROPERTY_CONST), |
52c239d7 | 773 | SD_BUS_PROPERTY("StandardOutputFileDescriptorName", "s", property_get_output_fdname, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc | 774 | SD_BUS_PROPERTY("StandardError", "s", bus_property_get_exec_output, offsetof(ExecContext, std_error), SD_BUS_VTABLE_PROPERTY_CONST), |
52c239d7 | 775 | SD_BUS_PROPERTY("StandardErrorFileDescriptorName", "s", property_get_output_fdname, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc LP |
776 | SD_BUS_PROPERTY("TTYPath", "s", NULL, offsetof(ExecContext, tty_path), SD_BUS_VTABLE_PROPERTY_CONST), |
777 | SD_BUS_PROPERTY("TTYReset", "b", bus_property_get_bool, offsetof(ExecContext, tty_reset), SD_BUS_VTABLE_PROPERTY_CONST), | |
778 | SD_BUS_PROPERTY("TTYVHangup", "b", bus_property_get_bool, offsetof(ExecContext, tty_vhangup), SD_BUS_VTABLE_PROPERTY_CONST), | |
779 | SD_BUS_PROPERTY("TTYVTDisallocate", "b", bus_property_get_bool, offsetof(ExecContext, tty_vt_disallocate), SD_BUS_VTABLE_PROPERTY_CONST), | |
780 | SD_BUS_PROPERTY("SyslogPriority", "i", bus_property_get_int, offsetof(ExecContext, syslog_priority), SD_BUS_VTABLE_PROPERTY_CONST), | |
781 | SD_BUS_PROPERTY("SyslogIdentifier", "s", NULL, offsetof(ExecContext, syslog_identifier), SD_BUS_VTABLE_PROPERTY_CONST), | |
782 | SD_BUS_PROPERTY("SyslogLevelPrefix", "b", bus_property_get_bool, offsetof(ExecContext, syslog_level_prefix), SD_BUS_VTABLE_PROPERTY_CONST), | |
06f2ccf9 EV |
783 | SD_BUS_PROPERTY("SyslogLevel", "i", property_get_syslog_level, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
784 | SD_BUS_PROPERTY("SyslogFacility", "i", property_get_syslog_facility, 0, SD_BUS_VTABLE_PROPERTY_CONST), | |
479050b3 | 785 | SD_BUS_PROPERTY("Capabilities", "s", property_get_empty_string, 0, SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN), |
556089dc LP |
786 | SD_BUS_PROPERTY("SecureBits", "i", bus_property_get_int, offsetof(ExecContext, secure_bits), SD_BUS_VTABLE_PROPERTY_CONST), |
787 | SD_BUS_PROPERTY("CapabilityBoundingSet", "t", property_get_capability_bounding_set, 0, SD_BUS_VTABLE_PROPERTY_CONST), | |
755d4b67 | 788 | SD_BUS_PROPERTY("AmbientCapabilities", "t", property_get_ambient_capabilities, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc LP |
789 | SD_BUS_PROPERTY("User", "s", NULL, offsetof(ExecContext, user), SD_BUS_VTABLE_PROPERTY_CONST), |
790 | SD_BUS_PROPERTY("Group", "s", NULL, offsetof(ExecContext, group), SD_BUS_VTABLE_PROPERTY_CONST), | |
29206d46 | 791 | SD_BUS_PROPERTY("DynamicUser", "b", bus_property_get_bool, offsetof(ExecContext, dynamic_user), SD_BUS_VTABLE_PROPERTY_CONST), |
00d9ef85 | 792 | SD_BUS_PROPERTY("RemoveIPC", "b", bus_property_get_bool, offsetof(ExecContext, remove_ipc), SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc | 793 | SD_BUS_PROPERTY("SupplementaryGroups", "as", NULL, offsetof(ExecContext, supplementary_groups), SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc | 794 | SD_BUS_PROPERTY("PAMName", "s", NULL, offsetof(ExecContext, pam_name), SD_BUS_VTABLE_PROPERTY_CONST), |
d724118e LP |
795 | SD_BUS_PROPERTY("ReadWriteDirectories", "as", NULL, offsetof(ExecContext, read_write_paths), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN), |
796 | SD_BUS_PROPERTY("ReadOnlyDirectories", "as", NULL, offsetof(ExecContext, read_only_paths), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN), | |
797 | SD_BUS_PROPERTY("InaccessibleDirectories", "as", NULL, offsetof(ExecContext, inaccessible_paths), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN), | |
2a624c36 AP |
798 | SD_BUS_PROPERTY("ReadWritePaths", "as", NULL, offsetof(ExecContext, read_write_paths), SD_BUS_VTABLE_PROPERTY_CONST), |
799 | SD_BUS_PROPERTY("ReadOnlyPaths", "as", NULL, offsetof(ExecContext, read_only_paths), SD_BUS_VTABLE_PROPERTY_CONST), | |
800 | SD_BUS_PROPERTY("InaccessiblePaths", "as", NULL, offsetof(ExecContext, inaccessible_paths), SD_BUS_VTABLE_PROPERTY_CONST), | |
556089dc LP |
801 | SD_BUS_PROPERTY("MountFlags", "t", bus_property_get_ulong, offsetof(ExecContext, mount_flags), SD_BUS_VTABLE_PROPERTY_CONST), |
802 | SD_BUS_PROPERTY("PrivateTmp", "b", bus_property_get_bool, offsetof(ExecContext, private_tmp), SD_BUS_VTABLE_PROPERTY_CONST), | |
7f112f50 | 803 | SD_BUS_PROPERTY("PrivateDevices", "b", bus_property_get_bool, offsetof(ExecContext, private_devices), SD_BUS_VTABLE_PROPERTY_CONST), |
59eeb84b | 804 | SD_BUS_PROPERTY("ProtectKernelTunables", "b", bus_property_get_bool, offsetof(ExecContext, protect_kernel_tunables), SD_BUS_VTABLE_PROPERTY_CONST), |
502d704e | 805 | SD_BUS_PROPERTY("ProtectKernelModules", "b", bus_property_get_bool, offsetof(ExecContext, protect_kernel_modules), SD_BUS_VTABLE_PROPERTY_CONST), |
59eeb84b | 806 | SD_BUS_PROPERTY("ProtectControlGroups", "b", bus_property_get_bool, offsetof(ExecContext, protect_control_groups), SD_BUS_VTABLE_PROPERTY_CONST), |
d251207d LP |
807 | SD_BUS_PROPERTY("PrivateNetwork", "b", bus_property_get_bool, offsetof(ExecContext, private_network), SD_BUS_VTABLE_PROPERTY_CONST), |
808 | SD_BUS_PROPERTY("PrivateUsers", "b", bus_property_get_bool, offsetof(ExecContext, private_users), SD_BUS_VTABLE_PROPERTY_CONST), | |
1b8689f9 LP |
809 | SD_BUS_PROPERTY("ProtectHome", "s", bus_property_get_protect_home, offsetof(ExecContext, protect_home), SD_BUS_VTABLE_PROPERTY_CONST), |
810 | SD_BUS_PROPERTY("ProtectSystem", "s", bus_property_get_protect_system, offsetof(ExecContext, protect_system), SD_BUS_VTABLE_PROPERTY_CONST), | |
556089dc LP |
811 | SD_BUS_PROPERTY("SameProcessGroup", "b", bus_property_get_bool, offsetof(ExecContext, same_pgrp), SD_BUS_VTABLE_PROPERTY_CONST), |
812 | SD_BUS_PROPERTY("UtmpIdentifier", "s", NULL, offsetof(ExecContext, utmp_id), SD_BUS_VTABLE_PROPERTY_CONST), | |
023a4f67 | 813 | SD_BUS_PROPERTY("UtmpMode", "s", property_get_exec_utmp_mode, offsetof(ExecContext, utmp_mode), SD_BUS_VTABLE_PROPERTY_CONST), |
5f8640fb | 814 | SD_BUS_PROPERTY("SELinuxContext", "(bs)", property_get_selinux_context, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
eef65bf3 | 815 | SD_BUS_PROPERTY("AppArmorProfile", "(bs)", property_get_apparmor_profile, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
2ca620c4 | 816 | SD_BUS_PROPERTY("SmackProcessLabel", "(bs)", property_get_smack_process_label, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc LP |
817 | SD_BUS_PROPERTY("IgnoreSIGPIPE", "b", bus_property_get_bool, offsetof(ExecContext, ignore_sigpipe), SD_BUS_VTABLE_PROPERTY_CONST), |
818 | SD_BUS_PROPERTY("NoNewPrivileges", "b", bus_property_get_bool, offsetof(ExecContext, no_new_privileges), SD_BUS_VTABLE_PROPERTY_CONST), | |
57183d11 LP |
819 | SD_BUS_PROPERTY("SystemCallFilter", "(bas)", property_get_syscall_filter, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
820 | SD_BUS_PROPERTY("SystemCallArchitectures", "as", property_get_syscall_archs, 0, SD_BUS_VTABLE_PROPERTY_CONST), | |
17df7223 | 821 | SD_BUS_PROPERTY("SystemCallErrorNumber", "i", property_get_syscall_errno, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
ac45f971 | 822 | SD_BUS_PROPERTY("Personality", "s", property_get_personality, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
4298d0b5 | 823 | SD_BUS_PROPERTY("RestrictAddressFamilies", "(bas)", property_get_address_families, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
e66cf1a3 LP |
824 | SD_BUS_PROPERTY("RuntimeDirectoryMode", "u", bus_property_get_mode, offsetof(ExecContext, runtime_directory_mode), SD_BUS_VTABLE_PROPERTY_CONST), |
825 | SD_BUS_PROPERTY("RuntimeDirectory", "as", NULL, offsetof(ExecContext, runtime_directory), SD_BUS_VTABLE_PROPERTY_CONST), | |
f3e43635 | 826 | SD_BUS_PROPERTY("MemoryDenyWriteExecute", "b", bus_property_get_bool, offsetof(ExecContext, memory_deny_write_execute), SD_BUS_VTABLE_PROPERTY_CONST), |
f4170c67 | 827 | SD_BUS_PROPERTY("RestrictRealtime", "b", bus_property_get_bool, offsetof(ExecContext, restrict_realtime), SD_BUS_VTABLE_PROPERTY_CONST), |
6a8c2d59 | 828 | SD_BUS_PROPERTY("RestrictNamespaces", "t", bus_property_get_ulong, offsetof(ExecContext, restrict_namespaces), SD_BUS_VTABLE_PROPERTY_CONST), |
d2d6c096 LP |
829 | SD_BUS_PROPERTY("BindPaths", "a(ssbt)", property_get_bind_paths, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
830 | SD_BUS_PROPERTY("BindReadOnlyPaths", "a(ssbt)", property_get_bind_paths, 0, SD_BUS_VTABLE_PROPERTY_CONST), | |
718db961 LP |
831 | SD_BUS_VTABLE_END |
832 | }; | |
82c121a4 | 833 | |
4d4c80d0 LP |
834 | static int append_exec_command(sd_bus_message *reply, ExecCommand *c) { |
835 | int r; | |
836 | ||
837 | assert(reply); | |
838 | assert(c); | |
839 | ||
840 | if (!c->path) | |
841 | return 0; | |
842 | ||
843 | r = sd_bus_message_open_container(reply, 'r', "sasbttttuii"); | |
844 | if (r < 0) | |
845 | return r; | |
846 | ||
847 | r = sd_bus_message_append(reply, "s", c->path); | |
848 | if (r < 0) | |
849 | return r; | |
850 | ||
851 | r = sd_bus_message_append_strv(reply, c->argv); | |
852 | if (r < 0) | |
853 | return r; | |
854 | ||
855 | r = sd_bus_message_append(reply, "bttttuii", | |
856 | c->ignore, | |
857 | c->exec_status.start_timestamp.realtime, | |
858 | c->exec_status.start_timestamp.monotonic, | |
859 | c->exec_status.exit_timestamp.realtime, | |
860 | c->exec_status.exit_timestamp.monotonic, | |
861 | (uint32_t) c->exec_status.pid, | |
862 | (int32_t) c->exec_status.code, | |
863 | (int32_t) c->exec_status.status); | |
864 | if (r < 0) | |
865 | return r; | |
866 | ||
867 | return sd_bus_message_close_container(reply); | |
868 | } | |
869 | ||
718db961 LP |
870 | int bus_property_get_exec_command( |
871 | sd_bus *bus, | |
872 | const char *path, | |
873 | const char *interface, | |
874 | const char *property, | |
875 | sd_bus_message *reply, | |
ebcf1f97 LP |
876 | void *userdata, |
877 | sd_bus_error *ret_error) { | |
fe68089d | 878 | |
4d4c80d0 | 879 | ExecCommand *c = (ExecCommand*) userdata; |
718db961 | 880 | int r; |
fe68089d | 881 | |
718db961 LP |
882 | assert(bus); |
883 | assert(reply); | |
fe68089d | 884 | |
718db961 LP |
885 | r = sd_bus_message_open_container(reply, 'a', "(sasbttttuii)"); |
886 | if (r < 0) | |
887 | return r; | |
fe68089d | 888 | |
4d4c80d0 LP |
889 | r = append_exec_command(reply, c); |
890 | if (r < 0) | |
891 | return r; | |
fe68089d | 892 | |
4d4c80d0 LP |
893 | return sd_bus_message_close_container(reply); |
894 | } | |
718db961 | 895 | |
4d4c80d0 LP |
896 | int bus_property_get_exec_command_list( |
897 | sd_bus *bus, | |
898 | const char *path, | |
899 | const char *interface, | |
900 | const char *property, | |
901 | sd_bus_message *reply, | |
902 | void *userdata, | |
903 | sd_bus_error *ret_error) { | |
718db961 | 904 | |
4d4c80d0 LP |
905 | ExecCommand *c = *(ExecCommand**) userdata; |
906 | int r; | |
718db961 | 907 | |
4d4c80d0 LP |
908 | assert(bus); |
909 | assert(reply); | |
910 | ||
911 | r = sd_bus_message_open_container(reply, 'a', "(sasbttttuii)"); | |
912 | if (r < 0) | |
913 | return r; | |
718db961 | 914 | |
4d4c80d0 LP |
915 | LIST_FOREACH(command, c, c) { |
916 | r = append_exec_command(reply, c); | |
718db961 LP |
917 | if (r < 0) |
918 | return r; | |
fe68089d LP |
919 | } |
920 | ||
718db961 | 921 | return sd_bus_message_close_container(reply); |
8351ceae | 922 | } |
c7040b5d LP |
923 | |
924 | int bus_exec_context_set_transient_property( | |
925 | Unit *u, | |
926 | ExecContext *c, | |
927 | const char *name, | |
928 | sd_bus_message *message, | |
929 | UnitSetPropertiesMode mode, | |
930 | sd_bus_error *error) { | |
931 | ||
cab2aca3 LP |
932 | const char *soft = NULL; |
933 | int r, ri; | |
c7040b5d LP |
934 | |
935 | assert(u); | |
936 | assert(c); | |
937 | assert(name); | |
938 | assert(message); | |
939 | ||
940 | if (streq(name, "User")) { | |
941 | const char *uu; | |
942 | ||
943 | r = sd_bus_message_read(message, "s", &uu); | |
944 | if (r < 0) | |
945 | return r; | |
946 | ||
6f3e7985 LP |
947 | if (!isempty(uu) && !valid_user_group_name_or_id(uu)) |
948 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid user name: %s", uu); | |
949 | ||
c7040b5d | 950 | if (mode != UNIT_CHECK) { |
76736280 LP |
951 | |
952 | if (isempty(uu)) | |
953 | c->user = mfree(c->user); | |
954 | else if (free_and_strdup(&c->user, uu) < 0) | |
955 | return -ENOMEM; | |
c7040b5d | 956 | |
b27b4b51 | 957 | unit_write_drop_in_private_format(u, mode, name, "User=%s", uu); |
c7040b5d LP |
958 | } |
959 | ||
960 | return 1; | |
961 | ||
962 | } else if (streq(name, "Group")) { | |
963 | const char *gg; | |
964 | ||
965 | r = sd_bus_message_read(message, "s", &gg); | |
966 | if (r < 0) | |
967 | return r; | |
968 | ||
6f3e7985 LP |
969 | if (!isempty(gg) && !valid_user_group_name_or_id(gg)) |
970 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid group name: %s", gg); | |
971 | ||
c7040b5d | 972 | if (mode != UNIT_CHECK) { |
76736280 LP |
973 | |
974 | if (isempty(gg)) | |
975 | c->group = mfree(c->group); | |
976 | else if (free_and_strdup(&c->group, gg) < 0) | |
977 | return -ENOMEM; | |
c7040b5d | 978 | |
b27b4b51 | 979 | unit_write_drop_in_private_format(u, mode, name, "Group=%s", gg); |
c7040b5d LP |
980 | } |
981 | ||
982 | return 1; | |
de53c417 EV |
983 | } else if (streq(name, "SyslogIdentifier")) { |
984 | const char *id; | |
c7040b5d | 985 | |
de53c417 EV |
986 | r = sd_bus_message_read(message, "s", &id); |
987 | if (r < 0) | |
988 | return r; | |
989 | ||
990 | if (mode != UNIT_CHECK) { | |
76736280 LP |
991 | |
992 | if (isempty(id)) | |
993 | c->syslog_identifier = mfree(c->syslog_identifier); | |
994 | else if (free_and_strdup(&c->syslog_identifier, id) < 0) | |
995 | return -ENOMEM; | |
de53c417 | 996 | |
b27b4b51 | 997 | unit_write_drop_in_private_format(u, mode, name, "SyslogIdentifier=%s", id); |
de53c417 EV |
998 | } |
999 | ||
a8a13575 EV |
1000 | return 1; |
1001 | } else if (streq(name, "SyslogLevel")) { | |
1002 | int level; | |
1003 | ||
1004 | r = sd_bus_message_read(message, "i", &level); | |
1005 | if (r < 0) | |
1006 | return r; | |
1007 | ||
e0d6e0fa EV |
1008 | if (!log_level_is_valid(level)) |
1009 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Log level value out of range"); | |
1010 | ||
a8a13575 EV |
1011 | if (mode != UNIT_CHECK) { |
1012 | c->syslog_priority = (c->syslog_priority & LOG_FACMASK) | level; | |
b27b4b51 | 1013 | unit_write_drop_in_private_format(u, mode, name, "SyslogLevel=%i", level); |
a8a13575 EV |
1014 | } |
1015 | ||
460ed929 EV |
1016 | return 1; |
1017 | } else if (streq(name, "SyslogFacility")) { | |
1018 | int facility; | |
1019 | ||
1020 | r = sd_bus_message_read(message, "i", &facility); | |
1021 | if (r < 0) | |
1022 | return r; | |
1023 | ||
e0d6e0fa EV |
1024 | if (!log_facility_unshifted_is_valid(facility)) |
1025 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Log facility value out of range"); | |
1026 | ||
460ed929 EV |
1027 | if (mode != UNIT_CHECK) { |
1028 | c->syslog_priority = (facility << 3) | LOG_PRI(c->syslog_priority); | |
b27b4b51 | 1029 | unit_write_drop_in_private_format(u, mode, name, "SyslogFacility=%i", facility); |
460ed929 EV |
1030 | } |
1031 | ||
de53c417 | 1032 | return 1; |
c7040b5d LP |
1033 | } else if (streq(name, "Nice")) { |
1034 | int n; | |
1035 | ||
1036 | r = sd_bus_message_read(message, "i", &n); | |
1037 | if (r < 0) | |
1038 | return r; | |
1039 | ||
41bf0590 | 1040 | if (!nice_is_valid(n)) |
c7040b5d LP |
1041 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Nice value out of range"); |
1042 | ||
1043 | if (mode != UNIT_CHECK) { | |
1044 | c->nice = n; | |
b27b4b51 | 1045 | unit_write_drop_in_private_format(u, mode, name, "Nice=%i", n); |
c7040b5d LP |
1046 | } |
1047 | ||
1048 | return 1; | |
1049 | ||
5f5d8eab | 1050 | } else if (STR_IN_SET(name, "TTYPath", "RootDirectory")) { |
602b8355 | 1051 | const char *s; |
9b15b784 | 1052 | |
602b8355 | 1053 | r = sd_bus_message_read(message, "s", &s); |
9b15b784 LP |
1054 | if (r < 0) |
1055 | return r; | |
1056 | ||
602b8355 NC |
1057 | if (!path_is_absolute(s)) |
1058 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "%s takes an absolute path", name); | |
9b15b784 LP |
1059 | |
1060 | if (mode != UNIT_CHECK) { | |
5f5d8eab LP |
1061 | if (streq(name, "TTYPath")) |
1062 | r = free_and_strdup(&c->tty_path, s); | |
1063 | else { | |
1064 | assert(streq(name, "RootDirectory")); | |
1065 | r = free_and_strdup(&c->root_directory, s); | |
602b8355 | 1066 | } |
5f5d8eab LP |
1067 | if (r < 0) |
1068 | return r; | |
9b15b784 | 1069 | |
b27b4b51 | 1070 | unit_write_drop_in_private_format(u, mode, name, "%s=%s", name, s); |
9b15b784 LP |
1071 | } |
1072 | ||
1073 | return 1; | |
1074 | ||
5f5d8eab LP |
1075 | } else if (streq(name, "WorkingDirectory")) { |
1076 | const char *s; | |
1077 | bool missing_ok; | |
1078 | ||
1079 | r = sd_bus_message_read(message, "s", &s); | |
1080 | if (r < 0) | |
1081 | return r; | |
1082 | ||
1083 | if (s[0] == '-') { | |
1084 | missing_ok = true; | |
1085 | s++; | |
1086 | } else | |
1087 | missing_ok = false; | |
1088 | ||
1089 | if (!streq(s, "~") && !path_is_absolute(s)) | |
1090 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "WorkingDirectory= expects an absolute path or '~'"); | |
1091 | ||
1092 | if (mode != UNIT_CHECK) { | |
1093 | if (streq(s, "~")) { | |
1094 | c->working_directory = mfree(c->working_directory); | |
1095 | c->working_directory_home = true; | |
1096 | } else { | |
1097 | r = free_and_strdup(&c->working_directory, s); | |
1098 | if (r < 0) | |
1099 | return r; | |
1100 | ||
1101 | c->working_directory_home = false; | |
1102 | } | |
1103 | ||
1104 | c->working_directory_missing_ok = missing_ok; | |
b27b4b51 | 1105 | unit_write_drop_in_private_format(u, mode, name, "WorkingDirectory=%s%s", missing_ok ? "-" : "", s); |
5f5d8eab LP |
1106 | } |
1107 | ||
1108 | return 1; | |
1109 | ||
9b15b784 LP |
1110 | } else if (streq(name, "StandardInput")) { |
1111 | const char *s; | |
1112 | ExecInput p; | |
1113 | ||
1114 | r = sd_bus_message_read(message, "s", &s); | |
1115 | if (r < 0) | |
1116 | return r; | |
1117 | ||
1118 | p = exec_input_from_string(s); | |
1119 | if (p < 0) | |
1120 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid standard input name"); | |
1121 | ||
1122 | if (mode != UNIT_CHECK) { | |
1123 | c->std_input = p; | |
1124 | ||
b27b4b51 | 1125 | unit_write_drop_in_private_format(u, mode, name, "StandardInput=%s", exec_input_to_string(p)); |
9b15b784 LP |
1126 | } |
1127 | ||
1128 | return 1; | |
1129 | ||
9b15b784 LP |
1130 | } else if (streq(name, "StandardOutput")) { |
1131 | const char *s; | |
1132 | ExecOutput p; | |
1133 | ||
1134 | r = sd_bus_message_read(message, "s", &s); | |
1135 | if (r < 0) | |
1136 | return r; | |
1137 | ||
1138 | p = exec_output_from_string(s); | |
1139 | if (p < 0) | |
1140 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid standard output name"); | |
1141 | ||
1142 | if (mode != UNIT_CHECK) { | |
1143 | c->std_output = p; | |
1144 | ||
b27b4b51 | 1145 | unit_write_drop_in_private_format(u, mode, name, "StandardOutput=%s", exec_output_to_string(p)); |
9b15b784 LP |
1146 | } |
1147 | ||
1148 | return 1; | |
1149 | ||
1150 | } else if (streq(name, "StandardError")) { | |
1151 | const char *s; | |
1152 | ExecOutput p; | |
1153 | ||
1154 | r = sd_bus_message_read(message, "s", &s); | |
1155 | if (r < 0) | |
1156 | return r; | |
1157 | ||
1158 | p = exec_output_from_string(s); | |
1159 | if (p < 0) | |
1160 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid standard error name"); | |
1161 | ||
1162 | if (mode != UNIT_CHECK) { | |
1163 | c->std_error = p; | |
1164 | ||
b27b4b51 | 1165 | unit_write_drop_in_private_format(u, mode, name, "StandardError=%s", exec_output_to_string(p)); |
9b15b784 LP |
1166 | } |
1167 | ||
1168 | return 1; | |
1169 | ||
52c239d7 LB |
1170 | } else if (STR_IN_SET(name, |
1171 | "StandardInputFileDescriptorName", "StandardOutputFileDescriptorName", "StandardErrorFileDescriptorName")) { | |
1172 | const char *s; | |
1173 | ||
1174 | r = sd_bus_message_read(message, "s", &s); | |
1175 | if (r < 0) | |
1176 | return r; | |
1177 | ||
1178 | if (!fdname_is_valid(s)) | |
1179 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid file descriptor name"); | |
1180 | ||
1181 | if (mode != UNIT_CHECK) { | |
1182 | if (streq(name, "StandardInputFileDescriptorName")) { | |
1183 | c->std_input = EXEC_INPUT_NAMED_FD; | |
1184 | r = free_and_strdup(&c->stdio_fdname[STDIN_FILENO], s); | |
1185 | if (r < 0) | |
1186 | return r; | |
1187 | unit_write_drop_in_private_format(u, mode, name, "StandardInput=fd:%s", s); | |
1188 | } else if (streq(name, "StandardOutputFileDescriptorName")) { | |
1189 | c->std_output = EXEC_OUTPUT_NAMED_FD; | |
1190 | r = free_and_strdup(&c->stdio_fdname[STDOUT_FILENO], s); | |
1191 | if (r < 0) | |
1192 | return r; | |
1193 | unit_write_drop_in_private_format(u, mode, name, "StandardOutput=fd:%s", s); | |
1194 | } else if (streq(name, "StandardErrorFileDescriptorName")) { | |
1195 | c->std_error = EXEC_OUTPUT_NAMED_FD; | |
1196 | r = free_and_strdup(&c->stdio_fdname[STDERR_FILENO], s); | |
1197 | if (r < 0) | |
1198 | return r; | |
1199 | unit_write_drop_in_private_format(u, mode, name, "StandardError=fd:%s", s); | |
1200 | } | |
1201 | } | |
1202 | ||
1203 | return 1; | |
1204 | ||
b9c50073 GP |
1205 | } else if (STR_IN_SET(name, |
1206 | "IgnoreSIGPIPE", "TTYVHangup", "TTYReset", | |
d251207d | 1207 | "PrivateTmp", "PrivateDevices", "PrivateNetwork", "PrivateUsers", |
29206d46 | 1208 | "NoNewPrivileges", "SyslogLevelPrefix", "MemoryDenyWriteExecute", |
59eeb84b | 1209 | "RestrictRealtime", "DynamicUser", "RemoveIPC", "ProtectKernelTunables", |
502d704e | 1210 | "ProtectKernelModules", "ProtectControlGroups")) { |
506711fd LP |
1211 | int b; |
1212 | ||
1213 | r = sd_bus_message_read(message, "b", &b); | |
1214 | if (r < 0) | |
1215 | return r; | |
1216 | ||
1217 | if (mode != UNIT_CHECK) { | |
b9c50073 GP |
1218 | if (streq(name, "IgnoreSIGPIPE")) |
1219 | c->ignore_sigpipe = b; | |
1220 | else if (streq(name, "TTYVHangup")) | |
1221 | c->tty_vhangup = b; | |
1222 | else if (streq(name, "TTYReset")) | |
1223 | c->tty_reset = b; | |
1224 | else if (streq(name, "PrivateTmp")) | |
1225 | c->private_tmp = b; | |
1226 | else if (streq(name, "PrivateDevices")) | |
1227 | c->private_devices = b; | |
1228 | else if (streq(name, "PrivateNetwork")) | |
1229 | c->private_network = b; | |
d251207d LP |
1230 | else if (streq(name, "PrivateUsers")) |
1231 | c->private_users = b; | |
b9c50073 GP |
1232 | else if (streq(name, "NoNewPrivileges")) |
1233 | c->no_new_privileges = b; | |
047d9933 EV |
1234 | else if (streq(name, "SyslogLevelPrefix")) |
1235 | c->syslog_level_prefix = b; | |
f3e43635 TM |
1236 | else if (streq(name, "MemoryDenyWriteExecute")) |
1237 | c->memory_deny_write_execute = b; | |
f4170c67 LP |
1238 | else if (streq(name, "RestrictRealtime")) |
1239 | c->restrict_realtime = b; | |
29206d46 LP |
1240 | else if (streq(name, "DynamicUser")) |
1241 | c->dynamic_user = b; | |
00d9ef85 LP |
1242 | else if (streq(name, "RemoveIPC")) |
1243 | c->remove_ipc = b; | |
59eeb84b LP |
1244 | else if (streq(name, "ProtectKernelTunables")) |
1245 | c->protect_kernel_tunables = b; | |
502d704e DH |
1246 | else if (streq(name, "ProtectKernelModules")) |
1247 | c->protect_kernel_modules = b; | |
59eeb84b LP |
1248 | else if (streq(name, "ProtectControlGroups")) |
1249 | c->protect_control_groups = b; | |
b9c50073 | 1250 | |
b27b4b51 | 1251 | unit_write_drop_in_private_format(u, mode, name, "%s=%s", name, yes_no(b)); |
506711fd LP |
1252 | } |
1253 | ||
1254 | return 1; | |
1255 | ||
1256 | } else if (streq(name, "UtmpIdentifier")) { | |
1257 | const char *id; | |
1258 | ||
1259 | r = sd_bus_message_read(message, "s", &id); | |
1260 | if (r < 0) | |
1261 | return r; | |
1262 | ||
1263 | if (mode != UNIT_CHECK) { | |
76736280 LP |
1264 | if (isempty(id)) |
1265 | c->utmp_id = mfree(c->utmp_id); | |
1266 | else if (free_and_strdup(&c->utmp_id, id) < 0) | |
1267 | return -ENOMEM; | |
506711fd | 1268 | |
b27b4b51 | 1269 | unit_write_drop_in_private_format(u, mode, name, "UtmpIdentifier=%s", strempty(id)); |
506711fd LP |
1270 | } |
1271 | ||
1272 | return 1; | |
1273 | ||
1274 | } else if (streq(name, "UtmpMode")) { | |
1275 | const char *s; | |
1276 | ExecUtmpMode m; | |
1277 | ||
1278 | r = sd_bus_message_read(message, "s", &s); | |
1279 | if (r < 0) | |
1280 | return r; | |
1281 | ||
1282 | m = exec_utmp_mode_from_string(s); | |
1283 | if (m < 0) | |
1284 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid utmp mode"); | |
1285 | ||
1286 | if (mode != UNIT_CHECK) { | |
1287 | c->utmp_mode = m; | |
1288 | ||
b27b4b51 | 1289 | unit_write_drop_in_private_format(u, mode, name, "UtmpMode=%s", exec_utmp_mode_to_string(m)); |
506711fd LP |
1290 | } |
1291 | ||
1292 | return 1; | |
1293 | ||
1294 | } else if (streq(name, "PAMName")) { | |
1295 | const char *n; | |
1296 | ||
1297 | r = sd_bus_message_read(message, "s", &n); | |
1298 | if (r < 0) | |
1299 | return r; | |
1300 | ||
1301 | if (mode != UNIT_CHECK) { | |
76736280 LP |
1302 | if (isempty(n)) |
1303 | c->pam_name = mfree(c->pam_name); | |
1304 | else if (free_and_strdup(&c->pam_name, n) < 0) | |
1305 | return -ENOMEM; | |
506711fd | 1306 | |
b27b4b51 | 1307 | unit_write_drop_in_private_format(u, mode, name, "PAMName=%s", strempty(n)); |
506711fd LP |
1308 | } |
1309 | ||
1310 | return 1; | |
1311 | ||
c7040b5d LP |
1312 | } else if (streq(name, "Environment")) { |
1313 | ||
1314 | _cleanup_strv_free_ char **l = NULL; | |
1315 | ||
1316 | r = sd_bus_message_read_strv(message, &l); | |
1317 | if (r < 0) | |
1318 | return r; | |
1319 | ||
1320 | if (!strv_env_is_valid(l)) | |
1321 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid environment block."); | |
1322 | ||
1323 | if (mode != UNIT_CHECK) { | |
1006a62d | 1324 | _cleanup_free_ char *joined = NULL; |
c7040b5d LP |
1325 | char **e; |
1326 | ||
e9876fc9 EV |
1327 | if (strv_length(l) == 0) { |
1328 | c->environment = strv_free(c->environment); | |
b27b4b51 | 1329 | unit_write_drop_in_private_format(u, mode, name, "Environment="); |
e9876fc9 EV |
1330 | } else { |
1331 | e = strv_env_merge(2, c->environment, l); | |
1332 | if (!e) | |
1333 | return -ENOMEM; | |
c7040b5d | 1334 | |
e9876fc9 EV |
1335 | strv_free(c->environment); |
1336 | c->environment = e; | |
c7040b5d | 1337 | |
e9876fc9 EV |
1338 | joined = strv_join_quoted(c->environment); |
1339 | if (!joined) | |
1340 | return -ENOMEM; | |
1341 | ||
b27b4b51 | 1342 | unit_write_drop_in_private_format(u, mode, name, "Environment=%s", joined); |
e9876fc9 | 1343 | } |
c7040b5d LP |
1344 | } |
1345 | ||
d584f638 LP |
1346 | return 1; |
1347 | ||
f1db3327 EV |
1348 | } else if (streq(name, "TimerSlackNSec")) { |
1349 | ||
1350 | nsec_t n; | |
1351 | ||
1352 | r = sd_bus_message_read(message, "t", &n); | |
1353 | if (r < 0) | |
1354 | return r; | |
1355 | ||
1356 | if (mode != UNIT_CHECK) { | |
1357 | c->timer_slack_nsec = n; | |
b27b4b51 | 1358 | unit_write_drop_in_private_format(u, mode, name, "TimerSlackNSec=" NSEC_FMT, n); |
f1db3327 EV |
1359 | } |
1360 | ||
1361 | return 1; | |
1362 | ||
6b862936 EV |
1363 | } else if (streq(name, "OOMScoreAdjust")) { |
1364 | int oa; | |
1365 | ||
1366 | r = sd_bus_message_read(message, "i", &oa); | |
1367 | if (r < 0) | |
1368 | return r; | |
1369 | ||
1370 | if (!oom_score_adjust_is_valid(oa)) | |
1371 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "OOM score adjust value out of range"); | |
1372 | ||
1373 | if (mode != UNIT_CHECK) { | |
1374 | c->oom_score_adjust = oa; | |
1375 | c->oom_score_adjust_set = true; | |
b27b4b51 | 1376 | unit_write_drop_in_private_format(u, mode, name, "OOMScoreAdjust=%i", oa); |
6b862936 EV |
1377 | } |
1378 | ||
1379 | return 1; | |
1380 | ||
ceb728cf NC |
1381 | } else if (streq(name, "EnvironmentFiles")) { |
1382 | ||
1383 | _cleanup_free_ char *joined = NULL; | |
1384 | _cleanup_fclose_ FILE *f = NULL; | |
2229f656 | 1385 | _cleanup_free_ char **l = NULL; |
ceb728cf | 1386 | size_t size = 0; |
2229f656 | 1387 | char **i; |
ceb728cf NC |
1388 | |
1389 | r = sd_bus_message_enter_container(message, 'a', "(sb)"); | |
1390 | if (r < 0) | |
1391 | return r; | |
1392 | ||
1393 | f = open_memstream(&joined, &size); | |
1394 | if (!f) | |
1395 | return -ENOMEM; | |
1396 | ||
2229f656 | 1397 | STRV_FOREACH(i, c->environment_files) |
b27b4b51 | 1398 | fprintf(f, "EnvironmentFile=%s", *i); |
ceb728cf NC |
1399 | |
1400 | while ((r = sd_bus_message_enter_container(message, 'r', "sb")) > 0) { | |
1401 | const char *path; | |
1402 | int b; | |
1403 | ||
ceb728cf NC |
1404 | r = sd_bus_message_read(message, "sb", &path, &b); |
1405 | if (r < 0) | |
1406 | return r; | |
1407 | ||
1408 | r = sd_bus_message_exit_container(message); | |
1409 | if (r < 0) | |
1410 | return r; | |
1411 | ||
d2d6c096 LP |
1412 | if (!path_is_absolute(path)) |
1413 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path %s is not absolute.", path); | |
ceb728cf NC |
1414 | |
1415 | if (mode != UNIT_CHECK) { | |
ceb728cf NC |
1416 | char *buf = NULL; |
1417 | ||
605405c6 | 1418 | buf = strjoin(b ? "-" : "", path); |
2229f656 | 1419 | if (!buf) |
ceb728cf NC |
1420 | return -ENOMEM; |
1421 | ||
b27b4b51 | 1422 | fprintf(f, "EnvironmentFile=%s", buf); |
ceb728cf | 1423 | |
2229f656 | 1424 | r = strv_consume(&l, buf); |
ceb728cf NC |
1425 | if (r < 0) |
1426 | return r; | |
1427 | } | |
1428 | } | |
1429 | if (r < 0) | |
1430 | return r; | |
1431 | ||
b0830e21 LP |
1432 | r = sd_bus_message_exit_container(message); |
1433 | if (r < 0) | |
1434 | return r; | |
1435 | ||
2229f656 LP |
1436 | r = fflush_and_check(f); |
1437 | if (r < 0) | |
1438 | return r; | |
ceb728cf | 1439 | |
2229f656 LP |
1440 | if (mode != UNIT_CHECK) { |
1441 | if (strv_isempty(l)) { | |
1442 | c->environment_files = strv_free(c->environment_files); | |
b27b4b51 | 1443 | unit_write_drop_in_private(u, mode, name, "EnvironmentFile="); |
2229f656 LP |
1444 | } else { |
1445 | r = strv_extend_strv(&c->environment_files, l, true); | |
1446 | if (r < 0) | |
1447 | return r; | |
1448 | ||
ceb728cf | 1449 | unit_write_drop_in_private(u, mode, name, joined); |
2229f656 LP |
1450 | } |
1451 | } | |
ceb728cf | 1452 | |
ceb728cf NC |
1453 | return 1; |
1454 | ||
b4c14404 FB |
1455 | } else if (streq(name, "PassEnvironment")) { |
1456 | ||
1457 | _cleanup_strv_free_ char **l = NULL; | |
1458 | ||
1459 | r = sd_bus_message_read_strv(message, &l); | |
1460 | if (r < 0) | |
1461 | return r; | |
1462 | ||
1463 | if (!strv_env_name_is_valid(l)) | |
1464 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid PassEnvironment block."); | |
1465 | ||
1466 | if (mode != UNIT_CHECK) { | |
1467 | if (strv_isempty(l)) { | |
1468 | c->pass_environment = strv_free(c->pass_environment); | |
b27b4b51 | 1469 | unit_write_drop_in_private_format(u, mode, name, "PassEnvironment="); |
b4c14404 FB |
1470 | } else { |
1471 | _cleanup_free_ char *joined = NULL; | |
1472 | ||
1473 | r = strv_extend_strv(&c->pass_environment, l, true); | |
1474 | if (r < 0) | |
1475 | return r; | |
1476 | ||
1477 | joined = strv_join_quoted(c->pass_environment); | |
1478 | if (!joined) | |
1479 | return -ENOMEM; | |
1480 | ||
b27b4b51 | 1481 | unit_write_drop_in_private_format(u, mode, name, "PassEnvironment=%s", joined); |
b4c14404 FB |
1482 | } |
1483 | } | |
1484 | ||
1485 | return 1; | |
1486 | ||
2a624c36 AP |
1487 | } else if (STR_IN_SET(name, "ReadWriteDirectories", "ReadOnlyDirectories", "InaccessibleDirectories", |
1488 | "ReadWritePaths", "ReadOnlyPaths", "InaccessiblePaths")) { | |
08596068 EV |
1489 | _cleanup_strv_free_ char **l = NULL; |
1490 | char ***dirs; | |
1491 | char **p; | |
1492 | ||
1493 | r = sd_bus_message_read_strv(message, &l); | |
1494 | if (r < 0) | |
1495 | return r; | |
1496 | ||
1497 | STRV_FOREACH(p, l) { | |
1498 | int offset; | |
1499 | if (!utf8_is_valid(*p)) | |
1500 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid %s", name); | |
1501 | ||
1502 | offset = **p == '-'; | |
1503 | if (!path_is_absolute(*p + offset)) | |
1504 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid %s", name); | |
1505 | } | |
1506 | ||
1507 | if (mode != UNIT_CHECK) { | |
1508 | _cleanup_free_ char *joined = NULL; | |
1509 | ||
c4b41707 AP |
1510 | if (STR_IN_SET(name, "ReadWriteDirectories", "ReadWritePaths")) |
1511 | dirs = &c->read_write_paths; | |
1512 | else if (STR_IN_SET(name, "ReadOnlyDirectories", "ReadOnlyPaths")) | |
1513 | dirs = &c->read_only_paths; | |
1514 | else /* "InaccessiblePaths" */ | |
1515 | dirs = &c->inaccessible_paths; | |
08596068 EV |
1516 | |
1517 | if (strv_length(l) == 0) { | |
1518 | *dirs = strv_free(*dirs); | |
b27b4b51 | 1519 | unit_write_drop_in_private_format(u, mode, name, "%s=", name); |
08596068 EV |
1520 | } else { |
1521 | r = strv_extend_strv(dirs, l, true); | |
1522 | ||
1523 | if (r < 0) | |
1524 | return -ENOMEM; | |
1525 | ||
1526 | joined = strv_join_quoted(*dirs); | |
1527 | if (!joined) | |
1528 | return -ENOMEM; | |
1529 | ||
b27b4b51 | 1530 | unit_write_drop_in_private_format(u, mode, name, "%s=%s", name, joined); |
08596068 EV |
1531 | } |
1532 | ||
1533 | } | |
1534 | ||
1535 | return 1; | |
1536 | ||
5664e6cf EV |
1537 | } else if (streq(name, "ProtectSystem")) { |
1538 | const char *s; | |
1539 | ProtectSystem ps; | |
1540 | ||
1541 | r = sd_bus_message_read(message, "s", &s); | |
1542 | if (r < 0) | |
1543 | return r; | |
1544 | ||
1545 | r = parse_boolean(s); | |
1546 | if (r > 0) | |
1547 | ps = PROTECT_SYSTEM_YES; | |
1548 | else if (r == 0) | |
1549 | ps = PROTECT_SYSTEM_NO; | |
1550 | else { | |
1551 | ps = protect_system_from_string(s); | |
1552 | if (ps < 0) | |
1553 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Failed to parse protect system value"); | |
1554 | } | |
1555 | ||
1556 | if (mode != UNIT_CHECK) { | |
1557 | c->protect_system = ps; | |
b27b4b51 | 1558 | unit_write_drop_in_private_format(u, mode, name, "%s=%s", name, s); |
5664e6cf EV |
1559 | } |
1560 | ||
1561 | return 1; | |
1562 | ||
eff58074 EV |
1563 | } else if (streq(name, "ProtectHome")) { |
1564 | const char *s; | |
1565 | ProtectHome ph; | |
1566 | ||
1567 | r = sd_bus_message_read(message, "s", &s); | |
1568 | if (r < 0) | |
1569 | return r; | |
1570 | ||
1571 | r = parse_boolean(s); | |
1572 | if (r > 0) | |
1573 | ph = PROTECT_HOME_YES; | |
1574 | else if (r == 0) | |
1575 | ph = PROTECT_HOME_NO; | |
1576 | else { | |
1577 | ph = protect_home_from_string(s); | |
1578 | if (ph < 0) | |
1579 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Failed to parse protect home value"); | |
1580 | } | |
1581 | ||
1582 | if (mode != UNIT_CHECK) { | |
1583 | c->protect_home = ph; | |
b27b4b51 | 1584 | unit_write_drop_in_private_format(u, mode, name, "%s=%s", name, s); |
eff58074 EV |
1585 | } |
1586 | ||
1587 | return 1; | |
1588 | ||
fa21b5e3 EV |
1589 | } else if (streq(name, "RuntimeDirectory")) { |
1590 | _cleanup_strv_free_ char **l = NULL; | |
1591 | char **p; | |
1592 | ||
1593 | r = sd_bus_message_read_strv(message, &l); | |
1594 | if (r < 0) | |
1595 | return r; | |
1596 | ||
1597 | STRV_FOREACH(p, l) { | |
1598 | if (!filename_is_valid(*p)) | |
1599 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Runtime directory is not valid %s", *p); | |
1600 | } | |
1601 | ||
1602 | if (mode != UNIT_CHECK) { | |
1603 | _cleanup_free_ char *joined = NULL; | |
1604 | ||
1605 | if (strv_isempty(l)) { | |
1606 | c->runtime_directory = strv_free(c->runtime_directory); | |
b27b4b51 | 1607 | unit_write_drop_in_private_format(u, mode, name, "%s=", name); |
fa21b5e3 EV |
1608 | } else { |
1609 | r = strv_extend_strv(&c->runtime_directory, l, true); | |
1610 | ||
1611 | if (r < 0) | |
1612 | return -ENOMEM; | |
1613 | ||
1614 | joined = strv_join_quoted(c->runtime_directory); | |
1615 | if (!joined) | |
1616 | return -ENOMEM; | |
1617 | ||
b27b4b51 | 1618 | unit_write_drop_in_private_format(u, mode, name, "%s=%s", name, joined); |
fa21b5e3 EV |
1619 | } |
1620 | } | |
1621 | ||
1622 | return 1; | |
1623 | ||
186ad4b1 JB |
1624 | } else if (streq(name, "SELinuxContext")) { |
1625 | const char *s; | |
1626 | ||
1627 | r = sd_bus_message_read(message, "s", &s); | |
1628 | if (r < 0) | |
1629 | return r; | |
1630 | ||
1631 | if (mode != UNIT_CHECK) { | |
4e282d11 JB |
1632 | if (isempty(s)) |
1633 | c->selinux_context = mfree(c->selinux_context); | |
1634 | else if (free_and_strdup(&c->selinux_context, s) < 0) | |
1635 | return -ENOMEM; | |
186ad4b1 | 1636 | |
b27b4b51 | 1637 | unit_write_drop_in_private_format(u, mode, name, "%s=%s", name, strempty(s)); |
186ad4b1 JB |
1638 | } |
1639 | ||
1640 | return 1; | |
add00535 LP |
1641 | } else if (streq(name, "RestrictNamespaces")) { |
1642 | uint64_t flags; | |
186ad4b1 | 1643 | |
add00535 LP |
1644 | r = sd_bus_message_read(message, "t", &flags); |
1645 | if (r < 0) | |
1646 | return r; | |
1647 | if ((flags & NAMESPACE_FLAGS_ALL) != flags) | |
1648 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Unknown namespace types"); | |
1649 | ||
1650 | if (mode != UNIT_CHECK) { | |
1651 | _cleanup_free_ char *s = NULL; | |
1652 | ||
1653 | r = namespace_flag_to_string_many(flags, &s); | |
1654 | if (r < 0) | |
1655 | return r; | |
1656 | ||
1657 | c->restrict_namespaces = flags; | |
1658 | unit_write_drop_in_private_format(u, mode, name, "%s=%s", name, s); | |
1659 | } | |
1660 | ||
1661 | return 1; | |
83555251 LP |
1662 | } else if (streq(name, "MountFlags")) { |
1663 | uint64_t flags; | |
1664 | ||
1665 | r = sd_bus_message_read(message, "t", &flags); | |
1666 | if (r < 0) | |
1667 | return r; | |
1668 | if (!IN_SET(flags, 0, MS_SHARED, MS_PRIVATE, MS_SLAVE)) | |
1669 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Unknown mount propagation flags"); | |
cab2aca3 | 1670 | |
83555251 LP |
1671 | if (mode != UNIT_CHECK) { |
1672 | c->mount_flags = flags; | |
1673 | ||
c7383828 | 1674 | unit_write_drop_in_private_format(u, mode, name, "%s=%s", name, mount_propagation_flags_to_string(flags)); |
83555251 LP |
1675 | } |
1676 | ||
d2d6c096 LP |
1677 | return 1; |
1678 | } else if (STR_IN_SET(name, "BindPaths", "BindReadOnlyPaths")) { | |
1679 | unsigned empty = true; | |
1680 | ||
1681 | r = sd_bus_message_enter_container(message, 'a', "(ssbt)"); | |
1682 | if (r < 0) | |
1683 | return r; | |
1684 | ||
1685 | while ((r = sd_bus_message_enter_container(message, 'r', "ssbt")) > 0) { | |
1686 | const char *source, *destination; | |
1687 | int ignore_enoent; | |
1688 | uint64_t mount_flags; | |
1689 | ||
1690 | r = sd_bus_message_read(message, "ssbt", &source, &destination, &ignore_enoent, &mount_flags); | |
1691 | if (r < 0) | |
1692 | return r; | |
1693 | ||
1694 | r = sd_bus_message_exit_container(message); | |
1695 | if (r < 0) | |
1696 | return r; | |
1697 | ||
1698 | if (!path_is_absolute(source)) | |
1699 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Source path %s is not absolute.", source); | |
1700 | if (!path_is_absolute(destination)) | |
1701 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Destination path %s is not absolute.", source); | |
1702 | if (!IN_SET(mount_flags, 0, MS_REC)) | |
1703 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Unknown mount flags."); | |
1704 | ||
1705 | if (mode != UNIT_CHECK) { | |
1706 | r = bind_mount_add(&c->bind_mounts, &c->n_bind_mounts, | |
1707 | &(BindMount) { | |
1708 | .source = strdup(source), | |
1709 | .destination = strdup(destination), | |
1710 | .read_only = !!strstr(name, "ReadOnly"), | |
1711 | .recursive = !!(mount_flags & MS_REC), | |
1712 | .ignore_enoent = ignore_enoent, | |
1713 | }); | |
1714 | if (r < 0) | |
1715 | return r; | |
1716 | ||
1717 | unit_write_drop_in_private_format( | |
1718 | u, mode, name, | |
1719 | "%s=%s%s:%s:%s", | |
1720 | name, | |
1721 | ignore_enoent ? "-" : "", | |
1722 | source, | |
1723 | destination, | |
1724 | (mount_flags & MS_REC) ? "rbind" : "norbind"); | |
1725 | } | |
1726 | ||
1727 | empty = false; | |
1728 | } | |
1729 | if (r < 0) | |
1730 | return r; | |
1731 | ||
1732 | r = sd_bus_message_exit_container(message); | |
1733 | if (r < 0) | |
1734 | return r; | |
1735 | ||
1736 | if (empty) { | |
1737 | bind_mount_free_many(c->bind_mounts, c->n_bind_mounts); | |
1738 | c->bind_mounts = NULL; | |
1739 | c->n_bind_mounts = 0; | |
1740 | } | |
1741 | ||
83555251 LP |
1742 | return 1; |
1743 | } | |
d2d6c096 | 1744 | |
cab2aca3 LP |
1745 | ri = rlimit_from_string(name); |
1746 | if (ri < 0) { | |
1747 | soft = endswith(name, "Soft"); | |
1748 | if (soft) { | |
1749 | const char *n; | |
1750 | ||
1751 | n = strndupa(name, soft - name); | |
1752 | ri = rlimit_from_string(n); | |
1753 | if (ri >= 0) | |
1754 | name = n; | |
1755 | ||
1756 | } | |
1757 | } | |
1758 | ||
1759 | if (ri >= 0) { | |
d584f638 LP |
1760 | uint64_t rl; |
1761 | rlim_t x; | |
1762 | ||
1763 | r = sd_bus_message_read(message, "t", &rl); | |
1764 | if (r < 0) | |
1765 | return r; | |
1766 | ||
1767 | if (rl == (uint64_t) -1) | |
1768 | x = RLIM_INFINITY; | |
1769 | else { | |
1770 | x = (rlim_t) rl; | |
1771 | ||
1772 | if ((uint64_t) x != rl) | |
1773 | return -ERANGE; | |
1774 | } | |
1775 | ||
1776 | if (mode != UNIT_CHECK) { | |
cab2aca3 LP |
1777 | _cleanup_free_ char *f = NULL; |
1778 | struct rlimit nl; | |
1779 | ||
1780 | if (c->rlimit[ri]) { | |
1781 | nl = *c->rlimit[ri]; | |
1782 | ||
1783 | if (soft) | |
1784 | nl.rlim_cur = x; | |
1785 | else | |
1786 | nl.rlim_max = x; | |
1787 | } else | |
1788 | /* When the resource limit is not initialized yet, then assign the value to both fields */ | |
1789 | nl = (struct rlimit) { | |
1790 | .rlim_cur = x, | |
1791 | .rlim_max = x, | |
1792 | }; | |
1793 | ||
1794 | r = rlimit_format(&nl, &f); | |
1795 | if (r < 0) | |
1796 | return r; | |
d584f638 | 1797 | |
cab2aca3 LP |
1798 | if (c->rlimit[ri]) |
1799 | *c->rlimit[ri] = nl; | |
1800 | else { | |
1801 | c->rlimit[ri] = newdup(struct rlimit, &nl, 1); | |
1802 | if (!c->rlimit[ri]) | |
d584f638 LP |
1803 | return -ENOMEM; |
1804 | } | |
1805 | ||
b27b4b51 | 1806 | unit_write_drop_in_private_format(u, mode, name, "%s=%s", name, f); |
d584f638 LP |
1807 | } |
1808 | ||
c7040b5d LP |
1809 | return 1; |
1810 | } | |
1811 | ||
1812 | return 0; | |
1813 | } |