more utmpx work
authorAlex Hornung <ahornung@gmail.com>
Mon, 6 Dec 2010 17:25:36 +0000 (17:25 +0000)
committerAlex Hornung <ahornung@gmail.com>
Wed, 15 Dec 2010 17:46:06 +0000 (17:46 +0000)
18 files changed:
games/dm/Makefile
games/dm/dm.c
libexec/talkd/Makefile
libexec/talkd/process.c
usr.bin/finger/Makefile
usr.bin/finger/finger.c
usr.bin/login/login.c
usr.bin/systat/Makefile
usr.bin/systat/vmstat.c
usr.bin/users/Makefile
usr.bin/users/users.c
usr.bin/w/w.c
usr.bin/wall/Makefile
usr.bin/wall/wall.c
usr.bin/write/Makefile
usr.bin/write/write.c
usr.sbin/syslogd/Makefile
usr.sbin/syslogd/syslogd.c

index 3d153f6..f32d29f 100644 (file)
@@ -3,9 +3,17 @@
 # $DragonFly: src/games/dm/Makefile,v 1.4 2006/10/08 16:22:35 pavalos Exp $
 
 # -DLOG                log games
+.PATH: ${.CURDIR}/../../usr.bin/who
+
 PROG=  dm
+SRCS=  dm.c utmpentry.c
 MAN=   dm.8 dm.conf.5
 BINGRP= games
 BINMODE=2555
 
+DPADD= ${LIBUTIL}
+LDADD= -lutil
+
+CFLAGS+= -I${.CURDIR}/../../usr.bin/who -DSUPPORT_UTMP -DSUPPORT_UTMPX
+
 .include <bsd.prog.mk>
index 83d86d6..298e77e 100644 (file)
@@ -50,7 +50,7 @@
 #include <string.h>
 #include <time.h>
 #include <unistd.h>
-#include <utmp.h>
+#include "utmpentry.h"
 
 #include "pathnames.h"
 
@@ -257,18 +257,13 @@ load(void)
 static int
 users(void)
 {
+       struct utmpentry *ep;
+       int nusers;
 
-       int nusers, utmp;
-       struct utmp buf;
+       getutentries(NULL, &ep);
+       for (; ep; ep = ep->next)
+               ++nusers;
 
-       if ((utmp = open(_PATH_UTMP, O_RDONLY, 0)) < 0) {
-               fprintf(stderr, "dm: %s: %s\n",
-                   _PATH_UTMP, strerror(errno));
-               exit(1);
-       }
-       for (nusers = 0; read(utmp, (char *)&buf, sizeof(struct utmp)) > 0;)
-               if (buf.ut_name[0] != '\0')
-                       ++nusers;
        return(nusers);
 }
 
index b85e7e8..501d1d3 100644 (file)
@@ -1,12 +1,16 @@
 #      @(#)Makefile    8.1 (Berkeley) 6/4/93
 # $FreeBSD: src/libexec/talkd/Makefile,v 1.6.2.2 2001/10/18 12:30:42 des Exp $
 
-.PATH:  ${.CURDIR}/../../usr.bin/wall
+.PATH:  ${.CURDIR}/../../usr.bin/wall ${.CURDIR}/../../usr.bin/who
 
 PROG=  ntalkd
-SRCS=  talkd.c announce.c process.c table.c print.c ttymsg.c
+SRCS=  talkd.c announce.c process.c table.c print.c ttymsg.c utmpentry.c
 MAN=   talkd.8
 
+DPADD= ${LIBUTIL}
+LDADD= -lutil
+
 CFLAGS+=-I${.CURDIR}/../../usr.bin/wall
+CFLAGS+=-I${.CURDIR}/../../usr.bin/who -DSUPPORT_UTMP -DSUPPORT_UTMPX
 
 .include <bsd.prog.mk>
index 3c7257e..70ec159 100644 (file)
@@ -54,7 +54,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <syslog.h>
-#include <utmp.h>
+#include "utmpentry.h"
 
 #include "extern.h"
 
@@ -183,47 +183,41 @@ do_announce(CTL_MSG *mp, CTL_RESPONSE *rp)
 int
 find_user(const char *name, char *tty)
 {
-       struct utmp ubuf;
+       struct utmpentry *ep;
        int status;
-       FILE *fd;
        struct stat statb;
        time_t best = 0;
-       char line[sizeof(ubuf.ut_line) + 1];
-       char ftty[sizeof(_PATH_DEV) - 1 + sizeof(line)];
+       char ftty[sizeof(_PATH_DEV) + sizeof(ep->line)];
+
+       getutentries(NULL, &ep);
 
-       if ((fd = fopen(_PATH_UTMP, "r")) == NULL) {
-               warnx("can't read %s", _PATH_UTMP);
-               return (FAILED);
-       }
 #define SCMPN(a, b)    strncmp(a, b, sizeof (a))
        status = NOT_HERE;
        (void) strcpy(ftty, _PATH_DEV);
-       while (fread((char *) &ubuf, sizeof ubuf, 1, fd) == 1)
-               if (SCMPN(ubuf.ut_name, name) == 0) {
-                       strncpy(line, ubuf.ut_line, sizeof(ubuf.ut_line));
-                       line[sizeof(ubuf.ut_line)] = '\0';
+       for (; ep; ep = ep->next)
+               if (SCMPN(ep->name, name) == 0) {
                        if (*tty == '\0' || best != 0) {
                                if (best == 0)
                                        status = PERMISSION_DENIED;
                                /* no particular tty was requested */
                                (void) strcpy(ftty + sizeof(_PATH_DEV) - 1,
-                                   line);
+                                   ep->line);
                                if (stat(ftty, &statb) == 0) {
                                        if (!(statb.st_mode & 020))
                                                continue;
                                        if (statb.st_atime > best) {
                                                best = statb.st_atime;
-                                               (void) strcpy(tty, line);
+                                               (void) strcpy(tty, ep->line);
                                                status = SUCCESS;
                                                continue;
                                        }
                                }
                        }
-                       if (strcmp(line, tty) == 0) {
+                       if (strcmp(ep->line, tty) == 0) {
                                status = SUCCESS;
                                break;
                        }
                }
-       fclose(fd);
+
        return (status);
 }
index 4c1b8c8..2117052 100644 (file)
@@ -2,8 +2,15 @@
 # $FreeBSD: src/usr.bin/finger/Makefile,v 1.1.1.1.14.2 2001/04/25 11:29:20 ru Exp $
 # $DragonFly: src/usr.bin/finger/Makefile,v 1.3 2007/08/27 16:50:53 pavalos Exp $
 
+.PATH: ${.CURDIR}/../../usr.bin/who
+
 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
 MAN=   finger.1 finger.conf.5
 
+DPADD+=        ${LIBUTIL}
+LDADD+=        -lutil
+
+CFLAGS+= -I${.CURDIR}/../../usr.bin/who -DSUPPORT_UTMP -DSUPPORT_UTMPX
+
 .include <bsd.prog.mk>
index 4089f76..388b592 100644 (file)
@@ -73,7 +73,7 @@
 #include <string.h>
 #include <time.h>
 #include <unistd.h>
-#include <utmp.h>
+#include "utmpentry.h"
 #include <locale.h>
 
 #include "finger.h"
@@ -223,19 +223,13 @@ loginlist(void)
        PERSON *pn;
        DBT data, key;
        struct passwd *pw;
-       struct utmp user;
+       struct utmpentry *ep;
        int r, sflag1;
-       char name[UT_NAMESIZE + 1];
 
-       if (!freopen(_PATH_UTMP, "r", stdin))
-               err(1, "%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) {
-                       bcopy(user.ut_name, name, UT_NAMESIZE);
-                       if ((pw = getpwnam(name)) == NULL)
+       getutentries(NULL, &ep);
+       for (; ep; ep = ep->next) {
+               if ((pn = find_person(ep->name)) == NULL) {
+                       if ((pw = getpwnam(ep->name)) == NULL)
                                continue;
                        if (hide(pw))
                                continue;
@@ -262,7 +256,7 @@ userlist(int argc, char **argv)
 {
        PERSON *pn;
        DBT data, key;
-       struct utmp user;
+       struct utmpentry *ep;
        struct passwd *pw;
        int r, sflag1, *used, *ip;
        char **ap, **nargv, **np, **p;
@@ -367,12 +361,9 @@ net:       for (p = nargv; *p;) {
         * 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])
-                       continue;
-               if ((pn = find_person(user.ut_name)) == NULL)
+       getutentries(NULL, &ep);
+       for (; ep; ep = ep->next) {
+               if ((pn = find_person(ep->name)) == NULL)
                        continue;
                enter_where(&user, pn);
        }
index 554c38b..a3b793c 100644 (file)
@@ -240,8 +240,8 @@ main(int argc, char **argv)
                snprintf(tname, sizeof(tname), "%s??", _PATH_TTY);
                ttyn = tname;
        }
-       if ((tty = strrchr(ttyn, '/')) != NULL)
-               ++tty;
+       if (strncmp(ttyn, _PATH_DEV, sizeof(_PATH_DEV) -1) == 0)
+               tty = ttyn + sizeof(_PATH_DEV) -1;
        else
                tty = ttyn;
 
index eb67d47..2d8d1f7 100644 (file)
@@ -1,14 +1,22 @@
 #      @(#)Makefile    8.1 (Berkeley) 6/6/93
 #      $DragonFly: src/usr.bin/systat/Makefile,v 1.7 2008/11/10 04:59:45 swildner Exp $
 
+.PATH: ${.CURDIR}/../../usr.bin/who
+
 PROG=  systat
 CFLAGS+=-DINET6 -I${.CURDIR}/../../sys
 SRCS=  cmds.c cmdtab.c convtbl.c devs.c fetch.c ifcmds.c ifstat.c iostat.c \
        keyboard.c main.c mbufs.c netcmds.c netstat.c pigs.c sensors.c swap.c \
-       icmp.c mode.c ip.c tcp.c vmstat.c ip6.c icmp6.c vmmeter.c symbols.c
+       icmp.c mode.c ip.c tcp.c vmstat.c ip6.c icmp6.c vmmeter.c symbols.c \
+       utmpentry.c
 DPADD= ${LIBCURSES} ${LIBTERMCAP} ${LIBM} ${LIBKVM} ${LIBDEVSTAT} ${LIBKINFO}
 LDADD= -lcurses -ltermcap -lm -lkvm -ldevstat -lkinfo
 BINGRP=        kmem
 BINMODE=2555
 
+DPADD+=        ${LIBUTIL}
+LDADD+=        -lutil
+
+CFLAGS+= -I${.CURDIR}/../../usr.bin/who -DSUPPORT_UTMP -DSUPPORT_UTMPX
+
 .include <bsd.prog.mk>
index 87e1e5a..2ff380b 100644 (file)
@@ -63,7 +63,7 @@
 #include <string.h>
 #include <time.h>
 #include <unistd.h>
-#include <utmp.h>
+#include "utmpentry.h"
 #include <devstat.h>
 #include "systat.h"
 #include "extern.h"
@@ -109,7 +109,6 @@ static void putlongdoublez(long double, int, int, int, int, int);
 static int ucount(void);
 
 static int ncpu;
-static int ut;
 static char buf[26];
 static time_t t;
 static double etime;
@@ -119,16 +118,12 @@ static    char **intrname;
 static int nextintsrow;
 static  int extended_vm_stats;
 
-struct utmp utmp;
 
 
 WINDOW *
 openkre(void)
 {
 
-       ut = open(_PATH_UTMP, O_RDONLY);
-       if (ut < 0)
-               error("No utmp");
        return (stdscr);
 }
 
@@ -136,7 +131,6 @@ void
 closekre(WINDOW *w)
 {
 
-       (void) close(ut);
        if (w == NULL)
                return;
        wclear(w);
@@ -646,15 +640,13 @@ cmdkre(const char *cmd, char *args)
 static int
 ucount(void)
 {
+       struct utmpentry *ep;
        int nusers = 0;
 
-       if (ut < 0)
-               return (0);
-       while (read(ut, &utmp, sizeof(utmp)))
-               if (utmp.ut_name[0] != '\0')
-                       nusers++;
+       getutentries(NULL, &ep);
+       for (; ep; ep = ep->next)
+               nusers++;
 
-       lseek(ut, 0L, L_SET);
        return (nusers);
 }
 
index 6b9ad03..cf0929c 100644 (file)
@@ -1,6 +1,13 @@
 #      @(#)Makefile    8.1 (Berkeley) 6/6/93
 # $DragonFly: src/usr.bin/users/Makefile,v 1.3 2007/08/27 16:51:00 pavalos Exp $
+.PATH: ${.CURDIR}/../../usr.bin/who
 
 PROG=  users
+SRCS=  users.c utmpentry.c
+
+DPADD= ${LIBUTIL}
+LDADD= -lutil
+
+CFLAGS+= -I${.CURDIR}/../../usr.bin/who -DSUPPORT_UTMP -DSUPPORT_UTMPX
 
 .include <bsd.prog.mk>
index 473312e..a0ae65e 100644 (file)
@@ -42,9 +42,9 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
-#include <utmp.h>
+#include "utmpentry.h"
 
-typedef char   namebuf[UT_NAMESIZE];
+typedef char   namebuf[32];
 
 static int scmp(const void *, const void *);
 static void usage(void);
@@ -52,11 +52,11 @@ static void usage(void);
 int
 main(int argc, char **argv)
 {
+       struct utmpentry *ep;
        namebuf *names = NULL;
        int ncnt = 0;
        int nmax = 0;
        int cnt;
-       struct utmp utmp;
        int ch;
 
        while ((ch = getopt(argc, argv, "")) != -1) {
@@ -68,27 +68,24 @@ main(int argc, char **argv)
        argc -= optind;
        argv += optind;
 
-       if (!freopen(_PATH_UTMP, "r", stdin))
-               err(1, "can't open %s", _PATH_UTMP);
-       while (fread((char *)&utmp, sizeof(utmp), 1, stdin) == 1) {
-               if (*utmp.ut_name) {
-                       if (ncnt >= nmax) {
-                               nmax += 32;
-                               names = realloc(names,
-                                       sizeof (*names) * nmax);
-                               if (names == NULL)
-                                       err(1, "realloc");
-                       }
-                       strncpy(names[ncnt], utmp.ut_name, UT_NAMESIZE);
-                       ++ncnt;
+       getutentries(NULL, &ep);
+       for (; ep; ep = ep->next) {
+               if (ncnt >= nmax) {
+                       nmax += 32;
+                       names = realloc(names,
+                               sizeof (*names) * nmax);
+                       if (names == NULL)
+                               err(1, "realloc");
                }
+               strcpy(names[ncnt], ep->name);
+               ++ncnt;
        }
        if (ncnt) {
-               qsort(names, ncnt, UT_NAMESIZE, scmp);
-               printf("%.*s", UT_NAMESIZE, names[0]);
+               qsort(names, ncnt, 32, scmp);
+               printf("%.*s", 32, names[0]);
                for (cnt = 1; cnt < ncnt; ++cnt) {
-                       if (strncmp(names[cnt], names[cnt - 1], UT_NAMESIZE))
-                               printf(" %.*s", UT_NAMESIZE, names[cnt]);
+                       if (strcmp(names[cnt], names[cnt - 1]))
+                               printf(" %.*s", 32, names[cnt]);
                }
                printf("\n");
        }
@@ -105,5 +102,5 @@ usage(void)
 int
 scmp(const void *p, const void *q)
 {
-       return(strncmp(p, q, UT_NAMESIZE));
+       return(strncmp(p, q, 32));
 }
index 5830767..023748b 100644 (file)
@@ -84,7 +84,9 @@
 #include "extern.h"
 
 struct timeval boottime;
+#ifdef SUPPORT_UTMP
 struct utmp    utmp;
+#endif
 struct winsize ws;
 kvm_t         *kd;
 time_t         now;            /* the current time of day */
@@ -138,7 +140,6 @@ main(int argc, char **argv)
        struct kinfo_proc *kp;
        struct kinfo_proc *dkp;
        struct hostent *hp;
-       struct stat *stp;
        in_addr_t l;
        int ch, i, nentries, nusers, wcmd, longidle, dropgid;
        char *memf, *nlistf, *p, *x;
@@ -237,7 +238,7 @@ main(int argc, char **argv)
 
                        usermatch = 0;
                        for (user = sel_users; !usermatch && *user; user++)
-                               if (!strncmp(utx->ut_name, *user, UT_NAMESIZE))
+                               if (!strncmp(utx->ut_name, *user, UTX_USERSIZE))
                                        usermatch = 1;
                        if (!usermatch)
                                continue;
@@ -276,8 +277,6 @@ main(int argc, char **argv)
        while ((ut = getutent()) != NULL) {
                if (ut->ut_name[0] == '\0')
                        continue;
-               if (!(stp = ttystat(ut->ut_line, UT_LINESIZE)))
-                       continue;       /* corrupted record */
                ++nusers;
                if (sel_users) {
                        int usermatch;
@@ -338,7 +337,7 @@ main(int argc, char **argv)
 #define HEADER_FROM            "FROM"
 #define HEADER_LOGIN_IDLE      "LOGIN@  IDLE "
 #define HEADER_WHAT            "WHAT\n"
-#define WUSED  (UT_NAMESIZE + UT_LINESIZE + UT_HOSTSIZE + \
+#define WUSED  (maxname + maxline + maxhost + \
                sizeof(HEADER_LOGIN_IDLE) + 3)  /* header width incl. spaces */ 
                (void)printf("%-*.*s %-*.*s %-*.*s  %s", 
                                maxname, maxname, HEADER_USER,
@@ -445,9 +444,9 @@ main(int argc, char **argv)
        }
 
        for (ep = ehead; ep != NULL; ep = ep->next) {
-               char host_buf[UT_HOSTSIZE + 1];
+               char host_buf[UTX_HOSTSIZE + 1];
 
-               host_buf[UT_HOSTSIZE] = '\0';
+               host_buf[UTX_HOSTSIZE] = '\0';
                strncpy(host_buf, ep->host, maxhost);
                p = *host_buf ? host_buf : "-";
                if ((x = strchr(p, ':')) != NULL)
index 46967ae..e0ceefb 100644 (file)
@@ -1,9 +1,16 @@
 #      @(#)Makefile    8.1 (Berkeley) 6/6/93
 # $DragonFly: src/usr.bin/wall/Makefile,v 1.2 2007/08/27 16:51:01 pavalos Exp $
 
+.PATH: ${.CURDIR}/../../usr.bin/who
+
 PROG=  wall
-SRCS=  ttymsg.c wall.c
+SRCS=  ttymsg.c wall.c utmpentry.c
 BINGRP=        tty
 BINMODE=2555
 
+DPADD+=        ${LIBUTIL}
+LDADD+=        -lutil
+
+CFLAGS+= -I${.CURDIR}/../../usr.bin/who -DSUPPORT_UTMP -DSUPPORT_UTMPX
+
 .include <bsd.prog.mk>
index c5733e6..72dfae8 100644 (file)
@@ -56,7 +56,7 @@
 #include <string.h>
 #include <time.h>
 #include <unistd.h>
-#include <utmp.h>
+#include "utmpentry.h"
 
 #include "ttymsg.h"
 
@@ -76,7 +76,7 @@ int
 main(int argc, char *argv[])
 {
        struct iovec iov;
-       struct utmp utmp;
+       struct utmpentry *ep;
        int ch;
        int ingroup;
        FILE *fp;
@@ -85,8 +85,6 @@ main(int argc, char *argv[])
        char **np;
        const char *p;
        struct passwd *pw;
-       char line[sizeof(utmp.ut_line) + 1];
-       char username[sizeof(utmp.ut_name) + 1];
 
        (void)setlocale(LC_CTYPE, "");
 
@@ -123,18 +121,15 @@ main(int argc, char *argv[])
 
        makemsg(*argv);
 
-       if (!(fp = fopen(_PATH_UTMP, "r")))
-               err(1, "cannot read %s", _PATH_UTMP);
        iov.iov_base = mbuf;
        iov.iov_len = mbufsize;
+
+       getutentries(NULL, &ep);
        /* NOSTRICT */
-       while (fread((char *)&utmp, sizeof(utmp), 1, fp) == 1) {
-               if (!utmp.ut_name[0])
-                       continue;
+       for (; ep; ep = ep->next) {
                if (grouplist) {
                        ingroup = 0;
-                       strlcpy(username, utmp.ut_name, sizeof(utmp.ut_name));
-                       pw = getpwnam(username);
+                       pw = getpwnam(ep->name);
                        if (!pw)
                                continue;
                        for (g = grouplist; g && ingroup == 0; g = g->next) {
@@ -154,9 +149,11 @@ main(int argc, char *argv[])
                        if (ingroup == 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)
+               /* skip [xgk]dm/xserver entries (":0", ":1", etc.) */
+               if (ep->line[0] == ':' && isdigit((unsigned char)ep->line[1]))
+                       continue;
+               
+               if ((p = ttymsg(&iov, 1, ep->line, 60*5)) != NULL)
                        warnx("%s", p);
        }
        exit(0);
index a76bb99..cfb6b4a 100644 (file)
@@ -1,8 +1,16 @@
 #      @(#)Makefile    8.1 (Berkeley) 6/6/93
 # $DragonFly: src/usr.bin/write/Makefile,v 1.3 2007/08/27 16:51:01 pavalos Exp $
 
+.PATH: ${.CURDIR}/../../usr.bin/who
+
 PROG=  write
+SRCS=  write.c utmpentry.c
 BINMODE=2555
 BINGRP=        tty
 
+DPADD+=        ${LIBUTIL}
+LDADD+=        -lutil
+
+CFLAGS+= -I${.CURDIR}/../../usr.bin/who -DSUPPORT_UTMP -DSUPPORT_UTMPX
+
 .include <bsd.prog.mk>
index fb2daac..1b461a9 100644 (file)
@@ -54,7 +54,7 @@
 #include <signal.h>
 #include <time.h>
 #include <unistd.h>
-#include <utmp.h>
+#include "utmpentry.h"
 
 static void    done(int);
 static void    do_write(const char *, const char *, uid_t, int *);
@@ -132,21 +132,17 @@ usage(void)
 static 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)
-               err(1, "open failed: %s\n", _PATH_UTMP);
+       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) {
-                       close(ufd);
+       for (; ep; ep = ep->next) {
+               if (strcmp(user, ep->name) == 0 &&
+                   strcmp(tty, ep->line) == 0) {
                        return(0);
                }
        }
 
-       close(ufd);
        return(1);
 }
 
@@ -164,37 +160,33 @@ utmp_chk(const char *user, const char *tty)
 static void
 search_utmp(const char *user, char *tty, size_t ttyl, const char *mytty, uid_t myuid)
 {
-       struct utmp u;
+       struct utmpentry *ep;
        time_t bestatime, atime;
-       int ufd, nloggedttys, nttys, msgsok, user_is_me;
-       char atty[UT_LINESIZE + 1];
+       int nloggedttys, nttys, msgsok, user_is_me;
 
-       if ((ufd = open(_PATH_UTMP, O_RDONLY)) < 0)
-               err(1, "open failed: %s", _PATH_UTMP);
+       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;
-                       strlcpy(atty, u.ut_line, ttyl);
-                       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;
-                               strlcpy(tty, atty, ttyl);
+                               strlcpy(tty, ep->line, ttyl);
                        }
                }
 
-       close(ufd);
        if (nloggedttys == 0)
                errx(1, "%s is not logged in", user);
        if (nttys == 0) {
index 147b496..29a488e 100644 (file)
@@ -2,16 +2,18 @@
 # $FreeBSD: src/usr.sbin/syslogd/Makefile,v 1.14 2008/12/17 16:51:40 obrien Exp $
 # $DragonFly: src/usr.sbin/syslogd/Makefile,v 1.3 2004/08/09 20:11:19 dillon Exp $
 
-.PATH: ${.CURDIR}/../../usr.bin/wall ${.CURDIR}/../nscd
+.PATH: ${.CURDIR}/../../usr.bin/wall ${.CURDIR}/../nscd ${.CURDIR}/../../usr.bin/who
 
 PROG=  syslogd
 MAN=   syslog.conf.5 syslogd.8
-SRCS=  pidfile.c syslogd.c ttymsg.c
+SRCS=  pidfile.c syslogd.c ttymsg.c utmpentry.c
 
 DPADD= ${LIBUTIL}
 LDADD= -lutil
 
 CFLAGS+= -DINET6
 CFLAGS+= -I${.CURDIR}/../../usr.bin/wall
+CFLAGS+= -I${.CURDIR}/../../usr.bin/who -DSUPPORT_UTMP -DSUPPORT_UTMPX
+
 
 .include <bsd.prog.mk>
index 4aca424..d76415a 100644 (file)
@@ -96,7 +96,7 @@
 #include <string.h>
 #include <sysexits.h>
 #include <unistd.h>
-#include <utmp.h>
+#include "utmpentry.h"
 
 #include "pathnames.h"
 #include "ttymsg.h"
@@ -1355,28 +1355,25 @@ static void
 wallmsg(struct filed *f, struct iovec *iov, const int iovlen)
 {
        static int reenter;                     /* avoid calling ourselves */
-       FILE *uf;
-       struct utmp ut;
+
+       struct utmpentry *ep;
        int i;
        const char *p;
-       char line[sizeof(ut.ut_line) + 1];
 
        if (reenter++)
                return;
-       if ((uf = fopen(_PATH_UTMP, "r")) == NULL) {
+
+       getutentries(NULL, &ep);
+       if (ep == NULL) {
                logerror(_PATH_UTMP);
                reenter = 0;
                return;
        }
        /* NOSTRICT */
-       while (fread((char *)&ut, sizeof(ut), 1, uf) == 1) {
-               if (ut.ut_name[0] == '\0')
-                       continue;
+       for (; ep; ep = ep->next) {
                /* We must use strncpy since ut_* may not be NUL terminated. */
-               strncpy(line, ut.ut_line, sizeof(line) - 1);
-               line[sizeof(line) - 1] = '\0';
                if (f->f_type == F_WALL) {
-                       if ((p = ttymsg(iov, iovlen, line, TTYMSGTIME)) !=
+                       if ((p = ttymsg(iov, iovlen, ep->line, TTYMSGTIME)) !=
                            NULL) {
                                errno = 0;      /* already in msg */
                                logerror(p);
@@ -1387,9 +1384,8 @@ wallmsg(struct filed *f, struct iovec *iov, const int iovlen)
                for (i = 0; i < MAXUNAMES; i++) {
                        if (!f->f_un.f_uname[i][0])
                                break;
-                       if (!strncmp(f->f_un.f_uname[i], ut.ut_name,
-                           UT_NAMESIZE)) {
-                               if ((p = ttymsg(iov, iovlen, line, TTYMSGTIME))
+                       if (!strcmp(f->f_un.f_uname[i], ep->name)) {
+                               if ((p = ttymsg(iov, iovlen, ep->line, TTYMSGTIME))
                                    != NULL) {
                                        errno = 0;      /* already in msg */
                                        logerror(p);
@@ -1398,7 +1394,6 @@ wallmsg(struct filed *f, struct iovec *iov, const int iovlen)
                        }
                }
        }
-       fclose(uf);
        reenter = 0;
 }