]> granicus.if.org Git - php/commitdiff
- Added the chroot function for changing root in a script.
authorDerick Rethans <derick@php.net>
Wed, 14 Feb 2001 10:48:48 +0000 (10:48 +0000)
committerDerick Rethans <derick@php.net>
Wed, 14 Feb 2001 10:48:48 +0000 (10:48 +0000)
#- This can be usefull when using PHP in a shell environment, or when PHP
#  runs as CGI which needs a little more security

ext/standard/basic_functions.c
ext/standard/dir.c
ext/standard/php_dir.h

index d1e6fa3ff9b252ce3246bc2d99ae53d66ad98541..40c37b85f8c1c4523aa0ddb3bce1e4ef501ed1a0 100644 (file)
@@ -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)
index 97f2ac89c608fd805ec9abb434849e23e50a4da0..37d7ddfb658b2c613b7f41f98f6d9a821d2c5a36 100644 (file)
@@ -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 */
index 8bbaba3b80d87e22789a8647c919edad438aeebd..7e48f0783e4e0319214e637ed704a32484aac0b5 100644 (file)
@@ -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);