本文整理汇总了C#中SecurityIdentifier.GetBinaryForm方法的典型用法代码示例。如果您正苦于以下问题:C# SecurityIdentifier.GetBinaryForm方法的具体用法?C# SecurityIdentifier.GetBinaryForm怎么用?C# SecurityIdentifier.GetBinaryForm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SecurityIdentifier
的用法示例。
在下文中一共展示了SecurityIdentifier.GetBinaryForm方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindPrincipalByIdentRef
// Performs store-specific resolution of an IdentityReference to a Principal
// corresponding to the IdentityReference. Returns null if no matching object found.
// principalType can be used to scope the search to principals of a specified type, e.g., users or groups.
// Specify typeof(Principal) to search all principal types.
internal override Principal FindPrincipalByIdentRef(
Type principalType, string urnScheme, string urnValue, DateTime referenceDate)
{
// Perform the appropriate action based on the type of the UrnScheme
if (urnScheme == UrnScheme.SidScheme)
{
// Get the SID from the UrnValue
SecurityIdentifier sidObj = new SecurityIdentifier(urnValue);
byte[] sid = new byte[sidObj.BinaryLength];
sidObj.GetBinaryForm(sid, 0);
if (sid == null)
throw new ArgumentException(StringResources.StoreCtxSecurityIdentityClaimBadFormat);
// If they're searching by SID for a SID corresponding to a fake group, construct
// and return the fake group
IntPtr pSid = IntPtr.Zero;
try
{
pSid = Utils.ConvertByteArrayToIntPtr(sid);
if (UnsafeNativeMethods.IsValidSid(pSid) && (Utils.ClassifySID(pSid) == SidType.FakeObject))
{
GlobalDebug.WriteLineIf(GlobalDebug.Info,
"SAMStoreCtx",
"FindPrincipalByIdentRef: fake principal {0}",
sidObj.ToString());
return ConstructFakePrincipalFromSID(sid);
}
}
finally
{
if (pSid != IntPtr.Zero)
Marshal.FreeHGlobal(pSid);
}
// Not a fake group. Search for the real group.
object o = FindNativeBySIDIdentRef(principalType, sid);
return (o != null) ? GetAsPrincipal(o, null) : null;
}
else if (urnScheme == UrnScheme.SamAccountScheme || urnScheme == UrnScheme.NameScheme)
{
object o = FindNativeByNT4IdentRef(principalType, urnValue);
return (o != null) ? GetAsPrincipal(o, null) : null;
}
else if (urnScheme == null)
{
object sidPrincipal = null;
object nt4Principal = null;
//
// Try UrnValue as a SID IdentityClaim
//
// Get the SID from the UrnValue
byte[] sid = null;
try
{
SecurityIdentifier sidObj = new SecurityIdentifier(urnValue);
sid = new byte[sidObj.BinaryLength];
sidObj.GetBinaryForm(sid, 0);
}
catch (ArgumentException)
{
// must not have been a valid sid claim ignore it.
}
// If null, must have been a non-SID UrnValue. Ignore it, and
// continue on to try NT4 Account IdentityClaim.
if (sid != null)
{
// Are they perhaps searching for a fake group?
// If they passed in a valid SID for a fake group, construct and return the fake
// group.
if (principalType == typeof(Principal) || principalType == typeof(GroupPrincipal) || principalType.IsSubclassOf(typeof(GroupPrincipal)))
{
// They passed in a hex string, is it a valid SID, and if so, does it correspond to a fake
// principal?
IntPtr pSid = IntPtr.Zero;
try
{
pSid = Utils.ConvertByteArrayToIntPtr(sid);
if (UnsafeNativeMethods.IsValidSid(pSid) && (Utils.ClassifySID(pSid) == SidType.FakeObject))
{
GlobalDebug.WriteLineIf(GlobalDebug.Info,
"SAMStoreCtx",
"FindPrincipalByIdentRef: fake principal {0} (scheme==null)",
Utils.ByteArrayToString(sid));
return ConstructFakePrincipalFromSID(sid);
}
//.........这里部分代码省略.........
示例2: GetEffectiveRights
static uint GetEffectiveRights(SE_OBJECT_TYPE type, String name, String sidString)
{
SecurityIdentifier sid = new SecurityIdentifier(sidString);
IntPtr pOwner = IntPtr.Zero; // pSID
IntPtr pGroup = IntPtr.Zero; // pSID
IntPtr pSacl = IntPtr.Zero;
IntPtr pDacl = IntPtr.Zero;
IntPtr pSD = IntPtr.Zero; // pSECURITY_DESCRIPTOR
uint result = GetNamedSecurityInfo(name, type, SECURITY_INFORMATION.DACL_SECURITY_INFORMATION, out pOwner,
out pGroup, out pDacl, out pSacl, out pSD);
if (result != 0) {
throw new System.ComponentModel.Win32Exception((int)result);
}
byte[] sidBuffer = new byte[sid.BinaryLength];
sid.GetBinaryForm(sidBuffer, 0);
TRUSTEE t = new TRUSTEE();
BuildTrusteeWithSid(ref t, sidBuffer);
uint access = 0;
uint hr = GetEffectiveRightsFromAcl(pDacl, ref t, ref access);
int i = Marshal.Release(t.ptstrName);
return access;
}
示例3: FindPrincipalByIdentRef
internal override Principal FindPrincipalByIdentRef(Type principalType, string urnScheme, string urnValue, DateTime referenceDate)
{
Principal principal;
if (urnScheme != "ms-sid")
{
if (urnScheme == "ms-nt4account" || urnScheme == "ms-name")
{
object obj = this.FindNativeByNT4IdentRef(principalType, urnValue);
if (obj != null)
{
return this.GetAsPrincipal(obj, null);
}
else
{
return null;
}
}
else
{
if (urnScheme != null)
{
throw new ArgumentException(StringResources.StoreCtxUnsupportedIdentityClaimForQuery);
}
else
{
object obj1 = null;
object obj2 = null;
byte[] numArray = null;
try
{
SecurityIdentifier securityIdentifier = new SecurityIdentifier(urnValue);
numArray = new byte[securityIdentifier.BinaryLength];
securityIdentifier.GetBinaryForm(numArray, 0);
}
catch (ArgumentException argumentException)
{
}
if (numArray != null)
{
if (principalType == typeof(Principal) || principalType == typeof(GroupPrincipal) || principalType.IsSubclassOf(typeof(GroupPrincipal)))
{
IntPtr zero = IntPtr.Zero;
try
{
zero = Utils.ConvertByteArrayToIntPtr(numArray);
if (UnsafeNativeMethods.IsValidSid(zero) && Utils.ClassifySID(zero) == SidType.FakeObject)
{
principal = this.ConstructFakePrincipalFromSID(numArray);
return principal;
}
}
finally
{
if (zero != IntPtr.Zero)
{
Marshal.FreeHGlobal(zero);
}
}
}
obj1 = this.FindNativeBySIDIdentRef(principalType, numArray);
}
try
{
obj2 = this.FindNativeByNT4IdentRef(principalType, urnValue);
}
catch (ArgumentException argumentException1)
{
}
if (obj1 == null || obj2 == null)
{
if (obj1 != null)
{
return this.GetAsPrincipal(obj1, null);
}
else
{
if (obj2 != null)
{
return this.GetAsPrincipal(obj2, null);
}
else
{
return null;
}
}
}
else
{
throw new MultipleMatchesException(StringResources.MultipleMatchingPrincipals);
}
}
}
}
else
{
SecurityIdentifier securityIdentifier1 = new SecurityIdentifier(urnValue);
byte[] numArray1 = new byte[securityIdentifier1.BinaryLength];
securityIdentifier1.GetBinaryForm(numArray1, 0);
if (numArray1 != null)
{
//.........这里部分代码省略.........
示例4: FindPrincipalByIdentRefHelper
// Handles all the work required to implement FindPrincipalByIdentRef (and FindPrincipalBySID).
private Principal FindPrincipalByIdentRefHelper(
Type principalType,
string urnScheme,
string urnValue,
DateTime referenceDate,
bool useSidHistory)
{
GlobalDebug.WriteLineIf(GlobalDebug.Info,
"ADStoreCtx",
"FindPrincipalByIdentRefHelper: type={0}, scheme={1}, value={2}, useSidHistory={3}",
principalType.ToString(),
(urnScheme != null ? urnScheme : "NULL"),
(urnValue != null ? urnValue : "NULL"),
useSidHistory);
//
// Set up a DirectorySearcher
//
DirectorySearcher ds = new DirectorySearcher(this.ctxBase);
SearchResultCollection src = null;
try
{
ds.SizeLimit = 2; // so we can efficiently check for duplicates
// If we are searching for AuthPrincpal or Principal in the end we will construct the acutal type
// i.e. if the objects objectClass is User we will construct a UserPrincipal even though they searched for Principal.FindByIdentity
// At this time we don't know the actual object type so we have to ask AD for all the attributes of the derived types so they are there
// when we go to load the principal.
if (principalType == typeof(Principal) || principalType == typeof(AuthenticablePrincipal))
{
BuildPropertySet(typeof(UserPrincipal), ds.PropertiesToLoad);
BuildPropertySet(typeof(GroupPrincipal), ds.PropertiesToLoad);
BuildPropertySet(typeof(ComputerPrincipal), ds.PropertiesToLoad);
if (principalType == typeof(Principal))
{
BuildPropertySet(typeof(AuthenticablePrincipal), ds.PropertiesToLoad);
}
}
BuildPropertySet(principalType, ds.PropertiesToLoad);
//
// Build an appropriate filter
//
StringBuilder ldapFilter = new StringBuilder();
// Limit the results returned to principalType by specifying the corresponding objectClass/objectCategory
ldapFilter.Append(GetObjectClassPortion(principalType));
// Build the rest of the filter based off of the user's specified IdentityReference.
if (urnScheme != null)
{
// If they're searching by SID for a SID corresponding to a fake group, construct
// and return the fake group
if ((urnScheme == UrnScheme.SidScheme) &&
(principalType == typeof(Principal) || principalType == typeof(GroupPrincipal) || principalType.IsSubclassOf(typeof(GroupPrincipal))))
{
SecurityIdentifier sid = new SecurityIdentifier(urnValue);
byte[] sidb = new byte[sid.BinaryLength];
sid.GetBinaryForm(sidb, 0);
// = Utils.StringToByteArray(urnValue);
if (sid == null)
throw new ArgumentException(StringResources.StoreCtxSecurityIdentityClaimBadFormat);
IntPtr pSid = IntPtr.Zero;
try
{
pSid = Utils.ConvertByteArrayToIntPtr(sidb);
if (UnsafeNativeMethods.IsValidSid(pSid) && (Utils.ClassifySID(pSid) == SidType.FakeObject))
{
GlobalDebug.WriteLineIf(GlobalDebug.Info,
"ADStoreCtx",
"FindPrincipalByIdentRefHelper: fake principal, SID Scheme, {0}",
sid.ToString());
return ConstructFakePrincipalFromSID(sidb);
}
}
finally
{
if (pSid != IntPtr.Zero)
Marshal.FreeHGlobal(pSid);
}
}
// This is the simple case --- we got a specific UrnScheme, so we'll just build
// a filter for it.
// Ignore referenceDate --- all IdentityClaims in AD are forever
string innerLdapFilter = null;
BuildLdapFilterFromIdentityClaim(urnValue, urnScheme, ref innerLdapFilter, useSidHistory, true);
ldapFilter.Append(innerLdapFilter);
//.........这里部分代码省略.........