]> git.ipfire.org Git - thirdparty/glibc.git/blame - support/namespace.h
Prefer https to http for gnu.org and fsf.org URLs
[thirdparty/glibc.git] / support / namespace.h
CommitLineData
5707a64d 1/* Entering namespaces for test case isolation.
04277e02 2 Copyright (C) 2016-2019 Free Software Foundation, Inc.
5707a64d
FW
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
5a82c748 17 <https://www.gnu.org/licenses/>. */
5707a64d
FW
18
19#ifndef SUPPORT_NAMESPACE_H
20#define SUPPORT_NAMESPACE_H
21
22#include <stdbool.h>
23#include <sys/cdefs.h>
24
25__BEGIN_DECLS
26
27/* Attempts to become root (or acquire root-like privileges), possibly
28 with the help of user namespaces. Return true if (restricted) root
29 privileges could be attained in some way. Print diagnostics to
30 standard output.
31
32 Note that this function generally has to be called before a process
33 becomes multi-threaded, otherwise it may fail with insufficient
34 privileges on systems which would support this operation for
35 single-threaded processes. */
36bool support_become_root (void);
37
2714c5f3
FW
38/* Return true if this process can perform a chroot operation. In
39 general, this is only possible if support_become_root has been
40 called. Note that the actual test is performed in a subprocess,
41 after fork, so that the file system root of the original process is
42 not changed. */
43bool support_can_chroot (void);
44
5707a64d
FW
45/* Enter a network namespace (and a UTS namespace if possible) and
46 configure the loopback interface. Return true if a network
47 namespace could be created. Print diagnostics to standard output.
48 If a network namespace could be created, but networking in it could
49 not be configured, terminate the process. It is recommended to
50 call support_become_root before this function so that the process
51 has sufficient privileges. */
52bool support_enter_network_namespace (void);
53
273a0c49
FW
54/* Enter a mount namespace and mark / as private (not shared). If
55 this function returns true, mount operations in this process will
56 not affect the host system afterwards. */
57bool support_enter_mount_namespace (void);
58
5707a64d
FW
59/* Return true if support_enter_network_namespace managed to enter a
60 UTS namespace. */
61bool support_in_uts_namespace (void);
62
2714c5f3
FW
63/* Invoke CALLBACK (CLOSURE) in a subprocess created using fork.
64 Terminate the calling process if the subprocess exits with a
65 non-zero exit status. */
66void support_isolate_in_subprocess (void (*callback) (void *), void *closure);
67
d4165eed
FW
68/* Describe the setup of a chroot environment, for
69 support_chroot_create below. */
70struct support_chroot_configuration
71{
72 /* File contents. The files are not created if the field is
73 NULL. */
65329bd2
FW
74 const char *resolv_conf; /* /etc/resolv.conf. */
75 const char *hosts; /* /etc/hosts. */
76 const char *host_conf; /* /etc/host.conf. */
2bac7daa 77 const char *aliases; /* /etc/aliases. */
d4165eed
FW
78};
79
80/* The result of the creation of a chroot. */
81struct support_chroot
82{
83 /* Path information. All these paths are relative to the parent
84 chroot. */
85
86 /* Path to the chroot directory. */
87 char *path_chroot;
88
65329bd2
FW
89 /* Paths to files in the chroot. These are absolute and outside of
90 the chroot. */
91 char *path_resolv_conf; /* /etc/resolv.conf. */
92 char *path_hosts; /* /etc/hosts. */
93 char *path_host_conf; /* /etc/host.conf. */
2bac7daa 94 char *path_aliases; /* /etc/aliases. */
d4165eed
FW
95};
96
97/* Create a chroot environment. The returned data should be freed
98 using support_chroot_free below. The files will be deleted when
99 the process exits. This function does not enter the chroot. */
100struct support_chroot *support_chroot_create
101 (struct support_chroot_configuration);
102
103/* Deallocate the chroot information created by
104 support_chroot_create. */
105void support_chroot_free (struct support_chroot *);
106
5707a64d
FW
107__END_DECLS
108
109#endif