mirror of
https://github.com/winfsp/winfsp.git
synced 2025-04-22 08:23:05 -05:00
dll: FspFileSystemRegister, FspFileSystemUnregister
This commit is contained in:
parent
26aadb0b72
commit
b089b98afc
@ -74,10 +74,8 @@ Global
|
||||
{AA7190E8-877F-4827-8CDD-E0D85F83C8C1}.Release|x86.Build.0 = Release|Win32
|
||||
{D53AAC39-4C57-4CA5-A4F3-C2B24888C594}.Debug|x64.ActiveCfg = Debug|x86
|
||||
{D53AAC39-4C57-4CA5-A4F3-C2B24888C594}.Debug|x86.ActiveCfg = Debug|x86
|
||||
{D53AAC39-4C57-4CA5-A4F3-C2B24888C594}.Debug|x86.Build.0 = Debug|x86
|
||||
{D53AAC39-4C57-4CA5-A4F3-C2B24888C594}.Release|x64.ActiveCfg = Release|x86
|
||||
{D53AAC39-4C57-4CA5-A4F3-C2B24888C594}.Release|x86.ActiveCfg = Release|x86
|
||||
{D53AAC39-4C57-4CA5-A4F3-C2B24888C594}.Release|x86.Build.0 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -145,6 +145,7 @@
|
||||
<MapFileName>$(OutDir)$(TargetFileName).map</MapFileName>
|
||||
<IgnoreAllDefaultLibraries>true</IgnoreAllDefaultLibraries>
|
||||
<ModuleDefinitionFile>..\..\src\dll\library.def</ModuleDefinitionFile>
|
||||
<AdditionalDependencies>%(AdditionalDependencies);version.lib</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
@ -169,6 +170,7 @@
|
||||
<MapFileName>$(OutDir)$(TargetFileName).map</MapFileName>
|
||||
<IgnoreAllDefaultLibraries>true</IgnoreAllDefaultLibraries>
|
||||
<ModuleDefinitionFile>..\..\src\dll\library.def</ModuleDefinitionFile>
|
||||
<AdditionalDependencies>%(AdditionalDependencies);version.lib</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
@ -196,6 +198,7 @@
|
||||
<MapFileName>$(OutDir)$(TargetFileName).map</MapFileName>
|
||||
<IgnoreAllDefaultLibraries>true</IgnoreAllDefaultLibraries>
|
||||
<ModuleDefinitionFile>..\..\src\dll\library.def</ModuleDefinitionFile>
|
||||
<AdditionalDependencies>%(AdditionalDependencies);version.lib</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
@ -223,6 +226,7 @@
|
||||
<MapFileName>$(OutDir)$(TargetFileName).map</MapFileName>
|
||||
<IgnoreAllDefaultLibraries>true</IgnoreAllDefaultLibraries>
|
||||
<ModuleDefinitionFile>..\..\src\dll\library.def</ModuleDefinitionFile>
|
||||
<AdditionalDependencies>%(AdditionalDependencies);version.lib</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
|
@ -24,6 +24,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define FSP_FSCTL_DRIVER_NAME "WinFsp"
|
||||
#define FSP_FSCTL_DISK_DEVICE_NAME "WinFsp.Disk"
|
||||
#define FSP_FSCTL_NET_DEVICE_NAME "WinFsp.Net"
|
||||
|
||||
|
125
src/dll/fs.c
125
src/dll/fs.c
@ -372,3 +372,128 @@ FSP_API VOID FspFileSystemSendResponse(FSP_FILE_SYSTEM *FileSystem,
|
||||
FspFsctlStop(FileSystem->VolumeHandle);
|
||||
}
|
||||
}
|
||||
|
||||
NTSTATUS FspFileSystemRegister(VOID)
|
||||
{
|
||||
extern HINSTANCE DllInstance;
|
||||
PWSTR DriverName = L"" FSP_FSCTL_DRIVER_NAME;
|
||||
WCHAR DriverPath[MAX_PATH];
|
||||
DWORD Size;
|
||||
SC_HANDLE ScmHandle = 0;
|
||||
SC_HANDLE SvcHandle = 0;
|
||||
PVOID VersionInfo = 0;
|
||||
SERVICE_DESCRIPTION ServiceDescription;
|
||||
DWORD LastError;
|
||||
NTSTATUS Result;
|
||||
|
||||
if (0 == GetModuleFileNameW(DllInstance, DriverPath, MAX_PATH))
|
||||
return FspNtStatusFromWin32(GetLastError());
|
||||
|
||||
Size = lstrlenW(DriverPath);
|
||||
if (4 < Size &&
|
||||
(L'.' == DriverPath[Size - 4]) &&
|
||||
(L'D' == DriverPath[Size - 3] || L'd' == DriverPath[Size - 3]) &&
|
||||
(L'L' == DriverPath[Size - 2] || L'l' == DriverPath[Size - 2]) &&
|
||||
(L'L' == DriverPath[Size - 1] || L'l' == DriverPath[Size - 1]) &&
|
||||
(L'\0' == DriverPath[Size]))
|
||||
{
|
||||
DriverPath[Size - 3] = L's';
|
||||
DriverPath[Size - 2] = L'y';
|
||||
DriverPath[Size - 1] = L's';
|
||||
}
|
||||
else
|
||||
/* should not happen! */
|
||||
return STATUS_NO_SUCH_DEVICE;
|
||||
|
||||
ScmHandle = OpenSCManagerW(0, 0, SC_MANAGER_CREATE_SERVICE);
|
||||
if (0 == ScmHandle)
|
||||
{
|
||||
Result = FspNtStatusFromWin32(GetLastError());
|
||||
goto exit;
|
||||
}
|
||||
|
||||
SvcHandle = CreateServiceW(ScmHandle, DriverName, DriverName,
|
||||
SERVICE_CHANGE_CONFIG,
|
||||
SERVICE_FILE_SYSTEM_DRIVER, SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL, DriverPath,
|
||||
0, 0, 0, 0, 0);
|
||||
if (0 == SvcHandle)
|
||||
{
|
||||
LastError = GetLastError();
|
||||
if (ERROR_SERVICE_EXISTS != LastError && ERROR_DUPLICATE_SERVICE_NAME != LastError)
|
||||
Result = FspNtStatusFromWin32(LastError);
|
||||
else
|
||||
Result = STATUS_SUCCESS;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
Size = GetFileVersionInfoSizeW(DriverPath, &Size/*dummy*/);
|
||||
if (0 < Size)
|
||||
{
|
||||
VersionInfo = MemAlloc(Size);
|
||||
if (0 != VersionInfo &&
|
||||
GetFileVersionInfoW(DriverPath, 0, Size, VersionInfo) &&
|
||||
VerQueryValueW(VersionInfo, L"\\StringFileInfo\\040904b0\\FileDescription",
|
||||
&ServiceDescription.lpDescription, &Size))
|
||||
{
|
||||
ChangeServiceConfig2W(SvcHandle, SERVICE_CONFIG_DESCRIPTION, &ServiceDescription);
|
||||
}
|
||||
}
|
||||
|
||||
Result = STATUS_SUCCESS;
|
||||
|
||||
exit:
|
||||
MemFree(VersionInfo);
|
||||
if (0 != SvcHandle)
|
||||
CloseServiceHandle(ScmHandle);
|
||||
if (0 != ScmHandle)
|
||||
CloseServiceHandle(ScmHandle);
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
NTSTATUS FspFileSystemUnregister(VOID)
|
||||
{
|
||||
PWSTR DriverName = L"" FSP_FSCTL_DRIVER_NAME;
|
||||
SC_HANDLE ScmHandle = 0;
|
||||
SC_HANDLE SvcHandle = 0;
|
||||
DWORD LastError;
|
||||
NTSTATUS Result;
|
||||
|
||||
ScmHandle = OpenSCManagerW(0, 0, 0);
|
||||
if (0 == ScmHandle)
|
||||
{
|
||||
Result = FspNtStatusFromWin32(GetLastError());
|
||||
goto exit;
|
||||
}
|
||||
|
||||
SvcHandle = OpenServiceW(ScmHandle, DriverName, DELETE);
|
||||
if (0 == SvcHandle)
|
||||
{
|
||||
LastError = GetLastError();
|
||||
if (ERROR_SERVICE_DOES_NOT_EXIST != LastError)
|
||||
Result = FspNtStatusFromWin32(LastError);
|
||||
else
|
||||
Result = STATUS_SUCCESS;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (!DeleteService(SvcHandle))
|
||||
{
|
||||
LastError = GetLastError();
|
||||
if (ERROR_SERVICE_MARKED_FOR_DELETE != LastError)
|
||||
Result = FspNtStatusFromWin32(LastError);
|
||||
else
|
||||
Result = STATUS_SUCCESS;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
Result = STATUS_SUCCESS;
|
||||
|
||||
exit:
|
||||
if (0 != SvcHandle)
|
||||
CloseServiceHandle(ScmHandle);
|
||||
if (0 != ScmHandle)
|
||||
CloseServiceHandle(ScmHandle);
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
@ -51,10 +51,20 @@ HRESULT WINAPI DllRegisterServer(VOID)
|
||||
{
|
||||
NTSTATUS Result;
|
||||
|
||||
Result = FspFileSystemRegister();
|
||||
FspDebugLog("FspFileSystemRegister = %lx\n", Result);
|
||||
if (!NT_SUCCESS(Result))
|
||||
goto exit;
|
||||
|
||||
Result = FspNpRegister();
|
||||
FspDebugLog("FspNpRegister = %lx\n", Result);
|
||||
if (!NT_SUCCESS(Result))
|
||||
{
|
||||
FspFileSystemUnregister();
|
||||
goto exit;
|
||||
}
|
||||
|
||||
FspDebugLog("FspNpRegister = %ld\n", Result);
|
||||
|
||||
exit:
|
||||
return NT_SUCCESS(Result) ? S_OK : 0x80040201/*SELFREG_E_CLASS*/;
|
||||
}
|
||||
|
||||
@ -63,8 +73,18 @@ HRESULT WINAPI DllUnregisterServer(VOID)
|
||||
NTSTATUS Result;
|
||||
|
||||
Result = FspNpUnregister();
|
||||
FspDebugLog("FspNpUnregister = %lx\n", Result);
|
||||
if (!NT_SUCCESS(Result))
|
||||
goto exit;
|
||||
|
||||
FspDebugLog("FspNpUnregister = %ld\n", Result);
|
||||
Result = FspFileSystemUnregister();
|
||||
FspDebugLog("FspFileSystemUnregister = %lx\n", Result);
|
||||
if (!NT_SUCCESS(Result))
|
||||
{
|
||||
FspNpRegister();
|
||||
goto exit;
|
||||
}
|
||||
|
||||
exit:
|
||||
return NT_SUCCESS(Result) ? S_OK : 0x80040201/*SELFREG_E_CLASS*/;
|
||||
}
|
||||
|
@ -105,6 +105,8 @@ BOOLEAN RemoveEntryList(PLIST_ENTRY Entry)
|
||||
|
||||
VOID FspFileSystemInitialize(VOID);
|
||||
VOID FspFileSystemFinalize(VOID);
|
||||
NTSTATUS FspFileSystemRegister(VOID);
|
||||
NTSTATUS FspFileSystemUnregister(VOID);
|
||||
|
||||
NTSTATUS FspNpRegister(VOID);
|
||||
NTSTATUS FspNpUnregister(VOID);
|
||||
|
@ -28,7 +28,7 @@
|
||||
#pragma warning(disable:4100) /* unreferenced formal parameter */
|
||||
#pragma warning(disable:4200) /* zero-sized array in struct/union */
|
||||
|
||||
#define DRIVER_NAME "WinFsp"
|
||||
#define DRIVER_NAME FSP_FSCTL_DRIVER_NAME
|
||||
|
||||
/* IoCreateDeviceSecure default SDDL's */
|
||||
#define FSP_FSCTL_DEVICE_SDDL "D:P(A;;GA;;;SY)(A;;GA;;;BA)(A;;GR;;;WD)"
|
||||
|
Loading…
x
Reference in New Issue
Block a user