14.4. LDAPMod
slapi_add_internal_pb() and slapi_modify_internal_pb() 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.
bab@example.com:
Slapi_PBlock *mod_pb = slapi_pblock_new();
LDAPMod attribute1;
LDAPMod *list_of_attrs[2];
char *mail_values[] = { "bab@example.com" , NULL };
Slapi_DN *dn;
int ret = 0;
...
...
/* Identify the entry that you want changed */
dn = "cn=Barbara Jensen, ou=Product Development, l=US, dc=example,dc=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 */
slapi_modify_internal_set_pb(mod_pb, config_entry->dn,
list_of_attrs, 0, 0, getPluginID(), 0);
slapi_modify_internal_pb(mod_pb);
slapi_pblock_get(mod_pb, SLAPI_PLUGIN_INTOP_RESULT, &ret);
slapi_pblock_destroy(mod_pb);
...
...
Table 14.4. Frontend API Functions for Entry Attribute Changes
| To perform this action... | Call this function |
|---|---|
| Translate from entry to LDAPMod. | slapi_entry2mods() |
| Dump the contents of an LDAPMod to the server log. | slapi_mod_dump() |
| Get a reference to the LDAPMod in a Slapi_Mod structure. | slapi_mod_get_ldapmod_byref() |
| Retrieve the reference to the LDAPMod contained in a Slapi_Mod structure. | slapi_mod_get_ldapmod_passout() |
This struct definition uses the following syntax:
typedef struct ldapmod {
int mod_op;
char *mod_type;
union mod_vals_u{
char **modv_strvals;
struct berval **modv_bvals;
} mod_vals;
#define mod_values mod_vals.modv_strvals
#define mod_bvalues mod_vals.modv_bvals
} LDAPMod;
This struct definition contains the following fields:
Table 14.5. ldapmod Field Listing
| Field | Description |
|---|---|
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:
LDAP_MOD_BVALUES with the operation type. For example:
mod->mod_op = LDAP_MOD_ADD | LDAP_MOD_BVALUES |
mod_type | Pointer to the attribute type that you want to add, delete, or replace. |
mod_values_u | A NULL-terminated array of string values for the attribute. |
modv_strvals | Pointer to a NULL terminated array of string values for the attribute. |
mod_bvalues | Pointer to a NULL-terminated array of berval structures for the attribute. |
mod_vals | Values that you want to add, delete, or replace. |

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.