Browse Source

Improved AccessMask implementation

Tal Aloni 7 years ago
parent
commit
932780bc60

+ 0 - 132
SMBLibrary/EnumStructures/AccessMask.cs

@@ -1,132 +0,0 @@
-/* Copyright (C) 2014-2017 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
- * 
- * You can redistribute this program and/or modify it under the terms of
- * the GNU Lesser Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- */
-using System;
-using System.Collections.Generic;
-using System.Text;
-using Utilities;
-
-namespace SMBLibrary
-{
-    /// <summary>
-    /// [MS-CIFS] SMB_COM_NT_CREATE_ANDX request (DesiredAccess field) and NT_TRANSACT_CREATE request (DesiredAccess field)
-    /// [MS-SMB] 2.2.1.4.1 - File_Pipe_Printer_Access_Mask
-    /// </summary>
-    [Flags]
-    public enum FileAccessMask : uint
-    {
-        FILE_READ_DATA = 0x00000001,
-        FILE_WRITE_DATA = 0x00000002,
-        FILE_APPEND_DATA = 0x00000004,
-        FILE_READ_EA = 0x00000008,
-        FILE_WRITE_EA = 0x00000010,
-        FILE_EXECUTE = 0x00000020,
-        FILE_READ_ATTRIBUTES = 0x00000080,
-        FILE_WRITE_ATTRIBUTES = 0x00000100,
-        DELETE = 0x00010000,
-        READ_CONTROL = 0x00020000,
-        WRITE_DAC = 0x00040000,
-        WRITE_OWNER = 0x00080000,
-        SYNCHRONIZE = 0x00100000,
-        ACCESS_SYSTEM_SECURITY = 0x01000000,
-        MAXIMUM_ALLOWED = 0x02000000,
-        GENERIC_ALL = 0x10000000,
-        GENERIC_EXECUTE = 0x20000000,
-        GENERIC_WRITE = 0x40000000,
-        GENERIC_READ = 0x80000000,
-    }
-
-    /// <summary>
-    /// [MS-SMB] 2.2.1.4.2 - Directory_Access_Mask
-    /// </summary>
-    [Flags]
-    public enum DirectoryAccessMask : uint
-    {
-        FILE_LIST_DIRECTORY = 0x00000001,
-        FILE_ADD_FILE = 0x00000002,
-        FILE_ADD_SUBDIRECTORY = 0x00000004,
-        FILE_READ_EA = 0x00000008,
-        FILE_WRITE_EA = 0x00000010,
-        FILE_TRAVERSE = 0x00000020,
-        FILE_DELETE_CHILD = 0x00000040,
-        FILE_READ_ATTRIBUTES = 0x00000080,
-        FILE_WRITE_ATTRIBUTES = 0x00000100,
-        DELETE = 0x00010000,
-        READ_CONTROL = 0x00020000,
-        WRITE_DAC = 0x00040000,
-        WRITE_OWNER = 0x00080000,
-        SYNCHRONIZE = 0x00100000,
-        ACCESS_SYSTEM_SECURITY = 0x01000000,
-        MAXIMUM_ALLOWED = 0x02000000,
-        GENERIC_ALL = 0x10000000,
-        GENERIC_EXECUTE = 0x20000000,
-        GENERIC_WRITE = 0x40000000,
-        GENERIC_READ = 0x80000000,
-    }
-
-    /// <summary>
-    /// [MS-DTYP] 2.4.3 - ACCESS_MASK
-    /// </summary>
-    public struct AccessMask // uint
-    {
-        public const int Length = 4;
-
-        public FileAccessMask File;
-        public DirectoryAccessMask Directory;
-
-        public AccessMask(byte[] buffer, ref int offset) : this(buffer, offset)
-        {
-            offset += Length;
-        }
-
-        public AccessMask(byte[] buffer, int offset)
-        {
-            uint value = LittleEndianConverter.ToUInt32(buffer, offset);
-            File = (FileAccessMask)value;
-            Directory = (DirectoryAccessMask)value;
-        }
-
-        public void WriteBytes(byte[] buffer, int offset)
-        {
-            uint value = (uint)this.File | (uint)this.Directory;
-            LittleEndianWriter.WriteUInt32(buffer, offset, value);
-        }
-
-        public void WriteBytes(byte[] buffer, ref int offset)
-        {
-            WriteBytes(buffer, offset);
-            offset += 4;
-        }
-
-        public static explicit operator AccessMask(uint value)
-        {
-            AccessMask result = new AccessMask();
-            result.File = (FileAccessMask)value;
-            result.Directory = (DirectoryAccessMask)value;
-            return result;
-        }
-
-        public static implicit operator AccessMask(FileAccessMask accessMask)
-        {
-            AccessMask result = new AccessMask();
-            result.File = accessMask;
-            return result;
-        }
-
-        public static implicit operator AccessMask(DirectoryAccessMask accessMask)
-        {
-            AccessMask result = new AccessMask();
-            result.Directory = accessMask;
-            return result;
-        }
-
-        public static explicit operator uint(AccessMask accessMask)
-        {
-            uint value = (uint)accessMask.File | (uint)accessMask.Directory;
-            return value;
-        }
-    }
-}

+ 1 - 1
SMBLibrary/NTFileStore/Adapter/NTFileSystemAdapter.cs

@@ -236,7 +236,7 @@ namespace SMBLibrary
                 return NTStatus.STATUS_INVALID_PARAMETER;
             }
 
-            FileAccess fileAccess = NTFileStoreHelper.ToFileAccess(desiredAccess.File);
+            FileAccess fileAccess = NTFileStoreHelper.ToFileAccess((FileAccessMask)desiredAccess);
             Stream stream;
             if (fileAccess == (FileAccess)0 || entry.IsDirectory)
             {

+ 24 - 0
SMBLibrary/NTFileStore/Enums/AccessMask/AccessMask.cs

@@ -0,0 +1,24 @@
+using System;
+
+namespace SMBLibrary
+{
+    /// <summary>
+    /// [MS-DTYP] 2.4.3 - ACCESS_MASK
+    /// </summary>
+    [Flags]
+    public enum AccessMask : uint
+    {
+        // The bits in positions 16 through 31 are object specific.
+        DELETE = 0x00010000,
+        READ_CONTROL = 0x00020000,
+        WRITE_DAC = 0x00040000,
+        WRITE_OWNER = 0x00080000,
+        SYNCHRONIZE = 0x00100000,
+        ACCESS_SYSTEM_SECURITY = 0x01000000,
+        MAXIMUM_ALLOWED = 0x02000000,
+        GENERIC_ALL = 0x10000000,
+        GENERIC_EXECUTE = 0x20000000,
+        GENERIC_WRITE = 0x40000000,
+        GENERIC_READ = 0x80000000,
+    }
+}

+ 33 - 0
SMBLibrary/NTFileStore/Enums/AccessMask/DirectoryAccessMask.cs

@@ -0,0 +1,33 @@
+using System;
+
+namespace SMBLibrary
+{
+    /// <summary>
+    /// [MS-SMB] 2.2.1.4.2 - Directory_Access_Mask
+    /// [MS-SMB2] 2.2.13.1.2 - Directory_Access_Mask
+    /// </summary>
+    [Flags]
+    public enum DirectoryAccessMask : uint
+    {
+        FILE_LIST_DIRECTORY = 0x00000001,
+        FILE_ADD_FILE = 0x00000002,
+        FILE_ADD_SUBDIRECTORY = 0x00000004,
+        FILE_READ_EA = 0x00000008,
+        FILE_WRITE_EA = 0x00000010,
+        FILE_TRAVERSE = 0x00000020,
+        FILE_DELETE_CHILD = 0x00000040,
+        FILE_READ_ATTRIBUTES = 0x00000080,
+        FILE_WRITE_ATTRIBUTES = 0x00000100,
+        DELETE = 0x00010000,
+        READ_CONTROL = 0x00020000,
+        WRITE_DAC = 0x00040000,
+        WRITE_OWNER = 0x00080000,
+        SYNCHRONIZE = 0x00100000,
+        ACCESS_SYSTEM_SECURITY = 0x01000000,
+        MAXIMUM_ALLOWED = 0x02000000,
+        GENERIC_ALL = 0x10000000,
+        GENERIC_EXECUTE = 0x20000000,
+        GENERIC_WRITE = 0x40000000,
+        GENERIC_READ = 0x80000000,
+    }
+}

+ 32 - 0
SMBLibrary/NTFileStore/Enums/AccessMask/FileAccessMask.cs

@@ -0,0 +1,32 @@
+using System;
+
+namespace SMBLibrary
+{
+    /// <summary>
+    /// [MS-SMB] 2.2.1.4.1 - File_Pipe_Printer_Access_Mask
+    /// [MS-SMB2] 2.2.13.1.1 - File_Pipe_Printer_Access_Mask
+    /// </summary>
+    [Flags]
+    public enum FileAccessMask : uint
+    {
+        FILE_READ_DATA = 0x00000001,
+        FILE_WRITE_DATA = 0x00000002,
+        FILE_APPEND_DATA = 0x00000004,
+        FILE_READ_EA = 0x00000008,
+        FILE_WRITE_EA = 0x00000010,
+        FILE_EXECUTE = 0x00000020,
+        FILE_READ_ATTRIBUTES = 0x00000080,
+        FILE_WRITE_ATTRIBUTES = 0x00000100,
+        DELETE = 0x00010000,
+        READ_CONTROL = 0x00020000,
+        WRITE_DAC = 0x00040000,
+        WRITE_OWNER = 0x00080000,
+        SYNCHRONIZE = 0x00100000,
+        ACCESS_SYSTEM_SECURITY = 0x01000000,
+        MAXIMUM_ALLOWED = 0x02000000,
+        GENERIC_ALL = 0x10000000,
+        GENERIC_EXECUTE = 0x20000000,
+        GENERIC_WRITE = 0x40000000,
+        GENERIC_READ = 0x80000000,
+    }
+}

+ 18 - 18
SMBLibrary/NTFileStore/NTFileStoreHelper.cs

@@ -17,31 +17,31 @@ namespace SMBLibrary
         {
             FileAccess result = 0;
 
-            if ((desiredAccess.File & FileAccessMask.FILE_READ_DATA) > 0 ||
-                (desiredAccess.File & FileAccessMask.FILE_READ_EA) > 0 ||
-                (desiredAccess.File & FileAccessMask.FILE_READ_ATTRIBUTES) > 0 ||
-                (desiredAccess.File & FileAccessMask.MAXIMUM_ALLOWED) > 0 ||
-                (desiredAccess.File & FileAccessMask.GENERIC_ALL) > 0 ||
-                (desiredAccess.File & FileAccessMask.GENERIC_READ) > 0)
+            if (((FileAccessMask)desiredAccess & FileAccessMask.FILE_READ_DATA) > 0 ||
+                ((FileAccessMask)desiredAccess & FileAccessMask.FILE_READ_EA) > 0 ||
+                ((FileAccessMask)desiredAccess & FileAccessMask.FILE_READ_ATTRIBUTES) > 0 ||
+                (desiredAccess & AccessMask.MAXIMUM_ALLOWED) > 0 ||
+                (desiredAccess & AccessMask.GENERIC_ALL) > 0 ||
+                (desiredAccess & AccessMask.GENERIC_READ) > 0)
             {
                 result |= FileAccess.Read;
             }
 
-            if ((desiredAccess.File & FileAccessMask.FILE_WRITE_DATA) > 0 ||
-                (desiredAccess.File & FileAccessMask.FILE_APPEND_DATA) > 0 ||
-                (desiredAccess.File & FileAccessMask.FILE_WRITE_EA) > 0 ||
-                (desiredAccess.File & FileAccessMask.FILE_WRITE_ATTRIBUTES) > 0 ||
-                (desiredAccess.File & FileAccessMask.DELETE) > 0 ||
-                (desiredAccess.File & FileAccessMask.WRITE_DAC) > 0 ||
-                (desiredAccess.File & FileAccessMask.WRITE_OWNER) > 0 ||
-                (desiredAccess.File & FileAccessMask.MAXIMUM_ALLOWED) > 0 ||
-                (desiredAccess.File & FileAccessMask.GENERIC_ALL) > 0 ||
-                (desiredAccess.File & FileAccessMask.GENERIC_WRITE) > 0)
+            if (((FileAccessMask)desiredAccess & FileAccessMask.FILE_WRITE_DATA) > 0 ||
+                ((FileAccessMask)desiredAccess & FileAccessMask.FILE_APPEND_DATA) > 0 ||
+                ((FileAccessMask)desiredAccess & FileAccessMask.FILE_WRITE_EA) > 0 ||
+                ((FileAccessMask)desiredAccess & FileAccessMask.FILE_WRITE_ATTRIBUTES) > 0 ||
+                (desiredAccess & AccessMask.DELETE) > 0 ||
+                (desiredAccess & AccessMask.WRITE_DAC) > 0 ||
+                (desiredAccess & AccessMask.WRITE_OWNER) > 0 ||
+                (desiredAccess & AccessMask.MAXIMUM_ALLOWED) > 0 ||
+                (desiredAccess & AccessMask.GENERIC_ALL) > 0 ||
+                (desiredAccess & AccessMask.GENERIC_WRITE) > 0)
             {
                 result |= FileAccess.Write;
             }
 
-            if ((desiredAccess.Directory & DirectoryAccessMask.FILE_DELETE_CHILD) > 0)
+            if (((DirectoryAccessMask)desiredAccess & DirectoryAccessMask.FILE_DELETE_CHILD) > 0)
             {
                 result |= FileAccess.Write;
             }
@@ -103,7 +103,7 @@ namespace SMBLibrary
         {
             object handle;
             FileStatus fileStatus;
-            NTStatus openStatus = fileStore.CreateFile(out handle, out fileStatus, path, FileAccessMask.FILE_READ_ATTRIBUTES, 0, ShareAccess.FILE_SHARE_READ | ShareAccess.FILE_SHARE_WRITE, CreateDisposition.FILE_OPEN, 0, securityContext);
+            NTStatus openStatus = fileStore.CreateFile(out handle, out fileStatus, path, (AccessMask)FileAccessMask.FILE_READ_ATTRIBUTES, 0, ShareAccess.FILE_SHARE_READ | ShareAccess.FILE_SHARE_WRITE, CreateDisposition.FILE_OPEN, 0, securityContext);
             if (openStatus != NTStatus.STATUS_SUCCESS)
             {
                 return null;

+ 2 - 2
SMBLibrary/NTFileStore/Structures/ACE/AccessAllowedACE.cs

@@ -1,4 +1,4 @@
-/* Copyright (C) 2014 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
+/* Copyright (C) 2014-2017 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
  * 
  * You can redistribute this program and/or modify it under the terms of
  * the GNU Lesser Public License as published by the Free Software Foundation,
@@ -29,7 +29,7 @@ namespace SMBLibrary
         public AccessAllowedACE(byte[] buffer, int offset)
         {
             Header = new AceHeader(buffer, offset + 0);
-            Mask = new AccessMask(buffer, offset + 4);
+            Mask = (AccessMask)LittleEndianConverter.ToUInt32(buffer, offset + 4);
             Sid = new SID(buffer, offset + 8);
         }
 

+ 2 - 2
SMBLibrary/SMB1/Commands/NTCreateAndXRequest.cs

@@ -25,7 +25,7 @@ namespace SMBLibrary.SMB1
         // ushort NameLength; // in bytes
         public NTCreateFlags Flags;
         public uint RootDirectoryFID;
-        public FileAccessMask DesiredAccess;
+        public AccessMask DesiredAccess;
         public long AllocationSize;
         public ExtendedFileAttributes ExtFileAttributes;
         public ShareAccess ShareAccess;
@@ -46,7 +46,7 @@ namespace SMBLibrary.SMB1
             ushort nameLength = LittleEndianConverter.ToUInt16(this.SMBParameters, 5);
             Flags = (NTCreateFlags)LittleEndianConverter.ToUInt32(this.SMBParameters, 7);
             RootDirectoryFID = LittleEndianConverter.ToUInt32(this.SMBParameters, 11);
-            DesiredAccess = (FileAccessMask)LittleEndianConverter.ToUInt32(this.SMBParameters, 15);
+            DesiredAccess = (AccessMask)LittleEndianConverter.ToUInt32(this.SMBParameters, 15);
             AllocationSize = LittleEndianConverter.ToInt64(this.SMBParameters, 19);
             ExtFileAttributes = (ExtendedFileAttributes)LittleEndianConverter.ToUInt32(this.SMBParameters, 27);
             ShareAccess = (ShareAccess)LittleEndianConverter.ToUInt32(this.SMBParameters, 31);

+ 7 - 7
SMBLibrary/SMB1/Commands/NTCreateAndXResponseExtended.cs

@@ -18,9 +18,9 @@ namespace SMBLibrary.SMB1
     {
         public const int ParametersLength = 100;
         // Parameters:
-        //CommandName AndXCommand;
-        //byte AndXReserved;
-        //ushort AndXOffset;
+        // CommandName AndXCommand;
+        // byte AndXReserved;
+        // ushort AndXOffset;
         public OpLockLevel OpLockLevel;
         public ushort FID;
         public CreateDisposition CreateDisposition;
@@ -61,8 +61,8 @@ namespace SMBLibrary.SMB1
             Directory = (ByteReader.ReadByte(this.SMBParameters, ref parametersOffset) > 0);
             VolumeGuid = LittleEndianReader.ReadGuid(this.SMBParameters, ref parametersOffset);
             FileID = LittleEndianReader.ReadUInt64(this.SMBParameters, ref parametersOffset);
-            MaximalAccessRights = new AccessMask(this.SMBParameters, ref parametersOffset);
-            GuestMaximalAccessRights = new AccessMask(this.SMBParameters, ref parametersOffset);
+            MaximalAccessRights = (AccessMask)LittleEndianReader.ReadUInt32(this.SMBParameters, ref parametersOffset);
+            GuestMaximalAccessRights = (AccessMask)LittleEndianReader.ReadUInt32(this.SMBParameters, ref parametersOffset);
         }
 
         public override byte[] GetBytes(bool isUnicode)
@@ -84,8 +84,8 @@ namespace SMBLibrary.SMB1
             ByteWriter.WriteByte(this.SMBParameters, ref parametersOffset, Convert.ToByte(Directory));
             LittleEndianWriter.WriteGuidBytes(this.SMBParameters, ref parametersOffset, VolumeGuid);
             LittleEndianWriter.WriteUInt64(this.SMBParameters, ref parametersOffset, FileID);
-            MaximalAccessRights.WriteBytes(this.SMBParameters, ref parametersOffset);
-            GuestMaximalAccessRights.WriteBytes(this.SMBParameters, ref parametersOffset);
+            LittleEndianWriter.WriteUInt32(this.SMBParameters, ref parametersOffset, (uint)MaximalAccessRights);
+            LittleEndianWriter.WriteUInt32(this.SMBParameters, ref parametersOffset, (uint)GuestMaximalAccessRights);
             return base.GetBytes(isUnicode);
         }
 

+ 5 - 5
SMBLibrary/SMB1/Commands/OpenAndXResponseExtended.cs

@@ -18,9 +18,9 @@ namespace SMBLibrary.SMB1
     {
         public const int ParametersLength = 38;
         // Parameters:
-        //CommandName AndXCommand;
-        //byte AndXReserved;
-        //ushort AndXOffset;
+        // CommandName AndXCommand;
+        // byte AndXReserved;
+        // ushort AndXOffset;
         public ushort FID;
         public SMBFileAttributes FileAttrs;
         public DateTime? LastWriteTime; // UTime
@@ -57,8 +57,8 @@ namespace SMBLibrary.SMB1
             OpenResults.WriteBytes(this.SMBParameters, ref parametersOffset);
             LittleEndianWriter.WriteUInt32(this.SMBParameters, ref parametersOffset, ServerFID);
             LittleEndianWriter.WriteUInt16(this.SMBParameters, ref parametersOffset, Reserved);
-            MaximalAccessRights.WriteBytes(this.SMBParameters, ref parametersOffset);
-            GuestMaximalAccessRights.WriteBytes(this.SMBParameters, ref parametersOffset);
+            LittleEndianWriter.WriteUInt32(this.SMBParameters, ref parametersOffset, (uint)MaximalAccessRights);
+            LittleEndianWriter.WriteUInt32(this.SMBParameters, ref parametersOffset, (uint)GuestMaximalAccessRights);
             return base.GetBytes(isUnicode);
         }
 

+ 7 - 7
SMBLibrary/SMB1/Commands/TreeConnectAndXResponseExtended.cs

@@ -18,9 +18,9 @@ namespace SMBLibrary.SMB1
     {
         public const int ParametersLength = 14;
         // Parameters:
-        //CommandName AndXCommand;
-        //byte AndXReserved;
-        //ushort AndXOffset;
+        // CommandName AndXCommand;
+        // byte AndXReserved;
+        // ushort AndXOffset;
         public OptionalSupportFlags OptionalSupport;
         public AccessMask MaximalShareAccessRights;
         public AccessMask GuestMaximalShareAccessRights;
@@ -36,8 +36,8 @@ namespace SMBLibrary.SMB1
         {
             int parametersOffset = 4;
             OptionalSupport = (OptionalSupportFlags)LittleEndianReader.ReadUInt16(this.SMBParameters, ref parametersOffset);
-            MaximalShareAccessRights = new AccessMask(this.SMBParameters, ref parametersOffset);
-            GuestMaximalShareAccessRights = new AccessMask(this.SMBParameters, ref parametersOffset);
+            MaximalShareAccessRights = (AccessMask)LittleEndianReader.ReadUInt32(this.SMBParameters, ref parametersOffset);
+            GuestMaximalShareAccessRights = (AccessMask)LittleEndianReader.ReadUInt32(this.SMBParameters, ref parametersOffset);
 
             int dataOffset = 0;
             string serviceString = ByteReader.ReadNullTerminatedAnsiString(this.SMBData, ref dataOffset);
@@ -51,8 +51,8 @@ namespace SMBLibrary.SMB1
             this.SMBParameters = new byte[ParametersLength];
             int parametersOffset = 4;
             LittleEndianWriter.WriteUInt16(this.SMBParameters, ref parametersOffset, (ushort)OptionalSupport);
-            MaximalShareAccessRights.WriteBytes(this.SMBParameters, ref parametersOffset);
-            GuestMaximalShareAccessRights.WriteBytes(this.SMBParameters, ref parametersOffset);
+            LittleEndianWriter.WriteUInt32(this.SMBParameters, ref parametersOffset, (uint)MaximalShareAccessRights);
+            LittleEndianWriter.WriteUInt32(this.SMBParameters, ref parametersOffset, (uint)GuestMaximalShareAccessRights);
 
             // Should be written as OEM string but it doesn't really matter
             string serviceString = ServiceNameHelper.GetServiceString(Service);

+ 5 - 5
SMBLibrary/SMB1/NTTransactSubcommands/NTTransactCreateRequest.cs

@@ -20,15 +20,15 @@ namespace SMBLibrary.SMB1
         // Parameters:
         public NTCreateFlags Flags;
         public uint RootDirectoryFID;
-        public FileAccessMask DesiredAccess;
+        public AccessMask DesiredAccess;
         public long AllocationSize;
         public ExtendedFileAttributes ExtFileAttributes;
         public ShareAccess ShareAccess;
         public CreateDisposition CreateDisposition;
         public CreateOptions CreateOptions;
-        //uint SecurityDescriptiorLength;
-        //uint EALength;
-        //uint NameLength;
+        // uint SecurityDescriptiorLength;
+        // uint EALength;
+        // uint NameLength;
         public ImpersonationLevel ImpersonationLevel;
         public SecurityFlags SecurityFlags;
         public string Name; // OEM / Unicode. NOT null terminated. (MUST be aligned to start on a 2-byte boundary from the start of the NT_Trans_Parameters)
@@ -45,7 +45,7 @@ namespace SMBLibrary.SMB1
             int parametersOffset = 0;
             Flags = (NTCreateFlags)LittleEndianReader.ReadUInt32(parameters, ref parametersOffset);
             RootDirectoryFID = LittleEndianReader.ReadUInt32(parameters, ref parametersOffset);
-            DesiredAccess = (FileAccessMask)LittleEndianReader.ReadUInt32(parameters, ref parametersOffset);
+            DesiredAccess = (AccessMask)LittleEndianReader.ReadUInt32(parameters, ref parametersOffset);
             AllocationSize = LittleEndianReader.ReadInt64(parameters, ref parametersOffset);
             ExtFileAttributes = (ExtendedFileAttributes)LittleEndianReader.ReadUInt32(parameters, ref parametersOffset);
             ShareAccess = (ShareAccess)LittleEndianReader.ReadUInt32(parameters, ref parametersOffset);

+ 2 - 2
SMBLibrary/SMB2/Commands/CreateRequest.cs

@@ -49,7 +49,7 @@ namespace SMBLibrary.SMB2
             ImpersonationLevel = (ImpersonationLevel)LittleEndianConverter.ToUInt32(buffer, offset + SMB2Header.Length + 4);
             SmbCreateFlags = LittleEndianConverter.ToUInt64(buffer, offset + SMB2Header.Length + 8);
             Reserved = LittleEndianConverter.ToUInt64(buffer, offset + SMB2Header.Length + 16);
-            DesiredAccess = new AccessMask(buffer, offset + SMB2Header.Length + 24);
+            DesiredAccess = (AccessMask)LittleEndianConverter.ToUInt32(buffer, offset + SMB2Header.Length + 24);
             FileAttributes = (FileAttributes)LittleEndianConverter.ToUInt32(buffer, offset + SMB2Header.Length + 28);
             ShareAccess = (ShareAccess)LittleEndianConverter.ToUInt32(buffer, offset + SMB2Header.Length + 32);
             CreateDisposition = (CreateDisposition)LittleEndianConverter.ToUInt32(buffer, offset + SMB2Header.Length + 36);
@@ -87,7 +87,7 @@ namespace SMBLibrary.SMB2
             LittleEndianWriter.WriteUInt32(buffer, offset + 4, (uint)ImpersonationLevel);
             LittleEndianWriter.WriteUInt64(buffer, offset + 8, (ulong)SmbCreateFlags);
             LittleEndianWriter.WriteUInt64(buffer, offset + 16, (ulong)Reserved);
-            DesiredAccess.WriteBytes(buffer, offset + 24);
+            LittleEndianWriter.WriteUInt32(buffer, offset + 24, (uint)DesiredAccess);
             LittleEndianWriter.WriteUInt32(buffer, offset + 28, (uint)FileAttributes);
             LittleEndianWriter.WriteUInt32(buffer, offset + 32, (uint)ShareAccess);
             LittleEndianWriter.WriteUInt32(buffer, offset + 36, (uint)CreateDisposition);

+ 2 - 2
SMBLibrary/SMB2/Commands/TreeConnectResponse.cs

@@ -37,7 +37,7 @@ namespace SMBLibrary.SMB2
             Reserved = ByteReader.ReadByte(buffer, offset + SMB2Header.Length + 3);
             ShareFlags = (ShareFlags)LittleEndianConverter.ToUInt32(buffer, offset + SMB2Header.Length + 4);
             Capabilities = (ShareCapabilities)LittleEndianConverter.ToUInt32(buffer, offset + SMB2Header.Length + 8);
-            MaximalAccess = new AccessMask(buffer, offset + SMB2Header.Length + 12);
+            MaximalAccess = (AccessMask)LittleEndianConverter.ToUInt32(buffer, offset + SMB2Header.Length + 12);
         }
 
         public override void WriteCommandBytes(byte[] buffer, int offset)
@@ -47,7 +47,7 @@ namespace SMBLibrary.SMB2
             ByteWriter.WriteByte(buffer, offset + 3, Reserved);
             LittleEndianWriter.WriteUInt32(buffer, offset + 4, (uint)ShareFlags);
             LittleEndianWriter.WriteUInt32(buffer, offset + 8, (uint)Capabilities);
-            MaximalAccess.WriteBytes(buffer, offset + 12);
+            LittleEndianWriter.WriteUInt32(buffer, offset + 12, (uint)MaximalAccess);
         }
 
         public override int CommandLength

+ 3 - 1
SMBLibrary/SMBLibrary.csproj

@@ -61,7 +61,6 @@
     <Compile Include="Enums\NTStatus.cs" />
     <Compile Include="Enums\SMBTransportType.cs" />
     <Compile Include="Enums\Win32Error.cs" />
-    <Compile Include="EnumStructures\AccessMask.cs" />
     <Compile Include="Exceptions\UnsupportedInformationLevelException.cs" />
     <Compile Include="Helpers\FileTimeHelper.cs" />
     <Compile Include="NetBios\NameServicePackets\Enums\NameRecordType.cs" />
@@ -94,6 +93,9 @@
     <Compile Include="NTFileStore\Adapter\NTFileSystemAdapter.QueryDirectory.cs" />
     <Compile Include="NTFileStore\Adapter\NTFileSystemAdapter.QueryFileSystem.cs" />
     <Compile Include="NTFileStore\Adapter\NTFileSystemAdapter.Set.cs" />
+    <Compile Include="NTFileStore\Enums\AccessMask\AccessMask.cs" />
+    <Compile Include="NTFileStore\Enums\AccessMask\DirectoryAccessMask.cs" />
+    <Compile Include="NTFileStore\Enums\AccessMask\FileAccessMask.cs" />
     <Compile Include="NTFileStore\Enums\FileInformation\CompressionFormat.cs" />
     <Compile Include="NTFileStore\Enums\FileInformation\ExtendedAttributeFlags.cs" />
     <Compile Include="NTFileStore\Enums\FileInformation\FileAttributes.cs" />

+ 19 - 19
SMBLibrary/Server/SMB1/NTCreateHelper.cs

@@ -41,7 +41,7 @@ namespace SMBLibrary.Server.SMB1
             FileStatus fileStatus;
             FileAttributes fileAttributes = ToFileAttributes(request.ExtFileAttributes);
             // GetFileInformation/FileNetworkOpenInformation requires FILE_READ_ATTRIBUTES
-            FileAccessMask desiredAccess = request.DesiredAccess | FileAccessMask.FILE_READ_ATTRIBUTES;
+            AccessMask desiredAccess = request.DesiredAccess | (AccessMask)FileAccessMask.FILE_READ_ATTRIBUTES;
             NTStatus createStatus = share.FileStore.CreateFile(out handle, out fileStatus, path, desiredAccess, fileAttributes, request.ShareAccess, request.CreateDisposition, request.CreateOptions, session.SecurityContext);
             if (createStatus != NTStatus.STATUS_SUCCESS)
             {
@@ -112,15 +112,15 @@ namespace SMBLibrary.Server.SMB1
             status.ReadMode = ReadMode.MessageMode;
             status.NamedPipeType = NamedPipeType.MessageModePipe;
             response.NMPipeStatus = status;
-            response.MaximalAccessRights.File = FileAccessMask.FILE_READ_DATA | FileAccessMask.FILE_WRITE_DATA | FileAccessMask.FILE_APPEND_DATA |
-                                                FileAccessMask.FILE_READ_EA | FileAccessMask.FILE_WRITE_EA |
-                                                FileAccessMask.FILE_EXECUTE |
-                                                FileAccessMask.FILE_READ_ATTRIBUTES | FileAccessMask.FILE_WRITE_ATTRIBUTES |
-                                                FileAccessMask.DELETE | FileAccessMask.READ_CONTROL | FileAccessMask.WRITE_DAC | FileAccessMask.WRITE_OWNER | FileAccessMask.SYNCHRONIZE;
-            response.GuestMaximalAccessRights.File = FileAccessMask.FILE_READ_DATA | FileAccessMask.FILE_WRITE_DATA |
-                                                    FileAccessMask.FILE_READ_EA | FileAccessMask.FILE_WRITE_EA |
-                                                    FileAccessMask.FILE_READ_ATTRIBUTES | FileAccessMask.FILE_WRITE_ATTRIBUTES |
-                                                    FileAccessMask.READ_CONTROL | FileAccessMask.SYNCHRONIZE;
+            response.MaximalAccessRights = (AccessMask)(FileAccessMask.FILE_READ_DATA | FileAccessMask.FILE_WRITE_DATA | FileAccessMask.FILE_APPEND_DATA |
+                                                        FileAccessMask.FILE_READ_EA | FileAccessMask.FILE_WRITE_EA |
+                                                        FileAccessMask.FILE_EXECUTE |
+                                                        FileAccessMask.FILE_READ_ATTRIBUTES | FileAccessMask.FILE_WRITE_ATTRIBUTES) |
+                                                        AccessMask.DELETE | AccessMask.READ_CONTROL | AccessMask.WRITE_DAC | AccessMask.WRITE_OWNER | AccessMask.SYNCHRONIZE;
+            response.GuestMaximalAccessRights = (AccessMask)(FileAccessMask.FILE_READ_DATA | FileAccessMask.FILE_WRITE_DATA |
+                                                             FileAccessMask.FILE_READ_EA | FileAccessMask.FILE_WRITE_EA |
+                                                             FileAccessMask.FILE_READ_ATTRIBUTES | FileAccessMask.FILE_WRITE_ATTRIBUTES) |
+                                                             AccessMask.READ_CONTROL | AccessMask.SYNCHRONIZE;
             return response;
         }
 
@@ -156,15 +156,15 @@ namespace SMBLibrary.Server.SMB1
             response.ResourceType = ResourceType.FileTypeDisk;
             response.FileStatusFlags = FileStatusFlags.NO_EAS | FileStatusFlags.NO_SUBSTREAMS | FileStatusFlags.NO_REPARSETAG;
             response.Directory = fileInfo.IsDirectory;
-            response.MaximalAccessRights.File = FileAccessMask.FILE_READ_DATA | FileAccessMask.FILE_WRITE_DATA | FileAccessMask.FILE_APPEND_DATA |
-                                                FileAccessMask.FILE_READ_EA | FileAccessMask.FILE_WRITE_EA |
-                                                FileAccessMask.FILE_EXECUTE |
-                                                FileAccessMask.FILE_READ_ATTRIBUTES | FileAccessMask.FILE_WRITE_ATTRIBUTES |
-                                                FileAccessMask.DELETE | FileAccessMask.READ_CONTROL | FileAccessMask.WRITE_DAC | FileAccessMask.WRITE_OWNER | FileAccessMask.SYNCHRONIZE;
-            response.GuestMaximalAccessRights.File = FileAccessMask.FILE_READ_DATA | FileAccessMask.FILE_WRITE_DATA |
-                                                    FileAccessMask.FILE_READ_EA | FileAccessMask.FILE_WRITE_EA |
-                                                    FileAccessMask.FILE_READ_ATTRIBUTES | FileAccessMask.FILE_WRITE_ATTRIBUTES |
-                                                    FileAccessMask.READ_CONTROL | FileAccessMask.SYNCHRONIZE;
+            response.MaximalAccessRights = (AccessMask)(FileAccessMask.FILE_READ_DATA | FileAccessMask.FILE_WRITE_DATA | FileAccessMask.FILE_APPEND_DATA |
+                                                        FileAccessMask.FILE_READ_EA | FileAccessMask.FILE_WRITE_EA |
+                                                        FileAccessMask.FILE_EXECUTE |
+                                                        FileAccessMask.FILE_READ_ATTRIBUTES | FileAccessMask.FILE_WRITE_ATTRIBUTES) |
+                                                        AccessMask.DELETE | AccessMask.READ_CONTROL | AccessMask.WRITE_DAC | AccessMask.WRITE_OWNER | AccessMask.SYNCHRONIZE;
+            response.GuestMaximalAccessRights = (AccessMask)(FileAccessMask.FILE_READ_DATA | FileAccessMask.FILE_WRITE_DATA |
+                                                             FileAccessMask.FILE_READ_EA | FileAccessMask.FILE_WRITE_EA |
+                                                             FileAccessMask.FILE_READ_ATTRIBUTES | FileAccessMask.FILE_WRITE_ATTRIBUTES) |
+                                                             AccessMask.READ_CONTROL | AccessMask.SYNCHRONIZE;
             return response;
         }
 

+ 14 - 14
SMBLibrary/Server/SMB1/OpenAndXHelper.cs

@@ -103,19 +103,19 @@ namespace SMBLibrary.Server.SMB1
         {
             if (accessMode == AccessMode.Read)
             {
-                return FileAccessMask.GENERIC_READ;
+                return AccessMask.GENERIC_READ;
             }
-            if (accessMode == AccessMode.Write)
+            else if (accessMode == AccessMode.Write)
             {
-                return FileAccessMask.GENERIC_WRITE | FileAccessMask.FILE_READ_ATTRIBUTES;
+                return AccessMask.GENERIC_WRITE | (AccessMask)FileAccessMask.FILE_READ_ATTRIBUTES;
             }
             else if (accessMode == AccessMode.ReadWrite)
             {
-                return FileAccessMask.GENERIC_READ | FileAccessMask.GENERIC_WRITE;
+                return AccessMask.GENERIC_READ | AccessMask.GENERIC_WRITE;
             }
             else if (accessMode == AccessMode.Execute)
             {
-                return FileAccessMask.GENERIC_READ | FileAccessMask.GENERIC_EXECUTE;
+                return AccessMask.GENERIC_READ | AccessMask.GENERIC_EXECUTE;
             }
             else
             {
@@ -301,15 +301,15 @@ namespace SMBLibrary.Server.SMB1
             response.AccessRights = AccessRights.SMB_DA_ACCESS_READ;
             response.ResourceType = ResourceType.FileTypeDisk;
             response.OpenResults.OpenResult = openResult;
-            response.MaximalAccessRights.File = FileAccessMask.FILE_READ_DATA | FileAccessMask.FILE_WRITE_DATA | FileAccessMask.FILE_APPEND_DATA |
-                                                FileAccessMask.FILE_READ_EA | FileAccessMask.FILE_WRITE_EA |
-                                                FileAccessMask.FILE_EXECUTE |
-                                                FileAccessMask.FILE_READ_ATTRIBUTES | FileAccessMask.FILE_WRITE_ATTRIBUTES |
-                                                FileAccessMask.DELETE | FileAccessMask.READ_CONTROL | FileAccessMask.WRITE_DAC | FileAccessMask.WRITE_OWNER | FileAccessMask.SYNCHRONIZE;
-            response.GuestMaximalAccessRights.File = FileAccessMask.FILE_READ_DATA | FileAccessMask.FILE_WRITE_DATA |
-                                                    FileAccessMask.FILE_READ_EA | FileAccessMask.FILE_WRITE_EA |
-                                                    FileAccessMask.FILE_READ_ATTRIBUTES | FileAccessMask.FILE_WRITE_ATTRIBUTES |
-                                                    FileAccessMask.READ_CONTROL | FileAccessMask.SYNCHRONIZE;
+            response.MaximalAccessRights = (AccessMask)(FileAccessMask.FILE_READ_DATA | FileAccessMask.FILE_WRITE_DATA | FileAccessMask.FILE_APPEND_DATA |
+                                                        FileAccessMask.FILE_READ_EA | FileAccessMask.FILE_WRITE_EA |
+                                                        FileAccessMask.FILE_EXECUTE |
+                                                        FileAccessMask.FILE_READ_ATTRIBUTES | FileAccessMask.FILE_WRITE_ATTRIBUTES) |
+                                                        AccessMask.DELETE | AccessMask.READ_CONTROL | AccessMask.WRITE_DAC | AccessMask.WRITE_OWNER | AccessMask.SYNCHRONIZE;
+            response.GuestMaximalAccessRights = (AccessMask)(FileAccessMask.FILE_READ_DATA | FileAccessMask.FILE_WRITE_DATA |
+                                                             FileAccessMask.FILE_READ_EA | FileAccessMask.FILE_WRITE_EA |
+                                                             FileAccessMask.FILE_READ_ATTRIBUTES | FileAccessMask.FILE_WRITE_ATTRIBUTES) |
+                                                             AccessMask.READ_CONTROL | AccessMask.SYNCHRONIZE;
             return response;
         }
     }

+ 1 - 1
SMBLibrary/Server/SMB1/SMB1FileStoreHelper.Query.cs

@@ -18,7 +18,7 @@ namespace SMBLibrary.Server.SMB1
         {
             object handle;
             FileStatus fileStatus;
-            NTStatus openStatus = fileStore.CreateFile(out handle, out fileStatus, path, FileAccessMask.FILE_READ_ATTRIBUTES, 0, ShareAccess.FILE_SHARE_READ | ShareAccess.FILE_SHARE_WRITE, CreateDisposition.FILE_OPEN, 0, securityContext);
+            NTStatus openStatus = fileStore.CreateFile(out handle, out fileStatus, path, (AccessMask)FileAccessMask.FILE_READ_ATTRIBUTES, 0, ShareAccess.FILE_SHARE_READ | ShareAccess.FILE_SHARE_WRITE, CreateDisposition.FILE_OPEN, 0, securityContext);
             if (openStatus != NTStatus.STATUS_SUCCESS)
             {
                 result = null;

+ 1 - 1
SMBLibrary/Server/SMB1/SMB1FileStoreHelper.QueryDirectory.cs

@@ -33,7 +33,7 @@ namespace SMBLibrary.Server.SMB1
                 FileStatus fileStatus;
                 DirectoryAccessMask accessMask = DirectoryAccessMask.FILE_LIST_DIRECTORY | DirectoryAccessMask.FILE_TRAVERSE | DirectoryAccessMask.SYNCHRONIZE;
                 CreateOptions createOptions = CreateOptions.FILE_DIRECTORY_FILE | CreateOptions.FILE_SYNCHRONOUS_IO_NONALERT;
-                NTStatus status = fileStore.CreateFile(out handle, out fileStatus, path, accessMask, 0, ShareAccess.FILE_SHARE_READ | ShareAccess.FILE_SHARE_WRITE, CreateDisposition.FILE_OPEN, createOptions, securityContext);
+                NTStatus status = fileStore.CreateFile(out handle, out fileStatus, path, (AccessMask)accessMask, 0, ShareAccess.FILE_SHARE_READ | ShareAccess.FILE_SHARE_WRITE, CreateDisposition.FILE_OPEN, createOptions, securityContext);
                 if (status != NTStatus.STATUS_SUCCESS)
                 {
                     result = null;

+ 5 - 5
SMBLibrary/Server/SMB1/SMB1FileStoreHelper.cs

@@ -18,7 +18,7 @@ namespace SMBLibrary.Server.SMB1
         {
             object handle;
             FileStatus fileStatus;
-            NTStatus createStatus = fileStore.CreateFile(out handle, out fileStatus, path, DirectoryAccessMask.FILE_ADD_SUBDIRECTORY, 0, ShareAccess.FILE_SHARE_READ | ShareAccess.FILE_SHARE_WRITE, CreateDisposition.FILE_CREATE, CreateOptions.FILE_DIRECTORY_FILE, securityContext);
+            NTStatus createStatus = fileStore.CreateFile(out handle, out fileStatus, path, (AccessMask)DirectoryAccessMask.FILE_ADD_SUBDIRECTORY, 0, ShareAccess.FILE_SHARE_READ | ShareAccess.FILE_SHARE_WRITE, CreateDisposition.FILE_CREATE, CreateOptions.FILE_DIRECTORY_FILE, securityContext);
             if (createStatus != NTStatus.STATUS_SUCCESS)
             {
                 return createStatus;
@@ -42,7 +42,7 @@ namespace SMBLibrary.Server.SMB1
             object handle;
             FileStatus fileStatus;
             ShareAccess shareAccess = ShareAccess.FILE_SHARE_READ | ShareAccess.FILE_SHARE_WRITE | ShareAccess.FILE_SHARE_DELETE;
-            NTStatus status = fileStore.CreateFile(out handle, out fileStatus, path, DirectoryAccessMask.DELETE, 0, shareAccess, CreateDisposition.FILE_OPEN, createOptions, securityContext);
+            NTStatus status = fileStore.CreateFile(out handle, out fileStatus, path, AccessMask.DELETE, 0, shareAccess, CreateDisposition.FILE_OPEN, createOptions, securityContext);
             if (status != NTStatus.STATUS_SUCCESS)
             {
                 return status;
@@ -66,7 +66,7 @@ namespace SMBLibrary.Server.SMB1
                 createOptions = CreateOptions.FILE_NON_DIRECTORY_FILE;
             }
             ShareAccess shareAccess = ShareAccess.FILE_SHARE_READ | ShareAccess.FILE_SHARE_WRITE | ShareAccess.FILE_SHARE_DELETE;
-            NTStatus status = fileStore.CreateFile(out handle, out fileStatus, oldName, DirectoryAccessMask.DELETE, 0, shareAccess, CreateDisposition.FILE_OPEN, createOptions, securityContext);
+            NTStatus status = fileStore.CreateFile(out handle, out fileStatus, oldName, AccessMask.DELETE, 0, shareAccess, CreateDisposition.FILE_OPEN, createOptions, securityContext);
             if (status != NTStatus.STATUS_SUCCESS)
             {
                 return status;
@@ -97,7 +97,7 @@ namespace SMBLibrary.Server.SMB1
         {
             object handle;
             FileStatus fileStatus;
-            NTStatus openStatus = fileStore.CreateFile(out handle, out fileStatus, path, FileAccessMask.FILE_READ_ATTRIBUTES, 0, ShareAccess.FILE_SHARE_READ | ShareAccess.FILE_SHARE_WRITE, CreateDisposition.FILE_OPEN, 0, securityContext);
+            NTStatus openStatus = fileStore.CreateFile(out handle, out fileStatus, path, (AccessMask)FileAccessMask.FILE_READ_ATTRIBUTES, 0, ShareAccess.FILE_SHARE_READ | ShareAccess.FILE_SHARE_WRITE, CreateDisposition.FILE_OPEN, 0, securityContext);
             if (openStatus != NTStatus.STATUS_SUCCESS)
             {
                 fileInfo = null;
@@ -113,7 +113,7 @@ namespace SMBLibrary.Server.SMB1
         {
             object handle;
             FileStatus fileStatus;
-            NTStatus status = fileStore.CreateFile(out handle, out fileStatus, path, FileAccessMask.FILE_WRITE_ATTRIBUTES, (FileAttributes)0, ShareAccess.FILE_SHARE_READ | ShareAccess.FILE_SHARE_WRITE, CreateDisposition.FILE_OPEN, 0, securityContext);
+            NTStatus status = fileStore.CreateFile(out handle, out fileStatus, path, (AccessMask)FileAccessMask.FILE_WRITE_ATTRIBUTES, (FileAttributes)0, ShareAccess.FILE_SHARE_READ | ShareAccess.FILE_SHARE_WRITE, CreateDisposition.FILE_OPEN, 0, securityContext);
             if (status != NTStatus.STATUS_SUCCESS)
             {
                 return status;

+ 9 - 9
SMBLibrary/Server/SMB1/TreeConnectHelper.cs

@@ -93,15 +93,15 @@ namespace SMBLibrary.Server.SMB1
         {
             TreeConnectAndXResponseExtended response = new TreeConnectAndXResponseExtended();
             response.OptionalSupport = supportFlags;
-            response.MaximalShareAccessRights.File = FileAccessMask.FILE_READ_DATA | FileAccessMask.FILE_WRITE_DATA | FileAccessMask.FILE_APPEND_DATA |
-                                                        FileAccessMask.FILE_READ_EA | FileAccessMask.FILE_WRITE_EA |
-                                                        FileAccessMask.FILE_EXECUTE |
-                                                        FileAccessMask.FILE_READ_ATTRIBUTES | FileAccessMask.FILE_WRITE_ATTRIBUTES |
-                                                        FileAccessMask.DELETE | FileAccessMask.READ_CONTROL | FileAccessMask.WRITE_DAC | FileAccessMask.WRITE_OWNER | FileAccessMask.SYNCHRONIZE;
-            response.GuestMaximalShareAccessRights.File = FileAccessMask.FILE_READ_DATA | FileAccessMask.FILE_WRITE_DATA |
-                                                            FileAccessMask.FILE_READ_EA | FileAccessMask.FILE_WRITE_EA |
-                                                            FileAccessMask.FILE_READ_ATTRIBUTES | FileAccessMask.FILE_WRITE_ATTRIBUTES |
-                                                            FileAccessMask.READ_CONTROL | FileAccessMask.SYNCHRONIZE;
+            response.MaximalShareAccessRights = (AccessMask)(FileAccessMask.FILE_READ_DATA | FileAccessMask.FILE_WRITE_DATA | FileAccessMask.FILE_APPEND_DATA |
+                                                             FileAccessMask.FILE_READ_EA | FileAccessMask.FILE_WRITE_EA |
+                                                             FileAccessMask.FILE_EXECUTE |
+                                                             FileAccessMask.FILE_READ_ATTRIBUTES | FileAccessMask.FILE_WRITE_ATTRIBUTES) |
+                                                             AccessMask.DELETE | AccessMask.READ_CONTROL | AccessMask.WRITE_DAC | AccessMask.WRITE_OWNER | AccessMask.SYNCHRONIZE;
+            response.GuestMaximalShareAccessRights = (AccessMask)(FileAccessMask.FILE_READ_DATA | FileAccessMask.FILE_WRITE_DATA |
+                                                                  FileAccessMask.FILE_READ_EA | FileAccessMask.FILE_WRITE_EA |
+                                                                  FileAccessMask.FILE_READ_ATTRIBUTES | FileAccessMask.FILE_WRITE_ATTRIBUTES) |
+                                                                  AccessMask.READ_CONTROL | AccessMask.SYNCHRONIZE;
             response.NativeFileSystem = String.Empty;
             response.Service = serviceName;
             return response;

+ 1 - 1
SMBLibrary/Server/SMB2/CreateHelper.cs

@@ -36,7 +36,7 @@ namespace SMBLibrary.Server.SMB2
             object handle;
             FileStatus fileStatus;
             // GetFileInformation/FileNetworkOpenInformation requires FILE_READ_ATTRIBUTES
-            AccessMask desiredAccess = request.DesiredAccess.File | FileAccessMask.FILE_READ_ATTRIBUTES;
+            AccessMask desiredAccess = request.DesiredAccess | (AccessMask)FileAccessMask.FILE_READ_ATTRIBUTES;
             NTStatus createStatus = share.FileStore.CreateFile(out handle, out fileStatus, path, desiredAccess, request.FileAttributes, request.ShareAccess, request.CreateDisposition, request.CreateOptions, session.SecurityContext);
             if (createStatus != NTStatus.STATUS_SUCCESS)
             {

+ 5 - 5
SMBLibrary/Server/SMB2/TreeConnectHelper.cs

@@ -54,11 +54,11 @@ namespace SMBLibrary.Server.SMB2
             response.Header.TreeID = treeID.Value;
             response.ShareType = shareType;
             response.ShareFlags = shareFlags;
-            response.MaximalAccess.File = FileAccessMask.FILE_READ_DATA | FileAccessMask.FILE_WRITE_DATA | FileAccessMask.FILE_APPEND_DATA |
-                                          FileAccessMask.FILE_READ_EA | FileAccessMask.FILE_WRITE_EA |
-                                          FileAccessMask.FILE_EXECUTE |
-                                          FileAccessMask.FILE_READ_ATTRIBUTES | FileAccessMask.FILE_WRITE_ATTRIBUTES |
-                                          FileAccessMask.DELETE | FileAccessMask.READ_CONTROL | FileAccessMask.WRITE_DAC | FileAccessMask.WRITE_OWNER | FileAccessMask.SYNCHRONIZE;
+            response.MaximalAccess = (AccessMask)(FileAccessMask.FILE_READ_DATA | FileAccessMask.FILE_WRITE_DATA | FileAccessMask.FILE_APPEND_DATA |
+                                                  FileAccessMask.FILE_READ_EA | FileAccessMask.FILE_WRITE_EA |
+                                                  FileAccessMask.FILE_EXECUTE |
+                                                  FileAccessMask.FILE_READ_ATTRIBUTES | FileAccessMask.FILE_WRITE_ATTRIBUTES) |
+                                                  AccessMask.DELETE | AccessMask.READ_CONTROL | AccessMask.WRITE_DAC | AccessMask.WRITE_OWNER | AccessMask.SYNCHRONIZE;
             return response;
         }
 

+ 3 - 3
SMBLibrary/Win32/NTFileStore/NTDirectoryFileSystem.cs

@@ -165,12 +165,12 @@ namespace SMBLibrary.Win32
             // NtQueryDirectoryFile will return STATUS_PENDING if the directory handle was not opened with SYNCHRONIZE and FILE_SYNCHRONOUS_IO_ALERT or FILE_SYNCHRONOUS_IO_NONALERT.
             // Our usage of NtNotifyChangeDirectoryFile assumes the directory handle is opened with SYNCHRONIZE and FILE_SYNCHRONOUS_IO_ALERT (or FILE_SYNCHRONOUS_IO_NONALERT starting from Windows Vista).
             // Note: Sometimes a directory will be opened without specifying FILE_DIRECTORY_FILE.
-            desiredAccess.Directory |= DirectoryAccessMask.SYNCHRONIZE;
+            desiredAccess |= AccessMask.SYNCHRONIZE;
             createOptions &= ~CreateOptions.FILE_SYNCHRONOUS_IO_NONALERT;
             createOptions |= CreateOptions.FILE_SYNCHRONOUS_IO_ALERT;
 
             if ((createOptions & CreateOptions.FILE_NO_INTERMEDIATE_BUFFERING) > 0 &&
-                (desiredAccess.File & FileAccessMask.FILE_APPEND_DATA) > 0)
+                ((FileAccessMask)desiredAccess & FileAccessMask.FILE_APPEND_DATA) > 0)
             {
                 // FILE_NO_INTERMEDIATE_BUFFERING is incompatible with FILE_APPEND_DATA
                 // [MS-SMB2] 3.3.5.9 suggests setting FILE_APPEND_DATA to zero in this case.
@@ -345,7 +345,7 @@ namespace SMBLibrary.Win32
             IntPtr volumeHandle;
             FileStatus fileStatus;
             string nativePath = @"\??\" + m_directory.FullName.Substring(0, 3);
-            NTStatus status = CreateFile(out volumeHandle, out fileStatus, nativePath, DirectoryAccessMask.GENERIC_READ, 0, (FileAttributes)0, ShareAccess.FILE_SHARE_READ, CreateDisposition.FILE_OPEN, (CreateOptions)0);
+            NTStatus status = CreateFile(out volumeHandle, out fileStatus, nativePath, AccessMask.GENERIC_READ, 0, (FileAttributes)0, ShareAccess.FILE_SHARE_READ, CreateDisposition.FILE_OPEN, (CreateOptions)0);
             result = null;
             if (status != NTStatus.STATUS_SUCCESS)
             {