Ejemplo n.º 1
0
        /// <summary>
        /// Adds all the "user"/"group" objects to the tree
        /// </summary>
        /// <param name="container"></param>
        /// <param name="parentPage"></param>
        /// <param name="plugin"></param>
        /// <param name="PageType"></param>
        public AddUsertoGroup(IPlugInContainer container, MPPage parentPage, ADUCPlugin plugin, int PageType)
            : this()
        {
            this.IPlugInContainer = container;
            _addplugin            = plugin;
            _aducRootnode         = _addplugin.GetPlugInNode();
            _PageType             = PageType;

            if (_aducRootnode.Nodes.Count > 0)
            {
                ADUCDirectoryNode rootNode =
                    ADUCDirectoryNode.GetDirectoryRoot(_addplugin.GetpluginContext(),
                                                       _addplugin.GetRootDN(),
                                                       Resources.ADUC, typeof(ADUCPage), _addplugin);

                if (rootNode != null)
                {
                    treeView1.Nodes.Add(rootNode);
                    rootNode.Refresh();
                    treeView1.ExpandAll();
                }
            }
            else
            {
                Logger.Log("The LWTreeView control does not have any nodes.");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the list of groups those are all of members to the selected node
        /// </summary>
        /// <param name="groupDn"></param>
        /// <param name="_dirnode"></param>
        /// <returns></returns>
        public static List <string> GetMemberAttrofGroup(string groupDn, ADUCDirectoryNode _dirnode)
        {
            string[]      search_attrs = { "objectsid", "member", null };
            List <string> member       = new List <string>();

            ADUCDirectoryNode newGroupnode = new ADUCDirectoryNode(_dirnode, "group", groupDn);

            List <LdapEntry> ldapEntries = UserGroupUtils.getLdapEntries(false, newGroupnode, search_attrs, "(objectClass=*)", LdapAPI.LDAPSCOPE.BASE);

            if (ldapEntries != null && ldapEntries.Count > 0)
            {
                LdapEntry ldapNextEntry = ldapEntries[0];
                if (ldapNextEntry != null)
                {
                    string[] attrsList = ldapNextEntry.GetAttributeNames();


                    if (attrsList != null)
                    {
                        foreach (string attr in attrsList)
                        {
                            if (attr.Equals("member", StringComparison.InvariantCultureIgnoreCase))
                            {
                                LdapValue[] attrValues = ldapNextEntry.GetAttributeValues(attr, newGroupnode.LdapContext);
                                foreach (LdapValue attrValue in attrValues)
                                {
                                    member.Add(attrValue.stringData);
                                }
                            }
                        }
                    }
                }
            }
            return(member);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets all class attributes from the Schema template and add them to the treeview
        /// </summary>
        /// <param name="objectAddDlg"></param>
        public ObjectAddWelcomePage(ADObjectAddDlg objectAddDlg, ADUCDirectoryNode dirnode, IPlugInContainer container, StandardPage parentPage)
            : this()
        {
            this._objectAddDlg = objectAddDlg;
            this.dirnode       = dirnode;
            this._container    = container;
            this._parentPage   = parentPage;

            if (_objectAddDlg.objectClasses != null)
            {
                if (treeView1.Nodes != null)
                {
                    treeView1.Nodes.Clear();
                }

                foreach (string node in _objectAddDlg.objectClasses)
                {
                    if (node != null)
                    {
                        SchemaType    schemaType          = _objectAddDlg.schemaCache.GetSchemaTypeByObjectClass(node);
                        LdapClassType ldapClassType       = schemaType as LdapClassType;
                        String[]      mandatoryAttributes = ldapClassType.MandatoryAttributes;
                        TreeNode      schemeNode          = new TreeNode();
                        schemeNode.Text = schemaType.AttributeDisplayName;
                        schemeNode.Tag  = mandatoryAttributes;
                        treeView1.Nodes.Add(schemeNode);
                        treeView1.Sort();
                    }
                }
            }

            treeView1.HideSelection = true;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// initializes the Directory node DistinguishedName with DistinguishedName Dn for the selected AD Object
        /// </summary>
        /// <param name="dirnode"></param>
        /// <param name="objectClass"></param>
        /// <param name="newDn"></param>
        public ADUCDirectoryNode(ADUCDirectoryNode dirnode, string objectClass, string newDn)
        {
            this.distinguishedName = newDn;
            this.dirContext        = dirnode.dirContext;

            _objectClass     = objectClass;
            this._IsDisabled = dirnode.IsDisabled;

            if (!dirnode.distinguishedName.StartsWith("DC=", StringComparison.InvariantCultureIgnoreCase))
            {
                string[] parts = dirnode.distinguishedName.Split(',');
                if (parts.Length > 0)
                {
                    Text = parts[0];
                }
            }

            if (_IsDisabled && _objectClass.Equals("user", StringComparison.InvariantCultureIgnoreCase))
            {
                objectClass = "disabledUser";
            }
            else if (_IsDisabled && _objectClass.Equals("computer", StringComparison.InvariantCultureIgnoreCase))
            {
                objectClass = "disabledComputer";
            }

            ImageIndex         = (int)GetNodeType(objectClass);
            SelectedImageIndex = (int)GetNodeType(objectClass);
        }
    /// <summary>
    /// Gets all class attributes from the Schema template and add them to the treeview
    /// </summary>
    /// <param name="objectAddDlg"></param>
    public ObjectAddWelcomePage(ADObjectAddDlg objectAddDlg, ADUCDirectoryNode dirnode, IPlugInContainer container, StandardPage parentPage)
        : this()
    {
        this._objectAddDlg = objectAddDlg;
        this.dirnode = dirnode;
        this._container = container;
        this._parentPage = parentPage;

        if (_objectAddDlg.objectClasses != null)
        {
            if (treeView1.Nodes != null)
            {
                treeView1.Nodes.Clear();
            }

            foreach (string node in _objectAddDlg.objectClasses)
            {
                if (node != null)
                {
                    SchemaType schemaType = _objectAddDlg.schemaCache.GetSchemaTypeByObjectClass(node);
                    LdapClassType ldapClassType = schemaType as LdapClassType;
                    String[] mandatoryAttributes = ldapClassType.MandatoryAttributes;
                    TreeNode schemeNode = new TreeNode();
                    schemeNode.Text = schemaType.AttributeDisplayName;
                    schemeNode.Tag = mandatoryAttributes;
                    treeView1.Nodes.Add(schemeNode);
                    treeView1.Sort();
                }
            }
        }

        treeView1.HideSelection = true;
    }
Ejemplo n.º 6
0
 public UserAddFinishPage(ADUserAddDlg userAddDlg, ADUCDirectoryNode dirnode)
     : this()
 {
     this._dirnode         = dirnode;
     this._userAddDlg      = userAddDlg;
     this.txtcreatein.Text = "Create in: " + this._userAddDlg.userInfo.OUPath;
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Gets the seleted  object class information
        /// And changes the distinguished name from old to new for the object that is being moved
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            if (sender != null)
            {
                if (e.Button != System.Windows.Forms.MouseButtons.Right)
                {
                    LACTreeNode node = e.Node as LACTreeNode;


                    ADUCDirectoryNode dirnode = node as ADUCDirectoryNode;

                    if (dirnode != null)
                    {
                        // dirnode.ListChildren();
                        ADUCDirectoryNode[] childNodes = dirnode.ListContainerChildren(dirnode);
                        if (childNodes != null)
                        {
                            dirnode.Nodes.AddRange(childNodes);
                        }

                        dirnode.Expand();
                        moveInfo.newParentDn      = dirnode.DistinguishedName;
                        moveInfo.newParentDirnode = dirnode;
                    }
                }
            }
        }
Ejemplo n.º 8
0
        public ADComputerAddDlg(IPlugInContainer container, StandardPage parentPage, ADUCDirectoryNode dirnode)
            : this()
        {
            this.IPlugInContainer = container;

            computerInfo = new ComputerInfo();
            int ret = -1;

            if (dirnode != null)
            {
                List <LdapEntry> ldapEntries = null;
                ret = dirnode.LdapContext.ListChildEntriesSynchronous
                          (dirnode.DistinguishedName,
                          LdapAPI.LDAPSCOPE.BASE,
                          "(objectClass=*)",
                          null,
                          false,
                          out ldapEntries);

                if (ldapEntries == null || ldapEntries.Count == 0)
                {
                    return;
                }

                LdapEntry ldapNextEntry = ldapEntries[0];
                //As of now we are not getting canonicalName attribute in the list because of paging issue
                //LdapValue[] attr = ldapNextEntry.GetAttributeValues("canonicalName", dirnode.LdapContext);
                //if (attr != null && attr.Length > 0)
                //    this.lblCreatein.Text = "Create in: " + attr[0].stringData;

                //As of now we are taking "DistinguishedName" and spliting and displaying it.
                string[] sData   = dirnode.DistinguishedName.Split(',');
                string   sOutput = "";
                for (int i = sData.Length - 1; i >= 0; i--)
                {
                    if (sData[i].ToString().Trim().StartsWith("DC", StringComparison.InvariantCultureIgnoreCase))
                    {
                        sOutput = sData[i].ToString().Trim().Substring(3) + "." + sOutput;
                    }
                    else if (sData[i].ToString().Trim().StartsWith("OU", StringComparison.InvariantCultureIgnoreCase) || sData[i].ToString().Trim().StartsWith("CN", StringComparison.InvariantCultureIgnoreCase))
                    {
                        sOutput += "/" + sData[i].ToString().Trim().Substring(3);
                    }
                }
                if (sOutput.EndsWith("."))
                {
                    sOutput += "/";
                }
                sOutput = sOutput.Replace("./", "/");

                this.computerInfo.DomainName = sOutput;
            }


            this.AddPage(new ComputerAddWelcomepage(this, dirnode));
            this.AddPage(new ComputerAddManagedPage(this));
            this.AddPage(new ComputerAddHostServerPage(this));
            this.AddPage(new ComputerAddFinishPage(this));
        }
Ejemplo n.º 9
0
 public ComputerAddWelcomepage(ADComputerAddDlg computerAddDlg, ADUCDirectoryNode dirnode)
     : this()
 {
     this._computerAddDlg      = computerAddDlg;
     this._computerAddDlg.Text = "New Object - Computer";
     this._dirnode             = dirnode;
     this.txtcreatein.Text     = "Create in: " + computerAddDlg.computerInfo.DomainName;
 }
        public ADDeleteComputerConfirmDialog(ADUCDirectoryNode dirnode)
        {
            InitializeComponent();

            string lblText = label1.Text;

            label1.Text = string.Format(lblText, dirnode.Text);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Gets all groups for the selected user AD Object is member of
        /// Add groups to the Member Of page listview
        /// </summary>
        /// <param name="ce"></param>
        /// <param name="servername"></param>
        /// <param name="name"></param>
        /// <param name="dirnode"></param>
        public void SetData(CredentialEntry ce, string servername, string name, ADUCDirectoryNode dirnode)
        {
            _servername = servername;
            _dirnode    = dirnode;

            try
            {
                string[] groupDns = UserGroupUtils.GetGroupsforUser(dirnode);

                MemoflistView.Items.Clear();
                //show a list of group names in the member of page
                Logger.Log("user member of contains: ");
                if (groupDns != null && groupDns.Length > 0)
                {
                    //populate the data in usermemberOf page using groupDns
                    foreach (string groupDn in groupDns)
                    {
                        Logger.Log("group: " + groupDn);
                        //CN=Domain Users,CN=Users,DC=qadom,DC=centeris,DC=com
                        // split the groupDns
                        string[]       slvItem   = UserGroupUtils.splitDn(groupDn);
                        string         sLDAPPath = string.Format("LDAP://{0}/{1}", _dirnode.LdapContext.DomainName, groupDn);
                        DirectoryEntry entry     = new DirectoryEntry(sLDAPPath, _dirnode.LdapContext.UserName, _dirnode.LdapContext.Password);
                        if (entry == null)
                        {
                            return;
                        }
                        ListViewItem lvItem = new ListViewItem(slvItem);
                        lvItem.ImageIndex = MemOfPages.GetIndexForADObject(entry);
                        MemoflistView.Items.Add(lvItem);
                        lvItem.Tag = groupDn;

                        if (!slvItem[0].Equals("Domain Users", StringComparison.InvariantCultureIgnoreCase))
                        {
                            MemofDnList.Add(groupDn);
                        }
                    }
                    //settings primary group to user
                    sPrimayGroup = UserGroupUtils.GetPrimaryGroup(_dirnode);
                    string[] Items = UserGroupUtils.splitDn(sPrimayGroup);
                    if (!string.IsNullOrEmpty(Items[0]))
                    {
                        DomainUserlabel.Text = Items[0];
                    }

                    if (MemoflistView.Items.Count > 0)
                    {
                        MemoflistView.Items[0].Selected = true;
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.LogException("UserMemberOfPage.SetData", ex);
            }
        }
 public ADGroupPropertiesDlg(IPlugInContainer container, StandardPage parentPage, ADUCPlugin plugin,ADUCDirectoryNode dirnode)
 : base(container, parentPage)
 {
     this.Text = "{0} Properties";
     this._dirnode = dirnode;
     InitializeComponent();
     _plugin = plugin;
     _container = container;
     InitializePages();
 }
Ejemplo n.º 13
0
 public ADGroupPropertiesDlg(IPlugInContainer container, StandardPage parentPage, ADUCPlugin plugin, ADUCDirectoryNode dirnode)
     : base(container, parentPage)
 {
     this.Text     = "{0} Properties";
     this._dirnode = dirnode;
     InitializeComponent();
     _plugin    = plugin;
     _container = container;
     InitializePages();
 }
Ejemplo n.º 14
0
        /// <summary>
        /// Queries and fills the ldap message for the selected group
        /// Gets the attribute list from AD for group schema attribute.
        /// search for the attributes description, cn or name and displays them in a controls
        /// </summary>
        /// <param name="ce"></param>
        /// <param name="servername"></param>
        /// <param name="name"></param>
        /// <param name="dirnode"></param>
        public void SetData(CredentialEntry ce, string servername, string name, ADUCDirectoryNode dirnode)
        {
            try
            {
                this.dirnode = dirnode;

                DirectoryContext dirContext = dirnode.LdapContext;

                //first obtain the current userAccountControl value
                DirectoryEntry de = new DirectoryEntry(string.Format("LDAP://{0}/{1}", dirContext.DomainName, dirnode.DistinguishedName));

                profilePath   = de.Properties["profilePath"].Value as string;
                scriptPath    = de.Properties["scriptPath"].Value as string;
                homeDirectory = de.Properties["homeDirectory"].Value as string;
                homeDrive     = de.Properties["homeDrive"].Value as string;

                foreach (string ch in Charlist)
                {
                    cbDrive.Items.Add(ch);
                }

                if (homeDrive != null)
                {
                    rbConnect.Checked = true;
                    txtConnect.Text   = homeDirectory;
                    int selectedIndex = 0;
                    if (cbDrive.Items.Contains(homeDrive))
                    {
                        selectedIndex = cbDrive.Items.IndexOf(homeDrive);
                    }
                    else
                    {
                        selectedIndex = cbDrive.Items.Add(homeDrive);
                    }
                    cbDrive.SelectedIndex = selectedIndex;
                }
                else
                {
                    rbLocalPath.Checked   = true;
                    txtLocalPath.Text     = homeDirectory;
                    cbDrive.SelectedIndex = 0;
                }

                txtProfilePath.Text = profilePath;
                txtLogonScript.Text = scriptPath;

                ParentContainer.DataChanged = false;

                ParentContainer.btnApply.Enabled = false;
            }
            catch (Exception e)
            {
                Logger.LogException("UserGeneralEditPage.SetData", e);
            }
        }
Ejemplo n.º 15
0
        public static int GetIndexForADObject(System.DirectoryServices.DirectoryEntry de)
        {
            try
            {
                object[] asProp = de.Properties["objectClass"].Value as object[];
                // poke these in a list for easier reference
                List <string> liClasses = new List <string>();
                foreach (string s in asProp)
                {
                    liClasses.Add(s);
                }
                if (liClasses.Contains("user") || liClasses.Contains("computer"))
                {
                    string usercontrol    = de.Properties["userAccountControl"].Value.ToString();
                    int    userControl    = Convert.ToInt32(usercontrol);
                    string userCtrlBinStr = UserGroupUtils.DecimalToBase(userControl, 2);
                    if (userCtrlBinStr.Length >= 2)
                    {
                        if (liClasses.Contains("computer"))
                        {
                            if (userCtrlBinStr[userCtrlBinStr.Length - 2] == '1')
                            {
                                return((int)ADUCDirectoryNode.GetNodeType("Computer"));
                            }
                            else
                            {
                                return((int)ADUCDirectoryNode.GetNodeType("computer"));
                            }
                        }
                        if (liClasses.Contains("user"))
                        {
                            if (userCtrlBinStr[userCtrlBinStr.Length - 2] == '1')
                            {
                                return((int)ADUCDirectoryNode.GetNodeType("disabledUser"));
                            }
                            else
                            {
                                return((int)ADUCDirectoryNode.GetNodeType("user"));
                            }
                        }
                    }
                }
                else if (liClasses.Contains("group") || liClasses.Contains("foreignSecurityPrincipal"))
                {
                    return((int)ADUCDirectoryNode.GetNodeType("group"));
                }
            }

            catch
            {
                return((int)ADUCDirectoryNode.GetNodeType("group"));
            }

            return((int)ADUCDirectoryNode.GetNodeType("group"));
        }
Ejemplo n.º 16
0
 /// <summary>
 ///
 /// </summary>
 public void SetData(CredentialEntry ce, string servername, string name, ADUCDirectoryNode dirnode)
 {
     try
     {
         this.dirnode = dirnode;
         SetControlStatus();
     }
     catch (Exception e)
     {
         Logger.LogException("UserMultiEditPage.SetData", e);
     }
 }
 /// <summary>
 ///
 /// </summary>
 public void SetData(CredentialEntry ce, string servername, string name, ADUCDirectoryNode dirnode)
 {
     try
     {
         this.dirnode = dirnode;
         SetControlStatus();
     }
     catch (Exception e)
     {
         Logger.LogException("UserMultiEditPage.SetData", e);
     }
 }
Ejemplo n.º 18
0
        public UserAddWelcomePage(ADUserAddDlg userAddDlg, ADUCDirectoryNode dirnode)
            : this()
        {
            this._userAddDlg = userAddDlg;
            this._dirnode    = dirnode;
            string[] prefixes = this._userAddDlg.userInfo.domainName.Split('.');
            string   prefix   = string.Concat(prefixes[0].ToUpper(), "\\");

            this.prelogontextBox.Text    = prefix;
            this.domainNamecomboBox.Text = this._userAddDlg.userInfo.domainName;
            this.txtcreatein.Text        = "Create in: " + this._userAddDlg.userInfo.OUPath;
        }
Ejemplo n.º 19
0
        public UserAddWelcomePage(ADUserAddDlg userAddDlg, ADUCDirectoryNode dirnode)
            : this()
        {

            this._userAddDlg = userAddDlg;
            this._dirnode = dirnode;
            string[] prefixes = this._userAddDlg.userInfo.domainName.Split('.');
            string prefix = string.Concat(prefixes[0].ToUpper(), "\\");
            this.prelogontextBox.Text = prefix;
            this.domainNamecomboBox.Text = this._userAddDlg.userInfo.domainName;
            this.txtcreatein.Text = "Create in: " + this._userAddDlg.userInfo.OUPath;
        }
Ejemplo n.º 20
0
        public ADGroupAddDlg(IPlugInContainer container, StandardPage parentPage, ADUCDirectoryNode dirnode)
            : this()
        {
            int ret = -1;
            this.IPlugInContainer = container;
            this._dirnode = dirnode;
            if (dirnode != null)
            {
                List<LdapEntry> ldapEntries = null;

                ret = dirnode.LdapContext.ListChildEntriesSynchronous
                (dirnode.DistinguishedName,
                LdapAPI.LDAPSCOPE.BASE,
                "(objectClass=*)",
                null,
                false,
                out ldapEntries);

                if (ldapEntries == null || ldapEntries.Count == 0)
                {
                    return;
                }

                LdapEntry ldapNextEntry = ldapEntries[0];
                //As of now we are not getting canonicalName attribute in the list because of paging issue
                //LdapValue[] attr = ldapNextEntry.GetAttributeValues("canonicalName", dirnode.LdapContext);
                //if (attr != null && attr.Length > 0)
                //    this.lblCreatein.Text = "Create in: " + attr[0].stringData;

                //As of now we are taking "DistinguishedName" and spliting and displaying it.
                string[] sData = dirnode.DistinguishedName.Split(',');
                string sOutput = "";
                for (int i = sData.Length - 1; i >= 0; i--)
                {
                    if (sData[i].ToString().Trim().StartsWith("DC", StringComparison.InvariantCultureIgnoreCase))
                    {
                        sOutput = sData[i].ToString().Trim().Substring(3) + "." + sOutput;
                    }
                    else if (sData[i].ToString().Trim().StartsWith("OU", StringComparison.InvariantCultureIgnoreCase) || sData[i].ToString().Trim().StartsWith("CN", StringComparison.InvariantCultureIgnoreCase))
                    {
                        sOutput += "/" + sData[i].ToString().Trim().Substring(3);
                    }
                }
                if (sOutput.EndsWith("."))
                {
                    sOutput += "/";
                }
                sOutput = sOutput.Replace("./", "/");

                this.txtcreatein.Text = "Create in: " + sOutput;
            }
        }
Ejemplo n.º 21
0
        public static ADUCDirectoryNode GetDirectoryRoot(DirectoryContext dirCtx, string DistinguishedName, Icon image, Type t, IPlugIn plugin)
        {
            if (dirCtx == null)
            {
                Logger.LogMsgBox("DirectoryNode.GetDirectoryRoot(): dirCtx == null");
                return(null);
            }

            ADUCDirectoryNode dn = new ADUCDirectoryNode(DistinguishedName,
                                                         dirCtx, "container", image, t, plugin, false);

            return(dn);
        }
Ejemplo n.º 22
0
        private static string OnApply_GetObjectRealmName(ADUCDirectoryNode _dirnode)
        {
            string[] search_attrs = { "sAMAccountName", "userPrincipalName", null };
            string   realmName    = string.Empty;

            ADUCDirectoryNode newGroupnode = new ADUCDirectoryNode(_dirnode, _dirnode.ObjectClass, _dirnode.DistinguishedName);

            List <LdapEntry> ldapEntries = UserGroupUtils.getLdapEntries(false, newGroupnode, search_attrs, "(objectClass=*)", LdapAPI.LDAPSCOPE.BASE);

            if (ldapEntries != null && ldapEntries.Count > 0)
            {
                LdapEntry ldapNextEntry = ldapEntries[0];
                if (ldapNextEntry != null)
                {
                    string[] attrsList = ldapNextEntry.GetAttributeNames();

                    if (attrsList != null)
                    {
                        foreach (string attr in attrsList)
                        {
                            if (_dirnode.ObjectClass.Equals("group", StringComparison.InvariantCultureIgnoreCase) ||
                                _dirnode.ObjectClass.Equals("computer", StringComparison.InvariantCultureIgnoreCase))
                            {
                                if (attr.Equals("sAMAccountName", StringComparison.InvariantCultureIgnoreCase))
                                {
                                    LdapValue[] attrValues = ldapNextEntry.GetAttributeValues(attr, newGroupnode.LdapContext);
                                    if (attrValues != null)
                                    {
                                        realmName = attrValues[0].stringData;
                                        break;
                                    }
                                }
                            }
                            else if (_dirnode.ObjectClass.Equals("user", StringComparison.InvariantCultureIgnoreCase))
                            {
                                if (attr.Equals("userPrincipalName", StringComparison.InvariantCultureIgnoreCase))
                                {
                                    LdapValue[] attrValues = ldapNextEntry.GetAttributeValues(attr, newGroupnode.LdapContext);
                                    if (attrValues != null)
                                    {
                                        realmName = attrValues[0].stringData;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(realmName);
        }
Ejemplo n.º 23
0
        /// <summary>
        /// only list those children that are group type
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            // When a Node is selected, ShowNode already gets called because of LWTreeView1_NodeMouseClick
            LACTreeNode node = e.Node as LACTreeNode;

            if (node is ADUCDirectoryNode)
            {
                ADUCDirectoryNode dirnode = node as ADUCDirectoryNode;

                dirnode.ListChildren();
                groupInfo.groupName  = dirnode.DistinguishedName;
                groupInfo.objectName = dirnode.DistinguishedName;
            }
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Queries and initializes the ldapMessage for the selected group
        /// Gets all users and groups those are members for selected group
        /// Fills the list with listview
        /// </summary>
        /// <param name="ce"></param>
        /// <param name="servername"></param>
        /// <param name="name"></param>
        /// <param name="dirnode"></param>
        public void SetData(CredentialEntry ce, string servername, string name, ADUCDirectoryNode dirnode)
        {
            Dictionary <string, string> members = UserGroupUtils.GetGroupMembers(dirnode);

            foreach (string str in members.Keys)
            {
                OriginalObjects.Add(str);
                ModifiedObjects.Add(str.ToLower());
            }

            _dirnode = dirnode;

            MemoflistView.Items.Clear();
            //show a list of group names in the member of page
            Logger.Log("Group member contains: ");

            foreach (string sDN in members.Keys)
            {
                string[] slvItem = null;
                System.DirectoryServices.DirectoryEntry de = new System.DirectoryServices.DirectoryEntry(sDN, _dirnode.LdapContext.UserName, _dirnode.LdapContext.Password);
                if (members[sDN].Equals("foreignSecurityPrincipal"))
                {
                    byte[] objectSid = de.Properties["objectSid"].Value as byte[];
                    string Sid       = UserGroupUtils.SIDtoString(objectSid);
                    string cn        = UserGroupUtils.GetGroupFromForeignSecurity(Sid, dirnode.LdapContext);
                    if (cn != null)
                    {
                        slvItem = new string[] { cn, "NT AUTHORITY" };
                    }
                    else
                    {
                        continue;
                    }
                }
                else
                {
                    slvItem = UserGroupUtils.splitDn(sDN);
                }
                ListViewItem lvItem = new ListViewItem(slvItem);
                lvItem.ImageIndex = MemOfPages.GetIndexForADObject(de);
                MemoflistView.Items.Add(lvItem);
                lvItem.Tag = sDN;
            }

            if (MemoflistView.Items.Count > 0)
            {
                MemoflistView.Items[0].Selected = true;
            }
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Method to load data to the tab pages while loading
        /// Gets all the tab pages that are of type MPage and gets call the SetData()
        /// Queries the ldap message to the selected node
        /// </summary>
        /// <param name="ce"></param>
        /// <param name="servername"></param>
        /// <param name="computer"></param>
        /// <param name="dirnode"></param>
        /// <param name="ldapSchemaCache"></param>
        public void SetData(CredentialEntry ce, string servername, string sOU, ADUCDirectoryNode dirnode, LDAPSchemaCache ldapSchemaCache)
        {
            Applied = false;
            _plugin = dirnode.Plugin as ADUCPlugin;

            objInfo = new ObjectPropertyInfo
                          (ce,
                          servername,
                          sOU,
                          dirnode,
                          null);

            threadMain = new Thread(new ThreadStart(AddPagesToThread));
            threadMain.Start();
        }
Ejemplo n.º 26
0
    /// <summary>
    /// Overriden constructor gets all class schema attributes from AD Schema template
    /// </summary>
    /// <param name="container"></param>
    /// <param name="parentPage"></param>
    /// <param name="text"></param>
    /// <param name="schemaCache"></param>
    public ADObjectAddDlg(IPlugInContainer container, StandardPage parentPage, string text, LDAPSchemaCache schemaCache, ADUCDirectoryNode dirnode)
        : this()
    {
        this.IPlugInContainer = container;
        this.Text = text;

        string[] objectClasses = null;
        string[] attrs = { "name", "allowedAttributes", "allowedChildClasses", null };

        if (schemaCache != null && dirnode != null)
        {
            List<LdapEntry> ldapEntries = null;
            int ret = dirnode.LdapContext.ListChildEntriesSynchronous
            (dirnode.DistinguishedName,
            LdapAPI.LDAPSCOPE.BASE,
            "(objectClass=*)",
            attrs,
            false,
            out ldapEntries);

            if (ldapEntries == null)
            {
                return;
            }

            LdapEntry ldapNextEntry = ldapEntries[0];

            LdapValue[] ldapValues = ldapNextEntry.GetAttributeValues("allowedChildClasses", dirnode.LdapContext);
            if (ldapValues != null && ldapValues.Length > 0)
            {
                objectClasses = new string[ldapValues.Length];
                int index = 0;
                foreach (LdapValue Oclass in ldapValues)
                {
                    objectClasses[index] = Oclass.stringData;
                    index++;
                }
            }
        }

        this.objectClasses = objectClasses;
        this.schemaCache = schemaCache;
        this.choosenClass = null;

        this.objectInfo = new ObjectInfo();

        this.AddPage(new ObjectAddWelcomePage(this, dirnode, container, parentPage));
    }
Ejemplo n.º 27
0
        /// <summary>
        /// initializes the Mandatory and Optional list objects with respect to the attribute types
        /// </summary>
        /// <param name="ce"></param>
        /// <param name="servername"></param>
        /// <param name="name"></param>
        /// <param name="node"></param>
        public void SetData(CredentialEntry ce, string servername, string name, ADUCDirectoryNode node)
        {
            string initialSelectedAttrSyntax = "";

            if (_newAttributesList == null)
            {
                return;
            }

            foreach (AttributeInfo attrInfo in _newAttributesList.Values)
            {
                if (_objectAddDlg.objectInfo.htMandatoryAttrList != null && !_objectAddDlg.objectInfo.htMandatoryAttrList.Contains(attrInfo.sAttributename))
                {
                    if (attrInfo.sAttributeType.Equals("Mandatory", StringComparison.InvariantCultureIgnoreCase))
                    {
                        cbMandProperty.Add(attrInfo.sAttributename);
                        cbBothProperty.Add(attrInfo.sAttributename);
                    }
                    else if (attrInfo.sAttributeType.Equals("Optional", StringComparison.InvariantCultureIgnoreCase))
                    {
                        cbOptionProperty.Add(attrInfo.sAttributename);
                        cbBothProperty.Add(attrInfo.sAttributename);
                    }
                }
            }

            /*foreach (string Attr in _newAttributesList.Keys)
             * {
             *  if (_objectAddDlg.objectInfo.htMandatoryAttrList != null)
             *  {
             *      if (!_objectAddDlg.objectInfo.htMandatoryAttrList.Contains(Attr))
             *          cbProperty.Items.Add(Attr);
             *  }
             *  else
             *      cbProperty.Items.Add(Attr);
             * }*/

            {
                this.chooseMandOrOptionList();
            }

            initialSelectedAttrSyntax = _objectAddDlg.ClassAttributeList[0].AttributeSyntax;

            cbProOptionorMandatory.SelectedIndex = 1;
            lbClass.Text = _objectAddDlg.choosenClass;
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Gets the selected "user" or "group" info from the tree
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            if (sender != null)
            {
                bool IsValidObject = false;
                if (e.Button != System.Windows.Forms.MouseButtons.Right)
                {
                    LACTreeNode node = e.Node as LACTreeNode;

                    ADUCDirectoryNode dirnode = node as ADUCDirectoryNode;

                    if (dirnode != null)
                    {
                        if (_PageType == MEMOF_PAGE)
                        {
                            dirnode.ListGroupOUChildren();
                            if (dirnode.ObjectClass.Trim().ToLower().Equals("group"))
                            {
                                IsValidObject = true;
                            }
                            groupInfo.groupName = dirnode.DistinguishedName;
                        }

                        if (_PageType == MEMBERS_PAGE)
                        {
                            dirnode.ListGroupAndUserOUChildren();
                            if (dirnode.ObjectClass.Trim().ToLower().Equals("group") ||
                                dirnode.ObjectClass.Trim().ToLower().Equals("user"))
                            {
                                IsValidObject = true;
                            }
                            groupInfo.objectName = dirnode.DistinguishedName;
                        }
                    }
                    if (!IsValidObject)
                    {
                        Okbtn.Enabled = false;
                    }
                    else
                    {
                        Okbtn.Enabled = true;
                    }
                }
            }
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Method to load data to the tab pages while loading
        /// Gets all the tab pages that are of type MPage and gets calls the SetData()
        /// Queries the ldap message to the selected node
        /// </summary>
        /// <param name="ce"></param>
        /// <param name="servername"></param>
        /// <param name="computer"></param>
        /// <param name="dirnode"></param>
        /// <param name="ldapSchemaCache"></param>
        public void SetData(CredentialEntry ce, string servername, string group, ADUCDirectoryNode dirnode, LDAPSchemaCache ldapSchemaCache)
        {
            Applied   = false;
            _plugin   = dirnode.Plugin as ADUCPlugin;
            this.Text = String.Format(this.Text, group);

            objInfo = new ObjectPropertyInfo(ce,
                                             servername,
                                             group,
                                             dirnode,
                                             null
                                             );

            threadMain = new Thread(new ThreadStart(AddPagesToThread));
            threadMain.Start();

            _plugin.Propertywindowhandles.Add(objInfo.dirnode.DistinguishedName, this);
        }
Ejemplo n.º 30
0
        /// <summary>
        /// When a Node is selected, ShowNode already gets called because of LWTreeView1_NodeMouseClick
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            // When a Node is selected, ShowNode already gets called because of LWTreeView1_NodeMouseClick
            LACTreeNode node = e.Node as LACTreeNode;

            if (node is ADUCDirectoryNode)
            {
                ADUCDirectoryNode dirnode = node as ADUCDirectoryNode;

                ADUCDirectoryNode[] childNodes = dirnode.ListContainerChildren(dirnode);
                if (childNodes != null)
                {
                    dirnode.Nodes.AddRange(childNodes);
                }

                dirnode.Expand();
                moveInfo.newParentDn = dirnode.DistinguishedName;
            }
        }
Ejemplo n.º 31
0
        /// <summary>
        /// Method to get the NodeType for the selected object
        /// </summary>
        /// <param name="dirNode"></param>
        /// <returns></returns>
        public static Manage.ManageImageType GetNodeType(ADUCDirectoryNode dirNode)
        {
            if (dirNode != null)
            {
                string objClass = dirNode._objectClass;

                if (dirNode._IsDisabled && dirNode._objectClass.Equals("user", StringComparison.InvariantCultureIgnoreCase))
                {
                    objClass = "disabledUser";
                }
                else if (dirNode._IsDisabled && dirNode._objectClass.Equals("computer", StringComparison.InvariantCultureIgnoreCase))
                {
                    objClass = "disabledComputer";
                }

                return(GetNodeType(objClass));
            }
            return(Manage.ManageImageType.Generic);
        }
Ejemplo n.º 32
0
        /// <summary>
        /// Override constructor gets the Plugin node and all its childs
        /// Adds the all nodes to the treeview
        /// </summary>
        /// <param name="container"></param>
        /// <param name="parentPage"></param>
        /// <param name="plugin"></param>
        /// <param name="origTreeview"></param>
        public ADMoveObjectPage(IPlugInContainer container, StandardPage parentPage, ADUCPlugin plugin, LWTreeView origTreeview)
            : this()
        {
            this.IPlugInContainer = container;
            _addplugin            = plugin;

            _origLWTreeView = origTreeview;

            _aducRootnode = _addplugin.GetPlugInNode();

            if (_aducRootnode.Nodes.Count > 0)
            {
                /*TreeNode[] newTreeArray = new TreeNode[_aducRootnode.Nodes.Count];
                 * // Iterate through the root nodes in the Nodes property.
                 * _aducRootnode.Nodes.CopyTo(newTreeArray, 0);
                 * foreach (TreeNode node in newTreeArray)
                 * {
                 *  LACTreeNode lacnode = node as LACTreeNode;
                 *  //   treeView1.Nodes.Add(lacnode.DeepCopy() as TreeNode);
                 * }*/
                ADUCDirectoryNode rootNode =
                    ADUCDirectoryNode.GetDirectoryRoot(_addplugin.GetpluginContext(),
                                                       _addplugin.GetRootDN(),
                                                       Resources.ADUC, typeof(ADUCPage), _addplugin);

                if (rootNode != null)
                {
                    treeView1.Nodes.Add(rootNode);
                    ADUCDirectoryNode[] childNodes = rootNode.ListContainerChildren(rootNode);
                    if (childNodes != null)
                    {
                        rootNode.Nodes.AddRange(childNodes);
                    }
                    treeView1.ExpandAll();
                }
            }
            else
            {
                Logger.Log("The LWTreeView control does not have any nodes.");
            }
        }
Ejemplo n.º 33
0
        /// <summary>
        /// Gets and initializes the LikewiseIdentityCell for each root level
        /// </summary>
        /// <param name="dirnode"></param>
        private void likewiseIdentityCell_init(ADUCDirectoryNode dirnode)
        {
            string likewiseCellDN = string.Concat("CN=$LikewiseIdentityCell,", dirnode.LdapContext.RootDN);

            LdapValue[] descriptionValues =
                UserGroupUtils.SearchAttrByDn(likewiseCellDN, dirnode, "description");

            if (descriptionValues == null)
            {
                Logger.Log(String.Format(
                               "No description attribute found in {0}",
                               likewiseCellDN),
                           Logger.LogLevel.Error);
                return;
            }

            foreach (LdapValue value in descriptionValues)
            {
                string descriptionString = value.stringData;
                if (!String.IsNullOrEmpty(descriptionString))
                {
                    string[] split = descriptionString.Split('=');
                    if (split[0].Equals("unixHomeDirectory", StringComparison.InvariantCultureIgnoreCase))
                    {
                        _defaultUnixHomedir = split[1].Trim();
                    }
                    if (split[0].Equals("loginShell", StringComparison.InvariantCultureIgnoreCase))
                    {
                        _loginShell = split[1].Trim();
                    }
                    if (split[0].Equals("use2307Attrs", StringComparison.InvariantCultureIgnoreCase))
                    {
                        if (split[1].Equals("True", StringComparison.InvariantCultureIgnoreCase))
                        {
                            Logger.Log("RFC2307 mode is detected!", Logger.ldapLogLevel);
                        }
                    }
                }
            }
        }
Ejemplo n.º 34
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);
        }
Ejemplo n.º 35
0
        /// <summary>
        /// Event raises when we click on any contextmenu item
        /// And then performs the specified action
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cm_OnMenuClick(object sender, EventArgs e)
        {
            // assure that the sender is a MenuItem
            MenuItem    mi      = sender as MenuItem;
            LACTreeNode lacnode = mi.Tag as LACTreeNode;

            if (lacnode != null && lacnode.Nodes.Count != 0)
            {
                ADUCDirectoryNode rootNode   = lacnode.Nodes[0] as ADUCDirectoryNode;
                ADUCPage          pluginpage = lacnode.PluginPage as ADUCPage;
                if (pluginpage != null)
                {
                    pluginpage.TreeNode.IsModified = true;
                    rootNode.IsModified            = true;
                    pluginpage.RefreshPluginPage();
                    pluginpage.TreeNode.TreeView.SelectedNode = pluginpage.TreeNode;
                    rootNode.ListChildren();
                    if (rootNode.IsExpanded)
                    {
                        rootNode.toggleLACNode();
                    }
                }
            }
        }
Ejemplo n.º 36
0
        /// <summary>
        /// Method to load data to the tab pages while loading
        /// Gets all the tab pages that are of type MPage and gets call the SetData()
        /// Queries the ldap message to the selected node
        /// </summary>
        /// <param name="ce"></param>
        /// <param name="servername"></param>
        /// <param name="computer"></param>
        /// <param name="dirnode"></param>
        /// <param name="ldapSchemaCache"></param>
        public void SetData(CredentialEntry ce, string servername, string computer, ADUCDirectoryNode dirnode, LDAPSchemaCache ldapSchemaCache)
        {
            string PageTitle = string.Format("cn={0}", _objectAddDlg.objectInfo.htMandatoryAttrList["cn"]);

            if (PageTitle != null)
            {
                this.Text = String.Format(this.Text, PageTitle);
            }

            if (this.GetPages() != null)
            {
                foreach (MPPage page in this.GetPages())
                {
                    if (page != null)
                    {
                        IDirectoryPropertiesPage ipp = page as IDirectoryPropertiesPage;
                        if (ipp != null)
                        {
                            ipp.SetData(ce, servername, computer, dirnode);
                        }
                    }
                }
            }
        }
 /// <summary>
 /// Queries and fills the ldap message for the Domain
 /// Gets the attribute list from AD for Domain schema attribute.
 /// search for the attributes description
 /// </summary>
 /// <param name="ce"></param>
 /// <param name="servername"></param>
 /// <param name="name"></param>
 /// <param name="dirnode"></param>
 public void SetData(CredentialEntry ce, string servername, string name, ADUCDirectoryNode dirnode)
 {
     try
     {
         this.dirnode = dirnode;
         int ret = -1;
         List<LdapEntry> ldapEntries = null;
         
         ret = dirnode.LdapContext.ListChildEntriesSynchronous
         (dirnode.DistinguishedName,
         LdapAPI.LDAPSCOPE.BASE,
         "(objectClass=*)",
         null,
         false,
         out ldapEntries);
         
         if (ldapEntries == null || ldapEntries.Count == 0)
         {
             return;
         }
         
         LdapEntry ldapNextEntry = ldapEntries[0];
         
         string[] attrsList = ldapNextEntry.GetAttributeNames();
         
         if (attrsList != null)
         {
             foreach (string attr in attrsList)
             {
                 string sValue = "";
                 
                 LdapValue[] attrValues = ldapNextEntry.GetAttributeValues(attr, dirnode.LdapContext);
                 
                 if (attrValues != null && attrValues.Length > 0)
                 {
                     foreach (LdapValue value in attrValues)
                     {
                         sValue = sValue + "," + value.stringData;
                     }
                 }
                 
                 if (sValue.StartsWith(","))
                 {
                     sValue = sValue.Substring(1);
                 }
                 
                 if (string.Compare(sValue, "") == 0)
                 {
                     sValue = "<Not Set>";
                 }
                 
                 if (string.Compare(attr, "description") == 0)
                 {
                     this.txtDescription.Text = sValue;
                     Description = sValue;
                 }
                 
                 //As of now we are not getting canonicalName attribute in the list because of paging issue
                 if (string.Compare(attr, "canonicalName") == 0)
                 {
                     this.Namelabel.Text = sValue.Substring(0, sValue.Length - 1);
                 }
                 
                 if (string.Compare(attr, "name") == 0)
                 {
                     this.textBoxDomainName.Text = sValue.ToUpper();
                     this.Namelabel.Text = sValue;
                 }
             }
             
             this.lblForestLevel.Text = this.labelDomainLevel.Text = "Windows Server 2003";
             
             this.ParentContainer.DataChanged = false;
             this.ParentContainer.btnApply.Enabled = false;
         }
     }
     catch (Exception e)
     {
         container.ShowError(e.Message);
     }
     // throw new NotImplementedException();
 }
Ejemplo n.º 38
0
 /// <summary>
 /// Method to get the NodeType for the selected object
 /// </summary>
 /// <param name="dirNode"></param>
 /// <returns></returns>
 public static Manage.ManageImageType GetNodeType(ADUCDirectoryNode dirNode)
 {
     if (dirNode != null)
     {
         string objClass = dirNode._objectClass;
         
         if (dirNode._IsDisabled && dirNode._objectClass.Equals("user", StringComparison.InvariantCultureIgnoreCase))
         {
             objClass = "disabledUser";
         }
         else if (dirNode._IsDisabled && dirNode._objectClass.Equals("computer", StringComparison.InvariantCultureIgnoreCase))
         {
             objClass = "disabledComputer";
         }
         
         return GetNodeType(objClass);
     }
     return Manage.ManageImageType.Generic;
 }
        /// <summary>
        /// Method to load data to the tab pages while loading
        /// Gets all the tab pages that are of type MPage and gets call the SetData()
        /// Queries the ldap message to the selected node
        /// </summary>
        /// <param name="ce"></param>
        /// <param name="servername"></param>
        /// <param name="computer"></param>
        /// <param name="dirnode"></param>
        /// <param name="ldapSchemaCache"></param>
        public void SetData(CredentialEntry ce, string servername, string sOU, ADUCDirectoryNode dirnode, LDAPSchemaCache ldapSchemaCache)
        {
            Applied = false;
            _plugin = dirnode.Plugin as ADUCPlugin;

            objInfo = new ObjectPropertyInfo
                                     (ce,
                                     servername,
                                     sOU,
                                     dirnode,
                                     null);

            threadMain = new Thread(new ThreadStart(AddPagesToThread));
            threadMain.Start();
        }
Ejemplo n.º 40
0
    /// <summary>
    /// Gets the list of groups those are all of members to the selected node
    /// </summary>
    /// <param name="groupDn"></param>
    /// <param name="_dirnode"></param>
    /// <returns></returns>
    public static List<string> GetMemberAttrofGroup(string groupDn, ADUCDirectoryNode _dirnode)
    {
        string[] search_attrs = { "objectsid", "member", null };
        List<string> member = new List<string>();

        ADUCDirectoryNode newGroupnode = new ADUCDirectoryNode(_dirnode, "group", groupDn);

        List<LdapEntry> ldapEntries = UserGroupUtils.getLdapEntries(false, newGroupnode, search_attrs, "(objectClass=*)", LdapAPI.LDAPSCOPE.BASE);

        if (ldapEntries != null && ldapEntries.Count > 0)
        {
            LdapEntry ldapNextEntry = ldapEntries[0];
            if (ldapNextEntry != null)
            {

                string[] attrsList = ldapNextEntry.GetAttributeNames();


                if (attrsList != null)
                {
                    foreach (string attr in attrsList)
                    {
                        if (attr.Equals("member", StringComparison.InvariantCultureIgnoreCase))
                        {
                            LdapValue[] attrValues = ldapNextEntry.GetAttributeValues(attr, newGroupnode.LdapContext);
                            foreach (LdapValue attrValue in attrValues)
                            {
                                member.Add(attrValue.stringData);
                            }
                        }
                    }
                }
            }
        }
        return member;
    }
Ejemplo n.º 41
0
    private static string OnApply_GetObjectRealmName(ADUCDirectoryNode _dirnode)
    {
        string[] search_attrs = { "sAMAccountName", "userPrincipalName", null };
        string realmName = string.Empty;

        ADUCDirectoryNode newGroupnode = new ADUCDirectoryNode(_dirnode, _dirnode.ObjectClass, _dirnode.DistinguishedName);

        List<LdapEntry> ldapEntries = UserGroupUtils.getLdapEntries(false, newGroupnode, search_attrs, "(objectClass=*)", LdapAPI.LDAPSCOPE.BASE);

        if (ldapEntries != null && ldapEntries.Count > 0)
        {
            LdapEntry ldapNextEntry = ldapEntries[0];
            if (ldapNextEntry != null)
            {

                string[] attrsList = ldapNextEntry.GetAttributeNames();

                if (attrsList != null)
                {
                    foreach (string attr in attrsList)
                    {
                        if (_dirnode.ObjectClass.Equals("group", StringComparison.InvariantCultureIgnoreCase) ||
                            _dirnode.ObjectClass.Equals("computer", StringComparison.InvariantCultureIgnoreCase))
                        {
                            if (attr.Equals("sAMAccountName", StringComparison.InvariantCultureIgnoreCase))
                            {
                                LdapValue[] attrValues = ldapNextEntry.GetAttributeValues(attr, newGroupnode.LdapContext);
                                if (attrValues != null)
                                {
                                    realmName = attrValues[0].stringData;
                                    break;
                                }
                            }
                        }
                        else if (_dirnode.ObjectClass.Equals("user", StringComparison.InvariantCultureIgnoreCase))
                        {
                            if (attr.Equals("userPrincipalName", StringComparison.InvariantCultureIgnoreCase))
                            {
                                LdapValue[] attrValues = ldapNextEntry.GetAttributeValues(attr, newGroupnode.LdapContext);
                                if (attrValues != null)
                                {
                                    realmName = attrValues[0].stringData;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
        return realmName;
    }
        /// <summary>
        /// Method to load data to the tab pages while loading
        /// Gets all the tab pages that are of type MPage and get calls the SetData()
        /// Queries the ldap message to the selected node
        /// </summary>
        /// <param name="ce"></param>
        /// <param name="servername"></param>
        /// <param name="user"></param>
        /// <param name="dirnode"></param>
        /// <param name="ldapSchemaCache"></param>
        public void SetData(CredentialEntry ce, string servername, string user, ADUCDirectoryNode dirnode, LDAPSchemaCache ldapSchemaCache)
        {
            Applied = false;
            _plugin = dirnode.Plugin as ADUCPlugin;
            this.Text = String.Format(this.Text, user);

            objInfo = new ObjectPropertyInfo
                                      (ce,
                                      servername,
                                      user,
                                      dirnode,
                                      null
                                      );

            threadMain = new Thread(new ThreadStart(AddPagesToThread));
            threadMain.Start();

            _plugin.Propertywindowhandles.Add(objInfo.dirnode.DistinguishedName, this);
        }
Ejemplo n.º 43
0
        /// <summary>
        /// Queries and fills the ldap message for the selected group
        /// Gets the attribute list from AD for group schema attribute.
        /// search for the attributes description, cn or name and displays them in a controls
        /// </summary>
        /// <param name="ce"></param>
        /// <param name="servername"></param>
        /// <param name="name"></param>
        /// <param name="dirnode"></param>
        public void SetData(CredentialEntry ce, string servername, string name, ADUCDirectoryNode dirnode)
        {
            try
            {
                this.dirnode = dirnode;
                this.plugin = dirnode.Plugin as ADUCPlugin;
                DirectoryContext dirContext = dirnode.LdapContext;
                Logonname = "";
                PreLogonname = "";

                //first obtain the current userAccountControl value
                DirectoryEntry de = new DirectoryEntry(string.Format("LDAP://{0}/{1}", dirContext.DomainName, dirnode.DistinguishedName));
                int userCtrlInt = Convert.ToInt32(de.Properties["userAccountControl"].Value.ToString());
                long pwdLastSet = Convert.ToInt64(de.Properties["pwdLastSet"].Value.ToString());
                sUserWorkStations = de.Properties["userWorkstations"].Value as string;

                if (de.Properties["userPrincipalName"].Value != null)
                {
                    Logonname = de.Properties["userPrincipalName"].Value as string;
                    Logonname = Logonname.IndexOf('@') >= 0 ? Logonname.Substring(0, Logonname.IndexOf('@')) : Logonname;
                    txtlogon.Text = Logonname;
                }

                txtpreLogonname.Text = de.Properties["sAMAccountName"].Value as string;
                PreLogonname = txtpreLogonname.Text.Trim();

                txtDomian.Text = dirContext.DomainName.Substring(0, dirContext.DomainName.IndexOf('.')).ToUpper() + @"\";
                cbDomain.Items.Add(string.Concat("@", dirContext.DomainName.ToUpper()));
                cbDomain.SelectedIndex = 0;

                double accountExpires = Convert.ToInt64(de.Properties["accountExpires"].Value);

                if (accountExpires == 9223372036854775807)
                    rbNever.Checked = true;
                else
                {
                    rbEndOf.Checked = true;
                    ConvertFromUnixTimestamp(accountExpires);
                }
                try
                {
                    string userCtrlBinStr = UserGroupUtils.DecimalToBase(userCtrlInt, 2);

                    if (userCtrlBinStr.Length >= 10 && userCtrlBinStr[userCtrlBinStr.Length - 10] == '1')
                    {
                        bMustChangePwd = true;
                    }
                    if (userCtrlBinStr.Length >= 10 && userCtrlBinStr[userCtrlBinStr.Length - 2] == '1')
                    {
                        bAcountDisable = true;
                    }
                    if (userCtrlBinStr.Length >= 17 && userCtrlBinStr[userCtrlBinStr.Length - 17] == '1')
                    {
                        bNeverExpiresPwd = true;
                        bMustChangePwd = false;
                    }
                    if (userCtrlBinStr.Length >= 10 && userCtrlBinStr[userCtrlBinStr.Length - 7] == '1'
                        && pwdLastSet != 0)
                    {
                        bUserCannotChange = true;
                    }
                    if (userCtrlBinStr.Length >= 8 && userCtrlBinStr[userCtrlBinStr.Length - 8] == '1')
                    {
                        bStorePwd = true;
                    }
                    if (userCtrlBinStr.Length >= 19 && userCtrlBinStr[userCtrlBinStr.Length - 19] == '1')
                    {
                        bSmartCardRequired = true;
                    }
                    if (userCtrlBinStr.Length >= 21 && userCtrlBinStr[userCtrlBinStr.Length - 21] == '1')
                    {
                        bAccSensitive = true;
                    }
                    if (userCtrlBinStr.Length >= 22 && userCtrlBinStr[userCtrlBinStr.Length - 22] == '1')
                    {
                        bUseDESDescription = true;
                    }
                    if (userCtrlBinStr.Length >= 23 && userCtrlBinStr[userCtrlBinStr.Length - 23] == '1')
                    {
                        bNotKrbAuthentication = true;
                    }
                }
                catch
                {
                }

                FillUserOptions();

                dateTimePicker.Enabled = rbEndOf.Checked;

                this.ParentContainer.DataChanged = false;
                this.ParentContainer.btnApply.Enabled = false;
            }
            catch (Exception e)
            {
                Logger.LogException("UserAccountPage.SetData", e);
            }
        }
Ejemplo n.º 44
0
    /// <summary>
    /// List the all children for the selected distinguished name
    /// Adds the all children to the node
    /// </summary>
    public void ListChildren()
    {
        Logger.Log("ADUCDirectoryNode.ListChildren() called", Logger.ldapLogLevel);
        int ret = -1;

        if (haveRetrievedChildren && !this.IsModified)
        {
            return;
        }

        string[] attrList = new string[]
        {
            "dummy", 
            "objectClass", 
            "distinguishedName",
            "userAccountControl",
            null
        };

        ret = dirContext.ListChildEntriesSynchronous
        (distinguishedName,
        LdapAPI.LDAPSCOPE.ONE_LEVEL,
        "(objectClass=*)",
        attrList,
        false,
        out ldapEntries);

        if (ldapEntries == null || ldapEntries.Count == 0)
        {
            //clears the domian level node, if the ldap connection timed out or disconnected
            ADUCPlugin plugin = this.Plugin as ADUCPlugin;
            haveRetrievedChildren = true;
            this.IsModified = false;
            if (ret == (int)Likewise.LMC.Utilities.ErrorCodes.LDAPEnum.LDAP_SERVER_DOWN ||
            ret == (int)Likewise.LMC.Utilities.ErrorCodes.LDAPEnum.LDAP_CONNECT_ERROR ||
            ret == -1)
            {
                if (ret == -1)
                {
                    ret = (int)ErrorCodes.LDAPEnum.LDAP_TIMEOUT;
                    Logger.LogMsgBox(ErrorCodes.LDAPString(ret));
                }
                plugin._pluginNode.Nodes.Clear();
                this.sc.ShowControl(plugin._pluginNode);
            }
            else
            {
                Nodes.Clear();
            }

            return;
        }
        else if (IsModified)
        {
            Nodes.Clear();
        }

        DateTime timer = Logger.StartTimer();

        //The following is optimized for speed, taking into account that in Mono,
        //Nodes.Add() and Nodes.AddRange() both take a long time to complete.
        //Nodes.AddRange() does not offer much time savings over Nodes.Add()
        //Therefore, make two hashtables holding the new and old contents of the DN.
        //Determine which have been added, and which have been deleted, to minimize the number of calls
        //to Nodes.Add() and Nodes.Remove();
        Hashtable oldEntries = new Hashtable();
        Hashtable newEntries = new Hashtable();

        List<ADUCDirectoryNode> nodesToAdd = new List<ADUCDirectoryNode>();
        int nodesAdded = 0;

        foreach (TreeNode node in Nodes)
        {
            ADUCDirectoryNode dNode = (ADUCDirectoryNode)node;
            if (dNode != null && !String.IsNullOrEmpty(dNode.distinguishedName) &&
            !oldEntries.ContainsKey(dNode.distinguishedName))
            {
                oldEntries.Add(dNode.distinguishedName, dNode);
            }
        }

        foreach (LdapEntry ldapNextEntry in ldapEntries)
        {
            string currentDN = ldapNextEntry.GetDN();

            if (!String.IsNullOrEmpty(currentDN))
            {

                LdapValue[] values = ldapNextEntry.GetAttributeValues("objectClass", dirContext);
                string objectClass = "";
                if (values != null && values.Length > 0)
                {
                    objectClass = values[values.Length - 1].stringData;
                }

                bool IsDisabled = false;
                bool IsDc = false;
                if (objectClass.Equals("user", StringComparison.InvariantCultureIgnoreCase)
                || objectClass.Equals("computer", StringComparison.InvariantCultureIgnoreCase))
                {
                    values = ldapNextEntry.GetAttributeValues("userAccountControl", dirContext);
                    int userCtrlVal = 0;
                    if (values != null && values.Length > 0)
                    {
                        userCtrlVal = Convert.ToInt32(values[0].stringData);
                    }
                    if (userCtrlVal.Equals(8224) || userCtrlVal.Equals(8202) || userCtrlVal.Equals(532480))
                    {
                        IsDc = true;
                    }
                    string userCtrlBinStr = UserGroupUtils.DecimalToBase(userCtrlVal, 2);

                    //Determine whether this user is enabled or disabled
                    //examine the second to last position from the right (0=Active, 1=Inactive)
                    if (userCtrlBinStr.Length >= 2)
                    {
                        if (userCtrlBinStr[userCtrlBinStr.Length - 2] == '1')
                        {
                            IsDisabled = true;
                        }
                        else if (userCtrlBinStr[userCtrlBinStr.Length - 2] == '0')
                        {
                            IsDisabled = false;
                        }
                    }
                }

                ADUCDirectoryNode newNode = new ADUCDirectoryNode(currentDN, dirContext, objectClass,
                Resources.Group_16, NodeType, Plugin, IsDisabled);
                newNode.sc = this.sc;
                newNode._IsDomainController = IsDc;
                newNode.Text = newNode.Text.Substring(3);

                Logger.Log(String.Format("new Entry: {0}", currentDN), Logger.ldapLogLevel);

                newEntries.Add(currentDN, newNode);

                if (oldEntries.ContainsKey(currentDN))
                {
                    ADUCDirectoryNode oldNode = (ADUCDirectoryNode)oldEntries[currentDN];

                    if ((oldNode != null && oldNode.ObjectClass != objectClass)
                    ||
                    (oldNode != null && oldNode.IsDisabled != IsDisabled))
                    {
                        oldEntries.Remove(currentDN);
                        oldEntries.Add(currentDN, newNode);
                        Nodes.Remove(oldNode);
                        nodesToAdd.Add(newNode);
                        nodesAdded++;
                    }

                }
                else
                {
                    Logger.Log(String.Format("scheduling addition of new Entry: {0}", currentDN), Logger.ldapLogLevel);
                    nodesToAdd.Add(newNode);
                    nodesAdded++;
                }

            }
        }

        foreach (Object o in oldEntries.Keys)
        {
            string oldNodeKey = (string)o;

            Logger.Log(String.Format("old Entry: {0}", oldNodeKey));

            if (!String.IsNullOrEmpty(oldNodeKey) && !newEntries.ContainsKey(oldNodeKey))
            {
                ADUCDirectoryNode oldNode = (ADUCDirectoryNode)oldEntries[oldNodeKey];

                if (oldNode != null)
                {
                    Logger.Log(String.Format("removing old Entry: {0}", oldNodeKey), Logger.ldapLogLevel);

                    Nodes.Remove(oldNode);
                }
            }
        }

        ADUCDirectoryNode[] nodesToAddRecast = new ADUCDirectoryNode[nodesAdded];
        try
        {
            nodesToAdd.Sort(delegate(ADUCDirectoryNode d1, ADUCDirectoryNode d2)
            {
                return d1.Text.CompareTo(d2.Text);
            }
            );
            for (int i = 0; i < nodesAdded; i++)
            {
                nodesToAddRecast[i] = nodesToAdd[i];
            }
        }
        catch (Exception)
        {
        }

        Nodes.AddRange(nodesToAddRecast);

        Logger.TimerMsg(ref timer, String.Format("DirectoryNode.ListChildren(): Entry Processing({0})", distinguishedName));
        this.IsModified = false;
        haveRetrievedChildren = true;
    }
Ejemplo n.º 45
0
        /// <summary>
        /// Queries and fills the ldap message for the selected computer
        /// Gets the attribute list from AD for computer schema attribute.
        /// search for the attributes dNSHostName, cn or name and displays them in a controls
        /// </summary>
        /// <param name="ce"></param>
        /// <param name="servername"></param>
        /// <param name="name"></param>
        /// <param name="dirnode"></param>
        public void SetData(CredentialEntry ce, string servername, string name, ADUCDirectoryNode dirnode)
        {
            try
            {
                this.dirnode = dirnode;
                int ret = -1;
                List<LdapEntry> ldapEntries = null;

                ret = dirnode.LdapContext.ListChildEntriesSynchronous
                (dirnode.DistinguishedName,
                LdapAPI.LDAPSCOPE.BASE,
                "(objectClass=*)",
                null,
                false,
                out ldapEntries);

                if (ldapEntries == null || ldapEntries.Count == 0)
                {
                    return;
                }

                LdapEntry ldapNextEntry = ldapEntries[0];

                string[] attrsList = ldapNextEntry.GetAttributeNames();

                if (attrsList != null)
                {
                    foreach (string attr in attrsList)
                    {
                        string sValue = "";

                        LdapValue[] attrValues = ldapNextEntry.GetAttributeValues(attr, dirnode.LdapContext);

                        if (attrValues != null && attrValues.Length > 0)
                        {
                            foreach (LdapValue value in attrValues)
                            {
                                sValue = sValue + "," + value.stringData;
                            }
                        }

                        if (sValue.StartsWith(","))
                        {
                            sValue = sValue.Substring(1);
                        }

                        sValue = sValue.Substring(0, sValue.Length);

                        if (string.Compare(sValue, "") == 0)
                        {
                            sValue = "<Not Set>";
                        }

                        if (string.Compare(attr, "operatingSystem") == 0)
                        {
                            txtName.Text = sValue;
                            operatingSystem = txtName.Text.Trim();
                        }

                        if (string.Compare(attr, "operatingSystemServicePack") == 0)
                        {
                            txtServicePack.Text = sValue;
                            operatingSystemServicePack = txtServicePack.Text.Trim();
                        }

                        if (string.Compare(attr, "operatingSystemVersion") == 0)
                        {
                            txtVersion.Text = sValue;
                            operatingSystemVersion = txtVersion.Text.Trim();
                        }
                    }
                }
                this.ParentContainer.DataChanged = false;
                UpdateApplyButton();
            }
            catch (Exception e)
            {
                container.ShowError(e.Message);
            }
        }
Ejemplo n.º 46
0
    /// <summary>
    /// Method to load data to the tab pages while loading
    /// Gets the all attribute list for the selected AD object by querying the Ldap Message.
    /// </summary>
    /// <param name="ce"></param>
    /// <param name="servername"></param>
    /// <param name="username"></param>
    /// <param name="dirNode"></param
    public void SetData(CredentialEntry ce, string servername, string username, ADUCDirectoryNode dirNode)
    {
        try
        {
            dirnode = dirNode;
            InitLdapMessage();
            schemaCache = dirnode.LdapContext.SchemaCache;

            if (objectClasses != null && objectClasses.Length != 0)
            {
                MandatoryAttributes = new List<string>();
                foreach (string objectClass in objectClasses)
                {
                    LdapClassType classtype = schemaCache.GetSchemaTypeByObjectClass(objectClass) as LdapClassType;
                    if (classtype != null && classtype.MandatoryAttributes != null)
                    {
                        foreach (string attr in classtype.MandatoryAttributes)
                        {
                            MandatoryAttributes.Add(attr);
                        }
                    }
                }
                if (dirnode.ObjectClass.Trim().Equals("user", StringComparison.InvariantCultureIgnoreCase) ||
                    dirnode.ObjectClass.Trim().Equals("group", StringComparison.InvariantCultureIgnoreCase) ||
                    dirnode.ObjectClass.Trim().Equals("computer", StringComparison.InvariantCultureIgnoreCase))
                {
                    MandatoryAttributes.Add("objectSid");
                    MandatoryAttributes.Add("sAMAccountName");
                    if (!MandatoryAttributes.Contains("cn"))
                    {
                        MandatoryAttributes.Add("cn");
                    }
                }
            }

            FillAttributeList(true, out _modifiedPageObject);
            ParentContainer.DataChanged = false;
            if (_modifiedPageObject != null)
            {
                _OriginalPageObject = (ADEditPageObject)_modifiedPageObject.Clone();
            }
            else
            {
                _OriginalPageObject = new ADEditPageObject();
            }
            UpdateApplyButton();
        }
        catch (Exception e)
        {
            Logger.LogException("ADEditPage.SetData", e);
        }
    }
Ejemplo n.º 47
0
    /// <summary>
    /// Gets all groups for the selected user AD Object is member of
    /// Add groups to the Member Of page listview
    /// </summary>
    /// <param name="ce"></param>
    /// <param name="servername"></param>
    /// <param name="name"></param>
    /// <param name="dirnode"></param>
    public void SetData(CredentialEntry ce, string servername, string name, ADUCDirectoryNode dirnode)
    {
        _servername = servername;
        _dirnode = dirnode;

        try
        {
            string[] groupDns = UserGroupUtils.GetGroupsforUser(dirnode);

            MemoflistView.Items.Clear();
            //show a list of group names in the member of page
            Logger.Log("user member of contains: ");
            if (groupDns != null && groupDns.Length > 0)
            {
                //populate the data in usermemberOf page using groupDns
                foreach (string groupDn in groupDns)
                {
                    Logger.Log("group: " + groupDn);
                    //CN=Domain Users,CN=Users,DC=qadom,DC=centeris,DC=com
                    // split the groupDns
                    string[] slvItem = UserGroupUtils.splitDn(groupDn);
                    string sLDAPPath = string.Format("LDAP://{0}/{1}", _dirnode.LdapContext.DomainName, groupDn);
                    DirectoryEntry entry = new DirectoryEntry(sLDAPPath, _dirnode.LdapContext.UserName, _dirnode.LdapContext.Password);
                    if (entry == null)
                    {
                        return;
                    }
                    ListViewItem lvItem = new ListViewItem(slvItem);
                    lvItem.ImageIndex = MemOfPages.GetIndexForADObject(entry);
                    MemoflistView.Items.Add(lvItem);
                    lvItem.Tag = groupDn;

                    if (!slvItem[0].Equals("Domain Users", StringComparison.InvariantCultureIgnoreCase))
                    {
                        MemofDnList.Add(groupDn);
                    }
                }
                //settings primary group to user
                sPrimayGroup = UserGroupUtils.GetPrimaryGroup(_dirnode);
                string[] Items = UserGroupUtils.splitDn(sPrimayGroup);
                if (!string.IsNullOrEmpty(Items[0]))
                {
                    DomainUserlabel.Text = Items[0];
                }

                if (MemoflistView.Items.Count > 0)
                {
                    MemoflistView.Items[0].Selected = true;
                }
            }
        }
        catch (Exception ex)
        {
            Logger.LogException("UserMemberOfPage.SetData", ex);
        }
    }
Ejemplo n.º 48
0
    private void MemoflistView_MouseDoubleClick(object sender, MouseEventArgs e)
    {
        if (MemoflistView.SelectedItems.Count > 0)
        {
            ListViewItem selectedItem = MemoflistView.SelectedItems[0];
            if (selectedItem.Tag != null)
            {
                string distinguishedName = selectedItem.Tag.ToString();
                if (distinguishedName.Equals(_dirnode.DistinguishedName, StringComparison.InvariantCultureIgnoreCase))
                {
                    return;
                }
                ADUCPlugin plugin = _dirnode.Plugin as ADUCPlugin;
                if (plugin.Propertywindowhandles.ContainsKey(distinguishedName))
                {
                    Form f = plugin.Propertywindowhandles[distinguishedName] as Form;
                    f.BringToFront();
                    return;
                }

                string sLDAPPath = string.Format("LDAP://{0}/{1}", _dirnode.LdapContext.DomainName, distinguishedName);
                DirectoryEntry entry = new DirectoryEntry(sLDAPPath);
                if (entry == null)
                {
                    return;
                }

                object[] asProp = entry.Properties["objectClass"].Value as object[];

                // poke these in a list for easier reference
                List<string> liClasses = new List<string>();
                foreach (string s in asProp)
                {
                    liClasses.Add(s);
                }

                if (liClasses.Contains("computer"))
                {
                    ADUCDirectoryNode dirnode = new ADUCDirectoryNode(distinguishedName,
                    _dirnode.LdapContext, "computer",
                    Properties.Resources.computer, _dirnode.t, _dirnode.Plugin, _dirnode.IsDisabled);
                    ADComputerPropertiesDlg f = new ADComputerPropertiesDlg(base.container, _dirnode.PluginPage as ADUCPage, _plugin);
                    if (_dirnode.LdapContext.SchemaCache != null)
                    {
                        f.SetData(_plugin.HostInfo.creds, _plugin.HostInfo.hostName, dirnode.Text.Substring(3), dirnode, _dirnode.LdapContext.SchemaCache);
                        f.Show();
                    }
                }
                else if (liClasses.Contains("user"))
                {
                    ADUCDirectoryNode dirnode = new ADUCDirectoryNode(distinguishedName,
                    _dirnode.LdapContext, "user",
                    Properties.Resources.User, _dirnode.t, _dirnode.Plugin, _dirnode.IsDisabled);

                    List<object> dirnodes = new List<object>();
                    dirnodes.Add(dirnode);
                    ADUserPropertiesDlg f = new ADUserPropertiesDlg(base.container, _dirnode.PluginPage as ADUCPage, _plugin, dirnodes);
                    if (_dirnode.LdapContext.SchemaCache != null)
                    {
                        f.SetData(_plugin.HostInfo.creds, _plugin.HostInfo.hostName, dirnode.Text.Substring(3), dirnode, _dirnode.LdapContext.SchemaCache);
                        f.Show();
                    }
                }
                else if (liClasses.Contains("group"))
                {
                    ADUCDirectoryNode dirnode = new ADUCDirectoryNode(distinguishedName,
                    _dirnode.LdapContext, "group",
                    Properties.Resources.Group_48, _dirnode.t, _dirnode.Plugin, _dirnode.IsDisabled);
                    ADGroupPropertiesDlg f = new ADGroupPropertiesDlg(base.container, _dirnode.PluginPage as ADUCPage, _plugin, dirnode);
                    if (_dirnode.LdapContext.SchemaCache != null)
                    {
                        f.SetData(_plugin.HostInfo.creds, _plugin.HostInfo.hostName, dirnode.Text.Substring(3), dirnode, _dirnode.LdapContext.SchemaCache);
                        f.Show();
                    }
                }
                else if (liClasses.Contains("foreignSecurityPrincipal"))
                {
                    ADUCDirectoryNode dirnode = new ADUCDirectoryNode(distinguishedName,
                    _dirnode.LdapContext, "foreignSecurityPrincipal",
                    Properties.Resources.Group_48, _dirnode.t, _dirnode.Plugin, _dirnode.IsDisabled);
                    ADGroupPropertiesDlg f = new ADGroupPropertiesDlg(base.container, _dirnode.PluginPage as ADUCPage, _plugin, dirnode);
                    if (_dirnode.LdapContext.SchemaCache != null)
                    {
                        f.SetData(_plugin.HostInfo.creds, _plugin.HostInfo.hostName, dirnode.Text.Substring(3), dirnode, _dirnode.LdapContext.SchemaCache);
                        f.Show();
                    }
                }
            }
        }
    }
        /// <summary>
        /// Queries and fills the ldap message for the selected User
        /// Gets the attribute list from AD for User schema attribute.
        /// search for the attributes givenName, displayName, sAMAccountName,
        /// memberOf, sAMAccountType, userPrincipalName, sn and displays them in a controls
        /// </summary>
        /// <param name="ce"></param>
        /// <param name="servername"></param>
        /// <param name="name"></param>
        /// <param name="dirnode"></param>
        public void SetData(CredentialEntry ce, string servername, string name, ADUCDirectoryNode dirnode)
        {
            try
            {
                this.dirnode = dirnode;
                SetControlStatus();

                int iOuCount = 0; int iUserCount = 0; int iCompCount = 0; int iGroupCount = 0; int iContactCount = 0;
                int iOtherCount = 0; int iTotalSummary = 0;

                foreach (ADUCDirectoryNode dn in this.parentDlg.ObjectCounts)
                {
                    if (dn != null)
                    {
                        if (dn.ObjectClass.Trim().Equals("OrganizationalUnit", StringComparison.InvariantCultureIgnoreCase))
                        {
                            iOuCount++;
                        }
                        else if (dn.ObjectClass.Trim().Equals("user", StringComparison.InvariantCultureIgnoreCase))
                        {
                            iUserCount++;
                        }
                        else if (dn.ObjectClass.Trim().Equals("group", StringComparison.InvariantCultureIgnoreCase))
                        {
                            iGroupCount++;
                        }
                        else if (dn.ObjectClass.Trim().Equals("computer", StringComparison.InvariantCultureIgnoreCase))
                        {
                            iCompCount++;
                        }
                        else if (dn.ObjectClass.Trim().Equals("contact", StringComparison.InvariantCultureIgnoreCase))
                        {
                            iContactCount++;
                        }
                        else
                        {
                            iOtherCount++;
                        }
                    }
                }
                if (iOuCount != 0)
                {
                    lblOUs.Show();
                    lblOUs.Text = iOuCount.ToString();
                    iTotalSummary += iOuCount;
                }
                if (iUserCount != 0)
                {
                    lblUsers.Show();
                    iTotalSummary += iUserCount;
                    lblUsers.Text = iUserCount.ToString();
                }
                if (iGroupCount != 0)
                {
                    lblGroups.Show();
                    iTotalSummary += iGroupCount;
                    lblGroups.Text = iGroupCount.ToString();
                }
                if (iCompCount != 0)
                {
                    lblComputers.Show();
                    iTotalSummary += iCompCount;
                    lblComputers.Text = iCompCount.ToString();
                }
                if (iContactCount != 0)
                {
                    lblContacts.Show();
                    iTotalSummary += iContactCount;
                    lblContacts.Text = iContactCount.ToString();
                }
                if (iOtherCount != 0)
                {
                    lblOthers.Show();
                    iTotalSummary += iOtherCount;
                    lblOthers.Text = iOtherCount.ToString();
                }
                lblSummary.Text = iTotalSummary.ToString();
            }
            catch (Exception e)
            {
                Logger.LogException("MultiItemsGeneralEditPage.SetData", e);
            }
        }
Ejemplo n.º 50
0
 public static ADUCDirectoryNode GetDirectoryRoot(DirectoryContext dirCtx, string DistinguishedName, Icon image, Type t, IPlugIn plugin)
 {
     if (dirCtx == null)
     {
         Logger.LogMsgBox("DirectoryNode.GetDirectoryRoot(): dirCtx == null");
         return null;
     }
     
     ADUCDirectoryNode dn = new ADUCDirectoryNode(DistinguishedName,
     dirCtx, "container", image, t, plugin, false);
     
     return dn;
 }
 /// <summary>
 /// Queries and fills the ldap message for the selected User
 /// Gets the attribute list from AD for User schema attribute.
 /// search for the attributes givenName, displayName, sAMAccountName,
 /// memberOf, sAMAccountType, userPrincipalName, sn and displays them in a controls
 /// </summary>
 /// <param name="ce"></param>
 /// <param name="servername"></param>
 /// <param name="name"></param>
 /// <param name="dirnode"></param>
 public void SetData(CredentialEntry ce, string servername, string name, ADUCDirectoryNode dirnode)
 {
     try
     {
         int ret = -1;
         _editObject = new UserGenerelEditObject();
         this.dirnode = dirnode;
         
         List<LdapEntry> ldapEntries = null;
         
         ret = dirnode.LdapContext.ListChildEntriesSynchronous(
         dirnode.DistinguishedName,
         LdapAPI.LDAPSCOPE.BASE,
         "(objectClass=*)",
         null,
         false,
         out ldapEntries);
         
         if (ldapEntries == null || ldapEntries.Count == 0)
         {
             return;
         }
         
         LdapEntry ldapNextEntry = ldapEntries[0];
         
         string[] attrsList = ldapNextEntry.GetAttributeNames();
         
         if (attrsList != null)
         {
             foreach (string attr in attrsList)
             {
                 string sValue = "";
                 
                 LdapValue[] attrValues = ldapNextEntry.GetAttributeValues(attr, dirnode.LdapContext);
                 
                 if (attrValues != null && attrValues.Length > 0)
                 {
                     foreach (LdapValue value in attrValues)
                     {
                         sValue = sValue + "," + value.stringData;
                     }
                 }
                 
                 if (sValue.StartsWith(","))
                 {
                     sValue = sValue.Substring(1);
                 }
                 if (string.Compare(sValue, "") == 0)
                 {
                     sValue = "<Not Set>";
                 }
                 
                 if (string.Compare(attr, "cn") == 0)
                 {
                     this.lblUserName.Text = sValue;
                 }
                 
                 if (string.Compare(attr, "givenName") == 0)
                 {
                     this.FnametextBox.Text = sValue;
                     _editObject.FirstName = sValue;
                 }
                 
                 if (string.Compare(attr, "initials") == 0)
                 {
                     this.InitialTextBox.Text = sValue;
                     _editObject.Initails = sValue;
                 }
                 
                 if (string.Compare(attr, "sn") == 0)
                 {
                     this.LnametextBox.Text = sValue;
                     _editObject.LastName = sValue;
                 }
                 
                 if (string.Compare(attr, "displayName") == 0)
                 {
                     this.DisplayNametextBox.Text = sValue;
                     _editObject.DisplayName = sValue;
                 }
                 
                 if (string.Compare(attr, "description") == 0)
                 {
                     this.DescriptextBox.Text = sValue;
                     _editObject.Description = sValue;
                 }
                 
                 if (string.Compare(attr, "physicalDeliveryOfficeName") == 0)
                 {
                     this.OfficetextBox.Text = sValue;
                     _editObject.Office = sValue;
                 }
                 
                 if (string.Compare(attr, "telephoneNumber") == 0)
                 {
                     this.TelephonetextBox.Text = sValue;
                     _editObject.TelephoneNumber = sValue;
                 }
                 
                 if (string.Compare(attr, "mail") == 0)
                 {
                     this.emailtextBox.Text = sValue;
                     _editObject.Email = sValue;
                 }
                 
                 if (string.Compare(attr, "wWWHomePage") == 0)
                 {
                     this.webpagetextBox.Text = sValue;
                     _editObject.WebPage = sValue;
                 }
                 if (string.Compare(attr, "url") == 0)
                 {
                     _editObject.WebPageOther = sValue;
                 }
                 if (string.Compare(attr, "otherTelephone") == 0)
                 {
                     sValue = sValue.Replace(',', ';');
                     _editObject.TelephoneNumberOther = sValue;
                 }
             }
         }
         
         if (_editObject != null)
         {
             _originalObject = (UserGenerelEditObject)_editObject.Clone();
         }
         else
         {
             _originalObject = new UserGenerelEditObject();
         }
         ParentContainer.DataChanged = false;
         UpdateApplyButton();
     }
     catch (Exception e)
     {
         Logger.LogException("UserGeneralEditPage.SetData", e);
     }
 }
Ejemplo n.º 52
0
    /// <summary>
    /// List the all children for the selected distinguished name
    /// Adds the all children to the node
    /// </summary>
    public ADUCDirectoryNode[] ListContainerChildren(ADUCDirectoryNode dnode)
    {
        Logger.Log("DirectoryNode.ListChildren() called", Logger.ldapLogLevel);
        int ret = -1;

        if (haveRetrievedChildren && !this.IsModified)
        {
            return null;
        }

        string[] attrList = new string[]
        {
            "dummy",
            "objectClass",
            "distinguishedName",
            "userAccountControl",
            null
        };

        string ObjectClassFilters = "(|(objectClass=container)(objectClass=organizationalUnit)(objectClass=infrastructureUpdate)(objectClass=builtinDomain)(objectClass=LostAndFound))";

        ret = dirContext.ListChildEntriesSynchronous
        (distinguishedName,
        LdapAPI.LDAPSCOPE.ONE_LEVEL,
        ObjectClassFilters,
        attrList,
        false,
        out ldapEntries);

        if (ldapEntries == null || ldapEntries.Count == 0)
        {
            //clears the domian level node, if the ldap connection timed out or disconnected
            ADUCPlugin plugin = this.Plugin as ADUCPlugin;
            haveRetrievedChildren = true;
            this.IsModified = false;
            if (ret == (int)Likewise.LMC.Utilities.ErrorCodes.LDAPEnum.LDAP_SERVER_DOWN ||
            ret == (int)Likewise.LMC.Utilities.ErrorCodes.LDAPEnum.LDAP_CONNECT_ERROR ||
            ret == -1)
            {
                if (ret == -1)
                {
                    ret = (int)ErrorCodes.LDAPEnum.LDAP_TIMEOUT;
                    Logger.LogMsgBox(ErrorCodes.LDAPString(ret));
                }
                plugin._pluginNode.Nodes.Clear();
                this.sc.ShowControl(plugin._pluginNode);
            }
            else
            {
                Nodes.Clear();
            }

            return null;
        }

        DateTime timer = Logger.StartTimer();

        //The following is optimized for speed, taking into account that in Mono,
        //Nodes.Add() and Nodes.AddRange() both take a long time to complete.
        //Nodes.AddRange() does not offer much time savings over Nodes.Add()
        //Therefore, make two hashtables holding the new and old contents of the DN.
        //Determine which have been added, and which have been deleted, to minimize the number of calls
        //to Nodes.Add() and Nodes.Remove();
        Hashtable oldEntries = new Hashtable();
        Hashtable newEntries = new Hashtable();

        List<ADUCDirectoryNode> nodesToAdd = new List<ADUCDirectoryNode>();
        int nodesAdded = 0;

        foreach (TreeNode node in Nodes)
        {
            ADUCDirectoryNode dNode = (ADUCDirectoryNode)node;
            if (dNode != null && !String.IsNullOrEmpty(dNode.distinguishedName) &&
            !oldEntries.ContainsKey(dNode.distinguishedName))
            {
                oldEntries.Add(dNode.distinguishedName, dNode);
            }
        }

        foreach (LdapEntry ldapNextEntry in ldapEntries)
        {
            string currentDN = ldapNextEntry.GetDN();

            if (!String.IsNullOrEmpty(currentDN))
            {
                LdapValue[] values = ldapNextEntry.GetAttributeValues("objectClass", dirContext);
                string objectClass = "";
                if (values != null && values.Length > 0)
                {
                    objectClass = values[values.Length - 1].stringData;
                }

                ADUCDirectoryNode newNode = new ADUCDirectoryNode(currentDN, dirContext, objectClass,
                Resources.Group_16, NodeType, Plugin, IsDisabled);
                newNode.sc = this.sc;
                newNode.Text = newNode.Text.Substring(3);

                Logger.Log(String.Format("new Entry: {0}", currentDN), Logger.ldapLogLevel);

                newEntries.Add(currentDN, newNode);

                if (oldEntries.ContainsKey(currentDN))
                {
                    ADUCDirectoryNode oldNode = (ADUCDirectoryNode)oldEntries[currentDN];

                    if ((oldNode != null && oldNode.ObjectClass != objectClass)
                    ||
                    (oldNode != null && oldNode.IsDisabled != IsDisabled))
                    {
                        oldEntries.Remove(currentDN);
                        oldEntries.Add(currentDN, newNode);
                        Nodes.Remove(oldNode);
                        nodesToAdd.Add(newNode);
                        nodesAdded++;
                    }
                }
                else
                {
                    Logger.Log(String.Format("scheduling addition of new Entry: {0}", currentDN), Logger.ldapLogLevel);
                    nodesToAdd.Add(newNode);
                    nodesAdded++;
                }
            }
        }

        foreach (Object o in oldEntries.Keys)
        {
            string oldNodeKey = (string)o;

            Logger.Log(String.Format("old Entry: {0}", oldNodeKey));

            if (!String.IsNullOrEmpty(oldNodeKey) && !newEntries.ContainsKey(oldNodeKey))
            {
                ADUCDirectoryNode oldNode = (ADUCDirectoryNode)oldEntries[oldNodeKey];

                if (oldNode != null)
                {
                    Logger.Log(String.Format("removing old Entry: {0}", oldNodeKey), Logger.ldapLogLevel);

                    Nodes.Remove(oldNode);
                }
            }
        }

        ADUCDirectoryNode[] nodesToAddRecast = new ADUCDirectoryNode[nodesAdded];

        try
        {
            nodesToAdd.Sort(delegate(ADUCDirectoryNode d1, ADUCDirectoryNode d2)
            {
                return d1.Text.CompareTo(d2.Text);
            }
            );
            for (int i = 0; i < nodesAdded; i++)
            {
                nodesToAddRecast[i] = nodesToAdd[i];
            }
        }
        catch (Exception)
        {
        }
        Logger.TimerMsg(ref timer, String.Format("DirectoryNode.ListChildren(): Entry Processing({0})", distinguishedName));
        this.IsModified = false;
        haveRetrievedChildren = true;

        return nodesToAddRecast;
    }
Ejemplo n.º 53
0
    /// <summary>
    /// Modifies the "member" attribute for the selected "user" or "group" in AD schema template
    /// </summary>
    /// <param name="changedGroups"></param>
    /// <param name="_dirnode"></param>
    /// <param name="page"></param>
    /// <param name="operation"></param>
    /// <returns></returns>
    private static bool OnApply_inner(List<string> changedGroups, ADUCDirectoryNode _dirnode, MPPage page, int operation)
    {
        bool retVal = true;
        int ret = -1;
        string AdminGroupDN = string.Concat("CN=Administrators,CN=Builtin,", _dirnode.LdapContext.RootDN);

        if (changedGroups != null && changedGroups.Count > 0)
        {
            foreach (string newGroupname in changedGroups)
            {
                List<string> members = new List<string>();
                members = GetMemberAttrofGroup(newGroupname.Trim(), _dirnode);

                bool existingMember = false;

                //if we want to add, we need check whether it is already a member of the group
                if (operation == ADDING)
                {
                    foreach (string str in members)
                    {
                        if (str.Equals(_dirnode.DistinguishedName, StringComparison.InvariantCultureIgnoreCase))
                        {
                            existingMember = true;
                            break;
                        }
                    }
                }

                if (!existingMember)
                {
                    if (operation == ADDING)
                    {
                        members.Add(_dirnode.DistinguishedName);
                    }
                    if (operation == REMOVING)
                    {
                        members.Remove(_dirnode.DistinguishedName);
                    }

                    if (newGroupname.Trim().ToLower().Equals(AdminGroupDN.Trim().ToLower()))
                    {
                        string userlogonName = OnApply_GetObjectRealmName(_dirnode);
                        LUGAPI.NetAddGroupMember(_dirnode.LdapContext.DomainControllerName, "Administrators", userlogonName);
                    }
                    else
                    {
                        string[] members_values = new string[members.Count + 1];
                        members.CopyTo(members_values);
                        members_values[members.Count] = null;

                        LDAPMod memberattr_Info =
                        new LDAPMod((int)LDAPMod.mod_ops.LDAP_MOD_REPLACE, "member",
                        members_values);

                        LDAPMod[] attrinfo = new LDAPMod[] { memberattr_Info };

                        if (_dirnode != null)
                        {
                            ret = _dirnode.LdapContext.ModifySynchronous(newGroupname.Trim(), attrinfo);

                            if (ret == 0)
                            {
                                retVal = true;
                            }
                            else
                            {
                                string sMsg = ErrorCodes.LDAPString(ret);
                                MessageBox.Show(page, sMsg, "Likewise Management Console",
                                MessageBoxButtons.OK);
                                retVal = false;
                            }
                        }
                    }
                }
            }
            if (ret == 0)
            {
                if (operation == ADDING)
                {
                    MessageBox.Show(
                    page,
                    "User/Computer/Group list is added to new groups!",
                    CommonResources.GetString("Caption_Console"),
                    MessageBoxButtons.OK);
                }
                if (operation == REMOVING)
                {
                    MessageBox.Show(
                    page,
                    "User/Computer/Group list is removed from chose groups!",
                    CommonResources.GetString("Caption_Console"),
                    MessageBoxButtons.OK);
                }
            }
        }
        return retVal;
    }
Ejemplo n.º 54
0
 /// <summary>
 /// Getting added all children to the selected node that are of type ObjectClass="group"
 /// , ObjectClass="user", ObjectClass="computer", ObjectClass="organizationalUnit"
 /// </summary>
 public void ListGroupAndUserOUChildren()
 {
     int ret = -1;
     
     if (haveRetrievedChildren && !this.IsModified)
     {
         return;
     }
     
     string[] attrs = { "objectClass", "distinguishedName", null };
     
     DateTime start = DateTime.Now;
     
     ret = dirContext.ListChildEntriesSynchronous
     (distinguishedName,
     LdapAPI.LDAPSCOPE.ONE_LEVEL,
     "(objectClass=*)",
     attrs,
     false,
     out ldapEntries);
     
     if (ldapEntries == null || ldapEntries.Count == 0)
     {
         //haveRetrievedChildren = true;
         //return;
         
         //clears the domian level node, if the ldap connection timed out or disconnected
         ADUCPlugin plugin = this.Plugin as ADUCPlugin;
         haveRetrievedChildren = true;
         this.IsModified = false;
         if (ret == (int)Likewise.LMC.Utilities.ErrorCodes.LDAPEnum.LDAP_SERVER_DOWN ||
         ret == (int)Likewise.LMC.Utilities.ErrorCodes.LDAPEnum.LDAP_CONNECT_ERROR ||
         ret == -1)
         {
             if (ret == -1)
             {
                 ret = (int)ErrorCodes.LDAPEnum.LDAP_TIMEOUT;
                 Logger.LogMsgBox(ErrorCodes.LDAPString(ret));
             }
             plugin._pluginNode.Nodes.Clear();
             this.sc.ShowControl(plugin._pluginNode);
         }
         else
         {
             Nodes.Clear();
         }
         
         return;
     }
     
     foreach (LdapEntry ldapNextEntry in ldapEntries)
     {
         string s = ldapNextEntry.GetDN();
         string objectClass = "";
         
         LdapValue[] values = ldapNextEntry.GetAttributeValues("objectClass", dirContext);
         if (values != null && values.Length > 0)
         {
             //use the most specific object Class, which will be listed last.
             objectClass = values[values.Length - 1].stringData;
             
             Logger.Log("Start--", Logger.ldapLogLevel);
             for (int i = 0; i < values.Length; i++)
             {
                 Logger.Log("objectclass is " + values[i], Logger.ldapLogLevel);
             }
             Logger.Log("End--", Logger.ldapLogLevel);
         }
         
         if (objectClass.Equals("group", StringComparison.InvariantCultureIgnoreCase))
         {
             
             ADUCDirectoryNode dtn = new ADUCDirectoryNode(s, dirContext, objectClass,
             Resources.Group_16, NodeType, Plugin, false);
             dtn.sc = this.sc;
             Nodes.Add(dtn);
         }
         
         bool IsDisabled = false;
         bool IsDc = false;
         if (objectClass.Equals("user", StringComparison.InvariantCultureIgnoreCase)
         || objectClass.Equals("computer", StringComparison.InvariantCultureIgnoreCase))
         {
             values = ldapNextEntry.GetAttributeValues("userAccountControl", dirContext);
             int userCtrlVal = 0;
             if (values != null && values.Length > 0)
             {
                 userCtrlVal = Convert.ToInt32(values[0].stringData);
             }
             if (userCtrlVal.Equals(8224) || userCtrlVal.Equals(8202) || userCtrlVal.Equals(532480))
             {
                 IsDc = true;
             }
             string userCtrlBinStr = UserGroupUtils.DecimalToBase(userCtrlVal, 2);
             
             //Determine whether this user is enabled or disabled
             //examine the second to last position from the right (0=Active, 1=Inactive)
             if (userCtrlBinStr.Length >= 2)
             {
                 if (userCtrlBinStr[userCtrlBinStr.Length - 2] == '1')
                 {
                     IsDisabled = true;
                 }
                 else if (userCtrlBinStr[userCtrlBinStr.Length - 2] == '0')
                 {
                     IsDisabled = false;
                 }
             }
             
             ADUCDirectoryNode dtn = new ADUCDirectoryNode(s, dirContext, objectClass,
             Resources.Group_16, NodeType, Plugin, IsDisabled);
             dtn.sc = this.sc;
             dtn._IsDomainController = IsDc;
             Nodes.Add(dtn);
         }
         
         
         if (objectClass.Equals("organizationalUnit", StringComparison.InvariantCultureIgnoreCase))
         {
             
             ADUCDirectoryNode dtn = new ADUCDirectoryNode(s, dirContext, objectClass,
             Resources.Group_16, NodeType, Plugin,false);
             dtn.sc = this.sc;
             Nodes.Add(dtn);
         }
     }
     haveRetrievedChildren = true;
 }
Ejemplo n.º 55
0
    public static bool OnApply_helper(List<string> MemofDnList, List<string> AddedGroups, List<string> RemovedGroups, ADUCDirectoryNode _dirnode, MPPage page)
    {
        bool retVal = true;

        if (MemofDnList != null && MemofDnList.Count > 0)
        {
            retVal = OnApply_inner(AddedGroups, _dirnode, page, ADDING);
            if (!retVal)
            {
                return retVal;
            }
            retVal = OnApply_inner(RemovedGroups, _dirnode, page, REMOVING);
            if (AddedGroups != null && AddedGroups.Count > 0)
            {
                AddedGroups.Clear();
            }
            if (RemovedGroups != null && RemovedGroups.Count > 0)
            {
                RemovedGroups.Clear();
            }
        }
        return retVal;
    }
Ejemplo n.º 56
0
 /// <summary>
 /// initializes the Directory node DistinguishedName with DistinguishedName Dn for the selected AD Object
 /// </summary>
 /// <param name="dirnode"></param>
 /// <param name="objectClass"></param>
 /// <param name="newDn"></param>
 public ADUCDirectoryNode(ADUCDirectoryNode dirnode, string objectClass, string newDn)
 {
     this.distinguishedName = newDn;
     this.dirContext = dirnode.dirContext;
     
     _objectClass = objectClass;      
     this._IsDisabled = dirnode.IsDisabled;
     
     if (!dirnode.distinguishedName.StartsWith("DC=", StringComparison.InvariantCultureIgnoreCase))
     {
         string[] parts = dirnode.distinguishedName.Split(',');
         if (parts.Length > 0)
         {
             Text = parts[0];
         }
     }
     
     if (_IsDisabled && _objectClass.Equals("user", StringComparison.InvariantCultureIgnoreCase))
     {
         objectClass = "disabledUser";
     }
     else if (_IsDisabled && _objectClass.Equals("computer", StringComparison.InvariantCultureIgnoreCase))
     {
         objectClass = "disabledComputer";
     }
     
     ImageIndex = (int)GetNodeType(objectClass);
     SelectedImageIndex = (int)GetNodeType(objectClass);
     
 }
Ejemplo n.º 57
0
 /// <summary>
 /// Getting added all children to the selected node that are of type ObjectClass="group"
 /// </summary>
 public void ListGroupOUChildren()
 {
     
     int ret = -1;
     
     if (haveRetrievedChildren && !this.IsModified)
     {
         return;
     }
     
     string[] attrs = { "objectClass", "distinguishedName", null };
     
     DateTime start = DateTime.Now;
     
     ret = dirContext.ListChildEntriesSynchronous
     (distinguishedName,
     LdapAPI.LDAPSCOPE.ONE_LEVEL,
     "(objectClass=*)",
     attrs,
     false,
     out ldapEntries);
     
     if (ldapEntries == null || ldapEntries.Count == 0)
     {
         //haveRetrievedChildren = true;
         //return;
         
         //clears the domian level node, if the ldap connection timed out or disconnected
         ADUCPlugin plugin = this.Plugin as ADUCPlugin;
         haveRetrievedChildren = true;
         this.IsModified = false;
         if (ret == (int)Likewise.LMC.Utilities.ErrorCodes.LDAPEnum.LDAP_SERVER_DOWN ||
         ret == (int)Likewise.LMC.Utilities.ErrorCodes.LDAPEnum.LDAP_CONNECT_ERROR ||
         ret == -1)
         {
             if (ret == -1)
             {
                 ret = (int)ErrorCodes.LDAPEnum.LDAP_TIMEOUT;
                 Logger.LogMsgBox(ErrorCodes.LDAPString(ret));
             }
             plugin._pluginNode.Nodes.Clear();
             this.sc.ShowControl(plugin._pluginNode);
         }
         else
         {
             Nodes.Clear();
         }
         
         return;
     }
     
     foreach (LdapEntry ldapNextEntry in ldapEntries)
     {
         string s = ldapNextEntry.GetDN();
         string objectClass = "";
         
         LdapValue[] values = ldapNextEntry.GetAttributeValues("objectClass", dirContext);
         if (values != null && values.Length > 0)
         {
             //use the most specific object Class, which will be listed last.
             objectClass = values[values.Length - 1].stringData;
             
             Logger.Log("Start--", Logger.ldapLogLevel);
             for (int i = 0; i < values.Length; i++)
             {
                 Logger.Log("objectclass is " + values[i], Logger.ldapLogLevel);
             }
             Logger.Log("End--", Logger.ldapLogLevel);
         }
         
         if (objectClass.Equals("group", StringComparison.InvariantCultureIgnoreCase) || objectClass.Equals("organizationalUnit", StringComparison.InvariantCultureIgnoreCase))
         {
             
             ADUCDirectoryNode dtn = new ADUCDirectoryNode(s, dirContext, objectClass,
             Resources.Group_16, NodeType, Plugin, false);
             dtn.sc = this.sc;
             Nodes.Add(dtn);
         }
     }
     haveRetrievedChildren = true;
 }   
Ejemplo n.º 58
0
    /// <summary>
    /// List the all children for the selected distinguished name
    /// Adds the all children to the node
    /// </summary>
    public ADUCDirectoryNode[] ListChildren(ADUCDirectoryNode dnode)
    {
        Logger.Log("DirectoryNode.ListChildren() called", Logger.ldapLogLevel);
        int ret = -1;

        string[] attrList = new string[]
        {
            "dummy",
            "objectClass", 
            "distinguishedName",
            "userAccountControl",
            null
        };

        ret = dirContext.ListChildEntriesSynchronous
        (distinguishedName,
        LdapAPI.LDAPSCOPE.ONE_LEVEL,
        "(objectClass=*)",
        attrList,
        false,
        out ldapEntries);

        if (ldapEntries == null || ldapEntries.Count == 0)
        {
            //clears the domian level node, if the ldap connection timed out or disconnected
            ADUCPlugin plugin = this.Plugin as ADUCPlugin;
            haveRetrievedChildren = true;
            this.IsModified = false;
            if (ret == (int)Likewise.LMC.Utilities.ErrorCodes.LDAPEnum.LDAP_SERVER_DOWN ||
            ret == (int)Likewise.LMC.Utilities.ErrorCodes.LDAPEnum.LDAP_CONNECT_ERROR ||
            ret == -1)
            {
                if (ret == -1)
                {
                    ret = (int)ErrorCodes.LDAPEnum.LDAP_TIMEOUT;
                    Logger.LogMsgBox(ErrorCodes.LDAPString(ret));
                }
                plugin._pluginNode.Nodes.Clear();
                this.sc.ShowControl(plugin._pluginNode);
            }

            return null;
        }

        DateTime timer = Logger.StartTimer();

        List<ADUCDirectoryNode> nodesToAdd = new List<ADUCDirectoryNode>();
        int nodesAdded = 0;

        foreach (LdapEntry ldapNextEntry in ldapEntries)
        {
            string currentDN = ldapNextEntry.GetDN();

            if (!String.IsNullOrEmpty(currentDN))
            {
                bool IsDisabled = false;
                bool IsDc = false;

                LdapValue[] values = ldapNextEntry.GetAttributeValues("objectClass", dirContext);
                string objectClass = "";
                if (values != null && values.Length > 0)
                {
                    objectClass = values[values.Length - 1].stringData;
                }

                if (objectClass.Equals("user", StringComparison.InvariantCultureIgnoreCase)
                || objectClass.Equals("computer", StringComparison.InvariantCultureIgnoreCase))
                {
                    values = ldapNextEntry.GetAttributeValues("userAccountControl", dirContext);
                    int userCtrlVal = 0;
                    if (values != null && values.Length > 0)
                    {
                        userCtrlVal = Convert.ToInt32(values[0].stringData);
                    }
                    if (userCtrlVal.Equals(8224) || userCtrlVal.Equals(8202) || userCtrlVal.Equals(532480))
                    {
                        IsDc = true;
                    }
                    string userCtrlBinStr = UserGroupUtils.DecimalToBase(userCtrlVal, 2);

                    //Determine whether this user is enabled or disabled
                    //examine the second to last position from the right (0=Active, 1=Inactive)
                    if (userCtrlBinStr.Length >= 2)
                    {
                        if (userCtrlBinStr[userCtrlBinStr.Length - 2] == '1')
                        {
                            IsDisabled = true;
                        }
                        else if (userCtrlBinStr[userCtrlBinStr.Length - 2] == '0')
                        {
                            IsDisabled = false;
                        }
                    }
                }

                ADUCDirectoryNode newNode = new ADUCDirectoryNode(currentDN, dirContext, objectClass,
                Resources.Group_16, NodeType, Plugin, IsDisabled);
                newNode.sc = this.sc;
                newNode._IsDomainController = IsDc;
                newNode.Text = newNode.Text.Substring(3);

                Logger.Log(String.Format("new Entry: {0}", currentDN), Logger.ldapLogLevel);
                Logger.Log(String.Format("scheduling addition of new Entry: {0}", currentDN), Logger.ldapLogLevel);

                nodesToAdd.Add(newNode);
                nodesAdded++;
            }
        }

        ADUCDirectoryNode[] nodesToAddRecast = new ADUCDirectoryNode[nodesAdded];

        try
        {
            nodesToAdd.Sort(delegate(ADUCDirectoryNode d1, ADUCDirectoryNode d2)
            {
                return d1.Text.CompareTo(d2.Text);
            }
            );
            for (int i = 0; i < nodesAdded; i++)
            {
                nodesToAddRecast[i] = nodesToAdd[i];
            }
        }
        catch (Exception)
        {
        }
        Logger.TimerMsg(ref timer, String.Format("DirectoryNode.ListChildren(): Entry Processing({0})", distinguishedName));
        this.IsModified = false;
        haveRetrievedChildren = true;

        return nodesToAddRecast;
    }
Ejemplo n.º 59
0
 public ADUserAddDlg(IPlugInContainer container, 
                     StandardPage parentPage, 
                     string text, 
                     ADUCDirectoryNode dirnode, 
                     bool bAcountDisable, 
                     bool bNeverExpiresPwd, 
                     bool bMustChangePwd,
                     bool bUserCannotChange,
                     string copyfrom)
 : this()
 {
     this.IPlugInContainer = container;
     
     this.userInfo = new UserInfo();
     
     if (dirnode != null)
     {
         int ret = -1;
         List<LdapEntry> ldapEntries = null;
         
         ret = dirnode.LdapContext.ListChildEntriesSynchronous
         (dirnode.DistinguishedName,
         LdapAPI.LDAPSCOPE.BASE,
         "(objectClass=*)",
         null,
         false,
         out ldapEntries);
         
         if (ldapEntries == null || ldapEntries.Count == 0)
         {
             return;
         }
         
         LdapEntry ldapNextEntry = ldapEntries[0];
         //As of now we are not getting canonicalName attribute in the list because of paging issue
         //LdapValue[] attr = ldapNextEntry.GetAttributeValues("canonicalName", dirnode.LdapContext);
         //if (attr != null && attr.Length > 0)
         //    this.lblCreatein.Text = "Create in: " + attr[0].stringData;
         
         //As of now we are taking "DistinguishedName" and spliting and displaying it.
         string[] sData = dirnode.DistinguishedName.Split(',');
         string sOutput = "";
         for (int i = sData.Length - 1; i >= 0; i--)
         {
             if (sData[i].ToString().Trim().StartsWith("DC", StringComparison.InvariantCultureIgnoreCase))
             {
                 sOutput = sData[i].ToString().Trim().Substring(3) + "." + sOutput;
             }
             else if (sData[i].ToString().Trim().StartsWith("OU", StringComparison.InvariantCultureIgnoreCase) || sData[i].ToString().Trim().StartsWith("CN", StringComparison.InvariantCultureIgnoreCase))
             {
                 sOutput += "/" + sData[i].ToString().Trim().Substring(3);
             }
         }
         if (sOutput.EndsWith("."))
         {
             sOutput += "/";
         }
         sOutput = sOutput.Replace("./", "/");
         this.userInfo.OUPath = sOutput;
         this.userInfo.domainName = dirnode.LdapContext.DomainName;
     }
     
     this.userInfo.bAcountDisable = bAcountDisable;
     this.userInfo.bMustChangePwd = bMustChangePwd;
     this.userInfo.bNeverExpiresPwd = bNeverExpiresPwd;
     this.userInfo.bCannotChangePwd = bUserCannotChange;
     this.userInfo.copyfrom = copyfrom;
     
     this.Text = text;
     
     this.AddPage(new UserAddWelcomePage(this,dirnode));
     this.AddPage(new UserAddpasswordPage(this));
     this.AddPage(new UserAddFinishPage(this, dirnode));
 }
Ejemplo n.º 60
0
        /// <summary>
        /// Queries and fills the ldap message for the selected group
        /// Gets the attribute list from AD for group schema attribute.
        /// search for the attributes description, cn or name and displays them in a controls
        /// </summary>
        /// <param name="ce"></param>
        /// <param name="servername"></param>
        /// <param name="name"></param>
        /// <param name="dirnode"></param>
        public void SetData(CredentialEntry ce, string servername, string name, ADUCDirectoryNode dirnode)
        {
            try
            {
                this.dirnode = dirnode;

                DirectoryContext dirContext = dirnode.LdapContext;

                //first obtain the current userAccountControl value
                DirectoryEntry de = new DirectoryEntry(string.Format("LDAP://{0}/{1}", dirContext.DomainName, dirnode.DistinguishedName));

                profilePath = de.Properties["profilePath"].Value as string;
                scriptPath = de.Properties["scriptPath"].Value as string;
                homeDirectory = de.Properties["homeDirectory"].Value as string;
                homeDrive = de.Properties["homeDrive"].Value as string;

                foreach (string ch in Charlist)
                {
                    cbDrive.Items.Add(ch);
                }

                if (homeDrive != null)
                {
                    rbConnect.Checked = true;
                    txtConnect.Text = homeDirectory;
                    int selectedIndex = 0;
                    if (cbDrive.Items.Contains(homeDrive))
                    {
                        selectedIndex = cbDrive.Items.IndexOf(homeDrive);
                    }
                    else
                    {
                        selectedIndex = cbDrive.Items.Add(homeDrive);
                    }
                    cbDrive.SelectedIndex = selectedIndex;
                }
                else
                {
                    rbLocalPath.Checked = true;
                    txtLocalPath.Text = homeDirectory;
                    cbDrive.SelectedIndex = 0;
                }

                txtProfilePath.Text = profilePath;
                txtLogonScript.Text = scriptPath;

                ParentContainer.DataChanged = false;

                ParentContainer.btnApply.Enabled = false;
            }
            catch (Exception e)
            {
                Logger.LogException("UserGeneralEditPage.SetData", e);
            }
        }