]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
6629161f LP |
2 | /*** |
3 | This file is part of systemd. | |
4 | ||
5 | Copyright 2013 Lennart Poettering | |
6 | ||
7 | systemd is free software; you can redistribute it and/or modify it | |
8 | under the terms of the GNU Lesser General Public License as published by | |
9 | the Free Software Foundation; either version 2.1 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | systemd is distributed in the hope that it will be useful, but | |
13 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | Lesser General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU Lesser General Public License | |
18 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
19 | ***/ | |
20 | ||
349cc4a5 | 21 | #if HAVE_VALGRIND_MEMCHECK_H |
7211f918 LP |
22 | #include <valgrind/memcheck.h> |
23 | #endif | |
24 | ||
6629161f | 25 | #include <fcntl.h> |
c556fe79 | 26 | #include <malloc.h> |
fd8d62d9 | 27 | #include <sys/mman.h> |
5972fe95 | 28 | #include <sys/prctl.h> |
6629161f | 29 | |
eef46c37 | 30 | /* When we include libgen.h because we need dirname() we immediately |
11c9f1e4 SM |
31 | * undefine basename() since libgen.h defines it as a macro to the POSIX |
32 | * version which is really broken. We prefer GNU basename(). */ | |
eef46c37 LP |
33 | #include <libgen.h> |
34 | #undef basename | |
35 | ||
b5efdb8a | 36 | #include "alloc-util.h" |
07630cea | 37 | #include "bus-internal.h" |
3ffd4af2 | 38 | #include "bus-kernel.h" |
07630cea LP |
39 | #include "bus-label.h" |
40 | #include "bus-message.h" | |
41 | #include "bus-util.h" | |
430f0182 | 42 | #include "capability-util.h" |
3ffd4af2 | 43 | #include "fd-util.h" |
1a299299 | 44 | #include "fileio.h" |
f97b34a6 | 45 | #include "format-util.h" |
07630cea | 46 | #include "memfd-util.h" |
6bedfcbb | 47 | #include "parse-util.h" |
d054f0a4 | 48 | #include "stdio-util.h" |
07630cea LP |
49 | #include "string-util.h" |
50 | #include "strv.h" | |
ee104e11 | 51 | #include "user-util.h" |
07630cea | 52 | #include "util.h" |
777d7a61 | 53 | |
a132bef0 | 54 | void close_and_munmap(int fd, void *address, size_t size) { |
45fbe937 | 55 | if (size > 0) |
76b7742c | 56 | assert_se(munmap(address, PAGE_ALIGN(size)) >= 0); |
45fbe937 | 57 | |
03e334a1 | 58 | safe_close(fd); |
bc7fd8cd LP |
59 | } |
60 | ||
a132bef0 | 61 | void bus_flush_memfd(sd_bus *b) { |
bc7fd8cd LP |
62 | unsigned i; |
63 | ||
64 | assert(b); | |
65 | ||
76b7742c | 66 | for (i = 0; i < b->n_memfd_cache; i++) |
8e959fbf | 67 | close_and_munmap(b->memfd_cache[i].fd, b->memfd_cache[i].address, b->memfd_cache[i].mapped); |
bc7fd8cd | 68 | } |
0253ddcc | 69 | |
b5dae4c7 | 70 | uint64_t attach_flags_to_kdbus(uint64_t mask) { |
e3dd987c LP |
71 | uint64_t m = 0; |
72 | ||
705a415f LP |
73 | if (mask & (SD_BUS_CREDS_UID|SD_BUS_CREDS_EUID|SD_BUS_CREDS_SUID|SD_BUS_CREDS_FSUID| |
74 | SD_BUS_CREDS_GID|SD_BUS_CREDS_EGID|SD_BUS_CREDS_SGID|SD_BUS_CREDS_FSGID)) | |
e3dd987c LP |
75 | m |= KDBUS_ATTACH_CREDS; |
76 | ||
1386e47d | 77 | if (mask & (SD_BUS_CREDS_PID|SD_BUS_CREDS_TID|SD_BUS_CREDS_PPID)) |
705a415f LP |
78 | m |= KDBUS_ATTACH_PIDS; |
79 | ||
a2243d54 DM |
80 | if (mask & SD_BUS_CREDS_COMM) |
81 | m |= KDBUS_ATTACH_PID_COMM; | |
82 | ||
83 | if (mask & SD_BUS_CREDS_TID_COMM) | |
84 | m |= KDBUS_ATTACH_TID_COMM; | |
e3dd987c LP |
85 | |
86 | if (mask & SD_BUS_CREDS_EXE) | |
87 | m |= KDBUS_ATTACH_EXE; | |
88 | ||
89 | if (mask & SD_BUS_CREDS_CMDLINE) | |
90 | m |= KDBUS_ATTACH_CMDLINE; | |
91 | ||
92 | if (mask & (SD_BUS_CREDS_CGROUP|SD_BUS_CREDS_UNIT|SD_BUS_CREDS_USER_UNIT|SD_BUS_CREDS_SLICE|SD_BUS_CREDS_SESSION|SD_BUS_CREDS_OWNER_UID)) | |
93 | m |= KDBUS_ATTACH_CGROUP; | |
94 | ||
95 | if (mask & (SD_BUS_CREDS_EFFECTIVE_CAPS|SD_BUS_CREDS_PERMITTED_CAPS|SD_BUS_CREDS_INHERITABLE_CAPS|SD_BUS_CREDS_BOUNDING_CAPS)) | |
96 | m |= KDBUS_ATTACH_CAPS; | |
97 | ||
98 | if (mask & SD_BUS_CREDS_SELINUX_CONTEXT) | |
99 | m |= KDBUS_ATTACH_SECLABEL; | |
0253ddcc | 100 | |
e3dd987c LP |
101 | if (mask & (SD_BUS_CREDS_AUDIT_SESSION_ID|SD_BUS_CREDS_AUDIT_LOGIN_UID)) |
102 | m |= KDBUS_ATTACH_AUDIT; | |
103 | ||
49b832c5 LP |
104 | if (mask & SD_BUS_CREDS_WELL_KNOWN_NAMES) |
105 | m |= KDBUS_ATTACH_NAMES; | |
106 | ||
455971c1 | 107 | if (mask & SD_BUS_CREDS_DESCRIPTION) |
635f9f0d | 108 | m |= KDBUS_ATTACH_CONN_DESCRIPTION; |
cccb0b2c | 109 | |
02581590 LP |
110 | if (mask & SD_BUS_CREDS_SUPPLEMENTARY_GIDS) |
111 | m |= KDBUS_ATTACH_AUXGROUPS; | |
112 | ||
b5dae4c7 | 113 | return m; |
0253ddcc | 114 | } |