• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

systemd / systemd / 21192089104

20 Jan 2026 11:35PM UTC coverage: 72.524% (-0.3%) from 72.818%
21192089104

push

github

yuwata
mkdir: reset mtime *after* fchown()

Follow-up for 34c3d5747

Also, drop pointless shortcut.

1 of 2 new or added lines in 1 file covered. (50.0%)

2960 existing lines in 48 files now uncovered.

309808 of 427181 relevant lines covered (72.52%)

1236537.64 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

65.7
/src/core/dbus-execute.c
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);
5,642✔
51
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_input, exec_input, ExecInput);
2,802✔
52
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_utmp_mode, exec_utmp_mode, ExecUtmpMode);
2,802✔
53
BUS_DEFINE_PROPERTY_GET_ENUM(bus_property_get_exec_preserve_mode, exec_preserve_mode, ExecPreserveMode);
5,468✔
54
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_keyring_mode, exec_keyring_mode, ExecKeyringMode);
2,802✔
55
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_protect_proc, protect_proc, ProtectProc);
2,802✔
56
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_proc_subset, proc_subset, ProcSubset);
2,802✔
57
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_private_bpf, private_bpf, PrivateBPF);
2,802✔
58
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_protect_home, protect_home, ProtectHome);
2,802✔
59
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_protect_system, protect_system, ProtectSystem);
2,802✔
60
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_personality, personality, unsigned long);
2,802✔
61
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_memory_thp, memory_thp, MemoryTHP);
2,802✔
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);
2,802✔
64
static BUS_DEFINE_PROPERTY_GET(property_get_bind_log_sockets, "b", ExecContext, exec_context_get_effective_bind_log_sockets);
2,802✔
65
static BUS_DEFINE_PROPERTY_GET2(property_get_ioprio_class, "i", ExecContext, exec_context_get_effective_ioprio, ioprio_prio_class);
2,802✔
66
static BUS_DEFINE_PROPERTY_GET2(property_get_ioprio_priority, "i", ExecContext, exec_context_get_effective_ioprio, ioprio_prio_data);
2,802✔
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);
2,802✔
69
static BUS_DEFINE_PROPERTY_GET_REF(property_get_private_users_ex, "s", PrivateUsers, private_users_to_string);
2,802✔
70
static BUS_DEFINE_PROPERTY_GET_REF(property_get_protect_control_groups_ex, "s", ProtectControlGroups, protect_control_groups_to_string);
2,802✔
71
static BUS_DEFINE_PROPERTY_GET_REF(property_get_private_pids, "s", PrivatePIDs, private_pids_to_string);
2,802✔
72
static BUS_DEFINE_PROPERTY_GET_REF(property_get_syslog_level, "i", int, LOG_PRI);
2,802✔
73
static BUS_DEFINE_PROPERTY_GET_REF(property_get_syslog_facility, "i", int, LOG_FAC);
2,802✔
74
static BUS_DEFINE_PROPERTY_GET(property_get_cpu_affinity_from_numa, "b", ExecContext, exec_context_get_cpu_affinity_from_numa);
2,802✔
75
static BUS_DEFINE_PROPERTY_GET(property_get_oom_score_adjust, "i", ExecContext, exec_context_get_oom_score_adjust);
2,802✔
76
static BUS_DEFINE_PROPERTY_GET(property_get_nice, "i", ExecContext, exec_context_get_nice);
2,802✔
77
static BUS_DEFINE_PROPERTY_GET(property_get_cpu_sched_policy, "i", ExecContext, exec_context_get_cpu_sched_policy);
2,802✔
78
static BUS_DEFINE_PROPERTY_GET(property_get_cpu_sched_priority, "i", ExecContext, exec_context_get_cpu_sched_priority);
2,802✔
79
static BUS_DEFINE_PROPERTY_GET(property_get_coredump_filter, "t", ExecContext, exec_context_get_coredump_filter);
2,802✔
80
static BUS_DEFINE_PROPERTY_GET(property_get_timer_slack_nsec, "t", ExecContext, exec_context_get_timer_slack_nsec);
2,802✔
81
static BUS_DEFINE_PROPERTY_GET(property_get_set_login_environment, "b", ExecContext, exec_context_get_set_login_environment);
2,802✔
82

83
static int property_get_environment_files(
2,802✔
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);
2,802✔
93
        int r;
2,802✔
94

95
        assert(bus);
2,802✔
96
        assert(reply);
2,802✔
97

98
        r = sd_bus_message_open_container(reply, 'a', "(sb)");
2,802✔
99
        if (r < 0)
2,802✔
100
                return r;
101

102
        STRV_FOREACH(j, c->environment_files) {
2,808✔
103
                const char *fn = *j;
6✔
104

105
                r = sd_bus_message_append(reply, "(sb)", fn[0] == '-' ? fn + 1 : fn, fn[0] == '-');
6✔
106
                if (r < 0)
6✔
107
                        return r;
108
        }
109

110
        return sd_bus_message_close_container(reply);
2,802✔
111
}
112

113
static int property_get_cpu_affinity(
2,802✔
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);
2,802✔
123
        _cleanup_(cpu_set_done) CPUSet s = {};
×
124
        _cleanup_free_ uint8_t *array = NULL;
2,802✔
125
        size_t allocated;
2,802✔
126

127
        assert(bus);
2,802✔
128
        assert(reply);
2,802✔
129

130
        if (c->cpu_affinity_from_numa) {
2,802✔
131
                int r;
×
132

133
                r = numa_to_cpu_set(&c->numa_policy, &s);
×
134
                if (r < 0)
×
135
                        return r;
136
        }
137

138
        (void) cpu_set_to_dbus(c->cpu_affinity_from_numa ? &s : &c->cpu_set,  &array, &allocated);
2,802✔
139

140
        return sd_bus_message_append_array(reply, 'y', array, allocated);
2,802✔
141
}
142

143
static int property_get_numa_mask(
2,802✔
144
                sd_bus *bus,
145
                const char *path,
146
                const char *interface,
147
                const char *property,
148
                sd_bus_message *reply,
149
                void *userdata,
150
                sd_bus_error *reterr_error) {
151

152
        ExecContext *c = ASSERT_PTR(userdata);
2,802✔
153
        _cleanup_free_ uint8_t *array = NULL;
2,802✔
154
        size_t allocated;
2,802✔
155

156
        assert(bus);
2,802✔
157
        assert(reply);
2,802✔
158

159
        (void) cpu_set_to_dbus(&c->numa_policy.nodes, &array, &allocated);
2,802✔
160

161
        return sd_bus_message_append_array(reply, 'y', array, allocated);
2,802✔
162
}
163

164
static int property_get_numa_policy(
2,802✔
165
                sd_bus *bus,
166
                const char *path,
167
                const char *interface,
168
                const char *property,
169
                sd_bus_message *reply,
170
                void *userdata,
171
                sd_bus_error *reterr_error) {
172
        ExecContext *c = ASSERT_PTR(userdata);
2,802✔
173
        int32_t policy;
2,802✔
174

175
        assert(bus);
2,802✔
176
        assert(reply);
2,802✔
177

178
        policy = numa_policy_get_type(&c->numa_policy);
2,802✔
179

180
        return sd_bus_message_append_basic(reply, 'i', &policy);
2,802✔
181
}
182

183
static int property_get_syscall_filter(
2,802✔
184
                sd_bus *bus,
185
                const char *path,
186
                const char *interface,
187
                const char *property,
188
                sd_bus_message *reply,
189
                void *userdata,
190
                sd_bus_error *reterr_error) {
191

192
        ExecContext *c = ASSERT_PTR(userdata);
2,802✔
193
        _cleanup_strv_free_ char **l = NULL;
2,802✔
194
        int r;
2,802✔
195

196
        assert(bus);
2,802✔
197
        assert(reply);
2,802✔
198

199
        r = sd_bus_message_open_container(reply, 'r', "bas");
2,802✔
200
        if (r < 0)
2,802✔
201
                return r;
202

203
        r = sd_bus_message_append(reply, "b", c->syscall_allow_list);
2,802✔
204
        if (r < 0)
2,802✔
205
                return r;
206

207
        l = exec_context_get_syscall_filter(c);
2,802✔
208
        if (!l)
2,802✔
209
                return -ENOMEM;
210

211
        r = sd_bus_message_append_strv(reply, l);
2,802✔
212
        if (r < 0)
2,802✔
213
                return r;
214

215
        return sd_bus_message_close_container(reply);
2,802✔
216
}
217

218
static int property_get_syscall_log(
2,802✔
219
                sd_bus *bus,
220
                const char *path,
221
                const char *interface,
222
                const char *property,
223
                sd_bus_message *reply,
224
                void *userdata,
225
                sd_bus_error *reterr_error) {
226

227
        ExecContext *c = ASSERT_PTR(userdata);
2,802✔
228
        _cleanup_strv_free_ char **l = NULL;
2,802✔
229
        int r;
2,802✔
230

231
        assert(bus);
2,802✔
232
        assert(reply);
2,802✔
233

234
        r = sd_bus_message_open_container(reply, 'r', "bas");
2,802✔
235
        if (r < 0)
2,802✔
236
                return r;
237

238
        r = sd_bus_message_append(reply, "b", c->syscall_log_allow_list);
2,802✔
239
        if (r < 0)
2,802✔
240
                return r;
241

242
        l = exec_context_get_syscall_log(c);
2,802✔
243
        if (!l)
2,802✔
244
                return -ENOMEM;
245

246
        r = sd_bus_message_append_strv(reply, l);
2,802✔
247
        if (r < 0)
2,802✔
248
                return r;
249

250
        return sd_bus_message_close_container(reply);
2,802✔
251
}
252

253
static int property_get_syscall_archs(
2,802✔
254
                sd_bus *bus,
255
                const char *path,
256
                const char *interface,
257
                const char *property,
258
                sd_bus_message *reply,
259
                void *userdata,
260
                sd_bus_error *reterr_error) {
261

262
        ExecContext *c = ASSERT_PTR(userdata);
2,802✔
263
        _cleanup_strv_free_ char **l = NULL;
2,802✔
264
        int r;
2,802✔
265

266
        assert(bus);
2,802✔
267
        assert(reply);
2,802✔
268

269
        l = exec_context_get_syscall_archs(c);
2,802✔
270
        if (!l)
2,802✔
271
                return -ENOMEM;
272

273
        r = sd_bus_message_append_strv(reply, l);
2,802✔
274
        if (r < 0)
2,802✔
275
                return r;
×
276

277
        return 0;
278
}
279

280
static int property_get_selinux_context(
2,802✔
281
                sd_bus *bus,
282
                const char *path,
283
                const char *interface,
284
                const char *property,
285
                sd_bus_message *reply,
286
                void *userdata,
287
                sd_bus_error *reterr_error) {
288

289
        ExecContext *c = ASSERT_PTR(userdata);
2,802✔
290

291
        assert(bus);
2,802✔
292
        assert(reply);
2,802✔
293

294
        return sd_bus_message_append(reply, "(bs)", c->selinux_context_ignore, c->selinux_context);
2,802✔
295
}
296

297
static int property_get_apparmor_profile(
2,802✔
298
                sd_bus *bus,
299
                const char *path,
300
                const char *interface,
301
                const char *property,
302
                sd_bus_message *reply,
303
                void *userdata,
304
                sd_bus_error *reterr_error) {
305

306
        ExecContext *c = ASSERT_PTR(userdata);
2,802✔
307

308
        assert(bus);
2,802✔
309
        assert(reply);
2,802✔
310

311
        return sd_bus_message_append(reply, "(bs)", c->apparmor_profile_ignore, c->apparmor_profile);
2,802✔
312
}
313

314
static int property_get_smack_process_label(
2,802✔
315
                sd_bus *bus,
316
                const char *path,
317
                const char *interface,
318
                const char *property,
319
                sd_bus_message *reply,
320
                void *userdata,
321
                sd_bus_error *reterr_error) {
322

323
        ExecContext *c = ASSERT_PTR(userdata);
2,802✔
324

325
        assert(bus);
2,802✔
326
        assert(reply);
2,802✔
327

328
        return sd_bus_message_append(reply, "(bs)", c->smack_process_label_ignore, c->smack_process_label);
2,802✔
329
}
330

331
static int property_get_address_families(
2,802✔
332
                sd_bus *bus,
333
                const char *path,
334
                const char *interface,
335
                const char *property,
336
                sd_bus_message *reply,
337
                void *userdata,
338
                sd_bus_error *reterr_error) {
339

340
        ExecContext *c = ASSERT_PTR(userdata);
2,802✔
341
        _cleanup_strv_free_ char **l = NULL;
2,802✔
342
        int r;
2,802✔
343

344
        assert(bus);
2,802✔
345
        assert(reply);
2,802✔
346

347
        r = sd_bus_message_open_container(reply, 'r', "bas");
2,802✔
348
        if (r < 0)
2,802✔
349
                return r;
350

351
        r = sd_bus_message_append(reply, "b", c->address_families_allow_list);
2,802✔
352
        if (r < 0)
2,802✔
353
                return r;
354

355
        l = exec_context_get_address_families(c);
2,802✔
356
        if (!l)
2,802✔
357
                return -ENOMEM;
358

359
        r = sd_bus_message_append_strv(reply, l);
2,802✔
360
        if (r < 0)
2,802✔
361
                return r;
362

363
        return sd_bus_message_close_container(reply);
2,802✔
364
}
365

366
static int property_get_working_directory(
2,802✔
367
                sd_bus *bus,
368
                const char *path,
369
                const char *interface,
370
                const char *property,
371
                sd_bus_message *reply,
372
                void *userdata,
373
                sd_bus_error *reterr_error) {
374

375
        ExecContext *c = ASSERT_PTR(userdata);
2,802✔
376
        const char *wd;
2,802✔
377

378
        assert(bus);
2,802✔
379
        assert(reply);
2,802✔
380

381
        if (c->working_directory_home)
2,802✔
382
                wd = "~";
383
        else
384
                wd = c->working_directory;
2,485✔
385

386
        if (c->working_directory_missing_ok)
2,802✔
387
                wd = strjoina("!", wd);
2,960✔
388

389
        return sd_bus_message_append(reply, "s", wd);
2,802✔
390
}
391

392
static int property_get_stdio_fdname(
8,406✔
393
                sd_bus *bus,
394
                const char *path,
395
                const char *interface,
396
                const char *property,
397
                sd_bus_message *reply,
398
                void *userdata,
399
                sd_bus_error *reterr_error) {
400

401
        ExecContext *c = ASSERT_PTR(userdata);
8,406✔
402
        int fileno;
8,406✔
403

404
        assert(bus);
8,406✔
405
        assert(property);
8,406✔
406
        assert(reply);
8,406✔
407

408
        if (streq(property, "StandardInputFileDescriptorName"))
8,406✔
409
                fileno = STDIN_FILENO;
410
        else if (streq(property, "StandardOutputFileDescriptorName"))
5,604✔
411
                fileno = STDOUT_FILENO;
412
        else {
413
                assert(streq(property, "StandardErrorFileDescriptorName"));
2,802✔
414
                fileno = STDERR_FILENO;
415
        }
416

417
        return sd_bus_message_append(reply, "s", exec_context_fdname(c, fileno));
8,406✔
418
}
419

420
static int property_get_input_data(
2,802✔
421
                sd_bus *bus,
422
                const char *path,
423
                const char *interface,
424
                const char *property,
425
                sd_bus_message *reply,
426
                void *userdata,
427
                sd_bus_error *reterr_error) {
428

429
        ExecContext *c = ASSERT_PTR(userdata);
2,802✔
430

431
        assert(bus);
2,802✔
432
        assert(property);
2,802✔
433
        assert(reply);
2,802✔
434

435
        return sd_bus_message_append_array(reply, 'y', c->stdin_data, c->stdin_data_size);
2,802✔
436
}
437

438
static int property_get_restrict_filesystems(
2,802✔
439
                sd_bus *bus,
440
                const char *path,
441
                const char *interface,
442
                const char *property,
443
                sd_bus_message *reply,
444
                void *userdata,
445
                sd_bus_error *reterr_error) {
446

447
        ExecContext *c = ASSERT_PTR(userdata);
2,802✔
448
        _cleanup_free_ char **l = NULL; /* Strings are owned by 'c->restrict_filesystems'! */
2,802✔
449
        int r;
2,802✔
450

451
        assert(bus);
2,802✔
452
        assert(reply);
2,802✔
453

454
        r = sd_bus_message_open_container(reply, 'r', "bas");
2,802✔
455
        if (r < 0)
2,802✔
456
                return r;
457

458
        r = sd_bus_message_append(reply, "b", c->restrict_filesystems_allow_list);
2,802✔
459
        if (r < 0)
2,802✔
460
                return r;
461

462
        l = exec_context_get_restrict_filesystems(c);
2,802✔
463
        if (!l)
2,802✔
464
                return -ENOMEM;
465

466
        r = sd_bus_message_append_strv(reply, l);
2,802✔
467
        if (r < 0)
2,802✔
468
                return r;
469

470
        return sd_bus_message_close_container(reply);
2,802✔
471
}
472

473
static int property_get_bind_paths(
5,604✔
474
                sd_bus *bus,
475
                const char *path,
476
                const char *interface,
477
                const char *property,
478
                sd_bus_message *reply,
479
                void *userdata,
480
                sd_bus_error *reterr_error) {
481

482
        ExecContext *c = ASSERT_PTR(userdata);
5,604✔
483
        bool ro;
5,604✔
484
        int r;
5,604✔
485

486
        assert(bus);
5,604✔
487
        assert(property);
5,604✔
488
        assert(reply);
5,604✔
489

490
        ro = strstr(property, "ReadOnly");
5,604✔
491

492
        r = sd_bus_message_open_container(reply, 'a', "(ssbt)");
5,604✔
493
        if (r < 0)
5,604✔
494
                return r;
495

496
        FOREACH_ARRAY(i, c->bind_mounts, c->n_bind_mounts) {
5,852✔
497
                if (ro != i->read_only)
248✔
498
                        continue;
124✔
499

500
                r = sd_bus_message_append(
372✔
501
                                reply, "(ssbt)",
502
                                i->source,
503
                                i->destination,
504
                                i->ignore_enoent,
124✔
505
                                i->recursive ? (uint64_t) MS_REC : UINT64_C(0));
124✔
506
                if (r < 0)
124✔
507
                        return r;
508
        }
509

510
        return sd_bus_message_close_container(reply);
5,604✔
511
}
512

513
static int property_get_temporary_filesystems(
2,802✔
514
                sd_bus *bus,
515
                const char *path,
516
                const char *interface,
517
                const char *property,
518
                sd_bus_message *reply,
519
                void *userdata,
520
                sd_bus_error *reterr_error) {
521

522
        ExecContext *c = ASSERT_PTR(userdata);
2,802✔
523
        int r;
2,802✔
524

525
        assert(bus);
2,802✔
526
        assert(property);
2,802✔
527
        assert(reply);
2,802✔
528

529
        r = sd_bus_message_open_container(reply, 'a', "(ss)");
2,802✔
530
        if (r < 0)
2,802✔
531
                return r;
532

533
        FOREACH_ARRAY(t, c->temporary_filesystems, c->n_temporary_filesystems) {
2,828✔
534
                r = sd_bus_message_append(
26✔
535
                                reply, "(ss)",
536
                                t->path,
537
                                t->options);
538
                if (r < 0)
26✔
539
                        return r;
540
        }
541

542
        return sd_bus_message_close_container(reply);
2,802✔
543
}
544

545
static int property_get_log_extra_fields(
2,802✔
546
                sd_bus *bus,
547
                const char *path,
548
                const char *interface,
549
                const char *property,
550
                sd_bus_message *reply,
551
                void *userdata,
552
                sd_bus_error *reterr_error) {
553

554
        ExecContext *c = ASSERT_PTR(userdata);
2,802✔
555
        int r;
2,802✔
556

557
        assert(bus);
2,802✔
558
        assert(property);
2,802✔
559
        assert(reply);
2,802✔
560

561
        r = sd_bus_message_open_container(reply, 'a', "ay");
2,802✔
562
        if (r < 0)
2,802✔
563
                return r;
564

565
        FOREACH_ARRAY(i, c->log_extra_fields, c->n_log_extra_fields) {
5,714✔
566
                r = sd_bus_message_append_array(reply, 'y', i->iov_base, i->iov_len);
2,912✔
567
                if (r < 0)
2,912✔
568
                        return r;
569
        }
570

571
        return sd_bus_message_close_container(reply);
2,802✔
572
}
573

574
static int sd_bus_message_append_log_filter_patterns(sd_bus_message *reply, Set *patterns, bool is_allowlist) {
5,604✔
575
        const char *pattern;
5,604✔
576
        int r;
5,604✔
577

578
        assert(reply);
5,604✔
579

580
        SET_FOREACH(pattern, patterns) {
5,604✔
581
                r = sd_bus_message_append(reply, "(bs)", is_allowlist, pattern);
×
582
                if (r < 0)
×
583
                        return r;
×
584
        }
585

586
        return 0;
5,604✔
587
}
588

589
static int property_get_log_filter_patterns(
2,802✔
590
                sd_bus *bus,
591
                const char *path,
592
                const char *interface,
593
                const char *property,
594
                sd_bus_message *reply,
595
                void *userdata,
596
                sd_bus_error *reterr_error) {
597

598
        ExecContext *c = userdata;
2,802✔
599
        int r;
2,802✔
600

601
        assert(c);
2,802✔
602
        assert(reply);
2,802✔
603

604
        r = sd_bus_message_open_container(reply, 'a', "(bs)");
2,802✔
605
        if (r < 0)
2,802✔
606
                return r;
607

608
        r = sd_bus_message_append_log_filter_patterns(reply, c->log_filter_allowed_patterns,
2,802✔
609
                                                      /* is_allowlist= */ true);
610
        if (r < 0)
2,802✔
611
                return r;
612

613
        r = sd_bus_message_append_log_filter_patterns(reply, c->log_filter_denied_patterns,
2,802✔
614
                                                      /* is_allowlist= */ false);
615
        if (r < 0)
2,802✔
616
                return r;
617

618
        return sd_bus_message_close_container(reply);
2,802✔
619
}
620

621
static int property_get_set_credential(
5,604✔
622
                sd_bus *bus,
623
                const char *path,
624
                const char *interface,
625
                const char *property,
626
                sd_bus_message *reply,
627
                void *userdata,
628
                sd_bus_error *reterr_error) {
629

630
        ExecContext *c = ASSERT_PTR(userdata);
5,604✔
631
        ExecSetCredential *sc;
5,604✔
632
        int r;
5,604✔
633

634
        assert(bus);
5,604✔
635
        assert(property);
5,604✔
636
        assert(reply);
5,604✔
637

638
        r = sd_bus_message_open_container(reply, 'a', "(say)");
5,604✔
639
        if (r < 0)
5,604✔
640
                return r;
5,604✔
641

642
        HASHMAP_FOREACH(sc, c->set_credentials) {
5,700✔
643

644
                if (sc->encrypted != streq(property, "SetCredentialEncrypted"))
96✔
645
                        continue;
48✔
646

647
                r = sd_bus_message_open_container(reply, 'r', "say");
48✔
648
                if (r < 0)
48✔
649
                        return r;
×
650

651
                r = sd_bus_message_append(reply, "s", sc->id);
48✔
652
                if (r < 0)
48✔
653
                        return r;
654

655
                r = sd_bus_message_append_array(reply, 'y', sc->data, sc->size);
48✔
656
                if (r < 0)
48✔
657
                        return r;
658

659
                r = sd_bus_message_close_container(reply);
48✔
660
                if (r < 0)
48✔
661
                        return r;
662
        }
663

664
        return sd_bus_message_close_container(reply);
5,604✔
665
}
666

667
static int property_get_load_credential(
5,604✔
668
                sd_bus *bus,
669
                const char *path,
670
                const char *interface,
671
                const char *property,
672
                sd_bus_message *reply,
673
                void *userdata,
674
                sd_bus_error *reterr_error) {
675

676
        ExecContext *c = ASSERT_PTR(userdata);
5,604✔
677
        ExecLoadCredential *lc;
5,604✔
678
        int r;
5,604✔
679

680
        assert(bus);
5,604✔
681
        assert(property);
5,604✔
682
        assert(reply);
5,604✔
683

684
        r = sd_bus_message_open_container(reply, 'a', "(ss)");
5,604✔
685
        if (r < 0)
5,604✔
686
                return r;
5,604✔
687

688
        HASHMAP_FOREACH(lc, c->load_credentials) {
5,644✔
689

690
                if (lc->encrypted != streq(property, "LoadCredentialEncrypted"))
40✔
691
                        continue;
20✔
692

693
                r = sd_bus_message_append(reply, "(ss)", lc->id, lc->path);
20✔
694
                if (r < 0)
20✔
695
                        return r;
×
696
        }
697

698
        return sd_bus_message_close_container(reply);
5,604✔
699
}
700

701
static int property_get_import_credential(
2,802✔
702
                sd_bus *bus,
703
                const char *path,
704
                const char *interface,
705
                const char *property,
706
                sd_bus_message *reply,
707
                void *userdata,
708
                sd_bus_error *reterr_error) {
709

710
        ExecContext *c = ASSERT_PTR(userdata);
2,802✔
711
        ExecImportCredential *ic;
2,802✔
712
        int r;
2,802✔
713

714
        assert(bus);
2,802✔
715
        assert(property);
2,802✔
716
        assert(reply);
2,802✔
717

718
        r = sd_bus_message_open_container(reply, 'a', "s");
2,802✔
719
        if (r < 0)
2,802✔
720
                return r;
2,802✔
721

722
        ORDERED_SET_FOREACH(ic, c->import_credentials) {
2,930✔
723
                r = sd_bus_message_append(reply, "s", ic->glob);
128✔
724
                if (r < 0)
128✔
725
                        return r;
×
726
        }
727

728
        return sd_bus_message_close_container(reply);
2,802✔
729
}
730

731
static int property_get_import_credential_ex(
2,802✔
732
                sd_bus *bus,
733
                const char *path,
734
                const char *interface,
735
                const char *property,
736
                sd_bus_message *reply,
737
                void *userdata,
738
                sd_bus_error *reterr_error) {
739

740
        ExecContext *c = ASSERT_PTR(userdata);
2,802✔
741
        ExecImportCredential *ic;
2,802✔
742
        int r;
2,802✔
743

744
        assert(bus);
2,802✔
745
        assert(property);
2,802✔
746
        assert(reply);
2,802✔
747

748
        r = sd_bus_message_open_container(reply, 'a', "(ss)");
2,802✔
749
        if (r < 0)
2,802✔
750
                return r;
2,802✔
751

752
        ORDERED_SET_FOREACH(ic, c->import_credentials) {
2,930✔
753
                r = sd_bus_message_append(reply, "(ss)", ic->glob, ic->rename);
128✔
754
                if (r < 0)
128✔
755
                        return r;
×
756
        }
757

758
        return sd_bus_message_close_container(reply);
2,802✔
759
}
760

761
static int property_get_root_hash(
2,802✔
762
                sd_bus *bus,
763
                const char *path,
764
                const char *interface,
765
                const char *property,
766
                sd_bus_message *reply,
767
                void *userdata,
768
                sd_bus_error *reterr_error) {
769

770
        ExecContext *c = ASSERT_PTR(userdata);
2,802✔
771

772
        assert(bus);
2,802✔
773
        assert(property);
2,802✔
774
        assert(reply);
2,802✔
775

776
        return sd_bus_message_append_array(reply, 'y', c->root_hash.iov_base, c->root_hash.iov_len);
2,802✔
777
}
778

779
static int property_get_root_hash_sig(
2,802✔
780
                sd_bus *bus,
781
                const char *path,
782
                const char *interface,
783
                const char *property,
784
                sd_bus_message *reply,
785
                void *userdata,
786
                sd_bus_error *reterr_error) {
787

788
        ExecContext *c = ASSERT_PTR(userdata);
2,802✔
789

790
        assert(bus);
2,802✔
791
        assert(property);
2,802✔
792
        assert(reply);
2,802✔
793

794
        return sd_bus_message_append_array(reply, 'y', c->root_hash_sig.iov_base, c->root_hash_sig.iov_len);
2,802✔
795
}
796

797
static int bus_append_mount_options(
2,863✔
798
                sd_bus_message *reply,
799
                const MountOptions *options) {
800

801
        int r;
2,863✔
802

803
        assert(reply);
2,863✔
804

805
        r = sd_bus_message_open_container(reply, 'a', "(ss)");
2,863✔
806
        if (r < 0)
2,863✔
807
                return r;
808

809
        if (options)
2,863✔
810
                for (PartitionDesignator i = 0; i < _PARTITION_DESIGNATOR_MAX; i++) {
252✔
811
                        if (isempty(options->options[i]))
234✔
812
                                continue;
214✔
813

814
                        r = sd_bus_message_append(reply, "(ss)",
20✔
815
                                                  partition_designator_to_string(i),
816
                                                  options->options[i]);
817
                        if (r < 0)
20✔
818
                                return r;
819
                }
820

821
        return sd_bus_message_close_container(reply);
2,863✔
822
}
823

824
static int property_get_root_image_options(
2,802✔
825
                sd_bus *bus,
826
                const char *path,
827
                const char *interface,
828
                const char *property,
829
                sd_bus_message *reply,
830
                void *userdata,
831
                sd_bus_error *reterr_error) {
832

833
        ExecContext *c = ASSERT_PTR(userdata);
2,802✔
834

835
        assert(bus);
2,802✔
836
        assert(property);
2,802✔
837
        assert(reply);
2,802✔
838

839
        return bus_append_mount_options(reply, c->root_image_options);
2,802✔
840
}
841

842
static int property_get_mount_images(
2,802✔
843
                sd_bus *bus,
844
                const char *path,
845
                const char *interface,
846
                const char *property,
847
                sd_bus_message *reply,
848
                void *userdata,
849
                sd_bus_error *reterr_error) {
850

851
        ExecContext *c = ASSERT_PTR(userdata);
2,802✔
852
        int r;
2,802✔
853

854
        assert(bus);
2,802✔
855
        assert(property);
2,802✔
856
        assert(reply);
2,802✔
857

858
        r = sd_bus_message_open_container(reply, 'a', "(ssba(ss))");
2,802✔
859
        if (r < 0)
2,802✔
860
                return r;
861

862
        FOREACH_ARRAY(i, c->mount_images, c->n_mount_images) {
2,814✔
863
                r = sd_bus_message_open_container(reply, SD_BUS_TYPE_STRUCT, "ssba(ss)");
12✔
864
                if (r < 0)
12✔
865
                        return r;
866

867
                r = sd_bus_message_append(
24✔
868
                                reply, "ssb",
869
                                i->source,
870
                                i->destination,
871
                                i->ignore_enoent);
12✔
872
                if (r < 0)
12✔
873
                        return r;
874

875
                r = bus_append_mount_options(reply, i->mount_options);
12✔
876
                if (r < 0)
12✔
877
                        return r;
878

879
                r = sd_bus_message_close_container(reply);
12✔
880
                if (r < 0)
12✔
881
                        return r;
882
        }
883

884
        return sd_bus_message_close_container(reply);
2,802✔
885
}
886

887
static int property_get_extension_images(
2,802✔
888
                sd_bus *bus,
889
                const char *path,
890
                const char *interface,
891
                const char *property,
892
                sd_bus_message *reply,
893
                void *userdata,
894
                sd_bus_error *reterr_error) {
895

896
        ExecContext *c = ASSERT_PTR(userdata);
2,802✔
897
        int r;
2,802✔
898

899
        assert(bus);
2,802✔
900
        assert(property);
2,802✔
901
        assert(reply);
2,802✔
902

903
        r = sd_bus_message_open_container(reply, 'a', "(sba(ss))");
2,802✔
904
        if (r < 0)
2,802✔
905
                return r;
906

907
        FOREACH_ARRAY(i, c->extension_images, c->n_extension_images) {
2,851✔
908
                r = sd_bus_message_open_container(reply, SD_BUS_TYPE_STRUCT, "sba(ss)");
49✔
909
                if (r < 0)
49✔
910
                        return r;
911

912
                r = sd_bus_message_append(
98✔
913
                                reply, "sb",
914
                                i->source,
915
                                i->ignore_enoent);
49✔
916
                if (r < 0)
49✔
917
                        return r;
918

919
                r = bus_append_mount_options(reply, i->mount_options);
49✔
920
                if (r < 0)
49✔
921
                        return r;
922

923
                r = sd_bus_message_close_container(reply);
49✔
924
                if (r < 0)
49✔
925
                        return r;
926
        }
927

928
        return sd_bus_message_close_container(reply);
2,802✔
929
}
930

931
static int property_get_exec_dir(
14,010✔
932
                sd_bus *bus,
933
                const char *path,
934
                const char *interface,
935
                const char *property,
936
                sd_bus_message *reply,
937
                void *userdata,
938
                sd_bus_error *reterr_error) {
939

940
        ExecDirectory *d = ASSERT_PTR(userdata);
14,010✔
941
        int r;
14,010✔
942

943
        assert(bus);
14,010✔
944
        assert(property);
14,010✔
945
        assert(reply);
14,010✔
946

947
        r = sd_bus_message_open_container(reply, 'a', "s");
14,010✔
948
        if (r < 0)
14,010✔
949
                return r;
950

951
        FOREACH_ARRAY(i, d->items, d->n_items) {
14,537✔
952
                r = sd_bus_message_append_basic(reply, 's', i->path);
527✔
953
                if (r < 0)
527✔
954
                        return r;
955
        }
956

957
        return sd_bus_message_close_container(reply);
14,010✔
958
}
959

960
static int property_get_exec_dir_symlink(
11,208✔
961
                sd_bus *bus,
962
                const char *path,
963
                const char *interface,
964
                const char *property,
965
                sd_bus_message *reply,
966
                void *userdata,
967
                sd_bus_error *reterr_error) {
968

969
        ExecDirectory *d = ASSERT_PTR(userdata);
11,208✔
970
        int r;
11,208✔
971

972
        assert(bus);
11,208✔
973
        assert(property);
11,208✔
974
        assert(reply);
11,208✔
975

976
        r = sd_bus_message_open_container(reply, 'a', "(sst)");
11,208✔
977
        if (r < 0)
11,208✔
978
                return r;
979

980
        FOREACH_ARRAY(i, d->items, d->n_items)
11,582✔
981
                if (strv_isempty(i->symlinks)) {
374✔
982
                        /* The old exec directory properties cannot represent flags, so list them here with no
983
                         * destination */
984
                        r = sd_bus_message_append(reply, "(sst)", i->path, "", (uint64_t) (i->flags & _EXEC_DIRECTORY_FLAGS_PUBLIC));
338✔
985
                        if (r < 0)
338✔
986
                                return r;
987
                } else
988
                        STRV_FOREACH(dst, i->symlinks) {
72✔
989
                                r = sd_bus_message_append(reply, "(sst)", i->path, *dst, (uint64_t) (i->flags & _EXEC_DIRECTORY_FLAGS_PUBLIC));
36✔
990
                                if (r < 0)
36✔
991
                                        return r;
992
                        }
993

994
        return sd_bus_message_close_container(reply);
11,208✔
995
}
996

997
static int property_get_exec_quota(sd_bus *bus,
8,406✔
998
                const char *path,
999
                const char *interface,
1000
                const char *property,
1001
                sd_bus_message *reply,
1002
                void *userdata,
1003
                sd_bus_error *reterr_error) {
1004

1005
        QuotaLimit *q = ASSERT_PTR(userdata);
8,406✔
1006

1007
        assert(bus);
8,406✔
1008
        assert(reply);
8,406✔
1009

1010
        return sd_bus_message_append(reply, "(tus)", q->quota_absolute, q->quota_scale, yes_no(q->quota_enforce));
16,812✔
1011
}
1012

1013
static int property_get_image_policy(
8,406✔
1014
                sd_bus *bus,
1015
                const char *path,
1016
                const char *interface,
1017
                const char *property,
1018
                sd_bus_message *reply,
1019
                void *userdata,
1020
                sd_bus_error *reterr_error) {
1021

1022
        ImagePolicy **pp = ASSERT_PTR(userdata);
8,406✔
1023
        _cleanup_free_ char *s = NULL;
8,406✔
1024
        int r;
8,406✔
1025

1026
        assert(bus);
8,406✔
1027
        assert(property);
8,406✔
1028
        assert(reply);
8,406✔
1029

1030
        r = image_policy_to_string(*pp ?: &image_policy_service, /* simplify= */ true, &s);
16,796✔
1031
        if (r < 0)
8,406✔
1032
                return r;
1033

1034
        return sd_bus_message_append(reply, "s", s);
8,406✔
1035
}
1036

1037
static int property_get_private_tmp(
2,802✔
1038
                sd_bus *bus,
1039
                const char *path,
1040
                const char *interface,
1041
                const char *property,
1042
                sd_bus_message *reply,
1043
                void *userdata,
1044
                sd_bus_error *reterr_error) {
1045

1046
        PrivateTmp *p = ASSERT_PTR(userdata);
2,802✔
1047
        int b = *p != PRIVATE_TMP_NO;
2,802✔
1048

1049
        return sd_bus_message_append_basic(reply, 'b', &b);
2,802✔
1050
}
1051

1052
static int property_get_private_users(
2,802✔
1053
                sd_bus *bus,
1054
                const char *path,
1055
                const char *interface,
1056
                const char *property,
1057
                sd_bus_message *reply,
1058
                void *userdata,
1059
                sd_bus_error *reterr_error) {
1060

1061
        PrivateUsers *p = ASSERT_PTR(userdata);
2,802✔
1062
        int b = *p != PRIVATE_USERS_NO;
2,802✔
1063

1064
        return sd_bus_message_append_basic(reply, 'b', &b);
2,802✔
1065
}
1066

1067
static int property_get_protect_control_groups(
2,802✔
1068
                sd_bus *bus,
1069
                const char *path,
1070
                const char *interface,
1071
                const char *property,
1072
                sd_bus_message *reply,
1073
                void *userdata,
1074
                sd_bus_error *reterr_error) {
1075

1076
        ProtectControlGroups *p = ASSERT_PTR(userdata);
2,802✔
1077
        int b = *p != PROTECT_CONTROL_GROUPS_NO;
2,802✔
1078

1079
        return sd_bus_message_append_basic(reply, 'b', &b);
2,802✔
1080
}
1081

1082
static int property_get_protect_hostname(
2,802✔
1083
                sd_bus *bus,
1084
                const char *path,
1085
                const char *interface,
1086
                const char *property,
1087
                sd_bus_message *reply,
1088
                void *userdata,
1089
                sd_bus_error *reterr_error) {
1090

1091
        ProtectHostname *p = ASSERT_PTR(userdata);
2,802✔
1092
        int b = *p != PROTECT_HOSTNAME_NO;
2,802✔
1093

1094
        return sd_bus_message_append_basic(reply, 'b', &b);
2,802✔
1095
}
1096

1097
static int property_get_protect_hostname_ex(
2,802✔
1098
                sd_bus *bus,
1099
                const char *path,
1100
                const char *interface,
1101
                const char *property,
1102
                sd_bus_message *reply,
1103
                void *userdata,
1104
                sd_bus_error *reterr_error) {
1105

1106
        ExecContext *c = ASSERT_PTR(userdata);
2,802✔
1107

1108
        return sd_bus_message_append(reply, "(ss)", protect_hostname_to_string(c->protect_hostname), c->private_hostname);
2,802✔
1109
}
1110

1111
static int property_get_unsigned_as_uint16(
5,604✔
1112
                sd_bus *bus,
1113
                const char *path,
1114
                const char *interface,
1115
                const char *property,
1116
                sd_bus_message *reply,
1117
                void *userdata,
1118
                sd_bus_error *reterr_error) {
1119

1120
        unsigned *value = ASSERT_PTR(userdata);
5,604✔
1121

1122
        /* 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. */
1123

1124
        uint16_t q = *value >= UINT16_MAX ? UINT16_MAX : (uint16_t) *value;
5,604✔
1125
        return sd_bus_message_append_basic(reply, 'q', &q);
5,604✔
1126
}
1127

1128
static int property_get_bpf_delegate_commands(
2,802✔
1129
                sd_bus *bus,
1130
                const char *path,
1131
                const char *interface,
1132
                const char *property,
1133
                sd_bus_message *reply,
1134
                void *userdata,
1135
                sd_bus_error *reterr_error) {
1136

1137
        uint64_t *u = ASSERT_PTR(userdata);
2,802✔
1138
        _cleanup_free_ char *s = NULL;
2,802✔
1139

1140
        assert(reply);
2,802✔
1141

1142
        s = bpf_delegate_commands_to_string(*u);
2,802✔
1143
        if (!s)
2,802✔
1144
                return -ENOMEM;
1145

1146
        return sd_bus_message_append(reply, "s", s);
2,802✔
1147
}
1148

1149
static int property_get_bpf_delegate_maps(
2,802✔
1150
                sd_bus *bus,
1151
                const char *path,
1152
                const char *interface,
1153
                const char *property,
1154
                sd_bus_message *reply,
1155
                void *userdata,
1156
                sd_bus_error *reterr_error) {
1157

1158
        uint64_t *u = ASSERT_PTR(userdata);
2,802✔
1159
        _cleanup_free_ char *s = NULL;
2,802✔
1160

1161
        assert(reply);
2,802✔
1162

1163
        s = bpf_delegate_maps_to_string(*u);
2,802✔
1164
        if (!s)
2,802✔
1165
                return -ENOMEM;
1166

1167
        return sd_bus_message_append(reply, "s", s);
2,802✔
1168
}
1169

1170
static int property_get_bpf_delegate_programs(
2,802✔
1171
                sd_bus *bus,
1172
                const char *path,
1173
                const char *interface,
1174
                const char *property,
1175
                sd_bus_message *reply,
1176
                void *userdata,
1177
                sd_bus_error *reterr_error) {
1178

1179
        uint64_t *u = ASSERT_PTR(userdata);
2,802✔
1180
        _cleanup_free_ char *s = NULL;
2,802✔
1181

1182
        assert(reply);
2,802✔
1183

1184
        s = bpf_delegate_programs_to_string(*u);
2,802✔
1185
        if (!s)
2,802✔
1186
                return -ENOMEM;
1187

1188
        return sd_bus_message_append(reply, "s", s);
2,802✔
1189
}
1190

1191
static int property_get_bpf_delegate_attachments(
2,802✔
1192
                sd_bus *bus,
1193
                const char *path,
1194
                const char *interface,
1195
                const char *property,
1196
                sd_bus_message *reply,
1197
                void *userdata,
1198
                sd_bus_error *reterr_error) {
1199

1200
        uint64_t *u = ASSERT_PTR(userdata);
2,802✔
1201
        _cleanup_free_ char *s = NULL;
2,802✔
1202

1203
        assert(reply);
2,802✔
1204

1205
        s = bpf_delegate_attachments_to_string(*u);
2,802✔
1206
        if (!s)
2,802✔
1207
                return -ENOMEM;
1208

1209
        return sd_bus_message_append(reply, "s", s);
2,802✔
1210
}
1211

1212
const sd_bus_vtable bus_exec_vtable[] = {
1213
        SD_BUS_VTABLE_START(0),
1214
        SD_BUS_PROPERTY("Environment", "as", NULL, offsetof(ExecContext, environment), SD_BUS_VTABLE_PROPERTY_CONST),
1215
        SD_BUS_PROPERTY("EnvironmentFiles", "a(sb)", property_get_environment_files, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1216
        SD_BUS_PROPERTY("PassEnvironment", "as", NULL, offsetof(ExecContext, pass_environment), SD_BUS_VTABLE_PROPERTY_CONST),
1217
        SD_BUS_PROPERTY("UnsetEnvironment", "as", NULL, offsetof(ExecContext, unset_environment), SD_BUS_VTABLE_PROPERTY_CONST),
1218
        SD_BUS_PROPERTY("UMask", "u", bus_property_get_mode, offsetof(ExecContext, umask), SD_BUS_VTABLE_PROPERTY_CONST),
1219
        SD_BUS_PROPERTY("LimitCPU", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_CPU]), SD_BUS_VTABLE_PROPERTY_CONST),
1220
        SD_BUS_PROPERTY("LimitCPUSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_CPU]), SD_BUS_VTABLE_PROPERTY_CONST),
1221
        SD_BUS_PROPERTY("LimitFSIZE", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_FSIZE]), SD_BUS_VTABLE_PROPERTY_CONST),
1222
        SD_BUS_PROPERTY("LimitFSIZESoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_FSIZE]), SD_BUS_VTABLE_PROPERTY_CONST),
1223
        SD_BUS_PROPERTY("LimitDATA", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_DATA]), SD_BUS_VTABLE_PROPERTY_CONST),
1224
        SD_BUS_PROPERTY("LimitDATASoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_DATA]), SD_BUS_VTABLE_PROPERTY_CONST),
1225
        SD_BUS_PROPERTY("LimitSTACK", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_STACK]), SD_BUS_VTABLE_PROPERTY_CONST),
1226
        SD_BUS_PROPERTY("LimitSTACKSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_STACK]), SD_BUS_VTABLE_PROPERTY_CONST),
1227
        SD_BUS_PROPERTY("LimitCORE", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_CORE]), SD_BUS_VTABLE_PROPERTY_CONST),
1228
        SD_BUS_PROPERTY("LimitCORESoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_CORE]), SD_BUS_VTABLE_PROPERTY_CONST),
1229
        SD_BUS_PROPERTY("LimitRSS", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RSS]), SD_BUS_VTABLE_PROPERTY_CONST),
1230
        SD_BUS_PROPERTY("LimitRSSSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RSS]), SD_BUS_VTABLE_PROPERTY_CONST),
1231
        SD_BUS_PROPERTY("LimitNOFILE", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NOFILE]), SD_BUS_VTABLE_PROPERTY_CONST),
1232
        SD_BUS_PROPERTY("LimitNOFILESoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NOFILE]), SD_BUS_VTABLE_PROPERTY_CONST),
1233
        SD_BUS_PROPERTY("LimitAS", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_AS]), SD_BUS_VTABLE_PROPERTY_CONST),
1234
        SD_BUS_PROPERTY("LimitASSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_AS]), SD_BUS_VTABLE_PROPERTY_CONST),
1235
        SD_BUS_PROPERTY("LimitNPROC", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NPROC]), SD_BUS_VTABLE_PROPERTY_CONST),
1236
        SD_BUS_PROPERTY("LimitNPROCSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NPROC]), SD_BUS_VTABLE_PROPERTY_CONST),
1237
        SD_BUS_PROPERTY("LimitMEMLOCK", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_MEMLOCK]), SD_BUS_VTABLE_PROPERTY_CONST),
1238
        SD_BUS_PROPERTY("LimitMEMLOCKSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_MEMLOCK]), SD_BUS_VTABLE_PROPERTY_CONST),
1239
        SD_BUS_PROPERTY("LimitLOCKS", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_LOCKS]), SD_BUS_VTABLE_PROPERTY_CONST),
1240
        SD_BUS_PROPERTY("LimitLOCKSSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_LOCKS]), SD_BUS_VTABLE_PROPERTY_CONST),
1241
        SD_BUS_PROPERTY("LimitSIGPENDING", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_SIGPENDING]), SD_BUS_VTABLE_PROPERTY_CONST),
1242
        SD_BUS_PROPERTY("LimitSIGPENDINGSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_SIGPENDING]), SD_BUS_VTABLE_PROPERTY_CONST),
1243
        SD_BUS_PROPERTY("LimitMSGQUEUE", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_MSGQUEUE]), SD_BUS_VTABLE_PROPERTY_CONST),
1244
        SD_BUS_PROPERTY("LimitMSGQUEUESoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_MSGQUEUE]), SD_BUS_VTABLE_PROPERTY_CONST),
1245
        SD_BUS_PROPERTY("LimitNICE", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NICE]), SD_BUS_VTABLE_PROPERTY_CONST),
1246
        SD_BUS_PROPERTY("LimitNICESoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_NICE]), SD_BUS_VTABLE_PROPERTY_CONST),
1247
        SD_BUS_PROPERTY("LimitRTPRIO", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RTPRIO]), SD_BUS_VTABLE_PROPERTY_CONST),
1248
        SD_BUS_PROPERTY("LimitRTPRIOSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RTPRIO]), SD_BUS_VTABLE_PROPERTY_CONST),
1249
        SD_BUS_PROPERTY("LimitRTTIME", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RTTIME]), SD_BUS_VTABLE_PROPERTY_CONST),
1250
        SD_BUS_PROPERTY("LimitRTTIMESoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RTTIME]), SD_BUS_VTABLE_PROPERTY_CONST),
1251
        SD_BUS_PROPERTY("WorkingDirectory", "s", property_get_working_directory, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1252
        SD_BUS_PROPERTY("RootDirectory", "s", NULL, offsetof(ExecContext, root_directory), SD_BUS_VTABLE_PROPERTY_CONST),
1253
        SD_BUS_PROPERTY("RootImage", "s", NULL, offsetof(ExecContext, root_image), SD_BUS_VTABLE_PROPERTY_CONST),
1254
        SD_BUS_PROPERTY("RootImageOptions", "a(ss)", property_get_root_image_options, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1255
        SD_BUS_PROPERTY("RootHash", "ay", property_get_root_hash, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1256
        SD_BUS_PROPERTY("RootHashPath", "s", NULL, offsetof(ExecContext, root_hash_path), SD_BUS_VTABLE_PROPERTY_CONST),
1257
        SD_BUS_PROPERTY("RootHashSignature", "ay", property_get_root_hash_sig, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1258
        SD_BUS_PROPERTY("RootHashSignaturePath", "s", NULL, offsetof(ExecContext, root_hash_sig_path), SD_BUS_VTABLE_PROPERTY_CONST),
1259
        SD_BUS_PROPERTY("RootVerity", "s", NULL, offsetof(ExecContext, root_verity), SD_BUS_VTABLE_PROPERTY_CONST),
1260
        SD_BUS_PROPERTY("RootEphemeral", "b", bus_property_get_bool, offsetof(ExecContext, root_ephemeral), SD_BUS_VTABLE_PROPERTY_CONST),
1261
        SD_BUS_PROPERTY("ExtensionDirectories", "as", NULL, offsetof(ExecContext, extension_directories), SD_BUS_VTABLE_PROPERTY_CONST),
1262
        SD_BUS_PROPERTY("ExtensionImages", "a(sba(ss))", property_get_extension_images, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1263
        SD_BUS_PROPERTY("MountImages", "a(ssba(ss))", property_get_mount_images, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1264
        SD_BUS_PROPERTY("OOMScoreAdjust", "i", property_get_oom_score_adjust, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1265
        SD_BUS_PROPERTY("CoredumpFilter", "t", property_get_coredump_filter, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1266
        SD_BUS_PROPERTY("Nice", "i", property_get_nice, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1267
        SD_BUS_PROPERTY("IOSchedulingClass", "i", property_get_ioprio_class, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1268
        SD_BUS_PROPERTY("IOSchedulingPriority", "i", property_get_ioprio_priority, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1269
        SD_BUS_PROPERTY("CPUSchedulingPolicy", "i", property_get_cpu_sched_policy, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1270
        SD_BUS_PROPERTY("CPUSchedulingPriority", "i", property_get_cpu_sched_priority, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1271
        SD_BUS_PROPERTY("CPUAffinity", "ay", property_get_cpu_affinity, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1272
        SD_BUS_PROPERTY("CPUAffinityFromNUMA", "b", property_get_cpu_affinity_from_numa, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1273
        SD_BUS_PROPERTY("NUMAPolicy", "i", property_get_numa_policy, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1274
        SD_BUS_PROPERTY("NUMAMask", "ay", property_get_numa_mask, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1275
        SD_BUS_PROPERTY("TimerSlackNSec", "t", property_get_timer_slack_nsec, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1276
        SD_BUS_PROPERTY("CPUSchedulingResetOnFork", "b", bus_property_get_bool, offsetof(ExecContext, cpu_sched_reset_on_fork), SD_BUS_VTABLE_PROPERTY_CONST),
1277
        SD_BUS_PROPERTY("NonBlocking", "b", bus_property_get_bool, offsetof(ExecContext, non_blocking), SD_BUS_VTABLE_PROPERTY_CONST),
1278
        SD_BUS_PROPERTY("StandardInput", "s", property_get_exec_input, offsetof(ExecContext, std_input), SD_BUS_VTABLE_PROPERTY_CONST),
1279
        SD_BUS_PROPERTY("StandardInputFileDescriptorName", "s", property_get_stdio_fdname, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1280
        SD_BUS_PROPERTY("StandardInputData", "ay", property_get_input_data, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1281
        SD_BUS_PROPERTY("StandardOutput", "s", bus_property_get_exec_output, offsetof(ExecContext, std_output), SD_BUS_VTABLE_PROPERTY_CONST),
1282
        SD_BUS_PROPERTY("StandardOutputFileDescriptorName", "s", property_get_stdio_fdname, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1283
        SD_BUS_PROPERTY("StandardError", "s", bus_property_get_exec_output, offsetof(ExecContext, std_error), SD_BUS_VTABLE_PROPERTY_CONST),
1284
        SD_BUS_PROPERTY("StandardErrorFileDescriptorName", "s", property_get_stdio_fdname, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1285
        SD_BUS_PROPERTY("TTYPath", "s", NULL, offsetof(ExecContext, tty_path), SD_BUS_VTABLE_PROPERTY_CONST),
1286
        SD_BUS_PROPERTY("TTYReset", "b", bus_property_get_bool, offsetof(ExecContext, tty_reset), SD_BUS_VTABLE_PROPERTY_CONST),
1287
        SD_BUS_PROPERTY("TTYVHangup", "b", bus_property_get_bool, offsetof(ExecContext, tty_vhangup), SD_BUS_VTABLE_PROPERTY_CONST),
1288
        SD_BUS_PROPERTY("TTYVTDisallocate", "b", bus_property_get_bool, offsetof(ExecContext, tty_vt_disallocate), SD_BUS_VTABLE_PROPERTY_CONST),
1289
        SD_BUS_PROPERTY("TTYRows", "q", property_get_unsigned_as_uint16, offsetof(ExecContext, tty_rows), SD_BUS_VTABLE_PROPERTY_CONST),
1290
        SD_BUS_PROPERTY("TTYColumns", "q", property_get_unsigned_as_uint16, offsetof(ExecContext, tty_cols), SD_BUS_VTABLE_PROPERTY_CONST),
1291
        SD_BUS_PROPERTY("SyslogPriority", "i", bus_property_get_int, offsetof(ExecContext, syslog_priority), SD_BUS_VTABLE_PROPERTY_CONST),
1292
        SD_BUS_PROPERTY("SyslogIdentifier", "s", NULL, offsetof(ExecContext, syslog_identifier), SD_BUS_VTABLE_PROPERTY_CONST),
1293
        SD_BUS_PROPERTY("SyslogLevelPrefix", "b", bus_property_get_bool, offsetof(ExecContext, syslog_level_prefix), SD_BUS_VTABLE_PROPERTY_CONST),
1294
        SD_BUS_PROPERTY("SyslogLevel", "i", property_get_syslog_level, offsetof(ExecContext, syslog_priority), SD_BUS_VTABLE_PROPERTY_CONST),
1295
        SD_BUS_PROPERTY("SyslogFacility", "i", property_get_syslog_facility, offsetof(ExecContext, syslog_priority), SD_BUS_VTABLE_PROPERTY_CONST),
1296
        SD_BUS_PROPERTY("LogLevelMax", "i", bus_property_get_int, offsetof(ExecContext, log_level_max), SD_BUS_VTABLE_PROPERTY_CONST),
1297
        SD_BUS_PROPERTY("LogRateLimitIntervalUSec", "t", bus_property_get_usec, offsetof(ExecContext, log_ratelimit.interval), SD_BUS_VTABLE_PROPERTY_CONST),
1298
        SD_BUS_PROPERTY("LogRateLimitBurst", "u", bus_property_get_unsigned, offsetof(ExecContext, log_ratelimit.burst), SD_BUS_VTABLE_PROPERTY_CONST),
1299
        SD_BUS_PROPERTY("LogExtraFields", "aay", property_get_log_extra_fields, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1300
        SD_BUS_PROPERTY("LogFilterPatterns", "a(bs)", property_get_log_filter_patterns, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1301
        SD_BUS_PROPERTY("LogNamespace", "s", NULL, offsetof(ExecContext, log_namespace), SD_BUS_VTABLE_PROPERTY_CONST),
1302
        SD_BUS_PROPERTY("SecureBits", "i", bus_property_get_int, offsetof(ExecContext, secure_bits), SD_BUS_VTABLE_PROPERTY_CONST),
1303
        SD_BUS_PROPERTY("CapabilityBoundingSet", "t", NULL, offsetof(ExecContext, capability_bounding_set), SD_BUS_VTABLE_PROPERTY_CONST),
1304
        SD_BUS_PROPERTY("AmbientCapabilities", "t", NULL, offsetof(ExecContext, capability_ambient_set), SD_BUS_VTABLE_PROPERTY_CONST),
1305
        SD_BUS_PROPERTY("User", "s", NULL, offsetof(ExecContext, user), SD_BUS_VTABLE_PROPERTY_CONST),
1306
        SD_BUS_PROPERTY("Group", "s", NULL, offsetof(ExecContext, group), SD_BUS_VTABLE_PROPERTY_CONST),
1307
        SD_BUS_PROPERTY("DynamicUser", "b", bus_property_get_bool, offsetof(ExecContext, dynamic_user), SD_BUS_VTABLE_PROPERTY_CONST),
1308
        SD_BUS_PROPERTY("SetLoginEnvironment", "b", property_get_set_login_environment, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1309
        SD_BUS_PROPERTY("RemoveIPC", "b", bus_property_get_bool, offsetof(ExecContext, remove_ipc), SD_BUS_VTABLE_PROPERTY_CONST),
1310
        SD_BUS_PROPERTY("SetCredential", "a(say)", property_get_set_credential, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1311
        SD_BUS_PROPERTY("SetCredentialEncrypted", "a(say)", property_get_set_credential, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1312
        SD_BUS_PROPERTY("LoadCredential", "a(ss)", property_get_load_credential, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1313
        SD_BUS_PROPERTY("LoadCredentialEncrypted", "a(ss)", property_get_load_credential, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1314
        SD_BUS_PROPERTY("ImportCredential", "as", property_get_import_credential, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1315
        SD_BUS_PROPERTY("ImportCredentialEx", "a(ss)", property_get_import_credential_ex, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1316
        SD_BUS_PROPERTY("SupplementaryGroups", "as", NULL, offsetof(ExecContext, supplementary_groups), SD_BUS_VTABLE_PROPERTY_CONST),
1317
        SD_BUS_PROPERTY("PAMName", "s", NULL, offsetof(ExecContext, pam_name), SD_BUS_VTABLE_PROPERTY_CONST),
1318
        SD_BUS_PROPERTY("ReadWritePaths", "as", NULL, offsetof(ExecContext, read_write_paths), SD_BUS_VTABLE_PROPERTY_CONST),
1319
        SD_BUS_PROPERTY("ReadOnlyPaths", "as", NULL, offsetof(ExecContext, read_only_paths), SD_BUS_VTABLE_PROPERTY_CONST),
1320
        SD_BUS_PROPERTY("InaccessiblePaths", "as", NULL, offsetof(ExecContext, inaccessible_paths), SD_BUS_VTABLE_PROPERTY_CONST),
1321
        SD_BUS_PROPERTY("ExecPaths", "as", NULL, offsetof(ExecContext, exec_paths), SD_BUS_VTABLE_PROPERTY_CONST),
1322
        SD_BUS_PROPERTY("NoExecPaths", "as", NULL, offsetof(ExecContext, no_exec_paths), SD_BUS_VTABLE_PROPERTY_CONST),
1323
        SD_BUS_PROPERTY("ExecSearchPath", "as", NULL, offsetof(ExecContext, exec_search_path), SD_BUS_VTABLE_PROPERTY_CONST),
1324
        SD_BUS_PROPERTY("MountFlags", "t", bus_property_get_ulong, offsetof(ExecContext, mount_propagation_flag), SD_BUS_VTABLE_PROPERTY_CONST),
1325
        SD_BUS_PROPERTY("PrivateTmp", "b", property_get_private_tmp, offsetof(ExecContext, private_tmp), SD_BUS_VTABLE_PROPERTY_CONST),
1326
        SD_BUS_PROPERTY("PrivateTmpEx", "s", property_get_private_tmp_ex, offsetof(ExecContext, private_tmp), SD_BUS_VTABLE_PROPERTY_CONST),
1327
        SD_BUS_PROPERTY("PrivateDevices", "b", bus_property_get_bool, offsetof(ExecContext, private_devices), SD_BUS_VTABLE_PROPERTY_CONST),
1328
        SD_BUS_PROPERTY("ProtectClock", "b", bus_property_get_bool, offsetof(ExecContext, protect_clock), SD_BUS_VTABLE_PROPERTY_CONST),
1329
        SD_BUS_PROPERTY("ProtectKernelTunables", "b", bus_property_get_bool, offsetof(ExecContext, protect_kernel_tunables), SD_BUS_VTABLE_PROPERTY_CONST),
1330
        SD_BUS_PROPERTY("ProtectKernelModules", "b", bus_property_get_bool, offsetof(ExecContext, protect_kernel_modules), SD_BUS_VTABLE_PROPERTY_CONST),
1331
        SD_BUS_PROPERTY("ProtectKernelLogs", "b", bus_property_get_bool, offsetof(ExecContext, protect_kernel_logs), SD_BUS_VTABLE_PROPERTY_CONST),
1332
        SD_BUS_PROPERTY("ProtectControlGroups", "b", property_get_protect_control_groups, offsetof(ExecContext, protect_control_groups), SD_BUS_VTABLE_PROPERTY_CONST),
1333
        SD_BUS_PROPERTY("ProtectControlGroupsEx", "s", property_get_protect_control_groups_ex, offsetof(ExecContext, protect_control_groups), SD_BUS_VTABLE_PROPERTY_CONST),
1334
        SD_BUS_PROPERTY("PrivateNetwork", "b", bus_property_get_bool, offsetof(ExecContext, private_network), SD_BUS_VTABLE_PROPERTY_CONST),
1335
        SD_BUS_PROPERTY("PrivateUsers", "b", property_get_private_users, offsetof(ExecContext, private_users), SD_BUS_VTABLE_PROPERTY_CONST),
1336
        SD_BUS_PROPERTY("PrivateUsersEx", "s", property_get_private_users_ex, offsetof(ExecContext, private_users), SD_BUS_VTABLE_PROPERTY_CONST),
1337
        SD_BUS_PROPERTY("PrivateMounts", "b", bus_property_get_tristate, offsetof(ExecContext, private_mounts), SD_BUS_VTABLE_PROPERTY_CONST),
1338
        SD_BUS_PROPERTY("PrivateIPC", "b", bus_property_get_bool, offsetof(ExecContext, private_ipc), SD_BUS_VTABLE_PROPERTY_CONST),
1339
        SD_BUS_PROPERTY("PrivatePIDs", "s", property_get_private_pids, offsetof(ExecContext, private_pids), SD_BUS_VTABLE_PROPERTY_CONST),
1340
        SD_BUS_PROPERTY("ProtectHome", "s", property_get_protect_home, offsetof(ExecContext, protect_home), SD_BUS_VTABLE_PROPERTY_CONST),
1341
        SD_BUS_PROPERTY("ProtectSystem", "s", property_get_protect_system, offsetof(ExecContext, protect_system), SD_BUS_VTABLE_PROPERTY_CONST),
1342
        SD_BUS_PROPERTY("SameProcessGroup", "b", bus_property_get_bool, offsetof(ExecContext, same_pgrp), SD_BUS_VTABLE_PROPERTY_CONST),
1343
        SD_BUS_PROPERTY("UtmpIdentifier", "s", NULL, offsetof(ExecContext, utmp_id), SD_BUS_VTABLE_PROPERTY_CONST),
1344
        SD_BUS_PROPERTY("UtmpMode", "s", property_get_exec_utmp_mode, offsetof(ExecContext, utmp_mode), SD_BUS_VTABLE_PROPERTY_CONST),
1345
        SD_BUS_PROPERTY("SELinuxContext", "(bs)", property_get_selinux_context, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1346
        SD_BUS_PROPERTY("AppArmorProfile", "(bs)", property_get_apparmor_profile, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1347
        SD_BUS_PROPERTY("SmackProcessLabel", "(bs)", property_get_smack_process_label, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1348
        SD_BUS_PROPERTY("IgnoreSIGPIPE", "b", bus_property_get_bool, offsetof(ExecContext, ignore_sigpipe), SD_BUS_VTABLE_PROPERTY_CONST),
1349
        SD_BUS_PROPERTY("NoNewPrivileges", "b", bus_property_get_bool, offsetof(ExecContext, no_new_privileges), SD_BUS_VTABLE_PROPERTY_CONST),
1350
        SD_BUS_PROPERTY("SystemCallFilter", "(bas)", property_get_syscall_filter, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1351
        SD_BUS_PROPERTY("SystemCallArchitectures", "as", property_get_syscall_archs, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1352
        SD_BUS_PROPERTY("SystemCallErrorNumber", "i", bus_property_get_int, offsetof(ExecContext, syscall_errno), SD_BUS_VTABLE_PROPERTY_CONST),
1353
        SD_BUS_PROPERTY("SystemCallLog", "(bas)", property_get_syscall_log, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1354
        SD_BUS_PROPERTY("Personality", "s", property_get_personality, offsetof(ExecContext, personality), SD_BUS_VTABLE_PROPERTY_CONST),
1355
        SD_BUS_PROPERTY("LockPersonality", "b", bus_property_get_bool, offsetof(ExecContext, lock_personality), SD_BUS_VTABLE_PROPERTY_CONST),
1356
        SD_BUS_PROPERTY("RestrictAddressFamilies", "(bas)", property_get_address_families, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1357
        SD_BUS_PROPERTY("RuntimeDirectorySymlink", "a(sst)", property_get_exec_dir_symlink, offsetof(ExecContext, directories[EXEC_DIRECTORY_RUNTIME]), SD_BUS_VTABLE_PROPERTY_CONST),
1358
        SD_BUS_PROPERTY("RuntimeDirectoryPreserve", "s", bus_property_get_exec_preserve_mode, offsetof(ExecContext, runtime_directory_preserve_mode), SD_BUS_VTABLE_PROPERTY_CONST),
1359
        SD_BUS_PROPERTY("RuntimeDirectoryMode", "u", bus_property_get_mode, offsetof(ExecContext, directories[EXEC_DIRECTORY_RUNTIME].mode), SD_BUS_VTABLE_PROPERTY_CONST),
1360
        SD_BUS_PROPERTY("RuntimeDirectory", "as", property_get_exec_dir, offsetof(ExecContext, directories[EXEC_DIRECTORY_RUNTIME]), SD_BUS_VTABLE_PROPERTY_CONST),
1361
        SD_BUS_PROPERTY("StateDirectorySymlink", "a(sst)", property_get_exec_dir_symlink, offsetof(ExecContext, directories[EXEC_DIRECTORY_STATE]), SD_BUS_VTABLE_PROPERTY_CONST),
1362
        SD_BUS_PROPERTY("StateDirectoryMode", "u", bus_property_get_mode, offsetof(ExecContext, directories[EXEC_DIRECTORY_STATE].mode), SD_BUS_VTABLE_PROPERTY_CONST),
1363
        SD_BUS_PROPERTY("StateDirectoryAccounting", "b", bus_property_get_bool, offsetof(ExecContext, directories[EXEC_DIRECTORY_STATE].exec_quota.quota_accounting), SD_BUS_VTABLE_PROPERTY_CONST),
1364
        SD_BUS_PROPERTY("StateDirectoryQuota", "(tus)", property_get_exec_quota, offsetof(ExecContext, directories[EXEC_DIRECTORY_STATE].exec_quota), SD_BUS_VTABLE_PROPERTY_CONST),
1365
        SD_BUS_PROPERTY("StateDirectory", "as", property_get_exec_dir, offsetof(ExecContext, directories[EXEC_DIRECTORY_STATE]), SD_BUS_VTABLE_PROPERTY_CONST),
1366
        SD_BUS_PROPERTY("CacheDirectorySymlink", "a(sst)", property_get_exec_dir_symlink, offsetof(ExecContext, directories[EXEC_DIRECTORY_CACHE]), SD_BUS_VTABLE_PROPERTY_CONST),
1367
        SD_BUS_PROPERTY("CacheDirectoryMode", "u", bus_property_get_mode, offsetof(ExecContext, directories[EXEC_DIRECTORY_CACHE].mode), SD_BUS_VTABLE_PROPERTY_CONST),
1368
        SD_BUS_PROPERTY("CacheDirectoryAccounting", "b", bus_property_get_bool, offsetof(ExecContext, directories[EXEC_DIRECTORY_CACHE].exec_quota.quota_accounting), SD_BUS_VTABLE_PROPERTY_CONST),
1369
        SD_BUS_PROPERTY("CacheDirectoryQuota", "(tus)", property_get_exec_quota, offsetof(ExecContext, directories[EXEC_DIRECTORY_CACHE].exec_quota), SD_BUS_VTABLE_PROPERTY_CONST),
1370
        SD_BUS_PROPERTY("CacheDirectory", "as", property_get_exec_dir, offsetof(ExecContext, directories[EXEC_DIRECTORY_CACHE]), SD_BUS_VTABLE_PROPERTY_CONST),
1371
        SD_BUS_PROPERTY("LogsDirectorySymlink", "a(sst)", property_get_exec_dir_symlink, offsetof(ExecContext, directories[EXEC_DIRECTORY_LOGS]), SD_BUS_VTABLE_PROPERTY_CONST),
1372
        SD_BUS_PROPERTY("LogsDirectoryMode", "u", bus_property_get_mode, offsetof(ExecContext, directories[EXEC_DIRECTORY_LOGS].mode), SD_BUS_VTABLE_PROPERTY_CONST),
1373
        SD_BUS_PROPERTY("LogsDirectoryAccounting", "b", bus_property_get_bool, offsetof(ExecContext, directories[EXEC_DIRECTORY_LOGS].exec_quota.quota_accounting), SD_BUS_VTABLE_PROPERTY_CONST),
1374
        SD_BUS_PROPERTY("LogsDirectoryQuota", "(tus)", property_get_exec_quota, offsetof(ExecContext, directories[EXEC_DIRECTORY_LOGS].exec_quota), SD_BUS_VTABLE_PROPERTY_CONST),
1375
        SD_BUS_PROPERTY("LogsDirectory", "as", property_get_exec_dir, offsetof(ExecContext, directories[EXEC_DIRECTORY_LOGS]), SD_BUS_VTABLE_PROPERTY_CONST),
1376
        SD_BUS_PROPERTY("ConfigurationDirectoryMode", "u", bus_property_get_mode, offsetof(ExecContext, directories[EXEC_DIRECTORY_CONFIGURATION].mode), SD_BUS_VTABLE_PROPERTY_CONST),
1377
        SD_BUS_PROPERTY("ConfigurationDirectory", "as", property_get_exec_dir, offsetof(ExecContext, directories[EXEC_DIRECTORY_CONFIGURATION]), SD_BUS_VTABLE_PROPERTY_CONST),
1378
        SD_BUS_PROPERTY("TimeoutCleanUSec", "t", bus_property_get_usec, offsetof(ExecContext, timeout_clean_usec), SD_BUS_VTABLE_PROPERTY_CONST),
1379
        SD_BUS_PROPERTY("MemoryDenyWriteExecute", "b", bus_property_get_bool, offsetof(ExecContext, memory_deny_write_execute), SD_BUS_VTABLE_PROPERTY_CONST),
1380
        SD_BUS_PROPERTY("RestrictRealtime", "b", bus_property_get_bool, offsetof(ExecContext, restrict_realtime), SD_BUS_VTABLE_PROPERTY_CONST),
1381
        SD_BUS_PROPERTY("RestrictSUIDSGID", "b", bus_property_get_bool, offsetof(ExecContext, restrict_suid_sgid), SD_BUS_VTABLE_PROPERTY_CONST),
1382
        SD_BUS_PROPERTY("RestrictNamespaces", "t", bus_property_get_ulong, offsetof(ExecContext, restrict_namespaces), SD_BUS_VTABLE_PROPERTY_CONST),
1383
        SD_BUS_PROPERTY("DelegateNamespaces", "t", bus_property_get_ulong, offsetof(ExecContext, delegate_namespaces), SD_BUS_VTABLE_PROPERTY_CONST),
1384
        SD_BUS_PROPERTY("RestrictFileSystems", "(bas)", property_get_restrict_filesystems, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1385
        SD_BUS_PROPERTY("BindPaths", "a(ssbt)", property_get_bind_paths, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1386
        SD_BUS_PROPERTY("BindReadOnlyPaths", "a(ssbt)", property_get_bind_paths, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1387
        SD_BUS_PROPERTY("TemporaryFileSystem", "a(ss)", property_get_temporary_filesystems, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1388
        SD_BUS_PROPERTY("MountAPIVFS", "b", property_get_mount_apivfs, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1389
        SD_BUS_PROPERTY("BindLogSockets", "b", property_get_bind_log_sockets, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1390
        SD_BUS_PROPERTY("KeyringMode", "s", property_get_exec_keyring_mode, offsetof(ExecContext, keyring_mode), SD_BUS_VTABLE_PROPERTY_CONST),
1391
        SD_BUS_PROPERTY("ProtectProc", "s", property_get_protect_proc, offsetof(ExecContext, protect_proc), SD_BUS_VTABLE_PROPERTY_CONST),
1392
        SD_BUS_PROPERTY("ProcSubset", "s", property_get_proc_subset, offsetof(ExecContext, proc_subset), SD_BUS_VTABLE_PROPERTY_CONST),
1393
        SD_BUS_PROPERTY("ProtectHostname", "b", property_get_protect_hostname, offsetof(ExecContext, protect_hostname), SD_BUS_VTABLE_PROPERTY_CONST),
1394
        SD_BUS_PROPERTY("ProtectHostnameEx", "(ss)", property_get_protect_hostname_ex, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1395
        SD_BUS_PROPERTY("PrivateBPF", "s", property_get_private_bpf, offsetof(ExecContext, private_bpf), SD_BUS_VTABLE_PROPERTY_CONST),
1396
        SD_BUS_PROPERTY("BPFDelegateCommands", "s", property_get_bpf_delegate_commands, offsetof(ExecContext, bpf_delegate_commands), SD_BUS_VTABLE_PROPERTY_CONST),
1397
        SD_BUS_PROPERTY("BPFDelegateMaps", "s", property_get_bpf_delegate_maps, offsetof(ExecContext, bpf_delegate_maps), SD_BUS_VTABLE_PROPERTY_CONST),
1398
        SD_BUS_PROPERTY("BPFDelegatePrograms", "s", property_get_bpf_delegate_programs, offsetof(ExecContext, bpf_delegate_programs), SD_BUS_VTABLE_PROPERTY_CONST),
1399
        SD_BUS_PROPERTY("BPFDelegateAttachments", "s", property_get_bpf_delegate_attachments, offsetof(ExecContext, bpf_delegate_attachments), SD_BUS_VTABLE_PROPERTY_CONST),
1400
        SD_BUS_PROPERTY("MemoryKSM", "b", bus_property_get_tristate, offsetof(ExecContext, memory_ksm), SD_BUS_VTABLE_PROPERTY_CONST),
1401
        SD_BUS_PROPERTY("MemoryTHP", "s", property_get_memory_thp, offsetof(ExecContext, memory_thp), SD_BUS_VTABLE_PROPERTY_CONST),
1402
        SD_BUS_PROPERTY("UserNamespacePath", "s", NULL, offsetof(ExecContext, user_namespace_path), SD_BUS_VTABLE_PROPERTY_CONST),
1403
        SD_BUS_PROPERTY("NetworkNamespacePath", "s", NULL, offsetof(ExecContext, network_namespace_path), SD_BUS_VTABLE_PROPERTY_CONST),
1404
        SD_BUS_PROPERTY("IPCNamespacePath", "s", NULL, offsetof(ExecContext, ipc_namespace_path), SD_BUS_VTABLE_PROPERTY_CONST),
1405
        SD_BUS_PROPERTY("RootImagePolicy", "s", property_get_image_policy, offsetof(ExecContext, root_image_policy), SD_BUS_VTABLE_PROPERTY_CONST),
1406
        SD_BUS_PROPERTY("MountImagePolicy", "s", property_get_image_policy, offsetof(ExecContext, mount_image_policy), SD_BUS_VTABLE_PROPERTY_CONST),
1407
        SD_BUS_PROPERTY("ExtensionImagePolicy", "s", property_get_image_policy, offsetof(ExecContext, extension_image_policy), SD_BUS_VTABLE_PROPERTY_CONST),
1408

1409
        /* Obsolete/redundant properties: */
1410
        SD_BUS_PROPERTY("Capabilities", "s", property_get_empty_string, 0, SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN),
1411
        SD_BUS_PROPERTY("ReadWriteDirectories", "as", NULL, offsetof(ExecContext, read_write_paths), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN),
1412
        SD_BUS_PROPERTY("ReadOnlyDirectories", "as", NULL, offsetof(ExecContext, read_only_paths), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN),
1413
        SD_BUS_PROPERTY("InaccessibleDirectories", "as", NULL, offsetof(ExecContext, inaccessible_paths), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN),
1414
        SD_BUS_PROPERTY("IOScheduling", "i", property_get_ioprio, 0, SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN),
1415

1416
        SD_BUS_VTABLE_END
1417
};
1418

1419
static int property_get_quota_usage(
8,406✔
1420
                sd_bus *bus,
1421
                const char *path,
1422
                const char *interface,
1423
                const char *property,
1424
                sd_bus_message *reply,
1425
                void *userdata,
1426
                sd_bus_error *reterr_error) {
1427

1428
        Unit *u = ASSERT_PTR(userdata);
8,406✔
1429
        ExecContext *c = ASSERT_PTR(unit_get_exec_context(u));
8,406✔
1430
        uint64_t current_usage_bytes = UINT64_MAX, limit_bytes = UINT64_MAX;
8,406✔
1431
        int r;
8,406✔
1432

1433
        assert(bus);
8,406✔
1434
        assert(reply);
8,406✔
1435

1436
        ExecDirectoryType dt;
8,406✔
1437
        if (streq(property, "StateDirectoryQuotaUsage"))
8,406✔
1438
                dt = EXEC_DIRECTORY_STATE;
1439
        else if (streq(property, "CacheDirectoryQuotaUsage"))
5,604✔
1440
                dt = EXEC_DIRECTORY_CACHE;
1441
        else if (streq(property, "LogsDirectoryQuotaUsage"))
2,802✔
1442
                dt = EXEC_DIRECTORY_LOGS;
1443
        else
1444
                assert_not_reached();
×
1445

1446
        const QuotaLimit *q;
8,406✔
1447
        q = &c->directories[dt].exec_quota;
8,406✔
1448

1449
        if (q->quota_enforce || q->quota_accounting) {
8,406✔
1450
                r = unit_get_exec_quota_stats(u, c, dt, &current_usage_bytes, &limit_bytes);
×
1451
                if (r < 0)
×
1452
                        return r;
8,406✔
1453
        }
1454

1455
        if (!q->quota_enforce)
8,406✔
1456
                limit_bytes = UINT64_MAX;
8,406✔
1457
        if (!q->quota_accounting)
8,406✔
1458
                current_usage_bytes = UINT64_MAX;
8,406✔
1459

1460
        return sd_bus_message_append(reply, "(tt)", current_usage_bytes, limit_bytes);
8,406✔
1461
}
1462

1463
const sd_bus_vtable bus_unit_exec_vtable[] = {
1464
        SD_BUS_VTABLE_START(0),
1465

1466
        SD_BUS_PROPERTY("StateDirectoryQuotaUsage", "(tt)", property_get_quota_usage, 0, 0),
1467
        SD_BUS_PROPERTY("CacheDirectoryQuotaUsage", "(tt)", property_get_quota_usage, 0, 0),
1468
        SD_BUS_PROPERTY("LogsDirectoryQuotaUsage", "(tt)", property_get_quota_usage, 0, 0),
1469

1470
        SD_BUS_VTABLE_END
1471
};
1472

1473
static int append_exec_command(sd_bus_message *reply, ExecCommand *c) {
3,100✔
1474
        int r;
3,100✔
1475

1476
        assert(reply);
3,100✔
1477
        assert(c);
3,100✔
1478

1479
        if (!c->path)
3,100✔
1480
                return 0;
1481

1482
        r = sd_bus_message_open_container(reply, 'r', "sasbttttuii");
2,948✔
1483
        if (r < 0)
2,948✔
1484
                return r;
1485

1486
        r = sd_bus_message_append(reply, "s", c->path);
2,948✔
1487
        if (r < 0)
2,948✔
1488
                return r;
1489

1490
        r = sd_bus_message_append_strv(reply, c->argv);
2,948✔
1491
        if (r < 0)
2,948✔
1492
                return r;
1493

1494
        r = sd_bus_message_append(reply, "bttttuii",
5,896✔
1495
                                  !!(c->flags & EXEC_COMMAND_IGNORE_FAILURE),
2,948✔
1496
                                  c->exec_status.start_timestamp.realtime,
1497
                                  c->exec_status.start_timestamp.monotonic,
1498
                                  c->exec_status.exit_timestamp.realtime,
1499
                                  c->exec_status.exit_timestamp.monotonic,
1500
                                  (uint32_t) c->exec_status.pid,
2,948✔
1501
                                  (int32_t) c->exec_status.code,
1502
                                  (int32_t) c->exec_status.status);
1503
        if (r < 0)
2,948✔
1504
                return r;
1505

1506
        return sd_bus_message_close_container(reply);
2,948✔
1507
}
1508

1509
static int append_exec_ex_command(sd_bus_message *reply, ExecCommand *c) {
2,944✔
1510
        _cleanup_strv_free_ char **ex_opts = NULL;
2,944✔
1511
        int r;
2,944✔
1512

1513
        assert(reply);
2,944✔
1514
        assert(c);
2,944✔
1515

1516
        if (!c->path)
2,944✔
1517
                return 0;
1518

1519
        r = sd_bus_message_open_container(reply, 'r', "sasasttttuii");
2,944✔
1520
        if (r < 0)
2,944✔
1521
                return r;
1522

1523
        r = sd_bus_message_append(reply, "s", c->path);
2,944✔
1524
        if (r < 0)
2,944✔
1525
                return r;
1526

1527
        r = sd_bus_message_append_strv(reply, c->argv);
2,944✔
1528
        if (r < 0)
2,944✔
1529
                return r;
1530

1531
        r = exec_command_flags_to_strv(c->flags, &ex_opts);
2,944✔
1532
        if (r < 0)
2,944✔
1533
                return r;
1534

1535
        r = sd_bus_message_append_strv(reply, ex_opts);
2,944✔
1536
        if (r < 0)
2,944✔
1537
                return r;
1538

1539
        r = sd_bus_message_append(reply, "ttttuii",
5,888✔
1540
                                  c->exec_status.start_timestamp.realtime,
1541
                                  c->exec_status.start_timestamp.monotonic,
1542
                                  c->exec_status.exit_timestamp.realtime,
1543
                                  c->exec_status.exit_timestamp.monotonic,
1544
                                  (uint32_t) c->exec_status.pid,
2,944✔
1545
                                  (int32_t) c->exec_status.code,
1546
                                  (int32_t) c->exec_status.status);
1547
        if (r < 0)
2,944✔
1548
                return r;
1549

1550
        return sd_bus_message_close_container(reply);
2,944✔
1551
}
1552

1553
int bus_property_get_exec_command(
156✔
1554
                sd_bus *bus,
1555
                const char *path,
1556
                const char *interface,
1557
                const char *property,
1558
                sd_bus_message *reply,
1559
                void *userdata,
1560
                sd_bus_error *reterr_error) {
1561

1562
        ExecCommand *c = (ExecCommand*) userdata;
156✔
1563
        int r;
156✔
1564

1565
        assert(bus);
156✔
1566
        assert(reply);
156✔
1567

1568
        r = sd_bus_message_open_container(reply, 'a', "(sasbttttuii)");
156✔
1569
        if (r < 0)
156✔
1570
                return r;
1571

1572
        r = append_exec_command(reply, c);
156✔
1573
        if (r < 0)
156✔
1574
                return r;
1575

1576
        return sd_bus_message_close_container(reply);
156✔
1577
}
1578

1579
int bus_property_get_exec_command_list(
21,664✔
1580
                sd_bus *bus,
1581
                const char *path,
1582
                const char *interface,
1583
                const char *property,
1584
                sd_bus_message *reply,
1585
                void *userdata,
1586
                sd_bus_error *reterr_error) {
1587

1588
        ExecCommand *exec_command = *(ExecCommand**) userdata;
21,664✔
1589
        int r;
21,664✔
1590

1591
        assert(bus);
21,664✔
1592
        assert(reply);
21,664✔
1593

1594
        r = sd_bus_message_open_container(reply, 'a', "(sasbttttuii)");
21,664✔
1595
        if (r < 0)
21,664✔
1596
                return r;
1597

1598
        LIST_FOREACH(command, c, exec_command) {
24,608✔
1599
                r = append_exec_command(reply, c);
2,944✔
1600
                if (r < 0)
2,944✔
1601
                        return r;
1602
        }
1603

1604
        return sd_bus_message_close_container(reply);
21,664✔
1605
}
1606

1607
int bus_property_get_exec_ex_command_list(
21,328✔
1608
                sd_bus *bus,
1609
                const char *path,
1610
                const char *interface,
1611
                const char *property,
1612
                sd_bus_message *reply,
1613
                void *userdata,
1614
                sd_bus_error *reterr_error) {
1615

1616
        ExecCommand *exec_command = *(ExecCommand**) userdata;
21,328✔
1617
        int r;
21,328✔
1618

1619
        assert(bus);
21,328✔
1620
        assert(reply);
21,328✔
1621

1622
        r = sd_bus_message_open_container(reply, 'a', "(sasasttttuii)");
21,328✔
1623
        if (r < 0)
21,328✔
1624
                return r;
1625

1626
        LIST_FOREACH(command, c, exec_command) {
24,272✔
1627
                r = append_exec_ex_command(reply, c);
2,944✔
1628
                if (r < 0)
2,944✔
1629
                        return r;
1630
        }
1631

1632
        return sd_bus_message_close_container(reply);
21,328✔
1633
}
1634

1635
static char* exec_command_flags_to_exec_chars(ExecCommandFlags flags) {
309✔
1636
        return strjoin(FLAGS_SET(flags, EXEC_COMMAND_IGNORE_FAILURE)   ? "-" : "",
1,765✔
1637
                       FLAGS_SET(flags, EXEC_COMMAND_NO_ENV_EXPAND)    ? ":" : "",
1638
                       FLAGS_SET(flags, EXEC_COMMAND_FULLY_PRIVILEGED) ? "+" : "",
1639
                       FLAGS_SET(flags, EXEC_COMMAND_NO_SETUID)        ? "!" : "",
1640
                       FLAGS_SET(flags, EXEC_COMMAND_VIA_SHELL)        ? "|" : "");
1641
}
1642

1643
int bus_set_transient_exec_command(
618✔
1644
                Unit *u,
1645
                const char *name,
1646
                ExecCommand **exec_command,
1647
                sd_bus_message *message,
1648
                UnitWriteFlags flags,
1649
                sd_bus_error *reterr_error) {
1650

1651
        const char *ex_prop = endswith(ASSERT_PTR(name), "Ex");
618✔
1652
        size_t n = 0;
618✔
1653
        int r;
618✔
1654

1655
        assert(u);
618✔
1656
        assert(exec_command);
618✔
1657
        assert(message);
618✔
1658
        assert(reterr_error);
618✔
1659

1660
        /* Drop Ex from the written setting. E.g. ExecStart=, not ExecStartEx=. */
1661
        const char *written_name = ex_prop ? strndupa_safe(name, ex_prop - name) : name;
618✔
1662

1663
        r = sd_bus_message_enter_container(message, 'a', ex_prop ? "(sasas)" : "(sasb)");
618✔
1664
        if (r < 0)
618✔
1665
                return r;
1666

1667
        while ((r = sd_bus_message_enter_container(message, 'r', ex_prop ? "sasas" : "sasb")) > 0) {
2,148✔
1668
                _cleanup_strv_free_ char **argv = NULL;
×
1669
                const char *path;
618✔
1670
                ExecCommandFlags command_flags;
618✔
1671

1672
                r = sd_bus_message_read(message, "s", &path);
618✔
1673
                if (r < 0)
618✔
1674
                        return r;
1675

1676
                r = sd_bus_message_read_strv(message, &argv);
618✔
1677
                if (r < 0)
618✔
1678
                        return r;
1679

1680
                if (ex_prop) {
618✔
1681
                        _cleanup_strv_free_ char **ex_opts = NULL;
162✔
1682

1683
                        r = sd_bus_message_read_strv(message, &ex_opts);
162✔
1684
                        if (r < 0)
162✔
1685
                                return r;
1686

1687
                        r = exec_command_flags_from_strv(ex_opts, &command_flags);
162✔
1688
                        if (r < 0)
162✔
1689
                                return r;
1690
                } else {
1691
                        int b;
456✔
1692

1693
                        r = sd_bus_message_read(message, "b", &b);
456✔
1694
                        if (r < 0)
456✔
1695
                                return r;
×
1696

1697
                        command_flags = b ? EXEC_COMMAND_IGNORE_FAILURE : 0;
456✔
1698
                }
1699

1700
                if (!FLAGS_SET(command_flags, EXEC_COMMAND_VIA_SHELL)) {
618✔
1701
                        if (!filename_or_absolute_path_is_valid(path))
604✔
1702
                                return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS,
×
1703
                                                         "\"%s\" is neither a valid executable name nor an absolute path",
1704
                                                         path);
1705

1706
                        if (strv_isempty(argv))
604✔
1707
                                return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS,
×
1708
                                                         "\"%s\" argv cannot be empty", name);
1709
                } else {
1710
                        /* Always normalize path and argv0 to be "sh" */
1711
                        path = _PATH_BSHELL;
14✔
1712

1713
                        if (strv_isempty(argv))
14✔
1714
                                r = strv_extend(&argv, "sh");
×
1715
                        else
1716
                                r = free_and_strdup(&argv[0], argv[0][0] == '-' ? "-sh" : "sh");
14✔
1717
                        if (r < 0)
14✔
1718
                                return r;
1719
                }
1720

1721
                r = sd_bus_message_exit_container(message);
618✔
1722
                if (r < 0)
618✔
1723
                        return r;
1724

1725
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
618✔
1726
                        _cleanup_(exec_command_freep) ExecCommand *c = NULL;
309✔
1727

1728
                        c = new(ExecCommand, 1);
309✔
1729
                        if (!c)
309✔
1730
                                return -ENOMEM;
1731

1732
                        *c = (ExecCommand) {
309✔
1733
                                .argv = TAKE_PTR(argv),
309✔
1734
                                .flags = command_flags,
1735
                        };
1736

1737
                        r = path_simplify_alloc(path, &c->path);
309✔
1738
                        if (r < 0)
309✔
1739
                                return r;
1740

1741
                        exec_command_append_list(exec_command, TAKE_PTR(c));
309✔
1742
                }
1743

1744
                n++;
618✔
1745
        }
1746
        if (r < 0)
618✔
1747
                return r;
1748

1749
        r = sd_bus_message_exit_container(message);
618✔
1750
        if (r < 0)
618✔
1751
                return r;
1752

1753
        if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
618✔
1754
                _cleanup_(memstream_done) MemStream m = {};
×
1755
                _cleanup_free_ char *buf = NULL;
309✔
1756
                FILE *f;
309✔
1757

1758
                if (n == 0)
309✔
1759
                        *exec_command = exec_command_free_list(*exec_command);
×
1760

1761
                f = memstream_init(&m);
309✔
1762
                if (!f)
309✔
1763
                        return -ENOMEM;
1764

1765
                fprintf(f, "%s=\n", written_name);
309✔
1766

1767
                LIST_FOREACH(command, c, *exec_command) {
618✔
1768
                        _cleanup_free_ char *a = NULL, *exec_chars = NULL;
309✔
1769
                        UnitWriteFlags esc_flags = UNIT_ESCAPE_SPECIFIERS |
228✔
1770
                                (FLAGS_SET(c->flags, EXEC_COMMAND_NO_ENV_EXPAND) ? UNIT_ESCAPE_EXEC_SYNTAX : UNIT_ESCAPE_EXEC_SYNTAX_ENV);
309✔
1771
                        bool via_shell = FLAGS_SET(c->flags, EXEC_COMMAND_VIA_SHELL);
309✔
1772

1773
                        exec_chars = exec_command_flags_to_exec_chars(c->flags);
309✔
1774
                        if (!exec_chars)
309✔
1775
                                return -ENOMEM;
1776

1777
                        a = unit_concat_strv(via_shell ? strv_skip(c->argv, 1) : c->argv, esc_flags);
309✔
1778
                        if (!a)
309✔
1779
                                return -ENOMEM;
1780

1781
                        if (via_shell || streq(c->path, c->argv[0]))
309✔
1782
                                fprintf(f, "%s=%s%s%s\n",
309✔
1783
                                        written_name, exec_chars, via_shell && c->argv[0][0] == '-' ? "@" : "", a);
7✔
1784
                        else {
1785
                                _cleanup_free_ char *t = NULL;
×
1786
                                const char *p;
×
1787

1788
                                p = unit_escape_setting(c->path, esc_flags, &t);
×
1789
                                if (!p)
×
1790
                                        return -ENOMEM;
×
1791

1792
                                fprintf(f, "%s=%s@%s %s\n", written_name, exec_chars, p, a);
×
1793
                        }
1794
                }
1795

1796
                r = memstream_finalize(&m, &buf, NULL);
309✔
1797
                if (r < 0)
309✔
1798
                        return r;
1799

1800
                unit_write_setting(u, flags, written_name, buf);
309✔
1801
        }
1802

1803
        return 1;
1804
}
1805

1806
static int parse_personality(const char *s, unsigned long *p) {
×
1807
        unsigned long v;
×
1808

1809
        assert(p);
×
1810

1811
        v = personality_from_string(s);
×
1812
        if (v == PERSONALITY_INVALID)
×
1813
                return -EINVAL;
1814

1815
        *p = v;
×
1816
        return 0;
×
1817
}
1818

1819
static const char* mount_propagation_flag_to_string_with_check(unsigned long n) {
2✔
1820
        if (!mount_propagation_flag_is_valid(n))
2✔
1821
                return NULL;
1822

1823
        return mount_propagation_flag_to_string(n);
2✔
1824
}
1825

1826
static BUS_DEFINE_SET_TRANSIENT(nsec, "t", uint64_t, nsec_t, NSEC_FMT);
×
1827
static BUS_DEFINE_SET_TRANSIENT_IS_VALID(log_level, "i", int32_t, int, "%" PRIi32, log_level_is_valid);
×
1828
#if HAVE_SECCOMP
1829
static BUS_DEFINE_SET_TRANSIENT_IS_VALID(errno, "i", int32_t, int, "%" PRIi32, seccomp_errno_or_action_is_valid);
×
1830
#endif
1831
static BUS_DEFINE_SET_TRANSIENT_PARSE(std_input, ExecInput, exec_input_from_string);
×
1832
static BUS_DEFINE_SET_TRANSIENT_PARSE(std_output, ExecOutput, exec_output_from_string);
60✔
1833
static BUS_DEFINE_SET_TRANSIENT_PARSE(utmp_mode, ExecUtmpMode, exec_utmp_mode_from_string);
×
1834
static BUS_DEFINE_SET_TRANSIENT_PARSE(protect_system, ProtectSystem, protect_system_from_string);
2✔
1835
static BUS_DEFINE_SET_TRANSIENT_PARSE(protect_home, ProtectHome, protect_home_from_string);
6✔
1836
static BUS_DEFINE_SET_TRANSIENT_PARSE(keyring_mode, ExecKeyringMode, exec_keyring_mode_from_string);
×
1837
static BUS_DEFINE_SET_TRANSIENT_PARSE(protect_proc, ProtectProc, protect_proc_from_string);
14✔
1838
static BUS_DEFINE_SET_TRANSIENT_PARSE(proc_subset, ProcSubset, proc_subset_from_string);
6✔
1839
static BUS_DEFINE_SET_TRANSIENT_PARSE(private_bpf, PrivateBPF, private_bpf_from_string);
×
1840
static BUS_DEFINE_SET_TRANSIENT_PARSE_PTR(bpf_delegate_commands, uint64_t, bpf_delegate_commands_from_string);
×
1841
static BUS_DEFINE_SET_TRANSIENT_PARSE_PTR(bpf_delegate_maps, uint64_t, bpf_delegate_maps_from_string);
×
1842
static BUS_DEFINE_SET_TRANSIENT_PARSE_PTR(bpf_delegate_programs, uint64_t, bpf_delegate_programs_from_string);
×
1843
static BUS_DEFINE_SET_TRANSIENT_PARSE_PTR(bpf_delegate_attachments, uint64_t, bpf_delegate_attachments_from_string);
×
1844
static BUS_DEFINE_SET_TRANSIENT_PARSE(memory_thp, MemoryTHP, memory_thp_from_string);
×
1845
BUS_DEFINE_SET_TRANSIENT_PARSE(exec_preserve_mode, ExecPreserveMode, exec_preserve_mode_from_string);
10✔
1846
static BUS_DEFINE_SET_TRANSIENT_PARSE_PTR(personality, unsigned long, parse_personality);
×
1847
static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(secure_bits, "i", int32_t, int, "%" PRIi32, secure_bits_to_string_alloc_with_check);
×
1848
static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(capability, "t", uint64_t, uint64_t, "%" PRIu64, capability_set_to_string);
14✔
1849
static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(namespace_flag, "t", uint64_t, unsigned long, "%" PRIu64, namespace_flags_to_string);
18✔
1850
static BUS_DEFINE_SET_TRANSIENT_TO_STRING(mount_propagation_flag, "t", uint64_t, unsigned long, "%" PRIu64, mount_propagation_flag_to_string_with_check);
2✔
1851

1852
int bus_exec_context_set_transient_property(
3,693✔
1853
                Unit *u,
1854
                ExecContext *c,
1855
                const char *name,
1856
                sd_bus_message *message,
1857
                UnitWriteFlags flags,
1858
                sd_bus_error *reterr_error) {
1859

1860
        const char *suffix;
3,693✔
1861
        int r;
3,693✔
1862

1863
        assert(u);
3,693✔
1864
        assert(c);
3,693✔
1865
        assert(name);
3,693✔
1866
        assert(message);
3,693✔
1867

1868
        flags |= UNIT_PRIVATE;
3,693✔
1869

1870
        if (streq(name, "User"))
3,693✔
1871
                return bus_set_transient_user_relaxed(u, name, &c->user, message, flags, reterr_error);
112✔
1872

1873
        if (streq(name, "Group"))
3,581✔
1874
                return bus_set_transient_user_relaxed(u, name, &c->group, message, flags, reterr_error);
14✔
1875

1876
        if (streq(name, "SetLoginEnvironment"))
3,567✔
1877
                return bus_set_transient_tristate(u, name, &c->set_login_environment, message, flags, reterr_error);
×
1878

1879
        if (streq(name, "TTYPath"))
3,567✔
1880
                return bus_set_transient_path(u, name, &c->tty_path, message, flags, reterr_error);
24✔
1881

1882
        if (streq(name, "RootImage"))
3,543✔
1883
                return bus_set_transient_path(u, name, &c->root_image, message, flags, reterr_error);
18✔
1884

1885
        if (streq(name, "RootImageOptions")) {
3,525✔
1886
                _cleanup_(mount_options_free_allp) MountOptions *options = NULL;
×
1887
                _cleanup_free_ char *format_str = NULL;
6✔
1888

1889
                r = bus_read_mount_options(message, reterr_error, &options, &format_str, " ");
6✔
1890
                if (r < 0)
6✔
1891
                        return r;
1892

1893
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
6✔
1894
                        if (options) {
3✔
1895
                                if (!c->root_image_options)
3✔
1896
                                        c->root_image_options = TAKE_PTR(options);
2✔
1897
                                else
1898
                                        for (PartitionDesignator j = 0; j < _PARTITION_DESIGNATOR_MAX; j++) {
14✔
1899
                                                if (isempty(options->options[j])) {
13✔
1900
                                                        if (options->options[j]) /* Free current value if "" is passed */
11✔
1901
                                                                c->root_image_options->options[j] = mfree(c->root_image_options->options[j]);
×
1902
                                                        continue;
11✔
1903
                                                }
1904
                                                free_and_replace(c->root_image_options->options[j], options->options[j]);
2✔
1905
                                        }
1906
                                unit_write_settingf(
3✔
1907
                                                u, flags|UNIT_ESCAPE_SPECIFIERS, name,
3✔
1908
                                                "%s=%s",
1909
                                                name,
1910
                                                format_str);
1911
                        } else {
1912
                                c->root_image_options = mount_options_free_all(c->root_image_options);
×
1913
                                unit_write_settingf(u, flags, name, "%s=", name);
×
1914
                        }
1915
                }
1916

1917
                return 1;
6✔
1918
        }
1919

1920
        if (streq(name, "RootHash")) {
3,519✔
1921
                struct iovec roothash_decoded;
×
1922

1923
                r = sd_bus_message_read_array(message, 'y', (const void**) &roothash_decoded.iov_base, &roothash_decoded.iov_len);
×
1924
                if (r < 0)
×
1925
                        return r;
×
1926

1927
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
×
1928

1929
                        if (!iovec_is_set(&roothash_decoded)) {
×
1930
                                c->root_hash_path = mfree(c->root_hash_path);
×
1931
                                iovec_done(&c->root_hash);
×
1932

1933
                                unit_write_settingf(u, flags, name, "RootHash=");
×
1934
                        } else {
1935
                                _cleanup_free_ char *encoded = hexmem(roothash_decoded.iov_base, roothash_decoded.iov_len);
×
1936
                                if (!encoded)
×
1937
                                        return -ENOMEM;
1938

1939
                                _cleanup_(iovec_done) struct iovec p = {};
×
1940
                                if (!iovec_memdup(&roothash_decoded, &p))
×
1941
                                        return -ENOMEM;
×
1942

1943
                                iovec_done(&c->root_hash);
×
1944
                                c->root_hash = TAKE_STRUCT(p);
×
1945
                                c->root_hash_path = mfree(c->root_hash_path);
×
1946

1947
                                unit_write_settingf(u, flags, name, "RootHash=%s", encoded);
×
1948
                        }
1949
                }
1950

1951
                return 1;
×
1952
        }
1953

1954
        if (streq(name, "RootHashPath")) {
3,519✔
1955
                iovec_done(&c->root_hash);
×
1956
                return bus_set_transient_path(u, "RootHash", &c->root_hash_path, message, flags, reterr_error);
×
1957
        }
1958

1959
        if (streq(name, "RootHashSignature")) {
3,519✔
1960
                struct iovec roothash_sig_decoded;
×
1961

1962
                r = sd_bus_message_read_array(message, 'y', (const void**) &roothash_sig_decoded.iov_base, &roothash_sig_decoded.iov_len);
×
1963
                if (r < 0)
×
1964
                        return r;
×
1965

1966
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
×
1967
                        if (!iovec_is_set(&roothash_sig_decoded)) {
×
1968
                                c->root_hash_sig_path = mfree(c->root_hash_sig_path);
×
1969
                                iovec_done(&c->root_hash_sig);
×
1970

1971
                                unit_write_settingf(u, flags, name, "RootHashSignature=");
×
1972
                        } else {
1973
                                _cleanup_free_ char *encoded = NULL;
×
1974
                                ssize_t len = base64mem(roothash_sig_decoded.iov_base, roothash_sig_decoded.iov_len, &encoded);
×
1975
                                if (len < 0)
×
1976
                                        return -ENOMEM;
1977

1978
                                _cleanup_(iovec_done) struct iovec p = {};
×
1979
                                if (!iovec_memdup(&roothash_sig_decoded, &p))
×
1980
                                        return -ENOMEM;
×
1981

1982
                                iovec_done(&c->root_hash_sig);
×
1983
                                c->root_hash_sig = TAKE_STRUCT(p);
×
1984
                                c->root_hash_sig_path = mfree(c->root_hash_sig_path);
×
1985

1986
                                unit_write_settingf(u, flags, name, "RootHashSignature=base64:%s", encoded);
×
1987
                        }
1988
                }
1989

1990
                return 1;
×
1991
        }
1992

1993
        if (streq(name, "RootHashSignaturePath")) {
3,519✔
1994
                iovec_done(&c->root_hash_sig);
×
1995
                return bus_set_transient_path(u, "RootHashSignature", &c->root_hash_sig_path, message, flags, reterr_error);
×
1996
        }
1997

1998
        if (streq(name, "RootVerity"))
3,519✔
1999
                return bus_set_transient_path(u, name, &c->root_verity, message, flags, reterr_error);
×
2000

2001
        if (streq(name, "RootDirectory"))
3,519✔
2002
                return bus_set_transient_path(u, name, &c->root_directory, message, flags, reterr_error);
8✔
2003

2004
        if (streq(name, "RootEphemeral"))
3,511✔
2005
                return bus_set_transient_bool(u, name, &c->root_ephemeral, message, flags, reterr_error);
×
2006

2007
        if (streq(name, "SyslogIdentifier"))
3,511✔
2008
                return bus_set_transient_string(u, name, &c->syslog_identifier, message, flags, reterr_error);
×
2009

2010
        if (streq(name, "LogLevelMax"))
3,511✔
2011
                return bus_set_transient_log_level(u, name, &c->log_level_max, message, flags, reterr_error);
×
2012

2013
        if (streq(name, "LogRateLimitIntervalUSec"))
3,511✔
2014
                return bus_set_transient_usec(u, name, &c->log_ratelimit.interval, message, flags, reterr_error);
×
2015

2016
        if (streq(name, "LogRateLimitBurst"))
3,511✔
2017
                return bus_set_transient_unsigned(u, name, &c->log_ratelimit.burst, message, flags, reterr_error);
×
2018

2019
        if (streq(name, "LogFilterPatterns")) {
3,511✔
2020
                /* Use _cleanup_free_, not _cleanup_strv_free_, as we don't want the content of the strv
2021
                 * to be freed. */
2022
                _cleanup_free_ char **allow_list = NULL, **deny_list = NULL;
×
2023
                const char *pattern;
×
2024
                int is_allowlist;
×
2025

2026
                r = sd_bus_message_enter_container(message, 'a', "(bs)");
×
2027
                if (r < 0)
×
2028
                        return r;
2029

2030
                while ((r = sd_bus_message_read(message, "(bs)", &is_allowlist, &pattern)) > 0) {
×
2031
                        _cleanup_(pcre2_code_freep) pcre2_code *compiled_pattern = NULL;
×
2032

2033
                        if (isempty(pattern))
×
2034
                                continue;
×
2035

2036
                        r = pattern_compile_and_log(pattern, 0, &compiled_pattern);
×
2037
                        if (r < 0)
×
2038
                                return r;
2039

2040
                        r = strv_push(is_allowlist ? &allow_list : &deny_list, (char *)pattern);
×
2041
                        if (r < 0)
×
2042
                                return r;
2043
                }
2044
                if (r < 0)
×
2045
                        return r;
2046

2047
                r = sd_bus_message_exit_container(message);
×
2048
                if (r < 0)
×
2049
                        return r;
2050

2051
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
×
2052
                        if (strv_isempty(allow_list) && strv_isempty(deny_list)) {
×
2053
                                c->log_filter_allowed_patterns = set_free(c->log_filter_allowed_patterns);
×
2054
                                c->log_filter_denied_patterns = set_free(c->log_filter_denied_patterns);
×
2055
                                unit_write_settingf(u, flags, name, "%s=", name);
×
2056
                        } else {
2057
                                r = set_put_strdupv(&c->log_filter_allowed_patterns, allow_list);
×
2058
                                if (r < 0)
×
2059
                                        return r;
2060
                                r = set_put_strdupv(&c->log_filter_denied_patterns, deny_list);
×
2061
                                if (r < 0)
×
2062
                                        return r;
2063

2064
                                STRV_FOREACH(unit_pattern, allow_list)
×
2065
                                        unit_write_settingf(u, flags, name, "%s=%s", name, *unit_pattern);
×
2066
                                STRV_FOREACH(unit_pattern, deny_list)
×
2067
                                        unit_write_settingf(u, flags, name, "%s=~%s", name, *unit_pattern);
×
2068
                        }
2069
                }
2070

2071
                return 1;
×
2072
        }
2073

2074
        if (streq(name, "Personality"))
3,511✔
2075
                return bus_set_transient_personality(u, name, &c->personality, message, flags, reterr_error);
×
2076

2077
        if (streq(name, "StandardInput"))
3,511✔
2078
                return bus_set_transient_std_input(u, name, &c->std_input, message, flags, reterr_error);
×
2079

2080
        if (streq(name, "StandardOutput"))
3,511✔
2081
                return bus_set_transient_std_output(u, name, &c->std_output, message, flags, reterr_error);
30✔
2082

2083
        if (streq(name, "StandardError"))
3,481✔
2084
                return bus_set_transient_std_output(u, name, &c->std_error, message, flags, reterr_error);
30✔
2085

2086
        if (streq(name, "IgnoreSIGPIPE"))
3,451✔
2087
                return bus_set_transient_bool(u, name, &c->ignore_sigpipe, message, flags, reterr_error);
160✔
2088

2089
        if (streq(name, "TTYVHangup"))
3,291✔
2090
                return bus_set_transient_bool(u, name, &c->tty_vhangup, message, flags, reterr_error);
×
2091

2092
        if (streq(name, "TTYReset"))
3,291✔
2093
                return bus_set_transient_bool(u, name, &c->tty_reset, message, flags, reterr_error);
×
2094

2095
        if (streq(name, "TTYVTDisallocate"))
3,291✔
2096
                return bus_set_transient_bool(u, name, &c->tty_vt_disallocate, message, flags, reterr_error);
×
2097

2098
        if (streq(name, "TTYRows"))
3,291✔
2099
                return bus_set_transient_unsigned(u, name, &c->tty_rows, message, flags, reterr_error);
×
2100

2101
        if (streq(name, "TTYColumns"))
3,291✔
2102
                return bus_set_transient_unsigned(u, name, &c->tty_cols, message, flags, reterr_error);
×
2103

2104
        if (streq(name, "PrivateTmp")) {
3,291✔
2105
                int v;
12✔
2106

2107
                r = sd_bus_message_read(message, "b", &v);
12✔
2108
                if (r < 0)
12✔
2109
                        return r;
12✔
2110

2111
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
12✔
2112
                        c->private_tmp = v ? PRIVATE_TMP_CONNECTED : PRIVATE_TMP_NO;
6✔
2113
                        (void) unit_write_settingf(u, flags, name, "%s=%s", name, yes_no(v));
6✔
2114
                }
2115

2116
                return 1;
12✔
2117

2118
        } else if (streq(name, "PrivateTmpEx")) {
3,279✔
2119
                const char *s;
×
2120
                PrivateTmp t;
×
2121

2122
                r = sd_bus_message_read(message, "s", &s);
×
2123
                if (r < 0)
×
2124
                        return r;
×
2125

2126
                t = private_tmp_from_string(s);
×
2127
                if (t < 0)
×
2128
                        return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Invalid %s setting: %s", name, s);
×
2129

2130
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
×
2131
                        c->private_tmp = t;
×
2132
                        (void) unit_write_settingf(u, flags, name, "PrivateTmp=%s",
×
2133
                                                   private_tmp_to_string(c->private_tmp));
2134
                }
2135

2136
                return 1;
×
2137
        }
2138

2139
        if (streq(name, "PrivateUsers")) {
3,279✔
2140
                int v;
8✔
2141

2142
                r = sd_bus_message_read(message, "b", &v);
8✔
2143
                if (r < 0)
8✔
2144
                        return r;
8✔
2145

2146
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
8✔
2147
                        c->private_users = v ? PRIVATE_USERS_SELF : PRIVATE_USERS_NO;
4✔
2148
                        (void) unit_write_settingf(u, flags, name, "%s=%s", name, yes_no(v));
4✔
2149
                }
2150

2151
                return 1;
8✔
2152

2153
        } else if (streq(name, "PrivateUsersEx")) {
3,271✔
2154
                const char *s;
18✔
2155
                PrivateUsers t;
18✔
2156

2157
                r = sd_bus_message_read(message, "s", &s);
18✔
2158
                if (r < 0)
18✔
2159
                        return r;
18✔
2160

2161
                t = private_users_from_string(s);
18✔
2162
                if (t < 0)
18✔
2163
                        return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Invalid %s setting: %s", name, s);
×
2164

2165
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
18✔
2166
                        c->private_users = t;
9✔
2167
                        (void) unit_write_settingf(u, flags, name, "PrivateUsers=%s",
9✔
2168
                                                   private_users_to_string(c->private_users));
2169
                }
2170

2171
                return 1;
18✔
2172
        }
2173

2174
        if (streq(name, "ProtectControlGroups")) {
3,253✔
2175
                int v;
×
2176

2177
                r = sd_bus_message_read(message, "b", &v);
×
2178
                if (r < 0)
×
2179
                        return r;
×
2180

2181
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
×
2182
                        c->protect_control_groups = v ? PROTECT_CONTROL_GROUPS_YES : PROTECT_CONTROL_GROUPS_NO;
×
2183
                        (void) unit_write_settingf(u, flags, name, "%s=%s", name, yes_no(v));
×
2184
                }
2185

2186
                return 1;
×
2187
        }
2188

2189
        if (streq(name, "ProtectControlGroupsEx")) {
3,253✔
2190
                const char *s;
2✔
2191
                ProtectControlGroups t;
2✔
2192

2193
                r = sd_bus_message_read(message, "s", &s);
2✔
2194
                if (r < 0)
2✔
2195
                        return r;
2✔
2196

2197
                t = protect_control_groups_from_string(s);
2✔
2198
                if (t < 0)
2✔
2199
                        return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Invalid %s setting: %s", name, s);
×
2200

2201
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2✔
2202
                        c->protect_control_groups = t;
1✔
2203
                        (void) unit_write_settingf(u, flags, name, "ProtectControlGroups=%s",
1✔
2204
                                                   protect_control_groups_to_string(c->protect_control_groups));
2205
                }
2206

2207
                return 1;
2✔
2208
        }
2209

2210
        if (streq(name, "PrivatePIDs")) {
3,251✔
2211
                const char *s;
8✔
2212
                PrivatePIDs t;
8✔
2213

2214
                r = sd_bus_message_read(message, "s", &s);
8✔
2215
                if (r < 0)
8✔
2216
                        return r;
8✔
2217

2218
                t = private_pids_from_string(s);
8✔
2219
                if (t < 0)
8✔
2220
                        return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Invalid %s setting: %s", name, s);
×
2221

2222
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
8✔
2223
                        c->private_pids = t;
4✔
2224
                        (void) unit_write_settingf(u, flags, name, "%s=%s",
4✔
2225
                                                   name, private_pids_to_string(c->private_pids));
2226
                }
2227

2228
                return 1;
8✔
2229
        }
2230

2231
        if (streq(name, "ProtectHostname")) {
3,243✔
2232
                int v;
4✔
2233

2234
                r = sd_bus_message_read(message, "b", &v);
4✔
2235
                if (r < 0)
4✔
2236
                        return r;
4✔
2237

2238
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
4✔
2239
                        c->protect_hostname = v ? PROTECT_HOSTNAME_YES : PROTECT_HOSTNAME_NO;
2✔
2240
                        (void) unit_write_settingf(u, flags, name, "%s=%s", name, yes_no(v));
2✔
2241
                }
2242

2243
                return 1;
4✔
2244

2245
        }
2246

2247
        if (streq(name, "ProtectHostnameEx")) {
3,239✔
2248
                const char *s, *h = NULL;
4✔
2249

2250
                r = sd_bus_message_read(message, "(ss)", &s, &h);
4✔
2251
                if (r < 0)
4✔
2252
                        return r;
4✔
2253

2254
                if (!isempty(h) && !hostname_is_valid(h, /* flags= */ 0))
4✔
2255
                        return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Invalid hostname in %s setting: %s", name, h);
×
2256

2257
                ProtectHostname t = protect_hostname_from_string(s);
4✔
2258
                if (t < 0 || (t == PROTECT_HOSTNAME_NO && !isempty(h)))
4✔
2259
                        return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Invalid %s setting: %s", name, s);
×
2260

2261
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
4✔
2262
                        c->protect_hostname = t;
2✔
2263
                        r = free_and_strdup(&c->private_hostname, empty_to_null(h));
4✔
2264
                        if (r < 0)
2✔
2265
                                return r;
2266

2267
                        (void) unit_write_settingf(u, flags, name, "ProtectHostname=%s%s%s",
4✔
2268
                                                   protect_hostname_to_string(c->protect_hostname),
2269
                                                   c->private_hostname ? ":" : "",
2270
                                                   strempty(c->private_hostname));
2✔
2271
                }
2272

2273
                return 1;
4✔
2274
        }
2275

2276
        if (streq(name, "PrivateDevices"))
3,235✔
2277
                return bus_set_transient_bool(u, name, &c->private_devices, message, flags, reterr_error);
4✔
2278

2279
        if (streq(name, "PrivateMounts"))
3,231✔
2280
                return bus_set_transient_tristate(u, name, &c->private_mounts, message, flags, reterr_error);
22✔
2281

2282
        if (streq(name, "MountAPIVFS"))
3,209✔
2283
                return bus_set_transient_tristate(u, name, &c->mount_apivfs, message, flags, reterr_error);
4✔
2284

2285
        if (streq(name, "BindLogSockets"))
3,205✔
2286
                return bus_set_transient_tristate(u, name, &c->bind_log_sockets, message, flags, reterr_error);
×
2287

2288
        if (streq(name, "PrivateNetwork"))
3,205✔
2289
                return bus_set_transient_bool(u, name, &c->private_network, message, flags, reterr_error);
8✔
2290

2291
        if (streq(name, "PrivateIPC"))
3,197✔
2292
                return bus_set_transient_bool(u, name, &c->private_ipc, message, flags, reterr_error);
4✔
2293

2294
        if (streq(name, "NoNewPrivileges"))
3,193✔
2295
                return bus_set_transient_bool(u, name, &c->no_new_privileges, message, flags, reterr_error);
2✔
2296

2297
        if (streq(name, "SyslogLevelPrefix"))
3,191✔
2298
                return bus_set_transient_bool(u, name, &c->syslog_level_prefix, message, flags, reterr_error);
×
2299

2300
        if (streq(name, "MemoryDenyWriteExecute"))
3,191✔
2301
                return bus_set_transient_bool(u, name, &c->memory_deny_write_execute, message, flags, reterr_error);
×
2302

2303
        if (streq(name, "RestrictRealtime"))
3,191✔
2304
                return bus_set_transient_bool(u, name, &c->restrict_realtime, message, flags, reterr_error);
×
2305

2306
        if (streq(name, "RestrictSUIDSGID"))
3,191✔
2307
                return bus_set_transient_bool(u, name, &c->restrict_suid_sgid, message, flags, reterr_error);
×
2308

2309
        if (streq(name, "DynamicUser"))
3,191✔
2310
                return bus_set_transient_bool(u, name, &c->dynamic_user, message, flags, reterr_error);
4✔
2311

2312
        if (streq(name, "RemoveIPC"))
3,187✔
2313
                return bus_set_transient_bool(u, name, &c->remove_ipc, message, flags, reterr_error);
×
2314

2315
        if (streq(name, "ProtectKernelTunables"))
3,187✔
2316
                return bus_set_transient_bool(u, name, &c->protect_kernel_tunables, message, flags, reterr_error);
4✔
2317

2318
        if (streq(name, "ProtectKernelModules"))
3,183✔
2319
                return bus_set_transient_bool(u, name, &c->protect_kernel_modules, message, flags, reterr_error);
4✔
2320

2321
        if (streq(name, "ProtectKernelLogs"))
3,179✔
2322
                return bus_set_transient_bool(u, name, &c->protect_kernel_logs, message, flags, reterr_error);
2✔
2323

2324
        if (streq(name, "ProtectClock"))
3,177✔
2325
                return bus_set_transient_bool(u, name, &c->protect_clock, message, flags, reterr_error);
4✔
2326

2327
        if (streq(name, "CPUSchedulingResetOnFork"))
3,173✔
2328
                return bus_set_transient_bool(u, name, &c->cpu_sched_reset_on_fork, message, flags, reterr_error);
×
2329

2330
        if (streq(name, "NonBlocking"))
3,173✔
2331
                return bus_set_transient_bool(u, name, &c->non_blocking, message, flags, reterr_error);
×
2332

2333
        if (streq(name, "LockPersonality"))
3,173✔
2334
                return bus_set_transient_bool(u, name, &c->lock_personality, message, flags, reterr_error);
2✔
2335

2336
        if (streq(name, "MemoryKSM"))
3,171✔
2337
                return bus_set_transient_tristate(u, name, &c->memory_ksm, message, flags, reterr_error);
×
2338

2339
        if (streq(name, "MemoryTHP"))
3,171✔
2340
                return bus_set_transient_memory_thp(u, name, &c->memory_thp, message, flags, reterr_error);
×
2341

2342
        if (streq(name, "UtmpIdentifier"))
3,171✔
2343
                return bus_set_transient_string(u, name, &c->utmp_id, message, flags, reterr_error);
×
2344

2345
        if (streq(name, "UtmpMode"))
3,171✔
2346
                return bus_set_transient_utmp_mode(u, name, &c->utmp_mode, message, flags, reterr_error);
×
2347

2348
        if (streq(name, "PAMName"))
3,171✔
2349
                return bus_set_transient_string(u, name, &c->pam_name, message, flags, reterr_error);
190✔
2350

2351
        if (streq(name, "TimerSlackNSec"))
2,981✔
2352
                return bus_set_transient_nsec(u, name, &c->timer_slack_nsec, message, flags, reterr_error);
×
2353

2354
        if (streq(name, "ProtectSystem"))
2,981✔
2355
                return bus_set_transient_protect_system(u, name, &c->protect_system, message, flags, reterr_error);
2✔
2356

2357
        if (streq(name, "ProtectHome"))
2,979✔
2358
                return bus_set_transient_protect_home(u, name, &c->protect_home, message, flags, reterr_error);
6✔
2359

2360
        if (streq(name, "KeyringMode"))
2,973✔
2361
                return bus_set_transient_keyring_mode(u, name, &c->keyring_mode, message, flags, reterr_error);
×
2362

2363
        if (streq(name, "ProtectProc"))
2,973✔
2364
                return bus_set_transient_protect_proc(u, name, &c->protect_proc, message, flags, reterr_error);
14✔
2365

2366
        if (streq(name, "ProcSubset"))
2,959✔
2367
                return bus_set_transient_proc_subset(u, name, &c->proc_subset, message, flags, reterr_error);
6✔
2368

2369
        if (streq(name, "PrivateBPF"))
2,953✔
2370
                return bus_set_transient_private_bpf(u, name, &c->private_bpf, message, flags, reterr_error);
×
2371

2372
        if (streq(name, "BPFDelegateCommands"))
2,953✔
2373
                return bus_set_transient_bpf_delegate_commands(u, name, &c->bpf_delegate_commands, message, flags, reterr_error);
×
2374

2375
        if (streq(name, "BPFDelegateMaps"))
2,953✔
2376
                return bus_set_transient_bpf_delegate_maps(u, name, &c->bpf_delegate_maps, message, flags, reterr_error);
×
2377

2378
        if (streq(name, "BPFDelegatePrograms"))
2,953✔
2379
                return bus_set_transient_bpf_delegate_programs(u, name, &c->bpf_delegate_programs, message, flags, reterr_error);
×
2380

2381
        if (streq(name, "BPFDelegateAttachments"))
2,953✔
2382
                return bus_set_transient_bpf_delegate_attachments(u, name, &c->bpf_delegate_attachments, message, flags, reterr_error);
×
2383

2384
        if (streq(name, "RuntimeDirectoryPreserve"))
2,953✔
2385
                return bus_set_transient_exec_preserve_mode(u, name, &c->runtime_directory_preserve_mode, message, flags, reterr_error);
10✔
2386

2387
        if (streq(name, "UMask"))
2,943✔
2388
                return bus_set_transient_mode_t(u, name, &c->umask, message, flags, reterr_error);
×
2389

2390
        if (streq(name, "RuntimeDirectoryMode"))
2,943✔
2391
                return bus_set_transient_mode_t(u, name, &c->directories[EXEC_DIRECTORY_RUNTIME].mode, message, flags, reterr_error);
×
2392

2393
        if (streq(name, "StateDirectoryAccounting"))
2,943✔
2394
                return bus_set_transient_bool(u, name, &c->directories[EXEC_DIRECTORY_STATE].exec_quota.quota_accounting, message, flags, reterr_error);
×
2395

2396
        if (streq(name, "CacheDirectoryAccounting"))
2,943✔
2397
                return bus_set_transient_bool(u, name, &c->directories[EXEC_DIRECTORY_CACHE].exec_quota.quota_accounting, message, flags, reterr_error);
×
2398

2399
        if (streq(name, "LogsDirectoryAccounting"))
2,943✔
2400
                return bus_set_transient_bool(u, name, &c->directories[EXEC_DIRECTORY_LOGS].exec_quota.quota_accounting, message, flags, reterr_error);
×
2401

2402
        if (streq(name, "StateDirectoryMode"))
2,943✔
2403
                return bus_set_transient_mode_t(u, name, &c->directories[EXEC_DIRECTORY_STATE].mode, message, flags, reterr_error);
10✔
2404

2405
        if (streq(name, "CacheDirectoryMode"))
2,933✔
2406
                return bus_set_transient_mode_t(u, name, &c->directories[EXEC_DIRECTORY_CACHE].mode, message, flags, reterr_error);
20✔
2407

2408
        if (streq(name, "LogsDirectoryMode"))
2,913✔
2409
                return bus_set_transient_mode_t(u, name, &c->directories[EXEC_DIRECTORY_LOGS].mode, message, flags, reterr_error);
×
2410

2411
        if (streq(name, "ConfigurationDirectoryMode"))
2,913✔
2412
                return bus_set_transient_mode_t(u, name, &c->directories[EXEC_DIRECTORY_CONFIGURATION].mode, message, flags, reterr_error);
10✔
2413

2414
        if (streq(name, "SELinuxContext"))
2,903✔
2415
                return bus_set_transient_string(u, name, &c->selinux_context, message, flags, reterr_error);
×
2416

2417
        if (streq(name, "SecureBits"))
2,903✔
2418
                return bus_set_transient_secure_bits(u, name, &c->secure_bits, message, flags, reterr_error);
×
2419

2420
        if (streq(name, "CapabilityBoundingSet"))
2,903✔
2421
                return bus_set_transient_capability(u, name, &c->capability_bounding_set, message, flags, reterr_error);
2✔
2422

2423
        if (streq(name, "AmbientCapabilities"))
2,901✔
2424
                return bus_set_transient_capability(u, name, &c->capability_ambient_set, message, flags, reterr_error);
12✔
2425

2426
        if (streq(name, "RestrictNamespaces"))
2,889✔
2427
                return bus_set_transient_namespace_flag(u, name, &c->restrict_namespaces, message, flags, reterr_error);
×
2428

2429
        if (streq(name, "DelegateNamespaces"))
2,889✔
2430
                return bus_set_transient_namespace_flag(u, name, &c->delegate_namespaces, message, flags, reterr_error);
18✔
2431

2432
        if (streq(name, "RestrictFileSystems")) {
2,871✔
2433
                int allow_list;
×
2434
                _cleanup_strv_free_ char **l = NULL;
×
2435

2436
                r = sd_bus_message_enter_container(message, 'r', "bas");
×
2437
                if (r < 0)
×
2438
                        return r;
2439

2440
                r = sd_bus_message_read(message, "b", &allow_list);
×
2441
                if (r < 0)
×
2442
                        return r;
2443

2444
                r = sd_bus_message_read_strv(message, &l);
×
2445
                if (r < 0)
×
2446
                        return r;
2447

2448
                r = sd_bus_message_exit_container(message);
×
2449
                if (r < 0)
×
2450
                        return r;
2451

2452
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
×
2453
                        _cleanup_free_ char *joined = NULL;
×
2454
                        FilesystemParseFlags invert_flag = allow_list ? 0 : FILESYSTEM_PARSE_INVERT;
×
2455

2456
                        if (strv_isempty(l)) {
×
2457
                                c->restrict_filesystems_allow_list = false;
×
2458
                                c->restrict_filesystems = set_free(c->restrict_filesystems);
×
2459

2460
                                unit_write_setting(u, flags, name, "RestrictFileSystems=");
×
2461
                                return 1;
2462
                        }
2463

2464
                        if (!c->restrict_filesystems)
×
2465
                                c->restrict_filesystems_allow_list = allow_list;
×
2466

2467
                        STRV_FOREACH(s, l) {
×
2468
                                r = bpf_restrict_fs_parse_filesystem(
×
2469
                                              *s,
2470
                                              &c->restrict_filesystems,
2471
                                              FILESYSTEM_PARSE_LOG|
×
2472
                                              (invert_flag ? FILESYSTEM_PARSE_INVERT : 0)|
×
2473
                                              (c->restrict_filesystems_allow_list ? FILESYSTEM_PARSE_ALLOW_LIST : 0),
×
2474
                                              u->id, NULL, 0);
×
2475
                                if (r < 0)
×
2476
                                        return r;
2477
                        }
2478

2479
                        joined = strv_join(l, " ");
×
2480
                        if (!joined)
×
2481
                                return -ENOMEM;
2482

2483
                        unit_write_settingf(u, flags, name, "%s=%s%s", name, allow_list ? "" : "~", joined);
×
2484
                }
2485

2486
                return 1;
×
2487
        }
2488

2489
        if (streq(name, "MountFlags"))
2,871✔
2490
                return bus_set_transient_mount_propagation_flag(u, name, &c->mount_propagation_flag, message, flags, reterr_error);
2✔
2491

2492
        if (streq(name, "NetworkNamespacePath"))
2,869✔
2493
                return bus_set_transient_path(u, name, &c->network_namespace_path, message, flags, reterr_error);
×
2494

2495
        if (streq(name, "UserNamespacePath"))
2,869✔
2496
                return bus_set_transient_path(u, name, &c->user_namespace_path, message, flags, reterr_error);
×
2497

2498
        if (streq(name, "IPCNamespacePath"))
2,869✔
2499
                return bus_set_transient_path(u, name, &c->ipc_namespace_path, message, flags, reterr_error);
×
2500

2501
        if (streq(name, "SupplementaryGroups")) {
2,869✔
2502
                _cleanup_strv_free_ char **l = NULL;
6✔
2503

2504
                r = sd_bus_message_read_strv(message, &l);
6✔
2505
                if (r < 0)
6✔
2506
                        return r;
2507

2508
                STRV_FOREACH(p, l)
12✔
2509
                        if (!isempty(*p) && !valid_user_group_name(*p, VALID_USER_ALLOW_NUMERIC|VALID_USER_RELAX|VALID_USER_WARN))
6✔
2510
                                return sd_bus_error_set(reterr_error, SD_BUS_ERROR_INVALID_ARGS,
×
2511
                                                        "Invalid supplementary group names");
2512

2513
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
6✔
2514
                        if (strv_isempty(l)) {
3✔
2515
                                c->supplementary_groups = strv_free(c->supplementary_groups);
×
2516
                                unit_write_settingf(u, flags, name, "%s=", name);
×
2517
                        } else {
2518
                                _cleanup_free_ char *joined = NULL;
3✔
2519

2520
                                r = strv_extend_strv(&c->supplementary_groups, l, true);
3✔
2521
                                if (r < 0)
3✔
2522
                                        return r;
2523

2524
                                joined = strv_join(c->supplementary_groups, " ");
3✔
2525
                                if (!joined)
3✔
2526
                                        return -ENOMEM;
2527

2528
                                unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "%s=%s", name, joined);
3✔
2529
                        }
2530
                }
2531

2532
                return 1;
6✔
2533

2534
        } else if (STR_IN_SET(name, "SetCredential", "SetCredentialEncrypted")) {
2,863✔
2535
                bool isempty = true;
12✔
2536

2537
                r = sd_bus_message_enter_container(message, 'a', "(say)");
12✔
2538
                if (r < 0)
12✔
2539
                        return r;
504✔
2540

2541
                for (;;) {
12✔
2542
                        const char *id;
24✔
2543
                        const void *p;
24✔
2544
                        size_t sz;
24✔
2545

2546
                        r = sd_bus_message_enter_container(message, 'r', "say");
24✔
2547
                        if (r < 0)
24✔
2548
                                return r;
×
2549
                        if (r == 0)
24✔
2550
                                break;
2551

2552
                        r = sd_bus_message_read(message, "s", &id);
12✔
2553
                        if (r < 0)
12✔
2554
                                return r;
2555

2556
                        r = sd_bus_message_read_array(message, 'y', &p, &sz);
12✔
2557
                        if (r < 0)
12✔
2558
                                return r;
2559

2560
                        r = sd_bus_message_exit_container(message);
12✔
2561
                        if (r < 0)
12✔
2562
                                return r;
2563

2564
                        if (!credential_name_valid(id))
12✔
2565
                                return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Credential ID is invalid: %s", id);
×
2566

2567
                        isempty = false;
12✔
2568

2569
                        if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
12✔
2570
                                bool encrypted = endswith(name, "Encrypted");
6✔
2571
                                _cleanup_free_ char *a = NULL, *b = NULL;
6✔
2572
                                _cleanup_free_ void *copy = NULL;
6✔
2573

2574
                                copy = memdup(p, sz);
6✔
2575
                                if (!copy)
6✔
2576
                                        return -ENOMEM;
2577

2578
                                a = specifier_escape(id);
6✔
2579
                                if (!a)
6✔
2580
                                        return -ENOMEM;
2581

2582
                                b = cescape_length(p, sz);
6✔
2583
                                if (!b)
6✔
2584
                                        return -ENOMEM;
2585

2586
                                r = exec_context_put_set_credential(c, id, TAKE_PTR(copy), sz, encrypted);
6✔
2587
                                if (r < 0)
6✔
2588
                                        return r;
2589

2590
                                (void) unit_write_settingf(u, flags, name, "%s=%s:%s", name, a, b);
6✔
2591
                        }
2592
                }
2593

2594
                r = sd_bus_message_exit_container(message);
12✔
2595
                if (r < 0)
12✔
2596
                        return r;
2597

2598
                if (!UNIT_WRITE_FLAGS_NOOP(flags) && isempty) {
12✔
2599
                        c->set_credentials = hashmap_free(c->set_credentials);
×
2600
                        (void) unit_write_settingf(u, flags, name, "%s=", name);
×
2601
                }
2602

2603
                return 1;
12✔
2604

2605
        } else if (STR_IN_SET(name, "LoadCredential", "LoadCredentialEncrypted")) {
2,851✔
2606
                bool isempty = true;
4✔
2607

2608
                r = sd_bus_message_enter_container(message, 'a', "(ss)");
4✔
2609
                if (r < 0)
4✔
2610
                        return r;
492✔
2611

2612
                for (;;) {
4✔
2613
                        const char *id, *source;
8✔
2614

2615
                        r = sd_bus_message_read(message, "(ss)", &id, &source);
8✔
2616
                        if (r < 0)
8✔
2617
                                return r;
×
2618
                        if (r == 0)
8✔
2619
                                break;
2620

2621
                        if (!credential_name_valid(id))
4✔
2622
                                return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Credential ID is invalid: %s", id);
×
2623

2624
                        if (!(path_is_absolute(source) ? path_is_normalized(source) : credential_name_valid(source)))
4✔
2625
                                return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Credential source is invalid: %s", source);
×
2626

2627
                        isempty = false;
4✔
2628

2629
                        if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
4✔
2630
                                bool encrypted = endswith(name, "Encrypted");
2✔
2631

2632
                                r = exec_context_put_load_credential(c, id, source, encrypted);
2✔
2633
                                if (r < 0)
2✔
2634
                                        return r;
2635

2636
                                (void) unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "%s=%s:%s", name, id, source);
2✔
2637
                        }
2638
                }
2639

2640
                r = sd_bus_message_exit_container(message);
4✔
2641
                if (r < 0)
4✔
2642
                        return r;
2643

2644
                if (!UNIT_WRITE_FLAGS_NOOP(flags) && isempty) {
4✔
2645
                        c->load_credentials = hashmap_free(c->load_credentials);
×
2646
                        (void) unit_write_settingf(u, flags, name, "%s=", name);
×
2647
                }
2648

2649
                return 1;
4✔
2650

2651
        } else if (STR_IN_SET(name, "ImportCredential", "ImportCredentialEx")) {
2,847✔
2652
                bool empty = true, ex = streq(name, "ImportCredentialEx");
8✔
2653

2654
                r = sd_bus_message_enter_container(message, 'a', ex ? "(ss)" : "s");
16✔
2655
                if (r < 0)
8✔
2656
                        return r;
488✔
2657

2658
                for (;;) {
8✔
2659
                        const char *glob, *rename = NULL;
16✔
2660

2661
                        if (ex)
16✔
2662
                                r = sd_bus_message_read(message, "(ss)", &glob, &rename);
×
2663
                        else
2664
                                r = sd_bus_message_read(message, "s", &glob);
16✔
2665
                        if (r < 0)
16✔
2666
                                return r;
×
2667
                        if (r == 0)
16✔
2668
                                break;
2669

2670
                        if (!credential_glob_valid(glob))
8✔
2671
                                return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Credential name or glob is invalid: %s", glob);
×
2672

2673
                        rename = empty_to_null(rename);
8✔
2674

2675
                        if (rename && !credential_name_valid(rename))
8✔
2676
                                return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Credential name is invalid: %s", rename);
×
2677

2678
                        empty = false;
8✔
2679

2680
                        if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
8✔
2681
                                r = exec_context_put_import_credential(c, glob, rename);
4✔
2682
                                if (r < 0)
4✔
2683
                                        return r;
2684

2685
                                (void) unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name,
12✔
2686
                                                           "ImportCredential=%s%s%s",
2687
                                                           glob, rename ? ":" : "", strempty(rename));
2688
                        }
2689
                }
2690

2691
                r = sd_bus_message_exit_container(message);
8✔
2692
                if (r < 0)
8✔
2693
                        return r;
2694

2695
                if (!UNIT_WRITE_FLAGS_NOOP(flags) && empty) {
8✔
2696
                        c->import_credentials = ordered_set_free(c->import_credentials);
×
2697
                        (void) unit_write_settingf(u, flags, name, "%s=", name);
×
2698
                }
2699

2700
                return 1;
8✔
2701

2702
        } else if (streq(name, "SyslogLevel")) {
2,839✔
2703
                int32_t level;
×
2704

2705
                r = sd_bus_message_read(message, "i", &level);
×
2706
                if (r < 0)
×
2707
                        return r;
×
2708

2709
                if (!log_level_is_valid(level))
×
2710
                        return sd_bus_error_set(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Log level value out of range");
×
2711

2712
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
×
2713
                        c->syslog_priority = (c->syslog_priority & LOG_FACMASK) | level;
×
2714
                        unit_write_settingf(u, flags, name, "SyslogLevel=%i", level);
×
2715
                }
2716

2717
                return 1;
×
2718

2719
        } else if (streq(name, "SyslogFacility")) {
2,839✔
2720
                int32_t facility;
×
2721

2722
                r = sd_bus_message_read(message, "i", &facility);
×
2723
                if (r < 0)
×
2724
                        return r;
×
2725

2726
                if (!log_facility_unshifted_is_valid(facility))
×
2727
                        return sd_bus_error_set(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Log facility value out of range");
×
2728

2729
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
×
2730
                        c->syslog_priority = (facility << 3) | LOG_PRI(c->syslog_priority);
×
2731
                        unit_write_settingf(u, flags, name, "SyslogFacility=%i", facility);
×
2732
                }
2733

2734
                return 1;
×
2735

2736
        } else if (streq(name, "LogNamespace")) {
2,839✔
2737
                const char *n;
×
2738

2739
                r = sd_bus_message_read(message, "s", &n);
×
2740
                if (r < 0)
×
2741
                        return r;
×
2742

2743
                if (!isempty(n) && !log_namespace_name_valid(n))
×
2744
                        return sd_bus_error_set(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Log namespace name not valid");
×
2745

2746
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
×
2747

2748
                        if (isempty(n)) {
×
2749
                                c->log_namespace = mfree(c->log_namespace);
×
2750
                                unit_write_settingf(u, flags, name, "%s=", name);
×
2751
                        } else {
2752
                                r = free_and_strdup(&c->log_namespace, n);
×
2753
                                if (r < 0)
×
2754
                                        return r;
2755

2756
                                unit_write_settingf(u, flags, name, "%s=%s", name, n);
×
2757
                        }
2758
                }
2759

2760
                return 1;
×
2761

2762
        } else if (streq(name, "LogExtraFields")) {
2,839✔
2763
                size_t n = 0;
480✔
2764

2765
                r = sd_bus_message_enter_container(message, 'a', "ay");
480✔
2766
                if (r < 0)
480✔
2767
                        return r;
2768

2769
                for (;;) {
1,440✔
2770
                        _cleanup_free_ void *copy = NULL;
480✔
2771
                        const char *eq;
960✔
2772
                        const void *p;
960✔
2773
                        size_t sz;
960✔
2774

2775
                        /* Note that we expect a byte array for each field, instead of a string. That's because on the
2776
                         * lower-level journal fields can actually contain binary data and are not restricted to text,
2777
                         * and we should not "lose precision" in our types on the way. That said, I am pretty sure
2778
                         * actually encoding binary data as unit metadata is not a good idea. Hence we actually refuse
2779
                         * any actual binary data, and only accept UTF-8. This allows us to eventually lift this
2780
                         * limitation, should a good, valid use case arise. */
2781

2782
                        r = sd_bus_message_read_array(message, 'y', &p, &sz);
960✔
2783
                        if (r < 0)
960✔
2784
                                return r;
2785
                        if (r == 0)
960✔
2786
                                break;
2787

2788
                        if (memchr(p, 0, sz))
480✔
2789
                                return sd_bus_error_set(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Journal field contains zero byte");
×
2790

2791
                        eq = memchr(p, '=', sz);
480✔
2792
                        if (!eq)
480✔
2793
                                return sd_bus_error_set(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Journal field contains no '=' character");
×
2794
                        if (!journal_field_valid(p, eq - (const char*) p, false))
480✔
2795
                                return sd_bus_error_set(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Journal field invalid");
×
2796

2797
                        copy = memdup_suffix0(p, sz);
480✔
2798
                        if (!copy)
480✔
2799
                                return -ENOMEM;
2800

2801
                        if (!utf8_is_valid(copy))
480✔
2802
                                return sd_bus_error_set(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Journal field is not valid UTF-8");
×
2803

2804
                        if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
480✔
2805
                                if (!GREEDY_REALLOC(c->log_extra_fields, c->n_log_extra_fields + 1))
240✔
2806
                                        return -ENOMEM;
2807

2808
                                c->log_extra_fields[c->n_log_extra_fields++] = IOVEC_MAKE(copy, sz);
240✔
2809
                                unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS|UNIT_ESCAPE_C, name, "LogExtraFields=%s", (char*) copy);
240✔
2810
                                TAKE_PTR(copy);
2811
                        }
2812

2813
                        n++;
480✔
2814
                }
2815

2816
                r = sd_bus_message_exit_container(message);
480✔
2817
                if (r < 0)
480✔
2818
                        return r;
2819

2820
                if (!UNIT_WRITE_FLAGS_NOOP(flags) && n == 0) {
480✔
2821
                        exec_context_free_log_extra_fields(c);
×
2822
                        unit_write_setting(u, flags, name, "LogExtraFields=");
×
2823
                }
2824

2825
                return 1;
480✔
2826
        }
2827

2828
#if HAVE_SECCOMP
2829

2830
        if (streq(name, "SystemCallErrorNumber"))
2,359✔
2831
                return bus_set_transient_errno(u, name, &c->syscall_errno, message, flags, reterr_error);
×
2832

2833
        if (streq(name, "SystemCallFilter")) {
2,359✔
2834
                int allow_list;
10✔
2835
                _cleanup_strv_free_ char **l = NULL;
10✔
2836

2837
                r = sd_bus_message_enter_container(message, 'r', "bas");
10✔
2838
                if (r < 0)
10✔
2839
                        return r;
2840

2841
                r = sd_bus_message_read(message, "b", &allow_list);
10✔
2842
                if (r < 0)
10✔
2843
                        return r;
2844

2845
                r = sd_bus_message_read_strv(message, &l);
10✔
2846
                if (r < 0)
10✔
2847
                        return r;
2848

2849
                r = sd_bus_message_exit_container(message);
10✔
2850
                if (r < 0)
10✔
2851
                        return r;
2852

2853
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
10✔
2854
                        _cleanup_free_ char *joined = NULL;
5✔
2855
                        SeccompParseFlags invert_flag = allow_list ? 0 : SECCOMP_PARSE_INVERT;
5✔
2856

2857
                        if (strv_isempty(l)) {
5✔
2858
                                c->syscall_allow_list = false;
×
2859
                                c->syscall_filter = hashmap_free(c->syscall_filter);
×
2860

2861
                                unit_write_settingf(u, flags, name, "SystemCallFilter=");
×
2862
                                return 1;
2863
                        }
2864

2865
                        if (!c->syscall_filter) {
5✔
2866
                                c->syscall_filter = hashmap_new(NULL);
5✔
2867
                                if (!c->syscall_filter)
5✔
2868
                                        return log_oom();
×
2869

2870
                                c->syscall_allow_list = allow_list;
5✔
2871

2872
                                if (c->syscall_allow_list) {
5✔
2873
                                        r = seccomp_parse_syscall_filter("@default",
×
2874
                                                                         -1,
2875
                                                                         c->syscall_filter,
2876
                                                                         SECCOMP_PARSE_PERMISSIVE |
2877
                                                                         SECCOMP_PARSE_ALLOW_LIST,
2878
                                                                         u->id,
×
2879
                                                                         NULL, 0);
2880
                                        if (r < 0)
×
2881
                                                return r;
2882
                                }
2883
                        }
2884

2885
                        STRV_FOREACH(s, l) {
10✔
2886
                                _cleanup_free_ char *n = NULL;
5✔
2887
                                int e;
5✔
2888

2889
                                r = parse_syscall_and_errno(*s, &n, &e);
5✔
2890
                                if (r < 0)
5✔
2891
                                        return r;
2892

2893
                                if (allow_list && e >= 0)
5✔
2894
                                        return -EINVAL;
2895

2896
                                r = seccomp_parse_syscall_filter(n,
10✔
2897
                                                                 e,
2898
                                                                 c->syscall_filter,
2899
                                                                 SECCOMP_PARSE_LOG | SECCOMP_PARSE_PERMISSIVE |
2900
                                                                 invert_flag |
5✔
2901
                                                                 (c->syscall_allow_list ? SECCOMP_PARSE_ALLOW_LIST : 0),
5✔
2902
                                                                 u->id,
5✔
2903
                                                                 NULL, 0);
2904
                                if (r < 0)
5✔
2905
                                        return r;
2906
                        }
2907

2908
                        joined = strv_join(l, " ");
5✔
2909
                        if (!joined)
5✔
2910
                                return -ENOMEM;
2911

2912
                        unit_write_settingf(u, flags, name, "SystemCallFilter=%s%s", allow_list ? "" : "~", joined);
10✔
2913
                }
2914

2915
                return 1;
10✔
2916

2917
        } else if (streq(name, "SystemCallLog")) {
2,349✔
2918
                int allow_list;
×
2919
                _cleanup_strv_free_ char **l = NULL;
×
2920

2921
                r = sd_bus_message_enter_container(message, 'r', "bas");
×
2922
                if (r < 0)
×
2923
                        return r;
2924

2925
                r = sd_bus_message_read(message, "b", &allow_list);
×
2926
                if (r < 0)
×
2927
                        return r;
2928

2929
                r = sd_bus_message_read_strv(message, &l);
×
2930
                if (r < 0)
×
2931
                        return r;
2932

2933
                r = sd_bus_message_exit_container(message);
×
2934
                if (r < 0)
×
2935
                        return r;
2936

2937
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
×
2938
                        _cleanup_free_ char *joined = NULL;
×
2939
                        SeccompParseFlags invert_flag = allow_list ? 0 : SECCOMP_PARSE_INVERT;
×
2940

2941
                        if (strv_isempty(l)) {
×
2942
                                c->syscall_log_allow_list = false;
×
2943
                                c->syscall_log = hashmap_free(c->syscall_log);
×
2944

2945
                                unit_write_settingf(u, flags, name, "SystemCallLog=");
×
2946
                                return 1;
2947
                        }
2948

2949
                        if (!c->syscall_log) {
×
2950
                                c->syscall_log = hashmap_new(NULL);
×
2951
                                if (!c->syscall_log)
×
2952
                                        return log_oom();
×
2953

2954
                                c->syscall_log_allow_list = allow_list;
×
2955
                        }
2956

2957
                        STRV_FOREACH(s, l) {
×
2958
                                r = seccomp_parse_syscall_filter(*s,
×
2959
                                                                 -1, /* errno not used */
2960
                                                                 c->syscall_log,
2961
                                                                 SECCOMP_PARSE_LOG | SECCOMP_PARSE_PERMISSIVE |
2962
                                                                 invert_flag |
×
2963
                                                                 (c->syscall_log_allow_list ? SECCOMP_PARSE_ALLOW_LIST : 0),
×
2964
                                                                 u->id,
×
2965
                                                                 NULL, 0);
2966
                                if (r < 0)
×
2967
                                        return r;
2968
                        }
2969

2970
                        joined = strv_join(l, " ");
×
2971
                        if (!joined)
×
2972
                                return -ENOMEM;
2973

2974
                        unit_write_settingf(u, flags, name, "SystemCallLog=%s%s", allow_list ? "" : "~", joined);
×
2975
                }
2976

2977
                return 1;
×
2978

2979
        } else if (streq(name, "SystemCallArchitectures")) {
2,349✔
2980
                _cleanup_strv_free_ char **l = NULL;
×
2981

2982
                r = sd_bus_message_read_strv(message, &l);
×
2983
                if (r < 0)
×
2984
                        return r;
2985

2986
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
×
2987
                        _cleanup_free_ char *joined = NULL;
×
2988

2989
                        if (strv_isempty(l))
×
2990
                                c->syscall_archs = set_free(c->syscall_archs);
×
2991
                        else {
2992
                                r = parse_syscall_archs(l, &c->syscall_archs);
×
2993
                                if (r < 0)
×
2994
                                        return r;
2995
                        }
2996

2997
                        joined = strv_join(l, " ");
×
2998
                        if (!joined)
×
2999
                                return -ENOMEM;
3000

3001
                        unit_write_settingf(u, flags, name, "%s=%s", name, joined);
×
3002
                }
3003

3004
                return 1;
×
3005

3006
        } else if (streq(name, "RestrictAddressFamilies")) {
2,349✔
3007
                _cleanup_strv_free_ char **l = NULL;
×
3008
                int allow_list;
×
3009

3010
                r = sd_bus_message_enter_container(message, 'r', "bas");
×
3011
                if (r < 0)
×
3012
                        return r;
3013

3014
                r = sd_bus_message_read(message, "b", &allow_list);
×
3015
                if (r < 0)
×
3016
                        return r;
3017

3018
                r = sd_bus_message_read_strv(message, &l);
×
3019
                if (r < 0)
×
3020
                        return r;
3021

3022
                r = sd_bus_message_exit_container(message);
×
3023
                if (r < 0)
×
3024
                        return r;
3025

3026
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
×
3027
                        _cleanup_free_ char *joined = NULL;
×
3028

3029
                        if (strv_isempty(l)) {
×
3030
                                c->address_families_allow_list = allow_list;
×
3031
                                c->address_families = set_free(c->address_families);
×
3032

3033
                                unit_write_settingf(u, flags, name, "RestrictAddressFamilies=%s",
×
3034
                                                    allow_list ? "none" : "");
×
3035
                                return 1;
3036
                        }
3037

3038
                        if (!c->address_families) {
×
3039
                                c->address_families = set_new(NULL);
×
3040
                                if (!c->address_families)
×
3041
                                        return log_oom();
×
3042

3043
                                c->address_families_allow_list = allow_list;
×
3044
                        }
3045

3046
                        STRV_FOREACH(s, l) {
×
3047
                                int af;
×
3048

3049
                                af = af_from_name(*s);
×
3050
                                if (af < 0)
×
3051
                                        return af;
3052

3053
                                if (allow_list == c->address_families_allow_list) {
×
3054
                                        r = set_put(c->address_families, INT_TO_PTR(af));
×
3055
                                        if (r < 0)
×
3056
                                                return r;
3057
                                } else
3058
                                        set_remove(c->address_families, INT_TO_PTR(af));
×
3059
                        }
3060

3061
                        joined = strv_join(l, " ");
×
3062
                        if (!joined)
×
3063
                                return -ENOMEM;
3064

3065
                        unit_write_settingf(u, flags, name, "RestrictAddressFamilies=%s%s", allow_list ? "" : "~", joined);
×
3066
                }
3067

3068
                return 1;
×
3069
        }
3070
#endif
3071
        if (STR_IN_SET(name, "CPUAffinity", "NUMAMask")) {
2,349✔
3072
                _cleanup_(cpu_set_done) CPUSet set = {};
×
3073
                const void *a;
×
3074
                size_t n;
×
3075

3076
                r = sd_bus_message_read_array(message, 'y', &a, &n);
×
3077
                if (r < 0)
×
3078
                        return r;
3079

3080
                r = cpu_set_from_dbus(a, n, &set);
×
3081
                if (r < 0)
×
3082
                        return r;
3083

3084
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
×
3085
                        CPUSet *cpuset = streq(name, "CPUAffinity") ? &c->cpu_set : &c->numa_policy.nodes;
×
3086

3087
                        if (n == 0) {
×
3088
                                cpu_set_done(cpuset);
×
3089
                                unit_write_settingf(u, flags, name, "%s=", name);
×
3090
                        } else {
3091
                                _cleanup_free_ char *str = NULL;
×
3092

3093
                                str = cpu_set_to_string(&set);
×
3094
                                if (!str)
×
3095
                                        return -ENOMEM;
3096

3097
                                /* We forego any optimizations here, and always create the structure using
3098
                                 * cpu_set_add_set(), because we don't want to care if the existing size we
3099
                                 * got over dbus is appropriate. */
3100
                                r = cpu_set_add_set(cpuset, &set);
×
3101
                                if (r < 0)
×
3102
                                        return r;
3103

3104
                                unit_write_settingf(u, flags, name, "%s=%s", name, str);
×
3105
                        }
3106
                }
3107

3108
                return 1;
×
3109

3110
        } else if (streq(name, "CPUAffinityFromNUMA")) {
2,349✔
3111
                int q;
×
3112

3113
                r = sd_bus_message_read_basic(message, 'b', &q);
×
3114
                if (r < 0)
×
3115
                        return r;
×
3116

3117
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
×
3118
                        c->cpu_affinity_from_numa = q;
×
3119
                        unit_write_settingf(u, flags, name, "%s=%s", "CPUAffinity", "numa");
×
3120
                }
3121

3122
                return 1;
×
3123

3124
        } else if (streq(name, "NUMAPolicy")) {
2,349✔
3125
                int32_t type;
×
3126

3127
                r = sd_bus_message_read(message, "i", &type);
×
3128
                if (r < 0)
×
3129
                        return r;
×
3130

3131
                if (!mpol_is_valid(type))
×
3132
                        return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Invalid NUMAPolicy value: %i", type);
×
3133

3134
                if (!UNIT_WRITE_FLAGS_NOOP(flags))
×
3135
                        c->numa_policy.type = type;
×
3136

3137
                return 1;
×
3138

3139
        } else if (streq(name, "Nice")) {
2,349✔
3140
                int32_t q;
2✔
3141

3142
                r = sd_bus_message_read(message, "i", &q);
2✔
3143
                if (r < 0)
2✔
3144
                        return r;
2✔
3145

3146
                if (!nice_is_valid(q))
2✔
3147
                        return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Invalid Nice value: %i", q);
×
3148

3149
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
2✔
3150
                        c->nice = q;
1✔
3151
                        c->nice_set = true;
1✔
3152

3153
                        unit_write_settingf(u, flags, name, "Nice=%i", q);
1✔
3154
                }
3155

3156
                return 1;
2✔
3157

3158
        } else if (streq(name, "CPUSchedulingPolicy")) {
2,347✔
3159
                int32_t q;
×
3160

3161
                r = sd_bus_message_read(message, "i", &q);
×
3162
                if (r < 0)
×
3163
                        return r;
×
3164

3165
                if (!sched_policy_is_valid(q))
×
3166
                        return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Invalid CPU scheduling policy: %i", q);
×
3167

3168
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
×
3169
                        _cleanup_free_ char *s = NULL;
×
3170

3171
                        r = sched_policy_to_string_alloc(q, &s);
×
3172
                        if (r < 0)
×
3173
                                return r;
×
3174

3175
                        c->cpu_sched_policy = q;
×
3176
                        c->cpu_sched_priority = CLAMP(c->cpu_sched_priority, sched_get_priority_min_safe(q), sched_get_priority_max_safe(q));
×
3177
                        c->cpu_sched_set = true;
×
3178

3179
                        unit_write_settingf(u, flags, name, "CPUSchedulingPolicy=%s", s);
×
3180
                }
3181

3182
                return 1;
×
3183

3184
        } else if (streq(name, "CPUSchedulingPriority")) {
2,347✔
3185
                int32_t p;
×
3186

3187
                r = sd_bus_message_read(message, "i", &p);
×
3188
                if (r < 0)
×
3189
                        return r;
×
3190

3191
                /* On Linux RR/FIFO range from 1 to 99 and OTHER/BATCH may only be 0. Policy might be set
3192
                 * later so we do not check the precise range, but only the generic outer bounds. */
3193
                if (p < 0 || p > 99)
×
3194
                        return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Invalid CPU scheduling priority: %i", p);
×
3195

3196
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
×
3197
                        c->cpu_sched_priority = p;
×
3198
                        c->cpu_sched_set = true;
×
3199

3200
                        unit_write_settingf(u, flags, name, "CPUSchedulingPriority=%i", p);
×
3201
                }
3202

3203
                return 1;
×
3204

3205
        } else if (streq(name, "IOSchedulingClass")) {
2,347✔
3206
                int32_t q;
×
3207

3208
                r = sd_bus_message_read(message, "i", &q);
×
3209
                if (r < 0)
×
3210
                        return r;
×
3211

3212
                if (!ioprio_class_is_valid(q))
×
3213
                        return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Invalid IO scheduling class: %i", q);
×
3214

3215
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
×
3216
                        _cleanup_free_ char *s = NULL;
×
3217

3218
                        r = ioprio_class_to_string_alloc(q, &s);
×
3219
                        if (r < 0)
×
3220
                                return r;
×
3221

3222
                        c->ioprio = ioprio_normalize(ioprio_prio_value(q, ioprio_prio_data(c->ioprio)));
×
3223
                        c->ioprio_is_set = true;
×
3224

3225
                        unit_write_settingf(u, flags, name, "IOSchedulingClass=%s", s);
×
3226
                }
3227

3228
                return 1;
×
3229

3230
        } else if (streq(name, "IOSchedulingPriority")) {
2,347✔
3231
                int32_t p;
×
3232

3233
                r = sd_bus_message_read(message, "i", &p);
×
3234
                if (r < 0)
×
3235
                        return r;
×
3236

3237
                if (!ioprio_priority_is_valid(p))
×
3238
                        return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Invalid IO scheduling priority: %i", p);
×
3239

3240
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
×
3241
                        c->ioprio = ioprio_normalize(ioprio_prio_value(ioprio_prio_class(c->ioprio), p));
×
3242
                        c->ioprio_is_set = true;
×
3243

3244
                        unit_write_settingf(u, flags, name, "IOSchedulingPriority=%i", p);
×
3245
                }
3246

3247
                return 1;
×
3248

3249
        } else if (streq(name, "WorkingDirectory")) {
2,347✔
3250
                _cleanup_free_ char *simplified = NULL;
162✔
3251
                bool missing_ok = false, is_home = false;
162✔
3252
                const char *s;
162✔
3253

3254
                r = sd_bus_message_read(message, "s", &s);
162✔
3255
                if (r < 0)
162✔
3256
                        return r;
3257

3258
                if (!isempty(s)) {
162✔
3259
                        if (s[0] == '-') {
162✔
3260
                                missing_ok = true;
×
3261
                                s++;
×
3262
                        }
3263

3264
                        if (streq(s, "~"))
162✔
3265
                                is_home = true;
3266
                        else {
3267
                                if (!path_is_absolute(s))
106✔
3268
                                        return sd_bus_error_set(reterr_error, SD_BUS_ERROR_INVALID_ARGS,
×
3269
                                                                "WorkingDirectory= expects an absolute path or '~'");
3270

3271
                                r = path_simplify_alloc(s, &simplified);
106✔
3272
                                if (r < 0)
106✔
3273
                                        return r;
3274

3275
                                if (!path_is_normalized(simplified))
106✔
3276
                                        return sd_bus_error_set(reterr_error, SD_BUS_ERROR_INVALID_ARGS,
×
3277
                                                                "WorkingDirectory= expects a normalized path or '~'");
3278
                        }
3279
                }
3280

3281
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
162✔
3282
                        free_and_replace(c->working_directory, simplified);
81✔
3283
                        c->working_directory_home = is_home;
81✔
3284
                        c->working_directory_missing_ok = missing_ok;
81✔
3285

3286
                        unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name,
81✔
3287
                                            "WorkingDirectory=%s%s",
3288
                                            c->working_directory_missing_ok ? "-" : "",
81✔
3289
                                            c->working_directory_home ? "~" : strempty(c->working_directory));
81✔
3290
                }
3291

3292
                return 1;
162✔
3293

3294
        } else if (STR_IN_SET(name,
2,185✔
3295
                              "StandardInputFileDescriptorName", "StandardOutputFileDescriptorName", "StandardErrorFileDescriptorName")) {
3296
                const char *s;
×
3297

3298
                r = sd_bus_message_read(message, "s", &s);
×
3299
                if (r < 0)
×
3300
                        return r;
×
3301

3302
                if (!isempty(s) && !fdname_is_valid(s))
×
3303
                        return sd_bus_error_set(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Invalid file descriptor name");
×
3304

3305
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
×
3306

3307
                        if (streq(name, "StandardInputFileDescriptorName")) {
×
3308
                                r = free_and_strdup(c->stdio_fdname + STDIN_FILENO, empty_to_null(s));
×
3309
                                if (r < 0)
×
3310
                                        return r;
3311

3312
                                c->std_input = EXEC_INPUT_NAMED_FD;
×
3313
                                unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardInput=fd:%s", exec_context_fdname(c, STDIN_FILENO));
×
3314

3315
                        } else if (streq(name, "StandardOutputFileDescriptorName")) {
×
3316
                                r = free_and_strdup(c->stdio_fdname + STDOUT_FILENO, empty_to_null(s));
×
3317
                                if (r < 0)
×
3318
                                        return r;
3319

3320
                                c->std_output = EXEC_OUTPUT_NAMED_FD;
×
3321
                                unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardOutput=fd:%s", exec_context_fdname(c, STDOUT_FILENO));
×
3322

3323
                        } else {
3324
                                assert(streq(name, "StandardErrorFileDescriptorName"));
×
3325

3326
                                r = free_and_strdup(&c->stdio_fdname[STDERR_FILENO], empty_to_null(s));
×
3327
                                if (r < 0)
×
3328
                                        return r;
3329

3330
                                c->std_error = EXEC_OUTPUT_NAMED_FD;
×
3331
                                unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardError=fd:%s", exec_context_fdname(c, STDERR_FILENO));
×
3332
                        }
3333
                }
3334

3335
                return 1;
×
3336

3337
        } else if (STR_IN_SET(name,
2,185✔
3338
                              "StandardInputFile",
3339
                              "StandardOutputFile", "StandardOutputFileToAppend", "StandardOutputFileToTruncate",
3340
                              "StandardErrorFile", "StandardErrorFileToAppend", "StandardErrorFileToTruncate")) {
3341
                const char *s;
×
3342

3343
                r = sd_bus_message_read(message, "s", &s);
×
3344
                if (r < 0)
×
3345
                        return r;
×
3346

3347
                if (!path_is_absolute(s))
×
3348
                        return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Path %s is not absolute", s);
×
3349
                if (!path_is_normalized(s))
×
3350
                        return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Path %s is not normalized", s);
×
3351

3352
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
×
3353

3354
                        if (streq(name, "StandardInputFile")) {
×
3355
                                r = free_and_strdup(&c->stdio_file[STDIN_FILENO], s);
×
3356
                                if (r < 0)
×
3357
                                        return r;
3358

3359
                                c->std_input = EXEC_INPUT_FILE;
×
3360
                                unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardInput=file:%s", s);
×
3361

3362
                        } else if (STR_IN_SET(name, "StandardOutputFile", "StandardOutputFileToAppend", "StandardOutputFileToTruncate")) {
×
3363
                                r = free_and_strdup(&c->stdio_file[STDOUT_FILENO], s);
×
3364
                                if (r < 0)
×
3365
                                        return r;
×
3366

3367
                                if (streq(name, "StandardOutputFile")) {
×
3368
                                        c->std_output = EXEC_OUTPUT_FILE;
×
3369
                                        unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardOutput=file:%s", s);
×
3370
                                } else if (streq(name, "StandardOutputFileToAppend")) {
×
3371
                                        c->std_output = EXEC_OUTPUT_FILE_APPEND;
×
3372
                                        unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardOutput=append:%s", s);
×
3373
                                } else {
3374
                                        assert(streq(name, "StandardOutputFileToTruncate"));
×
3375
                                        c->std_output = EXEC_OUTPUT_FILE_TRUNCATE;
×
3376
                                        unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardOutput=truncate:%s", s);
×
3377
                                }
3378
                        } else {
3379
                                assert(STR_IN_SET(name, "StandardErrorFile", "StandardErrorFileToAppend", "StandardErrorFileToTruncate"));
×
3380

3381
                                r = free_and_strdup(&c->stdio_file[STDERR_FILENO], s);
×
3382
                                if (r < 0)
×
3383
                                        return r;
3384

3385
                                if (streq(name, "StandardErrorFile")) {
×
3386
                                        c->std_error = EXEC_OUTPUT_FILE;
×
3387
                                        unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardError=file:%s", s);
×
3388
                                } else if (streq(name, "StandardErrorFileToAppend")) {
×
3389
                                        c->std_error = EXEC_OUTPUT_FILE_APPEND;
×
3390
                                        unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardError=append:%s", s);
×
3391
                                } else {
3392
                                        assert(streq(name, "StandardErrorFileToTruncate"));
×
3393
                                        c->std_error = EXEC_OUTPUT_FILE_TRUNCATE;
×
3394
                                        unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "StandardError=truncate:%s", s);
×
3395
                                }
3396
                        }
3397
                }
3398

3399
                return 1;
×
3400

3401
        } else if (streq(name, "StandardInputData")) {
2,185✔
3402
                const void *p;
×
3403
                size_t sz;
×
3404

3405
                r = sd_bus_message_read_array(message, 'y', &p, &sz);
×
3406
                if (r < 0)
×
3407
                        return r;
×
3408

3409
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
×
3410
                        _cleanup_free_ char *encoded = NULL;
×
3411

3412
                        if (sz == 0) {
×
3413
                                c->stdin_data = mfree(c->stdin_data);
×
3414
                                c->stdin_data_size = 0;
×
3415

3416
                                unit_write_settingf(u, flags, name, "StandardInputData=");
×
3417
                        } else {
3418
                                void *q;
×
3419
                                ssize_t n;
×
3420

3421
                                if (c->stdin_data_size + sz < c->stdin_data_size || /* check for overflow */
×
3422
                                    c->stdin_data_size + sz > EXEC_STDIN_DATA_MAX)
3423
                                        return -E2BIG;
3424

3425
                                n = base64mem(p, sz, &encoded);
×
3426
                                if (n < 0)
×
3427
                                        return (int) n;
×
3428

3429
                                q = realloc(c->stdin_data, c->stdin_data_size + sz);
×
3430
                                if (!q)
×
3431
                                        return -ENOMEM;
3432

3433
                                memcpy((uint8_t*) q + c->stdin_data_size, p, sz);
×
3434

3435
                                c->stdin_data = q;
×
3436
                                c->stdin_data_size += sz;
×
3437

3438
                                unit_write_settingf(u, flags, name, "StandardInputData=%s", encoded);
×
3439
                        }
3440
                }
3441

3442
                return 1;
×
3443

3444
        } else if (streq(name, "Environment")) {
2,185✔
3445

3446
                _cleanup_strv_free_ char **l = NULL;
242✔
3447

3448
                r = sd_bus_message_read_strv(message, &l);
242✔
3449
                if (r < 0)
242✔
3450
                        return r;
3451

3452
                if (!strv_env_is_valid(l))
242✔
3453
                        return sd_bus_error_set(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Invalid environment block.");
×
3454

3455
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
242✔
3456
                        if (strv_isempty(l)) {
121✔
3457
                                c->environment = strv_free(c->environment);
×
3458
                                unit_write_setting(u, flags, name, "Environment=");
×
3459
                        } else {
3460
                                _cleanup_free_ char *joined = NULL;
121✔
3461
                                char **e;
121✔
3462

3463
                                joined = unit_concat_strv(l, UNIT_ESCAPE_SPECIFIERS|UNIT_ESCAPE_C);
121✔
3464
                                if (!joined)
121✔
3465
                                        return -ENOMEM;
3466

3467
                                e = strv_env_merge(c->environment, l);
121✔
3468
                                if (!e)
121✔
3469
                                        return -ENOMEM;
3470

3471
                                strv_free_and_replace(c->environment, e);
121✔
3472
                                unit_write_settingf(u, flags, name, "Environment=%s", joined);
121✔
3473
                        }
3474
                }
3475

3476
                return 1;
242✔
3477

3478
        } else if (streq(name, "UnsetEnvironment")) {
1,943✔
3479

3480
                _cleanup_strv_free_ char **l = NULL;
×
3481

3482
                r = sd_bus_message_read_strv(message, &l);
×
3483
                if (r < 0)
×
3484
                        return r;
3485

3486
                if (!strv_env_name_or_assignment_is_valid(l))
×
3487
                        return sd_bus_error_set(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Invalid UnsetEnvironment= list.");
×
3488

3489
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
×
3490
                        if (strv_isempty(l)) {
×
3491
                                c->unset_environment = strv_free(c->unset_environment);
×
3492
                                unit_write_setting(u, flags, name, "UnsetEnvironment=");
×
3493
                        } else {
3494
                                _cleanup_free_ char *joined = NULL;
×
3495
                                char **e;
×
3496

3497
                                joined = unit_concat_strv(l, UNIT_ESCAPE_SPECIFIERS|UNIT_ESCAPE_C);
×
3498
                                if (!joined)
×
3499
                                        return -ENOMEM;
3500

3501
                                e = strv_env_merge(c->unset_environment, l);
×
3502
                                if (!e)
×
3503
                                        return -ENOMEM;
3504

3505
                                strv_free_and_replace(c->unset_environment, e);
×
3506
                                unit_write_settingf(u, flags, name, "UnsetEnvironment=%s", joined);
×
3507
                        }
3508
                }
3509

3510
                return 1;
×
3511

3512
        } else if (streq(name, "OOMScoreAdjust")) {
1,943✔
3513
                int oa;
×
3514

3515
                r = sd_bus_message_read(message, "i", &oa);
×
3516
                if (r < 0)
×
3517
                        return r;
×
3518

3519
                if (!oom_score_adjust_is_valid(oa))
×
3520
                        return sd_bus_error_set(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "OOM score adjust value out of range");
×
3521

3522
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
×
3523
                        c->oom_score_adjust = oa;
×
3524
                        c->oom_score_adjust_set = true;
×
3525
                        unit_write_settingf(u, flags, name, "OOMScoreAdjust=%i", oa);
×
3526
                }
3527

3528
                return 1;
×
3529

3530
        } else if (streq(name, "CoredumpFilter")) {
1,943✔
3531
                uint64_t f;
×
3532

3533
                r = sd_bus_message_read(message, "t", &f);
×
3534
                if (r < 0)
×
3535
                        return r;
×
3536

3537
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
×
3538
                        c->coredump_filter = f;
×
3539
                        c->coredump_filter_set = true;
×
3540
                        unit_write_settingf(u, flags, name, "CoredumpFilter=0x%"PRIx64, f);
×
3541
                }
3542

3543
                return 1;
×
3544

3545
        } else if (streq(name, "EnvironmentFiles")) {
1,943✔
3546
                _cleanup_(memstream_done) MemStream m = {};
×
3547
                _cleanup_free_ char *joined = NULL;
4✔
3548
                _cleanup_strv_free_ char **l = NULL;
4✔
3549
                FILE *f;
4✔
3550

3551
                r = sd_bus_message_enter_container(message, 'a', "(sb)");
4✔
3552
                if (r < 0)
4✔
3553
                        return r;
3554

3555
                f = memstream_init(&m);
4✔
3556
                if (!f)
4✔
3557
                        return -ENOMEM;
3558

3559
                fputs("EnvironmentFile=\n", f);
4✔
3560

3561
                STRV_FOREACH(i, c->environment_files) {
4✔
3562
                        _cleanup_free_ char *q = NULL;
×
3563

3564
                        q = specifier_escape(*i);
×
3565
                        if (!q)
×
3566
                                return -ENOMEM;
×
3567

3568
                        fprintf(f, "EnvironmentFile=%s\n", q);
×
3569
                }
3570

3571
                while ((r = sd_bus_message_enter_container(message, 'r', "sb")) > 0) {
8✔
3572
                        const char *path;
4✔
3573
                        int b;
4✔
3574

3575
                        r = sd_bus_message_read(message, "sb", &path, &b);
4✔
3576
                        if (r < 0)
4✔
3577
                                return r;
×
3578

3579
                        r = sd_bus_message_exit_container(message);
4✔
3580
                        if (r < 0)
4✔
3581
                                return r;
3582

3583
                        if (!path_is_absolute(path))
4✔
3584
                                return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Path %s is not absolute.", path);
×
3585

3586
                        if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
4✔
3587
                                _cleanup_free_ char *q = NULL, *buf = NULL;
2✔
3588

3589
                                buf = strjoin(b ? "-" : "", path);
3✔
3590
                                if (!buf)
2✔
3591
                                        return -ENOMEM;
3592

3593
                                q = specifier_escape(buf);
2✔
3594
                                if (!q)
2✔
3595
                                        return -ENOMEM;
3596

3597
                                fprintf(f, "EnvironmentFile=%s\n", q);
2✔
3598

3599
                                r = strv_consume(&l, TAKE_PTR(buf));
2✔
3600
                                if (r < 0)
2✔
3601
                                        return r;
3602
                        }
3603
                }
3604
                if (r < 0)
4✔
3605
                        return r;
3606

3607
                r = sd_bus_message_exit_container(message);
4✔
3608
                if (r < 0)
4✔
3609
                        return r;
3610

3611
                r = memstream_finalize(&m, &joined, NULL);
4✔
3612
                if (r < 0)
4✔
3613
                        return r;
3614

3615
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
4✔
3616
                        if (strv_isempty(l)) {
2✔
3617
                                c->environment_files = strv_free(c->environment_files);
×
3618
                                unit_write_setting(u, flags, name, "EnvironmentFile=");
×
3619
                        } else {
3620
                                r = strv_extend_strv(&c->environment_files, l, true);
2✔
3621
                                if (r < 0)
2✔
3622
                                        return r;
3623

3624
                                unit_write_setting(u, flags, name, joined);
2✔
3625
                        }
3626
                }
3627

3628
                return 1;
4✔
3629

3630
        } else if (streq(name, "PassEnvironment")) {
1,939✔
3631

3632
                _cleanup_strv_free_ char **l = NULL;
×
3633

3634
                r = sd_bus_message_read_strv(message, &l);
×
3635
                if (r < 0)
×
3636
                        return r;
3637

3638
                if (!strv_env_name_is_valid(l))
×
3639
                        return sd_bus_error_set(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Invalid PassEnvironment= block.");
×
3640

3641
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
×
3642
                        if (strv_isempty(l)) {
×
3643
                                c->pass_environment = strv_free(c->pass_environment);
×
3644
                                unit_write_setting(u, flags, name, "PassEnvironment=");
×
3645
                        } else {
3646
                                _cleanup_free_ char *joined = NULL;
×
3647

3648
                                r = strv_extend_strv(&c->pass_environment, l, true);
×
3649
                                if (r < 0)
×
3650
                                        return r;
3651

3652
                                /* We write just the new settings out to file, with unresolved specifiers. */
3653
                                joined = unit_concat_strv(l, UNIT_ESCAPE_SPECIFIERS);
×
3654
                                if (!joined)
×
3655
                                        return -ENOMEM;
3656

3657
                                unit_write_settingf(u, flags, name, "PassEnvironment=%s", joined);
×
3658
                        }
3659
                }
3660

3661
                return 1;
×
3662

3663
        } else if (STR_IN_SET(name, "ReadWriteDirectories", "ReadOnlyDirectories", "InaccessibleDirectories",
1,939✔
3664
                              "ReadWritePaths", "ReadOnlyPaths", "InaccessiblePaths", "ExecPaths", "NoExecPaths",
3665
                              "ExtensionDirectories")) {
3666
                _cleanup_strv_free_ char **l = NULL;
14✔
3667
                char ***dirs;
14✔
3668

3669
                r = sd_bus_message_read_strv(message, &l);
14✔
3670
                if (r < 0)
14✔
3671
                        return r;
3672

3673
                STRV_FOREACH(p, l) {
32✔
3674
                        char *i = *p;
18✔
3675
                        size_t offset;
18✔
3676

3677
                        offset = i[0] == '-';
18✔
3678
                        offset += i[offset] == '+';
18✔
3679
                        if (!path_is_absolute(i + offset))
18✔
3680
                                return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Invalid %s", name);
×
3681

3682
                        path_simplify(i + offset);
18✔
3683
                }
3684

3685
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
14✔
3686
                        if (STR_IN_SET(name, "ReadWriteDirectories", "ReadWritePaths"))
7✔
3687
                                dirs = &c->read_write_paths;
1✔
3688
                        else if (STR_IN_SET(name, "ReadOnlyDirectories", "ReadOnlyPaths"))
6✔
3689
                                dirs = &c->read_only_paths;
2✔
3690
                        else if (streq(name, "ExecPaths"))
4✔
3691
                                dirs = &c->exec_paths;
1✔
3692
                        else if (streq(name, "NoExecPaths"))
3✔
3693
                                dirs = &c->no_exec_paths;
1✔
3694
                        else if (streq(name, "ExtensionDirectories"))
2✔
3695
                                dirs = &c->extension_directories;
1✔
3696
                        else /* "InaccessiblePaths" */
3697
                                dirs = &c->inaccessible_paths;
1✔
3698

3699
                        if (strv_isempty(l)) {
7✔
3700
                                *dirs = strv_free(*dirs);
×
3701
                                unit_write_settingf(u, flags, name, "%s=", name);
×
3702
                        } else {
3703
                                _cleanup_free_ char *joined = NULL;
7✔
3704

3705
                                joined = unit_concat_strv(l, UNIT_ESCAPE_SPECIFIERS);
7✔
3706
                                if (!joined)
7✔
3707
                                        return -ENOMEM;
3708

3709
                                r = strv_extend_strv(dirs, l, true);
7✔
3710
                                if (r < 0)
7✔
3711
                                        return r;
3712

3713
                                unit_write_settingf(u, flags, name, "%s=%s", name, joined);
7✔
3714
                        }
3715
                }
3716

3717
                return 1;
14✔
3718

3719
        } else if (streq(name, "ExecSearchPath")) {
1,925✔
3720
                _cleanup_strv_free_ char **l = NULL;
×
3721

3722
                r = sd_bus_message_read_strv(message, &l);
×
3723
                if (r < 0)
×
3724
                        return r;
3725

3726
                STRV_FOREACH(p, l)
×
3727
                        if (!path_is_absolute(*p) || !path_is_normalized(*p) || strchr(*p, ':'))
×
3728
                                return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Invalid %s", name);
×
3729

3730
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
×
3731
                        if (strv_isempty(l)) {
×
3732
                                c->exec_search_path = strv_free(c->exec_search_path);
×
3733
                                unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "ExecSearchPath=");
×
3734
                        } else {
3735
                                _cleanup_free_ char *joined = NULL;
×
3736
                                r = strv_extend_strv(&c->exec_search_path, l, true);
×
3737
                                if (r < 0)
×
3738
                                        return r;
3739
                                joined = strv_join(c->exec_search_path, ":");
×
3740
                                if (!joined)
×
3741
                                        return log_oom();
×
3742
                                unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "ExecSearchPath=%s", joined);
×
3743
                        }
3744
                }
3745

3746
                return 1;
×
3747

3748
        } else if (STR_IN_SET(name, "RuntimeDirectory", "StateDirectory", "CacheDirectory", "LogsDirectory", "ConfigurationDirectory")) {
1,925✔
3749
                _cleanup_strv_free_ char **l = NULL;
114✔
3750

3751
                r = sd_bus_message_read_strv(message, &l);
114✔
3752
                if (r < 0)
114✔
3753
                        return r;
3754

3755
                STRV_FOREACH(p, l) {
288✔
3756
                        if (!path_is_normalized(*p))
174✔
3757
                                return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "%s= path is not normalized: %s", name, *p);
×
3758

3759
                        if (path_is_absolute(*p))
174✔
3760
                                return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "%s= path is absolute: %s", name, *p);
×
3761

3762
                        if (path_startswith(*p, "private"))
174✔
3763
                                return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "%s= path can't be 'private': %s", name, *p);
×
3764
                }
3765

3766
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
114✔
3767
                        ExecDirectoryType i;
57✔
3768
                        ExecDirectory *d;
57✔
3769

3770
                        assert_se((i = exec_directory_type_from_string(name)) >= 0);
57✔
3771
                        d = c->directories + i;
57✔
3772

3773
                        if (strv_isempty(l)) {
57✔
3774
                                exec_directory_done(d);
×
3775
                                unit_write_settingf(u, flags, name, "%s=", name);
×
3776
                        } else {
3777
                                _cleanup_free_ char *joined = NULL;
57✔
3778

3779
                                STRV_FOREACH(source, l) {
144✔
3780
                                        r = exec_directory_add(d, *source, /* symlink= */ NULL, /* flags= */ 0);
87✔
3781
                                        if (r < 0)
87✔
3782
                                                return log_oom();
×
3783
                                }
3784
                                exec_directory_sort(d);
57✔
3785

3786
                                joined = unit_concat_strv(l, UNIT_ESCAPE_SPECIFIERS);
57✔
3787
                                if (!joined)
57✔
3788
                                        return -ENOMEM;
3789

3790
                                unit_write_settingf(u, flags, name, "%s=%s", name, joined);
57✔
3791
                        }
3792
                }
3793

3794
                return 1;
114✔
3795

3796
        } else if (STR_IN_SET(name, "StateDirectoryQuota", "CacheDirectoryQuota", "LogsDirectoryQuota")) {
1,811✔
3797
                uint64_t quota_absolute = UINT64_MAX;
×
3798
                uint32_t quota_scale = UINT32_MAX;
×
3799
                const char *enforce_flag;
×
3800
                int quota_enforce;
×
3801

3802
                r = sd_bus_message_read(message, "(tus)", &quota_absolute, &quota_scale, &enforce_flag);
×
3803
                if (r < 0)
×
3804
                        return r;
×
3805

3806
                quota_enforce = parse_boolean(enforce_flag);
×
3807
                if (quota_enforce < 0)
×
3808
                        return quota_enforce;
3809

3810
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
×
3811
                        ExecDirectoryType dt;
×
3812
                        if (streq(name, "StateDirectoryQuota"))
×
3813
                                dt = EXEC_DIRECTORY_STATE;
3814
                        else if (streq(name, "CacheDirectoryQuota"))
×
3815
                                dt = EXEC_DIRECTORY_CACHE;
3816
                        else if (streq(name, "LogsDirectoryQuota"))
×
3817
                                dt = EXEC_DIRECTORY_LOGS;
3818
                        else
3819
                                assert_not_reached();
×
3820

3821
                        if (quota_enforce) {
×
3822
                                c->directories[dt].exec_quota.quota_absolute = quota_absolute;
×
3823
                                c->directories[dt].exec_quota.quota_scale = quota_scale;
×
3824

3825
                                if (quota_absolute != UINT64_MAX)
×
3826
                                        unit_write_settingf(u, flags, name, "%s=%" PRIu64, name, quota_absolute);
×
3827
                                else
3828
                                        unit_write_settingf(u, flags, name, "%s=%d%%", name, UINT32_SCALE_TO_PERCENT(quota_scale));
×
3829
                        } else
3830
                                unit_write_settingf(u, flags, name, "%s=", name);
×
3831

3832
                        c->directories[dt].exec_quota.quota_enforce = quota_enforce;
×
3833
                }
3834

3835
                return 1;
×
3836

3837
        } else if (STR_IN_SET(name, "AppArmorProfile", "SmackProcessLabel")) {
1,811✔
3838
                int ignore;
×
3839
                const char *s;
×
3840

3841
                r = sd_bus_message_read(message, "(bs)", &ignore, &s);
×
3842
                if (r < 0)
×
3843
                        return r;
×
3844

3845
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
×
3846
                        char **p;
×
3847
                        bool *b;
×
3848

3849
                        if (streq(name, "AppArmorProfile")) {
×
3850
                                p = &c->apparmor_profile;
×
3851
                                b = &c->apparmor_profile_ignore;
×
3852
                        } else { /* "SmackProcessLabel" */
3853
                                p = &c->smack_process_label;
×
3854
                                b = &c->smack_process_label_ignore;
×
3855
                        }
3856

3857
                        if (isempty(s)) {
×
3858
                                *p = mfree(*p);
×
3859
                                *b = false;
×
3860
                        } else {
3861
                                if (free_and_strdup(p, s) < 0)
×
3862
                                        return -ENOMEM;
3863
                                *b = ignore;
×
3864
                        }
3865

3866
                        unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "%s=%s%s", name, ignore ? "-" : "", strempty(s));
×
3867
                }
3868

3869
                return 1;
×
3870

3871
        } else if (STR_IN_SET(name, "BindPaths", "BindReadOnlyPaths")) {
1,811✔
3872
                char *source, *destination;
14✔
3873
                int ignore_enoent;
14✔
3874
                uint64_t mount_flags;
14✔
3875
                bool empty = true;
14✔
3876

3877
                r = sd_bus_message_enter_container(message, 'a', "(ssbt)");
14✔
3878
                if (r < 0)
14✔
3879
                        return r;
14✔
3880

3881
                while ((r = sd_bus_message_read(message, "(ssbt)", &source, &destination, &ignore_enoent, &mount_flags)) > 0) {
44✔
3882

3883
                        if (!path_is_absolute(source))
30✔
3884
                                return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Source path %s is not absolute.", source);
×
3885
                        if (!path_is_absolute(destination))
30✔
3886
                                return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Destination path %s is not absolute.", destination);
×
3887
                        if (!IN_SET(mount_flags, 0, MS_REC))
30✔
3888
                                return sd_bus_error_set(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Unknown mount flags.");
×
3889

3890
                        if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
30✔
3891
                                r = bind_mount_add(&c->bind_mounts, &c->n_bind_mounts,
30✔
3892
                                                   &(BindMount) {
15✔
3893
                                                           .source = source,
3894
                                                           .destination = destination,
3895
                                                           .read_only = !!strstr(name, "ReadOnly"),
15✔
3896
                                                           .recursive = !!(mount_flags & MS_REC),
15✔
3897
                                                           .ignore_enoent = ignore_enoent,
15✔
3898
                                                   });
3899
                                if (r < 0)
15✔
3900
                                        return r;
×
3901

3902
                                unit_write_settingf(
45✔
3903
                                                u, flags|UNIT_ESCAPE_SPECIFIERS, name,
15✔
3904
                                                "%s=%s%s:%s:%s",
3905
                                                name,
3906
                                                ignore_enoent ? "-" : "",
15✔
3907
                                                source,
3908
                                                destination,
3909
                                                (mount_flags & MS_REC) ? "rbind" : "norbind");
15✔
3910
                        }
3911

3912
                        empty = false;
3913
                }
3914
                if (r < 0)
14✔
3915
                        return r;
3916

3917
                r = sd_bus_message_exit_container(message);
14✔
3918
                if (r < 0)
14✔
3919
                        return r;
3920

3921
                if (!UNIT_WRITE_FLAGS_NOOP(flags) && empty) {
14✔
3922
                        bind_mount_free_many(c->bind_mounts, c->n_bind_mounts);
×
3923
                        c->bind_mounts = NULL;
×
3924
                        c->n_bind_mounts = 0;
×
3925

3926
                        unit_write_settingf(u, flags, name, "%s=", name);
×
3927
                }
3928

3929
                return 1;
14✔
3930

3931
        } else if (streq(name, "TemporaryFileSystem")) {
1,797✔
3932
                const char *path, *options;
8✔
3933
                bool empty = true;
8✔
3934

3935
                r = sd_bus_message_enter_container(message, 'a', "(ss)");
8✔
3936
                if (r < 0)
8✔
3937
                        return r;
8✔
3938

3939
                while ((r = sd_bus_message_read(message, "(ss)", &path, &options)) > 0) {
16✔
3940

3941
                        if (!path_is_absolute(path))
8✔
3942
                                return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Mount point %s is not absolute.", path);
×
3943

3944
                        if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
8✔
3945
                                r = temporary_filesystem_add(&c->temporary_filesystems, &c->n_temporary_filesystems, path, options);
4✔
3946
                                if (r < 0)
4✔
3947
                                        return r;
3948

3949
                                unit_write_settingf(
4✔
3950
                                                u, flags|UNIT_ESCAPE_SPECIFIERS, name,
4✔
3951
                                                "%s=%s:%s",
3952
                                                name,
3953
                                                path,
3954
                                                options);
3955
                        }
3956

3957
                        empty = false;
3958
                }
3959
                if (r < 0)
8✔
3960
                        return r;
3961

3962
                r = sd_bus_message_exit_container(message);
8✔
3963
                if (r < 0)
8✔
3964
                        return r;
3965

3966
                if (!UNIT_WRITE_FLAGS_NOOP(flags) && empty) {
8✔
3967
                        temporary_filesystem_free_many(c->temporary_filesystems, c->n_temporary_filesystems);
×
3968
                        c->temporary_filesystems = NULL;
×
3969
                        c->n_temporary_filesystems = 0;
×
3970

3971
                        unit_write_settingf(u, flags, name, "%s=", name);
×
3972
                }
3973

3974
                return 1;
8✔
3975

3976
        } else if ((suffix = startswith(name, "Limit"))) {
1,789✔
3977
                const char *soft = NULL;
96✔
3978
                int ri;
96✔
3979

3980
                ri = rlimit_from_string(suffix);
96✔
3981
                if (ri < 0) {
96✔
3982
                        soft = endswith(suffix, "Soft");
48✔
3983
                        if (soft) {
48✔
3984
                                const char *n;
48✔
3985

3986
                                n = strndupa_safe(suffix, soft - suffix);
48✔
3987
                                ri = rlimit_from_string(n);
48✔
3988
                                if (ri >= 0)
48✔
3989
                                        name = strjoina("Limit", n);
240✔
3990
                        }
3991
                }
3992

3993
                if (ri >= 0) {
48✔
3994
                        uint64_t rl;
96✔
3995
                        rlim_t x;
96✔
3996

3997
                        r = sd_bus_message_read(message, "t", &rl);
96✔
3998
                        if (r < 0)
96✔
3999
                                return r;
96✔
4000

4001
                        if (rl == UINT64_MAX)
96✔
4002
                                x = RLIM_INFINITY;
4003
                        else {
4004
                                x = (rlim_t) rl;
80✔
4005

4006
                                if ((uint64_t) x != rl)
80✔
4007
                                        return -ERANGE;
4008
                        }
4009

4010
                        if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
96✔
4011
                                _cleanup_free_ char *f = NULL;
48✔
4012
                                struct rlimit nl;
48✔
4013

4014
                                if (c->rlimit[ri]) {
48✔
4015
                                        nl = *c->rlimit[ri];
30✔
4016

4017
                                        if (soft)
30✔
4018
                                                nl.rlim_cur = x;
24✔
4019
                                        else
4020
                                                nl.rlim_max = x;
6✔
4021
                                } else
4022
                                        /* When the resource limit is not initialized yet, then assign the value to both fields */
4023
                                        nl = (struct rlimit) {
18✔
4024
                                                .rlim_cur = x,
4025
                                                .rlim_max = x,
4026
                                        };
4027

4028
                                r = rlimit_format(&nl, &f);
48✔
4029
                                if (r < 0)
48✔
4030
                                        return r;
4031

4032
                                if (c->rlimit[ri])
48✔
4033
                                        *c->rlimit[ri] = nl;
30✔
4034
                                else {
4035
                                        c->rlimit[ri] = newdup(struct rlimit, &nl, 1);
18✔
4036
                                        if (!c->rlimit[ri])
18✔
4037
                                                return -ENOMEM;
4038
                                }
4039

4040
                                unit_write_settingf(u, flags, name, "%s=%s", name, f);
48✔
4041
                        }
4042

4043
                        return 1;
96✔
4044
                }
4045

4046
        } else if (streq(name, "MountImages")) {
1,693✔
4047
                _cleanup_free_ char *format_str = NULL;
4✔
4048
                MountImage *mount_images = NULL;
4✔
4049
                size_t n_mount_images = 0;
4✔
4050

4051
                CLEANUP_ARRAY(mount_images, n_mount_images, mount_image_free_many);
4✔
4052

4053
                r = sd_bus_message_enter_container(message, 'a', "(ssba(ss))");
4✔
4054
                if (r < 0)
4✔
4055
                        return r;
4056

4057
                for (;;) {
4✔
4058
                        _cleanup_(mount_options_free_allp) MountOptions *options = NULL;
×
4059
                        _cleanup_free_ char *source_escaped = NULL, *destination_escaped = NULL;
8✔
4060
                        char *source, *destination;
8✔
4061
                        int permissive;
8✔
4062

4063
                        r = sd_bus_message_enter_container(message, 'r', "ssba(ss)");
8✔
4064
                        if (r < 0)
8✔
4065
                                return r;
4066

4067
                        r = sd_bus_message_read(message, "ssb", &source, &destination, &permissive);
8✔
4068
                        if (r <= 0)
8✔
4069
                                break;
4070

4071
                        if (!path_is_absolute(source))
4✔
UNCOV
4072
                                return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Source path %s is not absolute.", source);
×
4073
                        if (!path_is_normalized(source))
4✔
UNCOV
4074
                                return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Source path %s is not normalized.", source);
×
4075
                        if (!path_is_absolute(destination))
4✔
UNCOV
4076
                                return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Destination path %s is not absolute.", destination);
×
4077
                        if (!path_is_normalized(destination))
4✔
UNCOV
4078
                                return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Destination path %s is not normalized.", destination);
×
4079

4080
                        /* Need to store them in the unit with the escapes, so that they can be parsed again */
4081
                        source_escaped = shell_escape(source, ":");
4✔
4082
                        if (!source_escaped)
4✔
4083
                                return -ENOMEM;
4084
                        destination_escaped = shell_escape(destination, ":");
4✔
4085
                        if (!destination_escaped)
4✔
4086
                                return -ENOMEM;
4087

4088
                        r = strextendf_with_separator(&format_str, " ", "%s%s:%s",
4✔
4089
                                                      permissive ? "-" : "",
4✔
4090
                                                      source_escaped,
4091
                                                      destination_escaped);
4092
                        if (r < 0)
4✔
4093
                                return r;
4094

4095
                        r = bus_read_mount_options(message, reterr_error, &options, &format_str, ":");
4✔
4096
                        if (r < 0)
4✔
4097
                                return r;
4098

4099
                        r = sd_bus_message_exit_container(message);
4✔
4100
                        if (r < 0)
4✔
4101
                                return r;
4102

4103
                        r = mount_image_add(&mount_images, &n_mount_images,
8✔
4104
                                            &(MountImage) {
4✔
4105
                                                    .source = source,
4106
                                                    .destination = destination,
4107
                                                    .mount_options = options,
4108
                                                    .ignore_enoent = permissive,
4✔
4109
                                                    .type = MOUNT_IMAGE_DISCRETE,
4110
                                            });
4111
                        if (r < 0)
4✔
4112
                                return r;
4113
                }
4114
                if (r < 0)
4✔
4115
                        return r;
4116

4117
                r = sd_bus_message_exit_container(message);
4✔
4118
                if (r < 0)
4✔
4119
                        return r;
4120

4121
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
4✔
4122
                        if (n_mount_images == 0) {
2✔
UNCOV
4123
                                mount_image_free_many(c->mount_images, c->n_mount_images);
×
UNCOV
4124
                                c->mount_images = NULL;
×
4125
                                c->n_mount_images = 0;
×
4126

4127
                                unit_write_settingf(u, flags, name, "%s=", name);
×
4128
                        } else {
4129
                                if (!c->mount_images) {
2✔
4130
                                        c->mount_images = TAKE_PTR(mount_images);
2✔
4131
                                        c->n_mount_images = n_mount_images;
2✔
4132
                                } else
UNCOV
4133
                                        FOREACH_ARRAY(i, mount_images, n_mount_images) {
×
UNCOV
4134
                                                r = mount_image_add(&c->mount_images, &c->n_mount_images, i);
×
UNCOV
4135
                                                if (r < 0)
×
4136
                                                        return r;
4137
                                        }
4138

4139
                                unit_write_settingf(u, flags|UNIT_ESCAPE_C|UNIT_ESCAPE_SPECIFIERS,
2✔
4140
                                                    name,
4141
                                                    "%s=%s",
4142
                                                    name,
4143
                                                    format_str);
4144
                        }
4145
                }
4146

4147
                return 1;
4✔
4148

4149
        } else if (streq(name, "ExtensionImages")) {
1,689✔
4150
                _cleanup_free_ char *format_str = NULL;
14✔
4151
                MountImage *extension_images = NULL;
14✔
4152
                size_t n_extension_images = 0;
14✔
4153

4154
                CLEANUP_ARRAY(extension_images, n_extension_images, mount_image_free_many);
14✔
4155

4156
                r = sd_bus_message_enter_container(message, 'a', "(sba(ss))");
14✔
4157
                if (r < 0)
14✔
4158
                        return r;
4159

4160
                for (;;) {
14✔
UNCOV
4161
                        _cleanup_(mount_options_free_allp) MountOptions *options = NULL;
×
4162
                        _cleanup_free_ char *source_escaped = NULL;
28✔
4163
                        char *source;
28✔
4164
                        int permissive;
28✔
4165

4166
                        r = sd_bus_message_enter_container(message, 'r', "sba(ss)");
28✔
4167
                        if (r < 0)
28✔
4168
                                return r;
4169

4170
                        r = sd_bus_message_read(message, "sb", &source, &permissive);
28✔
4171
                        if (r <= 0)
28✔
4172
                                break;
4173

4174
                        if (!path_is_absolute(source))
14✔
UNCOV
4175
                                return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Source path %s is not absolute.", source);
×
4176
                        if (!path_is_normalized(source))
14✔
UNCOV
4177
                                return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Source path %s is not normalized.", source);
×
4178

4179
                        /* Need to store them in the unit with the escapes, so that they can be parsed again */
4180
                        source_escaped = shell_escape(source, ":");
14✔
4181
                        if (!source_escaped)
14✔
4182
                                return -ENOMEM;
4183

4184
                        r = strextendf_with_separator(&format_str, " ", "%s%s",
14✔
4185
                                                      permissive ? "-" : "", source_escaped);
14✔
4186
                        if (r < 0)
14✔
4187
                                return r;
4188

4189
                        r = bus_read_mount_options(message, reterr_error, &options, &format_str, ":");
14✔
4190
                        if (r < 0)
14✔
4191
                                return r;
4192

4193
                        r = sd_bus_message_exit_container(message);
14✔
4194
                        if (r < 0)
14✔
4195
                                return r;
4196

4197
                        r = mount_image_add(&extension_images, &n_extension_images,
28✔
4198
                                            &(MountImage) {
14✔
4199
                                                    .source = source,
4200
                                                    .mount_options = options,
4201
                                                    .ignore_enoent = permissive,
14✔
4202
                                                    .type = MOUNT_IMAGE_EXTENSION,
4203
                                            });
4204
                        if (r < 0)
14✔
4205
                                return r;
4206
                }
4207
                if (r < 0)
14✔
4208
                        return r;
4209

4210
                r = sd_bus_message_exit_container(message);
14✔
4211
                if (r < 0)
14✔
4212
                        return r;
4213

4214
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
14✔
4215
                        if (n_extension_images == 0) {
7✔
4216
                                mount_image_free_many(c->extension_images, c->n_extension_images);
×
UNCOV
4217
                                c->extension_images = NULL;
×
UNCOV
4218
                                c->n_extension_images = 0;
×
4219

UNCOV
4220
                                unit_write_settingf(u, flags, name, "%s=", name);
×
4221
                        } else {
4222
                                if (!c->extension_images) {
7✔
4223
                                        c->extension_images = TAKE_PTR(extension_images);
7✔
4224
                                        c->n_extension_images = n_extension_images;
7✔
4225
                                } else
UNCOV
4226
                                        FOREACH_ARRAY(i, extension_images, n_extension_images) {
×
UNCOV
4227
                                                r = mount_image_add(&c->extension_images, &c->n_extension_images, i);
×
UNCOV
4228
                                                if (r < 0)
×
4229
                                                        return r;
4230
                                        }
4231

4232
                                unit_write_settingf(u, flags|UNIT_ESCAPE_C|UNIT_ESCAPE_SPECIFIERS,
7✔
4233
                                                    name,
4234
                                                    "%s=%s",
4235
                                                    name,
4236
                                                    format_str);
4237
                        }
4238
                }
4239

4240
                return 1;
14✔
4241

4242
        } else if (STR_IN_SET(name, "StateDirectorySymlink", "RuntimeDirectorySymlink", "CacheDirectorySymlink", "LogsDirectorySymlink")) {
1,675✔
4243
                char *source, *destination;
14✔
4244
                ExecDirectory *directory;
14✔
4245
                uint64_t symlink_flags;
14✔
4246
                ExecDirectoryType i;
14✔
4247

4248
                assert_se((i = exec_directory_type_symlink_from_string(name)) >= 0);
14✔
4249
                directory = c->directories + i;
14✔
4250

4251
                r = sd_bus_message_enter_container(message, 'a', "(sst)");
14✔
4252
                if (r < 0)
14✔
4253
                        return r;
14✔
4254

4255
                while ((r = sd_bus_message_read(message, "(sst)", &source, &destination, &symlink_flags)) > 0) {
28✔
4256
                        if ((symlink_flags & ~_EXEC_DIRECTORY_FLAGS_PUBLIC) != 0)
14✔
4257
                                return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Invalid 'flags' parameter '%" PRIu64 "'", symlink_flags);
×
4258
                        if (!path_is_valid(source))
14✔
UNCOV
4259
                                return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Source path %s is not valid.", source);
×
4260
                        if (path_is_absolute(source))
14✔
UNCOV
4261
                                return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Source path %s is absolute.", source);
×
4262
                        if (!path_is_normalized(source))
14✔
UNCOV
4263
                                return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Source path %s is not normalized.", source);
×
4264
                        if (isempty(destination))
14✔
4265
                                destination = NULL;
2✔
4266
                        else {
4267
                                if (!path_is_valid(destination))
12✔
UNCOV
4268
                                        return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Destination path %s is not valid.", destination);
×
4269
                                if (path_is_absolute(destination))
12✔
UNCOV
4270
                                        return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Destination path %s is absolute.", destination);
×
4271
                                if (!path_is_normalized(destination))
12✔
UNCOV
4272
                                        return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Destination path %s is not normalized.", destination);
×
4273
                        }
4274

4275
                        if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
14✔
4276
                                _cleanup_free_ char *destination_escaped = NULL, *source_escaped = NULL;
7✔
4277

4278
                                r = exec_directory_add(directory, source, destination, symlink_flags);
7✔
4279
                                if (r < 0)
7✔
4280
                                        return r;
4281

4282
                                /* Need to store them in the unit with the escapes, so that they can be parsed again */
4283
                                source_escaped = xescape(source, ":");
7✔
4284
                                if (!source_escaped)
7✔
4285
                                        return -ENOMEM;
4286
                                if (destination) {
7✔
4287
                                        destination_escaped = xescape(destination, ":");
6✔
4288
                                        if (!destination_escaped)
6✔
4289
                                                return -ENOMEM;
4290
                                }
4291

4292
                                unit_write_settingf(
8✔
4293
                                                u, flags|UNIT_ESCAPE_SPECIFIERS, exec_directory_type_to_string(i),
7✔
4294
                                                "%s=%s%s%s%s",
4295
                                                exec_directory_type_to_string(i),
4296
                                                source_escaped,
4297
                                                destination_escaped || FLAGS_SET(symlink_flags, EXEC_DIRECTORY_READ_ONLY) ? ":" : "",
1✔
4298
                                                destination_escaped,
4299
                                                FLAGS_SET(symlink_flags, EXEC_DIRECTORY_READ_ONLY) ? ":ro" : "");
7✔
4300
                        }
4301
                }
4302
                if (r < 0)
14✔
4303
                        return r;
4304

4305
                exec_directory_sort(directory);
14✔
4306

4307
                r = sd_bus_message_exit_container(message);
14✔
4308
                if (r < 0)
14✔
4309
                        return r;
4310

4311
                return 1;
14✔
4312

4313
        } else if (STR_IN_SET(name, "RootImagePolicy", "MountImagePolicy", "ExtensionImagePolicy")) {
1,661✔
4314
                _cleanup_(image_policy_freep) ImagePolicy *p = NULL;
4✔
4315
                const char *s;
4✔
4316

4317
                r = sd_bus_message_read(message, "s", &s);
4✔
4318
                if (r < 0)
4✔
4319
                        return r;
4320

4321
                r = image_policy_from_string(s, /* graceful= */ true, &p);
4✔
4322
                if (r < 0)
4✔
UNCOV
4323
                        return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, "Failed to parse image policy string: %s", s);
×
4324

4325
                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
4✔
4326
                        _cleanup_free_ char *t = NULL;
2✔
4327
                        ImagePolicy **pp =
2✔
4328
                                streq(name, "RootImagePolicy")  ? &c->root_image_policy :
2✔
4329
                                streq(name, "MountImagePolicy") ? &c->mount_image_policy :
2✔
4330
                                                                  &c->extension_image_policy;
4331

4332
                        r = image_policy_to_string(p, /* simplify= */ true, &t);
2✔
4333
                        if (r < 0)
2✔
UNCOV
4334
                                return r;
×
4335

4336
                        image_policy_free(*pp);
2✔
4337
                        *pp = TAKE_PTR(p);
2✔
4338

4339
                        unit_write_settingf(
2✔
4340
                                        u, flags, name,
4341
                                        "%s=%s",
4342
                                        name,
4343
                                        t); /* no escaping necessary */
4344
                }
4345

4346
                return 1;
4✔
4347
        }
4348

4349
        return 0;
1,657✔
4350
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc