2 * Copyright (c) 1990 Regents of the University of Michigan.
11 static char copyright[] = "@(#) Copyright (c) 1990 Regents of the University of Michigan.\nAll rights reserved.\n";
16 #include <ac/socket.h>
17 #include <ac/string.h>
25 * ldap_modify - initiate an ldap (and X.500) modify operation. Parameters:
28 * dn DN of the object to modify
29 * mods List of modifications to make. This is null-terminated
30 * array of struct ldapmod's, specifying the modifications
35 * { LDAP_MOD_ADD, "cn", { "babs jensen", "babs", 0 } },
36 * { LDAP_MOD_REPLACE, "sn", { "jensen", 0 } },
39 * msgid = ldap_modify( ld, dn, mods );
42 ldap_modify( LDAP *ld, char *dn, LDAPMod **mods )
48 * A modify request looks like this:
49 * ModifyRequet ::= SEQUENCE {
50 * object DistinguishedName,
51 * modifications SEQUENCE OF SEQUENCE {
52 * operation ENUMERATED {
57 * modification SEQUENCE {
59 * values SET OF AttributeValue
65 Debug( LDAP_DEBUG_TRACE, "ldap_modify\n", 0, 0, 0 );
67 /* create a message to send */
68 if ( (ber = ldap_alloc_ber_with_options( ld )) == NULLBER ) {
72 if ( ber_printf( ber, "{it{s{", ++ld->ld_msgid, LDAP_REQ_MODIFY, dn )
74 ld->ld_errno = LDAP_ENCODING_ERROR;
79 /* for each modification to be performed... */
80 for ( i = 0; mods[i] != NULL; i++ ) {
81 if (( mods[i]->mod_op & LDAP_MOD_BVALUES) != 0 ) {
82 rc = ber_printf( ber, "{e{s[V]}}",
83 mods[i]->mod_op & ~LDAP_MOD_BVALUES,
84 mods[i]->mod_type, mods[i]->mod_bvalues );
86 rc = ber_printf( ber, "{e{s[v]}}", mods[i]->mod_op,
87 mods[i]->mod_type, mods[i]->mod_values );
91 ld->ld_errno = LDAP_ENCODING_ERROR;
97 if ( ber_printf( ber, "}}}" ) == -1 ) {
98 ld->ld_errno = LDAP_ENCODING_ERROR;
103 /* send the message */
104 return( ldap_send_initial_request( ld, LDAP_REQ_MODIFY, dn, ber ));
108 ldap_modify_s( LDAP *ld, char *dn, LDAPMod **mods )
113 if ( (msgid = ldap_modify( ld, dn, mods )) == -1 )
114 return( ld->ld_errno );
116 if ( ldap_result( ld, msgid, 1, (struct timeval *) NULL, &res ) == -1 )
117 return( ld->ld_errno );
119 return( ldap_result2error( ld, res, 1 ) );