[Date Prev][Date Next] [Chronological] [Thread] [Top]

Re: ldap_modify()

I agree its bit complicated. The main reason being that it allows multiple
values to an attribute. But once we understand its a beauty,

It gets better with an example.

  char *vals[2];	//List of values of an attribute. list should be
				null terminated
  LDAPMod mod;		// this structure stores list of values of an
attribute, attribute name and operation to be performed on the attribute.

  LDAPMod *mods[2]; 	// List of attributes to modify at a time, List
				should be null terminated.

    vals[0] = (char *)&Buffer;
    vals[1] = NULL;
    mod.mod_op = LDAP_MOD_REPLACE;
    mod.mod_type = (char *) &Attr;
    mod.mod_values = vals;
    mods[0] = &mod;
    mods[1] = NULL;

    if ( ldap_modify_s (ld, MODDN, mods) < 0 ) {
	   ldap_perror( ld, "ldap_modify_s");
      	   exit (1);
 Assuming other mandatory connection and authentication steps are
performed, the above segemnt will store the value of attribute in Buffer.
If you have many values, store it in many buffers and make vals[0] point to
1st value, vals[1] to 2nd value and so on. Finally terminate the list by
NULL. In above segment, there is only one value, hence vals[1] = NULL.

mod.mod_op stores type of operation, (details in Man page)
mod.mod_type stores pointer to attribute name
and mod.mod_values store pointer to list of values.

Simillarly you can have many attributes in different instances os mod
structure and assign the pointer to each structure to list of LdapMod.
hence mods[0] = &mod and since only one attribute is to be changed,
mods[1] = NULL.

just plug in above structure as arguments to ldap_modify (ld, MODDN, mods)
where MODDN is the DN of entry.

Hope this helps.

On Thu, 29 Jul 1999, Patrik Eichenberger wrote:

> Hi there,
> I would like to use the API C function ldap_modify() in a client to
> modify some entries.
> Could someone tell me, how I have to use this function ?
> How do I have to fill up the LDAPMod structure ?
> Thanks
> Patrik Eichenberger