28 Kasım 2017 Salı

DirectorySecurity Sınıfı

Constructor
Örnek
Şöyle yaparız.
DirectorySecurity secInfo = Directory.GetAccessControl(path);
Örnek
Şöyle yaparız.
DirectoryInfo directoryInfo = new DirectoryInfo(...);
DirectorySecurity dirSecurity = directoryInfo.GetAccessControl();
GetAccessRules metodu
Şöyle yaparız.
var sids = new[]
{
  "S-1-5-21-448539723-725345543-1417001333-1111111",
  "S-1-5-21-448539723-725345543-1417001333-2222222",
  "S-1-5-21-448539723-725345543-1417001333-3333333"
};

var ok = Directory.GetAccessControl(path)
  .GetAccessRules(true, false, typeof(SecurityIdentifier))
  .OfType<FileSystemAccessRule>()
  .Any(f => f.IdentityReference.Value == sids[i]);
ResetAccessRule metodu
Şöyle yaparız.
var fileSystemAccessRule = new FileSystemAccessRule(new SecurityIdentifier(sid), 
  FileSystemRights.Modify | FileSystemRights.Synchronize,
  InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
  PropagationFlags.None,
  AccessControlType.Allow);

var directorySecurity = Directory.GetAccessControl(path);
directorySecurity.ResetAccessRule(fileSystemAccessRule);
Directory.SetAccessControl(path, directorySecurity);

Hiç yorum yok:

Yorum Gönder