diff -uNr exim-3.22/scripts/MakeLinks exim-3.22.dirsearch/scripts/MakeLinks --- exim-3.22/scripts/MakeLinks Fri Jan 19 09:32:06 2001 +++ exim-3.22.dirsearch/scripts/MakeLinks Mon Jan 29 16:36:35 2001 @@ -69,6 +69,8 @@ ln -s ../../src/lookups/ldap.c ldap.c ln -s ../../src/lookups/lsearch.h lsearch.h ln -s ../../src/lookups/lsearch.c lsearch.c +ln -s ../../src/lookups/dirsearch.h dirsearch.h +ln -s ../../src/lookups/dirsearch.c dirsearch.c ln -s ../../src/lookups/mysql.h mysql.h ln -s ../../src/lookups/mysql.c mysql.c ln -s ../../src/lookups/nis.h nis.h diff -uNr exim-3.22/src/EDITME exim-3.22.dirsearch/src/EDITME --- exim-3.22/src/EDITME Fri Jan 19 09:32:06 2001 +++ exim-3.22.dirsearch/src/EDITME Mon Jan 29 16:14:27 2001 @@ -334,6 +334,7 @@ LOOKUP_DBM=yes LOOKUP_LSEARCH=yes +# LOOKUP_DIRSEARCH=yes # LOOKUP_CDB=yes # LOOKUP_DNSDB=yes # LOOKUP_LDAP=yes diff -uNr exim-3.22/src/config.h.defaults exim-3.22.dirsearch/src/config.h.defaults --- exim-3.22/src/config.h.defaults Fri Jan 19 09:32:07 2001 +++ exim-3.22.dirsearch/src/config.h.defaults Mon Jan 29 16:14:47 2001 @@ -50,6 +50,7 @@ #define LOOKUP_DNSDB #define LOOKUP_LDAP #define LOOKUP_LSEARCH +#define LOOKUP_DIRSEARCH #define LOOKUP_MYSQL #define LOOKUP_NIS #define LOOKUP_NISPLUS diff -uNr exim-3.22/src/drtables.c exim-3.22.dirsearch/src/drtables.c --- exim-3.22/src/drtables.c Fri Jan 19 09:32:07 2001 +++ exim-3.22.dirsearch/src/drtables.c Mon Jan 29 16:16:55 2001 @@ -55,6 +55,10 @@ #include "lookups/lsearch.h" #endif +#ifdef LOOKUP_DIRSEARCH +#include "lookups/dirsearch.h" +#endif + #ifdef LOOKUP_MYSQL #include "lookups/mysql.h" #endif @@ -218,6 +222,23 @@ lsearch_check, /* check function */ lsearch_find, /* find function */ lsearch_close, /* close function */ + NULL, /* no tidy function */ + NULL /* no quoting function */ +#else + NULL, NULL, NULL, NULL, NULL, NULL /* lookup not present */ +#endif + }, + +/* Search of files in a directory */ + + { + "dirsearch", /* lookup name */ + lookup_absfile, /* uses absolute file name */ +#ifdef LOOKUP_DIRSEARCH + dsearch_open, /* open function */ + dsearch_check, /* check function */ + dsearch_find, /* find function */ + dsearch_close, /* close function */ NULL, /* no tidy function */ NULL /* no quoting function */ #else diff -uNr exim-3.22/src/lookups/Makefile exim-3.22.dirsearch/src/lookups/Makefile --- exim-3.22/src/lookups/Makefile Fri Jan 19 09:32:08 2001 +++ exim-3.22.dirsearch/src/lookups/Makefile Mon Jan 29 16:17:53 2001 @@ -4,7 +4,7 @@ # defined, dummy modules get compiled. OBJ = cdb.o dbmdb.o dnsdb.o ldap.o lsearch.o mysql.o nis.o nisplus.o pgsql.o \ - testdb.o + testdb.o dirsearch.o lookups.a: $(OBJ) /bin/rm -f lookups.a @@ -20,6 +20,7 @@ dnsdb.o: $(HDRS) dnsdb.c dnsdb.h ldap.o: $(HDRS) ldap.c ldap.h lsearch.o: $(HDRS) lsearch.c lsearch.h +dirsearch.o: $(HDRS) dirsearch.c dirsearch.h mysql.o: $(HDRS) mysql.c mysql.h nis.o: $(HDRS) nis.c nis.h nisplus.o: $(HDRS) nisplus.c nisplus.h diff -uNr exim-3.22/src/lookups/dirsearch.c exim-3.22.dirsearch/src/lookups/dirsearch.c --- exim-3.22/src/lookups/dirsearch.c Thu Jan 1 01:00:00 1970 +++ exim-3.22.dirsearch/src/lookups/dirsearch.c Mon Jan 29 17:09:38 2001 @@ -0,0 +1,149 @@ +/************************************************* +* Exim - an Internet mail transport agent * +*************************************************/ + +/* Copyright (c) University of Cambridge 1995 - 2001 */ +/* See the file NOTICE for conditions of use and distribution. */ +/* This file amended from the lsearch.c code by Matthew Byng-Maddick */ +/* These changes (c) Matthew Byng-Maddick 2001 */ + +#include "../exim.h" +#include +#include "dirsearch.h" + + + +/************************************************* +* Open entry point * +*************************************************/ + +/* See local README for interface description */ + +void * +dsearch_open(char *dirname, char **errmsg) +{ +DIR *dp = opendir(dirname); +if (dp == NULL) + { + int save_errno = errno; + *errmsg = string_open_failed(errno, "%s for directory search", dirname); + errno = save_errno; + return NULL; + } +return dp; +} + + +/************************************************* +* Check entry point * +*************************************************/ + +BOOL +dsearch_check(void *handle, char *dirname, int modemask, uid_t *owners, + gid_t *owngroups, char **errmsg) +{ + int i; + struct stat statbuf; + + if(stat(dirname, &statbuf) != 0) + { + int save_errno = errno; + *errmsg = string_sprintf("%s: stat failed", dirname); + errno = save_errno; + return 0; + } + + if ((statbuf.st_mode & S_IFMT) != S_IFDIR || + (statbuf.st_mode & modemask) !=0) + { + *errmsg = string_sprintf("%s (dirsearch lookup): directory mode %.4o should " + "not contain %.4o", dirname, statbuf.st_mode & 07777, + statbuf.st_mode & modemask); + errno = ERRNO_BADMODE; + return 0; + } + +if (owners != NULL) + { + BOOL uid_ok = FALSE; + for (i = 1; i <= (int)owners[0]; i++) + if (owners[i] == statbuf.st_uid) { uid_ok = TRUE; break; } + if (!uid_ok) + { + *errmsg = string_sprintf("%s (dirsearch lookup): directory has wrong owner", + dirname); + errno = ERRNO_BADUGID; + return 0; + } + } + +if (owngroups != NULL) + { + BOOL gid_ok = FALSE; + for (i = 1; i <= (int)owngroups[0]; i++) + if (owngroups[i] == statbuf.st_gid) { gid_ok = TRUE; break; } + if (!gid_ok) + { + *errmsg = string_sprintf("%s (dirsearch lookup): directory has wrong group", + dirname); + errno = ERRNO_BADUGID; + return 0; + } + } + +return 1; +} + + +/************************************************* +* Find entry point * +*************************************************/ + +/* See local README for interface description */ + +int +dsearch_find(void *handle, char *dirname, char *keystring, int length, + char **result, char **errmsg) +{ +DIR *dp = (DIR *)handle; +struct dirent *d_ent; + +dirname = dirname; /* Keep picky compilers happy */ +errmsg = errmsg; + +rewinddir(dp); +while (d_ent=readdir(dp)) + { + int ptr, size; + char *yield; + + if(d_ent->d_name[0]=='.') continue; + if(strlen(d_ent->d_name)!=strlen(keystring)) continue; + if(strncmpic(d_ent->d_name,keystring,length)!=0) continue; + + size=strlen(d_ent->d_name); + ptr=0; + yield=store_get(size); + yield = string_cat(yield, &size, &ptr, d_ent->d_name, (int)strlen(d_ent->d_name)); + yield[ptr] = 0; + + *result = yield; + return OK; + } +return FAIL; +} + + +/************************************************* +* Close entry point * +*************************************************/ + +/* See local README for interface description */ + +void +dsearch_close(void *handle) +{ +closedir((DIR *)handle); +} + +/* End of lookups/dirsearch.c */ diff -uNr exim-3.22/src/lookups/dirsearch.h exim-3.22.dirsearch/src/lookups/dirsearch.h --- exim-3.22/src/lookups/dirsearch.h Thu Jan 1 01:00:00 1970 +++ exim-3.22.dirsearch/src/lookups/dirsearch.h Mon Jan 29 17:10:30 2001 @@ -0,0 +1,17 @@ +/************************************************* +* Exim - an Internet mail transport agent * +*************************************************/ + +/* Copyright (c) University of Cambridge 1995 - 2001 */ +/* See the file NOTICE for conditions of use and distribution. */ +/* Amends (c) Matthew Byng-Maddick 2001 */ + +/* Header for the dirsearch lookup */ + +extern void *dsearch_open(char *, char **); +extern BOOL dsearch_check(void *, char *, int, uid_t *, gid_t *, char **); +extern int dsearch_find(void *, char *, char *, int, char **, char **); +extern void dsearch_close(void *); + +/* End of lookups/dirsearch.h */ +