[Exim] Lookup using fifth field as key

Top Page
Delete this message
Reply to this message
Author: Jonathan Hunter
Date:  
To: exim-users
Subject: [Exim] Lookup using fifth field as key
Hi,

I would like to have my Exim mail server perform a lookup on the GECOS field
in /etc/passwd. Mail sent to (for example) jonathan.hunter@mydomain would
then be delivered to the [first] user in /etc/passwd who has "Jonathan
Hunter" in his/her GECOS field. (Yes, I know that it won't work if we have
two John Smiths on the machine - we can live with that.)

What is the best way to go about this? I know that the standard lsearch
lookup uses the first field in the file as a key, so that won't quite do
what I want. I don't particularly want to have to use embedded Perl, either.

The following logic looks like it will achieve what I need:

1. Only run when local_part has one or more dots in it.
2. Replace all dots in local_part with spaces
3. Search /etc/passwd (case-insensitive) for a GECOS field matching the
string we now have for local_part
4. Deliver to the user found from the /etc/passwd search (using smartuser?)

I think one way of achieving this search functionality might be to extend
lsearch, to something like "field5-lsearch", or another way would be to
write a new lookup type. These would both use the specified field within the
file as the 'primary key', and would return the entire line as the result.

Is this feasible at all, or is it more sensible to use embedded Perl? I
suspect lsearch might not like the colons used in /etc/passwd as field
seperators, thus necessitating a new search type to be written. If I do
write a new search type, are there any coding standards to follow for
inclusion in the next Exim distribution if other people want it?

Or (hopefully) have I missed something obvious and is there a much simpler
way of achieving this? I would like to avoid generating an aliases file from
/etc/passwd every so often, as that's just duplicating existing
information...

Thanks for any comments,

Jonathan