ACL.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* Copyright (C) 2014-2017 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
  2. *
  3. * You can redistribute this program and/or modify it under the terms of
  4. * the GNU Lesser Public License as published by the Free Software Foundation,
  5. * either version 3 of the License, or (at your option) any later version.
  6. */
  7. using System;
  8. using System.Collections.Generic;
  9. using Utilities;
  10. namespace SMBLibrary
  11. {
  12. /// <summary>
  13. /// [MS-DTYP] ACL (Access Control List)
  14. /// </summary>
  15. public class ACL : List<ACE>
  16. {
  17. public const int FixedLength = 8;
  18. public byte AclRevision;
  19. public byte Sbz1;
  20. // ushort AclSize;
  21. // ushort AceCount;
  22. public ushort Sbz2;
  23. public ACL()
  24. {
  25. AclRevision = 0x02;
  26. }
  27. public ACL(byte[] buffer, int offset)
  28. {
  29. AclRevision = ByteReader.ReadByte(buffer, offset + 0);
  30. Sbz1 = ByteReader.ReadByte(buffer, offset + 1);
  31. ushort aclSize = LittleEndianConverter.ToUInt16(buffer, offset + 2);
  32. ushort aceCount = LittleEndianConverter.ToUInt16(buffer, offset + 4);
  33. Sbz2 = LittleEndianConverter.ToUInt16(buffer, offset + 6);
  34. offset += 8;
  35. for (int index = 0; index < aceCount; index++)
  36. {
  37. ACE ace = ACE.GetAce(buffer, offset);
  38. this.Add(ace);
  39. offset += ace.Length;
  40. }
  41. }
  42. public void WriteBytes(byte[] buffer, ref int offset)
  43. {
  44. ByteWriter.WriteByte(buffer, ref offset, AclRevision);
  45. ByteWriter.WriteByte(buffer, ref offset, Sbz1);
  46. LittleEndianWriter.WriteUInt16(buffer, ref offset, (ushort)Length);
  47. LittleEndianWriter.WriteUInt16(buffer, ref offset, (ushort)Count);
  48. LittleEndianWriter.WriteUInt16(buffer, ref offset, Sbz2);
  49. foreach (ACE ace in this)
  50. {
  51. ace.WriteBytes(buffer, ref offset);
  52. }
  53. }
  54. public int Length
  55. {
  56. get
  57. {
  58. int length = FixedLength;
  59. foreach (ACE ace in this)
  60. {
  61. length += ace.Length;
  62. }
  63. return length;
  64. }
  65. }
  66. }
  67. }