--- embedaddon/php/TSRM/tsrm_virtual_cwd.c 2012/02/21 23:47:52 1.1 +++ embedaddon/php/TSRM/tsrm_virtual_cwd.c 2014/06/15 20:04:03 1.1.1.4 @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | 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, | | that is bundled with this package in the file LICENSE, and is | @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: tsrm_virtual_cwd.c,v 1.1 2012/02/21 23:47:52 misho Exp $ */ +/* $Id: tsrm_virtual_cwd.c,v 1.1.1.4 2014/06/15 20:04:03 misho Exp $ */ #include #include @@ -40,6 +40,10 @@ # define IO_REPARSE_TAG_SYMLINK 0xA000000C # endif +# ifndef IO_REPARSE_TAG_DEDUP +# define IO_REPARSE_TAG_DEDUP 0x80000013 +# endif + # ifndef VOLUME_NAME_NT # define VOLUME_NAME_NT 0x2 # endif @@ -277,18 +281,6 @@ CWD_API int php_sys_readlink(const char *link, char *t } /* }}} */ -CWD_API int php_sys_stat(const char *path, struct stat *buf) /* {{{ */ -{ - return php_sys_stat_ex(path, buf, 0); -} -/* }}} */ - -CWD_API int php_sys_lstat(const char *path, struct stat *buf) /* {{{ */ -{ - return php_sys_stat_ex(path, buf, 1); -} -/* }}} */ - CWD_API int php_sys_stat_ex(const char *path, struct stat *buf, int lstat) /* {{{ */ { WIN32_FILE_ATTRIBUTE_DATA data; @@ -718,7 +710,6 @@ static inline realpath_cache_bucket* realpath_cache_fi } else { CWDG(realpath_cache_size) -= sizeof(realpath_cache_bucket) + r->path_len + 1 + r->realpath_len + 1; } - free(r); } else if (key == (*bucket)->key && path_len == (*bucket)->path_len && memcmp(path, (*bucket)->path, path_len) == 0) { @@ -773,6 +764,9 @@ static int tsrm_realpath_r(char *path, int start, int while (1) { if (len <= start) { + if (link_is_dir) { + *link_is_dir = 1; + } return start; } @@ -789,6 +783,10 @@ static int tsrm_realpath_r(char *path, int start, int continue; } else if (i == len - 2 && path[i] == '.' && path[i+1] == '.') { /* remove '..' and previous directory */ + is_dir = 1; + if (link_is_dir) { + *link_is_dir = 1; + } if (i - 1 <= start) { return start ? start : len; } @@ -951,6 +949,11 @@ static int tsrm_realpath_r(char *path, int start, int return -1; }; substitutename[substitutename_len] = 0; + } + else if (pbuffer->ReparseTag == IO_REPARSE_TAG_DEDUP) { + isabsolute = 1; + memcpy(substitutename, path, len + 1); + substitutename_len = len; } else { tsrm_free_alloca(pbuffer, use_heap_large); return -1; @@ -1145,7 +1148,7 @@ static int tsrm_realpath_r(char *path, int start, int /* Resolve path relatively to state and put the real path into state */ /* returns 0 for ok, 1 for error */ -CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func verify_path, int use_realpath) /* {{{ */ +CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func verify_path, int use_realpath TSRMLS_DC) /* {{{ */ { int path_length = strlen(path); char resolved_path[MAXPATHLEN]; @@ -1155,7 +1158,6 @@ CWD_API int virtual_file_ex(cwd_state *state, const ch int ret; int add_slash; void *tmp; - TSRMLS_FETCH(); if (path_length == 0 || path_length >= MAXPATHLEN-1) { #ifdef TSRM_WIN32 @@ -1214,9 +1216,14 @@ CWD_API int virtual_file_ex(cwd_state *state, const ch return 1; } memcpy(resolved_path, state->cwd, state_cwd_length); - resolved_path[state_cwd_length] = DEFAULT_SLASH; - memcpy(resolved_path + state_cwd_length + 1, path, path_length + 1); - path_length += state_cwd_length + 1; + if (resolved_path[state_cwd_length-1] == DEFAULT_SLASH) { + memcpy(resolved_path + state_cwd_length, path, path_length + 1); + path_length += state_cwd_length; + } else { + resolved_path[state_cwd_length] = DEFAULT_SLASH; + memcpy(resolved_path + state_cwd_length + 1, path, path_length + 1); + path_length += state_cwd_length + 1; + } } } else { #ifdef TSRM_WIN32 @@ -1351,7 +1358,7 @@ verify: CWD_API int virtual_chdir(const char *path TSRMLS_DC) /* {{{ */ { - return virtual_file_ex(&CWDG(cwd), path, php_is_dir_ok, CWD_REALPATH)?-1:0; + return virtual_file_ex(&CWDG(cwd), path, php_is_dir_ok, CWD_REALPATH TSRMLS_CC)?-1:0; } /* }}} */ @@ -1419,7 +1426,7 @@ CWD_API char *virtual_realpath(const char *path, char new_state.cwd_length = 0; } - if (virtual_file_ex(&new_state, path, NULL, CWD_REALPATH)==0) { + if (virtual_file_ex(&new_state, path, NULL, CWD_REALPATH TSRMLS_CC)==0) { int len = new_state.cwd_length>MAXPATHLEN-1?MAXPATHLEN-1:new_state.cwd_length; memcpy(real_path, new_state.cwd, len); @@ -1441,7 +1448,7 @@ CWD_API int virtual_filepath_ex(const char *path, char int retval; CWD_STATE_COPY(&new_state, &CWDG(cwd)); - retval = virtual_file_ex(&new_state, path, verify_path, CWD_FILEPATH); + retval = virtual_file_ex(&new_state, path, verify_path, CWD_FILEPATH TSRMLS_CC); *filepath = new_state.cwd; @@ -1466,7 +1473,7 @@ CWD_API FILE *virtual_fopen(const char *path, const ch } CWD_STATE_COPY(&new_state, &CWDG(cwd)); - if (virtual_file_ex(&new_state, path, NULL, CWD_FILEPATH)) { + if (virtual_file_ex(&new_state, path, NULL, CWD_EXPAND TSRMLS_CC)) { CWD_STATE_FREE(&new_state); return NULL; } @@ -1484,13 +1491,13 @@ CWD_API int virtual_access(const char *pathname, int m int ret; CWD_STATE_COPY(&new_state, &CWDG(cwd)); - if (virtual_file_ex(&new_state, pathname, NULL, CWD_REALPATH)) { + if (virtual_file_ex(&new_state, pathname, NULL, CWD_REALPATH TSRMLS_CC)) { CWD_STATE_FREE(&new_state); return -1; } #if defined(TSRM_WIN32) - ret = tsrm_win32_access(new_state.cwd, mode); + ret = tsrm_win32_access(new_state.cwd, mode TSRMLS_CC); #else ret = access(new_state.cwd, mode); #endif @@ -1557,7 +1564,7 @@ CWD_API int virtual_utime(const char *filename, struct int ret; CWD_STATE_COPY(&new_state, &CWDG(cwd)); - if (virtual_file_ex(&new_state, filename, NULL, CWD_REALPATH)) { + if (virtual_file_ex(&new_state, filename, NULL, CWD_REALPATH TSRMLS_CC)) { CWD_STATE_FREE(&new_state); return -1; } @@ -1580,7 +1587,7 @@ CWD_API int virtual_chmod(const char *filename, mode_t int ret; CWD_STATE_COPY(&new_state, &CWDG(cwd)); - if (virtual_file_ex(&new_state, filename, NULL, CWD_REALPATH)) { + if (virtual_file_ex(&new_state, filename, NULL, CWD_REALPATH TSRMLS_CC)) { CWD_STATE_FREE(&new_state); return -1; } @@ -1599,7 +1606,7 @@ CWD_API int virtual_chown(const char *filename, uid_t int ret; CWD_STATE_COPY(&new_state, &CWDG(cwd)); - if (virtual_file_ex(&new_state, filename, NULL, CWD_REALPATH)) { + if (virtual_file_ex(&new_state, filename, NULL, CWD_REALPATH TSRMLS_CC)) { CWD_STATE_FREE(&new_state); return -1; } @@ -1626,7 +1633,7 @@ CWD_API int virtual_open(const char *path TSRMLS_DC, i int f; CWD_STATE_COPY(&new_state, &CWDG(cwd)); - if (virtual_file_ex(&new_state, path, NULL, CWD_FILEPATH)) { + if (virtual_file_ex(&new_state, path, NULL, CWD_FILEPATH TSRMLS_CC)) { CWD_STATE_FREE(&new_state); return -1; } @@ -1654,7 +1661,7 @@ CWD_API int virtual_creat(const char *path, mode_t mod int f; CWD_STATE_COPY(&new_state, &CWDG(cwd)); - if (virtual_file_ex(&new_state, path, NULL, CWD_FILEPATH)) { + if (virtual_file_ex(&new_state, path, NULL, CWD_FILEPATH TSRMLS_CC)) { CWD_STATE_FREE(&new_state); return -1; } @@ -1673,14 +1680,14 @@ CWD_API int virtual_rename(char *oldname, char *newnam int retval; CWD_STATE_COPY(&old_state, &CWDG(cwd)); - if (virtual_file_ex(&old_state, oldname, NULL, CWD_EXPAND)) { + if (virtual_file_ex(&old_state, oldname, NULL, CWD_EXPAND TSRMLS_CC)) { CWD_STATE_FREE(&old_state); return -1; } oldname = old_state.cwd; CWD_STATE_COPY(&new_state, &CWDG(cwd)); - if (virtual_file_ex(&new_state, newname, NULL, CWD_EXPAND)) { + if (virtual_file_ex(&new_state, newname, NULL, CWD_EXPAND TSRMLS_CC)) { CWD_STATE_FREE(&old_state); CWD_STATE_FREE(&new_state); return -1; @@ -1709,7 +1716,7 @@ CWD_API int virtual_stat(const char *path, struct stat int retval; CWD_STATE_COPY(&new_state, &CWDG(cwd)); - if (virtual_file_ex(&new_state, path, NULL, CWD_REALPATH)) { + if (virtual_file_ex(&new_state, path, NULL, CWD_REALPATH TSRMLS_CC)) { CWD_STATE_FREE(&new_state); return -1; } @@ -1727,7 +1734,7 @@ CWD_API int virtual_lstat(const char *path, struct sta int retval; CWD_STATE_COPY(&new_state, &CWDG(cwd)); - if (virtual_file_ex(&new_state, path, NULL, CWD_EXPAND)) { + if (virtual_file_ex(&new_state, path, NULL, CWD_EXPAND TSRMLS_CC)) { CWD_STATE_FREE(&new_state); return -1; } @@ -1745,7 +1752,7 @@ CWD_API int virtual_unlink(const char *path TSRMLS_DC) int retval; CWD_STATE_COPY(&new_state, &CWDG(cwd)); - if (virtual_file_ex(&new_state, path, NULL, CWD_EXPAND)) { + if (virtual_file_ex(&new_state, path, NULL, CWD_EXPAND TSRMLS_CC)) { CWD_STATE_FREE(&new_state); return -1; } @@ -1763,7 +1770,7 @@ CWD_API int virtual_mkdir(const char *pathname, mode_t int retval; CWD_STATE_COPY(&new_state, &CWDG(cwd)); - if (virtual_file_ex(&new_state, pathname, NULL, CWD_FILEPATH)) { + if (virtual_file_ex(&new_state, pathname, NULL, CWD_FILEPATH TSRMLS_CC)) { CWD_STATE_FREE(&new_state); return -1; } @@ -1784,7 +1791,7 @@ CWD_API int virtual_rmdir(const char *pathname TSRMLS_ int retval; CWD_STATE_COPY(&new_state, &CWDG(cwd)); - if (virtual_file_ex(&new_state, pathname, NULL, CWD_EXPAND)) { + if (virtual_file_ex(&new_state, pathname, NULL, CWD_EXPAND TSRMLS_CC)) { CWD_STATE_FREE(&new_state); return -1; } @@ -1806,7 +1813,7 @@ CWD_API DIR *virtual_opendir(const char *pathname TSRM DIR *retval; CWD_STATE_COPY(&new_state, &CWDG(cwd)); - if (virtual_file_ex(&new_state, pathname, NULL, CWD_REALPATH)) { + if (virtual_file_ex(&new_state, pathname, NULL, CWD_REALPATH TSRMLS_CC)) { CWD_STATE_FREE(&new_state); return NULL; } @@ -1821,7 +1828,7 @@ CWD_API DIR *virtual_opendir(const char *pathname TSRM #ifdef TSRM_WIN32 CWD_API FILE *virtual_popen(const char *command, const char *type TSRMLS_DC) /* {{{ */ { - return popen_ex(command, type, CWDG(cwd).cwd, NULL); + return popen_ex(command, type, CWDG(cwd).cwd, NULL TSRMLS_CC); } /* }}} */ #elif defined(NETWARE) @@ -1944,7 +1951,7 @@ CWD_API char *tsrm_realpath(const char *path, char *re new_state.cwd_length = 0; } - if (virtual_file_ex(&new_state, path, NULL, CWD_REALPATH)) { + if (virtual_file_ex(&new_state, path, NULL, CWD_REALPATH TSRMLS_CC)) { free(new_state.cwd); return NULL; }