version 1.1.1.1, 2012/02/21 23:48:02
|
version 1.1.1.4, 2014/06/15 20:03:57
|
Line 2
|
Line 2
|
+----------------------------------------------------------------------+ |
+----------------------------------------------------------------------+ |
| PHP Version 5 | |
| PHP Version 5 | |
+----------------------------------------------------------------------+ |
+----------------------------------------------------------------------+ |
| Copyright (c) 1997-2012 The PHP Group | | | Copyright (c) 1997-2014 The PHP Group | |
+----------------------------------------------------------------------+ |
+----------------------------------------------------------------------+ |
| This source file is subject to version 3.01 of the PHP license, | |
| This source file is subject to version 3.01 of the PHP license, | |
| that is bundled with this package in the file LICENSE, and is | |
| that is bundled with this package in the file LICENSE, and is | |
Line 148 PHP_MINIT_FUNCTION(dir)
|
Line 148 PHP_MINIT_FUNCTION(dir)
|
pathsep_str[1] = '\0'; |
pathsep_str[1] = '\0'; |
REGISTER_STRING_CONSTANT("PATH_SEPARATOR", pathsep_str, CONST_CS|CONST_PERSISTENT); |
REGISTER_STRING_CONSTANT("PATH_SEPARATOR", pathsep_str, CONST_CS|CONST_PERSISTENT); |
|
|
|
REGISTER_LONG_CONSTANT("SCANDIR_SORT_ASCENDING", PHP_SCANDIR_SORT_ASCENDING, CONST_CS | CONST_PERSISTENT); |
|
REGISTER_LONG_CONSTANT("SCANDIR_SORT_DESCENDING", PHP_SCANDIR_SORT_DESCENDING, CONST_CS | CONST_PERSISTENT); |
|
REGISTER_LONG_CONSTANT("SCANDIR_SORT_NONE", PHP_SCANDIR_SORT_NONE, CONST_CS | CONST_PERSISTENT); |
|
|
#ifdef HAVE_GLOB |
#ifdef HAVE_GLOB |
|
|
#ifdef GLOB_BRACE |
#ifdef GLOB_BRACE |
Line 221 static void _php_do_opendir(INTERNAL_FUNCTION_PARAMETE
|
Line 225 static void _php_do_opendir(INTERNAL_FUNCTION_PARAMETE
|
|
|
context = php_stream_context_from_zval(zcontext, 0); |
context = php_stream_context_from_zval(zcontext, 0); |
|
|
dirp = php_stream_opendir(dirname, ENFORCE_SAFE_MODE|REPORT_ERRORS, context); | dirp = php_stream_opendir(dirname, REPORT_ERRORS, context); |
|
|
if (dirp == NULL) { |
if (dirp == NULL) { |
RETURN_FALSE; |
RETURN_FALSE; |
Line 321 PHP_FUNCTION(chdir)
|
Line 325 PHP_FUNCTION(chdir)
|
char *str; |
char *str; |
int ret, str_len; |
int ret, str_len; |
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) == FAILURE) { | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &str, &str_len) == FAILURE) { |
RETURN_FALSE; |
RETURN_FALSE; |
} |
} |
|
|
if (strlen(str) != str_len) { | if (php_check_open_basedir(str TSRMLS_CC)) { |
RETURN_FALSE; |
RETURN_FALSE; |
} |
} |
|
|
if ((PG(safe_mode) && !php_checkuid(str, NULL, CHECKUID_CHECK_FILE_AND_DIR)) || php_check_open_basedir(str TSRMLS_CC)) { |
|
RETURN_FALSE; |
|
} |
|
ret = VCWD_CHDIR(str); |
ret = VCWD_CHDIR(str); |
|
|
if (ret != 0) { |
if (ret != 0) { |
Line 436 PHP_FUNCTION(glob)
|
Line 436 PHP_FUNCTION(glob)
|
int ret; |
int ret; |
zend_bool basedir_limit = 0; |
zend_bool basedir_limit = 0; |
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &pattern, &pattern_len, &flags) == FAILURE) { | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p|l", &pattern, &pattern_len, &flags) == FAILURE) { |
return; |
return; |
} |
} |
|
|
if (strlen(pattern) != pattern_len) { |
|
RETURN_FALSE; |
|
} |
|
|
|
if (pattern_len >= MAXPATHLEN) { |
if (pattern_len >= MAXPATHLEN) { |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Pattern exceeds the maximum allowed length of %d characters", MAXPATHLEN); |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Pattern exceeds the maximum allowed length of %d characters", MAXPATHLEN); |
RETURN_FALSE; |
RETURN_FALSE; |
Line 495 PHP_FUNCTION(glob)
|
Line 491 PHP_FUNCTION(glob)
|
/* now catch the FreeBSD style of "no matches" */ |
/* now catch the FreeBSD style of "no matches" */ |
if (!globbuf.gl_pathc || !globbuf.gl_pathv) { |
if (!globbuf.gl_pathc || !globbuf.gl_pathv) { |
no_results: |
no_results: |
if (PG(safe_mode) || (PG(open_basedir) && *PG(open_basedir))) { | if (PG(open_basedir) && *PG(open_basedir)) { |
struct stat s; |
struct stat s; |
|
|
if (0 != VCWD_STAT(pattern, &s) || S_IFDIR != (s.st_mode & S_IFMT)) { |
if (0 != VCWD_STAT(pattern, &s) || S_IFDIR != (s.st_mode & S_IFMT)) { |
Line 508 no_results:
|
Line 504 no_results:
|
|
|
array_init(return_value); |
array_init(return_value); |
for (n = 0; n < globbuf.gl_pathc; n++) { |
for (n = 0; n < globbuf.gl_pathc; n++) { |
if (PG(safe_mode) || (PG(open_basedir) && *PG(open_basedir))) { | if (PG(open_basedir) && *PG(open_basedir)) { |
if (PG(safe_mode) && (!php_checkuid_ex(globbuf.gl_pathv[n], NULL, CHECKUID_CHECK_FILE_AND_DIR, CHECKUID_NO_ERRORS))) { | if (php_check_open_basedir_ex(globbuf.gl_pathv[n], 0 TSRMLS_CC)) { |
basedir_limit = 1; |
basedir_limit = 1; |
continue; |
continue; |
} else if (php_check_open_basedir_ex(globbuf.gl_pathv[n], 0 TSRMLS_CC)) { |
|
basedir_limit = 1; |
|
continue; |
|
} |
} |
} |
} |
/* we need to do this everytime since GLOB_ONLYDIR does not guarantee that |
/* we need to do this everytime since GLOB_ONLYDIR does not guarantee that |
Line 561 PHP_FUNCTION(scandir)
|
Line 554 PHP_FUNCTION(scandir)
|
zval *zcontext = NULL; |
zval *zcontext = NULL; |
php_stream_context *context = NULL; |
php_stream_context *context = NULL; |
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|lr", &dirn, &dirn_len, &flags, &zcontext) == FAILURE) { | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p|lr", &dirn, &dirn_len, &flags, &zcontext) == FAILURE) { |
return; |
return; |
} |
} |
|
|
if (strlen(dirn) != dirn_len) { |
|
RETURN_FALSE; |
|
} |
|
|
|
if (dirn_len < 1) { |
if (dirn_len < 1) { |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Directory name cannot be empty"); |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Directory name cannot be empty"); |
RETURN_FALSE; |
RETURN_FALSE; |
Line 578 PHP_FUNCTION(scandir)
|
Line 567 PHP_FUNCTION(scandir)
|
context = php_stream_context_from_zval(zcontext, 0); |
context = php_stream_context_from_zval(zcontext, 0); |
} |
} |
|
|
if (!flags) { | if (flags == PHP_SCANDIR_SORT_ASCENDING) { |
n = php_stream_scandir(dirn, &namelist, context, (void *) php_stream_dirent_alphasort); |
n = php_stream_scandir(dirn, &namelist, context, (void *) php_stream_dirent_alphasort); |
|
} else if (flags == PHP_SCANDIR_SORT_NONE) { |
|
n = php_stream_scandir(dirn, &namelist, context, NULL); |
} else { |
} else { |
n = php_stream_scandir(dirn, &namelist, context, (void *) php_stream_dirent_alphasortr); |
n = php_stream_scandir(dirn, &namelist, context, (void *) php_stream_dirent_alphasortr); |
} |
} |