summaryrefslogtreecommitdiff
path: root/TSRM
diff options
context:
space:
mode:
Diffstat (limited to 'TSRM')
-rw-r--r--TSRM/TODO2
-rw-r--r--TSRM/TSRM.c69
-rw-r--r--TSRM/TSRM.h16
-rw-r--r--TSRM/build.mk3
-rw-r--r--TSRM/config.w321
-rw-r--r--TSRM/configure.ac4
-rw-r--r--TSRM/m4/ax_func_which_gethostbyname_r.m4 (renamed from TSRM/m4/gethostbyname.m4)10
-rw-r--r--TSRM/threads.m481
-rw-r--r--TSRM/tsrm.m440
-rw-r--r--TSRM/tsrm_config.w32.h1
-rw-r--r--TSRM/tsrm_win32.c292
-rw-r--r--TSRM/tsrm_win32.h4
12 files changed, 203 insertions, 320 deletions
diff --git a/TSRM/TODO b/TSRM/TODO
deleted file mode 100644
index 82b4fedfde..0000000000
--- a/TSRM/TODO
+++ /dev/null
@@ -1,2 +0,0 @@
-- Improve the lock in ts_resource_ex() in order to cover less code.
- This can probably be done by more careful hash table access
diff --git a/TSRM/TSRM.c b/TSRM/TSRM.c
index ed1f24f8b8..01433db53b 100644
--- a/TSRM/TSRM.c
+++ b/TSRM/TSRM.c
@@ -6,7 +6,7 @@
| This source file is subject to the TSRM license, that is bundled |
| with this package in the file LICENSE |
+----------------------------------------------------------------------+
- | Authors: Zeev Suraski <zeev@zend.com> |
+ | Authors: Zeev Suraski <zeev@php.net> |
+----------------------------------------------------------------------+
*/
@@ -115,11 +115,6 @@ static DWORD tls_key;
# define tsrm_tls_set(what) TlsSetValue(tls_key, (void*)(what))
# define tsrm_tls_get() TlsGetValue(tls_key)
-#elif defined(BETHREADS)
-static int32 tls_key;
-# define tsrm_tls_set(what) tls_set(tls_key, (void*)(what))
-# define tsrm_tls_get() (tsrm_tls_entry*)tls_get(tls_key)
-
#else
# define tsrm_tls_set(what)
# define tsrm_tls_get() NULL
@@ -141,8 +136,6 @@ TSRM_API int tsrm_startup(int expected_threads, int expected_resources, int debu
st_key_create(&tls_key, 0);
#elif defined(TSRM_WIN32)
tls_key = TlsAlloc();
-#elif defined(BETHREADS)
- tls_key = tls_allocate();
#endif
/* ensure singleton */
@@ -251,13 +244,15 @@ TSRM_API ts_rsrc_id ts_allocate_id(ts_rsrc_id *rsrc_id, size_t size, ts_allocate
/* store the new resource type in the resource sizes table */
if (resource_types_table_size < id_count) {
- resource_types_table = (tsrm_resource_type *) realloc(resource_types_table, sizeof(tsrm_resource_type)*id_count);
- if (!resource_types_table) {
+ tsrm_resource_type *_tmp;
+ _tmp = (tsrm_resource_type *) realloc(resource_types_table, sizeof(tsrm_resource_type)*id_count);
+ if (!_tmp) {
tsrm_mutex_unlock(tsmm_mutex);
TSRM_ERROR((TSRM_ERROR_LEVEL_ERROR, "Unable to allocate storage for resource"));
*rsrc_id = 0;
return 0;
}
+ resource_types_table = _tmp;
resource_types_table_size = id_count;
}
resource_types_table[TSRM_UNSHUFFLE_RSRC_ID(*rsrc_id)].size = size;
@@ -591,14 +586,8 @@ TSRM_API THREAD_T tsrm_thread_id(void)
return pth_self();
#elif defined(PTHREADS)
return pthread_self();
-#elif defined(NSAPI)
- return systhread_current();
-#elif defined(PI3WEB)
- return PIThread_getCurrent();
#elif defined(TSRM_ST)
return st_thread_self();
-#elif defined(BETHREADS)
- return find_thread(NULL);
#endif
}/*}}}*/
@@ -616,16 +605,8 @@ TSRM_API MUTEX_T tsrm_mutex_alloc(void)
#elif defined(PTHREADS)
mutexp = (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t));
pthread_mutex_init(mutexp,NULL);
-#elif defined(NSAPI)
- mutexp = crit_init();
-#elif defined(PI3WEB)
- mutexp = PIPlatform_allocLocalMutex();
#elif defined(TSRM_ST)
mutexp = st_mutex_new();
-#elif defined(BETHREADS)
- mutexp = (beos_ben*)malloc(sizeof(beos_ben));
- mutexp->ben = 0;
- mutexp->sem = create_sem(1, "PHP sempahore");
#endif
#ifdef THR_DEBUG
printf("Mutex created thread: %d\n",mythreadid());
@@ -646,15 +627,8 @@ TSRM_API void tsrm_mutex_free(MUTEX_T mutexp)
#elif defined(PTHREADS)
pthread_mutex_destroy(mutexp);
free(mutexp);
-#elif defined(NSAPI)
- crit_terminate(mutexp);
-#elif defined(PI3WEB)
- PISync_delete(mutexp);
#elif defined(TSRM_ST)
st_mutex_destroy(mutexp);
-#elif defined(BETHREADS)
- delete_sem(mutexp->sem);
- free(mutexp);
#endif
}
#ifdef THR_DEBUG
@@ -680,17 +654,8 @@ TSRM_API int tsrm_mutex_lock(MUTEX_T mutexp)
return -1;
#elif defined(PTHREADS)
return pthread_mutex_lock(mutexp);
-#elif defined(NSAPI)
- crit_enter(mutexp);
- return 0;
-#elif defined(PI3WEB)
- return PISync_lock(mutexp);
#elif defined(TSRM_ST)
return st_mutex_lock(mutexp);
-#elif defined(BETHREADS)
- if (atomic_add(&mutexp->ben, 1) != 0)
- return acquire_sem(mutexp->sem);
- return 0;
#endif
}/*}}}*/
@@ -712,17 +677,8 @@ TSRM_API int tsrm_mutex_unlock(MUTEX_T mutexp)
return -1;
#elif defined(PTHREADS)
return pthread_mutex_unlock(mutexp);
-#elif defined(NSAPI)
- crit_exit(mutexp);
- return 0;
-#elif defined(PI3WEB)
- return PISync_unlock(mutexp);
#elif defined(TSRM_ST)
return st_mutex_unlock(mutexp);
-#elif defined(BETHREADS)
- if (atomic_add(&mutexp->ben, -1) != 1)
- return release_sem(mutexp->sem);
- return 0;
#endif
}/*}}}*/
@@ -825,6 +781,21 @@ TSRM_API uint8_t tsrm_is_main_thread(void)
return in_main_thread;
}/*}}}*/
+TSRM_API const char *tsrm_api_name(void)
+{/*{{{*/
+#if defined(GNUPTH)
+ return "GNU Pth";
+#elif defined(PTHREADS)
+ return "POSIX Threads";
+#elif defined(TSRM_ST)
+ return "State Threads";
+#elif defined(TSRM_WIN32)
+ return "Windows Threads";
+#else
+ return "Unknown";
+#endif
+}/*}}}*/
+
#endif /* ZTS */
/*
diff --git a/TSRM/TSRM.h b/TSRM/TSRM.h
index af72b4d8e9..ad18012f3d 100644
--- a/TSRM/TSRM.h
+++ b/TSRM/TSRM.h
@@ -6,7 +6,7 @@
| This source file is subject to the TSRM license, that is bundled |
| with this package in the file LICENSE |
+----------------------------------------------------------------------+
- | Authors: Zeev Suraski <zeev@zend.com> |
+ | Authors: Zeev Suraski <zeev@php.net> |
+----------------------------------------------------------------------+
*/
@@ -69,22 +69,9 @@ typedef int ts_rsrc_id;
#elif defined(PTHREADS)
# define THREAD_T pthread_t
# define MUTEX_T pthread_mutex_t *
-#elif defined(NSAPI)
-# define THREAD_T SYS_THREAD
-# define MUTEX_T CRITICAL
-#elif defined(PI3WEB)
-# define THREAD_T PIThread *
-# define MUTEX_T PISync *
#elif defined(TSRM_ST)
# define THREAD_T st_thread_t
# define MUTEX_T st_mutex_t
-#elif defined(BETHREADS)
-# define THREAD_T thread_id
-typedef struct {
- sem_id sem;
- int32 ben;
-} beos_ben;
-# define MUTEX_T beos_ben *
#endif
#ifdef HAVE_SIGNAL_H
@@ -156,6 +143,7 @@ TSRM_API void tsrm_free_interpreter_context(void *context);
TSRM_API void *tsrm_get_ls_cache(void);
TSRM_API uint8_t tsrm_is_main_thread(void);
+TSRM_API const char *tsrm_api_name(void);
#if defined(__cplusplus) && __cplusplus > 199711L
# define TSRM_TLS thread_local
diff --git a/TSRM/build.mk b/TSRM/build.mk
index 70ef4b8cc3..e5e46b7eaa 100644
--- a/TSRM/build.mk
+++ b/TSRM/build.mk
@@ -4,9 +4,6 @@
# make -f build.mk
#
# Written by Sascha Schumann
-#
-# $Id$
-
LT_TARGETS = ltmain.sh ltconfig
diff --git a/TSRM/config.w32 b/TSRM/config.w32
index cfbd169127..c65a91cc97 100644
--- a/TSRM/config.w32
+++ b/TSRM/config.w32
@@ -1,5 +1,4 @@
// vim:ft=javascript
-// $Id$
ADD_SOURCES("TSRM", "TSRM.c tsrm_strtok_r.c tsrm_win32.c");
ADD_FLAG("CFLAGS_BD_TSRM", "/D ZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
diff --git a/TSRM/configure.ac b/TSRM/configure.ac
index 0f6d53dc8d..c3ed326bce 100644
--- a/TSRM/configure.ac
+++ b/TSRM/configure.ac
@@ -1,4 +1,3 @@
-dnl $Id$
dnl
dnl Minimalistic configure.ac for TSRM.
dnl
@@ -32,4 +31,5 @@ unistd.h \
limits.h
)
-AC_OUTPUT(Makefile)
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
diff --git a/TSRM/m4/gethostbyname.m4 b/TSRM/m4/ax_func_which_gethostbyname_r.m4
index 3f598849bd..bb6bc959e7 100644
--- a/TSRM/m4/gethostbyname.m4
+++ b/TSRM/m4/ax_func_which_gethostbyname_r.m4
@@ -1,6 +1,6 @@
-# =================================================================================
-# http://www.gnu.org/software/autoconf-archive/ax_func_which_gethostbyname_r.html
-# =================================================================================
+# ==================================================================================
+# https://www.gnu.org/software/autoconf-archive/ax_func_which_gethostbyname_r.html
+# ==================================================================================
#
# SYNOPSIS
#
@@ -46,7 +46,7 @@
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
-# with this program. If not, see <http://www.gnu.org/licenses/>.
+# with this program. If not, see <https://www.gnu.org/licenses/>.
#
# As a special exception, the respective Autoconf Macro's copyright owner
# gives unlimited permission to copy, distribute and modify the configure
@@ -61,7 +61,7 @@
# modified version of the Autoconf Macro, you may extend this special
# exception to the GPL to apply to your modified version as well.
-#serial 7
+#serial 8
AC_DEFUN([AX_FUNC_WHICH_GETHOSTBYNAME_R], [
diff --git a/TSRM/threads.m4 b/TSRM/threads.m4
index 95b51e48d8..55864c8982 100644
--- a/TSRM/threads.m4
+++ b/TSRM/threads.m4
@@ -103,52 +103,47 @@ dnl -threads gcc (HP-UX)
dnl
AC_DEFUN([PTHREADS_CHECK],[
-if test "$beos_threads" = "1"; then
- pthreads_working="yes"
- ac_cv_pthreads_cflags=""
-else
- save_CFLAGS=$CFLAGS
- save_LIBS=$LIBS
- PTHREADS_ASSIGN_VARS
- PTHREADS_CHECK_COMPILE
- LIBS=$save_LIBS
- CFLAGS=$save_CFLAGS
+save_CFLAGS=$CFLAGS
+save_LIBS=$LIBS
+PTHREADS_ASSIGN_VARS
+PTHREADS_CHECK_COMPILE
+LIBS=$save_LIBS
+CFLAGS=$save_CFLAGS
- AC_CACHE_CHECK(for pthreads_cflags,ac_cv_pthreads_cflags,[
- ac_cv_pthreads_cflags=
- if test "$pthreads_working" != "yes"; then
- for flag in -kthread -pthread -pthreads -mthreads -Kthread -threads -mt -qthreaded; do
- ac_save=$CFLAGS
- CFLAGS="$CFLAGS $flag"
- PTHREADS_CHECK_COMPILE
- CFLAGS=$ac_save
- if test "$pthreads_checked" = "yes"; then
- ac_cv_pthreads_cflags=$flag
- break
- fi
- done
- fi
- ])
+AC_CACHE_CHECK(for pthreads_cflags,ac_cv_pthreads_cflags,[
+ac_cv_pthreads_cflags=
+if test "$pthreads_working" != "yes"; then
+ for flag in -kthread -pthread -pthreads -mthreads -Kthread -threads -mt -qthreaded; do
+ ac_save=$CFLAGS
+ CFLAGS="$CFLAGS $flag"
+ PTHREADS_CHECK_COMPILE
+ CFLAGS=$ac_save
+ if test "$pthreads_checked" = "yes"; then
+ ac_cv_pthreads_cflags=$flag
+ break
+ fi
+ done
+fi
+])
- AC_CACHE_CHECK(for pthreads_lib, ac_cv_pthreads_lib,[
- ac_cv_pthreads_lib=
- if test "$pthreads_working" != "yes"; then
- for lib in pthread pthreads c_r; do
- ac_save=$LIBS
- LIBS="$LIBS -l$lib"
- PTHREADS_CHECK_COMPILE
- LIBS=$ac_save
- if test "$pthreads_checked" = "yes"; then
- ac_cv_pthreads_lib=$lib
- break
- fi
- done
- fi
- ])
+AC_CACHE_CHECK(for pthreads_lib, ac_cv_pthreads_lib,[
+ac_cv_pthreads_lib=
+if test "$pthreads_working" != "yes"; then
+ for lib in pthread pthreads c_r; do
+ ac_save=$LIBS
+ LIBS="$LIBS -l$lib"
+ PTHREADS_CHECK_COMPILE
+ LIBS=$ac_save
+ if test "$pthreads_checked" = "yes"; then
+ ac_cv_pthreads_lib=$lib
+ break
+ fi
+ done
+fi
+])
- if test "x$ac_cv_pthreads_cflags" != "x" -o "x$ac_cv_pthreads_lib" != "x"; then
- pthreads_working="yes"
- fi
+if test "x$ac_cv_pthreads_cflags" != "x" -o "x$ac_cv_pthreads_lib" != "x"; then
+ pthreads_working="yes"
fi
if test "$pthreads_working" = "yes"; then
diff --git a/TSRM/tsrm.m4 b/TSRM/tsrm.m4
index 27caf1bab9..d02f88ee94 100644
--- a/TSRM/tsrm.m4
+++ b/TSRM/tsrm.m4
@@ -1,26 +1,4 @@
-m4_include([TSRM/m4/gethostbyname.m4])
-
-dnl TSRM_CHECK_GCC_ARG(ARG, ACTION-IF-FOUND, ACTION-IF-NOT_FOUND)
-AC_DEFUN([TSRM_CHECK_GCC_ARG],[
- gcc_arg_name=[ac_cv_gcc_arg]translit($1,A-Z-,a-z_)
- AC_CACHE_CHECK([whether $CC supports $1], [ac_cv_gcc_arg]translit($1,A-Z-,a-z_), [
- echo 'void somefunc() { };' > conftest.c
- cmd='$CC $1 -c conftest.c'
- if eval $cmd 2>&1 | egrep -e $1 >/dev/null ; then
- ac_result=no
- else
- ac_result=yes
- fi
- eval $gcc_arg_name=$ac_result
- rm -f conftest.*
- ])
- if eval test "\$$gcc_arg_name" = "yes"; then
- $2
- else
- :
- $3
- fi
-])
+m4_include([TSRM/m4/ax_func_which_gethostbyname_r.m4])
AC_DEFUN([TSRM_BASIC_CHECKS],[
@@ -78,18 +56,14 @@ AC_DEFUN([TSRM_CHECK_PTHREADS],[
PTHREADS_CHECK
-if test "$beos_threads" = "1"; then
- AC_DEFINE(BETHREADS, 1, Whether to use native BeOS threads)
-else
- if test "$pthreads_working" != "yes"; then
- AC_MSG_ERROR(Your system seems to lack POSIX threads.)
- fi
+if test "$pthreads_working" != "yes"; then
+ AC_MSG_ERROR(Your system seems to lack POSIX threads.)
+fi
- AC_DEFINE(PTHREADS, 1, Whether to use Pthreads)
+AC_DEFINE(PTHREADS, 1, Whether to use Pthreads)
- AC_MSG_CHECKING(for POSIX threads)
- AC_MSG_RESULT(yes)
-fi
+AC_MSG_CHECKING(for POSIX threads)
+AC_MSG_RESULT(yes)
])
AC_DEFUN([TSRM_THREADS_CHECKS],[
diff --git a/TSRM/tsrm_config.w32.h b/TSRM/tsrm_config.w32.h
index a58d47517c..ab45141179 100644
--- a/TSRM/tsrm_config.w32.h
+++ b/TSRM/tsrm_config.w32.h
@@ -6,7 +6,6 @@
#define HAVE_UTIME 1
#define HAVE_ALLOCA 1
-#define HAVE_REALPATH 1
#include <malloc.h>
#include <stdlib.h>
diff --git a/TSRM/tsrm_win32.c b/TSRM/tsrm_win32.c
index 34b0676461..5f0ebba5ae 100644
--- a/TSRM/tsrm_win32.c
+++ b/TSRM/tsrm_win32.c
@@ -16,8 +16,6 @@
+----------------------------------------------------------------------+
*/
-/* $Id$ */
-
#include <stdio.h>
#include <fcntl.h>
#include <io.h>
@@ -207,192 +205,169 @@ TSRM_API int tsrm_win32_access(const char *pathname, int mode)
BOOL fAccess = FALSE;
realpath_cache_bucket * bucket = NULL;
- char * real_path = NULL;
+ char real_path[MAXPATHLEN] = {0};
+
+ if(!IS_ABSOLUTE_PATH(pathname, strlen(pathname)+1)) {
+ if(tsrm_realpath(pathname, real_path) == NULL) {
+ SET_ERRNO_FROM_WIN32_CODE(ERROR_FILE_NOT_FOUND);
+ return -1;
+ }
+ pathname = real_path;
+ }
PHP_WIN32_IOUTIL_INIT_W(pathname)
if (!pathw) {
return -1;
}
- if (mode == 1 /*X_OK*/) {
- DWORD type;
- int ret;
-
- ret = GetBinaryTypeW(pathw, &type) ? 0 : -1;
-
+ /* Either access call failed, or the mode was asking for a specific check.*/
+ int ret = php_win32_ioutil_access_w(pathw, mode);
+ if (0 > ret || X_OK == mode || F_OK == mode) {
PHP_WIN32_IOUTIL_CLEANUP_W()
-
return ret;
- } else {
- if(!IS_ABSOLUTE_PATH(pathname, strlen(pathname)+1)) {
- real_path = (char *)malloc(MAXPATHLEN);
- if(tsrm_realpath(pathname, real_path) == NULL) {
- goto Finished;
- }
- pathname = real_path;
- PHP_WIN32_IOUTIL_REINIT_W(pathname);
- }
-
- if(php_win32_ioutil_access(pathname, mode)) {
- PHP_WIN32_IOUTIL_CLEANUP_W()
- free(real_path);
- return errno;
- }
-
- /* If only existence check is made, return now */
- if (mode == 0) {
- PHP_WIN32_IOUTIL_CLEANUP_W()
- free(real_path);
- return 0;
- }
+ }
/* Only in NTS when impersonate==1 (aka FastCGI) */
- /*
- AccessCheck() requires an impersonation token. We first get a primary
- token and then create a duplicate impersonation token. The
- impersonation token is not actually assigned to the thread, but is
- used in the call to AccessCheck. Thus, this function itself never
- impersonates, but does use the identity of the thread. If the thread
- was impersonating already, this function uses that impersonation context.
- */
- if(!OpenThreadToken(GetCurrentThread(), TOKEN_ALL_ACCESS, TRUE, &thread_token)) {
- if (GetLastError() == ERROR_NO_TOKEN) {
- if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ALL_ACCESS, &thread_token)) {
- TWG(impersonation_token) = NULL;
- goto Finished;
- }
- }
+ /*
+ AccessCheck() requires an impersonation token. We first get a primary
+ token and then create a duplicate impersonation token. The
+ impersonation token is not actually assigned to the thread, but is
+ used in the call to AccessCheck. Thus, this function itself never
+ impersonates, but does use the identity of the thread. If the thread
+ was impersonating already, this function uses that impersonation context.
+ */
+ if(!OpenThreadToken(GetCurrentThread(), TOKEN_ALL_ACCESS, TRUE, &thread_token)) {
+ if (GetLastError() == ERROR_NO_TOKEN) {
+ if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ALL_ACCESS, &thread_token)) {
+ TWG(impersonation_token) = NULL;
+ goto Finished;
+ }
}
+ }
- /* token_sid will be freed in tsrmwin32_dtor */
- token_sid = tsrm_win32_get_token_sid(thread_token);
- if (!token_sid) {
- if (TWG(impersonation_token_sid)) {
- free(TWG(impersonation_token_sid));
- }
- TWG(impersonation_token_sid) = NULL;
- goto Finished;
+ /* token_sid will be freed in tsrmwin32_dtor */
+ token_sid = tsrm_win32_get_token_sid(thread_token);
+ if (!token_sid) {
+ if (TWG(impersonation_token_sid)) {
+ free(TWG(impersonation_token_sid));
}
+ TWG(impersonation_token_sid) = NULL;
+ goto Finished;
+ }
- /* Different identity, we need a new impersontated token as well */
- if (!TWG(impersonation_token_sid) || !EqualSid(token_sid, TWG(impersonation_token_sid))) {
- if (TWG(impersonation_token_sid)) {
- free(TWG(impersonation_token_sid));
- }
- TWG(impersonation_token_sid) = token_sid;
-
- /* Duplicate the token as impersonated token */
- if (!DuplicateToken(thread_token, SecurityImpersonation, &TWG(impersonation_token))) {
- goto Finished;
- }
- } else {
- /* we already have it, free it then */
- free(token_sid);
+ /* Different identity, we need a new impersontated token as well */
+ if (!TWG(impersonation_token_sid) || !EqualSid(token_sid, TWG(impersonation_token_sid))) {
+ if (TWG(impersonation_token_sid)) {
+ free(TWG(impersonation_token_sid));
}
+ TWG(impersonation_token_sid) = token_sid;
- if (CWDG(realpath_cache_size_limit)) {
- t = time(0);
- bucket = realpath_cache_lookup(pathname, strlen(pathname), t);
- if(bucket == NULL && real_path == NULL) {
- /* We used the pathname directly. Call tsrm_realpath */
- /* so that entry is created in realpath cache */
- real_path = (char *)malloc(MAXPATHLEN);
- if(tsrm_realpath(pathname, real_path) != NULL) {
- pathname = real_path;
- bucket = realpath_cache_lookup(pathname, strlen(pathname), t);
- PHP_WIN32_IOUTIL_REINIT_W(pathname);
- }
- }
- }
-
- /* Do a full access check because access() will only check read-only attribute */
- if(mode == 0 || mode > 6) {
- if(bucket != NULL && bucket->is_rvalid) {
- fAccess = bucket->is_readable;
- goto Finished;
- }
- desired_access = FILE_GENERIC_READ;
- } else if(mode <= 2) {
- if(bucket != NULL && bucket->is_wvalid) {
- fAccess = bucket->is_writable;
- goto Finished;
- }
- desired_access = FILE_GENERIC_WRITE;
- } else if(mode <= 4) {
- if(bucket != NULL && bucket->is_rvalid) {
- fAccess = bucket->is_readable;
- goto Finished;
- }
- desired_access = FILE_GENERIC_READ|FILE_FLAG_BACKUP_SEMANTICS;
- } else { // if(mode <= 6)
- if(bucket != NULL && bucket->is_rvalid && bucket->is_wvalid) {
- fAccess = bucket->is_readable & bucket->is_writable;
- goto Finished;
+ /* Duplicate the token as impersonated token */
+ if (!DuplicateToken(thread_token, SecurityImpersonation, &TWG(impersonation_token))) {
+ goto Finished;
+ }
+ } else {
+ /* we already have it, free it then */
+ free(token_sid);
+ }
+
+ if (CWDG(realpath_cache_size_limit)) {
+ t = time(0);
+ bucket = realpath_cache_lookup(pathname, strlen(pathname), t);
+ if(bucket == NULL && !real_path[0]) {
+ /* We used the pathname directly. Call tsrm_realpath */
+ /* so that entry is created in realpath cache */
+ if(tsrm_realpath(pathname, real_path) != NULL) {
+ pathname = real_path;
+ bucket = realpath_cache_lookup(pathname, strlen(pathname), t);
+ PHP_WIN32_IOUTIL_REINIT_W(pathname);
}
- desired_access = FILE_GENERIC_READ | FILE_GENERIC_WRITE;
- }
+ }
+ }
- if(TWG(impersonation_token) == NULL) {
+ /* Do a full access check because access() will only check read-only attribute */
+ if(mode == 0 || mode > 6) {
+ if(bucket != NULL && bucket->is_rvalid) {
+ fAccess = bucket->is_readable;
goto Finished;
}
-
- /* Get size of security buffer. Call is expected to fail */
- if(GetFileSecurityW(pathw, sec_info, NULL, 0, &sec_desc_length)) {
+ desired_access = FILE_GENERIC_READ;
+ } else if(mode <= 2) {
+ if(bucket != NULL && bucket->is_wvalid) {
+ fAccess = bucket->is_writable;
goto Finished;
}
-
- psec_desc = (BYTE *)malloc(sec_desc_length);
- if(psec_desc == NULL ||
- !GetFileSecurityW(pathw, sec_info, (PSECURITY_DESCRIPTOR)psec_desc, sec_desc_length, &sec_desc_length)) {
+ desired_access = FILE_GENERIC_WRITE;
+ } else if(mode <= 4) {
+ if(bucket != NULL && bucket->is_rvalid) {
+ fAccess = bucket->is_readable;
+ goto Finished;
+ }
+ desired_access = FILE_GENERIC_READ|FILE_FLAG_BACKUP_SEMANTICS;
+ } else { // if(mode <= 6)
+ if(bucket != NULL && bucket->is_rvalid && bucket->is_wvalid) {
+ fAccess = bucket->is_readable & bucket->is_writable;
goto Finished;
}
+ desired_access = FILE_GENERIC_READ | FILE_GENERIC_WRITE;
+ }
- MapGenericMask(&desired_access, &gen_map);
+ if(TWG(impersonation_token) == NULL) {
+ goto Finished;
+ }
- if(!AccessCheck((PSECURITY_DESCRIPTOR)psec_desc, TWG(impersonation_token), desired_access, &gen_map, &privilege_set, &priv_set_length, &granted_access, &fAccess)) {
- goto Finished_Impersonate;
- }
+ /* Get size of security buffer. Call is expected to fail */
+ if(GetFileSecurityW(pathw, sec_info, NULL, 0, &sec_desc_length)) {
+ goto Finished;
+ }
- /* Keep the result in realpath_cache */
- if(bucket != NULL) {
- if(desired_access == (FILE_GENERIC_READ|FILE_FLAG_BACKUP_SEMANTICS)) {
- bucket->is_rvalid = 1;
- bucket->is_readable = fAccess;
- }
- else if(desired_access == FILE_GENERIC_WRITE) {
- bucket->is_wvalid = 1;
- bucket->is_writable = fAccess;
- } else if (desired_access == (FILE_GENERIC_READ | FILE_GENERIC_WRITE)) {
- bucket->is_rvalid = 1;
- bucket->is_readable = fAccess;
- bucket->is_wvalid = 1;
- bucket->is_writable = fAccess;
- }
+ psec_desc = (BYTE *)malloc(sec_desc_length);
+ if(psec_desc == NULL ||
+ !GetFileSecurityW(pathw, sec_info, (PSECURITY_DESCRIPTOR)psec_desc, sec_desc_length, &sec_desc_length)) {
+ goto Finished;
+ }
+
+ MapGenericMask(&desired_access, &gen_map);
+
+ if(!AccessCheck((PSECURITY_DESCRIPTOR)psec_desc, TWG(impersonation_token), desired_access, &gen_map, &privilege_set, &priv_set_length, &granted_access, &fAccess)) {
+ goto Finished_Impersonate;
+ }
+
+ /* Keep the result in realpath_cache */
+ if(bucket != NULL) {
+ if(desired_access == (FILE_GENERIC_READ|FILE_FLAG_BACKUP_SEMANTICS)) {
+ bucket->is_rvalid = 1;
+ bucket->is_readable = fAccess;
+ }
+ else if(desired_access == FILE_GENERIC_WRITE) {
+ bucket->is_wvalid = 1;
+ bucket->is_writable = fAccess;
+ } else if (desired_access == (FILE_GENERIC_READ | FILE_GENERIC_WRITE)) {
+ bucket->is_rvalid = 1;
+ bucket->is_readable = fAccess;
+ bucket->is_wvalid = 1;
+ bucket->is_writable = fAccess;
}
+ }
Finished_Impersonate:
- if(psec_desc != NULL) {
- free(psec_desc);
- psec_desc = NULL;
- }
+ if(psec_desc != NULL) {
+ free(psec_desc);
+ psec_desc = NULL;
+ }
Finished:
- if(thread_token != NULL) {
- CloseHandle(thread_token);
- }
- if(real_path != NULL) {
- free(real_path);
- real_path = NULL;
- }
+ if(thread_token != NULL) {
+ CloseHandle(thread_token);
+ }
- PHP_WIN32_IOUTIL_CLEANUP_W()
- if(fAccess == FALSE) {
- errno = EACCES;
- return errno;
- } else {
- return 0;
- }
+ PHP_WIN32_IOUTIL_CLEANUP_W()
+ if(fAccess == FALSE) {
+ errno = EACCES;
+ return errno;
+ } else {
+ return 0;
}
}/*}}}*/
@@ -789,15 +764,6 @@ TSRM_API int shmctl(int key, int cmd, struct shmid_ds *buf)
}
}/*}}}*/
-TSRM_API char *realpath(char *orig_path, char *buffer)
-{/*{{{*/
- int ret = GetFullPathName(orig_path, _MAX_PATH, buffer, NULL);
- if(!ret || ret > _MAX_PATH) {
- return NULL;
- }
- return buffer;
-}/*}}}*/
-
#if HAVE_UTIME
static zend_always_inline void UnixTimeToFileTime(time_t t, LPFILETIME pft) /* {{{ */
{
diff --git a/TSRM/tsrm_win32.h b/TSRM/tsrm_win32.h
index d8a2fce4de..b24224c66a 100644
--- a/TSRM/tsrm_win32.h
+++ b/TSRM/tsrm_win32.h
@@ -16,8 +16,6 @@
+----------------------------------------------------------------------+
*/
-/* $Id$ */
-
#ifndef TSRM_WIN32_H
#define TSRM_WIN32_H
@@ -110,8 +108,6 @@ TSRM_API int shmget(key_t key, size_t size, int flags);
TSRM_API void *shmat(int key, const void *shmaddr, int flags);
TSRM_API int shmdt(const void *shmaddr);
TSRM_API int shmctl(int key, int cmd, struct shmid_ds *buf);
-
-TSRM_API char *realpath(char *orig_path, char *buffer);
#endif
/*