From c0fa34f162c334c7749992fff09f0a1db5ab4c9a Mon Sep 17 00:00:00 2001 From: Alex Ionescu Date: Tue, 29 Nov 2011 15:04:31 +0000 Subject: [PATCH] [KERNEL32]: Write out the 3 internal APIs which will do path resolution, and define the structures that determine the search path order which each one will use. No functional change. svn path=/trunk/; revision=54536 --- reactos/dll/win32/kernel32/client/path.c | 129 ++++++++++++++++-- reactos/dll/win32/kernel32/include/kernel32.h | 18 +++ reactos/include/psdk/winbase.h | 6 + 3 files changed, 145 insertions(+), 8 deletions(-) diff --git a/reactos/dll/win32/kernel32/client/path.c b/reactos/dll/win32/kernel32/client/path.c index 3bc45dd574d..bd0c0370b76 100644 --- a/reactos/dll/win32/kernel32/client/path.c +++ b/reactos/dll/win32/kernel32/client/path.c @@ -33,8 +33,121 @@ DWORD IllegalMask[4] = 0x10000000 // 7C not allowed }; +BASE_SEARCH_PATH_TYPE BaseDllOrderCurrent[BaseCurrentDirMax][BaseSearchPathMax] = +{ + { + BaseSearchPathApp, + BaseSearchPathCurrent, + BaseSearchPathDefault, + BaseSearchPathEnv, + BaseSearchPathInvalid + }, + { + BaseSearchPathApp, + BaseSearchPathDefault, + BaseSearchPathCurrent, + BaseSearchPathEnv, + BaseSearchPathInvalid + } +}; + +BASE_SEARCH_PATH_TYPE BaseProcessOrderNoCurrent[BaseSearchPathMax] = +{ + BaseSearchPathApp, + BaseSearchPathDefault, + BaseSearchPathEnv, + BaseSearchPathInvalid, + BaseSearchPathInvalid +}; + +BASE_SEARCH_PATH_TYPE BaseDllOrderNoCurrent[BaseSearchPathMax] = +{ + BaseSearchPathApp, + BaseSearchPathDll, + BaseSearchPathDefault, + BaseSearchPathEnv, + BaseSearchPathInvalid +}; + +BASE_SEARCH_PATH_TYPE BaseProcessOrder[BaseSearchPathMax] = +{ + BaseSearchPathApp, + BaseSearchPathCurrent, + BaseSearchPathDefault, + BaseSearchPathEnv, + BaseSearchPathInvalid +}; + /* PRIVATE FUNCTIONS **********************************************************/ +LPWSTR +WINAPI +BasepComputeProcessPath(IN PBASE_SEARCH_PATH_TYPE PathOrder, + IN LPWSTR AppName, + IN LPVOID Environment) +{ + return NULL; +} + +LPWSTR +WINAPI +BaseComputeProcessSearchPath(VOID) +{ + DPRINT1("Computing Process Search path\n"); + + /* Compute the path using default process order */ + return BasepComputeProcessPath(BaseProcessOrder, NULL, NULL); +} + +LPWSTR +WINAPI +BaseComputeProcessExePath(IN LPWSTR FullPath) +{ + PBASE_SEARCH_PATH_TYPE PathOrder; + DPRINT1("Computing EXE path: %wZ\n", FullPath); + + /* Check if we should use the current directory */ + PathOrder = NeedCurrentDirectoryForExePathW(FullPath) ? + BaseProcessOrder : BaseProcessOrderNoCurrent; + + /* And now compute the path */ + return BasepComputeProcessPath(PathOrder, NULL, NULL); +} + +LPWSTR +WINAPI +BaseComputeProcessDllPath(IN LPWSTR FullPath, + IN PVOID Environment) +{ + LPWSTR DllPath = NULL; + DPRINT1("Computing DLL path: %wZ with BaseDll: %wZ\n", FullPath, &BaseDllDirectory); + + /* Acquire DLL directory lock */ + RtlEnterCriticalSection(&BaseDllDirectoryLock); + + /* Check if we have a base dll directory */ + if (BaseDllDirectory.Buffer) + { + /* Then compute the process path using DLL order (without curdir) */ + DllPath = BasepComputeProcessPath(BaseDllOrderNoCurrent, FullPath, Environment); + + /* Release DLL directory lock */ + RtlLeaveCriticalSection(&BaseDllDirectoryLock); + + /* Return dll path */ + return DllPath; + } + + /* Release DLL directory lock */ + RtlLeaveCriticalSection(&BaseDllDirectoryLock); + + /* There is no base DLL directory */ + UNIMPLEMENTED; + + /* Return dll path */ + return DllPath; +} + BOOLEAN WINAPI CheckForSameCurdir(IN PUNICODE_STRING DirName) @@ -45,7 +158,7 @@ CheckForSameCurdir(IN PUNICODE_STRING DirName) UNICODE_STRING CurDirCopy; CurDir = &NtCurrentPeb()->ProcessParameters->CurrentDirectory.DosPath; - + CurLength = CurDir->Length; if (CurDir->Length <= 6) { @@ -55,12 +168,12 @@ CheckForSameCurdir(IN PUNICODE_STRING DirName) { if ((CurLength - 2) != DirName->Length) return FALSE; } - + RtlAcquirePebLock(); CurDirCopy = *CurDir; if (CurDirCopy.Length > 6) CurDirCopy.Length -= 2; - + Result = 0; if (RtlEqualUnicodeString(&CurDirCopy, DirName, TRUE)) Result = TRUE; @@ -1672,21 +1785,21 @@ SetCurrentDirectoryA(IN LPCSTR lpPathName) BaseSetLastNTError(STATUS_INVALID_PARAMETER); return FALSE; } - + DirName = Basep8BitStringToStaticUnicodeString(lpPathName); if (!DirName) return FALSE; - + if (CheckForSameCurdir(DirName)) return FALSE; - + Status = RtlSetCurrentDirectory_U(DirName); if (NT_SUCCESS(Status)) return TRUE; - + if ((*DirName->Buffer != L'"') || (DirName->Length <= 2)) { BaseSetLastNTError(Status); return 0; } - + DirName = Basep8BitStringToStaticUnicodeString(lpPathName + 1); if (!DirName) return FALSE; diff --git a/reactos/dll/win32/kernel32/include/kernel32.h b/reactos/dll/win32/kernel32/include/kernel32.h index e88d5b2f892..314c51116bb 100644 --- a/reactos/dll/win32/kernel32/include/kernel32.h +++ b/reactos/dll/win32/kernel32/include/kernel32.h @@ -88,6 +88,24 @@ typedef struct tagLOADPARMS32 { DWORD dwReserved; } LOADPARMS32; +typedef enum _BASE_CURRENT_DIR_PRIORITY +{ + BaseCurrentDirInvalid = -1, + BaseCurrentDirFirst, + BaseCurrentDirLast, + BaseCurrentDirMax +} BASE_CURRENT_DIR_PRIORITY; + +typedef enum _BASE_SEARCH_PATH_TYPE +{ + BaseSearchPathInvalid, + BaseSearchPathDll, + BaseSearchPathApp, + BaseSearchPathDefault, + BaseSearchPathEnv, + BaseSearchPathCurrent, + BaseSearchPathMax +} BASE_SEARCH_PATH_TYPE, *PBASE_SEARCH_PATH_TYPE; #define BASEP_GET_MODULE_HANDLE_EX_PARAMETER_VALIDATION_ERROR 1 #define BASEP_GET_MODULE_HANDLE_EX_PARAMETER_VALIDATION_SUCCESS 2 diff --git a/reactos/include/psdk/winbase.h b/reactos/include/psdk/winbase.h index 0fc8b930f9e..48c78983967 100644 --- a/reactos/include/psdk/winbase.h +++ b/reactos/include/psdk/winbase.h @@ -1626,6 +1626,12 @@ HMODULE WINAPI GetModuleHandleW(LPCWSTR); BOOL WINAPI GetModuleHandleExA(DWORD,LPCSTR,HMODULE*); BOOL WINAPI GetModuleHandleExW(DWORD,LPCWSTR,HMODULE*); #endif + +#if _WIN32_WINNT >= 0x0502 +WINBASEAPI WINBOOL WINAPI NeedCurrentDirectoryForExePathA(LPCSTR ExeName); +WINBASEAPI WINBOOL WINAPI NeedCurrentDirectoryForExePathW(LPCWSTR ExeName); +#endif + BOOL WINAPI GetNamedPipeHandleStateA(HANDLE,PDWORD,PDWORD,PDWORD,PDWORD,LPSTR,DWORD); BOOL WINAPI GetNamedPipeHandleStateW(HANDLE,PDWORD,PDWORD,PDWORD,PDWORD,LPWSTR,DWORD); BOOL WINAPI GetNamedPipeInfo(HANDLE,PDWORD,PDWORD,PDWORD,PDWORD);