Implements GetTempPath2A() and GetTempPath2W() functions without special functionality when a system process calls them.
-- v4: kernelbase: Implement GetTempPath2A() and GetTempPath2W().
From: Đorđe Mančićdjordjemancic@outlook.com
--- dlls/kernel32/kernel32.spec | 2 ++ dlls/kernelbase/file.c | 22 ++++++++++++++++++++++ dlls/kernelbase/kernelbase.spec | 2 ++ include/fileapi.h | 3 +++ 4 files changed, 29 insertions(+)
diff --git a/dlls/kernel32/kernel32.spec b/dlls/kernel32/kernel32.spec index 179d49ba7cb..49140fb8307 100644 --- a/dlls/kernel32/kernel32.spec +++ b/dlls/kernel32/kernel32.spec @@ -864,6 +864,8 @@ @ stdcall -import GetTempFileNameW(wstr wstr long ptr) @ stdcall -import GetTempPathA(long ptr) @ stdcall -import GetTempPathW(long ptr) +@ stdcall -import GetTempPath2A(long ptr) +@ stdcall -import GetTempPath2W(long ptr) @ stdcall -import GetThreadContext(long ptr) @ stdcall -import GetThreadDescription(long ptr) @ stdcall -import GetThreadErrorMode() diff --git a/dlls/kernelbase/file.c b/dlls/kernelbase/file.c index 623e283d6d9..1f13511fa7b 100644 --- a/dlls/kernelbase/file.c +++ b/dlls/kernelbase/file.c @@ -2476,6 +2476,28 @@ DWORD WINAPI DECLSPEC_HOTPATCH GetTempPathW( DWORD count, LPWSTR path ) }
+/*********************************************************************** + * GetTempPath2A (kernelbase.@) + */ +DWORD WINAPI DECLSPEC_HOTPATCH GetTempPath2A(DWORD count, LPSTR path) +{ + /* TODO: Set temp path to C:\Windows\SystemTemp\ when a SYSTEM process calls this function */ + FIXME("(%lu, %s) semi-stub\n", count, path); + return GetTempPathA(count, path); +} + + +/*********************************************************************** + * GetTempPath2W (kernelbase.@) + */ +DWORD WINAPI DECLSPEC_HOTPATCH GetTempPath2W(DWORD count, LPWSTR path) +{ + /* TODO: Set temp path to C:\Windows\SystemTemp\ when a SYSTEM process calls this function */ + FIXME("(%lu, %s) semi-stub\n", count, debugstr_w(path)); + return GetTempPathW(count, path); +} + + /*********************************************************************** * GetWindowsDirectoryA (kernelbase.@) */ diff --git a/dlls/kernelbase/kernelbase.spec b/dlls/kernelbase/kernelbase.spec index a133380a27a..9504b07754a 100644 --- a/dlls/kernelbase/kernelbase.spec +++ b/dlls/kernelbase/kernelbase.spec @@ -741,6 +741,8 @@ @ stdcall GetTempFileNameW(wstr wstr long ptr) @ stdcall GetTempPathA(long ptr) @ stdcall GetTempPathW(long ptr) +@ stdcall GetTempPath2W(long ptr) +@ stdcall GetTempPath2A(long ptr) @ stdcall GetThreadContext(long ptr) @ stdcall GetThreadDescription(long ptr) @ stdcall GetThreadErrorMode() diff --git a/include/fileapi.h b/include/fileapi.h index 02bbbd4d920..2080fbbac21 100644 --- a/include/fileapi.h +++ b/include/fileapi.h @@ -34,6 +34,9 @@ typedef struct _CREATEFILE2_EXTENDED_PARAMETERS {
WINBASEAPI HANDLE WINAPI CreateFile2(LPCWSTR,DWORD,DWORD,DWORD,LPCREATEFILE2_EXTENDED_PARAMETERS);
+WINBASEAPI DWORD WINAPI GetTempPath2A(DWORD,LPSTR); +WINBASEAPI DWORD WINAPI GetTempPath2W(DWORD,LPWSTR); + #ifdef __cplusplus } #endif
Sorry for multiple updates, I've updated the merge request to contain the FIXMEs with the proper format for DWORDs.
Fabian Maurer (@DarkShadow44) commented about dlls/kernel32/kernel32.spec:
@ stdcall -import GetTempFileNameW(wstr wstr long ptr) @ stdcall -import GetTempPathA(long ptr) @ stdcall -import GetTempPathW(long ptr) +@ stdcall -import GetTempPath2A(long ptr) +@ stdcall -import GetTempPath2W(long ptr)
Nitpick: To be sorted it needs to be above GetTempPathA.
On Sun Jul 21 15:57:00 2024 +0000, Đorđe Mančić wrote:
Got it, I have updated the merge request to contain those FIXMEs. Although I haven't found any bugs already submitted on the Bugzilla, I've come across [this dotnet runtime issue](https://github.com/dotnet/runtime/issues/105012) which describes that dotnet has switched from using GetTempPath to GetTempPath2 for security reasons, and the MSDN page for GetTempPath recommends using GetTempPath2 instead.
According to the code GetTempPath2 is optional: [pal.windows.cpp](https://github.com/dotnet/runtime/blob/18b2ef18fd58146cc1c50acd8bfcd85a3a663...), [Path.Windows.c](https://github.com/dotnet/runtime/blob/18b2ef18fd58146cc1c50acd8bfcd85a3a663...)
Not that it would hurt having it, of course.