diff options
Diffstat (limited to 'libexec/talkd/process.c')
-rw-r--r-- | libexec/talkd/process.c | 31 |
1 files changed, 12 insertions, 19 deletions
diff --git a/libexec/talkd/process.c b/libexec/talkd/process.c index d77f8a168bf4..c6ec34d47147 100644 --- a/libexec/talkd/process.c +++ b/libexec/talkd/process.c @@ -59,6 +59,8 @@ static const char rcsid[] = #include <stdio.h> #include <string.h> #include <syslog.h> +#define _ULOG_POSIX_NAMES +#include <ulog.h> #include "extern.h" @@ -181,55 +183,46 @@ do_announce(CTL_MSG *mp, CTL_RESPONSE *rp) } } -#include <utmp.h> - /* * Search utmp for the local user */ int find_user(const char *name, char *tty) { - struct utmp ubuf; + struct utmpx *ut; 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) - 1 + sizeof(ut->ut_line)]; - 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)) + setutxent(); 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'; + while ((ut = getutxent()) != NULL) + if (ut->ut_type == USER_PROCESS && + strcmp(ut->ut_user, 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); + ut->ut_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, ut->ut_line); status = SUCCESS; continue; } } } - if (strcmp(line, tty) == 0) { + if (strcmp(ut->ut_line, tty) == 0) { status = SUCCESS; break; } } - fclose(fd); + endutxent(); return (status); } |