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