Esempio n. 1
0
        private string NtAccount(string userName)
        {
            var account = new NTAccount(userName);

            if (account.IsValidTargetType(typeof(SecurityIdentifier)))
            {
                return(account.Translate(typeof(SecurityIdentifier)).Value);
            }

            return(null);
        }
Esempio n. 2
0
        private void GetNTAcctForPath(String path)
        {
            FileSecurity fs = File.GetAccessControl(path);

            AuthorizationRuleCollection ntarc = fs.GetAccessRules(true, true, typeof(NTAccount));
            AuthorizationRuleCollection siarc = fs.GetAccessRules(true, true, typeof(SecurityIdentifier));

            Console.WriteLine("Checking SIDs on path: {0}", path);

            Console.WriteLine("\n== By NTAccount ==");
            foreach (FileSystemAccessRule fsar in ntarc)
            {
                NTAccount nta = (NTAccount)fsar.IdentityReference;
                Console.WriteLine("{0} <=> {1}", nta.Value, nta.IsValidTargetType(typeof(SecurityIdentifier)) ?
                                  nta.Translate(typeof(SecurityIdentifier)).ToString() :
                                  "-");
            }
            Console.WriteLine("\n== By SecurityIdentifier == ");
            foreach (FileSystemAccessRule siar in siarc)
            {
                SecurityIdentifier sia = (SecurityIdentifier)siar.IdentityReference;

                try
                {
                    Console.WriteLine("SDDL:{0} <=> {1}",
                                      sia.Value,
                                      (sia.IsAccountSid() ? (sia.IsValidTargetType(typeof(NTAccount)) ?
                                                             sia.Translate(typeof(NTAccount)).ToString() : "-") :
                                       "Not a real Windows Account"));
                }
                catch (Exception e)
                {
                    Console.WriteLine("Error: {0}", e.Message);
                }
            }
        }