PDA

View Full Version : سوال: دیدن ACL های فایل و فولدر ها ؟؟



l4tr0d3ctism
شنبه 01 تیر 1392, 18:40 عصر
سلام و خسته نباشید

دوستان ببینید این کد چه مشکلی داره که نمی توننم اجرا کنم می خوام وقتی آدرس یک فولدر و یا فایل رو بهش می دم خروجی رو در یک فایل متنی و ... نشون بده که ACL فایل چیه

کد این هست

http://justsomevbcode.blogspot.de/2012/11/acls-for-file-and-directory-access.html




Dim sLogFile As String
sLogFile = IO.Path.Combine(IO.Path.GetDirectoryName(Applicati on.ExecutablePath()), "Data", "Log", "Example.log")

If Not My.Computer.FileSystem.DirectoryExists(IO.Path.Get DirectoryName(sLogFile)) Then
' Create the directory
Dim sDataDir As String = IO.Path.Combine(IO.Path.GetDirectoryName(Applicati on.ExecutablePath()), "Data")

' The VB.NET runtime will create any intermediary directories as necessary
My.Computer.FileSystem.CreateDirectory(IO.Path.Get DirectoryName(sLogFile))

' Get the ACL for the directory just created
Dim oACL As Security.AccessControl.DirectorySecurity = IO.Directory.GetAccessControl(IO.Path.GetDirectory Name(sDataDir), Security.AccessControl.AccessControlSections.Acces s)

' Create a security Identifier for the BuiltinUsers Group to be passed to the new access rule
Dim oBuiltInUsersSid As New Security.Principal.SecurityIdentifier(Security.Pri ncipal.WellKnownSidType.BuiltinUsersSid, Nothing)

' Create the rule that needs to be added to the ACL
Dim oRule As New Security.AccessControl.FileSystemAccessRule(oBuilt InUsersSid,
Security.AccessControl.FileSystemRights.Modify Or Security.AccessControl.FileSystemRights.Synchroniz e,
Security.AccessControl.InheritanceFlags.ContainerI nherit Or Security.AccessControl.InheritanceFlags.ObjectInhe rit,
Security.AccessControl.PropagationFlags.None,
Security.AccessControl.AccessControlType.Allow)

' Add the new rule to our ACL
oACL.AddAccessRule(oRule)

' Update the directory to include the new rules created
System.IO.Directory.SetAccessControl(sDataDir, oACL)
End If



برای تشخیص acL فایل


Public Function ListFileACLs(ByVal Filename As String) As String
Dim oFileACLs As New Security.AccessControl.FileSecurity(Filename, Security.AccessControl.AccessControlSections.Acces s)
Dim sbAccess As New System.Text.StringBuilder()

For Each oAccessRule As System.Security.AccessControl.FileSystemAccessRule In oFileACLs.GetAccessRules(True, True, GetType(System.Security.Principal.NTAccount))
sbAccess.AppendFormat("Account: {0}", oAccessRule.IdentityReference.Value).AppendLine()
sbAccess.AppendFormat("Type: {0}", oAccessRule.AccessControlType).AppendLine()
sbAccess.AppendFormat("Rights: {0}", oAccessRule.FileSystemRights).AppendLine()
sbAccess.AppendFormat("Inherited: {0}", oAccessRule.IsInherited).AppendLine()
sbAccess.AppendFormat("Inheritance: {0}", oAccessRule.InheritanceFlags).AppendLine()
sbAccess.AppendFormat("Propagation: {0}", oAccessRule.PropagationFlags).AppendLine()
sbAccess.AppendLine(New String("-"c, 25))
Next

Return sbAccess.ToString()
End Function


و برای فولدر




Public Function ListDirectoryACLs(ByVal Directory As String) As String
Dim oDirACLs As New Security.AccessControl.DirectorySecurity(Directory , Security.AccessControl.AccessControlSections.Acces s)
Dim sbAccess As New System.Text.StringBuilder()

For Each oAccessRule As System.Security.AccessControl.FileSystemAccessRule In oDirACLs.GetAccessRules(True, True, GetType(System.Security.Principal.NTAccount))
sbAccess.AppendFormat("Account: {0}", oAccessRule.IdentityReference.Value).AppendLine()
sbAccess.AppendFormat("Type: {0}", oAccessRule.AccessControlType).AppendLine()
sbAccess.AppendFormat("Rights: {0}", oAccessRule.FileSystemRights).AppendLine()
sbAccess.AppendFormat("Inherited: {0}", oAccessRule.IsInherited).AppendLine()
sbAccess.AppendFormat("Inheritance: {0}", oAccessRule.InheritanceFlags).AppendLine()
sbAccess.AppendFormat("Propagation: {0}", oAccessRule.PropagationFlags).AppendLine()
sbAccess.AppendLine(New String("-"c, 25))
Next

Return sbAccess.ToString()
End Function



در نهایت خروجی باید یک همچین چیزی باشه


Account: NT AUTHORITY\SYSTEM
Type: Allow
Rights: FullControl
Inherited: True
Inheritance: ContainerInherit, ObjectInherit
Propagation: None

اگه این روش درست نشد اونوقت فرمان cacls رو میگیرم

ممنون میشم کسی راهنمایی کنه