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 struct metainfo *li = ( struct metainfo * )op->o_bd->be_private;
40 LDAPMod **modv = NULL;
43 int candidate = -1, i;
45 struct berval mdn = BER_BVNULL;
49 lc = meta_back_getconn( op, rs, META_OP_REQUIRE_SINGLE,
50 &op->o_req_ndn, &candidate );
56 if ( !meta_back_dobind( lc, op ) ) {
57 rs->sr_err = LDAP_UNAVAILABLE;
59 } else if ( !meta_back_is_valid( lc, candidate ) ) {
60 rs->sr_err = LDAP_OTHER;
63 if ( rs->sr_err != LDAP_SUCCESS ) {
69 * Rewrite the modify dn, if needed
71 dc.rwmap = &li->targets[ candidate ]->mt_rwmap;
76 if ( ldap_back_dn_massage( &dc, &op->o_req_dn, &mdn ) ) {
81 for ( i = 0, ml = op->orm_modlist; ml; i++ ,ml = ml->sml_next )
84 mods = ch_malloc( sizeof( LDAPMod )*i );
86 rs->sr_err = LDAP_NO_MEMORY;
90 modv = ( LDAPMod ** )ch_malloc( ( i + 1 )*sizeof( LDAPMod * ) );
92 rs->sr_err = LDAP_NO_MEMORY;
97 dc.ctx = "modifyAttrDN";
98 isupdate = be_shadow_update( op );
99 for ( i = 0, ml = op->orm_modlist; ml; ml = ml->sml_next ) {
102 if ( !isupdate && ml->sml_desc->ad_type->sat_no_user_mod ) {
106 if ( ml->sml_desc == slap_schema.si_ad_objectClass
107 || ml->sml_desc == slap_schema.si_ad_structuralObjectClass )
110 mapped = ml->sml_desc->ad_cname;
113 ldap_back_map( &li->targets[ candidate ]->mt_rwmap.rwm_at,
114 &ml->sml_desc->ad_cname, &mapped,
116 if ( BER_BVISNULL( &mapped ) || BER_BVISEMPTY( &mapped ) ) {
121 modv[ i ] = &mods[ i ];
122 mods[ i ].mod_op = ml->sml_op | LDAP_MOD_BVALUES;
123 mods[ i ].mod_type = mapped.bv_val;
126 * FIXME: dn-valued attrs should be rewritten
127 * to allow their use in ACLs at the back-ldap
130 if ( ml->sml_values != NULL ) {
132 for ( j = 0; !BER_BVISNULL( &ml->sml_values[ j ] ); j++ )
134 mods[ i ].mod_bvalues =
135 (struct berval **)ch_malloc( ( j + 1 ) *
136 sizeof( struct berval * ) );
137 for ( j = 0; !BER_BVISNULL( &ml->sml_values[ j ] ); ) {
138 struct ldapmapping *mapping;
140 ldap_back_mapping( &li->targets[ candidate ]->mt_rwmap.rwm_oc,
141 &ml->sml_values[ j ], &mapping, BACKLDAP_MAP );
143 if ( mapping == NULL ) {
144 if ( li->targets[ candidate ]->mt_rwmap.rwm_oc.drop_missing ) {
147 mods[ i ].mod_bvalues[ j ] = &ml->sml_values[ j ];
150 mods[ i ].mod_bvalues[ j ] = &mapping->dst;
154 mods[ i ].mod_bvalues[ j ] = NULL;
157 if ( ml->sml_desc->ad_type->sat_syntax ==
158 slap_schema.si_syn_distinguishedName )
160 ( void )ldap_dnattr_rewrite( &dc, ml->sml_values );
161 if ( ml->sml_values == NULL ) {
166 for ( j = 0; !BER_BVISNULL( &ml->sml_values[ j ] ); j++ )
168 mods[ i ].mod_bvalues =
169 (struct berval **)ch_malloc( ( j + 1 ) *
170 sizeof( struct berval * ) );
171 for ( j = 0; !BER_BVISNULL( &ml->sml_values[ j ] ); j++ ) {
172 mods[ i ].mod_bvalues[ j ] = &ml->sml_values[ j ];
174 mods[ i ].mod_bvalues[ j ] = NULL;
178 mods[ i ].mod_bvalues = NULL;
185 rs->sr_err = ldap_modify_ext_s( lc->mc_conns[ candidate ].msc_ld, mdn.bv_val,
186 modv, op->o_ctrls, NULL );
189 if ( mdn.bv_val != op->o_req_dn.bv_val ) {
193 if ( modv != NULL ) {
194 for ( i = 0; modv[ i ]; i++ ) {
195 free( modv[ i ]->mod_bvalues );
202 return meta_back_op_result( lc, op, rs );
205 send_ldap_result( op, rs );