diff --git a/src/dotnet/FileSystem.cs b/src/dotnet/FileSystem.cs index 63f27fb4..5979a3b1 100644 --- a/src/dotnet/FileSystem.cs +++ b/src/dotnet/FileSystem.cs @@ -16,7 +16,6 @@ */ using System; -using System.Security.AccessControl; using System.Runtime.InteropServices; using Fsp.Interop; @@ -130,7 +129,7 @@ namespace Fsp MountPoint); } Int32 Mount(String MountPoint, - GenericSecurityDescriptor SecurityDescriptor = null, + byte[] SecurityDescriptor = null, Boolean Synchronized = false, UInt32 DebugLog = 0) { @@ -196,7 +195,7 @@ namespace Fsp protected virtual Int32 GetSecurityByName( String FileName, out UInt32 FileAttributes/* or ReparsePointIndex */, - ref Object SecurityDescriptor) + ref byte[] SecurityDescriptor) { FileAttributes = default(UInt32); return STATUS_INVALID_DEVICE_REQUEST; @@ -337,7 +336,7 @@ namespace Fsp protected virtual Int32 GetSecurity( Object FileNode, Object FileDesc, - ref Object SecurityDescriptor) + ref byte[] SecurityDescriptor) { return STATUS_INVALID_DEVICE_REQUEST; } @@ -345,7 +344,7 @@ namespace Fsp Object FileNode, Object FileDesc, UInt32 SecurityInformation, - Object SecurityDescriptor) + byte[] SecurityDescriptor) { return STATUS_INVALID_DEVICE_REQUEST; } @@ -428,7 +427,7 @@ namespace Fsp } /* FSP_FILE_SYSTEM_INTERFACE */ - private static Object SecurityDescriptorNotNull = new Object(); + private static byte[] SecurityDescriptorNotNull = new byte[0]; private static Int32 GetVolumeInfo( IntPtr FileSystem, out VolumeInfo VolumeInfo) @@ -474,17 +473,17 @@ namespace Fsp try { UInt32 FileAttributes; - Object SecurityDescriptorObject = null; + byte[] SecurityDescriptorBytes = null; Int32 Result; if (IntPtr.Zero != PSecurityDescriptorSize) - SecurityDescriptorObject = SecurityDescriptorNotNull; + SecurityDescriptorBytes = SecurityDescriptorNotNull; Result = self.GetSecurityByName( FileName, out FileAttributes, - ref SecurityDescriptorObject); + ref SecurityDescriptorBytes); if (IntPtr.Zero != PFileAttributes) Marshal.WriteInt32(PFileAttributes, (Int32)FileAttributes); - return Api.CopySecurityDescriptor(SecurityDescriptorObject, + return Api.CopySecurityDescriptor(SecurityDescriptorBytes, SecurityDescriptor, PSecurityDescriptorSize); } catch (Exception ex) @@ -837,16 +836,16 @@ namespace Fsp try { Object FileNode, FileDesc; - Object SecurityDescriptorObject = null; + byte[] SecurityDescriptorBytes = null; Int32 Result; Api.GetFullContext(ref FullContext, out FileNode, out FileDesc); if (IntPtr.Zero != PSecurityDescriptorSize) - SecurityDescriptorObject = SecurityDescriptorNotNull; + SecurityDescriptorBytes = SecurityDescriptorNotNull; Result = self.GetSecurity( FileNode, FileDesc, - ref SecurityDescriptorObject); - return Api.CopySecurityDescriptor(SecurityDescriptorObject, + ref SecurityDescriptorBytes); + return Api.CopySecurityDescriptor(SecurityDescriptorBytes, SecurityDescriptor, PSecurityDescriptorSize); } catch (Exception ex) diff --git a/src/dotnet/Interop.cs b/src/dotnet/Interop.cs index 69a1d4c7..1901b035 100644 --- a/src/dotnet/Interop.cs +++ b/src/dotnet/Interop.cs @@ -18,7 +18,6 @@ using System; using System.Diagnostics; using System.IO; -using System.Security.AccessControl; using System.Runtime.InteropServices; using System.Security; @@ -101,7 +100,7 @@ namespace Fsp.Interop internal UInt16 VolumeLabelLength; internal unsafe fixed UInt16 VolumeLabel[VolumeLabelSize]; - internal unsafe void SetVolumeLabel(String Value) + public unsafe void SetVolumeLabel(String Value) { fixed (UInt16 *P = VolumeLabel) { @@ -543,13 +542,11 @@ namespace Fsp.Interop internal static unsafe Int32 FspFileSystemSetMountPointEx( IntPtr FileSystem, String MountPoint, - GenericSecurityDescriptor SecurityDescriptor) + byte[] SecurityDescriptor) { if (null != SecurityDescriptor) { - byte[] Bytes = new byte[SecurityDescriptor.BinaryLength]; - SecurityDescriptor.GetBinaryForm(Bytes, 0); - fixed (byte *P = Bytes) + fixed (byte *P = SecurityDescriptor) return _FspFileSystemSetMountPointEx(FileSystem, MountPoint, (IntPtr)P); } else @@ -625,42 +622,38 @@ namespace Fsp.Interop } internal unsafe static Int32 CopySecurityDescriptor( - Object SecurityDescriptorObject, + byte[] SecurityDescriptorBytes, IntPtr SecurityDescriptor, IntPtr PSecurityDescriptorSize) { if (IntPtr.Zero != PSecurityDescriptorSize) { - GenericSecurityDescriptor GenericSecurityDescriptor = - SecurityDescriptorObject as GenericSecurityDescriptor; - if (null != GenericSecurityDescriptor) + if (null != SecurityDescriptorBytes) { - 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*/; } - *(IntPtr *)PSecurityDescriptorSize = (IntPtr)GenericSecurityDescriptor.BinaryLength; + *(IntPtr *)PSecurityDescriptorSize = (IntPtr)SecurityDescriptorBytes.Length; if (IntPtr.Zero != SecurityDescriptor) - { - byte[] Bytes = new byte[GenericSecurityDescriptor.BinaryLength]; - GenericSecurityDescriptor.GetBinaryForm(Bytes, 0); - Marshal.Copy(Bytes, 0, SecurityDescriptor, Bytes.Length); - } + Marshal.Copy(SecurityDescriptorBytes, 0, + SecurityDescriptor, SecurityDescriptorBytes.Length); } else *(IntPtr *)PSecurityDescriptorSize = IntPtr.Zero; } return 0/*STATUS_SUCCESS*/; } - internal static Object MakeSecurityDescriptor( + internal static byte[] MakeSecurityDescriptor( IntPtr SecurityDescriptor) { if (IntPtr.Zero != SecurityDescriptor) { - byte[] Bytes = new byte[GetSecurityDescriptorLength(SecurityDescriptor)]; - Marshal.Copy(SecurityDescriptor, Bytes, 0, Bytes.Length); - return new RawSecurityDescriptor(Bytes, 0); + byte[] SecurityDescriptorBytes = new byte[GetSecurityDescriptorLength(SecurityDescriptor)]; + Marshal.Copy(SecurityDescriptor, + SecurityDescriptorBytes, 0, SecurityDescriptorBytes.Length); + return SecurityDescriptorBytes; } else return null; diff --git a/src/dotnet/Service.cs b/src/dotnet/Service.cs index 14b70d3c..9aaa04e3 100644 --- a/src/dotnet/Service.cs +++ b/src/dotnet/Service.cs @@ -96,6 +96,10 @@ namespace Fsp Api.FspServiceSetExitCode(_Service, (UInt32)value); } } + public IntPtr ServiceHandle + { + get { return _Service; } + } public static void Log(UInt32 Type, String Message) { Api.FspServiceLog(Type, "%s", Message);