public Tuple <int, string, bool> ACLParse(System.IO.DirectoryInfo directoryInfo) { string error = string.Empty; int aclId = 0; bool allInherited = true; try { var dirSecurity = directoryInfo.GetAccessControl(); var authRuleColl = dirSecurity.GetAccessRules(true, true, typeof(NTAccount)); var acl = new ACL(); foreach (FileSystemAccessRule fsaRule in authRuleColl) { if (!fsaRule.IsInherited) { allInherited = false; } var ace = new ACE(fsaRule); var id = _ACESet.GetId(ace); // add this ace to the aceset; acl.Add(ace, id); } acl.Seal(); aclId = _ACLSet.GetId(acl); } catch (Exception ex) { error = ex.Message; } finally { } return(Tuple.Create(aclId, error, allInherited)); }
private int _UnsafeGetId(ACE ace) { if (ace is null) { return(0); } if (aceList.TryGetValue(ace, out int id)) { ace.ResetID(maxID); return(id); } else { locker.EnterWriteLock(); try { return(_UnsafeAddId(ace)); } catch (Exception) { throw; } finally { locker.ExitWriteLock(); } } }
//public IEnumerable<T> GetEnumerable<T>(List<T> x) //{ // IEnumerable<T> result = x; // foreach(var item in x) // { // result. // } // return result; //} //private byte[] IntListCheckSum(List<int> intList) //{ // int[] intArray = intList.ToArray(); // var checksum = new byte[64]; // byte[] result = new byte[intArray.Length * sizeof(int)]; // Buffer.BlockCopy(intArray, 0, result, 0, result.Length); // using (var sha = new SHA512Managed()) // { // checksum = sha.ComputeHash(result); // } // return checksum; //} private int ACEdbId(ACE value) { var pName = value.PrincipalName; var pSID = value.PrincipalSID; var rights = value.Rights; var pNameID = PrincipalID(pName, pSID); var rightsID = RightsID(rights); var aceID = AceDBID(pNameID, rightsID); return(aceID); }
public int GetId(ACE ace) { locker.EnterUpgradeableReadLock(); try { return(_UnsafeGetId(ace)); } catch (Exception) { throw; } finally { locker.ExitUpgradeableReadLock(); } }
//private ReaderWriterLockSlim locker = new ReaderWriterLockSlim(); public void Add(ACE ace, int id) { if (hash != 0) { throw new Exception("ACL.Add(,) not allowed after Seal()."); } if (list.TryGetValue(id, out ACE value)) { if (!value.Equals(ace)) { throw new Exception("ACL.Add(,) AceID and ACE inconsistent."); } } else { list.Add(id, ace); } }
private int _UnsafeAddId(ACE ace) { var aceid = ace.AceID; aceList.Add(ace, aceid); if (idList.TryAdd(aceid, ace)) { } else { throw new ArgumentException($"@ ACESet.GetID Cannot add Duplicate ACE {ace}"); } if (aceid > maxID) { maxID = aceid; } return(ace.AceID); }