<-- Warning: charset 'unknown-8bit' is not supported -->
--
We've recently migrated our mailserver to one now running
exim, and have been configuring it to meet our requirements.
We filter all of our inbound mail through amavisd and use several
virus scanners here, this results in a delivery scheme roughly
equating to:
mail arrives
mail is passed to amavisd
mail arrives from amavisd on port 10025
mail is tested for deliverability and handled
this was a bit niggly because bounce messages always had localhost
as their last hop, which is confusing to some people, and wasting
CPU on virus checking messages that arnt going to be delivered
seemed wasteful. While two additional amavis routers (one with
local_parts = dbm;/etc/aliases.db and one with check_local_user)
would fix this for us, I didnt really want the overhead of
check_local_user (at this stage, we do need it later) or an lsearch
on /etc/passwd either, since the mail was just about to be fired off
to amavis pretty much none of what it does matters to me.
So instead I've added a lookup method "passwd", which will lookup a
string, turn it into lowercase and return it again if it's a local
user. The patch is attatched, my amavis router is now:
amavis:
driver = manualroute
condition = "${if eq {$interface_port}{10025} {0}{1}}"
# if scanning incoming mails, uncomment the following line and
# change local_domains accordingly
local_parts = dbm;/etc/aliases.db : passwd;$local_part
domains = +local_domains
transport = amavis
route_list = * localhost
self = send
which means that we can bounce mail quickly and efficiently
from the initial connection again, and we don't waste any
CPU virus checking mails which will never get anywhere :)
I'm not sure what other uses a passwd lookup has, but it's
proving very usefull for this anyway , so hopefully may prove
useful to others :)
--
Colm MacC?rthaigh
--
diff -uNr exim-4.10/scripts/MakeLinks exim-4.10.passwd/scripts/MakeLinks
--- exim-4.10/scripts/MakeLinks Mon Jul 22 09:59:47 2002
+++ exim-4.10.passwd/scripts/MakeLinks Thu Aug 1 16:04:00 2002
@@ -60,6 +60,8 @@
ln -s ../../src/lookups/nisplus.c nisplus.c
ln -s ../../src/lookups/oracle.h oracle.h
ln -s ../../src/lookups/oracle.c oracle.c
+ln -s ../../src/lookups/passwd.h passwd.h
+ln -s ../../src/lookups/passwd.c passwd.c
ln -s ../../src/lookups/pgsql.h pgsql.h
ln -s ../../src/lookups/pgsql.c pgsql.c
ln -s ../../src/lookups/testdb.h testdb.h
diff -uNr exim-4.10/src/EDITME exim-4.10.passwd/src/EDITME
--- exim-4.10/src/EDITME Mon Jul 22 09:59:47 2002
+++ exim-4.10.passwd/src/EDITME Thu Aug 1 16:04:00 2002
@@ -241,6 +241,7 @@
# LOOKUP_NIS=yes
# LOOKUP_NISPLUS=yes
# LOOKUP_ORACLE=yes
+# LOOKUP_PASSWD=yes
# LOOKUP_PGSQL=yes
# LOOKUP_WHOSON=yes
diff -uNr exim-4.10/src/config.h.defaults exim-4.10.passwd/src/config.h.defaults
--- exim-4.10/src/config.h.defaults Mon Jul 22 09:59:48 2002
+++ exim-4.10.passwd/src/config.h.defaults Thu Aug 1 16:04:00 2002
@@ -58,6 +58,7 @@
#define LOOKUP_NIS
#define LOOKUP_NISPLUS
#define LOOKUP_ORACLE
+#define LOOKUP_PASSWD
#define LOOKUP_PGSQL
#define LOOKUP_TESTDB
#define LOOKUP_WHOSON
diff -uNr exim-4.10/src/drtables.c exim-4.10.passwd/src/drtables.c
--- exim-4.10/src/drtables.c Mon Jul 22 09:59:48 2002
+++ exim-4.10.passwd/src/drtables.c Thu Aug 1 16:04:00 2002
@@ -75,6 +75,10 @@
#include "lookups/oracle.h"
#endif
+#ifdef LOOKUP_PASSWD
+#include "lookups/passwd.h"
+#endif
+
#ifdef LOOKUP_PGSQL
#include "lookups/pgsql.h"
#endif
@@ -333,6 +337,23 @@
NULL, /* no close function */
oracle_tidy, /* tidy function */
oracle_quote /* quoting function */
+#else
+ NULL, NULL, NULL, NULL, NULL, NULL /* lookup not present */
+#endif
+ },
+
+/* PASSWD lookup, */
+
+ {
+ US"passwd", /* lookup name */
+ lookup_querystyle, /* query-style lookup */
+#ifdef LOOKUP_PASSWD
+ passwd_open, /* open function */
+ NULL, /* check function */
+ passwd_find, /* find function */
+ NULL, /* no close function */
+ NULL, /* no tidy function */
+ NULL /* no quoting function */
#else
NULL, NULL, NULL, NULL, NULL, NULL /* lookup not present */
#endif
diff -uNr exim-4.10/src/lookups/Makefile exim-4.10.passwd/src/lookups/Makefile
--- exim-4.10/src/lookups/Makefile Mon Jul 22 09:59:49 2002
+++ exim-4.10.passwd/src/lookups/Makefile Thu Aug 1 16:04:00 2002
@@ -4,7 +4,8 @@
# defined, dummy modules get compiled.
OBJ = cdb.o dbmdb.o dnsdb.o dsearch.o ldap.o lsearch.o mysql.o nis.o \
- nisplus.o oracle.o pgsql.o testdb.o whoson.o lf_check_file.o
+ nisplus.o oracle.o passwd.o pgsql.o testdb.o whoson.o \
+ lf_check_file.o
lookups.a: $(OBJ)
/bin/rm -f lookups.a
@@ -27,6 +28,7 @@
nis.o: $(HDRS) nis.c nis.h
nisplus.o: $(HDRS) nisplus.c nisplus.h
oracle.o: $(HDRS) oracle.c oracle.h
+passwd.o: $(HDRS) passwd.c passwd.h
pgsql.o: $(HDRS) pgsql.c pgsql.h
testdb.o: $(HDRS) testdb.c testdb.h
whoson.o: $(HDRS) whoson.c whoson.h
diff -uNr exim-4.10/src/lookups/passwd.c exim-4.10.passwd/src/lookups/passwd.c
--- exim-4.10/src/lookups/passwd.c Thu Jan 1 01:00:00 1970
+++ exim-4.10.passwd/src/lookups/passwd.c Thu Aug 1 16:04:00 2002
@@ -0,0 +1,74 @@
+/*************************************************
+* Exim - an Internet mail transport agent *
+*************************************************/
+
+/* Copyright (c) University of Cambridge 1995 - 2002 */
+/* See the file NOTICE for conditions of use and distribution. */
+
+#include "../exim.h"
+#include "passwd.h"
+
+/* We can't just compile this code and allow the library mechanism to omit the
+functions if they are not wanted, because we need to have the NIS header
+available for compiling. Therefore, compile these functions only if LOOKUP_PASSWD
+is defined. However, some compilers don't like compiling empty modules, so keep
+them happy with a dummy when skipping the rest. Make it reference itself to
+stop picky compilers complaining that it is unused, and put in a dummy argument
+to stop even pickier compilers complaining about infinite loops. */
+
+#ifndef LOOKUP_PASSWD
+static void dummy(int x) { dummy(x-1); }
+#else
+
+#include <sys/types.h>
+#include <pwd.h>
+
+/*************************************************
+* Open entry point *
+*************************************************/
+
+/* See local README for interface description. */
+
+void *
+passwd_open(uschar *filename, uschar **errmsg)
+{
+return (void *)(1); /* Just return something non-null */
+}
+
+
+/*************************************************
+* Find entry point for passwd *
+*************************************************/
+
+/* See local README for interface description. */
+
+int
+passwd_find(void *handle, uschar *filename, uschar *query, int length,
+ uschar **result, uschar **errmsg)
+{
+struct passwd * p;
+uschar * username;
+int i;
+
+username = string_copy_malloc(CS query);
+
+for (i = 0; username[i]; i++)
+ {
+ username[i] = tolower(username[i]);
+ }
+
+/* check if it's a local user */
+if ((p = getpwnam(username)) != NULL)
+ {
+ *result = string_copy(p->pw_name);
+ free(username);
+ return OK;
+ }
+
+free(username);
+return FAIL;
+}
+
+#endif /* LOOKUP_PASSWD */
+
+/* End of lookups/passwd.c */
diff -uNr exim-4.10/src/lookups/passwd.h exim-4.10.passwd/src/lookups/passwd.h
--- exim-4.10/src/lookups/passwd.h Thu Jan 1 01:00:00 1970
+++ exim-4.10.passwd/src/lookups/passwd.h Thu Aug 1 16:04:00 2002
@@ -0,0 +1,13 @@
+/*************************************************
+* Exim - an Internet mail transport agent *
+*************************************************/
+
+/* Copyright (c) University of Cambridge 1995 - 2002 */
+/* See the file NOTICE for conditions of use and distribution. */
+
+/* Header for the passwd lookup */
+
+extern void *passwd_open(uschar *, uschar **);
+extern int passwd_find(void *, uschar *, uschar *, int, uschar **, uschar **);
+
+/* End of lookups/passwd.h */
--