public void GetOwnershipTest2()
        {
            // Arrange
            var tmpDir = Path.Combine(Path.GetTempPath(), "dirtools-test-" + Guid.NewGuid().ToString());
            Directory.CreateDirectory(tmpDir);

            var tmpFile = Path.Combine(tmpDir, "asdf");

            var localSystem = new SecurityIdentifier(WellKnownSidType.BuiltinAdministratorsSid, null);

            var fileSec = new FileSecurity();
            fileSec.SetOwner(localSystem);

            File.Create(tmpFile, 1, FileOptions.None, fileSec).Dispose();

            // Act
            var curIdentity = new NTAccount(Environment.UserDomainName, Environment.UserName);
            DirectoryTools.GetOwnershipForDirectory(tmpFile, curIdentity);

            // Assert
            var curFilesec = new FileSecurity(tmpFile, AccessControlSections.Owner);
            IdentityReference owner = curFilesec.GetOwner(typeof(NTAccount));
            Assert.IsTrue(curIdentity == owner);
        }
Exemple #2
0
 private string getFileOwner(string filename)
 {
     FileSecurity tmp = new FileSecurity(filename, AccessControlSections.Owner);
     string owner = "<unknown>";
     try
     {
         owner = tmp.GetOwner(System.Type.GetType("System.Security.Principal.SecurityIdentifier")).Value;
     }
     catch { }
     return owner;
 }