summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDerick Rethans <derick@php.net>2001-02-14 10:48:48 +0000
committerDerick Rethans <derick@php.net>2001-02-14 10:48:48 +0000
commit4a54a15fc6060b15d27970827ddb104e983e1058 (patch)
treee4df16a0a6779483f52295f0c7986af511c07aea
parentf5874e9758ac7001fd24f62752b476fba655cc42 (diff)
downloadphp-git-4a54a15fc6060b15d27970827ddb104e983e1058.tar.gz
- Added the chroot function for changing root in a script.
#- This can be usefull when using PHP in a shell environment, or when PHP # runs as CGI which needs a little more security
-rw-r--r--ext/standard/basic_functions.c1
-rw-r--r--ext/standard/dir.c24
-rw-r--r--ext/standard/php_dir.h1
3 files changed, 26 insertions, 0 deletions
diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c
index d1e6fa3ff9..40c37b85f8 100644
--- a/ext/standard/basic_functions.c
+++ b/ext/standard/basic_functions.c
@@ -465,6 +465,7 @@ function_entry basic_functions[] = {
PHP_FE(opendir, NULL)
PHP_FE(closedir, NULL)
PHP_FE(chdir, NULL)
+ PHP_FE(chroot, NULL)
PHP_FE(getcwd, NULL)
PHP_FE(rewinddir, NULL)
PHP_STATIC_FE("readdir", php_if_readdir, NULL)
diff --git a/ext/standard/dir.c b/ext/standard/dir.c
index 97f2ac89c6..37d7ddfb65 100644
--- a/ext/standard/dir.c
+++ b/ext/standard/dir.c
@@ -222,6 +222,30 @@ PHP_FUNCTION(closedir)
}
/* }}} */
+/* {{{ proto int chroot(string directory)
+ Change root directory */
+
+PHP_FUNCTION(chroot)
+{
+ pval **arg;
+ int ret;
+
+ if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) {
+ WRONG_PARAM_COUNT;
+ }
+ convert_to_string_ex(arg);
+
+ ret = chroot((*arg)->value.str.val);
+
+ if (ret != 0) {
+ php_error(E_WARNING, "chroot: %s (errno %d)", strerror(errno), errno);
+ RETURN_FALSE;
+ }
+
+ RETURN_TRUE;
+}
+
+/* }}} */
/* {{{ proto int chdir(string directory)
Change the current directory */
diff --git a/ext/standard/php_dir.h b/ext/standard/php_dir.h
index 8bbaba3b80..7e48f0783e 100644
--- a/ext/standard/php_dir.h
+++ b/ext/standard/php_dir.h
@@ -28,6 +28,7 @@ PHP_RINIT_FUNCTION(dir);
PHP_FUNCTION(opendir);
PHP_FUNCTION(closedir);
PHP_FUNCTION(chdir);
+PHP_FUNCTION(chroot);
PHP_FUNCTION(getcwd);
PHP_FUNCTION(rewinddir);
PHP_NAMED_FUNCTION(php_if_readdir);