db configuration fix for Debian; yet another location for ndbm.
[mmh] / uip / slocal.c
index a306cad..bbf1850 100644 (file)
@@ -3,6 +3,10 @@
  * slocal.c -- asynchronously filter and deliver new mail
  *
  * $Id$
+ *
+ * This code is Copyright (c) 2002, by the authors of nmh.  See the
+ * COPYRIGHT file in the root directory of the nmh distribution for
+ * complete copyright information.
  */
 
 /*
  *
  */
 
+/* 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/signals.h>
-#include <zotnet/tws/tws.h>
-#include <zotnet/mts/mts.h>
+#include <h/tws.h>
+#include <h/mts.h>
 
 #include <pwd.h>
 #include <signal.h>
 #include <sys/ioctl.h>
-#include <ndbm.h>
 #include <fcntl.h>
 
+#ifdef INITGROUPS_HEADER
+#include INITGROUPS_HEADER
+#else
+/* On AIX 4.1, initgroups() is defined and even documented (giving the parameter
+   types as char* and int), but doesn't have a prototype in any of the system
+   header files.  AIX 4.3, SunOS 4.1.3, and ULTRIX 4.2A have the same
+   problem. */
+extern int  initgroups(char*, int);
+#endif
+
+
+#ifdef HAVE_DB1_NDBM_H
+#include <db1/ndbm.h>
+#else
+#ifdef HAVE_GDBM_NDBM_H
+#include <gdbm/ndbm.h>
+#else
+#if defined(HAVE_DB_H) && defined(HAVE_LIBDB)
+#define DB_DBM_HSEARCH 1
+#include <db.h>
+#else
+#include <ndbm.h>
+#endif
+#endif
+#endif
+
 #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
 
@@ -70,7 +106,7 @@ static struct swit switches[] = {
 #define VERSIONSW     13
     { "version", 0 },
 #define        HELPSW        14
-    { "help", 4 },
+    { "help", 0 },
     { NULL, 0 }
 };
 
@@ -429,7 +465,7 @@ localmail (int fd, char *mdlvr)
 static int
 usr_delivery (int fd, char *delivery, int su)
 {
-    int i, accept, status, won, vecp, next;
+    int i, accept, status=1, won, vecp, next;
     char *field, *pattern, *action, *result, *string;
     char buffer[BUFSIZ], tmpbuf[BUFSIZ];
     char *cp, *vec[NVEC];
@@ -633,6 +669,8 @@ usr_delivery (int fd, char *delivery, int su)
                break;
        }
 
+       if (status) next = 0;   /* action failed, mark for 'N' result */
+
        if (accept && status == 0)
            won++;
     }
@@ -915,6 +953,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)
 {
@@ -940,7 +1004,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