version 1.1, 2012/02/21 23:48:02
|
version 1.1.1.3, 2013/07/22 01:32:05
|
Line 2
|
Line 2
|
+----------------------------------------------------------------------+ |
+----------------------------------------------------------------------+ |
| PHP Version 5 | |
| PHP Version 5 | |
+----------------------------------------------------------------------+ |
+----------------------------------------------------------------------+ |
| Copyright (c) 1997-2012 The PHP Group | | | Copyright (c) 1997-2013 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 19
|
Line 19
|
/* $Id$ */ |
/* $Id$ */ |
|
|
#include "php.h" |
#include "php.h" |
#include "safe_mode.h" |
|
#include "fopen_wrappers.h" |
#include "fopen_wrappers.h" |
#include "php_globals.h" |
#include "php_globals.h" |
|
|
Line 236 PHP_FUNCTION(disk_total_space)
|
Line 235 PHP_FUNCTION(disk_total_space)
|
char *path; |
char *path; |
int path_len; |
int path_len; |
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &path, &path_len) == FAILURE) { | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &path, &path_len) == FAILURE) { |
return; |
return; |
} |
} |
|
|
Line 371 PHP_FUNCTION(disk_free_space)
|
Line 370 PHP_FUNCTION(disk_free_space)
|
char *path; |
char *path; |
int path_len; |
int path_len; |
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &path, &path_len) == FAILURE) { | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &path, &path_len) == FAILURE) { |
return; |
return; |
} |
} |
|
|
Line 379 PHP_FUNCTION(disk_free_space)
|
Line 378 PHP_FUNCTION(disk_free_space)
|
RETURN_FALSE; |
RETURN_FALSE; |
} |
} |
|
|
if (strlen(path) != path_len) { |
|
RETURN_FALSE; |
|
} |
|
|
|
if (php_disk_free_space(path, &bytesfree TSRMLS_CC) == SUCCESS) { |
if (php_disk_free_space(path, &bytesfree TSRMLS_CC) == SUCCESS) { |
RETURN_DOUBLE(bytesfree); |
RETURN_DOUBLE(bytesfree); |
} |
} |
Line 391 PHP_FUNCTION(disk_free_space)
|
Line 386 PHP_FUNCTION(disk_free_space)
|
/* }}} */ |
/* }}} */ |
|
|
#if !defined(WINDOWS) && !defined(NETWARE) |
#if !defined(WINDOWS) && !defined(NETWARE) |
static void php_do_chgrp(INTERNAL_FUNCTION_PARAMETERS, int do_lchgrp) /* {{{ */ | PHPAPI int php_get_gid_by_name(const char *name, gid_t *gid TSRMLS_DC) |
{ |
{ |
char *filename; |
|
int filename_len; |
|
zval *group; |
|
gid_t gid; |
|
int ret; |
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz/", &filename, &filename_len, &group) == FAILURE) { |
|
RETURN_FALSE; |
|
} |
|
|
|
if (strlen(filename) != filename_len) { |
|
RETURN_FALSE; |
|
} |
|
|
|
if (Z_TYPE_P(group) == IS_LONG) { |
|
gid = (gid_t)Z_LVAL_P(group); |
|
} else if (Z_TYPE_P(group) == IS_STRING) { |
|
#if defined(ZTS) && defined(HAVE_GETGRNAM_R) && defined(_SC_GETGR_R_SIZE_MAX) |
#if defined(ZTS) && defined(HAVE_GETGRNAM_R) && defined(_SC_GETGR_R_SIZE_MAX) |
struct group gr; |
struct group gr; |
struct group *retgrptr; |
struct group *retgrptr; |
Line 417 static void php_do_chgrp(INTERNAL_FUNCTION_PARAMETERS,
|
Line 395 static void php_do_chgrp(INTERNAL_FUNCTION_PARAMETERS,
|
char *grbuf; |
char *grbuf; |
|
|
if (grbuflen < 1) { |
if (grbuflen < 1) { |
RETURN_FALSE; | return FAILURE; |
} |
} |
|
|
grbuf = emalloc(grbuflen); |
grbuf = emalloc(grbuflen); |
if (getgrnam_r(Z_STRVAL_P(group), &gr, grbuf, grbuflen, &retgrptr) != 0 || retgrptr == NULL) { | if (getgrnam_r(name, &gr, grbuf, grbuflen, &retgrptr) != 0 || retgrptr == NULL) { |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find gid for %s", Z_STRVAL_P(group)); | |
efree(grbuf); |
efree(grbuf); |
RETURN_FALSE; | return FAILURE; |
} |
} |
efree(grbuf); |
efree(grbuf); |
gid = gr.gr_gid; | *gid = gr.gr_gid; |
#else |
#else |
struct group *gr = getgrnam(Z_STRVAL_P(group)); | struct group *gr = getgrnam(name); |
|
|
if (!gr) { |
if (!gr) { |
|
return FAILURE; |
|
} |
|
*gid = gr->gr_gid; |
|
#endif |
|
return SUCCESS; |
|
} |
|
#endif |
|
|
|
static void php_do_chgrp(INTERNAL_FUNCTION_PARAMETERS, int do_lchgrp) /* {{{ */ |
|
{ |
|
char *filename; |
|
int filename_len; |
|
zval *group; |
|
#if !defined(WINDOWS) |
|
gid_t gid; |
|
int ret; |
|
#endif |
|
php_stream_wrapper *wrapper; |
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "pz/", &filename, &filename_len, &group) == FAILURE) { |
|
RETURN_FALSE; |
|
} |
|
|
|
wrapper = php_stream_locate_url_wrapper(filename, NULL, 0 TSRMLS_CC); |
|
if(wrapper != &php_plain_files_wrapper || strncasecmp("file://", filename, 7) == 0) { |
|
if(wrapper && wrapper->wops->stream_metadata) { |
|
int option; |
|
void *value; |
|
if (Z_TYPE_P(group) == IS_LONG) { |
|
option = PHP_STREAM_META_GROUP; |
|
value = &Z_LVAL_P(group); |
|
} else if (Z_TYPE_P(group) == IS_STRING) { |
|
option = PHP_STREAM_META_GROUP_NAME; |
|
value = Z_STRVAL_P(group); |
|
} else { |
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "parameter 2 should be string or integer, %s given", zend_zval_type_name(group)); |
|
RETURN_FALSE; |
|
} |
|
if(wrapper->wops->stream_metadata(wrapper, filename, option, value, NULL TSRMLS_CC)) { |
|
RETURN_TRUE; |
|
} else { |
|
RETURN_FALSE; |
|
} |
|
} else { |
|
#if !defined(WINDOWS) |
|
/* On Windows, we expect regular chgrp to fail silently by default */ |
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Can not call chgrp() for a non-standard stream"); |
|
#endif |
|
RETURN_FALSE; |
|
} |
|
} |
|
|
|
#if defined(WINDOWS) |
|
/* We have no native chgrp on Windows, nothing left to do if stream doesn't have own implementation */ |
|
RETURN_FALSE; |
|
#else |
|
if (Z_TYPE_P(group) == IS_LONG) { |
|
gid = (gid_t)Z_LVAL_P(group); |
|
} else if (Z_TYPE_P(group) == IS_STRING) { |
|
if(php_get_gid_by_name(Z_STRVAL_P(group), &gid TSRMLS_CC) != SUCCESS) { |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find gid for %s", Z_STRVAL_P(group)); |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find gid for %s", Z_STRVAL_P(group)); |
RETURN_FALSE; |
RETURN_FALSE; |
} |
} |
gid = gr->gr_gid; |
|
#endif |
|
} else { |
} else { |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "parameter 2 should be string or integer, %s given", zend_zval_type_name(group)); |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "parameter 2 should be string or integer, %s given", zend_zval_type_name(group)); |
RETURN_FALSE; |
RETURN_FALSE; |
} |
} |
|
|
if (PG(safe_mode) &&(!php_checkuid(filename, NULL, CHECKUID_ALLOW_FILE_NOT_EXISTS))) { |
|
RETURN_FALSE; |
|
} |
|
|
|
/* Check the basedir */ |
/* Check the basedir */ |
if (php_check_open_basedir(filename TSRMLS_CC)) { |
if (php_check_open_basedir(filename TSRMLS_CC)) { |
RETURN_FALSE; |
RETURN_FALSE; |
Line 463 static void php_do_chgrp(INTERNAL_FUNCTION_PARAMETERS,
|
Line 494 static void php_do_chgrp(INTERNAL_FUNCTION_PARAMETERS,
|
RETURN_FALSE; |
RETURN_FALSE; |
} |
} |
RETURN_TRUE; |
RETURN_TRUE; |
|
#endif |
} |
} |
/* }}} */ |
/* }}} */ |
#endif |
|
|
|
#ifndef NETWARE |
#ifndef NETWARE |
/* {{{ proto bool chgrp(string filename, mixed group) |
/* {{{ proto bool chgrp(string filename, mixed group) |
Change file group */ |
Change file group */ |
PHP_FUNCTION(chgrp) |
PHP_FUNCTION(chgrp) |
{ |
{ |
#if !defined(WINDOWS) |
|
php_do_chgrp(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); |
php_do_chgrp(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); |
#else |
|
RETURN_FALSE; |
|
#endif |
|
} |
} |
/* }}} */ |
/* }}} */ |
|
|
Line 496 PHP_FUNCTION(lchgrp)
|
Line 523 PHP_FUNCTION(lchgrp)
|
#endif /* !NETWARE */ |
#endif /* !NETWARE */ |
|
|
#if !defined(WINDOWS) && !defined(NETWARE) |
#if !defined(WINDOWS) && !defined(NETWARE) |
static void php_do_chown(INTERNAL_FUNCTION_PARAMETERS, int do_lchown) /* {{{ */ | PHPAPI uid_t php_get_uid_by_name(const char *name, uid_t *uid TSRMLS_DC) |
{ |
{ |
char *filename; |
|
int filename_len; |
|
zval *user; |
|
uid_t uid; |
|
int ret; |
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz/", &filename, &filename_len, &user) == FAILURE) { |
|
return; |
|
} |
|
|
|
if (strlen(filename) != filename_len) { |
|
RETURN_FALSE; |
|
} |
|
|
|
if (Z_TYPE_P(user) == IS_LONG) { |
|
uid = (uid_t)Z_LVAL_P(user); |
|
} else if (Z_TYPE_P(user) == IS_STRING) { |
|
#if defined(ZTS) && defined(_SC_GETPW_R_SIZE_MAX) && defined(HAVE_GETPWNAM_R) |
#if defined(ZTS) && defined(_SC_GETPW_R_SIZE_MAX) && defined(HAVE_GETPWNAM_R) |
struct passwd pw; |
struct passwd pw; |
struct passwd *retpwptr = NULL; |
struct passwd *retpwptr = NULL; |
Line 522 static void php_do_chown(INTERNAL_FUNCTION_PARAMETERS,
|
Line 532 static void php_do_chown(INTERNAL_FUNCTION_PARAMETERS,
|
char *pwbuf; |
char *pwbuf; |
|
|
if (pwbuflen < 1) { |
if (pwbuflen < 1) { |
RETURN_FALSE; | return FAILURE; |
} |
} |
|
|
pwbuf = emalloc(pwbuflen); |
pwbuf = emalloc(pwbuflen); |
if (getpwnam_r(Z_STRVAL_P(user), &pw, pwbuf, pwbuflen, &retpwptr) != 0 || retpwptr == NULL) { | if (getpwnam_r(name, &pw, pwbuf, pwbuflen, &retpwptr) != 0 || retpwptr == NULL) { |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find uid for %s", Z_STRVAL_P(user)); | |
efree(pwbuf); |
efree(pwbuf); |
RETURN_FALSE; | return FAILURE; |
} |
} |
efree(pwbuf); |
efree(pwbuf); |
uid = pw.pw_uid; | *uid = pw.pw_uid; |
#else |
#else |
struct passwd *pw = getpwnam(Z_STRVAL_P(user)); | struct passwd *pw = getpwnam(name); |
|
|
if (!pw) { |
if (!pw) { |
|
return FAILURE; |
|
} |
|
*uid = pw->pw_uid; |
|
#endif |
|
return SUCCESS; |
|
} |
|
#endif |
|
|
|
static void php_do_chown(INTERNAL_FUNCTION_PARAMETERS, int do_lchown) /* {{{ */ |
|
{ |
|
char *filename; |
|
int filename_len; |
|
zval *user; |
|
#if !defined(WINDOWS) |
|
uid_t uid; |
|
int ret; |
|
#endif |
|
php_stream_wrapper *wrapper; |
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "pz/", &filename, &filename_len, &user) == FAILURE) { |
|
return; |
|
} |
|
|
|
wrapper = php_stream_locate_url_wrapper(filename, NULL, 0 TSRMLS_CC); |
|
if(wrapper != &php_plain_files_wrapper || strncasecmp("file://", filename, 7) == 0) { |
|
if(wrapper && wrapper->wops->stream_metadata) { |
|
int option; |
|
void *value; |
|
if (Z_TYPE_P(user) == IS_LONG) { |
|
option = PHP_STREAM_META_OWNER; |
|
value = &Z_LVAL_P(user); |
|
} else if (Z_TYPE_P(user) == IS_STRING) { |
|
option = PHP_STREAM_META_OWNER_NAME; |
|
value = Z_STRVAL_P(user); |
|
} else { |
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "parameter 2 should be string or integer, %s given", zend_zval_type_name(user)); |
|
RETURN_FALSE; |
|
} |
|
if(wrapper->wops->stream_metadata(wrapper, filename, option, value, NULL TSRMLS_CC)) { |
|
RETURN_TRUE; |
|
} else { |
|
RETURN_FALSE; |
|
} |
|
} else { |
|
#if !defined(WINDOWS) |
|
/* On Windows, we expect regular chown to fail silently by default */ |
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Can not call chown() for a non-standard stream"); |
|
#endif |
|
RETURN_FALSE; |
|
} |
|
} |
|
|
|
#if defined(WINDOWS) |
|
/* We have no native chown on Windows, nothing left to do if stream doesn't have own implementation */ |
|
RETURN_FALSE; |
|
#else |
|
|
|
if (Z_TYPE_P(user) == IS_LONG) { |
|
uid = (uid_t)Z_LVAL_P(user); |
|
} else if (Z_TYPE_P(user) == IS_STRING) { |
|
if(php_get_uid_by_name(Z_STRVAL_P(user), &uid TSRMLS_CC) != SUCCESS) { |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find uid for %s", Z_STRVAL_P(user)); |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find uid for %s", Z_STRVAL_P(user)); |
RETURN_FALSE; |
RETURN_FALSE; |
} |
} |
uid = pw->pw_uid; |
|
#endif |
|
} else { |
} else { |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "parameter 2 should be string or integer, %s given", zend_zval_type_name(user)); |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "parameter 2 should be string or integer, %s given", zend_zval_type_name(user)); |
RETURN_FALSE; |
RETURN_FALSE; |
} |
} |
|
|
if (PG(safe_mode) && (!php_checkuid(filename, NULL, CHECKUID_ALLOW_FILE_NOT_EXISTS))) { |
|
RETURN_FALSE; |
|
} |
|
|
|
/* Check the basedir */ |
/* Check the basedir */ |
if (php_check_open_basedir(filename TSRMLS_CC)) { |
if (php_check_open_basedir(filename TSRMLS_CC)) { |
RETURN_FALSE; |
RETURN_FALSE; |
Line 567 static void php_do_chown(INTERNAL_FUNCTION_PARAMETERS,
|
Line 631 static void php_do_chown(INTERNAL_FUNCTION_PARAMETERS,
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", strerror(errno)); |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", strerror(errno)); |
RETURN_FALSE; |
RETURN_FALSE; |
} |
} |
|
RETURN_TRUE; |
|
#endif |
} |
} |
/* }}} */ |
/* }}} */ |
#endif |
|
|
|
|
|
#ifndef NETWARE |
#ifndef NETWARE |
/* {{{ proto bool chown (string filename, mixed user) |
/* {{{ proto bool chown (string filename, mixed user) |
Change file owner */ |
Change file owner */ |
PHP_FUNCTION(chown) |
PHP_FUNCTION(chown) |
{ |
{ |
#if !defined(WINDOWS) |
|
RETVAL_TRUE; |
|
php_do_chown(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); |
php_do_chown(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); |
#else |
|
RETURN_FALSE; |
|
#endif |
|
} |
} |
/* }}} */ |
/* }}} */ |
|
|
Line 610 PHP_FUNCTION(chmod)
|
Line 671 PHP_FUNCTION(chmod)
|
long mode; |
long mode; |
int ret; |
int ret; |
mode_t imode; |
mode_t imode; |
|
php_stream_wrapper *wrapper; |
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl", &filename, &filename_len, &mode) == FAILURE) { | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "pl", &filename, &filename_len, &mode) == FAILURE) { |
return; |
return; |
} |
} |
|
|
if (PG(safe_mode) &&(!php_checkuid(filename, NULL, CHECKUID_ALLOW_FILE_NOT_EXISTS))) { | wrapper = php_stream_locate_url_wrapper(filename, NULL, 0 TSRMLS_CC); |
RETURN_FALSE; | if(wrapper != &php_plain_files_wrapper || strncasecmp("file://", filename, 7) == 0) { |
| if(wrapper && wrapper->wops->stream_metadata) { |
| if(wrapper->wops->stream_metadata(wrapper, filename, PHP_STREAM_META_ACCESS, &mode, NULL TSRMLS_CC)) { |
| RETURN_TRUE; |
| } else { |
| RETURN_FALSE; |
| } |
| } else { |
| php_error_docref(NULL TSRMLS_CC, E_WARNING, "Can not call chmod() for a non-standard stream"); |
| RETURN_FALSE; |
| } |
} |
} |
|
|
if (strlen(filename) != filename_len) { |
|
RETURN_FALSE; |
|
} |
|
|
|
/* Check the basedir */ |
/* Check the basedir */ |
if (php_check_open_basedir(filename TSRMLS_CC)) { |
if (php_check_open_basedir(filename TSRMLS_CC)) { |
RETURN_FALSE; |
RETURN_FALSE; |
} |
} |
|
|
imode = (mode_t) mode; |
imode = (mode_t) mode; |
/* In safe mode, do not allow to setuid files. |
|
* Setuiding files could allow users to gain privileges |
|
* that safe mode doesn't give them. */ |
|
|
|
if (PG(safe_mode)) { |
|
php_stream_statbuf ssb; |
|
if (php_stream_stat_path_ex(filename, 0, &ssb, NULL)) { |
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "stat failed for %s", filename); |
|
RETURN_FALSE; |
|
} |
|
if ((imode & 04000) != 0 && (ssb.sb.st_mode & 04000) == 0) { |
|
imode ^= 04000; |
|
} |
|
if ((imode & 02000) != 0 && (ssb.sb.st_mode & 02000) == 0) { |
|
imode ^= 02000; |
|
} |
|
if ((imode & 01000) != 0 && (ssb.sb.st_mode & 01000) == 0) { |
|
imode ^= 01000; |
|
} |
|
} |
|
|
|
ret = VCWD_CHMOD(filename, imode); |
ret = VCWD_CHMOD(filename, imode); |
if (ret == -1) { |
if (ret == -1) { |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", strerror(errno)); |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", strerror(errno)); |
Line 671 PHP_FUNCTION(touch)
|
Line 719 PHP_FUNCTION(touch)
|
FILE *file; |
FILE *file; |
struct utimbuf newtimebuf; |
struct utimbuf newtimebuf; |
struct utimbuf *newtime = &newtimebuf; |
struct utimbuf *newtime = &newtimebuf; |
|
php_stream_wrapper *wrapper; |
|
|
if (zend_parse_parameters(argc TSRMLS_CC, "s|ll", &filename, &filename_len, &filetime, &fileatime) == FAILURE) { | if (zend_parse_parameters(argc TSRMLS_CC, "p|ll", &filename, &filename_len, &filetime, &fileatime) == FAILURE) { |
return; |
return; |
} |
} |
|
|
if (strlen(filename) != filename_len) { | if (!filename_len) { |
RETURN_FALSE; |
RETURN_FALSE; |
} |
} |
|
|
Line 700 PHP_FUNCTION(touch)
|
Line 749 PHP_FUNCTION(touch)
|
WRONG_PARAM_COUNT; |
WRONG_PARAM_COUNT; |
} |
} |
|
|
/* Safe-mode */ | wrapper = php_stream_locate_url_wrapper(filename, NULL, 0 TSRMLS_CC); |
if (PG(safe_mode) && (!php_checkuid(filename, NULL, CHECKUID_CHECK_FILE_AND_DIR))) { | if(wrapper != &php_plain_files_wrapper || strncasecmp("file://", filename, 7) == 0) { |
RETURN_FALSE; | if(wrapper && wrapper->wops->stream_metadata) { |
| if(wrapper->wops->stream_metadata(wrapper, filename, PHP_STREAM_META_TOUCH, newtime, NULL TSRMLS_CC)) { |
| RETURN_TRUE; |
| } else { |
| RETURN_FALSE; |
| } |
| } else { |
| php_stream *stream; |
| if(argc > 1) { |
| php_error_docref(NULL TSRMLS_CC, E_WARNING, "Can not call touch() for a non-standard stream"); |
| RETURN_FALSE; |
| } |
| stream = php_stream_open_wrapper_ex(filename, "c", REPORT_ERRORS, NULL, NULL); |
| if(stream != NULL) { |
| php_stream_pclose(stream); |
| RETURN_TRUE; |
| } else { |
| RETURN_FALSE; |
| } |
| } |
} |
} |
|
|
/* Check the basedir */ |
/* Check the basedir */ |
Line 735 PHP_FUNCTION(touch)
|
Line 803 PHP_FUNCTION(touch)
|
PHPAPI void php_clear_stat_cache(zend_bool clear_realpath_cache, const char *filename, int filename_len TSRMLS_DC) |
PHPAPI void php_clear_stat_cache(zend_bool clear_realpath_cache, const char *filename, int filename_len TSRMLS_DC) |
{ |
{ |
/* always clear CurrentStatFile and CurrentLStatFile even if filename is not NULL |
/* always clear CurrentStatFile and CurrentLStatFile even if filename is not NULL |
* as it may contain outdated data (e.g. "nlink" for a directory when deleting a file | * as it may contains outdated data (e.g. "nlink" for a directory when deleting a file |
* in this directory, as shown by lstat_stat_variation9.phpt) */ |
* in this directory, as shown by lstat_stat_variation9.phpt) */ |
|
|
if (BG(CurrentStatFile)) { |
if (BG(CurrentStatFile)) { |
efree(BG(CurrentStatFile)); |
efree(BG(CurrentStatFile)); |
BG(CurrentStatFile) = NULL; |
BG(CurrentStatFile) = NULL; |
Line 764 PHP_FUNCTION(clearstatcache)
|
Line 831 PHP_FUNCTION(clearstatcache)
|
char *filename = NULL; |
char *filename = NULL; |
int filename_len = 0; |
int filename_len = 0; |
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|bs", &clear_realpath_cache, &filename, &filename_len) == FAILURE) { | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|bp", &clear_realpath_cache, &filename, &filename_len) == FAILURE) { |
return; |
return; |
} |
} |
|
|
Line 792 PHPAPI void php_stat(const char *filename, php_stat_le
|
Line 859 PHPAPI void php_stat(const char *filename, php_stat_le
|
}; |
}; |
char *local; |
char *local; |
php_stream_wrapper *wrapper; |
php_stream_wrapper *wrapper; |
char safe_mode_buf[MAXPATHLEN]; |
|
|
|
if (!filename_length) { |
if (!filename_length) { |
RETURN_FALSE; |
RETURN_FALSE; |
} |
} |
|
|
if (strlen(filename) != filename_length) { | if ((wrapper = php_stream_locate_url_wrapper(filename, &local, 0 TSRMLS_CC)) == &php_plain_files_wrapper && php_check_open_basedir(local TSRMLS_CC)) { |
RETURN_FALSE; |
RETURN_FALSE; |
} |
} |
|
|
if ((wrapper = php_stream_locate_url_wrapper(filename, &local, 0 TSRMLS_CC)) == &php_plain_files_wrapper) { |
|
if (php_check_open_basedir(local TSRMLS_CC)) { |
|
RETURN_FALSE; |
|
} else if (PG(safe_mode)) { |
|
if (type == FS_IS_X) { |
|
if (strstr(local, "..")) { |
|
RETURN_FALSE; |
|
} else { |
|
char *b = strrchr(local, PHP_DIR_SEPARATOR); |
|
snprintf(safe_mode_buf, MAXPATHLEN, "%s%s%s", PG(safe_mode_exec_dir), (b ? "" : "/"), (b ? b : local)); |
|
local = (char *)&safe_mode_buf; |
|
} |
|
} else if (!php_checkuid_ex(local, NULL, CHECKUID_ALLOW_FILE_NOT_EXISTS, CHECKUID_NO_ERRORS)) { |
|
RETURN_FALSE; |
|
} |
|
} |
|
} |
|
|
|
if (IS_ACCESS_CHECK(type)) { |
if (IS_ACCESS_CHECK(type)) { |
if (wrapper == &php_plain_files_wrapper) { |
if (wrapper == &php_plain_files_wrapper) { |
|
|
Line 856 PHPAPI void php_stat(const char *filename, php_stat_le
|
Line 904 PHPAPI void php_stat(const char *filename, php_stat_le
|
} |
} |
|
|
if (php_stream_stat_path_ex((char *)filename, flags, &ssb, NULL)) { |
if (php_stream_stat_path_ex((char *)filename, flags, &ssb, NULL)) { |
/* Error Occured */ | /* Error Occurred */ |
if (!IS_EXISTS_CHECK(type)) { |
if (!IS_EXISTS_CHECK(type)) { |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%sstat failed for %s", IS_LINK_OPERATION(type) ? "L" : "", filename); |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%sstat failed for %s", IS_LINK_OPERATION(type) ? "L" : "", filename); |
} |
} |
Line 1034 void name(INTERNAL_FUNCTION_PARAMETERS) { \
|
Line 1082 void name(INTERNAL_FUNCTION_PARAMETERS) { \
|
char *filename; \ |
char *filename; \ |
int filename_len; \ |
int filename_len; \ |
\ |
\ |
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) { \ | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &filename, &filename_len) == FAILURE) { \ |
return; \ |
return; \ |
} \ |
} \ |
\ |
\ |
Line 1160 PHP_FUNCTION(realpath_cache_get)
|
Line 1208 PHP_FUNCTION(realpath_cache_get)
|
MAKE_STD_ZVAL(entry); |
MAKE_STD_ZVAL(entry); |
array_init(entry); |
array_init(entry); |
|
|
add_assoc_long(entry, "key", bucket->key); | /* bucket->key is unsigned long */ |
| if (LONG_MAX >= bucket->key) { |
| add_assoc_long(entry, "key", bucket->key); |
| } else { |
| add_assoc_double(entry, "key", (double)bucket->key); |
| } |
add_assoc_bool(entry, "is_dir", bucket->is_dir); |
add_assoc_bool(entry, "is_dir", bucket->is_dir); |
add_assoc_stringl(entry, "realpath", bucket->realpath, bucket->realpath_len, 1); |
add_assoc_stringl(entry, "realpath", bucket->realpath, bucket->realpath_len, 1); |
add_assoc_long(entry, "expires", bucket->expires); |
add_assoc_long(entry, "expires", bucket->expires); |