Permalink
Browse files

- Raise warning when trying to execute non-executeable shell

  for mail delivery binary.
  • Loading branch information...
1 parent 01e5d78 commit d4e63bc5bf1dacce00f317bc2b3b759f6f6138d7 Markus Fischer committed Mar 16, 2002
Showing with 19 additions and 8 deletions.
  1. +1 −1 ext/mbstring/mbstring.c
  2. +1 −2 ext/standard/basic_functions.c
  3. +16 −4 ext/standard/mail.c
  4. +1 −1 ext/standard/php_mail.h
View
@@ -2796,7 +2796,7 @@ PHP_FUNCTION(mb_send_mail)
extra_cmd = Z_STRVAL_PP(argv[4]);
}
- if (!err && php_mail(to, subject, message, headers, extra_cmd)){
+ if (!err && php_mail(to, subject, message, headers, extra_cmd TSRMLS_CC)) {
RETVAL_TRUE;
} else {
RETVAL_FALSE;
@@ -1515,8 +1515,7 @@ PHPAPI int _php_error_log(int opt_err, char *message, char *opt, char *headers T
case 1: /*send an email */
{
#if HAVE_SENDMAIL
- if (!php_mail
- (opt, "PHP error_log message", message, headers, NULL)) {
+ if (!php_mail(opt, "PHP error_log message", message, headers, NULL TSRMLS_CC)) {
return FAILURE;
}
#else
View
@@ -96,7 +96,7 @@ PHP_FUNCTION(mail)
if(extra_cmd)
extra_cmd = php_escape_shell_arg(extra_cmd);
- if (php_mail(to, subject, message, headers, extra_cmd)) {
+ if (php_mail(to, subject, message, headers, extra_cmd TSRMLS_CC)) {
RETVAL_TRUE;
} else {
RETVAL_FALSE;
@@ -108,7 +108,7 @@ PHP_FUNCTION(mail)
/* {{{ php_mail
*/
-PHPAPI int php_mail(char *to, char *subject, char *message, char *headers, char *extra_cmd)
+PHPAPI int php_mail(char *to, char *subject, char *message, char *headers, char *extra_cmd TSRMLS_DC)
{
#ifdef PHP_WIN32
int tsm_err;
@@ -122,7 +122,7 @@ PHPAPI int php_mail(char *to, char *subject, char *message, char *headers, char
#ifdef PHP_WIN32
/* handle old style win smtp sending */
if (TSendMail(INI_STR("SMTP"), &tsm_err, headers, subject, to, message) != SUCCESS){
- php_error(E_WARNING, GetSMErrorText(tsm_err));
+ php_error(E_WARNING, "%s() %s", get_active_function_name(TSRMLS_C), GetSMErrorText(tsm_err));
return 0;
}
return 1;
@@ -142,12 +142,23 @@ PHPAPI int php_mail(char *to, char *subject, char *message, char *headers, char
#ifdef PHP_WIN32
sendmail = popen(sendmail_cmd, "wb");
#else
+ /* Since popen() doesn't indicate if the internal fork() doesn't work
+ * (e.g. the shell can't be executed) we explicitely set it to 0 to be
+ * sure we don't catch any older errno value. */
+ errno = 0;
sendmail = popen(sendmail_cmd, "w");
#endif
if (extra_cmd != NULL)
efree (sendmail_cmd);
if (sendmail) {
+#ifndef PHP_WIN32
+ if (EACCES == errno) {
+ php_error(E_WARNING, "%s() permission denied; unable to execute shell to run mail delivery binary",
+ get_active_function_name(TSRMLS_C));
+ return 0;
+ }
+#endif
fprintf(sendmail, "To: %s\n", to);
fprintf(sendmail, "Subject: %s\n", subject);
if (headers != NULL) {
@@ -170,7 +181,8 @@ PHPAPI int php_mail(char *to, char *subject, char *message, char *headers, char
return 1;
}
} else {
- php_error(E_WARNING, "Could not execute mail delivery program");
+ php_error(E_WARNING, "%s() could not execute mail delivery program",
+ get_active_function_name(TSRMLS_C));
return 0;
}
View
@@ -26,7 +26,7 @@
PHP_FUNCTION(mail);
PHP_FUNCTION(ezmlm_hash);
PHP_MINFO_FUNCTION(mail);
-PHPAPI extern int php_mail(char *to, char *subject, char *message, char *headers, char *extra_cmd);
+PHPAPI extern int php_mail(char *to, char *subject, char *message, char *headers, char *extra_cmd TSRMLS_DC);
#endif

0 comments on commit d4e63bc

Please sign in to comment.