/// <summary> /// creates for all the Ldap types the OMSyntax and AttributeSyntax values; these values are defined by /// Ldap; http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ad/ad/choosing_a_syntax.asp /// </summary> /// <param name="AttrType">the attribute type</param> /// <param name="OMSyntax">out: the OM Syntax value</param> /// <param name="AttributeSyntax">out: the Attribute Syntax value</param> private static void GetAttributeTypeInfo(LdapAttributeTypes AttrType, out int OMSyntax, out string AttributeSyntax) { switch (AttrType) { // A string that represents an array of bytes. This syntax is used to store binary data case LdapAttributeTypes.BinaryData: { OMSyntax = 4; AttributeSyntax = "2.5.5.10"; break; } // An octet string that contains a string value and a DN. case LdapAttributeTypes.BinaryDataWithDN: { OMSyntax = 127; AttributeSyntax = "2.5.5.14"; break; } // Represents a Boolean value. case LdapAttributeTypes.Boolean: { OMSyntax = 1; AttributeSyntax = "2.5.5.8"; break; } // String that contains a distinguished name (DN). case LdapAttributeTypes.DNReference: { OMSyntax = 127; AttributeSyntax = "2.5.5.1"; break; } // Represents a 32-bit signed integer value. case LdapAttributeTypes.Integer: { OMSyntax = 2; AttributeSyntax = "2.5.5.9"; break; } // Represents a 64-bit signed integer value. case LdapAttributeTypes.LargeInteger: { OMSyntax = 65; AttributeSyntax = "2.5.5.16"; break; } // String that contains a distinguished name (DN). case LdapAttributeTypes.LinkedDN: { OMSyntax = 127; AttributeSyntax = "2.5.5.1"; break; } // An octet string that contains a Windows NT/Windows 2000 security descriptor. case LdapAttributeTypes.SecurityDescriptor: { OMSyntax = 66; AttributeSyntax = "2.5.5.15"; break; } // An octet string that contains a security identifier (SID). case LdapAttributeTypes.SecurityIdentifier: { OMSyntax = 4; AttributeSyntax = "2.5.5.17"; break; } // A case insensitive string that contains characters from the teletex character set. case LdapAttributeTypes.String: { OMSyntax = 20; AttributeSyntax = "2.5.5.4"; break; } // An octet string that contains a string value and a DN. case LdapAttributeTypes.StringWithDN: { OMSyntax = 127; AttributeSyntax = "2.5.5.14"; break; } // A time string format defined by ASN.1 standards. For more information, see ISO 8601 and X680. case LdapAttributeTypes.Time: { OMSyntax = 24; AttributeSyntax = "2.5.5.11"; break; } // unknown data type default: { OMSyntax = Int16.MinValue; AttributeSyntax = String.Empty; break; } } }
/// <summary> /// create a new ldap attribute /// </summary> /// <param name="AdsiSchemaPath">the path to the Ldap schema root</param> /// <param name="AttributeName">the attribute name</param> /// <param name="IsSingleValued">is the attribute single valued or not</param> /// <param name="AttributeOID">the last digits of the class OID - format: 1.2.840.113556.1.6.1.1.AttributeOID</param> /// <param name="AttrType">the type of the attribute</param> public static void CreateLdapAttribute(string AdsiSchemaPath, string AttributeName, bool IsSingleValued, string AttributeOID, LdapAttributeTypes AttrType) { int OMSyntax = Int16.MinValue; string AttributeSyntax = String.Empty; // get the OM and attribute syntax from the requested attribute type GetAttributeTypeInfo(AttrType, out OMSyntax, out AttributeSyntax); // define all the attribute properties object[,] Properties = new object[, ] { { LdapAttributeOMSyntaxSchemaClassName, OMSyntax }, { LdapAttributeDisplayNameSchemaClassName, AttributeName }, { LdapIsSingleValuedSchemaClassName, IsSingleValued }, { LdapAttributeSyntaxSchemaClassName, AttributeSyntax }, { LdapAttributeIDSchemaClassName, AttributeOIDBase + AttributeOID } }; // if the CN= prefix is missing then add it now AttributeName = AttributeName.StartsWith(LdapCnPrefix) ? AttributeName : LdapCnPrefix + AttributeName; // invoke edit Adsi object AddDirectoryObject(AdsiSchemaPath, AttributeName, LdapAttributeSchemaClassName, Properties, null); }