2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1999-2005 The OpenLDAP Foundation.
5 * Portions Copyright 2001-2003 Pierangelo Masarati.
6 * Portions Copyright 1999-2003 Howard Chu.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted only as authorized by the OpenLDAP
13 * A copy of this license is available in the file LICENSE in the
14 * top-level directory of the distribution or, alternatively, at
15 * <http://www.OpenLDAP.org/license.html>.
18 * This work was initially developed by the Howard Chu for inclusion
19 * in OpenLDAP Software and subsequently enhanced by Pierangelo
27 #include <ac/string.h>
28 #include <ac/socket.h>
31 #include "../back-ldap/back-ldap.h"
32 #include "back-meta.h"
35 meta_back_modify( Operation *op, SlapReply *rs )
37 metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
40 LDAPMod **modv = NULL;
43 int candidate = -1, i;
45 struct berval mdn = BER_BVNULL;
50 mc = meta_back_getconn( op, rs, &candidate, LDAP_BACK_SENDERR );
51 if ( !mc || !meta_back_dobind( op, rs, mc, LDAP_BACK_SENDERR ) ) {
55 assert( mc->mc_conns[ candidate ].msc_ld != NULL );
58 * Rewrite the modify dn, if needed
60 dc.rwmap = &mi->mi_targets[ candidate ]->mt_rwmap;
65 if ( ldap_back_dn_massage( &dc, &op->o_req_dn, &mdn ) ) {
70 for ( i = 0, ml = op->orm_modlist; ml; i++ ,ml = ml->sml_next )
73 mods = ch_malloc( sizeof( LDAPMod )*i );
75 rs->sr_err = LDAP_NO_MEMORY;
79 modv = ( LDAPMod ** )ch_malloc( ( i + 1 )*sizeof( LDAPMod * ) );
81 rs->sr_err = LDAP_NO_MEMORY;
86 dc.ctx = "modifyAttrDN";
87 isupdate = be_shadow_update( op );
88 for ( i = 0, ml = op->orm_modlist; ml; ml = ml->sml_next ) {
91 if ( !isupdate && ml->sml_desc->ad_type->sat_no_user_mod ) {
95 if ( ml->sml_desc == slap_schema.si_ad_objectClass
96 || ml->sml_desc == slap_schema.si_ad_structuralObjectClass )
99 mapped = ml->sml_desc->ad_cname;
102 ldap_back_map( &mi->mi_targets[ candidate ]->mt_rwmap.rwm_at,
103 &ml->sml_desc->ad_cname, &mapped,
105 if ( BER_BVISNULL( &mapped ) || BER_BVISEMPTY( &mapped ) ) {
110 modv[ i ] = &mods[ i ];
111 mods[ i ].mod_op = ml->sml_op | LDAP_MOD_BVALUES;
112 mods[ i ].mod_type = mapped.bv_val;
115 * FIXME: dn-valued attrs should be rewritten
116 * to allow their use in ACLs at the back-ldap
119 if ( ml->sml_values != NULL ) {
121 for ( j = 0; !BER_BVISNULL( &ml->sml_values[ j ] ); j++ )
123 mods[ i ].mod_bvalues =
124 (struct berval **)ch_malloc( ( j + 1 ) *
125 sizeof( struct berval * ) );
126 for ( j = 0; !BER_BVISNULL( &ml->sml_values[ j ] ); ) {
127 struct ldapmapping *mapping;
129 ldap_back_mapping( &mi->mi_targets[ candidate ]->mt_rwmap.rwm_oc,
130 &ml->sml_values[ j ], &mapping, BACKLDAP_MAP );
132 if ( mapping == NULL ) {
133 if ( mi->mi_targets[ candidate ]->mt_rwmap.rwm_oc.drop_missing ) {
136 mods[ i ].mod_bvalues[ j ] = &ml->sml_values[ j ];
139 mods[ i ].mod_bvalues[ j ] = &mapping->dst;
143 mods[ i ].mod_bvalues[ j ] = NULL;
146 if ( ml->sml_desc->ad_type->sat_syntax ==
147 slap_schema.si_syn_distinguishedName )
149 ( void )ldap_dnattr_rewrite( &dc, ml->sml_values );
150 if ( ml->sml_values == NULL ) {
155 for ( j = 0; !BER_BVISNULL( &ml->sml_values[ j ] ); j++ )
157 mods[ i ].mod_bvalues =
158 (struct berval **)ch_malloc( ( j + 1 ) *
159 sizeof( struct berval * ) );
160 for ( j = 0; !BER_BVISNULL( &ml->sml_values[ j ] ); j++ ) {
161 mods[ i ].mod_bvalues[ j ] = &ml->sml_values[ j ];
163 mods[ i ].mod_bvalues[ j ] = NULL;
167 mods[ i ].mod_bvalues = NULL;
175 rs->sr_err = ldap_modify_ext_s( mc->mc_conns[ candidate ].msc_ld, mdn.bv_val,
176 modv, op->o_ctrls, NULL );
177 if ( rs->sr_err == LDAP_UNAVAILABLE && do_retry ) {
179 if ( meta_back_retry( op, rs, mc, candidate, LDAP_BACK_SENDERR ) ) {
185 if ( mdn.bv_val != op->o_req_dn.bv_val ) {
189 if ( modv != NULL ) {
190 for ( i = 0; modv[ i ]; i++ ) {
191 free( modv[ i ]->mod_bvalues );
198 return meta_back_op_result( mc, op, rs, candidate );
201 send_ldap_result( op, rs );