cvs: php4(PHP_4_0_7) /ext/standard filestat.c
| From: | Sterling Hughes | Date: | Thu, 13 Dec 2001 13:51:42 +0000 |
| Subject: | cvs: php4(PHP_4_0_7) /ext/standard filestat.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-8600@lists.php.net to get a copy of this message | ||
sterling Thu Dec 13 08:51:42 2001 EDT
Modified files: (Branch: PHP_4_0_7)
/php4/ext/standard filestat.c
Log:
MFH
Index: php4/ext/standard/filestat.c diff -u php4/ext/standard/filestat.c:1.78.2.1 php4/ext/standard/filestat.c:1.78.2.2 --- php4/ext/standard/filestat.c:1.78.2.1 Tue Aug 21 19:59:21 2001 +++ php4/ext/standard/filestat.c Thu Dec 13 08:51:42 2001 @@ -1,8 +1,8 @@ /* +----------------------------------------------------------------------+ - | PHP version 4.0 | + | PHP Version 4 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2001 The PHP Group | + | Copyright (c) 1997-2002 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 2.02 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: filestat.c,v 1.78.2.1 2001/08/21 23:59:21 joey Exp $ */ +/* $Id: filestat.c,v 1.78.2.2 2001/12/13 13:51:42 sterling Exp $ */ #include "php.h" #include "safe_mode.h" @@ -118,14 +118,15 @@ return SUCCESS; } -PHP_RSHUTDOWN_FUNCTION(filestat) { +PHP_RSHUTDOWN_FUNCTION(filestat) +{ if (BG(CurrentStatFile)) { efree (BG(CurrentStatFile)); } return SUCCESS; } -/* {{{ proto double disk_total_space(string path) +/* {{{ proto float disk_total_space(string path) Get total disk space for filesystem that path is on */ PHP_FUNCTION(disk_total_space) { @@ -164,7 +165,7 @@ convert_to_string_ex(path); - if (php_check_open_basedir((*path)->value.str.val TSRMLS_CC)) { + if (php_check_open_basedir(Z_STRVAL_PP(path) TSRMLS_CC)) { RETURN_FALSE; } @@ -178,7 +179,7 @@ /* It's available, so we can call it. */ if (gdfse) { func = (gdfse_func)gdfse; - if (func((*path)->value.str.val, + if (func(Z_STRVAL_PP(path), &FreeBytesAvailableToCaller, &TotalNumberOfBytes, &TotalNumberOfFreeBytes) == 0) RETURN_FALSE; @@ -190,7 +191,7 @@ } /* If it's not available, we just use GetDiskFreeSpace */ else { - if (GetDiskFreeSpace((*path)->value.str.val, + if (GetDiskFreeSpace(Z_STRVAL_PP(path), &SectorsPerCluster, &BytesPerSector, &NumberOfFreeClusters, &TotalNumberOfClusters) == 0) RETURN_FALSE; bytestotal = (double)TotalNumberOfClusters * (double)SectorsPerCluster * (double)BytesPerSector; @@ -204,14 +205,14 @@ #elif defined(OS2) { FSALLOCATE fsinfo; - char drive = (*path)->value.str.val[0] & 95; + char drive = Z_STRVAL_PP(path)[0] & 95; if (DosQueryFSInfo( drive ? drive - 64 : 0, FSIL_ALLOC, &fsinfo, sizeof( fsinfo ) ) == 0) bytestotal = (double)fsinfo.cbSector * fsinfo.cSectorUnit * fsinfo.cUnit; } #else /* WINDOWS, OS/2 */ #if defined(HAVE_SYS_STATVFS_H) && defined(HAVE_STATVFS) - if (statvfs((*path)->value.str.val, &buf)) RETURN_FALSE; + if (statvfs(Z_STRVAL_PP(path), &buf)) RETURN_FALSE; if (buf.f_frsize) { bytestotal = (((double)buf.f_blocks) * ((double)buf.f_frsize)); } else { @@ -219,7 +220,7 @@ } #elif (defined(HAVE_SYS_STATFS_H) || defined(HAVE_SYS_MOUNT_H)) && defined(HAVE_STATFS) - if (statfs((*path)->value.str.val, &buf)) RETURN_FALSE; + if (statfs(Z_STRVAL_PP(path), &buf)) RETURN_FALSE; bytestotal = (((double)buf.f_bsize) * ((double)buf.f_blocks)); #endif #endif /* WINDOWS */ @@ -228,7 +229,7 @@ } /* }}} */ -/* {{{ proto double disk_free_space(string path) +/* {{{ proto float disk_free_space(string path) Get free disk space for filesystem that path is on */ PHP_FUNCTION(disk_free_space) { @@ -267,7 +268,7 @@ convert_to_string_ex(path); - if (php_check_open_basedir((*path)->value.str.val TSRMLS_CC)) { + if (php_check_open_basedir(Z_STRVAL_PP(path) TSRMLS_CC)) { RETURN_FALSE; } @@ -281,7 +282,7 @@ /* It's available, so we can call it. */ if (gdfse) { func = (gdfse_func)gdfse; - if (func((*path)->value.str.val, + if (func(Z_STRVAL_PP(path), &FreeBytesAvailableToCaller, &TotalNumberOfBytes, &TotalNumberOfFreeBytes) == 0) RETURN_FALSE; @@ -293,7 +294,7 @@ } /* If it's not available, we just use GetDiskFreeSpace */ else { - if (GetDiskFreeSpace((*path)->value.str.val, + if (GetDiskFreeSpace(Z_STRVAL_PP(path), &SectorsPerCluster, &BytesPerSector, &NumberOfFreeClusters, &TotalNumberOfClusters) == 0) RETURN_FALSE; bytesfree = (double)NumberOfFreeClusters * (double)SectorsPerCluster * (double)BytesPerSector; @@ -307,21 +308,21 @@ #elif defined(OS2) { FSALLOCATE fsinfo; - char drive = (*path)->value.str.val[0] & 95; + char drive = Z_STRVAL_PP(path)[0] & 95; if (DosQueryFSInfo( drive ? drive - 64 : 0, FSIL_ALLOC, &fsinfo, sizeof( fsinfo ) ) == 0) bytesfree = (double)fsinfo.cbSector * fsinfo.cSectorUnit * fsinfo.cUnitAvail; } #else /* WINDOWS, OS/2 */ #if defined(HAVE_SYS_STATVFS_H) && defined(HAVE_STATVFS) - if (statvfs((*path)->value.str.val, &buf)) RETURN_FALSE; + if (statvfs(Z_STRVAL_PP(path), &buf)) RETURN_FALSE; if (buf.f_frsize) { bytesfree = (((double)buf.f_bavail) * ((double)buf.f_frsize)); } else { bytesfree = (((double)buf.f_bavail) * ((double)buf.f_bsize)); } #elif (defined(HAVE_SYS_STATFS_H) || defined(HAVE_SYS_MOUNT_H)) && defined(HAVE_STATFS) - if (statfs((*path)->value.str.val, &buf)) RETURN_FALSE; + if (statfs(Z_STRVAL_PP(path), &buf)) RETURN_FALSE; bytesfree = (((double)buf.f_bsize) * ((double)buf.f_bavail)); #endif #endif /* WINDOWS */ @@ -344,29 +345,29 @@ WRONG_PARAM_COUNT; } convert_to_string_ex(filename); - if ((*group)->type == IS_STRING) { - gr = getgrnam((*group)->value.str.val); + if (Z_TYPE_PP(group) == IS_STRING) { + gr = getgrnam(Z_STRVAL_PP(group)); if (!gr) { php_error(E_WARNING, "unable to find gid for %s", - (*group)->value.str.val); + Z_STRVAL_PP(group)); RETURN_FALSE; } gid = gr->gr_gid; } else { convert_to_long_ex(group); - gid = (*group)->value.lval; + gid = Z_LVAL_PP(group); } - if (PG(safe_mode) &&(!php_checkuid((*filename)->value.str.val, NULL, CHECKUID_ALLOW_FILE_NOT_EXISTS))) { + if (PG(safe_mode) &&(!php_checkuid(Z_STRVAL_PP(filename), NULL, CHECKUID_ALLOW_FILE_NOT_EXISTS))) { RETURN_FALSE; } /* Check the basedir */ - if (php_check_open_basedir((*filename)->value.str.val TSRMLS_CC)) { + if (php_check_open_basedir(Z_STRVAL_PP(filename) TSRMLS_CC)) { RETURN_FALSE; } - ret = VCWD_CHOWN((*filename)->value.str.val, -1, gid); + ret = VCWD_CHOWN(Z_STRVAL_PP(filename), -1, gid); if (ret == -1) { php_error(E_WARNING, "chgrp failed: %s", strerror(errno)); RETURN_FALSE; @@ -392,29 +393,29 @@ WRONG_PARAM_COUNT; } convert_to_string_ex(filename); - if ((*user)->type == IS_STRING) { - pw = getpwnam((*user)->value.str.val); + if (Z_TYPE_PP(user) == IS_STRING) { + pw = getpwnam(Z_STRVAL_PP(user)); if (!pw) { php_error(E_WARNING, "unable to find uid for %s", - (*user)->value.str.val); + Z_STRVAL_PP(user)); RETURN_FALSE; } uid = pw->pw_uid; } else { convert_to_long_ex(user); - uid = (*user)->value.lval; + uid = Z_LVAL_PP(user); } - if (PG(safe_mode) &&(!php_checkuid((*filename)->value.str.val, NULL, CHECKUID_ALLOW_FILE_NOT_EXISTS))) { + if (PG(safe_mode) &&(!php_checkuid(Z_STRVAL_PP(filename), NULL, CHECKUID_ALLOW_FILE_NOT_EXISTS))) { RETURN_FALSE; } /* Check the basedir */ - if (php_check_open_basedir((*filename)->value.str.val TSRMLS_CC)) { + if (php_check_open_basedir(Z_STRVAL_PP(filename) TSRMLS_CC)) { RETURN_FALSE; } - ret = VCWD_CHOWN((*filename)->value.str.val, uid, -1); + ret = VCWD_CHOWN(Z_STRVAL_PP(filename), uid, -1); if (ret == -1) { php_error(E_WARNING, "chown failed: %s", strerror(errno)); RETURN_FALSE; @@ -438,16 +439,16 @@ convert_to_string_ex(filename); convert_to_long_ex(mode); - if (PG(safe_mode) &&(!php_checkuid((*filename)->value.str.val, NULL, CHECKUID_ALLOW_FILE_NOT_EXISTS))) { + if (PG(safe_mode) &&(!php_checkuid(Z_STRVAL_PP(filename), NULL, CHECKUID_ALLOW_FILE_NOT_EXISTS))) { RETURN_FALSE; } /* Check the basedir */ - if (php_check_open_basedir((*filename)->value.str.val TSRMLS_CC)) { + if (php_check_open_basedir(Z_STRVAL_PP(filename) TSRMLS_CC)) { RETURN_FALSE; } - imode = (mode_t) (*mode)->value.lval; + imode = (mode_t) Z_LVAL_PP(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. @@ -455,7 +456,7 @@ if(PG(safe_mode)) imode &= 0777; - ret = VCWD_CHMOD((*filename)->value.str.val, imode); + ret = VCWD_CHMOD(Z_STRVAL_PP(filename), imode); if (ret == -1) { php_error(E_WARNING, "chmod failed: %s", strerror(errno)); RETURN_FALSE; @@ -493,20 +494,20 @@ return; } convert_to_long_ex(filetime); - newtime->actime = (*filetime)->value.lval; - newtime->modtime = (*filetime)->value.lval; + newtime->actime = Z_LVAL_PP(filetime); + newtime->modtime = Z_LVAL_PP(filetime); } else { WRONG_PARAM_COUNT; } convert_to_string_ex(filename); - if (PG(safe_mode) &&(!php_checkuid((*filename)->value.str.val, NULL, CHECKUID_CHECK_FILE_AND_DIR))) { + if (PG(safe_mode) &&(!php_checkuid(Z_STRVAL_PP(filename), NULL, CHECKUID_CHECK_FILE_AND_DIR))) { if (newtime) efree(newtime); RETURN_FALSE; } /* Check the basedir */ - if (php_check_open_basedir((*filename)->value.str.val TSRMLS_CC)) { + if (php_check_open_basedir(Z_STRVAL_PP(filename) TSRMLS_CC)) { if (newtime) { efree(newtime); } @@ -514,18 +515,18 @@ } /* create the file if it doesn't exist already */ - ret = VCWD_STAT((*filename)->value.str.val, &sb); + ret = VCWD_STAT(Z_STRVAL_PP(filename), &sb); if (ret == -1) { - file = VCWD_FOPEN((*filename)->value.str.val, "w"); + file = VCWD_FOPEN(Z_STRVAL_PP(filename), "w"); if (file == NULL) { - php_error(E_WARNING, "unable to create file %s because %s", (*filename)->value.str.val, strerror(errno)); + php_error(E_WARNING, "unable to create file %s because %s", Z_STRVAL_PP(filename), strerror(errno)); if (newtime) efree(newtime); RETURN_FALSE; } fclose(file); } - ret = VCWD_UTIME((*filename)->value.str.val, newtime); + ret = VCWD_UTIME(Z_STRVAL_PP(filename), newtime); if (newtime) efree(newtime); if (ret == -1) { php_error(E_WARNING, "utime failed: %s", strerror(errno)); @@ -549,10 +550,11 @@ /* }}} */ #define IS_LINK_OPERATION() (type == 8 /* filetype */ || type == 14 /* is_link */ || type == 16 /* lstat */) +#define IS_EXISTS_CHECK(__t) ((__t) == FS_EXISTS || (__t) == FS_IS_W || (__t) == FS_IS_R || (__t) == FS_IS_X || (__t) == FS_IS_FILE || (__t) == FS_IS_DIR || (__t) == FS_IS_LINK) /* {{{ php_stat */ -static void php_stat(const char *filename, php_stat_len filename_length, int type, pval *return_value) +static void php_stat(const char *filename, php_stat_len filename_length, int type, pval *return_value TSRMLS_DC) { zval *stat_dev, *stat_ino, *stat_mode, *stat_nlink, *stat_uid, *stat_gid, *stat_rdev, *stat_size, *stat_atime, *stat_mtime, *stat_ctime, *stat_blksize, *stat_blocks; @@ -560,7 +562,6 @@ int rmask=S_IROTH, wmask=S_IWOTH, xmask=S_IXOTH; /* access rights defaults to other */ char *stat_sb_names[13]={"dev", "ino", "mode", "nlink", "uid", "gid", "rdev", "size", "atime", "mtime", "ctime", "blksize", "blocks"}; - TSRMLS_FETCH(); stat_sb = &BG(sb); @@ -578,7 +579,7 @@ BG(lsb).st_mode = 0; /* mark lstat buf invalid */ #endif if (VCWD_STAT(BG(CurrentStatFile), &BG(sb)) == -1) { - if (!IS_LINK_OPERATION() && (type != FS_EXISTS || errno != ENOENT)) { /* fileexists() test must print no error */ + if (!IS_LINK_OPERATION() && (!IS_EXISTS_CHECK(type) || errno != ENOENT)) { /* fileexists() test must print no error */ php_error(E_WARNING, "stat failed for %s (errno=%d - %s)", BG(CurrentStatFile), errno, strerror(errno)); } efree(BG(CurrentStatFile)); @@ -734,6 +735,7 @@ zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_nlink, sizeof(zval *), NULL); zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_uid, sizeof(zval *), NULL); zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_gid, sizeof(zval *), NULL); + zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_rdev, sizeof(zval *), NULL); zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_size, sizeof(zval *), NULL); zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_atime, sizeof(zval *), NULL); @@ -772,7 +774,7 @@ WRONG_PARAM_COUNT; \ } \ convert_to_string_ex(filename); \ - php_stat(Z_STRVAL_PP(filename), (php_stat_len) Z_STRLEN_PP(filename), funcnum, return_value); \ + php_stat(Z_STRVAL_PP(filename), (php_stat_len) Z_STRLEN_PP(filename), funcnum, return_value TSRMLS_CC); \ } /* {{{ proto int fileperms(string filename) @@ -870,6 +872,6 @@ * tab-width: 4 * c-basic-offset: 4 * End: - * vim600: sw=4 ts=4 tw=78 fdm=marker - * vim<600: sw=4 ts=4 tw=78 + * vim600: sw=4 ts=4 fdm=marker + * vim<600: sw=4 ts=4 */
Index: php4/ext/standard/filestat.c diff -u php4/ext/standard/filestat.c:1.78.2.1 php4/ext/standard/filestat.c:1.78.2.2 --- php4/ext/standard/filestat.c:1.78.2.1 Tue Aug 21 19:59:21 2001 +++ php4/ext/standard/filestat.c Thu Dec 13 08:51:42 2001 @@ -1,8 +1,8 @@ /* +----------------------------------------------------------------------+ - | PHP version 4.0 | + | PHP Version 4 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2001 The PHP Group | + | Copyright (c) 1997-2002 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 2.02 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: filestat.c,v 1.78.2.1 2001/08/21 23:59:21 joey Exp $ */ +/* $Id: filestat.c,v 1.78.2.2 2001/12/13 13:51:42 sterling Exp $ */ #include "php.h" #include "safe_mode.h" @@ -118,14 +118,15 @@ return SUCCESS; } -PHP_RSHUTDOWN_FUNCTION(filestat) { +PHP_RSHUTDOWN_FUNCTION(filestat) +{ if (BG(CurrentStatFile)) { efree (BG(CurrentStatFile)); } return SUCCESS; } -/* {{{ proto double disk_total_space(string path) +/* {{{ proto float disk_total_space(string path) Get total disk space for filesystem that path is on */ PHP_FUNCTION(disk_total_space) { @@ -164,7 +165,7 @@ convert_to_string_ex(path); - if (php_check_open_basedir((*path)->value.str.val TSRMLS_CC)) { + if (php_check_open_basedir(Z_STRVAL_PP(path) TSRMLS_CC)) { RETURN_FALSE; } @@ -178,7 +179,7 @@ /* It's available, so we can call it. */ if (gdfse) { func = (gdfse_func)gdfse; - if (func((*path)->value.str.val, + if (func(Z_STRVAL_PP(path), &FreeBytesAvailableToCaller, &TotalNumberOfBytes, &TotalNumberOfFreeBytes) == 0) RETURN_FALSE; @@ -190,7 +191,7 @@ } /* If it's not available, we just use GetDiskFreeSpace */ else { - if (GetDiskFreeSpace((*path)->value.str.val, + if (GetDiskFreeSpace(Z_STRVAL_PP(path), &SectorsPerCluster, &BytesPerSector, &NumberOfFreeClusters, &TotalNumberOfClusters) == 0) RETURN_FALSE; bytestotal = (double)TotalNumberOfClusters * (double)SectorsPerCluster * (double)BytesPerSector; @@ -204,14 +205,14 @@ #elif defined(OS2) { FSALLOCATE fsinfo; - char drive = (*path)->value.str.val[0] & 95; + char drive = Z_STRVAL_PP(path)[0] & 95; if (DosQueryFSInfo( drive ? drive - 64 : 0, FSIL_ALLOC, &fsinfo, sizeof( fsinfo ) ) == 0) bytestotal = (double)fsinfo.cbSector * fsinfo.cSectorUnit * fsinfo.cUnit; } #else /* WINDOWS, OS/2 */ #if defined(HAVE_SYS_STATVFS_H) && defined(HAVE_STATVFS) - if (statvfs((*path)->value.str.val, &buf)) RETURN_FALSE; + if (statvfs(Z_STRVAL_PP(path), &buf)) RETURN_FALSE; if (buf.f_frsize) { bytestotal = (((double)buf.f_blocks) * ((double)buf.f_frsize)); } else { @@ -219,7 +220,7 @@ } #elif (defined(HAVE_SYS_STATFS_H) || defined(HAVE_SYS_MOUNT_H)) && defined(HAVE_STATFS) - if (statfs((*path)->value.str.val, &buf)) RETURN_FALSE; + if (statfs(Z_STRVAL_PP(path), &buf)) RETURN_FALSE; bytestotal = (((double)buf.f_bsize) * ((double)buf.f_blocks)); #endif #endif /* WINDOWS */ @@ -228,7 +229,7 @@ } /* }}} */ -/* {{{ proto double disk_free_space(string path) +/* {{{ proto float disk_free_space(string path) Get free disk space for filesystem that path is on */ PHP_FUNCTION(disk_free_space) { @@ -267,7 +268,7 @@ convert_to_string_ex(path); - if (php_check_open_basedir((*path)->value.str.val TSRMLS_CC)) { + if (php_check_open_basedir(Z_STRVAL_PP(path) TSRMLS_CC)) { RETURN_FALSE; } @@ -281,7 +282,7 @@ /* It's available, so we can call it. */ if (gdfse) { func = (gdfse_func)gdfse; - if (func((*path)->value.str.val, + if (func(Z_STRVAL_PP(path), &FreeBytesAvailableToCaller, &TotalNumberOfBytes, &TotalNumberOfFreeBytes) == 0) RETURN_FALSE; @@ -293,7 +294,7 @@ } /* If it's not available, we just use GetDiskFreeSpace */ else { - if (GetDiskFreeSpace((*path)->value.str.val, + if (GetDiskFreeSpace(Z_STRVAL_PP(path), &SectorsPerCluster, &BytesPerSector, &NumberOfFreeClusters, &TotalNumberOfClusters) == 0) RETURN_FALSE; bytesfree = (double)NumberOfFreeClusters * (double)SectorsPerCluster * (double)BytesPerSector; @@ -307,21 +308,21 @@ #elif defined(OS2) { FSALLOCATE fsinfo; - char drive = (*path)->value.str.val[0] & 95; + char drive = Z_STRVAL_PP(path)[0] & 95; if (DosQueryFSInfo( drive ? drive - 64 : 0, FSIL_ALLOC, &fsinfo, sizeof( fsinfo ) ) == 0) bytesfree = (double)fsinfo.cbSector * fsinfo.cSectorUnit * fsinfo.cUnitAvail; } #else /* WINDOWS, OS/2 */ #if defined(HAVE_SYS_STATVFS_H) && defined(HAVE_STATVFS) - if (statvfs((*path)->value.str.val, &buf)) RETURN_FALSE; + if (statvfs(Z_STRVAL_PP(path), &buf)) RETURN_FALSE; if (buf.f_frsize) { bytesfree = (((double)buf.f_bavail) * ((double)buf.f_frsize)); } else { bytesfree = (((double)buf.f_bavail) * ((double)buf.f_bsize)); } #elif (defined(HAVE_SYS_STATFS_H) || defined(HAVE_SYS_MOUNT_H)) && defined(HAVE_STATFS) - if (statfs((*path)->value.str.val, &buf)) RETURN_FALSE; + if (statfs(Z_STRVAL_PP(path), &buf)) RETURN_FALSE; bytesfree = (((double)buf.f_bsize) * ((double)buf.f_bavail)); #endif #endif /* WINDOWS */ @@ -344,29 +345,29 @@ WRONG_PARAM_COUNT; } convert_to_string_ex(filename); - if ((*group)->type == IS_STRING) { - gr = getgrnam((*group)->value.str.val); + if (Z_TYPE_PP(group) == IS_STRING) { + gr = getgrnam(Z_STRVAL_PP(group)); if (!gr) { php_error(E_WARNING, "unable to find gid for %s", - (*group)->value.str.val); + Z_STRVAL_PP(group)); RETURN_FALSE; } gid = gr->gr_gid; } else { convert_to_long_ex(group); - gid = (*group)->value.lval; + gid = Z_LVAL_PP(group); } - if (PG(safe_mode) &&(!php_checkuid((*filename)->value.str.val, NULL, CHECKUID_ALLOW_FILE_NOT_EXISTS))) { + if (PG(safe_mode) &&(!php_checkuid(Z_STRVAL_PP(filename), NULL, CHECKUID_ALLOW_FILE_NOT_EXISTS))) { RETURN_FALSE; } /* Check the basedir */ - if (php_check_open_basedir((*filename)->value.str.val TSRMLS_CC)) { + if (php_check_open_basedir(Z_STRVAL_PP(filename) TSRMLS_CC)) { RETURN_FALSE; } - ret = VCWD_CHOWN((*filename)->value.str.val, -1, gid); + ret = VCWD_CHOWN(Z_STRVAL_PP(filename), -1, gid); if (ret == -1) { php_error(E_WARNING, "chgrp failed: %s", strerror(errno)); RETURN_FALSE; @@ -392,29 +393,29 @@ WRONG_PARAM_COUNT; } convert_to_string_ex(filename); - if ((*user)->type == IS_STRING) { - pw = getpwnam((*user)->value.str.val); + if (Z_TYPE_PP(user) == IS_STRING) { + pw = getpwnam(Z_STRVAL_PP(user)); if (!pw) { php_error(E_WARNING, "unable to find uid for %s", - (*user)->value.str.val); + Z_STRVAL_PP(user)); RETURN_FALSE; } uid = pw->pw_uid; } else { convert_to_long_ex(user); - uid = (*user)->value.lval; + uid = Z_LVAL_PP(user); } - if (PG(safe_mode) &&(!php_checkuid((*filename)->value.str.val, NULL, CHECKUID_ALLOW_FILE_NOT_EXISTS))) { + if (PG(safe_mode) &&(!php_checkuid(Z_STRVAL_PP(filename), NULL, CHECKUID_ALLOW_FILE_NOT_EXISTS))) { RETURN_FALSE; } /* Check the basedir */ - if (php_check_open_basedir((*filename)->value.str.val TSRMLS_CC)) { + if (php_check_open_basedir(Z_STRVAL_PP(filename) TSRMLS_CC)) { RETURN_FALSE; } - ret = VCWD_CHOWN((*filename)->value.str.val, uid, -1); + ret = VCWD_CHOWN(Z_STRVAL_PP(filename), uid, -1); if (ret == -1) { php_error(E_WARNING, "chown failed: %s", strerror(errno)); RETURN_FALSE; @@ -438,16 +439,16 @@ convert_to_string_ex(filename); convert_to_long_ex(mode); - if (PG(safe_mode) &&(!php_checkuid((*filename)->value.str.val, NULL, CHECKUID_ALLOW_FILE_NOT_EXISTS))) { + if (PG(safe_mode) &&(!php_checkuid(Z_STRVAL_PP(filename), NULL, CHECKUID_ALLOW_FILE_NOT_EXISTS))) { RETURN_FALSE; } /* Check the basedir */ - if (php_check_open_basedir((*filename)->value.str.val TSRMLS_CC)) { + if (php_check_open_basedir(Z_STRVAL_PP(filename) TSRMLS_CC)) { RETURN_FALSE; } - imode = (mode_t) (*mode)->value.lval; + imode = (mode_t) Z_LVAL_PP(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. @@ -455,7 +456,7 @@ if(PG(safe_mode)) imode &= 0777; - ret = VCWD_CHMOD((*filename)->value.str.val, imode); + ret = VCWD_CHMOD(Z_STRVAL_PP(filename), imode); if (ret == -1) { php_error(E_WARNING, "chmod failed: %s", strerror(errno)); RETURN_FALSE; @@ -493,20 +494,20 @@ return; } convert_to_long_ex(filetime); - newtime->actime = (*filetime)->value.lval; - newtime->modtime = (*filetime)->value.lval; + newtime->actime = Z_LVAL_PP(filetime); + newtime->modtime = Z_LVAL_PP(filetime); } else { WRONG_PARAM_COUNT; } convert_to_string_ex(filename); - if (PG(safe_mode) &&(!php_checkuid((*filename)->value.str.val, NULL, CHECKUID_CHECK_FILE_AND_DIR))) { + if (PG(safe_mode) &&(!php_checkuid(Z_STRVAL_PP(filename), NULL, CHECKUID_CHECK_FILE_AND_DIR))) { if (newtime) efree(newtime); RETURN_FALSE; } /* Check the basedir */ - if (php_check_open_basedir((*filename)->value.str.val TSRMLS_CC)) { + if (php_check_open_basedir(Z_STRVAL_PP(filename) TSRMLS_CC)) { if (newtime) { efree(newtime); } @@ -514,18 +515,18 @@ } /* create the file if it doesn't exist already */ - ret = VCWD_STAT((*filename)->value.str.val, &sb); + ret = VCWD_STAT(Z_STRVAL_PP(filename), &sb); if (ret == -1) { - file = VCWD_FOPEN((*filename)->value.str.val, "w"); + file = VCWD_FOPEN(Z_STRVAL_PP(filename), "w"); if (file == NULL) { - php_error(E_WARNING, "unable to create file %s because %s", (*filename)->value.str.val, strerror(errno)); + php_error(E_WARNING, "unable to create file %s because %s", Z_STRVAL_PP(filename), strerror(errno)); if (newtime) efree(newtime); RETURN_FALSE; } fclose(file); } - ret = VCWD_UTIME((*filename)->value.str.val, newtime); + ret = VCWD_UTIME(Z_STRVAL_PP(filename), newtime); if (newtime) efree(newtime); if (ret == -1) { php_error(E_WARNING, "utime failed: %s", strerror(errno)); @@ -549,10 +550,11 @@ /* }}} */ #define IS_LINK_OPERATION() (type == 8 /* filetype */ || type == 14 /* is_link */ || type == 16 /* lstat */) +#define IS_EXISTS_CHECK(__t) ((__t) == FS_EXISTS || (__t) == FS_IS_W || (__t) == FS_IS_R || (__t) == FS_IS_X || (__t) == FS_IS_FILE || (__t) == FS_IS_DIR || (__t) == FS_IS_LINK) /* {{{ php_stat */ -static void php_stat(const char *filename, php_stat_len filename_length, int type, pval *return_value) +static void php_stat(const char *filename, php_stat_len filename_length, int type, pval *return_value TSRMLS_DC) { zval *stat_dev, *stat_ino, *stat_mode, *stat_nlink, *stat_uid, *stat_gid, *stat_rdev, *stat_size, *stat_atime, *stat_mtime, *stat_ctime, *stat_blksize, *stat_blocks; @@ -560,7 +562,6 @@ int rmask=S_IROTH, wmask=S_IWOTH, xmask=S_IXOTH; /* access rights defaults to other */ char *stat_sb_names[13]={"dev", "ino", "mode", "nlink", "uid", "gid", "rdev", "size", "atime", "mtime", "ctime", "blksize", "blocks"}; - TSRMLS_FETCH(); stat_sb = &BG(sb); @@ -578,7 +579,7 @@ BG(lsb).st_mode = 0; /* mark lstat buf invalid */ #endif if (VCWD_STAT(BG(CurrentStatFile), &BG(sb)) == -1) { - if (!IS_LINK_OPERATION() && (type != FS_EXISTS || errno != ENOENT)) { /* fileexists() test must print no error */ + if (!IS_LINK_OPERATION() && (!IS_EXISTS_CHECK(type) || errno != ENOENT)) { /* fileexists() test must print no error */ php_error(E_WARNING, "stat failed for %s (errno=%d - %s)", BG(CurrentStatFile), errno, strerror(errno)); } efree(BG(CurrentStatFile)); @@ -734,6 +735,7 @@ zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_nlink, sizeof(zval *), NULL); zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_uid, sizeof(zval *), NULL); zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_gid, sizeof(zval *), NULL); + zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_rdev, sizeof(zval *), NULL); zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_size, sizeof(zval *), NULL); zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_atime, sizeof(zval *), NULL); @@ -772,7 +774,7 @@ WRONG_PARAM_COUNT; \ } \ convert_to_string_ex(filename); \ - php_stat(Z_STRVAL_PP(filename), (php_stat_len) Z_STRLEN_PP(filename), funcnum, return_value); \ + php_stat(Z_STRVAL_PP(filename), (php_stat_len) Z_STRLEN_PP(filename), funcnum, return_value TSRMLS_CC); \ } /* {{{ proto int fileperms(string filename) @@ -870,6 +872,6 @@ * tab-width: 4 * c-basic-offset: 4 * End: - * vim600: sw=4 ts=4 tw=78 fdm=marker - * vim<600: sw=4 ts=4 tw=78 + * vim600: sw=4 ts=4 fdm=marker + * vim<600: sw=4 ts=4 */