コード例 #1
0
ファイル: MemOfPages.cs プロジェクト: vmware/likewise-open
        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);
        }
コード例 #2
0
ファイル: MemOfPages.cs プロジェクト: vmware/likewise-open
        /// <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);
        }
コード例 #3
0
        private void GetObjectLdapPath(object args)
        {
            if (!(args is LdapEntry))
            {
                return;
            }

            if (args != null)
            {
                LdapEntry entry = args as LdapEntry;

                string[] attrsList = entry.GetAttributeNames();

                if (attrsList != null && attrsList.Length > 0)
                {
                    if (entry != null)
                    {
                        LdapValue[] values = entry.GetAttributeValues("distinguishedName", dirContext);
                        if (values != null && values.Length > 0)
                        {
                            ldapPaths.Add(string.Concat("LDAP://", sServer, "/", values[0].stringData));
                        }
                    }
                }
                //else return null;
            }
        }
コード例 #4
0
        //find the DN of given the sid
        public static string SearchBySid(string sid, Likewise.LMC.LDAP.DirectoryContext dirContext)
        {
            string searchFilter = string.Concat("(objectSid=", sid, ")");

            LdapMessage ldapMessage = dirContext.SearchSynchronous(
                dirContext.RootDN,
                LdapAPI.LDAPSCOPE.SUB_TREE,
                searchFilter,
                null,
                false);

            if (ldapMessage == null)
            {
                // Logger.Log("ldapMessage = null");
                return(null);
            }
            else
            {
                List <LdapEntry> ldapEntries = ldapMessage.Ldap_Get_Entries();
                if (ldapEntries == null || ldapEntries.Count == 0)
                {
                    // Logger.Log("ldapEntries.Count == 0");
                    return(null);
                }

                LdapEntry ldapNextEntry = ldapEntries[0];

                if (ldapNextEntry != null)
                {
                    string[] attrsList = ldapNextEntry.GetAttributeNames();

                    if (attrsList != null)
                    {
                        foreach (string attr in attrsList)
                        {
                            if (attr.Equals("distinguishedName", StringComparison.InvariantCultureIgnoreCase))
                            {
                                LdapValue[] attrValues = ldapNextEntry.GetAttributeValues(attr, dirContext);

                                if (attrValues != null && attrValues.Length > 0)
                                {
                                    return(attrValues[0].stringData);
                                }
                            }
                        }
                    }
                }
                return(null);
            }
        }
コード例 #5
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));
        }
コード例 #6
0
        //this function will return a ldapMessage that contains all the attributes that are available for an object
        //use this to populate DirectoryEntry's properties
        public static List <string> InitLdapMessageFilterForProperties(Likewise.LMC.LDAP.DirectoryContext dirContext, string nodeDN)
        {
            LdapMessage ldapMessagetemp = null;

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

            if (ldapMessagetemp == null)
            {
                ldapMessagetemp = dirContext.SearchSynchronous(
                    nodeDN,
                    LdapAPI.LDAPSCOPE.BASE,
                    "(objectClass=*)",
                    attrs,
                    false);
            }

            if (ldapMessagetemp == null)
            {
                return(null);
            }

            List <LdapEntry> ldapEntries = ldapMessagetemp.Ldap_Get_Entries();

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

            LdapEntry ldapNextEntry = ldapEntries[0];

            List <string> allowedAttributes = new List <string>();

            LdapValue[] attrValues = ldapNextEntry.GetAttributeValues("allowedAttributes", dirContext);
            if (attrValues != null && attrValues.Length > 0)
            {
                foreach (LdapValue attrValue in attrValues)
                {
                    allowedAttributes.Add(attrValue.stringData);
                }
            }

            return(allowedAttributes);
        }
コード例 #7
0
        public PropertyCollection(LdapEntry ldapEntry, DirectoryContext currentContext, string[] allowedAttributes)
            : this()
        {
            if (ldapEntry == null)
            {
                return;
            }

            if (allowedAttributes != null && allowedAttributes.Length > 0)
            {
                foreach (string attr in allowedAttributes)
                {
                    if (attr != null)
                    {
                        try
                        {
                            LdapValue[] attrValue = ldapEntry.GetAttributeValues(attr, currentContext);

                            if (attrValue != null && attrValue.Length > 0)
                            {
                                PropertyValueCollection propertyValue = new PropertyValueCollection(attrValue);
                                this.Add(attr, propertyValue);
                            }
                            else
                            {
                                PropertyValueCollection propertyValue = new PropertyValueCollection();
                                this.Add(attr, propertyValue);
                            }
                        }
                        catch
                        {
                            PropertyValueCollection propertyValue = new PropertyValueCollection();
                            this.Add(attr, propertyValue);
                        }
                    }
                }
            }
        }
コード例 #8
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;
                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, "cn") == 0)
                        {
                            this.lblGroupName.Text = sValue;
                        }

                        if (string.Compare(attr, "sAMAccountName") == 0)
                        {
                            _editObject.Name         = sValue;
                            this.txtPrewinGroup.Text = sValue;
                        }

                        if (string.Compare(attr, "description") == 0)
                        {
                            this.txtDescription.Text = sValue;
                            _editObject.Description  = sValue;
                        }

                        if (string.Compare(attr, "mail") == 0)
                        {
                            this.txtEmail.Text = sValue;
                            _editObject.Email  = sValue;
                        }

                        if (string.Compare(attr, "groupType") == 0)
                        {
                            EnableCheckBox(sValue);
                            _editObject.GroupType = sValue;
                        }


                        if (string.Compare(attr, "info") == 0)
                        {
                            this.txtNotes.Text = sValue;
                            _editObject.Notes  = sValue;
                        }
                    }
                }
                if (_editObject != null)
                {
                    _originalObject = (GroupGenerelEditObject)_editObject.Clone();
                }
                else
                {
                    _originalObject = new GroupGenerelEditObject();
                }
                UpdateApplyButton();
            }
            catch (Exception e)
            {
                container.ShowError(e.Message);
            }

            // throw new NotImplementedException();
        }
コード例 #9
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, "cn") == 0)
                        {
                            this.lblComputerName.Text = sValue;
                        }

                        if (string.Compare(attr, "sAMAccountName") == 0)
                        {
                            if (sValue.EndsWith("$"))
                            {
                                this.txtCName.Text = sValue.Substring(0, sValue.Length - 1);
                            }
                            else
                            {
                                this.txtCName.Text = sValue;
                            }
                        }

                        if (string.Compare(attr, "description") == 0)
                        {
                            this.txtDescription.Text = sValue;
                            _editObject.Description  = sValue;
                        }

                        if (string.Compare(attr, "dNSHostName") == 0)
                        {
                            this.txtDNSName.Text = sValue;
                        }

                        if (string.Compare(attr, "userAccountControl") == 0)
                        {
                            int userCtrlVal = 0;
                            if (attrValues != null && attrValues.Length > 0)
                            {
                                userCtrlVal = Convert.ToInt32(attrValues[0].stringData);
                            }
                            string userCtrlBinStr = UserGroupUtils.DecimalToBase(userCtrlVal, 16);
                            _editObject.UserCtrlBinStr = userCtrlVal;

                            this.txtRole.Text = "Workstation or server";
                            if (userCtrlBinStr.Length >= 3)
                            {
                                //Determine role of computer
                                if (userCtrlBinStr.Length == 3)
                                {
                                    //examine the third position from the left (2=NORMAL_ACCOUNT)
                                    if (userCtrlBinStr[0] == '2')
                                    {
                                        this.txtRole.Text = "Normal computer";
                                    }

                                    //examine the third position from the left (2=INTERDOMAIN_TRUST_ACCOUNT)
                                    if (userCtrlBinStr[0] == '8')
                                    {
                                        this.txtRole.Text = "Inter domain trust computer";
                                    }
                                }
                                else
                                {
                                    //examine the forth position from the left (2=WORKSTATION_TRUST_ACCOUNT)
                                    if (userCtrlBinStr[userCtrlBinStr.Length - 4] == '1')
                                    {
                                        this.txtRole.Text = "Workstation or server";
                                    }
                                    //examine the forth position from the left (2=SERVER_TRUST_ACCOUNT)
                                    if (userCtrlBinStr[userCtrlBinStr.Length - 4] == '2')
                                    {
                                        this.txtRole.Text = "Domain controller";
                                    }
                                }
                            }
                            if (userCtrlBinStr.Length >= 5)
                            {
                                //Determine whether this user is TRUSTED_FOR_DELEGATION
                                //examine the fifth position from the left (8=TRUSTED_FOR_DELEGATION, 0=NOT TRUSTED)
                                //TRUSTED_FOR_DELEGATION
                                if (userCtrlBinStr[userCtrlBinStr.Length - 5] == '8')
                                {
                                    this.checkBoxTrust.CheckedChanged -= new System.EventHandler(this.checkBoxTrust_CheckedChanged);
                                    checkBoxTrust.Checked              = true;
                                    this.checkBoxTrust.CheckedChanged += new System.EventHandler(this.checkBoxTrust_CheckedChanged);
                                }
                                else if (userCtrlBinStr[userCtrlBinStr.Length - 5] == '0')
                                {
                                    checkBoxTrust.Checked = false;
                                }
                            }
                            else
                            {
                                checkBoxTrust.Checked = false;
                            }

                            _editObject.DelegateTrust = checkBoxTrust.Checked;
                        }
                    }
                }
                UpdateOriginalData();
                UpdateApplyButton();
            }
            catch (Exception e)
            {
                container.ShowError(e.Message);
            }
        }
コード例 #10
0
        public ADRenameUserDlg(ADUCDirectoryNode dirnode, string parentDN)
            : this()
        {
            this.ParentDN       = parentDN;
            this._dirnode       = dirnode;
            this.renameUserInfo = new RenameUserInfo();
            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, "cn") == 0)
                    {
                        this.FullNametextbox.Text = sValue;
                        renameUserInfo.fullName   = sValue;
                    }

                    if (string.Compare(attr, "displayName") == 0)
                    {
                        this.displaynametextBox.Text = sValue;
                        renameUserInfo.displayName   = sValue;
                    }

                    if (string.Compare(attr, "givenName") == 0)
                    {
                        this.FnametextBox.Text = sValue;
                        renameUserInfo.fName   = sValue;
                    }

                    if (string.Compare(attr, "initials") == 0)
                    {
                        this.InitialtextBox.Text = sValue;
                        renameUserInfo.initials  = sValue;
                    }

                    if (string.Compare(attr, "sn") == 0)
                    {
                        this.LnametextBox.Text = sValue;
                        renameUserInfo.lName   = sValue;
                    }

                    if (string.Compare(attr, "userPrincipalName") == 0)
                    {
                        string[] pre = sValue.Split('@');
                        this.logonNametextBox.Text = pre[0].Trim();
                        renameUserInfo.logonName   = sValue;
                    }

                    if (string.Compare(attr, "sAMAccountName") == 0)
                    {
                        this.userlogonPretextBox.Text   = sValue;
                        renameUserInfo.userPrelogonname = sValue;
                    }
                }
            }

            string[] prefixes = dirnode.LdapContext.DomainName.Split('.');
            string   prefix   = string.Concat(prefixes[0].ToUpper(), "\\");

            this.prelogontextBox.Text = prefix;

            this.domainNamecomboBox.Items.Add(dirnode.LdapContext.DomainName);
            this.domainNamecomboBox.SelectedIndex = 0;
        }
コード例 #11
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);
            }
        }
コード例 #12
0
        //return the found entry's LdapPath
        public string FindFirstChild(string filter, SearchScope searchScope, string[] propertiesToLoad)
        {
            Assign_dirContext();

            if (dirContext == null)
            {
                return(null);
            }

            if (!get_baseDnFor_guidOrsid_called)
            {
                Get_baseDn_Guid_Or_sid();
            }

            LdapAPI.LDAPSCOPE ldapscope = LdapAPI.LDAPSCOPE.ONE_LEVEL;

            if (searchScope == SearchScope.Base)
            {
                ldapscope = LdapAPI.LDAPSCOPE.BASE;
            }
            else if (searchScope == SearchScope.OneLevel)
            {
                ldapscope = LdapAPI.LDAPSCOPE.ONE_LEVEL;
            }
            else if (searchScope == SearchScope.Subtree)
            {
                ldapscope = LdapAPI.LDAPSCOPE.SUB_TREE;
            }

            LdapMessage ldapMessage = dirContext.SearchSynchronous(
                baseDn,
                ldapscope,
                filter,
                //new string[] { "distinguishedName", null },
                Getsearch_attrs(propertiesToLoad),
                false);

            List <LdapEntry> ldapEntries = (ldapMessage != null ? ldapMessage.Ldap_Get_Entries() : null);

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

                string[] attrsList = entry.GetAttributeNames();

                if (attrsList != null && attrsList.Length > 0)
                {
                    if (entry != null)
                    {
                        LdapValue[] values = entry.GetAttributeValues("distinguishedName", dirContext);
                        if (values != null && values.Length > 0)
                        {
                            return(string.Concat("LDAP://", sServer, "/", values[0].stringData));
                        }
                    }
                }
                else
                {
                    return(null);
                }
            }

            return(null);
        }
コード例 #13
0
        //- RootDSE -> configurationNamingContext
        //- cn=partition, "configurationNamingContext" -> netBIOSName
        //Using the value of "netBIOSName" as shortDomain name.
        public string GetnetBiosName(string domain)
        {
            int    ret = -1;
            string configurationName = null;
            string netbiosName       = null;
            string baseDn            = "";

            string[] search_attrs = { null };

            DirectoryContext dircontext = null;

            if (exisitngDirContext != null && exisitngDirContext.Count > 0)
            {
                foreach (DirectoryContext context in exisitngDirContext)
                {
                    if (context.DomainName.Equals(domain, StringComparison.InvariantCultureIgnoreCase))
                    {
                        dircontext = context;
                    }
                }
            }

            //searching with baseDn="" allows ldap to access the domain “RootDSE”.
            //Without passing that, it cannot access the configurationNamingContext
            List <LdapEntry> ldapEntries = null;

            ret = dircontext.ListChildEntriesSynchronous
                      (baseDn,
                      LdapAPI.LDAPSCOPE.BASE,
                      "(objectClass=*)",
                      search_attrs,
                      false,
                      out ldapEntries);

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

                LdapValue[] values = ldapNextEntry.GetAttributeValues("configurationNamingContext", dircontext);

                if (values != null && values.Length > 0)
                {
                    configurationName = values[0].stringData;
                }
            }
            //by default, if we couldn't find configurateName we use CN=configuration + rootDN as one
            if (configurationName == null)
            {
                configurationName = "CN=configuration,";
                configurationName = string.Concat(configurationName, dircontext.RootDN);
            }

            string partitionDn = "CN=Partitions,";

            partitionDn = string.Concat(partitionDn, configurationName);

            string sFilter = "(&(objectcategory=Crossref)(dnsRoot=" + domain.ToLower() + ")(netBIOSName=*))";

            List <LdapEntry> ldapEntries1 = null;

            ret = dircontext.ListChildEntriesSynchronous
                      (partitionDn,
                      LdapAPI.LDAPSCOPE.SUB_TREE,
                      sFilter,
                      search_attrs,
                      false,
                      out ldapEntries1);

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

                LdapValue[] values = ldapNextEntry.GetAttributeValues("netBIOSName", dircontext);
                netbiosName = values[0].stringData;
            }

            //by default, if we couldn't find netbiosName we use the first portion of rootDn as one
            if (netbiosName == null)
            {
                string[] rootDns = dircontext.RootDN.Split(',');
                netbiosName = rootDns[0].Substring(3).ToUpper();
            }

            return(netbiosName);
        }
コード例 #14
0
        public void SetData(CredentialEntry ce, string servername, string name, ADUCDirectoryNode dirnode)
        {
            try
            {
                InitializeCountryNames();
                if (!bMultiUserSelected)
                {
                    int ret = -1;
                    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, "streetAddress") == 0)
                            {
                                this.txtStreet.Text = sValue;
                                chkStreet.Checked   = true;
                            }
                            if (string.Compare(attr, "postOfficeBox") == 0)
                            {
                                this.txtPOBox.Text = sValue;
                                chkPO.Checked      = true;
                            }
                            if (string.Compare(attr, "l") == 0)
                            {
                                this.txtCity.Text = sValue;
                                chkCity.Checked   = true;
                            }
                            if (string.Compare(attr, "st") == 0)
                            {
                                this.txtState.Text = sValue;
                                chkState.Checked   = true;
                            }
                            if (string.Compare(attr, "postalCode") == 0)
                            {
                                this.txtZip.Text = sValue;
                                chkZip.Checked   = true;
                            }
                            if (string.Compare(attr, "co") == 0)
                            {
                                bool bEntryFound = false;
                                for (int i = 0; i < cbCountry.Items.Count; i++)
                                {
                                    if (sValue.Trim().Equals(cbCountry.Items[i].ToString().Trim()))
                                    {
                                        cbCountry.SelectedIndex = i;
                                        bEntryFound             = true;
                                        break;
                                    }
                                }
                                if (bEntryFound)
                                {
                                    this.cbCountry.Items.Add(sValue);
                                    this.cbCountry.SelectedIndex = cbCountry.Items.Count - 1;
                                }
                                chkCountry.Checked = true;
                            }
                        }
                    }
                }
                else if (bMultiUserSelected)
                {
                    this.dirnode   = dirnode;
                    txtCity.Text   = "";
                    txtPOBox.Text  = "";
                    txtStreet.Text = "";
                    txtState.Text  = "";
                    txtZip.Text    = "";
                }
                ParentContainer.DataChanged = false;
            }
            catch (Exception e)
            {
                Logger.LogException("UserMultiEditPage.SetData", e);
            }
        }
コード例 #15
0
        /// <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();
        }
コード例 #16
0
        /// <summary>
        /// initializes the wiazrd pages based on "systemMustContain" attribute value list for the selected objectclass
        /// Adds the wizard pages to the wizard dialog
        /// </summary>
        /// <param name="nodeText"></param>
        /// <param name="mandatoryAttributes"></param>
        private void AddWizardPages(string nodeText, String[] mandatoryAttributes)
        {
            treeView1.HideSelection    = false;
            _objectAddDlg.choosenClass = nodeText;
            _objectAddDlg.objectInfo.htMandatoryAttrList = new Hashtable();

            List <string> attrlist = new List <string>();

            _objectAddDlg.ClassAttributeList = new List <LdapAttributeType>();

            attrlist.Add("instanceType");
            attrlist.Add("objectCategory");
            attrlist.Add("objectClass");
            if (_objectAddDlg.choosenClass.Trim().Equals("user", StringComparison.InvariantCultureIgnoreCase) ||
                _objectAddDlg.choosenClass.Trim().Equals("group", StringComparison.InvariantCultureIgnoreCase) ||
                _objectAddDlg.choosenClass.Trim().Equals("computer", StringComparison.InvariantCultureIgnoreCase))
            {
                attrlist.Add("objectSid");
                attrlist.Add("sAMAccountName");
                if (!attrlist.Contains("cn"))
                {
                    attrlist.Add("cn");
                }
                if (mandatoryAttributes != null)
                {
                    foreach (string attr in mandatoryAttributes)
                    {
                        if (!attrlist.Contains(attr))
                        {
                            attrlist.Add(attr);
                        }
                    }
                }
            }

            LdapClassType classtype = _objectAddDlg.schemaCache.GetSchemaTypeByObjectClass(_objectAddDlg.choosenClass) as LdapClassType;

            AttributeMap attr_map  = classtype.Tag as AttributeMap;
            LdapEntry    ldapentry = attr_map.Tag as LdapEntry;

            string DN = ldapentry.GetDN();

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

            List <LdapEntry> innerLdapEntries = null;
            int ret = dirnode.LdapContext.ListChildEntriesSynchronous
                          (dirnode.DistinguishedName,
                          LdapAPI.LDAPSCOPE.BASE,
                          "(objectClass=*)",
                          attrs,
                          false,
                          out innerLdapEntries);

            ldapentry = innerLdapEntries[0];

            LdapValue[] ldapValues = ldapentry.GetAttributeValues("allowedAttributes", dirnode.LdapContext);
            if (ldapValues != null && ldapValues.Length > 0)
            {
                string[] optionalAttrs = new string[ldapValues.Length];
                foreach (LdapValue Oclass in ldapValues)
                {
                    string     attrValue  = Oclass.stringData;
                    SchemaType schematype = _objectAddDlg.schemaCache.GetSchemaTypeByDisplayName(attrValue) as SchemaType;
                    if (schematype != null)
                    {
                        schematype.AttributeType = "Optional";
                        _objectAddDlg.ClassAttributeList.Add(schematype as LdapAttributeType);
                    }
                }

                foreach (string strValue in attrlist)
                {
                    SchemaType schematype = _objectAddDlg.schemaCache.GetSchemaTypeByDisplayName(strValue) as SchemaType;
                    if (schematype != null)
                    {
                        schematype.AttributeType = "Mandatory";
                        _objectAddDlg.ClassAttributeList.Add(schematype as LdapAttributeType);
                    }
                }
            }

            if (_objectAddDlg.ClassAttributeList != null && _objectAddDlg.ClassAttributeList.Count != 0)
            {
                foreach (LdapAttributeType Attribute in _objectAddDlg.ClassAttributeList)
                {
                    AttributeInfo attributeInfo = new AttributeInfo();
                    attributeInfo.sAttributename  = Attribute.AttributeDisplayName;
                    attributeInfo.sAttributeValue = "<not set>";
                    attributeInfo.sAttributeType  = Attribute.AttributeType;
                    attributeInfo.schemaInfo      =
                        _objectAddDlg.schemaCache.GetSchemaTypeByCommonName(Attribute.CName);
                    if (!_objectAddDlg.objectInfo._AttributesList.ContainsKey(Attribute.AttributeDisplayName))
                    {
                        _objectAddDlg.objectInfo._AttributesList.Add(Attribute.AttributeDisplayName, attributeInfo);
                    }
                }
            }
            ObjectAddSinglePage ObjectAddSinglePage = null;

            _objectAddDlg.objectInfo.addedPages = new List <string>();
            ObjectInfo.PageIndex = 0;
            //for all objects we should prompt to ask for their cn
            if (nodeText.Equals("organizationalUnit", StringComparison.InvariantCultureIgnoreCase))
            {
                ObjectAddSinglePage = new ObjectAddSinglePage(_objectAddDlg, "ou");
                _objectAddDlg.AddPage(ObjectAddSinglePage);
                _objectAddDlg.objectInfo.addedPages.Add("ou");
            }
            else
            {
                ObjectAddSinglePage = new ObjectAddSinglePage(_objectAddDlg, "cn");
                _objectAddDlg.AddPage(ObjectAddSinglePage);
                _objectAddDlg.objectInfo.addedPages.Add("cn");
            }

            if (mandatoryAttributes != null && mandatoryAttributes.Length != 0)
            {
                for (int i = 0; i < mandatoryAttributes.Length; i++)
                {
                    if (!((mandatoryAttributes[i].Trim().ToLower().Equals("cn")) || (mandatoryAttributes[i].Trim().ToLower().Equals("ou"))))
                    {
                        ObjectAddSinglePage = new ObjectAddSinglePage(_objectAddDlg, mandatoryAttributes[i].Trim());
                        _objectAddDlg.AddPage(ObjectAddSinglePage);
                        _objectAddDlg.objectInfo.addedPages.Add(mandatoryAttributes[i].Trim());
                    }
                }
            }

            if (_objectAddDlg.choosenClass.Equals("computer", StringComparison.InvariantCultureIgnoreCase)
                ||
                _objectAddDlg.choosenClass.Equals("user", StringComparison.InvariantCultureIgnoreCase)
                ||
                _objectAddDlg.choosenClass.Equals("group", StringComparison.InvariantCultureIgnoreCase))
            {
                ObjectAddSinglePage = new ObjectAddSinglePage(_objectAddDlg, "sAMAccountName");
                _objectAddDlg.AddPage(ObjectAddSinglePage);
                _objectAddDlg.objectInfo.addedPages.Add("sAMAccountName");
            }

            //for all objects they all come to the end of final page
            _objectAddDlg.AddPage(new ObjectAddFinalPage(_objectAddDlg, _container, _parentPage));

            Wizard.enableButton(WizardDialog.WizardButton.Start);
        }
コード例 #17
0
        /// <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();
        }
コード例 #18
0
ファイル: EventAPI.cs プロジェクト: vmware/likewise-open
        public static void ReadRemoteHostFQDN(string hostname, out string hostFQDN)
        {
            hostFQDN = string.Empty; string domain = string.Empty;

            uint error = CNetlogon.GetCurrentDomain(out domain);

            if (error != 0 && String.IsNullOrEmpty(domain))
            {
                return;
            }

            string[] rootDNcom = domain.Split('.');

            string rootDN = ""; string errorMessage = "";

            foreach (string str in rootDNcom)
            {
                string temp = string.Concat("dc=", str, ",");
                rootDN = string.Concat(rootDN, temp);
            }
            rootDN = rootDN.Substring(0, rootDN.Length - 1);

            try
            {
                DirectoryContext dirContext = DirectoryContext.CreateDirectoryContext
                                                  (domain,
                                                  rootDN,
                                                  null,
                                                  null,
                                                  389,
                                                  false,
                                                  out errorMessage);

                if (!String.IsNullOrEmpty(errorMessage))
                {
                    Logger.ShowUserError(errorMessage);
                }

                if (dirContext == null)
                {
                    return;
                }

                List <LdapEntry> ldapEntries = new List <LdapEntry>();

                string[] attrs = { "name", "dNSHostName", null };

                int ret = dirContext.ListChildEntriesSynchronous
                              (rootDN,
                              LdapAPI.LDAPSCOPE.SUB_TREE,
                              string.Format("(&(objectClass=computer)(cn={0}))", hostname),
                              attrs,
                              false,
                              out ldapEntries);

                if (ldapEntries == null)
                {
                    return;
                }

                LdapEntry ldapNextEntry = ldapEntries[0];

                string[] attrsList = ldapNextEntry.GetAttributeNames();

                Logger.Log("The number of attributes are " + attrsList.Length, Logger.ldapLogLevel);

                if (attrsList != null)
                {
                    foreach (string attr in attrsList)
                    {
                        if (attr.Trim().Equals("dNSHostName"))
                        {
                            LdapValue[] attrValues = ldapNextEntry.GetAttributeValues(attr, dirContext);
                            if (attrValues != null && attrValues.Length > 0)
                            {
                                hostFQDN = attrValues[0].stringData;
                                break;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                hostFQDN = string.Empty;
                Logger.LogException("EventAPI.ReadRemoteHostFQDN", ex);
            }
        }
コード例 #19
0
        /// <summary>
        /// Queries and fills the ldap message for the selected OU
        /// Gets the attribute list from AD for OU schema attribute.
        /// search for the attributes description, ou 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
            {
                InitializeCountryNames();
                _editObject = new OUGenerelEditObject();
                int ret = -1;
                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, "description") == 0)
                        {
                            this.txtDescription.Text = sValue;
                            _editObject.Description  = sValue;
                        }

                        if (string.Compare(attr, "street") == 0)
                        {
                            this.rtbStreet.Text = sValue;
                            _editObject.Street  = sValue;
                        }

                        if (string.Compare(attr, "l") == 0)
                        {
                            this.txtCity.Text = sValue;
                            _editObject.City  = sValue;
                        }

                        if (string.Compare(attr, "st") == 0)
                        {
                            this.txtstate.Text = sValue;
                            _editObject.State  = sValue;
                        }

                        if (string.Compare(attr, "postalCode") == 0)
                        {
                            this.txtZip.Text       = sValue;
                            _editObject.PostalCode = sValue;
                        }

                        if (string.Compare(attr, "co") == 0)
                        {
                            bool bEntryFound = false;
                            for (int i = 0; i < cbcountry.Items.Count; i++)
                            {
                                if (sValue.Trim().ToLower().Equals(cbcountry.Items[i].ToString().Trim().ToLower()))
                                {
                                    cbcountry.SelectedIndex = i;
                                    bEntryFound             = true;
                                    break;
                                }
                            }
                            if (!bEntryFound)
                            {
                                cbcountry.Items.Add(sValue);
                                cbcountry.SelectedIndex = cbcountry.Items.Count - 1;
                            }
                            _editObject.Country = sValue;
                        }

                        if (string.Compare(attr, "ou") == 0)
                        {
                            this.userNamelabel.Text = sValue;
                        }
                    }
                }
                if (_editObject != null)
                {
                    _originalObject = (OUGenerelEditObject)_editObject.Clone();
                }
                else
                {
                    _originalObject = new OUGenerelEditObject();
                }
                ParentContainer.DataChanged = false;
                UpdateApplyButton();
            }
            catch (Exception e)
            {
                container.ShowError(e.Message);
            }
            // throw new NotImplementedException();
        }
コード例 #20
0
        /// <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);
            }
        }