@@ -109,31 +109,35 @@ TSRM_API void tsrm_win32_shutdown(void)
109109char * tsrm_win32_get_path_sid_key (const char * pathname TSRMLS_DC )
110110{
111111 PSID pSid = TWG (impersonation_token_sid );
112- DWORD sid_len = pSid ? GetLengthSid (pSid ) : 0 ;
113112 TCHAR * ptcSid = NULL ;
114113 char * bucket_key = NULL ;
114+ size_t ptc_sid_len , pathname_len ;
115+
116+ pathname_len = strlen (pathname );
115117
116118 if (!pSid ) {
117- bucket_key = (char * )HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY , strlen ( pathname ) + 1 );
119+ bucket_key = (char * )HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY , pathname_len + 1 );
118120 if (!bucket_key ) {
119121 return NULL ;
120122 }
121- memcpy (bucket_key , pathname , strlen ( pathname ) );
123+ memcpy (bucket_key , pathname , pathname_len );
122124 return bucket_key ;
123125 }
124126
125127 if (!ConvertSidToStringSid (pSid , & ptcSid )) {
126128 return NULL ;
127129 }
128130
129- bucket_key = (char * )HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY , strlen (pathname ) + strlen (ptcSid ) + 1 );
131+
132+ ptc_sid_len = strlen (ptcSid );
133+ bucket_key = (char * )HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY , pathname_len + ptc_sid_len + 1 );
130134 if (!bucket_key ) {
131135 LocalFree (ptcSid );
132136 return NULL ;
133137 }
134138
135- memcpy (bucket_key , ptcSid , strlen ( ptcSid ) );
136- memcpy (bucket_key + strlen ( ptcSid ) , pathname , strlen ( pathname ) + 1 );
139+ memcpy (bucket_key , ptcSid , ptc_sid_len );
140+ memcpy (bucket_key + ptc_sid_len , pathname , pathname_len + 1 );
137141
138142 LocalFree (ptcSid );
139143 return bucket_key ;
@@ -142,11 +146,8 @@ char * tsrm_win32_get_path_sid_key(const char *pathname TSRMLS_DC)
142146
143147PSID tsrm_win32_get_token_sid (HANDLE hToken )
144148{
145- BOOL bSuccess = FALSE;
146149 DWORD dwLength = 0 ;
147150 PTOKEN_USER pTokenUser = NULL ;
148- PSID sid ;
149- PSID * ppsid = & sid ;
150151 DWORD sid_len ;
151152 PSID pResultSid = NULL ;
152153
@@ -207,7 +208,6 @@ TSRM_API int tsrm_win32_access(const char *pathname, int mode TSRMLS_DC)
207208 BYTE * psec_desc = NULL ;
208209 BOOL fAccess = FALSE;
209210
210- BOOL bucket_key_alloc = FALSE;
211211 realpath_cache_bucket * bucket = NULL ;
212212 char * real_path = NULL ;
213213
@@ -245,7 +245,6 @@ TSRM_API int tsrm_win32_access(const char *pathname, int mode TSRMLS_DC)
245245 was impersonating already, this function uses that impersonation context.
246246 */
247247 if (!OpenThreadToken (GetCurrentThread (), TOKEN_ALL_ACCESS , TRUE, & thread_token )) {
248- DWORD err = GetLastError ();
249248 if (GetLastError () == ERROR_NO_TOKEN ) {
250249 if (!OpenProcessToken (GetCurrentProcess (), TOKEN_ALL_ACCESS , & thread_token )) {
251250 TWG (impersonation_token ) = NULL ;
@@ -282,14 +281,14 @@ TSRM_API int tsrm_win32_access(const char *pathname, int mode TSRMLS_DC)
282281
283282 if (CWDG (realpath_cache_size_limit )) {
284283 t = time (0 );
285- bucket = realpath_cache_lookup (pathname , strlen (pathname ), t TSRMLS_CC );
284+ bucket = realpath_cache_lookup (pathname , ( int ) strlen (pathname ), t TSRMLS_CC );
286285 if (bucket == NULL && real_path == NULL ) {
287286 /* We used the pathname directly. Call tsrm_realpath */
288287 /* so that entry is created in realpath cache */
289288 real_path = (char * )malloc (MAX_PATH );
290289 if (tsrm_realpath (pathname , real_path TSRMLS_CC ) != NULL ) {
291290 pathname = real_path ;
292- bucket = realpath_cache_lookup (pathname , strlen (pathname ), t TSRMLS_CC );
291+ bucket = realpath_cache_lookup (pathname , ( int ) strlen (pathname ), t TSRMLS_CC );
293292 }
294293 }
295294 }
@@ -480,7 +479,7 @@ TSRM_API FILE *popen_ex(const char *command, const char *type, const char *cwd,
480479 }
481480
482481 /*The following two checks can be removed once we drop XP support */
483- type_len = strlen (type );
482+ type_len = ( int ) strlen (type );
484483 if (type_len < 1 || type_len > 2 ) {
485484 return NULL ;
486485 }
@@ -725,4 +724,52 @@ TSRM_API char *realpath(char *orig_path, char *buffer)
725724 return buffer ;
726725}
727726
727+ #if HAVE_UTIME
728+ static zend_always_inline void UnixTimeToFileTime (time_t t , LPFILETIME pft ) /* {{{ */
729+ {
730+ // Note that LONGLONG is a 64-bit value
731+ LONGLONG ll ;
732+
733+ ll = Int32x32To64 (t , 10000000 ) + 116444736000000000 ;
734+ pft -> dwLowDateTime = (DWORD )ll ;
735+ pft -> dwHighDateTime = ll >> 32 ;
736+ }
737+ /* }}} */
738+
739+ TSRM_API int win32_utime (const char * filename , struct utimbuf * buf ) /* {{{ */
740+ {
741+ FILETIME mtime , atime ;
742+ HANDLE hFile ;
743+
744+ hFile = CreateFile (filename , GENERIC_WRITE , FILE_SHARE_WRITE |FILE_SHARE_READ , NULL ,
745+ OPEN_ALWAYS , FILE_FLAG_BACKUP_SEMANTICS , NULL );
746+
747+ /* OPEN_ALWAYS mode sets the last error to ERROR_ALREADY_EXISTS but
748+ the CreateFile operation succeeds */
749+ if (GetLastError () == ERROR_ALREADY_EXISTS ) {
750+ SetLastError (0 );
751+ }
752+
753+ if ( hFile == INVALID_HANDLE_VALUE ) {
754+ return -1 ;
755+ }
756+
757+ if (!buf ) {
758+ SYSTEMTIME st ;
759+ GetSystemTime (& st );
760+ SystemTimeToFileTime (& st , & mtime );
761+ atime = mtime ;
762+ } else {
763+ UnixTimeToFileTime (buf -> modtime , & mtime );
764+ UnixTimeToFileTime (buf -> actime , & atime );
765+ }
766+ if (!SetFileTime (hFile , NULL , & atime , & mtime )) {
767+ CloseHandle (hFile );
768+ return -1 ;
769+ }
770+ CloseHandle (hFile );
771+ return 1 ;
772+ }
773+ /* }}} */
774+ #endif
728775#endif
0 commit comments