Example #1
0
        private void ShowAllProperties(DirectoryEntry directoryEntry)
        {
            lstResults.Items.Add("Directory Entry Properties for Object \"" + directoryEntry.Name + "\" of class \"" + directoryEntry.SchemaClassName + "\"");

            foreach (string propertyName in directoryEntry.Properties.PropertyNames)
            {
                lstResults.Items.Add("    " + propertyName + "=" + directoryEntry.Properties[propertyName]);

                CaseIgnoringSortedSetType propertyValueSet = new CaseIgnoringSortedSetType();

                propertyValueSet = AttributeValuesMultiString(propertyName, directoryEntry, propertyValueSet);

                foreach (string propertyValue in propertyValueSet)
                {
                    string valueString = "            " + propertyName + "=" + propertyValue;
                    lstResults.Items.Add(valueString);
                }
            }
        }
Example #2
0
        private void ShowNetworkUsersForGroup(string groupName)
        {
            SearchResultCollection groupSearchResultCollection = SearchResultCollectionFindAll("(&(cn=" + groupName + ")(ObjectClass=group))");

            if (groupSearchResultCollection != null)
            {
                // The search returned at least one result

                foreach (SearchResult groupSearchResult in groupSearchResultCollection)
                {
                    DirectoryEntry groupDirectoryEntry = groupSearchResult.GetDirectoryEntry();

                    lstResults.Items.Add("Network Users for Group \"" + groupDirectoryEntry.Name + "\" of class \"" + groupDirectoryEntry.SchemaClassName + "\"");

                    CaseIgnoringSortedSetType groupUsers = NetworkUsersInGroup(groupDirectoryEntry.Path, true);
                    foreach (string groupUserName in groupUsers)
                    {
                        lstResults.Items.Add("    \"" + groupUserName + "\"");
                    }
                }
            }
        }
Example #3
0
        private void ShowNetworkGroupsForUser(string userName)
        {
            SearchResultCollection userSearchResultCollection = SearchResultCollectionFindAll("(&(SAMAccountName=" + userName + ")(ObjectClass=user))");

            if (userSearchResultCollection != null)
            {
                // The search returned at least one result

                foreach (SearchResult userSearchResult in userSearchResultCollection)
                {
                    DirectoryEntry userDirectoryEntry = userSearchResult.GetDirectoryEntry();

                    lstResults.Items.Add("Network Groups for User \"" + userDirectoryEntry.Name + "\" of class \"" + userDirectoryEntry.SchemaClassName + "\"");

                    CaseIgnoringSortedSetType userGroups = NetworkGroupsForUser(userDirectoryEntry.Path, true);
                    foreach (string groupName in userGroups)
                    {
                        lstResults.Items.Add("    \"" + groupName + "\"");
                    }
                }
            } // The search returned at least one result
        }
Example #4
0
        private bool UserIsNetworkGroupMember(string userName, string groupName)
        {
            bool userIsNetworkGroupMember = false;

            try
            {
                // Get thje Group's Distinguished Name
                string groupDistinguishedName = DistinguishedNameFromCommonName(groupName);

                SearchResult userSearchResult = SearchResultCollectionFindOne("(&(SAMAccountName=" + userName + ")(ObjectClass=user))");
                if (userSearchResult != null)
                {
                    // Search returned a result
                    CaseIgnoringSortedSetType userGroupCollection = NetworkGroupsForUser(userSearchResult.GetDirectoryEntry().Path, true);
                    userIsNetworkGroupMember = userGroupCollection.Contains(groupDistinguishedName);
                } // Search returned a result
            }
            catch (Exception eek)
            {
            }

            return(userIsNetworkGroupMember);
        }
Example #5
0
        // Recursive
        private CaseIgnoringSortedSetType AttributeValuesMultiString(string attributeName, DirectoryEntry objectEntry, CaseIgnoringSortedSetType valuesCollection, bool recursive)
        {
            PropertyValueCollection ValueCollection = objectEntry.Properties[attributeName];
            IEnumerator             enumerator      = ValueCollection.GetEnumerator();

            while (enumerator.MoveNext())
            {
                if (enumerator.Current != null)
                {
                    if (!valuesCollection.Contains(enumerator.Current.ToString()))
                    {
                        valuesCollection.Add(enumerator.Current.ToString());
                        if (recursive)
                        {
                            AttributeValuesMultiString(attributeName, LdapPrefix + enumerator.Current.ToString(), valuesCollection, true);
                        }
                    }
                }
            }
            return(valuesCollection);
        }
Example #6
0
 // Non-recursive
 private CaseIgnoringSortedSetType AttributeValuesMultiString(string attributeName, DirectoryEntry objectEntry, CaseIgnoringSortedSetType valuesCollection)
 {
     return(AttributeValuesMultiString(attributeName, objectEntry, valuesCollection, false));
 }
Example #7
0
        private CaseIgnoringSortedSetType AttributeValuesMultiString(string attributeName, string objectDistinguishedName, CaseIgnoringSortedSetType valuesCollection, bool recursive)
        {
            DirectoryEntry objectEntry = new DirectoryEntry(objectDistinguishedName);

            valuesCollection = AttributeValuesMultiString(attributeName, objectEntry, valuesCollection, recursive);

            objectEntry.Close();
            objectEntry.Dispose();

            return(valuesCollection);
        }
Example #8
0
        private CaseIgnoringSortedSetType ComputerSharedVolumes(string computerDistinguishedName, bool recursive)
        {
            CaseIgnoringSortedSetType volumes = new CaseIgnoringSortedSetType();

            return(AttributeValuesMultiString("volumeCount", computerDistinguishedName, volumes, true));
        }
Example #9
0
        private CaseIgnoringSortedSetType NetworkUsersInGroup(string groupDistinguishedName, bool recursive)
        {
            CaseIgnoringSortedSetType userMemberships = new CaseIgnoringSortedSetType();

            return(AttributeValuesMultiString("member", groupDistinguishedName, userMemberships, recursive));
        }
Example #10
0
        private CaseIgnoringSortedSetType NetworkGroupsForUser(string userDistinguishedName, bool recursive)
        {
            CaseIgnoringSortedSetType groupMemberships = new CaseIgnoringSortedSetType();

            return(AttributeValuesMultiString("memberOf", userDistinguishedName, groupMemberships, recursive));
        }
Example #11
0
 // Construct and copy from another set
 public CaseIgnoringSortedSetType(CaseIgnoringSortedSetType existingSet)
     : base(existingSet, StringComparer.CurrentCultureIgnoreCase)
 {
 }