From: Ruud de Rooij Date: Sun, 28 May 2000 16:17:49 +0000 (+0000) Subject: * Added autoconf check for getutent(). X-Git-Tag: kim-before-sasl~22 X-Git-Url: http://git.marmaro.de/?a=commitdiff_plain;h=522138c8d86c20435f045eaee0944a9b008b1c5a;p=mmh * Added autoconf check for getutent(). * Changed uip/rcvtty.c and uip/slocal.c to use getutent() and friends. Since I can only check on Linux, please check if this works on other systems. --- diff --git a/ChangeLog b/ChangeLog index 53201cb..6134234 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Sun May 28 17:44:15 CEST 2000 Ruud de Rooij + + * Added autoconf check for getutent(). + * Changed uip/rcvtty.c and uip/slocal.c to use getutent() and + friends. Since I can only check on Linux, please check if + this works on other systems. + Sun May 28 14:58:49 CEST 2000 Ruud de Rooij * Applied patch from Peter Maydell to uip/scansbr.c for more diff --git a/configure b/configure index 55dd186..53a353a 100755 --- a/configure +++ b/configure @@ -1082,7 +1082,7 @@ else int main() { /* Ultrix mips cc rejects this. */ -typedef int charset[2]; const charset x; +typedef int charset[2]; const charset x = {0,0}; /* SunOS 4.1.1 cc rejects this. */ char const *const *ccp; char **p; @@ -1263,7 +1263,7 @@ if test -n "$RANLIB"; then else echo "$ac_t""no" 1>&6 fi - for ac_prog in gawk mawk nawk awk + for ac_prog in mawk gawk nawk awk do # Extract the first word of "$ac_prog", so it can be a program name with args. set dummy $ac_prog; ac_word=$2 @@ -2725,7 +2725,7 @@ fi for ac_func in waitpid wait3 sigaction sigprocmask sigblock sigsetmask \ sighold sigrelse writev lstat uname tzset killpg mkstemp \ - sethostent + sethostent getutent do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 echo "configure:2732: checking for $ac_func" >&5 diff --git a/uip/rcvtty.c b/uip/rcvtty.c index 5bdddb2..31ca80a 100644 --- a/uip/rcvtty.c +++ b/uip/rcvtty.c @@ -5,6 +5,11 @@ * $Id$ */ +/* Changed to use getutent() and friends. Assumes that when getutent() exists, + * a number of other things also exist. Please check. + * Ruud de Rooij Sun, 28 May 2000 17:28:55 +0200 + */ + #include #include #include @@ -15,11 +20,14 @@ #include #include -#ifndef UTMP_FILE -# ifdef _PATH_UTMP -# define UTMP_FILE _PATH_UTMP -# else -# define UTMP_FILE "/etc/utmp" + +#ifndef HAVE_GETUTENT +# ifndef UTMP_FILE +# ifdef _PATH_UTMP +# define UTMP_FILE _PATH_UTMP +# else +# define UTMP_FILE "/etc/utmp" +# endif # endif #endif @@ -80,8 +88,12 @@ 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 #ifdef LOCALE setlocale(LC_ALL, ""); @@ -156,17 +168,31 @@ main (int argc, char **argv) exit (RCV_MBX); user = getusername(); + +#ifdef HAVE_GETUTENT + setutent(); + while ((utp = getutent()) != NULL) { + if (utp->ut_type == USER_PROCESS + && utp->ut_user[0] != 0 + && utp->ut_line[0] != 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 + exit (RCV_MOK); return 0; /* dead code to satisfy the compiler */ } diff --git a/uip/slocal.c b/uip/slocal.c index 22ba3e8..acbdf2e 100644 --- a/uip/slocal.c +++ b/uip/slocal.c @@ -17,6 +17,11 @@ * */ +/* Changed to use getutent() and friends. Assumes that when getutent() exists, + * a number of other things also exist. Please check. + * Ruud de Rooij Sun, 28 May 2000 17:28:55 +0200 + */ + #include #include #include @@ -48,11 +53,13 @@ extern int initgroups(char*, int); #include -#ifndef UTMP_FILE -# ifdef _PATH_UTMP -# define UTMP_FILE _PATH_UTMP -# else -# define UTMP_FILE "/etc/utmp" +#ifndef HAVE_GETUTENT +# ifndef UTMP_FILE +# ifdef _PATH_UTMP +# define UTMP_FILE _PATH_UTMP +# else +# define UTMP_FILE "/etc/utmp" +# endif # endif #endif @@ -931,6 +938,32 @@ lookup (struct pair *pairs, char *key) * logged in. */ +#ifdef HAVE_GETUTENT +static int +logged_in (void) +{ + struct utmp * utp; + + if (utmped) + return utmped; + + setutent(); + + while ((utp = getutent()) != 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(); + return (utmped = DONE); + } + } + + endutent(); + return (utmped = NOTOK); +} +#else static int logged_in (void) { @@ -956,7 +989,7 @@ logged_in (void) 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