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;
}
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. */
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))
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
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
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))
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))
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;
ret = setgid(gid);
if (ret < 0) {
SYSERROR("Failed to switch to gid %d", gid);
- return -1;
+ return false;
}
NOTICE("Switched to gid %d", 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. */
/* 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. */