summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libexec/tftpd/tftpd.c22
1 files changed, 9 insertions, 13 deletions
diff --git a/libexec/tftpd/tftpd.c b/libexec/tftpd/tftpd.c
index 9b848b2816e..a9748d4cc57 100644
--- a/libexec/tftpd/tftpd.c
+++ b/libexec/tftpd/tftpd.c
@@ -39,7 +39,7 @@ char copyright[] =
#ifndef lint
/*static char sccsid[] = "from: @(#)tftpd.c 5.13 (Berkeley) 2/26/91";*/
-static char rcsid[] = "$Id: tftpd.c,v 1.1 1995/10/18 08:43:25 deraadt Exp $";
+static char rcsid[] = "$Id: tftpd.c,v 1.2 1996/08/11 23:22:00 deraadt Exp $";
#endif /* not lint */
/*
@@ -67,10 +67,6 @@ static char rcsid[] = "$Id: tftpd.c,v 1.1 1995/10/18 08:43:25 deraadt Exp $";
#include <string.h>
#include <stdlib.h>
-/* XXX svr4 defines UID_NOBODY and GID_NOBODY constants in <sys/param.h> */
-#define UID_NOBODY 32767
-#define GID_NOBODY 32766
-
#define TIMEOUT 5
extern int errno;
@@ -103,6 +99,7 @@ main(argc, argv)
char **argv;
{
register struct tftphdr *tp;
+ struct pwent *pw;
register int n = 0;
int on = 1;
int fd = 0;
@@ -135,20 +132,19 @@ main(argc, argv)
}
}
- if (secure && chroot(".")) {
- syslog(LOG_ERR, "chroot: %m\n");
+ pw = getpwnam("nobody");
+ if (!pw) {
+ syslog(LOG_ERR, "no nobody: %m\n");
exit(1);
}
- if (setgid(GID_NOBODY)) {
- syslog(LOG_ERR, "setgid: %m");
+ if (secure && chroot(".")) {
+ syslog(LOG_ERR, "chroot: %m\n");
exit(1);
}
- if (setuid(UID_NOBODY)) {
- syslog(LOG_ERR, "setuid: %m");
- exit(1);
- }
+ (void) setgid(pw->pw_gid);
+ (void) setuid(pw->pw_uid);
if (ioctl(fd, FIONBIO, &on) < 0) {
syslog(LOG_ERR, "ioctl(FIONBIO): %m\n");