diff options
author | ed <ed@FreeBSD.org> | 2009-12-29 10:28:20 +0000 |
---|---|---|
committer | ed <ed@FreeBSD.org> | 2009-12-29 10:28:20 +0000 |
commit | e11903ba0f4151c5e58486d06056e4fe4d95921d (patch) | |
tree | 5205cf2c26fc16eceb25d09e48a8e3132ace43d9 /libexec | |
parent | 3e6eb7c320d041ffd07edbcca18a8c594debe9ec (diff) | |
download | FreeBSD-src-e11903ba0f4151c5e58486d06056e4fe4d95921d.zip FreeBSD-src-e11903ba0f4151c5e58486d06056e4fe4d95921d.tar.gz |
Make rpc.ruserd work with utmpx/libulog.
Because strings are now null-terminated, I've decided to just use an
array of utmpx structures, instead of the separated strings. This means
we just copy the entire utmpx structure and point to the strings within
the structures directly.
Diffstat (limited to 'libexec')
-rw-r--r-- | libexec/rpc.rusersd/Makefile | 4 | ||||
-rw-r--r-- | libexec/rpc.rusersd/rusers_proc.c | 121 | ||||
-rw-r--r-- | libexec/rpc.rusersd/rusersd.c | 2 |
3 files changed, 35 insertions, 92 deletions
diff --git a/libexec/rpc.rusersd/Makefile b/libexec/rpc.rusersd/Makefile index 3cc42a0..e88674b 100644 --- a/libexec/rpc.rusersd/Makefile +++ b/libexec/rpc.rusersd/Makefile @@ -6,8 +6,8 @@ MAN = rpc.rusersd.8 WARNS?= 6 -DPADD= ${LIBRPCSVC} ${LIBUTIL} -LDADD= -lrpcsvc -lutil +DPADD= ${LIBRPCSVC} ${LIBULOG} ${LIBUTIL} +LDADD= -lrpcsvc -lulog -lutil #.if exists(/usr/X11R6/include/X11/extensions/xidle.h) #CFLAGS+= -DXIDLE diff --git a/libexec/rpc.rusersd/rusers_proc.c b/libexec/rpc.rusersd/rusers_proc.c index 78ca29a..9b5486f 100644 --- a/libexec/rpc.rusersd/rusers_proc.c +++ b/libexec/rpc.rusersd/rusers_proc.c @@ -45,56 +45,27 @@ static const char rcsid[] = #include <sys/stat.h> #include <stdlib.h> #include <syslog.h> -#include <utmp.h> +#define _ULOG_POSIX_NAMES +#include <ulog.h> #ifdef XIDLE #include <setjmp.h> #include <X11/Xlib.h> #include <X11/extensions/xidle.h> #endif -#define utmp rutmp #include <rpcsvc/rnusers.h> -#undef utmp - -#define IGNOREUSER "sleeper" - -#ifdef OSF -#define _PATH_UTMP UTMP_FILE -#endif - -#ifndef _PATH_UTMP -#define _PATH_UTMP "/etc/utmp" -#endif #ifndef _PATH_DEV #define _PATH_DEV "/dev" #endif -#ifndef UT_LINESIZE -#define UT_LINESIZE sizeof(((struct utmp *)0)->ut_line) -#endif -#ifndef UT_NAMESIZE -#define UT_NAMESIZE sizeof(((struct utmp *)0)->ut_name) -#endif -#ifndef UT_HOSTSIZE -#define UT_HOSTSIZE sizeof(((struct utmp *)0)->ut_host) -#endif - -typedef char ut_line_t[UT_LINESIZE+1]; -typedef char ut_name_t[UT_NAMESIZE+1]; -typedef char ut_host_t[UT_HOSTSIZE+1]; - static utmpidle utmp_idle[MAXUSERS]; -static rutmp old_utmp[MAXUSERS]; -static ut_line_t line[MAXUSERS]; -static ut_name_t name[MAXUSERS]; -static ut_host_t host[MAXUSERS]; +static utmp old_utmp[MAXUSERS]; +static struct utmpx utmp_list[MAXUSERS]; extern int from_inetd; void rusers_service(struct svc_req *, SVCXPRT *); -static FILE *ufp; - #ifdef XIDLE static Display *dpy; @@ -190,48 +161,33 @@ static utmpidlearr * do_names_2(void) { static utmpidlearr ut; - struct utmp usr; + struct utmpx *usr; int nusers = 0; - bzero((char *)&ut, sizeof(ut)); + memset(&ut, 0, sizeof(ut)); ut.utmpidlearr_val = &utmp_idle[0]; - ufp = fopen(_PATH_UTMP, "r"); - if (!ufp) { - syslog(LOG_ERR, "%m"); - return(&ut); + setutxent(); + while ((usr = getutxent()) != NULL && nusers < MAXUSERS) { + if (usr->ut_type != USER_PROCESS) + continue; + + memcpy(&utmp_list[nusers], usr, sizeof(*usr)); + utmp_idle[nusers].ui_utmp.ut_time = usr->ut_tv.tv_sec; + utmp_idle[nusers].ui_idle = + getidle(usr->ut_line, usr->ut_host); + utmp_idle[nusers].ui_utmp.ut_line = + utmp_list[nusers].ut_line; + utmp_idle[nusers].ui_utmp.ut_name = + utmp_list[nusers].ut_user; + utmp_idle[nusers].ui_utmp.ut_host = + utmp_list[nusers].ut_host; + + nusers++; } - - /* only entries with both name and line fields */ - while (fread((char *)&usr, sizeof(usr), 1, ufp) == 1 && - nusers < MAXUSERS) - if (*usr.ut_name && *usr.ut_line && - strncmp(usr.ut_name, IGNOREUSER, - sizeof(usr.ut_name)) -#ifdef OSF - && usr.ut_type == USER_PROCESS -#endif - ) { - utmp_idle[nusers].ui_utmp.ut_time = - usr.ut_time; - utmp_idle[nusers].ui_idle = - getidle(usr.ut_line, usr.ut_host); - utmp_idle[nusers].ui_utmp.ut_line = line[nusers]; - strncpy(line[nusers], usr.ut_line, UT_LINESIZE); - utmp_idle[nusers].ui_utmp.ut_name = name[nusers]; - strncpy(name[nusers], usr.ut_name, UT_NAMESIZE); - utmp_idle[nusers].ui_utmp.ut_host = host[nusers]; - strncpy(host[nusers], usr.ut_host, UT_HOSTSIZE); - - /* Make sure entries are NUL terminated */ - line[nusers][UT_LINESIZE] = - name[nusers][UT_NAMESIZE] = - host[nusers][UT_HOSTSIZE] = '\0'; - nusers++; - } + endutxent(); ut.utmpidlearr_len = nusers; - fclose(ufp); return(&ut); } @@ -239,27 +195,16 @@ static int * rusers_num(void *argp __unused, struct svc_req *rqstp __unused) { static int num_users = 0; - struct utmp usr; - - ufp = fopen(_PATH_UTMP, "r"); - if (!ufp) { - syslog(LOG_ERR, "%m"); - return(NULL); + struct utmpx *usr; + + setutxent(); + while ((usr = getutxent()) != NULL) { + if (usr->ut_type != USER_PROCESS) + continue; + num_users++; } - - /* only entries with both name and line fields */ - while (fread((char *)&usr, sizeof(usr), 1, ufp) == 1) - if (*usr.ut_name && *usr.ut_line && - strncmp(usr.ut_name, IGNOREUSER, - sizeof(usr.ut_name)) -#ifdef OSF - && usr.ut_type == USER_PROCESS -#endif - ) { - num_users++; - } - - fclose(ufp); + endutxent(); + return(&num_users); } diff --git a/libexec/rpc.rusersd/rusersd.c b/libexec/rpc.rusersd/rusersd.c index c05ca84..009bbfd 100644 --- a/libexec/rpc.rusersd/rusersd.c +++ b/libexec/rpc.rusersd/rusersd.c @@ -41,9 +41,7 @@ static const char rcsid[] = #include <sys/socket.h> #include <signal.h> #include <syslog.h> -#define utmp rutmp #include <rpcsvc/rnusers.h> -#undef utmp extern void rusers_service(struct svc_req *, SVCXPRT *); |