Beispiel #1
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);
        }
Beispiel #2
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;
            }
        }
Beispiel #3
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);
        }
Beispiel #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);
            }
        }
Beispiel #5
0
        public PropertyCollection(LdapEntry ldapEntry, DirectoryContext currentContext)
            : this()
        {
            if (ldapEntry == null)
            {
                return;
            }

            string[] allowedAttributes = ldapEntry.GetAttributeNames();

            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);
                    }
                }
            }
        }
        /// <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();
        }
Beispiel #7
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();
        }
Beispiel #8
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);
            }
        }
Beispiel #9
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;
        }
        /// <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);
            }
        }
Beispiel #11
0
        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);
            }
        }
        /// <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();
        }
Beispiel #13
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);
        }
Beispiel #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);
            }
        }
        /// <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();
        }
Beispiel #16
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);
            }
        }