]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/slapadd.c
fix typo
[openldap] / servers / slapd / slapadd.c
index 7f66cad740a64d1a26177d7515dba8a4b8669706..468dcea6716c6f1d14b8660bc6c4e2cbebc88abf 100644 (file)
@@ -1,7 +1,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1998-2007 The OpenLDAP Foundation.
+ * Copyright 1998-2008 The OpenLDAP Foundation.
  * Portions Copyright 1998-2003 Kurt D. Zeilenga.
  * Portions Copyright 2003 IBM Corporation.
  * All rights reserved.
@@ -67,6 +67,9 @@ slapadd( int argc, char **argv )
        int rc = EXIT_SUCCESS;
        int manage = 0; 
 
+       /* default "000" */
+       csnsid = 0;
+
        slap_tool_init( progname, SLAPADD, argc, argv );
 
        memset( &opbuf, 0, sizeof(opbuf) );
@@ -96,6 +99,11 @@ slapadd( int argc, char **argv )
        lmax = 0;
        nextline = 0;
 
+       /* enforce schema checking unless not disabled */
+       if ( (slapMode & SLAP_TOOL_NO_SCHEMA_CHECK) == 0) {
+               SLAP_DBFLAGS(be) &= ~(SLAP_DBFLAG_NO_SCHEMA_CHECK);
+       }
+
        if( !dryrun && be->be_entry_open( be, 1 ) != 0 ) {
                fprintf( stderr, "%s: could not open database.\n",
                        progname );
@@ -195,6 +203,7 @@ slapadd( int argc, char **argv )
                                        if( continuemode ) continue;
                                        break;
                                }
+                               textbuf[ 0 ] = '\0';
                        }
                }
 
@@ -215,7 +224,7 @@ slapadd( int argc, char **argv )
                        nvals[1].bv_len = 0;
                        nvals[1].bv_val = NULL;
 
-                       csn.bv_len = lutil_csnstr( csnbuf, sizeof( csnbuf ), 0, 0 );
+                       csn.bv_len = lutil_csnstr( csnbuf, sizeof( csnbuf ), csnsid, 0 );
                        csn.bv_val = csnbuf;
 
                        timestamp.bv_val = timebuf;
@@ -247,33 +256,33 @@ slapadd( int argc, char **argv )
                                attr_merge( e, slap_schema.si_ad_creatorsName, vals, nvals );
                        }
 
-                       if( attr_find( e->e_attrs, slap_schema.si_ad_modifiersName )
+                       if( attr_find( e->e_attrs, slap_schema.si_ad_createTimestamp )
                                == NULL )
                        {
-                               vals[0] = name;
-                               nvals[0] = nname;
-                               attr_merge( e, slap_schema.si_ad_modifiersName, vals, nvals );
+                               vals[0] = timestamp;
+                               attr_merge( e, slap_schema.si_ad_createTimestamp, vals, NULL );
                        }
 
-                       if( attr_find( e->e_attrs, slap_schema.si_ad_createTimestamp )
+                       if( attr_find( e->e_attrs, slap_schema.si_ad_entryCSN )
                                == NULL )
                        {
-                               vals[0] = timestamp;
-                               attr_merge( e, slap_schema.si_ad_createTimestamp, vals, NULL );
+                               vals[0] = csn;
+                               attr_merge( e, slap_schema.si_ad_entryCSN, vals, NULL );
                        }
 
-                       if( attr_find( e->e_attrs, slap_schema.si_ad_modifyTimestamp )
+                       if( attr_find( e->e_attrs, slap_schema.si_ad_modifiersName )
                                == NULL )
                        {
-                               vals[0] = timestamp;
-                               attr_merge( e, slap_schema.si_ad_modifyTimestamp, vals, NULL );
+                               vals[0] = name;
+                               nvals[0] = nname;
+                               attr_merge( e, slap_schema.si_ad_modifiersName, vals, nvals );
                        }
 
-                       if( attr_find( e->e_attrs, slap_schema.si_ad_entryCSN )
+                       if( attr_find( e->e_attrs, slap_schema.si_ad_modifyTimestamp )
                                == NULL )
                        {
-                               vals[0] = csn;
-                               attr_merge( e, slap_schema.si_ad_entryCSN, vals, NULL );
+                               vals[0] = timestamp;
+                               attr_merge( e, slap_schema.si_ad_modifyTimestamp, vals, NULL );
                        }
 
                        if ( update_ctxcsn ) {
@@ -344,11 +353,15 @@ slapadd( int argc, char **argv )
                } else {
                        ctxcsn_e = be->be_entry_get( be, ctxcsn_id );
                        if ( ctxcsn_e != NULL ) {
-                               attr = attr_find( ctxcsn_e->e_attrs, slap_schema.si_ad_contextCSN );
+                               Entry *e = entry_dup( ctxcsn_e );
+                               int change;
+                               attr = attr_find( e->e_attrs, slap_schema.si_ad_contextCSN );
                                if ( attr ) {
                                        int             i;
 
-                                       for ( i = 0; !BER_BVISNULL( &attr->a_vals[ i ] ); i++ ) {
+                                       change = 0;
+
+                                       for ( i = 0; !BER_BVISNULL( &attr->a_nvals[ i ] ); i++ ) {
                                                int rc_sid;
 
                                                rc_sid = slap_parse_csn_sid( &attr->a_nvals[ i ] );
@@ -375,7 +388,9 @@ slapadd( int argc, char **argv )
                                                                &maxcsn[ sid ], &attr->a_nvals[i], &text );
                                                }
 
-                                               if ( match < 0 ) {
+                                               if ( match > 0 ) {
+                                                       change = 1;
+                                               } else {
                                                        AC_MEMCPY( maxcsn[ sid ].bv_val,
                                                                attr->a_nvals[ i ].bv_val,
                                                                attr->a_nvals[ i ].bv_len );
@@ -384,33 +399,38 @@ slapadd( int argc, char **argv )
                                                }
                                        }
 
-#if 0
-                                       if ( attr->a_nvals && attr->a_nvals != attr->a_vals ) {
-                                               ber_bvarray_free( attr->a_nvals );
+                                       if ( change ) {
+                                               if ( attr->a_nvals != attr->a_vals ) {
+                                                       ber_bvarray_free( attr->a_nvals );
+                                               }
+                                               attr->a_nvals = NULL;
+                                               ber_bvarray_free( attr->a_vals );
+                                               attr->a_vals = NULL;
+                                               attr->a_numvals = 0;
                                        }
-                                       ber_bvarray_free( attr->a_vals );
-#endif
-
-                                       attr->a_vals = NULL;
-                                       attr->a_nvals = NULL;
+                               } else {
+                                       change = 1;
                                }
 
-                               for ( sid = 0; sid <= SLAP_SYNC_SID_MAX; sid++ ) {
-                                       if ( maxcsn[ sid ].bv_len ) {
-                                               attr_merge_one( ctxcsn_e, slap_schema.si_ad_contextCSN,
-                                                       &maxcsn[ sid], NULL );
+                               if ( change ) {
+                                       for ( sid = 0; sid <= SLAP_SYNC_SID_MAX; sid++ ) {
+                                               if ( maxcsn[ sid ].bv_len ) {
+                                                       attr_merge_one( e, slap_schema.si_ad_contextCSN,
+                                                               &maxcsn[ sid], NULL );
+                                               }
+                                       }
+
+                                       ctxcsn_id = be->be_entry_modify( be, e, &bvtext );
+                                       if( ctxcsn_id == NOID ) {
+                                               fprintf( stderr, "%s: could not modify ctxcsn\n",
+                                                       progname);
+                                               rc = EXIT_FAILURE;
+                                       } else if ( verbose ) {
+                                               fprintf( stderr, "modified: \"%s\" (%08lx)\n",
+                                                       e->e_dn, (long) ctxcsn_id );
                                        }
                                }
-                       
-                               ctxcsn_id = be->be_entry_modify( be, ctxcsn_e, &bvtext );
-                               if( ctxcsn_id == NOID ) {
-                                       fprintf( stderr, "%s: could not modify ctxcsn\n",
-                                               progname);
-                                       rc = EXIT_FAILURE;
-                               } else if ( verbose ) {
-                                       fprintf( stderr, "modified: \"%s\" (%08lx)\n",
-                                               ctxcsn_e->e_dn, (long) ctxcsn_id );
-                               }
+                               entry_free( e );
                        }
                } 
        }