mirror of
https://github.com/winfsp/winfsp.git
synced 2025-07-03 09:22:57 -05:00
Compare commits
203 Commits
Author | SHA1 | Date | |
---|---|---|---|
760cd5e46f | |||
b36b6c60e2 | |||
e4984bf675 | |||
0c8bcd5d7d | |||
b5d8cd3ea6 | |||
af5f409233 | |||
cffb066d46 | |||
804434d836 | |||
f7595e40b6 | |||
669dd07ce2 | |||
b6fa54d301 | |||
342e7e39e2 | |||
9dfdd19616 | |||
2c651b1bd8 | |||
41764f7b41 | |||
08e697c52c | |||
66cc043149 | |||
518cd0e8c0 | |||
c0344f53b0 | |||
76445a5403 | |||
0577b8febb | |||
610a7ac2a6 | |||
e33fda4d00 | |||
2151e193dc | |||
ccfaf04f76 | |||
7e8d9fb986 | |||
37b6936ad0 | |||
3683afe203 | |||
a3cfc84007 | |||
ee5c584614 | |||
b8b15e8035 | |||
3db09be764 | |||
f2a0eb544e | |||
8c1c407b34 | |||
8dc4225ea1 | |||
ed0b83c84d | |||
71c68d1e17 | |||
053a5f1e4b | |||
e5d7f4ee9a | |||
d6fb076cad | |||
698b711df4 | |||
842f649f06 | |||
b062df9c42 | |||
f0385e3c7d | |||
10ce221fcc | |||
3f3092bdae | |||
29496a35be | |||
99a1e331b5 | |||
68d79b0c3b | |||
b695ef8ad8 | |||
b8ec5ba019 | |||
958f694b6f | |||
e227ae5751 | |||
007ec8f360 | |||
00976b92b8 | |||
9b56b3a420 | |||
adecc6fb25 | |||
b71d086ea7 | |||
382a6675da | |||
cbf8079324 | |||
1124e24a61 | |||
c6bab18947 | |||
3310a4300e | |||
6347803392 | |||
259bd84cc9 | |||
6bc3ec7c8a | |||
cf66fc3931 | |||
8a5218b273 | |||
e3ffa209eb | |||
a8f0f58d35 | |||
beeae73c79 | |||
2aa683177e | |||
0437218691 | |||
8a37cb9c36 | |||
32912b587f | |||
fb6a139c85 | |||
267ed97d36 | |||
53289f0c74 | |||
a4f687c635 | |||
55336e3dcf | |||
90d868c58f | |||
e0386db270 | |||
3490a379b0 | |||
009728e2b7 | |||
240bdfeb39 | |||
ea8ed690f6 | |||
a94d41c6b4 | |||
662df6544f | |||
15363e0256 | |||
c74f34eaf0 | |||
bc777f2d91 | |||
a9868ba883 | |||
9d42c625cc | |||
afc498ba6e | |||
e222c3ae72 | |||
90039ecd72 | |||
8f0f5b3d9e | |||
0e8d694bdd | |||
b0b15dff05 | |||
0f63dddb32 | |||
20fc185530 | |||
6b99160625 | |||
1a406eb462 | |||
70d5c095ca | |||
396997fb22 | |||
8c8d80add3 | |||
6bef445102 | |||
9edbe7012e | |||
bc5f5c02db | |||
326d6479ad | |||
54d343c4e4 | |||
96e048ec5e | |||
c46d8b2e0a | |||
bcfa4a326b | |||
b451219bfc | |||
3286033191 | |||
1432d711d8 | |||
0d4aa15377 | |||
7fbaa8d37c | |||
229c3f81fa | |||
9ccb394b04 | |||
22da074ff7 | |||
e08b462566 | |||
77e7147893 | |||
7d4fc0f740 | |||
f0751f1fb3 | |||
4e2aaa8a21 | |||
8525c99d7a | |||
9b93c766c3 | |||
7fef1b87f6 | |||
190e2320c0 | |||
6910b67982 | |||
7e1906bad5 | |||
dddb55243b | |||
88b13082cb | |||
6d5abafdaa | |||
3f8e7273c3 | |||
8b8c567cf7 | |||
da95f05b29 | |||
a53e79984a | |||
59a305b333 | |||
3620de44d1 | |||
3f3c02f3ce | |||
4b9945d9bf | |||
19d400d251 | |||
b559c7405f | |||
765bb1e1a3 | |||
300ce8485b | |||
4a4dab14c5 | |||
fd8a3ab786 | |||
b7665478d9 | |||
a938cb4fe6 | |||
d12a256430 | |||
bcbba3e4cf | |||
10c3f6f507 | |||
ead273ae18 | |||
74a943d8d7 | |||
a40e7d8c56 | |||
187311bb5e | |||
e14a26b540 | |||
4850056bf6 | |||
3d3dcbe0c5 | |||
7ea13a967a | |||
c851e9c98e | |||
9e068049b3 | |||
f993cf7251 | |||
e8f35ac314 | |||
4d57a5c10e | |||
7db0f68dd7 | |||
1f22bd3517 | |||
91825106f1 | |||
9bceb577e3 | |||
2155cbadc3 | |||
71867f6779 | |||
214b43398f | |||
aa75d412ac | |||
6be55aa515 | |||
10c997ab6b | |||
1505b1f368 | |||
b004268583 | |||
301e8fed62 | |||
c2e38bcc97 | |||
37b1dc440e | |||
c4b6e9bb47 | |||
55f9053b1b | |||
a53abe8ab6 | |||
5fa7ba3513 | |||
7e2c767997 | |||
d102edf1e9 | |||
0412fac588 | |||
3935372956 | |||
d89baea193 | |||
599430e649 | |||
4f5e00474e | |||
16836c7cfb | |||
ffded63c56 | |||
0dba3ffe55 | |||
122592f332 | |||
c4421bf3aa | |||
222f015273 | |||
153eb42885 | |||
4d1aeeda4c | |||
f2241fcee4 |
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
[submodule "ext/test"]
|
||||||
|
path = ext/test
|
||||||
|
url = https://bitbucket.org/billziss/secfs.test.git
|
21
README.md
21
README.md
@ -20,14 +20,19 @@ WinFsp consists of a kernel mode FSD (File System Driver) and a user mode DLL (D
|
|||||||
|
|
||||||
The project source code is organized as follows:
|
The project source code is organized as follows:
|
||||||
|
|
||||||
* build/VStudio: contains the WinFsp solution and project files.
|
* build/VStudio: WinFsp solution and project files.
|
||||||
* doc: contains the WinFsp license, contributor agreement and additional documentation. The WinFsp design document can be found here.
|
* doc: WinFsp license, contributor agreement and additional documentation. The WinFsp design documents can be found here.
|
||||||
* ext/tlib: contains a small test library originally from the secfs (Secure Cloud File System) project.
|
* ext/tlib: A small test library originally from the secfs (Secure Cloud File System) project.
|
||||||
* inc/winfsp: contains public include files to be used when developing a user mode file system.
|
* ext/test: Submodule pointing to the secfs.test project, which contains a number of tools for testing Windows and POSIX file systems.
|
||||||
* src/dll: contains the source code to the WinFsp DLL.
|
* inc/winfsp: Public headers for the WinFsp API.
|
||||||
* src/sys: contains the source code to the WinFsp FSD.
|
* inc/fuse: Public headers for the FUSE compatibility layer.
|
||||||
* tst/memfs: contains the source code to an example file system written in C++ (memfs).
|
* src/dll: Source code to the WinFsp DLL.
|
||||||
* tst/winfsp-tests: contains the WinFsp test suite.
|
* src/dll/fuse: Source code to the FUSE compatibility layer.
|
||||||
|
* src/launcher: Source code to the launcher service and the launchctl utility.
|
||||||
|
* src/sys: Source code to the WinFsp FSD.
|
||||||
|
* opt/cygfuse: Source code for the Cygwin FUSE package.
|
||||||
|
* tst/memfs: Source code to an example file system written in C++ (memfs).
|
||||||
|
* tst/winfsp-tests: WinFsp test suite.
|
||||||
|
|
||||||
## Building
|
## Building
|
||||||
|
|
||||||
|
21
appveyor.yml
Normal file
21
appveyor.yml
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
version: '{build}'
|
||||||
|
|
||||||
|
environment:
|
||||||
|
CONFIGURATION: Release
|
||||||
|
|
||||||
|
install:
|
||||||
|
- git submodule update --init --recursive
|
||||||
|
- appveyor AddMessage "Change boot configuration and reboot" -Category Information
|
||||||
|
- bcdedit /set testsigning on
|
||||||
|
- ps: Restart-Computer -Force
|
||||||
|
- ps: Start-Sleep -s 10
|
||||||
|
|
||||||
|
build_script:
|
||||||
|
- appveyor AddMessage "Reboot complete" -Category Information
|
||||||
|
- bcdedit | findstr /i "testsigning"
|
||||||
|
- tools\build.bat %CONFIGURATION%
|
||||||
|
|
||||||
|
test_script:
|
||||||
|
- for %%f in ("build\VStudio\build\%CONFIGURATION%\winfsp-*.msi") do start /wait msiexec /i %%f /qn INSTALLLEVEL=1000
|
||||||
|
- tools\nmake-ext-test.bat %CONFIGURATION%
|
||||||
|
- tools\run-tests.bat %CONFIGURATION%
|
@ -45,13 +45,14 @@
|
|||||||
</Directory>
|
</Directory>
|
||||||
|
|
||||||
<DirectoryRef Id="INSTALLDIR">
|
<DirectoryRef Id="INSTALLDIR">
|
||||||
<Component Id="C.INSTALLDIR">
|
<Component Id="C.INSTALLDIR" Guid="{F876F26E-5016-4AC6-93B3-653C0312A6CE}">
|
||||||
<RegistryValue
|
<RegistryValue
|
||||||
Root="HKLM"
|
Root="HKLM"
|
||||||
Key="[P.RegistryKey]"
|
Key="[P.RegistryKey]"
|
||||||
Name="InstallDir"
|
Name="InstallDir"
|
||||||
Type="string"
|
Type="string"
|
||||||
Value="[INSTALLDIR]" />
|
Value="[INSTALLDIR]"
|
||||||
|
KeyPath="yes" />
|
||||||
</Component>
|
</Component>
|
||||||
</DirectoryRef>
|
</DirectoryRef>
|
||||||
<DirectoryRef Id="BINDIR" FileSource="..\build\$(var.Configuration)">
|
<DirectoryRef Id="BINDIR" FileSource="..\build\$(var.Configuration)">
|
||||||
@ -197,6 +198,20 @@
|
|||||||
<File Name="winfsp.h" KeyPath="yes" />
|
<File Name="winfsp.h" KeyPath="yes" />
|
||||||
</Component>
|
</Component>
|
||||||
</Directory>
|
</Directory>
|
||||||
|
<Directory Id="INCDIR.fuse" Name="fuse">
|
||||||
|
<Component Id="C.fuse.h">
|
||||||
|
<File Name="fuse.h" KeyPath="yes" />
|
||||||
|
</Component>
|
||||||
|
<Component Id="C.fuse_common.h">
|
||||||
|
<File Name="fuse_common.h" KeyPath="yes" />
|
||||||
|
</Component>
|
||||||
|
<Component Id="C.fuse_opt.h">
|
||||||
|
<File Name="fuse_opt.h" KeyPath="yes" />
|
||||||
|
</Component>
|
||||||
|
<Component Id="C.winfsp_fuse.h">
|
||||||
|
<File Name="winfsp_fuse.h" KeyPath="yes" />
|
||||||
|
</Component>
|
||||||
|
</Directory>
|
||||||
</DirectoryRef>
|
</DirectoryRef>
|
||||||
<DirectoryRef Id="LIBDIR" FileSource="..\build\$(var.Configuration)">
|
<DirectoryRef Id="LIBDIR" FileSource="..\build\$(var.Configuration)">
|
||||||
<Component Id="C.winfsp_x64.lib">
|
<Component Id="C.winfsp_x64.lib">
|
||||||
@ -205,6 +220,26 @@
|
|||||||
<Component Id="C.winfsp_x86.lib">
|
<Component Id="C.winfsp_x86.lib">
|
||||||
<File Name="winfsp-x86.lib" KeyPath="yes" />
|
<File Name="winfsp-x86.lib" KeyPath="yes" />
|
||||||
</Component>
|
</Component>
|
||||||
|
|
||||||
|
<!-- On Win64 copy fuse-x64.pc -->
|
||||||
|
<Component Id="C.fuse_x64.pc" Guid="407395D2-D076-411E-B1D0-D97E21E11A3C">
|
||||||
|
<File
|
||||||
|
Id="FILE.fuse_x64.pc"
|
||||||
|
Name="fuse.pc"
|
||||||
|
Source="..\build\$(var.Configuration)\fuse-x64.pc"
|
||||||
|
KeyPath="yes" />
|
||||||
|
<Condition>VersionNT64</Condition>
|
||||||
|
</Component>
|
||||||
|
|
||||||
|
<!-- On Win32 copy fuse-x86.pc -->
|
||||||
|
<Component Id="C.fuse_x86.pc" Guid="0568EBCB-782E-4C17-9B64-BAFCC43F64ED">
|
||||||
|
<File
|
||||||
|
Id="FILE.fuse_x86.pc"
|
||||||
|
Name="fuse.pc"
|
||||||
|
Source="..\build\$(var.Configuration)\fuse-x86.pc"
|
||||||
|
KeyPath="yes" />
|
||||||
|
<Condition>NOT VersionNT64</Condition>
|
||||||
|
</Component>
|
||||||
</DirectoryRef>
|
</DirectoryRef>
|
||||||
<DirectoryRef Id="SMPDIR" FileSource="..\..\..\tst">
|
<DirectoryRef Id="SMPDIR" FileSource="..\..\..\tst">
|
||||||
<Directory Id="SMPDIR.memfs" Name="memfs">
|
<Directory Id="SMPDIR.memfs" Name="memfs">
|
||||||
@ -237,10 +272,16 @@
|
|||||||
<ComponentGroup Id="C.WinFsp.inc">
|
<ComponentGroup Id="C.WinFsp.inc">
|
||||||
<ComponentRef Id="C.fsctl.h" />
|
<ComponentRef Id="C.fsctl.h" />
|
||||||
<ComponentRef Id="C.winfsp.h" />
|
<ComponentRef Id="C.winfsp.h" />
|
||||||
|
<ComponentRef Id="C.fuse.h" />
|
||||||
|
<ComponentRef Id="C.fuse_common.h" />
|
||||||
|
<ComponentRef Id="C.fuse_opt.h" />
|
||||||
|
<ComponentRef Id="C.winfsp_fuse.h" />
|
||||||
</ComponentGroup>
|
</ComponentGroup>
|
||||||
<ComponentGroup Id="C.WinFsp.lib">
|
<ComponentGroup Id="C.WinFsp.lib">
|
||||||
<ComponentRef Id="C.winfsp_x64.lib" />
|
<ComponentRef Id="C.winfsp_x64.lib" />
|
||||||
<ComponentRef Id="C.winfsp_x86.lib" />
|
<ComponentRef Id="C.winfsp_x86.lib" />
|
||||||
|
<ComponentRef Id="C.fuse_x64.pc" />
|
||||||
|
<ComponentRef Id="C.fuse_x86.pc" />
|
||||||
</ComponentGroup>
|
</ComponentGroup>
|
||||||
<ComponentGroup Id="C.WinFsp.smp">
|
<ComponentGroup Id="C.WinFsp.smp">
|
||||||
<ComponentRef Id="C.memfs_x64.exe" />
|
<ComponentRef Id="C.memfs_x64.exe" />
|
||||||
@ -275,7 +316,7 @@
|
|||||||
Id="F.Developer"
|
Id="F.Developer"
|
||||||
Level="1000"
|
Level="1000"
|
||||||
Title="Developer"
|
Title="Developer"
|
||||||
Description="Additional files needed for development. Please note that the memfs sample requires the VC++ 2015 redistributable to be installed."
|
Description="Additional files needed for development."
|
||||||
AllowAdvertise="no"
|
AllowAdvertise="no"
|
||||||
InstallDefault="local"
|
InstallDefault="local"
|
||||||
Absent="allow">
|
Absent="allow">
|
||||||
|
@ -104,6 +104,7 @@
|
|||||||
<AdditionalIncludeDirectories>..\..\..\src;..\..\..\inc</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>..\..\..\src;..\..\..\inc</AdditionalIncludeDirectories>
|
||||||
<BufferSecurityCheck>false</BufferSecurityCheck>
|
<BufferSecurityCheck>false</BufferSecurityCheck>
|
||||||
<BasicRuntimeChecks>Default</BasicRuntimeChecks>
|
<BasicRuntimeChecks>Default</BasicRuntimeChecks>
|
||||||
|
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
@ -121,6 +122,7 @@
|
|||||||
<AdditionalIncludeDirectories>..\..\..\src;..\..\..\inc</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>..\..\..\src;..\..\..\inc</AdditionalIncludeDirectories>
|
||||||
<BufferSecurityCheck>false</BufferSecurityCheck>
|
<BufferSecurityCheck>false</BufferSecurityCheck>
|
||||||
<BasicRuntimeChecks>Default</BasicRuntimeChecks>
|
<BasicRuntimeChecks>Default</BasicRuntimeChecks>
|
||||||
|
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
@ -139,6 +141,7 @@
|
|||||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<AdditionalIncludeDirectories>..\..\..\src;..\..\..\inc</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>..\..\..\src;..\..\..\inc</AdditionalIncludeDirectories>
|
||||||
<BufferSecurityCheck>false</BufferSecurityCheck>
|
<BufferSecurityCheck>false</BufferSecurityCheck>
|
||||||
|
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
@ -159,6 +162,7 @@
|
|||||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<AdditionalIncludeDirectories>..\..\..\src;..\..\..\inc</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>..\..\..\src;..\..\..\inc</AdditionalIncludeDirectories>
|
||||||
<BufferSecurityCheck>false</BufferSecurityCheck>
|
<BufferSecurityCheck>false</BufferSecurityCheck>
|
||||||
|
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
|
@ -104,11 +104,13 @@
|
|||||||
<AdditionalIncludeDirectories>..\..\..\src;..\..\..\inc</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>..\..\..\src;..\..\..\inc</AdditionalIncludeDirectories>
|
||||||
<BasicRuntimeChecks>Default</BasicRuntimeChecks>
|
<BasicRuntimeChecks>Default</BasicRuntimeChecks>
|
||||||
<BufferSecurityCheck>false</BufferSecurityCheck>
|
<BufferSecurityCheck>false</BufferSecurityCheck>
|
||||||
|
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
<IgnoreAllDefaultLibraries>true</IgnoreAllDefaultLibraries>
|
<IgnoreAllDefaultLibraries>true</IgnoreAllDefaultLibraries>
|
||||||
|
<AdditionalDependencies>%(AdditionalDependencies);rpcrt4.lib</AdditionalDependencies>
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
@ -121,11 +123,13 @@
|
|||||||
<AdditionalIncludeDirectories>..\..\..\src;..\..\..\inc</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>..\..\..\src;..\..\..\inc</AdditionalIncludeDirectories>
|
||||||
<BasicRuntimeChecks>Default</BasicRuntimeChecks>
|
<BasicRuntimeChecks>Default</BasicRuntimeChecks>
|
||||||
<BufferSecurityCheck>false</BufferSecurityCheck>
|
<BufferSecurityCheck>false</BufferSecurityCheck>
|
||||||
|
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
<IgnoreAllDefaultLibraries>true</IgnoreAllDefaultLibraries>
|
<IgnoreAllDefaultLibraries>true</IgnoreAllDefaultLibraries>
|
||||||
|
<AdditionalDependencies>%(AdditionalDependencies);rpcrt4.lib</AdditionalDependencies>
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
@ -139,6 +143,7 @@
|
|||||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<AdditionalIncludeDirectories>..\..\..\src;..\..\..\inc</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>..\..\..\src;..\..\..\inc</AdditionalIncludeDirectories>
|
||||||
<BufferSecurityCheck>false</BufferSecurityCheck>
|
<BufferSecurityCheck>false</BufferSecurityCheck>
|
||||||
|
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
@ -146,6 +151,7 @@
|
|||||||
<OptimizeReferences>true</OptimizeReferences>
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
<IgnoreAllDefaultLibraries>true</IgnoreAllDefaultLibraries>
|
<IgnoreAllDefaultLibraries>true</IgnoreAllDefaultLibraries>
|
||||||
|
<AdditionalDependencies>%(AdditionalDependencies);rpcrt4.lib</AdditionalDependencies>
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
@ -159,6 +165,7 @@
|
|||||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<AdditionalIncludeDirectories>..\..\..\src;..\..\..\inc</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>..\..\..\src;..\..\..\inc</AdditionalIncludeDirectories>
|
||||||
<BufferSecurityCheck>false</BufferSecurityCheck>
|
<BufferSecurityCheck>false</BufferSecurityCheck>
|
||||||
|
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
@ -166,6 +173,7 @@
|
|||||||
<OptimizeReferences>true</OptimizeReferences>
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
<IgnoreAllDefaultLibraries>true</IgnoreAllDefaultLibraries>
|
<IgnoreAllDefaultLibraries>true</IgnoreAllDefaultLibraries>
|
||||||
|
<AdditionalDependencies>%(AdditionalDependencies);rpcrt4.lib</AdditionalDependencies>
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -103,7 +103,7 @@
|
|||||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<SDLCheck>true</SDLCheck>
|
<SDLCheck>true</SDLCheck>
|
||||||
<AdditionalIncludeDirectories>..\..\..\src;..\..\..\inc</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>..\..\..\src;..\..\..\inc</AdditionalIncludeDirectories>
|
||||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
@ -119,7 +119,7 @@
|
|||||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<SDLCheck>true</SDLCheck>
|
<SDLCheck>true</SDLCheck>
|
||||||
<AdditionalIncludeDirectories>..\..\..\src;..\..\..\inc</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>..\..\..\src;..\..\..\inc</AdditionalIncludeDirectories>
|
||||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
@ -137,7 +137,7 @@
|
|||||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<SDLCheck>true</SDLCheck>
|
<SDLCheck>true</SDLCheck>
|
||||||
<AdditionalIncludeDirectories>..\..\..\src;..\..\..\inc</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>..\..\..\src;..\..\..\inc</AdditionalIncludeDirectories>
|
||||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
@ -157,7 +157,7 @@
|
|||||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<SDLCheck>true</SDLCheck>
|
<SDLCheck>true</SDLCheck>
|
||||||
<AdditionalIncludeDirectories>..\..\..\src;..\..\..\inc</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>..\..\..\src;..\..\..\inc</AdditionalIncludeDirectories>
|
||||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
|
@ -102,7 +102,7 @@
|
|||||||
<PreprocessorDefinitions>__func__=__FUNCTION__;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>__func__=__FUNCTION__;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<SDLCheck>true</SDLCheck>
|
<SDLCheck>true</SDLCheck>
|
||||||
<AdditionalIncludeDirectories>..\..\..\tst\memfs;..\..\..\src;..\..\..\inc;..\..\..\ext</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>..\..\..\tst\memfs;..\..\..\src;..\..\..\inc;..\..\..\ext</AdditionalIncludeDirectories>
|
||||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
@ -119,7 +119,7 @@
|
|||||||
<PreprocessorDefinitions>__func__=__FUNCTION__;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>__func__=__FUNCTION__;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<SDLCheck>true</SDLCheck>
|
<SDLCheck>true</SDLCheck>
|
||||||
<AdditionalIncludeDirectories>..\..\..\tst\memfs;..\..\..\src;..\..\..\inc;..\..\..\ext</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>..\..\..\tst\memfs;..\..\..\src;..\..\..\inc;..\..\..\ext</AdditionalIncludeDirectories>
|
||||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
@ -138,7 +138,7 @@
|
|||||||
<PreprocessorDefinitions>__func__=__FUNCTION__;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>__func__=__FUNCTION__;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<SDLCheck>true</SDLCheck>
|
<SDLCheck>true</SDLCheck>
|
||||||
<AdditionalIncludeDirectories>..\..\..\tst\memfs;..\..\..\src;..\..\..\inc;..\..\..\ext</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>..\..\..\tst\memfs;..\..\..\src;..\..\..\inc;..\..\..\ext</AdditionalIncludeDirectories>
|
||||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
@ -159,7 +159,7 @@
|
|||||||
<PreprocessorDefinitions>__func__=__FUNCTION__;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>__func__=__FUNCTION__;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<SDLCheck>true</SDLCheck>
|
<SDLCheck>true</SDLCheck>
|
||||||
<AdditionalIncludeDirectories>..\..\..\tst\memfs;..\..\..\src;..\..\..\inc;..\..\..\ext</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>..\..\..\tst\memfs;..\..\..\src;..\..\..\inc;..\..\..\ext</AdditionalIncludeDirectories>
|
||||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
@ -185,11 +185,13 @@
|
|||||||
<ClCompile Include="..\..\..\tst\winfsp-tests\dirctl-test.c" />
|
<ClCompile Include="..\..\..\tst\winfsp-tests\dirctl-test.c" />
|
||||||
<ClCompile Include="..\..\..\tst\winfsp-tests\eventlog-test.c" />
|
<ClCompile Include="..\..\..\tst\winfsp-tests\eventlog-test.c" />
|
||||||
<ClCompile Include="..\..\..\tst\winfsp-tests\flush-test.c" />
|
<ClCompile Include="..\..\..\tst\winfsp-tests\flush-test.c" />
|
||||||
|
<ClCompile Include="..\..\..\tst\winfsp-tests\fuse-opt-test.c" />
|
||||||
<ClCompile Include="..\..\..\tst\winfsp-tests\info-test.c" />
|
<ClCompile Include="..\..\..\tst\winfsp-tests\info-test.c" />
|
||||||
<ClCompile Include="..\..\..\tst\winfsp-tests\lock-test.c" />
|
<ClCompile Include="..\..\..\tst\winfsp-tests\lock-test.c" />
|
||||||
<ClCompile Include="..\..\..\tst\winfsp-tests\memfs-test.c" />
|
<ClCompile Include="..\..\..\tst\winfsp-tests\memfs-test.c" />
|
||||||
<ClCompile Include="..\..\..\tst\winfsp-tests\mount-test.c" />
|
<ClCompile Include="..\..\..\tst\winfsp-tests\mount-test.c" />
|
||||||
<ClCompile Include="..\..\..\tst\winfsp-tests\path-test.c" />
|
<ClCompile Include="..\..\..\tst\winfsp-tests\path-test.c" />
|
||||||
|
<ClCompile Include="..\..\..\tst\winfsp-tests\posix-test.c" />
|
||||||
<ClCompile Include="..\..\..\tst\winfsp-tests\rdwr-test.c" />
|
<ClCompile Include="..\..\..\tst\winfsp-tests\rdwr-test.c" />
|
||||||
<ClCompile Include="..\..\..\tst\winfsp-tests\security-test.c" />
|
<ClCompile Include="..\..\..\tst\winfsp-tests\security-test.c" />
|
||||||
<ClCompile Include="..\..\..\tst\winfsp-tests\timeout-test.c" />
|
<ClCompile Include="..\..\..\tst\winfsp-tests\timeout-test.c" />
|
||||||
|
@ -55,6 +55,12 @@
|
|||||||
<ClCompile Include="..\..\..\tst\winfsp-tests\eventlog-test.c">
|
<ClCompile Include="..\..\..\tst\winfsp-tests\eventlog-test.c">
|
||||||
<Filter>Source</Filter>
|
<Filter>Source</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\..\tst\winfsp-tests\fuse-opt-test.c">
|
||||||
|
<Filter>Source</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\..\tst\winfsp-tests\posix-test.c">
|
||||||
|
<Filter>Source</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\..\..\ext\tlib\testsuite.h">
|
<ClInclude Include="..\..\..\ext\tlib\testsuite.h">
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
<MyCopyright>2015-2016 Bill Zissimopoulos</MyCopyright>
|
<MyCopyright>2015-2016 Bill Zissimopoulos</MyCopyright>
|
||||||
<!-- build number: concat 2-digit year with 3-digit day of the year (16-bits until 2066) -->
|
<!-- build number: concat 2-digit year with 3-digit day of the year (16-bits until 2066) -->
|
||||||
<MyBuildNumber>$([System.DateTime]::Now.ToString(`yy`))$([System.DateTime]::Now.DayOfYear.ToString(`000`))</MyBuildNumber>
|
<MyBuildNumber>$([System.DateTime]::Now.ToString(`yy`))$([System.DateTime]::Now.DayOfYear.ToString(`000`))</MyBuildNumber>
|
||||||
<MyVersion>0.11.$(MyBuildNumber)</MyVersion>
|
<MyVersion>0.14.$(MyBuildNumber)</MyVersion>
|
||||||
<MyVersionWithCommas>$(MyVersion.Replace('.',',')),0</MyVersionWithCommas>
|
<MyVersionWithCommas>$(MyVersion.Replace('.',',')),0</MyVersionWithCommas>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
</Project>
|
</Project>
|
@ -20,14 +20,24 @@
|
|||||||
</ProjectConfiguration>
|
</ProjectConfiguration>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ClInclude Include="..\..\inc\fuse\fuse.h" />
|
||||||
|
<ClInclude Include="..\..\inc\fuse\fuse_common.h" />
|
||||||
|
<ClInclude Include="..\..\inc\fuse\fuse_opt.h" />
|
||||||
|
<ClInclude Include="..\..\inc\fuse\winfsp_fuse.h" />
|
||||||
<ClInclude Include="..\..\inc\winfsp\fsctl.h" />
|
<ClInclude Include="..\..\inc\winfsp\fsctl.h" />
|
||||||
<ClInclude Include="..\..\inc\winfsp\winfsp.h" />
|
<ClInclude Include="..\..\inc\winfsp\winfsp.h" />
|
||||||
|
<ClInclude Include="..\..\src\dll\fuse\library.h" />
|
||||||
<ClInclude Include="..\..\src\dll\library.h" />
|
<ClInclude Include="..\..\src\dll\library.h" />
|
||||||
<ClInclude Include="..\..\src\shared\minimal.h" />
|
<ClInclude Include="..\..\src\shared\minimal.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="..\..\src\dll\eventlog.c" />
|
<ClCompile Include="..\..\src\dll\eventlog.c" />
|
||||||
|
<ClCompile Include="..\..\src\dll\fuse\fuse.c" />
|
||||||
|
<ClCompile Include="..\..\src\dll\fuse\fuse_intf.c" />
|
||||||
|
<ClCompile Include="..\..\src\dll\fuse\fuse_main.c" />
|
||||||
|
<ClCompile Include="..\..\src\dll\fuse\fuse_opt.c" />
|
||||||
<ClCompile Include="..\..\src\dll\np.c" />
|
<ClCompile Include="..\..\src\dll\np.c" />
|
||||||
|
<ClCompile Include="..\..\src\dll\posix.c" />
|
||||||
<ClCompile Include="..\..\src\dll\security.c" />
|
<ClCompile Include="..\..\src\dll\security.c" />
|
||||||
<ClCompile Include="..\..\src\dll\debug.c" />
|
<ClCompile Include="..\..\src\dll\debug.c" />
|
||||||
<ClCompile Include="..\..\src\dll\fsctl.c" />
|
<ClCompile Include="..\..\src\dll\fsctl.c" />
|
||||||
@ -37,10 +47,33 @@
|
|||||||
<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\util.c" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<CustomBuild Include="..\..\src\dll\fuse\fuse.pc">
|
||||||
|
<FileType>Document</FileType>
|
||||||
|
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">echo arch=$(PlatformTarget) >$(OutDir)fuse-$(PlatformTarget).pc
|
||||||
|
copy /b $(OutDir)fuse-$(PlatformTarget).pc + %(FullPath) $(OutDir)fuse-$(PlatformTarget).pc >nul</Command>
|
||||||
|
<Message Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Writing fuse-$(PlatformTarget).pc</Message>
|
||||||
|
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(OutDir)fuse-$(PlatformTarget).pc</Outputs>
|
||||||
|
<LinkObjects Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</LinkObjects>
|
||||||
|
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">echo arch=$(PlatformTarget) >$(OutDir)fuse-$(PlatformTarget).pc
|
||||||
|
copy /b $(OutDir)fuse-$(PlatformTarget).pc + %(FullPath) $(OutDir)fuse-$(PlatformTarget).pc >nul</Command>
|
||||||
|
<Message Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Writing fuse-$(PlatformTarget).pc</Message>
|
||||||
|
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(OutDir)fuse-$(PlatformTarget).pc</Outputs>
|
||||||
|
<LinkObjects Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkObjects>
|
||||||
|
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">echo arch=$(PlatformTarget) >$(OutDir)fuse-$(PlatformTarget).pc
|
||||||
|
copy /b $(OutDir)fuse-$(PlatformTarget).pc + %(FullPath) $(OutDir)fuse-$(PlatformTarget).pc >nul</Command>
|
||||||
|
<Message Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Writing fuse-$(PlatformTarget).pc</Message>
|
||||||
|
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(OutDir)fuse-$(PlatformTarget).pc</Outputs>
|
||||||
|
<LinkObjects Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</LinkObjects>
|
||||||
|
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">echo arch=$(PlatformTarget) >$(OutDir)fuse-$(PlatformTarget).pc
|
||||||
|
copy /b $(OutDir)fuse-$(PlatformTarget).pc + %(FullPath) $(OutDir)fuse-$(PlatformTarget).pc >nul</Command>
|
||||||
|
<Message Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Writing fuse-$(PlatformTarget).pc</Message>
|
||||||
|
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutDir)fuse-$(PlatformTarget).pc</Outputs>
|
||||||
|
<LinkObjects Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</LinkObjects>
|
||||||
|
</CustomBuild>
|
||||||
<None Include="..\..\src\dll\library.def" />
|
<None Include="..\..\src\dll\library.def" />
|
||||||
<None Include="..\..\src\dll\ntstatus.i" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ResourceCompile Include="..\..\src\dll\eventlog\eventlog.rc" />
|
<ResourceCompile Include="..\..\src\dll\eventlog\eventlog.rc" />
|
||||||
@ -137,7 +170,7 @@
|
|||||||
<SDLCheck>
|
<SDLCheck>
|
||||||
</SDLCheck>
|
</SDLCheck>
|
||||||
<AdditionalIncludeDirectories>..\..\src;..\..\inc</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>..\..\src;..\..\inc</AdditionalIncludeDirectories>
|
||||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||||
<BasicRuntimeChecks>Default</BasicRuntimeChecks>
|
<BasicRuntimeChecks>Default</BasicRuntimeChecks>
|
||||||
<BufferSecurityCheck>false</BufferSecurityCheck>
|
<BufferSecurityCheck>false</BufferSecurityCheck>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
@ -147,9 +180,9 @@
|
|||||||
<ProgramDatabaseFile>$(OutDir)$(TargetFileName).pdb</ProgramDatabaseFile>
|
<ProgramDatabaseFile>$(OutDir)$(TargetFileName).pdb</ProgramDatabaseFile>
|
||||||
<GenerateMapFile>true</GenerateMapFile>
|
<GenerateMapFile>true</GenerateMapFile>
|
||||||
<MapFileName>$(OutDir)$(TargetFileName).map</MapFileName>
|
<MapFileName>$(OutDir)$(TargetFileName).map</MapFileName>
|
||||||
<IgnoreAllDefaultLibraries>true</IgnoreAllDefaultLibraries>
|
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
|
||||||
<ModuleDefinitionFile>..\..\src\dll\library.def</ModuleDefinitionFile>
|
<ModuleDefinitionFile>..\..\src\dll\library.def</ModuleDefinitionFile>
|
||||||
<AdditionalDependencies>%(AdditionalDependencies);version.lib</AdditionalDependencies>
|
<AdditionalDependencies>%(AdditionalDependencies);credui.lib;version.lib</AdditionalDependencies>
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
@ -162,7 +195,7 @@
|
|||||||
<SDLCheck>
|
<SDLCheck>
|
||||||
</SDLCheck>
|
</SDLCheck>
|
||||||
<AdditionalIncludeDirectories>..\..\src;..\..\inc</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>..\..\src;..\..\inc</AdditionalIncludeDirectories>
|
||||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||||
<BasicRuntimeChecks>Default</BasicRuntimeChecks>
|
<BasicRuntimeChecks>Default</BasicRuntimeChecks>
|
||||||
<BufferSecurityCheck>false</BufferSecurityCheck>
|
<BufferSecurityCheck>false</BufferSecurityCheck>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
@ -174,7 +207,7 @@
|
|||||||
<MapFileName>$(OutDir)$(TargetFileName).map</MapFileName>
|
<MapFileName>$(OutDir)$(TargetFileName).map</MapFileName>
|
||||||
<IgnoreAllDefaultLibraries>true</IgnoreAllDefaultLibraries>
|
<IgnoreAllDefaultLibraries>true</IgnoreAllDefaultLibraries>
|
||||||
<ModuleDefinitionFile>..\..\src\dll\library.def</ModuleDefinitionFile>
|
<ModuleDefinitionFile>..\..\src\dll\library.def</ModuleDefinitionFile>
|
||||||
<AdditionalDependencies>%(AdditionalDependencies);version.lib</AdditionalDependencies>
|
<AdditionalDependencies>%(AdditionalDependencies);credui.lib;version.lib</AdditionalDependencies>
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
@ -189,7 +222,7 @@
|
|||||||
<SDLCheck>
|
<SDLCheck>
|
||||||
</SDLCheck>
|
</SDLCheck>
|
||||||
<AdditionalIncludeDirectories>..\..\src;..\..\inc</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>..\..\src;..\..\inc</AdditionalIncludeDirectories>
|
||||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||||
<BufferSecurityCheck>false</BufferSecurityCheck>
|
<BufferSecurityCheck>false</BufferSecurityCheck>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
@ -200,9 +233,9 @@
|
|||||||
<ProgramDatabaseFile>$(OutDir)$(TargetFileName).pdb</ProgramDatabaseFile>
|
<ProgramDatabaseFile>$(OutDir)$(TargetFileName).pdb</ProgramDatabaseFile>
|
||||||
<GenerateMapFile>true</GenerateMapFile>
|
<GenerateMapFile>true</GenerateMapFile>
|
||||||
<MapFileName>$(OutDir)$(TargetFileName).map</MapFileName>
|
<MapFileName>$(OutDir)$(TargetFileName).map</MapFileName>
|
||||||
<IgnoreAllDefaultLibraries>true</IgnoreAllDefaultLibraries>
|
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
|
||||||
<ModuleDefinitionFile>..\..\src\dll\library.def</ModuleDefinitionFile>
|
<ModuleDefinitionFile>..\..\src\dll\library.def</ModuleDefinitionFile>
|
||||||
<AdditionalDependencies>%(AdditionalDependencies);version.lib</AdditionalDependencies>
|
<AdditionalDependencies>%(AdditionalDependencies);credui.lib;version.lib</AdditionalDependencies>
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
@ -217,7 +250,7 @@
|
|||||||
<SDLCheck>
|
<SDLCheck>
|
||||||
</SDLCheck>
|
</SDLCheck>
|
||||||
<AdditionalIncludeDirectories>..\..\src;..\..\inc</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>..\..\src;..\..\inc</AdditionalIncludeDirectories>
|
||||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||||
<BufferSecurityCheck>false</BufferSecurityCheck>
|
<BufferSecurityCheck>false</BufferSecurityCheck>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
@ -230,7 +263,7 @@
|
|||||||
<MapFileName>$(OutDir)$(TargetFileName).map</MapFileName>
|
<MapFileName>$(OutDir)$(TargetFileName).map</MapFileName>
|
||||||
<IgnoreAllDefaultLibraries>true</IgnoreAllDefaultLibraries>
|
<IgnoreAllDefaultLibraries>true</IgnoreAllDefaultLibraries>
|
||||||
<ModuleDefinitionFile>..\..\src\dll\library.def</ModuleDefinitionFile>
|
<ModuleDefinitionFile>..\..\src\dll\library.def</ModuleDefinitionFile>
|
||||||
<AdditionalDependencies>%(AdditionalDependencies);version.lib</AdditionalDependencies>
|
<AdditionalDependencies>%(AdditionalDependencies);credui.lib;version.lib</AdditionalDependencies>
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
|
@ -15,6 +15,12 @@
|
|||||||
<Filter Include="Include\shared">
|
<Filter Include="Include\shared">
|
||||||
<UniqueIdentifier>{c7b83307-0aa0-4593-b2d4-26ff2f1edfc6}</UniqueIdentifier>
|
<UniqueIdentifier>{c7b83307-0aa0-4593-b2d4-26ff2f1edfc6}</UniqueIdentifier>
|
||||||
</Filter>
|
</Filter>
|
||||||
|
<Filter Include="Include\fuse">
|
||||||
|
<UniqueIdentifier>{0e7ab1b1-bfca-4439-accb-45a909be9cad}</UniqueIdentifier>
|
||||||
|
</Filter>
|
||||||
|
<Filter Include="Source\fuse">
|
||||||
|
<UniqueIdentifier>{518cce17-85cd-489c-b4be-920a84c1d73c}</UniqueIdentifier>
|
||||||
|
</Filter>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\..\inc\winfsp\fsctl.h">
|
<ClInclude Include="..\..\inc\winfsp\fsctl.h">
|
||||||
@ -29,6 +35,21 @@
|
|||||||
<ClInclude Include="..\..\src\shared\minimal.h">
|
<ClInclude Include="..\..\src\shared\minimal.h">
|
||||||
<Filter>Include\shared</Filter>
|
<Filter>Include\shared</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\inc\fuse\fuse.h">
|
||||||
|
<Filter>Include\fuse</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\inc\fuse\fuse_common.h">
|
||||||
|
<Filter>Include\fuse</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\inc\fuse\fuse_opt.h">
|
||||||
|
<Filter>Include\fuse</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\inc\fuse\winfsp_fuse.h">
|
||||||
|
<Filter>Include\fuse</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\dll\fuse\library.h">
|
||||||
|
<Filter>Source\fuse</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="..\..\src\dll\library.c">
|
<ClCompile Include="..\..\src\dll\library.c">
|
||||||
@ -64,11 +85,26 @@
|
|||||||
<ClCompile Include="..\..\src\dll\eventlog.c">
|
<ClCompile Include="..\..\src\dll\eventlog.c">
|
||||||
<Filter>Source</Filter>
|
<Filter>Source</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\src\dll\util.c">
|
||||||
|
<Filter>Source</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\src\dll\fuse\fuse.c">
|
||||||
|
<Filter>Source\fuse</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\src\dll\fuse\fuse_opt.c">
|
||||||
|
<Filter>Source\fuse</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\src\dll\fuse\fuse_main.c">
|
||||||
|
<Filter>Source\fuse</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\src\dll\posix.c">
|
||||||
|
<Filter>Source</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\src\dll\fuse\fuse_intf.c">
|
||||||
|
<Filter>Source\fuse</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="..\..\src\dll\ntstatus.i">
|
|
||||||
<Filter>Source</Filter>
|
|
||||||
</None>
|
|
||||||
<None Include="..\..\src\dll\library.def">
|
<None Include="..\..\src\dll\library.def">
|
||||||
<Filter>Source</Filter>
|
<Filter>Source</Filter>
|
||||||
</None>
|
</None>
|
||||||
@ -81,4 +117,7 @@
|
|||||||
<Filter>Source</Filter>
|
<Filter>Source</Filter>
|
||||||
</ResourceCompile>
|
</ResourceCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<CustomBuild Include="..\..\src\dll\fuse\fuse.pc" />
|
||||||
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
24
doc/Changelog.adoc
Normal file
24
doc/Changelog.adoc
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
= Changelog
|
||||||
|
|
||||||
|
|
||||||
|
v0.14::
|
||||||
|
|
||||||
|
This release includes support for file systems protected by credentials.
|
||||||
|
|
||||||
|
- WinFsp now supports file systems that require username/password to be unlocked (e.g. sshfs/secfs). Such file systems must add a DWORD registry value with name "Credentials" and value 1 under their WinFsp.Launcher service entry. The WinFsp network provider will then prompt for credentials using the `CredUIPromptForWindowsCredentials` API. Credentials can optionally be saved with the Windows Credential Manager.
|
||||||
|
- WinFsp-FUSE now uses the S-1-0-65534 <--> 65534 mapping for unmapped SID/UID's. The Anonymous SID mapping from the previous release had security issues.
|
||||||
|
|
||||||
|
|
||||||
|
v0.13::
|
||||||
|
|
||||||
|
This release includes a Cygwin package, an API change and some other minor changes:
|
||||||
|
|
||||||
|
- New Cygwin package includes `cygfuse-2.8.dll` and `libfuse-2.8.dll.a` for easy use in the Cygwin environment. This is currently offered as a separate download.
|
||||||
|
- Minor but breaking API change: `SetFileSize`/`SetAllocationSize` have been consolidated. Please refer to the documentation for a description of the changes.
|
||||||
|
- File system drive symbolic links (`DefineDosDeviceW`) now automatically cleaned up even if user mode file system crashes or is terminated forcefully.
|
||||||
|
- WinFsp-FUSE now maps unmapped UID's to the Anonymous SID (S-1-5-7). See: https://cygwin.com/ml/cygwin/2016-06/msg00359.html
|
||||||
|
|
||||||
|
|
||||||
|
v0.12::
|
||||||
|
|
||||||
|
Prior changes are not recorded in this Changelog.
|
10
doc/Makefile
10
doc/Makefile
@ -1,4 +1,8 @@
|
|||||||
web: web/winfsp-design.html web/service-architecture.html web/winfsp.h.html
|
web: \
|
||||||
|
web/winfsp-design.html \
|
||||||
|
web/service-architecture.html \
|
||||||
|
web/sshfs-port-case-study.html \
|
||||||
|
web/winfsp.h.html
|
||||||
|
|
||||||
web/winfsp-design.html:
|
web/winfsp-design.html:
|
||||||
mkdir -p web
|
mkdir -p web
|
||||||
@ -8,6 +12,10 @@ web/service-architecture.html:
|
|||||||
mkdir -p web
|
mkdir -p web
|
||||||
asciidoc -b html4 -a hr= -s -o $@ service-architecture.adoc
|
asciidoc -b html4 -a hr= -s -o $@ service-architecture.adoc
|
||||||
|
|
||||||
|
web/sshfs-port-case-study.html:
|
||||||
|
mkdir -p web
|
||||||
|
asciidoc -b html4 -a hr= -s -o $@ sshfs-port-case-study.adoc
|
||||||
|
|
||||||
web/winfsp.h.html:
|
web/winfsp.h.html:
|
||||||
mkdir -p web
|
mkdir -p web
|
||||||
prettydoc -H-O -o web ../inc/winfsp/winfsp.h
|
prettydoc -H-O -o web ../inc/winfsp/winfsp.h
|
||||||
|
217
doc/sshfs-port-case-study.adoc
Normal file
217
doc/sshfs-port-case-study.adoc
Normal file
@ -0,0 +1,217 @@
|
|||||||
|
= SSHFS Port Case Study
|
||||||
|
|
||||||
|
This document is a case study in porting SSHFS to Windows and WinFsp. At the time of this writing WinFsp has a native API, but no FUSE compatible API. The main purpose of this case study is to develop a FUSE compatible API for WinFsp.
|
||||||
|
|
||||||
|
== Step 1: Gather Information about SSHFS
|
||||||
|
|
||||||
|
The SSHFS project is one of the early FUSE projects. The project was originally written by Miklos Szeredi who is also the author of FUSE. SSHFS provides a file system interface on top of SFTP (Secure File Transfer Protocol).
|
||||||
|
|
||||||
|
The project's website is at https://github.com/libfuse/sshfs. A quick perusal of the source code shows that this is a POSIX program, the file `configure.ac` further shows that it depends on GLib and FUSE.
|
||||||
|
|
||||||
|
Luckily Cygwin on Windows provides a POSIX interface and it also includes GLib and pkg-config. We are missing FUSE of course. Let's try it anyway:
|
||||||
|
|
||||||
|
----
|
||||||
|
billziss@windows:~/Projects/ext$ git clone https://github.com/libfuse/sshfs.git
|
||||||
|
Cloning into 'sshfs'...
|
||||||
|
[snip]
|
||||||
|
billziss@windows:~/Projects/ext$ cd sshfs/
|
||||||
|
billziss@windows:~/Projects/ext/sshfs [master]$ autoreconf -i
|
||||||
|
[snip]
|
||||||
|
billziss@windows:~/Projects/ext/sshfs [master]$ ./configure
|
||||||
|
[snip]
|
||||||
|
configure: error: Package requirements (fuse >= 2.3 glib-2.0 gthread-2.0) were not met:
|
||||||
|
|
||||||
|
No package 'fuse' found
|
||||||
|
----
|
||||||
|
|
||||||
|
As expected we get an error because there is no package named FUSE. So let's create one.
|
||||||
|
|
||||||
|
== Step 2: Create a FUSE Compatible Package
|
||||||
|
|
||||||
|
After a few days of development there exists now an initial FUSE implementation within WinFsp. Most of the FUSE API's from the header files `fuse.h`, `fuse_common.h` and `fuse_opt.h` have been implemented. However none of the `fuse_operations` currently work as the necessary work to translate WinFsp requests to FUSE requests has not happened yet.
|
||||||
|
|
||||||
|
=== Challenges
|
||||||
|
|
||||||
|
- The FUSE API is old and somewhat hairy. There are multiple versions of it and choosing the right one was not easy. In the end version 2.8 of the API was chosen for implementation.
|
||||||
|
|
||||||
|
- The FUSE API uses a number of OS specific types (notably `struct stat`). Sometimes these types have multiple definitions even within the same OS (e.g. `struct stat` and `struct stat64`). For this reason it was decided to define our own `fuse_*` types (e.g. `struct fuse_stat`) instead of relying on the ones that come with MSVC. Care was taken to ensure that these types remain compatible with Cygwin as it is one of our primary target environments.
|
||||||
|
|
||||||
|
- The WinFsp DLL does *not* use the MSVCRT and uses its own memory allocator (`HeapAlloc`, `HeapFree`). Even if it used the MSVCRT `malloc`, it does not have access to the Cygwin `malloc`. The FUSE API has a few cases where users are expected to use `free` to deallocate memory (e.g. `fuse_opt_add_opt`). But which `free` is that for a Cygwin program? The Cygwin `free`, the MSVCRT `free` or our own `MemFree`?
|
||||||
|
+
|
||||||
|
To solve this problem we use the following pattern: every FUSE API is implemented as a `static inline` function that calls a WinFsp-FUSE API and passes it an extra argument that describes the environment:
|
||||||
|
+
|
||||||
|
----
|
||||||
|
static inline int fuse_opt_add_opt(char **opts, const char *opt)
|
||||||
|
{
|
||||||
|
return fsp_fuse_opt_add_opt(fsp_fuse_env(), opts, opt);
|
||||||
|
}
|
||||||
|
----
|
||||||
|
+
|
||||||
|
The `fsp_fuse_env` function is another `static inline` function that simply "captures" the current environment (things like the environment's `malloc` and `free`).
|
||||||
|
+
|
||||||
|
----
|
||||||
|
...
|
||||||
|
#elif defined(__CYGWIN__)
|
||||||
|
...
|
||||||
|
#define FSP_FUSE_ENV_INIT \
|
||||||
|
{ \
|
||||||
|
'C', \
|
||||||
|
malloc, free, \
|
||||||
|
fsp_fuse_daemonize, \
|
||||||
|
fsp_fuse_set_signal_handlers, \
|
||||||
|
fsp_fuse_remove_signal_handlers,\
|
||||||
|
}
|
||||||
|
...
|
||||||
|
#else
|
||||||
|
...
|
||||||
|
|
||||||
|
static inline struct fsp_fuse_env *fsp_fuse_env(void)
|
||||||
|
{
|
||||||
|
static struct fsp_fuse_env env = FSP_FUSE_ENV_INIT;
|
||||||
|
return &env;
|
||||||
|
}
|
||||||
|
----
|
||||||
|
|
||||||
|
- The implementation of `fuse_opt` proved an unexpected challenge. The function `fuse_opt_parse` is very flexible, but it also has a lot of quirks. It took a lot of trial and error to arrive at a clean reimplementation.
|
||||||
|
|
||||||
|
=== Things that worked rather nicely
|
||||||
|
|
||||||
|
- The pattern `fuse_new` / `fuse_loop` / `fuse_destroy` fits nicely to the WinFsp service model: `FspServiceCreate` / `FspServiceLoop` / `FspServiceDelete`. This means that every (high-level) FUSE file system can rather easily be converted into a Windows service if desired.
|
||||||
|
|
||||||
|
=== Integrating with Cygwin
|
||||||
|
|
||||||
|
It remains to show how to use the WinFsp-FUSE implementation from Cygwin and SSHFS. SSHFS uses `pkg-config` for its build configuration. `Pkg-config` requires a `fuse.pc` file:
|
||||||
|
|
||||||
|
----
|
||||||
|
arch=x64
|
||||||
|
prefix=${pcfiledir}/..
|
||||||
|
incdir=${prefix}/inc/fuse
|
||||||
|
implib=${prefix}/bin/winfsp-${arch}.dll
|
||||||
|
|
||||||
|
Name: fuse
|
||||||
|
Description: WinFsp FUSE compatible API
|
||||||
|
Version: 2.8
|
||||||
|
URL: http://www.secfs.net/winfsp/
|
||||||
|
Libs: "${implib}"
|
||||||
|
Cflags: -I"${incdir}"
|
||||||
|
----
|
||||||
|
|
||||||
|
The WinFsp installer has been modified to place this file within its installation directory. It remains to point `pkg-config` to the appropriate location (using `PKG_CONFIG_PATH`) and the SSHFS configuration process can now find the FUSE package.
|
||||||
|
|
||||||
|
=== SSHFS-Win
|
||||||
|
|
||||||
|
The sshfs-win open-source project (work in progress) can be found here: https://bitbucket.org/billziss/sshfs-win
|
||||||
|
|
||||||
|
== Step 3: Mapping Windows to POSIX
|
||||||
|
|
||||||
|
It would seem that we are now ready to start implementing the `fuse_operations`. However there is another matter that we need to attend to first and that is mapping the Windows file system view of the world to the POSIX one and vice-versa.
|
||||||
|
|
||||||
|
=== Mapping Paths
|
||||||
|
|
||||||
|
The Windows and POSIX file systems both use paths to address files. The path conventions are different, so we need a technique to convert between the two. This goes beyond a simple translation of the backslash character (`\`) to slash (`/`), because several characters are reserved and cannot be used in a Windows file path, but are legal when used in a POSIX path.
|
||||||
|
|
||||||
|
The reserved Windows characters are:
|
||||||
|
|
||||||
|
----
|
||||||
|
< > : " / \ | ? *
|
||||||
|
any character between 0 and 31
|
||||||
|
----
|
||||||
|
|
||||||
|
POSIX only has two reserved characters: slash (`/`) and `NUL`.
|
||||||
|
|
||||||
|
So how do we map between the two? Luckily this problem has been solved before by "Services for Macintosh" (SFM), "Services for UNIX" (SFU) and Gygwin. The solution involves the use of the Unicode "private use area". When mapping a POSIX path to Windows, if we encounter any of the Windows reserved characters we simply map it to the Unicode range U+F000 - U+F0FF. The reverse mapping from Windows to POSIX is obvious.
|
||||||
|
|
||||||
|
=== Mapping Security
|
||||||
|
|
||||||
|
Mapping Windows security to POSIX (and vice-versa) is a much more interesting (and difficult) problem. We have the following requirements:
|
||||||
|
|
||||||
|
- We need a method to map a Windows SID (Security Identifier) to a POSIX uid/gid.
|
||||||
|
- We need a method to map a Windows ACL (Access Control List) to a POSIX permission set.
|
||||||
|
- We want any mapping method we come up with to be bijective (to the extent that it is possible).
|
||||||
|
|
||||||
|
Luckily "Services for UNIX" (and Cygwin) come to the rescue again. The following Cygwin document describes in great detail a method to map a Windows SID to a POSIX uid/gid that is compatible with SFU: https://cygwin.com/cygwin-ug-net/ntsec.html. A different document from SFU describes how to map a Windows ACL to POSIX permissions: https://technet.microsoft.com/en-us/library/bb463216.aspx.
|
||||||
|
|
||||||
|
The mappings provided are not perfect, but they come pretty close. They are also proven as they have been used in SFU and Cygwin for years.
|
||||||
|
|
||||||
|
=== WinFsp Implementation
|
||||||
|
|
||||||
|
A WinFsp implementation of the above mappings can be found in the file `src/dll/posix.c`.
|
||||||
|
|
||||||
|
== Step 4: Implementing FUSE Core
|
||||||
|
|
||||||
|
We are now finally ready to implement the `fuse_operations`. This actually proves to be a straightforward mapping of the WinFSP `FSP_FILE_SYSTEM_INTERACE` to `fuse_operations`:
|
||||||
|
|
||||||
|
GetVolumeInfo:: Mapped to `statfs`. Volume labels are not supported by FUSE (see below).
|
||||||
|
|
||||||
|
SetVolumeLabel:: No equivalent on FUSE, so simply return `STATUS_INVALID_PARAMETER`. One thought is to map this call into a `setxattr("sys.VolumeLabel")` (or similar) call on the root directory (`/`).
|
||||||
|
|
||||||
|
GetSecurityByName:: Mapped to `fgetattr`/`getattr`. The returned `stat` information is translated into a Windows security descriptor using `FspPosixMapPermissionsToSecurityDescriptor`.
|
||||||
|
|
||||||
|
Create:: This is used to create a new file or directory. If a file is created this is mapped to `create` or `mknod`;`open`. If a directory is created this is mapped to `mkdir`;`opendir` calls (the reason is that on Windows a directory remains open after being created). In some circumstances a `chown` may be issued as well. After the file or directory has been created a `fgetattr`/`getattr` is issued to get `stat` information to return to the FSD.
|
||||||
|
|
||||||
|
Open:: This is used to open a new file or directory. First a `fgetattr`/`getattr` is issued. If the file is not a directory it is followed by `open`. If the file is a directory it is followed by `opendir`.
|
||||||
|
|
||||||
|
Overwrite:: This is used to overwrite a file when one of the `FILE_OVERWRITE`, `FILE_SUPERSEDE` or `FILE_OVERWRITE_IF` flags has been set. Mapped to `ftruncate`/`truncate`.
|
||||||
|
|
||||||
|
Cleanup:: Mapped to `unlink` when deleting a file and `rmdir` when deleting a directory.
|
||||||
|
|
||||||
|
Close:: Mapped to `flush`;`release` when closing a file and `releasedir` when closing a directory.
|
||||||
|
|
||||||
|
Read:: Mapped to `read`.
|
||||||
|
|
||||||
|
Write:: Mapped to `fgetattr`/`getattr` and `write`.
|
||||||
|
|
||||||
|
Flush:: Mapped to `fsync` or `fsyncdir`.
|
||||||
|
|
||||||
|
GetFileInfo:: Mapped to `fgetattr`/`getattr`.
|
||||||
|
|
||||||
|
SetBasicInfo:: Mapped to `utimens`/`utime`.
|
||||||
|
|
||||||
|
SetAllocationSize:: Mapped to `fgetattr`/`getattr` followed by `ftruncate`/`truncate`. Note that this call and `SetFileSize` may be consolidated soon in the WinFsp API.
|
||||||
|
|
||||||
|
SetFileSize:: Mapped to `fgetattr`/`getattr` followed by `ftruncate`/`truncate`. Note that this call and `SetAllocationSize` may be consolidated soon in the WinFsp API.
|
||||||
|
|
||||||
|
CanDelete:: For directories only: mapped to a `getdir`/`readdir` call to determine if they are empty and can therefore be deleted.
|
||||||
|
|
||||||
|
Rename:: Mapped to `fgetattr`/`getattr` on the destination file name and `rename`.
|
||||||
|
|
||||||
|
GetSecurity:: Mapped to `fgetattr`/`getattr`. The returned `stat` information is translated into a Windows security descriptor using `FspPosixMapPermissionsToSecurityDescriptor`.
|
||||||
|
|
||||||
|
SetSecurity:: Mapped to `fgetattr`/`getattr` followed by `chmod` and/or `chown`.
|
||||||
|
|
||||||
|
ReadDirectory:: Mapped to `getdir`/`readdir`. Note that because of how the Windows directory enumeration API's work there is a further `fgetattr`/`getattr` per file returned!
|
||||||
|
|
||||||
|
=== Some Additional Challenges
|
||||||
|
|
||||||
|
Let us now discuss a couple of final challenges in getting a proper FUSE port working under Cygwin: the implementation of `fuse_set_signal_handlers`/`fuse_remove_signal_handlers` and `fuse_daemonize`.
|
||||||
|
|
||||||
|
Let us start with `fuse_set_signal_handlers`/`fuse_remove_signal_handlers`. Cygwin supports POSIX signals and we can simply set up signal handlers similar to what libfuse does. However this simple approach does not work within WinFsp, because it uses native API's that Cygwin cannot interrupt with its signal mechanism. For example, the `fuse_loop` FUSE call eventually results in a `WaitForSingleObject` API call that Cygwin cannot interrupt. Even trying with an alertable `WaitForSingleObjectEx` did not work as unfortunately Cygwin does not issue a `QueueUserAPC` when issuing a signal. So we need an alternative mechanism to support signals.
|
||||||
|
|
||||||
|
The alternative is to use `sigwait` in a separate thread. `Fsp_fuse_signal_handler` is a WinFsp API that knows how to interrupt that `WaitForSingleObject` (actually it just signals the waited event).
|
||||||
|
|
||||||
|
----
|
||||||
|
static inline void *fsp_fuse_signal_thread(void *psigmask)
|
||||||
|
{
|
||||||
|
int sig;
|
||||||
|
|
||||||
|
if (0 == sigwait(psigmask, &sig))
|
||||||
|
fsp_fuse_signal_handler(sig);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
----
|
||||||
|
|
||||||
|
Let us now move to `fuse_daemonize`. This FUSE call allows a FUSE file system to become a (UNIX) daemon. This is achieved by using the POSIX fork call, which unfortunately has many limitations in Cygwin. One such limitation (and the one that bit us in WinFsp) is that it does not know how to clone Windows heaps (`HeapAlloc`/`HeapFree`).
|
||||||
|
|
||||||
|
Recall that WinFsp uses its own memory allocator (just a thin wrapper around `HeapAlloc`/`HeapFree`). This means that any allocations made prior to the fork() call are doomed after a fork(); with good luck the pointers will point to invalid memory and one will get an Access Violation; with bad luck the pointers will point to valid memory that contains bad data and the program may stumble for a while, just enough to hide the actual cause of the problem.
|
||||||
|
|
||||||
|
Luckily there is a rather straightforward work-around: "do not allocate any non-Cygwin resources prior to fork". This is actually possible within WinFsp, because we are already capturing the Cygwin environment and its `malloc`/`free` (see `fsp_fuse_env` in "Step 2"). It is also possible, because the typical FUSE program structure looks like this:
|
||||||
|
|
||||||
|
----
|
||||||
|
fuse_new
|
||||||
|
fuse_daemonize // do not allocate any non-Cygwin resources prior to this
|
||||||
|
fuse_loop/fuse_loop_mt // safe to allocate non-Cygwin resources
|
||||||
|
fuse_destroy
|
||||||
|
----
|
||||||
|
|
||||||
|
With this change `fuse_daemonize` works and allows me to declare the Cygwin portion of the SSHFS port complete!
|
1
ext/test
Submodule
1
ext/test
Submodule
Submodule ext/test added at a651263c4c
220
inc/fuse/fuse.h
Normal file
220
inc/fuse/fuse.h
Normal file
@ -0,0 +1,220 @@
|
|||||||
|
/**
|
||||||
|
* @file fuse/fuse.h
|
||||||
|
* WinFsp FUSE compatible API.
|
||||||
|
*
|
||||||
|
* This file is derived from libfuse/include/fuse.h:
|
||||||
|
* FUSE: Filesystem in Userspace
|
||||||
|
* Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu>
|
||||||
|
*
|
||||||
|
* @copyright 2015-2016 Bill Zissimopoulos
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* This file is part of WinFsp.
|
||||||
|
*
|
||||||
|
* You can redistribute it and/or modify it under the terms of the
|
||||||
|
* GNU Affero General Public License version 3 as published by the
|
||||||
|
* Free Software Foundation.
|
||||||
|
*
|
||||||
|
* Licensees holding a valid commercial license may use this file in
|
||||||
|
* accordance with the commercial license agreement provided with the
|
||||||
|
* software.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef FUSE_H_
|
||||||
|
#define FUSE_H_
|
||||||
|
|
||||||
|
#include "fuse_common.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct fuse;
|
||||||
|
|
||||||
|
typedef int (*fuse_fill_dir_t)(void *buf, const char *name,
|
||||||
|
const struct fuse_stat *stbuf, fuse_off_t off);
|
||||||
|
typedef struct fuse_dirhandle *fuse_dirh_t;
|
||||||
|
typedef int (*fuse_dirfil_t)(fuse_dirh_t h, const char *name,
|
||||||
|
int type, fuse_ino_t ino);
|
||||||
|
|
||||||
|
struct fuse_operations
|
||||||
|
{
|
||||||
|
int (*getattr)(const char *path, struct fuse_stat *stbuf);
|
||||||
|
int (*getdir)(const char *path, fuse_dirh_t h, fuse_dirfil_t filler);
|
||||||
|
int (*readlink)(const char *path, char *buf, size_t size);
|
||||||
|
int (*mknod)(const char *path, fuse_mode_t mode, fuse_dev_t dev);
|
||||||
|
int (*mkdir)(const char *path, fuse_mode_t mode);
|
||||||
|
int (*unlink)(const char *path);
|
||||||
|
int (*rmdir)(const char *path);
|
||||||
|
int (*symlink)(const char *dstpath, const char *srcpath);
|
||||||
|
int (*rename)(const char *oldpath, const char *newpath);
|
||||||
|
int (*link)(const char *srcpath, const char *dstpath);
|
||||||
|
int (*chmod)(const char *path, fuse_mode_t mode);
|
||||||
|
int (*chown)(const char *path, fuse_uid_t uid, fuse_gid_t gid);
|
||||||
|
int (*truncate)(const char *path, fuse_off_t size);
|
||||||
|
int (*utime)(const char *path, struct fuse_utimbuf *timbuf);
|
||||||
|
int (*open)(const char *path, struct fuse_file_info *fi);
|
||||||
|
int (*read)(const char *path, char *buf, size_t size, fuse_off_t off,
|
||||||
|
struct fuse_file_info *fi);
|
||||||
|
int (*write)(const char *path, const char *buf, size_t size, fuse_off_t off,
|
||||||
|
struct fuse_file_info *fi);
|
||||||
|
int (*statfs)(const char *path, struct fuse_statvfs *stbuf);
|
||||||
|
int (*flush)(const char *path, struct fuse_file_info *fi);
|
||||||
|
int (*release)(const char *path, struct fuse_file_info *fi);
|
||||||
|
int (*fsync)(const char *path, int datasync, struct fuse_file_info *fi);
|
||||||
|
int (*setxattr)(const char *path, const char *name, const char *value, size_t size,
|
||||||
|
int flags);
|
||||||
|
int (*getxattr)(const char *path, const char *name, char *value, size_t size);
|
||||||
|
int (*listxattr)(const char *path, char *namebuf, size_t size);
|
||||||
|
int (*removexattr)(const char *path, const char *name);
|
||||||
|
int (*opendir)(const char *path, struct fuse_file_info *fi);
|
||||||
|
int (*readdir)(const char *path, void *buf, fuse_fill_dir_t filler, fuse_off_t off,
|
||||||
|
struct fuse_file_info *fi);
|
||||||
|
int (*releasedir)(const char *path, struct fuse_file_info *fi);
|
||||||
|
int (*fsyncdir)(const char *path, int datasync, struct fuse_file_info *fi);
|
||||||
|
void *(*init)(struct fuse_conn_info *conn);
|
||||||
|
void (*destroy)(void *data);
|
||||||
|
int (*access)(const char *path, int mask);
|
||||||
|
int (*create)(const char *path, fuse_mode_t mode, struct fuse_file_info *fi);
|
||||||
|
int (*ftruncate)(const char *path, fuse_off_t off, struct fuse_file_info *fi);
|
||||||
|
int (*fgetattr)(const char *path, struct fuse_stat *stbuf, struct fuse_file_info *fi);
|
||||||
|
int (*lock)(const char *path, struct fuse_file_info *fi, int cmd, struct fuse_flock *lock);
|
||||||
|
int (*utimens)(const char *path, const struct fuse_timespec tv[2]);
|
||||||
|
int (*bmap)(const char *path, size_t blocksize, uint64_t *idx);
|
||||||
|
unsigned int flag_nullpath_ok:1;
|
||||||
|
unsigned int flag_reserved:31;
|
||||||
|
int (*ioctl)(const char *path, int cmd, void *arg, struct fuse_file_info *fi,
|
||||||
|
unsigned int flags, void *data);
|
||||||
|
int (*poll)(const char *path, struct fuse_file_info *fi,
|
||||||
|
struct fuse_pollhandle *ph, unsigned *reventsp);
|
||||||
|
};
|
||||||
|
|
||||||
|
struct fuse_context
|
||||||
|
{
|
||||||
|
struct fuse *fuse;
|
||||||
|
fuse_uid_t uid;
|
||||||
|
fuse_gid_t gid;
|
||||||
|
fuse_pid_t pid;
|
||||||
|
void *private_data;
|
||||||
|
fuse_mode_t umask;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define fuse_main(argc, argv, ops, data)\
|
||||||
|
fuse_main_real(argc, argv, ops, sizeof *(ops), data)
|
||||||
|
|
||||||
|
FSP_FUSE_API int FSP_FUSE_API_NAME(fsp_fuse_main_real)(struct fsp_fuse_env *env,
|
||||||
|
int argc, char *argv[],
|
||||||
|
const struct fuse_operations *ops, size_t opsize, void *data);
|
||||||
|
FSP_FUSE_API int FSP_FUSE_API_NAME(fsp_fuse_is_lib_option)(struct fsp_fuse_env *env,
|
||||||
|
const char *opt);
|
||||||
|
FSP_FUSE_API struct fuse *FSP_FUSE_API_NAME(fsp_fuse_new)(struct fsp_fuse_env *env,
|
||||||
|
struct fuse_chan *ch, struct fuse_args *args,
|
||||||
|
const struct fuse_operations *ops, size_t opsize, void *data);
|
||||||
|
FSP_FUSE_API void FSP_FUSE_API_NAME(fsp_fuse_destroy)(struct fsp_fuse_env *env,
|
||||||
|
struct fuse *f);
|
||||||
|
FSP_FUSE_API int FSP_FUSE_API_NAME(fsp_fuse_loop)(struct fsp_fuse_env *env,
|
||||||
|
struct fuse *f);
|
||||||
|
FSP_FUSE_API int FSP_FUSE_API_NAME(fsp_fuse_loop_mt)(struct fsp_fuse_env *env,
|
||||||
|
struct fuse *f);
|
||||||
|
FSP_FUSE_API void FSP_FUSE_API_NAME(fsp_fuse_exit)(struct fsp_fuse_env *env,
|
||||||
|
struct fuse *f);
|
||||||
|
FSP_FUSE_API struct fuse_context *FSP_FUSE_API_NAME(fsp_fuse_get_context)(struct fsp_fuse_env *env);
|
||||||
|
|
||||||
|
FSP_FUSE_SYM(
|
||||||
|
int fuse_main_real(int argc, char *argv[],
|
||||||
|
const struct fuse_operations *ops, size_t opsize, void *data),
|
||||||
|
{
|
||||||
|
return FSP_FUSE_API_CALL(fsp_fuse_main_real)
|
||||||
|
(fsp_fuse_env(), argc, argv, ops, opsize, data);
|
||||||
|
})
|
||||||
|
|
||||||
|
FSP_FUSE_SYM(
|
||||||
|
int fuse_is_lib_option(const char *opt),
|
||||||
|
{
|
||||||
|
return FSP_FUSE_API_CALL(fsp_fuse_is_lib_option)
|
||||||
|
(fsp_fuse_env(), opt);
|
||||||
|
})
|
||||||
|
|
||||||
|
FSP_FUSE_SYM(
|
||||||
|
struct fuse *fuse_new(struct fuse_chan *ch, struct fuse_args *args,
|
||||||
|
const struct fuse_operations *ops, size_t opsize, void *data),
|
||||||
|
{
|
||||||
|
return FSP_FUSE_API_CALL(fsp_fuse_new)
|
||||||
|
(fsp_fuse_env(), ch, args, ops, opsize, data);
|
||||||
|
})
|
||||||
|
|
||||||
|
FSP_FUSE_SYM(
|
||||||
|
void fuse_destroy(struct fuse *f),
|
||||||
|
{
|
||||||
|
FSP_FUSE_API_CALL(fsp_fuse_destroy)
|
||||||
|
(fsp_fuse_env(), f);
|
||||||
|
})
|
||||||
|
|
||||||
|
FSP_FUSE_SYM(
|
||||||
|
int fuse_loop(struct fuse *f),
|
||||||
|
{
|
||||||
|
return FSP_FUSE_API_CALL(fsp_fuse_loop)
|
||||||
|
(fsp_fuse_env(), f);
|
||||||
|
})
|
||||||
|
|
||||||
|
FSP_FUSE_SYM(
|
||||||
|
int fuse_loop_mt(struct fuse *f),
|
||||||
|
{
|
||||||
|
return FSP_FUSE_API_CALL(fsp_fuse_loop_mt)
|
||||||
|
(fsp_fuse_env(), f);
|
||||||
|
})
|
||||||
|
|
||||||
|
FSP_FUSE_SYM(
|
||||||
|
void fuse_exit(struct fuse *f),
|
||||||
|
{
|
||||||
|
FSP_FUSE_API_CALL(fsp_fuse_exit)
|
||||||
|
(fsp_fuse_env(), f);
|
||||||
|
})
|
||||||
|
|
||||||
|
FSP_FUSE_SYM(
|
||||||
|
struct fuse_context *fuse_get_context(void),
|
||||||
|
{
|
||||||
|
return FSP_FUSE_API_CALL(fsp_fuse_get_context)
|
||||||
|
(fsp_fuse_env());
|
||||||
|
})
|
||||||
|
|
||||||
|
FSP_FUSE_SYM(
|
||||||
|
int fuse_getgroups(int size, fuse_gid_t list[]),
|
||||||
|
{
|
||||||
|
(void)size;
|
||||||
|
(void)list;
|
||||||
|
return -ENOSYS;
|
||||||
|
})
|
||||||
|
|
||||||
|
FSP_FUSE_SYM(
|
||||||
|
int fuse_interrupted(void),
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
})
|
||||||
|
|
||||||
|
FSP_FUSE_SYM(
|
||||||
|
int fuse_invalidate(struct fuse *f, const char *path),
|
||||||
|
{
|
||||||
|
(void)f;
|
||||||
|
(void)path;
|
||||||
|
return -EINVAL;
|
||||||
|
})
|
||||||
|
|
||||||
|
FSP_FUSE_SYM(
|
||||||
|
int fuse_notify_poll(struct fuse_pollhandle *ph),
|
||||||
|
{
|
||||||
|
(void)ph;
|
||||||
|
return 0;
|
||||||
|
})
|
||||||
|
|
||||||
|
FSP_FUSE_SYM(
|
||||||
|
struct fuse_session *fuse_get_session(struct fuse *f),
|
||||||
|
{
|
||||||
|
return (struct fuse_session *)f;
|
||||||
|
})
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
149
inc/fuse/fuse_common.h
Normal file
149
inc/fuse/fuse_common.h
Normal file
@ -0,0 +1,149 @@
|
|||||||
|
/**
|
||||||
|
* @file fuse/fuse_common.h
|
||||||
|
* WinFsp FUSE compatible API.
|
||||||
|
*
|
||||||
|
* This file is derived from libfuse/include/fuse_common.h:
|
||||||
|
* FUSE: Filesystem in Userspace
|
||||||
|
* Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu>
|
||||||
|
*
|
||||||
|
* @copyright 2015-2016 Bill Zissimopoulos
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* This file is part of WinFsp.
|
||||||
|
*
|
||||||
|
* You can redistribute it and/or modify it under the terms of the
|
||||||
|
* GNU Affero General Public License version 3 as published by the
|
||||||
|
* Free Software Foundation.
|
||||||
|
*
|
||||||
|
* Licensees holding a valid commercial license may use this file in
|
||||||
|
* accordance with the commercial license agreement provided with the
|
||||||
|
* software.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef FUSE_COMMON_H_
|
||||||
|
#define FUSE_COMMON_H_
|
||||||
|
|
||||||
|
#include "winfsp_fuse.h"
|
||||||
|
#include "fuse_opt.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define FUSE_MAJOR_VERSION 2
|
||||||
|
#define FUSE_MINOR_VERSION 8
|
||||||
|
#define FUSE_MAKE_VERSION(maj, min) ((maj) * 10 + (min))
|
||||||
|
#define FUSE_VERSION FUSE_MAKE_VERSION(FUSE_MAJOR_VERSION, FUSE_MINOR_VERSION)
|
||||||
|
|
||||||
|
#define FUSE_CAP_ASYNC_READ (1 << 0)
|
||||||
|
#define FUSE_CAP_POSIX_LOCKS (1 << 1)
|
||||||
|
#define FUSE_CAP_ATOMIC_O_TRUNC (1 << 3)
|
||||||
|
#define FUSE_CAP_EXPORT_SUPPORT (1 << 4)
|
||||||
|
#define FUSE_CAP_BIG_WRITES (1 << 5)
|
||||||
|
#define FUSE_CAP_DONT_MASK (1 << 6)
|
||||||
|
|
||||||
|
#define FUSE_IOCTL_COMPAT (1 << 0)
|
||||||
|
#define FUSE_IOCTL_UNRESTRICTED (1 << 1)
|
||||||
|
#define FUSE_IOCTL_RETRY (1 << 2)
|
||||||
|
#define FUSE_IOCTL_MAX_IOV 256
|
||||||
|
|
||||||
|
struct fuse_file_info
|
||||||
|
{
|
||||||
|
int flags;
|
||||||
|
unsigned int fh_old;
|
||||||
|
int writepage;
|
||||||
|
unsigned int direct_io:1;
|
||||||
|
unsigned int keep_cache:1;
|
||||||
|
unsigned int flush:1;
|
||||||
|
unsigned int nonseekable:1;
|
||||||
|
unsigned int padding:28;
|
||||||
|
uint64_t fh;
|
||||||
|
uint64_t lock_owner;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct fuse_conn_info
|
||||||
|
{
|
||||||
|
unsigned proto_major;
|
||||||
|
unsigned proto_minor;
|
||||||
|
unsigned async_read;
|
||||||
|
unsigned max_write;
|
||||||
|
unsigned max_readahead;
|
||||||
|
unsigned capable;
|
||||||
|
unsigned want;
|
||||||
|
unsigned reserved[25];
|
||||||
|
};
|
||||||
|
|
||||||
|
struct fuse_session;
|
||||||
|
struct fuse_chan;
|
||||||
|
struct fuse_pollhandle;
|
||||||
|
|
||||||
|
FSP_FUSE_API int FSP_FUSE_API_NAME(fsp_fuse_version)(struct fsp_fuse_env *env);
|
||||||
|
FSP_FUSE_API struct fuse_chan *FSP_FUSE_API_NAME(fsp_fuse_mount)(struct fsp_fuse_env *env,
|
||||||
|
const char *mountpoint, struct fuse_args *args);
|
||||||
|
FSP_FUSE_API void FSP_FUSE_API_NAME(fsp_fuse_unmount)(struct fsp_fuse_env *env,
|
||||||
|
const char *mountpoint, struct fuse_chan *ch);
|
||||||
|
FSP_FUSE_API int FSP_FUSE_API_NAME(fsp_fuse_parse_cmdline)(struct fsp_fuse_env *env,
|
||||||
|
struct fuse_args *args,
|
||||||
|
char **mountpoint, int *multithreaded, int *foreground);
|
||||||
|
FSP_FUSE_API int32_t FSP_FUSE_API_NAME(fsp_fuse_ntstatus_from_errno)(struct fsp_fuse_env *env,
|
||||||
|
int err);
|
||||||
|
|
||||||
|
FSP_FUSE_SYM(
|
||||||
|
int fuse_version(void),
|
||||||
|
{
|
||||||
|
return FSP_FUSE_API_CALL(fsp_fuse_version)
|
||||||
|
(fsp_fuse_env());
|
||||||
|
})
|
||||||
|
|
||||||
|
FSP_FUSE_SYM(
|
||||||
|
struct fuse_chan *fuse_mount(const char *mountpoint, struct fuse_args *args),
|
||||||
|
{
|
||||||
|
return FSP_FUSE_API_CALL(fsp_fuse_mount)
|
||||||
|
(fsp_fuse_env(), mountpoint, args);
|
||||||
|
})
|
||||||
|
|
||||||
|
FSP_FUSE_SYM(
|
||||||
|
void fuse_unmount(const char *mountpoint, struct fuse_chan *ch),
|
||||||
|
{
|
||||||
|
FSP_FUSE_API_CALL(fsp_fuse_unmount)
|
||||||
|
(fsp_fuse_env(), mountpoint, ch);
|
||||||
|
})
|
||||||
|
|
||||||
|
FSP_FUSE_SYM(
|
||||||
|
int fuse_parse_cmdline(struct fuse_args *args,
|
||||||
|
char **mountpoint, int *multithreaded, int *foreground),
|
||||||
|
{
|
||||||
|
return FSP_FUSE_API_CALL(fsp_fuse_parse_cmdline)
|
||||||
|
(fsp_fuse_env(), args, mountpoint, multithreaded, foreground);
|
||||||
|
})
|
||||||
|
|
||||||
|
FSP_FUSE_SYM(
|
||||||
|
void fuse_pollhandle_destroy(struct fuse_pollhandle *ph),
|
||||||
|
{
|
||||||
|
(void)ph;
|
||||||
|
})
|
||||||
|
|
||||||
|
FSP_FUSE_SYM(
|
||||||
|
int fuse_daemonize(int foreground),
|
||||||
|
{
|
||||||
|
return fsp_fuse_daemonize(foreground);
|
||||||
|
})
|
||||||
|
|
||||||
|
FSP_FUSE_SYM(
|
||||||
|
int fuse_set_signal_handlers(struct fuse_session *se),
|
||||||
|
{
|
||||||
|
return fsp_fuse_set_signal_handlers(se);
|
||||||
|
})
|
||||||
|
|
||||||
|
FSP_FUSE_SYM(
|
||||||
|
void fuse_remove_signal_handlers(struct fuse_session *se),
|
||||||
|
{
|
||||||
|
(void)se;
|
||||||
|
fsp_fuse_set_signal_handlers(0);
|
||||||
|
})
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
129
inc/fuse/fuse_opt.h
Normal file
129
inc/fuse/fuse_opt.h
Normal file
@ -0,0 +1,129 @@
|
|||||||
|
/**
|
||||||
|
* @file fuse/fuse_opt.h
|
||||||
|
* WinFsp FUSE compatible API.
|
||||||
|
*
|
||||||
|
* This file is derived from libfuse/include/fuse_opt.h:
|
||||||
|
* FUSE: Filesystem in Userspace
|
||||||
|
* Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu>
|
||||||
|
*
|
||||||
|
* @copyright 2015-2016 Bill Zissimopoulos
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* This file is part of WinFsp.
|
||||||
|
*
|
||||||
|
* You can redistribute it and/or modify it under the terms of the
|
||||||
|
* GNU Affero General Public License version 3 as published by the
|
||||||
|
* Free Software Foundation.
|
||||||
|
*
|
||||||
|
* Licensees holding a valid commercial license may use this file in
|
||||||
|
* accordance with the commercial license agreement provided with the
|
||||||
|
* software.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef FUSE_OPT_H_
|
||||||
|
#define FUSE_OPT_H_
|
||||||
|
|
||||||
|
#include "winfsp_fuse.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define FUSE_OPT_KEY(templ, key) { templ, -1, key }
|
||||||
|
#define FUSE_OPT_END { NULL, 0, 0 }
|
||||||
|
|
||||||
|
#define FUSE_OPT_KEY_OPT -1
|
||||||
|
#define FUSE_OPT_KEY_NONOPT -2
|
||||||
|
#define FUSE_OPT_KEY_KEEP -3
|
||||||
|
#define FUSE_OPT_KEY_DISCARD -4
|
||||||
|
|
||||||
|
#define FUSE_ARGS_INIT(argc, argv) { argc, argv, 0 }
|
||||||
|
|
||||||
|
struct fuse_opt
|
||||||
|
{
|
||||||
|
const char *templ;
|
||||||
|
unsigned int offset;
|
||||||
|
int value;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct fuse_args
|
||||||
|
{
|
||||||
|
int argc;
|
||||||
|
char **argv;
|
||||||
|
int allocated;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef int (*fuse_opt_proc_t)(void *data, const char *arg, int key,
|
||||||
|
struct fuse_args *outargs);
|
||||||
|
|
||||||
|
FSP_FUSE_API int FSP_FUSE_API_NAME(fsp_fuse_opt_parse)(struct fsp_fuse_env *env,
|
||||||
|
struct fuse_args *args, void *data,
|
||||||
|
const struct fuse_opt opts[], fuse_opt_proc_t proc);
|
||||||
|
FSP_FUSE_API int FSP_FUSE_API_NAME(fsp_fuse_opt_add_arg)(struct fsp_fuse_env *env,
|
||||||
|
struct fuse_args *args, const char *arg);
|
||||||
|
FSP_FUSE_API int FSP_FUSE_API_NAME(fsp_fuse_opt_insert_arg)(struct fsp_fuse_env *env,
|
||||||
|
struct fuse_args *args, int pos, const char *arg);
|
||||||
|
FSP_FUSE_API void FSP_FUSE_API_NAME(fsp_fuse_opt_free_args)(struct fsp_fuse_env *env,
|
||||||
|
struct fuse_args *args);
|
||||||
|
FSP_FUSE_API int FSP_FUSE_API_NAME(fsp_fuse_opt_add_opt)(struct fsp_fuse_env *env,
|
||||||
|
char **opts, const char *opt);
|
||||||
|
FSP_FUSE_API int FSP_FUSE_API_NAME(fsp_fuse_opt_add_opt_escaped)(struct fsp_fuse_env *env,
|
||||||
|
char **opts, const char *opt);
|
||||||
|
FSP_FUSE_API int FSP_FUSE_API_NAME(fsp_fuse_opt_match)(struct fsp_fuse_env *env,
|
||||||
|
const struct fuse_opt opts[], const char *opt);
|
||||||
|
|
||||||
|
FSP_FUSE_SYM(
|
||||||
|
int fuse_opt_parse(struct fuse_args *args, void *data,
|
||||||
|
const struct fuse_opt opts[], fuse_opt_proc_t proc),
|
||||||
|
{
|
||||||
|
return FSP_FUSE_API_CALL(fsp_fuse_opt_parse)
|
||||||
|
(fsp_fuse_env(), args, data, opts, proc);
|
||||||
|
})
|
||||||
|
|
||||||
|
FSP_FUSE_SYM(
|
||||||
|
int fuse_opt_add_arg(struct fuse_args *args, const char *arg),
|
||||||
|
{
|
||||||
|
return FSP_FUSE_API_CALL(fsp_fuse_opt_add_arg)
|
||||||
|
(fsp_fuse_env(), args, arg);
|
||||||
|
})
|
||||||
|
|
||||||
|
FSP_FUSE_SYM(
|
||||||
|
int fuse_opt_insert_arg(struct fuse_args *args, int pos, const char *arg),
|
||||||
|
{
|
||||||
|
return FSP_FUSE_API_CALL(fsp_fuse_opt_insert_arg)
|
||||||
|
(fsp_fuse_env(), args, pos, arg);
|
||||||
|
})
|
||||||
|
|
||||||
|
FSP_FUSE_SYM(
|
||||||
|
void fuse_opt_free_args(struct fuse_args *args),
|
||||||
|
{
|
||||||
|
FSP_FUSE_API_CALL(fsp_fuse_opt_free_args)
|
||||||
|
(fsp_fuse_env(), args);
|
||||||
|
})
|
||||||
|
|
||||||
|
FSP_FUSE_SYM(
|
||||||
|
int fuse_opt_add_opt(char **opts, const char *opt),
|
||||||
|
{
|
||||||
|
return FSP_FUSE_API_CALL(fsp_fuse_opt_add_opt)
|
||||||
|
(fsp_fuse_env(), opts, opt);
|
||||||
|
})
|
||||||
|
|
||||||
|
FSP_FUSE_SYM(
|
||||||
|
int fuse_opt_add_opt_escaped(char **opts, const char *opt),
|
||||||
|
{
|
||||||
|
return FSP_FUSE_API_CALL(fsp_fuse_opt_add_opt_escaped)
|
||||||
|
(fsp_fuse_env(), opts, opt);
|
||||||
|
})
|
||||||
|
|
||||||
|
FSP_FUSE_SYM(
|
||||||
|
int fuse_opt_match(const struct fuse_opt opts[], const char *opt),
|
||||||
|
{
|
||||||
|
return FSP_FUSE_API_CALL(fsp_fuse_opt_match)
|
||||||
|
(fsp_fuse_env(), opts, opt);
|
||||||
|
})
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
364
inc/fuse/winfsp_fuse.h
Normal file
364
inc/fuse/winfsp_fuse.h
Normal file
@ -0,0 +1,364 @@
|
|||||||
|
/**
|
||||||
|
* @file fuse/winfsp_fuse.h
|
||||||
|
* WinFsp FUSE compatible API.
|
||||||
|
*
|
||||||
|
* @copyright 2015-2016 Bill Zissimopoulos
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* This file is part of WinFsp.
|
||||||
|
*
|
||||||
|
* You can redistribute it and/or modify it under the terms of the
|
||||||
|
* GNU Affero General Public License version 3 as published by the
|
||||||
|
* Free Software Foundation.
|
||||||
|
*
|
||||||
|
* Licensees holding a valid commercial license may use this file in
|
||||||
|
* accordance with the commercial license agreement provided with the
|
||||||
|
* software.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef FUSE_WINFSP_FUSE_H_INCLUDED
|
||||||
|
#define FUSE_WINFSP_FUSE_H_INCLUDED
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#if !defined(WINFSP_DLL_INTERNAL)
|
||||||
|
#include <stdlib.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !defined(FSP_FUSE_API)
|
||||||
|
#if defined(WINFSP_DLL_INTERNAL)
|
||||||
|
#define FSP_FUSE_API __declspec(dllexport)
|
||||||
|
#else
|
||||||
|
#define FSP_FUSE_API __declspec(dllimport)
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !defined(FSP_FUSE_API_NAME)
|
||||||
|
#define FSP_FUSE_API_NAME(n) (n)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !defined(FSP_FUSE_API_CALL)
|
||||||
|
#define FSP_FUSE_API_CALL(n) (n)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !defined(FSP_FUSE_SYM)
|
||||||
|
#if !defined(CYGFUSE)
|
||||||
|
#define FSP_FUSE_SYM(proto, ...) static inline proto { __VA_ARGS__ }
|
||||||
|
#else
|
||||||
|
#define FSP_FUSE_SYM(proto, ...) proto;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* FUSE uses a number of types (notably: struct stat) that are OS specific.
|
||||||
|
* Furthermore there are sometimes multiple definitions of the same type even
|
||||||
|
* within the same OS. This is certainly true on Windows, where these types
|
||||||
|
* are not even native.
|
||||||
|
*
|
||||||
|
* For this reason we will define our own fuse_* types which represent the
|
||||||
|
* types as the WinFsp DLL expects to see them. We will define these types
|
||||||
|
* to be compatible with the equivalent Cygwin types as we want WinFsp-FUSE
|
||||||
|
* to be usable from Cygwin.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(_WIN64) || defined(_WIN32)
|
||||||
|
|
||||||
|
typedef uint32_t fuse_uid_t;
|
||||||
|
typedef uint32_t fuse_gid_t;
|
||||||
|
typedef int32_t fuse_pid_t;
|
||||||
|
|
||||||
|
typedef uint32_t fuse_dev_t;
|
||||||
|
typedef uint64_t fuse_ino_t;
|
||||||
|
typedef uint32_t fuse_mode_t;
|
||||||
|
typedef uint16_t fuse_nlink_t;
|
||||||
|
typedef int64_t fuse_off_t;
|
||||||
|
|
||||||
|
#if defined(_WIN64)
|
||||||
|
typedef uint64_t fuse_fsblkcnt_t;
|
||||||
|
typedef uint64_t fuse_fsfilcnt_t;
|
||||||
|
#else
|
||||||
|
typedef uint32_t fuse_fsblkcnt_t;
|
||||||
|
typedef uint32_t fuse_fsfilcnt_t;
|
||||||
|
#endif
|
||||||
|
typedef int32_t fuse_blksize_t;
|
||||||
|
typedef int64_t fuse_blkcnt_t;
|
||||||
|
|
||||||
|
#if defined(_WIN64)
|
||||||
|
struct fuse_utimbuf
|
||||||
|
{
|
||||||
|
int64_t actime;
|
||||||
|
int64_t modtime;
|
||||||
|
};
|
||||||
|
struct fuse_timespec
|
||||||
|
{
|
||||||
|
int64_t tv_sec;
|
||||||
|
int64_t tv_nsec;
|
||||||
|
};
|
||||||
|
#else
|
||||||
|
struct fuse_utimbuf
|
||||||
|
{
|
||||||
|
int32_t actime;
|
||||||
|
int32_t modtime;
|
||||||
|
};
|
||||||
|
struct fuse_timespec
|
||||||
|
{
|
||||||
|
int32_t tv_sec;
|
||||||
|
int32_t tv_nsec;
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct fuse_stat
|
||||||
|
{
|
||||||
|
fuse_dev_t st_dev;
|
||||||
|
fuse_ino_t st_ino;
|
||||||
|
fuse_mode_t st_mode;
|
||||||
|
fuse_nlink_t st_nlink;
|
||||||
|
fuse_uid_t st_uid;
|
||||||
|
fuse_gid_t st_gid;
|
||||||
|
fuse_dev_t st_rdev;
|
||||||
|
fuse_off_t st_size;
|
||||||
|
struct fuse_timespec st_atim;
|
||||||
|
struct fuse_timespec st_mtim;
|
||||||
|
struct fuse_timespec st_ctim;
|
||||||
|
fuse_blksize_t st_blksize;
|
||||||
|
fuse_blkcnt_t st_blocks;
|
||||||
|
struct fuse_timespec st_birthtim;
|
||||||
|
};
|
||||||
|
|
||||||
|
#if defined(_WIN64)
|
||||||
|
struct fuse_statvfs
|
||||||
|
{
|
||||||
|
uint64_t f_bsize;
|
||||||
|
uint64_t f_frsize;
|
||||||
|
fuse_fsblkcnt_t f_blocks;
|
||||||
|
fuse_fsblkcnt_t f_bfree;
|
||||||
|
fuse_fsblkcnt_t f_bavail;
|
||||||
|
fuse_fsfilcnt_t f_files;
|
||||||
|
fuse_fsfilcnt_t f_ffree;
|
||||||
|
fuse_fsfilcnt_t f_favail;
|
||||||
|
uint64_t f_fsid;
|
||||||
|
uint64_t f_flag;
|
||||||
|
uint64_t f_namemax;
|
||||||
|
};
|
||||||
|
#else
|
||||||
|
struct fuse_statvfs
|
||||||
|
{
|
||||||
|
uint32_t f_bsize;
|
||||||
|
uint32_t f_frsize;
|
||||||
|
fuse_fsblkcnt_t f_blocks;
|
||||||
|
fuse_fsblkcnt_t f_bfree;
|
||||||
|
fuse_fsblkcnt_t f_bavail;
|
||||||
|
fuse_fsfilcnt_t f_files;
|
||||||
|
fuse_fsfilcnt_t f_ffree;
|
||||||
|
fuse_fsfilcnt_t f_favail;
|
||||||
|
uint32_t f_fsid;
|
||||||
|
uint32_t f_flag;
|
||||||
|
uint32_t f_namemax;
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct fuse_flock
|
||||||
|
{
|
||||||
|
int16_t l_type;
|
||||||
|
int16_t l_whence;
|
||||||
|
fuse_off_t l_start;
|
||||||
|
fuse_off_t l_len;
|
||||||
|
fuse_pid_t l_pid;
|
||||||
|
};
|
||||||
|
|
||||||
|
#if defined(WINFSP_DLL_INTERNAL)
|
||||||
|
#define FSP_FUSE_ENV_INIT \
|
||||||
|
{ \
|
||||||
|
'W', \
|
||||||
|
MemAlloc, MemFree, \
|
||||||
|
fsp_fuse_daemonize, \
|
||||||
|
fsp_fuse_set_signal_handlers, \
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
#define FSP_FUSE_ENV_INIT \
|
||||||
|
{ \
|
||||||
|
'W', \
|
||||||
|
malloc, free, \
|
||||||
|
fsp_fuse_daemonize, \
|
||||||
|
fsp_fuse_set_signal_handlers, \
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#elif defined(__CYGWIN__)
|
||||||
|
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/statvfs.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <utime.h>
|
||||||
|
|
||||||
|
#define fuse_uid_t uid_t
|
||||||
|
#define fuse_gid_t gid_t
|
||||||
|
#define fuse_pid_t pid_t
|
||||||
|
|
||||||
|
#define fuse_dev_t dev_t
|
||||||
|
#define fuse_ino_t ino_t
|
||||||
|
#define fuse_mode_t mode_t
|
||||||
|
#define fuse_nlink_t nlink_t
|
||||||
|
#define fuse_off_t off_t
|
||||||
|
|
||||||
|
#define fuse_fsblkcnt_t fsblkcnt_t
|
||||||
|
#define fuse_fsfilcnt_t fsfilcnt_t
|
||||||
|
#define fuse_blksize_t blksize_t
|
||||||
|
#define fuse_blkcnt_t blkcnt_t
|
||||||
|
|
||||||
|
#define fuse_utimbuf utimbuf
|
||||||
|
#define fuse_timespec timespec
|
||||||
|
|
||||||
|
#define fuse_stat stat
|
||||||
|
#define fuse_statvfs statvfs
|
||||||
|
#define fuse_flock flock
|
||||||
|
|
||||||
|
#define FSP_FUSE_ENV_INIT \
|
||||||
|
{ \
|
||||||
|
'C', \
|
||||||
|
malloc, free, \
|
||||||
|
fsp_fuse_daemonize, \
|
||||||
|
fsp_fuse_set_signal_handlers, \
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Note that long is 8 bytes long in Cygwin64 and 4 bytes long in Win64.
|
||||||
|
* For this reason we avoid using long anywhere in these headers.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#else
|
||||||
|
#error unsupported environment
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct fsp_fuse_env
|
||||||
|
{
|
||||||
|
unsigned environment;
|
||||||
|
void *(*memalloc)(size_t);
|
||||||
|
void (*memfree)(void *);
|
||||||
|
int (*daemonize)(int);
|
||||||
|
int (*set_signal_handlers)(void *);
|
||||||
|
void (*reserved[4])();
|
||||||
|
};
|
||||||
|
|
||||||
|
FSP_FUSE_API void FSP_FUSE_API_NAME(fsp_fuse_signal_handler)(int sig);
|
||||||
|
|
||||||
|
#if defined(_WIN64) || defined(_WIN32)
|
||||||
|
|
||||||
|
static inline int fsp_fuse_daemonize(int foreground)
|
||||||
|
{
|
||||||
|
(void)foreground;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int fsp_fuse_set_signal_handlers(void *se)
|
||||||
|
{
|
||||||
|
(void)se;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#elif defined(__CYGWIN__)
|
||||||
|
|
||||||
|
static inline int fsp_fuse_daemonize(int foreground)
|
||||||
|
{
|
||||||
|
int daemon(int nochdir, int noclose);
|
||||||
|
int chdir(const char *path);
|
||||||
|
|
||||||
|
if (!foreground)
|
||||||
|
{
|
||||||
|
if (-1 == daemon(0, 0))
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
chdir("/");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void *fsp_fuse_signal_thread(void *psigmask)
|
||||||
|
{
|
||||||
|
int sig;
|
||||||
|
|
||||||
|
if (0 == sigwait((sigset_t *)psigmask, &sig))
|
||||||
|
FSP_FUSE_API_CALL(fsp_fuse_signal_handler)(sig);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int fsp_fuse_set_signal_handlers(void *se)
|
||||||
|
{
|
||||||
|
#define FSP_FUSE_SET_SIGNAL_HANDLER(sig, newha)\
|
||||||
|
if (-1 != sigaction((sig), 0, &oldsa) &&\
|
||||||
|
oldsa.sa_handler == (se ? SIG_DFL : (newha)))\
|
||||||
|
{\
|
||||||
|
newsa.sa_handler = se ? (newha) : SIG_DFL;\
|
||||||
|
sigaction((sig), &newsa, 0);\
|
||||||
|
}
|
||||||
|
#define FSP_FUSE_SIGADDSET(sig)\
|
||||||
|
if (-1 != sigaction((sig), 0, &oldsa) &&\
|
||||||
|
oldsa.sa_handler == SIG_DFL)\
|
||||||
|
sigaddset(&sigmask, (sig));
|
||||||
|
|
||||||
|
static sigset_t sigmask;
|
||||||
|
static pthread_t sigthr;
|
||||||
|
struct sigaction oldsa, newsa = { 0 };
|
||||||
|
|
||||||
|
if (0 != se)
|
||||||
|
{
|
||||||
|
if (0 == sigthr)
|
||||||
|
{
|
||||||
|
FSP_FUSE_SET_SIGNAL_HANDLER(SIGPIPE, SIG_IGN);
|
||||||
|
|
||||||
|
sigemptyset(&sigmask);
|
||||||
|
FSP_FUSE_SIGADDSET(SIGHUP);
|
||||||
|
FSP_FUSE_SIGADDSET(SIGINT);
|
||||||
|
FSP_FUSE_SIGADDSET(SIGTERM);
|
||||||
|
if (0 != pthread_sigmask(SIG_BLOCK, &sigmask, 0))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (0 != pthread_create(&sigthr, 0, fsp_fuse_signal_thread, &sigmask))
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (0 != sigthr)
|
||||||
|
{
|
||||||
|
pthread_cancel(sigthr);
|
||||||
|
pthread_join(sigthr, 0);
|
||||||
|
sigthr = 0;
|
||||||
|
|
||||||
|
if (0 != pthread_sigmask(SIG_UNBLOCK, &sigmask, 0))
|
||||||
|
return -1;
|
||||||
|
sigemptyset(&sigmask);
|
||||||
|
|
||||||
|
FSP_FUSE_SET_SIGNAL_HANDLER(SIGPIPE, SIG_IGN);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
#undef FSP_FUSE_SIGADDSET
|
||||||
|
#undef FSP_FUSE_SET_SIGNAL_HANDLER
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
static inline struct fsp_fuse_env *fsp_fuse_env(void)
|
||||||
|
{
|
||||||
|
static struct fsp_fuse_env env = FSP_FUSE_ENV_INIT;
|
||||||
|
return &env;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
@ -258,7 +258,7 @@ typedef struct
|
|||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
FSP_FSCTL_TRANSACT_BUF NewFileName;
|
FSP_FSCTL_TRANSACT_BUF NewFileName;
|
||||||
UINT32 ReplaceIfExists:1;
|
UINT64 AccessToken; /* request access token (HANDLE) */
|
||||||
} Rename;
|
} Rename;
|
||||||
} Info;
|
} Info;
|
||||||
} SetInformation;
|
} SetInformation;
|
||||||
@ -422,6 +422,7 @@ FSP_API NTSTATUS FspFsctlTransact(HANDLE VolumeHandle,
|
|||||||
FSP_API NTSTATUS FspFsctlStop(HANDLE VolumeHandle);
|
FSP_API NTSTATUS FspFsctlStop(HANDLE VolumeHandle);
|
||||||
FSP_API NTSTATUS FspFsctlGetVolumeList(PWSTR DevicePath,
|
FSP_API NTSTATUS FspFsctlGetVolumeList(PWSTR DevicePath,
|
||||||
PWCHAR VolumeListBuf, PSIZE_T PVolumeListSize);
|
PWCHAR VolumeListBuf, PSIZE_T PVolumeListSize);
|
||||||
|
FSP_API NTSTATUS FspFsctlPreflight(PWSTR DevicePath);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -50,7 +50,7 @@ extern "C" {
|
|||||||
* FSP_FILE_SYSTEM_INTERFACE operations.
|
* FSP_FILE_SYSTEM_INTERFACE operations.
|
||||||
*/
|
*/
|
||||||
typedef struct _FSP_FILE_SYSTEM FSP_FILE_SYSTEM;
|
typedef struct _FSP_FILE_SYSTEM FSP_FILE_SYSTEM;
|
||||||
typedef VOID FSP_FILE_SYSTEM_OPERATION_GUARD(FSP_FILE_SYSTEM *,
|
typedef NTSTATUS FSP_FILE_SYSTEM_OPERATION_GUARD(FSP_FILE_SYSTEM *,
|
||||||
FSP_FSCTL_TRANSACT_REQ *, FSP_FSCTL_TRANSACT_RSP *);
|
FSP_FSCTL_TRANSACT_REQ *, FSP_FSCTL_TRANSACT_RSP *);
|
||||||
typedef NTSTATUS FSP_FILE_SYSTEM_OPERATION(FSP_FILE_SYSTEM *,
|
typedef NTSTATUS FSP_FILE_SYSTEM_OPERATION(FSP_FILE_SYSTEM *,
|
||||||
FSP_FSCTL_TRANSACT_REQ *, FSP_FSCTL_TRANSACT_RSP *);
|
FSP_FSCTL_TRANSACT_REQ *, FSP_FSCTL_TRANSACT_RSP *);
|
||||||
@ -402,41 +402,35 @@ typedef struct _FSP_FILE_SYSTEM_INTERFACE
|
|||||||
UINT64 CreationTime, UINT64 LastAccessTime, UINT64 LastWriteTime,
|
UINT64 CreationTime, UINT64 LastAccessTime, UINT64 LastWriteTime,
|
||||||
FSP_FSCTL_FILE_INFO *FileInfo);
|
FSP_FSCTL_FILE_INFO *FileInfo);
|
||||||
/**
|
/**
|
||||||
* Set file allocation size.
|
* Set file/allocation size.
|
||||||
|
*
|
||||||
|
* This function is used to change a file's sizes. Windows file systems maintain two kinds
|
||||||
|
* of sizes: the file size is where the End Of File (EOF) is, and the allocation size is the
|
||||||
|
* actual size that a file takes up on the "disk".
|
||||||
|
*
|
||||||
|
* The rules regarding file/allocation size are:
|
||||||
|
* <ul>
|
||||||
|
* <li>Allocation size must always be aligned to the allocation unit boundary. The allocation
|
||||||
|
* unit is the product <code>(UINT64)SectorSize * (UINT64)SectorsPerAllocationUnit</code> from
|
||||||
|
* the FSP_FSCTL_VOLUME_PARAMS structure. The FSD will always send properly aligned allocation
|
||||||
|
* sizes when setting the allocation size.</li>
|
||||||
|
* <li>Allocation size is always greater or equal to the file size.</li>
|
||||||
|
* <li>A file size of more than the current allocation size will also extend the allocation
|
||||||
|
* size to the next allocation unit boundary.</li>
|
||||||
|
* <li>An allocation size of less than the current file size should also truncate the current
|
||||||
|
* file size.</li>
|
||||||
|
* </ul>
|
||||||
*
|
*
|
||||||
* @param FileSystem
|
* @param FileSystem
|
||||||
* The file system on which this request is posted.
|
* The file system on which this request is posted.
|
||||||
* @param Request
|
* @param Request
|
||||||
* The request posted by the kernel mode FSD.
|
* The request posted by the kernel mode FSD.
|
||||||
* @param FileNode
|
* @param FileNode
|
||||||
* The file node of the file to set the allocation size for.
|
* The file node of the file to set the file/allocation size for.
|
||||||
* @param AllocationSize
|
* @param NewSize
|
||||||
* Allocation size to apply to the file. Allocation size is always greater than file size.
|
* New file/allocation size to apply to the file.
|
||||||
* An allocation size of less than the current file size should also truncate the current
|
* @param SetAllocationSize
|
||||||
* file size.
|
* If TRUE, then the allocation size is being set. if FALSE, then the file size is being set.
|
||||||
* @param FileInfo [out]
|
|
||||||
* Pointer to a structure that will receive the file information on successful return
|
|
||||||
* from this call. This information includes file attributes, file times, etc.
|
|
||||||
* @return
|
|
||||||
* STATUS_SUCCESS on error code.
|
|
||||||
*/
|
|
||||||
NTSTATUS (*SetAllocationSize)(FSP_FILE_SYSTEM *FileSystem,
|
|
||||||
FSP_FSCTL_TRANSACT_REQ *Request,
|
|
||||||
PVOID FileNode, UINT64 AllocationSize,
|
|
||||||
FSP_FSCTL_FILE_INFO *FileInfo);
|
|
||||||
/**
|
|
||||||
* Set file size.
|
|
||||||
*
|
|
||||||
* @param FileSystem
|
|
||||||
* The file system on which this request is posted.
|
|
||||||
* @param Request
|
|
||||||
* The request posted by the kernel mode FSD.
|
|
||||||
* @param FileNode
|
|
||||||
* The file node of the file to set the size for.
|
|
||||||
* @param FileSize
|
|
||||||
* FileSize size to apply to the file. Allocation size is always greater than file size.
|
|
||||||
* A file size of more than the current allocation size will also extend the allocation
|
|
||||||
* size to the next allocation unit boundary.
|
|
||||||
* @param FileInfo [out]
|
* @param FileInfo [out]
|
||||||
* Pointer to a structure that will receive the file information on successful return
|
* Pointer to a structure that will receive the file information on successful return
|
||||||
* from this call. This information includes file attributes, file times, etc.
|
* from this call. This information includes file attributes, file times, etc.
|
||||||
@ -445,7 +439,7 @@ typedef struct _FSP_FILE_SYSTEM_INTERFACE
|
|||||||
*/
|
*/
|
||||||
NTSTATUS (*SetFileSize)(FSP_FILE_SYSTEM *FileSystem,
|
NTSTATUS (*SetFileSize)(FSP_FILE_SYSTEM *FileSystem,
|
||||||
FSP_FSCTL_TRANSACT_REQ *Request,
|
FSP_FSCTL_TRANSACT_REQ *Request,
|
||||||
PVOID FileNode, UINT64 FileSize,
|
PVOID FileNode, UINT64 NewSize, BOOLEAN SetAllocationSize,
|
||||||
FSP_FSCTL_FILE_INFO *FileInfo);
|
FSP_FSCTL_FILE_INFO *FileInfo);
|
||||||
/**
|
/**
|
||||||
* Determine whether a file or directory can be deleted.
|
* Determine whether a file or directory can be deleted.
|
||||||
@ -454,6 +448,12 @@ typedef struct _FSP_FILE_SYSTEM_INTERFACE
|
|||||||
* not need to perform access checks, but may performs tasks such as check for empty
|
* not need to perform access checks, but may performs tasks such as check for empty
|
||||||
* directories, etc.
|
* directories, etc.
|
||||||
*
|
*
|
||||||
|
* This function should <b>NEVER</b> delete the file or directory in question. Deletion should
|
||||||
|
* happen during Cleanup with Delete==TRUE.
|
||||||
|
*
|
||||||
|
* This function gets called when Win32 API's such as DeleteFile or RemoveDirectory are used.
|
||||||
|
* It does not get called when a file or directory is opened with FILE_DELETE_ON_CLOSE.
|
||||||
|
*
|
||||||
* @param FileSystem
|
* @param FileSystem
|
||||||
* The file system on which this request is posted.
|
* The file system on which this request is posted.
|
||||||
* @param Request
|
* @param Request
|
||||||
@ -576,7 +576,26 @@ typedef struct _FSP_FILE_SYSTEM_INTERFACE
|
|||||||
PVOID FileNode, PVOID Buffer, UINT64 Offset, ULONG Length,
|
PVOID FileNode, PVOID Buffer, UINT64 Offset, ULONG Length,
|
||||||
PWSTR Pattern,
|
PWSTR Pattern,
|
||||||
PULONG PBytesTransferred);
|
PULONG PBytesTransferred);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This ensures that this interface will always contain 64 function pointers.
|
||||||
|
* Please update when changing the interface as it is important for future compatibility.
|
||||||
|
*/
|
||||||
|
NTSTATUS (*Reserved[45])();
|
||||||
} FSP_FILE_SYSTEM_INTERFACE;
|
} FSP_FILE_SYSTEM_INTERFACE;
|
||||||
|
#if defined(WINFSP_DLL_INTERNAL)
|
||||||
|
/*
|
||||||
|
* Static_assert is a C++11 feature, but seems to work with C on MSVC 2015.
|
||||||
|
* Use it to verify that FSP_FILE_SYSTEM_INTERFACE has the right size.
|
||||||
|
*/
|
||||||
|
static_assert(sizeof(FSP_FILE_SYSTEM_INTERFACE) == 64 * sizeof(NTSTATUS (*)()),
|
||||||
|
"FSP_FILE_SYSTEM_INTERFACE must have 64 entries.");
|
||||||
|
#endif
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
FSP_FILE_SYSTEM_OPERATION_GUARD_STRATEGY_FINE = 0,
|
||||||
|
FSP_FILE_SYSTEM_OPERATION_GUARD_STRATEGY_COARSE,
|
||||||
|
} FSP_FILE_SYSTEM_OPERATION_GUARD_STRATEGY;
|
||||||
typedef struct _FSP_FILE_SYSTEM
|
typedef struct _FSP_FILE_SYSTEM
|
||||||
{
|
{
|
||||||
UINT16 Version;
|
UINT16 Version;
|
||||||
@ -590,7 +609,10 @@ typedef struct _FSP_FILE_SYSTEM
|
|||||||
ULONG DispatcherThreadCount;
|
ULONG DispatcherThreadCount;
|
||||||
NTSTATUS DispatcherResult;
|
NTSTATUS DispatcherResult;
|
||||||
PWSTR MountPoint;
|
PWSTR MountPoint;
|
||||||
LIST_ENTRY MountEntry;
|
HANDLE MountHandle;
|
||||||
|
UINT32 DebugLog;
|
||||||
|
FSP_FILE_SYSTEM_OPERATION_GUARD_STRATEGY OpGuardStrategy;
|
||||||
|
SRWLOCK OpGuardLock;
|
||||||
} FSP_FILE_SYSTEM;
|
} FSP_FILE_SYSTEM;
|
||||||
/**
|
/**
|
||||||
* Create a file system object.
|
* Create a file system object.
|
||||||
@ -693,18 +715,22 @@ PWSTR FspFileSystemMountPoint(FSP_FILE_SYSTEM *FileSystem)
|
|||||||
return FileSystem->MountPoint;
|
return FileSystem->MountPoint;
|
||||||
}
|
}
|
||||||
static inline
|
static inline
|
||||||
VOID FspFileSystemEnterOperation(FSP_FILE_SYSTEM *FileSystem,
|
NTSTATUS FspFileSystemEnterOperation(FSP_FILE_SYSTEM *FileSystem,
|
||||||
FSP_FSCTL_TRANSACT_REQ *Request, FSP_FSCTL_TRANSACT_RSP *Response)
|
FSP_FSCTL_TRANSACT_REQ *Request, FSP_FSCTL_TRANSACT_RSP *Response)
|
||||||
{
|
{
|
||||||
if (0 != FileSystem->EnterOperation)
|
if (0 == FileSystem->EnterOperation)
|
||||||
FileSystem->EnterOperation(FileSystem, Request, Response);
|
return STATUS_SUCCESS;
|
||||||
|
|
||||||
|
return FileSystem->EnterOperation(FileSystem, Request, Response);
|
||||||
}
|
}
|
||||||
static inline
|
static inline
|
||||||
VOID FspFileSystemLeaveOperation(FSP_FILE_SYSTEM *FileSystem,
|
NTSTATUS FspFileSystemLeaveOperation(FSP_FILE_SYSTEM *FileSystem,
|
||||||
FSP_FSCTL_TRANSACT_REQ *Request, FSP_FSCTL_TRANSACT_RSP *Response)
|
FSP_FSCTL_TRANSACT_REQ *Request, FSP_FSCTL_TRANSACT_RSP *Response)
|
||||||
{
|
{
|
||||||
if (0 != FileSystem->LeaveOperation)
|
if (0 == FileSystem->LeaveOperation)
|
||||||
FileSystem->LeaveOperation(FileSystem, Request, Response);
|
return STATUS_SUCCESS;
|
||||||
|
|
||||||
|
return FileSystem->LeaveOperation(FileSystem, Request, Response);
|
||||||
}
|
}
|
||||||
static inline
|
static inline
|
||||||
VOID FspFileSystemSetOperationGuard(FSP_FILE_SYSTEM *FileSystem,
|
VOID FspFileSystemSetOperationGuard(FSP_FILE_SYSTEM *FileSystem,
|
||||||
@ -715,6 +741,12 @@ VOID FspFileSystemSetOperationGuard(FSP_FILE_SYSTEM *FileSystem,
|
|||||||
FileSystem->LeaveOperation = LeaveOperation;
|
FileSystem->LeaveOperation = LeaveOperation;
|
||||||
}
|
}
|
||||||
static inline
|
static inline
|
||||||
|
VOID FspFileSystemSetOperationGuardStrategy(FSP_FILE_SYSTEM *FileSystem,
|
||||||
|
FSP_FILE_SYSTEM_OPERATION_GUARD_STRATEGY GuardStrategy)
|
||||||
|
{
|
||||||
|
FileSystem->OpGuardStrategy = GuardStrategy;
|
||||||
|
}
|
||||||
|
static inline
|
||||||
VOID FspFileSystemSetOperation(FSP_FILE_SYSTEM *FileSystem,
|
VOID FspFileSystemSetOperation(FSP_FILE_SYSTEM *FileSystem,
|
||||||
ULONG Index,
|
ULONG Index,
|
||||||
FSP_FILE_SYSTEM_OPERATION *Operation)
|
FSP_FILE_SYSTEM_OPERATION *Operation)
|
||||||
@ -737,10 +769,20 @@ VOID FspFileSystemSetDispatcherResult(FSP_FILE_SYSTEM *FileSystem,
|
|||||||
return;
|
return;
|
||||||
InterlockedCompareExchange(&FileSystem->DispatcherResult, DispatcherResult, 0);
|
InterlockedCompareExchange(&FileSystem->DispatcherResult, DispatcherResult, 0);
|
||||||
}
|
}
|
||||||
|
static inline
|
||||||
|
VOID FspFileSystemSetDebugLog(FSP_FILE_SYSTEM *FileSystem,
|
||||||
|
UINT32 DebugLog)
|
||||||
|
{
|
||||||
|
FileSystem->DebugLog = DebugLog;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Operations
|
* Operations
|
||||||
*/
|
*/
|
||||||
|
FSP_API NTSTATUS FspFileSystemOpEnter(FSP_FILE_SYSTEM *FileSystem,
|
||||||
|
FSP_FSCTL_TRANSACT_REQ *Request, FSP_FSCTL_TRANSACT_RSP *Response);
|
||||||
|
FSP_API NTSTATUS FspFileSystemOpLeave(FSP_FILE_SYSTEM *FileSystem,
|
||||||
|
FSP_FSCTL_TRANSACT_REQ *Request, FSP_FSCTL_TRANSACT_RSP *Response);
|
||||||
FSP_API NTSTATUS FspFileSystemOpCreate(FSP_FILE_SYSTEM *FileSystem,
|
FSP_API NTSTATUS FspFileSystemOpCreate(FSP_FILE_SYSTEM *FileSystem,
|
||||||
FSP_FSCTL_TRANSACT_REQ *Request, FSP_FSCTL_TRANSACT_RSP *Response);
|
FSP_FSCTL_TRANSACT_REQ *Request, FSP_FSCTL_TRANSACT_RSP *Response);
|
||||||
FSP_API NTSTATUS FspFileSystemOpOverwrite(FSP_FILE_SYSTEM *FileSystem,
|
FSP_API NTSTATUS FspFileSystemOpOverwrite(FSP_FILE_SYSTEM *FileSystem,
|
||||||
@ -831,6 +873,22 @@ NTSTATUS FspAccessCheck(FSP_FILE_SYSTEM *FileSystem,
|
|||||||
0);
|
0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* POSIX Interop
|
||||||
|
*/
|
||||||
|
FSP_API NTSTATUS FspPosixMapUidToSid(UINT32 Uid, PSID *PSid);
|
||||||
|
FSP_API NTSTATUS FspPosixMapSidToUid(PSID Sid, PUINT32 PUid);
|
||||||
|
FSP_API VOID FspDeleteSid(PSID Sid, NTSTATUS (*CreateFunc)());
|
||||||
|
FSP_API NTSTATUS FspPosixMapPermissionsToSecurityDescriptor(
|
||||||
|
UINT32 Uid, UINT32 Gid, UINT32 Mode,
|
||||||
|
PSECURITY_DESCRIPTOR *PSecurityDescriptor);
|
||||||
|
FSP_API NTSTATUS FspPosixMapSecurityDescriptorToPermissions(
|
||||||
|
PSECURITY_DESCRIPTOR SecurityDescriptor,
|
||||||
|
PUINT32 PUid, PUINT32 PGid, PUINT32 PMode);
|
||||||
|
FSP_API NTSTATUS FspPosixMapWindowsToPosixPath(PWSTR WindowsPath, char **PPosixPath);
|
||||||
|
FSP_API NTSTATUS FspPosixMapPosixToWindowsPath(const char *PosixPath, PWSTR *PWindowsPath);
|
||||||
|
FSP_API VOID FspPosixDeletePath(void *Path);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Path Handling
|
* Path Handling
|
||||||
*/
|
*/
|
||||||
@ -887,10 +945,19 @@ typedef struct _FSP_SERVICE
|
|||||||
* @return
|
* @return
|
||||||
* Service process exit code.
|
* Service process exit code.
|
||||||
*/
|
*/
|
||||||
FSP_API ULONG FspServiceRun(PWSTR ServiceName,
|
FSP_API ULONG FspServiceRunEx(PWSTR ServiceName,
|
||||||
FSP_SERVICE_START *OnStart,
|
FSP_SERVICE_START *OnStart,
|
||||||
FSP_SERVICE_STOP *OnStop,
|
FSP_SERVICE_STOP *OnStop,
|
||||||
FSP_SERVICE_CONTROL *OnControl);
|
FSP_SERVICE_CONTROL *OnControl,
|
||||||
|
PVOID UserContext);
|
||||||
|
static inline
|
||||||
|
ULONG FspServiceRun(PWSTR ServiceName,
|
||||||
|
FSP_SERVICE_START *OnStart,
|
||||||
|
FSP_SERVICE_STOP *OnStop,
|
||||||
|
FSP_SERVICE_CONTROL *OnControl)
|
||||||
|
{
|
||||||
|
return FspServiceRunEx(ServiceName, OnStart, OnStop, OnControl, 0);
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Create a service object.
|
* Create a service object.
|
||||||
*
|
*
|
||||||
@ -1034,6 +1101,8 @@ FSP_API VOID FspEventLogV(ULONG Type, PWSTR Format, va_list ap);
|
|||||||
FSP_API VOID FspDebugLog(const char *format, ...);
|
FSP_API VOID FspDebugLog(const char *format, ...);
|
||||||
FSP_API VOID FspDebugLogSD(const char *format, PSECURITY_DESCRIPTOR SecurityDescriptor);
|
FSP_API VOID FspDebugLogSD(const char *format, PSECURITY_DESCRIPTOR SecurityDescriptor);
|
||||||
FSP_API VOID FspDebugLogFT(const char *format, PFILETIME FileTime);
|
FSP_API VOID FspDebugLogFT(const char *format, PFILETIME FileTime);
|
||||||
|
FSP_API VOID FspDebugLogRequest(FSP_FSCTL_TRANSACT_REQ *Request);
|
||||||
|
FSP_API VOID FspDebugLogResponse(FSP_FSCTL_TRANSACT_RSP *Response);
|
||||||
FSP_API NTSTATUS FspCallNamedPipeSecurely(PWSTR PipeName,
|
FSP_API NTSTATUS FspCallNamedPipeSecurely(PWSTR PipeName,
|
||||||
PVOID InBuffer, ULONG InBufferSize, PVOID OutBuffer, ULONG OutBufferSize,
|
PVOID InBuffer, ULONG InBufferSize, PVOID OutBuffer, ULONG OutBufferSize,
|
||||||
PULONG PBytesTransferred, ULONG Timeout,
|
PULONG PBytesTransferred, ULONG Timeout,
|
||||||
|
20
opt/cygfuse/Makefile
Normal file
20
opt/cygfuse/Makefile
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
Version = $(shell sed -n '/^VERSION=/s/VERSION=\(.*\)/\1/p' fuse.cygport)
|
||||||
|
#Debug = -g
|
||||||
|
|
||||||
|
cygfuse-$(Version).dll libfuse-$(Version).dll.a fuse.pc: cygfuse.c fuse.pc.in
|
||||||
|
gcc $(Debug) -shared -o cygfuse-$(Version).dll -Wl,--out-implib=libfuse-$(Version).dll.a -I../../inc/fuse cygfuse.c
|
||||||
|
[ -n "$(Debug)" ] || strip cygfuse-$(Version).dll
|
||||||
|
sed "s/@Version@/$(Version)/g" fuse.pc.in > fuse.pc
|
||||||
|
|
||||||
|
cygfuse-test.exe: cygfuse-test.c cygfuse-$(Version).dll libfuse-$(Version).dll.a
|
||||||
|
gcc $(Debug) -o cygfuse-test.exe -I../../inc/fuse -DCYGFUSE cygfuse-test.c -L$(PWD) -lfuse-$(Version)
|
||||||
|
|
||||||
|
cygport:
|
||||||
|
git clean -dfx
|
||||||
|
(\
|
||||||
|
cd `git rev-parse --show-toplevel` &&\
|
||||||
|
Stash=`git stash create` &&\
|
||||||
|
git archive --prefix=winfsp-work/ --format=tar.gz $${Stash:-HEAD}\
|
||||||
|
> opt/cygfuse/winfsp-work.tar.gz\
|
||||||
|
)
|
||||||
|
CYGPORT_SRC_URI=winfsp-work.tar.gz CYGPORT_SRC_DIR=winfsp-work cygport fuse.cygport download prep compile install package
|
6
opt/cygfuse/cygfuse-test.c
Normal file
6
opt/cygfuse/cygfuse-test.c
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#include <fuse.h>
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
return !(FUSE_VERSION == fuse_version());
|
||||||
|
}
|
146
opt/cygfuse/cygfuse.c
Normal file
146
opt/cygfuse/cygfuse.c
Normal file
@ -0,0 +1,146 @@
|
|||||||
|
/**
|
||||||
|
* @file cygfuse/cygfuse.c
|
||||||
|
*
|
||||||
|
* @copyright 2015-2016 Bill Zissimopoulos
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* This file is part of WinFsp.
|
||||||
|
*
|
||||||
|
* You can redistribute it and/or modify it under the terms of the
|
||||||
|
* GNU Affero General Public License version 3 as published by the
|
||||||
|
* Free Software Foundation.
|
||||||
|
*
|
||||||
|
* Licensees holding a valid commercial license may use this file in
|
||||||
|
* accordance with the commercial license agreement provided with the
|
||||||
|
* software.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <dlfcn.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/cygwin.h>
|
||||||
|
|
||||||
|
static void *cygfuse_init_winfsp();
|
||||||
|
static void *cygfuse_init_fail();
|
||||||
|
|
||||||
|
static pthread_mutex_t cygfuse_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
static void *cygfuse_handle = 0;
|
||||||
|
|
||||||
|
static inline void cygfuse_init(int force)
|
||||||
|
{
|
||||||
|
pthread_mutex_lock(&cygfuse_mutex);
|
||||||
|
if (force || 0 == cygfuse_handle)
|
||||||
|
cygfuse_handle = cygfuse_init_winfsp();
|
||||||
|
pthread_mutex_unlock(&cygfuse_mutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Unfortunately Cygwin fork is very fragile and cannot even correctly
|
||||||
|
* handle dlopen'ed DLL's if they are native (rather than Cygwin ones).
|
||||||
|
*
|
||||||
|
* So we have this very nasty hack where we reset the dlopen'ed handle
|
||||||
|
* immediately after daemonization. This will force cygfuse_init() to
|
||||||
|
* reload the WinFsp DLL and reset all API pointers in the daemonized
|
||||||
|
* process.
|
||||||
|
*/
|
||||||
|
static inline int cygfuse_daemon(int nochdir, int noclose)
|
||||||
|
{
|
||||||
|
if (-1 == daemon(nochdir, noclose))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
/* force reload of WinFsp DLL to workaround fork() problems */
|
||||||
|
cygfuse_init(1);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#define daemon cygfuse_daemon
|
||||||
|
|
||||||
|
#define FSP_FUSE_API static
|
||||||
|
#define FSP_FUSE_API_NAME(api) (* pfn_ ## api)
|
||||||
|
#define FSP_FUSE_API_CALL(api) (cygfuse_init(0), pfn_ ## api)
|
||||||
|
#define FSP_FUSE_SYM(proto, ...) __attribute__ ((visibility("default"))) proto { __VA_ARGS__ }
|
||||||
|
#include <fuse_common.h>
|
||||||
|
#include <fuse.h>
|
||||||
|
#include <fuse_opt.h>
|
||||||
|
|
||||||
|
#if defined(__LP64__)
|
||||||
|
#define CYGFUSE_WINFSP_NAME "winfsp-x64.dll"
|
||||||
|
#else
|
||||||
|
#define CYGFUSE_WINFSP_NAME "winfsp-x86.dll"
|
||||||
|
#endif
|
||||||
|
#define CYGFUSE_WINFSP_PATH "bin\\" CYGFUSE_WINFSP_NAME
|
||||||
|
#define CYGFUSE_GET_API(h, n) \
|
||||||
|
if (0 == (*(void **)&(pfn_ ## n) = dlsym(h, #n)))\
|
||||||
|
return cygfuse_init_fail();
|
||||||
|
|
||||||
|
static void *cygfuse_init_winfsp()
|
||||||
|
{
|
||||||
|
void *h;
|
||||||
|
|
||||||
|
h = dlopen(CYGFUSE_WINFSP_NAME, RTLD_NOW);
|
||||||
|
if (0 == h)
|
||||||
|
{
|
||||||
|
char winpath[260], *psxpath;
|
||||||
|
int regfd, bytes;
|
||||||
|
|
||||||
|
regfd = open("/proc/registry32/HKEY_LOCAL_MACHINE/Software/WinFsp/InstallDir", O_RDONLY);
|
||||||
|
if (-1 == regfd)
|
||||||
|
return cygfuse_init_fail();
|
||||||
|
|
||||||
|
bytes = read(regfd, winpath, sizeof winpath - sizeof CYGFUSE_WINFSP_PATH);
|
||||||
|
close(regfd);
|
||||||
|
if (-1 == bytes || 0 == bytes)
|
||||||
|
return cygfuse_init_fail();
|
||||||
|
|
||||||
|
if ('\0' == winpath[bytes - 1])
|
||||||
|
bytes--;
|
||||||
|
memcpy(winpath + bytes, CYGFUSE_WINFSP_PATH, sizeof CYGFUSE_WINFSP_PATH);
|
||||||
|
|
||||||
|
psxpath = (char *)cygwin_create_path(CCP_WIN_A_TO_POSIX | CCP_PROC_CYGDRIVE, winpath);
|
||||||
|
if (0 == psxpath)
|
||||||
|
return cygfuse_init_fail();
|
||||||
|
|
||||||
|
h = dlopen(psxpath, RTLD_NOW);
|
||||||
|
free(psxpath);
|
||||||
|
if (0 == h)
|
||||||
|
return cygfuse_init_fail();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* winfsp_fuse.h */
|
||||||
|
CYGFUSE_GET_API(h, fsp_fuse_signal_handler);
|
||||||
|
|
||||||
|
/* fuse_common.h */
|
||||||
|
CYGFUSE_GET_API(h, fsp_fuse_version);
|
||||||
|
CYGFUSE_GET_API(h, fsp_fuse_mount);
|
||||||
|
CYGFUSE_GET_API(h, fsp_fuse_unmount);
|
||||||
|
CYGFUSE_GET_API(h, fsp_fuse_parse_cmdline);
|
||||||
|
CYGFUSE_GET_API(h, fsp_fuse_ntstatus_from_errno);
|
||||||
|
|
||||||
|
/* fuse.h */
|
||||||
|
CYGFUSE_GET_API(h, fsp_fuse_main_real);
|
||||||
|
CYGFUSE_GET_API(h, fsp_fuse_is_lib_option);
|
||||||
|
CYGFUSE_GET_API(h, fsp_fuse_new);
|
||||||
|
CYGFUSE_GET_API(h, fsp_fuse_destroy);
|
||||||
|
CYGFUSE_GET_API(h, fsp_fuse_loop);
|
||||||
|
CYGFUSE_GET_API(h, fsp_fuse_loop_mt);
|
||||||
|
CYGFUSE_GET_API(h, fsp_fuse_exit);
|
||||||
|
CYGFUSE_GET_API(h, fsp_fuse_get_context);
|
||||||
|
|
||||||
|
/* fuse_opt.h */
|
||||||
|
CYGFUSE_GET_API(h, fsp_fuse_opt_parse);
|
||||||
|
CYGFUSE_GET_API(h, fsp_fuse_opt_add_arg);
|
||||||
|
CYGFUSE_GET_API(h, fsp_fuse_opt_insert_arg);
|
||||||
|
CYGFUSE_GET_API(h, fsp_fuse_opt_free_args);
|
||||||
|
CYGFUSE_GET_API(h, fsp_fuse_opt_add_opt);
|
||||||
|
CYGFUSE_GET_API(h, fsp_fuse_opt_add_opt_escaped);
|
||||||
|
CYGFUSE_GET_API(h, fsp_fuse_opt_match);
|
||||||
|
|
||||||
|
return h;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void *cygfuse_init_fail()
|
||||||
|
{
|
||||||
|
abort();
|
||||||
|
return 0;
|
||||||
|
}
|
35
opt/cygfuse/fuse.cygport
Normal file
35
opt/cygfuse/fuse.cygport
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
NAME="fuse"
|
||||||
|
VERSION=2.8
|
||||||
|
RELEASE=3
|
||||||
|
CATEGORY="Utils"
|
||||||
|
SUMMARY="WinFsp-FUSE compatibility layer"
|
||||||
|
DESCRIPTION="WinFsp-FUSE enables FUSE file systems to be run on Cygwin."
|
||||||
|
HOMEPAGE="http://www.secfs.net/winfsp/"
|
||||||
|
|
||||||
|
SRC_URI=${CYGPORT_SRC_URI:-"https://github.com/billziss-gh/winfsp/archive/master.tar.gz"}
|
||||||
|
SRC_DIR=${CYGPORT_SRC_DIR:-winfsp-master}
|
||||||
|
|
||||||
|
src_compile()
|
||||||
|
{
|
||||||
|
lndirs
|
||||||
|
cd ${B}/opt/cygfuse
|
||||||
|
make
|
||||||
|
}
|
||||||
|
|
||||||
|
src_install()
|
||||||
|
{
|
||||||
|
cd ${B}/inc/fuse
|
||||||
|
includeinto fuse
|
||||||
|
doinclude fuse.h
|
||||||
|
doinclude fuse_common.h
|
||||||
|
doinclude fuse_opt.h
|
||||||
|
doinclude winfsp_fuse.h
|
||||||
|
|
||||||
|
cd ${B}/opt/cygfuse
|
||||||
|
dobin cygfuse-${VERSION}.dll
|
||||||
|
dolib libfuse-${VERSION}.dll.a
|
||||||
|
dosym libfuse-${VERSION}.dll.a /usr/lib/libfuse.dll.a
|
||||||
|
dopkgconfig fuse.pc
|
||||||
|
}
|
||||||
|
|
||||||
|
RESTRICT="strip postinst-doc"
|
9
opt/cygfuse/fuse.pc.in
Normal file
9
opt/cygfuse/fuse.pc.in
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
prefix=/usr
|
||||||
|
incdir=${prefix}/include/fuse
|
||||||
|
|
||||||
|
Name: fuse
|
||||||
|
Description: WinFsp FUSE compatible API
|
||||||
|
Version: @Version@
|
||||||
|
URL: http://www.secfs.net/winfsp/
|
||||||
|
Libs: -lfuse-@Version@
|
||||||
|
Cflags: -I"${incdir}" -DCYGFUSE
|
587
src/dll/debug.c
587
src/dll/debug.c
@ -37,7 +37,8 @@ FSP_API VOID FspDebugLogSD(const char *format, PSECURITY_DESCRIPTOR SecurityDesc
|
|||||||
|
|
||||||
if (0 == SecurityDescriptor)
|
if (0 == SecurityDescriptor)
|
||||||
FspDebugLog(format, "null security descriptor");
|
FspDebugLog(format, "null security descriptor");
|
||||||
else if (ConvertSecurityDescriptorToStringSecurityDescriptorA(SecurityDescriptor, SDDL_REVISION_1,
|
else if (ConvertSecurityDescriptorToStringSecurityDescriptorA(SecurityDescriptor,
|
||||||
|
SDDL_REVISION_1,
|
||||||
OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION |
|
OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION |
|
||||||
DACL_SECURITY_INFORMATION | SACL_SECURITY_INFORMATION,
|
DACL_SECURITY_INFORMATION | SACL_SECURITY_INFORMATION,
|
||||||
&Sddl, 0))
|
&Sddl, 0))
|
||||||
@ -65,3 +66,587 @@ FSP_API VOID FspDebugLogFT(const char *format, PFILETIME FileTime)
|
|||||||
else
|
else
|
||||||
FspDebugLog(format, "invalid file time");
|
FspDebugLog(format, "invalid file time");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define MAKE_UINT32_PAIR(v) \
|
||||||
|
((PLARGE_INTEGER)&(v))->HighPart, ((PLARGE_INTEGER)&(v))->LowPart
|
||||||
|
|
||||||
|
static const char *FspDebugLogDispositionString(UINT32 CreateOptions)
|
||||||
|
{
|
||||||
|
switch ((CreateOptions >> 24) & 0xff)
|
||||||
|
{
|
||||||
|
case FILE_CREATE:
|
||||||
|
return "FILE_CREATE";
|
||||||
|
case FILE_OPEN:
|
||||||
|
return "FILE_OPEN";
|
||||||
|
case FILE_OPEN_IF:
|
||||||
|
return "FILE_OPEN_IF";
|
||||||
|
case FILE_OVERWRITE:
|
||||||
|
return "FILE_OVERWRITE";
|
||||||
|
case FILE_SUPERSEDE:
|
||||||
|
return "FILE_SUPERSEDE";
|
||||||
|
case FILE_OVERWRITE_IF:
|
||||||
|
return "FILE_OVERWRITE_IF";
|
||||||
|
default:
|
||||||
|
return "INVALID";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static const char *FspDebugLogUserContextString(UINT64 UserContext, UINT64 UserContext2, char *Buf)
|
||||||
|
{
|
||||||
|
wsprintfA(Buf, 0 == UserContext2 ? "%p" : "%p:%p", UserContext, UserContext2);
|
||||||
|
|
||||||
|
return Buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const char *FspDebugLogFileTimeString(UINT64 FileTime, char *Buf)
|
||||||
|
{
|
||||||
|
SYSTEMTIME SystemTime;
|
||||||
|
|
||||||
|
if (0 == FileTime)
|
||||||
|
lstrcpyA(Buf, "0");
|
||||||
|
else if (FileTimeToSystemTime((PFILETIME)&FileTime, &SystemTime))
|
||||||
|
{
|
||||||
|
wsprintfA(Buf, "%04hu-%02hu-%02huT%02hu:%02hu:%02hu.%03huZ",
|
||||||
|
SystemTime.wYear, SystemTime.wMonth, SystemTime.wDay,
|
||||||
|
SystemTime.wHour, SystemTime.wMinute, SystemTime.wSecond,
|
||||||
|
SystemTime.wMilliseconds);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
lstrcpyA(Buf, "INVALID");
|
||||||
|
|
||||||
|
return Buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const char *FspDebugLogFileInfoString(FSP_FSCTL_FILE_INFO *FileInfo, char *Buf)
|
||||||
|
{
|
||||||
|
char CreationTimeBuf[32], LastAccessTimeBuf[32], LastWriteTimeBuf[32], ChangeTimeBuf[32];
|
||||||
|
|
||||||
|
wsprintfA(Buf,
|
||||||
|
"{"
|
||||||
|
"FileAttributes=%lx, "
|
||||||
|
"ReparseTag=%lx, "
|
||||||
|
"AllocationSize=%lx:%lx, "
|
||||||
|
"FileSize=%lx:%lx, "
|
||||||
|
"CreationTime=%s, "
|
||||||
|
"LastAccessTime=%s, "
|
||||||
|
"LastWriteTime=%s, "
|
||||||
|
"ChangeTime=%s, "
|
||||||
|
"IndexNumber=%lx:%lx"
|
||||||
|
"}",
|
||||||
|
FileInfo->FileAttributes,
|
||||||
|
FileInfo->ReparseTag,
|
||||||
|
MAKE_UINT32_PAIR(FileInfo->AllocationSize),
|
||||||
|
MAKE_UINT32_PAIR(FileInfo->FileSize),
|
||||||
|
FspDebugLogFileTimeString(FileInfo->CreationTime, CreationTimeBuf),
|
||||||
|
FspDebugLogFileTimeString(FileInfo->LastAccessTime, LastAccessTimeBuf),
|
||||||
|
FspDebugLogFileTimeString(FileInfo->LastWriteTime, LastWriteTimeBuf),
|
||||||
|
FspDebugLogFileTimeString(FileInfo->ChangeTime, ChangeTimeBuf),
|
||||||
|
MAKE_UINT32_PAIR(FileInfo->IndexNumber));
|
||||||
|
|
||||||
|
return Buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const char *FspDebugLogVolumeInfoString(FSP_FSCTL_VOLUME_INFO *VolumeInfo, char *Buf)
|
||||||
|
{
|
||||||
|
wsprintfA(Buf,
|
||||||
|
"{"
|
||||||
|
"TotalSize=%lx:%lx, "
|
||||||
|
"FreeSize=%lx:%lx, "
|
||||||
|
"VolumeLabel=\"%.32S\""
|
||||||
|
"}",
|
||||||
|
MAKE_UINT32_PAIR(VolumeInfo->TotalSize),
|
||||||
|
MAKE_UINT32_PAIR(VolumeInfo->FreeSize),
|
||||||
|
&VolumeInfo->VolumeLabel);
|
||||||
|
|
||||||
|
return Buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
static VOID FspDebugLogRequestVoid(FSP_FSCTL_TRANSACT_REQ *Request, const char *Name)
|
||||||
|
{
|
||||||
|
FspDebugLog("%S[TID=%04lx]: %p: >>%s\n",
|
||||||
|
FspDiagIdent(), GetCurrentThreadId(), Request->Hint, Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
static VOID FspDebugLogResponseStatus(FSP_FSCTL_TRANSACT_RSP *Response, const char *Name)
|
||||||
|
{
|
||||||
|
FspDebugLog("%S[TID=%04lx]: %p: <<%s IoStatus=%lx[%ld]\n",
|
||||||
|
FspDiagIdent(), GetCurrentThreadId(), Response->Hint, Name,
|
||||||
|
Response->IoStatus.Status, Response->IoStatus.Information);
|
||||||
|
}
|
||||||
|
|
||||||
|
FSP_API VOID FspDebugLogRequest(FSP_FSCTL_TRANSACT_REQ *Request)
|
||||||
|
{
|
||||||
|
char UserContextBuf[40];
|
||||||
|
char CreationTimeBuf[32], LastAccessTimeBuf[32], LastWriteTimeBuf[32];
|
||||||
|
char *Sddl = 0;
|
||||||
|
|
||||||
|
switch (Request->Kind)
|
||||||
|
{
|
||||||
|
case FspFsctlTransactReservedKind:
|
||||||
|
FspDebugLogRequestVoid(Request, "RESERVED");
|
||||||
|
break;
|
||||||
|
case FspFsctlTransactCreateKind:
|
||||||
|
if (0 != Request->Req.Create.SecurityDescriptor.Offset)
|
||||||
|
ConvertSecurityDescriptorToStringSecurityDescriptorA(
|
||||||
|
Request->Buffer + Request->Req.Create.SecurityDescriptor.Offset,
|
||||||
|
SDDL_REVISION_1,
|
||||||
|
OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION |
|
||||||
|
DACL_SECURITY_INFORMATION | SACL_SECURITY_INFORMATION,
|
||||||
|
&Sddl, 0);
|
||||||
|
FspDebugLog("%S[TID=%04lx]: %p: >>Create [%c%c%c%c] \"%S\", "
|
||||||
|
"%s, CreateOptions=%lx, FileAttributes=%lx, Security=%s%s%s, "
|
||||||
|
"AllocationSize=%lx:%lx, AccessToken=%p, DesiredAccess=%lx, ShareAccess=%lx\n",
|
||||||
|
FspDiagIdent(), GetCurrentThreadId(), Request->Hint,
|
||||||
|
Request->Req.Create.UserMode ? 'U' : 'K',
|
||||||
|
Request->Req.Create.HasTraversePrivilege ? 'T' : '-',
|
||||||
|
Request->Req.Create.OpenTargetDirectory ? 'D' : '-',
|
||||||
|
Request->Req.Create.CaseSensitive ? 'C' : '-',
|
||||||
|
(PWSTR)Request->Buffer,
|
||||||
|
FspDebugLogDispositionString(Request->Req.Create.CreateOptions),
|
||||||
|
Request->Req.Create.CreateOptions & 0xffffff,
|
||||||
|
Request->Req.Create.FileAttributes,
|
||||||
|
Sddl ? "\"" : "",
|
||||||
|
Sddl ? Sddl : "NULL",
|
||||||
|
Sddl ? "\"" : "",
|
||||||
|
MAKE_UINT32_PAIR(Request->Req.Create.AllocationSize),
|
||||||
|
(PVOID)Request->Req.Create.AccessToken,
|
||||||
|
Request->Req.Create.DesiredAccess,
|
||||||
|
Request->Req.Create.ShareAccess);
|
||||||
|
LocalFree(Sddl);
|
||||||
|
break;
|
||||||
|
case FspFsctlTransactOverwriteKind:
|
||||||
|
FspDebugLog("%S[TID=%04lx]: %p: >>Overwrite%s %s%S%s%s, "
|
||||||
|
"FileAttributes=%lx\n",
|
||||||
|
FspDiagIdent(), GetCurrentThreadId(), Request->Hint,
|
||||||
|
Request->Req.Overwrite.Supersede ? " [Supersede]" : "",
|
||||||
|
Request->FileName.Size ? "\"" : "",
|
||||||
|
Request->FileName.Size ? (PWSTR)Request->Buffer : L"",
|
||||||
|
Request->FileName.Size ? "\", " : "",
|
||||||
|
FspDebugLogUserContextString(
|
||||||
|
Request->Req.Overwrite.UserContext, Request->Req.Overwrite.UserContext2,
|
||||||
|
UserContextBuf),
|
||||||
|
Request->Req.Overwrite.FileAttributes);
|
||||||
|
break;
|
||||||
|
case FspFsctlTransactCleanupKind:
|
||||||
|
FspDebugLog("%S[TID=%04lx]: %p: >>Cleanup%s %s%S%s%s\n",
|
||||||
|
FspDiagIdent(), GetCurrentThreadId(), Request->Hint,
|
||||||
|
Request->Req.Cleanup.Delete ? " [Delete]" : "",
|
||||||
|
Request->FileName.Size ? "\"" : "",
|
||||||
|
Request->FileName.Size ? (PWSTR)Request->Buffer : L"",
|
||||||
|
Request->FileName.Size ? "\", " : "",
|
||||||
|
FspDebugLogUserContextString(
|
||||||
|
Request->Req.Cleanup.UserContext, Request->Req.Cleanup.UserContext2,
|
||||||
|
UserContextBuf));
|
||||||
|
break;
|
||||||
|
case FspFsctlTransactCloseKind:
|
||||||
|
FspDebugLog("%S[TID=%04lx]: %p: >>Close %s%S%s%s\n",
|
||||||
|
FspDiagIdent(), GetCurrentThreadId(), Request->Hint,
|
||||||
|
Request->FileName.Size ? "\"" : "",
|
||||||
|
Request->FileName.Size ? (PWSTR)Request->Buffer : L"",
|
||||||
|
Request->FileName.Size ? "\", " : "",
|
||||||
|
FspDebugLogUserContextString(
|
||||||
|
Request->Req.Close.UserContext, Request->Req.Close.UserContext2,
|
||||||
|
UserContextBuf));
|
||||||
|
break;
|
||||||
|
case FspFsctlTransactReadKind:
|
||||||
|
FspDebugLog("%S[TID=%04lx]: %p: >>Read %s%S%s%s, "
|
||||||
|
"Address=%p, Offset=%lx:%lx, Length=%ld, Key=%lx\n",
|
||||||
|
FspDiagIdent(), GetCurrentThreadId(), Request->Hint,
|
||||||
|
Request->FileName.Size ? "\"" : "",
|
||||||
|
Request->FileName.Size ? (PWSTR)Request->Buffer : L"",
|
||||||
|
Request->FileName.Size ? "\", " : "",
|
||||||
|
FspDebugLogUserContextString(
|
||||||
|
Request->Req.Read.UserContext, Request->Req.Read.UserContext2,
|
||||||
|
UserContextBuf),
|
||||||
|
Request->Req.Read.Address,
|
||||||
|
MAKE_UINT32_PAIR(Request->Req.Read.Offset),
|
||||||
|
Request->Req.Read.Length,
|
||||||
|
Request->Req.Read.Key);
|
||||||
|
break;
|
||||||
|
case FspFsctlTransactWriteKind:
|
||||||
|
FspDebugLog("%S[TID=%04lx]: %p: >>Write%s %s%S%s%s, "
|
||||||
|
"Address=%p, Offset=%lx:%lx, Length=%ld, Key=%lx\n",
|
||||||
|
FspDiagIdent(), GetCurrentThreadId(), Request->Hint,
|
||||||
|
Request->Req.Write.ConstrainedIo ? " [C]" : "",
|
||||||
|
Request->FileName.Size ? "\"" : "",
|
||||||
|
Request->FileName.Size ? (PWSTR)Request->Buffer : L"",
|
||||||
|
Request->FileName.Size ? "\", " : "",
|
||||||
|
FspDebugLogUserContextString(
|
||||||
|
Request->Req.Write.UserContext, Request->Req.Write.UserContext2,
|
||||||
|
UserContextBuf),
|
||||||
|
Request->Req.Write.Address,
|
||||||
|
MAKE_UINT32_PAIR(Request->Req.Write.Offset),
|
||||||
|
Request->Req.Write.Length,
|
||||||
|
Request->Req.Write.Key);
|
||||||
|
break;
|
||||||
|
case FspFsctlTransactQueryInformationKind:
|
||||||
|
FspDebugLog("%S[TID=%04lx]: %p: >>QueryInformation %s%S%s%s\n",
|
||||||
|
FspDiagIdent(), GetCurrentThreadId(), Request->Hint,
|
||||||
|
Request->FileName.Size ? "\"" : "",
|
||||||
|
Request->FileName.Size ? (PWSTR)Request->Buffer : L"",
|
||||||
|
Request->FileName.Size ? "\", " : "",
|
||||||
|
FspDebugLogUserContextString(
|
||||||
|
Request->Req.QueryInformation.UserContext, Request->Req.QueryInformation.UserContext2,
|
||||||
|
UserContextBuf));
|
||||||
|
break;
|
||||||
|
case FspFsctlTransactSetInformationKind:
|
||||||
|
switch (Request->Req.SetInformation.FileInformationClass)
|
||||||
|
{
|
||||||
|
case 4/*FileBasicInformation*/:
|
||||||
|
FspDebugLog("%S[TID=%04lx]: %p: >>SetInformation [Basic] %s%S%s%s, "
|
||||||
|
"FileAttributes=%lx, CreationTime=%s, LastAccessTime=%s, LastWriteTime=%s\n",
|
||||||
|
FspDiagIdent(), GetCurrentThreadId(), Request->Hint,
|
||||||
|
Request->FileName.Size ? "\"" : "",
|
||||||
|
Request->FileName.Size ? (PWSTR)Request->Buffer : L"",
|
||||||
|
Request->FileName.Size ? "\", " : "",
|
||||||
|
FspDebugLogUserContextString(
|
||||||
|
Request->Req.SetInformation.UserContext, Request->Req.SetInformation.UserContext2,
|
||||||
|
UserContextBuf),
|
||||||
|
Request->Req.SetInformation.Info.Basic.FileAttributes,
|
||||||
|
FspDebugLogFileTimeString(Request->Req.SetInformation.Info.Basic.CreationTime,
|
||||||
|
CreationTimeBuf),
|
||||||
|
FspDebugLogFileTimeString(Request->Req.SetInformation.Info.Basic.LastAccessTime,
|
||||||
|
LastAccessTimeBuf),
|
||||||
|
FspDebugLogFileTimeString(Request->Req.SetInformation.Info.Basic.LastWriteTime,
|
||||||
|
LastWriteTimeBuf));
|
||||||
|
break;
|
||||||
|
case 19/*FileAllocationInformation*/:
|
||||||
|
FspDebugLog("%S[TID=%04lx]: %p: >>SetInformation [Allocation] %s%S%s%s, "
|
||||||
|
"AllocationSize=%lx:%lx\n",
|
||||||
|
FspDiagIdent(), GetCurrentThreadId(), Request->Hint,
|
||||||
|
Request->FileName.Size ? "\"" : "",
|
||||||
|
Request->FileName.Size ? (PWSTR)Request->Buffer : L"",
|
||||||
|
Request->FileName.Size ? "\", " : "",
|
||||||
|
FspDebugLogUserContextString(
|
||||||
|
Request->Req.SetInformation.UserContext, Request->Req.SetInformation.UserContext2,
|
||||||
|
UserContextBuf),
|
||||||
|
MAKE_UINT32_PAIR(Request->Req.SetInformation.Info.Allocation.AllocationSize));
|
||||||
|
break;
|
||||||
|
case 20/*FileEndOfFileInformation*/:
|
||||||
|
FspDebugLog("%S[TID=%04lx]: %p: >>SetInformation [EndOfFile] %s%S%s%s, "
|
||||||
|
"FileSize = %lx:%lx\n",
|
||||||
|
FspDiagIdent(), GetCurrentThreadId(), Request->Hint,
|
||||||
|
Request->FileName.Size ? "\"" : "",
|
||||||
|
Request->FileName.Size ? (PWSTR)Request->Buffer : L"",
|
||||||
|
Request->FileName.Size ? "\", " : "",
|
||||||
|
FspDebugLogUserContextString(
|
||||||
|
Request->Req.SetInformation.UserContext, Request->Req.SetInformation.UserContext2,
|
||||||
|
UserContextBuf),
|
||||||
|
MAKE_UINT32_PAIR(Request->Req.SetInformation.Info.EndOfFile.FileSize));
|
||||||
|
break;
|
||||||
|
case 13/*FileDispositionInformation*/:
|
||||||
|
FspDebugLog("%S[TID=%04lx]: %p: >>SetInformation [Disposition] %s%S%s%s, "
|
||||||
|
"%s\n",
|
||||||
|
FspDiagIdent(), GetCurrentThreadId(), Request->Hint,
|
||||||
|
Request->FileName.Size ? "\"" : "",
|
||||||
|
Request->FileName.Size ? (PWSTR)Request->Buffer : L"",
|
||||||
|
Request->FileName.Size ? "\", " : "",
|
||||||
|
FspDebugLogUserContextString(
|
||||||
|
Request->Req.SetInformation.UserContext, Request->Req.SetInformation.UserContext2,
|
||||||
|
UserContextBuf),
|
||||||
|
Request->Req.SetInformation.Info.Disposition.Delete ? "Delete" : "Undelete");
|
||||||
|
break;
|
||||||
|
case 10/*FileRenameInformation*/:
|
||||||
|
FspDebugLog("%S[TID=%04lx]: %p: >>SetInformation [Rename] %s%S%s%s, "
|
||||||
|
"NewFileName=\"%S\", AccessToken=%p\n",
|
||||||
|
FspDiagIdent(), GetCurrentThreadId(), Request->Hint,
|
||||||
|
Request->FileName.Size ? "\"" : "",
|
||||||
|
Request->FileName.Size ? (PWSTR)Request->Buffer : L"",
|
||||||
|
Request->FileName.Size ? "\", " : "",
|
||||||
|
FspDebugLogUserContextString(
|
||||||
|
Request->Req.SetInformation.UserContext, Request->Req.SetInformation.UserContext2,
|
||||||
|
UserContextBuf),
|
||||||
|
(PWSTR)(Request->Buffer + Request->Req.SetInformation.Info.Rename.NewFileName.Offset),
|
||||||
|
(PVOID)Request->Req.SetInformation.Info.Rename.AccessToken);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
FspDebugLog("%S[TID=%04lx]: %p: >>SetInformation [INVALID] %s%S%s%s\n",
|
||||||
|
FspDiagIdent(), GetCurrentThreadId(), Request->Hint,
|
||||||
|
Request->FileName.Size ? "\"" : "",
|
||||||
|
Request->FileName.Size ? (PWSTR)Request->Buffer : L"",
|
||||||
|
Request->FileName.Size ? "\", " : "",
|
||||||
|
FspDebugLogUserContextString(
|
||||||
|
Request->Req.SetInformation.UserContext, Request->Req.SetInformation.UserContext2,
|
||||||
|
UserContextBuf));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case FspFsctlTransactQueryEaKind:
|
||||||
|
FspDebugLogRequestVoid(Request, "QUERYEA");
|
||||||
|
break;
|
||||||
|
case FspFsctlTransactSetEaKind:
|
||||||
|
FspDebugLogRequestVoid(Request, "SETEA");
|
||||||
|
break;
|
||||||
|
case FspFsctlTransactFlushBuffersKind:
|
||||||
|
FspDebugLog("%S[TID=%04lx]: %p: >>FlushBuffers %s%S%s%s\n",
|
||||||
|
FspDiagIdent(), GetCurrentThreadId(), Request->Hint,
|
||||||
|
Request->FileName.Size ? "\"" : "",
|
||||||
|
Request->FileName.Size ? (PWSTR)Request->Buffer : L"",
|
||||||
|
Request->FileName.Size ? "\", " : "",
|
||||||
|
FspDebugLogUserContextString(
|
||||||
|
Request->Req.FlushBuffers.UserContext, Request->Req.FlushBuffers.UserContext2,
|
||||||
|
UserContextBuf));
|
||||||
|
break;
|
||||||
|
case FspFsctlTransactQueryVolumeInformationKind:
|
||||||
|
FspDebugLogRequestVoid(Request, "QueryVolumeInformation");
|
||||||
|
break;
|
||||||
|
case FspFsctlTransactSetVolumeInformationKind:
|
||||||
|
switch (Request->Req.SetVolumeInformation.FsInformationClass)
|
||||||
|
{
|
||||||
|
case 2/*FileFsLabelInformation*/:
|
||||||
|
FspDebugLog("%S[TID=%04lx]: %p: >>SetVolumeInformation [FsLabel] "
|
||||||
|
"Label=\"%S\"\n",
|
||||||
|
FspDiagIdent(), GetCurrentThreadId(), Request->Hint,
|
||||||
|
(PWSTR)Request->Buffer);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
FspDebugLog("%S[TID=%04lx]: %p: >>SetVolumeInformation [INVALID]\n",
|
||||||
|
FspDiagIdent(), GetCurrentThreadId(), Request->Hint);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case FspFsctlTransactQueryDirectoryKind:
|
||||||
|
FspDebugLog("%S[TID=%04lx]: %p: >>QueryDirectory %s%S%s%s, "
|
||||||
|
"Address=%p, Offset=%lx:%lx, Length=%ld, Pattern=%s%S%s\n",
|
||||||
|
FspDiagIdent(), GetCurrentThreadId(), Request->Hint,
|
||||||
|
Request->FileName.Size ? "\"" : "",
|
||||||
|
Request->FileName.Size ? (PWSTR)Request->Buffer : L"",
|
||||||
|
Request->FileName.Size ? "\", " : "",
|
||||||
|
FspDebugLogUserContextString(
|
||||||
|
Request->Req.QueryDirectory.UserContext, Request->Req.QueryDirectory.UserContext2,
|
||||||
|
UserContextBuf),
|
||||||
|
Request->Req.QueryDirectory.Address,
|
||||||
|
MAKE_UINT32_PAIR(Request->Req.QueryDirectory.Offset),
|
||||||
|
Request->Req.QueryDirectory.Length,
|
||||||
|
Request->Req.QueryDirectory.Pattern.Size ? "\"" : "",
|
||||||
|
Request->Req.QueryDirectory.Pattern.Size ?
|
||||||
|
(PWSTR)(Request->Buffer + Request->Req.QueryDirectory.Pattern.Offset) : L"NULL",
|
||||||
|
Request->Req.QueryDirectory.Pattern.Size ? "\"" : "");
|
||||||
|
break;
|
||||||
|
case FspFsctlTransactFileSystemControlKind:
|
||||||
|
FspDebugLogRequestVoid(Request, "FILESYSTEMCONTROL");
|
||||||
|
break;
|
||||||
|
case FspFsctlTransactDeviceControlKind:
|
||||||
|
FspDebugLogRequestVoid(Request, "DEVICECONTROL");
|
||||||
|
break;
|
||||||
|
case FspFsctlTransactShutdownKind:
|
||||||
|
FspDebugLogRequestVoid(Request, "SHUTDOWN");
|
||||||
|
break;
|
||||||
|
case FspFsctlTransactLockControlKind:
|
||||||
|
FspDebugLogRequestVoid(Request, "LOCKCONTROL");
|
||||||
|
break;
|
||||||
|
case FspFsctlTransactQuerySecurityKind:
|
||||||
|
FspDebugLog("%S[TID=%04lx]: %p: >>QuerySecurity %s%S%s%s\n",
|
||||||
|
FspDiagIdent(), GetCurrentThreadId(), Request->Hint,
|
||||||
|
Request->FileName.Size ? "\"" : "",
|
||||||
|
Request->FileName.Size ? (PWSTR)Request->Buffer : L"",
|
||||||
|
Request->FileName.Size ? "\", " : "",
|
||||||
|
FspDebugLogUserContextString(
|
||||||
|
Request->Req.QuerySecurity.UserContext, Request->Req.QuerySecurity.UserContext2,
|
||||||
|
UserContextBuf));
|
||||||
|
break;
|
||||||
|
case FspFsctlTransactSetSecurityKind:
|
||||||
|
if (0 != Request->Req.SetSecurity.SecurityDescriptor.Size)
|
||||||
|
ConvertSecurityDescriptorToStringSecurityDescriptorA(
|
||||||
|
Request->Buffer + Request->Req.SetSecurity.SecurityDescriptor.Offset,
|
||||||
|
SDDL_REVISION_1,
|
||||||
|
OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION |
|
||||||
|
DACL_SECURITY_INFORMATION | SACL_SECURITY_INFORMATION,
|
||||||
|
&Sddl, 0);
|
||||||
|
FspDebugLog("%S[TID=%04lx]: %p: >>SetSecurity %s%S%s%s, "
|
||||||
|
"SecurityInformation=%lx, AccessToken=%p, Security=%s%s%s\n",
|
||||||
|
FspDiagIdent(), GetCurrentThreadId(), Request->Hint,
|
||||||
|
Request->FileName.Size ? "\"" : "",
|
||||||
|
Request->FileName.Size ? (PWSTR)Request->Buffer : L"",
|
||||||
|
Request->FileName.Size ? "\", " : "",
|
||||||
|
FspDebugLogUserContextString(
|
||||||
|
Request->Req.SetSecurity.UserContext, Request->Req.SetSecurity.UserContext2,
|
||||||
|
UserContextBuf),
|
||||||
|
Request->Req.SetSecurity.SecurityInformation,
|
||||||
|
(PVOID)Request->Req.SetSecurity.AccessToken,
|
||||||
|
Sddl ? "\"" : "",
|
||||||
|
Sddl ? Sddl : "NULL",
|
||||||
|
Sddl ? "\"" : "");
|
||||||
|
LocalFree(Sddl);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
FspDebugLogRequestVoid(Request, "INVALID");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FSP_API VOID FspDebugLogResponse(FSP_FSCTL_TRANSACT_RSP *Response)
|
||||||
|
{
|
||||||
|
if (STATUS_PENDING == Response->IoStatus.Status)
|
||||||
|
return;
|
||||||
|
|
||||||
|
char UserContextBuf[40];
|
||||||
|
char InfoBuf[256];
|
||||||
|
char *Sddl = 0;
|
||||||
|
|
||||||
|
switch (Response->Kind)
|
||||||
|
{
|
||||||
|
case FspFsctlTransactReservedKind:
|
||||||
|
FspDebugLogResponseStatus(Response, "RESERVED");
|
||||||
|
break;
|
||||||
|
case FspFsctlTransactCreateKind:
|
||||||
|
if (!NT_SUCCESS(Response->IoStatus.Status))
|
||||||
|
FspDebugLogResponseStatus(Response, "Create");
|
||||||
|
else if (STATUS_REPARSE == Response->IoStatus.Status)
|
||||||
|
FspDebugLog("%S[TID=%04lx]: %p: <<Create IoStatus=%lx[%ld] "
|
||||||
|
"Reparse.FileName=\"%S\"\n",
|
||||||
|
FspDiagIdent(), GetCurrentThreadId(), Response->Hint,
|
||||||
|
Response->IoStatus.Status, Response->IoStatus.Information,
|
||||||
|
(PWSTR)(Response->Buffer + Response->Rsp.Create.Reparse.FileName.Offset));
|
||||||
|
else
|
||||||
|
FspDebugLog("%S[TID=%04lx]: %p: <<Create IoStatus=%lx[%ld] "
|
||||||
|
"UserContext=%s, GrantedAccess=%lx, FileInfo=%s\n",
|
||||||
|
FspDiagIdent(), GetCurrentThreadId(), Response->Hint,
|
||||||
|
Response->IoStatus.Status, Response->IoStatus.Information,
|
||||||
|
FspDebugLogUserContextString(
|
||||||
|
Response->Rsp.Create.Opened.UserContext, Response->Rsp.Create.Opened.UserContext2,
|
||||||
|
UserContextBuf),
|
||||||
|
Response->Rsp.Create.Opened.GrantedAccess,
|
||||||
|
FspDebugLogFileInfoString(&Response->Rsp.Create.Opened.FileInfo, InfoBuf));
|
||||||
|
break;
|
||||||
|
case FspFsctlTransactOverwriteKind:
|
||||||
|
if (!NT_SUCCESS(Response->IoStatus.Status))
|
||||||
|
FspDebugLogResponseStatus(Response, "Overwrite");
|
||||||
|
else
|
||||||
|
FspDebugLog("%S[TID=%04lx]: %p: <<Overwrite IoStatus=%lx[%ld] "
|
||||||
|
"FileInfo=%s\n",
|
||||||
|
FspDiagIdent(), GetCurrentThreadId(), Response->Hint,
|
||||||
|
Response->IoStatus.Status, Response->IoStatus.Information,
|
||||||
|
FspDebugLogFileInfoString(&Response->Rsp.Overwrite.FileInfo, InfoBuf));
|
||||||
|
break;
|
||||||
|
case FspFsctlTransactCleanupKind:
|
||||||
|
FspDebugLogResponseStatus(Response, "Cleanup");
|
||||||
|
break;
|
||||||
|
case FspFsctlTransactCloseKind:
|
||||||
|
FspDebugLogResponseStatus(Response, "Close");
|
||||||
|
break;
|
||||||
|
case FspFsctlTransactReadKind:
|
||||||
|
FspDebugLogResponseStatus(Response, "Read");
|
||||||
|
break;
|
||||||
|
case FspFsctlTransactWriteKind:
|
||||||
|
if (!NT_SUCCESS(Response->IoStatus.Status))
|
||||||
|
FspDebugLogResponseStatus(Response, "Write");
|
||||||
|
else
|
||||||
|
FspDebugLog("%S[TID=%04lx]: %p: <<Write IoStatus=%lx[%ld] "
|
||||||
|
"FileInfo=%s\n",
|
||||||
|
FspDiagIdent(), GetCurrentThreadId(), Response->Hint,
|
||||||
|
Response->IoStatus.Status, Response->IoStatus.Information,
|
||||||
|
FspDebugLogFileInfoString(&Response->Rsp.Write.FileInfo, InfoBuf));
|
||||||
|
break;
|
||||||
|
case FspFsctlTransactQueryInformationKind:
|
||||||
|
if (!NT_SUCCESS(Response->IoStatus.Status))
|
||||||
|
FspDebugLogResponseStatus(Response, "QueryInformation");
|
||||||
|
else
|
||||||
|
FspDebugLog("%S[TID=%04lx]: %p: <<QueryInformation IoStatus=%lx[%ld] "
|
||||||
|
"FileInfo=%s\n",
|
||||||
|
FspDiagIdent(), GetCurrentThreadId(), Response->Hint,
|
||||||
|
Response->IoStatus.Status, Response->IoStatus.Information,
|
||||||
|
FspDebugLogFileInfoString(&Response->Rsp.QueryInformation.FileInfo, InfoBuf));
|
||||||
|
break;
|
||||||
|
case FspFsctlTransactSetInformationKind:
|
||||||
|
if (!NT_SUCCESS(Response->IoStatus.Status))
|
||||||
|
FspDebugLogResponseStatus(Response, "SetInformation");
|
||||||
|
else
|
||||||
|
FspDebugLog("%S[TID=%04lx]: %p: <<SetInformation IoStatus=%lx[%ld] "
|
||||||
|
"FileInfo=%s\n",
|
||||||
|
FspDiagIdent(), GetCurrentThreadId(), Response->Hint,
|
||||||
|
Response->IoStatus.Status, Response->IoStatus.Information,
|
||||||
|
FspDebugLogFileInfoString(&Response->Rsp.SetInformation.FileInfo, InfoBuf));
|
||||||
|
break;
|
||||||
|
case FspFsctlTransactQueryEaKind:
|
||||||
|
FspDebugLogResponseStatus(Response, "QUERYEA");
|
||||||
|
break;
|
||||||
|
case FspFsctlTransactSetEaKind:
|
||||||
|
FspDebugLogResponseStatus(Response, "SETEA");
|
||||||
|
break;
|
||||||
|
case FspFsctlTransactFlushBuffersKind:
|
||||||
|
FspDebugLogResponseStatus(Response, "FlushBuffers");
|
||||||
|
break;
|
||||||
|
case FspFsctlTransactQueryVolumeInformationKind:
|
||||||
|
if (!NT_SUCCESS(Response->IoStatus.Status))
|
||||||
|
FspDebugLogResponseStatus(Response, "QueryVolumeInformation");
|
||||||
|
else
|
||||||
|
FspDebugLog("%S[TID=%04lx]: %p: <<QueryVolumeInformation IoStatus=%lx[%ld] "
|
||||||
|
"VolumeInfo=%s\n",
|
||||||
|
FspDiagIdent(), GetCurrentThreadId(), Response->Hint,
|
||||||
|
Response->IoStatus.Status, Response->IoStatus.Information,
|
||||||
|
FspDebugLogVolumeInfoString(&Response->Rsp.QueryVolumeInformation.VolumeInfo, InfoBuf));
|
||||||
|
break;
|
||||||
|
case FspFsctlTransactSetVolumeInformationKind:
|
||||||
|
if (!NT_SUCCESS(Response->IoStatus.Status))
|
||||||
|
FspDebugLogResponseStatus(Response, "SetVolumeInformation");
|
||||||
|
else
|
||||||
|
FspDebugLog("%S[TID=%04lx]: %p: <<SetVolumeInformation IoStatus=%lx[%ld] "
|
||||||
|
"VolumeInfo=%s\n",
|
||||||
|
FspDiagIdent(), GetCurrentThreadId(), Response->Hint,
|
||||||
|
Response->IoStatus.Status, Response->IoStatus.Information,
|
||||||
|
FspDebugLogVolumeInfoString(&Response->Rsp.SetVolumeInformation.VolumeInfo, InfoBuf));
|
||||||
|
break;
|
||||||
|
case FspFsctlTransactQueryDirectoryKind:
|
||||||
|
FspDebugLogResponseStatus(Response, "QueryDirectory");
|
||||||
|
break;
|
||||||
|
case FspFsctlTransactFileSystemControlKind:
|
||||||
|
FspDebugLogResponseStatus(Response, "FILESYSTEMCONTROL");
|
||||||
|
break;
|
||||||
|
case FspFsctlTransactDeviceControlKind:
|
||||||
|
FspDebugLogResponseStatus(Response, "DEVICECONTROL");
|
||||||
|
break;
|
||||||
|
case FspFsctlTransactShutdownKind:
|
||||||
|
FspDebugLogResponseStatus(Response, "SHUTDOWN");
|
||||||
|
break;
|
||||||
|
case FspFsctlTransactLockControlKind:
|
||||||
|
FspDebugLogResponseStatus(Response, "LOCKCONTROL");
|
||||||
|
break;
|
||||||
|
case FspFsctlTransactQuerySecurityKind:
|
||||||
|
if (!NT_SUCCESS(Response->IoStatus.Status))
|
||||||
|
FspDebugLogResponseStatus(Response, "QuerySecurity");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (0 != Response->Rsp.QuerySecurity.SecurityDescriptor.Size)
|
||||||
|
ConvertSecurityDescriptorToStringSecurityDescriptorA(
|
||||||
|
Response->Buffer + Response->Rsp.QuerySecurity.SecurityDescriptor.Offset,
|
||||||
|
SDDL_REVISION_1,
|
||||||
|
OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION |
|
||||||
|
DACL_SECURITY_INFORMATION | SACL_SECURITY_INFORMATION,
|
||||||
|
&Sddl, 0);
|
||||||
|
FspDebugLog("%S[TID=%04lx]: %p: <<QuerySecurity IoStatus=%lx[%ld] "
|
||||||
|
"Security=%s%s%s\n",
|
||||||
|
FspDiagIdent(), GetCurrentThreadId(), Response->Hint,
|
||||||
|
Response->IoStatus.Status, Response->IoStatus.Information,
|
||||||
|
Sddl ? "\"" : "",
|
||||||
|
Sddl ? Sddl : "NULL",
|
||||||
|
Sddl ? "\"" : "");
|
||||||
|
LocalFree(Sddl);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case FspFsctlTransactSetSecurityKind:
|
||||||
|
if (!NT_SUCCESS(Response->IoStatus.Status))
|
||||||
|
FspDebugLogResponseStatus(Response, "SetSecurity");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (0 != Response->Rsp.SetSecurity.SecurityDescriptor.Size)
|
||||||
|
ConvertSecurityDescriptorToStringSecurityDescriptorA(
|
||||||
|
Response->Buffer + Response->Rsp.SetSecurity.SecurityDescriptor.Offset,
|
||||||
|
SDDL_REVISION_1,
|
||||||
|
OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION |
|
||||||
|
DACL_SECURITY_INFORMATION | SACL_SECURITY_INFORMATION,
|
||||||
|
&Sddl, 0);
|
||||||
|
FspDebugLog("%S[TID=%04lx]: %p: <<SetSecurity IoStatus=%lx[%ld] "
|
||||||
|
"Security=%s%s%s\n",
|
||||||
|
FspDiagIdent(), GetCurrentThreadId(), Response->Hint,
|
||||||
|
Response->IoStatus.Status, Response->IoStatus.Information,
|
||||||
|
Sddl ? "\"" : "",
|
||||||
|
Sddl ? Sddl : "NULL",
|
||||||
|
Sddl ? "\"" : "");
|
||||||
|
LocalFree(Sddl);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
FspDebugLogResponseStatus(Response, "INVALID");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -21,13 +21,16 @@
|
|||||||
|
|
||||||
#define FSP_EVENTLOG_NAME LIBRARY_NAME
|
#define FSP_EVENTLOG_NAME LIBRARY_NAME
|
||||||
|
|
||||||
static HANDLE FspEventLogHandle;
|
|
||||||
static INIT_ONCE FspEventLogInitOnce = INIT_ONCE_STATIC_INIT;
|
static INIT_ONCE FspEventLogInitOnce = INIT_ONCE_STATIC_INIT;
|
||||||
static BOOL WINAPI FspEventLogRegisterEventSource(
|
static HANDLE FspEventLogHandle;
|
||||||
PINIT_ONCE InitOnce, PVOID Parameter, PVOID *Context);
|
|
||||||
|
|
||||||
VOID FspEventLogInitialize(BOOLEAN Dynamic)
|
static BOOL WINAPI FspEventLogInitialize(
|
||||||
|
PINIT_ONCE InitOnce, PVOID Parameter, PVOID *Context)
|
||||||
{
|
{
|
||||||
|
FspEventLogHandle = RegisterEventSourceW(0, L"" FSP_EVENTLOG_NAME);
|
||||||
|
if (0 == FspEventLogHandle)
|
||||||
|
FspEventLogHandle = RegisterEventSourceW(0, FspDiagIdent());
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID FspEventLogFinalize(BOOLEAN Dynamic)
|
VOID FspEventLogFinalize(BOOLEAN Dynamic)
|
||||||
@ -55,17 +58,19 @@ FSP_API VOID FspEventLog(ULONG Type, PWSTR Format, ...)
|
|||||||
|
|
||||||
FSP_API VOID FspEventLogV(ULONG Type, PWSTR Format, va_list ap)
|
FSP_API VOID FspEventLogV(ULONG Type, PWSTR Format, va_list ap)
|
||||||
{
|
{
|
||||||
InitOnceExecuteOnce(&FspEventLogInitOnce, FspEventLogRegisterEventSource, 0, 0);
|
InitOnceExecuteOnce(&FspEventLogInitOnce, FspEventLogInitialize, 0, 0);
|
||||||
if (0 == FspEventLogHandle)
|
if (0 == FspEventLogHandle)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
WCHAR Buf[1024], *Strings[1];
|
WCHAR Buf[1024], *Strings[2];
|
||||||
/* wvsprintfW is only safe with a 1024 WCHAR buffer */
|
/* wvsprintfW is only safe with a 1024 WCHAR buffer */
|
||||||
DWORD EventId;
|
DWORD EventId;
|
||||||
|
|
||||||
|
Strings[0] = FspDiagIdent();
|
||||||
|
|
||||||
wvsprintfW(Buf, Format, ap);
|
wvsprintfW(Buf, Format, ap);
|
||||||
Buf[(sizeof Buf / sizeof Buf[0]) - 1] = L'\0';
|
Buf[(sizeof Buf / sizeof Buf[0]) - 1] = L'\0';
|
||||||
Strings[0] = Buf;
|
Strings[1] = Buf;
|
||||||
|
|
||||||
switch (Type)
|
switch (Type)
|
||||||
{
|
{
|
||||||
@ -82,14 +87,7 @@ FSP_API VOID FspEventLogV(ULONG Type, PWSTR Format, va_list ap)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReportEventW(FspEventLogHandle, (WORD)Type, 0, EventId, 0, 1, 0, Strings, 0);
|
ReportEventW(FspEventLogHandle, (WORD)Type, 0, EventId, 0, 2, 0, Strings, 0);
|
||||||
}
|
|
||||||
|
|
||||||
static BOOL WINAPI FspEventLogRegisterEventSource(
|
|
||||||
PINIT_ONCE InitOnce, PVOID Parameter, PVOID *Context)
|
|
||||||
{
|
|
||||||
FspEventLogHandle = RegisterEventSourceW(0, L"" FSP_EVENTLOG_NAME);
|
|
||||||
return TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS FspEventLogRegister(VOID)
|
NTSTATUS FspEventLogRegister(VOID)
|
||||||
@ -103,7 +101,7 @@ NTSTATUS FspEventLogRegister(VOID)
|
|||||||
return FspNtStatusFromWin32(GetLastError());
|
return FspNtStatusFromWin32(GetLastError());
|
||||||
|
|
||||||
RegResult = RegCreateKeyExW(
|
RegResult = RegCreateKeyExW(
|
||||||
HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Services\\EventLog\\System\\" FSP_EVENTLOG_NAME,
|
HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\" FSP_EVENTLOG_NAME,
|
||||||
0, 0, 0, KEY_ALL_ACCESS, 0, &RegKey, 0);
|
0, 0, 0, KEY_ALL_ACCESS, 0, &RegKey, 0);
|
||||||
if (ERROR_SUCCESS != RegResult)
|
if (ERROR_SUCCESS != RegResult)
|
||||||
return FspNtStatusFromWin32(RegResult);
|
return FspNtStatusFromWin32(RegResult);
|
||||||
@ -133,7 +131,7 @@ NTSTATUS FspEventLogUnregister(VOID)
|
|||||||
DWORD RegResult;
|
DWORD RegResult;
|
||||||
|
|
||||||
RegResult = RegDeleteTreeW(
|
RegResult = RegDeleteTreeW(
|
||||||
HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Services\\EventLog\\System\\" FSP_EVENTLOG_NAME);
|
HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\" FSP_EVENTLOG_NAME);
|
||||||
if (ERROR_SUCCESS != RegResult && ERROR_FILE_NOT_FOUND != RegResult)
|
if (ERROR_SUCCESS != RegResult && ERROR_FILE_NOT_FOUND != RegResult)
|
||||||
return FspNtStatusFromWin32(RegResult);
|
return FspNtStatusFromWin32(RegResult);
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@
|
|||||||
//
|
//
|
||||||
// MessageText:
|
// MessageText:
|
||||||
//
|
//
|
||||||
// %1
|
// %1: %2
|
||||||
//
|
//
|
||||||
#define FSP_EVENTLOG_INFORMATION 0x60000001L
|
#define FSP_EVENTLOG_INFORMATION 0x60000001L
|
||||||
|
|
||||||
@ -48,7 +48,7 @@
|
|||||||
//
|
//
|
||||||
// MessageText:
|
// MessageText:
|
||||||
//
|
//
|
||||||
// %1
|
// %1: %2
|
||||||
//
|
//
|
||||||
#define FSP_EVENTLOG_WARNING 0xA0000001L
|
#define FSP_EVENTLOG_WARNING 0xA0000001L
|
||||||
|
|
||||||
@ -57,7 +57,7 @@
|
|||||||
//
|
//
|
||||||
// MessageText:
|
// MessageText:
|
||||||
//
|
//
|
||||||
// %1
|
// %1: %2
|
||||||
//
|
//
|
||||||
#define FSP_EVENTLOG_ERROR 0xE0000001L
|
#define FSP_EVENTLOG_ERROR 0xE0000001L
|
||||||
|
|
||||||
|
@ -2,19 +2,19 @@ MessageId=1
|
|||||||
Severity=Informational
|
Severity=Informational
|
||||||
SymbolicName=FSP_EVENTLOG_INFORMATION
|
SymbolicName=FSP_EVENTLOG_INFORMATION
|
||||||
Language=English
|
Language=English
|
||||||
%1
|
%1: %2
|
||||||
.
|
.
|
||||||
|
|
||||||
MessageId=1
|
MessageId=1
|
||||||
Severity=Warning
|
Severity=Warning
|
||||||
SymbolicName=FSP_EVENTLOG_WARNING
|
SymbolicName=FSP_EVENTLOG_WARNING
|
||||||
Language=English
|
Language=English
|
||||||
%1
|
%1: %2
|
||||||
.
|
.
|
||||||
|
|
||||||
MessageId=1
|
MessageId=1
|
||||||
Severity=Error
|
Severity=Error
|
||||||
SymbolicName=FSP_EVENTLOG_ERROR
|
SymbolicName=FSP_EVENTLOG_ERROR
|
||||||
Language=English
|
Language=English
|
||||||
%1
|
%1: %2
|
||||||
.
|
.
|
||||||
|
Binary file not shown.
160
src/dll/fs.c
160
src/dll/fs.c
@ -24,62 +24,35 @@ enum
|
|||||||
|
|
||||||
static FSP_FILE_SYSTEM_INTERFACE FspFileSystemNullInterface;
|
static FSP_FILE_SYSTEM_INTERFACE FspFileSystemNullInterface;
|
||||||
|
|
||||||
static CRITICAL_SECTION FspFileSystemMountListGuard;
|
static INIT_ONCE FspFileSystemInitOnce = INIT_ONCE_STATIC_INIT;
|
||||||
static LIST_ENTRY FspFileSystemMountList = { &FspFileSystemMountList, &FspFileSystemMountList };
|
static NTSTATUS (NTAPI *FspNtOpenSymbolicLinkObject)(
|
||||||
|
PHANDLE LinkHandle, ACCESS_MASK DesiredAccess, POBJECT_ATTRIBUTES ObjectAttributes);
|
||||||
|
static NTSTATUS (NTAPI *FspNtMakeTemporaryObject)(
|
||||||
|
HANDLE Handle);
|
||||||
|
static NTSTATUS (NTAPI *FspNtClose)(
|
||||||
|
HANDLE Handle);
|
||||||
|
|
||||||
VOID FspFileSystemInitialize(BOOLEAN Dynamic)
|
static BOOL WINAPI FspFileSystemInitialize(
|
||||||
|
PINIT_ONCE InitOnce, PVOID Parameter, PVOID *Context)
|
||||||
{
|
{
|
||||||
/*
|
HANDLE Handle;
|
||||||
* This function is called during DLL_PROCESS_ATTACH. We must therefore keep
|
|
||||||
* initialization tasks to a minimum.
|
|
||||||
*
|
|
||||||
* Initialization of synchronization objects is allowed! See:
|
|
||||||
* https://msdn.microsoft.com/en-us/library/windows/desktop/dn633971(v=vs.85).aspx
|
|
||||||
*/
|
|
||||||
|
|
||||||
InitializeCriticalSection(&FspFileSystemMountListGuard);
|
Handle = GetModuleHandleW(L"ntdll.dll");
|
||||||
|
if (0 != Handle)
|
||||||
|
{
|
||||||
|
FspNtOpenSymbolicLinkObject = (PVOID)GetProcAddress(Handle, "NtOpenSymbolicLinkObject");
|
||||||
|
FspNtMakeTemporaryObject = (PVOID)GetProcAddress(Handle, "NtMakeTemporaryObject");
|
||||||
|
FspNtClose = (PVOID)GetProcAddress(Handle, "NtClose");
|
||||||
|
|
||||||
|
if (0 == FspNtOpenSymbolicLinkObject || 0 == FspNtMakeTemporaryObject || 0 == FspNtClose)
|
||||||
|
{
|
||||||
|
FspNtOpenSymbolicLinkObject = 0;
|
||||||
|
FspNtMakeTemporaryObject = 0;
|
||||||
|
FspNtClose = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID FspFileSystemFinalize(BOOLEAN Dynamic)
|
return TRUE;
|
||||||
{
|
|
||||||
/*
|
|
||||||
* This function is called during DLL_PROCESS_DETACH. We must therefore keep
|
|
||||||
* finalization tasks to a minimum.
|
|
||||||
*
|
|
||||||
* We enter our FspFileSystemMountListGuard critical section here and then attempt to cleanup
|
|
||||||
* our mount points using DefineDosDeviceW. On Vista and later orphaned critical sections
|
|
||||||
* become "electrified", so our process will be forcefully terminated if one of its threads
|
|
||||||
* was already modifying the list when the ExitProcess happened. This is a good thing!
|
|
||||||
*
|
|
||||||
* The use of DefineDosDeviceW is rather suspect and probably unsafe. DefineDosDeviceW reaches
|
|
||||||
* out to CSRSS, which is probably not the safest thing to do when in DllMain! There is also
|
|
||||||
* some evidence that it may attempt to load DLL's under some circumstances, which is a
|
|
||||||
* definite no-no as we are under the loader lock!
|
|
||||||
*
|
|
||||||
* We only delete the criticaly section when being dynamically unloaded. On process exit the
|
|
||||||
* OS will clean it up for us.
|
|
||||||
*/
|
|
||||||
|
|
||||||
FSP_FILE_SYSTEM *FileSystem;
|
|
||||||
PLIST_ENTRY MountEntry;
|
|
||||||
|
|
||||||
EnterCriticalSection(&FspFileSystemMountListGuard);
|
|
||||||
|
|
||||||
for (MountEntry = FspFileSystemMountList.Flink;
|
|
||||||
&FspFileSystemMountList != MountEntry;
|
|
||||||
MountEntry = MountEntry->Flink)
|
|
||||||
{
|
|
||||||
FileSystem = CONTAINING_RECORD(MountEntry, FSP_FILE_SYSTEM, MountEntry);
|
|
||||||
|
|
||||||
DefineDosDeviceW(
|
|
||||||
DDD_RAW_TARGET_PATH | DDD_REMOVE_DEFINITION | DDD_EXACT_MATCH_ON_REMOVE,
|
|
||||||
FileSystem->MountPoint, FileSystem->VolumeName);
|
|
||||||
}
|
|
||||||
|
|
||||||
LeaveCriticalSection(&FspFileSystemMountListGuard);
|
|
||||||
|
|
||||||
if (Dynamic)
|
|
||||||
DeleteCriticalSection(&FspFileSystemMountListGuard);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FSP_API NTSTATUS FspFileSystemCreate(PWSTR DevicePath,
|
FSP_API NTSTATUS FspFileSystemCreate(PWSTR DevicePath,
|
||||||
@ -95,6 +68,8 @@ FSP_API NTSTATUS FspFileSystemCreate(PWSTR DevicePath,
|
|||||||
if (0 == Interface)
|
if (0 == Interface)
|
||||||
Interface = &FspFileSystemNullInterface;
|
Interface = &FspFileSystemNullInterface;
|
||||||
|
|
||||||
|
InitOnceExecuteOnce(&FspFileSystemInitOnce, FspFileSystemInitialize, 0, 0);
|
||||||
|
|
||||||
FileSystem = MemAlloc(sizeof *FileSystem);
|
FileSystem = MemAlloc(sizeof *FileSystem);
|
||||||
if (0 == FileSystem)
|
if (0 == FileSystem)
|
||||||
return STATUS_INSUFFICIENT_RESOURCES;
|
return STATUS_INSUFFICIENT_RESOURCES;
|
||||||
@ -123,9 +98,13 @@ FSP_API NTSTATUS FspFileSystemCreate(PWSTR DevicePath,
|
|||||||
FileSystem->Operations[FspFsctlTransactQueryDirectoryKind] = FspFileSystemOpQueryDirectory;
|
FileSystem->Operations[FspFsctlTransactQueryDirectoryKind] = FspFileSystemOpQueryDirectory;
|
||||||
FileSystem->Operations[FspFsctlTransactQuerySecurityKind] = FspFileSystemOpQuerySecurity;
|
FileSystem->Operations[FspFsctlTransactQuerySecurityKind] = FspFileSystemOpQuerySecurity;
|
||||||
FileSystem->Operations[FspFsctlTransactSetSecurityKind] = FspFileSystemOpSetSecurity;
|
FileSystem->Operations[FspFsctlTransactSetSecurityKind] = FspFileSystemOpSetSecurity;
|
||||||
// !!!: ...
|
|
||||||
FileSystem->Interface = Interface;
|
FileSystem->Interface = Interface;
|
||||||
|
|
||||||
|
FileSystem->OpGuardStrategy = FSP_FILE_SYSTEM_OPERATION_GUARD_STRATEGY_FINE;
|
||||||
|
InitializeSRWLock(&FileSystem->OpGuardLock);
|
||||||
|
FileSystem->EnterOperation = FspFileSystemOpEnter;
|
||||||
|
FileSystem->LeaveOperation = FspFileSystemOpLeave;
|
||||||
|
|
||||||
*PFileSystem = FileSystem;
|
*PFileSystem = FileSystem;
|
||||||
|
|
||||||
return STATUS_SUCCESS;
|
return STATUS_SUCCESS;
|
||||||
@ -144,6 +123,7 @@ FSP_API NTSTATUS FspFileSystemSetMountPoint(FSP_FILE_SYSTEM *FileSystem, PWSTR M
|
|||||||
return STATUS_INVALID_PARAMETER;
|
return STATUS_INVALID_PARAMETER;
|
||||||
|
|
||||||
NTSTATUS Result;
|
NTSTATUS Result;
|
||||||
|
HANDLE MountHandle = 0;
|
||||||
|
|
||||||
if (0 == MountPoint)
|
if (0 == MountPoint)
|
||||||
{
|
{
|
||||||
@ -196,13 +176,41 @@ FSP_API NTSTATUS FspFileSystemSetMountPoint(FSP_FILE_SYSTEM *FileSystem, PWSTR M
|
|||||||
}
|
}
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
|
if (NT_SUCCESS(Result) && 0 != FspNtOpenSymbolicLinkObject)
|
||||||
|
{
|
||||||
|
WCHAR SymlinkBuf[6];
|
||||||
|
UNICODE_STRING Symlink;
|
||||||
|
OBJECT_ATTRIBUTES Obja;
|
||||||
|
|
||||||
|
memcpy(SymlinkBuf, L"\\??\\X:", sizeof SymlinkBuf);
|
||||||
|
SymlinkBuf[4] = MountPoint[0];
|
||||||
|
Symlink.Length = Symlink.MaximumLength = sizeof SymlinkBuf;
|
||||||
|
Symlink.Buffer = SymlinkBuf;
|
||||||
|
|
||||||
|
memset(&Obja, 0, sizeof Obja);
|
||||||
|
Obja.Length = sizeof Obja;
|
||||||
|
Obja.ObjectName = &Symlink;
|
||||||
|
Obja.Attributes = OBJ_CASE_INSENSITIVE;
|
||||||
|
|
||||||
|
Result = FspNtOpenSymbolicLinkObject(&MountHandle, DELETE, &Obja);
|
||||||
|
if (NT_SUCCESS(Result))
|
||||||
|
{
|
||||||
|
Result = FspNtMakeTemporaryObject(MountHandle);
|
||||||
|
if (!NT_SUCCESS(Result))
|
||||||
|
{
|
||||||
|
FspNtClose(MountHandle);
|
||||||
|
MountHandle = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* this path always considered successful regardless if we made symlink temporary */
|
||||||
|
Result = STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
if (NT_SUCCESS(Result))
|
if (NT_SUCCESS(Result))
|
||||||
{
|
{
|
||||||
FileSystem->MountPoint = MountPoint;
|
FileSystem->MountPoint = MountPoint;
|
||||||
|
FileSystem->MountHandle = MountHandle;
|
||||||
EnterCriticalSection(&FspFileSystemMountListGuard);
|
|
||||||
InsertTailList(&FspFileSystemMountList, &FileSystem->MountEntry);
|
|
||||||
LeaveCriticalSection(&FspFileSystemMountListGuard);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
MemFree(MountPoint);
|
MemFree(MountPoint);
|
||||||
@ -215,15 +223,16 @@ FSP_API VOID FspFileSystemRemoveMountPoint(FSP_FILE_SYSTEM *FileSystem)
|
|||||||
if (0 == FileSystem->MountPoint)
|
if (0 == FileSystem->MountPoint)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
EnterCriticalSection(&FspFileSystemMountListGuard);
|
|
||||||
RemoveEntryList(&FileSystem->MountEntry);
|
|
||||||
LeaveCriticalSection(&FspFileSystemMountListGuard);
|
|
||||||
|
|
||||||
DefineDosDeviceW(DDD_RAW_TARGET_PATH | DDD_REMOVE_DEFINITION | DDD_EXACT_MATCH_ON_REMOVE,
|
DefineDosDeviceW(DDD_RAW_TARGET_PATH | DDD_REMOVE_DEFINITION | DDD_EXACT_MATCH_ON_REMOVE,
|
||||||
FileSystem->MountPoint, FileSystem->VolumeName);
|
FileSystem->MountPoint, FileSystem->VolumeName);
|
||||||
|
|
||||||
MemFree(FileSystem->MountPoint);
|
MemFree(FileSystem->MountPoint);
|
||||||
FileSystem->MountPoint = 0;
|
FileSystem->MountPoint = 0;
|
||||||
|
|
||||||
|
if (0 != FileSystem->MountHandle)
|
||||||
|
{
|
||||||
|
FspNtClose(FileSystem->MountHandle);
|
||||||
|
FileSystem->MountHandle = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static DWORD WINAPI FspFileSystemDispatcherThread(PVOID FileSystem0)
|
static DWORD WINAPI FspFileSystemDispatcherThread(PVOID FileSystem0)
|
||||||
@ -267,24 +276,37 @@ static DWORD WINAPI FspFileSystemDispatcherThread(PVOID FileSystem0)
|
|||||||
if (0 == RequestSize)
|
if (0 == RequestSize)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
#if 0
|
if (FileSystem->DebugLog)
|
||||||
FspDebugLog("FspFileSystemDispatcherThread: TID=%ld, Request={Kind=%d, Hint=%p}\n",
|
{
|
||||||
GetCurrentThreadId(), Request->Kind, (PVOID)Request->Hint);
|
if (FspFsctlTransactKindCount <= Request->Kind ||
|
||||||
#endif
|
(FileSystem->DebugLog & (1 << Request->Kind)))
|
||||||
|
FspDebugLogRequest(Request);
|
||||||
|
}
|
||||||
|
|
||||||
Response->Size = sizeof *Response;
|
Response->Size = sizeof *Response;
|
||||||
Response->Kind = Request->Kind;
|
Response->Kind = Request->Kind;
|
||||||
Response->Hint = Request->Hint;
|
Response->Hint = Request->Hint;
|
||||||
if (FspFsctlTransactKindCount > Request->Kind && 0 != FileSystem->Operations[Request->Kind])
|
if (FspFsctlTransactKindCount > Request->Kind && 0 != FileSystem->Operations[Request->Kind])
|
||||||
{
|
{
|
||||||
|
Response->IoStatus.Status =
|
||||||
FspFileSystemEnterOperation(FileSystem, Request, Response);
|
FspFileSystemEnterOperation(FileSystem, Request, Response);
|
||||||
|
if (NT_SUCCESS(Response->IoStatus.Status))
|
||||||
|
{
|
||||||
Response->IoStatus.Status =
|
Response->IoStatus.Status =
|
||||||
FileSystem->Operations[Request->Kind](FileSystem, Request, Response);
|
FileSystem->Operations[Request->Kind](FileSystem, Request, Response);
|
||||||
FspFileSystemLeaveOperation(FileSystem, Request, Response);
|
FspFileSystemLeaveOperation(FileSystem, Request, Response);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
Response->IoStatus.Status = STATUS_INVALID_DEVICE_REQUEST;
|
Response->IoStatus.Status = STATUS_INVALID_DEVICE_REQUEST;
|
||||||
|
|
||||||
|
if (FileSystem->DebugLog)
|
||||||
|
{
|
||||||
|
if (FspFsctlTransactKindCount <= Response->Kind ||
|
||||||
|
(FileSystem->DebugLog & (1 << Response->Kind)))
|
||||||
|
FspDebugLogResponse(Response);
|
||||||
|
}
|
||||||
|
|
||||||
ResponseSize = FSP_FSCTL_DEFAULT_ALIGN_UP(Response->Size);
|
ResponseSize = FSP_FSCTL_DEFAULT_ALIGN_UP(Response->Size);
|
||||||
if (FSP_FSCTL_TRANSACT_RSP_SIZEMAX < ResponseSize/* should NOT happen */)
|
if (FSP_FSCTL_TRANSACT_RSP_SIZEMAX < ResponseSize/* should NOT happen */)
|
||||||
{
|
{
|
||||||
@ -357,6 +379,7 @@ FSP_API VOID FspFileSystemStopDispatcher(FSP_FILE_SYSTEM *FileSystem)
|
|||||||
|
|
||||||
WaitForSingleObject(FileSystem->DispatcherThread, INFINITE);
|
WaitForSingleObject(FileSystem->DispatcherThread, INFINITE);
|
||||||
CloseHandle(FileSystem->DispatcherThread);
|
CloseHandle(FileSystem->DispatcherThread);
|
||||||
|
FileSystem->DispatcherThread = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
FSP_API VOID FspFileSystemSendResponse(FSP_FILE_SYSTEM *FileSystem,
|
FSP_API VOID FspFileSystemSendResponse(FSP_FILE_SYSTEM *FileSystem,
|
||||||
@ -364,6 +387,13 @@ FSP_API VOID FspFileSystemSendResponse(FSP_FILE_SYSTEM *FileSystem,
|
|||||||
{
|
{
|
||||||
NTSTATUS Result;
|
NTSTATUS Result;
|
||||||
|
|
||||||
|
if (FileSystem->DebugLog)
|
||||||
|
{
|
||||||
|
if (FspFsctlTransactKindCount <= Response->Kind ||
|
||||||
|
(FileSystem->DebugLog & (1 << Response->Kind)))
|
||||||
|
FspDebugLogResponse(Response);
|
||||||
|
}
|
||||||
|
|
||||||
Result = FspFsctlTransact(FileSystem->VolumeHandle,
|
Result = FspFsctlTransact(FileSystem->VolumeHandle,
|
||||||
Response, Response->Size, 0, 0, FALSE);
|
Response, Response->Size, 0, 0, FALSE);
|
||||||
if (!NT_SUCCESS(Result))
|
if (!NT_SUCCESS(Result))
|
||||||
|
@ -193,6 +193,23 @@ exit:
|
|||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FSP_API NTSTATUS FspFsctlPreflight(PWSTR DevicePath)
|
||||||
|
{
|
||||||
|
NTSTATUS Result;
|
||||||
|
SIZE_T VolumeListSize;
|
||||||
|
|
||||||
|
Result = FspFsctlStartService();
|
||||||
|
if (!NT_SUCCESS(Result))
|
||||||
|
return Result;
|
||||||
|
|
||||||
|
VolumeListSize = 0;
|
||||||
|
Result = FspFsctlGetVolumeList(DevicePath, 0, &VolumeListSize);
|
||||||
|
if (!NT_SUCCESS(Result) && STATUS_BUFFER_TOO_SMALL != Result)
|
||||||
|
return Result;
|
||||||
|
|
||||||
|
return STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
static NTSTATUS FspFsctlStartService(VOID)
|
static NTSTATUS FspFsctlStartService(VOID)
|
||||||
{
|
{
|
||||||
PWSTR DriverName = L"" FSP_FSCTL_DRIVER_NAME;
|
PWSTR DriverName = L"" FSP_FSCTL_DRIVER_NAME;
|
||||||
@ -212,7 +229,11 @@ static NTSTATUS FspFsctlStartService(VOID)
|
|||||||
SvcHandle = OpenServiceW(ScmHandle, DriverName, SERVICE_QUERY_STATUS | SERVICE_START);
|
SvcHandle = OpenServiceW(ScmHandle, DriverName, SERVICE_QUERY_STATUS | SERVICE_START);
|
||||||
if (0 == SvcHandle)
|
if (0 == SvcHandle)
|
||||||
{
|
{
|
||||||
Result = FspNtStatusFromWin32(GetLastError());
|
LastError = GetLastError();
|
||||||
|
if (ERROR_SERVICE_DOES_NOT_EXIST != LastError)
|
||||||
|
Result = FspNtStatusFromWin32(LastError);
|
||||||
|
else
|
||||||
|
Result = STATUS_NO_SUCH_DEVICE;
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
204
src/dll/fsop.c
204
src/dll/fsop.c
@ -17,6 +17,96 @@
|
|||||||
|
|
||||||
#include <dll/library.h>
|
#include <dll/library.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The FspFileSystemOpEnter/FspFileSystemOpLeave functions guard against
|
||||||
|
* concurrent accesses. Two concurrency models are provided:
|
||||||
|
*
|
||||||
|
* 1. A fine-grained concurrency model where file system NAMESPACE accesses
|
||||||
|
* are guarded using an exclusive-shared (read-write) lock. File I/O is not
|
||||||
|
* guarded and concurrent reads/writes/etc. are possible. [Note that the FSD
|
||||||
|
* will still apply an exclusive-shared lock PER INDIVIDUAL FILE, but it will
|
||||||
|
* not limit I/O operations for different files.]
|
||||||
|
*
|
||||||
|
* The fine-grained concurrency model applies the exclusive-shared lock as
|
||||||
|
* follows:
|
||||||
|
* - EXCL: SetVolumeLabel, Create, Cleanup(Delete), SetInformation(Rename)
|
||||||
|
* - SHRD: GetVolumeInfo, Open, SetInformation(Disposition), ReadDirectory
|
||||||
|
* - NONE: all other operations
|
||||||
|
*
|
||||||
|
* 2. A coarse-grained concurrency model where all file system accesses are
|
||||||
|
* guarded by a mutually exclusive lock.
|
||||||
|
*/
|
||||||
|
|
||||||
|
FSP_API NTSTATUS FspFileSystemOpEnter(FSP_FILE_SYSTEM *FileSystem,
|
||||||
|
FSP_FSCTL_TRANSACT_REQ *Request, FSP_FSCTL_TRANSACT_RSP *Response)
|
||||||
|
{
|
||||||
|
switch (FileSystem->OpGuardStrategy)
|
||||||
|
{
|
||||||
|
case FSP_FILE_SYSTEM_OPERATION_GUARD_STRATEGY_FINE:
|
||||||
|
if ((FspFsctlTransactCreateKind == Request->Kind &&
|
||||||
|
FILE_OPEN != ((Request->Req.Create.CreateOptions >> 24) & 0xff)) ||
|
||||||
|
(FspFsctlTransactCleanupKind == Request->Kind &&
|
||||||
|
Request->Req.Cleanup.Delete) ||
|
||||||
|
(FspFsctlTransactSetInformationKind == Request->Kind &&
|
||||||
|
10/*FileRenameInformation*/ == Request->Req.SetInformation.FileInformationClass) ||
|
||||||
|
FspFsctlTransactSetVolumeInformationKind == Request->Kind)
|
||||||
|
{
|
||||||
|
AcquireSRWLockExclusive(&FileSystem->OpGuardLock);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if (FspFsctlTransactCreateKind == Request->Kind ||
|
||||||
|
(FspFsctlTransactSetInformationKind == Request->Kind &&
|
||||||
|
13/*FileDispositionInformation*/ == Request->Req.SetInformation.FileInformationClass) ||
|
||||||
|
FspFsctlTransactQueryDirectoryKind == Request->Kind ||
|
||||||
|
FspFsctlTransactQueryVolumeInformationKind == Request->Kind)
|
||||||
|
{
|
||||||
|
AcquireSRWLockShared(&FileSystem->OpGuardLock);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case FSP_FILE_SYSTEM_OPERATION_GUARD_STRATEGY_COARSE:
|
||||||
|
AcquireSRWLockExclusive(&FileSystem->OpGuardLock);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
FSP_API NTSTATUS FspFileSystemOpLeave(FSP_FILE_SYSTEM *FileSystem,
|
||||||
|
FSP_FSCTL_TRANSACT_REQ *Request, FSP_FSCTL_TRANSACT_RSP *Response)
|
||||||
|
{
|
||||||
|
switch (FileSystem->OpGuardStrategy)
|
||||||
|
{
|
||||||
|
case FSP_FILE_SYSTEM_OPERATION_GUARD_STRATEGY_FINE:
|
||||||
|
if ((FspFsctlTransactCreateKind == Request->Kind &&
|
||||||
|
FILE_OPEN != ((Request->Req.Create.CreateOptions >> 24) & 0xff)) ||
|
||||||
|
(FspFsctlTransactCleanupKind == Request->Kind &&
|
||||||
|
Request->Req.Cleanup.Delete) ||
|
||||||
|
(FspFsctlTransactSetInformationKind == Request->Kind &&
|
||||||
|
10/*FileRenameInformation*/ == Request->Req.SetInformation.FileInformationClass) ||
|
||||||
|
FspFsctlTransactSetVolumeInformationKind == Request->Kind)
|
||||||
|
{
|
||||||
|
ReleaseSRWLockExclusive(&FileSystem->OpGuardLock);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if (FspFsctlTransactCreateKind == Request->Kind ||
|
||||||
|
(FspFsctlTransactSetInformationKind == Request->Kind &&
|
||||||
|
13/*FileDispositionInformation*/ == Request->Req.SetInformation.FileInformationClass) ||
|
||||||
|
FspFsctlTransactQueryDirectoryKind == Request->Kind ||
|
||||||
|
FspFsctlTransactQueryVolumeInformationKind == Request->Kind)
|
||||||
|
{
|
||||||
|
ReleaseSRWLockShared(&FileSystem->OpGuardLock);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case FSP_FILE_SYSTEM_OPERATION_GUARD_STRATEGY_COARSE:
|
||||||
|
ReleaseSRWLockExclusive(&FileSystem->OpGuardLock);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
static inline
|
static inline
|
||||||
NTSTATUS FspFileSystemCreateCheck(FSP_FILE_SYSTEM *FileSystem,
|
NTSTATUS FspFileSystemCreateCheck(FSP_FILE_SYSTEM *FileSystem,
|
||||||
FSP_FSCTL_TRANSACT_REQ *Request,
|
FSP_FSCTL_TRANSACT_REQ *Request,
|
||||||
@ -25,6 +115,15 @@ NTSTATUS FspFileSystemCreateCheck(FSP_FILE_SYSTEM *FileSystem,
|
|||||||
{
|
{
|
||||||
NTSTATUS Result;
|
NTSTATUS Result;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* CreateCheck consists of checking the parent directory for the
|
||||||
|
* FILE_ADD_SUBDIRECTORY or FILE_ADD_FILE rights (depending on whether
|
||||||
|
* we are creating a file or directory).
|
||||||
|
*
|
||||||
|
* If the access check succeeds and MAXIMUM_ALLOWED has been requested
|
||||||
|
* then we go ahead and grant all access to the creator.
|
||||||
|
*/
|
||||||
|
|
||||||
Result = FspAccessCheckEx(FileSystem, Request, TRUE, AllowTraverseCheck,
|
Result = FspAccessCheckEx(FileSystem, Request, TRUE, AllowTraverseCheck,
|
||||||
(Request->Req.Create.CreateOptions & FILE_DIRECTORY_FILE) ?
|
(Request->Req.Create.CreateOptions & FILE_DIRECTORY_FILE) ?
|
||||||
FILE_ADD_SUBDIRECTORY : FILE_ADD_FILE,
|
FILE_ADD_SUBDIRECTORY : FILE_ADD_FILE,
|
||||||
@ -45,6 +144,16 @@ NTSTATUS FspFileSystemOpenCheck(FSP_FILE_SYSTEM *FileSystem,
|
|||||||
{
|
{
|
||||||
NTSTATUS Result;
|
NTSTATUS Result;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* OpenCheck consists of checking the file for the desired access,
|
||||||
|
* unless FILE_DELETE_ON_CLOSE is requested in which case we also
|
||||||
|
* check for DELETE access.
|
||||||
|
*
|
||||||
|
* If the access check succeeds and MAXIMUM_ALLOWED was not requested
|
||||||
|
* then we reset the DELETE access based on whether it was actually
|
||||||
|
* requested in DesiredAccess.
|
||||||
|
*/
|
||||||
|
|
||||||
Result = FspAccessCheck(FileSystem, Request, FALSE, AllowTraverseCheck,
|
Result = FspAccessCheck(FileSystem, Request, FALSE, AllowTraverseCheck,
|
||||||
Request->Req.Create.DesiredAccess |
|
Request->Req.Create.DesiredAccess |
|
||||||
((Request->Req.Create.CreateOptions & FILE_DELETE_ON_CLOSE) ? DELETE : 0),
|
((Request->Req.Create.CreateOptions & FILE_DELETE_ON_CLOSE) ? DELETE : 0),
|
||||||
@ -66,6 +175,17 @@ NTSTATUS FspFileSystemOverwriteCheck(FSP_FILE_SYSTEM *FileSystem,
|
|||||||
NTSTATUS Result;
|
NTSTATUS Result;
|
||||||
BOOLEAN Supersede = FILE_SUPERSEDE == ((Request->Req.Create.CreateOptions >> 24) & 0xff);
|
BOOLEAN Supersede = FILE_SUPERSEDE == ((Request->Req.Create.CreateOptions >> 24) & 0xff);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* OverwriteCheck consists of checking the file for the desired access,
|
||||||
|
* unless FILE_DELETE_ON_CLOSE is requested in which case we also
|
||||||
|
* check for DELETE access. Furthermore we grant DELETE or FILE_WRITE_DATA
|
||||||
|
* access based on whether this is a Supersede or Overwrite operation.
|
||||||
|
*
|
||||||
|
* If the access check succeeds and MAXIMUM_ALLOWED was not requested
|
||||||
|
* then we reset the DELETE and FILE_WRITE_DATA accesses based on whether
|
||||||
|
* they were actually requested in DesiredAccess.
|
||||||
|
*/
|
||||||
|
|
||||||
Result = FspAccessCheck(FileSystem, Request, FALSE, AllowTraverseCheck,
|
Result = FspAccessCheck(FileSystem, Request, FALSE, AllowTraverseCheck,
|
||||||
Request->Req.Create.DesiredAccess |
|
Request->Req.Create.DesiredAccess |
|
||||||
(Supersede ? DELETE : FILE_WRITE_DATA) |
|
(Supersede ? DELETE : FILE_WRITE_DATA) |
|
||||||
@ -81,6 +201,56 @@ NTSTATUS FspFileSystemOverwriteCheck(FSP_FILE_SYSTEM *FileSystem,
|
|||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline
|
||||||
|
NTSTATUS FspFileSystemRenameCheck(FSP_FILE_SYSTEM *FileSystem,
|
||||||
|
FSP_FSCTL_TRANSACT_REQ *Request)
|
||||||
|
{
|
||||||
|
NTSTATUS Result;
|
||||||
|
FSP_FSCTL_TRANSACT_REQ *CreateRequest = 0;
|
||||||
|
UINT32 GrantedAccess;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* RenameCheck consists of checking the new file name for DELETE access.
|
||||||
|
*
|
||||||
|
* The following assumptions are being made here for a file that is going
|
||||||
|
* to be replaced:
|
||||||
|
* - The new file is in the same directory as the old one. In that case
|
||||||
|
* there is no need for traverse access checks as they have been already
|
||||||
|
* performed (if necessary) when opening the file under the existing file
|
||||||
|
* name.
|
||||||
|
* - The new file is in a different directory than the old one. In that case
|
||||||
|
* NTOS called us with SL_OPEN_TARGET_DIRECTORY and we performed any
|
||||||
|
* necessary traverse access checks at that time.
|
||||||
|
*
|
||||||
|
* FspAccessCheckEx only works on Create requests, so we have to build
|
||||||
|
* a fake one just for that purpose. Sigh!
|
||||||
|
*/
|
||||||
|
|
||||||
|
CreateRequest = MemAlloc(sizeof *CreateRequest +
|
||||||
|
Request->Req.SetInformation.Info.Rename.NewFileName.Size);
|
||||||
|
if (0 == CreateRequest)
|
||||||
|
return STATUS_INSUFFICIENT_RESOURCES;
|
||||||
|
|
||||||
|
memset(CreateRequest, 0, sizeof *CreateRequest);
|
||||||
|
CreateRequest->Size = sizeof CreateRequest +
|
||||||
|
Request->Req.SetInformation.Info.Rename.NewFileName.Size;
|
||||||
|
CreateRequest->Kind = FspFsctlTransactCreateKind;
|
||||||
|
CreateRequest->Req.Create.CreateOptions = FILE_DELETE_ON_CLOSE; /* force read-only check! */
|
||||||
|
CreateRequest->Req.Create.AccessToken = Request->Req.SetInformation.Info.Rename.AccessToken;
|
||||||
|
CreateRequest->Req.Create.UserMode = TRUE;
|
||||||
|
CreateRequest->FileName.Offset = 0;
|
||||||
|
CreateRequest->FileName.Size = Request->Req.SetInformation.Info.Rename.NewFileName.Size;
|
||||||
|
memcpy(CreateRequest->Buffer,
|
||||||
|
Request->Buffer + Request->Req.SetInformation.Info.Rename.NewFileName.Offset,
|
||||||
|
Request->Req.SetInformation.Info.Rename.NewFileName.Size);
|
||||||
|
|
||||||
|
Result = FspAccessCheck(FileSystem, CreateRequest, FALSE, FALSE, DELETE, &GrantedAccess);
|
||||||
|
|
||||||
|
MemFree(CreateRequest);
|
||||||
|
|
||||||
|
return Result;
|
||||||
|
}
|
||||||
|
|
||||||
static NTSTATUS FspFileSystemOpCreate_FileCreate(FSP_FILE_SYSTEM *FileSystem,
|
static NTSTATUS FspFileSystemOpCreate_FileCreate(FSP_FILE_SYSTEM *FileSystem,
|
||||||
FSP_FSCTL_TRANSACT_REQ *Request, FSP_FSCTL_TRANSACT_RSP *Response)
|
FSP_FSCTL_TRANSACT_REQ *Request, FSP_FSCTL_TRANSACT_RSP *Response)
|
||||||
{
|
{
|
||||||
@ -520,32 +690,17 @@ FSP_API NTSTATUS FspFileSystemOpSetInformation(FSP_FILE_SYSTEM *FileSystem,
|
|||||||
&FileInfo);
|
&FileInfo);
|
||||||
break;
|
break;
|
||||||
case 19/*FileAllocationInformation*/:
|
case 19/*FileAllocationInformation*/:
|
||||||
if (0 != FileSystem->Interface->SetAllocationSize)
|
if (0 != FileSystem->Interface->SetFileSize)
|
||||||
Result = FileSystem->Interface->SetAllocationSize(FileSystem, Request,
|
|
||||||
(PVOID)Request->Req.SetInformation.UserContext,
|
|
||||||
Request->Req.SetInformation.Info.Allocation.AllocationSize,
|
|
||||||
&FileInfo);
|
|
||||||
else
|
|
||||||
if (0 != FileSystem->Interface->GetFileInfo &&
|
|
||||||
0 != FileSystem->Interface->SetFileSize)
|
|
||||||
{
|
|
||||||
Result = FileSystem->Interface->GetFileInfo(FileSystem, Request,
|
|
||||||
(PVOID)Request->Req.SetInformation.UserContext, &FileInfo);
|
|
||||||
if (NT_SUCCESS(Result) &&
|
|
||||||
Request->Req.SetInformation.Info.Allocation.AllocationSize < FileInfo.FileSize)
|
|
||||||
{
|
|
||||||
Result = FileSystem->Interface->SetFileSize(FileSystem, Request,
|
Result = FileSystem->Interface->SetFileSize(FileSystem, Request,
|
||||||
(PVOID)Request->Req.SetInformation.UserContext,
|
(PVOID)Request->Req.SetInformation.UserContext,
|
||||||
Request->Req.SetInformation.Info.Allocation.AllocationSize,
|
Request->Req.SetInformation.Info.Allocation.AllocationSize, TRUE,
|
||||||
&FileInfo);
|
&FileInfo);
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case 20/*FileEndOfFileInformation*/:
|
case 20/*FileEndOfFileInformation*/:
|
||||||
if (0 != FileSystem->Interface->SetFileSize)
|
if (0 != FileSystem->Interface->SetFileSize)
|
||||||
Result = FileSystem->Interface->SetFileSize(FileSystem, Request,
|
Result = FileSystem->Interface->SetFileSize(FileSystem, Request,
|
||||||
(PVOID)Request->Req.SetInformation.UserContext,
|
(PVOID)Request->Req.SetInformation.UserContext,
|
||||||
Request->Req.SetInformation.Info.EndOfFile.FileSize,
|
Request->Req.SetInformation.Info.EndOfFile.FileSize, FALSE,
|
||||||
&FileInfo);
|
&FileInfo);
|
||||||
break;
|
break;
|
||||||
case 13/*FileDispositionInformation*/:
|
case 13/*FileDispositionInformation*/:
|
||||||
@ -569,11 +724,21 @@ FSP_API NTSTATUS FspFileSystemOpSetInformation(FSP_FILE_SYSTEM *FileSystem,
|
|||||||
break;
|
break;
|
||||||
case 10/*FileRenameInformation*/:
|
case 10/*FileRenameInformation*/:
|
||||||
if (0 != FileSystem->Interface->Rename)
|
if (0 != FileSystem->Interface->Rename)
|
||||||
|
{
|
||||||
|
if (0 != Request->Req.SetInformation.Info.Rename.AccessToken)
|
||||||
|
{
|
||||||
|
Result = FspFileSystemRenameCheck(FileSystem, Request);
|
||||||
|
if (!NT_SUCCESS(Result) &&
|
||||||
|
STATUS_OBJECT_PATH_NOT_FOUND != Result &&
|
||||||
|
STATUS_OBJECT_NAME_NOT_FOUND != Result)
|
||||||
|
break;
|
||||||
|
}
|
||||||
Result = FileSystem->Interface->Rename(FileSystem, Request,
|
Result = FileSystem->Interface->Rename(FileSystem, Request,
|
||||||
(PVOID)Request->Req.SetInformation.UserContext,
|
(PVOID)Request->Req.SetInformation.UserContext,
|
||||||
(PWSTR)Request->Buffer,
|
(PWSTR)Request->Buffer,
|
||||||
(PWSTR)(Request->Buffer + Request->Req.SetInformation.Info.Rename.NewFileName.Offset),
|
(PWSTR)(Request->Buffer + Request->Req.SetInformation.Info.Rename.NewFileName.Offset),
|
||||||
Request->Req.SetInformation.Info.Rename.ReplaceIfExists);
|
0 != Request->Req.SetInformation.Info.Rename.AccessToken);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -617,6 +782,7 @@ FSP_API NTSTATUS FspFileSystemOpSetVolumeInformation(FSP_FILE_SYSTEM *FileSystem
|
|||||||
Result = FileSystem->Interface->SetVolumeLabel(FileSystem, Request,
|
Result = FileSystem->Interface->SetVolumeLabel(FileSystem, Request,
|
||||||
(PWSTR)Request->Buffer,
|
(PWSTR)Request->Buffer,
|
||||||
&VolumeInfo);
|
&VolumeInfo);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!NT_SUCCESS(Result))
|
if (!NT_SUCCESS(Result))
|
||||||
|
115
src/dll/fuse/errno.i
Normal file
115
src/dll/fuse/errno.i
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
#if FSP_FUSE_ERRNO == 87 /* Windows */
|
||||||
|
|
||||||
|
case 0: return STATUS_SUCCESS;
|
||||||
|
case 1: return STATUS_ACCESS_DENIED;
|
||||||
|
case 2: return STATUS_OBJECT_NAME_NOT_FOUND;
|
||||||
|
case 3: return STATUS_PROCEDURE_NOT_FOUND;
|
||||||
|
case 4: return STATUS_CANCELLED;
|
||||||
|
case 5: return STATUS_IO_DEVICE_ERROR;
|
||||||
|
case 6: return STATUS_FILE_INVALID;
|
||||||
|
case 7: return STATUS_INSUFFICIENT_RESOURCES;
|
||||||
|
case 8: return STATUS_INVALID_IMAGE_FORMAT;
|
||||||
|
case 9: return STATUS_INVALID_HANDLE;
|
||||||
|
case 12: return STATUS_INSUFFICIENT_RESOURCES;
|
||||||
|
case 13: return STATUS_ACCESS_DENIED;
|
||||||
|
case 14: return STATUS_ACCESS_VIOLATION;
|
||||||
|
case 16: return STATUS_DEVICE_BUSY;
|
||||||
|
case 17: return STATUS_OBJECT_NAME_COLLISION;
|
||||||
|
case 18: return STATUS_NOT_SAME_DEVICE;
|
||||||
|
case 19: return STATUS_NO_SUCH_DEVICE;
|
||||||
|
case 20: return STATUS_NOT_A_DIRECTORY;
|
||||||
|
case 21: return STATUS_FILE_IS_A_DIRECTORY;
|
||||||
|
case 22: return STATUS_INVALID_PARAMETER;
|
||||||
|
case 23: return STATUS_TOO_MANY_OPENED_FILES;
|
||||||
|
case 24: return STATUS_TOO_MANY_OPENED_FILES;
|
||||||
|
case 27: return STATUS_DISK_FULL;
|
||||||
|
case 28: return STATUS_DISK_FULL;
|
||||||
|
case 29: return STATUS_INVALID_PARAMETER;
|
||||||
|
case 30: return STATUS_MEDIA_WRITE_PROTECTED;
|
||||||
|
case 31: return STATUS_TOO_MANY_LINKS;
|
||||||
|
case 32: return STATUS_PIPE_BROKEN;
|
||||||
|
case 33: return STATUS_INVALID_PARAMETER;
|
||||||
|
case 34: return STATUS_INVALID_PARAMETER;
|
||||||
|
case 36: return STATUS_POSSIBLE_DEADLOCK;
|
||||||
|
case 38: return STATUS_NAME_TOO_LONG;
|
||||||
|
case 39: return STATUS_LOCK_NOT_GRANTED;
|
||||||
|
case 40: return STATUS_INVALID_DEVICE_REQUEST;
|
||||||
|
case 41: return STATUS_DIRECTORY_NOT_EMPTY;
|
||||||
|
case 42: return STATUS_INVALID_PARAMETER;
|
||||||
|
case 100: return STATUS_ADDRESS_ALREADY_ASSOCIATED;
|
||||||
|
case 103: return STATUS_CONNECTION_ACTIVE;
|
||||||
|
case 105: return STATUS_CANCELLED;
|
||||||
|
case 106: return STATUS_CONNECTION_ABORTED;
|
||||||
|
case 107: return STATUS_CONNECTION_REFUSED;
|
||||||
|
case 108: return STATUS_CONNECTION_RESET;
|
||||||
|
case 110: return STATUS_HOST_UNREACHABLE;
|
||||||
|
case 113: return STATUS_CONNECTION_ACTIVE;
|
||||||
|
case 114: return STATUS_REPARSE_POINT_NOT_RESOLVED;
|
||||||
|
case 116: return STATUS_HOST_DOWN;
|
||||||
|
case 117: return STATUS_CONNECTION_RESET;
|
||||||
|
case 118: return STATUS_NETWORK_UNREACHABLE;
|
||||||
|
case 119: return STATUS_INSUFFICIENT_RESOURCES;
|
||||||
|
case 120: return STATUS_END_OF_FILE;
|
||||||
|
case 121: return STATUS_CONNECTION_INVALID;
|
||||||
|
case 126: return STATUS_CONNECTION_INVALID;
|
||||||
|
case 128: return STATUS_INVALID_HANDLE;
|
||||||
|
case 138: return STATUS_TRANSACTION_TIMED_OUT;
|
||||||
|
|
||||||
|
#elif FSP_FUSE_ERRNO == 67 /* Cygwin */
|
||||||
|
|
||||||
|
case 0: return STATUS_SUCCESS;
|
||||||
|
case 1: return STATUS_ACCESS_DENIED;
|
||||||
|
case 2: return STATUS_OBJECT_NAME_NOT_FOUND;
|
||||||
|
case 3: return STATUS_PROCEDURE_NOT_FOUND;
|
||||||
|
case 4: return STATUS_CANCELLED;
|
||||||
|
case 5: return STATUS_IO_DEVICE_ERROR;
|
||||||
|
case 6: return STATUS_FILE_INVALID;
|
||||||
|
case 7: return STATUS_INSUFFICIENT_RESOURCES;
|
||||||
|
case 8: return STATUS_INVALID_IMAGE_FORMAT;
|
||||||
|
case 9: return STATUS_INVALID_HANDLE;
|
||||||
|
case 12: return STATUS_INSUFFICIENT_RESOURCES;
|
||||||
|
case 13: return STATUS_ACCESS_DENIED;
|
||||||
|
case 14: return STATUS_ACCESS_VIOLATION;
|
||||||
|
case 16: return STATUS_DEVICE_BUSY;
|
||||||
|
case 17: return STATUS_OBJECT_NAME_COLLISION;
|
||||||
|
case 18: return STATUS_NOT_SAME_DEVICE;
|
||||||
|
case 19: return STATUS_NO_SUCH_DEVICE;
|
||||||
|
case 20: return STATUS_NOT_A_DIRECTORY;
|
||||||
|
case 21: return STATUS_FILE_IS_A_DIRECTORY;
|
||||||
|
case 22: return STATUS_INVALID_PARAMETER;
|
||||||
|
case 23: return STATUS_TOO_MANY_OPENED_FILES;
|
||||||
|
case 24: return STATUS_TOO_MANY_OPENED_FILES;
|
||||||
|
case 27: return STATUS_DISK_FULL;
|
||||||
|
case 28: return STATUS_DISK_FULL;
|
||||||
|
case 29: return STATUS_INVALID_PARAMETER;
|
||||||
|
case 30: return STATUS_MEDIA_WRITE_PROTECTED;
|
||||||
|
case 31: return STATUS_TOO_MANY_LINKS;
|
||||||
|
case 32: return STATUS_PIPE_BROKEN;
|
||||||
|
case 33: return STATUS_INVALID_PARAMETER;
|
||||||
|
case 34: return STATUS_INVALID_PARAMETER;
|
||||||
|
case 45: return STATUS_POSSIBLE_DEADLOCK;
|
||||||
|
case 91: return STATUS_NAME_TOO_LONG;
|
||||||
|
case 46: return STATUS_LOCK_NOT_GRANTED;
|
||||||
|
case 88: return STATUS_INVALID_DEVICE_REQUEST;
|
||||||
|
case 90: return STATUS_DIRECTORY_NOT_EMPTY;
|
||||||
|
case 138: return STATUS_INVALID_PARAMETER;
|
||||||
|
case 112: return STATUS_ADDRESS_ALREADY_ASSOCIATED;
|
||||||
|
case 120: return STATUS_CONNECTION_ACTIVE;
|
||||||
|
case 140: return STATUS_CANCELLED;
|
||||||
|
case 113: return STATUS_CONNECTION_ABORTED;
|
||||||
|
case 111: return STATUS_CONNECTION_REFUSED;
|
||||||
|
case 104: return STATUS_CONNECTION_RESET;
|
||||||
|
case 118: return STATUS_HOST_UNREACHABLE;
|
||||||
|
case 127: return STATUS_CONNECTION_ACTIVE;
|
||||||
|
case 92: return STATUS_REPARSE_POINT_NOT_RESOLVED;
|
||||||
|
case 115: return STATUS_HOST_DOWN;
|
||||||
|
case 126: return STATUS_CONNECTION_RESET;
|
||||||
|
case 114: return STATUS_NETWORK_UNREACHABLE;
|
||||||
|
case 105: return STATUS_INSUFFICIENT_RESOURCES;
|
||||||
|
case 61: return STATUS_END_OF_FILE;
|
||||||
|
case 67: return STATUS_CONNECTION_INVALID;
|
||||||
|
case 128: return STATUS_CONNECTION_INVALID;
|
||||||
|
case 108: return STATUS_INVALID_HANDLE;
|
||||||
|
case 116: return STATUS_TRANSACTION_TIMED_OUT;
|
||||||
|
|
||||||
|
#endif
|
657
src/dll/fuse/fuse.c
Normal file
657
src/dll/fuse/fuse.c
Normal file
@ -0,0 +1,657 @@
|
|||||||
|
/**
|
||||||
|
* @file dll/fuse/fuse.c
|
||||||
|
*
|
||||||
|
* @copyright 2015-2016 Bill Zissimopoulos
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* This file is part of WinFsp.
|
||||||
|
*
|
||||||
|
* You can redistribute it and/or modify it under the terms of the
|
||||||
|
* GNU Affero General Public License version 3 as published by the
|
||||||
|
* Free Software Foundation.
|
||||||
|
*
|
||||||
|
* Licensees holding a valid commercial license may use this file in
|
||||||
|
* accordance with the commercial license agreement provided with the
|
||||||
|
* software.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <dll/fuse/library.h>
|
||||||
|
|
||||||
|
#define FSP_FUSE_SECTORSIZE_MIN 512
|
||||||
|
#define FSP_FUSE_SECTORSIZE_MAX 4096
|
||||||
|
|
||||||
|
struct fuse_chan
|
||||||
|
{
|
||||||
|
PWSTR MountPoint;
|
||||||
|
UINT8 Buffer[];
|
||||||
|
};
|
||||||
|
|
||||||
|
#define FSP_FUSE_CORE_OPT(n, f, v) { n, offsetof(struct fsp_fuse_core_opt_data, f), v }
|
||||||
|
|
||||||
|
struct fsp_fuse_core_opt_data
|
||||||
|
{
|
||||||
|
struct fsp_fuse_env *env;
|
||||||
|
int help, debug;
|
||||||
|
int hard_remove,
|
||||||
|
use_ino, readdir_ino,
|
||||||
|
set_umask, umask,
|
||||||
|
set_uid, uid,
|
||||||
|
set_gid, gid,
|
||||||
|
set_attr_timeout, attr_timeout;
|
||||||
|
int set_FileInfoTimeout;
|
||||||
|
int CaseInsensitiveSearch, ReparsePoints,
|
||||||
|
NamedStreams, ReadOnlyVolume;
|
||||||
|
FSP_FSCTL_VOLUME_PARAMS VolumeParams;
|
||||||
|
};
|
||||||
|
|
||||||
|
static struct fuse_opt fsp_fuse_core_opts[] =
|
||||||
|
{
|
||||||
|
FUSE_OPT_KEY("-h", 'h'),
|
||||||
|
FUSE_OPT_KEY("--help", 'h'),
|
||||||
|
FUSE_OPT_KEY("-V", 'V'),
|
||||||
|
FUSE_OPT_KEY("--version", 'V'),
|
||||||
|
FUSE_OPT_KEY("-d", FUSE_OPT_KEY_KEEP),
|
||||||
|
FUSE_OPT_KEY("debug", FUSE_OPT_KEY_KEEP),
|
||||||
|
FSP_FUSE_CORE_OPT("-d", debug, 1),
|
||||||
|
FSP_FUSE_CORE_OPT("debug", debug, 1),
|
||||||
|
|
||||||
|
FSP_FUSE_CORE_OPT("hard_remove", hard_remove, 1),
|
||||||
|
FSP_FUSE_CORE_OPT("use_ino", use_ino, 1),
|
||||||
|
FSP_FUSE_CORE_OPT("readdir_ino", readdir_ino, 1),
|
||||||
|
FUSE_OPT_KEY("direct_io", FUSE_OPT_KEY_DISCARD),
|
||||||
|
FUSE_OPT_KEY("kernel_cache", FUSE_OPT_KEY_DISCARD),
|
||||||
|
FUSE_OPT_KEY("auto_cache", FUSE_OPT_KEY_DISCARD),
|
||||||
|
FUSE_OPT_KEY("noauto_cache", FUSE_OPT_KEY_DISCARD),
|
||||||
|
FSP_FUSE_CORE_OPT("umask=", set_umask, 1),
|
||||||
|
FSP_FUSE_CORE_OPT("umask=%o", umask, 0),
|
||||||
|
FSP_FUSE_CORE_OPT("uid=", set_uid, 1),
|
||||||
|
FSP_FUSE_CORE_OPT("uid=%d", uid, 0),
|
||||||
|
FSP_FUSE_CORE_OPT("gid=", set_gid, 1),
|
||||||
|
FSP_FUSE_CORE_OPT("gid=%d", gid, 0),
|
||||||
|
FUSE_OPT_KEY("entry_timeout", FUSE_OPT_KEY_DISCARD),
|
||||||
|
FSP_FUSE_CORE_OPT("attr_timeout=", set_attr_timeout, 1),
|
||||||
|
FSP_FUSE_CORE_OPT("attr_timeout=%d", attr_timeout, 0),
|
||||||
|
FUSE_OPT_KEY("ac_attr_timeout", FUSE_OPT_KEY_DISCARD),
|
||||||
|
FUSE_OPT_KEY("negative_timeout", FUSE_OPT_KEY_DISCARD),
|
||||||
|
FUSE_OPT_KEY("noforget", FUSE_OPT_KEY_DISCARD),
|
||||||
|
FUSE_OPT_KEY("intr", FUSE_OPT_KEY_DISCARD),
|
||||||
|
FUSE_OPT_KEY("intr_signal=", FUSE_OPT_KEY_DISCARD),
|
||||||
|
FUSE_OPT_KEY("modules=", FUSE_OPT_KEY_DISCARD),
|
||||||
|
|
||||||
|
FSP_FUSE_CORE_OPT("SectorSize=%hu", VolumeParams.SectorSize, 4096),
|
||||||
|
FSP_FUSE_CORE_OPT("SectorsPerAllocationUnit=%hu", VolumeParams.SectorsPerAllocationUnit, 1),
|
||||||
|
FSP_FUSE_CORE_OPT("MaxComponentLength=%hu", VolumeParams.MaxComponentLength, 0),
|
||||||
|
FSP_FUSE_CORE_OPT("VolumeCreationTime=%lli", VolumeParams.VolumeCreationTime, 0),
|
||||||
|
FSP_FUSE_CORE_OPT("VolumeSerialNumber=%lx", VolumeParams.VolumeSerialNumber, 0),
|
||||||
|
FSP_FUSE_CORE_OPT("TransactTimeout=%u", VolumeParams.TransactTimeout, 0),
|
||||||
|
FSP_FUSE_CORE_OPT("IrpTimeout=%u", VolumeParams.IrpTimeout, 0),
|
||||||
|
FSP_FUSE_CORE_OPT("IrpCapacity=%u", VolumeParams.IrpCapacity, 0),
|
||||||
|
FSP_FUSE_CORE_OPT("FileInfoTimeout=", set_FileInfoTimeout, 1),
|
||||||
|
FSP_FUSE_CORE_OPT("FileInfoTimeout=%d", VolumeParams.FileInfoTimeout, 0),
|
||||||
|
FSP_FUSE_CORE_OPT("CaseInsensitiveSearch", CaseInsensitiveSearch, 1),
|
||||||
|
FSP_FUSE_CORE_OPT("ReparsePoints", ReparsePoints, 1),
|
||||||
|
FSP_FUSE_CORE_OPT("NamedStreams", NamedStreams, 1),
|
||||||
|
FUSE_OPT_KEY("HardLinks", FUSE_OPT_KEY_DISCARD),
|
||||||
|
FUSE_OPT_KEY("ExtendedAttributes", FUSE_OPT_KEY_DISCARD),
|
||||||
|
FSP_FUSE_CORE_OPT("ReadOnlyVolume", ReadOnlyVolume, 1),
|
||||||
|
FUSE_OPT_KEY("--UNC=", 'U'),
|
||||||
|
FUSE_OPT_KEY("--VolumePrefix=", 'U'),
|
||||||
|
|
||||||
|
FUSE_OPT_END,
|
||||||
|
};
|
||||||
|
|
||||||
|
static INIT_ONCE fsp_fuse_initonce = INIT_ONCE_STATIC_INIT;
|
||||||
|
static DWORD fsp_fuse_tlskey = TLS_OUT_OF_INDEXES;
|
||||||
|
|
||||||
|
struct fsp_fuse_obj_hdr
|
||||||
|
{
|
||||||
|
void (*dtor)(void *);
|
||||||
|
__declspec(align(MEMORY_ALLOCATION_ALIGNMENT)) UINT8 ObjectBuf[];
|
||||||
|
};
|
||||||
|
|
||||||
|
static inline void *fsp_fuse_obj_alloc(struct fsp_fuse_env *env, size_t size)
|
||||||
|
{
|
||||||
|
struct fsp_fuse_obj_hdr *hdr;
|
||||||
|
|
||||||
|
hdr = env->memalloc(sizeof(struct fsp_fuse_obj_hdr) + size);
|
||||||
|
if (0 == hdr)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
hdr->dtor = env->memfree;
|
||||||
|
memset(hdr->ObjectBuf, 0, size);
|
||||||
|
return hdr->ObjectBuf;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void fsp_fuse_obj_free(void *obj)
|
||||||
|
{
|
||||||
|
struct fsp_fuse_obj_hdr *hdr = (PVOID)((PUINT8)obj - sizeof(struct fsp_fuse_obj_hdr));
|
||||||
|
|
||||||
|
hdr->dtor(hdr);
|
||||||
|
}
|
||||||
|
|
||||||
|
static BOOL WINAPI fsp_fuse_initialize(
|
||||||
|
PINIT_ONCE InitOnce, PVOID Parameter, PVOID *Context)
|
||||||
|
{
|
||||||
|
fsp_fuse_tlskey = TlsAlloc();
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID fsp_fuse_finalize(BOOLEAN Dynamic)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* This function is called during DLL_PROCESS_DETACH. We must therefore keep
|
||||||
|
* finalization tasks to a minimum.
|
||||||
|
*
|
||||||
|
* We must free our TLS key (if any). We only do so if the library
|
||||||
|
* is being explicitly unloaded (rather than the process exiting).
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (Dynamic && TLS_OUT_OF_INDEXES != fsp_fuse_tlskey)
|
||||||
|
{
|
||||||
|
/* !!!:
|
||||||
|
* We should also free all thread local contexts, which means putting them in a list,
|
||||||
|
* protected with a critical section, etc. Arghhh!
|
||||||
|
*
|
||||||
|
* I am too lazy and I am not going to do that, unless people start using this
|
||||||
|
* DLL dynamically (LoadLibrary/FreeLibrary).
|
||||||
|
*/
|
||||||
|
TlsFree(fsp_fuse_tlskey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID fsp_fuse_finalize_thread(VOID)
|
||||||
|
{
|
||||||
|
struct fuse_context *context;
|
||||||
|
|
||||||
|
if (TLS_OUT_OF_INDEXES != fsp_fuse_tlskey)
|
||||||
|
{
|
||||||
|
context = TlsGetValue(fsp_fuse_tlskey);
|
||||||
|
if (0 != context)
|
||||||
|
{
|
||||||
|
fsp_fuse_obj_free(FSP_FUSE_HDR_FROM_CONTEXT(context));
|
||||||
|
TlsSetValue(fsp_fuse_tlskey, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FSP_FUSE_API int fsp_fuse_version(struct fsp_fuse_env *env)
|
||||||
|
{
|
||||||
|
return FUSE_VERSION;
|
||||||
|
}
|
||||||
|
|
||||||
|
FSP_FUSE_API struct fuse_chan *fsp_fuse_mount(struct fsp_fuse_env *env,
|
||||||
|
const char *mountpoint, struct fuse_args *args)
|
||||||
|
{
|
||||||
|
struct fuse_chan *ch = 0;
|
||||||
|
int Size;
|
||||||
|
|
||||||
|
if (0 == mountpoint)
|
||||||
|
mountpoint = "";
|
||||||
|
|
||||||
|
Size = MultiByteToWideChar(CP_UTF8, 0, mountpoint, -1, 0, 0);
|
||||||
|
if (0 == Size)
|
||||||
|
goto fail;
|
||||||
|
|
||||||
|
ch = fsp_fuse_obj_alloc(env, sizeof *ch + Size * sizeof(WCHAR));
|
||||||
|
if (0 == ch)
|
||||||
|
goto fail;
|
||||||
|
|
||||||
|
ch->MountPoint = (PVOID)ch->Buffer;
|
||||||
|
Size = MultiByteToWideChar(CP_UTF8, 0, mountpoint, -1, ch->MountPoint, Size);
|
||||||
|
if (0 == Size)
|
||||||
|
goto fail;
|
||||||
|
|
||||||
|
return ch;
|
||||||
|
|
||||||
|
fail:
|
||||||
|
fsp_fuse_obj_free(ch);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
FSP_FUSE_API void fsp_fuse_unmount(struct fsp_fuse_env *env,
|
||||||
|
const char *mountpoint, struct fuse_chan *ch)
|
||||||
|
{
|
||||||
|
fsp_fuse_obj_free(ch);
|
||||||
|
}
|
||||||
|
|
||||||
|
FSP_FUSE_API int fsp_fuse_is_lib_option(struct fsp_fuse_env *env,
|
||||||
|
const char *opt)
|
||||||
|
{
|
||||||
|
return fsp_fuse_opt_match(env, fsp_fuse_core_opts, opt);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void fsp_fuse_cleanup(struct fuse *f);
|
||||||
|
|
||||||
|
static NTSTATUS fsp_fuse_preflight(struct fuse *f)
|
||||||
|
{
|
||||||
|
NTSTATUS Result;
|
||||||
|
|
||||||
|
Result = FspFsctlPreflight(f->VolumeParams.Prefix[0] ?
|
||||||
|
L"" FSP_FSCTL_NET_DEVICE_NAME : L"" FSP_FSCTL_DISK_DEVICE_NAME);
|
||||||
|
if (!NT_SUCCESS(Result))
|
||||||
|
return Result;
|
||||||
|
|
||||||
|
if (L'\0' != f->MountPoint)
|
||||||
|
{
|
||||||
|
if ((
|
||||||
|
(L'A' <= f->MountPoint[0] && f->MountPoint[0] <= L'Z') ||
|
||||||
|
(L'a' <= f->MountPoint[0] && f->MountPoint[0] <= L'z')
|
||||||
|
) &&
|
||||||
|
L':' == f->MountPoint[1] || L'\0' == f->MountPoint[2])
|
||||||
|
{
|
||||||
|
if (GetLogicalDrives() & (1 << ((f->MountPoint[0] & ~0x20) - 'a')))
|
||||||
|
return STATUS_OBJECT_NAME_COLLISION;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if (L'*' == f->MountPoint[0] && L'\0' == f->MountPoint[1])
|
||||||
|
;
|
||||||
|
else
|
||||||
|
return STATUS_OBJECT_NAME_INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
|
return STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static NTSTATUS fsp_fuse_svcstart(FSP_SERVICE *Service, ULONG argc, PWSTR *argv)
|
||||||
|
{
|
||||||
|
struct fuse *f = Service->UserContext;
|
||||||
|
struct fuse_context *context;
|
||||||
|
struct fuse_conn_info conn;
|
||||||
|
NTSTATUS Result;
|
||||||
|
|
||||||
|
f->Service = Service;
|
||||||
|
|
||||||
|
context = fsp_fuse_get_context(f->env);
|
||||||
|
if (0 == context)
|
||||||
|
{
|
||||||
|
Result = STATUS_INSUFFICIENT_RESOURCES;
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
context->fuse = f;
|
||||||
|
context->private_data = f->data;
|
||||||
|
context->uid = -1;
|
||||||
|
context->gid = -1;
|
||||||
|
|
||||||
|
memset(&conn, 0, sizeof conn);
|
||||||
|
conn.proto_major = 7; /* pretend that we are FUSE kernel protocol 7.12 */
|
||||||
|
conn.proto_minor = 12; /* which was current at the time of FUSE 2.8 */
|
||||||
|
conn.async_read = 1;
|
||||||
|
conn.max_write = UINT_MAX;
|
||||||
|
conn.capable =
|
||||||
|
FUSE_CAP_ASYNC_READ |
|
||||||
|
//FUSE_CAP_POSIX_LOCKS | /* WinFsp handles locking in the FSD currently */
|
||||||
|
//FUSE_CAP_ATOMIC_O_TRUNC | /* due to Windows/WinFsp design, no support */
|
||||||
|
//FUSE_CAP_EXPORT_SUPPORT | /* not needed in Windows/WinFsp */
|
||||||
|
FUSE_CAP_BIG_WRITES |
|
||||||
|
FUSE_CAP_DONT_MASK;
|
||||||
|
if (0 != f->ops.init)
|
||||||
|
context->private_data = f->data = f->ops.init(&conn);
|
||||||
|
f->fsinit = TRUE;
|
||||||
|
if (0 != f->ops.statfs)
|
||||||
|
{
|
||||||
|
struct fuse_statvfs stbuf;
|
||||||
|
int err;
|
||||||
|
|
||||||
|
memset(&stbuf, 0, sizeof stbuf);
|
||||||
|
err = f->ops.statfs("/", &stbuf);
|
||||||
|
if (0 != err)
|
||||||
|
{
|
||||||
|
Result = fsp_fuse_ntstatus_from_errno(f->env, err);
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stbuf.f_frsize > FSP_FUSE_SECTORSIZE_MAX)
|
||||||
|
stbuf.f_frsize = FSP_FUSE_SECTORSIZE_MAX;
|
||||||
|
if (0 == f->VolumeParams.SectorSize)
|
||||||
|
f->VolumeParams.SectorSize = (UINT16)stbuf.f_frsize;
|
||||||
|
if (0 == f->VolumeParams.MaxComponentLength)
|
||||||
|
f->VolumeParams.MaxComponentLength = (UINT16)stbuf.f_namemax;
|
||||||
|
}
|
||||||
|
if (0 != f->ops.getattr)
|
||||||
|
{
|
||||||
|
struct fuse_stat stbuf;
|
||||||
|
int err;
|
||||||
|
|
||||||
|
memset(&stbuf, 0, sizeof stbuf);
|
||||||
|
err = f->ops.getattr("/", (void *)&stbuf);
|
||||||
|
if (0 != err)
|
||||||
|
{
|
||||||
|
Result = fsp_fuse_ntstatus_from_errno(f->env, err);
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (0 == f->VolumeParams.VolumeCreationTime)
|
||||||
|
{
|
||||||
|
if (0 != stbuf.st_birthtim.tv_sec)
|
||||||
|
f->VolumeParams.VolumeCreationTime =
|
||||||
|
Int32x32To64(stbuf.st_birthtim.tv_sec, 10000000) + 116444736000000000 +
|
||||||
|
stbuf.st_birthtim.tv_nsec / 100;
|
||||||
|
else
|
||||||
|
if (0 != stbuf.st_ctim.tv_sec)
|
||||||
|
f->VolumeParams.VolumeCreationTime =
|
||||||
|
Int32x32To64(stbuf.st_ctim.tv_sec, 10000000) + 116444736000000000 +
|
||||||
|
stbuf.st_ctim.tv_nsec / 100;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* the FSD does not currently limit these VolumeParams fields; do so here! */
|
||||||
|
if (f->VolumeParams.SectorSize < FSP_FUSE_SECTORSIZE_MIN)
|
||||||
|
f->VolumeParams.SectorSize = FSP_FUSE_SECTORSIZE_MIN;
|
||||||
|
if (f->VolumeParams.SectorSize > FSP_FUSE_SECTORSIZE_MAX)
|
||||||
|
f->VolumeParams.SectorSize = FSP_FUSE_SECTORSIZE_MAX;
|
||||||
|
if (f->VolumeParams.SectorsPerAllocationUnit == 0)
|
||||||
|
f->VolumeParams.SectorsPerAllocationUnit = 1;
|
||||||
|
if (f->VolumeParams.MaxComponentLength > 255)
|
||||||
|
f->VolumeParams.MaxComponentLength = 255;
|
||||||
|
|
||||||
|
if (0 == f->VolumeParams.VolumeCreationTime)
|
||||||
|
{
|
||||||
|
FILETIME FileTime;
|
||||||
|
GetSystemTimeAsFileTime(&FileTime);
|
||||||
|
f->VolumeParams.VolumeCreationTime = *(PUINT64)&FileTime;
|
||||||
|
}
|
||||||
|
if (0 == f->VolumeParams.VolumeSerialNumber)
|
||||||
|
f->VolumeParams.VolumeSerialNumber =
|
||||||
|
((PLARGE_INTEGER)&f->VolumeParams.VolumeCreationTime)->HighPart ^
|
||||||
|
((PLARGE_INTEGER)&f->VolumeParams.VolumeCreationTime)->LowPart;
|
||||||
|
|
||||||
|
Result = FspFileSystemCreate(
|
||||||
|
f->VolumeParams.Prefix[0] ?
|
||||||
|
L"" FSP_FSCTL_NET_DEVICE_NAME : L"" FSP_FSCTL_DISK_DEVICE_NAME,
|
||||||
|
&f->VolumeParams, &fsp_fuse_intf,
|
||||||
|
&f->FileSystem);
|
||||||
|
if (!NT_SUCCESS(Result))
|
||||||
|
{
|
||||||
|
FspServiceLog(EVENTLOG_ERROR_TYPE,
|
||||||
|
L"Cannot create " FSP_FUSE_LIBRARY_NAME " file system.");
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
f->FileSystem->UserContext = f;
|
||||||
|
FspFileSystemSetOperationGuard(f->FileSystem, fsp_fuse_op_enter, fsp_fuse_op_leave);
|
||||||
|
FspFileSystemSetOperationGuardStrategy(f->FileSystem, f->OpGuardStrategy);
|
||||||
|
FspFileSystemSetDebugLog(f->FileSystem, f->DebugLog);
|
||||||
|
|
||||||
|
if (L'\0' != f->MountPoint)
|
||||||
|
{
|
||||||
|
Result = FspFileSystemSetMountPoint(f->FileSystem,
|
||||||
|
L'*' == f->MountPoint[0] && L'\0' == f->MountPoint[1] ? 0 : f->MountPoint);
|
||||||
|
if (!NT_SUCCESS(Result))
|
||||||
|
{
|
||||||
|
FspServiceLog(EVENTLOG_ERROR_TYPE,
|
||||||
|
L"Cannot set " FSP_FUSE_LIBRARY_NAME " file system mount point.");
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Result = FspFileSystemStartDispatcher(f->FileSystem, 0);
|
||||||
|
if (!NT_SUCCESS(Result))
|
||||||
|
{
|
||||||
|
FspServiceLog(EVENTLOG_ERROR_TYPE,
|
||||||
|
L"Cannot start " FSP_FUSE_LIBRARY_NAME " file system dispatcher.");
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
return STATUS_SUCCESS;
|
||||||
|
|
||||||
|
fail:
|
||||||
|
fsp_fuse_cleanup(f);
|
||||||
|
|
||||||
|
return Result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static NTSTATUS fsp_fuse_svcstop(FSP_SERVICE *Service)
|
||||||
|
{
|
||||||
|
struct fuse *f = Service->UserContext;
|
||||||
|
|
||||||
|
FspFileSystemStopDispatcher(f->FileSystem);
|
||||||
|
|
||||||
|
fsp_fuse_cleanup(f);
|
||||||
|
|
||||||
|
return STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void fsp_fuse_cleanup(struct fuse *f)
|
||||||
|
{
|
||||||
|
if (0 != f->FileSystem)
|
||||||
|
{
|
||||||
|
FspFileSystemDelete(f->FileSystem);
|
||||||
|
f->FileSystem = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (f->fsinit)
|
||||||
|
{
|
||||||
|
if (f->ops.destroy)
|
||||||
|
f->ops.destroy(f->data);
|
||||||
|
f->fsinit = FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
f->Service = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int fsp_fuse_core_opt_proc(void *opt_data0, const char *arg, int key,
|
||||||
|
struct fuse_args *outargs)
|
||||||
|
{
|
||||||
|
struct fsp_fuse_core_opt_data *opt_data = opt_data0;
|
||||||
|
|
||||||
|
switch (key)
|
||||||
|
{
|
||||||
|
default:
|
||||||
|
return 1;
|
||||||
|
case 'h':
|
||||||
|
FspServiceLog(EVENTLOG_ERROR_TYPE, L""
|
||||||
|
FSP_FUSE_LIBRARY_NAME " options:\n"
|
||||||
|
" -o SectorSize=N sector size for Windows (512-4096, deflt: 512)\n"
|
||||||
|
" -o SectorsPerAllocationUnit=N allocation unit size (deflt: 1*SectorSize)\n"
|
||||||
|
" -o MaxComponentLength=N max file name component length (deflt: 255)\n"
|
||||||
|
" -o VolumeCreationTime=T volume creation time (FILETIME hex format)\n"
|
||||||
|
" -o VolumeSerialNumber=N 32-bit wide\n"
|
||||||
|
" -o FileInfoTimeout=N FileInfo/Security/VolumeInfo timeout (millisec)\n"
|
||||||
|
" -o CaseInsensitiveSearch file system supports case-insensitive file names\n"
|
||||||
|
//" -o ReparsePoints file system supports reparse points\n"
|
||||||
|
//" -o NamedStreams file system supports named streams\n"
|
||||||
|
//" -o ReadOnlyVolume file system is read only\n"
|
||||||
|
" --UNC=U --VolumePrefix=U UNC prefix (\\Server\\Share)\n");
|
||||||
|
opt_data->help = 1;
|
||||||
|
return 1;
|
||||||
|
case 'V':
|
||||||
|
FspServiceLog(EVENTLOG_ERROR_TYPE, L""
|
||||||
|
FSP_FUSE_LIBRARY_NAME " version %d.%d",
|
||||||
|
FUSE_MAJOR_VERSION, FUSE_MINOR_VERSION);
|
||||||
|
opt_data->help = 1;
|
||||||
|
return 1;
|
||||||
|
case 'U':
|
||||||
|
if ('U' == arg[2])
|
||||||
|
arg += sizeof "--UNC=" - 1;
|
||||||
|
else if ('V' == arg[2])
|
||||||
|
arg += sizeof "--VolumePrefix=" - 1;
|
||||||
|
if (0 == MultiByteToWideChar(CP_UTF8, 0, arg, -1,
|
||||||
|
opt_data->VolumeParams.Prefix, sizeof opt_data->VolumeParams.Prefix / sizeof(WCHAR)))
|
||||||
|
return -1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FSP_FUSE_API struct fuse *fsp_fuse_new(struct fsp_fuse_env *env,
|
||||||
|
struct fuse_chan *ch, struct fuse_args *args,
|
||||||
|
const struct fuse_operations *ops, size_t opsize, void *data)
|
||||||
|
{
|
||||||
|
struct fuse *f = 0;
|
||||||
|
struct fsp_fuse_core_opt_data opt_data;
|
||||||
|
ULONG Size;
|
||||||
|
PWSTR ErrorMessage = L".";
|
||||||
|
NTSTATUS Result;
|
||||||
|
|
||||||
|
if (opsize > sizeof(struct fuse_operations))
|
||||||
|
opsize = sizeof(struct fuse_operations);
|
||||||
|
|
||||||
|
memset(&opt_data, 0, sizeof opt_data);
|
||||||
|
opt_data.env = env;
|
||||||
|
|
||||||
|
if (-1 == fsp_fuse_opt_parse(env, args, &opt_data, fsp_fuse_core_opts, fsp_fuse_core_opt_proc))
|
||||||
|
return 0;
|
||||||
|
if (opt_data.help)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (!opt_data.set_FileInfoTimeout && opt_data.set_attr_timeout)
|
||||||
|
opt_data.VolumeParams.FileInfoTimeout = opt_data.set_attr_timeout * 1000;
|
||||||
|
opt_data.VolumeParams.CaseSensitiveSearch = !opt_data.CaseInsensitiveSearch;
|
||||||
|
opt_data.VolumeParams.PersistentAcls = TRUE;
|
||||||
|
opt_data.VolumeParams.ReparsePoints = !!opt_data.ReparsePoints;
|
||||||
|
opt_data.VolumeParams.NamedStreams = !!opt_data.NamedStreams;
|
||||||
|
opt_data.VolumeParams.ReadOnlyVolume = !!opt_data.ReadOnlyVolume;
|
||||||
|
|
||||||
|
f = fsp_fuse_obj_alloc(env, sizeof *f);
|
||||||
|
if (0 == f)
|
||||||
|
goto fail;
|
||||||
|
|
||||||
|
f->env = env;
|
||||||
|
f->set_umask = opt_data.set_umask; f->umask = opt_data.umask;
|
||||||
|
f->set_uid = opt_data.set_uid; f->uid = opt_data.uid;
|
||||||
|
f->set_gid = opt_data.set_gid; f->gid = opt_data.gid;
|
||||||
|
memcpy(&f->ops, ops, opsize);
|
||||||
|
f->data = data;
|
||||||
|
f->DebugLog = opt_data.debug ? -1 : 0;
|
||||||
|
memcpy(&f->VolumeParams, &opt_data.VolumeParams, sizeof opt_data.VolumeParams);
|
||||||
|
|
||||||
|
Size = (lstrlenW(ch->MountPoint) + 1) * sizeof(WCHAR);
|
||||||
|
f->MountPoint = fsp_fuse_obj_alloc(env, Size);
|
||||||
|
if (0 == f->MountPoint)
|
||||||
|
goto fail;
|
||||||
|
memcpy(f->MountPoint, ch->MountPoint, Size);
|
||||||
|
|
||||||
|
Result = fsp_fuse_preflight(f);
|
||||||
|
if (!NT_SUCCESS(Result))
|
||||||
|
{
|
||||||
|
switch (Result)
|
||||||
|
{
|
||||||
|
case STATUS_ACCESS_DENIED:
|
||||||
|
ErrorMessage = L": access denied.";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case STATUS_NO_SUCH_DEVICE:
|
||||||
|
ErrorMessage = L": FSD not found.";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case STATUS_OBJECT_NAME_INVALID:
|
||||||
|
ErrorMessage = L": invalid mount point.";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case STATUS_OBJECT_NAME_COLLISION:
|
||||||
|
ErrorMessage = L": mount point in use.";
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
ErrorMessage = L": unspecified error.";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
return f;
|
||||||
|
|
||||||
|
fail:
|
||||||
|
FspServiceLog(EVENTLOG_ERROR_TYPE,
|
||||||
|
L"Cannot create " FSP_FUSE_LIBRARY_NAME " file system%s",
|
||||||
|
ErrorMessage);
|
||||||
|
|
||||||
|
if (0 != f)
|
||||||
|
fsp_fuse_destroy(env, f);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
FSP_FUSE_API void fsp_fuse_destroy(struct fsp_fuse_env *env,
|
||||||
|
struct fuse *f)
|
||||||
|
{
|
||||||
|
fsp_fuse_cleanup(f);
|
||||||
|
|
||||||
|
fsp_fuse_obj_free(f->MountPoint);
|
||||||
|
|
||||||
|
fsp_fuse_obj_free(f);
|
||||||
|
}
|
||||||
|
|
||||||
|
FSP_FUSE_API int fsp_fuse_loop(struct fsp_fuse_env *env,
|
||||||
|
struct fuse *f)
|
||||||
|
{
|
||||||
|
f->OpGuardStrategy = FSP_FILE_SYSTEM_OPERATION_GUARD_STRATEGY_COARSE;
|
||||||
|
return 0 == FspServiceRunEx(FspDiagIdent(), fsp_fuse_svcstart, fsp_fuse_svcstop, 0, f) ?
|
||||||
|
0 : -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
FSP_FUSE_API int fsp_fuse_loop_mt(struct fsp_fuse_env *env,
|
||||||
|
struct fuse *f)
|
||||||
|
{
|
||||||
|
f->OpGuardStrategy = FSP_FILE_SYSTEM_OPERATION_GUARD_STRATEGY_FINE;
|
||||||
|
return 0 == FspServiceRunEx(FspDiagIdent(), fsp_fuse_svcstart, fsp_fuse_svcstop, 0, f) ?
|
||||||
|
0 : -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
FSP_FUSE_API void fsp_fuse_exit(struct fsp_fuse_env *env,
|
||||||
|
struct fuse *f)
|
||||||
|
{
|
||||||
|
if (0 != f->Service)
|
||||||
|
FspServiceStop(f->Service);
|
||||||
|
}
|
||||||
|
|
||||||
|
FSP_FUSE_API struct fuse_context *fsp_fuse_get_context(struct fsp_fuse_env *env)
|
||||||
|
{
|
||||||
|
struct fuse_context *context;
|
||||||
|
|
||||||
|
InitOnceExecuteOnce(&fsp_fuse_initonce, fsp_fuse_initialize, 0, 0);
|
||||||
|
if (TLS_OUT_OF_INDEXES == fsp_fuse_tlskey)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
context = TlsGetValue(fsp_fuse_tlskey);
|
||||||
|
if (0 == context)
|
||||||
|
{
|
||||||
|
struct fsp_fuse_context_header *contexthdr;
|
||||||
|
|
||||||
|
contexthdr = fsp_fuse_obj_alloc(env,
|
||||||
|
sizeof(struct fsp_fuse_context_header) + sizeof(struct fuse_context));
|
||||||
|
if (0 == contexthdr)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
context = FSP_FUSE_CONTEXT_FROM_HDR(contexthdr);
|
||||||
|
context->pid = -1;
|
||||||
|
|
||||||
|
TlsSetValue(fsp_fuse_tlskey, context);
|
||||||
|
}
|
||||||
|
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
|
||||||
|
FSP_FUSE_API int32_t fsp_fuse_ntstatus_from_errno(struct fsp_fuse_env *env,
|
||||||
|
int err)
|
||||||
|
{
|
||||||
|
if (0 > err)
|
||||||
|
err = -err;
|
||||||
|
|
||||||
|
if ('C' == env->environment)
|
||||||
|
switch (err)
|
||||||
|
{
|
||||||
|
#undef FSP_FUSE_ERRNO
|
||||||
|
#define FSP_FUSE_ERRNO 67
|
||||||
|
#include "errno.i"
|
||||||
|
default:
|
||||||
|
return STATUS_ACCESS_DENIED;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
switch (err)
|
||||||
|
{
|
||||||
|
#undef FSP_FUSE_ERRNO
|
||||||
|
#define FSP_FUSE_ERRNO 87
|
||||||
|
#include "errno.i"
|
||||||
|
default:
|
||||||
|
return STATUS_ACCESS_DENIED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Cygwin signal support */
|
||||||
|
|
||||||
|
FSP_FUSE_API void fsp_fuse_signal_handler(int sig)
|
||||||
|
{
|
||||||
|
FspServiceConsoleCtrlHandler(CTRL_BREAK_EVENT);
|
||||||
|
}
|
10
src/dll/fuse/fuse.pc
Normal file
10
src/dll/fuse/fuse.pc
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
prefix=${pcfiledir}/..
|
||||||
|
incdir=${prefix}/inc/fuse
|
||||||
|
implib=${prefix}/bin/winfsp-${arch}.dll
|
||||||
|
|
||||||
|
Name: fuse
|
||||||
|
Description: WinFsp FUSE compatible API
|
||||||
|
Version: 2.8
|
||||||
|
URL: http://www.secfs.net/winfsp/
|
||||||
|
Libs: "${implib}"
|
||||||
|
Cflags: -I"${incdir}"
|
1446
src/dll/fuse/fuse_intf.c
Normal file
1446
src/dll/fuse/fuse_intf.c
Normal file
File diff suppressed because it is too large
Load Diff
179
src/dll/fuse/fuse_main.c
Normal file
179
src/dll/fuse/fuse_main.c
Normal file
@ -0,0 +1,179 @@
|
|||||||
|
/**
|
||||||
|
* @file dll/fuse/fuse_main.c
|
||||||
|
*
|
||||||
|
* @copyright 2015-2016 Bill Zissimopoulos
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* This file is part of WinFsp.
|
||||||
|
*
|
||||||
|
* You can redistribute it and/or modify it under the terms of the
|
||||||
|
* GNU Affero General Public License version 3 as published by the
|
||||||
|
* Free Software Foundation.
|
||||||
|
*
|
||||||
|
* Licensees holding a valid commercial license may use this file in
|
||||||
|
* accordance with the commercial license agreement provided with the
|
||||||
|
* software.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <dll/fuse/library.h>
|
||||||
|
|
||||||
|
#define FSP_FUSE_MAIN_OPT(n, f, v) { n, offsetof(struct fsp_fuse_main_opt_data, f), v }
|
||||||
|
|
||||||
|
struct fsp_fuse_main_opt_data
|
||||||
|
{
|
||||||
|
struct fsp_fuse_env *env;
|
||||||
|
char *mountpoint;
|
||||||
|
int singlethread;
|
||||||
|
int foreground;
|
||||||
|
};
|
||||||
|
|
||||||
|
static struct fuse_opt fsp_fuse_main_opts[] =
|
||||||
|
{
|
||||||
|
FUSE_OPT_KEY("-h", 'h'),
|
||||||
|
FUSE_OPT_KEY("--help", 'h'),
|
||||||
|
FUSE_OPT_KEY("-ho", 'H'),
|
||||||
|
FUSE_OPT_KEY("-d", FUSE_OPT_KEY_KEEP),
|
||||||
|
FUSE_OPT_KEY("debug", FUSE_OPT_KEY_KEEP),
|
||||||
|
FSP_FUSE_MAIN_OPT("-d", foreground, 1),
|
||||||
|
FSP_FUSE_MAIN_OPT("debug", foreground, 1),
|
||||||
|
|
||||||
|
FSP_FUSE_MAIN_OPT("-f", foreground, 1),
|
||||||
|
FSP_FUSE_MAIN_OPT("-s", singlethread, 1),
|
||||||
|
|
||||||
|
FUSE_OPT_END,
|
||||||
|
};
|
||||||
|
|
||||||
|
static int fsp_fuse_main_opt_proc(void *opt_data0, const char *arg, int key,
|
||||||
|
struct fuse_args *outargs)
|
||||||
|
{
|
||||||
|
static PWSTR HeaderHelp = L""
|
||||||
|
"\n"
|
||||||
|
" -o opt,[opt...] mount options\n"
|
||||||
|
" -h --help print help\n"
|
||||||
|
" -V --version print version\n";
|
||||||
|
static PWSTR MainHelp = L""
|
||||||
|
"FUSE options:\n"
|
||||||
|
" -d -o debug enable debug output (implies -f)\n"
|
||||||
|
" -f foreground operation\n"
|
||||||
|
" -s disable multi-threaded operation\n";
|
||||||
|
struct fsp_fuse_main_opt_data *opt_data = opt_data0;
|
||||||
|
|
||||||
|
switch (key)
|
||||||
|
{
|
||||||
|
default:
|
||||||
|
return 1;
|
||||||
|
case 'h':
|
||||||
|
FspServiceLog(EVENTLOG_ERROR_TYPE, L""
|
||||||
|
"usage: %s mountpoint [options]\n"
|
||||||
|
"%s"
|
||||||
|
"\n"
|
||||||
|
"%s",
|
||||||
|
FspDiagIdent(), HeaderHelp, MainHelp);
|
||||||
|
return 1;
|
||||||
|
case 'H':
|
||||||
|
FspServiceLog(EVENTLOG_ERROR_TYPE, L""
|
||||||
|
"%s",
|
||||||
|
MainHelp);
|
||||||
|
fsp_fuse_opt_add_arg(opt_data->env, outargs, "-h");
|
||||||
|
return 0;
|
||||||
|
case FUSE_OPT_KEY_NONOPT:
|
||||||
|
if (0 == opt_data->mountpoint)
|
||||||
|
{
|
||||||
|
size_t size = lstrlenA(arg) + 1;
|
||||||
|
opt_data->mountpoint = opt_data->env->memalloc(size);
|
||||||
|
if (0 == opt_data->mountpoint)
|
||||||
|
return -1;
|
||||||
|
memcpy(opt_data->mountpoint, arg, size);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
FspServiceLog(EVENTLOG_ERROR_TYPE,
|
||||||
|
L"Invalid argument \"%S\"", arg);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FSP_FUSE_API int fsp_fuse_parse_cmdline(struct fsp_fuse_env *env,
|
||||||
|
struct fuse_args *args,
|
||||||
|
char **mountpoint, int *multithreaded, int *foreground)
|
||||||
|
{
|
||||||
|
struct fsp_fuse_main_opt_data opt_data;
|
||||||
|
|
||||||
|
memset(&opt_data, 0, sizeof opt_data);
|
||||||
|
opt_data.env = env;
|
||||||
|
|
||||||
|
if (-1 == fsp_fuse_opt_parse(env, args, &opt_data, fsp_fuse_main_opts, fsp_fuse_main_opt_proc))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (0 != mountpoint)
|
||||||
|
*mountpoint = opt_data.mountpoint;
|
||||||
|
else
|
||||||
|
env->memfree(mountpoint);
|
||||||
|
|
||||||
|
if (0 != multithreaded)
|
||||||
|
*multithreaded = !opt_data.singlethread;
|
||||||
|
|
||||||
|
if (0 != foreground)
|
||||||
|
*foreground = opt_data.foreground;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
FSP_FUSE_API int fsp_fuse_main_real(struct fsp_fuse_env *env,
|
||||||
|
int argc, char *argv[],
|
||||||
|
const struct fuse_operations *ops, size_t opsize, void *data)
|
||||||
|
{
|
||||||
|
struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
|
||||||
|
char *mountpoint = 0;
|
||||||
|
int multithreaded = 0;
|
||||||
|
int foreground = 0;
|
||||||
|
struct fuse_chan *ch = 0;
|
||||||
|
struct fuse *f = 0;
|
||||||
|
int signal_handlers = 0;
|
||||||
|
int result;
|
||||||
|
|
||||||
|
result = fsp_fuse_parse_cmdline(env, &args, &mountpoint, &multithreaded, &foreground);
|
||||||
|
if (-1 == result)
|
||||||
|
goto exit;
|
||||||
|
|
||||||
|
ch = fsp_fuse_mount(env, mountpoint, &args);
|
||||||
|
if (0 == ch)
|
||||||
|
{
|
||||||
|
result = -1;
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
f = fsp_fuse_new(env, ch, &args, ops, opsize, data);
|
||||||
|
if (0 == f)
|
||||||
|
{
|
||||||
|
result = -1;
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
result = env->daemonize(foreground);
|
||||||
|
if (-1 == result)
|
||||||
|
goto exit;
|
||||||
|
|
||||||
|
result = env->set_signal_handlers(f);
|
||||||
|
if (-1 == result)
|
||||||
|
goto exit;
|
||||||
|
signal_handlers = 1;
|
||||||
|
|
||||||
|
result = multithreaded ? fsp_fuse_loop_mt(env, f) : fsp_fuse_loop(env, f);
|
||||||
|
|
||||||
|
exit:
|
||||||
|
if (signal_handlers)
|
||||||
|
env->set_signal_handlers(0);
|
||||||
|
|
||||||
|
if (0 != f)
|
||||||
|
fsp_fuse_destroy(env, f);
|
||||||
|
|
||||||
|
if (0 != ch)
|
||||||
|
fsp_fuse_unmount(env, mountpoint, ch);
|
||||||
|
|
||||||
|
env->memfree(mountpoint);
|
||||||
|
|
||||||
|
fsp_fuse_opt_free_args(env, &args);
|
||||||
|
|
||||||
|
/* main() style return: 0 success, 1 error */
|
||||||
|
return !!result;
|
||||||
|
}
|
622
src/dll/fuse/fuse_opt.c
Normal file
622
src/dll/fuse/fuse_opt.c
Normal file
@ -0,0 +1,622 @@
|
|||||||
|
/**
|
||||||
|
* @file dll/fuse/fuse_opt.c
|
||||||
|
*
|
||||||
|
* @copyright 2015-2016 Bill Zissimopoulos
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* This file is part of WinFsp.
|
||||||
|
*
|
||||||
|
* You can redistribute it and/or modify it under the terms of the
|
||||||
|
* GNU Affero General Public License version 3 as published by the
|
||||||
|
* Free Software Foundation.
|
||||||
|
*
|
||||||
|
* Licensees holding a valid commercial license may use this file in
|
||||||
|
* accordance with the commercial license agreement provided with the
|
||||||
|
* software.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <dll/fuse/library.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Define the following symbol to support escaped commas (',') during fuse_opt_parse.
|
||||||
|
*/
|
||||||
|
#define FSP_FUSE_OPT_PARSE_ESCAPED_COMMAS
|
||||||
|
|
||||||
|
#define fsp_fuse_opt_match_none ((const char *)0) /* no option match */
|
||||||
|
#define fsp_fuse_opt_match_exact ((const char *)1) /* exact option match */
|
||||||
|
#define fsp_fuse_opt_match_next ((const char *)2) /* option match, value is next arg */
|
||||||
|
|
||||||
|
static long long strtoint(const char *p, int base, int is_signed)
|
||||||
|
{
|
||||||
|
long long v;
|
||||||
|
int maxdig, maxalp, sign = +1;
|
||||||
|
|
||||||
|
if (is_signed)
|
||||||
|
{
|
||||||
|
if ('+' == *p)
|
||||||
|
p++;
|
||||||
|
else if ('-' == *p)
|
||||||
|
p++, sign = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (0 == base)
|
||||||
|
{
|
||||||
|
if ('0' == *p)
|
||||||
|
{
|
||||||
|
p++;
|
||||||
|
if ('x' == *p || 'X' == *p)
|
||||||
|
{
|
||||||
|
p++;
|
||||||
|
base = 16;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
base = 8;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
base = 10;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
maxdig = 10 < base ? '9' : (base - 1) + '0';
|
||||||
|
maxalp = 10 < base ? (base - 1 - 10) + 'a' : 0;
|
||||||
|
|
||||||
|
for (v = 0; *p; p++)
|
||||||
|
{
|
||||||
|
int c = *p;
|
||||||
|
|
||||||
|
if ('0' <= c && c <= maxdig)
|
||||||
|
v = base * v + (c - '0');
|
||||||
|
else
|
||||||
|
{
|
||||||
|
c |= 0x20;
|
||||||
|
if ('a' <= c && c <= maxalp)
|
||||||
|
v = base * v + (c - 'a') + 10;
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return sign * v;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void fsp_fuse_opt_match_templ(
|
||||||
|
const char *templ, const char **pspec,
|
||||||
|
const char **parg)
|
||||||
|
{
|
||||||
|
const char *p, *q;
|
||||||
|
|
||||||
|
*pspec = 0;
|
||||||
|
|
||||||
|
for (p = templ, q = *parg;; p++, q++)
|
||||||
|
if ('\0' == *q)
|
||||||
|
{
|
||||||
|
if ('\0' == *p)
|
||||||
|
*parg = fsp_fuse_opt_match_exact;
|
||||||
|
else if (' ' == *p)
|
||||||
|
*pspec = p + 1, *parg = fsp_fuse_opt_match_next;
|
||||||
|
else
|
||||||
|
*parg = fsp_fuse_opt_match_none;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if ('=' == *p)
|
||||||
|
{
|
||||||
|
if (*q == *p)
|
||||||
|
{
|
||||||
|
p++, q++;
|
||||||
|
if ('%' == *p || '\0' == *p)
|
||||||
|
*pspec = p, *parg = q;
|
||||||
|
else
|
||||||
|
*parg = 0 == lstrcmpA(q, p) ?
|
||||||
|
fsp_fuse_opt_match_exact : fsp_fuse_opt_match_none;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
*parg = fsp_fuse_opt_match_none;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (' ' == *p)
|
||||||
|
{
|
||||||
|
*pspec = p + 1, *parg = q;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (*q != *p)
|
||||||
|
{
|
||||||
|
*parg = fsp_fuse_opt_match_none;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static const struct fuse_opt *fsp_fuse_opt_find(
|
||||||
|
const struct fuse_opt opts[], const char **pspec,
|
||||||
|
const char **parg)
|
||||||
|
{
|
||||||
|
const struct fuse_opt *opt;
|
||||||
|
const char *arg;
|
||||||
|
|
||||||
|
for (opt = opts; 0 != opt->templ; opt++)
|
||||||
|
{
|
||||||
|
arg = *parg;
|
||||||
|
fsp_fuse_opt_match_templ(opt->templ, pspec, &arg);
|
||||||
|
if (fsp_fuse_opt_match_none != arg)
|
||||||
|
{
|
||||||
|
*parg = arg;
|
||||||
|
return opt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int fsp_fuse_opt_call_proc(struct fsp_fuse_env *env,
|
||||||
|
void *data, fuse_opt_proc_t proc,
|
||||||
|
const char *arg, const char *argl,
|
||||||
|
int key, int is_opt,
|
||||||
|
struct fuse_args *outargs)
|
||||||
|
{
|
||||||
|
int result, len0, len1;
|
||||||
|
char *fullarg = 0;
|
||||||
|
|
||||||
|
if (FUSE_OPT_KEY_DISCARD == key)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
len0 = lstrlenA(arg);
|
||||||
|
|
||||||
|
if (0 != argl && !(arg <= argl && argl < arg + len0))
|
||||||
|
{
|
||||||
|
len1 = lstrlenA(argl);
|
||||||
|
|
||||||
|
fullarg = env->memalloc(len0 + len1 + 1);
|
||||||
|
if (0 == fullarg)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
memcpy(fullarg, arg, len0);
|
||||||
|
memcpy(fullarg + len0, argl, len1);
|
||||||
|
fullarg[len0 + len1] = '\0';
|
||||||
|
|
||||||
|
arg = fullarg;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (FUSE_OPT_KEY_KEEP != key && 0 != proc)
|
||||||
|
{
|
||||||
|
result = proc(data, arg, key, outargs);
|
||||||
|
if (-1 == result || 0 == result)
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_opt)
|
||||||
|
{
|
||||||
|
if (!(3 <= outargs->argc &&
|
||||||
|
'-' == outargs->argv[1][0] && 'o' == outargs->argv[1][1] &&
|
||||||
|
'\0' == outargs->argv[1][2]))
|
||||||
|
{
|
||||||
|
result = fsp_fuse_opt_insert_arg(env, outargs, 1, "-o");
|
||||||
|
if (-1 == result)
|
||||||
|
goto exit;
|
||||||
|
result = fsp_fuse_opt_insert_arg(env, outargs, 2, "");
|
||||||
|
if (-1 == result)
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(FSP_FUSE_OPT_PARSE_ESCAPED_COMMAS)
|
||||||
|
result = fsp_fuse_opt_add_opt_escaped(env, &outargs->argv[2], arg);
|
||||||
|
#else
|
||||||
|
result = fsp_fuse_opt_add_opt(env, &outargs->argv[2], arg);
|
||||||
|
#endif
|
||||||
|
if (-1 == result)
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result = fsp_fuse_opt_add_arg(env, outargs, arg);
|
||||||
|
if (-1 == result)
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
exit:
|
||||||
|
if (0 != fullarg)
|
||||||
|
env->memfree(fullarg);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int fsp_fuse_opt_process_arg(struct fsp_fuse_env *env,
|
||||||
|
void *data, const struct fuse_opt *opt, fuse_opt_proc_t proc,
|
||||||
|
const char *spec,
|
||||||
|
const char *arg, const char *argl,
|
||||||
|
int is_opt,
|
||||||
|
struct fuse_args *outargs)
|
||||||
|
{
|
||||||
|
#define VAR(data, opt, type) *(type *)((char *)(data) + (opt)->offset)
|
||||||
|
|
||||||
|
if (-1L == opt->offset)
|
||||||
|
return fsp_fuse_opt_call_proc(env,
|
||||||
|
data, proc, arg, argl, opt->value, is_opt, outargs);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int h, j, l, t, z;
|
||||||
|
long long llv;
|
||||||
|
char *s;
|
||||||
|
int len;
|
||||||
|
|
||||||
|
if (0 == spec || '\0' == spec[0])
|
||||||
|
{
|
||||||
|
VAR(data, opt, int) = opt->value;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ('%' != spec[0])
|
||||||
|
return -1; /* bad option template */
|
||||||
|
|
||||||
|
h = j = l = t = z = 0;
|
||||||
|
for (spec++; *spec; spec++)
|
||||||
|
switch (*spec)
|
||||||
|
{
|
||||||
|
default:
|
||||||
|
case 0: case 1: case 2: case 3: case 4:
|
||||||
|
case 5: case 6: case 7: case 8: case 9:
|
||||||
|
case 'm':
|
||||||
|
break;
|
||||||
|
case 'h':
|
||||||
|
h++;
|
||||||
|
break;
|
||||||
|
case 'j':
|
||||||
|
j++;
|
||||||
|
break;
|
||||||
|
case 'l':
|
||||||
|
l++;
|
||||||
|
break;
|
||||||
|
case 'L': case 'q':
|
||||||
|
l += 2;
|
||||||
|
break;
|
||||||
|
case 't':
|
||||||
|
t++;
|
||||||
|
break;
|
||||||
|
case 'z':
|
||||||
|
z++;
|
||||||
|
break;
|
||||||
|
case 'd':
|
||||||
|
llv = strtoint(argl, 10, 1);
|
||||||
|
goto ivar;
|
||||||
|
case 'i':
|
||||||
|
llv = strtoint(argl, 0, 1);
|
||||||
|
goto ivar;
|
||||||
|
case 'o':
|
||||||
|
llv = strtoint(argl, 8, 0);
|
||||||
|
goto ivar;
|
||||||
|
case 'u':
|
||||||
|
llv = strtoint(argl, 10, 0);
|
||||||
|
goto ivar;
|
||||||
|
case 'x': case 'X':
|
||||||
|
llv = strtoint(argl, 16, 0);
|
||||||
|
ivar:
|
||||||
|
if (z)
|
||||||
|
VAR(data, opt, size_t) = (size_t)llv;
|
||||||
|
else if (t)
|
||||||
|
VAR(data, opt, ptrdiff_t) = (ptrdiff_t)llv;
|
||||||
|
else if (j)
|
||||||
|
VAR(data, opt, intmax_t) = (intmax_t)llv;
|
||||||
|
else if (1 == h)
|
||||||
|
VAR(data, opt, short) = (short)llv;
|
||||||
|
else if (2 <= h)
|
||||||
|
VAR(data, opt, char) = (char)llv;
|
||||||
|
else if (1 == l)
|
||||||
|
{
|
||||||
|
#if defined(_WIN64)
|
||||||
|
/* long is 8 bytes long in Cygwin64 and 4 bytes long in Win64 */
|
||||||
|
if ('C' == env->environment)
|
||||||
|
VAR(data, opt, long long) = (long long)llv;
|
||||||
|
else
|
||||||
|
VAR(data, opt, long) = (long)llv;
|
||||||
|
#else
|
||||||
|
VAR(data, opt, long) = (long)llv;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
else if (2 <= l)
|
||||||
|
VAR(data, opt, long long) = (long long)llv;
|
||||||
|
else
|
||||||
|
VAR(data, opt, int) = (int)llv;
|
||||||
|
return 0;
|
||||||
|
case 's': case 'c':
|
||||||
|
len = lstrlenA(argl);
|
||||||
|
s = env->memalloc(len + 1);
|
||||||
|
if (0 == s)
|
||||||
|
return -1;
|
||||||
|
memcpy(s, argl, len);
|
||||||
|
s[len] = '\0';
|
||||||
|
VAR(data, opt, const char *) = (const char *)s;
|
||||||
|
return 0;
|
||||||
|
case 'a': case 'e': case 'E': case 'f': case 'g':
|
||||||
|
return -1; /* no float support */
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1; /* bad option template */
|
||||||
|
}
|
||||||
|
|
||||||
|
#undef VAR
|
||||||
|
}
|
||||||
|
|
||||||
|
static int fsp_fuse_opt_parse_arg(struct fsp_fuse_env *env,
|
||||||
|
void *data, const struct fuse_opt opts[], fuse_opt_proc_t proc,
|
||||||
|
const char *arg, const char *nextarg, int *pconsumed_nextarg,
|
||||||
|
int is_opt,
|
||||||
|
struct fuse_args *outargs)
|
||||||
|
{
|
||||||
|
const struct fuse_opt *opt;
|
||||||
|
const char *spec, *argl;
|
||||||
|
int processed = 0;
|
||||||
|
|
||||||
|
argl = arg;
|
||||||
|
opt = opts;
|
||||||
|
while (0 != (opt = fsp_fuse_opt_find(opt, &spec, &argl)))
|
||||||
|
{
|
||||||
|
if (fsp_fuse_opt_match_exact == argl)
|
||||||
|
argl = arg;
|
||||||
|
else if (fsp_fuse_opt_match_next == argl)
|
||||||
|
{
|
||||||
|
if (0 == nextarg)
|
||||||
|
return -1; /* missing argument for option */
|
||||||
|
argl = nextarg;
|
||||||
|
*pconsumed_nextarg = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (-1 == fsp_fuse_opt_process_arg(env,
|
||||||
|
data, opt, proc, spec, arg, argl, is_opt, outargs))
|
||||||
|
return -1;
|
||||||
|
processed++;
|
||||||
|
|
||||||
|
argl = arg;
|
||||||
|
opt++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (0 != processed)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return fsp_fuse_opt_call_proc(env,
|
||||||
|
data, proc, arg, arg, FUSE_OPT_KEY_OPT, is_opt, outargs);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int fsp_fuse_opt_proc0(void *data, const char *arg, int key,
|
||||||
|
struct fuse_args *outargs)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
FSP_FUSE_API int fsp_fuse_opt_parse(struct fsp_fuse_env *env,
|
||||||
|
struct fuse_args *args,
|
||||||
|
void *data, const struct fuse_opt opts[], fuse_opt_proc_t proc)
|
||||||
|
{
|
||||||
|
static struct fuse_args args0 = FUSE_ARGS_INIT(0, 0);
|
||||||
|
static struct fuse_opt opts0[1] = { FUSE_OPT_END };
|
||||||
|
struct fuse_args outargs = FUSE_ARGS_INIT(0, 0);
|
||||||
|
const char *arg;
|
||||||
|
char *argcopy, *argend;
|
||||||
|
int dashdash = 0, consumed_nextarg;
|
||||||
|
|
||||||
|
if (0 == args)
|
||||||
|
args = &args0;
|
||||||
|
if (0 == opts)
|
||||||
|
opts = opts0;
|
||||||
|
if (0 == proc)
|
||||||
|
proc = fsp_fuse_opt_proc0;
|
||||||
|
|
||||||
|
if (-1 == fsp_fuse_opt_add_arg(env, &outargs, args->argv[0]))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
for (int argi = 1; args->argc > argi; argi++)
|
||||||
|
{
|
||||||
|
arg = args->argv[argi];
|
||||||
|
if ('-' == arg[0] && !dashdash)
|
||||||
|
{
|
||||||
|
switch (arg[1])
|
||||||
|
{
|
||||||
|
case 'o':
|
||||||
|
if ('\0' == arg[2])
|
||||||
|
{
|
||||||
|
if (args->argc <= argi + 1)
|
||||||
|
goto fail; /* missing argument for option "-o" */
|
||||||
|
arg = args->argv[++argi];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
arg += 2;
|
||||||
|
argcopy = env->memalloc(lstrlenA(arg) + 1);
|
||||||
|
if (0 == argcopy)
|
||||||
|
goto fail;
|
||||||
|
argend = argcopy;
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
#if defined(FSP_FUSE_OPT_PARSE_ESCAPED_COMMAS)
|
||||||
|
if ('\\' == *arg)
|
||||||
|
{
|
||||||
|
arg++;
|
||||||
|
*argend++ = *arg++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
if ('\0' == *arg || ',' == *arg)
|
||||||
|
{
|
||||||
|
*argend = '\0';
|
||||||
|
if (-1 == fsp_fuse_opt_parse_arg(env,
|
||||||
|
data, opts, proc, argcopy, 0, 0, 1, &outargs))
|
||||||
|
{
|
||||||
|
env->memfree(argcopy);
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ('\0' == *arg)
|
||||||
|
break;
|
||||||
|
|
||||||
|
arg++;
|
||||||
|
argend = argcopy;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
*argend++ = *arg++;
|
||||||
|
}
|
||||||
|
env->memfree(argcopy);
|
||||||
|
break;
|
||||||
|
case '-':
|
||||||
|
if ('\0' == arg[2])
|
||||||
|
{
|
||||||
|
if (-1 == fsp_fuse_opt_add_arg(env, &outargs, arg))
|
||||||
|
return -1;
|
||||||
|
dashdash = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* fall through */
|
||||||
|
default:
|
||||||
|
consumed_nextarg = 0;
|
||||||
|
if (-1 == fsp_fuse_opt_parse_arg(env,
|
||||||
|
data, opts, proc, arg, args->argv[argi + 1], &consumed_nextarg, 0, &outargs))
|
||||||
|
goto fail;
|
||||||
|
if (consumed_nextarg)
|
||||||
|
argi++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if (-1 == fsp_fuse_opt_call_proc(env,
|
||||||
|
data, proc, arg, arg, FUSE_OPT_KEY_NONOPT, 0, &outargs))
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* if "--" is the last argument, remove it (fuse_opt compatibility) */
|
||||||
|
if (0 < outargs.argc &&
|
||||||
|
'-' == outargs.argv[outargs.argc - 1][0] &&
|
||||||
|
'-' == outargs.argv[outargs.argc - 1][1] &&
|
||||||
|
'\0' == outargs.argv[outargs.argc - 1][2])
|
||||||
|
{
|
||||||
|
env->memfree(outargs.argv[--outargs.argc]);
|
||||||
|
outargs.argv[outargs.argc] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
fsp_fuse_opt_free_args(env, args);
|
||||||
|
memcpy(args, &outargs, sizeof outargs);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
fail:
|
||||||
|
fsp_fuse_opt_free_args(env, &outargs);
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
FSP_FUSE_API int fsp_fuse_opt_add_arg(struct fsp_fuse_env *env,
|
||||||
|
struct fuse_args *args, const char *arg)
|
||||||
|
{
|
||||||
|
return fsp_fuse_opt_insert_arg(env, args, args->argc, arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
FSP_FUSE_API int fsp_fuse_opt_insert_arg(struct fsp_fuse_env *env,
|
||||||
|
struct fuse_args *args, int pos, const char *arg)
|
||||||
|
{
|
||||||
|
char **argv;
|
||||||
|
int argsize;
|
||||||
|
|
||||||
|
if (0 == args)
|
||||||
|
return -1;
|
||||||
|
if (0 != args->argv && !args->allocated)
|
||||||
|
return -1;
|
||||||
|
if (0 > pos || pos > args->argc)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
argv = env->memalloc((args->argc + 2) * sizeof(char *));
|
||||||
|
if (0 == argv)
|
||||||
|
return -1;
|
||||||
|
argsize = lstrlenA(arg) + 1;
|
||||||
|
argv[pos] = env->memalloc(argsize);
|
||||||
|
if (0 == argv[pos])
|
||||||
|
{
|
||||||
|
env->memfree(argv);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(argv[pos], arg, argsize);
|
||||||
|
memcpy(argv, args->argv, sizeof(char *) * pos);
|
||||||
|
memcpy(argv + pos + 1, args->argv + pos, sizeof(char *) * (args->argc - pos));
|
||||||
|
|
||||||
|
env->memfree(args->argv);
|
||||||
|
|
||||||
|
args->argc++;
|
||||||
|
args->argv = argv;
|
||||||
|
argv[args->argc] = 0;
|
||||||
|
args->allocated = 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
FSP_FUSE_API void fsp_fuse_opt_free_args(struct fsp_fuse_env *env,
|
||||||
|
struct fuse_args *args)
|
||||||
|
{
|
||||||
|
if (0 == args)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (args->allocated && 0 != args->argv)
|
||||||
|
{
|
||||||
|
for (int argi = 0; args->argc > argi; argi++)
|
||||||
|
env->memfree(args->argv[argi]);
|
||||||
|
|
||||||
|
env->memfree(args->argv);
|
||||||
|
}
|
||||||
|
|
||||||
|
args->argc = 0;
|
||||||
|
args->argv = 0;
|
||||||
|
args->allocated = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int fsp_fuse_opt_add_opt_internal(struct fsp_fuse_env *env,
|
||||||
|
char **opts, const char *opt, int escaped)
|
||||||
|
{
|
||||||
|
size_t optsize, optlen;
|
||||||
|
char *newopts;
|
||||||
|
const char *p;
|
||||||
|
|
||||||
|
optsize = 0 != *opts && '\0' != (*opts)[0] ? lstrlenA(*opts) + 1 : 0;
|
||||||
|
for (p = opt, optlen = 0; *p; p++, optlen++)
|
||||||
|
if (escaped && (',' == *p || '\\' == *p))
|
||||||
|
optlen++;
|
||||||
|
|
||||||
|
newopts = env->memalloc(optsize + optlen + 1);
|
||||||
|
if (0 == newopts)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (0 != optsize)
|
||||||
|
{
|
||||||
|
memcpy(newopts, *opts, optsize - 1);
|
||||||
|
newopts[optsize - 1] = ',';
|
||||||
|
}
|
||||||
|
|
||||||
|
env->memfree(*opts);
|
||||||
|
*opts = newopts;
|
||||||
|
newopts += optsize;
|
||||||
|
|
||||||
|
for (p = opt; *p; p++, newopts++)
|
||||||
|
{
|
||||||
|
if (escaped && (',' == *p || '\\' == *p))
|
||||||
|
*newopts++ = '\\';
|
||||||
|
*newopts = *p;
|
||||||
|
}
|
||||||
|
*newopts = '\0';
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
FSP_FUSE_API int fsp_fuse_opt_add_opt(struct fsp_fuse_env *env,
|
||||||
|
char **opts, const char *opt)
|
||||||
|
{
|
||||||
|
return fsp_fuse_opt_add_opt_internal(env, opts, opt, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
FSP_FUSE_API int fsp_fuse_opt_add_opt_escaped(struct fsp_fuse_env *env,
|
||||||
|
char **opts, const char *opt)
|
||||||
|
{
|
||||||
|
return fsp_fuse_opt_add_opt_internal(env, opts, opt, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
FSP_FUSE_API int fsp_fuse_opt_match(struct fsp_fuse_env *env,
|
||||||
|
const struct fuse_opt opts[], const char *arg)
|
||||||
|
{
|
||||||
|
if (0 == opts)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
const char *spec;
|
||||||
|
return !!fsp_fuse_opt_find(opts, &spec, &arg);
|
||||||
|
}
|
92
src/dll/fuse/library.h
Normal file
92
src/dll/fuse/library.h
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
/**
|
||||||
|
* @file dll/fuse/library.h
|
||||||
|
*
|
||||||
|
* @copyright 2015-2016 Bill Zissimopoulos
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* This file is part of WinFsp.
|
||||||
|
*
|
||||||
|
* You can redistribute it and/or modify it under the terms of the
|
||||||
|
* GNU Affero General Public License version 3 as published by the
|
||||||
|
* Free Software Foundation.
|
||||||
|
*
|
||||||
|
* Licensees holding a valid commercial license may use this file in
|
||||||
|
* accordance with the commercial license agreement provided with the
|
||||||
|
* software.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef WINFSP_DLL_FUSE_LIBRARY_H_INCLUDED
|
||||||
|
#define WINFSP_DLL_FUSE_LIBRARY_H_INCLUDED
|
||||||
|
|
||||||
|
#include <dll/library.h>
|
||||||
|
#include <fuse/fuse.h>
|
||||||
|
#include <fuse/fuse_opt.h>
|
||||||
|
|
||||||
|
#define FSP_FUSE_LIBRARY_NAME LIBRARY_NAME "-FUSE"
|
||||||
|
|
||||||
|
#define FSP_FUSE_HDR_FROM_CONTEXT(c) \
|
||||||
|
(struct fsp_fuse_context_header *)((PUINT8)(c) - sizeof(struct fsp_fuse_context_header))
|
||||||
|
#define FSP_FUSE_CONTEXT_FROM_HDR(h) \
|
||||||
|
(struct fuse_context *)((PUINT8)(h) + sizeof(struct fsp_fuse_context_header))
|
||||||
|
|
||||||
|
struct fuse
|
||||||
|
{
|
||||||
|
struct fsp_fuse_env *env;
|
||||||
|
int set_umask, umask;
|
||||||
|
int set_uid, uid;
|
||||||
|
int set_gid, gid;
|
||||||
|
struct fuse_operations ops;
|
||||||
|
void *data;
|
||||||
|
UINT32 DebugLog;
|
||||||
|
FSP_FILE_SYSTEM_OPERATION_GUARD_STRATEGY OpGuardStrategy;
|
||||||
|
FSP_FSCTL_VOLUME_PARAMS VolumeParams;
|
||||||
|
PWSTR MountPoint;
|
||||||
|
FSP_FILE_SYSTEM *FileSystem;
|
||||||
|
BOOLEAN fsinit;
|
||||||
|
FSP_SERVICE *Service; /* weak */
|
||||||
|
};
|
||||||
|
|
||||||
|
struct fsp_fuse_context_header
|
||||||
|
{
|
||||||
|
FSP_FSCTL_TRANSACT_REQ *Request;
|
||||||
|
FSP_FSCTL_TRANSACT_RSP *Response;
|
||||||
|
char *PosixPath;
|
||||||
|
__declspec(align(MEMORY_ALLOCATION_ALIGNMENT)) UINT8 ContextBuf[];
|
||||||
|
};
|
||||||
|
|
||||||
|
struct fsp_fuse_file_desc
|
||||||
|
{
|
||||||
|
char *PosixPath;
|
||||||
|
BOOLEAN IsDirectory;
|
||||||
|
int OpenFlags;
|
||||||
|
UINT64 FileHandle;
|
||||||
|
PVOID DirBuffer;
|
||||||
|
ULONG DirBufferSize;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct fuse_dirhandle
|
||||||
|
{
|
||||||
|
PVOID Buffer;
|
||||||
|
ULONG Length;
|
||||||
|
ULONG BytesTransferred;
|
||||||
|
BOOLEAN NonZeroOffset;
|
||||||
|
BOOLEAN DotFiles, HasChild;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct fsp_fuse_dirinfo
|
||||||
|
{
|
||||||
|
UINT16 Size;
|
||||||
|
FSP_FSCTL_FILE_INFO FileInfo;
|
||||||
|
BOOLEAN FileInfoValid;
|
||||||
|
UINT64 NextOffset;
|
||||||
|
char PosixNameBuf[]; /* includes term-0 (unlike FSP_FSCTL_DIR_INFO) */
|
||||||
|
};
|
||||||
|
|
||||||
|
NTSTATUS fsp_fuse_op_enter(FSP_FILE_SYSTEM *FileSystem,
|
||||||
|
FSP_FSCTL_TRANSACT_REQ *Request, FSP_FSCTL_TRANSACT_RSP *Response);
|
||||||
|
NTSTATUS fsp_fuse_op_leave(FSP_FILE_SYSTEM *FileSystem,
|
||||||
|
FSP_FSCTL_TRANSACT_REQ *Request, FSP_FSCTL_TRANSACT_RSP *Response);
|
||||||
|
|
||||||
|
extern FSP_FILE_SYSTEM_INTERFACE fsp_fuse_intf;
|
||||||
|
|
||||||
|
#endif
|
@ -18,7 +18,6 @@
|
|||||||
#include <dll/library.h>
|
#include <dll/library.h>
|
||||||
|
|
||||||
HINSTANCE DllInstance;
|
HINSTANCE DllInstance;
|
||||||
HANDLE ProcessHeap;
|
|
||||||
|
|
||||||
BOOL WINAPI DllMain(HINSTANCE Instance, DWORD Reason, PVOID Reserved)
|
BOOL WINAPI DllMain(HINSTANCE Instance, DWORD Reason, PVOID Reserved)
|
||||||
{
|
{
|
||||||
@ -28,22 +27,6 @@ BOOL WINAPI DllMain(HINSTANCE Instance, DWORD Reason, PVOID Reserved)
|
|||||||
{
|
{
|
||||||
case DLL_PROCESS_ATTACH:
|
case DLL_PROCESS_ATTACH:
|
||||||
DllInstance = Instance;
|
DllInstance = Instance;
|
||||||
ProcessHeap = GetProcessHeap();
|
|
||||||
if (0 == ProcessHeap)
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* These functions are called during DLL_PROCESS_ATTACH. We must therefore keep
|
|
||||||
* initialization tasks to a minimum.
|
|
||||||
*
|
|
||||||
* See the DLL best practices document:
|
|
||||||
* https://msdn.microsoft.com/en-us/library/windows/desktop/dn633971(v=vs.85).aspx
|
|
||||||
*/
|
|
||||||
Dynamic = 0 == Reserved;
|
|
||||||
FspNtStatusInitialize(Dynamic);
|
|
||||||
FspEventLogInitialize(Dynamic);
|
|
||||||
FspFileSystemInitialize(Dynamic);
|
|
||||||
FspServiceInitialize(Dynamic);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DLL_PROCESS_DETACH:
|
case DLL_PROCESS_DETACH:
|
||||||
@ -57,10 +40,14 @@ BOOL WINAPI DllMain(HINSTANCE Instance, DWORD Reason, PVOID Reserved)
|
|||||||
* https://blogs.msdn.microsoft.com/oldnewthing/20100122-00/?p=15193/
|
* https://blogs.msdn.microsoft.com/oldnewthing/20100122-00/?p=15193/
|
||||||
*/
|
*/
|
||||||
Dynamic = 0 == Reserved;
|
Dynamic = 0 == Reserved;
|
||||||
|
fsp_fuse_finalize(Dynamic);
|
||||||
FspServiceFinalize(Dynamic);
|
FspServiceFinalize(Dynamic);
|
||||||
FspFileSystemFinalize(Dynamic);
|
|
||||||
FspEventLogFinalize(Dynamic);
|
FspEventLogFinalize(Dynamic);
|
||||||
FspNtStatusFinalize(Dynamic);
|
FspPosixFinalize(Dynamic);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DLL_THREAD_DETACH:
|
||||||
|
fsp_fuse_finalize_thread();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,14 +36,11 @@
|
|||||||
#define DEBUGLOGSD(fmt, SD) ((void)0)
|
#define DEBUGLOGSD(fmt, SD) ((void)0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
VOID FspNtStatusInitialize(BOOLEAN Dynamic);
|
VOID FspPosixFinalize(BOOLEAN Dynamic);
|
||||||
VOID FspNtStatusFinalize(BOOLEAN Dynamic);
|
|
||||||
VOID FspEventLogInitialize(BOOLEAN Dynamic);
|
|
||||||
VOID FspEventLogFinalize(BOOLEAN Dynamic);
|
VOID FspEventLogFinalize(BOOLEAN Dynamic);
|
||||||
VOID FspFileSystemInitialize(BOOLEAN Dynamic);
|
|
||||||
VOID FspFileSystemFinalize(BOOLEAN Dynamic);
|
|
||||||
VOID FspServiceInitialize(BOOLEAN Dynamic);
|
|
||||||
VOID FspServiceFinalize(BOOLEAN Dynamic);
|
VOID FspServiceFinalize(BOOLEAN Dynamic);
|
||||||
|
VOID fsp_fuse_finalize(BOOLEAN Dynamic);
|
||||||
|
VOID fsp_fuse_finalize_thread(VOID);
|
||||||
|
|
||||||
NTSTATUS FspFsctlRegister(VOID);
|
NTSTATUS FspFsctlRegister(VOID);
|
||||||
NTSTATUS FspFsctlUnregister(VOID);
|
NTSTATUS FspFsctlUnregister(VOID);
|
||||||
@ -52,4 +49,8 @@ NTSTATUS FspNpUnregister(VOID);
|
|||||||
NTSTATUS FspEventLogRegister(VOID);
|
NTSTATUS FspEventLogRegister(VOID);
|
||||||
NTSTATUS FspEventLogUnregister(VOID);
|
NTSTATUS FspEventLogUnregister(VOID);
|
||||||
|
|
||||||
|
PWSTR FspDiagIdent(VOID);
|
||||||
|
|
||||||
|
BOOL WINAPI FspServiceConsoleCtrlHandler(DWORD CtrlType);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
441
src/dll/np.c
441
src/dll/np.c
@ -17,116 +17,29 @@
|
|||||||
|
|
||||||
#include <dll/library.h>
|
#include <dll/library.h>
|
||||||
#include <launcher/launcher.h>
|
#include <launcher/launcher.h>
|
||||||
#include <aclapi.h>
|
|
||||||
#include <npapi.h>
|
#include <npapi.h>
|
||||||
|
#include <wincred.h>
|
||||||
|
|
||||||
#define FSP_NP_NAME LIBRARY_NAME ".Np"
|
#define FSP_NP_NAME LIBRARY_NAME ".Np"
|
||||||
#define FSP_NP_TYPE ' spF' /* pick a value hopefully not in use */
|
#define FSP_NP_TYPE ' spF' /* pick a value hopefully not in use */
|
||||||
|
|
||||||
FSP_API NTSTATUS FspCallNamedPipeSecurely(PWSTR PipeName,
|
/*
|
||||||
PVOID InBuffer, ULONG InBufferSize, PVOID OutBuffer, ULONG OutBufferSize,
|
* Define the following macro to use CredUIPromptForWindowsCredentials.
|
||||||
PULONG PBytesTransferred, ULONG Timeout,
|
* Otherwise CredUIPromptForCredentials will be used.
|
||||||
PSID Sid)
|
*/
|
||||||
|
#define FSP_NP_CREDUI_PROMPT_NEW
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Define the following macro to include support for the credential manager.
|
||||||
|
*/
|
||||||
|
#define FSP_NP_CREDENTIAL_MANAGER
|
||||||
|
|
||||||
|
enum
|
||||||
{
|
{
|
||||||
NTSTATUS Result;
|
FSP_NP_CREDENTIALS_NONE = 0,
|
||||||
HANDLE Pipe = INVALID_HANDLE_VALUE;
|
FSP_NP_CREDENTIALS_PASSWORD = 1,
|
||||||
DWORD PipeMode;
|
FSP_NP_CREDENTIALS_USERPASS = 3,
|
||||||
|
};
|
||||||
Pipe = CreateFileW(PipeName,
|
|
||||||
GENERIC_READ | FILE_WRITE_DATA | FILE_WRITE_ATTRIBUTES,
|
|
||||||
FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING,
|
|
||||||
SECURITY_SQOS_PRESENT | SECURITY_IDENTIFICATION, 0);
|
|
||||||
if (INVALID_HANDLE_VALUE == Pipe)
|
|
||||||
{
|
|
||||||
if (ERROR_PIPE_BUSY != GetLastError())
|
|
||||||
{
|
|
||||||
Result = FspNtStatusFromWin32(GetLastError());
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
WaitNamedPipeW(PipeName, Timeout);
|
|
||||||
|
|
||||||
Pipe = CreateFileW(PipeName,
|
|
||||||
GENERIC_READ | FILE_WRITE_DATA | FILE_WRITE_ATTRIBUTES,
|
|
||||||
FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING,
|
|
||||||
SECURITY_SQOS_PRESENT | SECURITY_IDENTIFICATION, 0);
|
|
||||||
if (INVALID_HANDLE_VALUE == Pipe)
|
|
||||||
{
|
|
||||||
Result = FspNtStatusFromWin32(GetLastError());
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (0 != Sid)
|
|
||||||
{
|
|
||||||
PSECURITY_DESCRIPTOR SecurityDescriptor = 0;
|
|
||||||
PSID OwnerSid, WellKnownSid = 0;
|
|
||||||
DWORD SidSize, LastError;
|
|
||||||
|
|
||||||
/* if it is a small number treat it like a well known SID */
|
|
||||||
if (1024 > (INT_PTR)Sid)
|
|
||||||
{
|
|
||||||
SidSize = SECURITY_MAX_SID_SIZE;
|
|
||||||
WellKnownSid = MemAlloc(SidSize);
|
|
||||||
if (0 == WellKnownSid)
|
|
||||||
{
|
|
||||||
Result = STATUS_INSUFFICIENT_RESOURCES;
|
|
||||||
goto sid_exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!CreateWellKnownSid((INT_PTR)Sid, 0, WellKnownSid, &SidSize))
|
|
||||||
{
|
|
||||||
Result = FspNtStatusFromWin32(GetLastError());
|
|
||||||
goto sid_exit;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
LastError = GetSecurityInfo(Pipe, SE_FILE_OBJECT,
|
|
||||||
OWNER_SECURITY_INFORMATION, &OwnerSid, 0, 0, 0, &SecurityDescriptor);
|
|
||||||
if (0 != LastError)
|
|
||||||
{
|
|
||||||
Result = FspNtStatusFromWin32(GetLastError());
|
|
||||||
goto sid_exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!EqualSid(OwnerSid, WellKnownSid ? WellKnownSid : Sid))
|
|
||||||
{
|
|
||||||
Result = STATUS_ACCESS_DENIED;
|
|
||||||
goto sid_exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
Result = STATUS_SUCCESS;
|
|
||||||
|
|
||||||
sid_exit:
|
|
||||||
MemFree(WellKnownSid);
|
|
||||||
LocalFree(SecurityDescriptor);
|
|
||||||
|
|
||||||
if (!NT_SUCCESS(Result))
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
PipeMode = PIPE_READMODE_MESSAGE | PIPE_WAIT;
|
|
||||||
if (!SetNamedPipeHandleState(Pipe, &PipeMode, 0, 0))
|
|
||||||
{
|
|
||||||
Result = FspNtStatusFromWin32(GetLastError());
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!TransactNamedPipe(Pipe, InBuffer, InBufferSize, OutBuffer, OutBufferSize,
|
|
||||||
PBytesTransferred, 0))
|
|
||||||
{
|
|
||||||
Result = FspNtStatusFromWin32(GetLastError());
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
Result = STATUS_SUCCESS;
|
|
||||||
|
|
||||||
exit:
|
|
||||||
if (INVALID_HANDLE_VALUE != Pipe)
|
|
||||||
CloseHandle(Pipe);
|
|
||||||
|
|
||||||
return Result;
|
|
||||||
}
|
|
||||||
|
|
||||||
DWORD APIENTRY NPGetCaps(DWORD Index)
|
DWORD APIENTRY NPGetCaps(DWORD Index)
|
||||||
{
|
{
|
||||||
@ -208,6 +121,9 @@ static inline BOOLEAN FspNpParseRemoteName(PWSTR RemoteName,
|
|||||||
PWSTR ClassName, InstanceName, P;
|
PWSTR ClassName, InstanceName, P;
|
||||||
ULONG ClassNameLen, InstanceNameLen;
|
ULONG ClassNameLen, InstanceNameLen;
|
||||||
|
|
||||||
|
if (!FspNpCheckRemoteName(RemoteName))
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
ClassName = RemoteName + 2; /* skip \\ */
|
ClassName = RemoteName + 2; /* skip \\ */
|
||||||
for (P = ClassName; *P; P++)
|
for (P = ClassName; *P; P++)
|
||||||
if (L'\\' == *P)
|
if (L'\\' == *P)
|
||||||
@ -235,6 +151,27 @@ static inline BOOLEAN FspNpParseRemoteName(PWSTR RemoteName,
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline BOOLEAN FspNpParseUserName(PWSTR RemoteName,
|
||||||
|
PWSTR UserName, ULONG UserNameSize/* in chars */)
|
||||||
|
{
|
||||||
|
PWSTR ClassName, InstanceName, P;
|
||||||
|
ULONG ClassNameLen, InstanceNameLen;
|
||||||
|
|
||||||
|
if (FspNpParseRemoteName(RemoteName,
|
||||||
|
&ClassName, &ClassNameLen, &InstanceName, &InstanceNameLen))
|
||||||
|
{
|
||||||
|
for (P = InstanceName; *P; P++)
|
||||||
|
if ('@' == *P && P - InstanceName < UserNameSize)
|
||||||
|
{
|
||||||
|
memcpy(UserName, InstanceName, (P - InstanceName) * sizeof(WCHAR));
|
||||||
|
UserName[P - InstanceName] = L'\0';
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
static inline DWORD FspNpCallLauncherPipe(PWSTR PipeBuf, ULONG SendSize, ULONG RecvSize)
|
static inline DWORD FspNpCallLauncherPipe(PWSTR PipeBuf, ULONG SendSize, ULONG RecvSize)
|
||||||
{
|
{
|
||||||
DWORD NpResult;
|
DWORD NpResult;
|
||||||
@ -331,6 +268,144 @@ static WCHAR FspNpGetDriveLetter(PDWORD PLogicalDrives, PWSTR VolumeName)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static DWORD FspNpGetCredentialsKind(PWSTR RemoteName, PDWORD PCredentialsKind)
|
||||||
|
{
|
||||||
|
HKEY RegKey = 0;
|
||||||
|
DWORD NpResult, RegSize;
|
||||||
|
DWORD Credentials;
|
||||||
|
PWSTR ClassName, InstanceName;
|
||||||
|
ULONG ClassNameLen, InstanceNameLen;
|
||||||
|
WCHAR ClassNameBuf[sizeof(((FSP_FSCTL_VOLUME_PARAMS *)0)->Prefix) / sizeof(WCHAR)];
|
||||||
|
|
||||||
|
*PCredentialsKind = FSP_NP_CREDENTIALS_NONE;
|
||||||
|
|
||||||
|
if (!FspNpParseRemoteName(RemoteName,
|
||||||
|
&ClassName, &ClassNameLen, &InstanceName, &InstanceNameLen))
|
||||||
|
return WN_BAD_NETNAME;
|
||||||
|
|
||||||
|
if (ClassNameLen > sizeof ClassNameBuf / sizeof ClassNameBuf[0] - 1)
|
||||||
|
ClassNameLen = sizeof ClassNameBuf / sizeof ClassNameBuf[0] - 1;
|
||||||
|
memcpy(ClassNameBuf, ClassName, ClassNameLen * sizeof(WCHAR));
|
||||||
|
ClassNameBuf[ClassNameLen] = '\0';
|
||||||
|
|
||||||
|
NpResult = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"" LAUNCHER_REGKEY, 0, KEY_READ, &RegKey);
|
||||||
|
if (ERROR_SUCCESS != NpResult)
|
||||||
|
goto exit;
|
||||||
|
|
||||||
|
RegSize = sizeof Credentials;
|
||||||
|
Credentials = 0; /* default is NO credentials */
|
||||||
|
NpResult = RegGetValueW(RegKey, ClassNameBuf, L"Credentials", RRF_RT_REG_DWORD, 0,
|
||||||
|
&Credentials, &RegSize);
|
||||||
|
if (ERROR_SUCCESS != NpResult && ERROR_FILE_NOT_FOUND != NpResult)
|
||||||
|
goto exit;
|
||||||
|
|
||||||
|
switch (Credentials)
|
||||||
|
{
|
||||||
|
case FSP_NP_CREDENTIALS_NONE:
|
||||||
|
case FSP_NP_CREDENTIALS_PASSWORD:
|
||||||
|
case FSP_NP_CREDENTIALS_USERPASS:
|
||||||
|
*PCredentialsKind = Credentials;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
NpResult = ERROR_SUCCESS;
|
||||||
|
|
||||||
|
exit:
|
||||||
|
if (0 != RegKey)
|
||||||
|
RegCloseKey(RegKey);
|
||||||
|
|
||||||
|
return NpResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
static DWORD FspNpGetCredentials(
|
||||||
|
HWND hwndOwner, PWSTR Caption, DWORD PrevNpResult,
|
||||||
|
DWORD CredentialsKind,
|
||||||
|
PBOOL PSave,
|
||||||
|
PWSTR UserName, ULONG UserNameSize/* in chars */,
|
||||||
|
PWSTR Password, ULONG PasswordSize/* in chars */)
|
||||||
|
{
|
||||||
|
DWORD NpResult;
|
||||||
|
CREDUI_INFOW UiInfo;
|
||||||
|
|
||||||
|
memset(&UiInfo, 0, sizeof UiInfo);
|
||||||
|
UiInfo.cbSize = sizeof UiInfo;
|
||||||
|
UiInfo.hwndParent = hwndOwner;
|
||||||
|
UiInfo.pszCaptionText = Caption;
|
||||||
|
UiInfo.pszMessageText = L"Enter credentials to unlock this file system.";
|
||||||
|
|
||||||
|
#if !defined(FSP_NP_CREDUI_PROMPT_NEW)
|
||||||
|
NpResult = CredUIPromptForCredentialsW(&UiInfo, L"NONE", 0, 0,
|
||||||
|
UserName, UserNameSize,
|
||||||
|
Password, PasswordSize,
|
||||||
|
PSave,
|
||||||
|
CREDUI_FLAGS_GENERIC_CREDENTIALS |
|
||||||
|
CREDUI_FLAGS_DO_NOT_PERSIST |
|
||||||
|
CREDUI_FLAGS_ALWAYS_SHOW_UI |
|
||||||
|
(0 != PrevNpResult ? CREDUI_FLAGS_INCORRECT_PASSWORD : 0) |
|
||||||
|
(0 != PSave ? CREDUI_FLAGS_SHOW_SAVE_CHECK_BOX : 0) |
|
||||||
|
(FSP_NP_CREDENTIALS_PASSWORD == CredentialsKind ? 0/*CREDUI_FLAGS_KEEP_USERNAME*/ : 0));
|
||||||
|
#else
|
||||||
|
WCHAR Domain[CREDUI_MAX_DOMAIN_TARGET_LENGTH + 1];
|
||||||
|
ULONG AuthPackage = 0;
|
||||||
|
PVOID InAuthBuf = 0, OutAuthBuf = 0;
|
||||||
|
ULONG InAuthSize, OutAuthSize, DomainSize;
|
||||||
|
|
||||||
|
InAuthSize = 0;
|
||||||
|
if (!CredPackAuthenticationBufferW(
|
||||||
|
CRED_PACK_GENERIC_CREDENTIALS, UserName, Password, 0, &InAuthSize) &&
|
||||||
|
ERROR_INSUFFICIENT_BUFFER != GetLastError())
|
||||||
|
{
|
||||||
|
NpResult = GetLastError();
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
InAuthBuf = MemAlloc(InAuthSize);
|
||||||
|
if (0 == InAuthBuf)
|
||||||
|
{
|
||||||
|
NpResult = ERROR_NO_SYSTEM_RESOURCES;
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!CredPackAuthenticationBufferW(
|
||||||
|
CRED_PACK_GENERIC_CREDENTIALS, UserName, Password, InAuthBuf, &InAuthSize))
|
||||||
|
{
|
||||||
|
NpResult = GetLastError();
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
NpResult = CredUIPromptForWindowsCredentialsW(&UiInfo, PrevNpResult,
|
||||||
|
&AuthPackage, InAuthBuf, InAuthSize, &OutAuthBuf, &OutAuthSize, PSave,
|
||||||
|
CREDUIWIN_GENERIC | (0 != PSave ? CREDUIWIN_CHECKBOX : 0));
|
||||||
|
if (ERROR_SUCCESS != NpResult)
|
||||||
|
goto exit;
|
||||||
|
|
||||||
|
DomainSize = sizeof Domain / sizeof Domain[0];
|
||||||
|
if (!CredUnPackAuthenticationBufferW(0, OutAuthBuf, OutAuthSize,
|
||||||
|
UserName, &UserNameSize, Domain, &DomainSize, Password, &PasswordSize))
|
||||||
|
{
|
||||||
|
NpResult = GetLastError();
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
NpResult = ERROR_SUCCESS;
|
||||||
|
|
||||||
|
exit:
|
||||||
|
if (0 != OutAuthBuf)
|
||||||
|
{
|
||||||
|
SecureZeroMemory(OutAuthBuf, OutAuthSize);
|
||||||
|
CoTaskMemFree(OutAuthBuf);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (0 != InAuthBuf)
|
||||||
|
{
|
||||||
|
SecureZeroMemory(InAuthBuf, InAuthSize);
|
||||||
|
MemFree(InAuthBuf);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return NpResult;
|
||||||
|
}
|
||||||
|
|
||||||
DWORD APIENTRY NPGetConnection(
|
DWORD APIENTRY NPGetConnection(
|
||||||
LPWSTR lpLocalName, LPWSTR lpRemoteName, LPDWORD lpnBufferLen)
|
LPWSTR lpLocalName, LPWSTR lpRemoteName, LPDWORD lpnBufferLen)
|
||||||
{
|
{
|
||||||
@ -409,12 +484,6 @@ DWORD APIENTRY NPGetConnection(
|
|||||||
}
|
}
|
||||||
|
|
||||||
DWORD APIENTRY NPAddConnection(LPNETRESOURCEW lpNetResource, LPWSTR lpPassword, LPWSTR lpUserName)
|
DWORD APIENTRY NPAddConnection(LPNETRESOURCEW lpNetResource, LPWSTR lpPassword, LPWSTR lpUserName)
|
||||||
{
|
|
||||||
return NPAddConnection3(0, lpNetResource, lpPassword, lpUserName, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
DWORD APIENTRY NPAddConnection3(HWND hwndOwner,
|
|
||||||
LPNETRESOURCEW lpNetResource, LPWSTR lpPassword, LPWSTR lpUserName, DWORD dwFlags)
|
|
||||||
{
|
{
|
||||||
DWORD NpResult;
|
DWORD NpResult;
|
||||||
DWORD dwType = lpNetResource->dwType;
|
DWORD dwType = lpNetResource->dwType;
|
||||||
@ -423,14 +492,15 @@ DWORD APIENTRY NPAddConnection3(HWND hwndOwner,
|
|||||||
WCHAR LocalNameBuf[3];
|
WCHAR LocalNameBuf[3];
|
||||||
PWSTR ClassName, InstanceName, RemoteName, P;
|
PWSTR ClassName, InstanceName, RemoteName, P;
|
||||||
ULONG ClassNameLen, InstanceNameLen;
|
ULONG ClassNameLen, InstanceNameLen;
|
||||||
|
DWORD CredentialsKind;
|
||||||
PWSTR PipeBuf = 0;
|
PWSTR PipeBuf = 0;
|
||||||
|
#if defined(FSP_NP_CREDENTIAL_MANAGER)
|
||||||
|
PCREDENTIALW Credential = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (dwType & RESOURCETYPE_PRINT)
|
if (dwType & RESOURCETYPE_PRINT)
|
||||||
return WN_BAD_VALUE;
|
return WN_BAD_VALUE;
|
||||||
|
|
||||||
if (!FspNpCheckRemoteName(lpRemoteName))
|
|
||||||
return WN_BAD_NETNAME;
|
|
||||||
|
|
||||||
if (!FspNpParseRemoteName(lpRemoteName,
|
if (!FspNpParseRemoteName(lpRemoteName,
|
||||||
&ClassName, &ClassNameLen, &InstanceName, &InstanceNameLen))
|
&ClassName, &ClassNameLen, &InstanceName, &InstanceNameLen))
|
||||||
return WN_BAD_NETNAME;
|
return WN_BAD_NETNAME;
|
||||||
@ -450,22 +520,75 @@ DWORD APIENTRY NPAddConnection3(HWND hwndOwner,
|
|||||||
return WN_ALREADY_CONNECTED;
|
return WN_ALREADY_CONNECTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FspNpGetCredentialsKind(lpRemoteName, &CredentialsKind);
|
||||||
|
|
||||||
|
#if defined(FSP_NP_CREDENTIAL_MANAGER)
|
||||||
|
/* if we need credentials and none were passed check with the credential manager */
|
||||||
|
if (FSP_NP_CREDENTIALS_NONE != CredentialsKind && 0 == lpPassword &&
|
||||||
|
CredReadW(lpRemoteName, CRED_TYPE_GENERIC, 0, &Credential))
|
||||||
|
{
|
||||||
|
if (sizeof(WCHAR) <= Credential->CredentialBlobSize &&
|
||||||
|
L'\0' == ((PWSTR)(Credential->CredentialBlob))
|
||||||
|
[(Credential->CredentialBlobSize / sizeof(WCHAR)) - 1])
|
||||||
|
{
|
||||||
|
lpUserName = Credential->UserName;
|
||||||
|
lpPassword = (PVOID)Credential->CredentialBlob;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* if we need credentials and we don't have any return ACCESS DENIED */
|
||||||
|
if (FSP_NP_CREDENTIALS_NONE != CredentialsKind)
|
||||||
|
{
|
||||||
|
int Length;
|
||||||
|
if (0 == lpPassword ||
|
||||||
|
(0 == (Length = lstrlenW(lpPassword))) || CREDUI_MAX_PASSWORD_LENGTH < Length)
|
||||||
|
{
|
||||||
|
NpResult = WN_ACCESS_DENIED;
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (FSP_NP_CREDENTIALS_USERPASS == CredentialsKind)
|
||||||
|
{
|
||||||
|
int Length;
|
||||||
|
if (0 == lpUserName ||
|
||||||
|
(0 == (Length = lstrlenW(lpUserName))) || CREDUI_MAX_USERNAME_LENGTH < Length)
|
||||||
|
{
|
||||||
|
NpResult = WN_ACCESS_DENIED;
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
PipeBuf = MemAlloc(LAUNCHER_PIPE_BUFFER_SIZE);
|
PipeBuf = MemAlloc(LAUNCHER_PIPE_BUFFER_SIZE);
|
||||||
if (0 == PipeBuf)
|
if (0 == PipeBuf)
|
||||||
return WN_OUT_OF_MEMORY;
|
{
|
||||||
|
NpResult = WN_OUT_OF_MEMORY;
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* we do not explicitly check, but assumption is it all fits in LAUNCHER_PIPE_BUFFER_SIZE */
|
||||||
P = PipeBuf;
|
P = PipeBuf;
|
||||||
*P++ = LauncherSvcInstanceStart;
|
*P++ = FSP_NP_CREDENTIALS_NONE != CredentialsKind ?
|
||||||
|
LauncherSvcInstanceStartWithSecret : LauncherSvcInstanceStart;
|
||||||
memcpy(P, ClassName, ClassNameLen * sizeof(WCHAR)); P += ClassNameLen; *P++ = L'\0';
|
memcpy(P, ClassName, ClassNameLen * sizeof(WCHAR)); P += ClassNameLen; *P++ = L'\0';
|
||||||
memcpy(P, InstanceName, InstanceNameLen * sizeof(WCHAR)); P += InstanceNameLen; *P++ = L'\0';
|
memcpy(P, InstanceName, InstanceNameLen * sizeof(WCHAR)); P += InstanceNameLen; *P++ = L'\0';
|
||||||
lstrcpyW(P, RemoteName); P += lstrlenW(RemoteName) + 1;
|
lstrcpyW(P, RemoteName); P += lstrlenW(RemoteName) + 1;
|
||||||
lstrcpyW(P, LocalNameBuf); P += lstrlenW(LocalNameBuf) + 1;
|
lstrcpyW(P, LocalNameBuf); P += lstrlenW(LocalNameBuf) + 1;
|
||||||
|
if (FSP_NP_CREDENTIALS_USERPASS == CredentialsKind)
|
||||||
|
{
|
||||||
|
lstrcpyW(P, lpUserName); P += lstrlenW(lpUserName) + 1;
|
||||||
|
}
|
||||||
|
if (FSP_NP_CREDENTIALS_NONE != CredentialsKind)
|
||||||
|
{
|
||||||
|
lstrcpyW(P, lpPassword); P += lstrlenW(lpPassword) + 1;
|
||||||
|
}
|
||||||
|
|
||||||
NpResult = FspNpCallLauncherPipe(
|
NpResult = FspNpCallLauncherPipe(
|
||||||
PipeBuf, (ULONG)(P - PipeBuf) * sizeof(WCHAR), LAUNCHER_PIPE_BUFFER_SIZE);
|
PipeBuf, (ULONG)(P - PipeBuf) * sizeof(WCHAR), LAUNCHER_PIPE_BUFFER_SIZE);
|
||||||
switch (NpResult)
|
switch (NpResult)
|
||||||
{
|
{
|
||||||
case WN_SUCCESS:
|
case WN_SUCCESS:
|
||||||
|
case WN_ACCESS_DENIED:
|
||||||
break;
|
break;
|
||||||
case ERROR_ALREADY_EXISTS:
|
case ERROR_ALREADY_EXISTS:
|
||||||
/*
|
/*
|
||||||
@ -499,8 +622,89 @@ DWORD APIENTRY NPAddConnection3(HWND hwndOwner,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exit:
|
||||||
MemFree(PipeBuf);
|
MemFree(PipeBuf);
|
||||||
|
|
||||||
|
#if defined(FSP_NP_CREDENTIAL_MANAGER)
|
||||||
|
if (0 != Credential)
|
||||||
|
CredFree(Credential);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return NpResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
DWORD APIENTRY NPAddConnection3(HWND hwndOwner,
|
||||||
|
LPNETRESOURCEW lpNetResource, LPWSTR lpPassword, LPWSTR lpUserName, DWORD dwFlags)
|
||||||
|
{
|
||||||
|
DWORD NpResult;
|
||||||
|
PWSTR RemoteName = lpNetResource->lpRemoteName;
|
||||||
|
DWORD CredentialsKind;
|
||||||
|
WCHAR UserName[CREDUI_MAX_USERNAME_LENGTH + 1], Password[CREDUI_MAX_PASSWORD_LENGTH + 1];
|
||||||
|
#if defined(FSP_NP_CREDENTIAL_MANAGER)
|
||||||
|
BOOL Save = TRUE;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//dwFlags |= CONNECT_INTERACTIVE | CONNECT_PROMPT; /* TESTING ONLY! */
|
||||||
|
|
||||||
|
/* CONNECT_PROMPT is only valid if CONNECT_INTERACTIVE is also set */
|
||||||
|
if (CONNECT_PROMPT == (dwFlags & (CONNECT_INTERACTIVE | CONNECT_PROMPT)))
|
||||||
|
return WN_BAD_VALUE;
|
||||||
|
|
||||||
|
/* if not CONNECT_PROMPT go ahead and attempt to NPAddConnection once */
|
||||||
|
if (0 == (dwFlags & CONNECT_PROMPT))
|
||||||
|
{
|
||||||
|
NpResult = NPAddConnection(lpNetResource, lpPassword, lpUserName);
|
||||||
|
if (WN_ACCESS_DENIED != NpResult || 0 == (dwFlags & CONNECT_INTERACTIVE))
|
||||||
|
return NpResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
FspNpGetCredentialsKind(RemoteName, &CredentialsKind);
|
||||||
|
if (FSP_NP_CREDENTIALS_NONE == CredentialsKind)
|
||||||
|
return WN_CANCEL;
|
||||||
|
|
||||||
|
/* if CONNECT_INTERACTIVE keep asking the user for valid credentials or cancel */
|
||||||
|
NpResult = WN_SUCCESS;
|
||||||
|
lstrcpyW(UserName, L"UNSPECIFIED");
|
||||||
|
Password[0] = L'\0';
|
||||||
|
if (FSP_NP_CREDENTIALS_PASSWORD == CredentialsKind)
|
||||||
|
FspNpParseUserName(RemoteName, UserName, sizeof UserName / sizeof UserName[0]);
|
||||||
|
do
|
||||||
|
{
|
||||||
|
NpResult = FspNpGetCredentials(
|
||||||
|
hwndOwner, RemoteName, NpResult,
|
||||||
|
CredentialsKind,
|
||||||
|
#if defined(FSP_NP_CREDENTIAL_MANAGER)
|
||||||
|
&Save,
|
||||||
|
#else
|
||||||
|
0,
|
||||||
|
#endif
|
||||||
|
UserName, sizeof UserName / sizeof UserName[0],
|
||||||
|
Password, sizeof Password / sizeof Password[0]);
|
||||||
|
if (WN_SUCCESS != NpResult)
|
||||||
|
break;
|
||||||
|
|
||||||
|
NpResult = NPAddConnection(lpNetResource, Password, UserName);
|
||||||
|
} while (WN_ACCESS_DENIED == NpResult);
|
||||||
|
|
||||||
|
#if defined(FSP_NP_CREDENTIAL_MANAGER)
|
||||||
|
if (WN_SUCCESS == NpResult && Save)
|
||||||
|
{
|
||||||
|
CREDENTIALW Credential;
|
||||||
|
|
||||||
|
memset(&Credential, 0, sizeof Credential);
|
||||||
|
Credential.Type = CRED_TYPE_GENERIC;
|
||||||
|
Credential.Persist = CRED_PERSIST_LOCAL_MACHINE;
|
||||||
|
Credential.TargetName = RemoteName;
|
||||||
|
Credential.UserName = UserName;
|
||||||
|
Credential.CredentialBlobSize = (lstrlenW(Password) + 1) * sizeof(WCHAR);
|
||||||
|
Credential.CredentialBlob = (PVOID)Password;
|
||||||
|
|
||||||
|
CredWriteW(&Credential, 0);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
SecureZeroMemory(Password, sizeof Password);
|
||||||
|
|
||||||
return NpResult;
|
return NpResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -570,10 +774,9 @@ typedef struct
|
|||||||
static inline BOOLEAN FspNpValidateEnum(FSP_NP_ENUM *Enum)
|
static inline BOOLEAN FspNpValidateEnum(FSP_NP_ENUM *Enum)
|
||||||
{
|
{
|
||||||
#if 0
|
#if 0
|
||||||
extern HANDLE ProcessHeap;
|
|
||||||
return
|
return
|
||||||
0 != Enum &&
|
0 != Enum &&
|
||||||
HeapValidate(ProcessHeap, 0, Enum) &&
|
HeapValidate(GetProcessHeap(), 0, Enum) &&
|
||||||
'munE' == Enum->Signature;
|
'munE' == Enum->Signature;
|
||||||
#else
|
#else
|
||||||
return
|
return
|
||||||
@ -838,7 +1041,7 @@ NTSTATUS FspNpRegister(VOID)
|
|||||||
{
|
{
|
||||||
if (L',' == *P || '\0' == *P)
|
if (L',' == *P || '\0' == *P)
|
||||||
{
|
{
|
||||||
if (CSTR_EQUAL == CompareStringW(LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE,
|
if (CSTR_EQUAL == CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE,
|
||||||
Part, (int)(P - Part),
|
Part, (int)(P - Part),
|
||||||
L"" FSP_NP_NAME, (int)(sizeof L"" FSP_NP_NAME - sizeof(WCHAR)) / sizeof(WCHAR)))
|
L"" FSP_NP_NAME, (int)(sizeof L"" FSP_NP_NAME - sizeof(WCHAR)) / sizeof(WCHAR)))
|
||||||
{
|
{
|
||||||
@ -901,7 +1104,7 @@ NTSTATUS FspNpUnregister(VOID)
|
|||||||
{
|
{
|
||||||
if (L',' == *P || '\0' == *P)
|
if (L',' == *P || '\0' == *P)
|
||||||
{
|
{
|
||||||
if (CSTR_EQUAL == CompareStringW(LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE,
|
if (CSTR_EQUAL == CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE,
|
||||||
Part, (int)(P - Part),
|
Part, (int)(P - Part),
|
||||||
L"" FSP_NP_NAME, (int)(sizeof L"" FSP_NP_NAME - sizeof(WCHAR)) / sizeof(WCHAR)))
|
L"" FSP_NP_NAME, (int)(sizeof L"" FSP_NP_NAME - sizeof(WCHAR)) / sizeof(WCHAR)))
|
||||||
{
|
{
|
||||||
|
@ -17,27 +17,19 @@
|
|||||||
|
|
||||||
#include <dll/library.h>
|
#include <dll/library.h>
|
||||||
|
|
||||||
|
static INIT_ONCE FspNtStatusInitOnce = INIT_ONCE_STATIC_INIT;
|
||||||
static ULONG (WINAPI *FspRtlNtStatusToDosError)(NTSTATUS Status);
|
static ULONG (WINAPI *FspRtlNtStatusToDosError)(NTSTATUS Status);
|
||||||
|
|
||||||
VOID FspNtStatusInitialize(BOOLEAN Dynamic)
|
static BOOL WINAPI FspNtStatusInitialize(
|
||||||
|
PINIT_ONCE InitOnce, PVOID Parameter, PVOID *Context)
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
* This function is called during DLL_PROCESS_ATTACH. We must therefore keep
|
|
||||||
* initialization tasks to a minimum.
|
|
||||||
*
|
|
||||||
* GetModuleHandle/GetProcAddress is allowed (because they are kernel32 API's)! See:
|
|
||||||
* https://msdn.microsoft.com/en-us/library/windows/desktop/dn633971(v=vs.85).aspx
|
|
||||||
*/
|
|
||||||
|
|
||||||
HANDLE Handle;
|
HANDLE Handle;
|
||||||
|
|
||||||
Handle = GetModuleHandleW(L"ntdll.dll");
|
Handle = GetModuleHandleW(L"ntdll.dll");
|
||||||
if (0 != Handle)
|
if (0 != Handle)
|
||||||
FspRtlNtStatusToDosError = (PVOID)GetProcAddress(Handle, "RtlNtStatusToDosError");
|
FspRtlNtStatusToDosError = (PVOID)GetProcAddress(Handle, "RtlNtStatusToDosError");
|
||||||
}
|
|
||||||
|
|
||||||
VOID FspNtStatusFinalize(BOOLEAN Dynamic)
|
return TRUE;
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FSP_API NTSTATUS FspNtStatusFromWin32(DWORD Error)
|
FSP_API NTSTATUS FspNtStatusFromWin32(DWORD Error)
|
||||||
@ -46,12 +38,14 @@ FSP_API NTSTATUS FspNtStatusFromWin32(DWORD Error)
|
|||||||
{
|
{
|
||||||
#include "ntstatus.i"
|
#include "ntstatus.i"
|
||||||
default:
|
default:
|
||||||
return STATUS_ACCESS_DENIED;
|
/* use FACILITY_NTWIN32 if able, else STATUS_ACCESS_DENIED */
|
||||||
|
return 0xffff >= Error ? (0x80070000 | Error) : STATUS_ACCESS_DENIED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FSP_API DWORD FspWin32FromNtStatus(NTSTATUS Status)
|
FSP_API DWORD FspWin32FromNtStatus(NTSTATUS Status)
|
||||||
{
|
{
|
||||||
|
InitOnceExecuteOnce(&FspNtStatusInitOnce, FspNtStatusInitialize, 0, 0);
|
||||||
if (0 == FspRtlNtStatusToDosError)
|
if (0 == FspRtlNtStatusToDosError)
|
||||||
return ERROR_MR_MID_NOT_FOUND;
|
return ERROR_MR_MID_NOT_FOUND;
|
||||||
|
|
||||||
|
917
src/dll/posix.c
Normal file
917
src/dll/posix.c
Normal file
@ -0,0 +1,917 @@
|
|||||||
|
/**
|
||||||
|
* @file dll/posix.c
|
||||||
|
* POSIX Interop.
|
||||||
|
*
|
||||||
|
* This file provides routines for Windows/POSIX interoperability. It is based
|
||||||
|
* on "Services for UNIX" and Cygwin. See the following documents:
|
||||||
|
*
|
||||||
|
* [PERMS]
|
||||||
|
* https://technet.microsoft.com/en-us/library/bb463216.aspx
|
||||||
|
* [WKSID]
|
||||||
|
* https://support.microsoft.com/en-us/kb/243330
|
||||||
|
* [IDMAP]
|
||||||
|
* https://cygwin.com/cygwin-ug-net/ntsec.html
|
||||||
|
* [SNAME]
|
||||||
|
* https://www.cygwin.com/cygwin-ug-net/using-specialnames.html
|
||||||
|
*
|
||||||
|
* @copyright 2015-2016 Bill Zissimopoulos
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* This file is part of WinFsp.
|
||||||
|
*
|
||||||
|
* You can redistribute it and/or modify it under the terms of the
|
||||||
|
* GNU Affero General Public License version 3 as published by the
|
||||||
|
* Free Software Foundation.
|
||||||
|
*
|
||||||
|
* Licensees holding a valid commercial license may use this file in
|
||||||
|
* accordance with the commercial license agreement provided with the
|
||||||
|
* software.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <dll/library.h>
|
||||||
|
#include <aclapi.h>
|
||||||
|
#define _NTDEF_
|
||||||
|
#include <ntsecapi.h>
|
||||||
|
|
||||||
|
static PISID FspPosixCreateSid(BYTE Authority, ULONG Count, ...);
|
||||||
|
|
||||||
|
static INIT_ONCE FspPosixInitOnce = INIT_ONCE_STATIC_INIT;
|
||||||
|
union
|
||||||
|
{
|
||||||
|
SID V;
|
||||||
|
UINT8 B[sizeof(SID) - sizeof(DWORD) + (1 * sizeof(DWORD))];
|
||||||
|
} FspUnmappedSidBuf =
|
||||||
|
{
|
||||||
|
/* S-1-0-65534 */
|
||||||
|
.V.Revision = SID_REVISION,
|
||||||
|
.V.SubAuthorityCount = 1,
|
||||||
|
.V.IdentifierAuthority.Value[5] = 0,
|
||||||
|
.V.SubAuthority[0] = 65534,
|
||||||
|
};
|
||||||
|
static PISID FspAccountDomainSid, FspPrimaryDomainSid;
|
||||||
|
|
||||||
|
#define FspUnmappedSid (&FspUnmappedSidBuf.V)
|
||||||
|
#define FspUnmappedUid (65534)
|
||||||
|
|
||||||
|
static BOOL WINAPI FspPosixInitialize(
|
||||||
|
PINIT_ONCE InitOnce, PVOID Parameter, PVOID *Context)
|
||||||
|
{
|
||||||
|
static LSA_OBJECT_ATTRIBUTES Obja;
|
||||||
|
LSA_HANDLE PolicyHandle = 0;
|
||||||
|
PPOLICY_ACCOUNT_DOMAIN_INFO AccountDomainInfo = 0;
|
||||||
|
PPOLICY_DNS_DOMAIN_INFO PrimaryDomainInfo = 0;
|
||||||
|
BYTE Count;
|
||||||
|
ULONG Size;
|
||||||
|
NTSTATUS Result;
|
||||||
|
|
||||||
|
Result = LsaOpenPolicy(0, &Obja, POLICY_VIEW_LOCAL_INFORMATION, &PolicyHandle);
|
||||||
|
if (!NT_SUCCESS(Result))
|
||||||
|
goto exit;
|
||||||
|
|
||||||
|
Result = LsaQueryInformationPolicy(PolicyHandle, PolicyAccountDomainInformation,
|
||||||
|
&AccountDomainInfo);
|
||||||
|
if (NT_SUCCESS(Result) && 0 != AccountDomainInfo && 0 != AccountDomainInfo->DomainSid)
|
||||||
|
{
|
||||||
|
Count = *GetSidSubAuthorityCount(AccountDomainInfo->DomainSid);
|
||||||
|
Size = sizeof(SID) - sizeof(DWORD) + (Count * sizeof(DWORD));
|
||||||
|
FspAccountDomainSid = MemAlloc(Size);
|
||||||
|
if (0 != FspAccountDomainSid)
|
||||||
|
memcpy(FspAccountDomainSid, AccountDomainInfo->DomainSid, Size);
|
||||||
|
}
|
||||||
|
|
||||||
|
Result = LsaQueryInformationPolicy(PolicyHandle, PolicyDnsDomainInformation,
|
||||||
|
&PrimaryDomainInfo);
|
||||||
|
if (NT_SUCCESS(Result) && 0 != PrimaryDomainInfo && 0 != PrimaryDomainInfo->Sid)
|
||||||
|
{
|
||||||
|
Count = *GetSidSubAuthorityCount(PrimaryDomainInfo->Sid);
|
||||||
|
Size = sizeof(SID) - sizeof(DWORD) + (Count * sizeof(DWORD));
|
||||||
|
FspPrimaryDomainSid = MemAlloc(Size);
|
||||||
|
if (0 != FspPrimaryDomainSid)
|
||||||
|
memcpy(FspPrimaryDomainSid, PrimaryDomainInfo->Sid, Size);
|
||||||
|
}
|
||||||
|
|
||||||
|
exit:
|
||||||
|
if (0 != PrimaryDomainInfo)
|
||||||
|
LsaFreeMemory(PrimaryDomainInfo);
|
||||||
|
|
||||||
|
if (0 != AccountDomainInfo)
|
||||||
|
LsaFreeMemory(AccountDomainInfo);
|
||||||
|
|
||||||
|
if (0 != PolicyHandle)
|
||||||
|
LsaClose(PolicyHandle);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID FspPosixFinalize(BOOLEAN Dynamic)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* This function is called during DLL_PROCESS_DETACH. We must therefore keep
|
||||||
|
* finalization tasks to a minimum.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (Dynamic)
|
||||||
|
{
|
||||||
|
MemFree(FspAccountDomainSid);
|
||||||
|
MemFree(FspPrimaryDomainSid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FSP_API NTSTATUS FspPosixMapUidToSid(UINT32 Uid, PSID *PSid)
|
||||||
|
{
|
||||||
|
InitOnceExecuteOnce(&FspPosixInitOnce, FspPosixInitialize, 0, 0);
|
||||||
|
|
||||||
|
*PSid = 0;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* UID namespace partitioning (from [IDMAP] rules):
|
||||||
|
*
|
||||||
|
* 0x000000 + RID S-1-5-RID,S-1-5-32-RID
|
||||||
|
* 0x000ffe OtherSession
|
||||||
|
* 0x000fff CurrentSession
|
||||||
|
* 0x001000 * X + RID S-1-5-X-RID ([WKSID]: X=1-15,17-21,32,64,80,83)
|
||||||
|
* 0x010000 + 0x100 * X + Y S-1-X-Y ([WKSID]: X=1,2,3,4,5,9,16)
|
||||||
|
* 0x030000 + RID S-1-5-21-X-Y-Z-RID
|
||||||
|
* 0x060000 + RID S-1-16-RID
|
||||||
|
* 0x100000 + RID S-1-5-21-X-Y-Z-RID
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* [IDMAP]
|
||||||
|
* Well-known SIDs in the NT_AUTHORITY domain of the S-1-5-RID type,
|
||||||
|
* or aliases of the S-1-5-32-RID type are mapped to the uid/gid value RID.
|
||||||
|
* Examples:
|
||||||
|
* "SYSTEM" S-1-5-18 <=> uid/gid: 18
|
||||||
|
* "Users" S-1-5-32-545 <=> uid/gid: 545
|
||||||
|
*/
|
||||||
|
if (0x200 > Uid || 1000 == Uid)
|
||||||
|
*PSid = FspPosixCreateSid(5, 1, Uid);
|
||||||
|
else if (1000 > Uid)
|
||||||
|
*PSid = FspPosixCreateSid(5, 2, 32, Uid);
|
||||||
|
|
||||||
|
/* [IDMAP]
|
||||||
|
* Logon SIDs: The LogonSid of the current user's session is converted
|
||||||
|
* to the fixed uid 0xfff == 4095 and named "CurrentSession". Any other
|
||||||
|
* LogonSid is converted to the fixed uid 0xffe == 4094 and named
|
||||||
|
* "OtherSession".
|
||||||
|
*/
|
||||||
|
else if (0xfff == Uid || 0xffe == Uid)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Actually we do not support Logon SID's for translation.
|
||||||
|
* We need an access token to find its Logon SID and we do not have one.
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
/* [IDMAP]
|
||||||
|
* Accounts from the local machine's user DB (SAM):
|
||||||
|
* S-1-5-21-X-Y-Z-RID <=> uid/gid: 0x30000 + RID
|
||||||
|
*
|
||||||
|
* Accounts from the machine's primary domain:
|
||||||
|
* S-1-5-21-X-Y-Z-RID <=> uid/gid: 0x100000 + RID
|
||||||
|
*
|
||||||
|
* Accounts from a trusted domain of the machine's primary domain:
|
||||||
|
* S-1-5-21-X-Y-Z-RID <=> uid/gid: trustPosixOffset(domain) + RID
|
||||||
|
*/
|
||||||
|
else if (0x30000 <= Uid && Uid < 0x40000)
|
||||||
|
{
|
||||||
|
if (0 != FspAccountDomainSid &&
|
||||||
|
5 == FspAccountDomainSid->IdentifierAuthority.Value[5] &&
|
||||||
|
4 == FspAccountDomainSid->SubAuthorityCount)
|
||||||
|
{
|
||||||
|
*PSid = FspPosixCreateSid(5, 5,
|
||||||
|
21,
|
||||||
|
FspAccountDomainSid->SubAuthority[1],
|
||||||
|
FspAccountDomainSid->SubAuthority[2],
|
||||||
|
FspAccountDomainSid->SubAuthority[3],
|
||||||
|
Uid - 0x30000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (0x100000 <= Uid && Uid < 0x200000)
|
||||||
|
{
|
||||||
|
if (0 != FspPrimaryDomainSid &&
|
||||||
|
5 == FspPrimaryDomainSid->IdentifierAuthority.Value[5] &&
|
||||||
|
4 == FspPrimaryDomainSid->SubAuthorityCount)
|
||||||
|
{
|
||||||
|
*PSid = FspPosixCreateSid(5, 5,
|
||||||
|
21,
|
||||||
|
FspPrimaryDomainSid->SubAuthority[1],
|
||||||
|
FspPrimaryDomainSid->SubAuthority[2],
|
||||||
|
FspPrimaryDomainSid->SubAuthority[3],
|
||||||
|
Uid - 0x100000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* I am sorry, I am not going to bother with all that trustPosixOffset stuff.
|
||||||
|
* But if you need it, I accept patches :)
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* [IDMAP]
|
||||||
|
* Mandatory Labels:
|
||||||
|
* S-1-16-RID <=> uid/gid: 0x60000 + RID
|
||||||
|
*/
|
||||||
|
else if (0x60000 <= Uid && Uid < 0x70000)
|
||||||
|
*PSid = FspPosixCreateSid(16, 1, Uid - 0x60000);
|
||||||
|
|
||||||
|
/* [IDMAP]
|
||||||
|
* Other well-known SIDs:
|
||||||
|
* S-1-X-Y <=> uid/gid: 0x10000 + 0x100 * X + Y
|
||||||
|
*/
|
||||||
|
else if (0x10000 <= Uid && Uid < 0x11000)
|
||||||
|
*PSid = FspPosixCreateSid((Uid - 0x10000) >> 8, 1, (Uid - 0x10000) & 0xff);
|
||||||
|
|
||||||
|
/* [IDMAP]
|
||||||
|
* Other well-known SIDs in the NT_AUTHORITY domain (S-1-5-X-RID):
|
||||||
|
* S-1-5-X-RID <=> uid/gid: 0x1000 * X + RID
|
||||||
|
*/
|
||||||
|
else if (FspUnmappedUid != Uid && 0x1000 <= Uid && Uid < 0x100000)
|
||||||
|
*PSid = FspPosixCreateSid(5, 2, Uid >> 12, Uid & 0xfff);
|
||||||
|
|
||||||
|
if (0 == *PSid)
|
||||||
|
*PSid = FspUnmappedSid;
|
||||||
|
|
||||||
|
return STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
FSP_API NTSTATUS FspPosixMapSidToUid(PSID Sid, PUINT32 PUid)
|
||||||
|
{
|
||||||
|
InitOnceExecuteOnce(&FspPosixInitOnce, FspPosixInitialize, 0, 0);
|
||||||
|
|
||||||
|
BYTE Authority;
|
||||||
|
BYTE Count;
|
||||||
|
UINT32 SubAuthority0, Rid;
|
||||||
|
|
||||||
|
*PUid = -1;
|
||||||
|
|
||||||
|
if (!IsValidSid(Sid) || 0 == (Count = *GetSidSubAuthorityCount(Sid)))
|
||||||
|
return STATUS_INVALID_SID;
|
||||||
|
|
||||||
|
Authority = GetSidIdentifierAuthority(Sid)->Value[5];
|
||||||
|
SubAuthority0 = 2 <= Count ? *GetSidSubAuthority(Sid, 0) : 0;
|
||||||
|
Rid = *GetSidSubAuthority(Sid, Count - 1);
|
||||||
|
|
||||||
|
if (5 == Authority)
|
||||||
|
{
|
||||||
|
/* [IDMAP]
|
||||||
|
* Well-known SIDs in the NT_AUTHORITY domain of the S-1-5-RID type,
|
||||||
|
* or aliases of the S-1-5-32-RID type are mapped to the uid/gid value RID.
|
||||||
|
* Examples:
|
||||||
|
* "SYSTEM" S-1-5-18 <=> uid/gid: 18
|
||||||
|
* "Users" S-1-5-32-545 <=> uid/gid: 545
|
||||||
|
*/
|
||||||
|
if (1 == Count)
|
||||||
|
*PUid = Rid;
|
||||||
|
else if (2 == Count && 32 == SubAuthority0)
|
||||||
|
*PUid = Rid;
|
||||||
|
|
||||||
|
/* [IDMAP]
|
||||||
|
* Logon SIDs: The LogonSid of the current user's session is converted
|
||||||
|
* to the fixed uid 0xfff == 4095 and named "CurrentSession". Any other
|
||||||
|
* LogonSid is converted to the fixed uid 0xffe == 4094 and named
|
||||||
|
* "OtherSession".
|
||||||
|
*/
|
||||||
|
else if (2 <= Count && 5 == SubAuthority0)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Actually we do not support Logon SID's for translation.
|
||||||
|
* We need an access token to find its Logon SID and we do not have one.
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
/* [IDMAP]
|
||||||
|
* Accounts from the local machine's user DB (SAM):
|
||||||
|
* S-1-5-21-X-Y-Z-RID <=> uid/gid: 0x30000 + RID
|
||||||
|
*
|
||||||
|
* Accounts from the machine's primary domain:
|
||||||
|
* S-1-5-21-X-Y-Z-RID <=> uid/gid: 0x100000 + RID
|
||||||
|
*
|
||||||
|
* Accounts from a trusted domain of the machine's primary domain:
|
||||||
|
* S-1-5-21-X-Y-Z-RID <=> uid/gid: trustPosixOffset(domain) + RID
|
||||||
|
*/
|
||||||
|
else if (5 <= Count && 21 == SubAuthority0)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* The order is important! A server that is also a domain controller
|
||||||
|
* has PrimaryDomainSid == AccountDomainSid.
|
||||||
|
*/
|
||||||
|
|
||||||
|
BOOL EqualDomains = FALSE;
|
||||||
|
if (0 != FspPrimaryDomainSid &&
|
||||||
|
EqualDomainSid(FspPrimaryDomainSid, Sid, &EqualDomains) && EqualDomains)
|
||||||
|
*PUid = 0x100000 + Rid;
|
||||||
|
else if (0 != FspAccountDomainSid &&
|
||||||
|
EqualDomainSid(FspAccountDomainSid, Sid, &EqualDomains) && EqualDomains)
|
||||||
|
*PUid = 0x30000 + Rid;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* I am sorry, I am not going to bother with all that trustPosixOffset stuff.
|
||||||
|
* But if you need it, I accept patches :)
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
/* [IDMAP]
|
||||||
|
* Other well-known SIDs in the NT_AUTHORITY domain (S-1-5-X-RID):
|
||||||
|
* S-1-5-X-RID <=> uid/gid: 0x1000 * X + RID
|
||||||
|
*/
|
||||||
|
else if (2 == Count)
|
||||||
|
{
|
||||||
|
*PUid = 0x1000 * SubAuthority0 + Rid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (16 == Authority)
|
||||||
|
{
|
||||||
|
/* [IDMAP]
|
||||||
|
* Mandatory Labels:
|
||||||
|
* S-1-16-RID <=> uid/gid: 0x60000 + RID
|
||||||
|
*/
|
||||||
|
*PUid = 0x60000 + Rid;
|
||||||
|
}
|
||||||
|
else if (
|
||||||
|
FspUnmappedSid->IdentifierAuthority.Value[5] != Authority ||
|
||||||
|
FspUnmappedSid->SubAuthority[0] != Rid)
|
||||||
|
{
|
||||||
|
/* [IDMAP]
|
||||||
|
* Other well-known SIDs:
|
||||||
|
* S-1-X-Y <=> uid/gid: 0x10000 + 0x100 * X + Y
|
||||||
|
*/
|
||||||
|
*PUid = 0x10000 + 0x100 * Authority + Rid;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (-1 == *PUid)
|
||||||
|
*PUid = FspUnmappedUid;
|
||||||
|
|
||||||
|
return STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PISID FspPosixCreateSid(BYTE Authority, ULONG Count, ...)
|
||||||
|
{
|
||||||
|
PISID Sid;
|
||||||
|
SID_IDENTIFIER_AUTHORITY IdentifierAuthority;
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
Sid = MemAlloc(sizeof(SID) - sizeof(DWORD) + (Count * sizeof(DWORD)));
|
||||||
|
if (0 == Sid)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
memset(&IdentifierAuthority, 0, sizeof IdentifierAuthority);
|
||||||
|
IdentifierAuthority.Value[5] = Authority;
|
||||||
|
|
||||||
|
InitializeSid(Sid, &IdentifierAuthority, (BYTE)Count);
|
||||||
|
va_start(ap, Count);
|
||||||
|
for (ULONG Index = 0; Count > Index; Index++)
|
||||||
|
Sid->SubAuthority[Index] = va_arg(ap, DWORD);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
return Sid;
|
||||||
|
}
|
||||||
|
|
||||||
|
FSP_API VOID FspDeleteSid(PSID Sid, NTSTATUS (*CreateFunc)())
|
||||||
|
{
|
||||||
|
if (FspUnmappedSid == Sid)
|
||||||
|
;
|
||||||
|
else if ((NTSTATUS (*)())FspPosixMapUidToSid == CreateFunc)
|
||||||
|
MemFree(Sid);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* [PERMS]
|
||||||
|
* By default, all access-allowed ACEs will contain the following Windows access rights.
|
||||||
|
*/
|
||||||
|
#define FspPosixDefaultPerm \
|
||||||
|
(SYNCHRONIZE | READ_CONTROL | FILE_READ_ATTRIBUTES | FILE_READ_EA)
|
||||||
|
/* [PERMS]
|
||||||
|
* There are some additional Windows access rights that are always set in the
|
||||||
|
* access-allowed ACE for the file's owner.
|
||||||
|
*/
|
||||||
|
#define FspPosixOwnerDefaultPerm \
|
||||||
|
(FspPosixDefaultPerm | DELETE | WRITE_DAC | WRITE_OWNER | FILE_WRITE_ATTRIBUTES | FILE_WRITE_EA)
|
||||||
|
|
||||||
|
static inline ACCESS_MASK FspPosixMapPermissionToAccessMask(UINT32 Mode, UINT32 Perm)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* We use only the 0040000 (directory) and 0001000 (sticky) bits from Mode.
|
||||||
|
* If this is a directory and it does not have the sticky bit set (and the
|
||||||
|
* write permission is enabled) we add FILE_DELETE_CHILD access.
|
||||||
|
*
|
||||||
|
* When calling this function for computing the Owner access mask, we always
|
||||||
|
* pass Mode & ~0001000 to remove the sticky bit and thus add FILE_DELETE_CHILD
|
||||||
|
* access if it is a directory. For Group and World permissions we do not
|
||||||
|
* remove the sticky bit as we do not want FILE_DELETE_CHILD access in these
|
||||||
|
* cases.
|
||||||
|
*/
|
||||||
|
|
||||||
|
ACCESS_MASK DeleteChild = 0040000 == (Mode & 0041000) ? FILE_DELETE_CHILD : 0;
|
||||||
|
|
||||||
|
/* [PERMS]
|
||||||
|
* Additionally, if the UNIX read permission bit is set, then the Windows
|
||||||
|
* File_Read access right is added to the ACE. When enabled on directories,
|
||||||
|
* this allows them to be searched. When enabled on files, it allows the data
|
||||||
|
* to be viewed. If the UNIX execute permission bit is set, then the Windows
|
||||||
|
* File_Execute access right is added to the ACE. On directories this enables
|
||||||
|
* the directory to be traversed. On files it allows the file to be executed.
|
||||||
|
*
|
||||||
|
* If the UNIX write permission bit is set then the following Windows access
|
||||||
|
* rights are added: Write_Data, Write_Attributes, Append_Data, Delete_Child.
|
||||||
|
*
|
||||||
|
* Notice how Windows has four separate access rights to UNIX's single "write"
|
||||||
|
* permission. In UNIX, the write permission bit on a directory permits both
|
||||||
|
* the creation and removal of new files or sub-directories in the directory.
|
||||||
|
* On Windows, the Write_Data access right controls the creation of new
|
||||||
|
* sub-files and the Delete_Child access right controls the deletion. The
|
||||||
|
* Delete_Child access right is not always present in all ACEs. In the case
|
||||||
|
* where the UNIX sticky-bit is enabled, the Delete_Child bit will be set only
|
||||||
|
* in the file owner ACE and no other ACEs. This will permit only the directory
|
||||||
|
* owner to remove any files or sub-directories from this directory regardless
|
||||||
|
* of the ownership on these sub-files. Other users will be allowed to delete
|
||||||
|
* files or sub-directories only if they are granted the Delete access right
|
||||||
|
* in an ACE of the file or sub-directory itself.
|
||||||
|
*/
|
||||||
|
|
||||||
|
return
|
||||||
|
((Perm & 4) ? FILE_READ_DATA : 0) |
|
||||||
|
((Perm & 2) ? FILE_WRITE_ATTRIBUTES | FILE_WRITE_DATA | FILE_APPEND_DATA | DeleteChild : 0) |
|
||||||
|
((Perm & 1) ? FILE_EXECUTE : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
FSP_API NTSTATUS FspPosixMapPermissionsToSecurityDescriptor(
|
||||||
|
UINT32 Uid, UINT32 Gid, UINT32 Mode,
|
||||||
|
PSECURITY_DESCRIPTOR *PSecurityDescriptor)
|
||||||
|
{
|
||||||
|
PSID OwnerSid = 0, GroupSid = 0, WorldSid = 0;
|
||||||
|
UINT32 OwnerPerm, OwnerDeny, GroupPerm, GroupDeny, WorldPerm;
|
||||||
|
PACL Acl = 0;
|
||||||
|
SECURITY_DESCRIPTOR SecurityDescriptor;
|
||||||
|
PSECURITY_DESCRIPTOR RelativeSecurityDescriptor = 0;
|
||||||
|
ULONG Size;
|
||||||
|
NTSTATUS Result;
|
||||||
|
|
||||||
|
*PSecurityDescriptor = 0;
|
||||||
|
|
||||||
|
Result = FspPosixMapUidToSid(Uid, &OwnerSid);
|
||||||
|
if (!NT_SUCCESS(Result))
|
||||||
|
goto exit;
|
||||||
|
|
||||||
|
Result = FspPosixMapUidToSid(Gid, &GroupSid);
|
||||||
|
if (!NT_SUCCESS(Result))
|
||||||
|
goto exit;
|
||||||
|
|
||||||
|
Result = FspPosixMapUidToSid(0x10100, &WorldSid);
|
||||||
|
if (!NT_SUCCESS(Result))
|
||||||
|
goto exit;
|
||||||
|
|
||||||
|
OwnerPerm = (Mode & 0700) >> 6;
|
||||||
|
GroupPerm = (Mode & 0070) >> 3;
|
||||||
|
WorldPerm = (Mode & 0007);
|
||||||
|
|
||||||
|
/* [PERMS]
|
||||||
|
* What about the case where both owner and group are the same SID and
|
||||||
|
* a chmod(1) request is made where the owner and the group permission
|
||||||
|
* bits are different?. In this case, the most restrictive permissions
|
||||||
|
* are chosen and assigned to both ACEs.
|
||||||
|
*/
|
||||||
|
if (EqualSid(OwnerSid, GroupSid))
|
||||||
|
OwnerPerm = GroupPerm = OwnerPerm & GroupPerm;
|
||||||
|
|
||||||
|
/* [PERMS]
|
||||||
|
* There are situations where one or two access-denied ACEs must be added
|
||||||
|
* to the DACL. If you recall, the UNIX file access algorithm makes a
|
||||||
|
* distinction between owner, group and other such that each is unique
|
||||||
|
* and the ID used in an access request can only match one of them.
|
||||||
|
* However, the Windows file access algorithm makes no such distinction
|
||||||
|
* while scanning the DACL. If the ID in the request is granted permission
|
||||||
|
* in any of the access-allowed ACEs then the request is permitted. This
|
||||||
|
* is a problem when the owner permissions are specified to be more
|
||||||
|
* restrictive than say the group or the other permissions (eg. when a
|
||||||
|
* "chmod 577 foobar" is executed) So, to support UNIX semantics we must
|
||||||
|
* examine the permissions granted to Everyone and if they are more
|
||||||
|
* permissive than those in the group permissions then a special
|
||||||
|
* access-denied ACE must be created for the group. And similarly, if
|
||||||
|
* either the group or other permissions are more permissive than the
|
||||||
|
* owner permissions, then an access-denied ACE must be created for the owner.
|
||||||
|
*/
|
||||||
|
OwnerDeny = (OwnerPerm ^ GroupPerm) & GroupPerm;
|
||||||
|
OwnerDeny |= (OwnerPerm ^ WorldPerm) & WorldPerm;
|
||||||
|
GroupDeny = (GroupPerm ^ WorldPerm) & WorldPerm;
|
||||||
|
|
||||||
|
Size = sizeof(ACL) + sizeof(ACCESS_ALLOWED_ACE) * 3 +
|
||||||
|
sizeof(ACCESS_DENIED_ACE) * (!!OwnerDeny + !!GroupDeny);
|
||||||
|
Size += GetLengthSid(OwnerSid) - sizeof(DWORD);
|
||||||
|
Size += GetLengthSid(GroupSid) - sizeof(DWORD);
|
||||||
|
Size += GetLengthSid(WorldSid) - sizeof(DWORD);
|
||||||
|
if (OwnerDeny)
|
||||||
|
Size += GetLengthSid(OwnerSid) - sizeof(DWORD);
|
||||||
|
if (GroupDeny)
|
||||||
|
Size += GetLengthSid(GroupSid) - sizeof(DWORD);
|
||||||
|
Size += sizeof(DWORD) - 1;
|
||||||
|
Size &= ~(sizeof(DWORD) - 1);
|
||||||
|
|
||||||
|
Acl = MemAlloc(Size);
|
||||||
|
if (0 == Acl)
|
||||||
|
{
|
||||||
|
Result = STATUS_INSUFFICIENT_RESOURCES;
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!InitializeAcl(Acl, Size, ACL_REVISION))
|
||||||
|
goto lasterror;
|
||||||
|
|
||||||
|
if (!AddAccessAllowedAce(Acl, ACL_REVISION,
|
||||||
|
FspPosixOwnerDefaultPerm | FspPosixMapPermissionToAccessMask(Mode & ~001000, OwnerPerm),
|
||||||
|
OwnerSid))
|
||||||
|
goto lasterror;
|
||||||
|
if (OwnerDeny)
|
||||||
|
{
|
||||||
|
if (!AddAccessDeniedAce(Acl, ACL_REVISION,
|
||||||
|
~FILE_WRITE_ATTRIBUTES & FspPosixMapPermissionToAccessMask(Mode & ~001000, OwnerDeny),
|
||||||
|
OwnerSid))
|
||||||
|
goto lasterror;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!AddAccessAllowedAce(Acl, ACL_REVISION,
|
||||||
|
FspPosixDefaultPerm | FspPosixMapPermissionToAccessMask(Mode, GroupPerm),
|
||||||
|
GroupSid))
|
||||||
|
goto lasterror;
|
||||||
|
if (GroupDeny)
|
||||||
|
{
|
||||||
|
if (!AddAccessDeniedAce(Acl, ACL_REVISION,
|
||||||
|
FspPosixMapPermissionToAccessMask(Mode, GroupDeny),
|
||||||
|
GroupSid))
|
||||||
|
goto lasterror;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!AddAccessAllowedAce(Acl, ACL_REVISION,
|
||||||
|
FspPosixDefaultPerm | FspPosixMapPermissionToAccessMask(Mode, WorldPerm),
|
||||||
|
WorldSid))
|
||||||
|
goto lasterror;
|
||||||
|
|
||||||
|
if (!InitializeSecurityDescriptor(&SecurityDescriptor, SECURITY_DESCRIPTOR_REVISION))
|
||||||
|
goto lasterror;
|
||||||
|
|
||||||
|
if (!SetSecurityDescriptorControl(&SecurityDescriptor, SE_DACL_PROTECTED, SE_DACL_PROTECTED))
|
||||||
|
goto lasterror;
|
||||||
|
if (!SetSecurityDescriptorOwner(&SecurityDescriptor, OwnerSid, FALSE))
|
||||||
|
goto lasterror;
|
||||||
|
if (!SetSecurityDescriptorGroup(&SecurityDescriptor, GroupSid, FALSE))
|
||||||
|
goto lasterror;
|
||||||
|
if (!SetSecurityDescriptorDacl(&SecurityDescriptor, TRUE, Acl, FALSE))
|
||||||
|
goto lasterror;
|
||||||
|
|
||||||
|
Size = 0;
|
||||||
|
if (!MakeSelfRelativeSD(&SecurityDescriptor, 0, &Size) &&
|
||||||
|
ERROR_INSUFFICIENT_BUFFER != GetLastError())
|
||||||
|
goto lasterror;
|
||||||
|
|
||||||
|
RelativeSecurityDescriptor = MemAlloc(Size);
|
||||||
|
if (0 == RelativeSecurityDescriptor)
|
||||||
|
{
|
||||||
|
Result = STATUS_INSUFFICIENT_RESOURCES;
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!MakeSelfRelativeSD(&SecurityDescriptor, RelativeSecurityDescriptor, &Size))
|
||||||
|
goto lasterror;
|
||||||
|
|
||||||
|
*PSecurityDescriptor = RelativeSecurityDescriptor;
|
||||||
|
|
||||||
|
Result = STATUS_SUCCESS;
|
||||||
|
|
||||||
|
exit:
|
||||||
|
if (!NT_SUCCESS(Result))
|
||||||
|
MemFree(RelativeSecurityDescriptor);
|
||||||
|
|
||||||
|
MemFree(Acl);
|
||||||
|
|
||||||
|
if (0 != WorldSid)
|
||||||
|
FspDeleteSid(WorldSid, FspPosixMapUidToSid);
|
||||||
|
|
||||||
|
if (0 != GroupSid)
|
||||||
|
FspDeleteSid(GroupSid, FspPosixMapUidToSid);
|
||||||
|
|
||||||
|
if (0 != OwnerSid)
|
||||||
|
FspDeleteSid(OwnerSid, FspPosixMapUidToSid);
|
||||||
|
|
||||||
|
return Result;
|
||||||
|
|
||||||
|
lasterror:
|
||||||
|
Result = FspNtStatusFromWin32(GetLastError());
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline UINT32 FspPosixMapAccessMaskToPermission(ACCESS_MASK AccessMask)
|
||||||
|
{
|
||||||
|
/* [PERMS]
|
||||||
|
* Once all the granted Windows access right bits have been collected,
|
||||||
|
* then the UNIX permission bits are assembled. For each class, if the
|
||||||
|
* Read_Data bit is granted, then the corresponding "r" permission bit
|
||||||
|
* is set. If both the Write_Data and Append_Data access rights are
|
||||||
|
* granted then the "w" permission bit is set. And finally, if the
|
||||||
|
* Execute access right is granted, then the "x" permission bit is set.
|
||||||
|
*/
|
||||||
|
|
||||||
|
return
|
||||||
|
((AccessMask & FILE_READ_DATA) ? 4 : 0) |
|
||||||
|
((FILE_WRITE_DATA | FILE_APPEND_DATA) ==
|
||||||
|
(AccessMask & (FILE_WRITE_DATA | FILE_APPEND_DATA)) ? 2 : 0) |
|
||||||
|
((AccessMask & FILE_EXECUTE) ? 1 : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
FSP_API NTSTATUS FspPosixMapSecurityDescriptorToPermissions(
|
||||||
|
PSECURITY_DESCRIPTOR SecurityDescriptor,
|
||||||
|
PUINT32 PUid, PUINT32 PGid, PUINT32 PMode)
|
||||||
|
{
|
||||||
|
PSID OwnerSid = 0, GroupSid = 0, WorldSid = 0, AuthUsersSid = 0;
|
||||||
|
BOOL Defaulted, DaclPresent;
|
||||||
|
PACL Acl = 0;
|
||||||
|
ACL_SIZE_INFORMATION AclSizeInfo;
|
||||||
|
PACE_HEADER Ace;
|
||||||
|
PSID AceSid;
|
||||||
|
DWORD AceAccessMask;
|
||||||
|
DWORD OwnerAllow, OwnerDeny, GroupAllow, GroupDeny, WorldAllow, WorldDeny;
|
||||||
|
UINT32 Uid, Gid, Mode;
|
||||||
|
NTSTATUS Result;
|
||||||
|
|
||||||
|
*PUid = 0;
|
||||||
|
*PGid = 0;
|
||||||
|
*PMode = 0;
|
||||||
|
|
||||||
|
if (!GetSecurityDescriptorOwner(SecurityDescriptor, &OwnerSid, &Defaulted))
|
||||||
|
goto lasterror;
|
||||||
|
if (!GetSecurityDescriptorGroup(SecurityDescriptor, &GroupSid, &Defaulted))
|
||||||
|
goto lasterror;
|
||||||
|
if (!GetSecurityDescriptorDacl(SecurityDescriptor, &DaclPresent, &Acl, &Defaulted))
|
||||||
|
goto lasterror;
|
||||||
|
|
||||||
|
Result = FspPosixMapSidToUid(OwnerSid, &Uid);
|
||||||
|
if (!NT_SUCCESS(Result))
|
||||||
|
goto exit;
|
||||||
|
|
||||||
|
Result = FspPosixMapSidToUid(GroupSid, &Gid);
|
||||||
|
if (!NT_SUCCESS(Result))
|
||||||
|
goto exit;
|
||||||
|
|
||||||
|
if (0 != Acl)
|
||||||
|
{
|
||||||
|
Result = FspPosixMapUidToSid(0x10100, &WorldSid);
|
||||||
|
if (!NT_SUCCESS(Result))
|
||||||
|
goto exit;
|
||||||
|
|
||||||
|
Result = FspPosixMapUidToSid(11, &AuthUsersSid);
|
||||||
|
if (!NT_SUCCESS(Result))
|
||||||
|
goto exit;
|
||||||
|
|
||||||
|
OwnerAllow = OwnerDeny = GroupAllow = GroupDeny = WorldAllow = WorldDeny = 0;
|
||||||
|
|
||||||
|
if (!GetAclInformation(Acl, &AclSizeInfo, sizeof AclSizeInfo, AclSizeInformation))
|
||||||
|
goto lasterror;
|
||||||
|
|
||||||
|
/* [PERMS]
|
||||||
|
* For each of the ACEs in the file's DACL
|
||||||
|
*/
|
||||||
|
for (ULONG Index = 0; AclSizeInfo.AceCount > Index; Index++)
|
||||||
|
{
|
||||||
|
if (!GetAce(Acl, Index, &Ace))
|
||||||
|
goto lasterror;
|
||||||
|
|
||||||
|
/* [PERMS]
|
||||||
|
* Ignore the ACE if it is not an access-denied or access-allowed type.
|
||||||
|
*/
|
||||||
|
if (ACCESS_ALLOWED_ACE_TYPE == Ace->AceType)
|
||||||
|
{
|
||||||
|
AceSid = &((PACCESS_ALLOWED_ACE)Ace)->SidStart;
|
||||||
|
AceAccessMask = ((PACCESS_ALLOWED_ACE)Ace)->Mask;
|
||||||
|
}
|
||||||
|
else if (ACCESS_DENIED_ACE_TYPE == Ace->AceType)
|
||||||
|
{
|
||||||
|
AceSid = &((PACCESS_DENIED_ACE)Ace)->SidStart;
|
||||||
|
AceAccessMask = ((PACCESS_DENIED_ACE)Ace)->Mask;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
continue;
|
||||||
|
|
||||||
|
/* [PERMS]
|
||||||
|
* If the ACE contains the Authenticated Users SID or the World SID then
|
||||||
|
* add the allowed or denied access right bits into the "owner", "group"
|
||||||
|
* and "other" collections.
|
||||||
|
*/
|
||||||
|
if (EqualSid(WorldSid, AceSid) || EqualSid(AuthUsersSid, AceSid))
|
||||||
|
{
|
||||||
|
/* [PERMS]
|
||||||
|
* If this is an access-denied ACE, then add each access right to the set
|
||||||
|
* of denied rights in each collection but only if the access right is not
|
||||||
|
* already present in the set of granted rights in that collection. Similarly
|
||||||
|
* If this is an access-allowed ACE, then add each access right to the set
|
||||||
|
* of granted rights in each collection but only if the access right is not
|
||||||
|
* already present in the set of denied rights in that collection.
|
||||||
|
*/
|
||||||
|
if (ACCESS_ALLOWED_ACE_TYPE == Ace->AceType)
|
||||||
|
{
|
||||||
|
WorldAllow |= AceAccessMask & ~WorldDeny;
|
||||||
|
GroupAllow |= AceAccessMask & ~GroupDeny;
|
||||||
|
OwnerAllow |= AceAccessMask & ~OwnerDeny;
|
||||||
|
}
|
||||||
|
else //if (ACCESS_DENIED_ACE_TYPE == Ace->AceType)
|
||||||
|
{
|
||||||
|
WorldDeny |= AceAccessMask & ~WorldAllow;
|
||||||
|
GroupDeny |= AceAccessMask & ~GroupAllow;
|
||||||
|
OwnerDeny |= AceAccessMask & ~OwnerAllow;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* [PERMS]
|
||||||
|
* Note that if the file owner and file group SIDs are the same,
|
||||||
|
* then the access rights are saved in both the "owner" and "group"
|
||||||
|
* collections.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* [PERMS]
|
||||||
|
* If the ACE contains the file's group SID, then save the access rights
|
||||||
|
* in the "group" collection as appropriate in the corresponding set of
|
||||||
|
* granted or denied rights (as described above).
|
||||||
|
*/
|
||||||
|
if (EqualSid(GroupSid, AceSid))
|
||||||
|
{
|
||||||
|
if (ACCESS_ALLOWED_ACE_TYPE == Ace->AceType)
|
||||||
|
GroupAllow |= AceAccessMask & ~GroupDeny;
|
||||||
|
else //if (ACCESS_DENIED_ACE_TYPE == Ace->AceType)
|
||||||
|
GroupDeny |= AceAccessMask & ~GroupAllow;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* [PERMS]
|
||||||
|
* If the ACE contains the file's owner SID, then save the access rights
|
||||||
|
* in the "owner" collection as appropriate in the corresponding set of
|
||||||
|
* granted or denied rights (as described above).
|
||||||
|
*/
|
||||||
|
if (EqualSid(OwnerSid, AceSid))
|
||||||
|
{
|
||||||
|
if (ACCESS_ALLOWED_ACE_TYPE == Ace->AceType)
|
||||||
|
OwnerAllow |= AceAccessMask & ~OwnerDeny;
|
||||||
|
else //if (ACCESS_DENIED_ACE_TYPE == Ace->AceType)
|
||||||
|
OwnerDeny |= AceAccessMask & ~OwnerAllow;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Mode =
|
||||||
|
(FspPosixMapAccessMaskToPermission(OwnerAllow) << 6) |
|
||||||
|
(FspPosixMapAccessMaskToPermission(GroupAllow) << 3) |
|
||||||
|
(FspPosixMapAccessMaskToPermission(WorldAllow));
|
||||||
|
if (0 != (OwnerAllow & FILE_DELETE_CHILD) &&
|
||||||
|
(
|
||||||
|
(0 == (GroupAllow & FILE_DELETE_CHILD) && 0 != (Mode & 0000020)) ||
|
||||||
|
(0 == (WorldAllow & FILE_DELETE_CHILD) && 0 != (Mode & 0000002))
|
||||||
|
))
|
||||||
|
Mode |= 0001000; /* sticky bit */
|
||||||
|
}
|
||||||
|
else
|
||||||
|
Mode = 0777;
|
||||||
|
|
||||||
|
*PUid = Uid;
|
||||||
|
*PGid = Gid;
|
||||||
|
*PMode = Mode;
|
||||||
|
|
||||||
|
Result = STATUS_SUCCESS;
|
||||||
|
|
||||||
|
exit:
|
||||||
|
if (0 != AuthUsersSid)
|
||||||
|
FspDeleteSid(AuthUsersSid, FspPosixMapUidToSid);
|
||||||
|
|
||||||
|
if (0 != WorldSid)
|
||||||
|
FspDeleteSid(WorldSid, FspPosixMapUidToSid);
|
||||||
|
|
||||||
|
return Result;
|
||||||
|
|
||||||
|
lasterror:
|
||||||
|
Result = FspNtStatusFromWin32(GetLastError());
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Services for Macintosh and Cygwin compatible filename transformation:
|
||||||
|
* Transform characters invalid for Windows filenames to the Unicode
|
||||||
|
* private use area in the U+F0XX range.
|
||||||
|
*
|
||||||
|
* The invalid maps are produced by the following Python script:
|
||||||
|
* reserved = ['<', '>', ':', '"', '\\', '|', '?', '*']
|
||||||
|
* l = [str(int(0 < i < 32 or chr(i) in reserved)) for i in xrange(0, 128)]
|
||||||
|
* print "0x%08x" % int("".join(l[0:32]), 2)
|
||||||
|
* print "0x%08x" % int("".join(l[32:64]), 2)
|
||||||
|
* print "0x%08x" % int("".join(l[64:96]), 2)
|
||||||
|
* print "0x%08x" % int("".join(l[96:128]), 2)
|
||||||
|
*/
|
||||||
|
static UINT32 FspPosixInvalidPathChars[4] =
|
||||||
|
{
|
||||||
|
0x7fffffff,
|
||||||
|
0x2020002b,
|
||||||
|
0x00000008,
|
||||||
|
0x00000008,
|
||||||
|
};
|
||||||
|
|
||||||
|
FSP_API NTSTATUS FspPosixMapWindowsToPosixPath(PWSTR WindowsPath, char **PPosixPath)
|
||||||
|
{
|
||||||
|
NTSTATUS Result;
|
||||||
|
ULONG Size;
|
||||||
|
char *PosixPath = 0, *p, *q;
|
||||||
|
|
||||||
|
*PPosixPath = 0;
|
||||||
|
|
||||||
|
Size = WideCharToMultiByte(CP_UTF8, 0, WindowsPath, -1, 0, 0, 0, 0);
|
||||||
|
if (0 == Size)
|
||||||
|
goto lasterror;
|
||||||
|
|
||||||
|
PosixPath = MemAlloc(Size);
|
||||||
|
if (0 == PosixPath)
|
||||||
|
{
|
||||||
|
Result = STATUS_INSUFFICIENT_RESOURCES;
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
Size = WideCharToMultiByte(CP_UTF8, 0, WindowsPath, -1, PosixPath, Size, 0, 0);
|
||||||
|
if (0 == Size)
|
||||||
|
goto lasterror;
|
||||||
|
|
||||||
|
for (p = PosixPath, q = p; *p; p++)
|
||||||
|
{
|
||||||
|
unsigned char c = *p;
|
||||||
|
|
||||||
|
if ('\\' == c)
|
||||||
|
*q++ = '/';
|
||||||
|
/* encode characters in the Unicode private use area: U+F0XX -> XX */
|
||||||
|
else if (0xef == c && 0x80 == (0xfc & p[1]) && 0x80 == (0xc0 & p[2]))
|
||||||
|
{
|
||||||
|
c = ((p[1] & 0x3) << 6) | (p[2] & 0x3f);
|
||||||
|
if (128 > c && (FspPosixInvalidPathChars[c >> 5] & (0x80000000 >> (c & 0x1f))))
|
||||||
|
*q++ = c, p += 2;
|
||||||
|
else
|
||||||
|
*q++ = *p++, *q++ = *p++, *q++ = *p;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
*q++ = c;
|
||||||
|
}
|
||||||
|
*q = '\0';
|
||||||
|
|
||||||
|
*PPosixPath = PosixPath;
|
||||||
|
|
||||||
|
Result = STATUS_SUCCESS;
|
||||||
|
|
||||||
|
exit:
|
||||||
|
if (!NT_SUCCESS(Result))
|
||||||
|
MemFree(PosixPath);
|
||||||
|
|
||||||
|
return Result;
|
||||||
|
|
||||||
|
lasterror:
|
||||||
|
Result = FspNtStatusFromWin32(GetLastError());
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
FSP_API NTSTATUS FspPosixMapPosixToWindowsPath(const char *PosixPath, PWSTR *PWindowsPath)
|
||||||
|
{
|
||||||
|
NTSTATUS Result;
|
||||||
|
ULONG Size;
|
||||||
|
PWSTR WindowsPath = 0, p;
|
||||||
|
|
||||||
|
*PWindowsPath = 0;
|
||||||
|
|
||||||
|
Size = MultiByteToWideChar(CP_UTF8, 0, PosixPath, -1, 0, 0);
|
||||||
|
if (0 == Size)
|
||||||
|
goto lasterror;
|
||||||
|
|
||||||
|
WindowsPath = MemAlloc(Size * sizeof(WCHAR));
|
||||||
|
if (0 == PosixPath)
|
||||||
|
{
|
||||||
|
Result = STATUS_INSUFFICIENT_RESOURCES;
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
Size = MultiByteToWideChar(CP_UTF8, 0, PosixPath, -1, WindowsPath, Size);
|
||||||
|
if (0 == Size)
|
||||||
|
goto lasterror;
|
||||||
|
|
||||||
|
for (p = WindowsPath; *p; p++)
|
||||||
|
{
|
||||||
|
WCHAR c = *p;
|
||||||
|
|
||||||
|
if (L'/' == c)
|
||||||
|
*p = L'\\';
|
||||||
|
else if (128 > c && (FspPosixInvalidPathChars[c >> 5] & (0x80000000 >> (c & 0x1f))))
|
||||||
|
*p |= 0xf000;
|
||||||
|
}
|
||||||
|
|
||||||
|
*PWindowsPath = WindowsPath;
|
||||||
|
|
||||||
|
Result = STATUS_SUCCESS;
|
||||||
|
|
||||||
|
exit:
|
||||||
|
if (!NT_SUCCESS(Result))
|
||||||
|
MemFree(WindowsPath);
|
||||||
|
|
||||||
|
return Result;
|
||||||
|
|
||||||
|
lasterror:
|
||||||
|
Result = FspNtStatusFromWin32(GetLastError());
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
FSP_API VOID FspPosixDeletePath(void *Path)
|
||||||
|
{
|
||||||
|
MemFree(Path);
|
||||||
|
}
|
@ -61,6 +61,10 @@ FSP_API NTSTATUS FspAccessCheckEx(FSP_FILE_SYSTEM *FileSystem,
|
|||||||
if (FspFsctlTransactCreateKind != Request->Kind)
|
if (FspFsctlTransactCreateKind != Request->Kind)
|
||||||
return STATUS_INVALID_PARAMETER;
|
return STATUS_INVALID_PARAMETER;
|
||||||
|
|
||||||
|
if (CheckParentDirectory &&
|
||||||
|
L'\\' == ((PWSTR)Request->Buffer)[0] && L'\0' == ((PWSTR)Request->Buffer)[1])
|
||||||
|
return STATUS_INVALID_PARAMETER;
|
||||||
|
|
||||||
if (0 == FileSystem->Interface->GetSecurityByName ||
|
if (0 == FileSystem->Interface->GetSecurityByName ||
|
||||||
(!Request->Req.Create.UserMode && 0 == PSecurityDescriptor))
|
(!Request->Req.Create.UserMode && 0 == PSecurityDescriptor))
|
||||||
{
|
{
|
||||||
@ -78,7 +82,7 @@ FSP_API NTSTATUS FspAccessCheckEx(FSP_FILE_SYSTEM *FileSystem,
|
|||||||
UINT8 PrivilegeSetBuf[sizeof(PRIVILEGE_SET) + 15 * sizeof(LUID_AND_ATTRIBUTES)];
|
UINT8 PrivilegeSetBuf[sizeof(PRIVILEGE_SET) + 15 * sizeof(LUID_AND_ATTRIBUTES)];
|
||||||
PPRIVILEGE_SET PrivilegeSet = (PVOID)PrivilegeSetBuf;
|
PPRIVILEGE_SET PrivilegeSet = (PVOID)PrivilegeSetBuf;
|
||||||
DWORD PrivilegeSetLength = sizeof PrivilegeSetBuf;
|
DWORD PrivilegeSetLength = sizeof PrivilegeSetBuf;
|
||||||
UINT32 TraverseAccess;
|
UINT32 TraverseAccess, ParentAccess, DesiredAccess2;
|
||||||
BOOL AccessStatus;
|
BOOL AccessStatus;
|
||||||
|
|
||||||
if (CheckParentDirectory)
|
if (CheckParentDirectory)
|
||||||
@ -147,7 +151,54 @@ FSP_API NTSTATUS FspAccessCheckEx(FSP_FILE_SYSTEM *FileSystem,
|
|||||||
else
|
else
|
||||||
Result = FspNtStatusFromWin32(GetLastError());
|
Result = FspNtStatusFromWin32(GetLastError());
|
||||||
if (!NT_SUCCESS(Result))
|
if (!NT_SUCCESS(Result))
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* If the desired access includes the DELETE or FILE_READ_ATTRIBUTES
|
||||||
|
* (or MAXIMUM_ALLOWED) rights we must still check with our parent to
|
||||||
|
* see if it gives us access (through the FILE_DELETE_CHILD and
|
||||||
|
* FILE_LIST_DIRECTORY rights).
|
||||||
|
*
|
||||||
|
* Does the Windows security model suck? Ermmmm...
|
||||||
|
*/
|
||||||
|
if (STATUS_ACCESS_DENIED != Result ||
|
||||||
|
0 == ((MAXIMUM_ALLOWED | DELETE | FILE_READ_ATTRIBUTES) & DesiredAccess))
|
||||||
goto exit;
|
goto exit;
|
||||||
|
|
||||||
|
Result = FspAccessCheck(FileSystem, Request, TRUE, FALSE,
|
||||||
|
(MAXIMUM_ALLOWED & DesiredAccess) ? (FILE_DELETE_CHILD | FILE_LIST_DIRECTORY) :
|
||||||
|
(
|
||||||
|
((DELETE & DesiredAccess) ? FILE_DELETE_CHILD : 0) |
|
||||||
|
((FILE_READ_ATTRIBUTES & DesiredAccess) ? FILE_LIST_DIRECTORY : 0)
|
||||||
|
),
|
||||||
|
&ParentAccess);
|
||||||
|
if (!NT_SUCCESS(Result))
|
||||||
|
{
|
||||||
|
/* any failure just becomes ACCESS DENIED at this point */
|
||||||
|
Result = STATUS_ACCESS_DENIED;
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* redo the access check but remove the DELETE and/or FILE_READ_ATTRIBUTES rights */
|
||||||
|
DesiredAccess2 = DesiredAccess & ~(
|
||||||
|
((FILE_DELETE_CHILD & ParentAccess) ? DELETE : 0) |
|
||||||
|
((FILE_LIST_DIRECTORY & ParentAccess) ? FILE_READ_ATTRIBUTES : 0));
|
||||||
|
if (0 != DesiredAccess2)
|
||||||
|
{
|
||||||
|
if (AccessCheck(SecurityDescriptor, (HANDLE)Request->Req.Create.AccessToken, DesiredAccess2,
|
||||||
|
&FspFileGenericMapping, PrivilegeSet, &PrivilegeSetLength, PGrantedAccess, &AccessStatus))
|
||||||
|
Result = AccessStatus ? STATUS_SUCCESS : STATUS_ACCESS_DENIED;
|
||||||
|
else
|
||||||
|
/* any failure just becomes ACCESS DENIED at this point */
|
||||||
|
Result = STATUS_ACCESS_DENIED;
|
||||||
|
if (!NT_SUCCESS(Result))
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (FILE_DELETE_CHILD & ParentAccess)
|
||||||
|
*PGrantedAccess |= DELETE;
|
||||||
|
if (FILE_LIST_DIRECTORY & ParentAccess)
|
||||||
|
*PGrantedAccess |= FILE_READ_ATTRIBUTES;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CheckParentDirectory)
|
if (CheckParentDirectory)
|
||||||
@ -192,6 +243,11 @@ FSP_API NTSTATUS FspAccessCheckEx(FSP_FILE_SYSTEM *FileSystem,
|
|||||||
if (0 == SecurityDescriptorSize)
|
if (0 == SecurityDescriptorSize)
|
||||||
*PGrantedAccess = (MAXIMUM_ALLOWED & DesiredAccess) ?
|
*PGrantedAccess = (MAXIMUM_ALLOWED & DesiredAccess) ?
|
||||||
FspFileGenericMapping.GenericAll : DesiredAccess;
|
FspFileGenericMapping.GenericAll : DesiredAccess;
|
||||||
|
|
||||||
|
if (0 != (FileAttributes & FILE_ATTRIBUTE_READONLY) &&
|
||||||
|
0 != (MAXIMUM_ALLOWED & DesiredAccess))
|
||||||
|
*PGrantedAccess &= ~(FILE_WRITE_DATA | FILE_APPEND_DATA |
|
||||||
|
FILE_ADD_SUBDIRECTORY | FILE_DELETE_CHILD);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
*PGrantedAccess = (MAXIMUM_ALLOWED & DesiredAccess) ?
|
*PGrantedAccess = (MAXIMUM_ALLOWED & DesiredAccess) ?
|
||||||
@ -306,7 +362,8 @@ FSP_API NTSTATUS FspSetSecurityDescriptor(FSP_FILE_SYSTEM *FileSystem,
|
|||||||
FSP_API VOID FspDeleteSecurityDescriptor(PSECURITY_DESCRIPTOR SecurityDescriptor,
|
FSP_API VOID FspDeleteSecurityDescriptor(PSECURITY_DESCRIPTOR SecurityDescriptor,
|
||||||
NTSTATUS (*CreateFunc)())
|
NTSTATUS (*CreateFunc)())
|
||||||
{
|
{
|
||||||
if ((NTSTATUS (*)())FspAccessCheckEx == CreateFunc)
|
if ((NTSTATUS (*)())FspAccessCheckEx == CreateFunc ||
|
||||||
|
(NTSTATUS (*)())FspPosixMapPermissionsToSecurityDescriptor == CreateFunc)
|
||||||
MemFree(SecurityDescriptor);
|
MemFree(SecurityDescriptor);
|
||||||
else
|
else
|
||||||
if ((NTSTATUS (*)())FspCreateSecurityDescriptor == CreateFunc ||
|
if ((NTSTATUS (*)())FspCreateSecurityDescriptor == CreateFunc ||
|
||||||
|
@ -46,16 +46,12 @@ static VOID FspServiceMain(FSP_SERVICE *Service, DWORD Argc, PWSTR *Argv);
|
|||||||
static DWORD WINAPI FspServiceCtrlHandler(
|
static DWORD WINAPI FspServiceCtrlHandler(
|
||||||
DWORD Control, DWORD EventType, PVOID EventData, PVOID Context);
|
DWORD Control, DWORD EventType, PVOID EventData, PVOID Context);
|
||||||
static DWORD WINAPI FspServiceConsoleModeThread(PVOID Context);
|
static DWORD WINAPI FspServiceConsoleModeThread(PVOID Context);
|
||||||
static BOOL WINAPI FspServiceConsoleCtrlHandler(DWORD CtrlType);
|
BOOL WINAPI FspServiceConsoleCtrlHandler(DWORD CtrlType);
|
||||||
|
|
||||||
#define FspServiceFromTable() (0 != FspServiceTable ?\
|
#define FspServiceFromTable() (0 != FspServiceTable ?\
|
||||||
(FSP_SERVICE *)((PUINT8)FspServiceTable[0].lpServiceName - FIELD_OFFSET(FSP_SERVICE, ServiceName)) :\
|
(FSP_SERVICE *)((PUINT8)FspServiceTable[0].lpServiceName - FIELD_OFFSET(FSP_SERVICE, ServiceName)) :\
|
||||||
0)
|
0)
|
||||||
|
|
||||||
VOID FspServiceInitialize(BOOLEAN Dynamic)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
VOID FspServiceFinalize(BOOLEAN Dynamic)
|
VOID FspServiceFinalize(BOOLEAN Dynamic)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
@ -69,10 +65,11 @@ VOID FspServiceFinalize(BOOLEAN Dynamic)
|
|||||||
CloseHandle(FspServiceConsoleModeEvent);
|
CloseHandle(FspServiceConsoleModeEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
FSP_API ULONG FspServiceRun(PWSTR ServiceName,
|
FSP_API ULONG FspServiceRunEx(PWSTR ServiceName,
|
||||||
FSP_SERVICE_START *OnStart,
|
FSP_SERVICE_START *OnStart,
|
||||||
FSP_SERVICE_STOP *OnStop,
|
FSP_SERVICE_STOP *OnStop,
|
||||||
FSP_SERVICE_CONTROL *OnControl)
|
FSP_SERVICE_CONTROL *OnControl,
|
||||||
|
PVOID UserContext)
|
||||||
{
|
{
|
||||||
FSP_SERVICE *Service;
|
FSP_SERVICE *Service;
|
||||||
NTSTATUS Result;
|
NTSTATUS Result;
|
||||||
@ -85,6 +82,7 @@ FSP_API ULONG FspServiceRun(PWSTR ServiceName,
|
|||||||
L"The service %s cannot be created (Status=%lx).", Service->ServiceName, Result);
|
L"The service %s cannot be created (Status=%lx).", Service->ServiceName, Result);
|
||||||
return FspWin32FromNtStatus(Result);
|
return FspWin32FromNtStatus(Result);
|
||||||
}
|
}
|
||||||
|
Service->UserContext = UserContext;
|
||||||
|
|
||||||
FspServiceAllowConsoleMode(Service);
|
FspServiceAllowConsoleMode(Service);
|
||||||
Result = FspServiceLoop(Service);
|
Result = FspServiceLoop(Service);
|
||||||
@ -510,7 +508,8 @@ static DWORD WINAPI FspServiceConsoleModeThread(PVOID Context)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static BOOL WINAPI FspServiceConsoleCtrlHandler(DWORD CtrlType)
|
/* expose FspServiceConsoleCtrlHandler so it can be used from fsp_fuse_signal_handler */
|
||||||
|
BOOL WINAPI FspServiceConsoleCtrlHandler(DWORD CtrlType)
|
||||||
{
|
{
|
||||||
UINT32 Disabled = FspServiceConsoleCtrlHandlerDisabled;
|
UINT32 Disabled = FspServiceConsoleCtrlHandlerDisabled;
|
||||||
MemoryBarrier();
|
MemoryBarrier();
|
||||||
|
165
src/dll/util.c
Normal file
165
src/dll/util.c
Normal file
@ -0,0 +1,165 @@
|
|||||||
|
/**
|
||||||
|
* @file dll/util.c
|
||||||
|
*
|
||||||
|
* @copyright 2015-2016 Bill Zissimopoulos
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* This file is part of WinFsp.
|
||||||
|
*
|
||||||
|
* You can redistribute it and/or modify it under the terms of the
|
||||||
|
* GNU Affero General Public License version 3 as published by the
|
||||||
|
* Free Software Foundation.
|
||||||
|
*
|
||||||
|
* Licensees holding a valid commercial license may use this file in
|
||||||
|
* accordance with the commercial license agreement provided with the
|
||||||
|
* software.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <dll/library.h>
|
||||||
|
#include <aclapi.h>
|
||||||
|
|
||||||
|
static INIT_ONCE FspDiagIdentInitOnce = INIT_ONCE_STATIC_INIT;
|
||||||
|
static WCHAR FspDiagIdentBuf[20] = L"UNKNOWN";
|
||||||
|
|
||||||
|
static BOOL WINAPI FspDiagIdentInitialize(
|
||||||
|
PINIT_ONCE InitOnce, PVOID Parameter, PVOID *Context)
|
||||||
|
{
|
||||||
|
WCHAR ModuleFileName[MAX_PATH];
|
||||||
|
WCHAR Root[2] = L"\\";
|
||||||
|
PWSTR Parent, ModuleBaseName;
|
||||||
|
|
||||||
|
if (0 != GetModuleFileNameW(0, ModuleFileName, sizeof ModuleFileName / sizeof(WCHAR)))
|
||||||
|
FspPathSuffix(ModuleFileName, &Parent, &ModuleBaseName, Root);
|
||||||
|
else
|
||||||
|
lstrcpyW(ModuleBaseName = ModuleFileName, L"UNKNOWN");
|
||||||
|
|
||||||
|
for (PWSTR P = ModuleBaseName, Dot = 0;; P++)
|
||||||
|
{
|
||||||
|
if (L'\0' == *P)
|
||||||
|
{
|
||||||
|
if (0 != Dot)
|
||||||
|
*Dot = L'\0';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (L'.' == *P)
|
||||||
|
Dot = P;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(FspDiagIdentBuf, ModuleBaseName, sizeof FspDiagIdentBuf);
|
||||||
|
FspDiagIdentBuf[(sizeof FspDiagIdentBuf / sizeof(WCHAR)) - 1] = L'\0';
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
PWSTR FspDiagIdent(VOID)
|
||||||
|
{
|
||||||
|
/* internal only: get a diagnostic identifier (eventlog, debug) */
|
||||||
|
|
||||||
|
InitOnceExecuteOnce(&FspDiagIdentInitOnce, FspDiagIdentInitialize, 0, 0);
|
||||||
|
return FspDiagIdentBuf;
|
||||||
|
}
|
||||||
|
|
||||||
|
FSP_API NTSTATUS FspCallNamedPipeSecurely(PWSTR PipeName,
|
||||||
|
PVOID InBuffer, ULONG InBufferSize, PVOID OutBuffer, ULONG OutBufferSize,
|
||||||
|
PULONG PBytesTransferred, ULONG Timeout,
|
||||||
|
PSID Sid)
|
||||||
|
{
|
||||||
|
NTSTATUS Result;
|
||||||
|
HANDLE Pipe = INVALID_HANDLE_VALUE;
|
||||||
|
DWORD PipeMode;
|
||||||
|
|
||||||
|
Pipe = CreateFileW(PipeName,
|
||||||
|
GENERIC_READ | FILE_WRITE_DATA | FILE_WRITE_ATTRIBUTES,
|
||||||
|
FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING,
|
||||||
|
SECURITY_SQOS_PRESENT | SECURITY_IDENTIFICATION, 0);
|
||||||
|
if (INVALID_HANDLE_VALUE == Pipe)
|
||||||
|
{
|
||||||
|
if (ERROR_PIPE_BUSY != GetLastError())
|
||||||
|
{
|
||||||
|
Result = FspNtStatusFromWin32(GetLastError());
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
WaitNamedPipeW(PipeName, Timeout);
|
||||||
|
|
||||||
|
Pipe = CreateFileW(PipeName,
|
||||||
|
GENERIC_READ | FILE_WRITE_DATA | FILE_WRITE_ATTRIBUTES,
|
||||||
|
FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING,
|
||||||
|
SECURITY_SQOS_PRESENT | SECURITY_IDENTIFICATION, 0);
|
||||||
|
if (INVALID_HANDLE_VALUE == Pipe)
|
||||||
|
{
|
||||||
|
Result = FspNtStatusFromWin32(GetLastError());
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (0 != Sid)
|
||||||
|
{
|
||||||
|
PSECURITY_DESCRIPTOR SecurityDescriptor = 0;
|
||||||
|
PSID OwnerSid, WellKnownSid = 0;
|
||||||
|
DWORD SidSize, LastError;
|
||||||
|
|
||||||
|
/* if it is a small number treat it like a well known SID */
|
||||||
|
if (1024 > (INT_PTR)Sid)
|
||||||
|
{
|
||||||
|
SidSize = SECURITY_MAX_SID_SIZE;
|
||||||
|
WellKnownSid = MemAlloc(SidSize);
|
||||||
|
if (0 == WellKnownSid)
|
||||||
|
{
|
||||||
|
Result = STATUS_INSUFFICIENT_RESOURCES;
|
||||||
|
goto sid_exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!CreateWellKnownSid((INT_PTR)Sid, 0, WellKnownSid, &SidSize))
|
||||||
|
{
|
||||||
|
Result = FspNtStatusFromWin32(GetLastError());
|
||||||
|
goto sid_exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LastError = GetSecurityInfo(Pipe, SE_FILE_OBJECT,
|
||||||
|
OWNER_SECURITY_INFORMATION, &OwnerSid, 0, 0, 0, &SecurityDescriptor);
|
||||||
|
if (0 != LastError)
|
||||||
|
{
|
||||||
|
Result = FspNtStatusFromWin32(GetLastError());
|
||||||
|
goto sid_exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!EqualSid(OwnerSid, WellKnownSid ? WellKnownSid : Sid))
|
||||||
|
{
|
||||||
|
Result = STATUS_ACCESS_DENIED;
|
||||||
|
goto sid_exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
Result = STATUS_SUCCESS;
|
||||||
|
|
||||||
|
sid_exit:
|
||||||
|
MemFree(WellKnownSid);
|
||||||
|
LocalFree(SecurityDescriptor);
|
||||||
|
|
||||||
|
if (!NT_SUCCESS(Result))
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
PipeMode = PIPE_READMODE_MESSAGE | PIPE_WAIT;
|
||||||
|
if (!SetNamedPipeHandleState(Pipe, &PipeMode, 0, 0))
|
||||||
|
{
|
||||||
|
Result = FspNtStatusFromWin32(GetLastError());
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!TransactNamedPipe(Pipe, InBuffer, InBufferSize, OutBuffer, OutBufferSize,
|
||||||
|
PBytesTransferred, 0))
|
||||||
|
{
|
||||||
|
Result = FspNtStatusFromWin32(GetLastError());
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
Result = STATUS_SUCCESS;
|
||||||
|
|
||||||
|
exit:
|
||||||
|
if (INVALID_HANDLE_VALUE != Pipe)
|
||||||
|
CloseHandle(Pipe);
|
||||||
|
|
||||||
|
return Result;
|
||||||
|
}
|
@ -55,6 +55,7 @@ static void usage(void)
|
|||||||
"\n"
|
"\n"
|
||||||
"commands:\n"
|
"commands:\n"
|
||||||
" start ClassName InstanceName Args...\n"
|
" start ClassName InstanceName Args...\n"
|
||||||
|
" startWithSecret ClassName InstanceName Args... Secret\n"
|
||||||
" stop ClassName InstanceName\n"
|
" stop ClassName InstanceName\n"
|
||||||
" info ClassName InstanceName\n"
|
" info ClassName InstanceName\n"
|
||||||
" list\n",
|
" list\n",
|
||||||
@ -115,7 +116,8 @@ static int call_pipe_and_report(PWSTR PipeBuf, ULONG SendSize, ULONG RecvSize)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int start(PWSTR PipeBuf, ULONG PipeBufSize,
|
int start(PWSTR PipeBuf, ULONG PipeBufSize,
|
||||||
PWSTR ClassName, PWSTR InstanceName, DWORD Argc, PWSTR *Argv)
|
PWSTR ClassName, PWSTR InstanceName, DWORD Argc, PWSTR *Argv,
|
||||||
|
BOOLEAN HasSecret)
|
||||||
{
|
{
|
||||||
PWSTR P;
|
PWSTR P;
|
||||||
DWORD ClassNameSize, InstanceNameSize, ArgvSize;
|
DWORD ClassNameSize, InstanceNameSize, ArgvSize;
|
||||||
@ -130,7 +132,7 @@ int start(PWSTR PipeBuf, ULONG PipeBufSize,
|
|||||||
return ERROR_INVALID_PARAMETER;
|
return ERROR_INVALID_PARAMETER;
|
||||||
|
|
||||||
P = PipeBuf;
|
P = PipeBuf;
|
||||||
*P++ = LauncherSvcInstanceStart;
|
*P++ = HasSecret ? LauncherSvcInstanceStartWithSecret : LauncherSvcInstanceStart;
|
||||||
memcpy(P, ClassName, ClassNameSize * sizeof(WCHAR)); P += ClassNameSize;
|
memcpy(P, ClassName, ClassNameSize * sizeof(WCHAR)); P += ClassNameSize;
|
||||||
memcpy(P, InstanceName, InstanceNameSize * sizeof(WCHAR)); P += InstanceNameSize;
|
memcpy(P, InstanceName, InstanceNameSize * sizeof(WCHAR)); P += InstanceNameSize;
|
||||||
for (DWORD Argi = 0; Argc > Argi; Argi++)
|
for (DWORD Argi = 0; Argc > Argi; Argi++)
|
||||||
@ -230,7 +232,17 @@ int wmain(int argc, wchar_t **argv)
|
|||||||
if (3 > argc || argc > 12)
|
if (3 > argc || argc > 12)
|
||||||
usage();
|
usage();
|
||||||
|
|
||||||
return start(PipeBuf, LAUNCHER_PIPE_BUFFER_SIZE, argv[1], argv[2], argc - 3, argv + 3);
|
return start(PipeBuf, LAUNCHER_PIPE_BUFFER_SIZE, argv[1], argv[2], argc - 3, argv + 3,
|
||||||
|
FALSE);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if (0 == lstrcmpW(L"startWithSecret", argv[0]))
|
||||||
|
{
|
||||||
|
if (4 > argc || argc > 13)
|
||||||
|
usage();
|
||||||
|
|
||||||
|
return start(PipeBuf, LAUNCHER_PIPE_BUFFER_SIZE, argv[1], argv[2], argc - 3, argv + 3,
|
||||||
|
TRUE);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (0 == lstrcmpW(L"stop", argv[0]))
|
if (0 == lstrcmpW(L"stop", argv[0]))
|
||||||
@ -276,16 +288,9 @@ void wmainCRTStartup(void)
|
|||||||
DWORD Argc;
|
DWORD Argc;
|
||||||
PWSTR *Argv;
|
PWSTR *Argv;
|
||||||
|
|
||||||
extern HANDLE ProcessHeap;
|
|
||||||
ProcessHeap = GetProcessHeap();
|
|
||||||
if (0 == ProcessHeap)
|
|
||||||
ExitProcess(GetLastError());
|
|
||||||
|
|
||||||
Argv = CommandLineToArgvW(GetCommandLineW(), &Argc);
|
Argv = CommandLineToArgvW(GetCommandLineW(), &Argc);
|
||||||
if (0 == Argv)
|
if (0 == Argv)
|
||||||
ExitProcess(GetLastError());
|
ExitProcess(GetLastError());
|
||||||
|
|
||||||
ExitProcess(wmain(Argc, Argv));
|
ExitProcess(wmain(Argc, Argv));
|
||||||
}
|
}
|
||||||
|
|
||||||
HANDLE ProcessHeap;
|
|
||||||
|
@ -19,7 +19,54 @@
|
|||||||
#include <sddl.h>
|
#include <sddl.h>
|
||||||
|
|
||||||
#define PROGNAME "WinFsp.Launcher"
|
#define PROGNAME "WinFsp.Launcher"
|
||||||
#define REGKEY "SYSTEM\\CurrentControlSet\\Services\\" PROGNAME "\\Services"
|
#define REGKEY LAUNCHER_REGKEY
|
||||||
|
|
||||||
|
BOOL CreateOverlappedPipe(
|
||||||
|
PHANDLE PReadPipe, PHANDLE PWritePipe, PSECURITY_ATTRIBUTES SecurityAttributes, DWORD Size,
|
||||||
|
DWORD ReadMode, DWORD WriteMode)
|
||||||
|
{
|
||||||
|
RPC_STATUS RpcStatus;
|
||||||
|
UUID Uuid;
|
||||||
|
WCHAR PipeNameBuf[MAX_PATH];
|
||||||
|
HANDLE ReadPipe, WritePipe;
|
||||||
|
DWORD LastError;
|
||||||
|
|
||||||
|
RpcStatus = UuidCreate(&Uuid);
|
||||||
|
if (S_OK != RpcStatus && RPC_S_UUID_LOCAL_ONLY != RpcStatus)
|
||||||
|
{
|
||||||
|
SetLastError(ERROR_INTERNAL_ERROR);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
wsprintfW(PipeNameBuf, L"\\\\.\\pipe\\"
|
||||||
|
"%08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X",
|
||||||
|
Uuid.Data1, Uuid.Data2, Uuid.Data3,
|
||||||
|
Uuid.Data4[0], Uuid.Data4[1], Uuid.Data4[2], Uuid.Data4[3],
|
||||||
|
Uuid.Data4[4], Uuid.Data4[5], Uuid.Data4[6], Uuid.Data4[7]);
|
||||||
|
|
||||||
|
ReadPipe = CreateNamedPipeW(PipeNameBuf,
|
||||||
|
PIPE_ACCESS_INBOUND | FILE_FLAG_FIRST_PIPE_INSTANCE | ReadMode,
|
||||||
|
PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT | PIPE_REJECT_REMOTE_CLIENTS,
|
||||||
|
1, Size, Size, 120 * 1000, SecurityAttributes);
|
||||||
|
if (INVALID_HANDLE_VALUE == ReadPipe)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
WritePipe = CreateFileW(PipeNameBuf,
|
||||||
|
GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
|
||||||
|
SecurityAttributes, OPEN_EXISTING, WriteMode, 0);
|
||||||
|
if (INVALID_HANDLE_VALUE == WritePipe)
|
||||||
|
{
|
||||||
|
LastError = GetLastError();
|
||||||
|
CloseHandle(ReadPipe);
|
||||||
|
SetLastError(LastError);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
*PReadPipe = ReadPipe;
|
||||||
|
*PWritePipe = WritePipe;
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
@ -80,6 +127,7 @@ static VOID CALLBACK KillProcessWait(PVOID Context, BOOLEAN Timeout)
|
|||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
|
LONG RefCount;
|
||||||
PWSTR ClassName;
|
PWSTR ClassName;
|
||||||
PWSTR InstanceName;
|
PWSTR InstanceName;
|
||||||
PWSTR CommandLine;
|
PWSTR CommandLine;
|
||||||
@ -87,6 +135,7 @@ typedef struct
|
|||||||
DWORD ProcessId;
|
DWORD ProcessId;
|
||||||
HANDLE Process;
|
HANDLE Process;
|
||||||
HANDLE ProcessWait;
|
HANDLE ProcessWait;
|
||||||
|
HANDLE StdioHandles[2];
|
||||||
LIST_ENTRY ListEntry;
|
LIST_ENTRY ListEntry;
|
||||||
WCHAR Buffer[];
|
WCHAR Buffer[];
|
||||||
} SVC_INSTANCE;
|
} SVC_INSTANCE;
|
||||||
@ -231,8 +280,132 @@ static NTSTATUS SvcInstanceAccessCheck(HANDLE ClientToken, ULONG DesiredAccess,
|
|||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NTSTATUS SvcInstanceCreateProcess(PWSTR Executable, PWSTR CommandLine,
|
||||||
|
HANDLE StdioHandles[2],
|
||||||
|
PPROCESS_INFORMATION ProcessInfo)
|
||||||
|
{
|
||||||
|
STARTUPINFOEXW StartupInfoEx;
|
||||||
|
HANDLE ChildHandles[3] = { INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE, 0/* DO NOT CLOSE!*/ };
|
||||||
|
HANDLE ParentHandles[2] = { INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE };
|
||||||
|
SECURITY_ATTRIBUTES PipeAttributes = { sizeof(SECURITY_ATTRIBUTES), 0, TRUE };
|
||||||
|
PPROC_THREAD_ATTRIBUTE_LIST AttrList = 0;
|
||||||
|
SIZE_T Size;
|
||||||
|
NTSTATUS Result;
|
||||||
|
|
||||||
|
memset(&StartupInfoEx, 0, sizeof StartupInfoEx);
|
||||||
|
StartupInfoEx.StartupInfo.cb = sizeof StartupInfoEx.StartupInfo;
|
||||||
|
|
||||||
|
if (0 != StdioHandles)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Create child process and redirect stdin/stdout. Do *not* inherit other handles.
|
||||||
|
*
|
||||||
|
* For explanation see:
|
||||||
|
* https://blogs.msdn.microsoft.com/oldnewthing/20111216-00/?p=8873/
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* create stdin read/write ends; make them inheritable */
|
||||||
|
if (!CreateOverlappedPipe(&ChildHandles[0], &ParentHandles[0], &PipeAttributes, 0,
|
||||||
|
0, 0))
|
||||||
|
{
|
||||||
|
Result = FspNtStatusFromWin32(GetLastError());
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* create stdout read/write ends; make them inheritable */
|
||||||
|
if (!CreateOverlappedPipe(&ParentHandles[1], &ChildHandles[1], &PipeAttributes, 0,
|
||||||
|
FILE_FLAG_OVERLAPPED, 0))
|
||||||
|
{
|
||||||
|
Result = FspNtStatusFromWin32(GetLastError());
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
ChildHandles[2] = GetStdHandle(STD_ERROR_HANDLE);
|
||||||
|
|
||||||
|
Size = 0;
|
||||||
|
if (!InitializeProcThreadAttributeList(0, 1, 0, &Size) &&
|
||||||
|
ERROR_INSUFFICIENT_BUFFER != GetLastError())
|
||||||
|
{
|
||||||
|
Result = FspNtStatusFromWin32(GetLastError());
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
AttrList = MemAlloc(Size);
|
||||||
|
if (0 == AttrList)
|
||||||
|
{
|
||||||
|
Result = STATUS_INSUFFICIENT_RESOURCES;
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!InitializeProcThreadAttributeList(AttrList, 1, 0, &Size))
|
||||||
|
{
|
||||||
|
Result = FspNtStatusFromWin32(GetLastError());
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* only the child ends of stdin/stdout are actually inherited */
|
||||||
|
if (!UpdateProcThreadAttribute(AttrList, 0, PROC_THREAD_ATTRIBUTE_HANDLE_LIST,
|
||||||
|
ChildHandles, sizeof ChildHandles, 0, 0))
|
||||||
|
{
|
||||||
|
Result = FspNtStatusFromWin32(GetLastError());
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
StartupInfoEx.StartupInfo.cb = sizeof StartupInfoEx;
|
||||||
|
StartupInfoEx.lpAttributeList = AttrList;
|
||||||
|
StartupInfoEx.StartupInfo.dwFlags = STARTF_USESTDHANDLES;
|
||||||
|
StartupInfoEx.StartupInfo.hStdInput = ChildHandles[0];
|
||||||
|
StartupInfoEx.StartupInfo.hStdOutput = ChildHandles[1];
|
||||||
|
StartupInfoEx.StartupInfo.hStdError = ChildHandles[2];
|
||||||
|
|
||||||
|
if (!CreateProcessW(Executable, CommandLine, 0, 0, TRUE,
|
||||||
|
CREATE_SUSPENDED | CREATE_NEW_PROCESS_GROUP | EXTENDED_STARTUPINFO_PRESENT, 0, 0,
|
||||||
|
&StartupInfoEx.StartupInfo, ProcessInfo))
|
||||||
|
{
|
||||||
|
Result = FspNtStatusFromWin32(GetLastError());
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!CreateProcessW(Executable, CommandLine, 0, 0, FALSE,
|
||||||
|
CREATE_SUSPENDED | CREATE_NEW_PROCESS_GROUP, 0, 0,
|
||||||
|
&StartupInfoEx.StartupInfo, ProcessInfo))
|
||||||
|
{
|
||||||
|
Result = FspNtStatusFromWin32(GetLastError());
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Result = STATUS_SUCCESS;
|
||||||
|
|
||||||
|
exit:
|
||||||
|
if (!NT_SUCCESS(Result))
|
||||||
|
{
|
||||||
|
if (INVALID_HANDLE_VALUE != ParentHandles[0])
|
||||||
|
CloseHandle(ParentHandles[0]);
|
||||||
|
if (INVALID_HANDLE_VALUE != ParentHandles[0])
|
||||||
|
CloseHandle(ParentHandles[1]);
|
||||||
|
}
|
||||||
|
else if (0 != StdioHandles)
|
||||||
|
{
|
||||||
|
StdioHandles[0] = ParentHandles[0];
|
||||||
|
StdioHandles[1] = ParentHandles[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (INVALID_HANDLE_VALUE != ChildHandles[0])
|
||||||
|
CloseHandle(ChildHandles[0]);
|
||||||
|
if (INVALID_HANDLE_VALUE != ChildHandles[1])
|
||||||
|
CloseHandle(ChildHandles[1]);
|
||||||
|
|
||||||
|
MemFree(AttrList);
|
||||||
|
|
||||||
|
return Result;
|
||||||
|
}
|
||||||
|
|
||||||
NTSTATUS SvcInstanceCreate(HANDLE ClientToken,
|
NTSTATUS SvcInstanceCreate(HANDLE ClientToken,
|
||||||
PWSTR ClassName, PWSTR InstanceName, ULONG Argc, PWSTR *Argv0, HANDLE Job,
|
PWSTR ClassName, PWSTR InstanceName, ULONG Argc, PWSTR *Argv0, HANDLE Job,
|
||||||
|
BOOLEAN RedirectStdio,
|
||||||
SVC_INSTANCE **PSvcInstance)
|
SVC_INSTANCE **PSvcInstance)
|
||||||
{
|
{
|
||||||
SVC_INSTANCE *SvcInstance = 0;
|
SVC_INSTANCE *SvcInstance = 0;
|
||||||
@ -241,10 +414,9 @@ NTSTATUS SvcInstanceCreate(HANDLE ClientToken,
|
|||||||
DWORD ClassNameSize, InstanceNameSize;
|
DWORD ClassNameSize, InstanceNameSize;
|
||||||
WCHAR Executable[MAX_PATH], CommandLineBuf[512], SecurityBuf[512];
|
WCHAR Executable[MAX_PATH], CommandLineBuf[512], SecurityBuf[512];
|
||||||
PWSTR CommandLine, Security;
|
PWSTR CommandLine, Security;
|
||||||
DWORD JobControl;
|
DWORD JobControl, Credentials;
|
||||||
PSECURITY_DESCRIPTOR SecurityDescriptor = 0;
|
PSECURITY_DESCRIPTOR SecurityDescriptor = 0;
|
||||||
PWSTR Argv[10];
|
PWSTR Argv[10];
|
||||||
STARTUPINFOW StartupInfo;
|
|
||||||
PROCESS_INFORMATION ProcessInfo;
|
PROCESS_INFORMATION ProcessInfo;
|
||||||
NTSTATUS Result;
|
NTSTATUS Result;
|
||||||
|
|
||||||
@ -259,7 +431,6 @@ NTSTATUS SvcInstanceCreate(HANDLE ClientToken,
|
|||||||
Argv[0] = 0;
|
Argv[0] = 0;
|
||||||
Argc++;
|
Argc++;
|
||||||
|
|
||||||
memset(&StartupInfo, 0, sizeof StartupInfo);
|
|
||||||
memset(&ProcessInfo, 0, sizeof ProcessInfo);
|
memset(&ProcessInfo, 0, sizeof ProcessInfo);
|
||||||
|
|
||||||
EnterCriticalSection(&SvcInstanceLock);
|
EnterCriticalSection(&SvcInstanceLock);
|
||||||
@ -277,6 +448,22 @@ NTSTATUS SvcInstanceCreate(HANDLE ClientToken,
|
|||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RegSize = sizeof Credentials;
|
||||||
|
Credentials = 0;
|
||||||
|
RegResult = RegGetValueW(RegKey, ClassName, L"Credentials", RRF_RT_REG_DWORD, 0,
|
||||||
|
&Credentials, &RegSize);
|
||||||
|
if (ERROR_SUCCESS != RegResult && ERROR_FILE_NOT_FOUND != RegResult)
|
||||||
|
{
|
||||||
|
Result = FspNtStatusFromWin32(RegResult);
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
if ((!RedirectStdio && 0 != Credentials) ||
|
||||||
|
( RedirectStdio && 0 == Credentials))
|
||||||
|
{
|
||||||
|
Result = STATUS_DEVICE_CONFIGURATION_ERROR;
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
RegSize = sizeof Executable;
|
RegSize = sizeof Executable;
|
||||||
Executable[0] = L'\0';
|
Executable[0] = L'\0';
|
||||||
RegResult = RegGetValueW(RegKey, ClassName, L"Executable", RRF_RT_REG_SZ, 0,
|
RegResult = RegGetValueW(RegKey, ClassName, L"Executable", RRF_RT_REG_SZ, 0,
|
||||||
@ -336,7 +523,7 @@ NTSTATUS SvcInstanceCreate(HANDLE ClientToken,
|
|||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
FspDebugLogSD(__FUNCTION__ ": SDDL = %s\n", SecurityDescriptor);
|
//FspDebugLogSD(__FUNCTION__ ": SDDL = %s\n", SecurityDescriptor);
|
||||||
|
|
||||||
Result = SvcInstanceAccessCheck(ClientToken, SERVICE_START, SecurityDescriptor);
|
Result = SvcInstanceAccessCheck(ClientToken, SERVICE_START, SecurityDescriptor);
|
||||||
if (!NT_SUCCESS(Result))
|
if (!NT_SUCCESS(Result))
|
||||||
@ -353,23 +540,23 @@ NTSTATUS SvcInstanceCreate(HANDLE ClientToken,
|
|||||||
}
|
}
|
||||||
|
|
||||||
memset(SvcInstance, 0, sizeof *SvcInstance);
|
memset(SvcInstance, 0, sizeof *SvcInstance);
|
||||||
|
SvcInstance->RefCount = 2;
|
||||||
memcpy(SvcInstance->Buffer, ClassName, ClassNameSize);
|
memcpy(SvcInstance->Buffer, ClassName, ClassNameSize);
|
||||||
memcpy(SvcInstance->Buffer + ClassNameSize / sizeof(WCHAR), InstanceName, InstanceNameSize);
|
memcpy(SvcInstance->Buffer + ClassNameSize / sizeof(WCHAR), InstanceName, InstanceNameSize);
|
||||||
SvcInstance->ClassName = SvcInstance->Buffer;
|
SvcInstance->ClassName = SvcInstance->Buffer;
|
||||||
SvcInstance->InstanceName = SvcInstance->Buffer + ClassNameSize / sizeof(WCHAR);
|
SvcInstance->InstanceName = SvcInstance->Buffer + ClassNameSize / sizeof(WCHAR);
|
||||||
SvcInstance->SecurityDescriptor = SecurityDescriptor;
|
SvcInstance->SecurityDescriptor = SecurityDescriptor;
|
||||||
|
SvcInstance->StdioHandles[0] = INVALID_HANDLE_VALUE;
|
||||||
|
SvcInstance->StdioHandles[1] = INVALID_HANDLE_VALUE;
|
||||||
|
|
||||||
Result = SvcInstanceReplaceArguments(CommandLine, Argc, Argv, &SvcInstance->CommandLine);
|
Result = SvcInstanceReplaceArguments(CommandLine, Argc, Argv, &SvcInstance->CommandLine);
|
||||||
if (!NT_SUCCESS(Result))
|
if (!NT_SUCCESS(Result))
|
||||||
goto exit;
|
goto exit;
|
||||||
|
|
||||||
StartupInfo.cb = sizeof StartupInfo;
|
Result = SvcInstanceCreateProcess(Executable, SvcInstance->CommandLine,
|
||||||
if (!CreateProcessW(Executable, SvcInstance->CommandLine, 0, 0, FALSE,
|
RedirectStdio ? SvcInstance->StdioHandles : 0, &ProcessInfo);
|
||||||
CREATE_SUSPENDED | CREATE_NEW_PROCESS_GROUP, 0, 0, &StartupInfo, &ProcessInfo))
|
if (!NT_SUCCESS(Result))
|
||||||
{
|
|
||||||
Result = FspNtStatusFromWin32(GetLastError());
|
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
|
||||||
|
|
||||||
SvcInstance->ProcessId = ProcessInfo.dwProcessId;
|
SvcInstance->ProcessId = ProcessInfo.dwProcessId;
|
||||||
SvcInstance->Process = ProcessInfo.hProcess;
|
SvcInstance->Process = ProcessInfo.hProcess;
|
||||||
@ -413,6 +600,11 @@ exit:
|
|||||||
|
|
||||||
if (0 != SvcInstance)
|
if (0 != SvcInstance)
|
||||||
{
|
{
|
||||||
|
if (INVALID_HANDLE_VALUE != SvcInstance->StdioHandles[0])
|
||||||
|
CloseHandle(SvcInstance->StdioHandles[0]);
|
||||||
|
if (INVALID_HANDLE_VALUE != SvcInstance->StdioHandles[1])
|
||||||
|
CloseHandle(SvcInstance->StdioHandles[1]);
|
||||||
|
|
||||||
if (0 != SvcInstance->ProcessWait)
|
if (0 != SvcInstance->ProcessWait)
|
||||||
UnregisterWaitEx(SvcInstance->ProcessWait, 0);
|
UnregisterWaitEx(SvcInstance->ProcessWait, 0);
|
||||||
|
|
||||||
@ -435,13 +627,21 @@ exit:
|
|||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID SvcInstanceDelete(SVC_INSTANCE *SvcInstance)
|
static VOID SvcInstanceRelease(SVC_INSTANCE *SvcInstance)
|
||||||
{
|
{
|
||||||
|
if (0 != InterlockedDecrement(&SvcInstance->RefCount))
|
||||||
|
return;
|
||||||
|
|
||||||
EnterCriticalSection(&SvcInstanceLock);
|
EnterCriticalSection(&SvcInstanceLock);
|
||||||
if (RemoveEntryList(&SvcInstance->ListEntry))
|
if (RemoveEntryList(&SvcInstance->ListEntry))
|
||||||
SetEvent(SvcInstanceEvent);
|
SetEvent(SvcInstanceEvent);
|
||||||
LeaveCriticalSection(&SvcInstanceLock);
|
LeaveCriticalSection(&SvcInstanceLock);
|
||||||
|
|
||||||
|
if (INVALID_HANDLE_VALUE != SvcInstance->StdioHandles[0])
|
||||||
|
CloseHandle(SvcInstance->StdioHandles[0]);
|
||||||
|
if (INVALID_HANDLE_VALUE != SvcInstance->StdioHandles[1])
|
||||||
|
CloseHandle(SvcInstance->StdioHandles[1]);
|
||||||
|
|
||||||
if (0 != SvcInstance->ProcessWait)
|
if (0 != SvcInstance->ProcessWait)
|
||||||
UnregisterWaitEx(SvcInstance->ProcessWait, 0);
|
UnregisterWaitEx(SvcInstance->ProcessWait, 0);
|
||||||
if (0 != SvcInstance->Process)
|
if (0 != SvcInstance->Process)
|
||||||
@ -457,15 +657,92 @@ static VOID CALLBACK SvcInstanceTerminated(PVOID Context, BOOLEAN Timeout)
|
|||||||
{
|
{
|
||||||
SVC_INSTANCE *SvcInstance = Context;
|
SVC_INSTANCE *SvcInstance = Context;
|
||||||
|
|
||||||
SvcInstanceDelete(SvcInstance);
|
SvcInstanceRelease(SvcInstance);
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS SvcInstanceStart(HANDLE ClientToken,
|
NTSTATUS SvcInstanceStart(HANDLE ClientToken,
|
||||||
PWSTR ClassName, PWSTR InstanceName, ULONG Argc, PWSTR *Argv, HANDLE Job)
|
PWSTR ClassName, PWSTR InstanceName, ULONG Argc, PWSTR *Argv, HANDLE Job,
|
||||||
|
BOOLEAN HasSecret)
|
||||||
{
|
{
|
||||||
SVC_INSTANCE *SvcInstance;
|
SVC_INSTANCE *SvcInstance;
|
||||||
|
NTSTATUS Result;
|
||||||
|
|
||||||
return SvcInstanceCreate(ClientToken, ClassName, InstanceName, Argc, Argv, Job, &SvcInstance);
|
if (HasSecret && (0 == Argc || L'\0' == Argv[Argc - 1][0]))
|
||||||
|
return STATUS_INVALID_PARAMETER;
|
||||||
|
HasSecret = !!HasSecret;
|
||||||
|
|
||||||
|
Result = SvcInstanceCreate(ClientToken, ClassName, InstanceName,
|
||||||
|
Argc - HasSecret, Argv, Job, HasSecret,
|
||||||
|
&SvcInstance);
|
||||||
|
if (!NT_SUCCESS(Result))
|
||||||
|
return Result;
|
||||||
|
|
||||||
|
if (!HasSecret)
|
||||||
|
Result = STATUS_SUCCESS;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PWSTR Secret = Argv[Argc - 1];
|
||||||
|
UINT8 ReqBuf[256];
|
||||||
|
UINT8 RspBuf[2];
|
||||||
|
DWORD BytesTransferred;
|
||||||
|
OVERLAPPED Overlapped;
|
||||||
|
|
||||||
|
if (0 == (BytesTransferred =
|
||||||
|
WideCharToMultiByte(CP_UTF8, 0, Secret, lstrlenW(Secret), ReqBuf, sizeof ReqBuf, 0, 0)))
|
||||||
|
{
|
||||||
|
Result = FspNtStatusFromWin32(GetLastError());
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!WriteFile(SvcInstance->StdioHandles[0], ReqBuf, BytesTransferred, &BytesTransferred, 0))
|
||||||
|
{
|
||||||
|
Result = FspNtStatusFromWin32(GetLastError());
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
CloseHandle(SvcInstance->StdioHandles[0]);
|
||||||
|
SvcInstance->StdioHandles[0] = INVALID_HANDLE_VALUE;
|
||||||
|
|
||||||
|
memset(&Overlapped, 0, sizeof Overlapped);
|
||||||
|
if (!ReadFile(SvcInstance->StdioHandles[1], RspBuf, sizeof RspBuf, 0, &Overlapped) &&
|
||||||
|
ERROR_IO_PENDING != GetLastError())
|
||||||
|
{
|
||||||
|
Result = FspNtStatusFromWin32(GetLastError());
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!GetOverlappedResultEx(SvcInstance->StdioHandles[1], &Overlapped, &BytesTransferred,
|
||||||
|
LAUNCHER_START_WITH_SECRET_TIMEOUT, FALSE))
|
||||||
|
{
|
||||||
|
if (WAIT_TIMEOUT == GetLastError())
|
||||||
|
Result = STATUS_TIMEOUT;
|
||||||
|
else
|
||||||
|
Result = FspNtStatusFromWin32(GetLastError());
|
||||||
|
CancelIoEx(SvcInstance->StdioHandles[1], &Overlapped);
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sizeof RspBuf <= BytesTransferred && 'O' == RspBuf[0] && 'K' == RspBuf[1])
|
||||||
|
Result = STATUS_SUCCESS;
|
||||||
|
else
|
||||||
|
Result = STATUS_ACCESS_DENIED;
|
||||||
|
}
|
||||||
|
|
||||||
|
exit:
|
||||||
|
if (INVALID_HANDLE_VALUE != SvcInstance->StdioHandles[0])
|
||||||
|
{
|
||||||
|
CloseHandle(SvcInstance->StdioHandles[0]);
|
||||||
|
SvcInstance->StdioHandles[0] = INVALID_HANDLE_VALUE;
|
||||||
|
}
|
||||||
|
if (INVALID_HANDLE_VALUE != SvcInstance->StdioHandles[1])
|
||||||
|
{
|
||||||
|
CloseHandle(SvcInstance->StdioHandles[1]);
|
||||||
|
SvcInstance->StdioHandles[1] = INVALID_HANDLE_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
SvcInstanceRelease(SvcInstance);
|
||||||
|
|
||||||
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS SvcInstanceStop(HANDLE ClientToken,
|
NTSTATUS SvcInstanceStop(HANDLE ClientToken,
|
||||||
@ -625,7 +902,7 @@ static NTSTATUS SvcStart(FSP_SERVICE *Service, ULONG argc, PWSTR *argv)
|
|||||||
&SecurityAttributes.lpSecurityDescriptor, 0))
|
&SecurityAttributes.lpSecurityDescriptor, 0))
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
FspDebugLogSD(__FUNCTION__ ": SDDL = %s\n", SecurityAttributes.lpSecurityDescriptor);
|
//FspDebugLogSD(__FUNCTION__ ": SDDL = %s\n", SecurityAttributes.lpSecurityDescriptor);
|
||||||
|
|
||||||
SvcInstanceEvent = CreateEventW(0, TRUE, TRUE, 0);
|
SvcInstanceEvent = CreateEventW(0, TRUE, TRUE, 0);
|
||||||
if (0 == SvcInstanceEvent)
|
if (0 == SvcInstanceEvent)
|
||||||
@ -909,12 +1186,16 @@ static VOID SvcPipeTransact(HANDLE ClientToken, PWSTR PipeBuf, PULONG PSize)
|
|||||||
PWSTR P = PipeBuf, PipeBufEnd = PipeBuf + *PSize / sizeof(WCHAR);
|
PWSTR P = PipeBuf, PipeBufEnd = PipeBuf + *PSize / sizeof(WCHAR);
|
||||||
PWSTR ClassName, InstanceName;
|
PWSTR ClassName, InstanceName;
|
||||||
ULONG Argc; PWSTR Argv[9];
|
ULONG Argc; PWSTR Argv[9];
|
||||||
|
BOOLEAN HasSecret = FALSE;
|
||||||
NTSTATUS Result;
|
NTSTATUS Result;
|
||||||
|
|
||||||
*PSize = 0;
|
*PSize = 0;
|
||||||
|
|
||||||
switch (*P++)
|
switch (*P++)
|
||||||
{
|
{
|
||||||
|
case LauncherSvcInstanceStartWithSecret:
|
||||||
|
HasSecret = TRUE;
|
||||||
|
/* fall through! */
|
||||||
case LauncherSvcInstanceStart:
|
case LauncherSvcInstanceStart:
|
||||||
ClassName = SvcPipeTransactGetPart(&P, PipeBufEnd);
|
ClassName = SvcPipeTransactGetPart(&P, PipeBufEnd);
|
||||||
InstanceName = SvcPipeTransactGetPart(&P, PipeBufEnd);
|
InstanceName = SvcPipeTransactGetPart(&P, PipeBufEnd);
|
||||||
@ -924,7 +1205,8 @@ static VOID SvcPipeTransact(HANDLE ClientToken, PWSTR PipeBuf, PULONG PSize)
|
|||||||
|
|
||||||
Result = STATUS_INVALID_PARAMETER;
|
Result = STATUS_INVALID_PARAMETER;
|
||||||
if (0 != ClassName && 0 != InstanceName)
|
if (0 != ClassName && 0 != InstanceName)
|
||||||
Result = SvcInstanceStart(ClientToken, ClassName, InstanceName, Argc, Argv, SvcJob);
|
Result = SvcInstanceStart(ClientToken, ClassName, InstanceName, Argc, Argv, SvcJob,
|
||||||
|
HasSecret);
|
||||||
|
|
||||||
SvcPipeTransactResult(Result, PipeBuf, PSize);
|
SvcPipeTransactResult(Result, PipeBuf, PSize);
|
||||||
break;
|
break;
|
||||||
@ -981,12 +1263,5 @@ int wmain(int argc, wchar_t **argv)
|
|||||||
|
|
||||||
void wmainCRTStartup(void)
|
void wmainCRTStartup(void)
|
||||||
{
|
{
|
||||||
extern HANDLE ProcessHeap;
|
|
||||||
ProcessHeap = GetProcessHeap();
|
|
||||||
if (0 == ProcessHeap)
|
|
||||||
ExitProcess(GetLastError());
|
|
||||||
|
|
||||||
ExitProcess(wmain(0, 0));
|
ExitProcess(wmain(0, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
HANDLE ProcessHeap;
|
|
||||||
|
@ -21,13 +21,17 @@
|
|||||||
#include <winfsp/winfsp.h>
|
#include <winfsp/winfsp.h>
|
||||||
#include <shared/minimal.h>
|
#include <shared/minimal.h>
|
||||||
|
|
||||||
|
#define LAUNCHER_REGKEY "SYSTEM\\CurrentControlSet\\Services\\WinFsp.Launcher\\Services"
|
||||||
|
|
||||||
#define LAUNCHER_STOP_TIMEOUT 5500
|
#define LAUNCHER_STOP_TIMEOUT 5500
|
||||||
#define LAUNCHER_KILL_TIMEOUT 5000
|
#define LAUNCHER_KILL_TIMEOUT 5000
|
||||||
|
|
||||||
#define LAUNCHER_PIPE_NAME "\\\\.\\pipe\\WinFsp.{14E7137D-22B4-437A-B0C1-D21D1BDF3767}"
|
#define LAUNCHER_PIPE_NAME "\\\\.\\pipe\\WinFsp.{14E7137D-22B4-437A-B0C1-D21D1BDF3767}"
|
||||||
#define LAUNCHER_PIPE_BUFFER_SIZE 2048
|
#define LAUNCHER_PIPE_BUFFER_SIZE 4096
|
||||||
#define LAUNCHER_PIPE_DEFAULT_TIMEOUT 3000
|
#define LAUNCHER_PIPE_DEFAULT_TIMEOUT 3000
|
||||||
|
|
||||||
|
#define LAUNCHER_START_WITH_SECRET_TIMEOUT 15000
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The launcher named pipe SDDL gives full access to LocalSystem and Administrators and
|
* The launcher named pipe SDDL gives full access to LocalSystem and Administrators and
|
||||||
* GENERIC_READ and FILE_WRITE_DATA access to Everyone. We are careful not to give the
|
* GENERIC_READ and FILE_WRITE_DATA access to Everyone. We are careful not to give the
|
||||||
@ -53,6 +57,7 @@
|
|||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
LauncherSvcInstanceStart = 'S', /* requires: SERVICE_START */
|
LauncherSvcInstanceStart = 'S', /* requires: SERVICE_START */
|
||||||
|
LauncherSvcInstanceStartWithSecret = 'X', /* requires: SERVICE_START */
|
||||||
LauncherSvcInstanceStop = 'T', /* requires: SERVICE_STOP */
|
LauncherSvcInstanceStop = 'T', /* requires: SERVICE_STOP */
|
||||||
LauncherSvcInstanceInfo = 'I', /* requires: SERVICE_QUERY_STATUS */
|
LauncherSvcInstanceInfo = 'I', /* requires: SERVICE_QUERY_STATUS */
|
||||||
LauncherSvcInstanceList = 'L', /* requires: none*/
|
LauncherSvcInstanceList = 'L', /* requires: none*/
|
||||||
|
@ -24,8 +24,25 @@
|
|||||||
* For this to work the following project settings must be set:
|
* For this to work the following project settings must be set:
|
||||||
* - "C/C++ > General > SDL checks" must be empty (not "Yes" or "No").
|
* - "C/C++ > General > SDL checks" must be empty (not "Yes" or "No").
|
||||||
* - "C/C++ > Code Generation > Basic Runtime Checks" must be set to "Default"
|
* - "C/C++ > Code Generation > Basic Runtime Checks" must be set to "Default"
|
||||||
|
* - "C/C++ > Code Generation > Runtime Library" must be set to "Multi-threaded (/MT)".
|
||||||
* - "C/C++ > Code Generation > Security Check" must be disabled (/GS-).
|
* - "C/C++ > Code Generation > Security Check" must be disabled (/GS-).
|
||||||
* - "Linker > Input > Ignore All Default Libraries" must be "Yes".
|
* - "Linker > Input > Ignore All Default Libraries" must be "Yes".
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Update:
|
||||||
|
*
|
||||||
|
* It is possible to have the "Linker > Input > Ignore All Default Libraries"
|
||||||
|
* setting to "No" and still eliminate most dependencies on the MSVCRT libraries.
|
||||||
|
* For example, the WinFsp DLL does this on 32-bit builds (only) to include the
|
||||||
|
* __allmul symbol that is used when doing int64_t multiplications.
|
||||||
|
*
|
||||||
|
* The following project setting must be changed:
|
||||||
|
* - "Linker > Input > Ignore All Default Libraries" must be "No".
|
||||||
|
*
|
||||||
|
* Extreme care must be taken to ensure that the linker does not pull in symbols
|
||||||
|
* that are not required (or worse create a half-baked CRT). For example, the WinFsp
|
||||||
|
* DLL ensures this by setting the "Linker > Input > Ignore All Default Libraries"
|
||||||
|
* to "Yes" on 64-bit builds and "No" on 32-bit builds.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#undef RtlFillMemory
|
#undef RtlFillMemory
|
||||||
@ -48,16 +65,14 @@ void *memset(void *dst, int val, size_t siz)
|
|||||||
return dst;
|
return dst;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline PVOID MemAlloc(SIZE_T Size)
|
static inline void *MemAlloc(size_t Size)
|
||||||
{
|
{
|
||||||
extern HANDLE ProcessHeap;
|
return HeapAlloc(GetProcessHeap(), 0, Size);
|
||||||
return HeapAlloc(ProcessHeap, 0, Size);
|
|
||||||
}
|
}
|
||||||
static inline VOID MemFree(PVOID Pointer)
|
static inline void MemFree(void *Pointer)
|
||||||
{
|
{
|
||||||
extern HANDLE ProcessHeap;
|
|
||||||
if (0 != Pointer)
|
if (0 != Pointer)
|
||||||
HeapFree(ProcessHeap, 0, Pointer);
|
HeapFree(GetProcessHeap(), 0, Pointer);
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCEINLINE
|
static FORCEINLINE
|
||||||
|
@ -105,6 +105,7 @@ NTSTATUS DriverEntry(
|
|||||||
FspIopPrepareFunction[IRP_MJ_WRITE] = FspFsvolWritePrepare;
|
FspIopPrepareFunction[IRP_MJ_WRITE] = FspFsvolWritePrepare;
|
||||||
FspIopCompleteFunction[IRP_MJ_WRITE] = FspFsvolWriteComplete;
|
FspIopCompleteFunction[IRP_MJ_WRITE] = FspFsvolWriteComplete;
|
||||||
FspIopCompleteFunction[IRP_MJ_QUERY_INFORMATION] = FspFsvolQueryInformationComplete;
|
FspIopCompleteFunction[IRP_MJ_QUERY_INFORMATION] = FspFsvolQueryInformationComplete;
|
||||||
|
FspIopPrepareFunction[IRP_MJ_SET_INFORMATION] = FspFsvolSetInformationPrepare;
|
||||||
FspIopCompleteFunction[IRP_MJ_SET_INFORMATION] = FspFsvolSetInformationComplete;
|
FspIopCompleteFunction[IRP_MJ_SET_INFORMATION] = FspFsvolSetInformationComplete;
|
||||||
FspIopCompleteFunction[IRP_MJ_QUERY_EA] = FspFsvolQueryEaComplete;
|
FspIopCompleteFunction[IRP_MJ_QUERY_EA] = FspFsvolQueryEaComplete;
|
||||||
FspIopCompleteFunction[IRP_MJ_SET_EA] = FspFsvolSetEaComplete;
|
FspIopCompleteFunction[IRP_MJ_SET_EA] = FspFsvolSetEaComplete;
|
||||||
|
@ -316,6 +316,7 @@ FSP_IOCMPL_DISPATCH FspFsvolQueryVolumeInformationComplete;
|
|||||||
FSP_IOPREP_DISPATCH FspFsvolReadPrepare;
|
FSP_IOPREP_DISPATCH FspFsvolReadPrepare;
|
||||||
FSP_IOCMPL_DISPATCH FspFsvolReadComplete;
|
FSP_IOCMPL_DISPATCH FspFsvolReadComplete;
|
||||||
FSP_IOCMPL_DISPATCH FspFsvolSetEaComplete;
|
FSP_IOCMPL_DISPATCH FspFsvolSetEaComplete;
|
||||||
|
FSP_IOPREP_DISPATCH FspFsvolSetInformationPrepare;
|
||||||
FSP_IOCMPL_DISPATCH FspFsvolSetInformationComplete;
|
FSP_IOCMPL_DISPATCH FspFsvolSetInformationComplete;
|
||||||
FSP_IOPREP_DISPATCH FspFsvolSetSecurityPrepare;
|
FSP_IOPREP_DISPATCH FspFsvolSetSecurityPrepare;
|
||||||
FSP_IOCMPL_DISPATCH FspFsvolSetSecurityComplete;
|
FSP_IOCMPL_DISPATCH FspFsvolSetSecurityComplete;
|
||||||
|
@ -63,6 +63,7 @@ static NTSTATUS FspFsvolSetRenameInformationSuccess(
|
|||||||
PIRP Irp, const FSP_FSCTL_TRANSACT_RSP *Response);
|
PIRP Irp, const FSP_FSCTL_TRANSACT_RSP *Response);
|
||||||
static NTSTATUS FspFsvolSetInformation(
|
static NTSTATUS FspFsvolSetInformation(
|
||||||
PDEVICE_OBJECT FsvolDeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp);
|
PDEVICE_OBJECT FsvolDeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp);
|
||||||
|
FSP_IOPREP_DISPATCH FspFsvolSetInformationPrepare;
|
||||||
FSP_IOCMPL_DISPATCH FspFsvolSetInformationComplete;
|
FSP_IOCMPL_DISPATCH FspFsvolSetInformationComplete;
|
||||||
static FSP_IOP_REQUEST_FINI FspFsvolSetInformationRequestFini;
|
static FSP_IOP_REQUEST_FINI FspFsvolSetInformationRequestFini;
|
||||||
FSP_DRIVER_DISPATCH FspQueryInformation;
|
FSP_DRIVER_DISPATCH FspQueryInformation;
|
||||||
@ -89,6 +90,7 @@ FSP_DRIVER_DISPATCH FspSetInformation;
|
|||||||
#pragma alloc_text(PAGE, FspFsvolSetRenameInformation)
|
#pragma alloc_text(PAGE, FspFsvolSetRenameInformation)
|
||||||
#pragma alloc_text(PAGE, FspFsvolSetRenameInformationSuccess)
|
#pragma alloc_text(PAGE, FspFsvolSetRenameInformationSuccess)
|
||||||
#pragma alloc_text(PAGE, FspFsvolSetInformation)
|
#pragma alloc_text(PAGE, FspFsvolSetInformation)
|
||||||
|
#pragma alloc_text(PAGE, FspFsvolSetInformationPrepare)
|
||||||
#pragma alloc_text(PAGE, FspFsvolSetInformationComplete)
|
#pragma alloc_text(PAGE, FspFsvolSetInformationComplete)
|
||||||
#pragma alloc_text(PAGE, FspFsvolSetInformationRequestFini)
|
#pragma alloc_text(PAGE, FspFsvolSetInformationRequestFini)
|
||||||
#pragma alloc_text(PAGE, FspQueryInformation)
|
#pragma alloc_text(PAGE, FspQueryInformation)
|
||||||
@ -106,6 +108,9 @@ enum
|
|||||||
/* SetInformation */
|
/* SetInformation */
|
||||||
//RequestFileNode = 0,
|
//RequestFileNode = 0,
|
||||||
RequestDeviceObject = 1,
|
RequestDeviceObject = 1,
|
||||||
|
/* Rename */
|
||||||
|
RequestAccessToken = 2,
|
||||||
|
RequestProcess = 3,
|
||||||
};
|
};
|
||||||
|
|
||||||
static NTSTATUS FspFsvolQueryAllInformation(PFILE_OBJECT FileObject,
|
static NTSTATUS FspFsvolQueryAllInformation(PFILE_OBJECT FileObject,
|
||||||
@ -845,7 +850,6 @@ static NTSTATUS FspFsvolSetRenameInformation(
|
|||||||
PFILE_OBJECT TargetFileObject = IrpSp->Parameters.SetFile.FileObject;
|
PFILE_OBJECT TargetFileObject = IrpSp->Parameters.SetFile.FileObject;
|
||||||
PFILE_RENAME_INFORMATION Info = (PFILE_RENAME_INFORMATION)Irp->AssociatedIrp.SystemBuffer;
|
PFILE_RENAME_INFORMATION Info = (PFILE_RENAME_INFORMATION)Irp->AssociatedIrp.SystemBuffer;
|
||||||
ULONG Length = IrpSp->Parameters.SetFile.Length;
|
ULONG Length = IrpSp->Parameters.SetFile.Length;
|
||||||
BOOLEAN ReplaceIfExists = IrpSp->Parameters.SetFile.ReplaceIfExists;
|
|
||||||
FSP_FILE_NODE *FileNode = FileObject->FsContext;
|
FSP_FILE_NODE *FileNode = FileObject->FsContext;
|
||||||
FSP_FILE_DESC *FileDesc = FileObject->FsContext2;
|
FSP_FILE_DESC *FileDesc = FileObject->FsContext2;
|
||||||
FSP_FILE_NODE *TargetFileNode = 0 != TargetFileObject ?
|
FSP_FILE_NODE *TargetFileNode = 0 != TargetFileObject ?
|
||||||
@ -922,7 +926,6 @@ static NTSTATUS FspFsvolSetRenameInformation(
|
|||||||
Request->Req.SetInformation.FileInformationClass = FileRenameInformation;
|
Request->Req.SetInformation.FileInformationClass = FileRenameInformation;
|
||||||
Request->Req.SetInformation.Info.Rename.NewFileName.Offset = Request->FileName.Size;
|
Request->Req.SetInformation.Info.Rename.NewFileName.Offset = Request->FileName.Size;
|
||||||
Request->Req.SetInformation.Info.Rename.NewFileName.Size = NewFileName.Length + sizeof(WCHAR);
|
Request->Req.SetInformation.Info.Rename.NewFileName.Size = NewFileName.Length + sizeof(WCHAR);
|
||||||
Request->Req.SetInformation.Info.Rename.ReplaceIfExists = ReplaceIfExists;
|
|
||||||
|
|
||||||
FspFsvolDeviceFileRenameSetOwner(FsvolDeviceObject, Request);
|
FspFsvolDeviceFileRenameSetOwner(FsvolDeviceObject, Request);
|
||||||
FspFileNodeSetOwner(FileNode, Full, Request);
|
FspFileNodeSetOwner(FileNode, Full, Request);
|
||||||
@ -1095,6 +1098,59 @@ static NTSTATUS FspFsvolSetInformation(
|
|||||||
return FSP_STATUS_IOQ_POST;
|
return FSP_STATUS_IOQ_POST;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NTSTATUS FspFsvolSetInformationPrepare(
|
||||||
|
PIRP Irp, FSP_FSCTL_TRANSACT_REQ *Request)
|
||||||
|
{
|
||||||
|
PAGED_CODE();
|
||||||
|
|
||||||
|
PIO_STACK_LOCATION IrpSp = IoGetCurrentIrpStackLocation(Irp);
|
||||||
|
|
||||||
|
if (FileRenameInformation != IrpSp->Parameters.SetFile.FileInformationClass ||
|
||||||
|
!IrpSp->Parameters.SetFile.ReplaceIfExists)
|
||||||
|
return STATUS_SUCCESS;
|
||||||
|
|
||||||
|
NTSTATUS Result;
|
||||||
|
SECURITY_SUBJECT_CONTEXT SecuritySubjectContext;
|
||||||
|
SECURITY_QUALITY_OF_SERVICE SecurityQualityOfService;
|
||||||
|
SECURITY_CLIENT_CONTEXT SecurityClientContext;
|
||||||
|
HANDLE UserModeAccessToken;
|
||||||
|
PEPROCESS Process;
|
||||||
|
|
||||||
|
/* duplicate the subject context access token into an impersonation token */
|
||||||
|
SecurityQualityOfService.Length = sizeof SecurityQualityOfService;
|
||||||
|
SecurityQualityOfService.ImpersonationLevel = SecurityIdentification;
|
||||||
|
SecurityQualityOfService.ContextTrackingMode = SECURITY_STATIC_TRACKING;
|
||||||
|
SecurityQualityOfService.EffectiveOnly = FALSE;
|
||||||
|
SeCaptureSubjectContext(&SecuritySubjectContext);
|
||||||
|
SeLockSubjectContext(&SecuritySubjectContext);
|
||||||
|
Result = SeCreateClientSecurityFromSubjectContext(&SecuritySubjectContext,
|
||||||
|
&SecurityQualityOfService, FALSE, &SecurityClientContext);
|
||||||
|
SeUnlockSubjectContext(&SecuritySubjectContext);
|
||||||
|
SeReleaseSubjectContext(&SecuritySubjectContext);
|
||||||
|
if (!NT_SUCCESS(Result))
|
||||||
|
return Result;
|
||||||
|
|
||||||
|
ASSERT(TokenImpersonation == SeTokenType(SecurityClientContext.ClientToken));
|
||||||
|
|
||||||
|
/* get a user-mode handle to the impersonation token */
|
||||||
|
Result = ObOpenObjectByPointer(SecurityClientContext.ClientToken,
|
||||||
|
0, 0, TOKEN_QUERY, *SeTokenObjectType, UserMode, &UserModeAccessToken);
|
||||||
|
SeDeleteClientSecurity(&SecurityClientContext);
|
||||||
|
if (!NT_SUCCESS(Result))
|
||||||
|
return Result;
|
||||||
|
|
||||||
|
/* get a pointer to the current process so that we can close the impersonation token later */
|
||||||
|
Process = PsGetCurrentProcess();
|
||||||
|
ObReferenceObject(Process);
|
||||||
|
|
||||||
|
/* send the user-mode handle to the user-mode file system */
|
||||||
|
FspIopRequestContext(Request, RequestAccessToken) = UserModeAccessToken;
|
||||||
|
FspIopRequestContext(Request, RequestProcess) = Process;
|
||||||
|
Request->Req.SetInformation.Info.Rename.AccessToken = (UINT_PTR)UserModeAccessToken;
|
||||||
|
|
||||||
|
return STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
NTSTATUS FspFsvolSetInformationComplete(
|
NTSTATUS FspFsvolSetInformationComplete(
|
||||||
PIRP Irp, const FSP_FSCTL_TRANSACT_RSP *Response)
|
PIRP Irp, const FSP_FSCTL_TRANSACT_RSP *Response)
|
||||||
{
|
{
|
||||||
@ -1154,12 +1210,38 @@ static VOID FspFsvolSetInformationRequestFini(FSP_FSCTL_TRANSACT_REQ *Request, P
|
|||||||
|
|
||||||
FSP_FILE_NODE *FileNode = Context[RequestFileNode];
|
FSP_FILE_NODE *FileNode = Context[RequestFileNode];
|
||||||
PDEVICE_OBJECT FsvolDeviceObject = Context[RequestDeviceObject];
|
PDEVICE_OBJECT FsvolDeviceObject = Context[RequestDeviceObject];
|
||||||
|
HANDLE AccessToken = Context[RequestAccessToken];
|
||||||
|
PEPROCESS Process = Context[RequestProcess];
|
||||||
|
|
||||||
if (0 != FileNode)
|
if (0 != FileNode)
|
||||||
FspFileNodeReleaseOwner(FileNode, Full, Request);
|
FspFileNodeReleaseOwner(FileNode, Full, Request);
|
||||||
|
|
||||||
if (0 != FsvolDeviceObject)
|
if (0 != FsvolDeviceObject)
|
||||||
FspFsvolDeviceFileRenameReleaseOwner(FsvolDeviceObject, Request);
|
FspFsvolDeviceFileRenameReleaseOwner(FsvolDeviceObject, Request);
|
||||||
|
|
||||||
|
if (0 != AccessToken)
|
||||||
|
{
|
||||||
|
KAPC_STATE ApcState;
|
||||||
|
BOOLEAN Attach;
|
||||||
|
|
||||||
|
ASSERT(0 != Process);
|
||||||
|
Attach = Process != PsGetCurrentProcess();
|
||||||
|
|
||||||
|
if (Attach)
|
||||||
|
KeStackAttachProcess(Process, &ApcState);
|
||||||
|
#if DBG
|
||||||
|
NTSTATUS Result0;
|
||||||
|
Result0 = ObCloseHandle(AccessToken, UserMode);
|
||||||
|
if (!NT_SUCCESS(Result0))
|
||||||
|
DEBUGLOG("ObCloseHandle() = %s", NtStatusSym(Result0));
|
||||||
|
#else
|
||||||
|
ObCloseHandle(AccessToken, UserMode);
|
||||||
|
#endif
|
||||||
|
if (Attach)
|
||||||
|
KeUnstackDetachProcess(&ApcState);
|
||||||
|
|
||||||
|
ObDereferenceObject(Process);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS FspQueryInformation(
|
NTSTATUS FspQueryInformation(
|
||||||
|
@ -117,7 +117,15 @@ static NTSTATUS FspFsvolQueryFsDeviceInformation(
|
|||||||
|
|
||||||
PFILE_FS_DEVICE_INFORMATION Info = (PFILE_FS_DEVICE_INFORMATION)*PBuffer;
|
PFILE_FS_DEVICE_INFORMATION Info = (PFILE_FS_DEVICE_INFORMATION)*PBuffer;
|
||||||
|
|
||||||
Info->DeviceType = FsvolDeviceObject->DeviceType;
|
/*
|
||||||
|
* The following value MUST be FILE_DEVICE_DISK or GetFileType fails,
|
||||||
|
* which has all sorts of interesting consequences (like cmd.exe failing
|
||||||
|
* to redirect to a file when under a network file system).
|
||||||
|
*
|
||||||
|
* See also (which explicitly says to use FILE_DEVICE_DISK for our case):
|
||||||
|
* https://msdn.microsoft.com/en-us/library/cc232109.aspx
|
||||||
|
*/
|
||||||
|
Info->DeviceType = FILE_DEVICE_DISK;
|
||||||
Info->Characteristics = FsvolDeviceObject->Characteristics;
|
Info->Characteristics = FsvolDeviceObject->Characteristics;
|
||||||
|
|
||||||
*PBuffer += sizeof(FILE_FS_DEVICE_INFORMATION);
|
*PBuffer += sizeof(FILE_FS_DEVICE_INFORMATION);
|
||||||
|
@ -188,7 +188,8 @@ static NTSTATUS FspVolumeCreateNoLock(
|
|||||||
|
|
||||||
/* create the volume (and virtual disk) device(s) */
|
/* create the volume (and virtual disk) device(s) */
|
||||||
Result = FspDeviceCreate(FspFsvolDeviceExtensionKind, 0,
|
Result = FspDeviceCreate(FspFsvolDeviceExtensionKind, 0,
|
||||||
FsctlDeviceObject->DeviceType, 0,
|
FsctlDeviceObject->DeviceType,
|
||||||
|
FILE_DEVICE_DISK_FILE_SYSTEM == FsctlDeviceObject->DeviceType ? 0 : FILE_REMOTE_DEVICE,
|
||||||
&FsvolDeviceObject);
|
&FsvolDeviceObject);
|
||||||
if (!NT_SUCCESS(Result))
|
if (!NT_SUCCESS(Result))
|
||||||
return Result;
|
return Result;
|
||||||
|
@ -1,29 +1,46 @@
|
|||||||
@echo off
|
@echo off
|
||||||
|
|
||||||
|
setlocal
|
||||||
|
|
||||||
set Configuration=Release
|
set Configuration=Release
|
||||||
set MsiName="WinFsp - Windows File System Proxy"
|
set MsiName="WinFsp - Windows File System Proxy"
|
||||||
set CrossCert="%~dp0DigiCert High Assurance EV Root CA.crt"
|
set CrossCert="%~dp0DigiCert High Assurance EV Root CA.crt"
|
||||||
set Issuer="DigiCert"
|
set Issuer="DigiCert"
|
||||||
set Subject="Navimatics Corporation"
|
set Subject="Navimatics Corporation"
|
||||||
|
|
||||||
call "%VS140COMNTOOLS%\..\..\VC\vcvarsall.bat"
|
|
||||||
|
|
||||||
if not X%1==X set Configuration=%1
|
if not X%1==X set Configuration=%1
|
||||||
|
|
||||||
|
call "%VS140COMNTOOLS%\..\..\VC\vcvarsall.bat" x64
|
||||||
|
|
||||||
cd %~dp0..\build\VStudio
|
cd %~dp0..\build\VStudio
|
||||||
if exist build\ del /s/q build >nul
|
if exist build\ del /s/q build >nul
|
||||||
|
|
||||||
devenv winfsp.sln /build "%Configuration%|x64"
|
devenv winfsp.sln /build "%Configuration%|x64"
|
||||||
|
if errorlevel 1 goto fail
|
||||||
devenv winfsp.sln /build "%Configuration%|x86"
|
devenv winfsp.sln /build "%Configuration%|x86"
|
||||||
|
if errorlevel 1 goto fail
|
||||||
|
|
||||||
|
set signfail=0
|
||||||
for %%f in (build\%Configuration%\winfsp-x64.sys build\%Configuration%\winfsp-x86.sys) do (
|
for %%f in (build\%Configuration%\winfsp-x64.sys build\%Configuration%\winfsp-x86.sys) do (
|
||||||
signtool sign /ac %CrossCert% /i %Issuer% /n %Subject% /fd sha1 /t http://timestamp.digicert.com %%f
|
signtool sign /ac %CrossCert% /i %Issuer% /n %Subject% /fd sha1 /t http://timestamp.digicert.com %%f
|
||||||
|
if errorlevel 1 set /a signfail=signfail+1
|
||||||
signtool sign /as /ac %CrossCert% /i %Issuer% /n %Subject% /fd sha256 /tr http://timestamp.digicert.com /td sha256 %%f
|
signtool sign /as /ac %CrossCert% /i %Issuer% /n %Subject% /fd sha256 /tr http://timestamp.digicert.com /td sha256 %%f
|
||||||
|
if errorlevel 1 set /a signfail=signfail+1
|
||||||
)
|
)
|
||||||
|
|
||||||
devenv winfsp.sln /build "Installer.%Configuration%|x86"
|
devenv winfsp.sln /build "Installer.%Configuration%|x86"
|
||||||
|
if errorlevel 1 goto fail
|
||||||
|
|
||||||
for %%f in (build\%Configuration%\winfsp-*.msi) do (
|
for %%f in (build\%Configuration%\winfsp-*.msi) do (
|
||||||
signtool sign /ac %CrossCert% /i %Issuer% /n %Subject% /fd sha1 /t http://timestamp.digicert.com /d %MsiName% %%f
|
signtool sign /ac %CrossCert% /i %Issuer% /n %Subject% /fd sha1 /t http://timestamp.digicert.com /d %MsiName% %%f
|
||||||
|
if errorlevel 1 set /a signfail=signfail+1
|
||||||
REM signtool sign /ac %CrossCert% /i %Issuer% /n %Subject% /fd sha256 /tr http://timestamp.digicert.com /td sha256 /d %MsiName% %%f
|
REM signtool sign /ac %CrossCert% /i %Issuer% /n %Subject% /fd sha256 /tr http://timestamp.digicert.com /td sha256 /d %MsiName% %%f
|
||||||
|
REM if errorlevel 1 set /a signfail=signfail+1
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if not %signfail%==0 echo SIGNING FAILED! The product has been successfully built, but not signed.
|
||||||
|
|
||||||
|
exit /b 0
|
||||||
|
|
||||||
|
:fail
|
||||||
|
exit /b 1
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
@echo off
|
@echo off
|
||||||
|
|
||||||
|
setlocal
|
||||||
|
|
||||||
set DebugWorkspace=winfsp
|
set DebugWorkspace=winfsp
|
||||||
set DebugPort=50000
|
set DebugPort=50000
|
||||||
set DebugKey=win8.debug.net.key
|
set DebugKey=win8.debug.net.key
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
@echo off
|
@echo off
|
||||||
|
|
||||||
|
setlocal
|
||||||
|
|
||||||
set CONFIG=Debug
|
set CONFIG=Debug
|
||||||
set SUFFIX=x64
|
set SUFFIX=x64
|
||||||
set TARGET_MACHINE=WIN8DBG
|
set TARGET_MACHINE=WIN8DBG
|
||||||
|
22
tools/gensrc/errno.sh
Normal file
22
tools/gensrc/errno.sh
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
cd $(dirname "$0")
|
||||||
|
|
||||||
|
(
|
||||||
|
echo '#include <errno.h>'
|
||||||
|
echo '/*beginbeginbeginbegin*/'
|
||||||
|
awk '{ printf "case %s: return %s;\n", $1, $2 }' errno.txt
|
||||||
|
) > errno.src
|
||||||
|
|
||||||
|
echo "#if FSP_FUSE_ERRNO == 87 /* Windows */"
|
||||||
|
echo
|
||||||
|
vcvars="$(cygpath -aw "$VS140COMNTOOLS/../../VC/vcvarsall.bat")"
|
||||||
|
cmd /c "call" "$vcvars" "x64" "&&" cl /nologo /EP /C errno.src 2>/dev/null | sed -e '1,/beginbeginbeginbegin/d'
|
||||||
|
echo
|
||||||
|
echo "#elif FSP_FUSE_ERRNO == 67 /* Cygwin */"
|
||||||
|
echo
|
||||||
|
cpp -C -P errno.src | sed -e '1,/beginbeginbeginbegin/d'
|
||||||
|
echo
|
||||||
|
echo "#endif"
|
||||||
|
|
||||||
|
rm errno.src
|
54
tools/gensrc/errno.txt
Normal file
54
tools/gensrc/errno.txt
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
0 STATUS_SUCCESS
|
||||||
|
EPERM STATUS_ACCESS_DENIED
|
||||||
|
ENOENT STATUS_OBJECT_NAME_NOT_FOUND
|
||||||
|
ESRCH STATUS_PROCEDURE_NOT_FOUND
|
||||||
|
EINTR STATUS_CANCELLED
|
||||||
|
EIO STATUS_IO_DEVICE_ERROR
|
||||||
|
ENXIO STATUS_FILE_INVALID
|
||||||
|
E2BIG STATUS_INSUFFICIENT_RESOURCES
|
||||||
|
ENOEXEC STATUS_INVALID_IMAGE_FORMAT
|
||||||
|
EBADF STATUS_INVALID_HANDLE
|
||||||
|
ENOMEM STATUS_INSUFFICIENT_RESOURCES
|
||||||
|
EACCES STATUS_ACCESS_DENIED
|
||||||
|
EFAULT STATUS_ACCESS_VIOLATION
|
||||||
|
EBUSY STATUS_DEVICE_BUSY
|
||||||
|
EEXIST STATUS_OBJECT_NAME_COLLISION
|
||||||
|
EXDEV STATUS_NOT_SAME_DEVICE
|
||||||
|
ENODEV STATUS_NO_SUCH_DEVICE
|
||||||
|
ENOTDIR STATUS_NOT_A_DIRECTORY
|
||||||
|
EISDIR STATUS_FILE_IS_A_DIRECTORY
|
||||||
|
EINVAL STATUS_INVALID_PARAMETER
|
||||||
|
ENFILE STATUS_TOO_MANY_OPENED_FILES
|
||||||
|
EMFILE STATUS_TOO_MANY_OPENED_FILES
|
||||||
|
EFBIG STATUS_DISK_FULL
|
||||||
|
ENOSPC STATUS_DISK_FULL
|
||||||
|
ESPIPE STATUS_INVALID_PARAMETER
|
||||||
|
EROFS STATUS_MEDIA_WRITE_PROTECTED
|
||||||
|
EMLINK STATUS_TOO_MANY_LINKS
|
||||||
|
EPIPE STATUS_PIPE_BROKEN
|
||||||
|
EDOM STATUS_INVALID_PARAMETER
|
||||||
|
ERANGE STATUS_INVALID_PARAMETER
|
||||||
|
EDEADLK STATUS_POSSIBLE_DEADLOCK
|
||||||
|
ENAMETOOLONG STATUS_NAME_TOO_LONG
|
||||||
|
ENOLCK STATUS_LOCK_NOT_GRANTED
|
||||||
|
ENOSYS STATUS_INVALID_DEVICE_REQUEST
|
||||||
|
ENOTEMPTY STATUS_DIRECTORY_NOT_EMPTY
|
||||||
|
EILSEQ STATUS_INVALID_PARAMETER
|
||||||
|
EADDRINUSE STATUS_ADDRESS_ALREADY_ASSOCIATED
|
||||||
|
EALREADY STATUS_CONNECTION_ACTIVE
|
||||||
|
ECANCELED STATUS_CANCELLED
|
||||||
|
ECONNABORTED STATUS_CONNECTION_ABORTED
|
||||||
|
ECONNREFUSED STATUS_CONNECTION_REFUSED
|
||||||
|
ECONNRESET STATUS_CONNECTION_RESET
|
||||||
|
EHOSTUNREACH STATUS_HOST_UNREACHABLE
|
||||||
|
EISCONN STATUS_CONNECTION_ACTIVE
|
||||||
|
ELOOP STATUS_REPARSE_POINT_NOT_RESOLVED
|
||||||
|
ENETDOWN STATUS_HOST_DOWN
|
||||||
|
ENETRESET STATUS_CONNECTION_RESET
|
||||||
|
ENETUNREACH STATUS_NETWORK_UNREACHABLE
|
||||||
|
ENOBUFS STATUS_INSUFFICIENT_RESOURCES
|
||||||
|
ENODATA STATUS_END_OF_FILE
|
||||||
|
ENOLINK STATUS_CONNECTION_INVALID
|
||||||
|
ENOTCONN STATUS_CONNECTION_INVALID
|
||||||
|
ENOTSOCK STATUS_INVALID_HANDLE
|
||||||
|
ETIMEDOUT STATUS_TRANSACTION_TIMED_OUT
|
11
tools/nmake-ext-test.bat
Normal file
11
tools/nmake-ext-test.bat
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
@echo off
|
||||||
|
|
||||||
|
setlocal
|
||||||
|
|
||||||
|
set Configuration=Release
|
||||||
|
if not X%1==X set Configuration=%1
|
||||||
|
|
||||||
|
call "%VS140COMNTOOLS%\..\..\VC\vcvarsall.bat" x64
|
||||||
|
|
||||||
|
cd %~dp0..\ext\test
|
||||||
|
nmake /f Nmakefile
|
107
tools/run-tests.bat
Normal file
107
tools/run-tests.bat
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
@echo off
|
||||||
|
|
||||||
|
setlocal
|
||||||
|
|
||||||
|
set Configuration=Release
|
||||||
|
if not X%1==X set Configuration=%1
|
||||||
|
|
||||||
|
cd %~dp0..
|
||||||
|
set ProjRoot=%cd%
|
||||||
|
|
||||||
|
cd build\VStudio
|
||||||
|
if not exist build\%Configuration% echo === No tests found >&2 & goto fail
|
||||||
|
cd build\%Configuration%
|
||||||
|
|
||||||
|
launchctl-x64 start memfs64 testdsk "" M: >nul
|
||||||
|
launchctl-x64 start memfs64 testnet \memfs64\test N: >nul
|
||||||
|
launchctl-x64 start memfs32 testdsk "" O: >nul
|
||||||
|
launchctl-x64 start memfs32 testnet \memfs32\test P: >nul
|
||||||
|
rem Cannot use timeout under cygwin/mintty: "Input redirection is not supported"
|
||||||
|
waitfor 7BF47D72F6664550B03248ECFE77C7DD /t 3 2>nul
|
||||||
|
cd M: >nul 2>nul || (echo === Unable to find drive M: >&2 & goto fail)
|
||||||
|
cd N: >nul 2>nul || (echo === Unable to find drive N: >&2 & goto fail)
|
||||||
|
cd O: >nul 2>nul || (echo === Unable to find drive O: >&2 & goto fail)
|
||||||
|
cd P: >nul 2>nul || (echo === Unable to find drive P: >&2 & goto fail)
|
||||||
|
|
||||||
|
set testpass=0
|
||||||
|
set testfail=0
|
||||||
|
for %%f in (winfsp-tests-x64 winfsp-tests-x86 :fsx-memfs-x64 :fsx-memfs-x86 :winfstest-memfs-x64 :winfstest-memfs-x86) do (
|
||||||
|
echo === Running %%f
|
||||||
|
|
||||||
|
if defined APPVEYOR (
|
||||||
|
appveyor AddTest "%%f" -FileName None -Framework None -Outcome Running
|
||||||
|
)
|
||||||
|
|
||||||
|
pushd %cd%
|
||||||
|
call %%f
|
||||||
|
popd
|
||||||
|
|
||||||
|
if errorlevel 1 (
|
||||||
|
set /a testfail=testfail+1
|
||||||
|
|
||||||
|
echo === Failed %%f
|
||||||
|
|
||||||
|
if defined APPVEYOR (
|
||||||
|
appveyor UpdateTest "%%f" -FileName None -Framework None -Outcome Failed -Duration 0
|
||||||
|
)
|
||||||
|
) else (
|
||||||
|
set /a testpass=testpass+1
|
||||||
|
|
||||||
|
echo === Passed %%f
|
||||||
|
|
||||||
|
if defined APPVEYOR (
|
||||||
|
appveyor UpdateTest "%%f" -FileName None -Framework None -Outcome Passed -Duration 0
|
||||||
|
)
|
||||||
|
)
|
||||||
|
echo:
|
||||||
|
)
|
||||||
|
|
||||||
|
launchctl-x64 stop memfs64 testdsk >nul
|
||||||
|
launchctl-x64 stop memfs64 testnet >nul
|
||||||
|
launchctl-x64 stop memfs32 testdsk >nul
|
||||||
|
launchctl-x64 stop memfs32 testnet >nul
|
||||||
|
|
||||||
|
set /a total=testpass+testfail
|
||||||
|
echo === Total: %testpass%/%total%
|
||||||
|
if not %testfail%==0 goto fail
|
||||||
|
|
||||||
|
exit /b 0
|
||||||
|
|
||||||
|
:fail
|
||||||
|
exit /b 1
|
||||||
|
|
||||||
|
:fsx-memfs-x64
|
||||||
|
M:
|
||||||
|
"%ProjRoot%\ext\test\fstools\src\fsx\fsx.exe" -N 5000 test xxxxxx
|
||||||
|
if errorlevel 1 goto fail
|
||||||
|
N:
|
||||||
|
"%ProjRoot%\ext\test\fstools\src\fsx\fsx.exe" -N 5000 test xxxxxx
|
||||||
|
if errorlevel 1 goto fail
|
||||||
|
exit /b 0
|
||||||
|
|
||||||
|
:fsx-memfs-x86
|
||||||
|
O:
|
||||||
|
"%ProjRoot%\ext\test\fstools\src\fsx\fsx.exe" -N 5000 test xxxxxx
|
||||||
|
if errorlevel 1 goto fail
|
||||||
|
P:
|
||||||
|
"%ProjRoot%\ext\test\fstools\src\fsx\fsx.exe" -N 5000 test xxxxxx
|
||||||
|
if errorlevel 1 goto fail
|
||||||
|
exit /b 0
|
||||||
|
|
||||||
|
:winfstest-memfs-x64
|
||||||
|
M:
|
||||||
|
call "%ProjRoot%\ext\test\winfstest\run-winfstest.bat" base
|
||||||
|
if errorlevel 1 goto fail
|
||||||
|
N:
|
||||||
|
call "%ProjRoot%\ext\test\winfstest\run-winfstest.bat" base
|
||||||
|
if errorlevel 1 goto fail
|
||||||
|
exit /b 0
|
||||||
|
|
||||||
|
:winfstest-memfs-x86
|
||||||
|
O:
|
||||||
|
call "%ProjRoot%\ext\test\winfstest\run-winfstest.bat" base
|
||||||
|
if errorlevel 1 goto fail
|
||||||
|
P:
|
||||||
|
call "%ProjRoot%\ext\test\winfstest\run-winfstest.bat" base
|
||||||
|
if errorlevel 1 goto fail
|
||||||
|
exit /b 0
|
@ -30,13 +30,14 @@
|
|||||||
static ULONG wcstol_deflt(wchar_t *w, ULONG deflt)
|
static ULONG wcstol_deflt(wchar_t *w, ULONG deflt)
|
||||||
{
|
{
|
||||||
wchar_t *endp;
|
wchar_t *endp;
|
||||||
ULONG ul = wcstol(w, &endp, 10);
|
ULONG ul = wcstol(w, &endp, 0);
|
||||||
return L'\0' != w[0] && L'\0' == *endp ? ul : deflt;
|
return L'\0' != w[0] && L'\0' == *endp ? ul : deflt;
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS SvcStart(FSP_SERVICE *Service, ULONG argc, PWSTR *argv)
|
NTSTATUS SvcStart(FSP_SERVICE *Service, ULONG argc, PWSTR *argv)
|
||||||
{
|
{
|
||||||
wchar_t **argp, **arge;
|
wchar_t **argp, **arge;
|
||||||
|
ULONG DebugFlags = 0;
|
||||||
ULONG Flags = MemfsDisk;
|
ULONG Flags = MemfsDisk;
|
||||||
ULONG FileInfoTimeout = INFINITE;
|
ULONG FileInfoTimeout = INFINITE;
|
||||||
ULONG MaxFileNodes = 1024;
|
ULONG MaxFileNodes = 1024;
|
||||||
@ -55,6 +56,9 @@ NTSTATUS SvcStart(FSP_SERVICE *Service, ULONG argc, PWSTR *argv)
|
|||||||
{
|
{
|
||||||
case L'?':
|
case L'?':
|
||||||
goto usage;
|
goto usage;
|
||||||
|
case L'd':
|
||||||
|
argtol(DebugFlags);
|
||||||
|
break;
|
||||||
case L'm':
|
case L'm':
|
||||||
argtos(MountPoint);
|
argtos(MountPoint);
|
||||||
break;
|
break;
|
||||||
@ -72,6 +76,7 @@ NTSTATUS SvcStart(FSP_SERVICE *Service, ULONG argc, PWSTR *argv)
|
|||||||
break;
|
break;
|
||||||
case L'u':
|
case L'u':
|
||||||
argtos(VolumePrefix);
|
argtos(VolumePrefix);
|
||||||
|
if (0 != VolumePrefix && L'\0' != VolumePrefix[0])
|
||||||
Flags = MemfsNet;
|
Flags = MemfsNet;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -93,6 +98,8 @@ NTSTATUS SvcStart(FSP_SERVICE *Service, ULONG argc, PWSTR *argv)
|
|||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FspFileSystemSetDebugLog(MemfsFileSystem(Memfs), DebugFlags);
|
||||||
|
|
||||||
if (0 != MountPoint && L'\0' != MountPoint[0])
|
if (0 != MountPoint && L'\0' != MountPoint[0])
|
||||||
{
|
{
|
||||||
Result = FspFileSystemSetMountPoint(MemfsFileSystem(Memfs),
|
Result = FspFileSystemSetMountPoint(MemfsFileSystem(Memfs),
|
||||||
@ -116,7 +123,8 @@ NTSTATUS SvcStart(FSP_SERVICE *Service, ULONG argc, PWSTR *argv)
|
|||||||
info(L"%s -t %ld -n %ld -s %ld%s%s%s%s%s%s",
|
info(L"%s -t %ld -n %ld -s %ld%s%s%s%s%s%s",
|
||||||
L"" PROGNAME, FileInfoTimeout, MaxFileNodes, MaxFileSize,
|
L"" PROGNAME, FileInfoTimeout, MaxFileNodes, MaxFileSize,
|
||||||
RootSddl ? L" -S " : L"", RootSddl ? RootSddl : L"",
|
RootSddl ? L" -S " : L"", RootSddl ? RootSddl : L"",
|
||||||
VolumePrefix ? L" -u " : L"", VolumePrefix ? VolumePrefix : L"",
|
0 != VolumePrefix && L'\0' != VolumePrefix[0] ? L" -u " : L"",
|
||||||
|
0 != VolumePrefix && L'\0' != VolumePrefix[0] ? VolumePrefix : L"",
|
||||||
MountPoint ? L" -m " : L"", MountPoint ? MountPoint : L"");
|
MountPoint ? L" -m " : L"", MountPoint ? MountPoint : L"");
|
||||||
|
|
||||||
Service->UserContext = Memfs;
|
Service->UserContext = Memfs;
|
||||||
@ -133,6 +141,7 @@ usage:
|
|||||||
"usage: %s OPTIONS\n"
|
"usage: %s OPTIONS\n"
|
||||||
"\n"
|
"\n"
|
||||||
"options:\n"
|
"options:\n"
|
||||||
|
" -d DebugFlags [-1: enable all debug logs]\n"
|
||||||
" -t FileInfoTimeout [millis]\n"
|
" -t FileInfoTimeout [millis]\n"
|
||||||
" -n MaxFileNodes\n"
|
" -n MaxFileNodes\n"
|
||||||
" -s MaxFileSize [bytes]\n"
|
" -s MaxFileSize [bytes]\n"
|
||||||
|
@ -79,7 +79,6 @@ typedef struct _MEMFS
|
|||||||
ULONG MaxFileSize;
|
ULONG MaxFileSize;
|
||||||
UINT16 VolumeLabelLength;
|
UINT16 VolumeLabelLength;
|
||||||
WCHAR VolumeLabel[32];
|
WCHAR VolumeLabel[32];
|
||||||
CRITICAL_SECTION Lock;
|
|
||||||
} MEMFS;
|
} MEMFS;
|
||||||
|
|
||||||
static inline
|
static inline
|
||||||
@ -274,7 +273,7 @@ BOOLEAN MemfsFileNodeMapEnumerateDescendants(MEMFS_FILE_NODE_MAP *FileNodeMap, M
|
|||||||
|
|
||||||
static NTSTATUS SetFileSize(FSP_FILE_SYSTEM *FileSystem,
|
static NTSTATUS SetFileSize(FSP_FILE_SYSTEM *FileSystem,
|
||||||
FSP_FSCTL_TRANSACT_REQ *Request,
|
FSP_FSCTL_TRANSACT_REQ *Request,
|
||||||
PVOID FileNode0, UINT64 FileSize,
|
PVOID FileNode0, UINT64 NewSize, BOOLEAN SetAllocationSize,
|
||||||
FSP_FSCTL_FILE_INFO *FileInfo);
|
FSP_FSCTL_FILE_INFO *FileInfo);
|
||||||
|
|
||||||
static NTSTATUS GetVolumeInfo(FSP_FILE_SYSTEM *FileSystem,
|
static NTSTATUS GetVolumeInfo(FSP_FILE_SYSTEM *FileSystem,
|
||||||
@ -379,7 +378,8 @@ static NTSTATUS Create(FSP_FILE_SYSTEM *FileSystem,
|
|||||||
if (!NT_SUCCESS(Result))
|
if (!NT_SUCCESS(Result))
|
||||||
return Result;
|
return Result;
|
||||||
|
|
||||||
FileNode->FileInfo.FileAttributes = FileAttributes;
|
FileNode->FileInfo.FileAttributes = (FileAttributes & FILE_ATTRIBUTE_DIRECTORY) ?
|
||||||
|
FileAttributes : FileAttributes | FILE_ATTRIBUTE_ARCHIVE;
|
||||||
|
|
||||||
if (0 != SecurityDescriptor)
|
if (0 != SecurityDescriptor)
|
||||||
{
|
{
|
||||||
@ -437,7 +437,19 @@ static NTSTATUS Open(FSP_FILE_SYSTEM *FileSystem,
|
|||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
FileNode->FileInfo.LastAccessTime = MemfsGetSystemTime();
|
/*
|
||||||
|
* NTFS and FastFat do this at Cleanup time, but we are going to cheat.
|
||||||
|
*
|
||||||
|
* To properly implement this we should maintain some state of whether
|
||||||
|
* we modified the file or not. Alternatively we could have the driver
|
||||||
|
* report to us at Cleanup time whether the file was modified. [The
|
||||||
|
* driver does not currently maintain the FO_FILE_MODIFIED bit however.]
|
||||||
|
*
|
||||||
|
* TBD.
|
||||||
|
*/
|
||||||
|
if (0 == (FileNode->FileInfo.FileAttributes & FILE_ATTRIBUTE_DIRECTORY) &&
|
||||||
|
Request->Req.Create.DesiredAccess & (FILE_WRITE_DATA | FILE_APPEND_DATA))
|
||||||
|
FileNode->FileInfo.FileAttributes |= FILE_ATTRIBUTE_ARCHIVE;
|
||||||
|
|
||||||
FileNode->RefCount++;
|
FileNode->RefCount++;
|
||||||
*PFileNode = FileNode;
|
*PFileNode = FileNode;
|
||||||
@ -455,9 +467,9 @@ NTSTATUS Overwrite(FSP_FILE_SYSTEM *FileSystem,
|
|||||||
MEMFS_FILE_NODE *FileNode = (MEMFS_FILE_NODE *)FileNode0;
|
MEMFS_FILE_NODE *FileNode = (MEMFS_FILE_NODE *)FileNode0;
|
||||||
|
|
||||||
if (ReplaceFileAttributes)
|
if (ReplaceFileAttributes)
|
||||||
FileNode->FileInfo.FileAttributes = FileAttributes;
|
FileNode->FileInfo.FileAttributes = FileAttributes | FILE_ATTRIBUTE_ARCHIVE;
|
||||||
else
|
else
|
||||||
FileNode->FileInfo.FileAttributes |= FileAttributes;
|
FileNode->FileInfo.FileAttributes |= FileAttributes | FILE_ATTRIBUTE_ARCHIVE;
|
||||||
|
|
||||||
FileNode->FileInfo.FileSize = 0;
|
FileNode->FileInfo.FileSize = 0;
|
||||||
FileNode->FileInfo.LastWriteTime =
|
FileNode->FileInfo.LastWriteTime =
|
||||||
@ -552,7 +564,7 @@ static NTSTATUS Write(FSP_FILE_SYSTEM *FileSystem,
|
|||||||
Offset = FileNode->FileInfo.FileSize;
|
Offset = FileNode->FileInfo.FileSize;
|
||||||
EndOffset = Offset + Length;
|
EndOffset = Offset + Length;
|
||||||
if (EndOffset > FileNode->FileInfo.FileSize)
|
if (EndOffset > FileNode->FileInfo.FileSize)
|
||||||
SetFileSize(FileSystem, Request, FileNode, EndOffset, FileInfo);
|
SetFileSize(FileSystem, Request, FileNode, EndOffset, FALSE, FileInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy((PUINT8)FileNode->FileData + Offset, Buffer, (size_t)(EndOffset - Offset));
|
memcpy((PUINT8)FileNode->FileData + Offset, Buffer, (size_t)(EndOffset - Offset));
|
||||||
@ -605,59 +617,52 @@ static NTSTATUS SetBasicInfo(FSP_FILE_SYSTEM *FileSystem,
|
|||||||
return STATUS_SUCCESS;
|
return STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static NTSTATUS SetAllocationSize(FSP_FILE_SYSTEM *FileSystem,
|
static NTSTATUS SetFileSize(FSP_FILE_SYSTEM *FileSystem,
|
||||||
FSP_FSCTL_TRANSACT_REQ *Request,
|
FSP_FSCTL_TRANSACT_REQ *Request,
|
||||||
PVOID FileNode0, UINT64 AllocationSize,
|
PVOID FileNode0, UINT64 NewSize, BOOLEAN SetAllocationSize,
|
||||||
FSP_FSCTL_FILE_INFO *FileInfo)
|
FSP_FSCTL_FILE_INFO *FileInfo)
|
||||||
{
|
{
|
||||||
MEMFS *Memfs = (MEMFS *)FileSystem->UserContext;
|
MEMFS *Memfs = (MEMFS *)FileSystem->UserContext;
|
||||||
MEMFS_FILE_NODE *FileNode = (MEMFS_FILE_NODE *)FileNode0;
|
MEMFS_FILE_NODE *FileNode = (MEMFS_FILE_NODE *)FileNode0;
|
||||||
PVOID FileData;
|
|
||||||
|
|
||||||
if (FileNode->FileInfo.AllocationSize != AllocationSize)
|
if (SetAllocationSize)
|
||||||
{
|
{
|
||||||
if (AllocationSize > Memfs->MaxFileSize)
|
if (FileNode->FileInfo.AllocationSize != NewSize)
|
||||||
|
{
|
||||||
|
if (NewSize > Memfs->MaxFileSize)
|
||||||
return STATUS_DISK_FULL;
|
return STATUS_DISK_FULL;
|
||||||
|
|
||||||
FileData = realloc(FileNode->FileData, (size_t)AllocationSize);
|
PVOID FileData = realloc(FileNode->FileData, (size_t)NewSize);
|
||||||
if (0 == FileData)
|
if (0 == FileData && 0 != NewSize)
|
||||||
return STATUS_INSUFFICIENT_RESOURCES;
|
return STATUS_INSUFFICIENT_RESOURCES;
|
||||||
|
|
||||||
FileNode->FileData = FileData;
|
FileNode->FileData = FileData;
|
||||||
|
|
||||||
FileNode->FileInfo.AllocationSize = AllocationSize;
|
FileNode->FileInfo.AllocationSize = NewSize;
|
||||||
if (FileNode->FileInfo.FileSize > AllocationSize)
|
if (FileNode->FileInfo.FileSize > NewSize)
|
||||||
FileNode->FileInfo.FileSize = AllocationSize;
|
FileNode->FileInfo.FileSize = NewSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
*FileInfo = FileNode->FileInfo;
|
|
||||||
|
|
||||||
return STATUS_SUCCESS;
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
static NTSTATUS SetFileSize(FSP_FILE_SYSTEM *FileSystem,
|
|
||||||
FSP_FSCTL_TRANSACT_REQ *Request,
|
|
||||||
PVOID FileNode0, UINT64 FileSize,
|
|
||||||
FSP_FSCTL_FILE_INFO *FileInfo)
|
|
||||||
{
|
{
|
||||||
MEMFS_FILE_NODE *FileNode = (MEMFS_FILE_NODE *)FileNode0;
|
if (FileNode->FileInfo.FileSize != NewSize)
|
||||||
|
|
||||||
if (FileNode->FileInfo.FileSize != FileSize)
|
|
||||||
{
|
{
|
||||||
if (FileNode->FileInfo.AllocationSize < FileSize)
|
if (FileNode->FileInfo.AllocationSize < NewSize)
|
||||||
{
|
{
|
||||||
UINT64 AllocationUnit = MEMFS_SECTOR_SIZE * MEMFS_SECTORS_PER_ALLOCATION_UNIT;
|
UINT64 AllocationUnit = MEMFS_SECTOR_SIZE * MEMFS_SECTORS_PER_ALLOCATION_UNIT;
|
||||||
UINT64 AllocationSize = (FileSize + AllocationUnit - 1) / AllocationUnit * AllocationUnit;
|
UINT64 AllocationSize = (NewSize + AllocationUnit - 1) / AllocationUnit * AllocationUnit;
|
||||||
|
|
||||||
NTSTATUS Result = SetAllocationSize(FileSystem, Request, FileNode, AllocationSize, FileInfo);
|
NTSTATUS Result = SetFileSize(FileSystem, Request, FileNode, AllocationSize, TRUE,
|
||||||
|
FileInfo);
|
||||||
if (!NT_SUCCESS(Result))
|
if (!NT_SUCCESS(Result))
|
||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FileNode->FileInfo.FileSize < FileSize)
|
if (FileNode->FileInfo.FileSize < NewSize)
|
||||||
memset((PUINT8)FileNode->FileData + FileNode->FileInfo.FileSize, 0,
|
memset((PUINT8)FileNode->FileData + FileNode->FileInfo.FileSize, 0,
|
||||||
(size_t)(FileSize - FileNode->FileInfo.FileSize));
|
(size_t)(NewSize - FileNode->FileInfo.FileSize));
|
||||||
FileNode->FileInfo.FileSize = FileSize;
|
FileNode->FileInfo.FileSize = NewSize;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*FileInfo = FileNode->FileInfo;
|
*FileInfo = FileNode->FileInfo;
|
||||||
@ -940,7 +945,6 @@ static FSP_FILE_SYSTEM_INTERFACE MemfsInterface =
|
|||||||
Flush,
|
Flush,
|
||||||
GetFileInfo,
|
GetFileInfo,
|
||||||
SetBasicInfo,
|
SetBasicInfo,
|
||||||
SetAllocationSize,
|
|
||||||
SetFileSize,
|
SetFileSize,
|
||||||
CanDelete,
|
CanDelete,
|
||||||
Rename,
|
Rename,
|
||||||
@ -949,20 +953,6 @@ static FSP_FILE_SYSTEM_INTERFACE MemfsInterface =
|
|||||||
ReadDirectory,
|
ReadDirectory,
|
||||||
};
|
};
|
||||||
|
|
||||||
static VOID MemfsEnterOperation(FSP_FILE_SYSTEM *FileSystem,
|
|
||||||
FSP_FSCTL_TRANSACT_REQ *Request, FSP_FSCTL_TRANSACT_RSP *Response)
|
|
||||||
{
|
|
||||||
MEMFS *Memfs = (MEMFS *)FileSystem->UserContext;
|
|
||||||
EnterCriticalSection(&Memfs->Lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
static VOID MemfsLeaveOperation(FSP_FILE_SYSTEM *FileSystem,
|
|
||||||
FSP_FSCTL_TRANSACT_REQ *Request, FSP_FSCTL_TRANSACT_RSP *Response)
|
|
||||||
{
|
|
||||||
MEMFS *Memfs = (MEMFS *)FileSystem->UserContext;
|
|
||||||
LeaveCriticalSection(&Memfs->Lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
NTSTATUS MemfsCreate(
|
NTSTATUS MemfsCreate(
|
||||||
ULONG Flags,
|
ULONG Flags,
|
||||||
ULONG FileInfoTimeout,
|
ULONG FileInfoTimeout,
|
||||||
@ -1037,11 +1027,10 @@ NTSTATUS MemfsCreate(
|
|||||||
Memfs->VolumeLabelLength = sizeof L"MEMFS" - sizeof(WCHAR);
|
Memfs->VolumeLabelLength = sizeof L"MEMFS" - sizeof(WCHAR);
|
||||||
memcpy(Memfs->VolumeLabel, L"MEMFS", Memfs->VolumeLabelLength);
|
memcpy(Memfs->VolumeLabel, L"MEMFS", Memfs->VolumeLabelLength);
|
||||||
|
|
||||||
InitializeCriticalSection(&Memfs->Lock);
|
#if 0
|
||||||
|
FspFileSystemSetOperationGuardStrategy(Memfs->FileSystem,
|
||||||
FspFileSystemSetOperationGuard(Memfs->FileSystem,
|
FSP_FILE_SYSTEM_OPERATION_GUARD_STRATEGY_COARSE);
|
||||||
MemfsEnterOperation,
|
#endif
|
||||||
MemfsLeaveOperation);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create root directory.
|
* Create root directory.
|
||||||
@ -1086,8 +1075,6 @@ NTSTATUS MemfsCreate(
|
|||||||
|
|
||||||
VOID MemfsDelete(MEMFS *Memfs)
|
VOID MemfsDelete(MEMFS *Memfs)
|
||||||
{
|
{
|
||||||
DeleteCriticalSection(&Memfs->Lock);
|
|
||||||
|
|
||||||
FspFileSystemDelete(Memfs->FileSystem);
|
FspFileSystemDelete(Memfs->FileSystem);
|
||||||
|
|
||||||
MemfsFileNodeMapDelete(Memfs->FileNodeMap);
|
MemfsFileNodeMapDelete(Memfs->FileNodeMap);
|
||||||
|
32
tst/secret/secret.c
Normal file
32
tst/secret/secret.c
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* Compile:
|
||||||
|
* - cl secret.c
|
||||||
|
*
|
||||||
|
* Register:
|
||||||
|
* - secret.reg (fix Executable path first)
|
||||||
|
*
|
||||||
|
* Run:
|
||||||
|
* - launchctl-x64 startWithSecret secret 1 nopass
|
||||||
|
* - launchctl-x64 startWithSecret secret 1 foobar
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
char pass[256];
|
||||||
|
|
||||||
|
gets(pass);
|
||||||
|
if (0 == strcmp("foobar", pass))
|
||||||
|
{
|
||||||
|
puts("OK");
|
||||||
|
fprintf(stderr, "OK secret=\"%s\"\n", pass);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
puts("KO");
|
||||||
|
fprintf(stderr, "KO secret=\"%s\"\n", pass);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
BIN
tst/secret/secret.reg
Normal file
BIN
tst/secret/secret.reg
Normal file
Binary file not shown.
355
tst/winfsp-tests/fuse-opt-test.c
Normal file
355
tst/winfsp-tests/fuse-opt-test.c
Normal file
@ -0,0 +1,355 @@
|
|||||||
|
#include <fuse/fuse_opt.h>
|
||||||
|
#include <tlib/testsuite.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
struct data
|
||||||
|
{
|
||||||
|
int fortytwo;
|
||||||
|
int a, b, c, d, e, f, g, h;
|
||||||
|
int i, j, k, l, m, n, o, p;
|
||||||
|
char *q, *r, *s, *t;
|
||||||
|
int u, v, V;
|
||||||
|
char *w;
|
||||||
|
short x;
|
||||||
|
long y;
|
||||||
|
long long z;
|
||||||
|
int dec, neg, hex, oct;
|
||||||
|
int sel;
|
||||||
|
char *esc; int ESC;
|
||||||
|
int arg_discard, arg_keep;
|
||||||
|
int opt_discard, opt_keep;
|
||||||
|
int nonopt_discard, nonopt_keep;
|
||||||
|
};
|
||||||
|
|
||||||
|
static int fuse_opt_parse_test_proc(void *data0, const char *arg, int key,
|
||||||
|
struct fuse_args *outargs)
|
||||||
|
{
|
||||||
|
struct data *data = data0;
|
||||||
|
|
||||||
|
switch (key)
|
||||||
|
{
|
||||||
|
default:
|
||||||
|
ASSERT(0);
|
||||||
|
return -1;
|
||||||
|
case FUSE_OPT_KEY_OPT:
|
||||||
|
if (0 == strcmp("--arg-discard", arg))
|
||||||
|
{
|
||||||
|
data->arg_discard++;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (0 == strcmp("--arg-keep", arg))
|
||||||
|
{
|
||||||
|
data->arg_keep++;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (0 == strcmp("opt-discard", arg))
|
||||||
|
{
|
||||||
|
data->opt_discard++;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (0 == strcmp("opt-keep", arg))
|
||||||
|
{
|
||||||
|
data->opt_keep++;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
ASSERT(0);
|
||||||
|
return -1;
|
||||||
|
case FUSE_OPT_KEY_NONOPT:
|
||||||
|
if (0 == strcmp("--discard", arg))
|
||||||
|
{
|
||||||
|
data->nonopt_discard++;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (0 == strcmp("--keep", arg))
|
||||||
|
{
|
||||||
|
data->nonopt_keep++;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
ASSERT(0);
|
||||||
|
return -1;
|
||||||
|
case 'a':
|
||||||
|
ASSERT(0);
|
||||||
|
return -1;
|
||||||
|
case 'b':
|
||||||
|
ASSERT(0 == strcmp("-b", arg));
|
||||||
|
data->b = 'B';
|
||||||
|
return 1;
|
||||||
|
case 'c':
|
||||||
|
ASSERT(0);
|
||||||
|
return -1;
|
||||||
|
case 'd':
|
||||||
|
ASSERT(0 == strcmp("--dlong", arg));
|
||||||
|
data->d = 'D';
|
||||||
|
return 1;
|
||||||
|
case 'e':
|
||||||
|
ASSERT(0);
|
||||||
|
return -1;
|
||||||
|
case 'f':
|
||||||
|
ASSERT(0 == strcmp("f", arg));
|
||||||
|
data->f = 'F';
|
||||||
|
return 1;
|
||||||
|
case 'g':
|
||||||
|
ASSERT(0);
|
||||||
|
return -1;
|
||||||
|
case 'h':
|
||||||
|
ASSERT(0 == strcmp("hlong", arg));
|
||||||
|
data->h = 'H';
|
||||||
|
return 1;
|
||||||
|
case 'i':
|
||||||
|
ASSERT(0);
|
||||||
|
return -1;
|
||||||
|
case 'j':
|
||||||
|
ASSERT(0 == strcmp("-j=74", arg));
|
||||||
|
data->j = 'J';
|
||||||
|
return 1;
|
||||||
|
case 'k':
|
||||||
|
ASSERT(0);
|
||||||
|
return -1;
|
||||||
|
case 'l':
|
||||||
|
ASSERT(0 == strcmp("--llong=76", arg));
|
||||||
|
data->l = 'L';
|
||||||
|
return 1;
|
||||||
|
case 'm':
|
||||||
|
ASSERT(0);
|
||||||
|
return -1;
|
||||||
|
case 'n':
|
||||||
|
ASSERT(0 == strcmp("n=78", arg));
|
||||||
|
data->n = 'N';
|
||||||
|
return 1;
|
||||||
|
case 'o':
|
||||||
|
ASSERT(0);
|
||||||
|
return -1;
|
||||||
|
case 'p':
|
||||||
|
ASSERT(0 == strcmp("plong=80", arg));
|
||||||
|
data->p = 'P';
|
||||||
|
return 1;
|
||||||
|
case 'q':
|
||||||
|
ASSERT(0);
|
||||||
|
return -1;
|
||||||
|
case 'r':
|
||||||
|
ASSERT(0);
|
||||||
|
return -1;
|
||||||
|
case 's':
|
||||||
|
ASSERT(0);
|
||||||
|
return -1;
|
||||||
|
case 't':
|
||||||
|
ASSERT(0);
|
||||||
|
return -1;
|
||||||
|
case 'u':
|
||||||
|
ASSERT(0);
|
||||||
|
return -1;
|
||||||
|
case 'v':
|
||||||
|
ASSERT(0 == strcmp("-v86", arg));
|
||||||
|
data->v = 'V';
|
||||||
|
return 1;
|
||||||
|
case 'V':
|
||||||
|
ASSERT(0 == strcmp("-V118", arg));
|
||||||
|
data->V = 'v';
|
||||||
|
return 1;
|
||||||
|
case 'w':
|
||||||
|
ASSERT(0);
|
||||||
|
return -1;
|
||||||
|
case 'x':
|
||||||
|
ASSERT(0);
|
||||||
|
return -1;
|
||||||
|
case 'y':
|
||||||
|
ASSERT(0);
|
||||||
|
return -1;
|
||||||
|
case 'z':
|
||||||
|
ASSERT(0);
|
||||||
|
return -1;
|
||||||
|
case 'ESC':
|
||||||
|
ASSERT(0 == strcmp("ESC=\\FOO,BAR\\", arg));
|
||||||
|
data->ESC = 1;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void fuse_opt_parse_test(void)
|
||||||
|
{
|
||||||
|
static struct fuse_opt opts[] =
|
||||||
|
{
|
||||||
|
{ "-a", offsetof(struct data, a), 'a' },
|
||||||
|
FUSE_OPT_KEY("-b", 'b'),
|
||||||
|
{ "--clong", offsetof(struct data, c), 'c' },
|
||||||
|
FUSE_OPT_KEY("--dlong", 'd'),
|
||||||
|
{ "e", offsetof(struct data, e), 'e' },
|
||||||
|
FUSE_OPT_KEY("f", 'f'),
|
||||||
|
{ "glong", offsetof(struct data, g), 'g' },
|
||||||
|
FUSE_OPT_KEY("hlong", 'h'),
|
||||||
|
|
||||||
|
{ "-i=", offsetof(struct data, i), 'i' },
|
||||||
|
FUSE_OPT_KEY("-j=", 'j'),
|
||||||
|
{ "--klong=", offsetof(struct data, k), 'k' },
|
||||||
|
FUSE_OPT_KEY("--llong=", 'l'),
|
||||||
|
{ "m=", offsetof(struct data, m), 'm' },
|
||||||
|
FUSE_OPT_KEY("n=", 'n'),
|
||||||
|
{ "olong=", offsetof(struct data, o), 'o' },
|
||||||
|
FUSE_OPT_KEY("plong=", 'p'),
|
||||||
|
|
||||||
|
{ "-q=%s", offsetof(struct data, q), 'q' },
|
||||||
|
{ "--rlong=%s", offsetof(struct data, r), 'r' },
|
||||||
|
{ "s=%s", offsetof(struct data, s), 's' },
|
||||||
|
{ "tlong=%s", offsetof(struct data, t), 't' },
|
||||||
|
|
||||||
|
{ "-u ", offsetof(struct data, u), 'u' },
|
||||||
|
FUSE_OPT_KEY("-v ", 'v'),
|
||||||
|
FUSE_OPT_KEY("-V ", 'V'),
|
||||||
|
|
||||||
|
{ "-w %s", offsetof(struct data, w), 'w' },
|
||||||
|
|
||||||
|
{ "-x=%hi", offsetof(struct data, x), 'x' },
|
||||||
|
{ "-y=%li", offsetof(struct data, y), 'y' },
|
||||||
|
{ "-z=%lli", offsetof(struct data, z), 'z' },
|
||||||
|
|
||||||
|
{ "--dec=%d", offsetof(struct data, dec), 'dec' },
|
||||||
|
{ "--neg=%d", offsetof(struct data, neg), 'neg' },
|
||||||
|
{ "--hex=%x", offsetof(struct data, hex), 'hex' },
|
||||||
|
{ "--oct=%o", offsetof(struct data, oct), 'oct' },
|
||||||
|
|
||||||
|
{ "--sel=fortyone", offsetof(struct data, sel), 141 },
|
||||||
|
{ "--sel=fortytwo", offsetof(struct data, sel), 142 },
|
||||||
|
{ "--sel=fortythree", offsetof(struct data, sel), 143 },
|
||||||
|
|
||||||
|
{ "esc=%s", offsetof(struct data, esc), 'esc' },
|
||||||
|
FUSE_OPT_KEY("ESC=", 'ESC'),
|
||||||
|
|
||||||
|
FUSE_OPT_KEY("--discard", FUSE_OPT_KEY_DISCARD),
|
||||||
|
FUSE_OPT_KEY("--keep", FUSE_OPT_KEY_KEEP),
|
||||||
|
|
||||||
|
FUSE_OPT_END,
|
||||||
|
};
|
||||||
|
static char *argv[] =
|
||||||
|
{
|
||||||
|
"exec",
|
||||||
|
"-a",
|
||||||
|
"-b",
|
||||||
|
"--clong",
|
||||||
|
"--dlong",
|
||||||
|
"-o", "e,f",
|
||||||
|
"-oglong,hlong",
|
||||||
|
"-i=73",
|
||||||
|
"-j=74",
|
||||||
|
"--klong=75",
|
||||||
|
"--llong=76",
|
||||||
|
"-om=77",
|
||||||
|
"-o", "n=78,olong=79,plong=80",
|
||||||
|
"-q=QqQq",
|
||||||
|
"--rlong=RrRrRrRr",
|
||||||
|
"-os=SsSs",
|
||||||
|
"-otlong=TtTtTtTt",
|
||||||
|
"-u85",
|
||||||
|
"-v", "86",
|
||||||
|
"-V118",
|
||||||
|
"-wWwWw",
|
||||||
|
"-x=65537",
|
||||||
|
"-y=040000000001",
|
||||||
|
"-z=0x100000001",
|
||||||
|
"--dec=+1234567890",
|
||||||
|
"--neg=-1234567890",
|
||||||
|
"--hex=ABCDEF",
|
||||||
|
"--oct=12345670",
|
||||||
|
"--sel=fortytwo",
|
||||||
|
"-oesc=\\\\foo\\,bar\\\\,ESC=\\\\FOO\\,BAR\\\\",
|
||||||
|
"--discard",
|
||||||
|
"--keep",
|
||||||
|
"--arg-discard",
|
||||||
|
"--arg-keep",
|
||||||
|
"-oopt-discard",
|
||||||
|
"-oopt-keep",
|
||||||
|
"--",
|
||||||
|
"--discard",
|
||||||
|
"--keep",
|
||||||
|
0
|
||||||
|
};
|
||||||
|
static char *outargv[] =
|
||||||
|
{
|
||||||
|
"exec",
|
||||||
|
"-o", "f,hlong,n=78,plong=80,ESC=\\\\FOO\\,BAR\\\\,opt-keep",
|
||||||
|
"-b",
|
||||||
|
"--dlong",
|
||||||
|
"-j=74",
|
||||||
|
"--llong=76",
|
||||||
|
"-v86",
|
||||||
|
"-V118",
|
||||||
|
"--keep",
|
||||||
|
"--arg-keep",
|
||||||
|
"--",
|
||||||
|
"--discard",
|
||||||
|
0
|
||||||
|
};
|
||||||
|
struct fuse_args args = FUSE_ARGS_INIT(0, 0);
|
||||||
|
struct data data;
|
||||||
|
int result;
|
||||||
|
|
||||||
|
args.argc = sizeof argv / sizeof argv[0] - 1;
|
||||||
|
args.argv = argv;
|
||||||
|
|
||||||
|
memset(&data, 0, sizeof data);
|
||||||
|
data.fortytwo = 42;
|
||||||
|
result = fuse_opt_parse(&args, &data, opts, fuse_opt_parse_test_proc);
|
||||||
|
ASSERT(0 == result);
|
||||||
|
|
||||||
|
ASSERT(42 == data.fortytwo);
|
||||||
|
ASSERT('a' == data.a);
|
||||||
|
ASSERT('B' == data.b);
|
||||||
|
ASSERT('c' == data.c);
|
||||||
|
ASSERT('D' == data.d);
|
||||||
|
ASSERT('e' == data.e);
|
||||||
|
ASSERT('F' == data.f);
|
||||||
|
ASSERT('g' == data.g);
|
||||||
|
ASSERT('H' == data.h);
|
||||||
|
ASSERT('i' == data.i);
|
||||||
|
ASSERT('J' == data.j);
|
||||||
|
ASSERT('k' == data.k);
|
||||||
|
ASSERT('L' == data.l);
|
||||||
|
ASSERT('m' == data.m);
|
||||||
|
ASSERT('N' == data.n);
|
||||||
|
ASSERT('o' == data.o);
|
||||||
|
ASSERT('P' == data.p);
|
||||||
|
ASSERT(0 == strcmp("QqQq", data.q));
|
||||||
|
ASSERT(0 == strcmp("RrRrRrRr", data.r));
|
||||||
|
ASSERT(0 == strcmp("SsSs", data.s));
|
||||||
|
ASSERT(0 == strcmp("TtTtTtTt", data.t));
|
||||||
|
ASSERT('u' == data.u);
|
||||||
|
ASSERT('V' == data.v);
|
||||||
|
ASSERT('v' == data.V);
|
||||||
|
ASSERT(0 == strcmp("WwWw", data.w));
|
||||||
|
ASSERT(1 == data.x);
|
||||||
|
ASSERT((long)040000000001 == data.y);
|
||||||
|
ASSERT((long long)0x100000001 == data.z);
|
||||||
|
ASSERT(+1234567890 == data.dec);
|
||||||
|
ASSERT(-1234567890 == data.neg);
|
||||||
|
ASSERT(0xABCDEF == data.hex);
|
||||||
|
ASSERT(012345670 == data.oct);
|
||||||
|
ASSERT(142 == data.sel);
|
||||||
|
ASSERT(0 == strcmp("\\foo,bar\\", data.esc));
|
||||||
|
ASSERT(1 == data.ESC);
|
||||||
|
ASSERT(1 == data.arg_discard);
|
||||||
|
ASSERT(1 == data.arg_keep);
|
||||||
|
ASSERT(1 == data.opt_discard);
|
||||||
|
ASSERT(1 == data.opt_keep);
|
||||||
|
ASSERT(1 == data.nonopt_discard);
|
||||||
|
ASSERT(1 == data.nonopt_keep);
|
||||||
|
|
||||||
|
ASSERT(args.argc == sizeof outargv / sizeof outargv[0] - 1);
|
||||||
|
for (int i = 0; args.argc > i; i++)
|
||||||
|
ASSERT(0 == strcmp(args.argv[i], outargv[i]));
|
||||||
|
ASSERT(0 == args.argv[args.argc]);
|
||||||
|
ASSERT(args.allocated);
|
||||||
|
|
||||||
|
fuse_opt_free_args(&args);
|
||||||
|
|
||||||
|
free(data.q);
|
||||||
|
free(data.r);
|
||||||
|
free(data.s);
|
||||||
|
free(data.t);
|
||||||
|
free(data.w);
|
||||||
|
free(data.esc);
|
||||||
|
}
|
||||||
|
|
||||||
|
void fuse_opt_tests(void)
|
||||||
|
{
|
||||||
|
TEST(fuse_opt_parse_test);
|
||||||
|
}
|
@ -313,14 +313,11 @@ static void delete_access_dotest(ULONG Flags, PWSTR Prefix, ULONG FileInfoTimeou
|
|||||||
Success = DeleteFileW(FilePath);
|
Success = DeleteFileW(FilePath);
|
||||||
ASSERT(Success);
|
ASSERT(Success);
|
||||||
|
|
||||||
/* enable this test when we have proper FILE_DELETE_CHILD support on the parent directory! */
|
static PWSTR Sddl = L"D:P(D;;GA;;;SY)(D;;GA;;;BA)(D;;GA;;;WD)";
|
||||||
#if 0
|
|
||||||
static PWSTR Sddl0 = L"D:P(D;;GA;;;SY)(D;;GA;;;BA)(D;;GA;;;WD)";
|
|
||||||
static PWSTR Sddl1 = L"D:P(A;;GA;;;SY)(A;;GA;;;BA)(A;;GA;;;WD)";
|
|
||||||
PSECURITY_DESCRIPTOR SecurityDescriptor;
|
PSECURITY_DESCRIPTOR SecurityDescriptor;
|
||||||
SECURITY_ATTRIBUTES SecurityAttributes = { 0 };
|
SECURITY_ATTRIBUTES SecurityAttributes = { 0 };
|
||||||
|
|
||||||
Success = ConvertStringSecurityDescriptorToSecurityDescriptorW(Sddl0, SDDL_REVISION_1, &SecurityDescriptor, 0);
|
Success = ConvertStringSecurityDescriptorToSecurityDescriptorW(Sddl, SDDL_REVISION_1, &SecurityDescriptor, 0);
|
||||||
ASSERT(Success);
|
ASSERT(Success);
|
||||||
|
|
||||||
SecurityAttributes.nLength = sizeof SecurityAttributes;
|
SecurityAttributes.nLength = sizeof SecurityAttributes;
|
||||||
@ -332,28 +329,10 @@ static void delete_access_dotest(ULONG Flags, PWSTR Prefix, ULONG FileInfoTimeou
|
|||||||
ASSERT(INVALID_HANDLE_VALUE != Handle);
|
ASSERT(INVALID_HANDLE_VALUE != Handle);
|
||||||
CloseHandle(Handle);
|
CloseHandle(Handle);
|
||||||
|
|
||||||
LocalFree(SecurityDescriptor);
|
|
||||||
|
|
||||||
Success = DeleteFileW(FilePath);
|
|
||||||
ASSERT(!Success);
|
|
||||||
ASSERT(ERROR_ACCESS_DENIED == GetLastError());
|
|
||||||
|
|
||||||
Success = ConvertStringSecurityDescriptorToSecurityDescriptorW(Sddl1, SDDL_REVISION_1, &SecurityDescriptor, 0);
|
|
||||||
ASSERT(Success);
|
|
||||||
|
|
||||||
Handle = CreateFileW(FilePath,
|
|
||||||
GENERIC_READ | GENERIC_WRITE | WRITE_DAC, FILE_SHARE_READ | FILE_SHARE_WRITE, 0,
|
|
||||||
OPEN_EXISTING, 0, 0);
|
|
||||||
ASSERT(INVALID_HANDLE_VALUE != Handle);
|
|
||||||
Success = SetKernelObjectSecurity(Handle, DACL_SECURITY_INFORMATION, SecurityDescriptor);
|
|
||||||
ASSERT(Success);
|
|
||||||
CloseHandle(Handle);
|
|
||||||
|
|
||||||
LocalFree(SecurityDescriptor);
|
|
||||||
|
|
||||||
Success = DeleteFileW(FilePath);
|
Success = DeleteFileW(FilePath);
|
||||||
ASSERT(Success);
|
ASSERT(Success);
|
||||||
#endif
|
|
||||||
|
LocalFree(SecurityDescriptor);
|
||||||
|
|
||||||
memfs_stop(memfs);
|
memfs_stop(memfs);
|
||||||
}
|
}
|
||||||
@ -508,6 +487,7 @@ void getvolinfo_dotest(ULONG Flags, PWSTR Prefix, ULONG FileInfoTimeout)
|
|||||||
ULARGE_INTEGER CallerFreeBytes;
|
ULARGE_INTEGER CallerFreeBytes;
|
||||||
ULARGE_INTEGER TotalBytes;
|
ULARGE_INTEGER TotalBytes;
|
||||||
ULARGE_INTEGER FreeBytes;
|
ULARGE_INTEGER FreeBytes;
|
||||||
|
HANDLE Handle;
|
||||||
|
|
||||||
StringCbPrintfW(FilePath, sizeof FilePath, L"%s%s\\",
|
StringCbPrintfW(FilePath, sizeof FilePath, L"%s%s\\",
|
||||||
Prefix ? L"" : L"\\\\?\\GLOBALROOT", Prefix ? Prefix : memfs_volumename(memfs));
|
Prefix ? L"" : L"\\\\?\\GLOBALROOT", Prefix ? Prefix : memfs_volumename(memfs));
|
||||||
@ -532,6 +512,21 @@ void getvolinfo_dotest(ULONG Flags, PWSTR Prefix, ULONG FileInfoTimeout)
|
|||||||
Success = GetDiskFreeSpaceExW(FilePath, &CallerFreeBytes, &TotalBytes, &FreeBytes);
|
Success = GetDiskFreeSpaceExW(FilePath, &CallerFreeBytes, &TotalBytes, &FreeBytes);
|
||||||
ASSERT(Success);
|
ASSERT(Success);
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
UINT DriveType = GetDriveTypeW(FilePath);
|
||||||
|
ASSERT(
|
||||||
|
((0 == Prefix || L'\\' != Prefix[0]) && DRIVE_FIXED == DriveType) ||
|
||||||
|
((0 != Prefix && L'\\' == Prefix[0]) && DRIVE_REMOTE == DriveType));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
Handle = CreateFileW(FilePath,
|
||||||
|
0, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING,
|
||||||
|
FILE_FLAG_BACKUP_SEMANTICS, 0);
|
||||||
|
ASSERT(INVALID_HANDLE_VALUE != Handle);
|
||||||
|
DWORD FileType = GetFileType(Handle);
|
||||||
|
ASSERT(FILE_TYPE_DISK == FileType);
|
||||||
|
CloseHandle(Handle);
|
||||||
|
|
||||||
memfs_stop(memfs);
|
memfs_stop(memfs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -276,14 +276,20 @@ static void lock_overlapped_dotest(ULONG Flags, PWSTR VolPrefix, PWSTR Prefix, U
|
|||||||
Success = LockFileEx(Handle, LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY, 0,
|
Success = LockFileEx(Handle, LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY, 0,
|
||||||
BytesPerSector, 0, &Overlapped);
|
BytesPerSector, 0, &Overlapped);
|
||||||
ASSERT(Success || ERROR_IO_PENDING == GetLastError() || ERROR_LOCK_VIOLATION == GetLastError());
|
ASSERT(Success || ERROR_IO_PENDING == GetLastError() || ERROR_LOCK_VIOLATION == GetLastError());
|
||||||
|
if (ERROR_LOCK_VIOLATION != GetLastError())
|
||||||
|
{
|
||||||
Success = GetOverlappedResult(Handle, &Overlapped, &BytesTransferred, TRUE);
|
Success = GetOverlappedResult(Handle, &Overlapped, &BytesTransferred, TRUE);
|
||||||
ASSERT(!Success && ERROR_LOCK_VIOLATION == GetLastError());
|
ASSERT(!Success && ERROR_LOCK_VIOLATION == GetLastError());
|
||||||
|
}
|
||||||
|
|
||||||
Overlapped.Offset = 0;
|
Overlapped.Offset = 0;
|
||||||
Success = WriteFile(Handle, Buffer[0], BytesPerSector, &BytesTransferred, &Overlapped);
|
Success = WriteFile(Handle, Buffer[0], BytesPerSector, &BytesTransferred, &Overlapped);
|
||||||
ASSERT(Success || ERROR_IO_PENDING == GetLastError() || ERROR_LOCK_VIOLATION == GetLastError());
|
ASSERT(Success || ERROR_IO_PENDING == GetLastError() || ERROR_LOCK_VIOLATION == GetLastError());
|
||||||
|
if (ERROR_LOCK_VIOLATION != GetLastError())
|
||||||
|
{
|
||||||
Success = GetOverlappedResult(Handle, &Overlapped, &BytesTransferred, TRUE);
|
Success = GetOverlappedResult(Handle, &Overlapped, &BytesTransferred, TRUE);
|
||||||
ASSERT(!Success && ERROR_LOCK_VIOLATION == GetLastError());
|
ASSERT(!Success && ERROR_LOCK_VIOLATION == GetLastError());
|
||||||
|
}
|
||||||
|
|
||||||
Overlapped.Offset = BytesPerSector / 2;
|
Overlapped.Offset = BytesPerSector / 2;
|
||||||
Success = UnlockFileEx(Handle, 0, BytesPerSector, 0, &Overlapped);
|
Success = UnlockFileEx(Handle, 0, BytesPerSector, 0, &Overlapped);
|
||||||
|
252
tst/winfsp-tests/posix-test.c
Normal file
252
tst/winfsp-tests/posix-test.c
Normal file
@ -0,0 +1,252 @@
|
|||||||
|
#include <winfsp/winfsp.h>
|
||||||
|
#include <tlib/testsuite.h>
|
||||||
|
#include <sddl.h>
|
||||||
|
|
||||||
|
void posix_map_sid_test(void)
|
||||||
|
{
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
PWSTR SidStr;
|
||||||
|
UINT32 Uid;
|
||||||
|
} map[] =
|
||||||
|
{
|
||||||
|
{ L"S-1-0-65534", 65534 },
|
||||||
|
{ L"S-1-0-0", 0x10000 },
|
||||||
|
{ L"S-1-1-0", 0x10100 },
|
||||||
|
{ L"S-1-2-0", 0x10200 },
|
||||||
|
{ L"S-1-2-1", 0x10201 },
|
||||||
|
{ L"S-1-3-0", 0x10300 },
|
||||||
|
{ L"S-1-3-1", 0x10301 },
|
||||||
|
{ L"S-1-3-2", 0x10302 },
|
||||||
|
{ L"S-1-3-3", 0x10303 },
|
||||||
|
{ L"S-1-3-4", 0x10304 },
|
||||||
|
{ L"S-1-5-1", 1 },
|
||||||
|
{ L"S-1-5-2", 2 },
|
||||||
|
{ L"S-1-5-3", 3 },
|
||||||
|
{ L"S-1-5-4", 4 },
|
||||||
|
{ L"S-1-5-6", 6 },
|
||||||
|
{ L"S-1-5-7", 7 },
|
||||||
|
{ L"S-1-5-8", 8 },
|
||||||
|
{ L"S-1-5-9", 9 },
|
||||||
|
{ L"S-1-5-10", 10 },
|
||||||
|
{ L"S-1-5-11", 11 },
|
||||||
|
{ L"S-1-5-12", 12 },
|
||||||
|
{ L"S-1-5-13", 13 },
|
||||||
|
{ L"S-1-5-14", 14 },
|
||||||
|
{ L"S-1-5-15", 15 },
|
||||||
|
{ L"S-1-5-17", 17 },
|
||||||
|
{ L"S-1-5-18", 18 },
|
||||||
|
{ L"S-1-5-19", 19 },
|
||||||
|
{ L"S-1-5-20", 20 },
|
||||||
|
{ L"S-1-5-32-544", 544 },
|
||||||
|
{ L"S-1-5-32-545", 545 },
|
||||||
|
{ L"S-1-5-32-546", 546 },
|
||||||
|
{ L"S-1-5-32-547", 547 },
|
||||||
|
{ L"S-1-5-32-548", 548 },
|
||||||
|
{ L"S-1-5-32-549", 549 },
|
||||||
|
{ L"S-1-5-32-550", 550 },
|
||||||
|
{ L"S-1-5-32-551", 551 },
|
||||||
|
{ L"S-1-5-32-552", 552 },
|
||||||
|
{ L"S-1-5-32-554", 554 },
|
||||||
|
{ L"S-1-5-32-555", 555 },
|
||||||
|
{ L"S-1-5-32-556", 556 },
|
||||||
|
{ L"S-1-5-32-557", 557 },
|
||||||
|
{ L"S-1-5-32-558", 558 },
|
||||||
|
{ L"S-1-5-32-559", 559 },
|
||||||
|
{ L"S-1-5-32-560", 560 },
|
||||||
|
{ L"S-1-5-32-561", 561 },
|
||||||
|
{ L"S-1-5-32-562", 562 },
|
||||||
|
{ L"S-1-5-32-573", 573 },
|
||||||
|
{ L"S-1-5-32-574", 574 },
|
||||||
|
{ L"S-1-5-32-575", 575 },
|
||||||
|
{ L"S-1-5-32-576", 576 },
|
||||||
|
{ L"S-1-5-32-577", 577 },
|
||||||
|
{ L"S-1-5-32-578", 578 },
|
||||||
|
{ L"S-1-5-32-579", 579 },
|
||||||
|
{ L"S-1-5-32-580", 580 },
|
||||||
|
{ L"S-1-5-64-10", 0x4000A },
|
||||||
|
{ L"S-1-5-64-14", 0x4000E },
|
||||||
|
{ L"S-1-5-64-21", 0x40015 },
|
||||||
|
{ L"S-1-5-80-0", 0x50000 },
|
||||||
|
{ L"S-1-5-83-0", 0x53000 },
|
||||||
|
{ L"S-1-16-0", 0x60000 },
|
||||||
|
{ L"S-1-16-4096", 0x61000 },
|
||||||
|
{ L"S-1-16-8192", 0x62000 },
|
||||||
|
{ L"S-1-16-8448", 0x62100 },
|
||||||
|
{ L"S-1-16-12288", 0x63000 },
|
||||||
|
{ L"S-1-16-16384", 0x64000 },
|
||||||
|
{ L"S-1-16-20480", 0x65000 },
|
||||||
|
{ L"S-1-16-28672", 0x67000 },
|
||||||
|
{ 0, 0 },
|
||||||
|
{ 0, 0 },
|
||||||
|
};
|
||||||
|
NTSTATUS Result;
|
||||||
|
BOOL Success;
|
||||||
|
HANDLE Token;
|
||||||
|
PTOKEN_USER UserInfo;
|
||||||
|
PTOKEN_PRIMARY_GROUP GroupInfo;
|
||||||
|
DWORD InfoSize;
|
||||||
|
PSID Sid0, Sid1;
|
||||||
|
UINT32 Uid;
|
||||||
|
|
||||||
|
Success = OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &Token);
|
||||||
|
ASSERT(Success);
|
||||||
|
|
||||||
|
Success = GetTokenInformation(Token, TokenUser, 0, 0, &InfoSize);
|
||||||
|
ASSERT(!Success);
|
||||||
|
ASSERT(ERROR_INSUFFICIENT_BUFFER == GetLastError());
|
||||||
|
|
||||||
|
UserInfo = malloc(InfoSize);
|
||||||
|
ASSERT(0 != UserInfo);
|
||||||
|
|
||||||
|
Success = GetTokenInformation(Token, TokenUser, UserInfo, InfoSize, &InfoSize);
|
||||||
|
ASSERT(Success);
|
||||||
|
|
||||||
|
Success = ConvertSidToStringSidW(UserInfo->User.Sid, &map[sizeof map / sizeof map[0] - 1].SidStr);
|
||||||
|
ASSERT(Success);
|
||||||
|
|
||||||
|
free(UserInfo);
|
||||||
|
|
||||||
|
Success = GetTokenInformation(Token, TokenPrimaryGroup, 0, 0, &InfoSize);
|
||||||
|
ASSERT(!Success);
|
||||||
|
ASSERT(ERROR_INSUFFICIENT_BUFFER == GetLastError());
|
||||||
|
|
||||||
|
GroupInfo = malloc(InfoSize);
|
||||||
|
ASSERT(0 != UserInfo);
|
||||||
|
|
||||||
|
Success = GetTokenInformation(Token, TokenPrimaryGroup, GroupInfo, InfoSize, &InfoSize);
|
||||||
|
ASSERT(Success);
|
||||||
|
|
||||||
|
Success = ConvertSidToStringSidW(GroupInfo->PrimaryGroup, &map[sizeof map / sizeof map[0] - 2].SidStr);
|
||||||
|
ASSERT(Success);
|
||||||
|
|
||||||
|
free(GroupInfo);
|
||||||
|
|
||||||
|
CloseHandle(Token);
|
||||||
|
|
||||||
|
for (size_t i = 0; sizeof map / sizeof map[0] > i; i++)
|
||||||
|
{
|
||||||
|
Success = ConvertStringSidToSidW(map[i].SidStr, &Sid0);
|
||||||
|
ASSERT(Success);
|
||||||
|
|
||||||
|
Result = FspPosixMapSidToUid(Sid0, &Uid);
|
||||||
|
ASSERT(NT_SUCCESS(Result));
|
||||||
|
|
||||||
|
if (0 != map[i].Uid)
|
||||||
|
ASSERT(Uid == map[i].Uid);
|
||||||
|
|
||||||
|
Result = FspPosixMapUidToSid(Uid, &Sid1);
|
||||||
|
ASSERT(NT_SUCCESS(Result));
|
||||||
|
|
||||||
|
ASSERT(EqualSid(Sid0, Sid1));
|
||||||
|
|
||||||
|
FspDeleteSid(Sid1, FspPosixMapUidToSid);
|
||||||
|
LocalFree(Sid0);
|
||||||
|
}
|
||||||
|
|
||||||
|
LocalFree(map[sizeof map / sizeof map[0] - 2].SidStr);
|
||||||
|
LocalFree(map[sizeof map / sizeof map[0] - 1].SidStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void posix_map_sd_test(void)
|
||||||
|
{
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
PWSTR Sddl;
|
||||||
|
UINT32 Uid, Gid, Mode;
|
||||||
|
} map[] =
|
||||||
|
{
|
||||||
|
{ L"O:SYG:BAD:P(A;;0x1f0198;;;SY)(A;;0x120088;;;BA)(A;;0x120088;;;WD)", 18, 544, 00000 },
|
||||||
|
|
||||||
|
{ L"O:SYG:BAD:P(A;;0x1f0199;;;SY)(A;;0x120088;;;BA)(A;;0x120088;;;WD)", 18, 544, 00400 },
|
||||||
|
{ L"O:SYG:BAD:P(A;;0x1f0198;;;SY)(D;;CC;;;SY)(A;;FR;;;BA)(A;;0x120088;;;WD)", 18, 544, 00040 },
|
||||||
|
{ L"O:SYG:BAD:P(A;;0x1f0198;;;SY)(D;;CC;;;SY)(A;;0x120088;;;BA)(D;;CC;;;BA)(A;;FR;;;WD)", 18, 544, 00004 },
|
||||||
|
|
||||||
|
{ L"O:SYG:BAD:P(A;;0x1f019e;;;SY)(A;;0x120088;;;BA)(A;;0x120088;;;WD)", 18, 544, 00200 },
|
||||||
|
{ L"O:SYG:BAD:P(A;;0x1f0198;;;SY)(D;;DCLC;;;SY)(A;;0x12018e;;;BA)(A;;0x120088;;;WD)", 18, 544, 00020 },
|
||||||
|
{ L"O:SYG:BAD:P(A;;0x1f0198;;;SY)(D;;DCLC;;;SY)(A;;0x120088;;;BA)(D;;DCLCCR;;;BA)(A;;0x12018e;;;WD)", 18, 544, 00002 },
|
||||||
|
|
||||||
|
{ L"O:SYG:BAD:P(A;;0x1f01b8;;;SY)(A;;0x120088;;;BA)(A;;0x120088;;;WD)", 18, 544, 00100 },
|
||||||
|
{ L"O:SYG:BAD:P(A;;0x1f0198;;;SY)(D;;WP;;;SY)(A;;0x1200a8;;;BA)(A;;0x120088;;;WD)", 18, 544, 00010 },
|
||||||
|
{ L"O:SYG:BAD:P(A;;0x1f0198;;;SY)(D;;WP;;;SY)(A;;0x120088;;;BA)(D;;WP;;;BA)(A;;0x1200a8;;;WD)", 18, 544, 00001 },
|
||||||
|
|
||||||
|
{ L"O:SYG:BAD:P(A;;0x1f01b9;;;SY)(D;;DCLC;;;SY)(A;;0x1201af;;;BA)(A;;0x1200a9;;;WD)", 18, 544, 00575 },
|
||||||
|
{ L"O:SYG:BAD:P(A;;0x1f01bf;;;SY)(A;;0x1200a9;;;BA)(D;;DCLCCR;;;BA)(A;;0x1201af;;;WD)", 18, 544, 00757 },
|
||||||
|
|
||||||
|
{ L"O:SYG:BAD:P(A;;0x1f01bf;;;SY)(A;;0x1200a9;;;BA)(A;;0x1200a9;;;WD)", 18, 544, 00755 },
|
||||||
|
{ L"O:SYG:BAD:P(A;;FA;;;SY)(A;;0x1200a9;;;BA)(A;;0x1200a9;;;WD)", 18, 544, 0040755 },
|
||||||
|
|
||||||
|
{ L"O:SYG:BAD:P(A;;0x1f01bf;;;SY)(A;;0x1201af;;;BA)(A;;0x1201af;;;WD)", 18, 544, 00777 },
|
||||||
|
{ L"O:SYG:BAD:P(A;;FA;;;SY)(A;;0x1201ef;;;BA)(A;;0x1201ef;;;WD)", 18, 544, 0040777 },
|
||||||
|
{ L"O:SYG:BAD:P(A;;FA;;;SY)(A;;0x1201af;;;BA)(A;;0x1201af;;;WD)", 18, 544, 0041777 },
|
||||||
|
|
||||||
|
{ L"O:BAG:BAD:P(A;;0x1f0199;;;BA)(A;;FR;;;BA)(A;;FR;;;WD)", 544, 544, 0444 },
|
||||||
|
};
|
||||||
|
NTSTATUS Result;
|
||||||
|
BOOL Success;
|
||||||
|
PSECURITY_DESCRIPTOR SecurityDescriptor;
|
||||||
|
PWSTR Sddl;
|
||||||
|
UINT32 Uid, Gid, Mode;
|
||||||
|
|
||||||
|
for (size_t i = 0; sizeof map / sizeof map[0] > i; i++)
|
||||||
|
{
|
||||||
|
Result = FspPosixMapPermissionsToSecurityDescriptor(
|
||||||
|
map[i].Uid, map[i].Gid, map[i].Mode, &SecurityDescriptor);
|
||||||
|
ASSERT(NT_SUCCESS(Result));
|
||||||
|
|
||||||
|
Success = ConvertSecurityDescriptorToStringSecurityDescriptorW(
|
||||||
|
SecurityDescriptor, SDDL_REVISION_1,
|
||||||
|
OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION,
|
||||||
|
&Sddl, 0);
|
||||||
|
ASSERT(Success);
|
||||||
|
ASSERT(0 == wcscmp(map[i].Sddl, Sddl));
|
||||||
|
LocalFree(Sddl);
|
||||||
|
|
||||||
|
Result = FspPosixMapSecurityDescriptorToPermissions(
|
||||||
|
SecurityDescriptor, &Uid, &Gid, &Mode);
|
||||||
|
ASSERT(NT_SUCCESS(Result));
|
||||||
|
ASSERT(map[i].Uid == Uid);
|
||||||
|
ASSERT(map[i].Gid == Gid);
|
||||||
|
ASSERT((map[i].Mode & 01777) == Mode);
|
||||||
|
|
||||||
|
FspDeleteSecurityDescriptor(SecurityDescriptor,
|
||||||
|
FspPosixMapPermissionsToSecurityDescriptor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void posix_map_path_test(void)
|
||||||
|
{
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
PWSTR WindowsPath;
|
||||||
|
const char *PosixPath;
|
||||||
|
} map[] =
|
||||||
|
{
|
||||||
|
{ L"\\foo\\bar", "/foo/bar" },
|
||||||
|
{ L"\\foo\xf03c\xf03e\xf03a\xf02f\xf05c\xf022\xf07c\xf03f\xf02a\\bar", "/foo<>:\xef\x80\xaf\\\"|?*/bar" },
|
||||||
|
};
|
||||||
|
NTSTATUS Result;
|
||||||
|
PWSTR WindowsPath;
|
||||||
|
char *PosixPath;
|
||||||
|
|
||||||
|
for (size_t i = 0; sizeof map / sizeof map[0] > i; i++)
|
||||||
|
{
|
||||||
|
Result = FspPosixMapWindowsToPosixPath(map[i].WindowsPath, &PosixPath);
|
||||||
|
ASSERT(NT_SUCCESS(Result));
|
||||||
|
ASSERT(0 == strcmp(map[i].PosixPath, PosixPath));
|
||||||
|
|
||||||
|
Result = FspPosixMapPosixToWindowsPath(map[i].PosixPath, &WindowsPath);
|
||||||
|
ASSERT(NT_SUCCESS(Result));
|
||||||
|
ASSERT(0 == wcscmp(map[i].WindowsPath, WindowsPath));
|
||||||
|
|
||||||
|
FspPosixDeletePath(WindowsPath);
|
||||||
|
FspPosixDeletePath(PosixPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void posix_tests(void)
|
||||||
|
{
|
||||||
|
TEST(posix_map_sid_test);
|
||||||
|
TEST(posix_map_sd_test);
|
||||||
|
TEST(posix_map_path_test);
|
||||||
|
}
|
@ -6,6 +6,8 @@ int WinFspNetTests = 1;
|
|||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
TESTSUITE(fuse_opt_tests);
|
||||||
|
TESTSUITE(posix_tests);
|
||||||
TESTSUITE(eventlog_tests);
|
TESTSUITE(eventlog_tests);
|
||||||
TESTSUITE(path_tests);
|
TESTSUITE(path_tests);
|
||||||
TESTSUITE(mount_tests);
|
TESTSUITE(mount_tests);
|
||||||
|
Reference in New Issue
Block a user