From: Christian Brauner Date: Sun, 9 Sep 2018 14:34:50 +0000 (+0200) Subject: utils: make lxc_switch_uid_gid() return bool X-Git-Tag: lxc-3.1.0~115^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=464c46115fe3f272c6114a76e1e6c647f475d661;p=thirdparty%2Flxc.git utils: make lxc_switch_uid_gid() return bool Signed-off-by: Christian Brauner --- diff --git a/src/lxc/attach.c b/src/lxc/attach.c index 951d3bb93..425f257e4 100644 --- a/src/lxc/attach.c +++ b/src/lxc/attach.c @@ -854,8 +854,7 @@ static int attach_child_main(struct attach_clone_payload *payload) if (ns_root_uid == LXC_INVALID_UID) goto on_error; - ret = lxc_switch_uid_gid(ns_root_uid, ns_root_gid); - if (ret < 0) + if (!lxc_switch_uid_gid(ns_root_uid, ns_root_gid)) goto on_error; } @@ -969,8 +968,7 @@ static int attach_child_main(struct attach_clone_payload *payload) if (new_gid == ns_root_gid) new_gid = LXC_INVALID_GID; - ret = lxc_switch_uid_gid(new_uid, new_gid); - if (ret < 0) + if (!lxc_switch_uid_gid(new_uid, new_gid)) goto on_error; /* We're done, so we can now do whatever the user intended us to do. */ diff --git a/src/lxc/cmd/lxc_usernsexec.c b/src/lxc/cmd/lxc_usernsexec.c index 0b698f86d..e5b5d1f01 100644 --- a/src/lxc/cmd/lxc_usernsexec.c +++ b/src/lxc/cmd/lxc_usernsexec.c @@ -104,8 +104,7 @@ static int do_child(void *vargv) char **argv = (char **)vargv; /* Assume we want to become root */ - ret = lxc_switch_uid_gid(0, 0); - if (ret < 0) + if (!lxc_switch_uid_gid(0, 0)) return -1; if (!lxc_setgroups(0, NULL)) diff --git a/src/lxc/start.c b/src/lxc/start.c index 8d0e2a1e6..8d3a7ced5 100644 --- a/src/lxc/start.c +++ b/src/lxc/start.c @@ -1124,8 +1124,7 @@ static int do_start(void *data) if (!handler->conf->root_nsgid_map) nsgid = handler->conf->init_gid; - ret = lxc_switch_uid_gid(nsuid, nsgid); - if (ret < 0) + if (!lxc_switch_uid_gid(nsuid, nsgid)) goto out_warn_father; /* Drop groups only after we switched to a valid gid in the new @@ -1362,8 +1361,7 @@ static int do_start(void *data) if (new_gid == nsgid) new_gid = LXC_INVALID_GID; - ret = lxc_switch_uid_gid(new_uid, new_gid); - if (ret < 0) + if (!lxc_switch_uid_gid(new_uid, new_gid)) goto out_warn_father; /* If we are in a new user namespace we already dropped all groups when diff --git a/src/lxc/storage/rsync.c b/src/lxc/storage/rsync.c index e53a538db..ca2da186e 100644 --- a/src/lxc/storage/rsync.c +++ b/src/lxc/storage/rsync.c @@ -50,8 +50,7 @@ int lxc_rsync_exec_wrapper(void *data) int ret; struct rsync_data_char *args = data; - ret = lxc_switch_uid_gid(0, 0); - if (ret < 0) + if (!lxc_switch_uid_gid(0, 0)) return -1; if (!lxc_setgroups(0, NULL)) @@ -116,8 +115,7 @@ int lxc_rsync(struct rsync_data *data) return -1; } - ret = lxc_switch_uid_gid(0, 0); - if (ret < 0) + if (!lxc_switch_uid_gid(0, 0)) return -1; if (!lxc_setgroups(0, NULL)) diff --git a/src/lxc/utils.c b/src/lxc/utils.c index 9c30dc2ea..9b6f0a617 100644 --- a/src/lxc/utils.c +++ b/src/lxc/utils.c @@ -1351,7 +1351,7 @@ int lxc_preserve_ns(const int pid, const char *ns) 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; @@ -1359,7 +1359,7 @@ int lxc_switch_uid_gid(uid_t uid, gid_t gid) ret = setgid(gid); if (ret < 0) { SYSERROR("Failed to switch to gid %d", gid); - return -1; + return false; } NOTICE("Switched to gid %d", gid); } @@ -1368,12 +1368,12 @@ int lxc_switch_uid_gid(uid_t uid, gid_t gid) ret = setuid(uid); if (ret < 0) { SYSERROR("Failed to switch to uid %d", uid); - return -1; + return false; } NOTICE("Switched to uid %d", uid); } - return ret; + return true; } /* Simple covenience function which enables uniform logging. */ diff --git a/src/lxc/utils.h b/src/lxc/utils.h index e6a82978f..0f121e673 100644 --- a/src/lxc/utils.h +++ b/src/lxc/utils.h @@ -361,7 +361,7 @@ extern bool task_blocks_signal(pid_t pid, int signal); /* 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. */ -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[]); /* Find an unused loop device and associate it with source. */