2 This file is part of systemd.
4 Copyright 2013 Lennart Poettering
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.
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.
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/>.
20 #if HAVE_VALGRIND_MEMCHECK_H
21 #include <valgrind/memcheck.h>
27 #include <sys/prctl.h>
29 /* When we include libgen.h because we need dirname() we immediately
30 * undefine basename() since libgen.h defines it as a macro to the POSIX
31 * version which is really broken. We prefer GNU basename(). */
35 #include "alloc-util.h"
36 #include "bus-internal.h"
37 #include "bus-kernel.h"
38 #include "bus-label.h"
39 #include "bus-message.h"
41 #include "capability-util.h"
44 #include "format-util.h"
45 #include "memfd-util.h"
46 #include "parse-util.h"
47 #include "stdio-util.h"
48 #include "string-util.h"
50 #include "user-util.h"
53 void close_and_munmap(int fd, void *address, size_t size) {
55 assert_se(munmap(address, PAGE_ALIGN(size)) >= 0);
60 void bus_flush_memfd(sd_bus *b) {
65 for (i = 0; i < b->n_memfd_cache; i++)
66 close_and_munmap(b->memfd_cache[i].fd, b->memfd_cache[i].address, b->memfd_cache[i].mapped);
69 uint64_t attach_flags_to_kdbus(uint64_t mask) {
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))
74 m |= KDBUS_ATTACH_CREDS;
76 if (mask & (SD_BUS_CREDS_PID|SD_BUS_CREDS_TID|SD_BUS_CREDS_PPID))
77 m |= KDBUS_ATTACH_PIDS;
79 if (mask & SD_BUS_CREDS_COMM)
80 m |= KDBUS_ATTACH_PID_COMM;
82 if (mask & SD_BUS_CREDS_TID_COMM)
83 m |= KDBUS_ATTACH_TID_COMM;
85 if (mask & SD_BUS_CREDS_EXE)
86 m |= KDBUS_ATTACH_EXE;
88 if (mask & SD_BUS_CREDS_CMDLINE)
89 m |= KDBUS_ATTACH_CMDLINE;
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;
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;
97 if (mask & SD_BUS_CREDS_SELINUX_CONTEXT)
98 m |= KDBUS_ATTACH_SECLABEL;
100 if (mask & (SD_BUS_CREDS_AUDIT_SESSION_ID|SD_BUS_CREDS_AUDIT_LOGIN_UID))
101 m |= KDBUS_ATTACH_AUDIT;
103 if (mask & SD_BUS_CREDS_WELL_KNOWN_NAMES)
104 m |= KDBUS_ATTACH_NAMES;
106 if (mask & SD_BUS_CREDS_DESCRIPTION)
107 m |= KDBUS_ATTACH_CONN_DESCRIPTION;
109 if (mask & SD_BUS_CREDS_SUPPLEMENTARY_GIDS)
110 m |= KDBUS_ATTACH_AUXGROUPS;
114 #if 0 /// UNNEEDED by elogind