Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,144 @@
2008-05-30 Sebastien Pouliot <sebastien@ximian.com>
* IdentityReferenceCollection.cs: Remove MonoTODO and throw NIE.
2007-07-28 Miguel de Icaza <miguel@novell.com>
* IdentityReference.cs, SecurityIdentifier.cs, NTAccount.cs: Do
not recurse infinitely as reported by Jesse Jones, the problem was
the comparison to null.
2006-12-22 Sebastien Pouliot <sebastien@ximian.com>
* NTAccount.cs: Implement == and != operators (MoMA reports).
* SecurityIdentifier.cs: Implement == and != operators (MoMA reports).
2006-08-08 Sebastien Pouliot <sebastien@ximian.com>
* GenericIdentity.cs: Rename fields to match MS for serialization
(indirecly required to fix GenericPrincipal serialization). Also
renamed ctor parameters to match fx.
* GenericPrincipal.cs: Rename fields to match MS for serialization.
Fix bug #79030.
Wed Nov 30 19:09:50 CET 2005 Paolo Molaro <lupus@ximian.com>
* WindowsIdentity.cs: remove check for an invalid user token on Posix
systems and check for PlatformID.Unix, too.
2005-10-28 Sebastien Pouliot <sebastien@ximian.com>
* IdentityReferenceCollection.cs: Removed virtual from Count and
IsReadOnly properties.
* WindowsIdentity.cs: AuthenticationType property isn't virtual in 2.0
2005-09-25 Sebastien Pouliot <sebastien@ximian.com>
* SecurityIdentifier.cs: Stubbed ctor(IntPtr) introduced in 2.0 RC.
2005-08-22 Sebastien Pouliot <sebastien@ximian.com>
* GenericPrincipal.cs: Roles are case-insensitive.
2005-06-18 Sebastien Pouliot <sebastien@ximian.com>
* IdentityReference.cs: Constructor is internal (which means it the
class cannot be inherited outside corlib).
2005-06-17 Sebastien Pouliot <sebastien@ximian.com>
* IdentityNotMappedException.cs: New (2.0). Identity exception.
* IdentityReference.cs: New (2.0). Abstract base class to collect /
translate identities.
* IdentityReferenceCollection.cs: New. (2.0) Collection of
IdentityReference (e.g. groups).
* NTAccount.cs: New (2.0). Domain/User (string based)
IdentityReference.
* SecurityIdentifier.cs: New (2.0). SID (binary based)
IdentityReference.
* TokenAccessLevels.cs: New (2.0). Type of identity token.
* TokenImpersonationLevel.cs: Fixed name in header.
* WellKnownSidType.cs: New (2.0). Enum of all well known SID.
* WindowsIdentity.cs: Implement IDisposable for 2.0. Add Identity
Reference support for User, Owner and a collection for groups.
* WindowsImpersonationContext.cs: Implement IDisposable for 2.0.
* WindowsPrincipal.cs: Added IsInRole(SecurityIdentifier) for 2.0.
2005-04-22 Sebastien Pouliot <sebastien@ximian.com>
* GenericIdentity.cs: Added [ComVisible(true)] for NET_2_0.
* GenericPrincipal.cs: Added [ComVisible(true)] for NET_2_0.
* IIdentity.cs: Added [ComVisible(true)] for NET_2_0.
* IPrincipal.cs: Added [ComVisible(true)] for NET_2_0.
* PrincipalPolicy.cs: Added [ComVisible(true)] for NET_2_0.
* TokenImpersonationLevel.cs: Added [ComVisible(true)] for NET_2_0.
* WindowsAccountType.cs: Added [ComVisible(true)] for NET_2_0.
* WindowsBuiltInRole.cs: Added [ComVisible(true)] for NET_2_0.
2005-01-24 Sebastien Pouliot <sebastien@ximian.com>
* WindowsIdentity.cs: Added security permissions for ControlPrincipal
when creating new instances of WindowsIdentity.
2004-09-12 Tim Coleman <tim@timcoleamn.com>
* TokenImpersonationLevel.cs: New enum for Fx 2.0
2004-04-25 Andreas Nahr <ClassDevelopment@A-SoftTech.com>
* WindowsPrincipal.cs: Call invariant ToUpper
2004-04-14 Sebastien Pouliot <sebastien@ximian.com>
* WindowsIdentity.cs: Implemented IDeserializationCallback and
ISerializable interfaces.
2004-04-13 Sebastien Pouliot <sebastien@ximian.com>
* WindowsIdentity.cs: Implemented for both Windows and Linux. Fix bug
#52532. Class is only missing serialization bits.
* WindowsImpersonationContext.cs: Implemented for both Windows and
Linux. Fix bug #52532.
* WindowsPrincipal.cs: Implemented for both Windows and Linux. Fix
bug #52532.
2003-12-29 Sebastien Pouliot <spouliot@videotron.ca>
* PrincipalPolicy.cs: Added missing [Serializable] to enum.
* WindowsAccountType.cs: Added missing [Serializable] to enum.
* WindowsBuiltInRole.cs: Added missing [Serializable] to enum.
* WindowsIdentity.cs: Updated to match the unit tests.
* WindowsPrincipal.cs: Return false for a null role.
2003-12-25 Sebastien Pouliot <spouliot@videotron.ca>
* WindowsIdentity.cs: Added ISerializable (for 1.1+) and default
implementation for constructors/properties.
* WindowsImpersonationContext.cs: Added MonoTODO on class and
NotImplementedException in constructor.
* WindowsPrincipal.cs: New. Basic implementation (mostly a stub).
2003-07-01 Sebastien Pouliot <spouliot@videotron.ca>
* ChangeLog: Sorry it seems that I couldn't find the right combinaison
just to commit the change to changelog (probably due to convertion to
windows).
* GenericPrincipal.cs: Fixed issues found during unit testing.
2002-12-17 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* GenericIdentity.cs: check arguments and fixed IsAuthenticated.
2002-08-26 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* WindowsIdentity.cs:
* WindowsImpersonationContext.cs: stubbed.
2002/07/10 Nick Drochak <ndrochak@gol.com>
* WindowsAccountType.cs:
* WindowsBuiltInRole.cs:
Make these enums public instead of internal.
2002-01-07 Nick Drochak <ndrochak@gol.com>
* PrincipalPolicy.cs: made enum public like it should be to get _AppDomain to compile.

View File

@@ -0,0 +1,77 @@
//
// System.Security.Principal.GenericIdentity.cs
//
// Author:
// Miguel de Icaza (miguel@ximian.com)
//
// (C) Ximian, Inc. http://www.ximian.com
// Copyright (C) 2004-2006 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Runtime.InteropServices;
namespace System.Security.Principal {
[Serializable]
[ComVisible (true)]
public class GenericIdentity : IIdentity {
// field names are serialization compatible with .net
private string m_name;
private string m_type;
public GenericIdentity (string name, string type)
{
if (name == null)
throw new ArgumentNullException ("name");
if (type == null)
throw new ArgumentNullException ("type");
m_name = name;
m_type = type;
}
public GenericIdentity (string name)
: this (name, String.Empty)
{
}
public virtual string AuthenticationType {
get {
return m_type;
}
}
public virtual string Name {
get {
return m_name;
}
}
public virtual bool IsAuthenticated {
get {
return (m_name.Length > 0);
}
}
}
}

View File

@@ -0,0 +1,80 @@
//
// System.Security.Principal.GenericPrincipal.cs
//
// Authors:
// Miguel de Icaza (miguel@ximian.com)
// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) Ximian, Inc. http://www.ximian.com
// Copyright (C) 2004-2006 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Runtime.InteropServices;
namespace System.Security.Principal {
[Serializable]
[ComVisible (true)]
public class GenericPrincipal : IPrincipal {
// field names are serialization compatible with .net
private IIdentity m_identity;
private string[] m_roles;
public GenericPrincipal (IIdentity identity, string [] roles)
{
if (identity == null)
throw new ArgumentNullException ("identity");
m_identity = identity;
if (roles != null) {
// make our own (unchangeable) copy of the roles
m_roles = new string [roles.Length];
for (int i=0; i < roles.Length; i++)
m_roles [i] = roles [i];
}
}
internal string [] Roles {
get { return m_roles; }
}
public virtual IIdentity Identity {
get { return m_identity; }
}
public virtual bool IsInRole (string role)
{
if (m_roles == null)
return false;
int l = role.Length;
foreach (string r in m_roles) {
if ((r != null) && (l == r.Length)) {
if (String.Compare (role, 0, r, 0, l, true) == 0)
return true;
}
}
return false;
}
}
}

View File

@@ -0,0 +1,49 @@
//
// System.Security.Principal.IIdentity.cs
//
// Author:
// Miguel de Icaza (miguel@ximian.com)
//
// (C) Ximian, Inc. http://www.ximian.com
// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Runtime.InteropServices;
namespace System.Security.Principal {
[ComVisible (true)]
public interface IIdentity {
string AuthenticationType {
get;
}
bool IsAuthenticated {
get;
}
string Name {
get;
}
}
}

View File

@@ -0,0 +1,43 @@
//
// System.Security.Principal.IPrincipal.cs
//
// Author:
// Miguel de Icaza (miguel@ximian.com)
//
// (C) Ximian, Inc. http://www.ximian.com
// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Runtime.InteropServices;
namespace System.Security.Principal {
[ComVisible (true)]
public interface IPrincipal {
IIdentity Identity {
get;
}
bool IsInRole (string role);
}
}

View File

@@ -0,0 +1,71 @@
//
// System.Security.Policy.IdentityNotMappedException.cs
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Globalization;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
namespace System.Security.Principal {
[Serializable]
[ComVisible (false)]
public sealed class IdentityNotMappedException : SystemException {
private IdentityReferenceCollection _coll;
public IdentityNotMappedException ()
: base (Locale.GetText ("Couldn't translate some identities."))
{
}
public IdentityNotMappedException (string message)
: base (message)
{
}
public IdentityNotMappedException (string message, Exception inner)
: base (message, inner)
{
}
public IdentityReferenceCollection UnmappedIdentities {
get {
if (_coll == null)
_coll = new IdentityReferenceCollection ();
return _coll;
}
}
[MonoTODO ("not implemented")]
public override void GetObjectData (SerializationInfo serializationInfo, StreamingContext streamingContext)
{
}
}
}

View File

@@ -0,0 +1,80 @@
//
// System.Security.Policy.IdentityReference.cs
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Globalization;
using System.Runtime.InteropServices;
namespace System.Security.Principal {
[ComVisible (false)]
public abstract class IdentityReference {
// yep, this means it cannot be inherited outside corlib
// not sure if this is "by design" reported as FDBK30180
internal IdentityReference ()
{
}
public abstract string Value {
get;
}
public abstract override bool Equals (object o);
public abstract override int GetHashCode ();
public abstract bool IsValidTargetType (Type targetType);
public abstract override string ToString ();
public abstract IdentityReference Translate (Type targetType);
public static bool operator== (IdentityReference left, IdentityReference right)
{
if (((object)left) == null)
return (((object)right) == null);
if (((object)right) == null)
return false;
return (left.Value == right.Value);
}
public static bool operator!= (IdentityReference left, IdentityReference right)
{
if (((object)left) == null)
return (((object)right) != null);
if (((object)right) == null)
return true;
return (left.Value != right.Value);
}
}
}

View File

@@ -0,0 +1,127 @@
//
// System.Security.Policy.IdentityReferenceCollection.cs
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Runtime.InteropServices;
namespace System.Security.Principal {
[ComVisible (false)]
public class IdentityReferenceCollection : IEnumerable, ICollection<IdentityReference>, IEnumerable<IdentityReference> {
private ArrayList _list;
public IdentityReferenceCollection ()
{
_list = new ArrayList ();
}
public IdentityReferenceCollection (int capacity)
{
_list = new ArrayList (capacity);
}
public int Count {
get { return _list.Count; }
}
public bool IsReadOnly {
get { return false; }
}
public IdentityReference this [int index] {
get {
if (index >= _list.Count)
return null;
return (IdentityReference) _list [index];
}
set { _list [index] = value; }
}
public void Add (IdentityReference identity)
{
_list.Add (identity);
}
public void Clear ()
{
_list.Clear ();
}
public bool Contains (IdentityReference identity)
{
foreach (IdentityReference id in _list) {
if (id.Equals (identity))
return true;
}
return false;
}
public void CopyTo (IdentityReference[] array, int offset)
{
throw new NotImplementedException ();
}
public IEnumerator<IdentityReference> GetEnumerator ()
{
throw new NotImplementedException ();
}
IEnumerator IEnumerable.GetEnumerator ()
{
throw new NotImplementedException ();
}
public bool Remove (IdentityReference identity)
{
foreach (IdentityReference id in _list) {
if (id.Equals (identity)) {
_list.Remove (id);
return true;
}
}
return false;
}
public IdentityReferenceCollection Translate (Type targetType)
{
throw new NotImplementedException ();
}
public IdentityReferenceCollection Translate (Type targetType, bool forceSuccess)
{
throw new NotImplementedException ();
}
}
}

View File

@@ -0,0 +1,130 @@
//
// System.Security.Policy.NTAccount.cs
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
// Kenneth Bell
//
// Copyright (C) 2005, 2006 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Globalization;
using System.Runtime.InteropServices;
namespace System.Security.Principal {
[ComVisible (false)]
public sealed class NTAccount : IdentityReference {
private string _value;
public NTAccount (string name)
{
if (name == null)
throw new ArgumentNullException ("name");
if (name.Length == 0)
throw new ArgumentException (Locale.GetText ("Empty"), "name");
_value = name;
}
public NTAccount (string domainName, string accountName)
{
if (accountName == null)
throw new ArgumentNullException ("accountName");
if (accountName.Length == 0)
throw new ArgumentException (Locale.GetText ("Empty"), "accountName");
if (domainName == null)
_value = accountName;
else
_value = domainName + "\\" + accountName;
}
public override string Value {
get { return _value; }
}
public override bool Equals (object o)
{
NTAccount nt = (o as NTAccount);
if (nt == null)
return false;
return (nt.Value == Value);
}
public override int GetHashCode ()
{
return Value.GetHashCode ();
}
public override bool IsValidTargetType (Type targetType)
{
if (targetType == typeof (NTAccount))
return true;
if (targetType == typeof (SecurityIdentifier))
return true;
return false;
}
public override string ToString ()
{
return Value;
}
public override IdentityReference Translate (Type targetType)
{
if (targetType == typeof (NTAccount))
return this; // ? copy
if(targetType == typeof(SecurityIdentifier)) {
WellKnownAccount acct = WellKnownAccount.LookupByName(this.Value);
if (acct == null || acct.Sid == null)
throw new IdentityNotMappedException("Cannot map account name: " + this.Value);
return new SecurityIdentifier(acct.Sid);
}
throw new ArgumentException("Unknown type", "targetType");
}
public static bool operator == (NTAccount left, NTAccount right)
{
if (((object)left) == null)
return (((object)right) == null);
if (((object)right) == null)
return false;
return (left.Value == right.Value);
}
public static bool operator != (NTAccount left, NTAccount right)
{
if (((object)left) == null)
return (((object)right) != null);
if (((object)right) == null)
return true;
return (left.Value != right.Value);
}
}
}

View File

@@ -0,0 +1,41 @@
//
// System.Security.Principal.PrincipalPolicy.cs
//
// Author:
// Miguel de Icaza (miguel@ximian.com)
//
// (C) Ximian, Inc. http://www.ximian.com
// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Runtime.InteropServices;
namespace System.Security.Principal {
[Serializable]
[ComVisible (true)]
public enum PrincipalPolicy {
UnauthenticatedPrincipal,
NoPrincipal,
WindowsPrincipal
}
}

View File

@@ -0,0 +1,415 @@
//
// System.Security.Policy.SecurityIdentifier class
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
// Kenneth Bell
// James Bellinger <jfb@zer7.com>
//
// Copyright (C) 2005, 2006 Novell, Inc (http://www.novell.com)
// Copyright (C) 2012 James Bellinger
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Globalization;
using System.Runtime.InteropServices;
using System.Text;
namespace System.Security.Principal
{
[ComVisible (false)]
public sealed class SecurityIdentifier : IdentityReference, IComparable<SecurityIdentifier>
{
private byte[] buffer;
public static readonly int MaxBinaryLength = 68;
public static readonly int MinBinaryLength = 8;
public SecurityIdentifier (string sddlForm)
{
if (sddlForm == null)
throw new ArgumentNullException ("sddlForm");
buffer = ParseSddlForm (sddlForm);
}
unsafe public SecurityIdentifier (byte[] binaryForm, int offset)
{
if (binaryForm == null)
throw new ArgumentNullException ("binaryForm");
if ((offset < 0) || (offset > binaryForm.Length - 2))
throw new ArgumentException ("offset");
fixed (byte* binaryFormPtr = binaryForm)
CreateFromBinaryForm ((IntPtr)(binaryFormPtr + offset), binaryForm.Length - offset);
}
public SecurityIdentifier (IntPtr binaryForm)
{
CreateFromBinaryForm (binaryForm, int.MaxValue);
}
void CreateFromBinaryForm (IntPtr binaryForm, int length)
{
int revision = Marshal.ReadByte (binaryForm, 0);
int numSubAuthorities = Marshal.ReadByte (binaryForm, 1);
if (revision != 1 || numSubAuthorities > 15)
throw new ArgumentException ("Value was invalid.");
if (length < (8 + (numSubAuthorities * 4)))
throw new ArgumentException ("offset");
buffer = new byte[8 + (numSubAuthorities * 4)];
Marshal.Copy (binaryForm, buffer, 0, buffer.Length);
}
public SecurityIdentifier (WellKnownSidType sidType,
SecurityIdentifier domainSid)
{
WellKnownAccount acct = WellKnownAccount.LookupByType (sidType);
if (acct == null)
throw new ArgumentException ("Unable to convert SID type: " + sidType);
if (acct.IsAbsolute) {
buffer = ParseSddlForm (acct.Sid);
} else {
if (domainSid == null)
throw new ArgumentNullException ("domainSid");
buffer = ParseSddlForm (domainSid.Value + "-" + acct.Rid);
}
}
public SecurityIdentifier AccountDomainSid {
get {
string strForm = this.Value;
// Check prefix, and ensure at least 4 sub authorities
if (!strForm.StartsWith ("S-1-5-21") || buffer[1] < 4)
return null;
// Domain is first four sub-authorities
byte[] temp = new byte[8 + (4 * 4)];
Array.Copy (buffer, 0, temp, 0, temp.Length);
temp[1] = 4;
return new SecurityIdentifier (temp, 0);
}
}
public int BinaryLength {
get { return buffer.Length; }
}
public override string Value {
get {
StringBuilder s = new StringBuilder ();
ulong authority = GetSidAuthority ();
s.AppendFormat (CultureInfo.InvariantCulture, "S-1-{0}", authority);
for (byte i = 0; i < GetSidSubAuthorityCount (); ++i)
s.AppendFormat (
CultureInfo.InvariantCulture,
"-{0}", GetSidSubAuthority (i));
return s.ToString ();
}
}
ulong GetSidAuthority ()
{
return (((ulong)buffer [2]) << 40) | (((ulong)buffer [3]) << 32)
| (((ulong)buffer [4]) << 24) | (((ulong)buffer [5]) << 16)
| (((ulong)buffer [6]) << 8) | (((ulong)buffer [7]) << 0);
}
byte GetSidSubAuthorityCount ()
{
return buffer [1];
}
uint GetSidSubAuthority (byte index)
{
// Note sub authorities little-endian, authority (above) is big-endian!
int offset = 8 + (index * 4);
return (((uint)buffer [offset + 0]) << 0)
| (((uint)buffer [offset + 1]) << 8)
| (((uint)buffer [offset + 2]) << 16)
| (((uint)buffer [offset + 3]) << 24);
}
// The CompareTo ordering was determined by unit test applied to MS.NET implementation,
// necessary because the CompareTo has no details in its documentation.
// (See MonoTests.System.Security.AccessControl.DiscretionaryAclTest.)
// The comparison was determined to be: authority, then subauthority count, then subauthority.
public int CompareTo (SecurityIdentifier sid)
{
if (sid == null)
throw new ArgumentNullException ("sid");
int result;
if (0 != (result = GetSidAuthority ().CompareTo (sid.GetSidAuthority ()))) return result;
if (0 != (result = GetSidSubAuthorityCount ().CompareTo (sid.GetSidSubAuthorityCount ()))) return result;
for (byte i = 0; i < GetSidSubAuthorityCount (); ++i)
if (0 != (result = GetSidSubAuthority (i).CompareTo (sid.GetSidSubAuthority (i)))) return result;
return 0;
}
public override bool Equals (object o)
{
return Equals (o as SecurityIdentifier);
}
public bool Equals (SecurityIdentifier sid)
{
if (sid == null)
return false;
return (sid.Value == Value);
}
public void GetBinaryForm (byte[] binaryForm, int offset)
{
if (binaryForm == null)
throw new ArgumentNullException ("binaryForm");
if ((offset < 0) || (offset > binaryForm.Length - buffer.Length))
throw new ArgumentException ("offset");
Array.Copy (buffer, 0, binaryForm, offset, buffer.Length);
}
public override int GetHashCode ()
{
return Value.GetHashCode ();
}
public bool IsAccountSid ()
{
return AccountDomainSid != null;
}
public bool IsEqualDomainSid (SecurityIdentifier sid)
{
SecurityIdentifier domSid = AccountDomainSid;
if (domSid == null)
return false;
return domSid.Equals (sid.AccountDomainSid);
}
public override bool IsValidTargetType (Type targetType)
{
if (targetType == typeof(SecurityIdentifier))
return true;
if (targetType == typeof(NTAccount))
return true;
return false;
}
public bool IsWellKnown (WellKnownSidType type)
{
WellKnownAccount acct = WellKnownAccount.LookupByType (type);
if (acct == null)
return false;
string sid = Value;
if (acct.IsAbsolute)
return sid == acct.Sid;
return sid.StartsWith ("S-1-5-21", StringComparison.OrdinalIgnoreCase)
&& sid.EndsWith ("-" + acct.Rid, StringComparison.OrdinalIgnoreCase);
}
public override string ToString ()
{
return Value;
}
public override IdentityReference Translate (Type targetType)
{
if (targetType == typeof(SecurityIdentifier))
return this;
if (targetType == typeof(NTAccount)) {
WellKnownAccount acct = WellKnownAccount.LookupBySid (this.Value);
if (acct == null || acct.Name == null)
throw new IdentityNotMappedException ("Unable to map SID: " + this.Value);
return new NTAccount (acct.Name);
}
throw new ArgumentException ("Unknown type.", "targetType");
}
public static bool operator == (SecurityIdentifier left, SecurityIdentifier right)
{
if (((object)left) == null)
return (((object)right) == null);
if (((object)right) == null)
return false;
return (left.Value == right.Value);
}
public static bool operator != (SecurityIdentifier left, SecurityIdentifier right)
{
if (((object)left) == null)
return (((object)right) != null);
if (((object)right) == null)
return true;
return (left.Value != right.Value);
}
internal string GetSddlForm()
{
string sidString = Value;
WellKnownAccount acct = WellKnownAccount.LookupBySid(sidString);
if(acct == null || acct.SddlForm == null)
return sidString;
return acct.SddlForm;
}
internal static SecurityIdentifier ParseSddlForm(string sddlForm, ref int pos)
{
if (sddlForm.Length - pos < 2)
throw new ArgumentException("Invalid SDDL string.", "sddlForm");
string sid;
int len;
string prefix = sddlForm.Substring(pos, 2).ToUpperInvariant();
if (prefix == "S-")
{
// Looks like a SID, try to parse it.
int endPos = pos;
char ch = Char.ToUpperInvariant(sddlForm[endPos]);
while (ch == 'S' || ch == '-' || ch == 'X'
|| (ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'F')) {
++endPos;
ch = Char.ToUpperInvariant(sddlForm[endPos]);
}
sid = sddlForm.Substring(pos, endPos - pos);
len = endPos - pos;
} else {
sid = prefix;
len = 2;
}
SecurityIdentifier ret = new SecurityIdentifier(sid);
pos += len;
return ret;
}
private static byte[] ParseSddlForm (string sddlForm)
{
string sid = sddlForm;
// If only 2 characters long, can't be a full SID string - so assume
// it's an attempted alias. Do that conversion first.
if(sddlForm.Length == 2) {
WellKnownAccount acct = WellKnownAccount.LookupBySddlForm(sddlForm);
if (acct == null)
throw new ArgumentException(
"Invalid SDDL string - unrecognized account: " + sddlForm,
"sddlForm");
if (!acct.IsAbsolute)
throw new NotImplementedException(
"Mono unable to convert account to SID: "
+ (acct.Name != null ? acct.Name : sddlForm));
sid = acct.Sid;
}
string[] elements = sid.ToUpperInvariant ().Split ('-');
int numSubAuthorities = elements.Length - 3;
if (elements.Length < 3 || elements[0] != "S" || numSubAuthorities > 15)
throw new ArgumentException ("Value was invalid.");
if (elements[1] != "1")
throw new ArgumentException ("Only SIDs with revision 1 are supported");
byte[] buffer = new byte[8 + (numSubAuthorities * 4)];
buffer[0] = 1;
buffer[1] = (byte)numSubAuthorities;
ulong authority;
if (!TryParseAuthority (elements[2], out authority))
throw new ArgumentException ("Value was invalid.");
buffer[2] = (byte)((authority >> 40) & 0xFF);
buffer[3] = (byte)((authority >> 32) & 0xFF);
buffer[4] = (byte)((authority >> 24) & 0xFF);
buffer[5] = (byte)((authority >> 16) & 0xFF);
buffer[6] = (byte)((authority >> 8) & 0xFF);
buffer[7] = (byte)((authority >> 0) & 0xFF);
for (int i = 0; i < numSubAuthorities; ++i) {
uint subAuthority;
if (!TryParseSubAuthority (elements[i + 3],
out subAuthority))
throw new ArgumentException ("Value was invalid.");
// Note sub authorities little-endian!
int offset = 8 + (i * 4);
buffer[offset + 0] = (byte)(subAuthority >> 0);
buffer[offset + 1] = (byte)(subAuthority >> 8);
buffer[offset + 2] = (byte)(subAuthority >> 16);
buffer[offset + 3] = (byte)(subAuthority >> 24);
}
return buffer;
}
private static bool TryParseAuthority (string s, out ulong result)
{
if (s.StartsWith ("0X")) {
return ulong.TryParse (s.Substring (2),
NumberStyles.HexNumber,
CultureInfo.InvariantCulture,
out result);
} else {
return ulong.TryParse (s, NumberStyles.Integer,
CultureInfo.InvariantCulture,
out result);
}
}
private static bool TryParseSubAuthority (string s, out uint result)
{
if (s.StartsWith ("0X")) {
return uint.TryParse (s.Substring (2),
NumberStyles.HexNumber,
CultureInfo.InvariantCulture,
out result);
} else {
return uint.TryParse (s, NumberStyles.Integer,
CultureInfo.InvariantCulture,
out result);
}
}
}
}

View File

@@ -0,0 +1,53 @@
//
// System.Security.Principal.TokenAccessLevels flags
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Runtime.InteropServices;
namespace System.Security.Principal {
[Serializable]
[Flags]
[ComVisible (true)]
public enum TokenAccessLevels {
AssignPrimary = 1,
Duplicate = 2,
Impersonate = 4,
Query = 8,
QuerySource = 16,
AdjustPrivileges = 32,
AdjustGroups = 64,
AdjustDefault = 128,
AdjustSessionId = 256,
Read = 0x20008,
Write = 0x200E0,
AllAccess = 0xF01FF,
MaximumAllowed = 0x2000000
}
}

View File

@@ -0,0 +1,46 @@
//
// System.Security.Principal.TokenImpersonationLevel.cs
//
// Author:
// Tim Coleman (tim@timcoleman.com)
//
// Copyright (C) Tim Coleman, 2004
// (C) Ximian, Inc. http://www.ximian.com
// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Runtime.InteropServices;
namespace System.Security.Principal {
[Serializable]
[ComVisible (true)]
public enum TokenImpersonationLevel {
Anonymous = 0x01,
Delegation = 0x04,
Identification = 0x02,
Impersonation = 0x03,
None = 0x00
}
}

View File

@@ -0,0 +1,129 @@
//
// System.Security.Policy.WellKnownAccount.cs
//
// Author:
// Kenneth Bell
//
namespace System.Security.Principal
{
internal class WellKnownAccount
{
public WellKnownSidType WellKnownValue { get; set; }
public bool IsAbsolute { get; set; }
public string Sid { get; set; }
public string Rid { get; set; }
public string Name { get; set; }
public string SddlForm { get; set; }
public static WellKnownAccount LookupByType (WellKnownSidType sidType)
{
foreach (var acct in accounts) {
if (acct.WellKnownValue == sidType)
return acct;
}
return null;
}
public static WellKnownAccount LookupBySid(string s)
{
foreach (var acct in accounts) {
if (acct.Sid == s)
return acct;
}
return null;
}
public static WellKnownAccount LookupByName(string s)
{
foreach (var acct in accounts) {
if (acct.Name == s)
return acct;
}
return null;
}
public static WellKnownAccount LookupBySddlForm(string s)
{
foreach (var acct in accounts) {
if (acct.SddlForm == s)
return acct;
}
return null;
}
private static readonly WellKnownAccount[] accounts = new WellKnownAccount[] {
new WellKnownAccount { WellKnownValue = WellKnownSidType.NullSid, IsAbsolute = true, Sid = "S-1-0-0", Name = @"NULL SID"},
new WellKnownAccount { WellKnownValue = WellKnownSidType.WorldSid, IsAbsolute = true, Sid = "S-1-1-0", Name = @"Everyone", SddlForm = "WD"},
new WellKnownAccount { WellKnownValue = WellKnownSidType.LocalSid, IsAbsolute = true, Sid = "S-1-2-0", Name = @"LOCAL"},
new WellKnownAccount { WellKnownValue = WellKnownSidType.CreatorOwnerSid, IsAbsolute = true, Sid = "S-1-3-0", Name = @"CREATOR OWNER", SddlForm = "CO"},
new WellKnownAccount { WellKnownValue = WellKnownSidType.CreatorGroupSid, IsAbsolute = true, Sid = "S-1-3-1", Name = @"CREATOR GROUP", SddlForm = "CG"},
new WellKnownAccount { WellKnownValue = WellKnownSidType.CreatorOwnerServerSid, IsAbsolute = true, Sid = "S-1-3-2", Name = @"CREATOR OWNER SERVER"},
new WellKnownAccount { WellKnownValue = WellKnownSidType.CreatorGroupServerSid, IsAbsolute = true, Sid = "S-1-3-3", Name = @"CREATOR GROUP SERVER"},
new WellKnownAccount { WellKnownValue = WellKnownSidType.NTAuthoritySid, IsAbsolute = true, Sid = "S-1-5", Name = null},
new WellKnownAccount { WellKnownValue = WellKnownSidType.DialupSid, IsAbsolute = true, Sid = "S-1-5-1", Name = @"NT AUTHORITY\DIALUP"},
new WellKnownAccount { WellKnownValue = WellKnownSidType.NetworkSid, IsAbsolute = true, Sid = "S-1-5-2", Name = @"NT AUTHORITY\NETWORK", SddlForm = "NU"},
new WellKnownAccount { WellKnownValue = WellKnownSidType.BatchSid, IsAbsolute = true, Sid = "S-1-5-3", Name = @"NT AUTHORITY\BATCH"},
new WellKnownAccount { WellKnownValue = WellKnownSidType.InteractiveSid, IsAbsolute = true, Sid = "S-1-5-4", Name = @"NT AUTHORITY\INTERACTIVE", SddlForm = "IU"},
new WellKnownAccount { WellKnownValue = WellKnownSidType.ServiceSid, IsAbsolute = true, Sid = "S-1-5-6", Name = @"NT AUTHORITY\SERVICE", SddlForm = "SU"},
new WellKnownAccount { WellKnownValue = WellKnownSidType.AnonymousSid, IsAbsolute = true, Sid = "S-1-5-7", Name = @"NT AUTHORITY\ANONYMOUS LOGON", SddlForm = "AN"},
new WellKnownAccount { WellKnownValue = WellKnownSidType.ProxySid, IsAbsolute = true, Sid = "S-1-5-8", Name = @"NT AUTHORITY\PROXY"},
new WellKnownAccount { WellKnownValue = WellKnownSidType.EnterpriseControllersSid, IsAbsolute = true, Sid = "S-1-5-9", Name = @"NT AUTHORITY\ENTERPRISE DOMAIN CONTROLLERS", SddlForm = "ED"},
new WellKnownAccount { WellKnownValue = WellKnownSidType.SelfSid, IsAbsolute = true, Sid = "S-1-5-10", Name = @"NT AUTHORITY\SELF", SddlForm = "PS"},
new WellKnownAccount { WellKnownValue = WellKnownSidType.AuthenticatedUserSid, IsAbsolute = true, Sid = "S-1-5-11", Name = @"NT AUTHORITY\Authenticated Users", SddlForm = "AU"},
new WellKnownAccount { WellKnownValue = WellKnownSidType.RestrictedCodeSid, IsAbsolute = true, Sid = "S-1-5-12", Name = @"NT AUTHORITY\RESTRICTED", SddlForm = "RC"},
new WellKnownAccount { WellKnownValue = WellKnownSidType.TerminalServerSid, IsAbsolute = true, Sid = "S-1-5-13", Name = @"NT AUTHORITY\TERMINAL SERVER USER"},
new WellKnownAccount { WellKnownValue = WellKnownSidType.RemoteLogonIdSid, IsAbsolute = true, Sid = "S-1-5-14", Name = @"NT AUTHORITY\REMOTE INTERACTIVE LOGON"},
new WellKnownAccount { WellKnownValue = WellKnownSidType.LocalSystemSid, IsAbsolute = true, Sid = "S-1-5-18", Name = @"NT AUTHORITY\SYSTEM", SddlForm = "SY"},
new WellKnownAccount { WellKnownValue = WellKnownSidType.LocalServiceSid, IsAbsolute = true, Sid = "S-1-5-19", Name = @"NT AUTHORITY\LOCAL SERVICE", SddlForm = "LS"},
new WellKnownAccount { WellKnownValue = WellKnownSidType.NetworkServiceSid, IsAbsolute = true, Sid = "S-1-5-20", Name = @"NT AUTHORITY\NETWORK SERVICE", SddlForm = "NS"},
new WellKnownAccount { WellKnownValue = WellKnownSidType.BuiltinDomainSid, IsAbsolute = true, Sid = "S-1-5-32", Name = null},
new WellKnownAccount { WellKnownValue = WellKnownSidType.BuiltinAdministratorsSid, IsAbsolute = true, Sid = "S-1-5-32-544", Name = @"BUILTIN\Administrators", SddlForm = "BA"},
new WellKnownAccount { WellKnownValue = WellKnownSidType.BuiltinUsersSid, IsAbsolute = true, Sid = "S-1-5-32-545", Name = @"BUILTIN\Users", SddlForm = "BU"},
new WellKnownAccount { WellKnownValue = WellKnownSidType.BuiltinGuestsSid, IsAbsolute = true, Sid = "S-1-5-32-546", Name = @"BUILTIN\Guests", SddlForm = "BG"},
new WellKnownAccount { WellKnownValue = WellKnownSidType.BuiltinPowerUsersSid, IsAbsolute = true, Sid = "S-1-5-32-547", Name = null, SddlForm = "PU"},
new WellKnownAccount { WellKnownValue = WellKnownSidType.BuiltinAccountOperatorsSid, IsAbsolute = true, Sid = "S-1-5-32-548", Name = null, SddlForm = "AO"},
new WellKnownAccount { WellKnownValue = WellKnownSidType.BuiltinSystemOperatorsSid, IsAbsolute = true, Sid = "S-1-5-32-549", Name = null, SddlForm = "SO"},
new WellKnownAccount { WellKnownValue = WellKnownSidType.BuiltinPrintOperatorsSid, IsAbsolute = true, Sid = "S-1-5-32-550", Name = null, SddlForm = "PO"},
new WellKnownAccount { WellKnownValue = WellKnownSidType.BuiltinBackupOperatorsSid, IsAbsolute = true, Sid = "S-1-5-32-551", Name = null, SddlForm = "BO"},
new WellKnownAccount { WellKnownValue = WellKnownSidType.BuiltinReplicatorSid, IsAbsolute = true, Sid = "S-1-5-32-552", Name = null, SddlForm = "RE"},
new WellKnownAccount { WellKnownValue = WellKnownSidType.BuiltinPreWindows2000CompatibleAccessSid, IsAbsolute = true, Sid = "S-1-5-32-554", Name = null, SddlForm = "RU"},
new WellKnownAccount { WellKnownValue = WellKnownSidType.BuiltinRemoteDesktopUsersSid, IsAbsolute = true, Sid = "S-1-5-32-555", Name = null, SddlForm = "RD"},
new WellKnownAccount { WellKnownValue = WellKnownSidType.BuiltinNetworkConfigurationOperatorsSid, IsAbsolute = true, Sid = "S-1-5-32-556", Name = null, SddlForm = "NO"},
new WellKnownAccount { WellKnownValue = WellKnownSidType.AccountAdministratorSid, IsAbsolute = false, Rid = "500", SddlForm = "LA"},
new WellKnownAccount { WellKnownValue = WellKnownSidType.AccountGuestSid, IsAbsolute = false, Rid = "501", SddlForm = "LG"},
new WellKnownAccount { WellKnownValue = WellKnownSidType.AccountKrbtgtSid, IsAbsolute = false, Rid = "502"},
new WellKnownAccount { WellKnownValue = WellKnownSidType.AccountDomainAdminsSid, IsAbsolute = false, Rid = "512", SddlForm = "DA"},
new WellKnownAccount { WellKnownValue = WellKnownSidType.AccountDomainUsersSid, IsAbsolute = false, Rid = "513", SddlForm = "DU"},
new WellKnownAccount { WellKnownValue = WellKnownSidType.AccountDomainGuestsSid, IsAbsolute = false, Rid = "514", SddlForm = "DG"},
new WellKnownAccount { WellKnownValue = WellKnownSidType.AccountComputersSid, IsAbsolute = false, Rid = "515", SddlForm = "DC"},
new WellKnownAccount { WellKnownValue = WellKnownSidType.AccountControllersSid, IsAbsolute = false, Rid = "516", SddlForm = "DD"},
new WellKnownAccount { WellKnownValue = WellKnownSidType.AccountCertAdminsSid, IsAbsolute = false, Rid = "517", SddlForm = "CA"},
new WellKnownAccount { WellKnownValue = WellKnownSidType.AccountSchemaAdminsSid, IsAbsolute = false, Rid = "518", SddlForm = "SA"},
new WellKnownAccount { WellKnownValue = WellKnownSidType.AccountEnterpriseAdminsSid, IsAbsolute = false, Rid = "519", SddlForm = "EA"},
new WellKnownAccount { WellKnownValue = WellKnownSidType.AccountPolicyAdminsSid, IsAbsolute = false, Rid = "520", SddlForm = "PA"},
new WellKnownAccount { WellKnownValue = WellKnownSidType.AccountRasAndIasServersSid, IsAbsolute = false, Rid = "553", SddlForm = "RS"},
new WellKnownAccount { WellKnownValue = WellKnownSidType.NtlmAuthenticationSid, IsAbsolute = true, Sid = "S-1-5-64-10", Name = @"NT AUTHORITY\NTLM Authentication"},
new WellKnownAccount { WellKnownValue = WellKnownSidType.DigestAuthenticationSid, IsAbsolute = true, Sid = "S-1-5-64-21", Name = @"NT AUTHORITY\Digest Authentication"},
new WellKnownAccount { WellKnownValue = WellKnownSidType.SChannelAuthenticationSid, IsAbsolute = true, Sid = "S-1-5-64-14", Name = @"NT AUTHORITY\SChannel Authentication"},
new WellKnownAccount { WellKnownValue = WellKnownSidType.ThisOrganizationSid, IsAbsolute = true, Sid = "S-1-5-15", Name = @"NT AUTHORITY\This Organization"},
new WellKnownAccount { WellKnownValue = WellKnownSidType.OtherOrganizationSid, IsAbsolute = true, Sid = "S-1-5-1000", Name = @"NT AUTHORITY\Other Organization"},
new WellKnownAccount { WellKnownValue = WellKnownSidType.BuiltinIncomingForestTrustBuildersSid, IsAbsolute = true, Sid = "S-1-5-32-557", Name = null},
new WellKnownAccount { WellKnownValue = WellKnownSidType.BuiltinPerformanceMonitoringUsersSid, IsAbsolute = true, Sid = "S-1-5-32-558", Name = @"BUILTIN\Performance Monitor Users", SddlForm = "MU"},
new WellKnownAccount { WellKnownValue = WellKnownSidType.BuiltinPerformanceLoggingUsersSid, IsAbsolute = true, Sid = "S-1-5-32-559", Name = @"BUILTIN\Performance Log Users"},
new WellKnownAccount { WellKnownValue = WellKnownSidType.BuiltinAuthorizationAccessSid, IsAbsolute = true, Sid = "S-1-5-32-560", Name = null},
new WellKnownAccount { WellKnownValue = WellKnownSidType.WinBuiltinTerminalServerLicenseServersSid, IsAbsolute = true, Sid = "S-1-5-32-561", Name = null},
new WellKnownAccount { WellKnownValue = (WellKnownSidType)66, IsAbsolute = false, Rid = "4096", SddlForm = "LW"},
new WellKnownAccount { WellKnownValue = (WellKnownSidType)67, IsAbsolute = false, Rid = "8192", SddlForm = "ME"},
new WellKnownAccount { WellKnownValue = (WellKnownSidType)68, IsAbsolute = false, Rid = "12288", SddlForm = "HI"},
new WellKnownAccount { WellKnownValue = (WellKnownSidType)69, IsAbsolute = false, Rid = "16384", SddlForm = "SI"},
new WellKnownAccount { WellKnownValue = (WellKnownSidType)74, IsAbsolute = false, Rid = "521", SddlForm = "RO"},
new WellKnownAccount { WellKnownValue = (WellKnownSidType)78, IsAbsolute = false, Rid = "574", SddlForm = "CD"},
};
}
}

View File

@@ -0,0 +1,100 @@
//
// System.Security.Principal.WellKnownSidType
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Runtime.InteropServices;
namespace System.Security.Principal {
[ComVisible (false)]
public enum WellKnownSidType {
NullSid,
WorldSid,
LocalSid,
CreatorOwnerSid,
CreatorGroupSid,
CreatorOwnerServerSid,
CreatorGroupServerSid,
NTAuthoritySid,
DialupSid,
NetworkSid,
BatchSid,
InteractiveSid,
ServiceSid,
AnonymousSid,
ProxySid,
EnterpriseControllersSid,
SelfSid,
AuthenticatedUserSid,
RestrictedCodeSid,
TerminalServerSid,
RemoteLogonIdSid,
LogonIdsSid,
LocalSystemSid,
LocalServiceSid,
NetworkServiceSid,
BuiltinDomainSid,
BuiltinAdministratorsSid,
BuiltinUsersSid,
BuiltinGuestsSid,
BuiltinPowerUsersSid,
BuiltinAccountOperatorsSid,
BuiltinSystemOperatorsSid,
BuiltinPrintOperatorsSid,
BuiltinBackupOperatorsSid,
BuiltinReplicatorSid,
BuiltinPreWindows2000CompatibleAccessSid,
BuiltinRemoteDesktopUsersSid,
BuiltinNetworkConfigurationOperatorsSid,
AccountAdministratorSid,
AccountGuestSid,
AccountKrbtgtSid,
AccountDomainAdminsSid,
AccountDomainUsersSid,
AccountDomainGuestsSid,
AccountComputersSid,
AccountControllersSid,
AccountCertAdminsSid,
AccountSchemaAdminsSid,
AccountEnterpriseAdminsSid,
AccountPolicyAdminsSid,
AccountRasAndIasServersSid,
NtlmAuthenticationSid,
DigestAuthenticationSid,
SChannelAuthenticationSid,
ThisOrganizationSid,
OtherOrganizationSid,
BuiltinIncomingForestTrustBuildersSid,
BuiltinPerformanceMonitoringUsersSid,
BuiltinPerformanceLoggingUsersSid,
BuiltinAuthorizationAccessSid,
WinBuiltinTerminalServerLicenseServersSid,
MaxDefined = WinBuiltinTerminalServerLicenseServersSid
}
}

View File

@@ -0,0 +1,42 @@
//
// System.Security.Principal.WindowsAccountType.cs
//
// Author:
// Miguel de Icaza (miguel@ximian.com)
//
// (C) Ximian, Inc. http://www.ximian.com
// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Runtime.InteropServices;
namespace System.Security.Principal {
[Serializable]
[ComVisible (true)]
public enum WindowsAccountType {
Normal,
Guest,
System,
Anonymous
}
}

View File

@@ -0,0 +1,47 @@
//
// System.Security.Principal.WindowsBuiltInRole.cs
//
// Author:
// Miguel de Icaza (miguel@ximian.com)
//
// (C) Ximian, Inc. http://www.ximian.com
// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Runtime.InteropServices;
namespace System.Security.Principal {
[Serializable]
[ComVisible (true)]
public enum WindowsBuiltInRole {
Administrator = 544,
User = 545,
Guest = 546,
PowerUser = 547,
AccountOperator = 548,
SystemOperator = 549,
PrintOperator = 550,
BackupOperator = 551,
Replicator = 552,
}
}

View File

@@ -0,0 +1,322 @@
//
// System.Security.Principal.WindowsIdentity
//
// Authors:
// Gonzalo Paniagua Javier (gonzalo@ximian.com)
// Sebastien Pouliot (sebastien@ximian.com)
//
// (C) 2002 Ximian, Inc (http://www.ximian.com)
// Portions (C) 2003 Motus Technologies Inc. (http://www.motus.com)
// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Security.Permissions;
namespace System.Security.Principal {
[Serializable]
[ComVisible (true)]
public class WindowsIdentity :
#if NET_4_5
System.Security.Claims.ClaimsIdentity,
#endif
IIdentity, IDeserializationCallback, ISerializable, IDisposable {
private IntPtr _token;
private string _type;
private WindowsAccountType _account;
private bool _authenticated;
private string _name;
private SerializationInfo _info;
static private IntPtr invalidWindows = IntPtr.Zero;
[SecurityPermission (SecurityAction.Demand, ControlPrincipal=true)]
public WindowsIdentity (IntPtr userToken)
: this (userToken, null, WindowsAccountType.Normal, false)
{
}
[SecurityPermission (SecurityAction.Demand, ControlPrincipal=true)]
public WindowsIdentity (IntPtr userToken, string type)
: this (userToken, type, WindowsAccountType.Normal, false)
{
}
[SecurityPermission (SecurityAction.Demand, ControlPrincipal=true)]
public WindowsIdentity (IntPtr userToken, string type, WindowsAccountType acctType)
: this (userToken, type, acctType, false)
{
}
[SecurityPermission (SecurityAction.Demand, ControlPrincipal=true)]
public WindowsIdentity (IntPtr userToken, string type, WindowsAccountType acctType, bool isAuthenticated)
{
_type = type;
_account = acctType;
_authenticated = isAuthenticated;
_name = null;
// last - as it can override some fields
SetToken (userToken);
}
[SecurityPermission (SecurityAction.Demand, ControlPrincipal=true)]
public WindowsIdentity (string sUserPrincipalName)
: this (sUserPrincipalName, null)
{
}
[SecurityPermission (SecurityAction.Demand, ControlPrincipal=true)]
public WindowsIdentity (string sUserPrincipalName, string type)
{
if (sUserPrincipalName == null)
throw new NullReferenceException ("sUserPrincipalName");
// TODO: Windows 2003 compatibility should be done in runtime
IntPtr token = GetUserToken (sUserPrincipalName);
if ((!Environment.IsUnix) && (token == IntPtr.Zero)) {
throw new ArgumentException ("only for Windows Server 2003 +");
}
_authenticated = true;
_account = WindowsAccountType.Normal;
_type = type;
// last - as it can override some fields
SetToken (token);
}
[SecurityPermission (SecurityAction.Demand, ControlPrincipal=true)]
public WindowsIdentity (SerializationInfo info, StreamingContext context)
{
_info = info;
}
[ComVisible (false)]
public void Dispose ()
{
_token = IntPtr.Zero;
}
[ComVisible (false)]
protected virtual void Dispose (bool disposing)
{
_token = IntPtr.Zero;
}
// static methods
public static WindowsIdentity GetAnonymous ()
{
WindowsIdentity id = null;
if (Environment.IsUnix) {
id = new WindowsIdentity ("nobody");
// special case
id._account = WindowsAccountType.Anonymous;
id._authenticated = false;
id._type = String.Empty;
}
else {
id = new WindowsIdentity (IntPtr.Zero, String.Empty, WindowsAccountType.Anonymous, false);
// special case (don't try to resolve the name)
id._name = String.Empty;
}
return id;
}
public static WindowsIdentity GetCurrent ()
{
return new WindowsIdentity (GetCurrentToken (), null, WindowsAccountType.Normal, true);
}
[MonoTODO ("need icall changes")]
public static WindowsIdentity GetCurrent (bool ifImpersonating)
{
throw new NotImplementedException ();
}
[MonoTODO ("need icall changes")]
public static WindowsIdentity GetCurrent (TokenAccessLevels desiredAccess)
{
throw new NotImplementedException ();
}
// methods
public virtual WindowsImpersonationContext Impersonate ()
{
return new WindowsImpersonationContext (_token);
}
[SecurityPermission (SecurityAction.Demand, ControlPrincipal=true)]
public static WindowsImpersonationContext Impersonate (IntPtr userToken)
{
return new WindowsImpersonationContext (userToken);
}
// properties
#if NET_4_5
sealed override
#endif
public string AuthenticationType {
get { return _type; }
}
public virtual bool IsAnonymous
{
get { return (_account == WindowsAccountType.Anonymous); }
}
#if NET_4_5
override
#else
virtual
#endif
public bool IsAuthenticated
{
get { return _authenticated; }
}
public virtual bool IsGuest
{
get { return (_account == WindowsAccountType.Guest); }
}
public virtual bool IsSystem
{
get { return (_account == WindowsAccountType.System); }
}
#if NET_4_5
override
#else
virtual
#endif
public string Name
{
get {
if (_name == null) {
// revolve name (runtime)
_name = GetTokenName (_token);
}
return _name;
}
}
public virtual IntPtr Token
{
get { return _token; }
}
[MonoTODO ("not implemented")]
public IdentityReferenceCollection Groups {
get { throw new NotImplementedException (); }
}
[MonoTODO ("not implemented")]
[ComVisible (false)]
public TokenImpersonationLevel ImpersonationLevel {
get { throw new NotImplementedException (); }
}
[MonoTODO ("not implemented")]
[ComVisible (false)]
public SecurityIdentifier Owner {
get { throw new NotImplementedException (); }
}
[MonoTODO ("not implemented")]
[ComVisible (false)]
public SecurityIdentifier User {
get { throw new NotImplementedException (); }
}
void IDeserializationCallback.OnDeserialization (object sender)
{
_token = (IntPtr) _info.GetValue ("m_userToken", typeof (IntPtr));
// can't trust this alone - we must validate the token
_name = _info.GetString ("m_name");
if (_name != null) {
// validate token by comparing names
string name = GetTokenName (_token);
if (name != _name)
throw new SerializationException ("Token-Name mismatch.");
}
else {
// validate token by getting name
_name = GetTokenName (_token);
if (_name == null)
throw new SerializationException ("Token doesn't match a user.");
}
_type = _info.GetString ("m_type");
_account = (WindowsAccountType) _info.GetValue ("m_acctType", typeof (WindowsAccountType));
_authenticated = _info.GetBoolean ("m_isAuthenticated");
}
void ISerializable.GetObjectData (SerializationInfo info, StreamingContext context)
{
info.AddValue ("m_userToken", _token);
// can be null when not resolved
info.AddValue ("m_name", _name);
info.AddValue ("m_type", _type);
info.AddValue ("m_acctType", _account);
info.AddValue ("m_isAuthenticated", _authenticated);
}
private void SetToken (IntPtr token)
{
if (Environment.IsUnix) {
_token = token;
// apply defaults
if (_type == null)
_type = "POSIX";
// override user choice in this specific case
if (_token == IntPtr.Zero)
_account = WindowsAccountType.System;
}
else {
if ((token == invalidWindows) && (_account != WindowsAccountType.Anonymous))
throw new ArgumentException ("Invalid token");
_token = token;
// apply defaults
if (_type == null)
_type = "NTLM";
}
}
// see mono/mono/metadata/security.c for implementation
// Many people use reflection to get a user's roles - so many
// that's it's hard to say it's an "undocumented" feature -
// so we also implement it in Mono :-/
// http://www.dotnet247.com/247reference/msgs/39/195403.aspx
[MethodImplAttribute (MethodImplOptions.InternalCall)]
internal extern static string[] _GetRoles (IntPtr token);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
internal extern static IntPtr GetCurrentToken ();
[MethodImplAttribute (MethodImplOptions.InternalCall)]
private extern static string GetTokenName (IntPtr token);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
private extern static IntPtr GetUserToken (string username);
}
}

View File

@@ -0,0 +1,97 @@
//
// System.Security.Principal.WindowsImpersonationContext
//
// Authors:
// Gonzalo Paniagua Javier (gonzalo@ximian.com)
// Sebastien Pouliot (sebastien@ximian.com)
//
// (C) 2002 Ximian, Inc (http://www.ximian.com)
// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security;
namespace System.Security.Principal {
[ComVisible (true)]
public class WindowsImpersonationContext : IDisposable {
private IntPtr _token;
private bool undo;
internal WindowsImpersonationContext (IntPtr token)
{
// we get a copy to control it's lifetime
_token = DuplicateToken (token);
if (!SetCurrentToken (token)) {
throw new SecurityException ("Couldn't impersonate token.");
}
undo = false;
}
[ComVisible (false)]
public void Dispose ()
{
if (!undo) {
Undo ();
}
}
[ComVisible (false)]
protected virtual void Dispose (bool disposing)
{
if (!undo) {
Undo ();
}
if (disposing){
// If we are explicitly disposed, we can avoid finalization.
GC.SuppressFinalize (this);
}
}
public void Undo ()
{
if (!RevertToSelf ()) {
CloseToken (_token);
throw new SecurityException ("Couldn't switch back to original token.");
}
CloseToken (_token);
undo = true;
GC.SuppressFinalize (this);
}
// see mono/mono/metadata/security.c for implementation
[MethodImplAttribute (MethodImplOptions.InternalCall)]
private extern static bool CloseToken (IntPtr token);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
private extern static IntPtr DuplicateToken (IntPtr token);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
private extern static bool SetCurrentToken (IntPtr token);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
private extern static bool RevertToSelf ();
}
}

View File

@@ -0,0 +1,170 @@
//
// WindowsPrincipal.cs: Windows IPrincipal implementation
//
// Author:
// Sebastien Pouliot (sebastien@ximian.com)
//
// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Collections;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace System.Security.Principal {
[Serializable]
[ComVisible (true)]
public class WindowsPrincipal : IPrincipal {
private WindowsIdentity _identity;
// http://groups.google.ca/groups?q=WindowsPrincipal+m_roles&hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=OghXf4OgCHA.4228%40tkmsftngp08&rnum=4
private string [] m_roles;
// case sensitivity versus number of groups
// http://groups.google.ca/groups?q=WindowsPrincipal+m_roles&hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=%23JEMHsMQCHA.1916%40tkmsftngp13&rnum=5
public WindowsPrincipal (WindowsIdentity ntIdentity)
{
if (ntIdentity == null)
throw new ArgumentNullException ("ntIdentity");
_identity = ntIdentity;
}
// properties
public virtual IIdentity Identity {
get { return _identity; }
}
// methods
public virtual bool IsInRole (int rid)
{
if (Environment.IsUnix) {
return IsMemberOfGroupId (Token, (IntPtr) rid);
}
else {
string role = null;
switch (rid) {
case 544: // Administrator
role = "BUILTIN\\Administrators";
break;
case 545: // User
role = "BUILTIN\\Users";
break;
case 546: // Guest
role = "BUILTIN\\Guests";
break;
case 547: // PowerUser
role = "BUILTIN\\Power Users";
break;
case 548: // AccountOperator
role = "BUILTIN\\Account Operators";
break;
case 549: // SystemOperator
role = "BUILTIN\\System Operators";
break;
case 550: // PrintOperator
role = "BUILTIN\\Print Operators";
break;
case 551: // BackupOperator
role = "BUILTIN\\Backup Operators";
break;
case 552: // Replicator
role = "BUILTIN\\Replicator";
break;
default:
return false;
}
return IsInRole (role);
}
}
public virtual bool IsInRole (string role)
{
if (role == null)
return false; // ArgumentNullException
if (Environment.IsUnix) {
// note: Posix is always case-sensitive
return IsMemberOfGroupName (Token, role);
}
else {
// Windows specific code that
// (a) build the role cache like the MS framework (for compatibility)
// (b) case sensitive (for Fx 1.0) and case insensitive (later Fx)
if (m_roles == null) {
m_roles = WindowsIdentity._GetRoles (Token);
}
role = role.ToUpperInvariant ();
foreach (string check in m_roles) {
if ((check != null) && (role == check.ToUpperInvariant ()))
return true;
}
return false;
}
}
public virtual bool IsInRole (WindowsBuiltInRole role)
{
if (Environment.IsUnix) {
// right now we only map Administrator == root
string group = null;
switch (role) {
case WindowsBuiltInRole.Administrator:
group = "root";
break;
default:
return false;
}
return IsInRole (group);
}
else {
return IsInRole ((int) role);
}
}
[MonoTODO ("not implemented")]
[ComVisible (false)]
public virtual bool IsInRole (SecurityIdentifier sid)
{
throw new NotImplementedException ();
}
private IntPtr Token {
get { return (_identity as WindowsIdentity).Token; }
}
// see mono/mono/metadata/security.c for implementation
// note: never called by Win32 code (i.e. always return false)
[MethodImplAttribute (MethodImplOptions.InternalCall)]
private extern static bool IsMemberOfGroupId (IntPtr user, IntPtr group);
// note: never called by Win32 code (i.e. always return false)
[MethodImplAttribute (MethodImplOptions.InternalCall)]
private extern static bool IsMemberOfGroupName (IntPtr user, string group);
}
}