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