|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-01-09 20:51 UTC] tuxracer69 at gmail dot com
Description:
------------
The milter SAPI seems unable to get the values of the sendmail macros using the smfi_getsymval function.
My steup:
0) I compile PHP with "--with-milter --disable-cli --disable-cgi"
1) I create a script milter1.php (code below)
2) I insert in my /etc/mail/sendmail.mc the two lines below:
======
define(`MILTER',`1')dnl
INPUT_MAIL_FILTER(`php-milter1',`S=local:/tmp/milter.sock,F=T,T=S:10m;R:10m;E:10m')dnl
======
3) I start the milter with:
php-milter -D -p /tmp/milter.sock milter1.php
4) I forge a mail to localhot using telnet to port 25
5) I look at the milter logs which shoud display the vaue of the "i" sendmail macro (the sendmail queueid).
Reproduce code:
---------------
<?php
function milter_log($msg)
{
$GLOBALS['log'] = fopen("/var/log/milter.log", "a");
fwrite($GLOBALS['log'], date("[H:i:s d.m.Y] p").getmypid()."\t{$msg}\n");
fclose($GLOBALS['log']);
}
function milter_init() {
milter_log("-- startup --");
milter_log("milter_init()");
}
function milter_envfrom($args){
$queueid=smfi_getsymval("i");
milter_log("queueid=".$queueid);
milter_log("milter_envfrom(args[])");
foreach ($args as $ix => $arg) {
milter_log("\targs[$ix] = $arg");
}
}
?>
Expected result:
----------------
After having started the milter:
# php-milter -D -p /tmp/milter.sock milter1.php
I forge a mail:
# telnet localhost 25
Trying 127.0.0.1...
Connected to debi.
Escape character is '^]'.
220 debi.local. ESMTP Sendmail 8.13.7/8.13.7/Debian-2; Tue, 9 Jan 2007 21:25:35 +0100; (No UCE/UBE) logging access from: debi(OK)-debi [127.0.0.1]
helo me
250 debi.local. Hello debi [127.0.0.1], pleased to meet you
mail from: test@atpic.com
250 2.1.0 test@atpic.com... Sender ok
quit
221 2.0.0 debi.local. closing connection
Connection closed by foreign host.
I get the queueid from the sendmail logs:
# tail -n 1 /var/log/mail.log
Jan 9 21:25:55 debi sm-mta[14429]: l09KPZRk014429: from=test@atpic.com, size=0, class=0, nrcpts=0, proto=SMTP, daemon=MTA-v4, relay=debi [127.0.0.1]
And a would expect a line in the milter logs saying
[21:25:49 09.01.2007] p14426 queueid=l09KPZRk014429
But (see below the logs I get), I can not get any value for the "i" macro.
I am sure it is set. If I strace -v -f the milter I see the queueid in a read system call.
Actual result:
--------------
The third line in the milter logs shows a blank queueid
tail -f /var/log/milter.log
[21:25:26 09.01.2007] p14426 -- startup --
[21:25:26 09.01.2007] p14426 milter_init()
[21:25:49 09.01.2007] p14426 queueid=
[21:25:49 09.01.2007] p14426 milter_envfrom(args[])
[21:25:49 09.01.2007] p14426 args[0] = test@atpic.com
I tried to modify my PHP code and call the macro "{i}" but it does not help.
I would say it is a PHP bug and not a sendmail bug; here is my sendmail version anyway:
# sendmail -d0.1
Version 8.13.7
Compiled with: DNSMAP LDAPMAP LDAP_REFERRALS LOG MAP_REGEX MATCHGECOS
MILTER MIME7TO8 MIME8TO7 NAMED_BIND NETINET NETINET6 NETUNIX
NEWDB NIS NISPLUS PIPELINING SASLv2 SCANF SOCKETMAP STARTTLS
USERDB USE_LDAP_INIT XDEBUG
============ SYSTEM IDENTITY (after readcf) ============
(short domain name) $w = debi
(canonical domain name) $j = debi.local.
(subdomain name) $m = local.
(node name) $k = debi
========================================================
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 08:00:01 2025 UTC |
Hi Iliia, I confirm it is bug in PHP and I even provide a fix below ;) and thus reopen this bug. In the file PHPROOT/sapi/milter/php_milter.c the last line in the function PHP_FUNCTION(smfi_getsymval) (i.e. the line RETVAL_NULL(); ) seems to be always called and thus the function when called in PHP always return NULL. Although I am not a SAPI expert (nor a C expert BTW) and thus do not understand why it is always called, removing this line and considering each case fixes the bug. Iliia could you please confirm this? Thanks Alex ==== here is an example of code fixing the bug ====== PHP_FUNCTION(smfi_getsymval) { char *symname, *ret; int len; /* valid in any callback */ if (MG(state) == MLFI_NONE) { /*php_error(E_WARNING, IS_NONE, get_active_function_name(TSRMLS_C));*/ RETVAL_STRING("MLFI_NONE", 1); } else { if (zend_parse_parameters(1 TSRMLS_CC, "s", &symname, &len) == SUCCESS) { if ((ret = smfi_getsymval(MG(ctx), symname)) != NULL) { RETVAL_STRING(ret, 1); } else { RETVAL_STRING("isnull", 1); } } else { RETVAL_STRING("zend_parse_parameters returned FAILURE", 1); } } } Note that if I just add again the line RETVAL_NULL(); at the bottom of the function above, I will again get a NULL string all the time.