From 637e8bb8c2dfad177b3cb80a3a8364783459b25b Mon Sep 17 00:00:00 2001 From: Bill Zissimopoulos Date: Fri, 19 Aug 2022 17:43:55 +0100 Subject: [PATCH] build.version.props: MyFsctlRegisterPath, MyNpRegisterPath, MyEventLogRegisterPath --- build/VStudio/build.common.props | 4 ++-- build/VStudio/build.version.props | 32 +++++++++++++++++++++++++++++++ build/VStudio/winfsp_dll.vcxproj | 12 ++++++------ src/dll/eventlog.c | 6 ++++-- src/dll/fsctl.c | 13 +++++++++++-- src/dll/library.h | 5 +++++ src/dll/np.c | 32 +++++++++++++++++++++++++------ src/dll/util.c | 31 ++++++++++++++++++++++++++++++ 8 files changed, 117 insertions(+), 18 deletions(-) diff --git a/build/VStudio/build.common.props b/build/VStudio/build.common.props index 81f57a60..ba6c66af 100644 --- a/build/VStudio/build.common.props +++ b/build/VStudio/build.common.props @@ -3,10 +3,10 @@ - NTDDI_VERSION=0x06010000;_WIN32_WINNT=0x0601;MyProductName=$(MyProductName);MyProductFileName=$(MyProductFileName);MyDescription=$(MyDescription);MyCompanyName=$(MyCompanyName);MyCopyright=$(MyCopyright);MyProductVersion=$(MyProductVersion);MyProductStage=$(MyProductStage);MyVersion=$(MyVersion);MyVersionWithCommas=$(MyVersionWithCommas);MyFullVersion=$(MyFullVersion);MyFspFsctlDeviceClassGuid=$(MyFspFsctlDeviceClassGuid);MyFspFsvrtDeviceClassGuid=$(MyFspFsvrtDeviceClassGuid) + NTDDI_VERSION=0x06010000;_WIN32_WINNT=0x0601;MyProductName=$(MyProductName);MyProductFileName=$(MyProductFileName);MyDescription=$(MyDescription);MyCompanyName=$(MyCompanyName);MyCopyright=$(MyCopyright);MyProductVersion=$(MyProductVersion);MyProductStage=$(MyProductStage);MyVersion=$(MyVersion);MyVersionWithCommas=$(MyVersionWithCommas);MyFullVersion=$(MyFullVersion);MyFspFsctlDeviceClassGuid=$(MyFspFsctlDeviceClassGuid);MyFspFsvrtDeviceClassGuid=$(MyFspFsvrtDeviceClassGuid);MyFsctlRegisterPath=$(MyFsctlRegisterPath);MyNpRegisterPath=$(MyNpRegisterPath);MyEventLogRegisterPath=$(MyEventLogRegisterPath) - MyProductName=$(MyProductName);MyProductFileName=$(MyProductFileName);MyDescription=$(MyDescription);MyCompanyName=$(MyCompanyName);MyCopyright=$(MyCopyright);MyProductVersion=$(MyProductVersion);MyProductStage=$(MyProductStage);MyVersion=$(MyVersion);MyVersionWithCommas=$(MyVersionWithCommas);MyFullVersion=$(MyFullVersion);MyFspFsctlDeviceClassGuid=$(MyFspFsctlDeviceClassGuid);MyFspFsvrtDeviceClassGuid=$(MyFspFsvrtDeviceClassGuid) + MyProductName=$(MyProductName);MyProductFileName=$(MyProductFileName);MyDescription=$(MyDescription);MyCompanyName=$(MyCompanyName);MyCopyright=$(MyCopyright);MyProductVersion=$(MyProductVersion);MyProductStage=$(MyProductStage);MyVersion=$(MyVersion);MyVersionWithCommas=$(MyVersionWithCommas);MyFullVersion=$(MyFullVersion);MyFspFsctlDeviceClassGuid=$(MyFspFsctlDeviceClassGuid);MyFspFsvrtDeviceClassGuid=$(MyFspFsvrtDeviceClassGuid);MyFsctlRegisterPath=$(MyFsctlRegisterPath);MyNpRegisterPath=$(MyNpRegisterPath);MyEventLogRegisterPath=$(MyEventLogRegisterPath) diff --git a/build/VStudio/build.version.props b/build/VStudio/build.version.props index 50e54b65..c2e4ef24 100644 --- a/build/VStudio/build.version.props +++ b/build/VStudio/build.version.props @@ -40,5 +40,37 @@ { 0x6f9d25fa, 0x6dee, 0x4a9d, { 0x80, 0xf5, 0xe9, 0x8e, 0x14, 0xf3, 0x5e, 0x54 } } { 0xb48171c3, 0xdd50, 0x4852, { 0x83, 0xa3, 0x34, 0x4c, 0x50, 0xd9, 0x3b, 0x17 } } + + + "." + "." + "." \ No newline at end of file diff --git a/build/VStudio/winfsp_dll.vcxproj b/build/VStudio/winfsp_dll.vcxproj index 19bd2de1..27443e88 100644 --- a/build/VStudio/winfsp_dll.vcxproj +++ b/build/VStudio/winfsp_dll.vcxproj @@ -288,7 +288,7 @@ copy /b $(OutDir)fuse3-$(MyProductFileArch).pc + %(FullPath) $(OutDir)fuse3-$(My $(OutDir)$(TargetFileName).map false ..\..\src\dll\library.def - %(AdditionalDependencies);rpcrt4.lib;credui.lib;secur32.lib;version.lib;netapi32.lib;wldap32.lib + %(AdditionalDependencies);credui.lib;netapi32.lib;rpcrt4.lib;secur32.lib;shlwapi.lib;version.lib;wldap32.lib $(OutDir)$(TargetFileName).public.pdb @@ -315,7 +315,7 @@ copy /b $(OutDir)fuse3-$(MyProductFileArch).pc + %(FullPath) $(OutDir)fuse3-$(My $(OutDir)$(TargetFileName).map true ..\..\src\dll\library.def - %(AdditionalDependencies);rpcrt4.lib;credui.lib;secur32.lib;version.lib;netapi32.lib;wldap32.lib + %(AdditionalDependencies);credui.lib;netapi32.lib;rpcrt4.lib;secur32.lib;shlwapi.lib;version.lib;wldap32.lib $(OutDir)$(TargetFileName).public.pdb @@ -342,7 +342,7 @@ copy /b $(OutDir)fuse3-$(MyProductFileArch).pc + %(FullPath) $(OutDir)fuse3-$(My $(OutDir)$(TargetFileName).map true ..\..\src\dll\library.def - %(AdditionalDependencies);rpcrt4.lib;credui.lib;secur32.lib;version.lib;netapi32.lib;wldap32.lib + %(AdditionalDependencies);credui.lib;netapi32.lib;rpcrt4.lib;secur32.lib;shlwapi.lib;version.lib;wldap32.lib $(OutDir)$(TargetFileName).public.pdb @@ -372,7 +372,7 @@ copy /b $(OutDir)fuse3-$(MyProductFileArch).pc + %(FullPath) $(OutDir)fuse3-$(My $(OutDir)$(TargetFileName).map false ..\..\src\dll\library.def - %(AdditionalDependencies);rpcrt4.lib;credui.lib;secur32.lib;version.lib;netapi32.lib;wldap32.lib + %(AdditionalDependencies);credui.lib;netapi32.lib;rpcrt4.lib;secur32.lib;shlwapi.lib;version.lib;wldap32.lib $(OutDir)$(TargetFileName).public.pdb /PDBALTPATH:$(TargetFileName).pdb %(AdditionalOptions) @@ -403,7 +403,7 @@ copy /b $(OutDir)fuse3-$(MyProductFileArch).pc + %(FullPath) $(OutDir)fuse3-$(My $(OutDir)$(TargetFileName).map true ..\..\src\dll\library.def - %(AdditionalDependencies);rpcrt4.lib;credui.lib;secur32.lib;version.lib;netapi32.lib;wldap32.lib + %(AdditionalDependencies);credui.lib;netapi32.lib;rpcrt4.lib;secur32.lib;shlwapi.lib;version.lib;wldap32.lib $(OutDir)$(TargetFileName).public.pdb /PDBALTPATH:$(TargetFileName).pdb %(AdditionalOptions) @@ -434,7 +434,7 @@ copy /b $(OutDir)fuse3-$(MyProductFileArch).pc + %(FullPath) $(OutDir)fuse3-$(My $(OutDir)$(TargetFileName).map true ..\..\src\dll\library.def - %(AdditionalDependencies);rpcrt4.lib;credui.lib;secur32.lib;version.lib;netapi32.lib;wldap32.lib + %(AdditionalDependencies);credui.lib;netapi32.lib;rpcrt4.lib;secur32.lib;shlwapi.lib;version.lib;wldap32.lib $(OutDir)$(TargetFileName).public.pdb /PDBALTPATH:$(TargetFileName).pdb %(AdditionalOptions) diff --git a/src/dll/eventlog.c b/src/dll/eventlog.c index a4d00fe3..24ba7cef 100644 --- a/src/dll/eventlog.c +++ b/src/dll/eventlog.c @@ -100,9 +100,11 @@ NTSTATUS FspEventLogRegister(VOID) WCHAR Path[MAX_PATH]; DWORD RegResult, DwordValue; HKEY RegKey; + NTSTATUS Result; - if (0 == GetModuleFileNameW(DllInstance, Path, MAX_PATH)) - return FspNtStatusFromWin32(GetLastError()); + Result = FspGetModuleFileName(DllInstance, Path, MAX_PATH, L"" MyEventLogRegisterPath); + if (!NT_SUCCESS(Result)) + return Result; RegResult = RegCreateKeyExW( HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\" FSP_EVENTLOG_NAME, diff --git a/src/dll/fsctl.c b/src/dll/fsctl.c index 81dbf823..5a12aba5 100644 --- a/src/dll/fsctl.c +++ b/src/dll/fsctl.c @@ -584,8 +584,9 @@ NTSTATUS FspFsctlRegister(VOID) SERVICE_DESCRIPTION ServiceDescription; NTSTATUS Result; - if (0 == GetModuleFileNameW(DllInstance, DriverPath, MAX_PATH)) - return FspNtStatusFromWin32(GetLastError()); + Result = FspGetModuleFileName(DllInstance, DriverPath, MAX_PATH, L"" MyFsctlRegisterPath); + if (!NT_SUCCESS(Result)) + return Result; Size = lstrlenW(DriverPath); if (4 < Size && @@ -599,6 +600,14 @@ NTSTATUS FspFsctlRegister(VOID) DriverPath[Size - 2] = L'y'; DriverPath[Size - 1] = L's'; } + else if (4 < Size && + (L'.' == DriverPath[Size - 4]) && + (L'S' == DriverPath[Size - 3] || L's' == DriverPath[Size - 3]) && + (L'Y' == DriverPath[Size - 2] || L'y' == DriverPath[Size - 2]) && + (L'S' == DriverPath[Size - 1] || L's' == DriverPath[Size - 1]) && + (L'\0' == DriverPath[Size])) + { + } else /* should not happen! */ return STATUS_NO_SUCH_DEVICE; diff --git a/src/dll/library.h b/src/dll/library.h index fa982ab2..767dbaff 100644 --- a/src/dll/library.h +++ b/src/dll/library.h @@ -91,6 +91,11 @@ ULONG FspLdapGetTrustPosixOffset(PVOID Ldap, PWSTR Context, PWSTR Domain, PWSTR PWSTR FspDiagIdent(VOID); NTSTATUS FspGetModuleVersion(PWSTR ModuleFileName, PUINT32 PVersion); +NTSTATUS FspGetModuleFileName( + HMODULE Module, + PWSTR FileName, + ULONG Size, + PWSTR RelativePath); #define FspFileSystemDirectoryBufferEntryInvalid ((ULONG)-1) VOID FspFileSystemPeekInDirectoryBuffer(PVOID *PDirBuffer, diff --git a/src/dll/np.c b/src/dll/np.c index e7c2ad4c..fab6f9f1 100644 --- a/src/dll/np.c +++ b/src/dll/np.c @@ -1152,15 +1152,34 @@ DWORD APIENTRY NPCloseEnum(HANDLE hEnum) NTSTATUS FspNpRegister(VOID) { extern HINSTANCE DllInstance; - WCHAR ProviderPath[MAX_PATH]; + WCHAR DllPath[MAX_PATH], ProviderPath[MAX_PATH]; + PWSTR VersionInfoPath; + BOOLEAN HasPercent; WCHAR RegBuffer[1024]; PWSTR P, Part; DWORD RegResult, RegType, RegBufferSize, RegBufferOffset; HKEY RegKey; BOOLEAN FoundProvider; + NTSTATUS Result; - if (0 == GetModuleFileNameW(DllInstance, ProviderPath, MAX_PATH)) - return FspNtStatusFromWin32(GetLastError()); + VersionInfoPath = ProviderPath; + HasPercent = FALSE; + for (P = L"" MyNpRegisterPath; *P; P++) + if ('%' == *P) + { + HasPercent = TRUE; + break; + } + if (HasPercent) + { + VersionInfoPath = DllPath; + if (0 == GetModuleFileNameW(DllInstance, DllPath, MAX_PATH)) + return FspNtStatusFromWin32(GetLastError()); + } + + Result = FspGetModuleFileName(DllInstance, ProviderPath, MAX_PATH, L"" MyNpRegisterPath); + if (!NT_SUCCESS(Result)) + return Result; RegResult = RegCreateKeyExW( HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Services\\" FSP_NP_NAME, @@ -1187,12 +1206,12 @@ NTSTATUS FspNpRegister(VOID) DWORD Size; PWSTR Description; - Size = GetFileVersionInfoSizeW(ProviderPath, &Size/*dummy*/); + Size = GetFileVersionInfoSizeW(VersionInfoPath, &Size/*dummy*/); if (0 < Size) { VersionInfo = MemAlloc(Size); if (0 != VersionInfo && - GetFileVersionInfoW(ProviderPath, 0, Size, VersionInfo) && + GetFileVersionInfoW(VersionInfoPath, 0, Size, VersionInfo) && VerQueryValueW(VersionInfo, L"\\StringFileInfo\\040904b0\\FileDescription", &Description, &Size)) { @@ -1208,7 +1227,8 @@ NTSTATUS FspNpRegister(VOID) goto close_and_exit; RegResult = RegSetValueExW(RegKey, - L"ProviderPath", 0, REG_SZ, (PVOID)ProviderPath, (lstrlenW(ProviderPath) + 1) * sizeof(WCHAR)); + L"ProviderPath", 0, HasPercent ? REG_EXPAND_SZ : REG_SZ, + (PVOID)ProviderPath, (lstrlenW(ProviderPath) + 1) * sizeof(WCHAR)); if (ERROR_SUCCESS != RegResult) goto close_and_exit; diff --git a/src/dll/util.c b/src/dll/util.c index b08ce50e..00da6b08 100644 --- a/src/dll/util.c +++ b/src/dll/util.c @@ -21,6 +21,7 @@ #include #include +#include static INIT_ONCE FspDiagIdentInitOnce = INIT_ONCE_STATIC_INIT; static WCHAR FspDiagIdentBuf[20] = L"UNKNOWN"; @@ -248,3 +249,33 @@ NTSTATUS FspGetModuleVersion(PWSTR ModuleFileName, PUINT32 PVersion) return STATUS_SUCCESS; } + +NTSTATUS FspGetModuleFileName( + HMODULE Module, + PWSTR FileName, + ULONG Size, + PWSTR RelativePath) +{ + if (MAX_PATH > Size) + return STATUS_BUFFER_TOO_SMALL; + + if (0 != RelativePath && + L'\0' != RelativePath[0] && + (L'.' != RelativePath[0] || L'\0' != RelativePath[1])) + { + WCHAR Temp[MAX_PATH]; + + if (0 == GetModuleFileNameW(Module, Temp, MAX_PATH)) + return FspNtStatusFromWin32(GetLastError()); + + if (0 == PathCombineW(FileName, Temp, RelativePath)) + return STATUS_UNSUCCESSFUL; + } + else + { + if (0 == GetModuleFileNameW(Module, FileName, MAX_PATH)) + return FspNtStatusFromWin32(GetLastError()); + } + + return STATUS_SUCCESS; +}