[Exim] Dynamically generated list of local users

Pàgina inicial
Delete this message
Reply to this message
Autor: Phil Pennock
Data:  
A: Exim Users
Assumpte: [Exim] Dynamically generated list of local users
I'm new to Exim, but I like to tinker. I've had a couple of requests
for info from the recipients of an all-user mailout I did to notify the
users of the move to exim, wanting to know how I made the list
dynamically generated. And let's face it - since I knew next to nothing
about setting up Exim at the beginning of the week, I'm slightly smug
about this. :^) Those users are on this list, so ...

Embedded perl. I started looking at multiple ${if ...} nests but it
started getting really sick even before I had the 'collect all users'
logic figured out. I used ${originator_uid} but switched it to _gid for
the example below. Set ALLPOSTGID. Does Exim interpolate things like
LOCALDOM into strings as below? If not, just amend as appropriate.

SETMEMIN and SETMEMAX in the perl script should be replaced by the
minimum and maximum values used as uids for human users. I thought of
passing them as values, but decided that as things stand, there's no
need.

Using prefix matches, I think that this could be expanded to a generic
all-groupname rule pretty trivially, as a nice exercise. Then use the
groupname as an argument for the call to the perl subroutine, and match
on being a member of the group through getgrnam and getpwent.

I like it anyway. Public domain, no warranty, etc etc ...

-----------------------------< cut here >-------------------------------
#[  exim configuration  ]
#[ main config section ]
perl_startup            = do '/etc/mail/exim.pl'
#[ directors section ]
all_users:
  driver    = smartuser
  domains    = localhost
  condition    = ${if eq {$local_part}{all-users} \
           {${if ={${originator_gid}}{ALLPOSTGID} {yes}{no}}}  {no}}} \
  rewrite    = true
  headers_add   = "X-List: all-users.LOCALDOM (private)"
  new_address    = ${perl{all_users}}
-----------------------------< cut here >-------------------------------
# Perl subroutines available from exim


sub all_users ()
{
    my @l;
    my $r ='';

    
    setpwent;
    while (@l=getpwent) {
        $r .= "$l[0]," if ($l[2]>=SETMEMIN and $l[2]<=SETMEMAX);
    }
    $r =~ s/,$//;
    endpwent;


    return ($r eq '') ? undef : $r;
}
-----------------------------< cut here >-------------------------------


--
HTML email - just say no --> Phil Pennock
"We've got a patent on the conquering of a country through the use of force.
We believe in world peace through extortionate license fees." -Bluemeat