]> git.proxmox.com Git - mirror_lxc.git/blame - src/lxc/conf.h
string_utils: fix includes
[mirror_lxc.git] / src / lxc / conf.h
CommitLineData
cc73685d
CB
1/* SPDX-License-Identifier: LGPL-2.1+ */
2
f1a4a029
ÇO
3#ifndef __LXC_CONF_H
4#define __LXC_CONF_H
0ad19a3f 5
d38dd64a
CB
6#ifndef _GNU_SOURCE
7#define _GNU_SOURCE 1
8#endif
9e99997b 9#include <linux/magic.h>
74a2b586 10#include <net/if.h>
1a0e70ac 11#include <netinet/in.h>
d38dd64a
CB
12#include <stdbool.h>
13#include <stdio.h>
b0a33c1e 14#include <sys/param.h>
8173e600 15#include <sys/types.h>
9e99997b
CB
16#include <sys/vfs.h>
17
4822319f 18#include "attach_options.h"
d84b26bc 19#include "caps.h"
d7f19646 20#include "compiler.h"
d38dd64a 21#include "config.h"
87d0990c 22#include "hlist.h"
f2363e38 23#include "list.h"
c3e3c21a 24#include "lxcseccomp.h"
ee91fa06 25#include "memory_utils.h"
734a677e 26#include "namespace.h"
732375f5 27#include "ringbuf.h"
d38dd64a 28#include "start.h"
734a677e 29#include "state.h"
4e86cad3 30#include "storage/storage.h"
02efd041 31#include "string_utils.h"
64a04c84 32#include "syscall_wrappers.h"
0ed9b1bc 33#include "terminal.h"
e3b4c4c4 34
d38dd64a
CB
35#if HAVE_SYS_RESOURCE_H
36#include <sys/resource.h>
37#endif
38
769872f9
SH
39#if HAVE_SCMP_FILTER_CTX
40typedef void * scmp_filter_ctx;
41#endif
42
64a04c84
CB
43typedef signed long personality_t;
44
97e9cfa0
SH
45/* worth moving to configure.ac? */
46#define subuidfile "/etc/subuid"
47#define subgidfile "/etc/subgid"
48
0ad19a3f 49/*
43654d34
CB
50 * Defines a generic struct to configure the control group. It is up to the
51 * programmer to specify the right subsystem.
ec64264d 52 * @subsystem : the targeted subsystem
576f946d 53 * @value : the value to set
54860ed0
CB
54 * @version : The version of the cgroup filesystem on which the controller
55 * resides.
43654d34
CB
56 *
57 * @controllers : The controllers to use for this container.
58 * @dir : The name of the directory containing the container's cgroup.
59 * Not that this is a per-container setting.
0ad19a3f 60 */
61struct lxc_cgroup {
43654d34
CB
62 union {
63 /* information about a specific controller */
64 struct /* controller */ {
54860ed0 65 int version;
43654d34
CB
66 char *subsystem;
67 char *value;
68 };
69
70 /* meta information about cgroup configuration */
71 struct /* meta */ {
72 char *controllers;
73 char *dir;
a900cbaf 74 char *monitor_dir;
7696c1f9 75 char *monitor_pivot_dir;
a900cbaf
WB
76 char *container_dir;
77 char *namespace_dir;
9caee129 78 bool relative;
43654d34
CB
79 };
80 };
c9dbb8ed
CB
81
82 struct list_head head;
0ad19a3f 83};
84
ee91fa06
CB
85static void free_lxc_cgroup(struct lxc_cgroup *ptr)
86{
87 if (ptr) {
88 free(ptr->subsystem);
89 free(ptr->value);
90 free_disarm(ptr);
91 }
92}
93define_cleanup_function(struct lxc_cgroup *, free_lxc_cgroup);
94
c6d09e15 95#if !HAVE_SYS_RESOURCE_H
3a0e314d 96#define RLIM_INFINITY ((unsigned long)-1)
c6d09e15
WB
97struct rlimit {
98 unsigned long rlim_cur;
99 unsigned long rlim_max;
223797c3 100 struct list_head head;
c6d09e15
WB
101};
102#endif
3a0e314d 103
c6d09e15
WB
104/*
105 * Defines a structure to configure resource limits to set via setrlimit().
106 * @resource : the resource name in lowercase without the RLIMIT_ prefix
107 * @limit : the limit to set
108 */
109struct lxc_limit {
110 char *resource;
111 struct rlimit limit;
223797c3 112 struct list_head head;
c6d09e15
WB
113};
114
8fa831e0
CB
115static void free_lxc_limit(struct lxc_limit *ptr)
116{
117 if (ptr) {
631d2715 118 free_disarm(ptr->resource);
8fa831e0
CB
119 free_disarm(ptr);
120 }
121}
122define_cleanup_function(struct lxc_limit *, free_lxc_limit);
123
f6d3e3e4
SH
124enum idtype {
125 ID_TYPE_UID,
126 ID_TYPE_GID
127};
128
7edd0540
L
129/*
130 * Defines a structure to configure kernel parameters at runtime.
131 * @key : the kernel parameters will be configured without the "lxc.sysctl" prefix
132 * @value : the value to set
133 */
134struct lxc_sysctl {
135 char *key;
136 char *value;
ba9f9347 137 struct list_head head;
7edd0540
L
138};
139
f10c80d2
CB
140static void free_lxc_sysctl(struct lxc_sysctl *ptr)
141{
142 if (ptr) {
143 free(ptr->key);
144 free(ptr->value);
145 free_disarm(ptr);
146 }
147}
148define_cleanup_function(struct lxc_sysctl *, free_lxc_sysctl);
149
61d7a733
YT
150/*
151 * Defines a structure to configure proc filesystem at runtime.
152 * @filename : the proc filesystem will be configured without the "lxc.proc" prefix
153 * @value : the value to set
154 */
155struct lxc_proc {
156 char *filename;
157 char *value;
91d04bf9 158 struct list_head head;
61d7a733
YT
159};
160
83332c24
CB
161static void free_lxc_proc(struct lxc_proc *ptr)
162{
163 if (ptr) {
164 free(ptr->filename);
165 free(ptr->value);
166 free_disarm(ptr);
167 }
168}
169define_cleanup_function(struct lxc_proc *, free_lxc_proc);
170
f6d3e3e4
SH
171/*
172 * id_map is an id map entry. Form in confile is:
bdcbb6b3
CB
173 * lxc.idmap = u 0 9800 100
174 * lxc.idmap = u 1000 9900 100
175 * lxc.idmap = g 0 9800 100
176 * lxc.idmap = g 1000 9900 100
251d0d2a
DE
177 * meaning the container can use uids and gids 0-99 and 1000-1099,
178 * with [ug]id 0 mapping to [ug]id 9800 on the host, and [ug]id 1000 to
179 * [ug]id 9900 on the host.
f6d3e3e4
SH
180 */
181struct id_map {
182 enum idtype idtype;
251d0d2a 183 unsigned long hostid, nsid, range;
0589d744 184 struct list_head head;
f6d3e3e4
SH
185};
186
0e4be3cf 187/* Defines the number of tty configured and contains the
a589434e 188 * instantiated ptys
885766f5 189 * @max = number of configured ttys
b0a33c1e 190 */
191struct lxc_tty_info {
885766f5
CB
192 size_t max;
193 char *dir;
194 char *tty_names;
2520facd 195 struct lxc_terminal_info *tty;
b0a33c1e 196};
197
0b932f9d
CB
198typedef enum lxc_mount_options_t {
199 LXC_MOUNT_CREATE_DIR = 0,
200 LXC_MOUNT_CREATE_FILE = 1,
201 LXC_MOUNT_OPTIONAL = 2,
202 LXC_MOUNT_RELATIVE = 3,
f6815906
CB
203 LXC_MOUNT_IDMAP = 4,
204 LXC_MOUNT_MAX = 5,
0b932f9d
CB
205} lxc_mount_options_t;
206
207__hidden extern const char *lxc_mount_options_info[LXC_MOUNT_MAX];
208
209struct lxc_mount_options {
2df612d4
CB
210 unsigned int create_dir : 1;
211 unsigned int create_file : 1;
212 unsigned int optional : 1;
213 unsigned int relative : 1;
3eb23230
CB
214 unsigned int bind_recursively : 1;
215 unsigned int propagate_recursively : 1;
2df612d4 216 unsigned int bind : 1;
f6815906 217 char userns_path[PATH_MAX];
423374e9
CB
218 unsigned long mnt_flags;
219 unsigned long prop_flags;
220 char *data;
1b82d721 221 struct lxc_mount_attr attr;
e73af35b 222 char *raw_options;
0b932f9d
CB
223};
224
13bb312d 225/* Defines a structure to store the rootfs location, the
33fcb7a0 226 * optionals pivot_root, rootfs mount paths
953db219
CB
227 * @path : the rootfs source (directory or device)
228 * @mount : where it is mounted
952b5031 229 * @buf : static buffer to construct paths
953db219 230 * @bev_type : optional backing store type
953db219 231 * @managed : whether it is managed by LXC
ea57e424 232 * @dfd_mnt : fd for @mount
a5a08920 233 * @dfd_dev : fd for /dev of the container
33fcb7a0
DL
234 */
235struct lxc_rootfs {
ea11a215 236 int dfd_host;
79ff643d 237
33fcb7a0 238 char *path;
79ff643d 239 int fd_path_pin;
4b875ef9 240 int dfd_idmapped;
79ff643d
CB
241
242 int dfd_mnt;
23b7ea69 243 char *mount;
79ff643d
CB
244
245 int dfd_dev;
246
952b5031 247 char buf[PATH_MAX];
b3b8c97f 248 char *bdev_type;
6e54330c 249 bool managed;
0b932f9d 250 struct lxc_mount_options mnt_opts;
4e86cad3 251 struct lxc_storage *storage;
33fcb7a0
DL
252};
253
368bbc02
CS
254/*
255 * Automatic mounts for LXC to perform inside the container
256 */
257enum {
3a0e314d
CB
258 LXC_AUTO_PROC_RW = 0x001, /* /proc read-write */
259 LXC_AUTO_PROC_MIXED = 0x002, /* /proc/sys and /proc/sysrq-trigger read-only */
b06b8511
CS
260 LXC_AUTO_PROC_MASK = 0x003,
261
3a0e314d
CB
262 LXC_AUTO_SYS_RW = 0x004, /* /sys */
263 LXC_AUTO_SYS_RO = 0x008, /* /sys read-only */
264 LXC_AUTO_SYS_MIXED = 0x00C, /* /sys read-only and /sys/class/net read-write */
b06b8511
CS
265 LXC_AUTO_SYS_MASK = 0x00C,
266
3a0e314d
CB
267 LXC_AUTO_CGROUP_RO = 0x010, /* /sys/fs/cgroup (partial mount, read-only) */
268 LXC_AUTO_CGROUP_RW = 0x020, /* /sys/fs/cgroup (partial mount, read-write) */
269 LXC_AUTO_CGROUP_MIXED = 0x030, /* /sys/fs/cgroup (partial mount, paths r/o, cgroup r/w) */
270 LXC_AUTO_CGROUP_FULL_RO = 0x040, /* /sys/fs/cgroup (full mount, read-only) */
271 LXC_AUTO_CGROUP_FULL_RW = 0x050, /* /sys/fs/cgroup (full mount, read-write) */
272 LXC_AUTO_CGROUP_FULL_MIXED = 0x060, /* /sys/fs/cgroup (full mount, parent r/o, own r/w) */
273 /*
274 * These are defined in such a way as to retain binary compatibility
275 * with earlier versions of this code. If the previous mask is applied,
276 * both of these will default back to the _MIXED variants, which is
277 * safe.
278 */
279 LXC_AUTO_CGROUP_NOSPEC = 0x0B0, /* /sys/fs/cgroup (partial mount, r/w or mixed, depending on caps) */
280 LXC_AUTO_CGROUP_FULL_NOSPEC = 0x0E0, /* /sys/fs/cgroup (full mount, r/w or mixed, depending on caps) */
281 LXC_AUTO_CGROUP_FORCE = 0x100, /* mount cgroups even when cgroup namespaces are supported */
6cc501f3 282 LXC_AUTO_CGROUP_MASK = 0x1F0, /* all known cgroup options */
adf0ba1f
LT
283
284 LXC_AUTO_SHMOUNTS = 0x200, /* shared mount point */
285 LXC_AUTO_SHMOUNTS_MASK = 0x200, /* shared mount point mask */
3a0e314d 286 LXC_AUTO_ALL_MASK = 0x1FF, /* all known settings */
368bbc02
CS
287};
288
26ddeedd 289enum lxchooks {
1a0e70ac
CB
290 LXCHOOK_PRESTART,
291 LXCHOOK_PREMOUNT,
292 LXCHOOK_MOUNT,
293 LXCHOOK_AUTODEV,
294 LXCHOOK_START,
295 LXCHOOK_STOP,
296 LXCHOOK_POSTSTOP,
297 LXCHOOK_CLONE,
298 LXCHOOK_DESTROY,
08dd2805 299 LXCHOOK_START_HOST,
1a0e70ac
CB
300 NUM_LXC_HOOKS
301};
72d0e1cb 302
59eac805 303__hidden extern char *lxchook_names[NUM_LXC_HOOKS];
7b35f3d6 304
d39b10eb
CB
305struct lxc_state_client {
306 int clientfd;
307 lxc_state_t states[MAX_STATE];
d2e75eba 308 struct list_head head;
d39b10eb
CB
309};
310
4b9dc703 311typedef enum lxc_bpf_devices_rule_t {
4b9dc703
CB
312 LXC_BPF_DEVICE_CGROUP_ALLOWLIST = 0,
313 LXC_BPF_DEVICE_CGROUP_DENYLIST = 1,
314} lxc_bpf_devices_rule_t;
fda39d45 315
4bfb655e
CB
316struct device_item {
317 char type;
318 int major;
319 int minor;
320 char access[4];
321 int allow;
93de768e 322 struct list_head head;
a134099d
CB
323};
324
325struct bpf_devices {
326 lxc_bpf_devices_rule_t list_type;
93de768e 327 struct list_head devices;
4bfb655e
CB
328};
329
70fd7fc9
CB
330struct timens_offsets {
331 /* Currently, either s_boot or ns_boot is set, but not both. */
332 int64_t s_boot;
333 int64_t ns_boot;
334
335 /* Currently, either s_monotonic or ns_monotonic is set, but not both. */
336 int64_t s_monotonic;
337 int64_t ns_monotonic;
338};
339
c294a68d
CB
340struct environment_entry {
341 char *key;
342 char *val;
343 struct list_head head;
344};
345
20ab7578
CB
346struct cap_entry {
347 char *cap_name;
348 int cap;
349 struct list_head head;
350};
351
352struct caps {
353 int keep;
354 struct list_head list;
355};
356
be0bc4d1
CB
357struct string_entry {
358 char *val;
359 struct list_head head;
360};
361
571e6ec8 362struct lxc_conf {
c7b17051
CB
363 /* Pointer to the name of the container. Do not free! */
364 const char *name;
07c4ea31 365 bool is_execute;
91480a0f 366 int reboot;
64a04c84 367 personality_t personality;
571e6ec8 368 struct utsname *utsname;
edd64e17 369
54860ed0 370 struct {
c9dbb8ed
CB
371 struct list_head cgroup;
372 struct list_head cgroup2;
a134099d 373 struct bpf_devices bpf_devices;
54860ed0 374 };
edd64e17 375
46ad64ab 376 struct {
0589d744 377 struct list_head id_map;
c7e345ae 378
edd64e17
CB
379 /*
380 * Pointer to the idmap entry for the container's root uid in
381 * the id_map list. Do not free!
382 */
5173b710 383 const struct id_map *root_nsuid_map;
c7e345ae 384
edd64e17
CB
385 /*
386 * Pointer to the idmap entry for the container's root gid in
387 * the id_map list. Do not free!
388 */
5173b710 389 const struct id_map *root_nsgid_map;
46ad64ab 390 };
edd64e17 391
87d0990c 392 struct list_head netdevs;
448d7b0c
CB
393
394 struct {
395 char *fstab;
396 int auto_mounts;
be0bc4d1 397 struct list_head mount_entries;
448d7b0c
CB
398 };
399
20ab7578 400 struct caps caps;
885766f5 401
a2db71c0 402 /* /dev/tty<idx> devices */
885766f5 403 struct lxc_tty_info ttys;
a2db71c0
CB
404 /* /dev/console device */
405 struct lxc_terminal console;
406 /* maximum pty devices allowed by devpts mount */
e528c735 407 size_t pty_max;
f797f05e
CB
408 /* file descriptor for the container's /dev/pts mount */
409 int devpts_fd;
885766f5 410
32fd6cf3
CB
411 /* set to true when rootfs has been setup */
412 bool rootfs_setup;
33fcb7a0 413 struct lxc_rootfs rootfs;
32fd6cf3 414
b3187a81 415 bool close_all_fds;
44ae0fb6
CB
416
417 struct {
418 unsigned int hooks_version;
5090de3e 419 struct list_head hooks[NUM_LXC_HOOKS];
44ae0fb6 420 };
4a85ce2a 421
fe4de9a6 422 char *lsm_aa_profile;
1800f924
WB
423 char *lsm_aa_profile_computed;
424 bool lsm_aa_profile_created;
425 unsigned int lsm_aa_allow_nesting;
a56e2df9 426 unsigned int lsm_aa_allow_incomplete;
1fb1e667 427 struct list_head lsm_aa_raw;
fe4de9a6 428 char *lsm_se_context;
4fef78bc 429 char *lsm_se_keyring_context;
8f818a84 430 bool keyring_disable_session;
952b5031 431 bool transient_procfs_mnt;
c3e3c21a 432 struct lxc_seccomp seccomp;
72d0e1cb 433 int maincmd_fd;
1a0e70ac 434 unsigned int autodev; /* if 1, mount and fill a /dev at start */
63012bdd 435 int autodevtmpfssize; /* size of the /dev tmpfs */
1a0e70ac
CB
436 int haltsignal; /* signal used to halt container */
437 int rebootsignal; /* signal used to reboot container */
438 int stopsignal; /* signal used to hard stop container */
439 char *rcfile; /* Copy of the top level rcfile we read */
440
b9949538 441 /* Logfile and loglevel can be set in a container config file. Those
7b660465 442 * function as defaults. The defaults can be overridden by command line.
1a0e70ac
CB
443 * However we don't want the command line specified values to be saved
444 * on c->save_config(). So we store the config file specified values
445 * here. */
98020c31
JS
446 char *logfile; /* the logfile as specified in config */
447 int loglevel; /* loglevel as specified in config (if any) */
858377e4 448 int logfd;
9f30a190 449
3590152f
CB
450 unsigned int start_auto;
451 unsigned int start_delay;
ee1e7aa0 452 int start_order;
ffb2a35f 453 struct list_head groups;
76a26f55 454 int nbd_idx;
35120d9c 455
a8dfe4e0 456 /* unshare the mount namespace in the monitor */
226dc30e 457 unsigned int monitor_unshare;
258f8051 458 unsigned int monitor_signal_pdeath;
a8dfe4e0 459
7c661726
MP
460 /* list of environment variables we'll add to the container when
461 * started */
c294a68d 462 struct list_head environment;
6b0d5538
SH
463
464 /* text representation of the config file */
465 char *unexpanded_config;
32fd6cf3
CB
466 size_t unexpanded_len;
467 size_t unexpanded_alloced;
67c660d0 468
5cda27c1
SH
469 /* default command for lxc-execute */
470 char *execute_cmd;
471
67c660d0
SG
472 /* init command */
473 char *init_cmd;
56f8ff00 474
4822319f 475 /* The uid to use for the container. */
c5cd20ce 476 uid_t init_uid;
4822319f 477 /* The gid to use for the container. */
c5cd20ce 478 gid_t init_gid;
4822319f
CB
479 /* The groups to use for the container. */
480 lxc_groups_t init_groups;
8796becf
CB
481
482 /* indicator if the container will be destroyed on shutdown */
66ffdb1a 483 unsigned int ephemeral;
76d0127f
CB
484
485 /* The facility to pass to syslog. Let's users establish as what type of
486 * program liblxc is supposed to write to the syslog. */
487 char *syslog;
5a46f283
CB
488
489 /* Whether PR_SET_NO_NEW_PRIVS will be set for the container. */
490 bool no_new_privs;
c6d09e15
WB
491
492 /* RLIMIT_* limits */
223797c3 493 struct list_head limits;
7ec2e32a 494
43654d34
CB
495 /* Contains generic info about the cgroup configuration for this
496 * container. Note that struct lxc_cgroup contains a union. It is only
497 * valid to access the members of the anonymous "meta" struct within
498 * that union.
499 */
500 struct lxc_cgroup cgroup_meta;
28d9e29e 501
b074bbf1 502 struct {
1d8d3676 503 int ns_clone;
abeb5bba 504 int ns_keep;
b074bbf1
CB
505 char *ns_share[LXC_NS_MAX];
506 };
3c491553
L
507
508 /* init working directory */
9e132956 509 char *init_cwd;
3c491553 510
d39b10eb 511 /* A list of clients registered to be informed about a container state. */
d2e75eba 512 struct list_head state_clients;
7edd0540
L
513
514 /* sysctls */
ba9f9347 515 struct list_head sysctls;
61d7a733
YT
516
517 /* procs */
91d04bf9 518 struct list_head procs;
adf0ba1f 519
7a41e857 520 struct shmount {
adf0ba1f
LT
521 /* Absolute path to the shared mount point on the host */
522 char *path_host;
523 /* Absolute path (in the container) to the shared mount point */
524 char *path_cont;
7a41e857 525 } shmount;
70fd7fc9
CB
526
527 struct timens_offsets timens;
571e6ec8
DL
528};
529
efb7e304
CB
530__hidden extern int write_id_mapping(enum idtype idtype, pid_t pid, const char *buf, size_t buf_size)
531 __access_r(3, 4);
344c9d81 532
d7f19646 533extern thread_local struct lxc_conf *current_config;
858377e4 534
efb7e304
CB
535__hidden extern int run_lxc_hooks(const char *name, char *hook, struct lxc_conf *conf, char *argv[]);
536__hidden extern struct lxc_conf *lxc_conf_init(void);
537__hidden extern void lxc_conf_free(struct lxc_conf *conf);
4e86cad3
CB
538__hidden extern int lxc_storage_prepare(struct lxc_conf *conf);
539__hidden extern int lxc_rootfs_prepare(struct lxc_conf *conf, bool userns);
540__hidden extern void lxc_storage_put(struct lxc_conf *conf);
239f29c9 541__hidden extern int lxc_rootfs_init(struct lxc_conf *conf, bool userns);
4b875ef9 542__hidden extern int lxc_rootfs_prepare_parent(struct lxc_handler *handler);
1b82d721 543__hidden extern int lxc_idmapped_mounts_parent(struct lxc_handler *handler);
0589d744 544__hidden extern int lxc_map_ids(struct list_head *idmap, pid_t pid);
efb7e304
CB
545__hidden extern int lxc_create_tty(const char *name, struct lxc_conf *conf);
546__hidden extern void lxc_delete_tty(struct lxc_tty_info *ttys);
547__hidden extern int lxc_clear_config_caps(struct lxc_conf *c);
efb7e304
CB
548__hidden extern int lxc_clear_cgroups(struct lxc_conf *c, const char *key, int version);
549__hidden extern int lxc_clear_mount_entries(struct lxc_conf *c);
550__hidden extern int lxc_clear_automounts(struct lxc_conf *c);
551__hidden extern int lxc_clear_hooks(struct lxc_conf *c, const char *key);
552__hidden extern int lxc_clear_idmaps(struct lxc_conf *c);
553__hidden extern int lxc_clear_groups(struct lxc_conf *c);
554__hidden extern int lxc_clear_environment(struct lxc_conf *c);
555__hidden extern int lxc_clear_limits(struct lxc_conf *c, const char *key);
556__hidden extern int lxc_delete_autodev(struct lxc_handler *handler);
557__hidden extern int lxc_clear_autodev_tmpfs_size(struct lxc_conf *c);
efb7e304
CB
558__hidden extern int lxc_setup_rootfs_prepare_root(struct lxc_conf *conf, const char *name,
559 const char *lxcpath);
560__hidden extern int lxc_setup(struct lxc_handler *handler);
561__hidden extern int lxc_setup_parent(struct lxc_handler *handler);
223797c3 562__hidden extern int setup_resource_limits(struct lxc_conf *conf, pid_t pid);
efb7e304
CB
563__hidden extern int find_unmapped_nsid(const struct lxc_conf *conf, enum idtype idtype);
564__hidden extern int mapped_hostid(unsigned id, const struct lxc_conf *conf, enum idtype idtype);
565__hidden extern int userns_exec_1(const struct lxc_conf *conf, int (*fn)(void *), void *data,
566 const char *fn_name);
567__hidden extern int userns_exec_full(struct lxc_conf *conf, int (*fn)(void *), void *data,
568 const char *fn_name);
d94eb390 569__hidden extern int parse_mntopts_legacy(const char *mntopts, unsigned long *mntflags, char **mntdata);
efb7e304 570__hidden extern int parse_propagationopts(const char *mntopts, unsigned long *pflags);
1b82d721 571__hidden extern int parse_lxc_mount_attrs(struct lxc_mount_options *opts, char *mnt_opts);
704cadd5 572__hidden extern int parse_mount_attrs(struct lxc_mount_options *opts, const char *mntopts);
efb7e304 573__hidden extern void tmp_proc_unmount(struct lxc_conf *lxc_conf);
efb7e304 574__hidden extern void suggest_default_idmap(void);
be0bc4d1
CB
575__hidden extern FILE *make_anonymous_mount_file(const struct list_head *mount,
576 bool include_nesting_helpers);
efb7e304
CB
577__hidden extern int run_script(const char *name, const char *section, const char *script, ...);
578__hidden extern int run_script_argv(const char *name, unsigned int hook_version, const char *section,
579 const char *script, const char *hookname, char **argsin);
309ae287 580
20ab7578 581__hidden extern bool has_cap(int cap, struct lxc_conf *conf);
d84b26bc 582static inline bool lxc_wants_cap(int cap, struct lxc_conf *conf)
309ae287 583{
d84b26bc
CB
584 if (lxc_caps_last_cap() < cap)
585 return false;
586
20ab7578 587 return has_cap(cap, conf);
309ae287
CB
588}
589
ba9f9347 590__hidden extern int setup_sysctl_parameters(struct lxc_conf *conf);
efb7e304 591__hidden extern int lxc_clear_sysctls(struct lxc_conf *c, const char *key);
91d04bf9 592__hidden extern int setup_proc_filesystem(struct lxc_conf *conf, pid_t pid);
efb7e304
CB
593__hidden extern int lxc_clear_procs(struct lxc_conf *c, const char *key);
594__hidden extern int lxc_clear_apparmor_raw(struct lxc_conf *c);
595__hidden extern int lxc_clear_namespace(struct lxc_conf *c);
596__hidden extern int userns_exec_minimal(const struct lxc_conf *conf, int (*fn_parent)(void *),
597 void *fn_parent_data, int (*fn_child)(void *),
598 void *fn_child_data);
599__hidden extern int userns_exec_mapped_root(const char *path, int path_fd,
600 const struct lxc_conf *conf);
6e1a327a
CB
601static inline int chown_mapped_root(const char *path, const struct lxc_conf *conf)
602{
603 return userns_exec_mapped_root(path, -EBADF, conf);
604}
5ae72b98 605
493ae3fe 606__hidden extern int lxc_sync_fds_parent(struct lxc_handler *handler);
111ed96e 607__hidden extern int lxc_sync_fds_child(struct lxc_handler *handler);
68f3899e 608
02efd041
CB
609static inline const char *get_rootfs_mnt(const struct lxc_rootfs *rootfs)
610{
611 static const char *s = "/";
612
613 return !is_empty_string(rootfs->path) ? rootfs->mount : s;
614}
615
423374e9
CB
616static inline void put_lxc_mount_options(struct lxc_mount_options *mnt_opts)
617{
618 mnt_opts->create_dir = 0;
619 mnt_opts->create_file = 0;
620 mnt_opts->optional = 0;
621 mnt_opts->relative = 0;
622 mnt_opts->userns_path[0] = '\0';
623 mnt_opts->mnt_flags = 0;
624 mnt_opts->prop_flags = 0;
625
423374e9 626 free_disarm(mnt_opts->data);
e73af35b 627 free_disarm(mnt_opts->raw_options);
423374e9
CB
628}
629
79ff643d
CB
630static inline void put_lxc_rootfs(struct lxc_rootfs *rootfs, bool unpin)
631{
632 if (rootfs) {
633 close_prot_errno_disarm(rootfs->dfd_host);
634 close_prot_errno_disarm(rootfs->dfd_mnt);
635 close_prot_errno_disarm(rootfs->dfd_dev);
636 if (unpin)
637 close_prot_errno_disarm(rootfs->fd_path_pin);
4b875ef9 638 close_prot_errno_disarm(rootfs->dfd_idmapped);
423374e9 639 put_lxc_mount_options(&rootfs->mnt_opts);
4e86cad3
CB
640 storage_put(rootfs->storage);
641 rootfs->storage = NULL;
79ff643d
CB
642 }
643}
644
a7744f12
CB
645static inline void lxc_clear_cgroup2_devices(struct bpf_devices *bpf_devices)
646{
93de768e 647 struct device_item *device, *n;
a7744f12 648
93de768e
CB
649 list_for_each_entry_safe(device, n, &bpf_devices->devices, head)
650 list_del(&device->head);
a7744f12 651
93de768e 652 INIT_LIST_HEAD(&bpf_devices->devices);
a7744f12
CB
653}
654
64a04c84
CB
655static inline int lxc_personality(personality_t persona)
656{
657 if (persona < 0)
658 return ret_errno(EINVAL);
659
660 return personality(persona);
661}
662
c294a68d 663__hidden extern int lxc_set_environment(const struct lxc_conf *conf);
20ab7578 664__hidden extern int parse_cap(const char *cap);
c294a68d 665
1a0e70ac 666#endif /* __LXC_CONF_H */