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