stevenmc
stevenmc

Reputation: 1669

Postfix piping email to php, permissions error

I'm attempting to pipe an email to PHP with my Postfix mail server, using the technique mentioned here and have encountered the following error...

Mar 16 22:52:52 s15438530 postfix/pipe[9259]: AD1632E84C63: to=<php@[myserver].com>, relay=plesk_virtual, delay=0.61, delays=0.59/0/0/0.02, dsn=4.3.0, status=deferred (temporary failure. Command output: /bin/sh: /var/www/vhosts/[myserver].com/httpdocs/clients/emailpipe/email2php.php: Permission denied 4.2.1 Message can not be delivered at this time )

I'd really appreciate if anyone could shed some light on this issue for me. I've tried 777'ing the emailpipe directory, to no avail. Where am I going wrong?

Many thanks.

Upvotes: 4

Views: 5279

Answers (4)

Saurabh Singla
Saurabh Singla

Reputation: 31

I have fixed this issue by disabling the SELINUX.

Upvotes: 3

Eli Rosencruft
Eli Rosencruft

Reputation: 7262

Make sure that you have

#!/usr/bin/php
<?php

(or whatever your path to php is - do "which php" on the server) at the top of each of your php scripts and that each of the php script files is executable

chmod +x /var/.../email2php.php

Also, make sure that you can test the script from the command line:

cat some_rfc822_email.txt | /var/.../email2php.php

and get the result that you want

Upvotes: 2

MrGomez
MrGomez

Reputation: 23886

To fix this issue, you'll want to chown or chmod /var/www/vhosts/[myserver].com/httpdocs/clients/emailpipe/email2php.php to executable by your postfix user. Alternately, you'll want to redefine this user to execute the file successfully.

Simply changing the permissions of your directory (unless you used -R) won't be sufficient.

To illustrate why this works, consider the following toy example:

<me>@harley:~$ touch test
<me>@harley:~$ ls -al test
-rw-r--r-- 1 <me> <me> 0 2012-03-26 23:44 test
<me>@harley:~$ sh test
<me>@harley:~$
<me>@harley:~$ ./test
bash: ./test: Permission denied
<me>@harley:~$ chmod 755 test
<me>@harley:~$ ./test
<me>@harley:~$ 

In order to execute a file directly through the running shell, it needs to be set as executable. Other invocations (for example, sh email2php.php or php email2php.php) only require read access, because they're chaining execution off a different file entirely.

For what's likely to be causing the issue in the first place, see here.

Upvotes: 0

outeredge
outeredge

Reputation: 285

From the postfix docs...

For security reasons, deliveries to command and file destinations are performed with the rights of the alias database owner. A default userid, default_privs, is used for deliveries to commands/files in root-owned aliases.

So you have two options, either set the default_privs in main.cf to match the ownership of the email2php file.

Alternatively, there should be a way to create an alias database that is owned by the user instead of postfix/nobody. I haven't tried this before though so can't advise.

Upvotes: 9

Related Questions