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