2 * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
3 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6 * Copyright (c) 1990 Regents of the University of Michigan.
16 #include <ac/socket.h>
17 #include <ac/string.h>
23 * ldap_modify_ext - initiate an ldap extended modify operation.
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
32 * sctrls Server Controls
33 * cctrls Client Controls
34 * msgidp Message ID pointer
38 * { LDAP_MOD_ADD, "cn", { "babs jensen", "babs", 0 } },
39 * { LDAP_MOD_REPLACE, "sn", { "jensen", 0 } },
42 * rc= ldap_modify_ext( ld, dn, mods, sctrls, cctrls, &msgid );
45 ldap_modify_ext( LDAP *ld,
56 * A modify request looks like this:
57 * ModifyRequet ::= SEQUENCE {
58 * object DistinguishedName,
59 * modifications SEQUENCE OF SEQUENCE {
60 * operation ENUMERATED {
65 * modification SEQUENCE {
67 * values SET OF AttributeValue
73 Debug( LDAP_DEBUG_TRACE, "ldap_modify_ext\n", 0, 0, 0 );
75 /* create a message to send */
76 if ( (ber = ldap_alloc_ber_with_options( ld )) == NULLBER ) {
77 return( LDAP_NO_MEMORY );
80 if ( ber_printf( ber, "{it{s{", ++ld->ld_msgid, LDAP_REQ_MODIFY, dn )
82 ld->ld_errno = LDAP_ENCODING_ERROR;
84 return( ld->ld_errno );
87 /* for each modification to be performed... */
88 for ( i = 0; mods[i] != NULL; i++ ) {
89 if (( mods[i]->mod_op & LDAP_MOD_BVALUES) != 0 ) {
90 rc = ber_printf( ber, "{e{s[V]}}",
91 mods[i]->mod_op & ~LDAP_MOD_BVALUES,
92 mods[i]->mod_type, mods[i]->mod_bvalues );
94 rc = ber_printf( ber, "{e{s[v]}}", mods[i]->mod_op,
95 mods[i]->mod_type, mods[i]->mod_values );
99 ld->ld_errno = LDAP_ENCODING_ERROR;
101 return( ld->ld_errno );
105 if ( ber_printf( ber, "}}" ) == -1 ) {
106 ld->ld_errno = LDAP_ENCODING_ERROR;
108 return( ld->ld_errno );
111 /* Put Server Controls */
112 if( ldap_int_put_controls( ld, sctrls, ber ) != LDAP_SUCCESS ) {
117 if ( ber_printf( ber, "}" ) == -1 ) {
118 ld->ld_errno = LDAP_ENCODING_ERROR;
120 return( ld->ld_errno );
123 /* send the message */
124 *msgidp = ldap_send_initial_request( ld, LDAP_REQ_MODIFY, dn, ber );
125 return( *msgidp < 0 ? ld->ld_errno : LDAP_SUCCESS );
129 * ldap_modify - initiate an ldap modify operation.
134 * dn DN of the object to modify
135 * mods List of modifications to make. This is null-terminated
136 * array of struct ldapmod's, specifying the modifications
140 * LDAPMod *mods[] = {
141 * { LDAP_MOD_ADD, "cn", { "babs jensen", "babs", 0 } },
142 * { LDAP_MOD_REPLACE, "sn", { "jensen", 0 } },
145 * msgid = ldap_modify( ld, dn, mods );
148 ldap_modify( LDAP *ld, LDAP_CONST char *dn, LDAPMod **mods )
152 Debug( LDAP_DEBUG_TRACE, "ldap_modify\n", 0, 0, 0 );
154 rc = ldap_modify_ext( ld, dn, mods, NULL, NULL, &msgid );
156 if ( rc != LDAP_SUCCESS )
163 ldap_modify_ext_s( LDAP *ld, LDAP_CONST char *dn,
164 LDAPMod **mods, LDAPControl **sctrl, LDAPControl **cctrl )
170 rc = ldap_modify_ext( ld, dn, mods, sctrl, cctrl, &msgid );
172 if ( rc != LDAP_SUCCESS )
175 if ( ldap_result( ld, msgid, 1, (struct timeval *) NULL, &res ) == -1 )
176 return( ld->ld_errno );
178 return( ldap_result2error( ld, res, 1 ) );
182 ldap_modify_s( LDAP *ld, LDAP_CONST char *dn, LDAPMod **mods )
184 return ldap_modify_ext_s( ld, dn, mods, NULL, NULL );