Exemplo n.º 1
0
        private void PopulateChild(Domain Domain)
        {
            Search objSearch = new Search(Domain);

            objSearch.SearchScope = SearchScope.OneLevel;
            objSearch.AddFilter(Configuration.ADSI_CLASS, CompareOperator.Is, ToString().ToString());

            ArrayList      resDomains = objSearch.GetEntries();
            DirectoryEntry entry;

            foreach (DirectoryEntry tempLoopVar_entry in resDomains)
            {
                entry = tempLoopVar_entry;
                Domain child;
                //If (Not Domain.Username Is Nothing) AndAlso (Not Domain.Password Is Nothing) Then
                //    child = ADSI.Domain.GetDomain(entry.Path, Domain.Username, Domain.Password, Domain.AuthenticationType)
                //Else
                child = GetDomain(entry.Path);
                //End If

                if (child != null)
                {
                    child.ParentDomain = Domain;
                    child.Level        = Domain.Level + 1;
                    // Add this child into childDomains collection
                    Domain.ChildDomains.Add(child);
                    // add this child and all it's child into allchilddomains collection
                    Domain.AllChildDomains.Add(child);
                    Domain.AllChildDomains.AddRange(child.AllChildDomains);
                }
            }
        }
Exemplo n.º 2
0
        private void PopulateChild( Domain Domain )
        {
            Search objSearch = new Search( Domain );

            objSearch.SearchScope = SearchScope.OneLevel;
            objSearch.AddFilter( Configuration.ADSI_CLASS, CompareOperator.Is, ToString().ToString() );

            ArrayList resDomains = objSearch.GetEntries();
            DirectoryEntry entry;

            foreach( DirectoryEntry tempLoopVar_entry in resDomains )
            {
                entry = tempLoopVar_entry;
                Domain child;
                //If (Not Domain.Username Is Nothing) AndAlso (Not Domain.Password Is Nothing) Then
                //    child = ADSI.Domain.GetDomain(entry.Path, Domain.Username, Domain.Password, Domain.AuthenticationType)
                //Else
                child = GetDomain( entry.Path );
                //End If

                if( child != null )
                {
                    child.ParentDomain = Domain;
                    child.Level = Domain.Level + 1;
                    // Add this child into childDomains collection
                    Domain.ChildDomains.Add( child );
                    // add this child and all it's child into allchilddomains collection
                    Domain.AllChildDomains.Add( child );
                    Domain.AllChildDomains.AddRange( child.AllChildDomains );
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// </summary>
        /// <remarks>
        ///     in multiple domains network that search result return more than one group with the same name (i.e Administrators)
        /// </remarks>
        /// <history>
        ///     [tamttt]	08/01/2004	Created
        /// </history>
        public static ArrayList GetGroupEntriesByName(string GroupName)
        {
            Domain RootDomain = GetRootDomain();
            Search objSearch  = new Search(RootDomain);

            objSearch.AddFilter(Configuration.ADSI_CLASS, CompareOperator.Is, ObjectClass.group.ToString());
            objSearch.AddFilter(Configuration.ADSI_ACCOUNTNAME, CompareOperator.Is, GroupName);

            ArrayList groupEntries = objSearch.GetEntries();

            if (groupEntries != null)
            {
                return(groupEntries);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        ///     Obtain user from Windows Active Directory using LogonName format - NETBIOSNAME\USERNAME
        /// </summary>
        /// <remarks>
        ///     -In multiple domains network, search result might return more than one user with the same name
        ///     -Additional steps to check by domain name to get correct user
        /// </remarks>
        public static DirectoryEntry GetUserEntryByName(string Name)
        {
            Search objSearch = new Search(GetRootDomain());

            objSearch.AddFilter("objectClass", CompareOperator.Is, ObjectClass.person.ToString());
            objSearch.AddFilter("sAMAccountName", CompareOperator.Is, TrimUserDomainName(Name));
            ArrayList userEntries = objSearch.GetEntries();

            switch (userEntries.Count)
            {
            case 0:
            {
                return(null);
            }

            case 1:
            {
                return((DirectoryEntry)userEntries[0]);
            }
            }
            Domain userDomain = GetDomainByBIOSName(GetUserDomainName(Name));

            if (userDomain == null)
            {
                return((DirectoryEntry)userEntries[0]);
            }
            foreach (DirectoryEntry userEntry in userEntries)
            {
                string entryPath     = userEntry.Path;
                string entryLocation = entryPath.Substring(entryPath.Length - entryPath.Length - entryPath.IndexOf("DC="), entryPath.Length - entryPath.IndexOf("DC="));
                if (entryLocation.ToLower() == userDomain.DistinguishedName.ToLower())
                {
                    return(userEntry);
                }
            }
            objSearch = null;
            return(null);
        }
Exemplo n.º 5
0
        /// <summary>
        ///     Obtain user from Windows Active Directory using LogonName format - NETBIOSNAME\USERNAME
        /// </summary>
        /// <remarks>
        ///     -In multiple domains network, search result might return more than one user with the same name
        ///     -Additional steps to check by domain name to get correct user
        /// </remarks>               
        public static DirectoryEntry GetUserEntryByName( string Name )
        {
            Search objSearch = new Search( GetRootDomain() );

            objSearch.AddFilter( "objectClass", CompareOperator.Is, ObjectClass.person.ToString() );
            objSearch.AddFilter( "sAMAccountName", CompareOperator.Is, TrimUserDomainName( Name ) );
            ArrayList userEntries = objSearch.GetEntries();
            switch( userEntries.Count )
            {
                case 0:
                    {
                        return null;
                    }
                case 1:
                    {
                        return ( (DirectoryEntry)userEntries[0] );
                    }
            }
            Domain userDomain = GetDomainByBIOSName( GetUserDomainName( Name ) );
            if( userDomain == null )
            {
                return ( (DirectoryEntry)userEntries[0] );
            }
            foreach( DirectoryEntry userEntry in userEntries )
            {
                string entryPath = userEntry.Path;
                string entryLocation = entryPath.Substring( entryPath.Length - entryPath.Length - entryPath.IndexOf( "DC=" ), entryPath.Length - entryPath.IndexOf( "DC=" ) );
                if( entryLocation.ToLower() == userDomain.DistinguishedName.ToLower() )
                {
                    return userEntry;
                }
            }
            objSearch = null;
            return null;
        }
Exemplo n.º 6
0
        /// <summary>
        /// </summary>
        /// <remarks>
        ///     in multiple domains network that search result return more than one group with the same name (i.e Administrators)
        /// </remarks>
        /// <history>
        ///     [tamttt]	08/01/2004	Created
        /// </history>
        public static ArrayList GetGroupEntriesByName( string GroupName )
        {
            Domain RootDomain = GetRootDomain();
            Search objSearch = new Search( RootDomain );

            objSearch.AddFilter( Configuration.ADSI_CLASS, CompareOperator.Is, ObjectClass.group.ToString() );
            objSearch.AddFilter( Configuration.ADSI_ACCOUNTNAME, CompareOperator.Is, GroupName );

            ArrayList groupEntries = objSearch.GetEntries();

            if( groupEntries != null )
            {
                return groupEntries;
            }
            else
            {
                return null;
            }
        }