summaryrefslogtreecommitdiff
path: root/main/fopen_wrappers.c
diff options
context:
space:
mode:
authorSara Golemon <pollita@php.net>2006-10-17 21:54:17 +0000
committerSara Golemon <pollita@php.net>2006-10-17 21:54:17 +0000
commitbe5debc65a28a15334ade0c7d3292ca5a9a007c0 (patch)
treec0c64b7a045a0da0620d26a90a8cdaa2b6baee63 /main/fopen_wrappers.c
parentcfb3b054a8e29137bac574a5d780b96188695c4f (diff)
downloadphp-git-be5debc65a28a15334ade0c7d3292ca5a9a007c0.tar.gz
Extend open_basedir functionality to allow runtime tightening
Diffstat (limited to 'main/fopen_wrappers.c')
-rw-r--r--main/fopen_wrappers.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/main/fopen_wrappers.c b/main/fopen_wrappers.c
index 265097d8ba..7f22be32ba 100644
--- a/main/fopen_wrappers.c
+++ b/main/fopen_wrappers.c
@@ -82,6 +82,64 @@
#endif
/* }}} */
+/* {{{ OnUpdateBaseDir
+Allows any change to open_basedir setting in during Startup and Shutdown events,
+or a tightening during activation/runtime/deactivation */
+PHPAPI ZEND_INI_MH(OnUpdateBaseDir)
+{
+ char **p, *pathbuf, *ptr, *end;
+#ifndef ZTS
+ char *base = (char *) mh_arg2;
+#else
+ char *base = (char *) ts_resource(*((int *) mh_arg2));
+#endif
+
+ p = (char **) (base+(size_t) mh_arg1);
+
+ if (stage == PHP_INI_STAGE_STARTUP || stage == PHP_INI_STAGE_SHUTDOWN) {
+ /* We're in a PHP_INI_SYSTEM context, no restrictions */
+ *p = new_value;
+ return SUCCESS;
+ }
+
+
+ /* Elsewise, we're in runtime */
+ if (!*p || !**p) {
+ /* open_basedir not set yet, go ahead and give it a value */
+ *p = new_value;
+ return SUCCESS;
+ }
+
+ /* Shortcut: When we have a open_basedir and someone tries to unset, we know it'll fail */
+ if (!new_value || !*new_value) {
+ return FAILURE;
+ }
+
+ /* Is the proposed open_basedir at least as restrictive as the current setting? */
+ ptr = pathbuf = estrdup(new_value);
+ while (ptr && *ptr) {
+ end = strchr(ptr, DEFAULT_DIR_SEPARATOR);
+ if (end != NULL) {
+ *end = '\0';
+ end++;
+ }
+ if (php_check_open_basedir_ex(ptr, 0 TSRMLS_CC) != 0) {
+ /* At least one portion of this open_basedir is less restrictive than the prior one, FAIL */
+ efree(pathbuf);
+ return FAILURE;
+ }
+ ptr = end;
+ }
+ efree(pathbuf);
+
+ /* Everything checks out, set it */
+ *p = new_value;
+
+ return SUCCESS;
+}
+/* }}} */
+
+
/* {{{ php_check_specific_open_basedir
When open_basedir is not NULL, check if the given filename is located in
open_basedir. Returns -1 if error or not in the open_basedir, else 0