From: Christian Brauner Date: Wed, 17 Mar 2021 09:35:33 +0000 (+0100) Subject: conf: add first, trivial support for idmapped mounts X-Git-Tag: lxc-5.0.0~197^2~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f6815906a1e4a852b1f43b956fbb8dd04306d13e;p=thirdparty%2Flxc.git conf: add first, trivial support for idmapped mounts Signed-off-by: Christian Brauner --- diff --git a/src/lxc/conf.c b/src/lxc/conf.c index 40e238ebd..c23bf0349 100644 --- a/src/lxc/conf.c +++ b/src/lxc/conf.c @@ -98,6 +98,10 @@ #include <../include/prlimit.h> #endif +#ifndef HAVE_STRLCPY +#include "include/strlcpy.h" +#endif + lxc_log_define(conf, lxc); /* @@ -2095,6 +2099,7 @@ const char *lxc_mount_options_info[LXC_MOUNT_MAX] = { "create=file", "optional", "relative", + "idmap=", }; /* Remove "optional", "create=dir", and "create=file" from mntopt */ @@ -2103,7 +2108,8 @@ void parse_lxc_mntopts(struct lxc_mount_options *opts, char *mnt_opts) for (size_t i = LXC_MOUNT_CREATE_DIR; i < LXC_MOUNT_MAX; i++) { const char *opt_name = lxc_mount_options_info[i]; - char *p, *p2; + size_t len; + char *idmap_path, *p, *p2; p = strstr(mnt_opts, opt_name); if (!p) @@ -2122,9 +2128,20 @@ void parse_lxc_mntopts(struct lxc_mount_options *opts, char *mnt_opts) case LXC_MOUNT_RELATIVE: opts->relative = 1; break; + case LXC_MOUNT_IDMAP: + p2 = p; + p2 += STRLITERALLEN("idmap="); + idmap_path = strchrnul(p2, ','); + + len = strlcpy(opts->userns_path, p2, idmap_path - p2 + 1); + if (len >= sizeof(opts->userns_path)) + WARN("Excessive idmap path length for \"idmap=\" LXC specific mount option"); + else + TRACE("Parse LXC specific mount option \"idmap=%s\"", opts->userns_path); + break; default: WARN("Unknown LXC specific mount option"); - continue; + break; } p2 = strchr(p, ','); diff --git a/src/lxc/conf.h b/src/lxc/conf.h index a141f9409..a840228ff 100644 --- a/src/lxc/conf.h +++ b/src/lxc/conf.h @@ -186,7 +186,8 @@ typedef enum lxc_mount_options_t { LXC_MOUNT_CREATE_FILE = 1, LXC_MOUNT_OPTIONAL = 2, LXC_MOUNT_RELATIVE = 3, - LXC_MOUNT_MAX = 4, + LXC_MOUNT_IDMAP = 4, + LXC_MOUNT_MAX = 5, } lxc_mount_options_t; __hidden extern const char *lxc_mount_options_info[LXC_MOUNT_MAX]; @@ -196,6 +197,7 @@ struct lxc_mount_options { int create_file : 1; int optional : 1; int relative : 1; + char userns_path[PATH_MAX]; }; /* Defines a structure to store the rootfs location, the