コード例 #1
0
    /// <summary>
    /// Will be called when we click on 'Set Target Machine Info' menu item and if plugin is already connected to domain
    /// Will gets all nodes along with its childs
    /// </summary>
    private bool ConnectToDomain()
    {
        Logger.Log("ADUCPlugin.ConnectToDomain", Logger.manageLogLevel);
        
        if (_usingSimpleBind &&
        (!Hostinfo.HasCreds(_hn) || _hn.creds.Invalidated))
        {
            _container.ShowError("ADUC cannot connect to domain due to invalid credentials");
            _hn.IsConnectionSuccess = false;
            return _hn.IsConnectionSuccess;
        }

        //Make sure one ADUC plugin only hosts one domain

        if (_aducPagelvChildNodes != null)
        {
            _aducPagelvChildNodes.Items.Clear();
        }

        if (_pluginNode != null && _pluginNode.Nodes.Count != 0)
        {
            foreach (TreeNode treeNode in _pluginNode.Nodes)
            {
                LACTreeNode lacTreeNode = treeNode as LACTreeNode;
                if (lacTreeNode != null && lacTreeNode is LACTreeNode)
                {
                    if (!lacTreeNode._IsPlugIn)
                    {
                        _pluginNode.Nodes.Remove(treeNode);
                    }
                    else
                    {
                        ListViewItem lvItem = new ListViewItem(treeNode.Text);
                        lvItem.Tag = treeNode;
                        lvItem.ImageIndex = (int)treeNode.ImageIndex;
                        _aducPagelvChildNodes.Items.Add(lvItem);
                    }
                }
            }
        }
        
        _currentDomain = new ADUCDomain();
        _currentDomain.HostInfo = _hn;
        _currentDomain.plugin = this;
        
        if (_currentDomain.ConnectToDomain(_usingSimpleBind) != null)
        {
            if (!_domainList.ContainsKey(_currentDomain.rootDN.ToLower()))
            {
                _domainList.Add(_currentDomain.rootDN.ToLower(), _currentDomain);
            }
            
            _pluginNode.Text = string.Format("Active Directory Users & Computers [{0}]", _hn.domainName);
            
            if (_currentDomain.rootNode != null)
            {
                _currentDomain.rootNode.sc = _pluginNode.sc;
                //_pluginNode.Nodes.Add(domain.rootNode);
                bool IsFound = false;
                if (_pluginNode != null && _pluginNode.Nodes.Count != 0)
                {
                    int index = 0;
                    foreach (TreeNode treeNode in _pluginNode.Nodes)
                    {
                        IsFound = false;
                        ADUCDirectoryNode node = treeNode as ADUCDirectoryNode;
                        if (node != null && node.Name.Trim().ToLower().Equals(_currentDomain.rootNode.Name.Trim().ToLower()))
                        {
                            IsFound = true;
                            _pluginNode.Nodes.RemoveAt(index);
                            _pluginNode.Nodes.Insert(index, _currentDomain.rootNode);
                            break;
                        }
                        index++;
                    }
                }
                if (!IsFound)
                {
                    _pluginNode.Nodes.Add(_currentDomain.rootNode);
                }
                
                _currentDomain.rootNode.Collapse();
                _currentDomain.rootNode.ExpandAll();
            }
            
            _adContext = _currentDomain.adContext;
            _rootDN = _currentDomain.rootDN;
            _shortDomainName = _currentDomain.ShortDomainName;
            
            _defaultUnixHomedir = _currentDomain.DefaultUnixHomeDir;
            
            _loginShell = _currentDomain.LoginShell;          
            _hn.IsConnectionSuccess = true;
        }
        else
        {            
            _hn.IsConnectionSuccess = false;
        }
        
        return _hn.IsConnectionSuccess;
    }
コード例 #2
0
        /// <summary>
        /// Will be called when we click on 'Set Target Machine Info' menu item and if plugin is already connected to domain
        /// Will gets all nodes along with its childs
        /// </summary>
        private bool ConnectToDomain()
        {
            Logger.Log("ADUCPlugin.ConnectToDomain", Logger.manageLogLevel);

            if (_usingSimpleBind &&
                (!Hostinfo.HasCreds(_hn) || _hn.creds.Invalidated))
            {
                _container.ShowError("ADUC cannot connect to domain due to invalid credentials");
                _hn.IsConnectionSuccess = false;
                return(_hn.IsConnectionSuccess);
            }

            //Make sure one ADUC plugin only hosts one domain

            if (_aducPagelvChildNodes != null)
            {
                _aducPagelvChildNodes.Items.Clear();
            }

            if (_pluginNode != null && _pluginNode.Nodes.Count != 0)
            {
                foreach (TreeNode treeNode in _pluginNode.Nodes)
                {
                    LACTreeNode lacTreeNode = treeNode as LACTreeNode;
                    if (lacTreeNode != null && lacTreeNode is LACTreeNode)
                    {
                        if (!lacTreeNode._IsPlugIn)
                        {
                            _pluginNode.Nodes.Remove(treeNode);
                        }
                        else
                        {
                            ListViewItem lvItem = new ListViewItem(treeNode.Text);
                            lvItem.Tag        = treeNode;
                            lvItem.ImageIndex = (int)treeNode.ImageIndex;
                            _aducPagelvChildNodes.Items.Add(lvItem);
                        }
                    }
                }
            }

            _currentDomain          = new ADUCDomain();
            _currentDomain.HostInfo = _hn;
            _currentDomain.plugin   = this;

            if (_currentDomain.ConnectToDomain(_usingSimpleBind) != null)
            {
                if (!_domainList.ContainsKey(_currentDomain.rootDN.ToLower()))
                {
                    _domainList.Add(_currentDomain.rootDN.ToLower(), _currentDomain);
                }

                _pluginNode.Text = string.Format("Active Directory Users & Computers [{0}]", _hn.domainName);

                if (_currentDomain.rootNode != null)
                {
                    _currentDomain.rootNode.sc = _pluginNode.sc;
                    //_pluginNode.Nodes.Add(domain.rootNode);
                    bool IsFound = false;
                    if (_pluginNode != null && _pluginNode.Nodes.Count != 0)
                    {
                        int index = 0;
                        foreach (TreeNode treeNode in _pluginNode.Nodes)
                        {
                            IsFound = false;
                            ADUCDirectoryNode node = treeNode as ADUCDirectoryNode;
                            if (node != null && node.Name.Trim().ToLower().Equals(_currentDomain.rootNode.Name.Trim().ToLower()))
                            {
                                IsFound = true;
                                _pluginNode.Nodes.RemoveAt(index);
                                _pluginNode.Nodes.Insert(index, _currentDomain.rootNode);
                                break;
                            }
                            index++;
                        }
                    }
                    if (!IsFound)
                    {
                        _pluginNode.Nodes.Add(_currentDomain.rootNode);
                    }

                    _currentDomain.rootNode.Collapse();
                    _currentDomain.rootNode.ExpandAll();
                }

                _adContext       = _currentDomain.adContext;
                _rootDN          = _currentDomain.rootDN;
                _shortDomainName = _currentDomain.ShortDomainName;

                _defaultUnixHomedir = _currentDomain.DefaultUnixHomeDir;

                _loginShell             = _currentDomain.LoginShell;
                _hn.IsConnectionSuccess = true;
            }
            else
            {
                _hn.IsConnectionSuccess = false;
            }

            return(_hn.IsConnectionSuccess);
        }