# $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>
#include <string.h>
#include <time.h>
#include <unistd.h>
-#include <utmp.h>
+#include "utmpentry.h"
#include "pathnames.h"
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);
}
# @(#)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>
#include <stdio.h>
#include <string.h>
#include <syslog.h>
-#include <utmp.h>
+#include "utmpentry.h"
#include "extern.h"
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);
}
# $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>
#include <string.h>
#include <time.h>
#include <unistd.h>
-#include <utmp.h>
+#include "utmpentry.h"
#include <locale.h>
#include "finger.h"
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;
{
PERSON *pn;
DBT data, key;
- struct utmp user;
+ struct utmpentry *ep;
struct passwd *pw;
int r, sflag1, *used, *ip;
char **ap, **nargv, **np, **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);
}
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;
# @(#)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>
#include <string.h>
#include <time.h>
#include <unistd.h>
-#include <utmp.h>
+#include "utmpentry.h"
#include <devstat.h>
#include "systat.h"
#include "extern.h"
static int ucount(void);
static int ncpu;
-static int ut;
static char buf[26];
static time_t t;
static double etime;
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);
}
closekre(WINDOW *w)
{
- (void) close(ut);
if (w == NULL)
return;
wclear(w);
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);
}
# @(#)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>
#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);
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) {
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");
}
int
scmp(const void *p, const void *q)
{
- return(strncmp(p, q, UT_NAMESIZE));
+ return(strncmp(p, q, 32));
}
#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 */
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;
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;
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;
#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,
}
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)
# @(#)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>
#include <string.h>
#include <time.h>
#include <unistd.h>
-#include <utmp.h>
+#include "utmpentry.h"
#include "ttymsg.h"
main(int argc, char *argv[])
{
struct iovec iov;
- struct utmp utmp;
+ struct utmpentry *ep;
int ch;
int ingroup;
FILE *fp;
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, "");
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) {
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);
# @(#)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>
#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 *);
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);
}
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) {
# $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>
#include <string.h>
#include <sysexits.h>
#include <unistd.h>
-#include <utmp.h>
+#include "utmpentry.h"
#include "pathnames.h"
#include "ttymsg.h"
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);
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);
}
}
}
- fclose(uf);
reenter = 0;
}