예제 #1
0
    public ADEditPage(MPContainer parentDlg)
    {
        pageID = "EditProperitiesAdvanced";
        InitializeComponent();

        // Create an instance of a ListView column sorter and assign it
        // to the ListView control.
        lvwColumnSorter = new ListViewColumnSorter();
        this.lvAttrs.ListViewItemSorter = lvwColumnSorter;

        SetPageTitle("Advanced");
        _modifiedPageObject = new ADEditPageObject();
        _EditPageObject = new EditPageObject(lvAttrs);
        _parentDlg = parentDlg;
    }
예제 #2
0
    /// <summary>
    /// Method to load data to the tab pages while loading
    /// Gets the all attribute list for the selected AD object by querying the Ldap Message.
    /// </summary>
    /// <param name="ce"></param>
    /// <param name="servername"></param>
    /// <param name="username"></param>
    /// <param name="dirNode"></param
    public void SetData(CredentialEntry ce, string servername, string username, ADUCDirectoryNode dirNode)
    {
        try
        {
            dirnode = dirNode;
            InitLdapMessage();
            schemaCache = dirnode.LdapContext.SchemaCache;

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

            FillAttributeList(true, out _modifiedPageObject);
            ParentContainer.DataChanged = false;
            if (_modifiedPageObject != null)
            {
                _OriginalPageObject = (ADEditPageObject)_modifiedPageObject.Clone();
            }
            else
            {
                _OriginalPageObject = new ADEditPageObject();
            }
            UpdateApplyButton();
        }
        catch (Exception e)
        {
            Logger.LogException("ADEditPage.SetData", e);
        }
    }
예제 #3
0
    /// <summary>
    /// Method to get all attributes to the specified AD Object.
    /// </summary>
    /// <param name="AddNotset"></param>
    /// <param name="_modifiedPageObject"></param>
    private void FillAttributeList(bool AddNotset, out ADEditPageObject _modifiedPageObject)
    {
        _modifiedPageObject = new ADEditPageObject();
        lvAttrs.Items.Clear();

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

        LdapEntry ldapNextEntry = ldapEntries[0];

        string[] attrsFullList = new string[allowedAttributes.Count];

        allowedAttributes.CopyTo(attrsFullList);

        attributeList = new List<ListViewItem>();

        foreach (string attr in attrsFullList)
        {
            string sValue = "";
            string sAttrType = "Optional";


            foreach (string mandatoryAttribute in MandatoryAttributes)
            {
                if (String.Equals(mandatoryAttribute, attr, StringComparison.InvariantCultureIgnoreCase))
                {
                    sAttrType = "Mandatory";
                    continue;
                }
            }

            LdapValue[] attrValues = ldapNextEntry.GetAttributeValues(attr, dirnode.LdapContext);
            if (attrValues != null && attrValues.Length > 0)
            {
                foreach (LdapValue value in attrValues)
                {
                    //need do a type check before we assign the values, the type check has been done in getAttributeValues
                    sValue = sValue + ";" + value.stringData;
                }
                if (String.Equals(attr, "objectSid", StringComparison.InvariantCultureIgnoreCase))
                {
                    _parentDlg.objectSidBytes = attrValues[0].byteData;
                }
                if (String.Equals(attr, "objectGUID", StringComparison.InvariantCultureIgnoreCase))
                {
                    _parentDlg.objectGUIDBytes = attrValues[0].byteData;
                }
            }

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

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

            SchemaType schemaType = schemaCache.GetSchemaTypeByDisplayName(attr);

            if (schemaType == null)
            {
                string[] addItem = null;
                string[] slvItem = {
                        attr,
                        "",
                        sValue,
                        sAttrType,
                        "false"
                    };
                if (String.Equals(attr, "objectGUID", StringComparison.InvariantCultureIgnoreCase) ||
                    String.Equals(attr, "objectSid", StringComparison.InvariantCultureIgnoreCase))
                {
                    slvItem[1] = "Octet String";
                }
                addItem = slvItem;
                ListViewItem lvItem = new ListViewItem(addItem);
                FillListView(AddNotset, attributeList, lvItem);
            }
            else
            {
                string sADSType = GetADSTypeString(schemaType);

                if (!String.Equals(sValue, "<Not Set>", StringComparison.InvariantCultureIgnoreCase) &&
                    String.Equals(schemaType.DataType.ToString(), ADSType.ADSTYPE_UTC_TIME.ToString(), StringComparison.InvariantCultureIgnoreCase))
                {
                    string sDate = "", sTime = "";
                    sDate = sValue.Substring(0, 4);
                    sDate += "/" + sValue.Substring(4, 2);
                    sDate += "/" + sValue.Substring(6, 2);

                    sTime = sValue.Substring(8, 2);
                    sTime += ":" + sValue.Substring(10, 2);
                    sTime += ":" + sValue.Substring(12, 2);

                    sValue = Convert.ToDateTime(sDate).ToShortDateString();
                    sValue += " " + Convert.ToDateTime(sTime).ToLongTimeString();
                }
                string[] slvItem = {
                        attr,
                        sADSType,
                        sValue,
                        sAttrType,
                        "false"
                    };
                ListViewItem lvItem = new ListViewItem(slvItem);
                lvItem.Tag = schemaType;
                FillListView(AddNotset, attributeList, lvItem);
            }
        }

        PopulateListView();
        _EditPageObject = new EditPageObject(lvAttrs);
    }