Example #1
0
        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));
        }
Example #2
0
        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();
                }
            }
        }
Example #3
0
        //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);
        }
Example #4
0
 public int GetId(ACE ace)
 {
     locker.EnterUpgradeableReadLock();
     try
     {
         return(_UnsafeGetId(ace));
     }
     catch (Exception)
     {
         throw;
     }
     finally
     {
         locker.ExitUpgradeableReadLock();
     }
 }
Example #5
0
        //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);
            }
        }
Example #6
0
        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);
        }