1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3 
4 #include <sys/types.h>
5 
6 int namespace_open(pid_t pid, int *pidns_fd, int *mntns_fd, int *netns_fd, int *userns_fd, int *root_fd);
7 int namespace_enter(int pidns_fd, int mntns_fd, int netns_fd, int userns_fd, int root_fd);
8 
9 int fd_is_ns(int fd, unsigned long nsflag);
10 
11 int detach_mount_namespace(void);
12 
userns_shift_range_valid(uid_t shift,uid_t range)13 static inline bool userns_shift_range_valid(uid_t shift, uid_t range) {
14         /* Checks that the specified userns range makes sense, i.e. contains at least one UID, and the end
15          * doesn't overflow uid_t. */
16 
17         assert_cc((uid_t) -1 > 0); /* verify that uid_t is unsigned */
18 
19         if (range <= 0)
20                 return false;
21 
22         if (shift > (uid_t) -1 - range)
23                 return false;
24 
25         return true;
26 }
27 
28 int userns_acquire(const char *uid_map, const char *gid_map);
29