Removing ACL’s for dead AD accounts

Audience

Everyone

image I have run into a very vexing problem with one of my applications. I was asked to provide an application that would fin all of the permissions set against Active Directory accounts that have been since removed. These normally show up in the permissions dialogs for folders as the full SID of the account as there is no longer nay way to look it up in Active Directory.

imageI have written a nice little threaded application that lets you select a folder and it finds all of the dead accounts. What it actually does is verify all accounts against Active Directory and flags them if they are not found. This will have the side effect of finding groups and local accounts and thinking they are dead as well. To solve this problem I added a “Safe List” of accounts and as way to add them from the GUI. The system then ignores any account names that are in this list.

All is well…

But not really. As I moved on to actually deleting the offending ACL’s on request, I found it was a little more difficult to actually delete them as .NET seams to ignore my code…

Private Sub RemoveACL(ByVal DirectoryName As String, _
                      ByVal IdentityReference As Security.Principal.IdentityReference)
    Dim DS As DirectorySecurity
    DS = System.IO.Directory.GetAccessControl(DirectoryName)

    DS.PurgeAccessRules(IdentityReference)
    DS.PurgeAuditRules(IdentityReference)

    System.IO.Directory.SetAccessControl(DirectoryName, DS)
End Sub

Now, this code is fairly simple. First we get the directory security object, then we change the directory security object, and then we save the directory security object.

The “DirectoryName” object contains a CuteFTP folder:

image

The “IdentityReference” object contains the offending SID:

image

This code should work, and I have used a similar piece to add permissions, so why on earth can’t I remove them!

 

 

UPDATE: I have added a question about this to the MSDN Forums

Technorati Tags:  

Create a conversation around this article

Share on Facebook
Share on Twitter
Share on Linkdin

Read more

Martin Hinshelwood
In organizational development and team dynamics, Agile (as the Agile Manifesto delineates) and Scrum (as the Scrum Guide outlines) guide teams not by solving their problems but by illuminating the issues that demand attention. These frameworks aim to identify and spotlight the challenges within a team or organization’s processes, effectively …
Martin Hinshelwood
This week, I participated in a Scrum.org Webinar hosted by Sabrina Love (Scrum.org Product Owner) as well as my colleagues, Joanna Płaskonka, Ph.D. and Alex Ballarin to discuss the state of learning and how immersive learning is the future of training. You can watch the video below to hear what …
Martin Hinshelwood
For a long time now I have been searching for that perfect domain that epitomised the vision, the why, of what I am trying to achieve with my customers and the industry at large. Now I have found it in http://nkdagility.com
Martin Hinshelwood
At the MVP Summit I was appalled by the number of people who asked questions about new features for supporting hierarchical tasks! I shared a disgusted look with Peter Provost and we had a quick (and I mean really quick) conversation that resulted in this post. it really comes down …