diff options
author | 1997-05-30 23:35:50 +0000 | |
---|---|---|
committer | 1997-05-30 23:35:50 +0000 | |
commit | c74ee44fd58fe283f7adb76fd4f2b94720cca3ff (patch) | |
tree | 169341e4e58e5cdbcd658d4bdbac268df8b09bd0 | |
parent | sleep returns u_int (diff) | |
download | wireguard-openbsd-c74ee44fd58fe283f7adb76fd4f2b94720cca3ff.tar.xz wireguard-openbsd-c74ee44fd58fe283f7adb76fd4f2b94720cca3ff.zip |
Integrate changed from NetBSD being careful not to step on our important
stuff (like the -M flag and things.)
-rw-r--r-- | usr.bin/finger/extern.h | 18 | ||||
-rw-r--r-- | usr.bin/finger/finger.1 | 30 | ||||
-rw-r--r-- | usr.bin/finger/finger.c | 54 | ||||
-rw-r--r-- | usr.bin/finger/finger.h | 6 | ||||
-rw-r--r-- | usr.bin/finger/lprint.c | 53 | ||||
-rw-r--r-- | usr.bin/finger/net.c | 26 | ||||
-rw-r--r-- | usr.bin/finger/sprint.c | 78 | ||||
-rw-r--r-- | usr.bin/finger/util.c | 143 |
8 files changed, 243 insertions, 165 deletions
diff --git a/usr.bin/finger/extern.h b/usr.bin/finger/extern.h index d5897be0594..475f9d4f352 100644 --- a/usr.bin/finger/extern.h +++ b/usr.bin/finger/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.2 1996/06/26 05:33:14 deraadt Exp $ */ +/* $OpenBSD: extern.h,v 1.3 1997/05/30 23:35:50 kstailey Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -35,17 +35,31 @@ * @(#)extern.h 8.2 (Berkeley) 4/28/95 */ +extern time_t now; /* Current time. */ extern char tbuf[1024]; /* Temp buffer for anybody. */ extern int entries; /* Number of people. */ -extern DB *db; /* Database. */ +extern int lflag; +extern int oflag; +extern int pplan; +int demi_print __P((char *, int)); void enter_lastlog __P((PERSON *)); PERSON *enter_person __P((struct passwd *)); void enter_where __P((struct utmp *, PERSON *)); +void expandusername __P((char *, char *, char *, int)); PERSON *find_person __P((char *)); +int hash __P((char *)); void lflag_print __P((void)); +void loginlist __P((void)); +void lprint __P((PERSON *)); int match __P((struct passwd *, char *)); void netfinger __P((char *)); PERSON *palloc __P((void)); char *prphone __P((char *)); +int psort __P((const void *, const void *)); void sflag_print __P((void)); +int show_text __P((char *, char *, char *)); +PERSON **sort __P((void)); +void stimeprint __P((WHERE *)); +void userlist __P((int, char **)); +void vputc __P((int)); diff --git a/usr.bin/finger/finger.1 b/usr.bin/finger/finger.1 index 74c4f758b84..4e15f842484 100644 --- a/usr.bin/finger/finger.1 +++ b/usr.bin/finger/finger.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: finger.1,v 1.3 1996/12/08 13:29:19 downsj Exp $ +.\" $OpenBSD: finger.1,v 1.4 1997/05/30 23:35:50 kstailey Exp $ .\" .\" Copyright (c) 1989, 1990 The Regents of the University of California. .\" All rights reserved. @@ -41,7 +41,7 @@ .Nd user information lookup program .Sh SYNOPSIS .Nm finger -.Op Fl lmMsp +.Op Fl lmMspho .Op Ar user ... .Op Ar user@host ... .Sh DESCRIPTION @@ -55,18 +55,38 @@ 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 is printed. +If +.Fl o +is given, the office location and phone number is printed instead +(the default). .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 +Login time is displayed as the dayname if less than six 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 diff --git a/usr.bin/finger/finger.c b/usr.bin/finger/finger.c index 0cdaf6a1f42..1c42b65938b 100644 --- a/usr.bin/finger/finger.c +++ b/usr.bin/finger/finger.c @@ -1,4 +1,4 @@ -/* $OpenBSD: finger.c,v 1.6 1997/01/17 07:12:31 millert Exp $ */ +/* $OpenBSD: finger.c,v 1.7 1997/05/30 23:35:51 kstailey Exp $ */ /* * Copyright (c) 1989 The Regents of the University of California. @@ -37,7 +37,13 @@ */ /* - * Mail status reporting added 931007 by Luke Mewburn, <zak@rmit.edu.au>. + * Luke Mewburn <lukem@netbsd.org> added the following on 961121: + * - 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 @@ -48,7 +54,7 @@ char copyright[] = #ifndef lint /*static char sccsid[] = "from: @(#)finger.c 5.22 (Berkeley) 6/29/90";*/ -static char rcsid[] = "$OpenBSD: finger.c,v 1.6 1997/01/17 07:12:31 millert Exp $"; +static char rcsid[] = "$OpenBSD: finger.c,v 1.7 1997/05/30 23:35:51 kstailey Exp $"; #endif /* not lint */ /* @@ -59,24 +65,25 @@ static char rcsid[] = "$OpenBSD: finger.c,v 1.6 1997/01/17 07:12:31 millert Exp * * 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> #include <sys/file.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> +#include <time.h> #include "finger.h" +#include "extern.h" time_t now; -int lflag, sflag, mflag, pplan, Mflag; +int entries, lflag, sflag, mflag, oflag, pplan, Mflag; char tbuf[1024]; -int loginlist __P((void)); -void userlist __P((int, char **)); - int main(argc, argv) int argc; @@ -85,9 +92,10 @@ main(argc, argv) extern int optind; int ch; char domain[256]; - time_t time(); - while ((ch = getopt(argc, argv, "lmMps")) != -1) + oflag = 1; /* default to old "office" behavior */ + + while ((ch = getopt(argc, argv, "lmMpsho")) != -1) switch(ch) { case 'l': lflag = 1; /* long format */ @@ -104,10 +112,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 [-lmMps] [login ...]\n"); + "usage: finger [-lmMpsho] [login ...]\n"); exit(1); } argc -= optind; @@ -149,10 +163,10 @@ main(argc, argv) exit(0); } -int +void loginlist() { - register PERSON *pn; + PERSON *pn; struct passwd *pw; struct utmp user; char name[UT_NAMESIZE + 1]; @@ -161,7 +175,7 @@ loginlist() (void)fprintf(stderr, "finger: can't read %s.\n", _PATH_UTMP); exit(2); } - name[UT_NAMESIZE] = NULL; + name[UT_NAMESIZE] = '\0'; while (fread((char *)&user, sizeof(user), 1, stdin) == 1) { if (!user.ut_name[0]) continue; @@ -179,10 +193,10 @@ loginlist() void userlist(argc, argv) - register argc; - register char **argv; + int argc; + char **argv; { - register i; + register int i; register PERSON *pn; PERSON *nethead, **nettail; struct utmp user; @@ -221,7 +235,7 @@ userlist(argc, argv) enter_person(pw); used[i] = 1; } - } else while (pw = getpwent()) + } else while ((pw = getpwent()) != NULL) for (i = 0; i < argc; i++) if (used[i] >= 0 && (!strcasecmp(pw->pw_name, argv[i]) || diff --git a/usr.bin/finger/finger.h b/usr.bin/finger/finger.h index 3e56988a301..2a39201be9b 100644 --- a/usr.bin/finger/finger.h +++ b/usr.bin/finger/finger.h @@ -1,4 +1,4 @@ -/* * $OpenBSD: finger.h,v 1.2 1996/06/26 05:33:16 deraadt Exp $*/ +/* * $OpenBSD: finger.h,v 1.3 1997/05/30 23:35:51 kstailey Exp $*/ /* * Copyright (c) 1989 The Regents of the University of California. * All rights reserved. @@ -82,9 +82,5 @@ typedef struct where { PERSON *htab[HSIZE]; /* the buckets */ PERSON *phead, *ptail; /* the linked list of all people */ -int entries; /* number of people */ - PERSON *enter_person(), *find_person(), *palloc(); WHERE *walloc(); - -extern char tbuf[1024]; /* temp buffer for anybody */ diff --git a/usr.bin/finger/lprint.c b/usr.bin/finger/lprint.c index 22c37176acb..830223a4db2 100644 --- a/usr.bin/finger/lprint.c +++ b/usr.bin/finger/lprint.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lprint.c,v 1.3 1996/08/27 22:38:23 deraadt Exp $ */ +/* $OpenBSD: lprint.c,v 1.4 1997/05/30 23:35:52 kstailey Exp $ */ /* * Copyright (c) 1989 The Regents of the University of California. @@ -38,7 +38,7 @@ #ifndef lint /*static char sccsid[] = "from: @(#)lprint.c 5.13 (Berkeley) 10/31/90";*/ -static char rcsid[] = "$OpenBSD: lprint.c,v 1.3 1996/08/27 22:38:23 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: lprint.c,v 1.4 1997/05/30 23:35:52 kstailey Exp $"; #endif /* not lint */ #include <sys/types.h> @@ -48,20 +48,22 @@ static char rcsid[] = "$OpenBSD: lprint.c,v 1.3 1996/08/27 22:38:23 deraadt Exp #include <tzfile.h> #include <stdio.h> #include <string.h> +#include <time.h> #include <ctype.h> #include <paths.h> #include <vis.h> #include "finger.h" +#include "extern.h" #define LINE_LEN 80 #define TAB_LEN 8 /* 8 spaces between tabs */ #define _PATH_PLAN ".plan" #define _PATH_PROJECT ".project" +void lflag_print() { - extern int pplan; - register PERSON *pn; + PERSON *pn; for (pn = phead;;) { lprint(pn); @@ -76,18 +78,18 @@ lflag_print() } } +void lprint(pn) - register PERSON *pn; + PERSON *pn; { - extern time_t now; - register struct tm *delta; - register WHERE *w; - register int cpr, len, maxlen; + struct tm *delta; + WHERE *w; + int cpr, len, maxlen; struct tm *tp; int oddfield; - time_t time(); - char *t, *tzn, *prphone(); + char *t, *tzn; + cpr = 0; /* * long format -- * login name @@ -95,6 +97,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); @@ -110,22 +113,25 @@ lprint(pn) if (pn->office && pn->officephone && strlen(pn->office) + strlen(pn->officephone) + sizeof(OFFICE_TAG) + 2 <= 5 * TAB_LEN) { - (void)sprintf(tbuf, "%s: %s, %s", OFFICE_TAG, pn->office, + (void)snprintf(tbuf, sizeof(tbuf), + "%s: %s, %s", OFFICE_TAG, pn->office, prphone(pn->officephone)); oddfield = demi_print(tbuf, oddfield); } else { if (pn->office) { - (void)sprintf(tbuf, "%s: %s", OFFICE_TAG, pn->office); + (void)snprintf(tbuf, sizeof(tbuf), + "%s: %s", OFFICE_TAG, pn->office); oddfield = demi_print(tbuf, oddfield); } if (pn->officephone) { - (void)sprintf(tbuf, "%s: %s", OFFICE_PHONE_TAG, + (void)snprintf(tbuf, sizeof(tbuf), + "%s: %s", OFFICE_PHONE_TAG, prphone(pn->officephone)); oddfield = demi_print(tbuf, oddfield); } } if (pn->homephone) { - (void)sprintf(tbuf, "%s: %s", "Home Phone", + (void)snprintf(tbuf, sizeof(tbuf), "%s: %s", "Home Phone", prphone(pn->homephone)); oddfield = demi_print(tbuf, oddfield); } @@ -133,7 +139,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 +228,7 @@ lprint(pn) } } +int demi_print(str, oddfield) char *str; int oddfield; @@ -260,13 +268,15 @@ demi_print(str, oddfield) return(oddfield); } +int show_text(directory, file_name, header) char *directory, *file_name, *header; { - register int ch, lastc; - register FILE *fp; + int ch, lastc; + FILE *fp; - (void)sprintf(tbuf, "%s/%s", directory, file_name); + lastc = 0; + (void)snprintf(tbuf, sizeof(tbuf), "%s/%s", directory, file_name); if ((fp = fopen(tbuf, "r")) == NULL) return(0); (void)printf("%s\n", header); @@ -278,10 +288,11 @@ show_text(directory, file_name, header) return(1); } +void vputc(ch) - register int ch; + int ch; { - char visout[4], *s2; + char visout[5], *s2; ch = toascii(ch); vis(visout, ch, VIS_SAFE|VIS_NOSLASH, 0); diff --git a/usr.bin/finger/net.c b/usr.bin/finger/net.c index 8d206a8a0d7..ea01e774ca8 100644 --- a/usr.bin/finger/net.c +++ b/usr.bin/finger/net.c @@ -1,4 +1,4 @@ -/* $OpenBSD: net.c,v 1.4 1997/04/23 19:17:29 millert Exp $ */ +/* $OpenBSD: net.c,v 1.5 1997/05/30 23:35:52 kstailey Exp $ */ /* * Copyright (c) 1989 The Regents of the University of California. @@ -38,7 +38,7 @@ #ifndef lint /*static char sccsid[] = "from: @(#)net.c 5.5 (Berkeley) 6/1/90";*/ -static char rcsid[] = "$OpenBSD: net.c,v 1.4 1997/04/23 19:17:29 millert Exp $"; +static char rcsid[] = "$OpenBSD: net.c,v 1.5 1997/05/30 23:35:52 kstailey Exp $"; #endif /* not lint */ #include <sys/types.h> @@ -49,24 +49,26 @@ static char rcsid[] = "$OpenBSD: net.c,v 1.4 1997/04/23 19:17:29 millert Exp $"; #include <stdio.h> #include <string.h> #include <ctype.h> +#include <unistd.h> +#include "finger.h" +#include "extern.h" +void netfinger(name) char *name; { - extern int lflag; - register FILE *fp; - register int c, lastc; - struct hostent *hp, def; + FILE *fp; + int c, lastc; + struct hostent *hp; struct servent *sp; struct sockaddr_in sin; int s; - char *alist[1], *host; + char *host; + lastc = 0; if (!(host = strrchr(name, '@'))) return; - *host++ = NULL; - if (*host == NULL) - host = "localhost"; + *host++ = '\0'; if (inet_aton(host, &sin.sin_addr) == 0) { hp = gethostbyname(host); if (hp == 0) { @@ -115,8 +117,8 @@ netfinger(name) * Otherwise, all high bits are stripped; if it isn't printable and * it isn't a space, we can simply set the 7th bit. Every ASCII * character with bit 7 set is printable. - */ - if (fp = fdopen(s, "r")) + */ + if ((fp = fdopen(s, "r")) != NULL) while ((c = getc(fp)) != EOF) { c &= 0x7f; if (c == '\r') { diff --git a/usr.bin/finger/sprint.c b/usr.bin/finger/sprint.c index fea9df9a622..f7300cf55dc 100644 --- a/usr.bin/finger/sprint.c +++ b/usr.bin/finger/sprint.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sprint.c,v 1.2 1996/06/26 05:33:18 deraadt Exp $ */ +/* $OpenBSD: sprint.c,v 1.3 1997/05/30 23:35:52 kstailey Exp $ */ /* * Copyright (c) 1989 The Regents of the University of California. @@ -38,27 +38,25 @@ #ifndef lint /*static char sccsid[] = "from: @(#)sprint.c 5.8 (Berkeley) 12/4/90";*/ -static char rcsid[] = "$OpenBSD: sprint.c,v 1.2 1996/06/26 05:33:18 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: sprint.c,v 1.3 1997/05/30 23:35:52 kstailey Exp $"; #endif /* not lint */ #include <sys/types.h> #include <sys/time.h> #include <tzfile.h> #include <stdio.h> +#include <stdlib.h> #include "finger.h" +#include "extern.h" -extern int entries; - +void sflag_print() { - extern time_t now; - register PERSON *pn; - register WHERE *w; - register int cnt; - register char *p; - PERSON **list, **sort(); - time_t time(); - char *ctime(), *prphone(); + PERSON *pn; + WHERE *w; + int cnt; + char *p; + PERSON **list; list = sort(); /* @@ -69,14 +67,20 @@ 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 < 6 days, + * show day name instead of month & day. + * if -h given + * remote host + * else if -o given (overriding -h) (default) + * office location + * office phone */ #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 (cnt = 0; cnt < entries; ++cnt) { pn = list[cnt]; for (w = pn->whead; w != NULL; w = w->next) { @@ -101,18 +105,26 @@ 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); + (void)printf(" %.4s ", p + 20); else (void)printf(" %.5s", p + 11); -office: 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)); +office: + putchar(' '); + 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'); } } @@ -121,10 +133,8 @@ office: if (pn->office) PERSON ** sort() { - register PERSON *pn, **lp; + PERSON *pn, **lp; PERSON **list; - int psort(); - char *malloc(); if (!(list = (PERSON **)malloc((u_int)(entries * sizeof(PERSON *))))) { (void)fprintf(stderr, "finger: out of space.\n"); @@ -136,16 +146,18 @@ sort() return(list); } +int psort(p, t) - PERSON **p, **t; + const void *p, *t; { - return(strcmp((*p)->name, (*t)->name)); + return(strcmp((*(PERSON **)p)->name, (*(PERSON **)t)->name)); } +void stimeprint(w) WHERE *w; { - register struct tm *delta; + struct tm *delta; delta = gmtime(&w->idletime); if (!delta->tm_yday) diff --git a/usr.bin/finger/util.c b/usr.bin/finger/util.c index 5eea1a3368e..422c5313f1a 100644 --- a/usr.bin/finger/util.c +++ b/usr.bin/finger/util.c @@ -1,8 +1,9 @@ -/* $OpenBSD: util.c,v 1.4 1996/08/30 11:39:36 deraadt Exp $ */ +/* $OpenBSD: util.c,v 1.5 1997/05/30 23:35:53 kstailey Exp $ */ /* * Copyright (c) 1989 The Regents of the University of California. * All rights reserved. + * Portions Copyright (c) 1983, 1995, 1996 Eric P. Allman (woof!) * * This code is derived from software contributed to Berkeley by * Tony Nardo of the Johns Hopkins University/Applied Physics Lab. @@ -38,9 +39,11 @@ #ifndef lint /*static char sccsid[] = "from: @(#)util.c 5.14 (Berkeley) 1/17/91";*/ -static char rcsid[] = "$OpenBSD: util.c,v 1.4 1996/08/30 11:39:36 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: util.c,v 1.5 1997/05/30 23:35:53 kstailey Exp $"; #endif /* not lint */ +#include <sys/types.h> +#include <sys/uio.h> #include <sys/param.h> #include <sys/stat.h> #include <sys/file.h> @@ -50,16 +53,17 @@ static char rcsid[] = "$OpenBSD: util.c,v 1.4 1996/08/30 11:39:36 deraadt Exp $" #include <string.h> #include <paths.h> #include <errno.h> +#include <unistd.h> #include "finger.h" +#include "extern.h" +void find_idle_and_ttywrite(w) - register WHERE *w; + WHERE *w; { - extern time_t now; - extern int errno; struct stat sb; - (void)sprintf(tbuf, "%s%s", _PATH_DEV, w->tty); + (void)snprintf(tbuf, sizeof(tbuf), "%s%s", _PATH_DEV, w->tty); if (stat(tbuf, &sb) < 0) { /* Don't bitch about it, just handle it... */ w->idletime = 0; @@ -73,16 +77,14 @@ find_idle_and_ttywrite(w) w->writable = ((sb.st_mode & TALKABLE) == TALKABLE); } +void userinfo(pn, pw) - register PERSON *pn; - register struct passwd *pw; + PERSON *pn; + struct passwd *pw; { - extern time_t now; - register char *p, *t; + char *p; + char *bp, name[1024]; struct stat sb; - extern int errno; - char *mbp, *bp, *name; - int len; pn->realname = pn->office = pn->officephone = pn->homephone = NULL; @@ -91,32 +93,12 @@ userinfo(pn, pw) pn->dir = strdup(pw->pw_dir); pn->shell = strdup(pw->pw_shell); - /* why do we skip asterisks!?!? */ - mbp = bp = (char *)malloc(strlen(pw->pw_gecos)+1); - strcpy(bp, pw->pw_gecos); - if (*bp == '*') - ++bp; + (void)strncpy(bp = tbuf, pw->pw_gecos, sizeof(tbuf)); /* ampersands get replaced by the login name */ - if (!(p = strsep(&bp, ","))) { - free(mbp); + if (!(p = strsep(&bp, ","))) return; - } - for (len = 0, t = p; *p; ++p) { - len++; - if (*p == '&') - len += strlen(pw->pw_name); - } - name = (char *)malloc(len + 1); - for (p = t, t = name; *t = *p; ++p) - if (*t == '&') { - (void)strcpy(t, pw->pw_name); - if (islower(*t)) - *t = toupper(*t); - while (*++t); - } else - ++t; - *t = '\0'; + expandusername(p, pw->pw_name, name, sizeof(name)); pn->realname = strdup(name); pn->office = ((p = strsep(&bp, ",")) && *p) ? strdup(p) : NULL; @@ -124,56 +106,81 @@ userinfo(pn, pw) strdup(p) : NULL; pn->homephone = ((p = strsep(&bp, ",")) && *p) ? strdup(p) : NULL; - (void)sprintf(tbuf, "%s/%s", _PATH_MAILSPOOL, pw->pw_name); + (void)snprintf(tbuf, sizeof(tbuf), "%s/%s", _PATH_MAILSPOOL, + 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)); - free(name); - free(mbp); return; } } else if (sb.st_size != 0) { pn->mailrecv = sb.st_mtime; pn->mailread = sb.st_atime; } - free(name); - free(mbp); } +int match(pw, user) struct passwd *pw; char *user; { - register char *p, *t; + char *p, *t; char name[1024]; - /* why do we skip asterisks!?!? */ - (void)strcpy(p = tbuf, pw->pw_gecos); - if (*p == '*') - ++p; + (void)strncpy(p = tbuf, pw->pw_gecos, sizeof(tbuf)); /* ampersands get replaced by the login name */ if (!(p = strtok(p, ","))) return(0); - for (t = name; *t = *p; ++p) - if (*t == '&') { - (void)strcpy(t, pw->pw_name); - while (*++t); - } - else - ++t; - for (t = name; p = strtok(t, "\t "); t = (char *)NULL) + expandusername(p, pw->pw_name, name, sizeof(name)); + for (t = name; (p = strtok(t, "\t ")) != NULL; t = (char *)NULL) if (!strcasecmp(p, user)) return(1); return(0); } +/* inspired by usr.sbin/sendmail/util.c::buildfname */ +void +expandusername(gecos, login, buf, buflen) + char *gecos; + char *login; + char *buf; + int buflen; +{ + char *p, *bp; + + /* why do we skip asterisks!?!? */ + if (*gecos == '*') + gecos++; + bp = buf; + + /* copy gecos, interpolating & to be full name */ + for (p = gecos; *p != '\0'; p++) { + if (bp >= &buf[buflen - 1]) { + /* buffer overflow - just use login name */ + snprintf(buf, buflen, "%s", login); + buf[buflen - 1] = '\0'; + return; + } + if (*p == '&') { + /* interpolate full name */ + snprintf(bp, buflen - (bp - buf), "%s", login); + *bp = toupper(*bp); + bp += strlen(bp); + } + else + *bp++ = *p; + } + *bp = '\0'; +} + +void enter_lastlog(pn) - register PERSON *pn; + PERSON *pn; { - register WHERE *w; + WHERE *w; static int opened, fd; struct lastlog ll; char doit = 0; @@ -188,7 +195,7 @@ enter_lastlog(pn) (long)pn->uid * sizeof(ll) || read(fd, (char *)&ll, sizeof(ll)) != sizeof(ll)) { /* as if never logged in */ - ll.ll_line[0] = ll.ll_host[0] = NULL; + ll.ll_line[0] = ll.ll_host[0] = '\0'; ll.ll_time = 0; } if ((w = pn->whead) == NULL) @@ -219,11 +226,12 @@ enter_lastlog(pn) } } +void enter_where(ut, pn) struct utmp *ut; PERSON *pn; { - register WHERE *w = walloc(pn); + WHERE *w = walloc(pn); w->info = LOGGEDIN; bcopy(ut->ut_line, w->tty, UT_LINESIZE); @@ -236,9 +244,9 @@ enter_where(ut, pn) PERSON * enter_person(pw) - register struct passwd *pw; + struct passwd *pw; { - register PERSON *pn, **pp; + PERSON *pn, **pp; for (pp = htab + hash(pw->pw_name); *pp != NULL && strcmp((*pp)->name, pw->pw_name) != 0; @@ -266,7 +274,7 @@ PERSON * find_person(name) char *name; { - register PERSON *pn; + PERSON *pn; /* name may be only UT_NAMESIZE long and not terminated */ for (pn = htab[hash(name)]; @@ -276,15 +284,16 @@ find_person(name) return(pn); } +int hash(name) - register char *name; + char *name; { - register int h, i; + int h, i; h = 0; /* name may be only UT_NAMESIZE long and not terminated */ for (i = UT_NAMESIZE; --i >= 0 && *name;) - h = ((h << 2 | h >> HBITS - 2) ^ *name++) & HMASK; + h = ((h << 2 | h >> (HBITS - 2)) ^ *name++) & HMASK; return(h); } @@ -302,9 +311,9 @@ palloc() WHERE * walloc(pn) - register PERSON *pn; + PERSON *pn; { - register WHERE *w; + WHERE *w; if ((w = (WHERE *)malloc((u_int) sizeof(WHERE))) == NULL) { (void)fprintf(stderr, "finger: out of space.\n"); @@ -324,7 +333,7 @@ char * prphone(num) char *num; { - register char *p; + char *p; int len; static char pbuf[15]; |