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 )) == NULL ) {
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 (ber_int_t) ( mods[i]->mod_op & ~LDAP_MOD_BVALUES ),
92 mods[i]->mod_type, mods[i]->mod_bvalues );
94 rc = ber_printf( ber, "{e{s[v]}}",
95 (ber_int_t) mods[i]->mod_op,
96 mods[i]->mod_type, mods[i]->mod_values );
100 ld->ld_errno = LDAP_ENCODING_ERROR;
102 return( ld->ld_errno );
106 if ( ber_printf( ber, /*{{*/ "}}" ) == -1 ) {
107 ld->ld_errno = LDAP_ENCODING_ERROR;
109 return( ld->ld_errno );
112 /* Put Server Controls */
113 if( ldap_int_put_controls( ld, sctrls, ber ) != LDAP_SUCCESS ) {
118 if ( ber_printf( ber, /*{*/ "}" ) == -1 ) {
119 ld->ld_errno = LDAP_ENCODING_ERROR;
121 return( ld->ld_errno );
124 /* send the message */
125 *msgidp = ldap_send_initial_request( ld, LDAP_REQ_MODIFY, dn, ber );
126 return( *msgidp < 0 ? ld->ld_errno : LDAP_SUCCESS );
130 * ldap_modify - initiate an ldap modify operation.
135 * dn DN of the object to modify
136 * mods List of modifications to make. This is null-terminated
137 * array of struct ldapmod's, specifying the modifications
141 * LDAPMod *mods[] = {
142 * { LDAP_MOD_ADD, "cn", { "babs jensen", "babs", 0 } },
143 * { LDAP_MOD_REPLACE, "sn", { "jensen", 0 } },
146 * msgid = ldap_modify( ld, dn, mods );
149 ldap_modify( LDAP *ld, LDAP_CONST char *dn, LDAPMod **mods )
153 Debug( LDAP_DEBUG_TRACE, "ldap_modify\n", 0, 0, 0 );
155 rc = ldap_modify_ext( ld, dn, mods, NULL, NULL, &msgid );
157 if ( rc != LDAP_SUCCESS )
164 ldap_modify_ext_s( LDAP *ld, LDAP_CONST char *dn,
165 LDAPMod **mods, LDAPControl **sctrl, LDAPControl **cctrl )
171 rc = ldap_modify_ext( ld, dn, mods, sctrl, cctrl, &msgid );
173 if ( rc != LDAP_SUCCESS )
176 if ( ldap_result( ld, msgid, 1, (struct timeval *) NULL, &res ) == -1 )
177 return( ld->ld_errno );
179 return( ldap_result2error( ld, res, 1 ) );
183 ldap_modify_s( LDAP *ld, LDAP_CONST char *dn, LDAPMod **mods )
185 return ldap_modify_ext_s( ld, dn, mods, NULL, NULL );