build method
void
build()
Build the user environment
Implementation
void build() {
// // [initgroups] can only be called when we are root
// // so depending on which direction we are moving the
// // users privilieges we need to call this before
// // or after changing the uid.
// if (uid == 0) {
// initgroups(username);
// }
// shells like bash/zsh reset the euid to the uid
// to descalate priviliges.
// This results in the euid being reset to sudo (0)
// so to stop this we need to ensure a real uid/gid
// are actually the original user not sudo.
// This fits nicely with our principle that when a user
// calls [releasePrivileges] the script should fully
// appear to not have been run as sudo.
verbose(() => '''
Building user enviroment
username: $username
HOME: $pathToHome
USER: $username
LOGNAME: $username
SHELL: ${env['SHELL']}
gid: $gid
uid: $uid''');
// reorder(() => uid == 0, () => setuid(uid), () => setgid(gid));
reorder(() => uid == 0, () => seteuid(uid), () => setegid(gid));
env['HOME'] = pathToHome;
env['USER'] = username;
env['LOGNAME'] = username;
env['SHELL'] = pathToShell;
}