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

Examples

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       */
                               {"quentin@example.com", 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;   /* "quentin@example.com"  */
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);
    slapi_mods_done(&smods);

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