utils: make lxc_switch_uid_gid() return bool

parent 8af07f82
...@@ -854,8 +854,7 @@ static int attach_child_main(struct attach_clone_payload *payload) ...@@ -854,8 +854,7 @@ static int attach_child_main(struct attach_clone_payload *payload)
if (ns_root_uid == LXC_INVALID_UID) if (ns_root_uid == LXC_INVALID_UID)
goto on_error; goto on_error;
ret = lxc_switch_uid_gid(ns_root_uid, ns_root_gid); if (!lxc_switch_uid_gid(ns_root_uid, ns_root_gid))
if (ret < 0)
goto on_error; goto on_error;
} }
...@@ -969,8 +968,7 @@ static int attach_child_main(struct attach_clone_payload *payload) ...@@ -969,8 +968,7 @@ static int attach_child_main(struct attach_clone_payload *payload)
if (new_gid == ns_root_gid) if (new_gid == ns_root_gid)
new_gid = LXC_INVALID_GID; new_gid = LXC_INVALID_GID;
ret = lxc_switch_uid_gid(new_uid, new_gid); if (!lxc_switch_uid_gid(new_uid, new_gid))
if (ret < 0)
goto on_error; goto on_error;
/* We're done, so we can now do whatever the user intended us to do. */ /* We're done, so we can now do whatever the user intended us to do. */
......
...@@ -104,8 +104,7 @@ static int do_child(void *vargv) ...@@ -104,8 +104,7 @@ static int do_child(void *vargv)
char **argv = (char **)vargv; char **argv = (char **)vargv;
/* Assume we want to become root */ /* Assume we want to become root */
ret = lxc_switch_uid_gid(0, 0); if (!lxc_switch_uid_gid(0, 0))
if (ret < 0)
return -1; return -1;
if (!lxc_setgroups(0, NULL)) if (!lxc_setgroups(0, NULL))
......
...@@ -1124,8 +1124,7 @@ static int do_start(void *data) ...@@ -1124,8 +1124,7 @@ static int do_start(void *data)
if (!handler->conf->root_nsgid_map) if (!handler->conf->root_nsgid_map)
nsgid = handler->conf->init_gid; nsgid = handler->conf->init_gid;
ret = lxc_switch_uid_gid(nsuid, nsgid); if (!lxc_switch_uid_gid(nsuid, nsgid))
if (ret < 0)
goto out_warn_father; goto out_warn_father;
/* Drop groups only after we switched to a valid gid in the new /* Drop groups only after we switched to a valid gid in the new
...@@ -1362,8 +1361,7 @@ static int do_start(void *data) ...@@ -1362,8 +1361,7 @@ static int do_start(void *data)
if (new_gid == nsgid) if (new_gid == nsgid)
new_gid = LXC_INVALID_GID; new_gid = LXC_INVALID_GID;
ret = lxc_switch_uid_gid(new_uid, new_gid); if (!lxc_switch_uid_gid(new_uid, new_gid))
if (ret < 0)
goto out_warn_father; goto out_warn_father;
/* If we are in a new user namespace we already dropped all groups when /* If we are in a new user namespace we already dropped all groups when
......
...@@ -50,8 +50,7 @@ int lxc_rsync_exec_wrapper(void *data) ...@@ -50,8 +50,7 @@ int lxc_rsync_exec_wrapper(void *data)
int ret; int ret;
struct rsync_data_char *args = data; struct rsync_data_char *args = data;
ret = lxc_switch_uid_gid(0, 0); if (!lxc_switch_uid_gid(0, 0))
if (ret < 0)
return -1; return -1;
if (!lxc_setgroups(0, NULL)) if (!lxc_setgroups(0, NULL))
...@@ -116,8 +115,7 @@ int lxc_rsync(struct rsync_data *data) ...@@ -116,8 +115,7 @@ int lxc_rsync(struct rsync_data *data)
return -1; return -1;
} }
ret = lxc_switch_uid_gid(0, 0); if (!lxc_switch_uid_gid(0, 0))
if (ret < 0)
return -1; return -1;
if (!lxc_setgroups(0, NULL)) if (!lxc_setgroups(0, NULL))
......
...@@ -1351,7 +1351,7 @@ int lxc_preserve_ns(const int pid, const char *ns) ...@@ -1351,7 +1351,7 @@ int lxc_preserve_ns(const int pid, const char *ns)
return open(path, O_RDONLY | O_CLOEXEC); return open(path, O_RDONLY | O_CLOEXEC);
} }
int lxc_switch_uid_gid(uid_t uid, gid_t gid) bool lxc_switch_uid_gid(uid_t uid, gid_t gid)
{ {
int ret = 0; int ret = 0;
...@@ -1359,7 +1359,7 @@ int lxc_switch_uid_gid(uid_t uid, gid_t gid) ...@@ -1359,7 +1359,7 @@ int lxc_switch_uid_gid(uid_t uid, gid_t gid)
ret = setgid(gid); ret = setgid(gid);
if (ret < 0) { if (ret < 0) {
SYSERROR("Failed to switch to gid %d", gid); SYSERROR("Failed to switch to gid %d", gid);
return -1; return false;
} }
NOTICE("Switched to gid %d", gid); NOTICE("Switched to gid %d", gid);
} }
...@@ -1368,12 +1368,12 @@ int lxc_switch_uid_gid(uid_t uid, gid_t gid) ...@@ -1368,12 +1368,12 @@ int lxc_switch_uid_gid(uid_t uid, gid_t gid)
ret = setuid(uid); ret = setuid(uid);
if (ret < 0) { if (ret < 0) {
SYSERROR("Failed to switch to uid %d", uid); SYSERROR("Failed to switch to uid %d", uid);
return -1; return false;
} }
NOTICE("Switched to uid %d", uid); NOTICE("Switched to uid %d", uid);
} }
return ret; return true;
} }
/* Simple covenience function which enables uniform logging. */ /* Simple covenience function which enables uniform logging. */
......
...@@ -361,7 +361,7 @@ extern bool task_blocks_signal(pid_t pid, int signal); ...@@ -361,7 +361,7 @@ extern bool task_blocks_signal(pid_t pid, int signal);
/* Switch to a new uid and gid. /* Switch to a new uid and gid.
* If LXC_INVALID_{G,U}ID is passed then the set{g,u}id() will not be called. * If LXC_INVALID_{G,U}ID is passed then the set{g,u}id() will not be called.
*/ */
extern int lxc_switch_uid_gid(uid_t uid, gid_t gid); extern bool lxc_switch_uid_gid(uid_t uid, gid_t gid);
extern bool lxc_setgroups(int size, gid_t list[]); extern bool lxc_setgroups(int size, gid_t list[]);
/* Find an unused loop device and associate it with source. */ /* Find an unused loop device and associate it with source. */
......
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