]> git.sur5r.net Git - openldap/blob - servers/slapd/modify.c
sync with HEAD
[openldap] / servers / slapd / modify.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 #include "portable.h"
19
20 #include <stdio.h>
21
22 #include <ac/socket.h>
23 #include <ac/string.h>
24 #include <ac/time.h>
25
26 #include "lutil.h"
27
28 #include "ldap_pvt.h"
29 #include "slap.h"
30
31 int
32 do_modify(
33     Connection  *conn,
34     Operation   *op )
35 {
36         struct berval dn = { 0, NULL };
37         struct berval pdn = { 0, NULL };
38         struct berval ndn = { 0, NULL };
39         char            *last;
40         ber_tag_t       tag;
41         ber_len_t       len;
42         Modifications   *modlist = NULL;
43         Modifications   **modtail = &modlist;
44 #ifdef LDAP_DEBUG
45         Modifications *tmp;
46 #endif
47         Backend         *be;
48         int rc;
49         const char      *text;
50         int manageDSAit;
51
52 #ifdef NEW_LOGGING
53         LDAP_LOG( OPERATION, ENTRY, "do_modify: enter\n", 0, 0, 0 );
54 #else
55         Debug( LDAP_DEBUG_TRACE, "do_modify\n", 0, 0, 0 );
56 #endif
57
58         /*
59          * Parse the modify request.  It looks like this:
60          *
61          *      ModifyRequest := [APPLICATION 6] SEQUENCE {
62          *              name    DistinguishedName,
63          *              mods    SEQUENCE OF SEQUENCE {
64          *                      operation       ENUMERATED {
65          *                              add     (0),
66          *                              delete  (1),
67          *                              replace (2)
68          *                      },
69          *                      modification    SEQUENCE {
70          *                              type    AttributeType,
71          *                              values  SET OF AttributeValue
72          *                      }
73          *              }
74          *      }
75          */
76
77         if ( ber_scanf( op->o_ber, "{m" /*}*/, &dn ) == LBER_ERROR ) {
78 #ifdef NEW_LOGGING
79                 LDAP_LOG( OPERATION, ERR, "do_modify: ber_scanf failed\n", 0, 0, 0 );
80 #else
81                 Debug( LDAP_DEBUG_ANY, "do_modify: ber_scanf failed\n", 0, 0, 0 );
82 #endif
83
84                 send_ldap_disconnect( conn, op,
85                         LDAP_PROTOCOL_ERROR, "decoding error" );
86                 return SLAPD_DISCONNECT;
87         }
88
89 #ifdef NEW_LOGGING
90         LDAP_LOG( OPERATION, ARGS, "do_modify: dn (%s)\n", dn.bv_val, 0, 0 );
91 #else
92         Debug( LDAP_DEBUG_ARGS, "do_modify: dn (%s)\n", dn.bv_val, 0, 0 );
93 #endif
94
95
96         /* collect modifications & save for later */
97
98         for ( tag = ber_first_element( op->o_ber, &len, &last );
99             tag != LBER_DEFAULT;
100             tag = ber_next_element( op->o_ber, &len, last ) )
101         {
102                 ber_int_t mop;
103                 Modifications tmp, *mod;
104
105
106                 if ( ber_scanf( op->o_ber, "{i{m[W]}}", &mop,
107                     &tmp.sml_type, &tmp.sml_bvalues )
108                     == LBER_ERROR )
109                 {
110                         send_ldap_disconnect( conn, op,
111                                 LDAP_PROTOCOL_ERROR, "decoding modlist error" );
112                         rc = SLAPD_DISCONNECT;
113                         goto cleanup;
114                 }
115
116                 mod = (Modifications *) ch_malloc( sizeof(Modifications) );
117                 mod->sml_op = mop;
118                 mod->sml_type = tmp.sml_type;
119                 mod->sml_bvalues = tmp.sml_bvalues;
120                 mod->sml_desc = NULL;
121                 mod->sml_next =NULL;
122                 *modtail = mod;
123
124                 switch( mop ) {
125                 case LDAP_MOD_ADD:
126                         if ( mod->sml_bvalues == NULL ) {
127 #ifdef NEW_LOGGING
128                                 LDAP_LOG( OPERATION, ERR, 
129                                         "do_modify: modify/add operation (%ld) requires values\n",
130                                         (long)mop, 0, 0 );
131 #else
132                                 Debug( LDAP_DEBUG_ANY,
133                                         "do_modify: modify/add operation (%ld) requires values\n",
134                                         (long) mop, 0, 0 );
135 #endif
136
137                                 send_ldap_result( conn, op, LDAP_PROTOCOL_ERROR,
138                                         NULL, "modify/add operation requires values",
139                                         NULL, NULL );
140                                 rc = LDAP_PROTOCOL_ERROR;
141                                 goto cleanup;
142                         }
143
144                         /* fall through */
145
146                 case LDAP_MOD_DELETE:
147                 case LDAP_MOD_REPLACE:
148                         break;
149
150                 default: {
151 #ifdef NEW_LOGGING
152                                 LDAP_LOG( OPERATION, ERR, 
153                                         "do_modify: invalid modify operation (%ld)\n", (long)mop, 0, 0 );
154 #else
155                                 Debug( LDAP_DEBUG_ANY,
156                                         "do_modify: invalid modify operation (%ld)\n",
157                                         (long) mop, 0, 0 );
158 #endif
159
160                                 send_ldap_result( conn, op, LDAP_PROTOCOL_ERROR,
161                                         NULL, "unrecognized modify operation", NULL, NULL );
162                                 rc = LDAP_PROTOCOL_ERROR;
163                                 goto cleanup;
164                         }
165                 }
166
167                 modtail = &mod->sml_next;
168         }
169         *modtail = NULL;
170
171         if( (rc = get_ctrls( conn, op, 1 )) != LDAP_SUCCESS ) {
172 #ifdef NEW_LOGGING
173                 LDAP_LOG( OPERATION, ERR, "do_modify: get_ctrls failed\n", 0, 0, 0 );
174 #else
175                 Debug( LDAP_DEBUG_ANY, "do_modify: get_ctrls failed\n", 0, 0, 0 );
176 #endif
177
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, "do_modify: conn %d  invalid dn (%s)\n",
185                         conn->c_connid, dn.bv_val, 0 );
186 #else
187                 Debug( LDAP_DEBUG_ANY,
188                         "do_modify: invalid dn (%s)\n", dn.bv_val, 0, 0 );
189 #endif
190                 send_ldap_result( conn, op, rc = LDAP_INVALID_DN_SYNTAX, NULL,
191                     "invalid DN", NULL, NULL );
192                 goto cleanup;
193         }
194
195         if( ndn.bv_len == 0 ) {
196 #ifdef NEW_LOGGING
197                 LDAP_LOG( OPERATION, ERR, 
198                         "do_modify: attempt to modify root DSE.\n",0, 0, 0 );
199 #else
200                 Debug( LDAP_DEBUG_ANY, "do_modify: root dse!\n", 0, 0, 0 );
201 #endif
202
203                 send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM,
204                         NULL, "modify upon the root DSE not supported", NULL, NULL );
205                 goto cleanup;
206
207 #if defined( SLAPD_SCHEMA_DN )
208         } else if ( bvmatch( &ndn, &global_schemandn ) ) {
209 #ifdef NEW_LOGGING
210                 LDAP_LOG( OPERATION, ERR,
211                         "do_modify: attempt to modify subschema subentry.\n" , 0, 0, 0  );
212 #else
213                 Debug( LDAP_DEBUG_ANY, "do_modify: subschema subentry!\n", 0, 0, 0 );
214 #endif
215
216                 send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM,
217                         NULL, "modification of subschema subentry not supported",
218                         NULL, NULL );
219                 goto cleanup;
220 #endif
221         }
222
223 #ifdef LDAP_DEBUG
224 #ifdef NEW_LOGGING
225         LDAP_LOG( OPERATION, DETAIL1, "do_modify: modifications:\n", 0, 0, 0  );
226 #else
227         Debug( LDAP_DEBUG_ARGS, "modifications:\n", 0, 0, 0 );
228 #endif
229
230         for ( tmp = modlist; tmp != NULL; tmp = tmp->sml_next ) {
231 #ifdef NEW_LOGGING
232                 LDAP_LOG( OPERATION, DETAIL1, "\t%s:  %s\n", 
233                         tmp->sml_op == LDAP_MOD_ADD ?
234                         "add" : (tmp->sml_op == LDAP_MOD_DELETE ?
235                         "delete" : "replace"), tmp->sml_type.bv_val, 0 );
236
237                 if ( tmp->sml_bvalues == NULL ) {
238                         LDAP_LOG( OPERATION, DETAIL1, "\t\tno values", 0, 0, 0 );
239                 } else if ( tmp->sml_bvalues[0].bv_val == NULL ) {
240                         LDAP_LOG( OPERATION, DETAIL1, "\t\tzero values", 0, 0, 0 );
241                 } else if ( tmp->sml_bvalues[1].bv_val == NULL ) {
242                         LDAP_LOG( OPERATION, DETAIL1, "\t\tone value", 0, 0, 0 );
243                 } else {
244                         LDAP_LOG( OPERATION, DETAIL1, "\t\tmultiple values", 0, 0, 0 );
245                 }
246
247 #else
248                 Debug( LDAP_DEBUG_ARGS, "\t%s: %s\n",
249                         tmp->sml_op == LDAP_MOD_ADD
250                                 ? "add" : (tmp->sml_op == LDAP_MOD_DELETE
251                                         ? "delete" : "replace"), tmp->sml_type.bv_val, 0 );
252
253                 if ( tmp->sml_bvalues == NULL ) {
254                         Debug( LDAP_DEBUG_ARGS, "%s\n",
255                            "\t\tno values", NULL, NULL );
256                 } else if ( tmp->sml_bvalues[0].bv_val == NULL ) {
257                         Debug( LDAP_DEBUG_ARGS, "%s\n",
258                            "\t\tzero values", NULL, NULL );
259                 } else if ( tmp->sml_bvalues[1].bv_val == NULL ) {
260                         Debug( LDAP_DEBUG_ARGS, "%s, length %ld\n",
261                            "\t\tone value", (long) tmp->sml_bvalues[0].bv_len, NULL );
262                 } else {
263                         Debug( LDAP_DEBUG_ARGS, "%s\n",
264                            "\t\tmultiple values", NULL, NULL );
265                 }
266 #endif
267         }
268 #endif
269
270         Statslog( LDAP_DEBUG_STATS, "conn=%lu op=%lu MOD dn=\"%s\"\n",
271             op->o_connid, op->o_opid, dn.bv_val, 0, 0 );
272
273         manageDSAit = get_manageDSAit( op );
274
275         /*
276          * We could be serving multiple database backends.  Select the
277          * appropriate one, or send a referral to our "referral server"
278          * if we don't hold it.
279          */
280         if ( (be = select_backend( &ndn, manageDSAit, 0 )) == NULL ) {
281                 BerVarray ref = referral_rewrite( default_referral,
282                         NULL, &pdn, LDAP_SCOPE_DEFAULT );
283
284                 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
285                         NULL, NULL, ref ? ref : default_referral, NULL );
286
287                 ber_bvarray_free( ref );
288                 goto cleanup;
289         }
290
291         /* check restrictions */
292         rc = backend_check_restrictions( be, conn, op, NULL, &text ) ;
293         if( rc != LDAP_SUCCESS ) {
294                 send_ldap_result( conn, op, rc,
295                         NULL, text, NULL, NULL );
296                 goto cleanup;
297         }
298
299         /* check for referrals */
300         rc = backend_check_referrals( be, conn, op, &pdn, &ndn );
301         if ( rc != LDAP_SUCCESS ) {
302                 goto cleanup;
303         }
304
305         /* deref suffix alias if appropriate */
306         suffix_alias( be, &ndn );
307
308         /*
309          * do the modify if 1 && (2 || 3)
310          * 1) there is a modify function implemented in this backend;
311          * 2) this backend is master for what it holds;
312          * 3) it's a replica and the dn supplied is the update_ndn.
313          */
314         if ( be->be_modify ) {
315                 /* do the update here */
316                 int repl_user = be_isupdate( be, &op->o_ndn );
317 #ifndef SLAPD_MULTIMASTER
318                 /* Multimaster slapd does not have to check for replicator dn
319                  * because it accepts each modify request
320                  */
321                 if ( !be->be_update_ndn.bv_len || repl_user )
322 #endif
323                 {
324                         int update = be->be_update_ndn.bv_len;
325                         const char *text;
326                         char textbuf[SLAP_TEXT_BUFLEN];
327                         size_t textlen = sizeof textbuf;
328
329                         rc = slap_mods_check( modlist, update, &text,
330                                 textbuf, textlen );
331
332                         if( rc != LDAP_SUCCESS ) {
333                                 send_ldap_result( conn, op, rc,
334                                         NULL, text, NULL, NULL );
335                                 goto cleanup;
336                         }
337
338                         if ( !repl_user ) {
339                                 for( modtail = &modlist;
340                                         *modtail != NULL;
341                                         modtail = &(*modtail)->sml_next )
342                                 {
343                                         /* empty */
344                                 }
345
346                                 rc = slap_mods_opattrs( be, op, modlist, modtail, &text,
347                                         textbuf, textlen );
348                                 if( rc != LDAP_SUCCESS ) {
349                                         send_ldap_result( conn, op, rc,
350                                                 NULL, text,
351                                                 NULL, NULL );
352                                         goto cleanup;
353                                 }
354                         }
355
356                         if ( (*be->be_modify)( be, conn, op, &pdn, &ndn, modlist ) == 0
357 #ifdef SLAPD_MULTIMASTER
358                                 && !repl_user
359 #endif
360                         ) {
361                                 /* but we log only the ones not from a replicator user */
362                                 replog( be, op, &pdn, &ndn, modlist );
363                         }
364
365 #ifndef SLAPD_MULTIMASTER
366                 /* send a referral */
367                 } else {
368                         BerVarray defref = be->be_update_refs
369                                 ? be->be_update_refs : default_referral;
370                         BerVarray ref = referral_rewrite( defref,
371                                 NULL, &pdn, LDAP_SCOPE_DEFAULT );
372
373                         send_ldap_result( conn, op, rc = LDAP_REFERRAL, NULL, NULL,
374                                 ref ? ref : defref, NULL );
375
376                         ber_bvarray_free( ref );
377 #endif
378                 }
379         } else {
380                 send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM,
381                     NULL, "operation not supported within namingContext",
382                         NULL, NULL );
383         }
384
385 cleanup:
386         free( pdn.bv_val );
387         free( ndn.bv_val );
388         if ( modlist != NULL )
389                 slap_mods_free( modlist );
390         return rc;
391 }
392
393 /*
394  * Do basic attribute type checking and syntax validation.
395  */
396 int slap_mods_check(
397         Modifications *ml,
398         int update,
399         const char **text,
400         char *textbuf,
401         size_t textlen )
402 {
403         int rc;
404
405         for( ; ml != NULL; ml = ml->sml_next ) {
406                 AttributeDescription *ad = NULL;
407
408                 /* convert to attribute description */
409                 rc = slap_bv2ad( &ml->sml_type, &ml->sml_desc, text );
410
411                 if( rc != LDAP_SUCCESS ) {
412                         snprintf( textbuf, textlen, "%s: %s",
413                                 ml->sml_type.bv_val, *text );
414                         *text = textbuf;
415                         return rc;
416                 }
417
418                 ad = ml->sml_desc;
419
420                 if( slap_syntax_is_binary( ad->ad_type->sat_syntax )
421                         && !slap_ad_is_binary( ad ))
422                 {
423                         /* attribute requires binary transfer */
424                         snprintf( textbuf, textlen,
425                                 "%s: requires ;binary transfer",
426                                 ml->sml_type.bv_val );
427                         *text = textbuf;
428                         return LDAP_UNDEFINED_TYPE;
429                 }
430
431                 if( !slap_syntax_is_binary( ad->ad_type->sat_syntax )
432                         && slap_ad_is_binary( ad ))
433                 {
434                         /* attribute requires binary transfer */
435                         snprintf( textbuf, textlen,
436                                 "%s: disallows ;binary transfer",
437                                 ml->sml_type.bv_val );
438                         *text = textbuf;
439                         return LDAP_UNDEFINED_TYPE;
440                 }
441
442                 if( slap_ad_is_lang_range( ad )) {
443                         /* attribute requires binary transfer */
444                         snprintf( textbuf, textlen,
445                                 "%s: inappropriate use of language range option",
446                                 ml->sml_type.bv_val );
447                         *text = textbuf;
448                         return LDAP_UNDEFINED_TYPE;
449                 }
450
451                 if (!update && is_at_no_user_mod( ad->ad_type )) {
452                         /* user modification disallowed */
453                         snprintf( textbuf, textlen,
454                                 "%s: no user modification allowed",
455                                 ml->sml_type.bv_val );
456                         *text = textbuf;
457                         return LDAP_CONSTRAINT_VIOLATION;
458                 }
459
460                 if ( is_at_obsolete( ad->ad_type ) &&
461                         ( ml->sml_op == LDAP_MOD_ADD || ml->sml_bvalues != NULL ) )
462                 {
463                         /*
464                          * attribute is obsolete,
465                          * only allow replace/delete with no values
466                          */
467                         snprintf( textbuf, textlen,
468                                 "%s: attribute is obsolete",
469                                 ml->sml_type.bv_val );
470                         *text = textbuf;
471                         return LDAP_CONSTRAINT_VIOLATION;
472                 }
473
474                 /*
475                  * check values
476                  */
477                 if( ml->sml_bvalues != NULL ) {
478                         ber_len_t nvals;
479                         slap_syntax_validate_func *validate =
480                                 ad->ad_type->sat_syntax->ssyn_validate;
481                         slap_syntax_transform_func *pretty =
482                                 ad->ad_type->sat_syntax->ssyn_pretty;
483  
484                         if( !pretty && !validate ) {
485                                 *text = "no validator for syntax";
486                                 snprintf( textbuf, textlen,
487                                         "%s: no validator for syntax %s",
488                                         ml->sml_type.bv_val,
489                                         ad->ad_type->sat_syntax->ssyn_oid );
490                                 *text = textbuf;
491                                 return LDAP_INVALID_SYNTAX;
492                         }
493
494                         /*
495                          * check that each value is valid per syntax
496                          *      and pretty if appropriate
497                          */
498                         for( nvals = 0; ml->sml_bvalues[nvals].bv_val; nvals++ ) {
499                                 struct berval pval;
500                                 if( pretty ) {
501                                         rc = pretty( ad->ad_type->sat_syntax,
502                                                 &ml->sml_bvalues[nvals], &pval );
503                                 } else {
504                                         rc = validate( ad->ad_type->sat_syntax,
505                                                 &ml->sml_bvalues[nvals] );
506                                 }
507
508                                 if( rc != 0 ) {
509                                         snprintf( textbuf, textlen,
510                                                 "%s: value #%ld invalid per syntax",
511                                                 ml->sml_type.bv_val, (long) nvals );
512                                         *text = textbuf;
513                                         return LDAP_INVALID_SYNTAX;
514                                 }
515
516                                 if( pretty ) {
517                                         ber_memfree( ml->sml_bvalues[nvals].bv_val );
518                                         ml->sml_bvalues[nvals] = pval;
519                                 }
520                         }
521
522                         /*
523                          * a rough single value check... an additional check is needed
524                          * to catch add of single value to existing single valued attribute
525                          */
526                         if( ( ml->sml_op == LDAP_MOD_ADD || ml->sml_op == LDAP_MOD_REPLACE )
527                                 && nvals > 1 && is_at_single_value( ad->ad_type ))
528                         {
529                                 snprintf( textbuf, textlen,
530                                         "%s: multiple value provided",
531                                         ml->sml_type.bv_val );
532                                 *text = textbuf;
533                                 return LDAP_CONSTRAINT_VIOLATION;
534                         }
535                 }
536         }
537
538         return LDAP_SUCCESS;
539 }
540
541 int slap_mods_opattrs(
542         Backend *be,
543         Operation *op,
544         Modifications *mods,
545         Modifications **modtail,
546         const char **text,
547         char *textbuf, size_t textlen )
548 {
549         struct berval name, timestamp, csn;
550         char timebuf[22];
551         char csnbuf[64];
552         Modifications *mod;
553
554         int mop = op->o_tag == LDAP_REQ_ADD
555                 ? LDAP_MOD_ADD : LDAP_MOD_REPLACE;
556
557         assert( modtail != NULL );
558         assert( *modtail == NULL );
559
560         if( SLAP_LASTMOD(be) ) {
561                 struct tm *ltm;
562                 time_t now = slap_get_time();
563
564                 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
565                 ltm = gmtime( &now );
566                 lutil_gentime( timebuf, sizeof(timebuf), ltm );
567
568                 csn.bv_len = lutil_csnstr( csnbuf, sizeof( csnbuf ), 0, 0 );
569                 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
570                 csn.bv_val = csnbuf;
571
572                 timestamp.bv_val = timebuf;
573                 timestamp.bv_len = strlen(timebuf);
574
575                 if( op->o_dn.bv_len == 0 ) {
576                         name.bv_val = SLAPD_ANONYMOUS;
577                         name.bv_len = sizeof(SLAPD_ANONYMOUS)-1;
578                 } else {
579                         name = op->o_dn;
580                 }
581         }
582
583         if( op->o_tag == LDAP_REQ_ADD ) {
584                 struct berval tmpval;
585
586                 if( global_schemacheck ) {
587                         int rc = mods_structural_class( mods, &tmpval,
588                                 text, textbuf, textlen );
589                         if( rc != LDAP_SUCCESS ) {
590                                 return rc;
591                         }
592                         if ( tmpval.bv_len ) {
593                                 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
594                                 mod->sml_op = mop;
595                                 mod->sml_type.bv_val = NULL;
596                                 mod->sml_desc = slap_schema.si_ad_structuralObjectClass;
597                                 mod->sml_bvalues = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
598                                 ber_dupbv( &mod->sml_bvalues[0], &tmpval );
599                                 mod->sml_bvalues[1].bv_val = NULL;
600                                 assert( mod->sml_bvalues[0].bv_val );
601                                 *modtail = mod;
602                                 modtail = &mod->sml_next;
603                         }
604                 }
605
606                 if( SLAP_LASTMOD(be) ) {
607                         char uuidbuf[40];
608
609                         tmpval.bv_len = lutil_uuidstr( uuidbuf, sizeof( uuidbuf ) );
610                         tmpval.bv_val = uuidbuf;
611                 
612                         mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
613                         mod->sml_op = mop;
614                         mod->sml_type.bv_val = NULL;
615                         mod->sml_desc = slap_schema.si_ad_entryUUID;
616                         mod->sml_bvalues = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
617                         ber_dupbv( &mod->sml_bvalues[0], &tmpval );
618                         mod->sml_bvalues[1].bv_val = NULL;
619                         assert( mod->sml_bvalues[0].bv_val );
620                         *modtail = mod;
621                         modtail = &mod->sml_next;
622
623                         mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
624                         mod->sml_op = mop;
625                         mod->sml_type.bv_val = NULL;
626                         mod->sml_desc = slap_schema.si_ad_creatorsName;
627                         mod->sml_bvalues = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
628                         ber_dupbv( &mod->sml_bvalues[0], &name );
629                         mod->sml_bvalues[1].bv_val = NULL;
630                         assert( mod->sml_bvalues[0].bv_val );
631                         *modtail = mod;
632                         modtail = &mod->sml_next;
633
634                         mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
635                         mod->sml_op = mop;
636                         mod->sml_type.bv_val = NULL;
637                         mod->sml_desc = slap_schema.si_ad_createTimestamp;
638                         mod->sml_bvalues = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
639                         ber_dupbv( &mod->sml_bvalues[0], &timestamp );
640                         mod->sml_bvalues[1].bv_val = NULL;
641                         assert( mod->sml_bvalues[0].bv_val );
642                         *modtail = mod;
643                         modtail = &mod->sml_next;
644                 }
645         }
646
647         if( SLAP_LASTMOD(be) ) {
648                 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
649                 mod->sml_op = mop;
650                 mod->sml_type.bv_val = NULL;
651                 mod->sml_desc = slap_schema.si_ad_entryCSN;
652                 mod->sml_bvalues = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
653                 ber_dupbv( &mod->sml_bvalues[0], &csn );
654                 mod->sml_bvalues[1].bv_val = NULL;
655                 assert( mod->sml_bvalues[0].bv_val );
656                 *modtail = mod;
657                 modtail = &mod->sml_next;
658
659                 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
660                 mod->sml_op = mop;
661                 mod->sml_type.bv_val = NULL;
662                 mod->sml_desc = slap_schema.si_ad_modifiersName;
663                 mod->sml_bvalues = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
664                 ber_dupbv( &mod->sml_bvalues[0], &name );
665                 mod->sml_bvalues[1].bv_val = NULL;
666                 assert( mod->sml_bvalues[0].bv_val );
667                 *modtail = mod;
668                 modtail = &mod->sml_next;
669
670                 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
671                 mod->sml_op = mop;
672                 mod->sml_type.bv_val = NULL;
673                 mod->sml_desc = slap_schema.si_ad_modifyTimestamp;
674                 mod->sml_bvalues = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
675                 ber_dupbv( &mod->sml_bvalues[0], &timestamp );
676                 mod->sml_bvalues[1].bv_val = NULL;
677                 assert( mod->sml_bvalues[0].bv_val );
678                 *modtail = mod;
679                 modtail = &mod->sml_next;
680         }
681
682         *modtail = NULL;
683         return LDAP_SUCCESS;
684 }