Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/finger support utmpx; no lastlogx support yet.



details:   https://anonhg.NetBSD.org/src/rev/0043d458e884
branches:  trunk
changeset: 534691:0043d458e884
user:      christos <christos%NetBSD.org@localhost>
date:      Fri Aug 02 00:10:40 2002 +0000

description:
support utmpx; no lastlogx support yet.

diffstat:

 usr.bin/finger/Makefile |   7 ++++---
 usr.bin/finger/extern.h |   4 ++--
 usr.bin/finger/finger.c |  38 +++++++++++++++-----------------------
 usr.bin/finger/finger.h |   6 +++---
 usr.bin/finger/lprint.c |   6 +++---
 usr.bin/finger/net.c    |   8 +++++---
 usr.bin/finger/sprint.c |   6 ++++--
 usr.bin/finger/util.c   |  38 +++++++++++++++++---------------------
 8 files changed, 53 insertions(+), 60 deletions(-)

diffs (truncated from 341 to 300 lines):

diff -r ffe787af5979 -r 0043d458e884 usr.bin/finger/Makefile
--- a/usr.bin/finger/Makefile   Fri Aug 02 00:09:33 2002 +0000
+++ b/usr.bin/finger/Makefile   Fri Aug 02 00:10:40 2002 +0000
@@ -1,9 +1,10 @@
-#      $NetBSD: Makefile,v 1.5 1999/07/02 06:01:22 itojun Exp $
+#      $NetBSD: Makefile,v 1.6 2002/08/02 00:10:40 christos Exp $
 #      from: @(#)Makefile      8.1 (Berkeley) 6/6/93
 
 PROG=  finger
-SRCS=  finger.c lprint.c net.c sprint.c util.c
+SRCS=  finger.c lprint.c net.c sprint.c util.c utmpentry.c
 
-CPPFLAGS+=-DINET6
+.PATH.c: ${.CURDIR}/../../usr.bin/who
+CPPFLAGS+=-I${.CURDIR}/../../usr.bin/who -DSUPPORT_UTMPX -DSUPPORT_UTMP -DINET6
 
 .include <bsd.prog.mk>
diff -r ffe787af5979 -r 0043d458e884 usr.bin/finger/extern.h
--- a/usr.bin/finger/extern.h   Fri Aug 02 00:09:33 2002 +0000
+++ b/usr.bin/finger/extern.h   Fri Aug 02 00:10:40 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: extern.h,v 1.6 1998/07/26 21:35:28 mycroft Exp $       */
+/*     $NetBSD: extern.h,v 1.7 2002/08/02 00:10:40 christos Exp $      */
 
 /*-
  * Copyright (c) 1991, 1993
@@ -46,7 +46,7 @@
 
 void    enter_lastlog __P((PERSON *));
 PERSON *enter_person __P((struct passwd *));
-void    enter_where __P((struct utmp *, PERSON *));
+void    enter_where __P((struct utmpentry *, PERSON *));
 void    expandusername __P((const char *, const char *, char *, int));
 PERSON *find_person __P((char *));
 int     hash __P((char *));
diff -r ffe787af5979 -r 0043d458e884 usr.bin/finger/finger.c
--- a/usr.bin/finger/finger.c   Fri Aug 02 00:09:33 2002 +0000
+++ b/usr.bin/finger/finger.c   Fri Aug 02 00:10:40 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: finger.c,v 1.15 2002/05/02 13:04:10 wiz Exp $  */
+/*     $NetBSD: finger.c,v 1.16 2002/08/02 00:10:40 christos Exp $     */
 
 /*
  * Copyright (c) 1989, 1993
@@ -56,7 +56,7 @@
 #if 0
 static char sccsid[] = "@(#)finger.c   8.5 (Berkeley) 5/4/95";
 #else
-__RCSID("$NetBSD: finger.c,v 1.15 2002/05/02 13:04:10 wiz Exp $");
+__RCSID("$NetBSD: finger.c,v 1.16 2002/08/02 00:10:40 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -86,7 +86,8 @@
 #include <string.h>
 #include <time.h>
 #include <unistd.h>
-#include <utmp.h>
+
+#include "utmpentry.h"
 
 #include "finger.h"
 #include "extern.h"
@@ -95,6 +96,7 @@
 time_t now;
 int entries, gflag, lflag, mflag, oflag, sflag, pplan;
 char tbuf[1024];
+struct utmpentry *ehead;
 
 static void loginlist __P((void));
 static void userlist __P((int, char **));
@@ -143,6 +145,7 @@
 
        (void)time(&now);
        setpassent(1);
+       entries = getutentries(NULL, &ehead);
        if (!*argv) {
                /*
                 * Assign explicit "small" format if no names given and -l
@@ -179,23 +182,16 @@
        PERSON *pn;
        DBT data, key;
        struct passwd *pw;
-       struct utmp user;
        int r, sflag;
-       char name[UT_NAMESIZE + 1];
+       struct utmpentry *ep;
 
-       if (!freopen(_PATH_UTMP, "r", stdin))
-               err(1, "cant read %s", _PATH_UTMP);
-       name[UT_NAMESIZE] = '\0';
-       while (fread((char *)&user, sizeof(user), 1, stdin) == 1) {
-               if (!user.ut_name[0])
-                       continue;
-               if ((pn = find_person(user.ut_name)) == NULL) {
-                       memcpy(name, user.ut_name, UT_NAMESIZE);
-                       if ((pw = getpwnam(name)) == NULL)
+       for (ep = ehead; ep; ep = ep->next) {
+               if ((pn = find_person(ep->name)) == NULL) {
+                       if ((pw = getpwnam(ep->name)) == NULL)
                                continue;
                        pn = enter_person(pw);
                }
-               enter_where(&user, pn);
+               enter_where(ep, pn);
        }
        if (db && lflag)
                for (sflag = R_FIRST;; sflag = R_NEXT) {
@@ -218,10 +214,10 @@
 {
        register PERSON *pn;
        DBT data, key;
-       struct utmp user;
        struct passwd *pw;
        int r, sflag, *used, *ip;
        char **ap, **nargv, **np, **p;
+       struct utmpentry *ep;
 
        if ((nargv = malloc((argc+1) * sizeof(char *))) == NULL ||
            (used = calloc(argc, sizeof(int))) == NULL)
@@ -276,14 +272,10 @@
         * Scan thru the list of users currently logged in, saving
         * appropriate data whenever a match occurs.
         */
-       if (!freopen(_PATH_UTMP, "r", stdin))
-               err(1, "%s", _PATH_UTMP);
-       while (fread((char *)&user, sizeof(user), 1, stdin) == 1) {
-               if (!user.ut_name[0])
+       for (ep = ehead; ep; ep = ep->next) {
+               if ((pn = find_person(ep->name)) == NULL)
                        continue;
-               if ((pn = find_person(user.ut_name)) == NULL)
-                       continue;
-               enter_where(&user, pn);
+               enter_where(ep, pn);
        }
        if (db)
                for (sflag = R_FIRST;; sflag = R_NEXT) {
diff -r ffe787af5979 -r 0043d458e884 usr.bin/finger/finger.h
--- a/usr.bin/finger/finger.h   Fri Aug 02 00:09:33 2002 +0000
+++ b/usr.bin/finger/finger.h   Fri Aug 02 00:10:40 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: finger.h,v 1.7 2001/02/05 01:56:38 christos Exp $      */
+/*     $NetBSD: finger.h,v 1.8 2002/08/02 00:10:40 christos Exp $      */
 
 /*
  * Copyright (c) 1989, 1993
@@ -67,6 +67,6 @@
        short writable;                 /* tty is writable */
        time_t loginat;                 /* time of (last) login */
        time_t idletime;                /* how long idle (if logged in) */
-       char tty[UT_LINESIZE+1];        /* null terminated tty line */
-       char host[UT_HOSTSIZE+1];       /* null terminated remote host name */
+       char *tty;                      /* tty line */
+       char *host;                     /* remote host name */
 } WHERE;
diff -r ffe787af5979 -r 0043d458e884 usr.bin/finger/lprint.c
--- a/usr.bin/finger/lprint.c   Fri Aug 02 00:09:33 2002 +0000
+++ b/usr.bin/finger/lprint.c   Fri Aug 02 00:10:40 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lprint.c,v 1.12 1998/12/19 16:00:33 christos Exp $     */
+/*     $NetBSD: lprint.c,v 1.13 2002/08/02 00:10:40 christos Exp $     */
 
 /*
  * Copyright (c) 1989, 1993
@@ -41,7 +41,7 @@
 #if 0
 static char sccsid[] = "@(#)lprint.c   8.3 (Berkeley) 4/28/95";
 #else
-__RCSID( "$NetBSD: lprint.c,v 1.12 1998/12/19 16:00:33 christos Exp $");
+__RCSID( "$NetBSD: lprint.c,v 1.13 2002/08/02 00:10:40 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -54,7 +54,6 @@
 #include <db.h>
 #include <err.h>
 #include <pwd.h>
-#include <utmp.h>
 #include <errno.h>
 #include <unistd.h>
 #include <stdio.h>
@@ -65,6 +64,7 @@
 #include <paths.h>
 #include <vis.h>
 
+#include "utmpentry.h"
 #include "finger.h"
 #include "extern.h"
 
diff -r ffe787af5979 -r 0043d458e884 usr.bin/finger/net.c
--- a/usr.bin/finger/net.c      Fri Aug 02 00:09:33 2002 +0000
+++ b/usr.bin/finger/net.c      Fri Aug 02 00:10:40 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: net.c,v 1.14 2000/07/07 15:13:22 itojun Exp $  */
+/*     $NetBSD: net.c,v 1.15 2002/08/02 00:10:40 christos Exp $        */
 
 /*
  * Copyright (c) 1989, 1993
@@ -41,7 +41,7 @@
 #if 0
 static char sccsid[] = "@(#)net.c      8.4 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: net.c,v 1.14 2000/07/07 15:13:22 itojun Exp $");
+__RCSID("$NetBSD: net.c,v 1.15 2002/08/02 00:10:40 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -53,16 +53,18 @@
 #include <arpa/inet.h>
 
 #include <netdb.h>
+#include <time.h>
 #include <db.h>
 #include <unistd.h>
 #include <pwd.h>
-#include <utmp.h>
 #include <stdio.h>
 #include <string.h>
 #include <ctype.h>
 #include <unistd.h>
 #include <err.h>
 
+#include "utmpentry.h"
+
 #include "finger.h"
 #include "extern.h"
 
diff -r ffe787af5979 -r 0043d458e884 usr.bin/finger/sprint.c
--- a/usr.bin/finger/sprint.c   Fri Aug 02 00:09:33 2002 +0000
+++ b/usr.bin/finger/sprint.c   Fri Aug 02 00:10:40 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sprint.c,v 1.10 1998/12/19 16:01:01 christos Exp $     */
+/*     $NetBSD: sprint.c,v 1.11 2002/08/02 00:10:40 christos Exp $     */
 
 /*
  * Copyright (c) 1989, 1993
@@ -41,7 +41,7 @@
 #if 0
 static char sccsid[] = "@(#)sprint.c   8.3 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: sprint.c,v 1.10 1998/12/19 16:01:01 christos Exp $");
+__RCSID("$NetBSD: sprint.c,v 1.11 2002/08/02 00:10:40 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -59,6 +59,8 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include "utmpentry.h"
+
 #include "finger.h"
 #include "extern.h"
 
diff -r ffe787af5979 -r 0043d458e884 usr.bin/finger/util.c
--- a/usr.bin/finger/util.c     Fri Aug 02 00:09:33 2002 +0000
+++ b/usr.bin/finger/util.c     Fri Aug 02 00:10:40 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: util.c,v 1.17 2001/02/05 01:56:51 christos Exp $       */
+/*     $NetBSD: util.c,v 1.18 2002/08/02 00:10:40 christos Exp $       */
 
 /*
  * Copyright (c) 1989, 1993
@@ -42,7 +42,7 @@
 #if 0
 static char sccsid[] = "@(#)util.c     8.3 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: util.c,v 1.17 2001/02/05 01:56:51 christos Exp $");
+__RCSID("$NetBSD: util.c,v 1.18 2002/08/02 00:10:40 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -62,6 +62,8 @@
 #include <unistd.h>
 #include <utmp.h>
 
+#include "utmpentry.h"
+
 #include "finger.h"
 #include "extern.h"
 
@@ -172,28 +174,27 @@
        if (doit) {
                w = walloc(pn);
                w->info = LASTLOG;
-               memcpy(w->tty, ll.ll_line, UT_LINESIZE);
-               w->tty[UT_LINESIZE] = 0;
-               memcpy(w->host, ll.ll_host, UT_HOSTSIZE);
-               w->host[UT_HOSTSIZE] = 0;
+               memcpy(w->tty = malloc(UT_LINESIZE + 1),
+                   ll.ll_line, UT_LINESIZE);
+               w->tty[UT_LINESIZE + 1] = '\0';
+               memcpy(w->host = malloc(UT_HOSTSIZE + 1),
+                   ll.ll_host, UT_HOSTSIZE);
+               w->host[UT_HOSTSIZE + 1] = '\0';
                w->loginat = ll.ll_time;
        }
 }
 



Home | Main Index | Thread Index | Old Index