Example #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 );
                }
            }
        }
Example #2
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 GetUserEntryByCName0( string CName, Domain RootDomain )
        {
            Search objSearch = new Search( RootDomain );

            objSearch.AddFilter( "objectClass", CompareOperator.Is, ObjectClass.person.ToString() );
            objSearch.AddFilter( "cn", CompareOperator.Is, TrimUserDomainName( CName ) );
            ArrayList userEntries = objSearch.GetEntries();
            switch( userEntries.Count )
            {
                case 0:
                    {
                        return null;
                    }
                case 1:
                    {
                        return ( (DirectoryEntry)userEntries[0] );
                    }
            }
            Domain userDomain = GetDomainByBIOSName( GetUserDomainName( CName ) );
            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 = ( (Search)null );
            return null;
        }
Example #3
0
        /// <summary>
        /// </summary>
        /// <remarks>
        /// Accessing ADs costs lots of resource so we better put ADs object into app cache
        /// </remarks>
        public static Domain GetDomain( string Path, string UserName, string Password, AuthenticationTypes AuthenticationType )
        {
            Domain Domain = (Domain)DataCache.GetCache( Path );
            if( Domain == null )
            {
                if( ( UserName.Length > 0 ) && ( Password.Length > 0 ) )
                {
                    Domain = new Domain( Path, UserName, Password, AuthenticationType );
                }
                else
                {
                    Domain = new Domain( Path );
                }

                DataCache.SetCache( Path, Domain );
            }

            return Domain;
        }
Example #4
0
        /// <summary>
        ///     Obtain user from Windows Active Directory using UPN format - USERNAME@DOMAIN
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <history>
        ///     [tamttt]	08/01/2004	Created
        /// </history>
        public static DirectoryEntry GetUserByUPN0( string Name, Domain RootDomain )
        {
            // Create search object then assign required params to get user entry in Active Directory
            Search objSearch = new Search( RootDomain );
            DirectoryEntry userEntry;

            // UPN is unique in entire Windows network
            objSearch.AddFilter( Configuration.ADSI_CLASS, CompareOperator.Is, ObjectClass.person.ToString() );
            objSearch.AddFilter( Configuration.ADSI_UPN, CompareOperator.Is, Name );
            userEntry = objSearch.GetEntry();

            return userEntry;
        }