Download | Plain Text | No Line Numbers


  1. diff -Naur php-5.3.2.orig/ext/standard/mail.c php-5.3.2/ext/standard/mail.c
  2. --- php-5.3.2.orig/ext/standard/mail.c 2010-02-05 01:19:32.000000000 +0100
  3. +++ php-5.3.2/ext/standard/mail.c 2010-06-04 00:34:46.000000000 +0200
  4. @@ -271,6 +271,20 @@
  5. sendmail_cmd = sendmail_path;
  6. }
  7.  
  8. + zval suexec_user;
  9. + char *env_user1 = NULL;
  10. + char *env_user2 = NULL;
  11. + if (zend_get_constant("SUEXEC_USER", sizeof("SUEXEC_USER") - 1, &suexec_user TSRMLS_CC)) {
  12. + if (Z_TYPE(suexec_user) == IS_STRING && Z_STRLEN(suexec_user) != 0) {
  13. + env_user1 = emalloc(sizeof("USER=") + Z_STRLEN(suexec_user) + 1);
  14. + strcpy(env_user1, "USER=");
  15. + strcat(env_user1, Z_STRVAL(suexec_user));
  16. + env_user2 = getenv("USER");
  17. + putenv(env_user1);
  18. + }
  19. + zval_dtor(&suexec_user);
  20. + }
  21. +
  22. #if PHP_SIGCHILD
  23. /* Set signal handler of SIGCHLD to default to prevent other signal handlers
  24. * from being called and reaping the return code when our child exits.
  25. @@ -294,6 +308,14 @@
  26. efree (sendmail_cmd);
  27. }
  28.  
  29. + if (env_user1 != NULL) {
  30. + if (env_user2 != NULL)
  31. + putenv(env_user2 - sizeof("USER"));
  32. + else
  33. + unsetenv("USER");
  34. + efree(env_user1);
  35. + }
  36. +
  37. if (sendmail) {
  38. #ifndef PHP_WIN32
  39. if (EACCES == errno) {
  40. diff -Naur php-5.3.2.orig/sapi/apache/mod_php5.c php-5.3.2/sapi/apache/mod_php5.c
  41. --- php-5.3.2.orig/sapi/apache/mod_php5.c 2010-02-05 20:34:47.000000000 +0100
  42. +++ php-5.3.2/sapi/apache/mod_php5.c 2010-06-04 00:34:00.000000000 +0200
  43. @@ -260,6 +260,15 @@
  44. HashTable *symbol_table;
  45. unsigned int new_val_len;
  46.  
  47. +#if !defined(WIN32) && !defined(WINNT)
  48. + server_rec *serv;
  49. + struct passwd *suexec_pw;
  50. + struct group *suexec_gr;
  51. + extern uid_t user_id;
  52. + extern gid_t group_id;
  53. + extern int suexec_enabled;
  54. +#endif
  55. +
  56. for (i = 0; i < arr->nelts; i++) {
  57. char *val;
  58. int val_len;
  59. @@ -290,6 +299,19 @@
  60. php_register_variable("PATH_TRANSLATED", Z_STRVAL_PP(path_translated), track_vars_array TSRMLS_CC);
  61. }
  62.  
  63. +#if !defined(WIN32) && !defined(WINNT)
  64. + zend_hash_del(EG(zend_constants), "SUEXEC_USER", sizeof("SUEXEC_USER"));
  65. + zend_hash_del(EG(zend_constants), "SUEXEC_GROUP", sizeof("SUEXEC_GROUP"));
  66. + serv = ((request_rec *) SG(server_context))->server;
  67. + if (suexec_enabled
  68. + && serv->server_uid != user_id
  69. + && (suexec_pw = getpwuid(serv->server_uid)) != NULL
  70. + && (suexec_gr = getgrgid(serv->server_gid)) != NULL) {
  71. + REGISTER_MAIN_STRINGL_CONSTANT("SUEXEC_USER", estrdup(suexec_pw->pw_name), strlen(suexec_pw->pw_name), CONST_CS);
  72. + REGISTER_MAIN_STRINGL_CONSTANT("SUEXEC_GROUP", estrdup(suexec_gr->gr_name), strlen(suexec_gr->gr_name), CONST_CS);
  73. + }
  74. +#endif
  75. +
  76. if (sapi_module.input_filter(PARSE_SERVER, "PHP_SELF", &((request_rec *) SG(server_context))->uri, strlen(((request_rec *) SG(server_context))->uri), &new_val_len TSRMLS_CC)) {
  77. php_register_variable("PHP_SELF", ((request_rec *) SG(server_context))->uri, track_vars_array TSRMLS_CC);
  78. }
  79. diff -Naur php-5.3.2.orig/sapi/apache/php_apache.c php-5.3.2/sapi/apache/php_apache.c
  80. --- php-5.3.2.orig/sapi/apache/php_apache.c 2010-01-03 10:23:27.000000000 +0100
  81. +++ php-5.3.2/sapi/apache/php_apache.c 2010-06-04 00:34:00.000000000 +0200
  82. @@ -168,6 +168,8 @@
  83. char name[64];
  84. char modulenames[1024];
  85. char *p;
  86. + struct passwd *pw;
  87. + extern int suexec_enabled;
  88. #endif
  89. server_rec *serv;
  90. extern char server_root[MAX_STRING_LEN];
  91. @@ -209,6 +211,12 @@
  92. #if !defined(WIN32) && !defined(WINNT)
  93. snprintf(output_buf, sizeof(output_buf), "%s(%d)/%d", user_name, (int)user_id, (int)group_id);
  94. php_info_print_table_row(2, "User/Group", output_buf);
  95. + if (suexec_enabled
  96. + && serv->server_uid != user_id
  97. + && (pw = getpwuid(serv->server_uid)) != NULL) {
  98. + sprintf(output_buf, "%s(%ld)/%ld", pw->pw_name, (long)serv->server_uid, (long)serv->server_gid);
  99. + php_info_print_table_row(2, "Suexec User/Group", output_buf);
  100. + }
  101. snprintf(output_buf, sizeof(output_buf), "Per Child: %d - Keep Alive: %s - Max Per Connection: %d", max_requests_per_child, serv->keep_alive ? "on":"off", serv->keep_alive_max);
  102. php_info_print_table_row(2, "Max Requests", output_buf);
  103. #endif
  104. diff -Naur php-5.3.2.orig/sapi/apache2handler/php_functions.c php-5.3.2/sapi/apache2handler/php_functions.c
  105. --- php-5.3.2.orig/sapi/apache2handler/php_functions.c 2010-01-03 10:23:27.000000000 +0100
  106. +++ php-5.3.2/sapi/apache2handler/php_functions.c 2010-06-04 00:34:00.000000000 +0200
  107. @@ -377,6 +377,8 @@
  108. #else
  109. AP_DECLARE_DATA extern unixd_config_rec unixd_config;
  110. #endif
  111. + ap_unix_identity_t *identity;
  112. + struct passwd *pw;
  113. #endif
  114.  
  115. for (n = 0; ap_loaded_modules[n]; ++n) {
  116. @@ -413,6 +415,23 @@
  117. snprintf(tmp, sizeof(tmp), "%s(%d)/%d", unixd_config.user_name, unixd_config.user_id, unixd_config.group_id);
  118. #endif
  119. php_info_print_table_row(2, "User/Group", tmp);
  120. +#if MODULE_MAGIC_NUMBER_MAJOR >= 20081201
  121. + if (ap_unixd_config.suexec_enabled
  122. + && (identity = ap_run_get_suexec_identity(((php_struct *) SG(server_context))->r))
  123. + && identity->uid != ap_unixd_config.user_id
  124. + && (pw = getpwuid(identity->uid)) != NULL) {
  125. + sprintf(tmp, "%s(%ld)/%ld", pw->pw_name, (long)identity->uid, (long)identity->gid);
  126. + php_info_print_table_row(2, "Suexec User/Group", tmp);
  127. + }
  128. +#else
  129. + if (unixd_config.suexec_enabled
  130. + && (identity = ap_run_get_suexec_identity(((php_struct *) SG(server_context))->r))
  131. + && identity->uid != unixd_config.user_id
  132. + && (pw = getpwuid(identity->uid)) != NULL) {
  133. + sprintf(tmp, "%s(%ld)/%ld", pw->pw_name, (long)identity->uid, (long)identity->gid);
  134. + php_info_print_table_row(2, "Suexec User/Group", tmp);
  135. + }
  136. +#endif
  137. #endif
  138.  
  139. ap_mpm_query(AP_MPMQ_MAX_REQUESTS_DAEMON, &max_requests);
  140. diff -Naur php-5.3.2.orig/sapi/apache2handler/sapi_apache2.c php-5.3.2/sapi/apache2handler/sapi_apache2.c
  141. --- php-5.3.2.orig/sapi/apache2handler/sapi_apache2.c 2010-02-05 20:34:47.000000000 +0100
  142. +++ php-5.3.2/sapi/apache2handler/sapi_apache2.c 2010-06-04 00:34:00.000000000 +0200
  143. @@ -50,6 +50,9 @@
  144. #include "util_script.h"
  145. #include "http_core.h"
  146. #include "ap_mpm.h"
  147. +#if !defined(WIN32) && !defined(WINNT)
  148. +#include "unixd.h"
  149. +#endif
  150.  
  151. #include "php_apache.h"
  152.  
  153. @@ -258,6 +261,13 @@
  154. char *key, *val;
  155. int new_val_len;
  156.  
  157. +#if !defined(WIN32) && !defined(WINNT)
  158. + AP_DECLARE_DATA extern unixd_config_rec unixd_config;
  159. + ap_unix_identity_t *identity;
  160. + struct passwd *suexec_pw;
  161. + struct group *suexec_gr;
  162. +#endif
  163. +
  164. APR_ARRAY_FOREACH_OPEN(arr, key, val)
  165. if (!val) {
  166. val = "";
  167. @@ -267,6 +277,19 @@
  168. }
  169. APR_ARRAY_FOREACH_CLOSE()
  170.  
  171. +#if !defined(WIN32) && !defined(WINNT)
  172. + zend_hash_del(EG(zend_constants), "SUEXEC_USER", sizeof("SUEXEC_USER"));
  173. + zend_hash_del(EG(zend_constants), "SUEXEC_GROUP", sizeof("SUEXEC_GROUP"));
  174. + if (unixd_config.suexec_enabled
  175. + && (identity = ap_run_get_suexec_identity(((php_struct *) SG(server_context))->r))
  176. + && identity->uid != unixd_config.user_id
  177. + && (suexec_pw = getpwuid(identity->uid)) != NULL
  178. + && (suexec_gr = getgrgid(identity->gid)) != NULL) {
  179. + REGISTER_MAIN_STRINGL_CONSTANT("SUEXEC_USER", estrdup(suexec_pw->pw_name), strlen(suexec_pw->pw_name), CONST_CS);
  180. + REGISTER_MAIN_STRINGL_CONSTANT("SUEXEC_GROUP", estrdup(suexec_gr->gr_name), strlen(suexec_gr->gr_name), CONST_CS);
  181. + }
  182. +#endif
  183. +
  184. if (sapi_module.input_filter(PARSE_SERVER, "PHP_SELF", &ctx->r->uri, strlen(ctx->r->uri), &new_val_len TSRMLS_CC)) {
  185. php_register_variable_safe("PHP_SELF", ctx->r->uri, new_val_len, track_vars_array TSRMLS_CC);
  186. }
  187.