Use the same technique as ps(1) to avoid the need for setgid. (ie: use

/dev/null as the default kernel and /dev/mem filenames, but still allow
the usual overrides)
This commit is contained in:
Peter Wemm 1999-11-17 15:28:45 +00:00
parent 821079e9be
commit 6ff4ec180d
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=53279
2 changed files with 9 additions and 5 deletions

View File

@ -1,12 +1,13 @@
# @(#)Makefile 8.1 (Berkeley) 6/6/93
# $FreeBSD$
PROG= w
SRCS= fmt.c pr_time.c proc_compare.c w.c
MAN1= w.1 uptime.1
DPADD= ${LIBKVM}
LDADD= -lkvm
BINGRP= kmem
BINMODE=2555
#BINGRP= kmem
#BINMODE=2555
LINKS= ${BINDIR}/w ${BINDIR}/uptime
.PATH: ${.CURDIR}/../../bin/ps

View File

@ -134,7 +134,7 @@ main(argc, argv)
struct stat *stp;
FILE *ut;
u_long l;
int ch, i, nentries, nusers, wcmd, longidle;
int ch, i, nentries, nusers, wcmd, longidle, dropgid;
char *memf, *nlistf, *p, *x;
char buf[MAXHOSTNAMELEN], errbuf[256];
@ -149,7 +149,8 @@ main(argc, argv)
p = "dhiflM:N:nsuw";
}
memf = nlistf = NULL;
dropgid = 0;
memf = nlistf = _PATH_DEVNULL;
while ((ch = getopt(argc, argv, p)) != -1)
switch (ch) {
case 'd':
@ -164,9 +165,11 @@ main(argc, argv)
case 'M':
header = 0;
memf = optarg;
dropgid = 1;
break;
case 'N':
nlistf = optarg;
dropgid = 1;
break;
case 'n':
nflag = 1;
@ -190,7 +193,7 @@ main(argc, argv)
* Discard setgid privileges if not the running kernel so that bad
* guys can't print interesting stuff from kernel memory.
*/
if (nlistf != NULL || memf != NULL)
if (dropgid)
setgid(getgid());
if ((kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, errbuf)) == NULL)