2.6 Schema Tasks

This section provides procedures for modifying the schema by deleting or creating classes and attributes. It also provides procedures for reading the schema definitions: classes, attributes, and syntaxes. See one of the following:

2.6.1 Creating a Class Definition

Defining a new object class for the eDirectory Schema is done with the following steps:

  1. Allocate a structure of type Class_Info_T and fill it in.

  2. Allocate a request buffer by calling NWDSAllocBuf.

  3. Initialize the request buffer for a DSV_DEFINE_CLASS operation by calling NWDSInitBuf.

  4. Prepare the request buffer for storing object-class names in the Super Class Names list by calling NWDSBeginClassItem.

  5. Place the desired object-class names in the Super Class List by calling NWDSPutClassItem once for each object-class name to be placed in the list.

  6. Prepare the request buffer for storing object-class names in the Containment Class Names list by calling NWDSBeginClassItem.

  7. Place the desired object-class names in the Containment Class Names list by calling NWDSPutClassItem once for each object-class name to be placed in the list.

  8. Prepare the request buffer for storing naming-attribute names in the Naming Attributes List by calling NWDSBeginClassItem.

  9. Place the desired naming-attribute names in the Naming Attributes List by calling NWDSPutClassItem once for each naming-attribute name to be placed in the list.

  10. Prepare the request buffer for storing attribute names in the Mandatory Attribute Names list by calling NWDSBeginClassItem.

  11. Place the desired attribute names in the Mandatory Attribute Names list by calling NWDSPutClassItem once for each attribute name to be placed in the list.

  12. Prepare the request buffer for storing attribute names in the Optional Attribute Names list by calling NWDSBeginClassItem.

  13. Place the desired attribute names in the Optional Attribute Names list by calling NWDSPutClassItem once for each attribute name to be added to the list.

  14. Add the object-class definition to the eDirectory Schema by calling NWDSDefineClass.

  15. Free the request buffer by calling NWDSFreeBuf.

NOTE:If you do not have any object names or attribute names you want to add to one of the lists, you must still call NWDSBeginClassItem to move to the list. You then immediately call NWDSBeginClassItem again to move to the next list.

See Also:

2.6.2 Creating an Attribute Definition

  1. Declare a structure of type Attr_Info_T and fill it.

  2. Create a new attribute definition to define the attribute by calling NWDSDefineAttr.

    NWDSDefineAttr requires three arguments: the directory context handle, the name of the new attribute in a string, and the address of the data structure of the attribute.

See Also:

2.6.3 Deleting a Class Definition

You can delete a class definition using a straightforward function called NWDSRemoveClassDef, as shown in the following example:

  ccode = NWDSRemoveClassDef(context, "Toaster"); 
  if (ccode != 0) 
     printf("Error while deleting class definition: %d\n", ccode);
  

NWDSRemoveClassDef requires two arguments: the NDS context handle and the name of the class to be deleted.

NOTE:You cannot remove base class definitions, nor can you remove any class until all of the objects associated with that class have been removed from the eDirectory tree.

See Also:

2.6.4 Deleting an Attribute Definition

Delete an attribute definition by calling NWDSRemoveAttrDef. If you wanted to delete the attribute “Toast Setting”, you would enter the following code:

  ccode = NWDSRemoveAttrDef(context, "Toast Setting"); 
  if (ccode != 0) 
     printf("Error while removing attribute: %d\n", ccode);
  

This function requires only two arguments: the NDS context handle and the name of the attribute to be deleted.

NOTE:You cannot remove an attribute that is part of the Base class, nor can you remove an attribute that you have added to the Base class definition.

See Also:

2.6.5 Listing Containable Classes

Use this procedure to list the object classes that can be contained by (are subordinate to) a specified object.

  1. Allocate a result buffer by calling NWDSAllocBuf. (The buffer does not need to be initialized since it is a result buffer.)

  2. Set iterationHandle to NO_MORE_ITERARTIONS.

  3. Retrieve the object classes the parent object can contain by calling NWDSListContainableClasses.

  4. Determine the number of object-class names contained in the buffer by calling NWDSGetClassItemCount.

  5. For each object class name in the result buffer, retrieve the name by calling NWDSGetClassItem.

  6. If the value of the iteration handle is not equal to NO_MORE_ITERATIONS, go to Step 3. Otherwise, go to Step 7.

  7. Free the result buffer by calling NWDSFreeBuf.

Aborting Iterative Operations

If you need information on aborting an iterative operation, see Controlling Iterations.

See Also:

2.6.6 Modifying a Class Definition

Optional attributes can be added to an object class definition by using the following steps:

  1. Allocate a request buffer by calling NWDSAllocBuf.

  2. Initialize the request buffer for a DS_MODIFY_CLASS_DEF operation by calling NWDSInitBuf.

  3. For each optional attribute to be added to the class definition, store the attribute’s name in the request buffer by calling NWDSPutAttrName.

  4. Modify the object class definition by calling NWDSModifyClassDef.

  5. Free the request buffer by calling NWDSFreeBuf.

See Also:

2.6.7 Reading a Class Definition

Use the following steps to retrieve information about object-class definitions in the eDirectory Schema.

  1. Allocate a request buffer by calling NWDSAllocBuf. (If you are retrieving information about all class definitions, you do not need a request buffer and can skip Steps 1 through 3.)

  2. Initialize the request buffer for a DSV_READ_CLASS_DEF operation by calling NWDSInitBuf.

  3. For each object class you want to receive information about, store the object-class name in the request buffer by calling NWDSPutClassName.

  4. Allocate a result buffer by calling NWDSAllocBuf. (It does not need to be initialized since it is a result buffer.)

  5. Set the contents of the iteration handle to NO_MORE_ITERATIONS.

  6. Retrieve the object-class information by calling NWDSReadClassDef.

  7. Determine the number of object classes whose information is in the result buffer by calling NWDSGetClassDefCount.

  8. If you have chosen object names and definitions, retrieve each object-class definition from the buffer by using the steps in the “Object Class Procedure List” that follows this list.

  9. If the iteration handle is not set to NO_MORE_ITERATIONS, loop to Step 6 to retrieve more information about object classes. Otherwise, go to Step 10.

  10. Free the request buffer by calling NWDSFreeBuf.

  11. Free the result buffer by calling NWDSFreeBuf.

Object Class Procedure List. For each object-class definition in the buffer, take the following steps to remove the information:

  1. Read the name (and other information) of the current object class whose definition is in the buffer by calling NWDSGetClassDef.

    If you called NWDSReadClassDef with infoType set to DS_INFO_CLASS_DEFS, skip the rest of the following steps. With this infoType, the NWDSGetClassDef function retrieves all the information about the class from the buffer. Repeat Step 1 for each object-class definition in the buffer.

  2. Move to the result buffer’s Super Class Names list and determine the number of super-class names in the list by calling NWDSGetClassItemCount. (Moving to the list and determining the number of class names is accomplished with one call to NWDSGetClassItemCount.)

  3. For each super-class name in the Super Class Names list, retrieve the super-class name by calling NWDSGetClassItem.

  4. Move to the result buffer’s Containment Class Names list and determine the number of containment-class names in the list by calling NWDSGetClassItemCount.

  5. For each containment class name in the Containment Class Names list, retrieve the containment-class name by calling NWDSGetClassItem.

  6. Move to the result buffer’s Naming Attribute Names list and determine the number of naming-attribute names in the list by calling NWDSGetClassItemCount.

  7. For each naming-attribute name in the Naming Attribute Names list, retrieve the naming-attribute name by calling NWDSGetClassItem.

  8. Move to the result buffer’s Mandatory Attribute Names list and determine the number of mandatory-attribute names in the list by calling NWDSGetClassItemCount.

  9. For each mandatory-attribute name in the Mandatory Attribute Names list, retrieve the naming attribute name by calling NWDSGetClassItem.

  10. Move to the result buffer’s Optional Attribute Names list and determine the number of optional-attribute names in the list by calling NWDSGetClassItemCount.

  11. For each optional-attribute name in the Optional Attribute Names list, retrieve the optional-attribute name by calling NWDSGetClassItem.

If you want to determine the names of all of the classes and their definitions, use NWDSReadClassDef as follows:

  ccode = NWDSReadClassDef(context, DS_CLASS_DEF_NAMES, TRUE, NULL, 
                           &iterationHandle, outBuffer); 
  if (ccode != 0) 
     printf("Error while reading class definition: %d\n", ccode);
  

NOTE:A call to NWDSReadClassDef returns only the attributes that were defined for that particular class. It does not return the attributes that were inherited, but it does return the name of the super class. To find all of the attributes available for a class, call NWDSReadClassDef for each super class until you reach Top.

See Also:

2.6.8 Reading an Attribute Definition

To retrieve information about selected attribute definitions use the following steps:

  1. Allocate a request buffer by calling NWDSAllocBuf. (If you want information about all attributes, you do not need a request buffer and can skip Steps 1 through 3.

  2. Initialize the request buffer for a DSV_READ_ATTR_DEF operation by calling NWDSInitBuf.

  3. For each attribute whose information you want to retrieve, store the attribute’s name in the request buffer by calling NWDSPutAttrName.

  4. Allocate a result buffer by calling NWDSAllocBuf. (This buffer does not need to be initialized since it is a result buffer.)

  5. Set the contents of the iteration handle to NO_MORE_ITERATIONS.

  6. Call NWDSReadAttrDef with infoType set to DS_ATTR_DEF_NAMES to retrieve names only, or set to DS_ATRR_DEFS to retrieve names and attribute definitions. Set allAttrs to FALSE if you are using a request buffer, or to TRUE if you are not using a request buffer.

  7. Determine the number of attributes whose information is in the result buffer by calling NWDSGetAttrCount.

  8. For each attribute in the buffer, remove the attribute information by calling NWDSGetAttrDef.

  9. If the iteration handle is not set to NO_MORE_ITERATIONS, loop to Step 6 to retrieve additional attribute information. Otherwise, go to Step 10.

  10. Free the request buffer by calling NWDSFreeBuf.

  11. Free the result buffer by calling NWDSFreeBuf.

Reading an attribute definition by using NWDSReadAttrDef is shown in the following example:

  ccode = NWDSReadAttrDef(context, DS_ATTR_DEFS, FALSE, inBuf, 
                          &iterationHandle, outBuf); 
  if (ccode != 0) 
     printf("Error reading attribute definition: %d\n", ccode);
  

See Also:

2.6.9 Retrieving Syntax Names and Definitions

To retrieve names and definitions for all syntaxes in the eDirectory Schema, use the following steps:

  1. Allocate memory for the result buffer by calling NWDSAllocBuf. (This buffer does not need to be initializes, since it is a result buffer.)

  2. Set the contents of the iteration handle to NO_MORE_ITERATIONS.

  3. Call NWDSReadSyntaxes with infoType =DS_SYNTAX_DEFS, allSyntaxes =TRUE, and syntaxNames =NULL.

  4. Determine the number of syntax definitions in the result buffer by calling NWDSGetSyntaxCount.

  5. For each syntax in the result buffer, retrieve the syntax name and definition by calling NWDSGetSyntaxDef.

  6. If the contents of the iteration handle is not set to NO_MORE_ITERATIONS, loop to Step 3. Otherwise, go to Step 7.

  7. Free the result buffer by calling NWDSFreeBuf.

To retrieve information about specific syntaxes, rather than all syntaxes in the eDirectory Schema, do the following:

  1. Allocate memory for the request buffer by calling NWDSAllocBuf.

  2. Initialize the request buffer for a DSV_READ_SYNTAXES operation by calling NWDSInitBuf.

  3. For each syntax whose information you want to retrieve, store the syntax’s name in the request buffer by calling NWDSPutSyntaxName.

  4. Allocate memory for the result buffer by calling NWDSAllocBuf. (This buffer does not need to be initialized since it is a result buffer.)

  5. Set the contents of the iteration handle to NO_MORE_ITERATIONS.

  6. Call NWDSReadSyntaxes with infoType =DS_SYNTAX_DEFS, allSyntaxes =FALSE, and syntaxNames =the address of the request buffer.

  7. Determine the number of syntax definitions in the result buffer by calling NWDSGetSyntaxCount.

  8. For each syntax in the buffer, retrieve the syntax name and definition by calling NWDSGetSyntaxDef.

  9. If the contents of the iteration handle is not set to NO_MORE_ITERATIONS, loop to Step 6. Otherwise, go to Step 10.

  10. Free the request buffer by calling NWDSFreeBuf.

  11. Free the result buffer by calling NWDSFreeBuf.

See Also: