mirror of
https://github.com/winfsp/winfsp.git
synced 2025-04-22 16:33:02 -05:00
src: dotnet: WIP
This commit is contained in:
parent
9a02a46cf4
commit
33f5b8c05b
@ -16,7 +16,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Security.AccessControl;
|
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
using Fsp.Interop;
|
using Fsp.Interop;
|
||||||
@ -130,7 +129,7 @@ namespace Fsp
|
|||||||
MountPoint);
|
MountPoint);
|
||||||
}
|
}
|
||||||
Int32 Mount(String MountPoint,
|
Int32 Mount(String MountPoint,
|
||||||
GenericSecurityDescriptor SecurityDescriptor = null,
|
byte[] SecurityDescriptor = null,
|
||||||
Boolean Synchronized = false,
|
Boolean Synchronized = false,
|
||||||
UInt32 DebugLog = 0)
|
UInt32 DebugLog = 0)
|
||||||
{
|
{
|
||||||
@ -196,7 +195,7 @@ namespace Fsp
|
|||||||
protected virtual Int32 GetSecurityByName(
|
protected virtual Int32 GetSecurityByName(
|
||||||
String FileName,
|
String FileName,
|
||||||
out UInt32 FileAttributes/* or ReparsePointIndex */,
|
out UInt32 FileAttributes/* or ReparsePointIndex */,
|
||||||
ref Object SecurityDescriptor)
|
ref byte[] SecurityDescriptor)
|
||||||
{
|
{
|
||||||
FileAttributes = default(UInt32);
|
FileAttributes = default(UInt32);
|
||||||
return STATUS_INVALID_DEVICE_REQUEST;
|
return STATUS_INVALID_DEVICE_REQUEST;
|
||||||
@ -337,7 +336,7 @@ namespace Fsp
|
|||||||
protected virtual Int32 GetSecurity(
|
protected virtual Int32 GetSecurity(
|
||||||
Object FileNode,
|
Object FileNode,
|
||||||
Object FileDesc,
|
Object FileDesc,
|
||||||
ref Object SecurityDescriptor)
|
ref byte[] SecurityDescriptor)
|
||||||
{
|
{
|
||||||
return STATUS_INVALID_DEVICE_REQUEST;
|
return STATUS_INVALID_DEVICE_REQUEST;
|
||||||
}
|
}
|
||||||
@ -345,7 +344,7 @@ namespace Fsp
|
|||||||
Object FileNode,
|
Object FileNode,
|
||||||
Object FileDesc,
|
Object FileDesc,
|
||||||
UInt32 SecurityInformation,
|
UInt32 SecurityInformation,
|
||||||
Object SecurityDescriptor)
|
byte[] SecurityDescriptor)
|
||||||
{
|
{
|
||||||
return STATUS_INVALID_DEVICE_REQUEST;
|
return STATUS_INVALID_DEVICE_REQUEST;
|
||||||
}
|
}
|
||||||
@ -428,7 +427,7 @@ namespace Fsp
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* FSP_FILE_SYSTEM_INTERFACE */
|
/* FSP_FILE_SYSTEM_INTERFACE */
|
||||||
private static Object SecurityDescriptorNotNull = new Object();
|
private static byte[] SecurityDescriptorNotNull = new byte[0];
|
||||||
private static Int32 GetVolumeInfo(
|
private static Int32 GetVolumeInfo(
|
||||||
IntPtr FileSystem,
|
IntPtr FileSystem,
|
||||||
out VolumeInfo VolumeInfo)
|
out VolumeInfo VolumeInfo)
|
||||||
@ -474,17 +473,17 @@ namespace Fsp
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
UInt32 FileAttributes;
|
UInt32 FileAttributes;
|
||||||
Object SecurityDescriptorObject = null;
|
byte[] SecurityDescriptorBytes = null;
|
||||||
Int32 Result;
|
Int32 Result;
|
||||||
if (IntPtr.Zero != PSecurityDescriptorSize)
|
if (IntPtr.Zero != PSecurityDescriptorSize)
|
||||||
SecurityDescriptorObject = SecurityDescriptorNotNull;
|
SecurityDescriptorBytes = SecurityDescriptorNotNull;
|
||||||
Result = self.GetSecurityByName(
|
Result = self.GetSecurityByName(
|
||||||
FileName,
|
FileName,
|
||||||
out FileAttributes,
|
out FileAttributes,
|
||||||
ref SecurityDescriptorObject);
|
ref SecurityDescriptorBytes);
|
||||||
if (IntPtr.Zero != PFileAttributes)
|
if (IntPtr.Zero != PFileAttributes)
|
||||||
Marshal.WriteInt32(PFileAttributes, (Int32)FileAttributes);
|
Marshal.WriteInt32(PFileAttributes, (Int32)FileAttributes);
|
||||||
return Api.CopySecurityDescriptor(SecurityDescriptorObject,
|
return Api.CopySecurityDescriptor(SecurityDescriptorBytes,
|
||||||
SecurityDescriptor, PSecurityDescriptorSize);
|
SecurityDescriptor, PSecurityDescriptorSize);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -837,16 +836,16 @@ namespace Fsp
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
Object FileNode, FileDesc;
|
Object FileNode, FileDesc;
|
||||||
Object SecurityDescriptorObject = null;
|
byte[] SecurityDescriptorBytes = null;
|
||||||
Int32 Result;
|
Int32 Result;
|
||||||
Api.GetFullContext(ref FullContext, out FileNode, out FileDesc);
|
Api.GetFullContext(ref FullContext, out FileNode, out FileDesc);
|
||||||
if (IntPtr.Zero != PSecurityDescriptorSize)
|
if (IntPtr.Zero != PSecurityDescriptorSize)
|
||||||
SecurityDescriptorObject = SecurityDescriptorNotNull;
|
SecurityDescriptorBytes = SecurityDescriptorNotNull;
|
||||||
Result = self.GetSecurity(
|
Result = self.GetSecurity(
|
||||||
FileNode,
|
FileNode,
|
||||||
FileDesc,
|
FileDesc,
|
||||||
ref SecurityDescriptorObject);
|
ref SecurityDescriptorBytes);
|
||||||
return Api.CopySecurityDescriptor(SecurityDescriptorObject,
|
return Api.CopySecurityDescriptor(SecurityDescriptorBytes,
|
||||||
SecurityDescriptor, PSecurityDescriptorSize);
|
SecurityDescriptor, PSecurityDescriptorSize);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Security.AccessControl;
|
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Security;
|
using System.Security;
|
||||||
|
|
||||||
@ -101,7 +100,7 @@ namespace Fsp.Interop
|
|||||||
internal UInt16 VolumeLabelLength;
|
internal UInt16 VolumeLabelLength;
|
||||||
internal unsafe fixed UInt16 VolumeLabel[VolumeLabelSize];
|
internal unsafe fixed UInt16 VolumeLabel[VolumeLabelSize];
|
||||||
|
|
||||||
internal unsafe void SetVolumeLabel(String Value)
|
public unsafe void SetVolumeLabel(String Value)
|
||||||
{
|
{
|
||||||
fixed (UInt16 *P = VolumeLabel)
|
fixed (UInt16 *P = VolumeLabel)
|
||||||
{
|
{
|
||||||
@ -543,13 +542,11 @@ namespace Fsp.Interop
|
|||||||
internal static unsafe Int32 FspFileSystemSetMountPointEx(
|
internal static unsafe Int32 FspFileSystemSetMountPointEx(
|
||||||
IntPtr FileSystem,
|
IntPtr FileSystem,
|
||||||
String MountPoint,
|
String MountPoint,
|
||||||
GenericSecurityDescriptor SecurityDescriptor)
|
byte[] SecurityDescriptor)
|
||||||
{
|
{
|
||||||
if (null != SecurityDescriptor)
|
if (null != SecurityDescriptor)
|
||||||
{
|
{
|
||||||
byte[] Bytes = new byte[SecurityDescriptor.BinaryLength];
|
fixed (byte *P = SecurityDescriptor)
|
||||||
SecurityDescriptor.GetBinaryForm(Bytes, 0);
|
|
||||||
fixed (byte *P = Bytes)
|
|
||||||
return _FspFileSystemSetMountPointEx(FileSystem, MountPoint, (IntPtr)P);
|
return _FspFileSystemSetMountPointEx(FileSystem, MountPoint, (IntPtr)P);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -625,42 +622,38 @@ namespace Fsp.Interop
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal unsafe static Int32 CopySecurityDescriptor(
|
internal unsafe static Int32 CopySecurityDescriptor(
|
||||||
Object SecurityDescriptorObject,
|
byte[] SecurityDescriptorBytes,
|
||||||
IntPtr SecurityDescriptor,
|
IntPtr SecurityDescriptor,
|
||||||
IntPtr PSecurityDescriptorSize)
|
IntPtr PSecurityDescriptorSize)
|
||||||
{
|
{
|
||||||
if (IntPtr.Zero != PSecurityDescriptorSize)
|
if (IntPtr.Zero != PSecurityDescriptorSize)
|
||||||
{
|
{
|
||||||
GenericSecurityDescriptor GenericSecurityDescriptor =
|
if (null != SecurityDescriptorBytes)
|
||||||
SecurityDescriptorObject as GenericSecurityDescriptor;
|
|
||||||
if (null != GenericSecurityDescriptor)
|
|
||||||
{
|
{
|
||||||
if (GenericSecurityDescriptor.BinaryLength > (int)*(IntPtr *)PSecurityDescriptorSize)
|
if (SecurityDescriptorBytes.Length > (int)*(IntPtr *)PSecurityDescriptorSize)
|
||||||
{
|
{
|
||||||
*(IntPtr *)PSecurityDescriptorSize = (IntPtr)GenericSecurityDescriptor.BinaryLength;
|
*(IntPtr *)PSecurityDescriptorSize = (IntPtr)SecurityDescriptorBytes.Length;
|
||||||
return unchecked((Int32)0x80000005)/*STATUS_BUFFER_OVERFLOW*/;
|
return unchecked((Int32)0x80000005)/*STATUS_BUFFER_OVERFLOW*/;
|
||||||
}
|
}
|
||||||
*(IntPtr *)PSecurityDescriptorSize = (IntPtr)GenericSecurityDescriptor.BinaryLength;
|
*(IntPtr *)PSecurityDescriptorSize = (IntPtr)SecurityDescriptorBytes.Length;
|
||||||
if (IntPtr.Zero != SecurityDescriptor)
|
if (IntPtr.Zero != SecurityDescriptor)
|
||||||
{
|
Marshal.Copy(SecurityDescriptorBytes, 0,
|
||||||
byte[] Bytes = new byte[GenericSecurityDescriptor.BinaryLength];
|
SecurityDescriptor, SecurityDescriptorBytes.Length);
|
||||||
GenericSecurityDescriptor.GetBinaryForm(Bytes, 0);
|
|
||||||
Marshal.Copy(Bytes, 0, SecurityDescriptor, Bytes.Length);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
*(IntPtr *)PSecurityDescriptorSize = IntPtr.Zero;
|
*(IntPtr *)PSecurityDescriptorSize = IntPtr.Zero;
|
||||||
}
|
}
|
||||||
return 0/*STATUS_SUCCESS*/;
|
return 0/*STATUS_SUCCESS*/;
|
||||||
}
|
}
|
||||||
internal static Object MakeSecurityDescriptor(
|
internal static byte[] MakeSecurityDescriptor(
|
||||||
IntPtr SecurityDescriptor)
|
IntPtr SecurityDescriptor)
|
||||||
{
|
{
|
||||||
if (IntPtr.Zero != SecurityDescriptor)
|
if (IntPtr.Zero != SecurityDescriptor)
|
||||||
{
|
{
|
||||||
byte[] Bytes = new byte[GetSecurityDescriptorLength(SecurityDescriptor)];
|
byte[] SecurityDescriptorBytes = new byte[GetSecurityDescriptorLength(SecurityDescriptor)];
|
||||||
Marshal.Copy(SecurityDescriptor, Bytes, 0, Bytes.Length);
|
Marshal.Copy(SecurityDescriptor,
|
||||||
return new RawSecurityDescriptor(Bytes, 0);
|
SecurityDescriptorBytes, 0, SecurityDescriptorBytes.Length);
|
||||||
|
return SecurityDescriptorBytes;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return null;
|
return null;
|
||||||
|
@ -96,6 +96,10 @@ namespace Fsp
|
|||||||
Api.FspServiceSetExitCode(_Service, (UInt32)value);
|
Api.FspServiceSetExitCode(_Service, (UInt32)value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public IntPtr ServiceHandle
|
||||||
|
{
|
||||||
|
get { return _Service; }
|
||||||
|
}
|
||||||
public static void Log(UInt32 Type, String Message)
|
public static void Log(UInt32 Type, String Message)
|
||||||
{
|
{
|
||||||
Api.FspServiceLog(Type, "%s", Message);
|
Api.FspServiceLog(Type, "%s", Message);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user