Module Name:    src
Committed By:   christos
Date:           Sun Apr  7 19:17:11 UTC 2013

Modified Files:
        src/external/bsd/tcpdump/dist: tcpdump.c

Log Message:
- the initgroups function needs to be able to do name to gid translations,
  so do it before the chroot, otherwise we lose /etc/nsswitch.conf and
  /etc/group
- run res_init() so that we prime and initialize the resolver before the
  chroot, since our chroot lacks /etc/{{nsswitch,resolve}.conf,hosts}
  this is not portable behavior, but it is a lot better than populating
  the chroot with crap.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/external/bsd/tcpdump/dist/tcpdump.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/bsd/tcpdump/dist/tcpdump.c
diff -u src/external/bsd/tcpdump/dist/tcpdump.c:1.4 src/external/bsd/tcpdump/dist/tcpdump.c:1.5
--- src/external/bsd/tcpdump/dist/tcpdump.c:1.4	Sat Apr  6 15:33:09 2013
+++ src/external/bsd/tcpdump/dist/tcpdump.c	Sun Apr  7 15:17:11 2013
@@ -34,7 +34,7 @@ The Regents of the University of Califor
 static const char rcsid[] _U_ =
     "@(#) Header: /tcpdump/master/tcpdump/tcpdump.c,v 1.283 2008-09-25 21:45:50 guy Exp  (LBL)";
 #else
-__RCSID("$NetBSD: tcpdump.c,v 1.4 2013/04/06 19:33:09 christos Exp $");
+__RCSID("$NetBSD: tcpdump.c,v 1.5 2013/04/07 19:17:11 christos Exp $");
 #endif
 #endif
 
@@ -71,6 +71,7 @@ extern int SIZE_BUF;
 #include <stdlib.h>
 #include <string.h>
 #include <limits.h>
+#include <resolv.h>
 #ifndef WIN32
 #include <sys/wait.h>
 #include <sys/resource.h>
@@ -533,17 +534,25 @@ droproot(const char *username, const cha
 	
 	pw = getpwnam(username);
 	if (pw) {
+		if (initgroups(pw->pw_name, pw->pw_gid) != 0) {
+			fprintf(stderr, "tcpdump: Couldn't initgroups to "
+			    "'%.32s' gid=%lu: %s\n", pw->pw_name,
+			    (unsigned long)pw->pw_gid,
+			    pcap_strerror(errno));
+			exit(1);
+		}
 		if (chroot_dir) {
 			setprotoent(1);
+			res_init();
 			if (chroot(chroot_dir) != 0 || chdir ("/") != 0) {
 				fprintf(stderr, "tcpdump: Couldn't chroot/chdir to '%.64s': %s\n",
 				    chroot_dir, pcap_strerror(errno));
 				exit(1);
 			}
 		}
-		if (initgroups(pw->pw_name, pw->pw_gid) != 0 ||
-		    setgid(pw->pw_gid) != 0 || setuid(pw->pw_uid) != 0) {
-			fprintf(stderr, "tcpdump: Couldn't change to '%.32s' uid=%lu gid=%lu: %s\n",
+		if (setgid(pw->pw_gid) != 0 || setuid(pw->pw_uid) != 0) {
+			fprintf(stderr, "tcpdump: Couldn't change to "
+			    "'%.32s' uid=%lu gid=%lu: %s\n",
 			    username, 
 			    (unsigned long)pw->pw_uid,
 			    (unsigned long)pw->pw_gid,

Reply via email to