1 /* modify.c - ldap backend modify function */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1999-2005 The OpenLDAP Foundation.
6 * Portions Copyright 1999-2003 Howard Chu.
7 * Portions Copyright 2000-2003 Pierangelo Masarati.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted only as authorized by the OpenLDAP
14 * A copy of this license is available in the file LICENSE in the
15 * top-level directory of the distribution or, alternatively, at
16 * <http://www.OpenLDAP.org/license.html>.
19 * This work was initially developed by the Howard Chu for inclusion
20 * in OpenLDAP Software and subsequently enhanced by Pierangelo
28 #include <ac/string.h>
29 #include <ac/socket.h>
32 #include "back-ldap.h"
40 LDAPMod **modv = NULL,
47 LDAPControl **ctrls = NULL;
49 lc = ldap_back_getconn( op, rs, LDAP_BACK_SENDERR );
50 if ( !lc || !ldap_back_dobind( lc, op, rs, LDAP_BACK_SENDERR ) ) {
54 for ( i = 0, ml = op->oq_modify.rs_modlist; ml; i++, ml = ml->sml_next )
55 /* just count mods */ ;
57 modv = (LDAPMod **)ch_malloc( ( i + 1 )*sizeof( LDAPMod * )
58 + i*sizeof( LDAPMod ) );
63 mods = (LDAPMod *)&modv[ i + 1 ];
65 isupdate = be_shadow_update( op );
66 for ( i = 0, ml = op->oq_modify.rs_modlist; ml; ml = ml->sml_next ) {
67 if ( !isupdate && !get_manageDIT( op ) && ml->sml_desc->ad_type->sat_no_user_mod )
72 modv[ i ] = &mods[ i ];
73 mods[ i ].mod_op = ( ml->sml_op | LDAP_MOD_BVALUES );
74 mods[ i ].mod_type = ml->sml_desc->ad_cname.bv_val;
76 if ( ml->sml_values != NULL ) {
77 if ( ml->sml_values == NULL ) {
81 for ( j = 0; !BER_BVISNULL( &ml->sml_values[ j ] ); j++ )
82 /* just count mods */ ;
83 mods[ i ].mod_bvalues =
84 (struct berval **)ch_malloc( ( j + 1 )*sizeof( struct berval * ) );
85 for ( j = 0; !BER_BVISNULL( &ml->sml_values[ j ] ); j++ )
87 mods[ i ].mod_bvalues[ j ] = &ml->sml_values[ j ];
89 mods[ i ].mod_bvalues[ j ] = NULL;
92 mods[ i ].mod_bvalues = NULL;
100 rc = ldap_back_proxy_authz_ctrl( lc, op, rs, &ctrls );
101 if ( rc != LDAP_SUCCESS ) {
102 send_ldap_result( op, rs );
108 rs->sr_err = ldap_modify_ext( lc->lc_ld, op->o_req_ndn.bv_val, modv,
109 ctrls, NULL, &msgid );
110 rc = ldap_back_op_result( lc, op, rs, msgid, LDAP_BACK_SENDRESULT );
111 if ( rs->sr_err == LDAP_UNAVAILABLE && do_retry ) {
113 if ( ldap_back_retry( lc, op, rs, LDAP_BACK_SENDERR ) ) {
119 (void)ldap_back_proxy_authz_ctrl_free( op, &ctrls );
121 for ( i = 0; modv[ i ]; i++ ) {
122 ch_free( modv[ i ]->mod_bvalues );
127 ldap_back_release_conn( op, rs, lc );