From: Derick Rethans Date: Wed, 14 Feb 2001 10:48:48 +0000 (+0000) Subject: - Added the chroot function for changing root in a script. X-Git-Tag: php-4.0.5RC1~292 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4a54a15fc6060b15d27970827ddb104e983e1058;p=php - 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 --- 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 @@ -221,6 +221,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);