From owner-svn-src-head@FreeBSD.ORG Tue Dec 29 10:28:21 2009 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 18CDE106568D; Tue, 29 Dec 2009 10:28:21 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 082508FC0A; Tue, 29 Dec 2009 10:28:21 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id nBTASKFu019919; Tue, 29 Dec 2009 10:28:20 GMT (envelope-from ed@svn.freebsd.org) Received: (from ed@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id nBTASKLq019915; Tue, 29 Dec 2009 10:28:20 GMT (envelope-from ed@svn.freebsd.org) Message-Id: <200912291028.nBTASKLq019915@svn.freebsd.org> From: Ed Schouten Date: Tue, 29 Dec 2009 10:28:20 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r201192 - head/libexec/rpc.rusersd X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 29 Dec 2009 10:28:21 -0000 Author: ed Date: Tue Dec 29 10:28:20 2009 New Revision: 201192 URL: http://svn.freebsd.org/changeset/base/201192 Log: 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. Modified: head/libexec/rpc.rusersd/Makefile head/libexec/rpc.rusersd/rusers_proc.c head/libexec/rpc.rusersd/rusersd.c Modified: head/libexec/rpc.rusersd/Makefile ============================================================================== --- head/libexec/rpc.rusersd/Makefile Tue Dec 29 10:15:13 2009 (r201191) +++ head/libexec/rpc.rusersd/Makefile Tue Dec 29 10:28:20 2009 (r201192) @@ -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 Modified: head/libexec/rpc.rusersd/rusers_proc.c ============================================================================== --- head/libexec/rpc.rusersd/rusers_proc.c Tue Dec 29 10:15:13 2009 (r201191) +++ head/libexec/rpc.rusersd/rusers_proc.c Tue Dec 29 10:28:20 2009 (r201192) @@ -45,56 +45,27 @@ static const char rcsid[] = #include #include #include -#include +#define _ULOG_POSIX_NAMES +#include #ifdef XIDLE #include #include #include #endif -#define utmp rutmp #include -#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; - /* 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++; - } + 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); } Modified: head/libexec/rpc.rusersd/rusersd.c ============================================================================== --- head/libexec/rpc.rusersd/rusersd.c Tue Dec 29 10:15:13 2009 (r201191) +++ head/libexec/rpc.rusersd/rusersd.c Tue Dec 29 10:28:20 2009 (r201192) @@ -41,9 +41,7 @@ static const char rcsid[] = #include #include #include -#define utmp rutmp #include -#undef utmp extern void rusers_service(struct svc_req *, SVCXPRT *);