[EXIM] Today's hack: a perl director for exim

Page principale
Supprimer ce message
Répondre à ce message
Auteur: Malcolm Beattie
Date:  
À: exim-users
Sujet: [EXIM] Today's hack: a perl director for exim
As pennance for stupidly missing off the suid bit on exim and
bothering exim-users with it, I've done a proof-of-concept patch
embedding perl in exim. It's mainly for hack value at the moment but
it's vaguely possible that there are some uses for being able to
write arbitrary perl code to decide how to direct/route/transport
or lookup mail in exim. Currently, I've just done a director, usage
as follows:

# directors
testperl:
driver = perl
startup = sub handler { return 'foo@bar' }
sub = handler

The perl driver captures any local_part at all (same as smartuser
which I used as template code) and runs the given sub named in the
"sub = ..." line. The "startup = ..." line gives some perl code to
be executed at startup time: in general you probably want it to be
"do '/some/file'" or "require Foo" but it can be anything. It can
do any initialisation and define any subs you want, including the
main "handler" sub. (The "startup = ..." string isn't string
expanded by exim so you don't need to backwhack everything in sight).

The return value of the handler sub can be
(1) undef, meaning the director returns FORCEFAIL (fail to handle the
    address and don't pass it on to subsequent directors)
(2) '' (i.e. a zero length string), meaning the director returns FAIL
    (fail to handle the address but pass it on to subsequent
    directors).
(3) a non-zero-length string taken to be a new address. The result is
    the same as though a smartuser director had "new_address = ..."
    for that new value.


Within your perl code, you can use the function "expand_string" which
calls back into exim's expand_string function. So you can say things
like:

    $d = expand_string('$domain');


It shouldn't be too hard allowing the perl code to manipulate exim
address structures/lists directly (the things that the
directors/README file talks about) but I haven't yet figured out
exactly how they work.

If anyone can think of any real applications, I'd be interested (and
only slightly surprised). I'd imagine a perl transport (which let you
do fancy things and "deliver" a message in the context of exim itself)
may be the most likely perl driver to be of use. Or maybe a generic
Perl code "lookup" thing (${lookup {key} perl {some_perl_sub} {arg}}).

I might as well send the whole patch this time: I won't do so if I
make any updates. Before applying this patch (from the top of your
exim tree), do
    touch src/directors/perl-exim.h
    touch src/directors/perl.c
in case your version of patch doesn't like creating files from
scratch. I've had to use "foo = $(shell ...)" in a makefile which
is probably a GNUism. I built/tested using exim 2.02 and perl 5.004_04
on Red Hat 5.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'M+JN'FV8I9M,L+:VC?G;NI`C0W^F:FX+)O5L
M$U@*E$?91;:"I'Q:^P7Z%"1RS=KJD]UKR$1!5\)VU6%]'@;`L8/RI#Z;C\*F
MM@H&@OL()43&S[Z]9^N]%>:,-6V68B1`;<ELL4D&X,51!!Z*$1ODPJ-2E"WV
MW>1^Q=6`,=<L<"C-J;@+**;;]0_Y6]7U0K&`X#6_]4!!:O#@#^NSY;F8%)5Y
M(]#ZE?Q+/F[;V3E9DQ=55')U'*G'L^I&"#T*Q*D?`T)U7#@*8`MD9737X*:I
MZV$R!JN#%.`1_&R1Q!Y>&?FVJ"5'$<A*F[6^?=(\6YW&>:PT=2T.,P.4#5]%
M1);_:5RVI887!'EW?:,=:'?^,ZM1G,%K`SAKC77P_:2?6;]QRD]3JC7D]J4D
M>KA`*8##Y=$J$)0QT_O;:`EK^C#\7-$JR.&-@_4*S,,L@)P6@-;'7(>N$>J+
M&*+K)%PAF4:^[[K:UVS99AT"@('[]-HRO3,*23ID%O_(>";+_PW[R?L.-S42
M=$T+GW6O#&HL"_SV?8#50QCBT^YI0+=*F*3'\0\`?,-,4`J6"Q_-^\PX3.\P
M.G00=8-BWBB;U\*_J$LMR/[IO4?SC9WU6Y<&^S,;?@!KV!3HT2[RN(8B-'%]
M&G`PBGDF4OV_=M13_=HXWNDIN<`J?$Q12'>:191Z-"3&`DB0,9%(T>"`&+U'
M10$9@0&T8-QR$Q-K05PA#NIRFB54E2DDP3#]%)08R)AWE"!1J6+X`1\,W?:O
J[WHGROHB'Z\ZN80Z&6+U4PU\/2V(,G7SK02[\94I>OS_3[QA)6Z(-```
`
end
------------------------------ cut here ------------------------------

--Malcolm

--
Malcolm Beattie <mbeattie@???>
Unix Systems Programmer
Oxford University Computing Services

--
*** Exim information can be found at http://www.exim.org/ ***