summaryrefslogtreecommitdiff
path: root/TSRM
diff options
context:
space:
mode:
authorOndřej Surý <ondrej@sury.org>2010-01-07 13:31:53 +0100
committerOndřej Surý <ondrej@sury.org>2010-01-07 13:31:53 +0100
commit0fab6db7cac8d2be99579dd049f812a8ff98e74f (patch)
tree91f01b0d06916c78262404096bfd466b8e95e5b5 /TSRM
parentd3a8757891280dc6650ca7eead67830c794b0e7b (diff)
downloadphp-0fab6db7cac8d2be99579dd049f812a8ff98e74f.tar.gz
Imported Upstream version 5.3.1upstream/5.3.1
Diffstat (limited to 'TSRM')
-rw-r--r--TSRM/TSRM.dsp372
-rw-r--r--TSRM/build.mk2
-rw-r--r--TSRM/config.w322
-rw-r--r--TSRM/configure.in2
-rw-r--r--TSRM/tsrm_nw.c2
-rw-r--r--TSRM/tsrm_virtual_cwd.c167
-rw-r--r--TSRM/tsrm_virtual_cwd.h11
-rw-r--r--TSRM/tsrm_win32.c248
-rw-r--r--TSRM/tsrm_win32.h5
9 files changed, 556 insertions, 255 deletions
diff --git a/TSRM/TSRM.dsp b/TSRM/TSRM.dsp
index 53bce254f..1a5693f5a 100644
--- a/TSRM/TSRM.dsp
+++ b/TSRM/TSRM.dsp
@@ -1,186 +1,186 @@
-# Microsoft Developer Studio Project File - Name="TSRM" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Static Library" 0x0104
-
-CFG=TSRM - Win32 Debug_TS
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,
-!MESSAGE use the Export Makefile command and run
-!MESSAGE
-!MESSAGE NMAKE /f "TSRM.mak".
-!MESSAGE
-!MESSAGE You can specify a configuration when running NMAKE
-!MESSAGE by defining the macro CFG on the command line. For example:
-!MESSAGE
-!MESSAGE NMAKE /f "TSRM.mak" CFG="TSRM - Win32 Debug_TS"
-!MESSAGE
-!MESSAGE Possible choices for configuration are:
-!MESSAGE
-!MESSAGE "TSRM - Win32 Debug_TS" (based on "Win32 (x86) Static Library")
-!MESSAGE "TSRM - Win32 Release_TS" (based on "Win32 (x86) Static Library")
-!MESSAGE "TSRM - Win32 Release_TS_inline" (based on "Win32 (x86) Static Library")
-!MESSAGE "TSRM - Win32 Release_TSDbg" (based on "Win32 (x86) Static Library")
-!MESSAGE
-
-# Begin Project
-# PROP AllowPerConfigDependencies 0
-# PROP Scc_ProjName ""
-# PROP Scc_LocalPath ""
-CPP=cl.exe
-RSC=rc.exe
-
-!IF "$(CFG)" == "TSRM - Win32 Debug_TS"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "TSRM___Win32_Debug_TS"
-# PROP BASE Intermediate_Dir "TSRM___Win32_Debug_TS"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "Debug_TS"
-# PROP Intermediate_Dir "Debug_TS"
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /I "C:\Projects\TSRM" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
-# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "." /D "_DEBUG" /D "ZTS" /D "_LIB" /D "TSRM_EXPORTS" /D "WIN32" /D "_MBCS" /D TSRM_DEBUG=1 /YX /FD /GZ /c
-# ADD BASE RSC /l 0x40d /d "_DEBUG"
-# ADD RSC /l 0x40d /d "_DEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LIB32=link.exe -lib
-# ADD BASE LIB32 /nologo
-# ADD LIB32 /nologo
-
-!ELSEIF "$(CFG)" == "TSRM - Win32 Release_TS"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "TSRM___Win32_Release_TS"
-# PROP BASE Intermediate_Dir "TSRM___Win32_Release_TS"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "Release_TS"
-# PROP Intermediate_Dir "Release_TS"
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
-# ADD CPP /nologo /MD /W3 /GX /O2 /I "." /D "NDEBUG" /D "ZTS" /D "_LIB" /D "TSRM_EXPORTS" /D "WIN32" /D "_MBCS" /D TSRM_DEBUG=0 /YX /FD /c
-# ADD BASE RSC /l 0x40d /d "NDEBUG"
-# ADD RSC /l 0x40d /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LIB32=link.exe -lib
-# ADD BASE LIB32 /nologo
-# ADD LIB32 /nologo
-
-!ELSEIF "$(CFG)" == "TSRM - Win32 Release_TS_inline"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "TSRM___Win32_Release_TS_inline"
-# PROP BASE Intermediate_Dir "TSRM___Win32_Release_TS_inline"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "Release_TS_inline"
-# PROP Intermediate_Dir "Release_TS_inline"
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MD /W3 /GX /O2 /I "." /D "NDEBUG" /D "WIN32" /D "_MBCS" /D "_LIB" /D "TSRM_EXPORTS" /YX /FD /c
-# ADD CPP /nologo /MD /W3 /GX /O2 /I "." /D "NDEBUG" /D "ZTS" /D "_LIB" /D "TSRM_EXPORTS" /D "WIN32" /D "_MBCS" /D TSRM_DEBUG=0 /YX /FD /c
-# ADD BASE RSC /l 0x40d /d "NDEBUG"
-# ADD RSC /l 0x40d /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LIB32=link.exe -lib
-# ADD BASE LIB32 /nologo
-# ADD LIB32 /nologo
-
-!ELSEIF "$(CFG)" == "TSRM - Win32 Release_TSDbg"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "TSRM___Win32_Release_TSDbg"
-# PROP BASE Intermediate_Dir "TSRM___Win32_Release_TSDbg"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "Release_TSDbg"
-# PROP Intermediate_Dir "Release_TSDbg"
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MD /W3 /GX /O2 /I "." /D "NDEBUG" /D "ZTS" /D "_LIB" /D "TSRM_EXPORTS" /D "WIN32" /D "_MBCS" /D TSRM_DEBUG=0 /YX /FD /c
-# ADD CPP /nologo /MD /W3 /GX /Zi /Od /I "." /D "NDEBUG" /D "ZTS" /D "_LIB" /D "TSRM_EXPORTS" /D "WIN32" /D "_MBCS" /D TSRM_DEBUG=0 /YX /FD /c
-# ADD BASE RSC /l 0x40d /d "NDEBUG"
-# ADD RSC /l 0x40d /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LIB32=link.exe -lib
-# ADD BASE LIB32 /nologo
-# ADD LIB32 /nologo
-
-!ENDIF
-
-# Begin Target
-
-# Name "TSRM - Win32 Debug_TS"
-# Name "TSRM - Win32 Release_TS"
-# Name "TSRM - Win32 Release_TS_inline"
-# Name "TSRM - Win32 Release_TSDbg"
-# Begin Group "Source Files"
-
-# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
-# Begin Source File
-
-SOURCE=.\TSRM.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\tsrm_strtok_r.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\tsrm_virtual_cwd.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\tsrm_win32.c
-# End Source File
-# End Group
-# Begin Group "Header Files"
-
-# PROP Default_Filter "h;hpp;hxx;hm;inl"
-# Begin Source File
-
-SOURCE=.\readdir.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\TSRM.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\tsrm_config.w32.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\tsrm_config_common.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\tsrm_strtok_r.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\tsrm_virtual_cwd.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\tsrm_win32.h
-# End Source File
-# End Group
-# End Target
-# End Project
+# Microsoft Developer Studio Project File - Name="TSRM" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Static Library" 0x0104
+
+CFG=TSRM - Win32 Debug_TS
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "TSRM.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "TSRM.mak" CFG="TSRM - Win32 Debug_TS"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "TSRM - Win32 Debug_TS" (based on "Win32 (x86) Static Library")
+!MESSAGE "TSRM - Win32 Release_TS" (based on "Win32 (x86) Static Library")
+!MESSAGE "TSRM - Win32 Release_TS_inline" (based on "Win32 (x86) Static Library")
+!MESSAGE "TSRM - Win32 Release_TSDbg" (based on "Win32 (x86) Static Library")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "TSRM - Win32 Debug_TS"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "TSRM___Win32_Debug_TS"
+# PROP BASE Intermediate_Dir "TSRM___Win32_Debug_TS"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug_TS"
+# PROP Intermediate_Dir "Debug_TS"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /I "C:\Projects\TSRM" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
+# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "." /D "_DEBUG" /D "ZTS" /D "_LIB" /D "TSRM_EXPORTS" /D "WIN32" /D "_MBCS" /D TSRM_DEBUG=1 /YX /FD /GZ /c
+# ADD BASE RSC /l 0x40d /d "_DEBUG"
+# ADD RSC /l 0x40d /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LIB32=link.exe -lib
+# ADD BASE LIB32 /nologo
+# ADD LIB32 /nologo
+
+!ELSEIF "$(CFG)" == "TSRM - Win32 Release_TS"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "TSRM___Win32_Release_TS"
+# PROP BASE Intermediate_Dir "TSRM___Win32_Release_TS"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release_TS"
+# PROP Intermediate_Dir "Release_TS"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
+# ADD CPP /nologo /MD /W3 /GX /O2 /I "." /D "NDEBUG" /D "ZTS" /D "_LIB" /D "TSRM_EXPORTS" /D "WIN32" /D "_MBCS" /D TSRM_DEBUG=0 /YX /FD /c
+# ADD BASE RSC /l 0x40d /d "NDEBUG"
+# ADD RSC /l 0x40d /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LIB32=link.exe -lib
+# ADD BASE LIB32 /nologo
+# ADD LIB32 /nologo
+
+!ELSEIF "$(CFG)" == "TSRM - Win32 Release_TS_inline"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "TSRM___Win32_Release_TS_inline"
+# PROP BASE Intermediate_Dir "TSRM___Win32_Release_TS_inline"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release_TS_inline"
+# PROP Intermediate_Dir "Release_TS_inline"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MD /W3 /GX /O2 /I "." /D "NDEBUG" /D "WIN32" /D "_MBCS" /D "_LIB" /D "TSRM_EXPORTS" /YX /FD /c
+# ADD CPP /nologo /MD /W3 /GX /O2 /I "." /D "NDEBUG" /D "ZTS" /D "_LIB" /D "TSRM_EXPORTS" /D "WIN32" /D "_MBCS" /D TSRM_DEBUG=0 /YX /FD /c
+# ADD BASE RSC /l 0x40d /d "NDEBUG"
+# ADD RSC /l 0x40d /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LIB32=link.exe -lib
+# ADD BASE LIB32 /nologo
+# ADD LIB32 /nologo
+
+!ELSEIF "$(CFG)" == "TSRM - Win32 Release_TSDbg"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "TSRM___Win32_Release_TSDbg"
+# PROP BASE Intermediate_Dir "TSRM___Win32_Release_TSDbg"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release_TSDbg"
+# PROP Intermediate_Dir "Release_TSDbg"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MD /W3 /GX /O2 /I "." /D "NDEBUG" /D "ZTS" /D "_LIB" /D "TSRM_EXPORTS" /D "WIN32" /D "_MBCS" /D TSRM_DEBUG=0 /YX /FD /c
+# ADD CPP /nologo /MD /W3 /GX /Zi /Od /I "." /D "NDEBUG" /D "ZTS" /D "_LIB" /D "TSRM_EXPORTS" /D "WIN32" /D "_MBCS" /D TSRM_DEBUG=0 /YX /FD /c
+# ADD BASE RSC /l 0x40d /d "NDEBUG"
+# ADD RSC /l 0x40d /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LIB32=link.exe -lib
+# ADD BASE LIB32 /nologo
+# ADD LIB32 /nologo
+
+!ENDIF
+
+# Begin Target
+
+# Name "TSRM - Win32 Debug_TS"
+# Name "TSRM - Win32 Release_TS"
+# Name "TSRM - Win32 Release_TS_inline"
+# Name "TSRM - Win32 Release_TSDbg"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\TSRM.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\tsrm_strtok_r.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\tsrm_virtual_cwd.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\tsrm_win32.c
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=.\readdir.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\TSRM.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\tsrm_config.w32.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\tsrm_config_common.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\tsrm_strtok_r.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\tsrm_virtual_cwd.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\tsrm_win32.h
+# End Source File
+# End Group
+# End Target
+# End Project
diff --git a/TSRM/build.mk b/TSRM/build.mk
index d62326a94..5cd3aa9a7 100644
--- a/TSRM/build.mk
+++ b/TSRM/build.mk
@@ -5,7 +5,7 @@
#
# Written by Sascha Schumann
#
-# $Id: build.mk,v 1.2 1999/10/10 02:01:20 sascha Exp $
+# $Id: build.mk 14329 1999-10-10 02:02:13Z sascha $
LT_TARGETS = ltmain.sh ltconfig
diff --git a/TSRM/config.w32 b/TSRM/config.w32
index 2f70ced85..0098b0e8f 100644
--- a/TSRM/config.w32
+++ b/TSRM/config.w32
@@ -1,5 +1,5 @@
// vim:ft=javascript
-// $Id: config.w32,v 1.1 2003/12/22 15:01:05 wez Exp $
+// $Id: config.w32 147168 2003-12-22 15:01:05Z wez $
if (CHECK_HEADER_ADD_INCLUDE("NewAPIs.h", "CFLAGS_PHP", php_usual_include_suspects)) {
// Need to add the flag directly, since TSRM doesn't include the config
diff --git a/TSRM/configure.in b/TSRM/configure.in
index fb1a5a6e6..6705f583d 100644
--- a/TSRM/configure.in
+++ b/TSRM/configure.in
@@ -1,4 +1,4 @@
-dnl $Id: configure.in,v 1.17 2001/08/08 10:26:21 zeev Exp $
+dnl $Id: configure.in 53832 2001-08-08 10:26:21Z zeev $
dnl
dnl Minimalistic configure.in for TSRM.
dnl
diff --git a/TSRM/tsrm_nw.c b/TSRM/tsrm_nw.c
index f007e7f99..4a9ccabdd 100644
--- a/TSRM/tsrm_nw.c
+++ b/TSRM/tsrm_nw.c
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: tsrm_nw.c,v 1.8.2.1.2.1.2.2 2008/12/31 11:15:31 sebastian Exp $ */
+/* $Id: tsrm_nw.c 272370 2008-12-31 11:15:49Z sebastian $ */
#include <stdlib.h>
#include <stdio.h>
diff --git a/TSRM/tsrm_virtual_cwd.c b/TSRM/tsrm_virtual_cwd.c
index 770bf15e2..37b9820ea 100644
--- a/TSRM/tsrm_virtual_cwd.c
+++ b/TSRM/tsrm_virtual_cwd.c
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: tsrm_virtual_cwd.c,v 1.74.2.9.2.35.2.22 2009/06/26 07:39:42 pajoye Exp $ */
+/* $Id: tsrm_virtual_cwd.c 289780 2009-10-19 23:38:55Z pajoye $ */
#include <sys/types.h>
#include <sys/stat.h>
@@ -271,9 +271,6 @@ CWD_API int php_sys_stat(const char *path, struct stat *buf) /* {{{ */
buf->st_atime = FileTimeToUnixTime(data.ftLastAccessTime);
buf->st_ctime = FileTimeToUnixTime(data.ftCreationTime);
buf->st_mtime = FileTimeToUnixTime(data.ftLastWriteTime);
- if (buf->st_mtime != buf->st_atime) {
- buf->st_atime = buf->st_mtime;
- }
return 0;
}
/* }}} */
@@ -431,6 +428,31 @@ CWD_API char *virtual_getcwd(char *buf, size_t size TSRMLS_DC) /* {{{ */
}
/* }}} */
+#ifdef PHP_WIN32
+static inline unsigned long realpath_cache_key(const char *path, int path_len TSRMLS_DC) /* {{{ */
+{
+ register unsigned long h;
+ char *bucket_key = tsrm_win32_get_path_sid_key(path TSRMLS_CC);
+ char *bucket_key_start = (char *)bucket_key;
+ const char *e = bucket_key + strlen(bucket_key);
+
+ if (!bucket_key) {
+ return 0;
+ }
+
+ for (h = 2166136261U; bucket_key < e;) {
+ h *= 16777619;
+ h ^= *bucket_key++;
+ }
+ /* if no SID were present the path is returned. Otherwise a Heap
+ allocated string is returned. */
+ if (bucket_key_start != path) {
+ LocalFree(bucket_key_start);
+ }
+ return h;
+}
+/* }}} */
+#else
static inline unsigned long realpath_cache_key(const char *path, int path_len) /* {{{ */
{
register unsigned long h;
@@ -444,6 +466,7 @@ static inline unsigned long realpath_cache_key(const char *path, int path_len) /
return h;
}
/* }}} */
+#endif /* defined(PHP_WIN32) */
CWD_API void realpath_cache_clean(TSRMLS_D) /* {{{ */
{
@@ -464,7 +487,11 @@ CWD_API void realpath_cache_clean(TSRMLS_D) /* {{{ */
CWD_API void realpath_cache_del(const char *path, int path_len TSRMLS_DC) /* {{{ */
{
+#ifdef PHP_WIN32
+ unsigned long key = realpath_cache_key(path, path_len TSRMLS_CC);
+#else
unsigned long key = realpath_cache_key(path, path_len);
+#endif
unsigned long n = key % (sizeof(CWDG(realpath_cache)) / sizeof(CWDG(realpath_cache)[0]));
realpath_cache_bucket **bucket = &CWDG(realpath_cache)[n];
@@ -497,8 +524,12 @@ static inline void realpath_cache_add(const char *path, int path_len, const char
if (CWDG(realpath_cache_size) + size <= CWDG(realpath_cache_size_limit)) {
realpath_cache_bucket *bucket = malloc(size);
unsigned long n;
-
+
+#ifdef PHP_WIN32
+ bucket->key = realpath_cache_key(path, path_len TSRMLS_CC);
+#else
bucket->key = realpath_cache_key(path, path_len);
+#endif
bucket->path = (char*)bucket + sizeof(realpath_cache_bucket);
memcpy(bucket->path, path, path_len+1);
bucket->path_len = path_len;
@@ -527,7 +558,12 @@ static inline void realpath_cache_add(const char *path, int path_len, const char
static inline realpath_cache_bucket* realpath_cache_find(const char *path, int path_len, time_t t TSRMLS_DC) /* {{{ */
{
+#ifdef PHP_WIN32
+ unsigned long key = realpath_cache_key(path, path_len TSRMLS_CC);
+#else
unsigned long key = realpath_cache_key(path, path_len);
+#endif
+
unsigned long n = key % (sizeof(CWDG(realpath_cache)) / sizeof(CWDG(realpath_cache)[0]));
realpath_cache_bucket **bucket = &CWDG(realpath_cache)[n];
@@ -564,13 +600,13 @@ static int tsrm_realpath_r(char *path, int start, int len, int *ll, time_t *t, i
#ifdef TSRM_WIN32
WIN32_FIND_DATA data;
HANDLE hFind;
+ TSRM_ALLOCA_FLAG(use_heap_large)
#else
struct stat st;
#endif
realpath_cache_bucket *bucket;
char *tmp;
TSRM_ALLOCA_FLAG(use_heap)
- TSRM_ALLOCA_FLAG(use_heap_large)
while (1) {
if (len <= start) {
@@ -670,9 +706,14 @@ static int tsrm_realpath_r(char *path, int start, int len, int *ll, time_t *t, i
/* File is a reparse point. Get the target */
HANDLE hLink = NULL;
REPARSE_DATA_BUFFER * pbuffer;
- unsigned int retlength = 0, rname_off = 0;
- int bufindex = 0, rname_len = 0, isabsolute = 0;
+ unsigned int retlength = 0;
+ int bufindex = 0, isabsolute = 0;
wchar_t * reparsetarget;
+ BOOL isVolume = FALSE;
+ char printname[MAX_PATH];
+ char substitutename[MAX_PATH];
+ int printname_len, substitutename_len;
+ int substitutename_off = 0;
if(++(*ll) > LINK_MAX) {
return -1;
@@ -693,37 +734,108 @@ static int tsrm_realpath_r(char *path, int start, int len, int *ll, time_t *t, i
CloseHandle(hLink);
if(pbuffer->ReparseTag == IO_REPARSE_TAG_SYMLINK) {
- rname_len = pbuffer->SymbolicLinkReparseBuffer.PrintNameLength/2;
- rname_off = pbuffer->SymbolicLinkReparseBuffer.PrintNameOffset/2;
reparsetarget = pbuffer->SymbolicLinkReparseBuffer.ReparseTarget;
+ printname_len = pbuffer->MountPointReparseBuffer.PrintNameLength / sizeof(WCHAR);
isabsolute = (pbuffer->SymbolicLinkReparseBuffer.Flags == 0) ? 1 : 0;
+ if (!WideCharToMultiByte(CP_THREAD_ACP, 0,
+ reparsetarget + pbuffer->MountPointReparseBuffer.PrintNameOffset / sizeof(WCHAR),
+ printname_len + 1,
+ printname, MAX_PATH, NULL, NULL
+ )) {
+ tsrm_free_alloca(pbuffer, use_heap_large);
+ return -1;
+ };
+ printname_len = pbuffer->MountPointReparseBuffer.PrintNameLength / sizeof(WCHAR);
+ printname[printname_len] = 0;
+
+ substitutename_len = pbuffer->MountPointReparseBuffer.SubstituteNameLength / sizeof(WCHAR);
+ if (!WideCharToMultiByte(CP_THREAD_ACP, 0,
+ reparsetarget + pbuffer->MountPointReparseBuffer.SubstituteNameOffset / sizeof(WCHAR),
+ substitutename_len + 1,
+ substitutename, MAX_PATH, NULL, NULL
+ )) {
+ tsrm_free_alloca(pbuffer, use_heap_large);
+ return -1;
+ };
+ substitutename[substitutename_len] = 0;
}
else if(pbuffer->ReparseTag == IO_REPARSE_TAG_MOUNT_POINT) {
- rname_len = pbuffer->MountPointReparseBuffer.PrintNameLength/2;
- rname_off = pbuffer->MountPointReparseBuffer.PrintNameOffset/2;
- reparsetarget = pbuffer->MountPointReparseBuffer.ReparseTarget;
isabsolute = 1;
- }
- else {
+ reparsetarget = pbuffer->MountPointReparseBuffer.ReparseTarget;
+ printname_len = pbuffer->MountPointReparseBuffer.PrintNameLength / sizeof(WCHAR);
+ if (!WideCharToMultiByte(CP_THREAD_ACP, 0,
+ reparsetarget + pbuffer->MountPointReparseBuffer.PrintNameOffset / sizeof(WCHAR),
+ printname_len + 1,
+ printname, MAX_PATH, NULL, NULL
+ )) {
+ tsrm_free_alloca(pbuffer, use_heap_large);
+ return -1;
+ };
+ printname[pbuffer->MountPointReparseBuffer.PrintNameLength / sizeof(WCHAR)] = 0;
+
+ substitutename_len = pbuffer->MountPointReparseBuffer.SubstituteNameLength / sizeof(WCHAR);
+ if (!WideCharToMultiByte(CP_THREAD_ACP, 0,
+ reparsetarget + pbuffer->MountPointReparseBuffer.SubstituteNameOffset / sizeof(WCHAR),
+ substitutename_len + 1,
+ substitutename, MAX_PATH, NULL, NULL
+ )) {
+ tsrm_free_alloca(pbuffer, use_heap_large);
+ return -1;
+ };
+ substitutename[substitutename_len] = 0;
+ } else {
tsrm_free_alloca(pbuffer, use_heap_large);
return -1;
}
- /* Convert wide string to narrow string */
- for(bufindex = 0; bufindex < rname_len; bufindex++) {
- *(path + bufindex) = (char)(reparsetarget[rname_off + bufindex]);
+ if(isabsolute && substitutename_len > 4) {
+ /* Do not resolve volumes (for now). A mounted point can
+ target a volume without a drive, it is not certain that
+ all IO functions we use in php and its deps support
+ path with volume GUID instead of the DOS way, like:
+ d:\test\mnt\foo
+ \\?\Volume{62d1c3f8-83b9-11de-b108-806e6f6e6963}\foo
+ */
+ if (strncmp(substitutename, "\\??\\Volume{",11) == 0
+ || strncmp(substitutename, "\\\\?\\Volume{",11) == 0) {
+ isVolume = TRUE;
+ substitutename_off = 0;
+ } else
+ /* do not use the \??\ and \\?\ prefix*/
+ if (strncmp(substitutename, "\\??\\", 4) == 0
+ || strncmp(substitutename, "\\\\?\\", 4) == 0) {
+ substitutename_off = 4;
+ }
}
- *(path + bufindex) = 0;
+ if (!isVolume) {
+ char * tmp = substitutename + substitutename_off;
+ for(bufindex = 0; bufindex < (substitutename_len - substitutename_off); bufindex++) {
+ *(path + bufindex) = *(tmp + bufindex);
+ }
+
+ *(path + bufindex) = 0;
+ j = bufindex;
+ } else {
+ j = len;
+ }
+
+
+#if VIRTUAL_CWD_DEBUG
+ fprintf(stderr, "reparse: print: %s ", printname);
+ fprintf(stderr, "sub: %s ", substitutename);
+ fprintf(stderr, "resolved: %s ", path);
+#endif
tsrm_free_alloca(pbuffer, use_heap_large);
- j = bufindex;
if(isabsolute == 1) {
- /* use_realpath is 0 in the call below coz path is absolute*/
- j = tsrm_realpath_r(path, 0, j, ll, t, 0, is_dir, &directory TSRMLS_CC);
- if(j < 0) {
- tsrm_free_alloca(tmp, use_heap);
- return -1;
+ if (!((j == 3) && (path[1] == ':') && (path[2] == '\\'))) {
+ /* use_realpath is 0 in the call below coz path is absolute*/
+ j = tsrm_realpath_r(path, 0, j, ll, t, 0, is_dir, &directory TSRMLS_CC);
+ if(j < 0) {
+ tsrm_free_alloca(tmp, use_heap);
+ return -1;
+ }
}
}
else {
@@ -741,6 +853,7 @@ static int tsrm_realpath_r(char *path, int start, int len, int *ll, time_t *t, i
return -1;
}
}
+ directory = (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
if(link_is_dir) {
*link_is_dir = directory;
@@ -1195,7 +1308,7 @@ static void UnixTimeToFileTime(time_t t, LPFILETIME pft) /* {{{ */
}
/* }}} */
-static int win32_utime(const char *filename, struct utimbuf *buf) /* {{{ */
+TSRM_API int win32_utime(const char *filename, struct utimbuf *buf) /* {{{ */
{
FILETIME mtime, atime;
HANDLE hFile;
@@ -1371,7 +1484,7 @@ CWD_API int virtual_rename(char *oldname, char *newname TSRMLS_DC) /* {{{ */
/* rename on windows will fail if newname already exists.
MoveFileEx has to be used */
#ifdef TSRM_WIN32
- retval = (MoveFileEx(oldname, newname, MOVEFILE_REPLACE_EXISTING) == 0) ? -1 : 0;
+ retval = (MoveFileEx(oldname, newname, MOVEFILE_REPLACE_EXISTING|MOVEFILE_COPY_ALLOWED) == 0) ? -1 : 0;
#else
retval = rename(oldname, newname);
#endif
diff --git a/TSRM/tsrm_virtual_cwd.h b/TSRM/tsrm_virtual_cwd.h
index 65225f37b..7f612bfec 100644
--- a/TSRM/tsrm_virtual_cwd.h
+++ b/TSRM/tsrm_virtual_cwd.h
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: tsrm_virtual_cwd.h,v 1.48.2.5.2.8.2.7 2009/06/16 00:07:04 pajoye Exp $ */
+/* $Id: tsrm_virtual_cwd.h 287673 2009-08-25 09:16:53Z pajoye $ */
#ifndef VIRTUAL_CWD_H
#define VIRTUAL_CWD_H
@@ -288,7 +288,7 @@ CWD_API realpath_cache_bucket* realpath_cache_lookup(const char *path, int path_
/* rename on windows will fail if newname already exists.
MoveFileEx has to be used */
#if defined(TSRM_WIN32)
-# define VCWD_RENAME(oldname, newname) (MoveFileEx(oldname, newname, MOVEFILE_REPLACE_EXISTING) == 0 ? -1 : 0)
+# define VCWD_RENAME(oldname, newname) (MoveFileEx(oldname, newname, MOVEFILE_REPLACE_EXISTING|MOVEFILE_COPY_ALLOWED) == 0 ? -1 : 0)
#else
# define VCWD_RENAME(oldname, newname) rename(oldname, newname)
#endif
@@ -311,8 +311,13 @@ CWD_API realpath_cache_bucket* realpath_cache_lookup(const char *path, int path_
#define VCWD_REALPATH(path, real_path) tsrm_realpath(path, real_path TSRMLS_CC)
#if HAVE_UTIME
-#define VCWD_UTIME(path, time) utime(path, time)
+# ifdef TSRM_WIN32
+# define VCWD_UTIME(path, time) win32_utime(path, time)
+# else
+# define VCWD_UTIME(path, time) utime(path, time)
+# endif
#endif
+
#define VCWD_CHMOD(path, mode) chmod(path, mode)
#if !defined(TSRM_WIN32) && !defined(NETWARE)
#define VCWD_CHOWN(path, owner, group) chown(path, owner, group)
diff --git a/TSRM/tsrm_win32.c b/TSRM/tsrm_win32.c
index 7c47fa336..b224d4b10 100644
--- a/TSRM/tsrm_win32.c
+++ b/TSRM/tsrm_win32.c
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: tsrm_win32.c,v 1.27.2.1.2.7.2.11 2009/06/16 00:07:04 pajoye Exp $ */
+/* $Id: tsrm_win32.c 290166 2009-11-03 10:48:12Z pajoye $ */
#include <stdio.h>
#include <fcntl.h>
@@ -30,7 +30,7 @@
#include "TSRM.h"
#ifdef TSRM_WIN32
-
+#include <Sddl.h>
#include "tsrm_win32.h"
#include "tsrm_virtual_cwd.h"
@@ -42,25 +42,21 @@ static tsrm_win32_globals win32_globals;
static void tsrm_win32_ctor(tsrm_win32_globals *globals TSRMLS_DC)
{
- HANDLE process_token = NULL;
-
globals->process = NULL;
globals->shm = NULL;
globals->process_size = 0;
globals->shm_size = 0;
globals->comspec = _strdup((GetVersion()<0x80000000)?"cmd.exe":"command.com");
- globals->impersonation_token = NULL;
-
- /* Access check requires impersonation token. Create a duplicate token. */
- if(OpenProcessToken(GetCurrentProcess(), TOKEN_DUPLICATE | TOKEN_QUERY, &process_token)) {
- DuplicateToken(process_token, SecurityImpersonation, &globals->impersonation_token);
- }
- /* impersonation_token will be closed when the process dies */
- if(process_token != NULL) {
- CloseHandle(process_token);
- process_token = NULL;
- }
+ /* Set it to INVALID_HANDLE_VALUE
+ * It will be initialized correctly in tsrm_win32_access or set to
+ * NULL if no impersonation has been done.
+ * the impersonated token can't be set here as the impersonation
+ * will happen later, in fcgi_accept_request (or whatever is the
+ * SAPI being used).
+ */
+ globals->impersonation_token = INVALID_HANDLE_VALUE;
+ globals->impersonation_token_sid = NULL;
}
static void tsrm_win32_dtor(tsrm_win32_globals *globals TSRMLS_DC)
@@ -83,9 +79,12 @@ static void tsrm_win32_dtor(tsrm_win32_globals *globals TSRMLS_DC)
free(globals->comspec);
- if(globals->impersonation_token) {
+ if (globals->impersonation_token && globals->impersonation_token != INVALID_HANDLE_VALUE ) {
CloseHandle(globals->impersonation_token);
}
+ if (globals->impersonation_token_sid) {
+ free(globals->impersonation_token_sid);
+ }
}
TSRM_API void tsrm_win32_startup(void)
@@ -104,8 +103,97 @@ TSRM_API void tsrm_win32_shutdown(void)
#endif
}
+char * tsrm_win32_get_path_sid_key(const char *pathname TSRMLS_DC)
+{
+ PSID pSid = TWG(impersonation_token_sid);
+ DWORD sid_len = pSid ? GetLengthSid(pSid) : 0;
+ TCHAR *ptcSid = NULL;
+ char *bucket_key = NULL;
+
+ if (!pSid) {
+ bucket_key = (char *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, strlen(pathname) + 1);
+ if (!bucket_key) {
+ return NULL;
+ }
+ memcpy(bucket_key, pathname, strlen(pathname));
+ return bucket_key;
+ }
+
+ if (!ConvertSidToStringSid(pSid, &ptcSid)) {
+ return NULL;
+ }
+
+ bucket_key = (char *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, strlen(pathname) + strlen(ptcSid) + 1);
+ if (!bucket_key) {
+ LocalFree(ptcSid);
+ return NULL;
+ }
+
+ memcpy(bucket_key, ptcSid, strlen(ptcSid));
+ memcpy(bucket_key + strlen(ptcSid), pathname, strlen(pathname) + 1);
+
+ LocalFree(ptcSid);
+ return bucket_key;
+}
+
+
+PSID tsrm_win32_get_token_sid(HANDLE hToken)
+{
+ BOOL bSuccess = FALSE;
+ DWORD dwLength = 0;
+ PTOKEN_USER pTokenUser = NULL;
+ PSID sid;
+ PSID *ppsid = &sid;
+ DWORD sid_len;
+ PSID pResultSid = NULL;
+
+ /* Get the actual size of the TokenUser structure */
+ if (!GetTokenInformation(
+ hToken, TokenUser, (LPVOID) pTokenUser, 0, &dwLength)) {
+ if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
+ goto Finished;
+ }
+
+ pTokenUser = (PTOKEN_USER)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwLength);
+ if (pTokenUser == NULL) {
+ goto Finished;
+ }
+ }
+
+ /* and fetch it now */
+ if (!GetTokenInformation(
+ hToken, TokenUser, (LPVOID) pTokenUser, dwLength, &dwLength)) {
+ goto Finished;
+ }
+
+ sid_len = GetLengthSid(pTokenUser->User.Sid);
+
+ /* ConvertSidToStringSid(pTokenUser->User.Sid, &ptcSidOwner); */
+ pResultSid = malloc(sid_len);
+ if (!pResultSid) {
+ goto Finished;
+ }
+ if (!CopySid(sid_len, pResultSid, pTokenUser->User.Sid)) {
+ goto Finished;
+ }
+ return pResultSid;
+
+Finished:
+ if (pResultSid) {
+ free(pResultSid);
+ }
+ /* Free the buffer for the token groups. */
+ if (pTokenUser != NULL) {
+ HeapFree(GetProcessHeap(), 0, (LPVOID)pTokenUser);
+ }
+ return NULL;
+}
+
TSRM_API int tsrm_win32_access(const char *pathname, int mode)
{
+ time_t t;
+ HANDLE thread_token;
+ PSID token_sid;
SECURITY_INFORMATION sec_info = OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION;
GENERIC_MAPPING gen_map = { FILE_GENERIC_READ, FILE_GENERIC_WRITE, FILE_GENERIC_EXECUTE, FILE_ALL_ACCESS };
DWORD priv_set_length = sizeof(PRIVILEGE_SET);
@@ -114,11 +202,10 @@ TSRM_API int tsrm_win32_access(const char *pathname, int mode)
DWORD sec_desc_length = 0, desired_access = 0, granted_access = 0;
BYTE * psec_desc = NULL;
BOOL fAccess = FALSE;
- HANDLE process_token = NULL;
+ BOOL bucket_key_alloc = FALSE;
realpath_cache_bucket * bucket = NULL;
char * real_path = NULL;
- time_t t;
TSRMLS_FETCH();
@@ -126,10 +213,6 @@ TSRM_API int tsrm_win32_access(const char *pathname, int mode)
DWORD type;
return GetBinaryType(pathname, &type) ? 0 : -1;
} else {
- if(access(pathname, mode)) {
- return errno;
- }
-
if(!IS_ABSOLUTE_PATH(pathname, strlen(pathname)+1)) {
real_path = (char *)malloc(MAX_PATH);
if(tsrm_realpath(pathname, real_path TSRMLS_CC) == NULL) {
@@ -138,6 +221,58 @@ TSRM_API int tsrm_win32_access(const char *pathname, int mode)
pathname = real_path;
}
+ if(access(pathname, mode)) {
+ return errno;
+ }
+
+ /* If only existence check is made, return now */
+ if (mode == 0) {
+ 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)) {
+ DWORD err = GetLastError();
+ 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;
+ }
+
+ /* 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;
+ }
+ }
+
if (CWDG(realpath_cache_size_limit)) {
t = time(0);
bucket = realpath_cache_lookup(pathname, strlen(pathname), t TSRMLS_CC);
@@ -151,7 +286,7 @@ TSRM_API int tsrm_win32_access(const char *pathname, int mode)
}
}
}
-
+
/* Do a full access check because access() will only check read-only attribute */
if(mode == 0 || mode > 6) {
if(bucket != NULL && bucket->is_rvalid) {
@@ -164,13 +299,13 @@ TSRM_API int tsrm_win32_access(const char *pathname, int mode)
fAccess = bucket->is_writable;
goto Finished;
}
- desired_access = FILE_GENERIC_WRITE;
+ desired_access = FILE_GENERIC_READ | FILE_GENERIC_WRITE;
} else if(mode <= 4) {
if(bucket != NULL && bucket->is_rvalid) {
fAccess = bucket->is_readable;
goto Finished;
}
- desired_access = FILE_GENERIC_READ;
+ 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;
@@ -194,13 +329,15 @@ TSRM_API int tsrm_win32_access(const char *pathname, int mode)
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;
+ goto Finished_Impersonate;
}
/* Keep the result in realpath_cache */
if(bucket != NULL) {
- if(desired_access == FILE_GENERIC_READ) {
+ if(desired_access == (FILE_GENERIC_READ|FILE_FLAG_BACKUP_SEMANTICS)) {
bucket->is_rvalid = 1;
bucket->is_readable = fAccess;
}
@@ -210,12 +347,13 @@ TSRM_API int tsrm_win32_access(const char *pathname, int mode)
}
}
-Finished:
+Finished_Impersonate:
if(psec_desc != NULL) {
free(psec_desc);
psec_desc = NULL;
}
+Finished:
if(real_path != NULL) {
free(real_path);
real_path = NULL;
@@ -305,21 +443,45 @@ TSRM_API FILE *popen(const char *command, const char *type)
TSRM_API FILE *popen_ex(const char *command, const char *type, const char *cwd, char *env)
{
FILE *stream = NULL;
- int fno, str_len = strlen(type), read, mode;
+ int fno, type_len = strlen(type), read, mode;
STARTUPINFO startup;
PROCESS_INFORMATION process;
SECURITY_ATTRIBUTES security;
HANDLE in, out;
DWORD dwCreateFlags = 0;
- char *cmd;
+ BOOL res;
process_pair *proc;
+ char *cmd;
+ int i;
+ char *ptype = (char *)type;
+ HANDLE thread_token = NULL;
+ HANDLE token_user = NULL;
+ BOOL asuser = TRUE;
+
TSRMLS_FETCH();
+ if (!type) {
+ return NULL;
+ }
+
+ /*The following two checks can be removed once we drop XP support */
+ type_len = strlen(type);
+ if (type_len <1 || type_len > 2) {
+ return NULL;
+ }
+
+ for (i=0; i < type_len; i++) {
+ if (!(*ptype == 'r' || *ptype == 'w' || *ptype == 'b' || *ptype == 't')) {
+ return NULL;
+ }
+ ptype++;
+ }
+
security.nLength = sizeof(SECURITY_ATTRIBUTES);
security.bInheritHandle = TRUE;
security.lpSecurityDescriptor = NULL;
- if (!str_len || !CreatePipe(&in, &out, &security, 2048L)) {
+ if (!type_len || !CreatePipe(&in, &out, &security, 2048L)) {
return NULL;
}
@@ -331,7 +493,7 @@ TSRM_API FILE *popen_ex(const char *command, const char *type, const char *cwd,
startup.hStdError = GetStdHandle(STD_ERROR_HANDLE);
read = (type[0] == 'r') ? TRUE : FALSE;
- mode = ((str_len == 2) && (type[1] == 'b')) ? O_BINARY : O_TEXT;
+ mode = ((type_len == 2) && (type[1] == 'b')) ? O_BINARY : O_TEXT;
if (read) {
in = dupHandle(in, FALSE);
@@ -348,13 +510,31 @@ TSRM_API FILE *popen_ex(const char *command, const char *type, const char *cwd,
dwCreateFlags |= CREATE_NO_WINDOW;
}
+ /* Get a token with the impersonated user. */
+ if(OpenThreadToken(GetCurrentThread(), TOKEN_ALL_ACCESS, TRUE, &thread_token)) {
+ DuplicateTokenEx(thread_token, MAXIMUM_ALLOWED, &security, SecurityImpersonation, TokenPrimary, &token_user);
+ } else {
+ DWORD err = GetLastError();
+ if (err == ERROR_NO_TOKEN) {
+ asuser = FALSE;
+ }
+
+ }
+
cmd = (char*)malloc(strlen(command)+strlen(TWG(comspec))+sizeof(" /c ")+2);
sprintf(cmd, "%s /c \"%s\"", TWG(comspec), command);
- if (!CreateProcess(NULL, cmd, &security, &security, security.bInheritHandle, dwCreateFlags, env, cwd, &startup, &process)) {
- return NULL;
+ if (asuser) {
+ res = CreateProcessAsUser(token_user, NULL, cmd, &security, &security, security.bInheritHandle, dwCreateFlags, env, cwd, &startup, &process);
+ CloseHandle(token_user);
+ } else {
+ res = CreateProcess(NULL, cmd, &security, &security, security.bInheritHandle, dwCreateFlags, env, cwd, &startup, &process);
}
free(cmd);
+ if (!res) {
+ return NULL;
+ }
+
CloseHandle(process.hThread);
proc = process_get(NULL TSRMLS_CC);
diff --git a/TSRM/tsrm_win32.h b/TSRM/tsrm_win32.h
index 912fac653..7cd966918 100644
--- a/TSRM/tsrm_win32.h
+++ b/TSRM/tsrm_win32.h
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: tsrm_win32.h,v 1.19.2.1.2.1.2.3 2009/05/17 19:42:53 pajoye Exp $ */
+/* $Id: tsrm_win32.h 289780 2009-10-19 23:38:55Z pajoye $ */
#ifndef TSRM_WIN32_H
#define TSRM_WIN32_H
@@ -64,6 +64,7 @@ typedef struct {
int shm_size;
char *comspec;
HANDLE impersonation_token;
+ PSID impersonation_token_sid;
} tsrm_win32_globals;
#ifdef ZTS
@@ -89,6 +90,7 @@ typedef struct {
#define SHM_RND FILE_MAP_WRITE
#define SHM_REMAP FILE_MAP_COPY
+char * tsrm_win32_get_path_sid_key(const char *pathname TSRMLS_DC);
TSRM_API void tsrm_win32_startup(void);
TSRM_API void tsrm_win32_shutdown(void);
@@ -97,6 +99,7 @@ TSRM_API FILE *popen_ex(const char *command, const char *type, const char *cwd,
TSRM_API FILE *popen(const char *command, const char *type);
TSRM_API int pclose(FILE *stream);
TSRM_API int tsrm_win32_access(const char *pathname, int mode);
+TSRM_API int win32_utime(const char *filename, struct utimbuf *buf);
TSRM_API int shmget(int key, int size, int flags);
TSRM_API void *shmat(int key, const void *shmaddr, int flags);