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.
17 #include <ac/socket.h>
18 #include <ac/string.h>
24 * ldap_modify_ext - initiate an ldap extended modify operation.
29 * dn DN of the object to modify
30 * mods List of modifications to make. This is null-terminated
31 * array of struct ldapmod's, specifying the modifications
33 * sctrls Server Controls
34 * cctrls Client Controls
35 * msgidp Message ID pointer
39 * { LDAP_MOD_ADD, "cn", { "babs jensen", "babs", 0 } },
40 * { LDAP_MOD_REPLACE, "sn", { "jensen", 0 } },
43 * rc= ldap_modify_ext( ld, dn, mods, sctrls, cctrls, &msgid );
46 ldap_modify_ext( LDAP *ld,
58 * A modify request looks like this:
59 * ModifyRequet ::= SEQUENCE {
60 * object DistinguishedName,
61 * modifications SEQUENCE OF SEQUENCE {
62 * operation ENUMERATED {
67 * modification SEQUENCE {
69 * values SET OF AttributeValue
76 LDAP_LOG ( OPERATION, ENTRY, "ldap_modify_ext\n", 0, 0, 0 );
78 Debug( LDAP_DEBUG_TRACE, "ldap_modify_ext\n", 0, 0, 0 );
81 /* check client controls */
82 rc = ldap_int_client_controls( ld, cctrls );
83 if( rc != LDAP_SUCCESS ) return rc;
85 /* create a message to send */
86 if ( (ber = ldap_alloc_ber_with_options( ld )) == NULL ) {
87 return( LDAP_NO_MEMORY );
90 LDAP_NEXT_MSGID( ld, id );
91 rc = ber_printf( ber, "{it{s{" /*}}}*/, id, LDAP_REQ_MODIFY, dn );
93 ld->ld_errno = LDAP_ENCODING_ERROR;
95 return( ld->ld_errno );
98 /* for each modification to be performed... */
99 for ( i = 0; mods[i] != NULL; i++ ) {
100 if (( mods[i]->mod_op & LDAP_MOD_BVALUES) != 0 ) {
101 rc = ber_printf( ber, "{e{s[V]N}N}",
102 (ber_int_t) ( mods[i]->mod_op & ~LDAP_MOD_BVALUES ),
103 mods[i]->mod_type, mods[i]->mod_bvalues );
105 rc = ber_printf( ber, "{e{s[v]N}N}",
106 (ber_int_t) mods[i]->mod_op,
107 mods[i]->mod_type, mods[i]->mod_values );
111 ld->ld_errno = LDAP_ENCODING_ERROR;
113 return( ld->ld_errno );
117 if ( ber_printf( ber, /*{{*/ "N}N}" ) == -1 ) {
118 ld->ld_errno = LDAP_ENCODING_ERROR;
120 return( ld->ld_errno );
123 /* Put Server Controls */
124 if( ldap_int_put_controls( ld, sctrls, ber ) != LDAP_SUCCESS ) {
129 if ( ber_printf( ber, /*{*/ "N}" ) == -1 ) {
130 ld->ld_errno = LDAP_ENCODING_ERROR;
132 return( ld->ld_errno );
135 /* send the message */
136 *msgidp = ldap_send_initial_request( ld, LDAP_REQ_MODIFY, dn, ber, id );
137 return( *msgidp < 0 ? ld->ld_errno : LDAP_SUCCESS );
141 * ldap_modify - initiate an ldap modify operation.
146 * dn DN of the object to modify
147 * mods List of modifications to make. This is null-terminated
148 * array of struct ldapmod's, specifying the modifications
152 * LDAPMod *mods[] = {
153 * { LDAP_MOD_ADD, "cn", { "babs jensen", "babs", 0 } },
154 * { LDAP_MOD_REPLACE, "sn", { "jensen", 0 } },
157 * msgid = ldap_modify( ld, dn, mods );
160 ldap_modify( LDAP *ld, LDAP_CONST char *dn, LDAPMod **mods )
165 LDAP_LOG ( OPERATION, ENTRY, "ldap_modify\n", 0, 0, 0 );
167 Debug( LDAP_DEBUG_TRACE, "ldap_modify\n", 0, 0, 0 );
170 rc = ldap_modify_ext( ld, dn, mods, NULL, NULL, &msgid );
172 if ( rc != LDAP_SUCCESS )
179 ldap_modify_ext_s( LDAP *ld, LDAP_CONST char *dn,
180 LDAPMod **mods, LDAPControl **sctrl, LDAPControl **cctrl )
186 rc = ldap_modify_ext( ld, dn, mods, sctrl, cctrl, &msgid );
188 if ( rc != LDAP_SUCCESS )
191 if ( ldap_result( ld, msgid, 1, (struct timeval *) NULL, &res ) == -1 )
192 return( ld->ld_errno );
194 return( ldap_result2error( ld, res, 1 ) );
198 ldap_modify_s( LDAP *ld, LDAP_CONST char *dn, LDAPMod **mods )
200 return ldap_modify_ext_s( ld, dn, mods, NULL, NULL );