Go to:
Gentoo Home
Documentation
Forums
Lists
Bugs
Planet
Store
Wiki
Get Gentoo!
Gentoo's Bugzilla – Attachment 122223 Details for
Bug 182187
dev-lang/php-5.2.x - patch for logging of mail() function
Home
|
New
–
[Ex]
|
Browse
|
Search
|
Privacy Policy
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
php-5.2.2-mail-log.patch
php-5.2.2-mail-log.patch (text/plain), 6.37 KB, created by
Krzysztof Pawlik (RETIRED)
on 2007-06-16 11:56:53 UTC
(
hide
)
Description:
php-5.2.2-mail-log.patch
Filename:
MIME Type:
Creator:
Krzysztof Pawlik (RETIRED)
Created:
2007-06-16 11:56:53 UTC
Size:
6.37 KB
patch
obsolete
>diff -Nru php-5.2.2.vanilla/ext/standard/mail.c php-5.2.2/ext/standard/mail.c >--- php-5.2.2.vanilla/ext/standard/mail.c 2007-06-16 12:34:10.000000000 +0200 >+++ php-5.2.2/ext/standard/mail.c 2007-06-16 13:19:49.000000000 +0200 >@@ -23,6 +23,8 @@ > #include <stdio.h> > #include "php.h" > #include "ext/standard/info.h" >+#include "ext/standard/php_string.h" >+#include "ext/standard/basic_functions.h" > > #if HAVE_SYSEXITS_H > #include <sysexits.h> >@@ -62,6 +64,7 @@ > *p = ' '; \ > } \ > >+extern long php_getuid(void); > > /* {{{ proto int ezmlm_hash(string addr) > Calculate EZMLM list hash value. */ >@@ -201,22 +204,67 @@ > int ret; > char *sendmail_path = INI_STR("sendmail_path"); > char *sendmail_cmd = NULL; >+ char *mail_log = INI_STR("mail.log"); >+ char *hdr = headers; >+ >+#define MAIL_RET(val) \ >+ if (hdr != headers) { \ >+ efree(hdr); \ >+ } \ >+ return val; \ >+ >+ if (mail_log) { >+ char *tmp; >+ int l = spprintf(&tmp, 0, "mail() on [%s:%d]: To: %s -- Headers: %s\n", zend_get_executed_filename(TSRMLS_C), zend_get_executed_lineno(TSRMLS_C), to, hdr ? hdr : ""); >+ if (hdr) { /* find all \r\n instances and replace them with spaces, so a log line is always one line long */ >+ char *p = tmp; >+ while ((p = strpbrk(p, "\r\n"))) { >+ *p = ' '; >+ } >+ tmp[l - 1] = '\n'; >+ } >+ _php_error_log(3, tmp, mail_log, NULL TSRMLS_CC); >+ efree(tmp); >+ } >+ if (PG(mail_x_header)) { >+ char *tmp = zend_get_executed_filename(TSRMLS_C); >+ char *f; >+ size_t f_len; >+ php_basename(tmp, strlen(tmp), NULL, 0, &f, &f_len TSRMLS_CC); >+ >+ if (!sendmail_path) { >+ /* sending via SMTP requires \r\n, but ... */ >+ if (headers != NULL) { >+ spprintf(&hdr, 0, "%s\r\nX-PHP-Originating-Script: %ld:%s\r\n", headers, php_getuid(), f); >+ } else { >+ spprintf(&hdr, 0, "X-PHP-Originating-Script: %ld:%s\r\n", php_getuid(), f); >+ } >+ } else { >+ /* ... sending via sendmail requires \n */ >+ if (headers != NULL) { >+ spprintf(&hdr, 0, "%s\nX-PHP-Originating-Script: %ld:%s\n", headers, php_getuid(), f); >+ } else { >+ spprintf(&hdr, 0, "X-PHP-Originating-Script: %ld:%s\n", php_getuid(), f); >+ } >+ } >+ efree(f); >+ } > > if (!sendmail_path) { > #if (defined PHP_WIN32 || defined NETWARE) > /* handle old style win smtp sending */ >- if (TSendMail(INI_STR("SMTP"), &tsm_err, &tsm_errmsg, headers, subject, to, message, NULL, NULL, NULL TSRMLS_CC) == FAILURE) { >+ if (TSendMail(INI_STR("SMTP"), &tsm_err, &tsm_errmsg, hdr, subject, to, message, NULL, NULL, NULL TSRMLS_CC) == FAILURE) { > if (tsm_errmsg) { > php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", tsm_errmsg); > efree(tsm_errmsg); > } else { > php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", GetSMErrorText(tsm_err)); > } >- return 0; >+ MAIL_RET(0); > } >- return 1; >+ MAIL_RET(1); > #else >- return 0; >+ MAIL_RET(0); > #endif > } > if (extra_cmd != NULL) { >@@ -242,13 +290,13 @@ > if (EACCES == errno) { > php_error_docref(NULL TSRMLS_CC, E_WARNING, "Permission denied: unable to execute shell to run mail delivery binary '%s'", sendmail_path); > pclose(sendmail); >- return 0; >+ MAIL_RET(0); > } > #endif > fprintf(sendmail, "To: %s\n", to); > fprintf(sendmail, "Subject: %s\n", subject); >- if (headers != NULL) { >- fprintf(sendmail, "%s\n", headers); >+ if (hdr != NULL) { >+ fprintf(sendmail, "%s\n", hdr); > } > fprintf(sendmail, "\n%s\n", message); > ret = pclose(sendmail); >@@ -264,16 +312,16 @@ > #endif > #endif > { >- return 0; >+ MAIL_RET(0); > } else { >- return 1; >+ MAIL_RET(1); > } > } else { > php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not execute mail delivery program '%s'", sendmail_path); >- return 0; >+ MAIL_RET(0); > } > >- return 1; /* never reached */ >+ MAIL_RET(1); /* never reached */ > } > /* }}} */ > >diff -Nru php-5.2.2.vanilla/main/main.c php-5.2.2/main/main.c >--- php-5.2.2.vanilla/main/main.c 2007-06-16 12:34:11.000000000 +0200 >+++ php-5.2.2/main/main.c 2007-06-16 12:37:13.000000000 +0200 >@@ -316,6 +316,8 @@ > > PHP_INI_ENTRY("SMTP", "localhost",PHP_INI_ALL, NULL) > PHP_INI_ENTRY("smtp_port", "25", PHP_INI_ALL, NULL) >+ STD_PHP_INI_BOOLEAN("mail.add_x_header", "0", PHP_INI_SYSTEM, OnUpdateBool, mail_x_header, php_core_globals, core_globals) >+ STD_PHP_INI_ENTRY("mail.log", NULL, PHP_INI_SYSTEM, OnUpdateString, mail_log, php_core_globals, core_globals) > PHP_INI_ENTRY("browscap", NULL, PHP_INI_SYSTEM, NULL) > PHP_INI_ENTRY("memory_limit", "128M", PHP_INI_ALL, OnChangeMemoryLimit) > PHP_INI_ENTRY("precision", "14", PHP_INI_ALL, OnSetPrecision) >diff -Nru php-5.2.2.vanilla/main/php_globals.h php-5.2.2/main/php_globals.h >--- php-5.2.2.vanilla/main/php_globals.h 2007-06-16 12:34:11.000000000 +0200 >+++ php-5.2.2/main/php_globals.h 2007-06-16 12:37:59.000000000 +0200 >@@ -71,6 +71,9 @@ > char *unserialize_callback_func; > long serialize_precision; > >+ zend_bool mail_x_header; >+ char *mail_log; >+ > char *safe_mode_exec_dir; > > long memory_limit; >diff -Nru php-5.2.2.vanilla/php.ini-dist php-5.2.2/php.ini-dist >--- php-5.2.2.vanilla/php.ini-dist 2007-06-16 12:34:12.000000000 +0200 >+++ php-5.2.2/php.ini-dist 2007-06-16 12:35:33.000000000 +0200 >@@ -686,6 +686,12 @@ > ; For Unix only. You may supply arguments as well (default: "sendmail -t -i"). > ;sendmail_path = > >+; Add X-PHP-Originaiting-Script: that will include uid of the script followed by the filename >+mail.add_x_header = On >+ >+; Log all mail() calls including the full path of the script, line #, to address and headers >+mail.log = >+ > ; Force the addition of the specified parameters to be passed as extra parameters > ; to the sendmail binary. These parameters will always replace the value of > ; the 5th parameter to mail(), even in safe mode. >diff -Nru php-5.2.2.vanilla/php.ini-recommended php-5.2.2/php.ini-recommended >--- php-5.2.2.vanilla/php.ini-recommended 2007-06-16 12:34:12.000000000 +0200 >+++ php-5.2.2/php.ini-recommended 2007-06-16 12:35:33.000000000 +0200 >@@ -731,6 +731,12 @@ > ; For Unix only. You may supply arguments as well (default: "sendmail -t -i"). > ;sendmail_path = > >+; Add X-PHP-Originaiting-Script: that will include uid of the script followed by the filename >+mail.add_x_header = On >+ >+; Log all mail() calls including the full path of the script, line #, to address and headers >+mail.log = >+ > ; Force the addition of the specified parameters to be passed as extra parameters > ; to the sendmail binary. These parameters will always replace the value of > ; the 5th parameter to mail(), even in safe mode.
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 182187
: 122223