Alexandre Julliard : kernel32: Use RtlGetSearchPath() in SearchPathW() implementation.

Alexandre Julliard julliard at winehq.org
Tue Oct 1 15:50:30 CDT 2019


Module: wine
Branch: master
Commit: 6113c468568e20c9e1c66f93791560c7e85193b7
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=6113c468568e20c9e1c66f93791560c7e85193b7

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Tue Oct  1 09:35:59 2019 +0200

kernel32: Use RtlGetSearchPath() in SearchPathW() implementation.

Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/kernel32/path.c | 93 ++++------------------------------------------------
 1 file changed, 6 insertions(+), 87 deletions(-)

diff --git a/dlls/kernel32/path.c b/dlls/kernel32/path.c
index d5736a2d81..b580e36756 100644
--- a/dlls/kernel32/path.c
+++ b/dlls/kernel32/path.c
@@ -43,8 +43,6 @@ WINE_DEFAULT_DEBUG_CHANNEL(file);
 
 #define MAX_PATHNAME_LEN        1024
 
-static int path_safe_mode = -1;  /* path mode set by SetSearchPathMode */
-
 /* check if a file name is for an executable file (.exe or .com) */
 static inline BOOL is_executable( const WCHAR *name )
 {
@@ -256,51 +254,6 @@ DWORD WINAPI GetShortPathNameA( LPCSTR longpath, LPSTR shortpath, DWORD shortlen
     return copy_filename_WtoA( shortpathW, shortpath, shortlen );
 }
 
-/***********************************************************************
- *           get_path_safe_mode
- */
-static BOOL get_path_safe_mode(void)
-{
-    static const WCHAR keyW[] = {'\\','R','e','g','i','s','t','r','y','\\',
-                                 'M','a','c','h','i','n','e','\\',
-                                 'S','y','s','t','e','m','\\',
-                                 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
-                                 'C','o','n','t','r','o','l','\\',
-                                 'S','e','s','s','i','o','n',' ','M','a','n','a','g','e','r',0};
-    static const WCHAR valueW[] = {'S','a','f','e','P','r','o','c','e','s','s','S','e','a','r','c','h','M','o','d','e',0};
-
-    if (path_safe_mode == -1)
-    {
-        char buffer[offsetof(KEY_VALUE_PARTIAL_INFORMATION, Data[sizeof(DWORD)])];
-        KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)buffer;
-        OBJECT_ATTRIBUTES attr;
-        UNICODE_STRING nameW;
-        HANDLE hkey;
-        DWORD size = sizeof(buffer);
-        BOOL mode = FALSE;
-
-        attr.Length = sizeof(attr);
-        attr.RootDirectory = 0;
-        attr.ObjectName = &nameW;
-        attr.Attributes = 0;
-        attr.SecurityDescriptor = NULL;
-        attr.SecurityQualityOfService = NULL;
-
-        RtlInitUnicodeString( &nameW, keyW );
-        if (!NtOpenKey( &hkey, KEY_READ, &attr ))
-        {
-            RtlInitUnicodeString( &nameW, valueW );
-            if (!NtQueryValueKey( hkey, &nameW, KeyValuePartialInformation, buffer, size, &size ) &&
-                info->Type == REG_DWORD && info->DataLength == sizeof(DWORD))
-                mode = !!*(DWORD *)info->Data;
-            NtClose( hkey );
-        }
-        InterlockedCompareExchange( &path_safe_mode, mode, -1 );
-    }
-    return path_safe_mode != 0;
-}
-
-
 /***********************************************************************
  *           contains_pathW
  *
@@ -536,23 +489,14 @@ DWORD WINAPI SearchPathW( LPCWSTR path, LPCWSTR name, LPCWSTR ext, DWORD buflen,
                 ret = req_len + 1;
 
             HeapFree( GetProcessHeap(), 0, dll_path );
-            HeapFree( GetProcessHeap(), 0, search );
         }
-        else
+        else if (!RtlGetSearchPath( &dll_path ))
         {
-            if ((dll_path = MODULE_get_dll_load_path( NULL, get_path_safe_mode() )))
-            {
-                ret = RtlDosSearchPath_U( dll_path, name, NULL, buflen * sizeof(WCHAR),
-                                          buffer, lastpart ) / sizeof(WCHAR);
-                HeapFree( GetProcessHeap(), 0, dll_path );
-                HeapFree( GetProcessHeap(), 0, search );
-            }
-            else
-            {
-                SetLastError( ERROR_OUTOFMEMORY );
-                return 0;
-            }
+            ret = RtlDosSearchPath_U( dll_path, name, NULL, buflen * sizeof(WCHAR),
+                                      buffer, lastpart ) / sizeof(WCHAR);
+            RtlReleasePath( dll_path );
         }
+        HeapFree( GetProcessHeap(), 0, search );
     }
 
     if (!ret) SetLastError( ERROR_FILE_NOT_FOUND );
@@ -1393,30 +1337,5 @@ BOOL WINAPI CheckNameLegalDOS8Dot3W(const WCHAR *name, char *oemname, DWORD oemn
  */
 BOOL WINAPI SetSearchPathMode( DWORD flags )
 {
-    int val;
-
-    switch (flags)
-    {
-    case BASE_SEARCH_PATH_ENABLE_SAFE_SEARCHMODE:
-        val = 1;
-        break;
-    case BASE_SEARCH_PATH_DISABLE_SAFE_SEARCHMODE:
-        val = 0;
-        break;
-    case BASE_SEARCH_PATH_ENABLE_SAFE_SEARCHMODE | BASE_SEARCH_PATH_PERMANENT:
-        InterlockedExchange( &path_safe_mode, 2 );
-        return TRUE;
-    default:
-        SetLastError( ERROR_INVALID_PARAMETER );
-        return FALSE;
-    }
-
-    for (;;)
-    {
-        int prev = path_safe_mode;
-        if (prev == 2) break;  /* permanently set */
-        if (InterlockedCompareExchange( &path_safe_mode, val, prev ) == prev) return TRUE;
-    }
-    SetLastError( ERROR_ACCESS_DENIED );
-    return FALSE;
+    return set_ntstatus( RtlSetSearchPathMode( flags ));
 }




More information about the wine-cvs mailing list