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