[ Team LiB ] |
Recipe 10.7 Adding a New Attribute10.7.1 ProblemYou want to add a new attribute to the schema. 10.7.2 Solution
10.7.2.1 Using a graphical user interface
10.7.2.2 Using a command-line interfaceYou can create new attributes by using ldifde and an LDIF file that contains the properties to be set on the attribute. The following text shows an example LDIF file called create_attr.ldf that creates an attribute called rallencorp-LanguagesSpoken: dn: cn=rallencorp-LanguagesSpoken,cn=schema,cn=configuration,<ForestRootDN> changetype: add objectclass: attributeSchema lDAPDisplayName: rallencorp-LanguagesSpoken attributeId: 1.3.6.1.4.1.999.1.1.28.3 oMSyntax: 20 attributeSyntax: 2.5.5.4 isSingleValued: FALSE searchFlags: 1 description: "Languages a user speaks" Then run the following command: > ldifde -v -i -f create_attr.ldf 10.7.2.3 Using VBScript' This code illustrates how to create an attribute ' called rallencorp-LanguagesSpoken set objRootDSE = GetObject("LDAP://RootDSE") set objSchemaCont = GetObject("LDAP://" & _ objRootDSE.Get("schemaNamingContext") ) set objAttr = objSchemaCont.Create("attributeSchema", _ "cn=rallencorp-LanguagesSpoken") objAttr.Put "lDAPDisplayName", "rallencorp-LanguagesSpoken" objAttr.Put "attributeId", "1.3.6.1.4.1.999.1.1.28.3" objAttr.Put "oMSyntax", 20 objAttr.Put "attributeSyntax", "2.5.5.4" objAttr.Put "isSingleValued", FALSE objAttr.Put "description", "Languages a user speaks" objAttr.Put "searchFlags", 1 ' index the attribute objAttr.SetInfo WScript.Echo "Attribute created" 10.7.3 DiscussionTo create an attribute, you need to add an attributeSchema object to the Schema container. Typically, when you extend the schema, you perform several additions or modifications at once. The order of your extensions is very important. You can't create a class, assign an attribute, and then create the attribute; you obviously need to create the attribute before it can be assigned to the class. Even if you create the attribute before you assign it to a class, you must reload the schema before doing the class assignment. Reloading the schema is described in more detail in Recipe 10.22. Most of the attributes that can be set on attributeSchema objects are pretty straightforward, but a couple of them take a little explanation. The attributeSyntax and oMSyntax attributes together define the syntax, or the type of data that can be contained in the attribute. Table 10-3 shows the possible combinations of these two attributes and the resulting syntax.
The searchFlags attribute is a bit flag that defines special properties related to searching with the attribute. Table 10-4 contains the values that can be set for this attribute. The values are cumulative; so in order to index an attribute and include it in ANR searches, you would set a value of 5 (1 + 4).
10.7.4 See AlsoRecipe 4.12 for setting a bit flag, Recipe 10.9 for adding a new class, and Recipe 10.22 for reloading the schema |
[ Team LiB ] |