system.security.accesscontrol question

Discussion in 'ASP .Net Security' started by Darko Bazulj, Jun 4, 2008.

  1. Darko Bazulj

    Darko Bazulj Guest

    Hi,

    how to clear DACL from folder/file?

    I want to achive next:

    I want to clear DACL and add ACEs to ACL and 'stop inheritance'(this work).
    But when I do that "Everyone" ACEs are added to ACL so I need to remove
    "Everyone" ACE from ACL.

    I now do next but is there maybe some better way?

    To remove 'Everyone' I use 'RemoveAccessRuleAll'.

    ######

    Sub Main()

    ClearDACL("C:\tmp\ntfs\test")
    SetInheritance("C:\tmp\ntfs\test", True, False)

    End Sub

    Sub ClearDACL(ByVal strFolderName As String)

    Dim dInfo As New DirectoryInfo(strFolderName)
    Dim dSecurity As DirectorySecurity =
    dInfo.GetAccessControl(AccessControlSections.None)

    dSecurity.AddAccessRule(New FileSystemAccessRule("Everyone",
    FileSystemRights.Read, AccessControlType.Allow))

    dInfo.SetAccessControl(dSecurity)

    End Sub

    Sub SetInheritance(ByVal strFolderPath As String, ByVal isProtected As
    Boolean, ByVal preserveInheritance As Boolean)

    Dim dInfo As New DirectoryInfo(strFolderPath)
    Dim dSecurity As DirectorySecurity = dInfo.GetAccessControl()

    dSecurity.SetAccessRuleProtection(isProtected, preserveInheritance)
    dInfo.SetAccessControl(dSecurity)

    End Sub

    #########


    Regards,
    Darko Bazulj
    Darko Bazulj, Jun 4, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page