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