Download | Plain Text | No Line Numbers


  1. diff -Naur php-5.3.18.orig/ext/standard/exec.c php-5.3.18/ext/standard/exec.c
  2. --- php-5.3.18.orig/ext/standard/exec.c 2012-10-25 16:59:06.000000000 +0200
  3. +++ php-5.3.18/ext/standard/exec.c 2012-10-25 17:00:44.000000000 +0200
  4. @@ -70,6 +70,7 @@
  5. void (*sig_handler)() = NULL;
  6. #endif
  7. char *safe_dir = NULL;
  8. + zval suexec_user, suexec_group;
  9.  
  10. if (PG(safe_mode)) {
  11. safe_dir = PG(safe_mode_exec_dir);
  12. @@ -107,6 +108,32 @@
  13. cmd_p = cmd;
  14. }
  15.  
  16. + if (PG(suexec_path) && strlen(PG(suexec_path))) {
  17. + if (!zend_get_constant("SUEXEC_USER", sizeof("SUEXEC_USER") - 1, &suexec_user TSRMLS_CC)) {
  18. + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to fetch suexec user");
  19. + goto err;
  20. + }
  21. + if (!zend_get_constant("SUEXEC_GROUP", sizeof("SUEXEC_GROUP") - 1, &suexec_group TSRMLS_CC)) {
  22. + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to fetch suexec group");
  23. + zval_dtor(&suexec_user);
  24. + goto err;
  25. + }
  26. + if (Z_TYPE(suexec_user) != IS_STRING || Z_STRLEN(suexec_user) <= 0 ||
  27. + Z_TYPE(suexec_group) != IS_STRING || Z_STRLEN(suexec_group) <= 0) {
  28. + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid value for suexec user or group");
  29. + zval_dtor(&suexec_user);
  30. + zval_dtor(&suexec_group);
  31. + goto err;
  32. + }
  33. + spprintf(&b, 0, "%s %s %s %s", PG(suexec_path), Z_STRVAL(suexec_user), Z_STRVAL(suexec_group), cmd_p);
  34. + if (d) {
  35. + efree(d);
  36. + }
  37. + cmd_p = d = b;
  38. + zval_dtor(&suexec_user);
  39. + zval_dtor(&suexec_group);
  40. + }
  41. +
  42. #if PHP_SIGCHILD
  43. sig_handler = signal (SIGCHLD, SIG_DFL);
  44. #endif
  45. @@ -487,6 +514,7 @@
  46. char *ret;
  47. php_stream *stream;
  48. char *command_p;
  49. + zval suexec_user, suexec_group;
  50.  
  51. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &command, &command_len) == FAILURE) {
  52. return;
  53. @@ -523,6 +551,35 @@
  54. command_p = estrdup(command);
  55. }
  56.  
  57. + if (PG(suexec_path) && strlen(PG(suexec_path))) {
  58. + if (!zend_get_constant("SUEXEC_USER", sizeof("SUEXEC_USER") - 1, &suexec_user TSRMLS_CC)) {
  59. + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to fetch suexec user");
  60. + efree(command_p);
  61. + RETURN_FALSE;
  62. + }
  63. + if (!zend_get_constant("SUEXEC_GROUP", sizeof("SUEXEC_GROUP") - 1, &suexec_group TSRMLS_CC)) {
  64. + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to fetch suexec group");
  65. + zval_dtor(&suexec_user);
  66. + efree(command_p);
  67. + RETURN_FALSE;
  68. + }
  69. + if (Z_TYPE(suexec_user) != IS_STRING || Z_STRLEN(suexec_user) <= 0 ||
  70. + Z_TYPE(suexec_group) != IS_STRING || Z_STRLEN(suexec_group) <= 0) {
  71. + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid value for suexec user or group");
  72. + zval_dtor(&suexec_user);
  73. + zval_dtor(&suexec_group);
  74. + efree(command_p);
  75. + RETURN_FALSE;
  76. + }
  77. +
  78. + char *b;
  79. + spprintf(&b, 0, "%s %s %s %s", PG(suexec_path), Z_STRVAL(suexec_user), Z_STRVAL(suexec_group), command_p);
  80. + efree(command_p);
  81. + command_p = b;
  82. + zval_dtor(&suexec_user);
  83. + zval_dtor(&suexec_group);
  84. + }
  85. +
  86. #ifdef PHP_WIN32
  87. if ((in=VCWD_POPEN(command_p, "rt"))==NULL) {
  88. #else
  89. diff -Naur php-5.3.18.orig/ext/standard/file.c php-5.3.18/ext/standard/file.c
  90. --- php-5.3.18.orig/ext/standard/file.c 2012-10-25 16:59:06.000000000 +0200
  91. +++ php-5.3.18/ext/standard/file.c 2012-10-25 17:00:44.000000000 +0200
  92. @@ -974,6 +974,7 @@
  93. php_stream *stream;
  94. char *posix_mode, *b, *buf = 0, *tmp;
  95. char *safe_dir = NULL;
  96. + zval suexec_user, suexec_group;
  97.  
  98. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &command, &command_len, &mode, &mode_len) == FAILURE) {
  99. return;
  100. @@ -989,6 +990,28 @@
  101. }
  102. #endif
  103.  
  104. + if (PG(suexec_path) && strlen(PG(suexec_path))) {
  105. + if (!zend_get_constant("SUEXEC_USER", sizeof("SUEXEC_USER") - 1, &suexec_user TSRMLS_CC)) {
  106. + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to fetch suexec user");
  107. + efree(posix_mode);
  108. + RETURN_FALSE;
  109. + }
  110. + if (!zend_get_constant("SUEXEC_GROUP", sizeof("SUEXEC_GROUP") - 1, &suexec_group TSRMLS_CC)) {
  111. + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to fetch suexec group");
  112. + zval_dtor(&suexec_user);
  113. + efree(posix_mode);
  114. + RETURN_FALSE;
  115. + }
  116. + if (Z_TYPE(suexec_user) != IS_STRING || Z_STRLEN(suexec_user) <= 0 ||
  117. + Z_TYPE(suexec_group) != IS_STRING || Z_STRLEN(suexec_group) <= 0) {
  118. + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid value for suexec user or group");
  119. + zval_dtor(&suexec_user);
  120. + zval_dtor(&suexec_group);
  121. + efree(posix_mode);
  122. + RETURN_FALSE;
  123. + }
  124. + }
  125. +
  126. if (PG(safe_mode)) {
  127. safe_dir = PG(safe_mode_exec_dir);
  128. } else if (PG(exec_dir) && strlen(PG(exec_dir))) {
  129. @@ -1015,6 +1038,15 @@
  130. }
  131.  
  132. tmp = php_escape_shell_cmd(buf);
  133. +
  134. + if (PG(suexec_path) && strlen(PG(suexec_path))) {
  135. + spprintf(&b, 0, "%s %s %s %s", PG(suexec_path), Z_STRVAL(suexec_user), Z_STRVAL(suexec_group), tmp);
  136. + efree(tmp);
  137. + tmp = b;
  138. + zval_dtor(&suexec_user);
  139. + zval_dtor(&suexec_group);
  140. + }
  141. +
  142. fp = VCWD_POPEN(tmp, posix_mode);
  143. efree(tmp);
  144.  
  145. @@ -1028,7 +1060,17 @@
  146. efree(buf);
  147.  
  148. } else {
  149. - fp = VCWD_POPEN(command, posix_mode);
  150. + if (PG(suexec_path) && strlen(PG(suexec_path))) {
  151. + spprintf(&tmp, 0, "%s %s %s %s", PG(suexec_path), Z_STRVAL(suexec_user), Z_STRVAL(suexec_group), command);
  152. + zval_dtor(&suexec_user);
  153. + zval_dtor(&suexec_group);
  154. + } else {
  155. + tmp = estrdup(command);
  156. + }
  157. +
  158. + fp = VCWD_POPEN(tmp, posix_mode);
  159. + efree(tmp);
  160. +
  161. if (!fp) {
  162. php_error_docref2(NULL TSRMLS_CC, command, posix_mode, E_WARNING, "%s", strerror(errno));
  163. efree(posix_mode);
  164. diff -Naur php-5.3.18.orig/main/main.c php-5.3.18/main/main.c
  165. --- php-5.3.18.orig/main/main.c 2012-10-25 16:59:06.000000000 +0200
  166. +++ php-5.3.18/main/main.c 2012-10-25 17:01:34.000000000 +0200
  167. @@ -550,6 +550,7 @@
  168. STD_PHP_INI_BOOLEAN("windows.show_crt_warning", "0", PHP_INI_ALL, OnUpdateBool, windows_show_crt_warning, php_core_globals, core_globals)
  169. #endif
  170. STD_PHP_INI_ENTRY("exec_dir", NULL, PHP_INI_SYSTEM, OnUpdateString, exec_dir, php_core_globals, core_globals)
  171. + STD_PHP_INI_ENTRY("suexec_path", NULL, PHP_INI_SYSTEM, OnUpdateString, suexec_path, php_core_globals, core_globals)
  172. PHP_INI_END()
  173. /* }}} */
  174.  
  175. diff -Naur php-5.3.18.orig/main/php_globals.h php-5.3.18/main/php_globals.h
  176. --- php-5.3.18.orig/main/php_globals.h 2012-10-25 16:59:06.000000000 +0200
  177. +++ php-5.3.18/main/php_globals.h 2012-10-25 17:02:20.000000000 +0200
  178. @@ -177,6 +177,7 @@
  179.  
  180. long max_input_vars;
  181. char *exec_dir;
  182. + char *suexec_path;
  183. };
  184.  
  185.  
  186. diff -Naur php-5.3.18.orig/php.ini-development php-5.3.18/php.ini-development
  187. --- php-5.3.18.orig/php.ini-development 2012-10-25 16:59:06.000000000 +0200
  188. +++ php-5.3.18/php.ini-development 2012-10-25 17:00:44.000000000 +0200
  189. @@ -878,6 +878,10 @@
  190. ; http://php.net/cgi.rfc2616-headers
  191. ;cgi.rfc2616_headers = 0
  192.  
  193. +; suEXEC-like-wrapper for the exec-family. Only useful for mod_php.
  194. +; Used only if nonempty.
  195. +suexec_path =
  196. +
  197. ;;;;;;;;;;;;;;;;
  198. ; File Uploads ;
  199. ;;;;;;;;;;;;;;;;
  200. diff -Naur php-5.3.18.orig/php.ini-production php-5.3.18/php.ini-production
  201. --- php-5.3.18.orig/php.ini-production 2012-10-25 16:59:06.000000000 +0200
  202. +++ php-5.3.18/php.ini-production 2012-10-25 17:00:44.000000000 +0200
  203. @@ -878,6 +878,10 @@
  204. ; http://php.net/cgi.rfc2616-headers
  205. ;cgi.rfc2616_headers = 0
  206.  
  207. +; suEXEC-like-wrapper for the exec-family. Only useful for mod_php.
  208. +; Used only if nonempty.
  209. +suexec_path =
  210. +
  211. ;;;;;;;;;;;;;;;;
  212. ; File Uploads ;
  213. ;;;;;;;;;;;;;;;;
  214.