Sun Java System Directory Server Enterprise Edition 6.0 Developer's Guide


Represents a modification to an attribute in a directory entry.


/* Defined in ldap.h, which is included by slapi-plugin.h */
#include "slapi-plugin.h"
typedef struct ldapmod {
    int                  mod_op;
    char               * mod_type;
    union {
        char          ** modv_strvals;
        struct berval ** modv_bvals;
    } mod_vals;
} LDAPMod;
#define mod_values  mod_vals.modv_strvals
#define mod_bvalues mod_vals.modv_bvals


This structure has the following fields.

Table 15–5 LDAPMod Fields




Operation to perform and data type of attribute values. 

The mod_op field takes the following values specifying the operation to perform.

  • LDAP_MOD_ADD to add the attribute values to the entry.

  • LDAP_MOD_DELETE to remove the attribute values from the entry.

  • LDAP_MOD_REPLACE to replace existing attribute values.

    To specify binary values, bitwise OR the macro LDAP_MOD_BVALUES with the operation type identifier.

    mod->mod_op = LDAP_MOD_ADD|LDAP_MOD_BVALUES;


Attribute type to modify. 


Pointer to NULL terminated array of string values for the attribute.


Pointer to NULL terminated array of berval structures for the attribute.


Example 15–1 sets up an LDAPMod to change an mail address.

Example 15–1 Preparing Modifications to an Entry

#include "slapi-plugin.h"
/* Declare the appropriate structures.                       */
LDAPMod          mod_attr;         /* Attribute to modify    */
LDAPMod        * mods[2];          /* Array of modifications */
char           * mail_vals[] =     /* New mail address       */
                               {"", NULL};

/* Set up the LDAPMod structure used to modify the entry.    */
mod_attr.mod_type   = "mail";
mod_attr.mod_op     = LDAP_MOD_REPLACE;
mod_attr.mod_values = mail_vals;   /* ""  */
mods[0]             = &mod_attr;
mods[1]             = NULL;

/* Modify the entry using slapi_modify_internal_set_pb()...  */

Example 15–2 optionally adds additional modifications to those present in the parameter block. This code might be part of a pre-operation modify plug-in function, for example.

Example 15–2 Adding Further Modifications

#include "slapi-plugin.h"

 * Set up an LDAPMod array, modify_mods, of additional modifications.

if (modify_mods != NULL) {
    LDAPMod ** mods;
    Slapi_Mods smods;
    int        i;

    slapi_pblock_get(pb, SLAPI_MODIFY_MODS, &mods);
    slapi_mods_init_passin(&smods, mods);

    for (i = 0; modify_mods[i] != NULL; i++) {
        /* Do not copy mods.                                        */
        slapi_mods_add_ldapmod(&smods, modify_mods[i]);

    mods = slapi_mods_get_ldapmods_passout(&smods);
    slapi_pblock_set(pb, SLAPI_MODIFY_MODS, mods);

    /* Release container only. Content is still pointed to by mods. */
    slapi_ch_free((void **)&modify_mods);