summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrpaulo <rpaulo@NetBSD.org>2005-09-15 00:58:49 +0000
committerrpaulo <rpaulo@NetBSD.org>2005-09-15 00:58:49 +0000
commitcaaefabc1922ab415fd803dc0e26ea97475930c8 (patch)
tree4213167a993a196565e8408e88805f078b867231
parent2f1d097559e73766405c0a24106f7a9a2fb607d7 (diff)
Don't print a warning about stale utmp{,x} entries if security.curtain
sysctl is equal to 1. We can still detect stale utmp entries if that knob is off.
-rw-r--r--usr.bin/w/w.c32
1 files changed, 24 insertions, 8 deletions
diff --git a/usr.bin/w/w.c b/usr.bin/w/w.c
index 8e1a82688cb..ed88a0b72b6 100644
--- a/usr.bin/w/w.c
+++ b/usr.bin/w/w.c
@@ -1,4 +1,4 @@
-/* $NetBSD: w.c,v 1.70 2005/09/04 21:18:33 elad Exp $ */
+/* $NetBSD: w.c,v 1.71 2005/09/15 00:58:49 rpaulo Exp $ */
/*-
* Copyright (c) 1980, 1991, 1993, 1994
@@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 1991, 1993, 1994\n\
#if 0
static char sccsid[] = "@(#)w.c 8.6 (Berkeley) 6/30/94";
#else
-__RCSID("$NetBSD: w.c,v 1.70 2005/09/04 21:18:33 elad Exp $");
+__RCSID("$NetBSD: w.c,v 1.71 2005/09/15 00:58:49 rpaulo Exp $");
#endif
#endif /* not lint */
@@ -135,9 +135,10 @@ main(int argc, char **argv)
struct kinfo_proc2 *kp;
struct hostent *hp;
struct in_addr l;
- int ch, i, nentries, nusers, wcmd;
- char *memf, *nlistf, *p, *x;
+ int ch, i, nentries, nusers, wcmd, curtain, use_sysctl;
+ char *memf, *nlistf, *p, *x, *usrnp;
time_t then;
+ size_t len;
#ifdef SUPPORT_UTMP
struct utmp *ut;
#endif
@@ -190,12 +191,21 @@ main(int argc, char **argv)
argc -= optind;
argv += optind;
+ use_sysctl = (memf == NULL && nlistf == NULL);
+
if ((kd = kvm_openfiles(nlistf, memf, NULL,
memf == NULL ? KVM_NO_FILES : O_RDONLY, errbuf)) == NULL)
errx(1, "%s", errbuf);
(void)time(&now);
+ if (use_sysctl) {
+ len = sizeof(curtain);
+ if (sysctlbyname("security.curtain", &curtain, &len,
+ NULL, 0) == -1)
+ curtain = 0;
+ }
+
#ifdef SUPPORT_UTMPX
setutxent();
#endif
@@ -409,17 +419,23 @@ main(int argc, char **argv)
(void)snprintf(buf, sizeof(buf), "%s:%s", p, x);
p = buf;
}
+
if (ep->tp != NULL)
kp = ep->tp;
else if (ep->pp != NULL)
kp = ep->pp;
else {
- warnx("Stale utmp%s entry: %s %s %s",
- ep->type, ep->name, ep->line, ep->host);
- continue;
+ if (curtain)
+ kp = NULL;
+ else {
+ warnx("Stale utmp%s entry: %s %s %s",
+ ep->type, ep->name, ep->line, ep->host);
+ continue;
+ }
}
+ usrnp = (kp == NULL) ? ep->name : kp->p_login;
(void)printf("%-*s %-7.7s %-*.*s ",
- maxname, kp->p_login, ep->line,
+ maxname, usrnp, ep->line,
maxhost, maxhost, *p ? p : "-");
then = (time_t)ep->tv.tv_sec;
pr_attime(&then, &now);