summaryrefslogtreecommitdiff
path: root/usr.bin/who
diff options
context:
space:
mode:
authorSebastien Marie <semarie@cvs.openbsd.org>2015-10-07 16:11:41 +0000
committerSebastien Marie <semarie@cvs.openbsd.org>2015-10-07 16:11:41 +0000
commit1a205a833c0d3b4be3ec10cb3948cfdcda7b98f5 (patch)
treeaef452b08466f883c57089a11604cddba1c3bb4a /usr.bin/who
parent2026b6b6176035a073a9edcd5f5b5c34ad340e1e (diff)
enable tame(2) in who(1).
some refactor to grab ttyname(0) early and use it later. gradually drop tame requests when no more needed. "ioctl" is used for grab ttyname(0) "rpath" is for -T and -u flag, that used stat(2) to get terminal status initial patch from deraadt with help from guenther ok deraadt@
Diffstat (limited to 'usr.bin/who')
-rw-r--r--usr.bin/who/who.c30
1 files changed, 21 insertions, 9 deletions
diff --git a/usr.bin/who/who.c b/usr.bin/who/who.c
index 3506affc337..63dc95c83b4 100644
--- a/usr.bin/who/who.c
+++ b/usr.bin/who/who.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: who.c,v 1.20 2013/08/22 04:43:41 guenther Exp $ */
+/* $OpenBSD: who.c,v 1.21 2015/10/07 16:11:40 semarie Exp $ */
/* $NetBSD: who.c,v 1.4 1994/12/07 04:28:49 jtc Exp $ */
/*
@@ -62,16 +62,26 @@ int show_quick; /* quick, names only */
#define HOST_WIDTH 45
int hostwidth = HOST_WIDTH;
+char *mytty;
int
main(int argc, char *argv[])
{
struct utmp usr;
FILE *ufp;
+ char *t;
int c;
setlocale(LC_ALL, "");
+ if (tame("stdio getpw rpath ioctl", NULL) == -1)
+ err(1, "tame");
+
+ mytty = ttyname(0);
+ /* strip any directory component */
+ if ((t = strrchr(mytty, '/')))
+ mytty = t + 1;
+
only_current_term = show_term = show_idle = show_labels = 0;
show_quick = 0;
while ((c = getopt(argc, argv, "HmqTu")) != -1) {
@@ -179,21 +189,16 @@ who_am_i(FILE *ufp)
{
struct utmp usr;
struct passwd *pw;
- char *p;
- char *t;
/* search through the utmp and find an entry for this tty */
- if ((p = ttyname(0))) {
- /* strip any directory component */
- if ((t = strrchr(p, '/')))
- p = t + 1;
+ if (mytty) {
while (fread((char *)&usr, sizeof(usr), 1, ufp) == 1)
- if (*usr.ut_name && !strcmp(usr.ut_line, p)) {
+ if (*usr.ut_name && !strcmp(usr.ut_line, mytty)) {
output(&usr);
return;
}
/* well, at least we know what the tty is */
- (void)strncpy(usr.ut_line, p, UT_LINESIZE);
+ (void)strncpy(usr.ut_line, mytty, UT_LINESIZE);
} else
(void)strncpy(usr.ut_line, "tty??", UT_LINESIZE);
@@ -284,6 +289,13 @@ file(char *name)
err(1, "%s", name);
/* NOTREACHED */
}
+ if (show_term || show_idle) {
+ if (tame("stdio getpw rpath", NULL) == -1)
+ err(1, "tame");
+ } else {
+ if (tame("stdio getpw", NULL) == -1)
+ err(1, "tame");
+ }
return(ufp);
}