]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
conf{ile}: detect ns{g,u}id mapping for root
authorChristian Brauner <christian.brauner@ubuntu.com>
Tue, 2 Jan 2018 22:27:55 +0000 (23:27 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Fri, 19 Jan 2018 13:20:11 +0000 (14:20 +0100)
Closes #2033.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/conf.c
src/lxc/conf.h
src/lxc/confile.c

index f9debf71e647143cfafc33690598e32fe4a3a035..e4411d9b98bc9de4c76904312d10476c9cea3ef4 100644 (file)
@@ -2325,6 +2325,8 @@ struct lxc_conf *lxc_conf_init(void)
        lxc_list_init(&new->caps);
        lxc_list_init(&new->keepcaps);
        lxc_list_init(&new->id_map);
+       new->root_nsuid_map = NULL;
+       new->root_nsgid_map = NULL;
        lxc_list_init(&new->includes);
        lxc_list_init(&new->aliens);
        lxc_list_init(&new->environment);
index aa819da4d6577214bec46e4dae86dbd857c6f6a9..306056105a4ca799b8d5c2956c04fc09188212ad 100644 (file)
@@ -209,7 +209,15 @@ struct lxc_conf {
        signed long personality;
        struct utsname *utsname;
        struct lxc_list cgroup;
-       struct lxc_list id_map;
+       struct {
+               struct lxc_list id_map;
+               /* Pointer to the idmap entry for the container's root uid in
+                * the id_map list. Do not free! */
+               struct id_map *root_nsuid_map;
+               /* Pointer to the idmap entry for the container's root gid in
+                * the id_map list. Do not free! */
+               struct id_map *root_nsgid_map;
+       };
        struct lxc_list network;
        int auto_mounts;
        struct lxc_list mount_list;
index 211b7b6fa99f077a6e0df0b63c25862a12d6cbce..77f06edc73e35ec39307faeb624e1de478c19f21 100644 (file)
@@ -1858,7 +1858,7 @@ static int set_config_idmaps(const char *key, const char *value,
        if (ret < 0)
                goto on_error;
 
-       INFO("read uid map: type %c nsid %lu hostid %lu range %lu", type, nsid, hostid, range);
+       INFO("Read uid map: type %c nsid %lu hostid %lu range %lu", type, nsid, hostid, range);
        if (type == 'u')
                idmap->idtype = ID_TYPE_UID;
        else if (type == 'g')
@@ -1871,6 +1871,16 @@ static int set_config_idmaps(const char *key, const char *value,
        idmap->range = range;
        idmaplist->elem = idmap;
        lxc_list_add_tail(&lxc_conf->id_map, idmaplist);
+
+       if (!lxc_conf->root_nsuid_map && idmap->idtype == ID_TYPE_UID)
+               if (idmap->nsid == 0)
+                       lxc_conf->root_nsuid_map = idmap;
+
+
+       if (!lxc_conf->root_nsuid_map && idmap->idtype == ID_TYPE_GID)
+               if (idmap->nsid == 0)
+                       lxc_conf->root_nsgid_map = idmap;
+
        idmap = NULL;
 
        return 0;