--- embedaddon/php/ext/standard/dir.c 2012/02/21 23:48:02 1.1.1.1 +++ embedaddon/php/ext/standard/dir.c 2012/05/29 12:34:43 1.1.1.2 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: dir.c,v 1.1.1.1 2012/02/21 23:48:02 misho Exp $ */ +/* $Id: dir.c,v 1.1.1.2 2012/05/29 12:34:43 misho Exp $ */ /* {{{ includes/startup/misc */ @@ -148,6 +148,10 @@ PHP_MINIT_FUNCTION(dir) pathsep_str[1] = '\0'; 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 GLOB_BRACE @@ -221,7 +225,7 @@ static void _php_do_opendir(INTERNAL_FUNCTION_PARAMETE 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) { RETURN_FALSE; @@ -321,17 +325,13 @@ PHP_FUNCTION(chdir) char *str; 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; } - if (strlen(str) != str_len) { + if (php_check_open_basedir(str TSRMLS_CC)) { 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); if (ret != 0) { @@ -436,14 +436,10 @@ PHP_FUNCTION(glob) int ret; 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; } - if (strlen(pattern) != pattern_len) { - RETURN_FALSE; - } - if (pattern_len >= MAXPATHLEN) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Pattern exceeds the maximum allowed length of %d characters", MAXPATHLEN); RETURN_FALSE; @@ -495,7 +491,7 @@ PHP_FUNCTION(glob) /* now catch the FreeBSD style of "no matches" */ if (!globbuf.gl_pathc || !globbuf.gl_pathv) { no_results: - if (PG(safe_mode) || (PG(open_basedir) && *PG(open_basedir))) { + if (PG(open_basedir) && *PG(open_basedir)) { struct stat s; if (0 != VCWD_STAT(pattern, &s) || S_IFDIR != (s.st_mode & S_IFMT)) { @@ -508,13 +504,10 @@ no_results: array_init(return_value); for (n = 0; n < globbuf.gl_pathc; n++) { - if (PG(safe_mode) || (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 (PG(open_basedir) && *PG(open_basedir)) { + if (php_check_open_basedir_ex(globbuf.gl_pathv[n], 0 TSRMLS_CC)) { basedir_limit = 1; 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 @@ -561,14 +554,10 @@ PHP_FUNCTION(scandir) zval *zcontext = 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; } - if (strlen(dirn) != dirn_len) { - RETURN_FALSE; - } - if (dirn_len < 1) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Directory name cannot be empty"); RETURN_FALSE; @@ -578,8 +567,10 @@ PHP_FUNCTION(scandir) 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); + } else if (flags == PHP_SCANDIR_SORT_NONE) { + n = php_stream_scandir(dirn, &namelist, context, NULL); } else { n = php_stream_scandir(dirn, &namelist, context, (void *) php_stream_dirent_alphasortr); }