Beispiel #1
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;
            }
        }
        /// <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;
                        }
                        if (string.Compare(attr, "objectSid") == 0)
                        {
                            System.DirectoryServices.DirectoryEntry de = new System.DirectoryServices.DirectoryEntry(dirnode.DistinguishedName);
                            byte[] objectSid = de.Properties["objectSid"].Value as byte[];
                            string Sid       = UserGroupUtils.SIDtoString(objectSid);
                            string cn        = UserGroupUtils.GetGroupFromForeignSecurity(Sid, dirnode.LdapContext);
                            if (cn != null)
                            {
                                lblName.Text = string.Concat("NT AUTHORITY\\", cn);
                            }
                        }
                    }

                    this.ParentContainer.DataChanged      = false;
                    this.ParentContainer.btnApply.Enabled = false;
                }
            }
            catch (Exception e)
            {
                container.ShowError(e.Message);
            }
            // throw new NotImplementedException();
        }