2.3 Adding an Entry

To add an entry to the directory, the client must have create permissions to the container that will be the entry's parent container. Entries can be created programmatically or from an LDIF file. (For more information on using an LDIF file, see Adding Entries.)

To add an entry programmatically, complete the following steps.

  1. Create an LDAPMod structure for each attribute that will be added with the entry.

    You need a structure for each attribute. For example, an entry with a base class of inetOrgPerson requires LDAPMod structures for the following attributes: cn, sn, and objectClass. If you want the entry to log in to the directory, the entry also requires a structure for the userPassword attribute.

  2. In each structure, set the modification operation to LDAP_MOD_ADD and the type to the name of the attribute. Add a NULL-terminated string of values for each attribute.

  3. Add each structure to a NULL-terminated array of LDAPMod structures.

  4. Set the dn for the entry.

    The containers in the entry's dn must already exist in the directory.

  5. Call the ldap_add_ext_s function to add the entry.

For sample code, see addentry.c.