I started with a fresh install of OpenBSD 6.0 which has a chroot (/var/www) on their httpd server (not Apache). I installed PHP 7.0 and set up the php-fpm using the binary installs. In the web root there exists both sendmail and femail objects. I moved a website into place and php works very well and php queries the postgresql database (also installed from binary) and everything works well - except mail().
I set up a log file in /var/www/logs/php.mail.log and it sees that mail is being recognized by php with log entries such as this:
[09-Dec-2016 15:04:34 UTC] mail() on [/do_quick_mail_test.php:23]: To: myemail@domain.com -- Headers: From: support@domain.com (domain.com Robot)
No errors occur in /var/www/logs/error.log nor in the system messages.
No indication of an email in the system maillog.
when I run the command from the command line like this it works and mail is delivered normally with no problem:
echo 'Subject: test' | chroot /var/www /usr/sbin/sendmail -v myemail@domain.com
The php program I am hitting with my browser is a very simple one:
<?php
session_start();
header( "Content-Type: text/plain" );
echo( 'Configuration Tests:'."\n" );
echo('Testing DNS:'."\n" );
print_r( dns_get_record("trialtoaster.com") );
echo( 'localhost lookup: '.gethostbyname( "localhost" )."\n" );
echo('Testing DateTime:'."\n" );
print_r( getdate() );
echo('Sending test email:'."\n" );
if ( mail("myemail@domain.com", "PHP Test mail", "PHP email - test message.", "From: support@domain.com (domain.com Robot)") ) {
echo '- PHP thinks the email went normally.';
} else {
echo '- PHP thinks the email failed.';
}
?>
The program produces no failures except mail() which dies. The DNS test returns all of the records including the MX records and the date is accurate. In spite of logging correctly in the php mail log.
When displayed, phpinfo() reflects the configuration correctly:
sendmail_path: /usr/sbin/sendmail -t
SMTP: localhost
smtp_port: 25
When I check the packet filter it is allowing anything in on lo0 to go anywhere and when I run the command I can see it on the pftop but nothing shows when I run the mail() from the browser.
I have tied installing a sendmail.ini in the same directory as the chrooted sendmail and that makes no difference whatsoever.
It is starting to look like the OpenBSD chrooted httpd install is incomplete in that in order to use the php mail() command something is just plain completely missing and I fear it might be a bash shell and libraries since the mail sends fine from the command line. This seems out of whack to me since the point of the chroot is to jail hacks and giving a bash shell and libraries to a jailed system just seems like a LOT of surface area for an attack.
I just feel like that CAN'T be the problem, because otherwise, you might as well just drop the chroot and just run it without a jail (it would seem).
Does anyone see what I am missing - and if not and I copy in a shell and libraries, what is the safest way to do that with the minimum exposure and without writing custom wrappers that can just be rewrapped by an attacker anyway?