Table of Contents | Previous | Next | Index

Netscape Directory SDK 3.0 for C Programmer’s Guide
     Chapter 17 Data Types and Structures

LDAPMod

LDAPMod is a type of structure that you use to specify changes to an attribute in an directory entry. Before you call the ldap_add_ext(), ldap_add_ext_s(), ldap_modify_ext(), or ldap_modify_ext_s() routines to add or modify an entry in the directory, you need to fill LDAPMod structures with the attribute values that you intend to add or change.

LDAPMod is defined as follows:

typedef struct ldapmod {
   int mod_op;
   char *mod_type;
   union {
      char **modv_strvals;
      struct berval **modv_bvals;
   } mod_vals;
#define mod_values mod_vals.modv_strvals
#define mod_bvalues mod_vals.modv_bvals
} LDAPMod;
The fields in this structure are described below:

mod_op

The operation to be performed on the attribute and the type of data specified as the attribute values. This field can have one of the following values:

In addition, if you are specifying binary values in the mod_bvalues field, you should use the bitwise OR operator ( | ) to combine LDAP_MOD_BVALUES with the operation type. For example:

mod->mod_op = LDAP_MOD_ADD | LDAP_MOD_BVALUES

NOTE: If you are using the structure to add a new entry, you can specify 0 for the mod_op field (unless you are adding binary values and need to specify LDAP_MOD_BVALUES). See "Adding a New Entry" for details.

mod_type

The attribute type that you want to add, delete, or replace the values of (for example, "sn" or "telephoneNumber").

mod_values 

A pointer to a NULL-terminated array of string values for the attribute.

mod_bvalues 

A pointer to a NULL-terminated array of berval structures for the attribute.

Note the following:

If you've allocated memory for the structures yourself, you should free the structures when you're finished by calling the ldap_mods_free() function.

The following section of code sets up an LDAPMod structure to change the email address of a user's entry to "bjensen@airius.com":

LDAP *ld;
LDAPMod attribute1;
LDAPMod *list_of_attrs[2];
char *mail_values[] = { "bjensen@airius.com", NULL };
char *dn;
...
/* Identify the entry that you want changed */
char *dn = "uid=bjensen, ou=People, o=Airius.com";
/* Specify that you want to replace the value of an attribute */
attribute1.mod_op = LDAP_MOD_REPLACE;
/* Specify that you want to change the value of the mail attribute */
attribute1.mod_type = "mail";
/* Specify the new value of the mail attribute */
attribute1.mod_values = mail_values;
/* Add the change to the list of attributes that you want changed */
list_of_attrs[0] = &attribute_change;
list_of_attrs[1] = NULL;
/* Update the entry with the change */
if ( ldap_modify_s( ld, dn, list_of_attrs ) != LDAP_SUCCESS ) {
   ldap_perror( ld, "ldap_modify_s" );
   return( 1 );
}
...

Table of Contents | Previous | Next | Index

Last Updated: 10/01/98 17:05:28