Not all systems implement setuid(2) the way you expect.
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@8362 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
@@ -954,14 +954,19 @@ main (int argc, char **argv)
|
|||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
struct passwd *pw;
|
struct passwd *pw;
|
||||||
|
uid_t uid = getuid();
|
||||||
if (!(pw = k_getpwuid(0)))
|
if (!(pw = k_getpwuid(0)))
|
||||||
errx (1, "can't get root's passwd!");
|
errx (1, "can't get root's passwd!");
|
||||||
strlcpy(root_cpass, pw->pw_passwd, sizeof(root_cpass));
|
strlcpy(root_cpass, pw->pw_passwd, sizeof(root_cpass));
|
||||||
|
|
||||||
if (!(pw = k_getpwuid(getuid())))
|
if (!(pw = k_getpwuid(uid)))
|
||||||
errx (1, "Can't get your password entry!");
|
errx (1, "Can't get your password entry!");
|
||||||
strlcpy(user_cpass, pw->pw_passwd, sizeof(user_cpass));
|
strlcpy(user_cpass, pw->pw_passwd, sizeof(user_cpass));
|
||||||
setuid(getuid());
|
setuid(uid);
|
||||||
|
if (uid != 0 && setuid(0) != -1) {
|
||||||
|
fprintf(stderr, "Failed to drop privileges!");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
/* Now we're no longer running setuid root. */
|
/* Now we're no longer running setuid root. */
|
||||||
strlcpy(login, pw->pw_name, sizeof(login));
|
strlcpy(login, pw->pw_name, sizeof(login));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user