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