You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modules-dev@httpd.apache.org by Frank Jones <jo...@gmail.com> on 2007/05/31 15:17:13 UTC

Sending email from an Apache content generator

What's a good way to send an email from a handler module? Is
system("mail") OK or is there a better way?

Re: Sending email from an Apache content generator

Posted by Frank Jones <jo...@gmail.com>.
On 5/31/07, Nick Kew <ni...@webthing.com> wrote:
> On Thu, 31 May 2007 10:01:06 -0500
> "Frank Jones" <jo...@gmail.com> wrote:
>
>
> > I should add some details. First, this is a pre-existing module in C,
> > not new development. I need to look up a value in a database and then
> > send a standard response email.
>
> OK.  Well, a few bulletpoints to improve security in what you wrote:
>  * Don't call "mail".  Always call external programs by their full path.
>  * But make that path configurable by the sysop.
>  * Set up your process environment explicitly before forking a process.

Thanks again. Having looked around a bit, it looks like I can avoid
calling out to another program by using libESMTP[1]. Apparently this
library can produce SIGPIPE if the mail server drops the connection or
something, so I should probably still fork before I call it, but I
wouldn't need to worry about my environment, right?


[1] http://www.stafford.uklinux.net/libesmtp/

Re: Sending email from an Apache content generator

Posted by Nick Kew <ni...@webthing.com>.
On Thu, 31 May 2007 10:01:06 -0500
"Frank Jones" <jo...@gmail.com> wrote:


> I should add some details. First, this is a pre-existing module in C,
> not new development. I need to look up a value in a database and then
> send a standard response email.

OK.  Well, a few bulletpoints to improve security in what you wrote:
 * Don't call "mail".  Always call external programs by their full path.
 * But make that path configurable by the sysop.
 * Set up your process environment explicitly before forking a process.

>   There is no user input in the email so
> my security concerns are not what they might be otherwise.

>   Second, I
> don't know anything at all about perl,

In that case, scrap the idea of using it to prototype this.
The great virtue of perl's taint checking is that it will simply
refuse to run "mail" without securing your call to it.  That
makes it a great teacher!

-- 
Nick Kew

Application Development with Apache - the Apache Modules Book
http://www.apachetutor.org/

Re: Sending email from an Apache content generator

Posted by Frank Jones <jo...@gmail.com>.
On 5/31/07, Nick Kew <ni...@webthing.com> wrote:
> On Thu, 31 May 2007 08:17:13 -0500
> "Frank Jones" <jo...@gmail.com> wrote:
>
> > What's a good way to send an email from a handler module? Is
> > system("mail") OK or is there a better way?
>
> That'll work if you don't care about performance or security.

Thanks, Nick.

As it happens, I don't much care about performance in my particular
case as this email will need to be sent rarely. I don't need to send
an email on every request. I do, however, care about security.

> To fix the security, hack up a perl/cgi prototype and fix
> the issues that perl's taint checking complains of.  To fix
> performance, drop the fork.

I should add some details. First, this is a pre-existing module in C,
not new development. I need to look up a value in a database and then
send a standard response email. There is no user input in the email so
my security concerns are not what they might be otherwise. Second, I
don't know anything at all about perl, although I suppose I could
learn enough to solve my particular problem pretty easily. Can I chain
a perl content generator behind my existing generator? If so, how?

Re: Sending email from an Apache content generator

Posted by Nick Kew <ni...@webthing.com>.
On Thu, 31 May 2007 08:17:13 -0500
"Frank Jones" <jo...@gmail.com> wrote:

> What's a good way to send an email from a handler module? Is
> system("mail") OK or is there a better way?

That'll work if you don't care about performance or security.

To fix the security, hack up a perl/cgi prototype and fix
the issues that perl's taint checking complains of.  To fix
performance, drop the fork.

-- 
Nick Kew

Application Development with Apache - the Apache Modules Book
http://www.apachetutor.org/