* 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
+#include <ndbm.h>
+#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
#define VERSIONSW 13
{ "version", 0 },
#define HELPSW 14
- { "help", 4 },
+ { "help", 0 },
{ NULL, 0 }
};
if ((fd = copy_message (fileno (stdin), tmpfil, 1)) == -1)
adios (NULL, "unable to create temporary file");
}
+
if (debug)
debug_printf ("temporary file=\"%s\"\n", tmpfil);
- else
- unlink (tmpfil);
+
+ /* Delete the temp file now or a copy of every single message passed through
+ slocal will be left in the /tmp directory until deleted manually! This
+ unlink() used to be under an 'else' of the 'if (debug)' above, but since
+ some people like to always run slocal with -debug and log the results,
+ the /tmp directory would get choked over time. Of course, now that we
+ always delete the temp file, the "temporary file=" message above is
+ somewhat pointless -- someone watching debug output wouldn't have a
+ chance to 'tail -f' or 'ln' the temp file before it's unlinked. The best
+ thing would be to delay this unlink() until later if debug == 1, but I'll
+ leave that for someone who cares about the temp-file-accessing
+ functionality (they'll have to watch out for cases where we adios()). */
+ unlink (tmpfil);
if (!(fp = fdopen (fd, "r+")))
adios (NULL, "unable to access temporary file");
/*
* If no sender given, extract it
- * from envelope information.
- */
+ * from envelope information. */
if (sender == NULL)
get_sender (envelope, &sender);
/* deliver the message */
status = localmail (fd, mdlvr);
- done (status != -1 ? RCV_MOK : RCV_MBX);
+ return done (status != -1 ? RCV_MOK : RCV_MBX);
}
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];
break;
}
+ if (status) next = 0; /* action failed, mark for 'N' result */
+
if (accept && status == 0)
won++;
}
for (p = hdrs; p->p_name; p++) {
if (!strcasecmp (p->p_name, name)) {
if (!(p->p_flags & P_HID)) {
- if ((cp = p->p_value))
+ if ((cp = p->p_value)) {
if (p->p_flags & P_ADR) {
dp = cp + strlen (cp) - 1;
if (*dp == '\n')
} else {
cp = add ("\t", cp);
}
+ }
p->p_value = add (lp, cp);
}
free (lp);
* 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)
{
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