Check return code of setuid() and setgid() in finger.

While they will not fail in normal circumstances, better safe than
sorry.

MFC after:	1 week
This commit is contained in:
Simon L. B. Nielsen 2011-04-23 14:19:26 +00:00
parent 1ae2ca130d
commit 6e46c1cc7d
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=220971

View file

@ -164,11 +164,15 @@ main(int argc, char **argv)
if (getuid() == 0 || geteuid() == 0) {
invoker_root = 1;
if ((pw = getpwnam(UNPRIV_NAME)) && pw->pw_uid > 0) {
setgid(pw->pw_gid);
setuid(pw->pw_uid);
if (setgid(pw->pw_gid) != 0)
err(1, "setgid()");
if (setuid(pw->pw_uid) != 0)
err(1, "setuid()");
} else {
setgid(UNPRIV_UGID);
setuid(UNPRIV_UGID);
if (setgid(UNPRIV_UGID) != 0)
err(1, "setgid()");
if (setuid(UNPRIV_UGID) != 0)
err(1, "setuid()");
}
}