struct berval csn;
struct berval maxcsn[ SLAP_SYNC_SID_MAX + 1 ];
- MatchingRule *mr_csnsid;
unsigned long sid;
struct berval bvtext;
Attribute *attr;
int rc = EXIT_SUCCESS;
int manage = 0;
+ /* default "000" */
+ csnsid = 0;
+
slap_tool_init( progname, SLAPADD, argc, argv );
memset( &opbuf, 0, sizeof(opbuf) );
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 );
}
if ( update_ctxcsn ) {
- mr_csnsid = mr_find( "CSNSIDMatch" );
- assert( mr_csnsid != NULL );
maxcsn[ 0 ].bv_val = maxcsnbuf;
for ( sid = 1; sid <= SLAP_SYNC_SID_MAX; sid++ ) {
maxcsn[ sid ].bv_val = maxcsn[ sid - 1 ].bv_val + LDAP_LUTIL_CSNSTR_BUFSIZE;
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;
}
if ( update_ctxcsn ) {
- struct berval nsid;
+ int rc_sid;
attr = attr_find( e->e_attrs, slap_schema.si_ad_entryCSN );
assert( attr != NULL );
-
- rc = mr_csnsid->smr_normalize( SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
- NULL, NULL, &attr->a_nvals[ 0 ], &nsid, NULL );
- assert( rc == LDAP_SUCCESS );
- rc = lutil_atoulx( &sid, nsid.bv_val, 16 );
- ber_memfree( nsid.bv_val );
- if ( rc ) {
+
+ rc_sid = slap_parse_csn_sid( &attr->a_nvals[ 0 ] );
+ if ( rc_sid < 0 ) {
Debug( LDAP_DEBUG_ANY, "%s: could not "
"extract SID from entryCSN=%s\n",
progname, attr->a_nvals[ 0 ].bv_val, 0 );
} else {
- assert( sid <= SLAP_SYNC_SID_MAX );
+ assert( rc_sid <= SLAP_SYNC_SID_MAX );
+ sid = (unsigned)rc_sid;
if ( maxcsn[ sid ].bv_len != 0 ) {
match = 0;
value_match( &match, slap_schema.si_ad_entryCSN,
} 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 );
+ 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++ ) {
- struct berval nsid;
-
- rc = mr_csnsid->smr_normalize( SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
- NULL, NULL, &attr->a_nvals[ i ], &nsid, NULL );
-
- /* must succeed, since it passed
- * validation/normalization */
- assert( rc == LDAP_SUCCESS );
-
- rc = lutil_atoulx( &sid, nsid.bv_val, 16 );
- ber_memfree( nsid.bv_val );
+ for ( i = 0; !BER_BVISNULL( &attr->a_nvals[ i ] ); i++ ) {
+ int rc_sid;
- if ( rc ) {
+ rc_sid = slap_parse_csn_sid( &attr->a_nvals[ i ] );
+ if ( rc_sid < 0 ) {
Debug( LDAP_DEBUG_ANY,
"%s: unable to extract SID "
"from #%d contextCSN=%s\n",
continue;
}
+ assert( rc_sid <= SLAP_SYNC_SID_MAX );
+
+ sid = (unsigned)rc_sid;
+
if ( maxcsn[ sid ].bv_len == 0 ) {
match = -1;
}
}
-#if 0
- if ( attr->a_nvals && attr->a_nvals != attr->a_vals ) {
+ if ( attr->a_nvals != attr->a_nvals ) {
ber_bvarray_free( attr->a_nvals );
}
+ attr->a_nvals = NULL;
ber_bvarray_free( attr->a_vals );
-#endif
-
attr->a_vals = NULL;
- attr->a_nvals = NULL;
}
for ( sid = 0; sid <= SLAP_SYNC_SID_MAX; sid++ ) {
if ( maxcsn[ sid ].bv_len ) {
- attr_merge_one( ctxcsn_e, slap_schema.si_ad_contextCSN,
+ attr_merge_one( e, slap_schema.si_ad_contextCSN,
&maxcsn[ sid], NULL );
}
}
- ctxcsn_id = be->be_entry_modify( be, ctxcsn_e, &bvtext );
+ 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",
- ctxcsn_e->e_dn, (long) ctxcsn_id );
+ e->e_dn, (long) ctxcsn_id );
}
+ entry_free( e );
}
}
}