summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpst <pst@FreeBSD.org>1994-09-07 07:22:41 +0000
committerpst <pst@FreeBSD.org>1994-09-07 07:22:41 +0000
commit72c244e5533a91ef34a3fac2404611a46ee6874a (patch)
treeef10cc8b732e94b450f8199f8c72cfd130652b5a
parent62391009757751f11deb63fb9ed07fab5976c86c (diff)
downloadFreeBSD-src-72c244e5533a91ef34a3fac2404611a46ee6874a.zip
FreeBSD-src-72c244e5533a91ef34a3fac2404611a46ee6874a.tar.gz
Install Luke's enhancements for finger.
By default, behave like the old ugly 4.4bsd finger and print office information instead of remote login information. It's an easy one line fix to make it behave like most other vendor's fingers if we decide to change the default. Reviewed by: pst
-rw-r--r--usr.bin/finger/finger.137
-rw-r--r--usr.bin/finger/finger.c32
-rw-r--r--usr.bin/finger/finger.h2
-rw-r--r--usr.bin/finger/lprint.c21
-rw-r--r--usr.bin/finger/sprint.c28
-rw-r--r--usr.bin/finger/util.c21
6 files changed, 117 insertions, 24 deletions
diff --git a/usr.bin/finger/finger.1 b/usr.bin/finger/finger.1
index 069f9cd..306aa74 100644
--- a/usr.bin/finger/finger.1
+++ b/usr.bin/finger/finger.1
@@ -39,7 +39,7 @@
.Nd user information lookup program
.Sh SYNOPSIS
.Nm finger
-.Op Fl lmsp
+.Op Fl lmpsho
.Op Ar user ...
.Op Ar user@host ...
.Sh DESCRIPTION
@@ -53,24 +53,41 @@ Options are:
.Nm Finger
displays the user's login name, real name, terminal name and write
status (as a ``*'' before the terminal name if write permission is
-denied), idle time, login time, office location and office phone
-number.
+denied), idle time, login time, and either office location and office
+phone number, or the remote host. If
+.Fl h
+is given, the remote host is printed (the default.) If
+.Fl o
+is given, the office location and office phone number is printed
+instead.
.Pp
Idle time is in minutes if it is a single integer, hours and minutes
if a ``:'' is present, or days if a ``d'' is present.
-Login time is displayed as month, day, hours and minutes, unless
-more than six months ago, in which case the year is displayed rather
-than the hours and minutes.
+Login time is displayed as the dayname if less than 6 days, else month, day;
+hours and minutes, unless more than six months ago, in which case the year
+is displayed rather than the hours and minutes.
.Pp
Unknown devices as well as nonexistent idle and login times are
displayed as single asterisks.
.Pp
+.It Fl h
+When used in conjunction with the
+.Fl s
+option, the name of the remote host is displayed instead of the office
+location and office phone.
+.Pp
+.It Fl o
+When used in conjunction with the
+.Fl s
+option, the office location and office phone information is displayed
+instead of the name of the remote host.
+.Pp
.It Fl l
Produces a multi-line format displaying all of the information
described for the
.Fl s
option as well as the user's home directory, home phone number, login
-shell, and the contents of the files
+shell, mail status, and the contents of the files
.Dq Pa .forward ,
.Dq Pa .plan
and
@@ -85,6 +102,7 @@ Phone numbers specified as eleven digits are printed as ``+N-NNN-NNN-NNNN''.
Numbers specified as ten or seven digits are printed as the appropriate
subset of that string.
Numbers specified as five digits are printed as ``xN-NNNN''.
+Numbers specified as four digits are printed as ``xNNNN''.
.Pp
If write permission is denied to the device, the phrase ``(messages off)''
is appended to the line containing the device name.
@@ -93,6 +111,11 @@ One entry per user is displayed with the
option; if a user is logged on multiple times, terminal information
is repeated once per login.
.Pp
+Mail status is shown as ``No Mail.'' if there is no mail at all, ``Mail
+last read DDD MMM ## HH:MM YYYY (TZ)'' if the person has looked at their
+mailbox since new mail arriving, or ``New mail received ...'', ``Unread
+since ...'' if they have new mail.
+.Pp
.It Fl p
Prevents
the
diff --git a/usr.bin/finger/finger.c b/usr.bin/finger/finger.c
index 5a16765..aaef07b 100644
--- a/usr.bin/finger/finger.c
+++ b/usr.bin/finger/finger.c
@@ -34,6 +34,16 @@
* SUCH DAMAGE.
*/
+/*
+ * Luke Mewburn <lm@rmit.edu.au> added the following on 940622:
+ * - mail status ("No Mail", "Mail read:...", or "New Mail ...,
+ * Unread since ...".)
+ * - 4 digit phone extensions (3210 is printed as x3210.)
+ * - host/office toggling in short format with -h & -o.
+ * - short day names (`Tue' printed instead of `Jun 21' if the
+ * login time is < 6 days.
+ */
+
#ifndef lint
static char copyright[] =
"@(#) Copyright (c) 1989, 1993\n\
@@ -52,9 +62,10 @@ static char sccsid[] = "@(#)finger.c 8.2 (Berkeley) 9/30/93";
*
* There are currently two output formats; the short format is one line
* per user and displays login name, tty, login time, real name, idle time,
- * and office location/phone number. The long format gives the same
- * information (in a more legible format) as well as home directory, shell,
- * mail info, and .plan/.project files.
+ * and either remote host information (default) or office location/phone
+ * number, depending on if -h or -o is used respectively.
+ * The long format gives the same information (in a more legible format) as
+ * well as home directory, shell, mail info, and .plan/.project files.
*/
#include <sys/param.h>
@@ -71,7 +82,7 @@ static char sccsid[] = "@(#)finger.c 8.2 (Berkeley) 9/30/93";
DB *db;
time_t now;
-int entries, lflag, mflag, pplan, sflag;
+int entries, lflag, mflag, pplan, sflag, oflag;
char tbuf[1024];
static void loginlist __P((void));
@@ -83,7 +94,10 @@ main(argc, argv)
{
int ch;
- while ((ch = getopt(argc, argv, "lmps")) != EOF)
+ /* delete this for sun behavior */
+ oflag = 1; /* default to old behavior for now */
+
+ while ((ch = getopt(argc, argv, "lmpsho")) != EOF)
switch(ch) {
case 'l':
lflag = 1; /* long format */
@@ -97,10 +111,16 @@ main(argc, argv)
case 's':
sflag = 1; /* short format */
break;
+ case 'h':
+ oflag = 0; /* remote host info */
+ break;
+ case 'o':
+ oflag = 1; /* office info */
+ break;
case '?':
default:
(void)fprintf(stderr,
- "usage: finger [-lmps] [login ...]\n");
+ "usage: finger [-lmpsho] [login ...]\n");
exit(1);
}
argc -= optind;
diff --git a/usr.bin/finger/finger.h b/usr.bin/finger/finger.h
index 5104425..b8538fa 100644
--- a/usr.bin/finger/finger.h
+++ b/usr.bin/finger/finger.h
@@ -45,6 +45,8 @@ typedef struct person {
char *officephone; /* pointer to office phone no. */
char *realname; /* pointer to full name */
char *shell; /* user's shell */
+ time_t mailread; /* last time mail was read */
+ time_t mailrecv; /* last time mail was received */
struct where *whead, *wtail; /* list of where user is or has been */
} PERSON;
diff --git a/usr.bin/finger/lprint.c b/usr.bin/finger/lprint.c
index d079c24..51e0f96 100644
--- a/usr.bin/finger/lprint.c
+++ b/usr.bin/finger/lprint.c
@@ -113,6 +113,7 @@ lprint(pn)
* home directory
* shell
* office, office phone, home phone if available
+ * mail status
*/
(void)printf("Login: %-15s\t\t\tName: %s\nDirectory: %-25s",
pn->name, pn->realname, pn->dir);
@@ -152,7 +153,8 @@ lprint(pn)
putchar('\n');
/*
- * long format con't: * if logged in
+ * long format con't:
+ * if logged in
* terminal
* idle time
* if messages allowed
@@ -221,6 +223,23 @@ lprint(pn)
}
putchar('\n');
}
+ if (pn->mailrecv == -1)
+ printf("No Mail.\n");
+ else if (pn->mailrecv > pn->mailread) {
+ tp = localtime(&pn->mailrecv);
+ t = asctime(tp);
+ tzn = tp->tm_zone;
+ printf("New mail received %.16s %.4s (%s)\n", t, t + 20, tzn);
+ tp = localtime(&pn->mailread);
+ t = asctime(tp);
+ tzn = tp->tm_zone;
+ printf(" Unread since %.16s %.4s (%s)\n", t, t + 20, tzn);
+ } else {
+ tp = localtime(&pn->mailread);
+ t = asctime(tp);
+ tzn = tp->tm_zone;
+ printf("Mail last read %.16s %.4s (%s)\n", t, t + 20, tzn);
+ }
}
static int
diff --git a/usr.bin/finger/sprint.c b/usr.bin/finger/sprint.c
index 68deb76..a59fdd0 100644
--- a/usr.bin/finger/sprint.c
+++ b/usr.bin/finger/sprint.c
@@ -57,6 +57,7 @@ void
sflag_print()
{
extern time_t now;
+ extern int oflag;
register PERSON *pn;
register WHERE *w;
register int sflag, r;
@@ -71,14 +72,19 @@ sflag_print()
* if terminal writeable (add an '*' to the terminal name
* if not)
* if logged in show idle time and day logged in, else
- * show last login date and time. If > 6 moths,
- * show year instead of time.
- * office location
- * office phone
+ * show last login date and time.
+ * If > 6 months, show year instead of time.
+ * if (-o)
+ * office location
+ * office phone
+ * else
+ * remote host
*/
#define MAXREALNAME 20
- (void)printf("%-*s %-*s %s\n", UT_NAMESIZE, "Login", MAXREALNAME,
- "Name", "Tty Idle Login Time Office Office Phone");
+#define MAXHOSTNAME 20
+ (void)printf("%-*s %-*s %s %s\n", UT_NAMESIZE, "Login", MAXREALNAME,
+ "Name", "TTY Idle Login Time",
+ oflag ? " Office Office Phone" : " Where");
for (sflag = R_FIRST;; sflag = R_NEXT) {
r = (*db->seq)(db, &key, &data, sflag);
@@ -110,18 +116,24 @@ sflag_print()
} else
(void)printf(" * ");
p = ctime(&w->loginat);
- (void)printf("%.6s", p + 4);
+ if (now - w->loginat < SECSPERDAY * (DAYSPERWEEK - 1))
+ (void)printf("%.3s ", p);
+ else
+ (void)printf("%.6s", p + 4);
if (now - w->loginat >= SECSPERDAY * DAYSPERNYEAR / 2)
(void)printf(" %.4s", p + 20);
else
(void)printf(" %.5s", p + 11);
-office: if (pn->office)
+office: if (oflag) {
+ if (pn->office)
(void)printf(" %-10.10s", pn->office);
else if (pn->officephone)
(void)printf(" %-10.10s", " ");
if (pn->officephone)
(void)printf(" %-.15s",
prphone(pn->officephone));
+ } else
+ (void)printf(" %.*s", MAXHOSTNAME, w->host);
putchar('\n');
}
}
diff --git a/usr.bin/finger/util.c b/usr.bin/finger/util.c
index c27cf1b..459c3cf 100644
--- a/usr.bin/finger/util.c
+++ b/usr.bin/finger/util.c
@@ -51,6 +51,7 @@ static char sccsid[] = "@(#)util.c 8.1 (Berkeley) 6/6/93";
#include <stdlib.h>
#include <string.h>
#include <paths.h>
+#include <errno.h>
#include "finger.h"
static void find_idle_and_ttywrite __P((WHERE *));
@@ -276,14 +277,17 @@ prphone(num)
*p++ = *num++;
break;
case 5: /* x0-1234 */
+ case 4: /* x1234 */
*p++ = 'x';
*p++ = *num++;
break;
default:
return(num);
}
- *p++ = '-';
- *p++ = *num++;
+ if (len != 4) {
+ *p++ = '-';
+ *p++ = *num++;
+ }
*p++ = *num++;
*p++ = *num++;
*p++ = *num++;
@@ -317,6 +321,7 @@ userinfo(pn, pw)
{
register char *p, *t;
char *bp, name[1024];
+ struct stat sb;
pn->realname = pn->office = pn->officephone = pn->homephone = NULL;
@@ -349,6 +354,18 @@ userinfo(pn, pw)
strdup(p) : NULL;
pn->homephone = ((p = strsep(&bp, ",")) && *p) ?
strdup(p) : NULL;
+ (void)sprintf(tbuf,"%s/%s", _PATH_MAILDIR, pw->pw_name);
+ pn->mailrecv = -1; /* -1 == not_valid */
+ if (stat(tbuf, &sb) < 0) {
+ if (errno != ENOENT) {
+ (void)fprintf(stderr,
+ "finger: %s: %s\n", tbuf, strerror(errno));
+ return;
+ }
+ } else if (sb.st_size != 0) {
+ pn->mailrecv = sb.st_mtime;
+ pn->mailread = sb.st_atime;
+ }
}
#if __STDC__
OpenPOWER on IntegriCloud