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 2006-09-29 04:41:37 +00:00
parent 0c209e1877
commit 16c630b2da

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);