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