
            Using regular expressions in sendmail.cf: map-regex-1.0
                                       
   _!!_ Don't forget to add -a@MATCH to map definition, if you use
   version 1.0 or later.
   
   If you want to use regular expressions in sendmail.cf e.g. to avoid
   UBE, you can use this little map implementation. If you want to use it
   in your sendmail.cf, be sure you understand, what you are doing. If
   you want to use the check_* rulesets look at
   http://www.informatik.uni-kiel.de/%7Eca/email/check.html
   
Features

     * the pattern is compiled only one time
     * easy to use map-lookup in sendmail.cf
     * easy to install for system-administrators
     * based on POSIX-regex-library (regcomp(), regerr(), regexec())
       
How to install

    1. Download map-regex-1.0.tar and 'tar xf' it.
    2. Apply the patch to sendmail-8.8.?/src/conf.c.
    3. Copy map_regex.c to sendmail-8.8.?/src/.
    4. Edit your Makefile in sendmail-8.8.?/src/Makefiles/

DBMDEF= -DMAP_REGEX ...

# additional .o files needed
OBJADD=map_regex.o
    5. ./makesendmail
    6. Test: ./sendmail -d72 -bt -Ctest_sendmail.cf
    7. Send bug-reports to: Jan.Krueger+map@stud.uni-hannover.de
    8. If you want to know, how extended regular expressions work, please
       read regex.ps.gz taken from lib-regex from gnu.
       
Troubleshooting

   _Link fails: undefined reference to 'regcomp'_ or
   _pattern-compile-error: : Operation not applicable_
   Your libc does not include a running version of POSIX-regex. Use
   libregex from gnu. ftp://prep.ai.mit.edu/pub/gnu/ Filename:
   regex-?.?.tar.gz. Or lookup a ftp-mirror e.g.
   ftp://ftp.rrzn.uni-hannover.de/pub/mirror/gnu/.
   Your can link the regex.o from gnu or put it in a libregex.a and
   install it in the same place as e.g. libdb.a. Then you can link
   '-lregex'. Make sure, your compiler reads regex.h from the
   distribution and not from /usr/include.
   
How it works

   It knows the following options:
     * -n NOT
     * -f case sensitive
     * -b basic regular expressions (default is extended)
     * -s enable parsing capablilies (substrings () syntax)
     * -dDELIM define the delimiter (use with -s)
     * -aAPPEND APPEND is appended, if matching
       
   This is a simple test_sendmail.cf
# regex map valid?
Kvalid regex -a@MATCH ^[0-9]+
In the following, the dialogue of the test is shown:

ADDRESS TEST MODE (ruleset 3 NOT automatically invoked)
Enter <ruleset> <address>

> match_valid 123
rewrite: ruleset 198   input: 123 < @ domain . com >
regex_map_lookup: key '123'
rewrite: ruleset 198 returns: @ MATCH

> match_valid user75
rewrite: ruleset 198   input: user75 < @ domain . com >
regex_map_lookup: key 'user75'
rewrite: ruleset 198 returns: user75 < @ domain . com >

> match_parse received from hostname.domain.com [123.43.5.1]
rewrite: ruleset 199   input: received from hostname . domain . com [ 123 . 43
. 5 . 1 ]
regex_map_lookup: key 'received from hostname.domain.com[123.43.5.1]'
rewrite: ruleset 199 returns: IP : 123 . 43 . 5 . 1 $| host : hostname . domain
 . com

Use it with m4


Copy checkregex.m4 to sendmail-?.?.?/cf/hack. Use
HACK(checkregex, `pattern') in
your .mc-file. The parameter is optional, the default
pattern is `^[0-9]+<@'.


After this you can add "checkregex-calls" to your check_*.m4 rulesets. E.g.:

ifdef(`_CHECKREGEX_',
# check address against checkregex
R$*             $: $(checkregex $1 $)
R@MATCH         $#error $@ 5.1.8 $: 551 spam address. go away.)

  __________________________________________________________________________
                                       

    Jan Krger, Jan.Krueger+map@stud.uni-hannover.de
