Table of Contents | Previous | Next | Index

Netscape Directory SDK 3.0 for C Programmer’s Guide
     Chapter 18 Functions

ldap_modify_s()

Modifies an existing entry in the directory synchronously.

Note that this is an older function that is included in the LDAP API for backward-compatibility. If you are writing a new LDAP client, use ldap_modify_ext_s() instead.

Syntax

#include <ldap.h>
int ldap_modify_s( LDAP *ld, const char *dn, LDAPMod **mods );

Parameters

This function has the following parameters:

ld

Connection handle, which is a pointer to an LDAP structure containing information about the connection to the LDAP server.

dn

Distinguished name (DN) of the entry to modify.

mods

Pointer to a NULL-terminated array of pointers to LDAPMod structures for the attributes you want modified.

Returns

For a list of possible result codes for an LDAP modify operation, see the result code documenation for the ldap_modify_ext_s() function.

Description

The ldap_modify_s() function updates an entry in the directory.

A newer version of this function, ldap_modify_ext_s(), is available in this release of the LDAP API. ldap_modify_s() (the older version of the function) is included only for backward-compatibility. If you are writing a new LDAP client, use ldap_modify_ext_s() instead of ldap_modify_s().

If you want more information on ldap_modify_s(), refer to the LDAP C SDK 1.0 Programmer's Guide.

Example

The following section of code uses the synchronous ldap_modify_s() function to makes the following changes to the "Barbara Jensen" entry:

  1. Adds the homePhone attribute.
  2. Changes the telephoneNumber attribute.
  3. Removes the facsimileTelephoneNumber attribute.
  4. #include <ldap.h>
    ...
    LDAP *ld;
    LDAPMod *list_of_attrs[4];
    LDAPMod attribute1, attribute2, attribute3;
    LDAPControl **srvrctrls, **clntctrls;
    /* Distinguished name of the entry that you want to modify. */
    char *dn = "uid=bjensen, ou=People, o=Airius.com";
    /* Values to add or change */
    char *homePhone_values[] = { "555-1212", NULL };
    char *telephoneNumber_values[] = { "869-5309", NULL };
    ...
    /* Specify each change in separate LDAPMod structures */
    attribute1.mod_type = "homePhone";
    attribute1.mod_op = LDAP_MOD_ADD;
    attribute1.mod_values = homePhone_values;
    attribute2.mod_type = "telephoneNumber";
    attribute2.mod_op = LDAP_MOD_REPLACE;
    attribute2.mod_values = telephoneNumber_values;
    attribute3.mod_type = "facsimileTelephoneNumber";
    attribute3.mod_op = LDAP_MOD_DELETE;
    attribute3.mod_values = NULL;
    /* NOTE: When removing entire attributes, you need to specify a NULL value for the mod_values or mod_bvalues field. */
    /* Add the pointers to these LDAPMod structures to an array */
    list_of_attrs[0] = &attribute1;
    list_of_attrs[1] = &attribute2;
    list_of_attrs[2] = &attribute3;
    list_of_attrs[3] = NULL;
    ...
    /* Change the entry */
    if ( ldap_modify_s( ld, dn, list_of_attrs ) != LDAP_SUCCESS ) {
       ldap_perror( ld, "ldap_modify_s" );
       return( 1 );
    }
    ...

See Also

ldap_modify_ext_s().


Table of Contents | Previous | Next | Index

Last Updated: 10/01/98 17:06:23