Created
November 24, 2010 06:34
-
-
Save noqisofon/713210 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.IO; | |
using System.Security.AccessControl; | |
using System.Security.Principal; | |
namespace demo.ac { | |
/// <summary> | |
/// | |
/// </summary> | |
/// <remarks>参考: [[http://hp.vector.co.jp/authors/VA019702/acl/listaccessrights.html]]</remarks> | |
class EnumerateFilePermissionsSample { | |
/// <summary> | |
/// | |
/// </summary> | |
/// <param name="args"></param> | |
public void run(string[] args) { | |
if ( args.Length == 0 ) { | |
Console.Error.WriteLine( "no input files" ); | |
return; | |
} | |
Console.WriteLine( "{0}\t{1}\t{2}\t{3}", | |
"accessControlType", | |
"accountName", | |
"fileSystemRight", | |
"isInherited" | |
); | |
foreach ( string file_path in args ) { | |
if ( !File.Exists( file_path ) ) | |
continue; | |
FileSecurity securty = File.GetAccessControl( file_path ); | |
foreach ( FileSystemAccessRule rule in securty.GetAccessRules( true, true, typeof( NTAccount ) ) ) { | |
Console.WriteLine( "{0}\t{1}\t{2}\t{3}", | |
rule.AccessControlType, | |
( rule.IdentityReference as NTAccount ).Value, | |
rule.FileSystemRights, | |
rule.IsInherited | |
); | |
} | |
Console.WriteLine(); | |
} | |
} | |
/// <summary> | |
/// | |
/// </summary> | |
/// <param name="args"></param> | |
static void Main(string[] args) { | |
EnumerateFilePermissionsSample progn = new EnumerateFilePermissionsSample(); | |
progn.run( args ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment