コード例 #1
0
        /// <summary>
        /// Gets all class attributes from the Schema template and add them to the treeview
        /// </summary>
        /// <param name="objectAddDlg"></param>
        public ObjectAddWelcomePage(ADObjectAddDlg objectAddDlg, ADUCDirectoryNode dirnode, IPlugInContainer container, StandardPage parentPage)
            : this()
        {
            this._objectAddDlg = objectAddDlg;
            this.dirnode       = dirnode;
            this._container    = container;
            this._parentPage   = parentPage;

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

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

            treeView1.HideSelection = true;
        }
コード例 #2
0
        /// <summary>
        /// Enables/Disables the controls based on the attribute selection
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cbProperty_SelectedIndexChanged(object sender, EventArgs e)
        {
            btnClear.Enabled = false;
            listboxValues.Items.Clear();
            if (cbProperty.SelectedItem == null)
            {
                return;
            }
            if (_newAttributesList == null)
            {
                return;
            }

            string selectedAttr = cbProperty.SelectedItem.ToString();

            if (_newAttributesList.ContainsKey(selectedAttr))
            {
                AttributeInfo AttrInfo   = _newAttributesList[selectedAttr];
                SchemaType    AttrSchema = AttrInfo.schemaInfo;
                if (AttrSchema.AttributeDisplayName.Equals(selectedAttr, StringComparison.InvariantCultureIgnoreCase))
                {
                    txtSyntax.Text = GetADSTypeString(AttrSchema);
                    if (AttrSchema.IsSingleValued)
                    {
                        txtValues.Show();
                        txtValues.Text = AttrInfo.sAttributeValue;
                        listboxValues.Hide();
                        btnSet.Text   = "&Set";
                        btnClear.Text = "&Clear";
                    }
                    else
                    {
                        txtValues.Hide();
                        string[] sValues = AttrInfo.sAttributeValue.Split(';');
                        foreach (string s in sValues)
                        {
                            listboxValues.Items.Add(s);
                        }
                        listboxValues.Show();
                        btnSet.Text   = "A&dd";
                        btnClear.Text = "&Remove";
                    }
                }
            }
        }
コード例 #3
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);
        }
コード例 #4
0
        /// <summary>
        /// Returns the attribute type based on attribute syntax
        /// </summary>
        /// <param name="schemaType"></param>
        /// <returns></returns>
        public static string GetADSTypeString(SchemaType schemaType)
        {
            ADSType syntaxID = schemaType.DataType;

            switch (syntaxID)
            {
            case ADSType.ADSTYPE_DN_STRING:
                return("DN");

            case ADSType.ADSTYPE_CASE_IGNORE_STRING:
                if (schemaType.AttributeSyntax.Equals("2.5.5.2"))
                {
                    return("OID");
                }
                else if (schemaType.AttributeSyntax.Equals("2.5.5.4"))
                {
                    return("CaseIgnoreString");
                }
                else if (schemaType.AttributeSyntax.Equals("2.5.5.12"))
                {
                    return("DirectoryString");
                }
                else if (schemaType.AttributeSyntax.Equals("2.5.5.13"))
                {
                    return("PresentationAddress");
                }
                return("IA5String");

            case ADSType.ADSTYPE_CASE_EXACT_STRING:
                return("CaseSensitiveString");

            case ADSType.ADSTYPE_PRINTABLE_STRING:
                return("PrintableString");

            case ADSType.ADSTYPE_NUMERIC_STRING:
                return("NumericString");

            case ADSType.ADSTYPE_DN_WITH_STRING:
                return("DNWithString");

            case ADSType.ADSTYPE_BOOLEAN:
                return("Boolean");

            case ADSType.ADSTYPE_INTEGER:
                return("INTEGER");

            case ADSType.ADSTYPE_OCTET_STRING:
                return("OctetString");

            case ADSType.ADSTYPE_UTC_TIME:
                return("GeneralizedTime");

            case ADSType.ADSTYPE_NT_SECURITY_DESCRIPTOR:
                return("NTSecurityDescriptor");

            case ADSType.ADSTYPE_LARGE_INTEGER:
                return("INTEGER8");

            default:
                return("");
            }
        }
コード例 #5
0
        /// <summary>
        /// Set the value to the selected attribute
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSet_Click(object sender, EventArgs e)
        {
            if (cbProperty.Items.Count == 0 || cbProperty.SelectedItem == null)
            {
                return;
            }
            if (cbProOptionorMandatory.Items.Count == 0 || cbProOptionorMandatory.SelectedItem == null)
            {
                return;
            }
            string Message;
            bool   bSuccess = ValidateData(txtEditAttribute.Text.Trim().ToString(), txtSyntax.Text.ToString(), out Message);

            if (!bSuccess)
            {
                container.ShowMessage(Message);
                txtEditAttribute.Clear();
                txtEditAttribute.Focus();
                return;
            }
            string sAttribute      = cbProperty.SelectedItem.ToString();
            string sAttributeType  = cbProOptionorMandatory.SelectedItem.ToString();
            string sAttributeValue = "";

            if (btnSet.Text.Trim().Equals("A&dd"))
            {
                if (listboxValues.Items.Contains("<not set>".Trim()))
                {
                    listboxValues.Items.Clear();
                }
                listboxValues.Items.Add(txtEditAttribute.Text.Trim());
            }
            else
            {
                txtValues.Text = txtEditAttribute.Text.Trim();
            }

            if (_newAttributesList.ContainsKey(sAttribute))
            {
                AttributeInfo AttrInfo = _newAttributesList[sAttribute];
                AttrInfo.sAttributeType = sAttributeType;
                SchemaType AttrSchema = AttrInfo.schemaInfo;
                if (AttrSchema != null && AttrSchema.IsSingleValued)
                {
                    AttrInfo.sAttributeValue = txtValues.Text.Trim();
                }
                else
                {
                    foreach (object item in listboxValues.Items)
                    {
                        sAttributeValue = sAttributeValue + ";" + item.ToString();
                    }
                    if (sAttributeValue.StartsWith(";"))
                    {
                        sAttributeValue = sAttributeValue.Substring(1);
                    }
                    AttrInfo.sAttributeValue = sAttributeValue;
                }
                _newAttributesList[sAttribute] = AttrInfo;

                if (_objectAddDlg.objectInfo.htMandatoryAttrList.Contains(sAttribute))
                {
                    _objectAddDlg.objectInfo.htMandatoryAttrList[sAttribute] = AttrInfo.sAttributeValue;
                }
                else
                {
                    _objectAddDlg.objectInfo.htMandatoryAttrList.Add(sAttribute, AttrInfo.sAttributeValue);
                }
            }
            btnClear.Enabled                 = listboxValues.SelectedItems.Count != 0 || txtValues.Text.Trim() != string.Empty;
            ParentContainer.DataChanged      = true;
            ParentContainer.btnApply.Enabled = true;

            txtEditAttribute.Text = "";
            txtEditAttribute.Focus();
        }
コード例 #6
0
 /// <summary>
 /// Method that returns the string specified based on Attribute syntax
 /// </summary>
 /// <param name="schemaType"></param>
 /// <returns></returns>
 public static string GetADSTypeString(SchemaType schemaType)
 {
     ADSType syntaxID = schemaType.DataType;
     switch (syntaxID)
     {
         case ADSType.ADSTYPE_DN_STRING:
         return "Distinguished Name";
         case ADSType.ADSTYPE_CASE_IGNORE_STRING:
         if (schemaType.AttributeSyntax.Equals("2.5.5.2"))
         {
             return "Object Identifier";
         }
         else if (schemaType.AttributeSyntax.Equals("2.5.5.12"))
         {
             return "Unicode String";
         }
         else if (schemaType.AttributeSyntax.Equals("2.5.5.13"))
         {
             return "Presentation Address";
         }
         else
         {
             return "Case Insensitive String";
         }
         case ADSType.ADSTYPE_CASE_EXACT_STRING:
         return "Case Sensitive String";
         case ADSType.ADSTYPE_PRINTABLE_STRING:
         return "IA5-String";
         case ADSType.ADSTYPE_NUMERIC_STRING:
         return "Numerical String";
         case ADSType.ADSTYPE_DN_WITH_STRING:
         if (schemaType.AttributeSyntax.Equals("2.5.5.14"))
         {
             return "Unicode String";
         }
         else if (schemaType.AttributeSyntax.Equals("2.5.5.7"))
         {
             return "DN Binary";//"DN with Binary";
         }
         else
         {
             return "DN With String";
         }
         case ADSType.ADSTYPE_BOOLEAN:
         return "Boolean";
         case ADSType.ADSTYPE_INTEGER:
         return "Integer";
         case ADSType.ADSTYPE_OCTET_STRING:
         if ((schemaType.AttributeSyntax.Equals("2.5.5.17")))
         {
             return "SID";
         }
         else
         {
             return "Octet String";
         }
         case ADSType.ADSTYPE_UTC_TIME:
         return "UTC Coded Time";
         case ADSType.ADSTYPE_NT_SECURITY_DESCRIPTOR:
         return "NT Security Descriptor";
         case ADSType.ADSTYPE_LARGE_INTEGER:
         return "Larger Integer/Interval";
         default :
         return "";
     }
 }
コード例 #7
0
 /// <summary>
 /// Returns the attribute type based on attribute syntax
 /// </summary>
 /// <param name="schemaType"></param>
 /// <returns></returns>
 public static string GetADSTypeString(SchemaType schemaType)
 {
     ADSType syntaxID = schemaType.DataType;
     switch (syntaxID)
     {
         case ADSType.ADSTYPE_DN_STRING:
         return "DN";
         case ADSType.ADSTYPE_CASE_IGNORE_STRING:
         if (schemaType.AttributeSyntax.Equals("2.5.5.2"))
         {
             return "OID";
         }
         else if (schemaType.AttributeSyntax.Equals("2.5.5.4"))
         {
             return "CaseIgnoreString";
         }
         else if (schemaType.AttributeSyntax.Equals("2.5.5.12"))
         {
             return "DirectoryString";
         }
         else if (schemaType.AttributeSyntax.Equals("2.5.5.13"))
         {
             return "PresentationAddress";
         }
         return "IA5String";
         case ADSType.ADSTYPE_CASE_EXACT_STRING:
         return "CaseSensitiveString";
         case ADSType.ADSTYPE_PRINTABLE_STRING:
         return "PrintableString";
         case ADSType.ADSTYPE_NUMERIC_STRING:
         return "NumericString";
         case ADSType.ADSTYPE_DN_WITH_STRING:
         return "DNWithString";
         case ADSType.ADSTYPE_BOOLEAN:
         return "Boolean";
         case ADSType.ADSTYPE_INTEGER:
         return "INTEGER";
         case ADSType.ADSTYPE_OCTET_STRING:
         return "OctetString";
         case ADSType.ADSTYPE_UTC_TIME:
         return "GeneralizedTime";
         case ADSType.ADSTYPE_NT_SECURITY_DESCRIPTOR:
         return "NTSecurityDescriptor";
         case ADSType.ADSTYPE_LARGE_INTEGER:
         return "INTEGER8";
         default:
         return "";
     }
 }