]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
conf: add first, trivial support for idmapped mounts
authorChristian Brauner <christian.brauner@ubuntu.com>
Wed, 17 Mar 2021 09:35:33 +0000 (10:35 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Wed, 21 Apr 2021 08:05:58 +0000 (10:05 +0200)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/conf.c
src/lxc/conf.h

index 40e238ebd311c3f76a4b8fceb7327f17246d876c..c23bf0349f6c7b5b1f490f8c4855a2fd37b21fdb 100644 (file)
 #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=<path>\" 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, ',');
index a141f9409595091de5341c34e6c48b8848846dd6..a840228ffbfb92a00f8e8fa60f663a5d8b98d82d 100644 (file)
@@ -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