]> git.sur5r.net Git - openldap/blob - servers/slapd/modrdn.c
88b251156ff130697a82a27352f7968e16e80953
[openldap] / servers / slapd / modrdn.c
1 /* $OpenLDAP$ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3  *
4  * Copyright 1998-2003 The OpenLDAP Foundation.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted only as authorized by the OpenLDAP
9  * Public License.
10  *
11  * A copy of this license is available in the file LICENSE in the
12  * top-level directory of the distribution or, alternatively, at
13  * <http://www.OpenLDAP.org/license.html>.
14  */
15 /* Portions Copyright 1999, Juan C. Gomez, All rights reserved.
16  * This software is not subject to any license of Silicon Graphics 
17  * Inc. or Purdue University.
18  *
19  * Redistribution and use in source and binary forms are permitted
20  * without restriction or fee of any kind as long as this notice
21  * is preserved.
22  */
23 /* Portions Copyright (c) 1995 Regents of the University of Michigan.
24  * All rights reserved.
25  *
26  * Redistribution and use in source and binary forms are permitted
27  * provided that this notice is preserved and that due credit is given
28  * to the University of Michigan at Ann Arbor. The name of the University
29  * may not be used to endorse or promote products derived from this
30  * software without specific prior written permission. This software
31  * is provided ``as is'' without express or implied warranty.
32  */
33
34 #include "portable.h"
35
36 #include <stdio.h>
37
38 #include <ac/socket.h>
39 #include <ac/string.h>
40
41 #include "ldap_pvt.h"
42 #include "slap.h"
43 #ifdef LDAP_SLAPI
44 #include "slapi.h"
45 #endif
46
47 int
48 do_modrdn(
49     Operation   *op,
50     SlapReply   *rs
51 )
52 {
53         struct berval dn = { 0, NULL };
54         struct berval newrdn = { 0, NULL };
55         struct berval newSuperior = { 0, NULL };
56         ber_int_t       deloldrdn;
57
58         struct berval pnewSuperior = { 0, NULL };
59
60         struct berval nnewSuperior = { 0, NULL };
61
62         Backend *newSuperior_be = NULL;
63         ber_len_t       length;
64         int manageDSAit;
65
66 #ifdef NEW_LOGGING
67         LDAP_LOG( OPERATION, ENTRY, "do_modrdn: begin\n", 0, 0, 0 );
68 #else
69         Debug( LDAP_DEBUG_TRACE, "do_modrdn\n", 0, 0, 0 );
70 #endif
71
72
73         /*
74          * Parse the modrdn request.  It looks like this:
75          *
76          *      ModifyRDNRequest := SEQUENCE {
77          *              entry   DistinguishedName,
78          *              newrdn  RelativeDistinguishedName
79          *              deleteoldrdn    BOOLEAN,
80          *              newSuperior     [0] LDAPDN OPTIONAL (v3 Only!)
81          *      }
82          */
83
84         if ( ber_scanf( op->o_ber, "{mmb", &dn, &newrdn, &deloldrdn )
85             == LBER_ERROR )
86         {
87 #ifdef NEW_LOGGING
88                 LDAP_LOG( OPERATION, ERR, "do_modrdn: ber_scanf failed\n", 0, 0, 0 );
89 #else
90                 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
91 #endif
92
93                 send_ldap_discon( op, rs, LDAP_PROTOCOL_ERROR, "decoding error" );
94                 return SLAPD_DISCONNECT;
95         }
96
97         /* Check for newSuperior parameter, if present scan it */
98
99         if ( ber_peek_tag( op->o_ber, &length ) == LDAP_TAG_NEWSUPERIOR ) {
100                 if ( op->o_protocol < LDAP_VERSION3 ) {
101                         /* Conection record indicates v2 but field 
102                          * newSuperior is present: report error.
103                          */
104 #ifdef NEW_LOGGING
105                         LDAP_LOG( OPERATION, ERR,
106                                 "do_modrdn: (v2) invalid field newSuperior.\n", 0, 0, 0 );
107 #else
108                         Debug( LDAP_DEBUG_ANY,
109                             "modrdn(v2): invalid field newSuperior!\n",
110                             0, 0, 0 );
111 #endif
112
113                         send_ldap_discon( op, rs,
114                                 LDAP_PROTOCOL_ERROR, "newSuperior requires LDAPv3" );
115                         rs->sr_err = SLAPD_DISCONNECT;
116                         goto cleanup;
117                 }
118
119                 if ( ber_scanf( op->o_ber, "m", &newSuperior ) 
120                      == LBER_ERROR ) {
121
122 #ifdef NEW_LOGGING
123                         LDAP_LOG( OPERATION, ERR,
124                                 "do_modrdn: ber_scanf(\"m\") failed\n", 0, 0, 0 );
125 #else
126                         Debug( LDAP_DEBUG_ANY, "ber_scanf(\"m\") failed\n",
127                                 0, 0, 0 );
128 #endif
129
130                         send_ldap_discon( op, rs,
131                                 LDAP_PROTOCOL_ERROR, "decoding error" );
132                         rs->sr_err = SLAPD_DISCONNECT;
133                         goto cleanup;
134                 }
135                 op->orr_newSup = &pnewSuperior;
136                 op->orr_nnewSup = &nnewSuperior;
137         }
138
139 #ifdef NEW_LOGGING
140         LDAP_LOG( OPERATION, ARGS, 
141                 "do_modrdn: dn (%s) newrdn (%s) newsuperior(%s)\n",
142                 dn.bv_val, newrdn.bv_val,
143                 newSuperior.bv_len ? newSuperior.bv_val : "" );
144 #else
145         Debug( LDAP_DEBUG_ARGS,
146             "do_modrdn: dn (%s) newrdn (%s) newsuperior (%s)\n",
147                 dn.bv_val, newrdn.bv_val,
148                 newSuperior.bv_len ? newSuperior.bv_val : "" );
149 #endif
150
151         if ( ber_scanf( op->o_ber, /*{*/ "}") == LBER_ERROR ) {
152 #ifdef NEW_LOGGING
153                 LDAP_LOG( OPERATION, ERR, "do_modrdn: ber_scanf failed\n", 0, 0, 0 );
154 #else
155                 Debug( LDAP_DEBUG_ANY, "do_modrdn: ber_scanf failed\n", 0, 0, 0 );
156 #endif
157
158                 send_ldap_discon( op, rs,
159                         LDAP_PROTOCOL_ERROR, "decoding error" );
160                 rs->sr_err = SLAPD_DISCONNECT;
161                 goto cleanup;
162         }
163
164         if( get_ctrls( op, rs, 1 ) != LDAP_SUCCESS ) {
165 #ifdef NEW_LOGGING
166                 LDAP_LOG( OPERATION, ERR, "do_modrdn: get_ctrls failed\n", 0, 0, 0 );
167 #else
168                 Debug( LDAP_DEBUG_ANY, "do_modrdn: get_ctrls failed\n", 0, 0, 0 );
169 #endif
170
171                 /* get_ctrls has sent results.  Now clean up. */
172                 goto cleanup;
173         } 
174
175         rs->sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn, op->o_tmpmemctx );
176         if( rs->sr_err != LDAP_SUCCESS ) {
177 #ifdef NEW_LOGGING
178                 LDAP_LOG( OPERATION, INFO, 
179                         "do_modrdn: conn %d  invalid dn (%s)\n",
180                         op->o_connid, dn.bv_val, 0 );
181 #else
182                 Debug( LDAP_DEBUG_ANY,
183                         "do_modrdn: invalid dn (%s)\n", dn.bv_val, 0, 0 );
184 #endif
185                 send_ldap_error( op, rs, LDAP_INVALID_DN_SYNTAX, "invalid DN" );
186                 goto cleanup;
187         }
188
189         if( op->o_req_ndn.bv_len == 0 ) {
190 #ifdef NEW_LOGGING
191                 LDAP_LOG( OPERATION, ERR,
192                         "do_modrdn:  attempt to modify root DSE.\n", 0, 0, 0 );
193 #else
194                 Debug( LDAP_DEBUG_ANY, "do_modrdn: root dse!\n", 0, 0, 0 );
195 #endif
196
197                 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
198                         "cannot rename the root DSE" );
199                 goto cleanup;
200
201         } else if ( bvmatch( &op->o_req_ndn, &global_schemandn ) ) {
202 #ifdef NEW_LOGGING
203                 LDAP_LOG( OPERATION, ERR,
204                         "do_modrdn: attempt to modify subschema subentry: %s (%ld)\n",
205                         global_schemandn.bv_val, (long) global_schemandn.bv_len, 0 );
206 #else
207                 Debug( LDAP_DEBUG_ANY, "do_modrdn: subschema subentry: %s (%ld)\n",
208                         global_schemandn.bv_val, (long) global_schemandn.bv_len, 0 );
209 #endif
210
211                 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
212                         "cannot rename subschema subentry" );
213                 goto cleanup;
214         }
215
216         /* FIXME: should have/use rdnPretty / rdnNormalize routines */
217
218         rs->sr_err = dnPrettyNormal( NULL, &newrdn, &op->orr_newrdn, &op->orr_nnewrdn, op->o_tmpmemctx );
219         if( rs->sr_err != LDAP_SUCCESS ) {
220 #ifdef NEW_LOGGING
221                 LDAP_LOG( OPERATION, INFO, 
222                         "do_modrdn: conn %d  invalid newrdn (%s)\n",
223                         op->o_connid, newrdn.bv_val, 0 );
224 #else
225                 Debug( LDAP_DEBUG_ANY,
226                         "do_modrdn: invalid newrdn (%s)\n", newrdn.bv_val, 0, 0 );
227 #endif
228                 send_ldap_error( op, rs, LDAP_INVALID_DN_SYNTAX, "invalid new RDN" );
229                 goto cleanup;
230         }
231
232         if( rdnValidate( &op->orr_newrdn ) != LDAP_SUCCESS ) {
233 #ifdef NEW_LOGGING
234                 LDAP_LOG( OPERATION, ERR, 
235                         "do_modrdn: invalid rdn (%s).\n", op->orr_newrdn.bv_val, 0, 0 );
236 #else
237                 Debug( LDAP_DEBUG_ANY, "do_modrdn: invalid rdn (%s)\n",
238                         op->orr_newrdn.bv_val, 0, 0 );
239 #endif
240
241                 send_ldap_error( op, rs, LDAP_INVALID_DN_SYNTAX, "invalid new RDN" );
242                 goto cleanup;
243         }
244
245         if( op->orr_newSup ) {
246                 rs->sr_err = dnPrettyNormal( NULL, &newSuperior, &pnewSuperior,
247                         &nnewSuperior, op->o_tmpmemctx );
248                 if( rs->sr_err != LDAP_SUCCESS ) {
249 #ifdef NEW_LOGGING
250                         LDAP_LOG( OPERATION, INFO, 
251                                 "do_modrdn: conn %d  invalid newSuperior (%s)\n",
252                                 op->o_connid, newSuperior.bv_val, 0 );
253 #else
254                         Debug( LDAP_DEBUG_ANY,
255                                 "do_modrdn: invalid newSuperior (%s)\n",
256                                 newSuperior.bv_val, 0, 0 );
257 #endif
258                         send_ldap_error( op, rs, LDAP_INVALID_DN_SYNTAX, "invalid newSuperior" );
259                         goto cleanup;
260                 }
261         }
262
263         Statslog( LDAP_DEBUG_STATS, "conn=%lu op=%lu MODRDN dn=\"%s\"\n",
264             op->o_connid, op->o_opid, op->o_req_dn.bv_val, 0, 0 );
265
266         manageDSAit = get_manageDSAit( op );
267
268         /*
269          * We could be serving multiple database backends.  Select the
270          * appropriate one, or send a referral to our "referral server"
271          * if we don't hold it.
272          */
273         if ( (op->o_bd = select_backend( &op->o_req_ndn, manageDSAit, 0 )) == NULL ) {
274                 rs->sr_ref = referral_rewrite( default_referral,
275                         NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
276                 if (!rs->sr_ref) rs->sr_ref = default_referral;
277
278                 if ( rs->sr_ref != NULL ) {
279                         rs->sr_err = LDAP_REFERRAL;
280                         send_ldap_result( op, rs );
281
282                         if (rs->sr_ref != default_referral) ber_bvarray_free( rs->sr_ref );
283                 } else {
284                         send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
285                                         "referral missing" );
286                 }
287                 goto cleanup;
288         }
289
290         /* check restrictions */
291         if( backend_check_restrictions( op, rs, NULL ) != LDAP_SUCCESS ) {
292                 send_ldap_result( op, rs );
293                 goto cleanup;
294         }
295
296         /* check for referrals */
297         if ( backend_check_referrals( op, rs ) != LDAP_SUCCESS ) {
298                 goto cleanup;
299         }
300
301         /* Make sure that the entry being changed and the newSuperior are in 
302          * the same backend, otherwise we return an error.
303          */
304         if( op->orr_newSup ) {
305                 newSuperior_be = select_backend( &nnewSuperior, 0, 0 );
306
307                 if ( newSuperior_be != op->o_bd ) {
308                         /* newSuperior is in different backend */
309                         send_ldap_error( op, rs, LDAP_AFFECTS_MULTIPLE_DSAS,
310                                 "cannot rename between DSAs" );
311
312                         goto cleanup;
313                 }
314         }
315
316 #if defined( LDAP_SLAPI )
317 #define pb      op->o_pb
318         if ( pb ) {
319                 slapi_int_pblock_set_operation( pb, op );
320                 slapi_pblock_set( pb, SLAPI_MODRDN_TARGET, (void *)dn.bv_val );
321                 slapi_pblock_set( pb, SLAPI_MODRDN_NEWRDN, (void *)newrdn.bv_val );
322                 slapi_pblock_set( pb, SLAPI_MODRDN_NEWSUPERIOR,
323                                 (void *)newSuperior.bv_val );
324                 slapi_pblock_set( pb, SLAPI_MODRDN_DELOLDRDN, (void *)deloldrdn );
325                 slapi_pblock_set( pb, SLAPI_MANAGEDSAIT, (void *)manageDSAit );
326
327                 rs->sr_err = doPluginFNs( op->o_bd, SLAPI_PLUGIN_PRE_MODRDN_FN, pb );
328                 if ( rs->sr_err < 0 ) {
329                         /*
330                          * A preoperation plugin failure will abort the
331                          * entire operation.
332                          */
333 #ifdef NEW_LOGGING
334                         LDAP_LOG( OPERATION, INFO, "do_modrdn: modrdn preoperation plugin "
335                                         "failed\n", 0, 0, 0 );
336 #else
337                         Debug(LDAP_DEBUG_TRACE, "do_modrdn: modrdn preoperation plugin "
338                                         "failed.\n", 0, 0, 0);
339 #endif
340                         if ( ( slapi_pblock_get( pb, SLAPI_RESULT_CODE, (void *)&rs->sr_err ) != 0 ) ||
341                                  rs->sr_err == LDAP_SUCCESS ) {
342                                 rs->sr_err = LDAP_OTHER;
343                         }
344                         goto cleanup;
345                 }
346         }
347 #endif /* defined( LDAP_SLAPI ) */
348
349         /*
350          * do the modrdn if 1 && (2 || 3)
351          * 1) there is a modrdn function implemented in this backend;
352          * 2) this backend is master for what it holds;
353          * 3) it's a replica and the dn supplied is the update_ndn.
354          */
355         if ( op->o_bd->be_modrdn ) {
356                 /* do the update here */
357                 int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
358 #ifndef SLAPD_MULTIMASTER
359                 if ( LDAP_STAILQ_EMPTY( &op->o_bd->be_syncinfo ) &&
360                         ( !op->o_bd->be_update_ndn.bv_len || repl_user ))
361 #else
362                 if ( LDAP_STAILQ_EMPTY( &op->o_bd->be_syncinfo ))
363 #endif
364                 {
365                         op->orr_deleteoldrdn = deloldrdn;
366                         repstamp( op );
367                         if ( (op->o_bd->be_modrdn)( op, rs ) == 0
368 #ifdef SLAPD_MULTIMASTER
369                                 && ( !op->o_bd->be_update_ndn.bv_len || !repl_user )
370 #endif
371                         ) {
372                                 replog( op );
373                         }
374 #ifndef SLAPD_MULTIMASTER
375                 } else {
376                         BerVarray defref = NULL;
377                         if ( !LDAP_STAILQ_EMPTY( &op->o_bd->be_syncinfo )) {
378                                 syncinfo_t *si;
379                                 LDAP_STAILQ_FOREACH( si, &op->o_bd->be_syncinfo, si_next ) {
380                                         struct berval tmpbv;
381                                         ber_dupbv( &tmpbv, &si->si_provideruri_bv[0] );
382                                         ber_bvarray_add( &defref, &tmpbv );
383                                 }
384                         } else {
385                                 defref = op->o_bd->be_update_refs
386                                         ? op->o_bd->be_update_refs : default_referral;
387                         }
388                         if ( defref != NULL ) {
389                                 rs->sr_ref = referral_rewrite( defref,
390                                         NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
391                                 if (!rs->sr_ref) rs->sr_ref = defref;
392
393                                 rs->sr_err = LDAP_REFERRAL;
394                                 send_ldap_result( op, rs );
395
396                                 if (rs->sr_ref != defref) ber_bvarray_free( rs->sr_ref );
397                         } else {
398                                 send_ldap_error( op, rs,
399                                         LDAP_UNWILLING_TO_PERFORM,
400                                         "referral missing" );
401                         }
402 #endif
403                 }
404         } else {
405                 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
406                         "operation not supported within namingContext" );
407         }
408
409 #if defined( LDAP_SLAPI )
410         if ( pb && doPluginFNs( op->o_bd, SLAPI_PLUGIN_POST_MODRDN_FN, pb ) < 0 ) {
411 #ifdef NEW_LOGGING
412                 LDAP_LOG( OPERATION, INFO, "do_modrdn: modrdn postoperation plugins "
413                                 "failed\n", 0, 0, 0 );
414 #else
415                 Debug(LDAP_DEBUG_TRACE, "do_modrdn: modrdn postoperation plugins "
416                                 "failed.\n", 0, 0, 0);
417 #endif
418         }
419 #endif /* defined( LDAP_SLAPI ) */
420
421 cleanup:
422
423         slap_graduate_commit_csn( op );
424
425         op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
426         op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
427
428         op->o_tmpfree( op->orr_newrdn.bv_val, op->o_tmpmemctx );        
429         op->o_tmpfree( op->orr_nnewrdn.bv_val, op->o_tmpmemctx );       
430
431         if ( pnewSuperior.bv_val ) op->o_tmpfree( pnewSuperior.bv_val, op->o_tmpmemctx );
432         if ( nnewSuperior.bv_val ) op->o_tmpfree( nnewSuperior.bv_val, op->o_tmpmemctx );
433
434         return rs->sr_err;
435 }
436
437 int
438 slap_modrdn2mods(
439         Operation       *op,
440         SlapReply       *rs,
441         Entry           *e,
442         LDAPRDN         old_rdn,
443         LDAPRDN         new_rdn,
444         Modifications   **pmod )
445 {
446         Modifications   *mod = NULL;
447         Modifications   **modtail = &mod;
448         int             a_cnt, d_cnt;
449         int repl_user;
450
451         assert( new_rdn != NULL );
452         assert( !op->orr_deleteoldrdn || old_rdn != NULL );
453
454         repl_user = be_isupdate( op->o_bd, &op->o_ndn );
455
456         /* Add new attribute values to the entry */
457         for ( a_cnt = 0; new_rdn[a_cnt]; a_cnt++ ) {
458                 AttributeDescription    *desc = NULL;
459                 Modifications           *mod_tmp;
460
461                 rs->sr_err = slap_bv2ad( &new_rdn[a_cnt]->la_attr, &desc, &rs->sr_text );
462
463                 if ( rs->sr_err != LDAP_SUCCESS ) {
464 #ifdef NEW_LOGGING
465                         LDAP_LOG ( OPERATION, ERR, 
466                                 "slap_modrdn2modlist: %s: %s (new)\n", 
467                                 rs->sr_text, 
468                                 new_rdn[ a_cnt ]->la_attr.bv_val, 0 );
469 #else
470                         Debug( LDAP_DEBUG_TRACE,
471                                 "slap_modrdn2modlist: %s: %s (new)\n",
472                                 rs->sr_text, 
473                                 new_rdn[ a_cnt ]->la_attr.bv_val, 0 );
474 #endif
475                         goto done;              
476                 }
477
478                 /* ACL check of newly added attrs */
479                 if ( op->o_bd && !access_allowed( op, e, desc,
480                         &new_rdn[a_cnt]->la_value, ACL_WRITE, NULL ) ) {
481 #ifdef NEW_LOGGING
482                         LDAP_LOG ( OPERATION, ERR, 
483                                 "slap_modrdn2modlist: access to attr \"%s\" "
484                                 "(new) not allowed\n", 
485                                 new_rdn[a_cnt]->la_attr.bv_val, 0, 0 );
486 #else
487                         Debug( LDAP_DEBUG_TRACE,
488                                 "slap_modrdn2modlist: access to attr \"%s\" "
489                                 "(new) not allowed\n", 
490                                 new_rdn[ a_cnt ]->la_attr.bv_val, 0, 0 );
491 #endif
492                         rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
493                         goto done;
494                 }
495
496                 /* Apply modification */
497                 mod_tmp = ( Modifications * )ch_malloc( sizeof( Modifications )
498                         + 4 * sizeof( struct berval ) );
499                 mod_tmp->sml_desc = desc;
500                 mod_tmp->sml_values = ( BerVarray )( mod_tmp + 1 );
501                 mod_tmp->sml_values[0] = new_rdn[a_cnt]->la_value;
502                 mod_tmp->sml_values[1].bv_val = NULL;
503                 if( desc->ad_type->sat_equality->smr_normalize) {
504                         mod_tmp->sml_nvalues = &mod_tmp->sml_values[2];
505                         (void) (*desc->ad_type->sat_equality->smr_normalize)(
506                                 SLAP_MR_EQUALITY|SLAP_MR_VALUE_OF_ASSERTION_SYNTAX,
507                                 desc->ad_type->sat_syntax,
508                                 desc->ad_type->sat_equality,
509                                 &mod_tmp->sml_values[0],
510                                 &mod_tmp->sml_nvalues[0], op->o_tmpmemctx );
511                         mod_tmp->sml_nvalues[1].bv_val = NULL;
512                 } else {
513                         mod_tmp->sml_nvalues = NULL;
514                 }
515                 mod_tmp->sml_op = SLAP_MOD_SOFTADD;
516                 mod_tmp->sml_next = mod;
517                 mod = mod_tmp;
518         }
519
520         /* Remove old rdn value if required */
521         if ( op->orr_deleteoldrdn ) {
522                 for ( d_cnt = 0; old_rdn[d_cnt]; d_cnt++ ) {
523                         AttributeDescription    *desc = NULL;
524                         Modifications           *mod_tmp;
525
526                         rs->sr_err = slap_bv2ad( &old_rdn[d_cnt]->la_attr, &desc, &rs->sr_text );
527                         if ( rs->sr_err != LDAP_SUCCESS ) {
528 #ifdef NEW_LOGGING
529                                 LDAP_LOG ( OPERATION, ERR, 
530                                         "slap_modrdn2modlist: %s: %s (old)\n", 
531                                         rs->sr_text, 
532                                         old_rdn[d_cnt]->la_attr.bv_val, 
533                                         0 );
534 #else
535                                 Debug( LDAP_DEBUG_TRACE,
536                                         "slap_modrdn2modlist: %s: %s (old)\n",
537                                         rs->sr_text, 
538                                         old_rdn[d_cnt]->la_attr.bv_val, 
539                                         0 );
540 #endif
541                                 goto done;              
542                         }
543
544                         /* ACL check of newly added attrs */
545                         if ( op->o_bd && !access_allowed( op, e, desc,
546                                 &old_rdn[d_cnt]->la_value, ACL_WRITE, 
547                                 NULL ) ) {
548 #ifdef NEW_LOGGING
549                                 LDAP_LOG ( OPERATION, ERR, 
550                                         "slap_modrdn2modlist: access "
551                                         "to attr \"%s\" (old) not allowed\n", 
552                                         old_rdn[ d_cnt ]->la_attr.bv_val, 
553                                         0, 0 );
554 #else
555                                 Debug( LDAP_DEBUG_TRACE,
556                                         "slap_modrdn2modlist: access "
557                                         "to attr \"%s\" (old) not allowed\n", 
558                                         old_rdn[ d_cnt ]->la_attr.bv_val,
559                                         0, 0 );
560 #endif
561                                 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
562                                 goto done;
563                         }
564
565                         /* Apply modification */
566                         mod_tmp = ( Modifications * )ch_malloc( sizeof( Modifications )
567                                 + 4 * sizeof ( struct berval ) );
568                         mod_tmp->sml_desc = desc;
569                         mod_tmp->sml_values = ( BerVarray )(mod_tmp+1);
570                         mod_tmp->sml_values[0] = old_rdn[d_cnt]->la_value;
571                         mod_tmp->sml_values[1].bv_val = NULL;
572                         if( desc->ad_type->sat_equality->smr_normalize) {
573                                 mod_tmp->sml_nvalues = &mod_tmp->sml_values[2];
574                                 (void) (*desc->ad_type->sat_equality->smr_normalize)(
575                                         SLAP_MR_EQUALITY|SLAP_MR_VALUE_OF_ASSERTION_SYNTAX,
576                                         desc->ad_type->sat_syntax,
577                                         desc->ad_type->sat_equality,
578                                         &mod_tmp->sml_values[0],
579                                         &mod_tmp->sml_nvalues[0], op->o_tmpmemctx );
580                                 mod_tmp->sml_nvalues[1].bv_val = NULL;
581                         } else {
582                                 mod_tmp->sml_nvalues = NULL;
583                         }
584                         mod_tmp->sml_op = LDAP_MOD_DELETE;
585                         mod_tmp->sml_next = mod;
586                         mod = mod_tmp;
587                 }
588         }
589         
590 done:
591
592         if ( !repl_user ) {
593                 char textbuf[ SLAP_TEXT_BUFLEN ];
594                 size_t textlen = sizeof textbuf;
595
596                 for( modtail = &mod;
597                         *modtail != NULL;
598                         modtail = &(*modtail)->sml_next )
599                 {
600                         /* empty */
601                 }
602
603                 rs->sr_err = slap_mods_opattrs( op, mod, modtail, &rs->sr_text, textbuf, textlen );
604         }
605
606         /* LDAP v2 supporting correct attribute handling. */
607         if ( rs->sr_err != LDAP_SUCCESS && mod != NULL ) {
608                 Modifications *tmp;
609                 for ( ; mod; mod = tmp ) {
610                         tmp = mod->sml_next;
611                         ch_free( mod );
612                 }
613         }
614
615         *pmod = mod;
616
617         return rs->sr_err;
618 }