SecurityIdentifier.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. //
  2. // System.Security.Policy.SecurityIdentifier class
  3. //
  4. // Author:
  5. // Sebastien Pouliot <[email protected]>
  6. //
  7. // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining
  10. // a copy of this software and associated documentation files (the
  11. // "Software"), to deal in the Software without restriction, including
  12. // without limitation the rights to use, copy, modify, merge, publish,
  13. // distribute, sublicense, and/or sell copies of the Software, and to
  14. // permit persons to whom the Software is furnished to do so, subject to
  15. // the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. #if NET_2_0
  29. using System.Globalization;
  30. using System.Runtime.InteropServices;
  31. namespace System.Security.Principal {
  32. [MonoTODO ("not implemented")]
  33. [ComVisible (false)]
  34. public sealed class SecurityIdentifier : IdentityReference, IComparable<SecurityIdentifier> {
  35. private string _value;
  36. public static readonly int MaxBinaryLength = 0;
  37. public static readonly int MinBinaryLength = 0;
  38. public SecurityIdentifier (string sddlForm)
  39. {
  40. if (sddlForm == null)
  41. throw new ArgumentNullException ("sddlForm");
  42. _value = sddlForm.ToUpperInvariant ();
  43. }
  44. public SecurityIdentifier (byte[] binaryForm, int offset)
  45. {
  46. if (binaryForm == null)
  47. throw new ArgumentNullException ("binaryForm");
  48. if ((offset < 0) || (offset > binaryForm.Length - 1))
  49. throw new ArgumentException ("offset");
  50. throw new NotImplementedException ();
  51. }
  52. public SecurityIdentifier (IntPtr binaryForm)
  53. {
  54. throw new NotImplementedException ();
  55. }
  56. public SecurityIdentifier (WellKnownSidType sidType, SecurityIdentifier domainSid)
  57. {
  58. switch (sidType) {
  59. case WellKnownSidType.LogonIdsSid:
  60. throw new ArgumentException ("sidType");
  61. case WellKnownSidType.AccountAdministratorSid:
  62. case WellKnownSidType.AccountGuestSid:
  63. case WellKnownSidType.AccountKrbtgtSid:
  64. case WellKnownSidType.AccountDomainAdminsSid:
  65. case WellKnownSidType.AccountDomainUsersSid:
  66. case WellKnownSidType.AccountDomainGuestsSid:
  67. case WellKnownSidType.AccountComputersSid:
  68. case WellKnownSidType.AccountControllersSid:
  69. case WellKnownSidType.AccountCertAdminsSid:
  70. case WellKnownSidType.AccountSchemaAdminsSid:
  71. case WellKnownSidType.AccountEnterpriseAdminsSid:
  72. case WellKnownSidType.AccountPolicyAdminsSid:
  73. case WellKnownSidType.AccountRasAndIasServersSid:
  74. if (domainSid == null)
  75. throw new ArgumentNullException ("domainSid");
  76. // TODO
  77. break;
  78. default:
  79. // TODO
  80. break;
  81. }
  82. }
  83. public SecurityIdentifier AccountDomainSid {
  84. get { throw new ArgumentNullException ("AccountDomainSid"); }
  85. }
  86. public int BinaryLength {
  87. get { return -1; }
  88. }
  89. public override string Value {
  90. get { return _value; }
  91. }
  92. public int CompareTo (SecurityIdentifier sid)
  93. {
  94. return Value.CompareTo (sid.Value);
  95. }
  96. public override bool Equals (object o)
  97. {
  98. return Equals (o as SecurityIdentifier);
  99. }
  100. public bool Equals (SecurityIdentifier sid)
  101. {
  102. if (sid == null)
  103. return false;
  104. return (sid.Value == Value);
  105. }
  106. public void GetBinaryForm (byte[] binaryForm, int offset)
  107. {
  108. if (binaryForm == null)
  109. throw new ArgumentNullException ("binaryForm");
  110. if ((offset < 0) || (offset > binaryForm.Length - 1 - this.BinaryLength))
  111. throw new ArgumentException ("offset");
  112. // TODO
  113. }
  114. public override int GetHashCode ()
  115. {
  116. return Value.GetHashCode ();
  117. }
  118. public bool IsAccountSid ()
  119. {
  120. throw new NotImplementedException ();
  121. }
  122. public bool IsEqualDomainSid (SecurityIdentifier sid)
  123. {
  124. throw new NotImplementedException ();
  125. }
  126. public override bool IsValidTargetType (Type targetType)
  127. {
  128. if (targetType == typeof (SecurityIdentifier))
  129. return true;
  130. if (targetType == typeof (NTAccount))
  131. return true;
  132. return false;
  133. }
  134. public bool IsWellKnown (WellKnownSidType type)
  135. {
  136. throw new NotImplementedException ();
  137. }
  138. public override string ToString ()
  139. {
  140. return Value;
  141. }
  142. public override IdentityReference Translate (Type targetType)
  143. {
  144. if (targetType == typeof (SecurityIdentifier))
  145. return this; // ? copy
  146. return null;
  147. }
  148. }
  149. }
  150. #endif