diff options
Diffstat (limited to 'usr.bin/finger/finger.c')
-rw-r--r-- | usr.bin/finger/finger.c | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/usr.bin/finger/finger.c b/usr.bin/finger/finger.c index b278752..ae2766f 100644 --- a/usr.bin/finger/finger.c +++ b/usr.bin/finger/finger.c @@ -83,7 +83,7 @@ __FBSDID("$FreeBSD$"); #include <string.h> #include <time.h> #include <unistd.h> -#include <utmp.h> +#include <utmpx.h> #include <locale.h> #include "finger.h" @@ -233,29 +233,26 @@ loginlist(void) PERSON *pn; DBT data, key; struct passwd *pw; - struct utmp user; + struct utmpx *user; int r, sflag1; - char name[UT_NAMESIZE + 1]; if (kflag) errx(1, "can't list logins without reading utmp"); - 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]) + setutxent(); + while ((user = getutxent()) != NULL) { + if (user->ut_type != USER_PROCESS) continue; - if ((pn = find_person(user.ut_name)) == NULL) { - bcopy(user.ut_name, name, UT_NAMESIZE); - if ((pw = getpwnam(name)) == NULL) + if ((pn = find_person(user->ut_user)) == NULL) { + if ((pw = getpwnam(user->ut_user)) == NULL) continue; if (hide(pw)) continue; pn = enter_person(pw); } - enter_where(&user, pn); + enter_where(user, pn); } + endutxent(); if (db && lflag) for (sflag1 = R_FIRST;; sflag1 = R_NEXT) { PERSON *tmp; @@ -275,7 +272,7 @@ userlist(int argc, char **argv) { PERSON *pn; DBT data, key; - struct utmp user; + struct utmpx *user; struct passwd *pw; int r, sflag1, *used, *ip; char **ap, **nargv, **np, **p; @@ -373,6 +370,7 @@ net: for (p = nargv; *p;) { printf("\n"); } + free(used); if (entries == 0) return; @@ -383,15 +381,15 @@ 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]) + setutxent(); + while ((user = getutxent()) != NULL) { + if (user->ut_type != USER_PROCESS) continue; - if ((pn = find_person(user.ut_name)) == NULL) + if ((pn = find_person(user->ut_user)) == NULL) continue; - enter_where(&user, pn); + enter_where(user, pn); } + endutxent(); if (db) for (sflag1 = R_FIRST;; sflag1 = R_NEXT) { PERSON *tmp; |