Do not chdir(2) until after setuid(2), otherwise "su - username" would fail

when root doesn't have the permission to enter target user's home directory.
If set, PAM environment variable HOME will be used in chdir(2) instead of
pwd->pw_dir, this allows pam_chroot module to continue to function.
This commit is contained in:
Luoqi Chen 2006-09-29 04:41:37 +00:00
parent a9a5d47c85
commit 5a8e64ee60
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=162761

View File

@ -403,12 +403,6 @@ main(int argc, char *argv[])
}
setpriority(PRIO_PROCESS, 0, prio);
/* Switch to home directory */
if (asthem) {
if (chdir(pwd->pw_dir) < 0)
errx(1, "no directory");
}
/*
* PAM modules might add supplementary groups in pam_setcred(), so
* initialize them first.
@ -540,6 +534,10 @@ main(int argc, char *argv[])
LOGIN_SETENV);
if (p)
setenv("TERM", p, 1);
p = pam_getenv(pamh, "HOME");
if (chdir(p ? p : pwd->pw_dir) < 0)
errx(1, "no directory");
}
}
login_close(lc);