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