From 7ba29497ff3f164e2a507eda35e81f1cb0658c74 Mon Sep 17 00:00:00 2001 From: Ken Hornstein Date: Tue, 17 Jan 2012 10:57:54 -0500 Subject: [PATCH] Convert from utmp functions to utmpx functions (which are in POSIX). --- configure.ac | 4 +--- uip/rcvtty.c | 47 +++++++--------------------------------------- uip/slocal.c | 59 ++++++++-------------------------------------------------- 3 files changed, 16 insertions(+), 94 deletions(-) diff --git a/configure.ac b/configure.ac index 3491f96..18b4ab3 100644 --- a/configure.ac +++ b/configure.ac @@ -510,7 +510,7 @@ AC_CHECK_HEADER([sys/ptem.h], AC_DEFINE(WINSIZE_IN_PTEM,1, dnl --------------- dnl CHECK FUNCTIONS dnl --------------- -AC_CHECK_FUNCS(writev lstat getutent nl_langinfo) +AC_CHECK_FUNCS(writev lstat nl_langinfo) dnl Check for multibyte character set support if test "x$ac_cv_header_wchar_h" = "xyes" -a "x$ac_cv_header_wctype_h" = "xyes" \ @@ -767,8 +767,6 @@ dnl ---------------- dnl CHECK STRUCTURES dnl ---------------- -AC_CHECK_MEMBERS(struct utmp.ut_type,,,[#include ]) - AC_STRUCT_DIRENT_D_TYPE dnl Where is located? Needed as input for signames.awk diff --git a/uip/rcvtty.c b/uip/rcvtty.c index 1ae8576..8e659ff 100644 --- a/uip/rcvtty.c +++ b/uip/rcvtty.c @@ -22,17 +22,7 @@ #include #include -#include - -#ifndef HAVE_GETUTENT -# ifndef UTMP_FILE -# ifdef _PATH_UTMP -# define UTMP_FILE _PATH_UTMP -# else -# define UTMP_FILE "/etc/utmp" -# endif -# endif -#endif +#include #define SCANFMT \ "%2(hour{dtimenow}):%02(min{dtimenow}): %<(size)%5(size) %>%<{encrypted}E%>\ @@ -91,13 +81,7 @@ main (int argc, char **argv) int md, vecp = 0; char *cp, *user, buf[BUFSIZ], tty[BUFSIZ]; char **argp, **arguments, *vec[MAXARGS]; -#ifdef HAVE_GETUTENT - struct utmp * utp; -#else - struct utmp ut; - register FILE *uf; -#endif - + struct utmpx *utp; #ifdef LOCALE setlocale(LC_ALL, ""); #endif @@ -172,33 +156,16 @@ main (int argc, char **argv) user = getusername(); -#ifdef HAVE_GETUTENT - setutent(); - while ((utp = getutent()) != NULL) { - if ( -#ifdef HAVE_STRUCT_UTMP_UT_TYPE - utp->ut_type == USER_PROCESS - && -#endif - utp->ut_name[0] != 0 + setutxent(); + while ((utp = getutxent()) != NULL) { + if (utp->ut_type == USER_PROCESS && utp->ut_user[0] != 0 && utp->ut_line[0] != 0 - && strncmp (user, utp->ut_name, sizeof(utp->ut_name)) == 0) { + && strncmp (user, utp->ut_user, sizeof(utp->ut_user)) == 0) { strncpy (tty, utp->ut_line, sizeof(utp->ut_line)); alert (tty, md); } } - endutent(); -#else - if ((uf = fopen (UTMP_FILE, "r")) == NULL) - exit (RCV_MBX); - while (fread ((char *) &ut, sizeof(ut), 1, uf) == 1) - if (ut.ut_name[0] != 0 - && strncmp (user, ut.ut_name, sizeof(ut.ut_name)) == 0) { - strncpy (tty, ut.ut_line, sizeof(ut.ut_line)); - alert (tty, md); - } - fclose (uf); -#endif + endutxent(); exit (RCV_MOK); return 0; /* dead code to satisfy the compiler */ diff --git a/uip/slocal.c b/uip/slocal.c index d701e78..5026d82 100644 --- a/uip/slocal.c +++ b/uip/slocal.c @@ -51,17 +51,7 @@ #include NDBM_HEADER #endif -#include - -#ifndef HAVE_GETUTENT -# ifndef UTMP_FILE -# ifdef _PATH_UTMP -# define UTMP_FILE _PATH_UTMP -# else -# define UTMP_FILE "/etc/utmp" -# endif -# endif -#endif +#include static struct swit switches[] = { #define ADDRSW 0 @@ -937,62 +927,29 @@ lookup (struct pair *pairs, char *key) * logged in. */ -#ifdef HAVE_GETUTENT static int logged_in (void) { - struct utmp * utp; + struct utmpx *utp; if (utmped) return utmped; - setutent(); + setutxent(); - while ((utp = getutent()) != NULL) { - if ( -#ifdef HAVE_STRUCT_UTMP_UT_TYPE - utp->ut_type == USER_PROCESS - && -#endif - utp->ut_name[0] != 0 - && strncmp (user, utp->ut_name, sizeof(utp->ut_name)) == 0) { + while ((utp = getutxent()) != NULL) { + if ( utp->ut_type == USER_PROCESS && utp->ut_user[0] != 0 + && strncmp (user, utp->ut_user, sizeof(utp->ut_user)) == 0) { if (debug) continue; - endutent(); + endutxent(); return (utmped = DONE); } } - endutent(); + endutxent(); return (utmped = NOTOK); } -#else -static int -logged_in (void) -{ - struct utmp ut; - FILE *uf; - - if (utmped) - return utmped; - - if ((uf = fopen (UTMP_FILE, "r")) == NULL) - return NOTOK; - - while (fread ((char *) &ut, sizeof(ut), 1, uf) == 1) { - if (ut.ut_name[0] != 0 - && strncmp (user, ut.ut_name, sizeof(ut.ut_name)) == 0) { - if (debug) - continue; - fclose (uf); - return (utmped = DONE); - } - } - - fclose (uf); - return (utmped = NOTOK); -} -#endif #define check(t,a,b) if (t < a || t > b) return -1 #define cmpar(h1,m1,h2,m2) if (h1 < h2 || (h1 == h2 && m1 < m2)) return 0 -- 1.7.10.4