Re: [exim] Run a Program from within Exim

Kezdőlap
Üzenet törlése
Válasz az üzenetre
Szerző: Jakob Hirsch
Dátum:  
Címzett: David Cunningham
CC: exim users
Tárgy: Re: [exim] Run a Program from within Exim
David Cunningham, 2010-03-23 12:46:

> The short of the story is that I need exim to execute another program
> upon the delivery of an email and send that program the following
> string:
> "/var/spool/maildirs/${substr_0_10:$tod_log}/${domain}/${local_part}/Maildir/new"


What do you mean by "send"? Give as an argument? Write to its stdin?

> For example, I tried adding a condition to my local_delivery transport
> that looked like this:
>
> condition = {run echo
> "/var/spool/maildirs/${substr_0_10:$tod_log}/${domain}/${local_part}/Maildir"
> >> /dev/shm/temp.file}{0}{1}


RTFM:

1. The syntax is
${run{<command> <args>}{<string1>}{<string2>}}
not
{run <command> ...}

2. "As in other command executions from Exim, a shell is not used by
default. If you want a shell, you must explicitly code it. "

As you use redirection in your test, you need to use a shell there.

3. You have to give the full path to the executable you want to run.
(Unfortunately, this is not documented in the spec of the ${run...}
expansion item. Should probably be added.)

So the expansion string would look like this:

${run {/bin/sh -c "echo
/var/spool/maildirs/${substr_0_10:$tod_log/${domain}/${local_part}/Maildir
>> /dev/shm/temp.file"}{0}{1}}


You really have to take care here that nobody can do shell injection
(e.g. by using ';' or other special shell chars in the local part). This
only applies when using a shell, so you should probably avoid that. Just
use a little script, that logs what your program would get, e.g.

#/bin/sh
echo $1 >> /tmp/bla.log

and use that instead of your real program.

> In this example I am simply trying to echo that string to a file in
> /dev/shm. I do not get an error in my logs, but I also do not get
> this file.


Errors are hidden here. Look into $runrc to see what went wrong.