example and not showing the setgid analogues:
1) setuid(getuid());
This dropped privileges before an exec and is normally a
good thing. Except here, the return value isn't checked.
And, we don't have any setuid programs in nmh now, so it was
unnecessary.
2) if (geteuid() == 0) setuid(pw->pw_uid);
This would have been a security hole if the executable was
setuid root because the user specifies the source of the pw
data. This was in slocal(1), which is not setuid, so this
was certainly not needed.
3) setuid(geteuid());
This was in post(8) for when it called the sendmail
executable directly (-mts sendmail or -mts sendmail/pipe.
It's not necessary with modern sendmail or replacements.
vec[vecp++] = "-ov";
vec[vecp++] = NULL;
- setgid (getegid ());
- setuid (geteuid ());
execvp (sendmail, vec);
fprintf (stderr, "unable to exec ");
perror (sendmail);
case 0:
/* It's not necessary to call unregister_for_removal(0)
because the child calls _exit() in context_save(). */
- setgid (getgid ());
- setuid (getuid ());
break;
default:
return 0;
case 0:
- setgid (getgid ());
- setuid (getuid ());
-
execl ("/bin/mkdir", "mkdir", dir, (void *) NULL);
execl ("/usr/bin/mkdir", "mkdir", dir, (void *) NULL);
fprintf (stderr, "unable to exec ");
int inpipe[2]; /* for reading from the server */
int outpipe[2]; /* for sending to the server */
- /* first give up any root priviledges we may have for rpop */
- setuid(getuid());
-
pipe(inpipe);
pipe(outpipe);
#include <sys/ioctl.h>
#include <fcntl.h>
-/* Hopefully, grp.h declares initgroups(). If we run into a platform
- where it doesn't, we could consider declaring it here as well. */
-#include <grp.h>
-
/* This define is needed for Berkeley db v2 and above to
* make the header file expose the 'historical' ndbm APIs.
* We define it unconditionally because this is simple and
chdir ("/");
umask (0077);
- if (geteuid() == 0) {
- setgid (pw->pw_gid);
- initgroups (pw->pw_name, pw->pw_gid);
- setuid (pw->pw_uid);
- }
-
if (info == NULL)
info = "";