예제 #1
0
        private bool BuildSchemaCache(bool usingSimpleBind)
        {
            if (_adContext == null)
            {
                return(false);
            }

            _adContext.SchemaCache = LDAPSchemaCache.Build(_adContext);
            _schemaCache           = _adContext.SchemaCache;
            DirectoryEntry.exisitngDirContext.Add(_adContext);
            DirectoryEntry.existingSchemaCache.Add(_schemaCache);

            string sldapPath = string.Concat("LDAP://", _hn.domainName, "/", rootDN);

            ADUCDirectoryNode rootNode = ADUCDirectoryNode.GetDirectoryRoot(
                _adContext,
                _rootDN,
                Resources.ADUC,
                typeof(ADUCPage),
                _plugin);

            if (rootNode == null)
            {
                Logger.Log("The rootNode is null");
                return(false);
            }

            _rootNode = rootNode;

            _shortDomainName = UserGroupUtils.getnetBiosName(rootNode);

            Logger.Log(
                "the obtained NetbiosName is " + _shortDomainName,
                Logger.ldapLogLevel);

            return(true);
        }
예제 #2
0
        private DirectoryContext Assign_dirContext()
        {
            if (dirContext == null)
            {
                if (sProtocol.Equals("GC", StringComparison.InvariantCultureIgnoreCase))
                {
                    if (!findDircontext(GC_PORT))
                    {
                        //Console.WriteLine("****************Creating GC directoryContext*******************");

                        if (findGCServer() != null)
                        {
                            sServer = findGCServer();
                        }

                        string errorMessage = null;

                        dirContext = DirectoryContext.CreateDirectoryContext(
                            sServer,
                            rootDN,
                            this.sUsername,
                            this.sPassword,
                            GC_PORT,
                            findBindingMethod(),
                            out errorMessage);

                        if (dirContext != null)
                        {
                            //Console.WriteLine("-------------Global catalog DirectoryContext is created.--------------------");
                            exisitngDirContext.Add(dirContext);
                            if (!FindSchemaCache())
                            {
                                dirContext.SchemaCache = LDAPSchemaCache.Build(dirContext);
                                existingSchemaCache.Add(dirContext.SchemaCache);
                            }
                        }
                    }
                }
                else if (sProtocol.Equals("LDAP", StringComparison.InvariantCultureIgnoreCase))
                {
                    if (!findDircontext(LDAP_PORT))
                    {
                        string errorMessage = null;

                        //Console.WriteLine("****************Creating Normal Ldap directoryContext*******************");
                        dirContext = DirectoryContext.CreateDirectoryContext(
                            sServer,
                            rootDN,
                            this.sUsername,
                            this.sPassword,
                            LDAP_PORT,
                            findBindingMethod(),
                            out errorMessage);

                        if (dirContext != null)
                        {
                            //Console.WriteLine("-------------------Normal LDAP DirectoryContext is created.--------------------");
                            exisitngDirContext.Add(dirContext);
                            //Console.WriteLine("dircontext portnumber is " + dirContext.PortNumber + dirContext.LdapHandle);
                            if (!FindSchemaCache())
                            {
                                dirContext.SchemaCache = LDAPSchemaCache.Build(dirContext);
                                existingSchemaCache.Add(dirContext.SchemaCache);
                            }
                        }
                    }
                }
            }

            if (dirContext == null)
            {
                throw new Exception("Create DirectoryContext Failed - logon failure: Unknown Username or Bad password.");
            }
            else
            {
                return(dirContext);
            }
        }