]> git.sur5r.net Git - openldap/blob - servers/slapd/modrdn.c
Updated notices
[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_x_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                         if ( (op->o_bd->be_modrdn)( op, rs ) == 0
367 #ifdef SLAPD_MULTIMASTER
368                                 && ( !op->o_bd->be_update_ndn.bv_len || !repl_user )
369 #endif
370                         ) {
371                                 replog( op );
372                         }
373 #ifndef SLAPD_MULTIMASTER
374                 } else {
375                         BerVarray defref = NULL;
376                         if ( !LDAP_STAILQ_EMPTY( &op->o_bd->be_syncinfo )) {
377                                 syncinfo_t *si;
378                                 LDAP_STAILQ_FOREACH( si, &op->o_bd->be_syncinfo, si_next ) {
379                                         struct berval tmpbv;
380                                         ber_dupbv( &tmpbv, &si->si_provideruri_bv[0] );
381                                         ber_bvarray_add( &defref, &tmpbv );
382                                 }
383                         } else {
384                                 defref = op->o_bd->be_update_refs
385                                         ? op->o_bd->be_update_refs : default_referral;
386                         }
387                         if ( defref != NULL ) {
388                                 rs->sr_ref = referral_rewrite( defref,
389                                         NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
390                                 if (!rs->sr_ref) rs->sr_ref = defref;
391
392                                 rs->sr_err = LDAP_REFERRAL;
393                                 send_ldap_result( op, rs );
394
395                                 if (rs->sr_ref != defref) ber_bvarray_free( rs->sr_ref );
396                         } else {
397                                 send_ldap_error( op, rs,
398                                         LDAP_UNWILLING_TO_PERFORM,
399                                         "referral missing" );
400                         }
401 #endif
402                 }
403         } else {
404                 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
405                         "operation not supported within namingContext" );
406         }
407
408 #if defined( LDAP_SLAPI )
409         if ( pb && doPluginFNs( op->o_bd, SLAPI_PLUGIN_POST_MODRDN_FN, pb ) < 0 ) {
410 #ifdef NEW_LOGGING
411                 LDAP_LOG( OPERATION, INFO, "do_modrdn: modrdn postoperation plugins "
412                                 "failed\n", 0, 0, 0 );
413 #else
414                 Debug(LDAP_DEBUG_TRACE, "do_modrdn: modrdn postoperation plugins "
415                                 "failed.\n", 0, 0, 0);
416 #endif
417         }
418 #endif /* defined( LDAP_SLAPI ) */
419
420 cleanup:
421
422         slap_graduate_commit_csn( op );
423
424         op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
425         op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
426
427         op->o_tmpfree( op->orr_newrdn.bv_val, op->o_tmpmemctx );        
428         op->o_tmpfree( op->orr_nnewrdn.bv_val, op->o_tmpmemctx );       
429
430         if ( pnewSuperior.bv_val ) op->o_tmpfree( pnewSuperior.bv_val, op->o_tmpmemctx );
431         if ( nnewSuperior.bv_val ) op->o_tmpfree( nnewSuperior.bv_val, op->o_tmpmemctx );
432
433         return rs->sr_err;
434 }
435
436 int
437 slap_modrdn2mods(
438         Operation       *op,
439         SlapReply       *rs,
440         Entry           *e,
441         LDAPRDN         old_rdn,
442         LDAPRDN         new_rdn,
443         Modifications   **pmod )
444 {
445         Modifications   *mod = NULL;
446         Modifications   **modtail = &mod;
447         int             a_cnt, d_cnt;
448         int repl_user;
449
450         assert( new_rdn != NULL );
451         assert( !op->orr_deleteoldrdn || old_rdn != NULL );
452
453         repl_user = be_isupdate( op->o_bd, &op->o_ndn );
454
455         /* Add new attribute values to the entry */
456         for ( a_cnt = 0; new_rdn[a_cnt]; a_cnt++ ) {
457                 AttributeDescription    *desc = NULL;
458                 Modifications           *mod_tmp;
459
460                 rs->sr_err = slap_bv2ad( &new_rdn[a_cnt]->la_attr, &desc, &rs->sr_text );
461
462                 if ( rs->sr_err != LDAP_SUCCESS ) {
463 #ifdef NEW_LOGGING
464                         LDAP_LOG ( OPERATION, ERR, 
465                                 "slap_modrdn2modlist: %s: %s (new)\n", 
466                                 rs->sr_text, 
467                                 new_rdn[ a_cnt ]->la_attr.bv_val, 0 );
468 #else
469                         Debug( LDAP_DEBUG_TRACE,
470                                 "slap_modrdn2modlist: %s: %s (new)\n",
471                                 rs->sr_text, 
472                                 new_rdn[ a_cnt ]->la_attr.bv_val, 0 );
473 #endif
474                         goto done;              
475                 }
476
477                 /* ACL check of newly added attrs */
478                 if ( op->o_bd && !access_allowed( op, e, desc,
479                         &new_rdn[a_cnt]->la_value, ACL_WRITE, NULL ) ) {
480 #ifdef NEW_LOGGING
481                         LDAP_LOG ( OPERATION, ERR, 
482                                 "slap_modrdn2modlist: access to attr \"%s\" "
483                                 "(new) not allowed\n", 
484                                 new_rdn[a_cnt]->la_attr.bv_val, 0, 0 );
485 #else
486                         Debug( LDAP_DEBUG_TRACE,
487                                 "slap_modrdn2modlist: access to attr \"%s\" "
488                                 "(new) not allowed\n", 
489                                 new_rdn[ a_cnt ]->la_attr.bv_val, 0, 0 );
490 #endif
491                         rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
492                         goto done;
493                 }
494
495                 /* Apply modification */
496                 mod_tmp = ( Modifications * )ch_malloc( sizeof( Modifications )
497                         + 4 * sizeof( struct berval ) );
498                 mod_tmp->sml_desc = desc;
499                 mod_tmp->sml_values = ( BerVarray )( mod_tmp + 1 );
500                 mod_tmp->sml_values[0] = new_rdn[a_cnt]->la_value;
501                 mod_tmp->sml_values[1].bv_val = NULL;
502                 if( desc->ad_type->sat_equality->smr_normalize) {
503                         mod_tmp->sml_nvalues = &mod_tmp->sml_values[2];
504                         (void) (*desc->ad_type->sat_equality->smr_normalize)(
505                                 SLAP_MR_EQUALITY|SLAP_MR_VALUE_OF_ASSERTION_SYNTAX,
506                                 desc->ad_type->sat_syntax,
507                                 desc->ad_type->sat_equality,
508                                 &mod_tmp->sml_values[0],
509                                 &mod_tmp->sml_nvalues[0], op->o_tmpmemctx );
510                         mod_tmp->sml_nvalues[1].bv_val = NULL;
511                 } else {
512                         mod_tmp->sml_nvalues = NULL;
513                 }
514                 mod_tmp->sml_op = SLAP_MOD_SOFTADD;
515                 mod_tmp->sml_next = mod;
516                 mod = mod_tmp;
517         }
518
519         /* Remove old rdn value if required */
520         if ( op->orr_deleteoldrdn ) {
521                 for ( d_cnt = 0; old_rdn[d_cnt]; d_cnt++ ) {
522                         AttributeDescription    *desc = NULL;
523                         Modifications           *mod_tmp;
524
525                         rs->sr_err = slap_bv2ad( &old_rdn[d_cnt]->la_attr, &desc, &rs->sr_text );
526                         if ( rs->sr_err != LDAP_SUCCESS ) {
527 #ifdef NEW_LOGGING
528                                 LDAP_LOG ( OPERATION, ERR, 
529                                         "slap_modrdn2modlist: %s: %s (old)\n", 
530                                         rs->sr_text, 
531                                         old_rdn[d_cnt]->la_attr.bv_val, 
532                                         0 );
533 #else
534                                 Debug( LDAP_DEBUG_TRACE,
535                                         "slap_modrdn2modlist: %s: %s (old)\n",
536                                         rs->sr_text, 
537                                         old_rdn[d_cnt]->la_attr.bv_val, 
538                                         0 );
539 #endif
540                                 goto done;              
541                         }
542
543                         /* ACL check of newly added attrs */
544                         if ( op->o_bd && !access_allowed( op, e, desc,
545                                 &old_rdn[d_cnt]->la_value, ACL_WRITE, 
546                                 NULL ) ) {
547 #ifdef NEW_LOGGING
548                                 LDAP_LOG ( OPERATION, ERR, 
549                                         "slap_modrdn2modlist: access "
550                                         "to attr \"%s\" (old) not allowed\n", 
551                                         old_rdn[ d_cnt ]->la_attr.bv_val, 
552                                         0, 0 );
553 #else
554                                 Debug( LDAP_DEBUG_TRACE,
555                                         "slap_modrdn2modlist: access "
556                                         "to attr \"%s\" (old) not allowed\n", 
557                                         old_rdn[ d_cnt ]->la_attr.bv_val,
558                                         0, 0 );
559 #endif
560                                 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
561                                 goto done;
562                         }
563
564                         /* Apply modification */
565                         mod_tmp = ( Modifications * )ch_malloc( sizeof( Modifications )
566                                 + 4 * sizeof ( struct berval ) );
567                         mod_tmp->sml_desc = desc;
568                         mod_tmp->sml_values = ( BerVarray )(mod_tmp+1);
569                         mod_tmp->sml_values[0] = old_rdn[d_cnt]->la_value;
570                         mod_tmp->sml_values[1].bv_val = NULL;
571                         if( desc->ad_type->sat_equality->smr_normalize) {
572                                 mod_tmp->sml_nvalues = &mod_tmp->sml_values[2];
573                                 (void) (*desc->ad_type->sat_equality->smr_normalize)(
574                                         SLAP_MR_EQUALITY|SLAP_MR_VALUE_OF_ASSERTION_SYNTAX,
575                                         desc->ad_type->sat_syntax,
576                                         desc->ad_type->sat_equality,
577                                         &mod_tmp->sml_values[0],
578                                         &mod_tmp->sml_nvalues[0], op->o_tmpmemctx );
579                                 mod_tmp->sml_nvalues[1].bv_val = NULL;
580                         } else {
581                                 mod_tmp->sml_nvalues = NULL;
582                         }
583                         mod_tmp->sml_op = LDAP_MOD_DELETE;
584                         mod_tmp->sml_next = mod;
585                         mod = mod_tmp;
586                 }
587         }
588         
589 done:
590
591         if ( !repl_user ) {
592                 char textbuf[ SLAP_TEXT_BUFLEN ];
593                 size_t textlen = sizeof textbuf;
594
595                 for( modtail = &mod;
596                         *modtail != NULL;
597                         modtail = &(*modtail)->sml_next )
598                 {
599                         /* empty */
600                 }
601
602                 rs->sr_err = slap_mods_opattrs( op, mod, modtail, &rs->sr_text, textbuf, textlen );
603         }
604
605         /* LDAP v2 supporting correct attribute handling. */
606         if ( rs->sr_err != LDAP_SUCCESS && mod != NULL ) {
607                 Modifications *tmp;
608                 for ( ; mod; mod = tmp ) {
609                         tmp = mod->sml_next;
610                         ch_free( mod );
611                 }
612         }
613
614         *pmod = mod;
615
616         return rs->sr_err;
617 }