diff options
author | peter <peter@FreeBSD.org> | 1997-03-11 13:08:12 +0000 |
---|---|---|
committer | peter <peter@FreeBSD.org> | 1997-03-11 13:08:12 +0000 |
commit | 297505f8fa9ec32b558f82504c27404854c3e313 (patch) | |
tree | 5902089a1ad90a715cb57bccc9fcdee6a33122e7 /usr.bin/finger | |
parent | cc62aa07770cbb99fb48c7068048a9fbd9326313 (diff) | |
download | FreeBSD-src-297505f8fa9ec32b558f82504c27404854c3e313.zip FreeBSD-src-297505f8fa9ec32b558f82504c27404854c3e313.tar.gz |
Import some parts of CSRG 4.4BSD-Lite2 usr.bin sources to fix tree build.
Diffstat (limited to 'usr.bin/finger')
-rw-r--r-- | usr.bin/finger/extern.h | 3 | ||||
-rw-r--r-- | usr.bin/finger/finger.1 | 11 | ||||
-rw-r--r-- | usr.bin/finger/finger.c | 41 | ||||
-rw-r--r-- | usr.bin/finger/lprint.c | 9 | ||||
-rw-r--r-- | usr.bin/finger/net.c | 5 | ||||
-rw-r--r-- | usr.bin/finger/sprint.c | 9 | ||||
-rw-r--r-- | usr.bin/finger/util.c | 64 |
7 files changed, 70 insertions, 72 deletions
diff --git a/usr.bin/finger/extern.h b/usr.bin/finger/extern.h index 2b675f1..b213fe4 100644 --- a/usr.bin/finger/extern.h +++ b/usr.bin/finger/extern.h @@ -30,7 +30,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#)extern.h 8.1 (Berkeley) 6/6/93 + * @(#)extern.h 8.2 (Berkeley) 4/28/95 */ extern char tbuf[1024]; /* Temp buffer for anybody. */ @@ -40,7 +40,6 @@ extern DB *db; /* Database. */ void enter_lastlog __P((PERSON *)); PERSON *enter_person __P((struct passwd *)); void enter_where __P((struct utmp *, PERSON *)); -void err __P((const char *, ...)); PERSON *find_person __P((char *)); void lflag_print __P((void)); int match __P((struct passwd *, char *)); diff --git a/usr.bin/finger/finger.1 b/usr.bin/finger/finger.1 index 069f9cd..045084a 100644 --- a/usr.bin/finger/finger.1 +++ b/usr.bin/finger/finger.1 @@ -1,4 +1,4 @@ -.\" Copyright (c) 1989, 1990, 1993 +.\" Copyright (c) 1989, 1990, 1993, 1994 .\" The Regents of the University of California. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without @@ -29,9 +29,9 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" @(#)finger.1 8.2 (Berkeley) 2/16/94 +.\" @(#)finger.1 8.3 (Berkeley) 5/5/94 .\" -.Dd February 16, 1994 +.Dd May 5, 1994 .Dt FINGER 1 .Os BSD 4 .Sh NAME @@ -150,6 +150,11 @@ style. The .Fl l option is the only option that may be passed to a remote machine. +.Sh FILES +.Bl -tag -width /var/log/lastlog -compact +.It Pa /var/log/lastlog +last login data base +.El .Sh SEE ALSO .Xr chpass 1 , .Xr w 1 , diff --git a/usr.bin/finger/finger.c b/usr.bin/finger/finger.c index 5a16765..f4ece3a 100644 --- a/usr.bin/finger/finger.c +++ b/usr.bin/finger/finger.c @@ -41,7 +41,7 @@ static char copyright[] = #endif /* not lint */ #ifndef lint -static char sccsid[] = "@(#)finger.c 8.2 (Berkeley) 9/30/93"; +static char sccsid[] = "@(#)finger.c 8.5 (Berkeley) 5/4/95"; #endif /* not lint */ /* @@ -58,15 +58,19 @@ static char sccsid[] = "@(#)finger.c 8.2 (Berkeley) 9/30/93"; */ #include <sys/param.h> + +#include <db.h> +#include <err.h> +#include <errno.h> #include <fcntl.h> -#include <time.h> #include <pwd.h> -#include <utmp.h> -#include <errno.h> #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <db.h> +#include <time.h> +#include <unistd.h> +#include <utmp.h> + #include "finger.h" DB *db; @@ -77,6 +81,7 @@ char tbuf[1024]; static void loginlist __P((void)); static void userlist __P((int, char **)); +int main(argc, argv) int argc; char **argv; @@ -134,7 +139,7 @@ main(argc, argv) lflag_print(); else sflag_print(); - exit(0); + return (0); } static void @@ -148,7 +153,7 @@ loginlist() char name[UT_NAMESIZE + 1]; if (!freopen(_PATH_UTMP, "r", stdin)) - err("%s: %s", _PATH_UTMP, strerror(errno)); + err(1, "%s", _PATH_UTMP); name[UT_NAMESIZE] = NULL; while (fread((char *)&user, sizeof(user), 1, stdin) == 1) { if (!user.ut_name[0]) @@ -163,12 +168,15 @@ loginlist() } if (db && lflag) for (sflag = R_FIRST;; sflag = R_NEXT) { + PERSON *tmp; + r = (*db->seq)(db, &key, &data, sflag); if (r == -1) - err("db seq: %s", strerror(errno)); + err(1, "db seq"); if (r == 1) break; - enter_lastlog(*(PERSON **)data.data); + memmove(&tmp, data.data, sizeof tmp); + enter_lastlog(tmp); } } @@ -186,7 +194,7 @@ userlist(argc, argv) if ((nargv = malloc((argc+1) * sizeof(char *))) == NULL || (used = calloc(argc, sizeof(int))) == NULL) - err("%s", strerror(errno)); + err(1, NULL); /* Pull out all network requests. */ for (ap = p = argv, np = nargv; *p; ++p) @@ -207,13 +215,13 @@ userlist(argc, argv) */ if (mflag) for (p = argv; *p; ++p) - if (pw = getpwnam(*p)) + if ((pw = getpwnam(*p)) != NULL) enter_person(pw); else (void)fprintf(stderr, "finger: %s: no such user\n", *p); else { - while (pw = getpwent()) + while ((pw = getpwent()) != NULL) for (p = argv, ip = used; *p; ++p, ++ip) if (match(pw, *p)) { enter_person(pw); @@ -237,7 +245,7 @@ net: for (p = nargv; *p;) * appropriate data whenever a match occurs. */ if (!freopen(_PATH_UTMP, "r", stdin)) - err("%s: %s", _PATH_UTMP, strerror(errno)); + err(1, "%s", _PATH_UTMP); while (fread((char *)&user, sizeof(user), 1, stdin) == 1) { if (!user.ut_name[0]) continue; @@ -247,11 +255,14 @@ net: for (p = nargv; *p;) } if (db) for (sflag = R_FIRST;; sflag = R_NEXT) { + PERSON *tmp; + r = (*db->seq)(db, &key, &data, sflag); if (r == -1) - err("db seq: %s", strerror(errno)); + err(1, "db seq"); if (r == 1) break; - enter_lastlog(*(PERSON **)data.data); + memmove(&tmp, data.data, sizeof tmp); + enter_lastlog(tmp); } } diff --git a/usr.bin/finger/lprint.c b/usr.bin/finger/lprint.c index d079c24..96edb1b 100644 --- a/usr.bin/finger/lprint.c +++ b/usr.bin/finger/lprint.c @@ -35,7 +35,7 @@ */ #ifndef lint -static char sccsid[] = "@(#)lprint.c 8.1 (Berkeley) 6/6/93"; +static char sccsid[] = "@(#)lprint.c 8.3 (Berkeley) 4/28/95"; #endif /* not lint */ #include <sys/types.h> @@ -45,6 +45,7 @@ static char sccsid[] = "@(#)lprint.c 8.1 (Berkeley) 6/6/93"; #include <time.h> #include <tzfile.h> #include <db.h> +#include <err.h> #include <pwd.h> #include <utmp.h> #include <errno.h> @@ -72,15 +73,17 @@ lflag_print() extern int pplan; register PERSON *pn; register int sflag, r; + PERSON *tmp; DBT data, key; for (sflag = R_FIRST;; sflag = R_NEXT) { r = (*db->seq)(db, &key, &data, sflag); if (r == -1) - err("db seq: %s", strerror(errno)); + err(1, "db seq"); if (r == 1) break; - pn = *(PERSON **)data.data; + memmove(&tmp, data.data, sizeof tmp); + pn = tmp; if (sflag != R_FIRST) putchar('\n'); lprint(pn); diff --git a/usr.bin/finger/net.c b/usr.bin/finger/net.c index 51f1b43..3eb7518 100644 --- a/usr.bin/finger/net.c +++ b/usr.bin/finger/net.c @@ -35,7 +35,7 @@ */ #ifndef lint -static char sccsid[] = "@(#)net.c 8.3 (Berkeley) 1/2/94"; +static char sccsid[] = "@(#)net.c 8.4 (Berkeley) 4/28/95"; #endif /* not lint */ #include <sys/types.h> @@ -121,7 +121,8 @@ netfinger(name) * 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")) + lastc = 0; + if ((fp = fdopen(s, "r")) != NULL) while ((c = getc(fp)) != EOF) { c &= 0x7f; if (c == 0x0d) { diff --git a/usr.bin/finger/sprint.c b/usr.bin/finger/sprint.c index 68deb76..54c7eea 100644 --- a/usr.bin/finger/sprint.c +++ b/usr.bin/finger/sprint.c @@ -35,7 +35,7 @@ */ #ifndef lint -static char sccsid[] = "@(#)sprint.c 8.1 (Berkeley) 6/6/93"; +static char sccsid[] = "@(#)sprint.c 8.3 (Berkeley) 4/28/95"; #endif /* not lint */ #include <sys/types.h> @@ -43,6 +43,7 @@ static char sccsid[] = "@(#)sprint.c 8.1 (Berkeley) 6/6/93"; #include <time.h> #include <tzfile.h> #include <db.h> +#include <err.h> #include <pwd.h> #include <errno.h> #include <utmp.h> @@ -61,6 +62,7 @@ sflag_print() register WHERE *w; register int sflag, r; register char *p; + PERSON *tmp; DBT data, key; /* @@ -83,10 +85,11 @@ sflag_print() for (sflag = R_FIRST;; sflag = R_NEXT) { r = (*db->seq)(db, &key, &data, sflag); if (r == -1) - err("db seq: %s", strerror(errno)); + err(1, "db seq"); if (r == 1) break; - pn = *(PERSON **)data.data; + memmove(&tmp, data.data, sizeof tmp); + pn = tmp; for (w = pn->whead; w != NULL; w = w->next) { (void)printf("%-*.*s %-*.*s ", UT_NAMESIZE, UT_NAMESIZE, diff --git a/usr.bin/finger/util.c b/usr.bin/finger/util.c index c27cf1b..b51b7ab 100644 --- a/usr.bin/finger/util.c +++ b/usr.bin/finger/util.c @@ -35,13 +35,14 @@ */ #ifndef lint -static char sccsid[] = "@(#)util.c 8.1 (Berkeley) 6/6/93"; +static char sccsid[] = "@(#)util.c 8.3 (Berkeley) 4/28/95"; #endif /* not lint */ #include <sys/param.h> #include <sys/stat.h> #include <fcntl.h> #include <db.h> +#include <err.h> #include <pwd.h> #include <utmp.h> #include <errno.h> @@ -80,14 +81,14 @@ match(pw, user) if ((p = strtok(p, ",")) == NULL) return(0); - for (t = name; *t = *p; ++p) + for (t = name; (*t = *p) != '\0'; ++p) if (*t == '&') { (void)strcpy(t, pw->pw_name); while (*++t); } else ++t; - for (t = name; p = strtok(t, "\t "); t = NULL) + for (t = name; (p = strtok(t, "\t ")) != NULL; t = NULL) if (!strcasecmp(p, user)) return(1); return(0); @@ -169,17 +170,18 @@ enter_person(pw) if (db == NULL && (db = dbopen(NULL, O_RDWR, 0, DB_BTREE, NULL)) == NULL) - err("%s", strerror(errno)); + err(1, NULL); key.data = pw->pw_name; key.size = strlen(pw->pw_name); - switch((*db->get)(db, &key, &data, 0)) { + switch ((*db->get)(db, &key, &data, 0)) { case 0: - return(*(PERSON **)data.data); + memmove(&pn, data.data, sizeof pn); + return (pn); default: case -1: - err("db get: %s", strerror(errno)); + err(1, "db get"); /* NOTREACHED */ case 1: ++entries; @@ -190,8 +192,8 @@ enter_person(pw) data.size = sizeof(PERSON *); data.data = &pn; if ((*db->put)(db, &key, &data, 0)) - err("%s", strerror(errno)); - return(pn); + err(1, "db put"); + return (pn); } } @@ -201,6 +203,7 @@ find_person(name) { register int cnt; DBT data, key; + PERSON *p; char buf[UT_NAMESIZE + 1]; if (!db) @@ -213,7 +216,10 @@ find_person(name) key.data = buf; key.size = cnt; - return((*db->get)(db, &key, &data, 0) ? NULL : *(PERSON **)data.data); + if ((*db->get)(db, &key, &data, 0)) + return (NULL); + memmove(&p, data.data, sizeof p); + return (p); } PERSON * @@ -222,7 +228,7 @@ palloc() PERSON *p; if ((p = malloc((u_int) sizeof(PERSON))) == NULL) - err("%s", strerror(errno)); + err(1, NULL); return(p); } @@ -233,7 +239,7 @@ walloc(pn) register WHERE *w; if ((w = malloc((u_int) sizeof(WHERE))) == NULL) - err("%s", strerror(errno)); + err(1, NULL); if (pn->whead == NULL) pn->whead = pn->wtail = w; else { @@ -300,8 +306,7 @@ find_idle_and_ttywrite(w) (void)snprintf(tbuf, sizeof(tbuf), "%s/%s", _PATH_DEV, w->tty); if (stat(tbuf, &sb) < 0) { - (void)fprintf(stderr, - "finger: %s: %s\n", tbuf, strerror(errno)); + warn(tbuf); return; } w->idletime = now < sb.st_atime ? 0 : now - sb.st_atime; @@ -333,7 +338,7 @@ userinfo(pn, pw) /* ampersands get replaced by the login name */ if (!(p = strsep(&bp, ","))) return; - for (t = name; *t = *p; ++p) + for (t = name; (*t = *p) != '\0'; ++p) if (*t == '&') { (void)strcpy(t, pw->pw_name); if (islower(*t)) @@ -350,32 +355,3 @@ userinfo(pn, pw) pn->homephone = ((p = strsep(&bp, ",")) && *p) ? strdup(p) : NULL; } - -#if __STDC__ -#include <stdarg.h> -#else -#include <varargs.h> -#endif - -void -#if __STDC__ -err(const char *fmt, ...) -#else -err(fmt, va_alist) - char *fmt; - va_dcl -#endif -{ - va_list ap; -#if __STDC__ - va_start(ap, fmt); -#else - va_start(ap); -#endif - (void)fprintf(stderr, "finger: "); - (void)vfprintf(stderr, fmt, ap); - va_end(ap); - (void)fprintf(stderr, "\n"); - exit(1); - /* NOTREACHED */ -} |