Table of Contents | Previous | Next | Index

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

ldap_modify()

Modifies an existing entry in the directory asynchronously.

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() instead.

Syntax

#include <ldap.h>
int ldap_modify( 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 representing the attributes that you want to modify.

Returns

Returns the message ID of the ldap_modify() operation. To check the result of this operation, call ldap_result() and ldap_result2error(). For a list of possible result codes for an LDAP modify operation, see the result code documentation on the ldap_modify_ext_s() function.

Description

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

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

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

Example

The following section of code uses the asynchronous ldap_modify() function to modify the entry for "Barbara Jensen" in the directory. The example makes the following changes to the 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;
    LDAPMessage *result;
    int msgid, rc;
    struct timeval tv;
    /* 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 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;
    ...
    /* Set up the timeout period to wait for the "modify" operation */
    tv.tv_sec = tv.tv_usec = 0;
    /* Change the entry */
    if ( ( msgid = ldap_modify( ld, dn, list_of_attrs ) ) == -1 ) {
       ldap_perror( ld, "ldap_modify" );
       return( 1 );
    }
    /* Check to see if the operation has completed */
    while ( ( rc = ldap_result( ld, msgid, 0, &tv, &result ) ) == 0 ) {
       ...
       /* do other work while waiting for the operation to complete */
       ...
    }
    /* Check the result to see if any errors occurred */
    ldap_result2error( ld, result, 1 );
    ldap_perror( ld, "ldap_modify" );
    ...

See Also

ldap_modify_ext().


Table of Contents | Previous | Next | Index

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