Unverified Commit 9e34dbeb by Christian Brauner Committed by Stéphane Graber

confile: add lxc_get_idmaps()

lxc_get_idmaps() retrieves the idmaps defined for the container. If multiple id mappings are defined they will be separated by newlines. Signed-off-by: 's avatarChristian Brauner <christian.brauner@ubuntu.com>
parent f7181965
...@@ -2730,6 +2730,54 @@ static int lxc_get_item_network(struct lxc_conf *c, char *retv, int inlen) ...@@ -2730,6 +2730,54 @@ static int lxc_get_item_network(struct lxc_conf *c, char *retv, int inlen)
return fulllen; return fulllen;
} }
static int lxc_get_idmaps(struct lxc_conf *c, char *retv, int inlen)
{
struct lxc_list *it;
int len, listlen, ret;
int fulllen = 0;
/* "u 1000 1000000 65536"
*
* let's render this as
*
* sizeof(char)
* +
* sizeof(" ")
* +
* sizeof(uint64_t)
* +
* sizeof(" ")
* +
* sizeof(uint64_t)
* +
* sizeof(" ")
* +
* sizeof(uint64_t)
* +
* \0
*/
#define __LXC_IDMAP_STR_BUF (3 * LXC_NUMSTRLEN64 + 3 + 1 + 1)
char buf[__LXC_IDMAP_STR_BUF];
if (!retv)
inlen = 0;
else
memset(retv, 0, inlen);
listlen = lxc_list_len(&c->id_map);
lxc_list_for_each(it, &c->id_map)
{
struct id_map *map = it->elem;
ret = snprintf(buf, __LXC_IDMAP_STR_BUF, "%c %lu %lu %lu",
(map->idtype == ID_TYPE_UID) ? 'u' : 'g',
map->nsid, map->hostid, map->range);
if (ret < 0 || ret >= __LXC_IDMAP_STR_BUF)
return -1;
strprint(retv, inlen, "%s%s", buf, (listlen-- > 1) ? "\n" : "");
}
return fulllen;
}
int lxc_get_config_item(struct lxc_conf *c, const char *key, char *retv, int lxc_get_config_item(struct lxc_conf *c, const char *key, char *retv,
int inlen) int inlen)
{ {
...@@ -2809,6 +2857,8 @@ int lxc_get_config_item(struct lxc_conf *c, const char *key, char *retv, ...@@ -2809,6 +2857,8 @@ int lxc_get_config_item(struct lxc_conf *c, const char *key, char *retv,
return lxc_get_conf_int(c, retv, inlen, c->init_gid); return lxc_get_conf_int(c, retv, inlen, c->init_gid);
else if (strcmp(key, "lxc.ephemeral") == 0) else if (strcmp(key, "lxc.ephemeral") == 0)
return lxc_get_conf_int(c, retv, inlen, c->ephemeral); return lxc_get_conf_int(c, retv, inlen, c->ephemeral);
else if (strcmp(key, "lxc.id_map") == 0)
return lxc_get_idmaps(c, retv, inlen);
else return -1; else return -1;
if (!v) if (!v)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment