* Added autoconf check for getutent().
authorRuud de Rooij <ruud@ruud.org>
Sun, 28 May 2000 16:17:49 +0000 (16:17 +0000)
committerRuud de Rooij <ruud@ruud.org>
Sun, 28 May 2000 16:17:49 +0000 (16:17 +0000)
* 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.

ChangeLog
configure
uip/rcvtty.c
uip/slocal.c

index 53201cb..6134234 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Sun May 28 17:44:15 CEST 2000 Ruud de Rooij <ruud@ruud.org>
+
+       * 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 <ruud@ruud.org>
 
        * Applied patch from Peter Maydell to uip/scansbr.c for more
 Sun May 28 14:58:49 CEST 2000 Ruud de Rooij <ruud@ruud.org>
 
        * Applied patch from Peter Maydell to uip/scansbr.c for more
index 55dd186..53a353a 100755 (executable)
--- a/configure
+++ b/configure
@@ -1082,7 +1082,7 @@ else
 int main() {
 
 /* Ultrix mips cc rejects this.  */
 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;
 /* 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
 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
 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 \
 
 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
 do
 echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
 echo "configure:2732: checking for $ac_func" >&5
index 5bdddb2..31ca80a 100644 (file)
@@ -5,6 +5,11 @@
  * $Id$
  */
 
  * $Id$
  */
 
+/* Changed to use getutent() and friends.  Assumes that when getutent() exists,
+ * a number of other things also exist.  Please check.
+ * Ruud de Rooij <ruud@ruud.org>  Sun, 28 May 2000 17:28:55 +0200
+ */
+
 #include <h/mh.h>
 #include <h/signals.h>
 #include <h/rcvmail.h>
 #include <h/mh.h>
 #include <h/signals.h>
 #include <h/rcvmail.h>
 #include <fcntl.h>
 
 #include <utmp.h>
 #include <fcntl.h>
 
 #include <utmp.h>
-#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
 
 # 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];
     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;
     struct utmp ut;
     register FILE *uf;
+#endif
 
 #ifdef LOCALE
     setlocale(LC_ALL, "");
 
 #ifdef LOCALE
     setlocale(LC_ALL, "");
@@ -156,17 +168,31 @@ main (int argc, char **argv)
        exit (RCV_MBX);
 
     user = getusername();
        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);
     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);
        }
     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);
     fclose (uf);
+#endif
+
     exit (RCV_MOK);
     return 0;  /* dead code to satisfy the compiler */
 }
     exit (RCV_MOK);
     return 0;  /* dead code to satisfy the compiler */
 }
index 22ba3e8..acbdf2e 100644 (file)
  *
  */
 
  *
  */
 
+/* Changed to use getutent() and friends.  Assumes that when getutent() exists,
+ * a number of other things also exist.  Please check.
+ * Ruud de Rooij <ruud@ruud.org>  Sun, 28 May 2000 17:28:55 +0200
+ */
+
 #include <h/mh.h>
 #include <h/dropsbr.h>
 #include <h/rcvmail.h>
 #include <h/mh.h>
 #include <h/dropsbr.h>
 #include <h/rcvmail.h>
@@ -48,11 +53,13 @@ extern int  initgroups(char*, int);
 
 #include <utmp.h>
 
 
 #include <utmp.h>
 
-#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
 
 # endif
 #endif
 
@@ -931,6 +938,32 @@ lookup (struct pair *pairs, char *key)
  * logged in.
  */
 
  * 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)
 {
 static int
 logged_in (void)
 {
@@ -956,7 +989,7 @@ logged_in (void)
     fclose (uf);
     return (utmped = NOTOK);
 }
     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
 
 #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