From 0830bd135eae1af8fbc5232bd6028e04bec7741d Mon Sep 17 00:00:00 2001 From: Jonathan Mini Date: Tue, 2 Jul 2002 08:00:20 +0000 Subject: [PATCH] Add -g option, which restricts printing of the gecos fields to just the user's real name. PR: bin/39462 Submitted by: Mike Makonnen Obtained from: NetBSD MFC after: 1 week --- usr.bin/finger/extern.h | 1 + usr.bin/finger/finger.1 | 9 ++++++++- usr.bin/finger/finger.c | 7 +++++-- usr.bin/finger/lprint.c | 3 +++ usr.bin/finger/sprint.c | 8 ++++++-- 5 files changed, 23 insertions(+), 5 deletions(-) diff --git a/usr.bin/finger/extern.h b/usr.bin/finger/extern.h index 89219c68528a..8054ff404b96 100644 --- a/usr.bin/finger/extern.h +++ b/usr.bin/finger/extern.h @@ -38,6 +38,7 @@ extern char tbuf[1024]; /* Temp buffer for anybody. */ extern int entries; /* Number of people. */ extern DB *db; /* Database. */ extern int d_first; +extern int gflag; void enter_lastlog(PERSON *); PERSON *enter_person(struct passwd *); diff --git a/usr.bin/finger/finger.1 b/usr.bin/finger/finger.1 index ff7574de2ddc..432d762bc169 100644 --- a/usr.bin/finger/finger.1 +++ b/usr.bin/finger/finger.1 @@ -40,7 +40,7 @@ .Nd user information lookup program .Sh SYNOPSIS .Nm -.Op Fl lmpshoT +.Op Fl glmpshoT .Op Ar user ...\& .Op Ar user@host ...\& .Sh DESCRIPTION @@ -87,6 +87,13 @@ When used in conjunction with the option, the office location and office phone information is displayed instead of the name of the remote host. .Pp +.It Fl g +This option restricts the gecos output to only the users' real +name. It also has the side-effect of restricting the output +of the remote host when used in conjunction with the +.Fl h +option. +.Pp .It Fl l Produce a multi-line format displaying all of the information described for the diff --git a/usr.bin/finger/finger.c b/usr.bin/finger/finger.c index d5d38c35d47a..0e6c176dc23e 100644 --- a/usr.bin/finger/finger.c +++ b/usr.bin/finger/finger.c @@ -89,7 +89,7 @@ __FBSDID("$FreeBSD$"); DB *db; time_t now; -int entries, lflag, mflag, pplan, sflag, oflag, Tflag; +int entries, gflag, lflag, mflag, pplan, sflag, oflag, Tflag; int d_first = -1; char tbuf[1024]; @@ -107,8 +107,11 @@ option(argc, argv) optind = 1; /* reset getopt */ - while ((ch = getopt(argc, argv, "lmpshoT")) != -1) + while ((ch = getopt(argc, argv, "glmpshoT")) != -1) switch(ch) { + case 'g': + gflag = 1; + break; case 'l': lflag = 1; /* long format */ break; diff --git a/usr.bin/finger/lprint.c b/usr.bin/finger/lprint.c index f55b6d4037c3..20b03060f3e2 100644 --- a/usr.bin/finger/lprint.c +++ b/usr.bin/finger/lprint.c @@ -127,6 +127,8 @@ lprint(pn) pn->name, pn->realname, pn->dir); (void)printf("\tShell: %-s\n", *pn->shell ? pn->shell : _PATH_BSHELL); + if (gflag) + goto no_gecos; /* * try and print office, office phone, and home phone on one line; * if that fails, do line filling so it looks nice. @@ -160,6 +162,7 @@ lprint(pn) if (oddfield) putchar('\n'); +no_gecos: /* * long format con't: * if logged in diff --git a/usr.bin/finger/sprint.c b/usr.bin/finger/sprint.c index be7006ede845..b209b5622b31 100644 --- a/usr.bin/finger/sprint.c +++ b/usr.bin/finger/sprint.c @@ -89,7 +89,7 @@ sflag_print() #define MAXREALNAME 20 #define MAXHOSTNAME 17 /* in reality, hosts are never longer than 16 */ (void)printf("%-*s %-*s%s %s\n", UT_NAMESIZE, "Login", MAXREALNAME, - "Name", " TTY Idle Login Time", + "Name", " TTY Idle Login Time ", (gflag) ? "" : oflag ? "Office Phone" : "Where"); for (sflag = R_FIRST;; sflag = R_NEXT) { @@ -143,7 +143,10 @@ sflag_print() (void)strftime(p, sizeof(p), "%R", lc); } (void)printf(" %-5.5s", p); -office: if (oflag) { +office: + if (gflag) + goto no_gecos; + if (oflag) { if (pn->office) (void)printf(" %-7.7s", pn->office); else if (pn->officephone) @@ -153,6 +156,7 @@ office: if (oflag) { prphone(pn->officephone)); } else (void)printf(" %.*s", MAXHOSTNAME, w->host); +no_gecos: putchar('\n'); } }