def setup_shell_and_homedir (username): assert os.geteuid () == 0 pw = pwd.getpwnam (username) dprint ("Setting shell for '%s' to '%s'", username, DEFAULT_SHELL) usermod.set_shell (username, DEFAULT_SHELL) temp_homedir = usermod.create_temporary_homedir (pw.pw_uid, pw.pw_gid) dprint ("Setting temporary home directory for '%s' to '%s'", username, temp_homedir) usermod.set_homedir (username, temp_homedir) return temp_homedir
def reset_shell_and_homedir (username, temp_homedir): assert os.geteuid () == 0 pw = pwd.getpwnam (username) dprint ("Unsetting homedir for '%s'", username) usermod.set_homedir (username, "") dprint ("Deleting temporary homedir '%s'", temp_homedir) shutil.rmtree (temp_homedir) dprint ("Resetting shell for '%s' to '%s'", username, NOLOGIN_SHELL) usermod.set_shell (username, NOLOGIN_SHELL)
def setup_shell_and_homedir (username): assert os.geteuid () == 0 pw = pwd.getpwnam (username) dprint ("Setting shell for '%s' to '%s'", username, DEFAULT_SHELL) usermod.set_shell (username, DEFAULT_SHELL) # Wait for previous sabayon processes to die before proceeding for i in range (1,30): temp_homedir = usermod.create_temporary_homedir (pw.pw_uid, pw.pw_gid) dprint ("Setting temporary home directory for '%s' to '%s' attempt %d", username, temp_homedir, i) retval = usermod.set_homedir (username, temp_homedir) dprint ("retval=%d", retval) if retval == 0: break time.sleep(1) return temp_homedir