2010-05-10 12 views

Odpowiedz

1

można skorzystać z następującego kodu:

DirectorySecurity security = directoryInfo.GetAccessControl(); 
AuthorizationRuleCollection authCollection = security.GetAccessRules(true, true, typeof(System.Security.Principal.NTAccount)); 

var username = (from FileSystemAccessRule rule in authCollection 
       where rule.IdentityReference.Value == "domain\\username" 
       select rule).ToList(); 
+0

Jeden problem, jaki mogę sobie wyobrazić, polega na tym, że konta w regułach dostępu mogą być grupami, więc musisz ustalić, czy dany użytkownik należy do jednej lub więcej grup. –

+0

To jest dokładnie problem. Ten kod nie uwzględnia grup użytkowników. Aby to zrobić, potrzebuję WindowsIdentity (o ile wiem). – Zvika

0

Co jeśli wziąć podejście odwrotne? Jeśli użytkownik nie ma dostępu (poprzez nazwę użytkownika) można uzyskać członkostwa w grupie i sprawdzić ich dostęp ...

private StringCollection GetUserGroupMembership(string strUser) 
{ 
    StringCollection groups = new StringCollection(); 
    try 
    { 
     DirectoryEntry obEntry = new DirectoryEntry(
      "LDAP://CN=users,DC=example,DC=com"); 
     DirectorySearcher srch = new DirectorySearcher(obEntry, 
      "(sAMAccountName=" + strUser + ")"); 
     SearchResult res = srch.FindOne(); 
     if (null != res) 
     { 
      DirectoryEntry obUser = new DirectoryEntry(res.Path); 
      // Invoke Groups method. 
      object obGroups = obUser.Invoke("Groups"); 
      foreach (object ob in (IEnumerable)obGroups) 
      { 
       // Create object for each group. 
       DirectoryEntry obGpEntry = new DirectoryEntry(ob); 
       groups.Add(obGpEntry.Name); 
      } 
     } 
    } 
    catch (Exception ex) 
    { 
     Trace.Write(ex.Message); 
    } 
    return groups; 
} 

Od http://www.codeproject.com/KB/dotnet/usergroupmembership.aspx

Teraz masz grupy, można to zrobić na sprzężenia elementy zwrócone z kataloguInfo i zobacz, czy którakolwiek z grup użytkowników ma dostęp do katalogu.

HTH

+0

To nie działa dla kont komputerów lokalnych. – Zvika

0

Czy masz szansę na sprawdzenie członkostwa w grupie, wykonując ifmember.exe i testując poziomy błędów? (Ifmember jest również w zestawie 2003 Resource)

Również zaledwie heads-up, to nie może być wykonane solidnie bez faktycznie zalogowaniu użytkownikowi.

Per http://technet.microsoft.com/en-us/library/cc772184.aspx

„Skuteczny Uprawnienia narzędzie tylko produkuje przybliżenie uprawnieniami że użytkownik ma. w rzeczywiste uprawnienia użytkownik ma być inny ponieważ uprawnienia mogą być przyznane lub odmówiono oparte na jak użytkownik loguje się. Ta specyficzna dla logistyki informacja nie może być określona za pomocą narzędzia Skuteczne uprawnienia, jeśli użytkownik nie jest zalogowany; dlatego też skuteczne uprawnienia wyświetlają odzwierciedlają tylko te uprawnienia określone przez użytkownika lub grupę, a nie uprawnień określonych przez logowanie .

Na przykład, jeśli użytkownik jest podłączony do komputera za pośrednictwem tego folderu udostępnionego, wtedy logowania dla tego użytkownika jest oznaczony jako logowania do sieci. Uprawnienia mogą być przyznane lub odrzucone dla dobrze znanego identyfikatora SID sieci , który otrzymuje podłączony użytkownik , więc użytkownik ma różne uprawnienia po zalogowaniu się lokalnie niż po zalogowaniu się w sieci."

2

Całe Problematyka coraz skuteczne uprawnienia do jakiegoś folderu lub pliku jest dość skomplikowana. Ale nie trzeba się WindowsIdentity z nazwy użytkownika i nazwy domeny. Do czytania skuteczne uprawnienia wystarczy mieć SID . użytkownik podczas sprawdzania

Istnieje klasa NTaccount który trwa dokładnie to, co trzeba. - nazwę i domenę, która może być łatwo przetłumaczony na Security Identifier, co stanowi dokładnie jedną SID

Istnieje klas można znaleźć w Przestrzeń nazw System.Security.Principal

NTAccount ntaccount = new NTAccount("domain", "username"); 
SecurityIdentifier identifier = 
    (SecurityIdentifier)ntaccount.Translate(typeof(SecurityIdentifier)); 

W ten sposób można przetłumaczyć nazwę użytkownika (z domeną lub bez niej) do identyfikatora SID, który można następnie wykorzystać do określenia, do których grup należy ten użytkownik (rekursywnie), a następnie można łatwo odczytać prawa dostępu przy użyciu klasy FileSecurity (z FileInfo) i jego metody GetAccessRules.

-1

Oto kod, który włamałem się do pracy z domeną \ użytkownik (pierwotnie z codeproject). Porzuciłem go jako "wadliwy" (po prostu nie lubiłem próbować ponownie wprowadzić kontroli, że tylko system operacyjny naprawdę zna odpowiedź). Nie przypominam sobie też, żebym doszła do jakiegoś poważnego testu. Jestem pewien, że nie obsługuje jawnych praw przyznanych użytkownikowi (a nie grupie) i nie byłem pewien, czy kod obsługuje odmowę praw.

class UserAccessRights 
{ 

    /// /// This code was written by Bruce Hatt 
    /// Code obtained from : http://www.codeproject.com/useritems/UserFileAccessRights.asp 
    /// 
    /// This class Contains a simple answer to a 
    /// potentially complicated question "Can I read this file or can I write to this file?" 
    /// 
    /// Using the "rule of least privilege", one must check not only is access granted but 
    /// is it denied at any point including a possibly recursive check of groups. 
    /// 
    /// For this simple check, a look at the user and immediate groups are only checked. 
    /// 
    /// This class could be expanded to identify if the applicable allow/deny rule 
    /// was explicit or inherited 
    /// 

    private string _path; 
    //private WindowsIdentity _principal; 
    private SecurityIdentifier _principalSid; 

    private bool _denyAppendData = false; 
    private bool _denyChangePermissions = false; 
    private bool _denyCreateDirectories = false; 
    private bool _denyCreateFiles = false; 
    private bool _denyDelete = false; 
    private bool _denyDeleteSubdirectoriesAndFiles = false; 
    private bool _denyExecuteFile = false; 
    private bool _denyFullControl = false; 
    private bool _denyListDirectory = false; 
    private bool _denyModify = false; 
    private bool _denyRead = false; 
    private bool _denyReadAndExecute = false; 
    private bool _denyReadAttributes = false; 
    private bool _denyReadData = false; 
    private bool _denyReadExtendedAttributes = false; 
    private bool _denyReadPermissions = false; 
    private bool _denySynchronize = false; 
    private bool _denyTakeOwnership = false; 
    private bool _denyTraverse = false; 
    private bool _denyWrite = false; 
    private bool _denyWriteAttributes = false; 
    private bool _denyWriteData = false; 
    private bool _denyWriteExtendedAttributes = false; 


    private bool _allowAppendData = false; 
    private bool _allowChangePermissions = false; 
    private bool _allowCreateDirectories = false; 
    private bool _allowCreateFiles = false; 
    private bool _allowDelete = false; 
    private bool _allowDeleteSubdirectoriesAndFiles = false; 
    private bool _allowExecuteFile = false; 
    private bool _allowFullControl = false; 
    private bool _allowListDirectory = false; 
    private bool _allowModify = false; 
    private bool _allowRead = false; 
    private bool _allowReadAndExecute = false; 
    private bool _allowReadAttributes = false; 
    private bool _allowReadData = false; 
    private bool _allowReadExtendedAttributes = false; 
    private bool _allowReadPermissions = false; 
    private bool _allowSynchronize = false; 
    private bool _allowTakeOwnership = false; 
    private bool _allowTraverse = false; 
    private bool _allowWrite = false; 
    private bool _allowWriteAttributes = false; 
    private bool _allowWriteData = false; 
    private bool _allowWriteExtendedAttributes = false; 


    public bool CanAppendData { get { return !_denyAppendData && _allowAppendData; } } 
    public bool CanChangePermissions { get { return !_denyChangePermissions && _allowChangePermissions; } } 
    public bool CanCreateDirectories { get { return !_denyCreateDirectories && _allowCreateDirectories; } } 
    public bool CanCreateFiles { get { return !_denyCreateFiles && _allowCreateFiles; } } 
    public bool CanDelete { get { return !_denyDelete && _allowDelete; } } 
    public bool CanDeleteSubdirectoriesAndFiles { get { return !_denyDeleteSubdirectoriesAndFiles && _allowDeleteSubdirectoriesAndFiles; } } 
    public bool CanExecuteFile { get { return !_denyExecuteFile && _allowExecuteFile; } } 
    public bool CanFullControl { get { return !_denyFullControl && _allowFullControl; } } 
    public bool CanListDirectory { get { return !_denyListDirectory && _allowListDirectory; } } 
    public bool CanModify { get { return !_denyModify && _allowModify; } } 
    public bool CanRead { get { return !_denyRead && _allowRead; } } 
    public bool CanReadAndExecute { get { return !_denyReadAndExecute && _allowReadAndExecute; } } 
    public bool CanReadAttributes { get { return !_denyReadAttributes && _allowReadAttributes; } } 
    public bool CanReadData { get { return !_denyReadData && _allowReadData; } } 
    public bool CanReadExtendedAttributes { get { return !_denyReadExtendedAttributes && _allowReadExtendedAttributes; } } 
    public bool CanReadPermissions { get { return !_denyReadPermissions && _allowReadPermissions; } } 
    public bool CanSynchronize { get { return !_denySynchronize && _allowSynchronize; } } 
    public bool CanTakeOwnership { get { return !_denyTakeOwnership && _allowTakeOwnership; } } 
    public bool CanTraverse { get { return !_denyTraverse && _allowTraverse; } } 
    public bool CanWrite { get { return !_denyWrite && _allowWrite; } } 
    public bool CanWriteAttributes { get { return !_denyWriteAttributes && _allowWriteAttributes; } } 
    public bool CanWriteData { get { return !_denyWriteData && _allowWriteData; } } 
    public bool CanWriteExtendedAttributes { get { return !_denyWriteExtendedAttributes && _allowWriteExtendedAttributes; } } 


    /// /// Simple accessor 
/*  public WindowsIdentity GetWindowsIdentity 
    { 
     get { return _principal; } 
    }*/ 

    /// /// Simple accessor 
    public String GetPath 
    { 
     get { return _path; } 
    } 


    public UserAccessRights(string path, string UserId) 
    { 

     if ((!String.IsNullOrEmpty(UserId)) && !String.IsNullOrEmpty(path)) 
     { 
      NTAccount n = new NTAccount(UserId); 
      _principalSid = (SecurityIdentifier)n.Translate(typeof(SecurityIdentifier)); 

      this._path = path; 

      System.IO.FileInfo fi = new System.IO.FileInfo(_path); 
      AuthorizationRuleCollection acl = fi.GetAccessControl().GetAccessRules(true, true, typeof(SecurityIdentifier)); 
      for (int i = 0; i < acl.Count; i++) 
      { 
       System.Security.AccessControl.FileSystemAccessRule rule = (System.Security.AccessControl.FileSystemAccessRule)acl[i]; 
       if (_principalSid.Equals(rule.IdentityReference)) 
       { 
        if (System.Security.AccessControl.AccessControlType.Deny.Equals(rule.AccessControlType)) 
        { 
         if (Contains(FileSystemRights.AppendData, rule)) _denyAppendData = true; 
         if (Contains(FileSystemRights.ChangePermissions, rule)) _denyChangePermissions = true; 
         if (Contains(FileSystemRights.CreateDirectories, rule)) _denyCreateDirectories = true; 
         if (Contains(FileSystemRights.CreateFiles, rule)) _denyCreateFiles = true; 
         if (Contains(FileSystemRights.Delete, rule)) _denyDelete = true; 
         if (Contains(FileSystemRights.DeleteSubdirectoriesAndFiles, rule)) _denyDeleteSubdirectoriesAndFiles = true; 
         if (Contains(FileSystemRights.ExecuteFile, rule)) _denyExecuteFile = true; 
         if (Contains(FileSystemRights.FullControl, rule)) _denyFullControl = true; 
         if (Contains(FileSystemRights.ListDirectory, rule)) _denyListDirectory = true; 
         if (Contains(FileSystemRights.Modify, rule)) _denyModify = true; 
         if (Contains(FileSystemRights.Read, rule)) _denyRead = true; 
         if (Contains(FileSystemRights.ReadAndExecute, rule)) _denyReadAndExecute = true; 
         if (Contains(FileSystemRights.ReadAttributes, rule)) _denyReadAttributes = true; 
         if (Contains(FileSystemRights.ReadData, rule)) _denyReadData = true; 
         if (Contains(FileSystemRights.ReadExtendedAttributes, rule)) _denyReadExtendedAttributes = true; 
         if (Contains(FileSystemRights.ReadPermissions, rule)) _denyReadPermissions = true; 
         if (Contains(FileSystemRights.Synchronize, rule)) _denySynchronize = true; 
         if (Contains(FileSystemRights.TakeOwnership, rule)) _denyTakeOwnership = true; 
         if (Contains(FileSystemRights.Traverse, rule)) _denyTraverse = true; 
         if (Contains(FileSystemRights.Write, rule)) _denyWrite = true; 
         if (Contains(FileSystemRights.WriteAttributes, rule)) _denyWriteAttributes = true; 
         if (Contains(FileSystemRights.WriteData, rule)) _denyWriteData = true; 
         if (Contains(FileSystemRights.WriteExtendedAttributes, rule)) _denyWriteExtendedAttributes = true; 
        } 
        else if (System.Security.AccessControl.AccessControlType.Allow.Equals(rule.AccessControlType)) 
        { 
         if (Contains(FileSystemRights.AppendData, rule)) _allowAppendData = true; 
         if (Contains(FileSystemRights.ChangePermissions, rule)) _allowChangePermissions = true; 
         if (Contains(FileSystemRights.CreateDirectories, rule)) _allowCreateDirectories = true; 
         if (Contains(FileSystemRights.CreateFiles, rule)) _allowCreateFiles = true; 
         if (Contains(FileSystemRights.Delete, rule)) _allowDelete = true; 
         if (Contains(FileSystemRights.DeleteSubdirectoriesAndFiles, rule)) _allowDeleteSubdirectoriesAndFiles = true; 
         if (Contains(FileSystemRights.ExecuteFile, rule)) _allowExecuteFile = true; 
         if (Contains(FileSystemRights.FullControl, rule)) _allowFullControl = true; 
         if (Contains(FileSystemRights.ListDirectory, rule)) _allowListDirectory = true; 
         if (Contains(FileSystemRights.Modify, rule)) _allowModify = true; 
         if (Contains(FileSystemRights.Read, rule)) _allowRead = true; 
         if (Contains(FileSystemRights.ReadAndExecute, rule)) _allowReadAndExecute = true; 
         if (Contains(FileSystemRights.ReadAttributes, rule)) _allowReadAttributes = true; 
         if (Contains(FileSystemRights.ReadData, rule)) _allowReadData = true; 
         if (Contains(FileSystemRights.ReadExtendedAttributes, rule)) _allowReadExtendedAttributes = true; 
         if (Contains(FileSystemRights.ReadPermissions, rule)) _allowReadPermissions = true; 
         if (Contains(FileSystemRights.Synchronize, rule)) _allowSynchronize = true; 
         if (Contains(FileSystemRights.TakeOwnership, rule)) _allowTakeOwnership = true; 
         if (Contains(FileSystemRights.Traverse, rule)) _allowTraverse = true; 
         if (Contains(FileSystemRights.Write, rule)) _allowWrite = true; 
         if (Contains(FileSystemRights.WriteAttributes, rule)) _allowWriteAttributes = true; 
         if (Contains(FileSystemRights.WriteData, rule)) _allowWriteData = true; 
         if (Contains(FileSystemRights.WriteExtendedAttributes, rule)) _allowWriteExtendedAttributes = true; 
        } 
       } 
      } 
      /* 
      IdentityReferenceCollection groups = _principal.Groups; 
      for (int j = 0; j < groups.Count; j++) 
      { 
       for (int i = 0; i < acl.Count; i++) 
       { 
        System.Security.AccessControl.FileSystemAccessRule rule = (System.Security.AccessControl.FileSystemAccessRule)acl[i]; 
        if (groups[j].Equals(rule.IdentityReference)) 
        { 
         if (System.Security.AccessControl.AccessControlType.Deny.Equals(rule.AccessControlType)) 
         { 
          if (Contains(FileSystemRights.AppendData, rule)) _denyAppendData = true; 
          if (Contains(FileSystemRights.ChangePermissions, rule)) _denyChangePermissions = true; 
          if (Contains(FileSystemRights.CreateDirectories, rule)) _denyCreateDirectories = true; 
          if (Contains(FileSystemRights.CreateFiles, rule)) _denyCreateFiles = true; 
          if (Contains(FileSystemRights.Delete, rule)) _denyDelete = true; 
          if (Contains(FileSystemRights.DeleteSubdirectoriesAndFiles, rule)) _denyDeleteSubdirectoriesAndFiles = true; 
          if (Contains(FileSystemRights.ExecuteFile, rule)) _denyExecuteFile = true; 
          if (Contains(FileSystemRights.FullControl, rule)) _denyFullControl = true; 
          if (Contains(FileSystemRights.ListDirectory, rule)) _denyListDirectory = true; 
          if (Contains(FileSystemRights.Modify, rule)) _denyModify = true; 
          if (Contains(FileSystemRights.Read, rule)) _denyRead = true; 
          if (Contains(FileSystemRights.ReadAndExecute, rule)) _denyReadAndExecute = true; 
          if (Contains(FileSystemRights.ReadAttributes, rule)) _denyReadAttributes = true; 
          if (Contains(FileSystemRights.ReadData, rule)) _denyReadData = true; 
          if (Contains(FileSystemRights.ReadExtendedAttributes, rule)) _denyReadExtendedAttributes = true; 
          if (Contains(FileSystemRights.ReadPermissions, rule)) _denyReadPermissions = true; 
          if (Contains(FileSystemRights.Synchronize, rule)) _denySynchronize = true; 
          if (Contains(FileSystemRights.TakeOwnership, rule)) _denyTakeOwnership = true; 
          if (Contains(FileSystemRights.Traverse, rule)) _denyTraverse = true; 
          if (Contains(FileSystemRights.Write, rule)) _denyWrite = true; 
          if (Contains(FileSystemRights.WriteAttributes, rule)) _denyWriteAttributes = true; 
          if (Contains(FileSystemRights.WriteData, rule)) _denyWriteData = true; 
          if (Contains(FileSystemRights.WriteExtendedAttributes, rule)) _denyWriteExtendedAttributes = true; 
         } 
         else if (System.Security.AccessControl.AccessControlType.Allow.Equals(rule.AccessControlType)) 
         { 
          if (Contains(FileSystemRights.AppendData, rule)) _allowAppendData = true; 
          if (Contains(FileSystemRights.ChangePermissions, rule)) _allowChangePermissions = true; 
          if (Contains(FileSystemRights.CreateDirectories, rule)) _allowCreateDirectories = true; 
          if (Contains(FileSystemRights.CreateFiles, rule)) _allowCreateFiles = true; 
          if (Contains(FileSystemRights.Delete, rule)) _allowDelete = true; 
          if (Contains(FileSystemRights.DeleteSubdirectoriesAndFiles, rule)) _allowDeleteSubdirectoriesAndFiles = true; 
          if (Contains(FileSystemRights.ExecuteFile, rule)) _allowExecuteFile = true; 
          if (Contains(FileSystemRights.FullControl, rule)) _allowFullControl = true; 
          if (Contains(FileSystemRights.ListDirectory, rule)) _allowListDirectory = true; 
          if (Contains(FileSystemRights.Modify, rule)) _allowModify = true; 
          if (Contains(FileSystemRights.Read, rule)) _allowRead = true; 
          if (Contains(FileSystemRights.ReadAndExecute, rule)) _allowReadAndExecute = true; 
          if (Contains(FileSystemRights.ReadAttributes, rule)) _allowReadAttributes = true; 
          if (Contains(FileSystemRights.ReadData, rule)) _allowReadData = true; 
          if (Contains(FileSystemRights.ReadExtendedAttributes, rule)) _allowReadExtendedAttributes = true; 
          if (Contains(FileSystemRights.ReadPermissions, rule)) _allowReadPermissions = true; 
          if (Contains(FileSystemRights.Synchronize, rule)) _allowSynchronize = true; 
          if (Contains(FileSystemRights.TakeOwnership, rule)) _allowTakeOwnership = true; 
          if (Contains(FileSystemRights.Traverse, rule)) _allowTraverse = true; 
          if (Contains(FileSystemRights.Write, rule)) _allowWrite = true; 
          if (Contains(FileSystemRights.WriteAttributes, rule)) _allowWriteAttributes = true; 
          if (Contains(FileSystemRights.WriteData, rule)) _allowWriteData = true; 
          if (Contains(FileSystemRights.WriteExtendedAttributes, rule)) _allowWriteExtendedAttributes = true; 
         } 
        } 
       } 
      } 
      */ 
     } 
    } 

    /// /// Simply displays all allowed rights 
    /// 
    /// Useful if say you want to test for write access and find 
    /// it is false; 
    /// <xmp> /// UserFileAccessRights rights = new UserFileAccessRights(txtLogPath.Text); 
    /// System.IO.FileInfo fi = new System.IO.FileInfo(txtLogPath.Text); 
    /// if (rights.canWrite() && rights.canRead()) { 
    /// lblLogMsg.Text = "R/W access"; 
    /// } else { 
    /// if (rights.canWrite()) { 
    /// lblLogMsg.Text = "Only Write access"; 
    /// } else if (rights.canRead()) { 
    /// lblLogMsg.Text = "Only Read access"; 
    /// } else { 
    /// lblLogMsg.CssClass = "error"; 
    /// lblLogMsg.Text = rights.ToString() 
    /// } 
    /// } 
    /// 
    /// </xmp> /// 
    public override String ToString() 
    { 
     StringBuilder sb = new StringBuilder(); 

     if (CanAppendData) { if (sb.Length != 0) sb.Append(","); sb.Append("AppendData"); } 
     if (CanChangePermissions) { if (sb.Length != 0) sb.Append(","); sb.Append("ChangePermissions"); } 
     if (CanCreateDirectories) { if (sb.Length != 0) sb.Append(","); sb.Append("CreateDirectories"); } 
     if (CanCreateFiles) { if (sb.Length != 0) sb.Append(","); sb.Append("CreateFiles"); } 
     if (CanDelete) { if (sb.Length != 0) sb.Append(","); sb.Append("Delete"); } 
     if (CanDeleteSubdirectoriesAndFiles) { if (sb.Length != 0) sb.Append(","); sb.Append("DeleteSubdirectoriesAndFiles"); } 
     if (CanExecuteFile) { if (sb.Length != 0) sb.Append(","); sb.Append("ExecuteFile"); } 
     if (CanFullControl) { if (sb.Length != 0) sb.Append(","); sb.Append("FullControl"); } 
     if (CanListDirectory) { if (sb.Length != 0) sb.Append(","); sb.Append("ListDirectory"); } 
     if (CanModify) { if (sb.Length != 0) sb.Append(","); sb.Append("Modify"); } 
     if (CanRead) { if (sb.Length != 0) sb.Append(","); sb.Append("Read"); } 
     if (CanReadAndExecute) { if (sb.Length != 0) sb.Append(","); sb.Append("ReadAndExecute"); } 
     if (CanReadAttributes) { if (sb.Length != 0) sb.Append(","); sb.Append("ReadAttributes"); } 
     if (CanReadData) { if (sb.Length != 0) sb.Append(","); sb.Append("ReadData"); } 
     if (CanReadExtendedAttributes) { if (sb.Length != 0) sb.Append(","); sb.Append("ReadExtendedAttributes"); } 
     if (CanReadPermissions) { if (sb.Length != 0) sb.Append(","); sb.Append("ReadPermissions"); } 
     if (CanSynchronize) { if (sb.Length != 0) sb.Append(","); sb.Append("Synchronize"); } 
     if (CanTakeOwnership) { if (sb.Length != 0) sb.Append(","); sb.Append("TakeOwnership"); } 
     if (CanTraverse) { if (sb.Length != 0) sb.Append(","); sb.Append("Traverse"); } 
     if (CanWrite) { if (sb.Length != 0) sb.Append(","); sb.Append("Write"); } 
     if (CanWriteAttributes) { if (sb.Length != 0) sb.Append(","); sb.Append("WriteAttributes"); } 
     if (CanWriteData) { if (sb.Length != 0) sb.Append(","); sb.Append("WriteData"); } 
     if (CanWriteExtendedAttributes) { if (sb.Length != 0) sb.Append(","); sb.Append("WriteExtendedAttributes"); } 

     if (sb.Length == 0) 
      sb.Append("None"); 

     return sb.ToString(); 
    } 

    /// /// Convenience method to test if the right exists within the given rights 
    public static bool Contains(FileSystemRights right, FileSystemAccessRule rule) 
    { 
     bool returnValue = false; 
     if (rule != null) 
     { 
      returnValue = (((int)right & (int)rule.FileSystemRights) == (int)right); 
     } 
     return returnValue; 
    } 

} 
+0

Możesz dodać ciągi do listy i 'String.Join (", ", list); na końcu – abatishchev

+0

@abatishchev: To nie jest mój kod źródłowy (patrz komentarz w codeproject). Po prostu szybko zmodyfikuję go tak, aby akceptował domenę użytkownika (zamiast zabezpieczenia). Nawet tego nie potwierdzam ... po prostu dzielę się swoimi brodawkami :) – user53794

Powiązane problemy