mirror of
https://github.com/winfsp/winfsp.git
synced 2025-06-07 20:42:09 -05:00
dll: FspSxsIdent
This commit is contained in:
parent
ec832b45ff
commit
40ba537dc2
@ -73,6 +73,7 @@
|
|||||||
<ClCompile Include="..\..\src\dll\ntstatus.c" />
|
<ClCompile Include="..\..\src\dll\ntstatus.c" />
|
||||||
<ClCompile Include="..\..\src\dll\path.c" />
|
<ClCompile Include="..\..\src\dll\path.c" />
|
||||||
<ClCompile Include="..\..\src\dll\service.c" />
|
<ClCompile Include="..\..\src\dll\service.c" />
|
||||||
|
<ClCompile Include="..\..\src\dll\sxs.c" />
|
||||||
<ClCompile Include="..\..\src\dll\util.c" />
|
<ClCompile Include="..\..\src\dll\util.c" />
|
||||||
<ClCompile Include="..\..\src\dll\wksid.c" />
|
<ClCompile Include="..\..\src\dll\wksid.c" />
|
||||||
<ClCompile Include="..\..\src\shared\ku\mountmgr.c" />
|
<ClCompile Include="..\..\src\shared\ku\mountmgr.c" />
|
||||||
|
@ -178,6 +178,9 @@
|
|||||||
<ClCompile Include="..\..\src\shared\ku\mountmgr.c">
|
<ClCompile Include="..\..\src\shared\ku\mountmgr.c">
|
||||||
<Filter>Source\shared\ku</Filter>
|
<Filter>Source\shared\ku</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\src\dll\sxs.c">
|
||||||
|
<Filter>Source</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="..\..\src\dll\library.def">
|
<None Include="..\..\src\dll\library.def">
|
||||||
|
@ -301,13 +301,15 @@ FSP_API NTSTATUS FspFsctlPreflight(PWSTR DevicePath)
|
|||||||
static BOOL WINAPI FspFsctlServiceVersionInitialize(
|
static BOOL WINAPI FspFsctlServiceVersionInitialize(
|
||||||
PINIT_ONCE InitOnce, PVOID Parameter, PVOID *Context)
|
PINIT_ONCE InitOnce, PVOID Parameter, PVOID *Context)
|
||||||
{
|
{
|
||||||
PWSTR DriverName = L"" FSP_FSCTL_DRIVER_NAME;
|
WCHAR DriverName[256];
|
||||||
PWSTR ModuleFileName;
|
PWSTR ModuleFileName;
|
||||||
SC_HANDLE ScmHandle = 0;
|
SC_HANDLE ScmHandle = 0;
|
||||||
SC_HANDLE SvcHandle = 0;
|
SC_HANDLE SvcHandle = 0;
|
||||||
QUERY_SERVICE_CONFIGW *ServiceConfig = 0;
|
QUERY_SERVICE_CONFIGW *ServiceConfig = 0;
|
||||||
DWORD Size;
|
DWORD Size;
|
||||||
|
|
||||||
|
wsprintfW(DriverName, L"" FSP_FSCTL_DRIVER_NAME "%s", FspSxsIdent());
|
||||||
|
|
||||||
ScmHandle = OpenSCManagerW(0, 0, 0);
|
ScmHandle = OpenSCManagerW(0, 0, 0);
|
||||||
if (0 == ScmHandle)
|
if (0 == ScmHandle)
|
||||||
goto exit;
|
goto exit;
|
||||||
@ -374,13 +376,15 @@ static VOID FspFsctlServiceVersion(PUINT32 PVersion)
|
|||||||
static NTSTATUS FspFsctlStartService(VOID)
|
static NTSTATUS FspFsctlStartService(VOID)
|
||||||
{
|
{
|
||||||
static SRWLOCK Lock = SRWLOCK_INIT;
|
static SRWLOCK Lock = SRWLOCK_INIT;
|
||||||
PWSTR DriverName = L"" FSP_FSCTL_DRIVER_NAME;
|
WCHAR DriverName[256];
|
||||||
SC_HANDLE ScmHandle = 0;
|
SC_HANDLE ScmHandle = 0;
|
||||||
SC_HANDLE SvcHandle = 0;
|
SC_HANDLE SvcHandle = 0;
|
||||||
SERVICE_STATUS ServiceStatus;
|
SERVICE_STATUS ServiceStatus;
|
||||||
DWORD LastError;
|
DWORD LastError;
|
||||||
NTSTATUS Result;
|
NTSTATUS Result;
|
||||||
|
|
||||||
|
wsprintfW(DriverName, L"" FSP_FSCTL_DRIVER_NAME "%s", FspSxsIdent());
|
||||||
|
|
||||||
AcquireSRWLockExclusive(&Lock);
|
AcquireSRWLockExclusive(&Lock);
|
||||||
|
|
||||||
/* Determine if we are running inside container.
|
/* Determine if we are running inside container.
|
||||||
@ -575,7 +579,7 @@ exit:
|
|||||||
NTSTATUS FspFsctlRegister(VOID)
|
NTSTATUS FspFsctlRegister(VOID)
|
||||||
{
|
{
|
||||||
extern HINSTANCE DllInstance;
|
extern HINSTANCE DllInstance;
|
||||||
PWSTR DriverName = L"" FSP_FSCTL_DRIVER_NAME;
|
WCHAR DriverName[256];
|
||||||
WCHAR DriverPath[MAX_PATH];
|
WCHAR DriverPath[MAX_PATH];
|
||||||
DWORD Size;
|
DWORD Size;
|
||||||
SC_HANDLE ScmHandle = 0;
|
SC_HANDLE ScmHandle = 0;
|
||||||
@ -584,6 +588,8 @@ NTSTATUS FspFsctlRegister(VOID)
|
|||||||
SERVICE_DESCRIPTION ServiceDescription;
|
SERVICE_DESCRIPTION ServiceDescription;
|
||||||
NTSTATUS Result;
|
NTSTATUS Result;
|
||||||
|
|
||||||
|
wsprintfW(DriverName, L"" FSP_FSCTL_DRIVER_NAME "%s", FspSxsIdent());
|
||||||
|
|
||||||
if (0 == GetModuleFileNameW(DllInstance, DriverPath, MAX_PATH))
|
if (0 == GetModuleFileNameW(DllInstance, DriverPath, MAX_PATH))
|
||||||
return FspNtStatusFromWin32(GetLastError());
|
return FspNtStatusFromWin32(GetLastError());
|
||||||
|
|
||||||
@ -623,7 +629,7 @@ NTSTATUS FspFsctlRegister(VOID)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SvcHandle = CreateServiceW(ScmHandle, DriverName, DriverName,
|
SvcHandle = CreateServiceW(ScmHandle, DriverName, L"" FSP_FSCTL_DRIVER_NAME,
|
||||||
SERVICE_CHANGE_CONFIG | READ_CONTROL | WRITE_DAC,
|
SERVICE_CHANGE_CONFIG | READ_CONTROL | WRITE_DAC,
|
||||||
SERVICE_FILE_SYSTEM_DRIVER, SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL, DriverPath,
|
SERVICE_FILE_SYSTEM_DRIVER, SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL, DriverPath,
|
||||||
0, 0, 0, 0, 0);
|
0, 0, 0, 0, 0);
|
||||||
@ -665,12 +671,14 @@ exit:
|
|||||||
|
|
||||||
NTSTATUS FspFsctlUnregister(VOID)
|
NTSTATUS FspFsctlUnregister(VOID)
|
||||||
{
|
{
|
||||||
PWSTR DriverName = L"" FSP_FSCTL_DRIVER_NAME;
|
WCHAR DriverName[256];
|
||||||
SC_HANDLE ScmHandle = 0;
|
SC_HANDLE ScmHandle = 0;
|
||||||
SC_HANDLE SvcHandle = 0;
|
SC_HANDLE SvcHandle = 0;
|
||||||
DWORD LastError;
|
DWORD LastError;
|
||||||
NTSTATUS Result;
|
NTSTATUS Result;
|
||||||
|
|
||||||
|
wsprintfW(DriverName, L"" FSP_FSCTL_DRIVER_NAME "%s", FspSxsIdent());
|
||||||
|
|
||||||
ScmHandle = OpenSCManagerW(0, 0, SC_MANAGER_CREATE_SERVICE);
|
ScmHandle = OpenSCManagerW(0, 0, SC_MANAGER_CREATE_SERVICE);
|
||||||
/*
|
/*
|
||||||
* The SC_MANAGER_CREATE_SERVICE access right is not strictly needed here,
|
* The SC_MANAGER_CREATE_SERVICE access right is not strictly needed here,
|
||||||
|
@ -70,6 +70,8 @@ NTSTATUS FspNpUnregister(VOID);
|
|||||||
NTSTATUS FspEventLogRegister(VOID);
|
NTSTATUS FspEventLogRegister(VOID);
|
||||||
NTSTATUS FspEventLogUnregister(VOID);
|
NTSTATUS FspEventLogUnregister(VOID);
|
||||||
|
|
||||||
|
PWSTR FspSxsIdent(VOID);
|
||||||
|
|
||||||
PSID FspWksidNew(WELL_KNOWN_SID_TYPE WellKnownSidType, PNTSTATUS PResult);
|
PSID FspWksidNew(WELL_KNOWN_SID_TYPE WellKnownSidType, PNTSTATUS PResult);
|
||||||
PSID FspWksidGet(WELL_KNOWN_SID_TYPE WellKnownSidType);
|
PSID FspWksidGet(WELL_KNOWN_SID_TYPE WellKnownSidType);
|
||||||
|
|
||||||
|
110
src/dll/sxs.c
Normal file
110
src/dll/sxs.c
Normal file
@ -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 <dll/library.h>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user