Created
November 26, 2010 06:10
-
-
Save noqisofon/716338 to your computer and use it in GitHub Desktop.
セキュリティ記述子のデモ。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Security; | |
using System.Security.Permissions; | |
using System.Security.Principal; | |
using System.Security.AccessControl; | |
namespace demo.security.descriptors { | |
class GainSecurityDescSample { | |
/// <summary> | |
/// アドミニストレータとパワーユーザーの混合セキュリティ記述子を作成して返します。 | |
/// </summary> | |
/// <returns></returns> | |
CommonSecurityDescriptor getSecurityDescriptor() { | |
SecurityIdentifier local_admin = new SecurityIdentifier( WellKnownSidType.BuiltinAdministratorsSid, null ); | |
SecurityIdentifier power_user = new SecurityIdentifier( WellKnownSidType.BuiltinPowerUsersSid, null ); | |
DiscretionaryAcl dacl = new DiscretionaryAcl( false, false, 1 ); | |
dacl.AddAccess( AccessControlType.Allow, | |
local_admin, | |
-1, | |
InheritanceFlags.None, | |
PropagationFlags.None | |
); | |
dacl.AddAccess( AccessControlType.Allow, | |
power_user, | |
-1, | |
InheritanceFlags.None, | |
PropagationFlags.None | |
); | |
return new CommonSecurityDescriptor( false, | |
false, | |
ControlFlags.GroupDefaulted | | |
ControlFlags.OwnerDefaulted | | |
ControlFlags.DiscretionaryAclPresent, | |
null, | |
null, | |
null, | |
dacl | |
); | |
} | |
/// <summary> | |
/// | |
/// </summary> | |
/// <param name="args"></param> | |
public void run(string[] args) { | |
CommonSecurityDescriptor csd = getSecurityDescriptor(); | |
Console.WriteLine( "binary length: {0}", csd.BinaryLength ); | |
Console.WriteLine( "control flags: [{0}]", csd.ControlFlags ); | |
Console.WriteLine( "discretionary acl hash: 0x{0:x}", csd.DiscretionaryAcl.GetHashCode() ); | |
int i = 0; | |
foreach ( GenericAce gace in csd.DiscretionaryAcl ) { | |
Console.WriteLine( " at {0}", i ); | |
Console.WriteLine( " ace flags: {0}", gace.AceFlags ); | |
Console.WriteLine( " ace type: {0}", gace.AceType ); | |
Console.WriteLine( " audit flags: {0}", gace.AuditFlags ); | |
Console.WriteLine( " binary length: {0}", gace.BinaryLength ); | |
Console.WriteLine( " inheritance flags: {0}", gace.InheritanceFlags ); | |
Console.WriteLine( " inherited?: {0}", gace.IsInherited ); | |
Console.WriteLine( " propagation flags: {0}", gace.PropagationFlags ); | |
++i; | |
} | |
Console.WriteLine( "group: {0}", csd.Group == null ? "null" : csd.Group.Value ); | |
Console.WriteLine( "container?: {0}", csd.IsContainer ); | |
Console.WriteLine( "discretionary acl canonical?: {0}", csd.IsDiscretionaryAclCanonical ); | |
Console.WriteLine( "directory object?: {0}", csd.IsDS ); | |
Console.WriteLine( "system acl canonical?: {0}", csd.IsSystemAclCanonical ); | |
Console.WriteLine( "owner: {0}", csd.Owner == null ? "null" : csd.Owner.Value ); | |
if ( csd.SystemAcl == null ) | |
Console.WriteLine( "system acl: null" ); | |
else | |
Console.WriteLine( "system acl: 0x{0:x}", csd.SystemAcl.GetHashCode() ); | |
} | |
/// <summary> | |
/// | |
/// </summary> | |
/// <param name="args"></param> | |
static void Main(string[] args) { | |
GainSecurityDescSample progn = new GainSecurityDescSample(); | |
progn.run( args ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment