3 * Copyright 1998-1999 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,
57 * A modify request looks like this:
58 * ModifyRequet ::= SEQUENCE {
59 * object DistinguishedName,
60 * modifications SEQUENCE OF SEQUENCE {
61 * operation ENUMERATED {
66 * modification SEQUENCE {
68 * values SET OF AttributeValue
74 Debug( LDAP_DEBUG_TRACE, "ldap_modify_ext\n", 0, 0, 0 );
76 /* create a message to send */
77 if ( (ber = ldap_alloc_ber_with_options( ld )) == NULL ) {
78 return( LDAP_NO_MEMORY );
81 if ( ber_printf( ber, "{it{s{" /*}}}*/, ++ld->ld_msgid, LDAP_REQ_MODIFY, dn )
83 ld->ld_errno = LDAP_ENCODING_ERROR;
85 return( ld->ld_errno );
88 /* for each modification to be performed... */
89 for ( i = 0; mods[i] != NULL; i++ ) {
90 if (( mods[i]->mod_op & LDAP_MOD_BVALUES) != 0 ) {
91 rc = ber_printf( ber, "{e{s[V]}}",
92 (ber_int_t) ( mods[i]->mod_op & ~LDAP_MOD_BVALUES ),
93 mods[i]->mod_type, mods[i]->mod_bvalues );
95 rc = ber_printf( ber, "{e{s[v]}}",
96 (ber_int_t) mods[i]->mod_op,
97 mods[i]->mod_type, mods[i]->mod_values );
101 ld->ld_errno = LDAP_ENCODING_ERROR;
103 return( ld->ld_errno );
107 if ( ber_printf( ber, /*{{*/ "}}" ) == -1 ) {
108 ld->ld_errno = LDAP_ENCODING_ERROR;
110 return( ld->ld_errno );
113 /* Put Server Controls */
114 if( ldap_int_put_controls( ld, sctrls, ber ) != LDAP_SUCCESS ) {
119 if ( ber_printf( ber, /*{*/ "}" ) == -1 ) {
120 ld->ld_errno = LDAP_ENCODING_ERROR;
122 return( ld->ld_errno );
125 /* send the message */
126 *msgidp = ldap_send_initial_request( ld, LDAP_REQ_MODIFY, dn, ber );
127 return( *msgidp < 0 ? ld->ld_errno : LDAP_SUCCESS );
131 * ldap_modify - initiate an ldap modify operation.
136 * dn DN of the object to modify
137 * mods List of modifications to make. This is null-terminated
138 * array of struct ldapmod's, specifying the modifications
142 * LDAPMod *mods[] = {
143 * { LDAP_MOD_ADD, "cn", { "babs jensen", "babs", 0 } },
144 * { LDAP_MOD_REPLACE, "sn", { "jensen", 0 } },
147 * msgid = ldap_modify( ld, dn, mods );
150 ldap_modify( LDAP *ld, LDAP_CONST char *dn, LDAPMod **mods )
154 Debug( LDAP_DEBUG_TRACE, "ldap_modify\n", 0, 0, 0 );
156 rc = ldap_modify_ext( ld, dn, mods, NULL, NULL, &msgid );
158 if ( rc != LDAP_SUCCESS )
165 ldap_modify_ext_s( LDAP *ld, LDAP_CONST char *dn,
166 LDAPMod **mods, LDAPControl **sctrl, LDAPControl **cctrl )
172 rc = ldap_modify_ext( ld, dn, mods, sctrl, cctrl, &msgid );
174 if ( rc != LDAP_SUCCESS )
177 if ( ldap_result( ld, msgid, 1, (struct timeval *) NULL, &res ) == -1 )
178 return( ld->ld_errno );
180 return( ldap_result2error( ld, res, 1 ) );
184 ldap_modify_s( LDAP *ld, LDAP_CONST char *dn, LDAPMod **mods )
186 return ldap_modify_ext_s( ld, dn, mods, NULL, NULL );