Unverified Commit e7bd80d8 by Christian Brauner Committed by Stéphane Graber

conf: improve lxc_map_ids()

parent fabcb0cc
...@@ -3234,7 +3234,14 @@ static int write_id_mapping(enum idtype idtype, pid_t pid, const char *buf, ...@@ -3234,7 +3234,14 @@ static int write_id_mapping(enum idtype idtype, pid_t pid, const char *buf,
return 0; return 0;
} }
/* Check whether a binary exist and has either CAP_SETUID, CAP_SETGID or both. */ /* Check whether a binary exist and has either CAP_SETUID, CAP_SETGID or both.
*
* @return 1 if functional binary was found
* @return 0 if binary exists but is lacking privilege
* @return -ENOENT if binary does not exist
* @return -EINVAL if cap to check is neither CAP_SETUID nor CAP_SETGID
*
*/
static int idmaptool_on_path_and_privileged(const char *binary, cap_value_t cap) static int idmaptool_on_path_and_privileged(const char *binary, cap_value_t cap)
{ {
char *path; char *path;
...@@ -3242,6 +3249,9 @@ static int idmaptool_on_path_and_privileged(const char *binary, cap_value_t cap) ...@@ -3242,6 +3249,9 @@ static int idmaptool_on_path_and_privileged(const char *binary, cap_value_t cap)
struct stat st; struct stat st;
int fret = 0; int fret = 0;
if (cap != CAP_SETUID && cap != CAP_SETGID)
return -EINVAL;
path = on_path(binary, NULL); path = on_path(binary, NULL);
if (!path) if (!path)
return -ENOENT; return -ENOENT;
...@@ -3330,7 +3340,17 @@ int lxc_map_ids(struct lxc_list *idmap, pid_t pid) ...@@ -3330,7 +3340,17 @@ int lxc_map_ids(struct lxc_list *idmap, pid_t pid)
* range by shadow. * range by shadow.
*/ */
uidmap = idmaptool_on_path_and_privileged("newuidmap", CAP_SETUID); uidmap = idmaptool_on_path_and_privileged("newuidmap", CAP_SETUID);
if (uidmap == -ENOENT)
WARN("newuidmap binary is missing");
else if (!uidmap)
WARN("newuidmap is lacking necessary privileges");
gidmap = idmaptool_on_path_and_privileged("newgidmap", CAP_SETGID); gidmap = idmaptool_on_path_and_privileged("newgidmap", CAP_SETGID);
if (gidmap == -ENOENT)
WARN("newgidmap binary is missing");
else if (!gidmap)
WARN("newgidmap is lacking necessary privileges");
if (uidmap > 0 && gidmap > 0) { if (uidmap > 0 && gidmap > 0) {
DEBUG("Functional newuidmap and newgidmap binary found."); DEBUG("Functional newuidmap and newgidmap binary found.");
use_shadow = true; use_shadow = true;
......
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