mirror of
https://github.com/php/php-src.git
synced 2024-11-28 04:14:26 +08:00
- Fix virtual cwd bug
- Add more V_STAT() V_LSTAT() changes
This commit is contained in:
parent
7412bd5c84
commit
883bd2b1de
@ -319,7 +319,7 @@ dbm_info *php_dbm_open(char *filename, char *mode) {
|
||||
strcat(lockfn, ".lck");
|
||||
|
||||
#if NFS_HACK
|
||||
while((last_try = stat(lockfn,&sb))==0) {
|
||||
while((last_try = V_STAT(lockfn,&sb))==0) {
|
||||
retries++;
|
||||
php_sleep(1);
|
||||
if (retries>30) break;
|
||||
|
@ -61,7 +61,7 @@ DBA_OPEN_FUNC(db2)
|
||||
|
||||
type = info->mode == DBA_READER ? DB_UNKNOWN :
|
||||
info->mode == DBA_TRUNC ? DB_BTREE :
|
||||
stat(info->path, &check_stat) ? DB_BTREE : DB_UNKNOWN;
|
||||
V_STAT(info->path, &check_stat) ? DB_BTREE : DB_UNKNOWN;
|
||||
|
||||
gmode = info->mode == DBA_READER ? DB_RDONLY :
|
||||
info->mode == DBA_CREAT ? DB_CREATE :
|
||||
|
@ -61,7 +61,7 @@ DBA_OPEN_FUNC(db3)
|
||||
|
||||
type = info->mode == DBA_READER ? DB_UNKNOWN :
|
||||
info->mode == DBA_TRUNC ? DB_BTREE :
|
||||
stat(info->path, &check_stat) ? DB_BTREE : DB_UNKNOWN;
|
||||
V_STAT(info->path, &check_stat) ? DB_BTREE : DB_UNKNOWN;
|
||||
|
||||
gmode = info->mode == DBA_READER ? DB_RDONLY :
|
||||
info->mode == DBA_CREAT ? DB_CREATE :
|
||||
|
@ -175,7 +175,7 @@ static int _ps_files_cleanup_dir(const char *dirname, int maxlifetime)
|
||||
snprintf(buf, MAXPATHLEN, "%s%c%s", dirname, DIR_DELIMITER,
|
||||
entry->d_name) > 0 &&
|
||||
/* stat the directory entry */
|
||||
stat(buf, &sbuf) == 0 &&
|
||||
V_STAT(buf, &sbuf) == 0 &&
|
||||
/* is it expired? */
|
||||
(now - sbuf.st_atime) > maxlifetime) {
|
||||
unlink(buf);
|
||||
|
@ -497,7 +497,7 @@ static void last_modified(void)
|
||||
|
||||
path = SG(request_info).path_translated;
|
||||
if (path) {
|
||||
if (stat(path, &sb) == -1) {
|
||||
if (V_STAT(path, &sb) == -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -385,7 +385,7 @@ PHP_FUNCTION(touch)
|
||||
RETURN_FALSE;
|
||||
|
||||
/* create the file if it doesn't exist already */
|
||||
ret = stat((*filename)->value.str.val, &sb);
|
||||
ret = V_STAT((*filename)->value.str.val, &sb);
|
||||
if (ret == -1) {
|
||||
file = V_FOPEN((*filename)->value.str.val, "w");
|
||||
if (file == NULL) {
|
||||
@ -439,7 +439,7 @@ static void php_stat(const char *filename, int type, pval *return_value)
|
||||
#if HAVE_SYMLINK
|
||||
BG(lsb).st_mode = 0; /* mark lstat buf invalid */
|
||||
#endif
|
||||
if (stat(BG(CurrentStatFile),&BG(sb))==-1) {
|
||||
if (V_STAT(BG(CurrentStatFile),&BG(sb))==-1) {
|
||||
if (type != 15 || errno != ENOENT) { /* fileexists() test must print no error */
|
||||
php_error(E_NOTICE,"stat failed for %s (errno=%d - %s)",BG(CurrentStatFile),errno,strerror(errno));
|
||||
}
|
||||
@ -457,7 +457,7 @@ static void php_stat(const char *filename, int type, pval *return_value)
|
||||
/* do lstat if the buffer is empty */
|
||||
|
||||
if (!BG(lsb).st_mode) {
|
||||
if (lstat(BG(CurrentStatFile),&BG(lsb)) == -1) {
|
||||
if (V_LSTAT(BG(CurrentStatFile),&BG(lsb)) == -1) {
|
||||
php_error(E_NOTICE,"lstat failed for %s (errno=%d - %s)",BG(CurrentStatFile),errno,strerror(errno));
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
@ -88,7 +88,7 @@ PHP_FUNCTION(linkinfo)
|
||||
}
|
||||
convert_to_string_ex(filename);
|
||||
|
||||
ret = lstat((*filename)->value.str.val, &sb);
|
||||
ret = V_LSTAT((*filename)->value.str.val, &sb);
|
||||
if (ret == -1) {
|
||||
php_error(E_WARNING, "LinkInfo failed (%s)", strerror(errno));
|
||||
RETURN_LONG(-1L);
|
||||
|
@ -206,7 +206,7 @@ static gzFile *php_gzopen_with_path(char *filename, char *mode, char *path, char
|
||||
if(PG(doc_root)) {
|
||||
snprintf(trypath, MAXPATHLEN, "%s%s", PG(doc_root), filename);
|
||||
} else {
|
||||
strncpy(trypath,filename,sizeof(trypath));
|
||||
strlcpy(trypath,filename,sizeof(trypath));
|
||||
}
|
||||
if (!php_checkuid(trypath,2)) {
|
||||
return(NULL);
|
||||
@ -251,7 +251,7 @@ static gzFile *php_gzopen_with_path(char *filename, char *mode, char *path, char
|
||||
}
|
||||
snprintf(trypath, MAXPATHLEN, "%s/%s", ptr, filename);
|
||||
if (PG(safe_mode)) {
|
||||
if (stat(trypath,&sb) == 0 &&(!php_checkuid(trypath,2))) {
|
||||
if (V_STAT(trypath,&sb) == 0 &&(!php_checkuid(trypath,2))) {
|
||||
efree(pathbuf);
|
||||
return(NULL);
|
||||
}
|
||||
|
@ -295,6 +295,7 @@ PHPAPI int cfg_get_string(char *varname, char **result);
|
||||
#define V_CHDIR_FILE(path) virtual_chdir_file(path)
|
||||
#define V_GETWD(buf)
|
||||
#define V_STAT(path, buff) virtual_stat(path, buff)
|
||||
#define V_LSTAT(path, buff) virtual_lstat(path, buff)
|
||||
#else
|
||||
#define V_GETCWD(buff, size) getcwd(buff,size)
|
||||
#define V_FOPEN(path, mode) fopen(path, mode)
|
||||
@ -302,6 +303,7 @@ PHPAPI int cfg_get_string(char *varname, char **result);
|
||||
#define V_CHDIR_FILE(path) chdir_file(path)
|
||||
#define V_GETWD(buf) getwd(buf)
|
||||
#define V_STAT(path, buff) stat(path, buff)
|
||||
#define V_LSTAT(path, buff) lstat(path, buff)
|
||||
#endif
|
||||
|
||||
#include "zend_constants.h"
|
||||
|
@ -7,9 +7,10 @@
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
|
||||
|
||||
#include "php_virtual_cwd.h"
|
||||
|
||||
#define VIRTUAL_CWD_DEBUG 0
|
||||
|
||||
#ifdef ZTS
|
||||
#include "TSRM.h"
|
||||
#endif
|
||||
@ -148,6 +149,9 @@ CWD_API void virtual_cwd_startup()
|
||||
|
||||
CWD_API void virtual_cwd_activate(char *filename)
|
||||
{
|
||||
#if VIRTUAL_CWD_DEBUG
|
||||
fprintf(stderr, "Changing dir to %s\n", filename);
|
||||
#endif
|
||||
if (filename) {
|
||||
virtual_chdir_file(filename);
|
||||
}
|
||||
@ -238,7 +242,9 @@ CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func
|
||||
|
||||
old_state = (cwd_state *) malloc(sizeof(cwd_state));
|
||||
CWD_STATE_COPY(old_state, state);
|
||||
|
||||
#if VIRTUAL_CWD_DEBUG
|
||||
fprintf(stderr,"cwd = %s path = %s\n", state->cwd, path);
|
||||
#endif
|
||||
if (IS_ABSOLUTE_PATH(path_copy, path_length)) {
|
||||
copy_amount = COPY_WHEN_ABSOLUTE;
|
||||
is_absolute = 1;
|
||||
@ -310,7 +316,9 @@ CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func
|
||||
free(old_state);
|
||||
|
||||
efree(free_path);
|
||||
|
||||
#if VIRTUAL_CWD_DEBUG
|
||||
fprintf (stderr, "virtual_file_ex() = %s\n",state->cwd);
|
||||
#endif
|
||||
return (ret);
|
||||
}
|
||||
|
||||
@ -324,6 +332,8 @@ CWD_API int virtual_chdir(char *path)
|
||||
CWD_API int virtual_chdir_file(char *path)
|
||||
{
|
||||
int length = strlen(path);
|
||||
char *temp;
|
||||
int retval;
|
||||
|
||||
if (length == 0) {
|
||||
return 1; /* Can't cd to empty string */
|
||||
@ -334,8 +344,16 @@ CWD_API int virtual_chdir_file(char *path)
|
||||
if (length == -1) {
|
||||
return virtual_chdir(path);
|
||||
}
|
||||
path[length] = DEFAULT_SLASH;
|
||||
return virtual_chdir(path);
|
||||
|
||||
temp = (char *) malloc(length+1);
|
||||
memcpy(temp, path, length);
|
||||
temp[length] = 0;
|
||||
#if VIRTUAL_CWD_DEBUG
|
||||
fprintf (stderr, "Changing directory to %s\n", temp);
|
||||
#endif
|
||||
retval = virtual_chdir(temp);
|
||||
free(temp);
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
@ -382,6 +400,21 @@ CWD_API int virtual_stat(const char *path, struct stat *buf)
|
||||
return retval;
|
||||
}
|
||||
|
||||
CWD_API int virtual_lstat(const char *path, struct stat *buf)
|
||||
{
|
||||
cwd_state new_state;
|
||||
int retval;
|
||||
CWDLS_FETCH();
|
||||
|
||||
CWD_STATE_COPY(&new_state, &CWDG(cwd));
|
||||
|
||||
virtual_file_ex(&new_state, path, NULL);
|
||||
|
||||
retval = lstat(new_state.cwd, buf);
|
||||
CWD_STATE_FREE(&new_state);
|
||||
return retval;
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
||||
main(void)
|
||||
|
@ -43,6 +43,7 @@ CWD_API int virtual_chdir_file(char *path);
|
||||
CWD_API int virtual_filepath(char *path, char **filepath);
|
||||
CWD_API FILE *virtual_fopen(const char *path, const char *mode);
|
||||
CWD_API int virtual_stat(const char *path, struct stat *buf);
|
||||
CWD_API int virtual_lstat(const char *path, struct stat *buf);
|
||||
CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func verify_path);
|
||||
|
||||
ZEND_BEGIN_MODULE_GLOBALS(cwd)
|
||||
|
Loading…
Reference in New Issue
Block a user