Source-Changes-HG archive

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

[src/trunk]: src/usr.bin utmpx support.



details:   https://anonhg.NetBSD.org/src/rev/3fc8c89446c8
branches:  trunk
changeset: 534709:3fc8c89446c8
user:      christos <christos%NetBSD.org@localhost>
date:      Fri Aug 02 01:52:13 2002 +0000

description:
utmpx support.

diffstat:

 usr.bin/wall/Makefile  |   6 +++++-
 usr.bin/wall/wall.c    |  24 ++++++++----------------
 usr.bin/write/Makefile |   6 +++++-
 usr.bin/write/write.c  |  43 ++++++++++++++++---------------------------
 4 files changed, 34 insertions(+), 45 deletions(-)

diffs (205 lines):

diff -r 546654ff30ac -r 3fc8c89446c8 usr.bin/wall/Makefile
--- a/usr.bin/wall/Makefile     Fri Aug 02 01:33:07 2002 +0000
+++ b/usr.bin/wall/Makefile     Fri Aug 02 01:52:13 2002 +0000
@@ -1,10 +1,14 @@
-#      $NetBSD: Makefile,v 1.6 1997/10/20 03:13:32 lukem Exp $
+#      $NetBSD: Makefile,v 1.7 2002/08/02 01:52:13 christos Exp $
 #      @(#)Makefile    8.1 (Berkeley) 6/6/93
 
 PROG=  wall
+SRCS=  wall.c utmpentry.c
 BINGRP=        tty
 BINMODE=2555
 DPADD+=${LIBUTIL}
 LDADD+=-lutil
 
+.PATH.c: ${.CURDIR}/../../usr.bin/who
+CPPFLAGS+=-I${.CURDIR}/../../usr.bin/who -DSUPPORT_UTMPX -DSUPPORT_UTMP
+
 .include <bsd.prog.mk>
diff -r 546654ff30ac -r 3fc8c89446c8 usr.bin/wall/wall.c
--- a/usr.bin/wall/wall.c       Fri Aug 02 01:33:07 2002 +0000
+++ b/usr.bin/wall/wall.c       Fri Aug 02 01:52:13 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: wall.c,v 1.18 2001/01/05 04:06:49 mjl Exp $    */
+/*     $NetBSD: wall.c,v 1.19 2002/08/02 01:52:13 christos Exp $       */
 
 /*
  * Copyright (c) 1988, 1990, 1993
@@ -43,7 +43,7 @@
 #if 0
 static char sccsid[] = "@(#)wall.c     8.2 (Berkeley) 11/16/93";
 #endif
-__RCSID("$NetBSD: wall.c,v 1.18 2001/01/05 04:06:49 mjl Exp $");
+__RCSID("$NetBSD: wall.c,v 1.19 2002/08/02 01:52:13 christos Exp $");
 #endif /* not lint */
 
 /*
@@ -63,9 +63,10 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
-#include <utmp.h>
 #include <util.h>
 
+#include "utmpentry.h"
+
 void   makemsg(const char *);
 int    main(int, char **);
 
@@ -79,11 +80,9 @@
 {
        int ch;
        struct iovec iov;
-       struct utmp utmp;
-       FILE *fp;
        char *p;
        struct passwd *pep = getpwnam("nobody");
-       char line[sizeof(utmp.ut_line) + 1];
+       struct utmpentry *ep;
 
        while ((ch = getopt(argc, argv, "n")) != -1)
                switch (ch) {
@@ -105,19 +104,12 @@
 
        makemsg(*argv);
 
-       if (!(fp = fopen(_PATH_UTMP, "r")))
-               err(1, "cannot read %s", _PATH_UTMP);
        iov.iov_base = mbuf;
        iov.iov_len = mbufsize;
-       /* NOSTRICT */
-       while (fread((char *)&utmp, sizeof(utmp), 1, fp) == 1) {
-               if (!utmp.ut_name[0])
-                       continue;
-               strncpy(line, utmp.ut_line, sizeof(utmp.ut_line));
-               line[sizeof(utmp.ut_line)] = '\0';
-               if ((p = ttymsg(&iov, 1, line, 60*5)) != NULL)
+       (void)getutentries(NULL, &ep);
+       for (; ep; ep = ep->next)
+               if ((p = ttymsg(&iov, 1, ep->line, 60*5)) != NULL)
                        warnx("%s", p);
-       }
        exit(0);
 }
 
diff -r 546654ff30ac -r 3fc8c89446c8 usr.bin/write/Makefile
--- a/usr.bin/write/Makefile    Fri Aug 02 01:33:07 2002 +0000
+++ b/usr.bin/write/Makefile    Fri Aug 02 01:52:13 2002 +0000
@@ -1,8 +1,12 @@
-#      $NetBSD: Makefile,v 1.4 1997/01/09 20:23:26 tls Exp $
+#      $NetBSD: Makefile,v 1.5 2002/08/02 01:59:43 christos Exp $
 #      from: @(#)Makefile      8.1 (Berkeley) 6/6/93
 
 PROG=  write
+SRCS=  write.c utmpentry.c
 BINMODE=2555
 BINGRP=        tty
 
+.PATH.c: ${.CURDIR}/../../usr.bin/who
+CPPFLAGS+=-I${.CURDIR}/../../usr.bin/who -DSUPPORT_UTMPX -DSUPPORT_UTMP
+
 .include <bsd.prog.mk>
diff -r 546654ff30ac -r 3fc8c89446c8 usr.bin/write/write.c
--- a/usr.bin/write/write.c     Fri Aug 02 01:33:07 2002 +0000
+++ b/usr.bin/write/write.c     Fri Aug 02 01:52:13 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: write.c,v 1.19 2001/01/03 13:25:11 mjl Exp $   */
+/*     $NetBSD: write.c,v 1.20 2002/08/02 01:59:44 christos Exp $      */
 
 /*
  * Copyright (c) 1989, 1993
@@ -46,7 +46,7 @@
 #if 0
 static char sccsid[] = "@(#)write.c    8.2 (Berkeley) 4/27/95";
 #else
-__RCSID("$NetBSD: write.c,v 1.19 2001/01/03 13:25:11 mjl Exp $");
+__RCSID("$NetBSD: write.c,v 1.20 2002/08/02 01:59:44 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -63,9 +63,10 @@
 #include <paths.h>
 #include <pwd.h>
 #include <unistd.h>
-#include <utmp.h>
 #include <err.h>
 
+#include "utmpentry.h"
+
 void done(int);
 void do_write(const char *, const char *, const uid_t);
 void wr_fputs(char *);
@@ -143,20 +144,13 @@
 int
 utmp_chk(const char *user, const char *tty)
 {
-       struct utmp u;
-       int ufd;
+       struct utmpentry *ep;
 
-       if ((ufd = open(_PATH_UTMP, O_RDONLY)) < 0)
-               return(0);      /* ignore error, shouldn't happen anyway */
+       (void)getutentries(NULL, &ep);
 
-       while (read(ufd, (char *) &u, sizeof(u)) == sizeof(u))
-               if (strncmp(user, u.ut_name, sizeof(u.ut_name)) == 0 &&
-                   strncmp(tty, u.ut_line, sizeof(u.ut_line)) == 0) {
-                       (void)close(ufd);
+       for (; ep; ep = ep->next)
+               if (strcmp(user, ep->name) == 0 && strcmp(tty, ep->line) == 0)
                        return(0);
-               }
-
-       (void)close(ufd);
        return(1);
 }
 
@@ -174,39 +168,34 @@
 void
 search_utmp(char *user, char *tty, char *mytty, uid_t myuid, int ttylen)
 {
-       struct utmp u;
        time_t bestatime, atime;
-       int ufd, nloggedttys, nttys, msgsok, user_is_me;
-       char atty[UT_LINESIZE + 1];
+       int nloggedttys, nttys, msgsok, user_is_me;
+       struct utmpentry *ep;
 
-       if ((ufd = open(_PATH_UTMP, O_RDONLY)) < 0)
-               err(1, "%s", _PATH_UTMP);
+       (void)getutentries(NULL, &ep);
 
        nloggedttys = nttys = 0;
        bestatime = 0;
        user_is_me = 0;
-       while (read(ufd, (char *) &u, sizeof(u)) == sizeof(u))
-               if (strncmp(user, u.ut_name, sizeof(u.ut_name)) == 0) {
+       for (; ep; ep = ep->next)
+               if (strcmp(user, ep->name) == 0) {
                        ++nloggedttys;
-                       (void)strncpy(atty, u.ut_line, UT_LINESIZE);
-                       atty[UT_LINESIZE] = '\0';
-                       if (term_chk(atty, &msgsok, &atime, 0))
+                       if (term_chk(ep->line, &msgsok, &atime, 0))
                                continue;       /* bad term? skip */
                        if (myuid && !msgsok)
                                continue;       /* skip ttys with msgs off */
-                       if (strcmp(atty, mytty) == 0) {
+                       if (strcmp(ep->line, mytty) == 0) {
                                user_is_me = 1;
                                continue;       /* don't write to yourself */
                        }
                        ++nttys;
                        if (atime > bestatime) {
                                bestatime = atime;
-                               (void)strncpy(tty, atty, ttylen - 1);
+                               (void)strncpy(tty, ep->line, ttylen - 1);
                                tty[ttylen - 1] = '\0';
                        }
                }
 
-       (void)close(ufd);
        if (nloggedttys == 0)
                errx(1, "%s is not logged in", user);
        if (nttys == 0) {



Home | Main Index | Thread Index | Old Index