3 * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
7 * Copyright (c) 1990 Regents of the University of Michigan.
13 * Portions Copyright (C) The Internet Society (1997)
14 * ASN.1 fragments are from RFC 2251; see RFC for full legal notices.
21 #include <ac/socket.h>
22 #include <ac/string.h>
28 * ldap_modify_ext - initiate an ldap extended modify operation.
33 * dn DN of the object to modify
34 * mods List of modifications to make. This is null-terminated
35 * array of struct ldapmod's, specifying the modifications
37 * sctrls Server Controls
38 * cctrls Client Controls
39 * msgidp Message ID pointer
43 * { LDAP_MOD_ADD, "cn", { "babs jensen", "babs", 0 } },
44 * { LDAP_MOD_REPLACE, "sn", { "babs jensen", "babs", 0 } },
45 * { LDAP_MOD_DELETE, "ou", 0 },
46 * { LDAP_MOD_INCREMENT, "uidNumber, { "1", 0 } }
49 * rc= ldap_modify_ext( ld, dn, mods, sctrls, cctrls, &msgid );
52 ldap_modify_ext( LDAP *ld,
64 * A modify request looks like this:
65 * ModifyRequet ::= SEQUENCE {
66 * object DistinguishedName,
67 * modifications SEQUENCE OF SEQUENCE {
68 * operation ENUMERATED {
72 * increment (3) -- extension
74 * modification SEQUENCE {
76 * values SET OF AttributeValue
83 LDAP_LOG ( OPERATION, ENTRY, "ldap_modify_ext\n", 0, 0, 0 );
85 Debug( LDAP_DEBUG_TRACE, "ldap_modify_ext\n", 0, 0, 0 );
88 /* check client controls */
89 rc = ldap_int_client_controls( ld, cctrls );
90 if( rc != LDAP_SUCCESS ) return rc;
92 /* create a message to send */
93 if ( (ber = ldap_alloc_ber_with_options( ld )) == NULL ) {
94 return( LDAP_NO_MEMORY );
97 LDAP_NEXT_MSGID( ld, id );
98 rc = ber_printf( ber, "{it{s{" /*}}}*/, id, LDAP_REQ_MODIFY, dn );
100 ld->ld_errno = LDAP_ENCODING_ERROR;
102 return( ld->ld_errno );
105 /* for each modification to be performed... */
106 for ( i = 0; mods[i] != NULL; i++ ) {
107 if (( mods[i]->mod_op & LDAP_MOD_BVALUES) != 0 ) {
108 rc = ber_printf( ber, "{e{s[V]N}N}",
109 (ber_int_t) ( mods[i]->mod_op & ~LDAP_MOD_BVALUES ),
110 mods[i]->mod_type, mods[i]->mod_bvalues );
112 rc = ber_printf( ber, "{e{s[v]N}N}",
113 (ber_int_t) mods[i]->mod_op,
114 mods[i]->mod_type, mods[i]->mod_values );
118 ld->ld_errno = LDAP_ENCODING_ERROR;
120 return( ld->ld_errno );
124 if ( ber_printf( ber, /*{{*/ "N}N}" ) == -1 ) {
125 ld->ld_errno = LDAP_ENCODING_ERROR;
127 return( ld->ld_errno );
130 /* Put Server Controls */
131 if( ldap_int_put_controls( ld, sctrls, ber ) != LDAP_SUCCESS ) {
136 if ( ber_printf( ber, /*{*/ "N}" ) == -1 ) {
137 ld->ld_errno = LDAP_ENCODING_ERROR;
139 return( ld->ld_errno );
142 /* send the message */
143 *msgidp = ldap_send_initial_request( ld, LDAP_REQ_MODIFY, dn, ber, id );
144 return( *msgidp < 0 ? ld->ld_errno : LDAP_SUCCESS );
148 * ldap_modify - initiate an ldap modify operation.
153 * dn DN of the object to modify
154 * mods List of modifications to make. This is null-terminated
155 * array of struct ldapmod's, specifying the modifications
159 * LDAPMod *mods[] = {
160 * { LDAP_MOD_ADD, "cn", { "babs jensen", "babs", 0 } },
161 * { LDAP_MOD_REPLACE, "sn", { "babs jensen", "babs", 0 } },
162 * { LDAP_MOD_DELETE, "ou", 0 },
163 * { LDAP_MOD_INCREMENT, "uidNumber, { "1", 0 } }
166 * msgid = ldap_modify( ld, dn, mods );
169 ldap_modify( LDAP *ld, LDAP_CONST char *dn, LDAPMod **mods )
174 LDAP_LOG ( OPERATION, ENTRY, "ldap_modify\n", 0, 0, 0 );
176 Debug( LDAP_DEBUG_TRACE, "ldap_modify\n", 0, 0, 0 );
179 rc = ldap_modify_ext( ld, dn, mods, NULL, NULL, &msgid );
181 if ( rc != LDAP_SUCCESS )
188 ldap_modify_ext_s( LDAP *ld, LDAP_CONST char *dn,
189 LDAPMod **mods, LDAPControl **sctrl, LDAPControl **cctrl )
195 rc = ldap_modify_ext( ld, dn, mods, sctrl, cctrl, &msgid );
197 if ( rc != LDAP_SUCCESS )
200 if ( ldap_result( ld, msgid, 1, (struct timeval *) NULL, &res ) == -1 )
201 return( ld->ld_errno );
203 return( ldap_result2error( ld, res, 1 ) );
207 ldap_modify_s( LDAP *ld, LDAP_CONST char *dn, LDAPMod **mods )
209 return ldap_modify_ext_s( ld, dn, mods, NULL, NULL );