本文整理汇总了C#中System.Security.Principal.SecurityIdentifier.GetBinaryForm方法的典型用法代码示例。如果您正苦于以下问题:C# SecurityIdentifier.GetBinaryForm方法的具体用法?C# SecurityIdentifier.GetBinaryForm怎么用?C# SecurityIdentifier.GetBinaryForm使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.Principal.SecurityIdentifier
的用法示例。
在下文中一共展示了SecurityIdentifier.GetBinaryForm方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SecurityIdentifierExtensions_GetBinaryForm_Test1
public void SecurityIdentifierExtensions_GetBinaryForm_Test1()
{
SecurityIdentifier sid = new SecurityIdentifier("S-1-5-21-3180365339-800773672-3767752645-500");
byte[] binary = sid.GetBinaryForm();
SecurityIdentifier sid2 = new SecurityIdentifier(binary, 0);
Assert.AreEqual(sid, sid2);
}
示例2: CheckStringCtor
private void CheckStringCtor (string strValue, byte[] expectedBinary)
{
SecurityIdentifier sid = new SecurityIdentifier (strValue);
byte[] buffer = new byte[sid.BinaryLength];
sid.GetBinaryForm (buffer, 0);
Assert.AreEqual (expectedBinary.Length, buffer.Length, "SID length mismatch");
Assert.AreEqual (expectedBinary, buffer, "SIDs different in binary form");
}
示例3: ConvertStringSidToSid
public static bool ConvertStringSidToSid (string StringSid, out IntPtr ptrSid)
{
unsafe {
var ident = new SecurityIdentifier (StringSid);
byte[] pSID = new byte[ident.BinaryLength];
ident.GetBinaryForm (pSID, 0);
ptrSid = GCHandle.ToIntPtr (GCHandle.Alloc (pSID));
}
return true;
}
示例4: SecurityIdentifierToLdapHexBindingString
// use this for binding string...
internal static string SecurityIdentifierToLdapHexBindingString(SecurityIdentifier sid)
{
byte[] sidB = new byte[sid.BinaryLength];
sid.GetBinaryForm(sidB, 0);
StringBuilder stringizedBinarySid = new StringBuilder();
foreach (byte b in sidB)
{
stringizedBinarySid.Append(b.ToString("x2", CultureInfo.InvariantCulture));
}
return stringizedBinarySid.ToString();
}
示例5: CreateProxy
//work around way to create a new userProxyFull object
public static void CreateProxy(string server, string path, string name, SecurityIdentifier sid)
{
var sidInBytes = new byte[sid.BinaryLength];
sid.GetBinaryForm(sidInBytes, 0);
var ouDE = new DirectoryEntry(string.Format("LDAP://{0}/{1}", server, path));
var proxyDE = ouDE.Children.Add(String.Format("CN={0}", name), "userProxyFull");
proxyDE.Properties["objectSid"].Clear();
proxyDE.Properties["objectSid"].Value = sidInBytes;
proxyDE.Properties["userPrincipalName"].Value = name;
proxyDE.CommitChanges();
}
示例6: CommonAce_CreateTestData
private static object[] CommonAce_CreateTestData(int intFlags, int intQualifier, int accessMask, string stringsid, bool isCallback, int opaqueLength, int offset)
{
AceFlags flags = (AceFlags)intFlags;
AceQualifier qualifier = (AceQualifier)intQualifier;
SecurityIdentifier sid = new SecurityIdentifier(stringsid);
byte[] opaque = new byte[opaqueLength];
CommonAce ace = new CommonAce(flags, qualifier, accessMask, sid, isCallback, opaque);
Assert.Equal(flags, ace.AceFlags);
Assert.Equal(accessMask, ace.AccessMask);
Assert.Equal(sid, ace.SecurityIdentifier);
Assert.Equal(opaque, ace.GetOpaque());
Assert.Equal(qualifier, ace.AceQualifier);
Assert.Equal(isCallback, ace.IsCallback);
byte[] binaryForm = new byte[ace.BinaryLength + offset];
switch (qualifier)
{
case AceQualifier.AccessAllowed:
binaryForm[offset + 0] = isCallback ? (byte)AceType.AccessAllowedCallback : (byte)AceType.AccessAllowed;
break;
case AceQualifier.AccessDenied:
binaryForm[offset + 0] = isCallback ? (byte)AceType.AccessDeniedCallback : (byte)AceType.AccessDenied;
break;
case AceQualifier.SystemAudit:
binaryForm[offset + 0] = isCallback ? (byte)AceType.SystemAuditCallback : (byte)AceType.SystemAudit;
break;
case AceQualifier.SystemAlarm:
binaryForm[offset + 0] = isCallback ? (byte)AceType.SystemAlarmCallback : (byte)AceType.SystemAlarm;
break;
default:
return null;
}
binaryForm[offset + 1] = (byte)flags;
binaryForm[offset + 2] = (byte)(ace.BinaryLength >> 0);
binaryForm[offset + 3] = (byte)(ace.BinaryLength >> 8);
int baseOffset = offset + 4;
int offsetLocal = 0;
binaryForm[baseOffset + 0] = (byte)(accessMask >> 0);
binaryForm[baseOffset + 1] = (byte)(accessMask >> 8);
binaryForm[baseOffset + 2] = (byte)(accessMask >> 16);
binaryForm[baseOffset + 3] = (byte)(accessMask >> 24);
offsetLocal += 4;
sid.GetBinaryForm(binaryForm, baseOffset + offsetLocal);
offsetLocal += sid.BinaryLength;
opaque.CopyTo(binaryForm, baseOffset + offsetLocal);
return new object[] { ace, binaryForm, offset };
}
示例7: SecurityDescriptor
//creates Everyone,Full, inherit security descriptor
private ManagementObject SecurityDescriptor()
{
SecurityIdentifier sec = new SecurityIdentifier(System.Security.Principal.WellKnownSidType.WorldSid, null);
byte[] sidArray = new byte[sec.BinaryLength];
sec.GetBinaryForm(sidArray, 0);
ManagementObject Trustee = new ManagementClass(new ManagementPath("Win32_Trustee"), null);
Trustee["Domain"] = "NT Authority";
Trustee["Name"] = "Everyone";
Trustee["SID"] = sidArray;
ManagementObject ACE = new ManagementClass(new ManagementPath("Win32_Ace"), null);
ACE["AccessMask"] = 2032127; // 0x1f01ff Full Access
ACE["AceFlags"] = 3; //Non-container and container child objects to inherit ace
ACE["AceType"] = 0; //defines access allowed (1 would be defining access denied
ACE["Trustee"] = Trustee;
ManagementObject SecDesc = new ManagementClass(new ManagementPath("Win32_SecurityDescriptor"), null);
SecDesc["ControlFlags"] = 4; //SE_DACL_present
SecDesc["DACL"] = new object[] { ACE };
return SecDesc;
}
示例8: CreateUncShare
public static bool CreateUncShare(string shareName, string localPath)
{
ManagementScope scope = new System.Management.ManagementScope(@"root\CIMV2");
scope.Connect();
using (ManagementClass managementClass = new ManagementClass(scope, new ManagementPath("Win32_Share"), (ObjectGetOptions) null))
{
SecurityIdentifier securityIdentifier = new SecurityIdentifier(WellKnownSidType.WorldSid, (SecurityIdentifier) null);
byte[] binaryForm = new byte[securityIdentifier.BinaryLength];
securityIdentifier.GetBinaryForm(binaryForm, 0);
using (ManagementObject wmiTrustee = new ManagementClass(scope, new ManagementPath("Win32_Trustee"), (ObjectGetOptions) null).CreateInstance())
{
wmiTrustee["SID"] = (object) binaryForm;
using (ManagementObject wmiACE = new ManagementClass(scope, new ManagementPath("Win32_ACE"), (ObjectGetOptions) null).CreateInstance())
{
wmiACE["AccessMask"] = 131241; //READ_CONTROL | FILE_READ | FILE_TRAVERSE | FILE_READ_EA | FILE_LIST_DIRECTORY
wmiACE["AceFlags"] = 3; //OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE
wmiACE["AceType"] = 0; //ACCESS_ALLOWED
wmiACE["Trustee"] = wmiTrustee;
using (ManagementObject wmiSecurityDescriptor = new ManagementClass(scope, new ManagementPath("Win32_SecurityDescriptor"), (ObjectGetOptions) null).CreateInstance())
{
wmiSecurityDescriptor["ControlFlags"] = 4;
wmiSecurityDescriptor["DACL"] = new ManagementObject[] { wmiACE };
using (ManagementBaseObject inParamsCreate = managementClass.GetMethodParameters("Create"))
{
inParamsCreate["Access"] = wmiSecurityDescriptor;
inParamsCreate["Path"] = localPath;
inParamsCreate["Name"] = shareName;
inParamsCreate["Type"] = 0;
inParamsCreate["Description"] = "TVServerXBMC share";
using (ManagementBaseObject outParams = managementClass.InvokeMethod("Create", inParamsCreate, (InvokeMethodOptions) null))
return ((int) (uint) outParams["returnValue"] == 0);
}
}
}
}
}
}
示例9: IsWellKnownSid
//
// Wrapper around advapi32.IsWellKnownSid
//
internal static bool IsWellKnownSid(
SecurityIdentifier sid,
WellKnownSidType type
)
{
byte[] BinaryForm = new byte[sid.BinaryLength];
sid.GetBinaryForm(BinaryForm, 0);
if (FALSE == Interop.mincore.IsWellKnownSid(BinaryForm, (int)type))
{
return false;
}
else
{
return true;
}
}
示例10: GetWindowsAccountDomainSid
//
// Wrapper around avdapi32.GetWindowsAccountDomainSid
//
internal static int GetWindowsAccountDomainSid(
SecurityIdentifier sid,
out SecurityIdentifier resultSid
)
{
//
// Passing an array as big as it can ever be is a small price to pay for
// not having to P/Invoke twice (once to get the buffer, once to get the data)
//
byte[] BinaryForm = new Byte[sid.BinaryLength];
sid.GetBinaryForm(BinaryForm, 0);
uint sidLength = (uint)SecurityIdentifier.MaxBinaryLength;
byte[] resultSidBinary = new byte[sidLength];
if (FALSE != Interop.mincore.GetWindowsAccountDomainSid(BinaryForm, resultSidBinary, ref sidLength))
{
resultSid = new SecurityIdentifier(resultSidBinary, 0);
return Interop.mincore.Errors.ERROR_SUCCESS;
}
else
{
resultSid = null;
return Marshal.GetLastWin32Error();
}
}
示例11: IsEqualDomainSid
//
// Wrapper around advapi32.EqualDomainSid
//
internal static bool IsEqualDomainSid(SecurityIdentifier sid1, SecurityIdentifier sid2)
{
if (sid1 == null || sid2 == null)
{
return false;
}
else
{
bool result;
byte[] BinaryForm1 = new Byte[sid1.BinaryLength];
sid1.GetBinaryForm(BinaryForm1, 0);
byte[] BinaryForm2 = new Byte[sid2.BinaryLength];
sid2.GetBinaryForm(BinaryForm2, 0);
return (Interop.mincore.IsEqualDomainSid(BinaryForm1, BinaryForm2, out result) == FALSE ? false : result);
}
}
示例12: TemplateT_SID
internal unsafe bool TemplateT_SID(
ref EventDescriptor eventDescriptor,
SecurityIdentifier Prop_SID
)
{
int argumentCount = 1;
bool status = true;
if (IsEnabled(eventDescriptor.Level, eventDescriptor.Keywords))
{
byte* userData = stackalloc byte[sizeof(EventData) * argumentCount];
EventData* userDataPtr = (EventData*)userData;
byte [] Prop_SIDBin = new byte[Prop_SID.BinaryLength];
Prop_SID.GetBinaryForm(Prop_SIDBin, 0);
userDataPtr[0].Size = (uint)(Prop_SID.BinaryLength);
fixed (byte* a0 = Prop_SIDBin)
{
userDataPtr[0].DataPointer = (ulong)a0;
status = WriteEvent(ref eventDescriptor, argumentCount, (IntPtr)(userData));
}
}
return status;
}
示例13: ObjectAce_CreateTestData
private static object[] ObjectAce_CreateTestData(int intFlags, int intQualifier, int accessMask, string stringsid, int intObjectAceFlags, string stringType, string stringInheritedType, bool isCallback, int opaqueLength, int offset)
{
AceFlags aceFlags = (AceFlags)intFlags;
AceQualifier qualifier = (AceQualifier)intQualifier;
SecurityIdentifier sid = new SecurityIdentifier(stringsid);
ObjectAceFlags flags = (ObjectAceFlags)intObjectAceFlags;
Guid type = new Guid(stringType);
Guid inheritedType = new Guid(stringInheritedType);
byte[] opaque = new byte[opaqueLength];
ObjectAce ace = new ObjectAce(aceFlags, qualifier, accessMask, sid, flags, type, inheritedType, isCallback, opaque);
VerifyObjectAce(ace, aceFlags, qualifier, accessMask, sid, flags, type, inheritedType, isCallback, opaque);
byte[] binaryForm = new byte[ace.BinaryLength + offset];
switch (qualifier)
{
case AceQualifier.AccessAllowed:
binaryForm[offset + 0] = isCallback ? (byte)AceType.AccessAllowedCallbackObject : (byte)AceType.AccessAllowedObject;
break;
case AceQualifier.AccessDenied:
binaryForm[offset + 0] = isCallback ? (byte)AceType.AccessDeniedCallbackObject : (byte)AceType.AccessDeniedObject;
break;
case AceQualifier.SystemAudit:
binaryForm[offset + 0] = isCallback ? (byte)AceType.SystemAuditCallbackObject : (byte)AceType.SystemAuditObject;
break;
case AceQualifier.SystemAlarm:
binaryForm[offset + 0] = isCallback ? (byte)AceType.SystemAlarmCallbackObject : (byte)AceType.SystemAlarmObject;
break;
default:
return null;
}
binaryForm[offset + 1] = (byte)aceFlags;
binaryForm[offset + 2] = (byte)(ace.BinaryLength >> 0);
binaryForm[offset + 3] = (byte)(ace.BinaryLength >> 8);
int baseOffset = offset + 4;
int offsetLocal = 0;
binaryForm[baseOffset + 0] = (byte)(accessMask >> 0);
binaryForm[baseOffset + 1] = (byte)(accessMask >> 8);
binaryForm[baseOffset + 2] = (byte)(accessMask >> 16);
binaryForm[baseOffset + 3] = (byte)(accessMask >> 24);
offsetLocal += 4;
binaryForm[baseOffset + offsetLocal + 0] = (byte)(((uint)flags) >> 0);
binaryForm[baseOffset + offsetLocal + 1] = (byte)(((uint)flags) >> 8);
binaryForm[baseOffset + offsetLocal + 2] = (byte)(((uint)flags) >> 16);
binaryForm[baseOffset + offsetLocal + 3] = (byte)(((uint)flags) >> 24);
offsetLocal += 4;
if ((flags & ObjectAceFlags.ObjectAceTypePresent) != 0)
{
type.ToByteArray().CopyTo(binaryForm, baseOffset + offsetLocal);
offsetLocal += 16;
}
if ((flags & ObjectAceFlags.InheritedObjectAceTypePresent) != 0)
{
inheritedType.ToByteArray().CopyTo(binaryForm, baseOffset + offsetLocal);
offsetLocal += 16;
}
sid.GetBinaryForm(binaryForm, baseOffset + offsetLocal);
offsetLocal += sid.BinaryLength;
opaque.CopyTo(binaryForm, baseOffset + offsetLocal);
return new object[] { ace, binaryForm, offset };
}
示例14: IsWellKnownSid
internal static bool IsWellKnownSid(SecurityIdentifier sid, WellKnownSidType type)
{
if (!WellKnownSidApisSupported)
{
throw new PlatformNotSupportedException(Environment.GetResourceString("PlatformNotSupported_RequiresW2kSP3"));
}
byte[] binaryForm = new byte[sid.BinaryLength];
sid.GetBinaryForm(binaryForm, 0);
if (Win32Native.IsWellKnownSid(binaryForm, (int) type) == 0)
{
return false;
}
return true;
}
示例15: IsEqualDomainSid
internal static bool IsEqualDomainSid(SecurityIdentifier sid1, SecurityIdentifier sid2)
{
bool flag;
if (!WellKnownSidApisSupported)
{
throw new PlatformNotSupportedException(Environment.GetResourceString("PlatformNotSupported_RequiresW2kSP3"));
}
if ((sid1 == null) || (sid2 == null))
{
return false;
}
byte[] binaryForm = new byte[sid1.BinaryLength];
sid1.GetBinaryForm(binaryForm, 0);
byte[] buffer2 = new byte[sid2.BinaryLength];
sid2.GetBinaryForm(buffer2, 0);
return ((Win32Native.IsEqualDomainSid(binaryForm, buffer2, out flag) != 0) && flag);
}