diff --git a/build/VStudio/winfsp_dll.vcxproj b/build/VStudio/winfsp_dll.vcxproj
index 19bd2de1..fdf44984 100644
--- a/build/VStudio/winfsp_dll.vcxproj
+++ b/build/VStudio/winfsp_dll.vcxproj
@@ -73,6 +73,7 @@
+
diff --git a/build/VStudio/winfsp_dll.vcxproj.filters b/build/VStudio/winfsp_dll.vcxproj.filters
index 13c62356..99346625 100644
--- a/build/VStudio/winfsp_dll.vcxproj.filters
+++ b/build/VStudio/winfsp_dll.vcxproj.filters
@@ -178,6 +178,9 @@
Source\shared\ku
+
+ Source
+
diff --git a/src/dll/fsctl.c b/src/dll/fsctl.c
index 81dbf823..61263c1b 100644
--- a/src/dll/fsctl.c
+++ b/src/dll/fsctl.c
@@ -301,13 +301,15 @@ FSP_API NTSTATUS FspFsctlPreflight(PWSTR DevicePath)
static BOOL WINAPI FspFsctlServiceVersionInitialize(
PINIT_ONCE InitOnce, PVOID Parameter, PVOID *Context)
{
- PWSTR DriverName = L"" FSP_FSCTL_DRIVER_NAME;
+ WCHAR DriverName[256];
PWSTR ModuleFileName;
SC_HANDLE ScmHandle = 0;
SC_HANDLE SvcHandle = 0;
QUERY_SERVICE_CONFIGW *ServiceConfig = 0;
DWORD Size;
+ wsprintfW(DriverName, L"" FSP_FSCTL_DRIVER_NAME "%s", FspSxsIdent());
+
ScmHandle = OpenSCManagerW(0, 0, 0);
if (0 == ScmHandle)
goto exit;
@@ -374,13 +376,15 @@ static VOID FspFsctlServiceVersion(PUINT32 PVersion)
static NTSTATUS FspFsctlStartService(VOID)
{
static SRWLOCK Lock = SRWLOCK_INIT;
- PWSTR DriverName = L"" FSP_FSCTL_DRIVER_NAME;
+ WCHAR DriverName[256];
SC_HANDLE ScmHandle = 0;
SC_HANDLE SvcHandle = 0;
SERVICE_STATUS ServiceStatus;
DWORD LastError;
NTSTATUS Result;
+ wsprintfW(DriverName, L"" FSP_FSCTL_DRIVER_NAME "%s", FspSxsIdent());
+
AcquireSRWLockExclusive(&Lock);
/* Determine if we are running inside container.
@@ -575,7 +579,7 @@ exit:
NTSTATUS FspFsctlRegister(VOID)
{
extern HINSTANCE DllInstance;
- PWSTR DriverName = L"" FSP_FSCTL_DRIVER_NAME;
+ WCHAR DriverName[256];
WCHAR DriverPath[MAX_PATH];
DWORD Size;
SC_HANDLE ScmHandle = 0;
@@ -584,6 +588,8 @@ NTSTATUS FspFsctlRegister(VOID)
SERVICE_DESCRIPTION ServiceDescription;
NTSTATUS Result;
+ wsprintfW(DriverName, L"" FSP_FSCTL_DRIVER_NAME "%s", FspSxsIdent());
+
if (0 == GetModuleFileNameW(DllInstance, DriverPath, MAX_PATH))
return FspNtStatusFromWin32(GetLastError());
@@ -623,7 +629,7 @@ NTSTATUS FspFsctlRegister(VOID)
}
else
{
- SvcHandle = CreateServiceW(ScmHandle, DriverName, DriverName,
+ SvcHandle = CreateServiceW(ScmHandle, DriverName, L"" FSP_FSCTL_DRIVER_NAME,
SERVICE_CHANGE_CONFIG | READ_CONTROL | WRITE_DAC,
SERVICE_FILE_SYSTEM_DRIVER, SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL, DriverPath,
0, 0, 0, 0, 0);
@@ -665,12 +671,14 @@ exit:
NTSTATUS FspFsctlUnregister(VOID)
{
- PWSTR DriverName = L"" FSP_FSCTL_DRIVER_NAME;
+ WCHAR DriverName[256];
SC_HANDLE ScmHandle = 0;
SC_HANDLE SvcHandle = 0;
DWORD LastError;
NTSTATUS Result;
+ wsprintfW(DriverName, L"" FSP_FSCTL_DRIVER_NAME "%s", FspSxsIdent());
+
ScmHandle = OpenSCManagerW(0, 0, SC_MANAGER_CREATE_SERVICE);
/*
* The SC_MANAGER_CREATE_SERVICE access right is not strictly needed here,
diff --git a/src/dll/library.h b/src/dll/library.h
index fa982ab2..b14039a9 100644
--- a/src/dll/library.h
+++ b/src/dll/library.h
@@ -70,6 +70,8 @@ NTSTATUS FspNpUnregister(VOID);
NTSTATUS FspEventLogRegister(VOID);
NTSTATUS FspEventLogUnregister(VOID);
+PWSTR FspSxsIdent(VOID);
+
PSID FspWksidNew(WELL_KNOWN_SID_TYPE WellKnownSidType, PNTSTATUS PResult);
PSID FspWksidGet(WELL_KNOWN_SID_TYPE WellKnownSidType);
diff --git a/src/dll/sxs.c b/src/dll/sxs.c
new file mode 100644
index 00000000..c98e1c02
--- /dev/null
+++ b/src/dll/sxs.c
@@ -0,0 +1,110 @@
+/**
+ * @file dll/sxs.c
+ *
+ * @copyright 2015-2022 Bill Zissimopoulos
+ */
+/*
+ * This file is part of WinFsp.
+ *
+ * You can redistribute it and/or modify it under the terms of the GNU
+ * General Public License version 3 as published by the Free Software
+ * Foundation.
+ *
+ * Licensees holding a valid commercial license may use this software
+ * in accordance with the commercial license agreement provided in
+ * conjunction with the software. The terms and conditions of any such
+ * commercial license agreement shall govern, supersede, and render
+ * ineffective any application of the GPLv3 license to this software,
+ * notwithstanding of any reference thereto in the software or
+ * associated repository.
+ */
+
+#include
+
+static INIT_ONCE FspSxsIdentInitOnce = INIT_ONCE_STATIC_INIT;
+static WCHAR FspSxsIdentBuf[32 + 1] = L"";
+
+static BOOL WINAPI FspSxsIdentInitialize(
+ PINIT_ONCE InitOnce, PVOID Parameter, PVOID *Context)
+{
+ extern HINSTANCE DllInstance;
+ WCHAR Path[MAX_PATH];
+ DWORD Size;
+ HANDLE Handle = INVALID_HANDLE_VALUE;
+ CHAR Buffer[ARRAYSIZE(FspSxsIdentBuf) - 1];
+ WCHAR WBuffer[ARRAYSIZE(FspSxsIdentBuf) - 1];
+
+ if (0 == GetModuleFileNameW(DllInstance, Path, MAX_PATH))
+ goto exit;
+
+ Size = lstrlenW(Path);
+ if (4 < Size &&
+ (L'.' == Path[Size - 4]) &&
+ (L'D' == Path[Size - 3] || L'd' == Path[Size - 3]) &&
+ (L'L' == Path[Size - 2] || L'l' == Path[Size - 2]) &&
+ (L'L' == Path[Size - 1] || L'l' == Path[Size - 1]) &&
+ (L'\0' == Path[Size]))
+ ;
+ else
+ goto exit;
+
+ Size -= 4;
+ for (PWCHAR P = Path + Size - 1; Path <= P; P--)
+ {
+ if (L'\\' == *P)
+ break;
+ if (L'-' == *P)
+ {
+ /* arch */
+ Size = (DWORD)(P - Path);
+ break;
+ }
+ }
+
+ Path[Size + 0] = L'.';
+ Path[Size + 1] = L's';
+ Path[Size + 2] = L'x';
+ Path[Size + 3] = L's';
+ Path[Size + 4] = L'\0';
+
+ Handle = CreateFileW(
+ Path,
+ FILE_READ_DATA,
+ FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
+ 0,
+ OPEN_EXISTING,
+ 0,
+ 0);
+ if (INVALID_HANDLE_VALUE == Handle)
+ goto exit;
+
+ if (!ReadFile(Handle, Buffer, sizeof Buffer, &Size, 0))
+ goto exit;
+
+ for (PCHAR P = Buffer, EndP = P + Size; EndP > P; P++)
+ if ('\r' == *P || '\n' == *P)
+ {
+ Size = (DWORD)(P - Buffer);
+ break;
+ }
+
+ Size = MultiByteToWideChar(CP_UTF8, 0,
+ Buffer, Size, WBuffer, ARRAYSIZE(WBuffer));
+ if (0 == Size)
+ goto exit;
+
+ memcpy(FspSxsIdentBuf, WBuffer, Size * sizeof(WCHAR));
+ FspSxsIdentBuf[Size] = L'\0';
+
+exit:
+ if (INVALID_HANDLE_VALUE != Handle)
+ CloseHandle(Handle);
+
+ return TRUE;
+}
+
+PWSTR FspSxsIdent(VOID)
+{
+ InitOnceExecuteOnce(&FspSxsIdentInitOnce, FspSxsIdentInitialize, 0, 0);
+ return FspSxsIdentBuf;
+}