const char *progname = "slapadd";
struct berval csn;
- struct berval maxcsn = { 0, NULL };
- struct berval ldifcsn = { 0, NULL };
+ struct berval maxcsn = BER_BVNULL;
+ struct berval ldifcsn = BER_BVNULL;
int match;
int provider_subentry = 0;
struct subentryinfo *sei;
Attribute *attr;
Entry *ctxcsn_e;
ID ctxcsn_id;
- struct berval ctxcsn_ndn = { 0, NULL };
+ struct berval ctxcsn_ndn = BER_BVNULL;
int ret;
struct berval bvtext;
int i;
struct berval mc;
struct sync_cookie sc;
-#ifdef NEW_LOGGING
- lutil_log_initialize(argc, argv );
-#endif
slap_tool_init( progname, SLAPADD, argc, argv );
LDAP_SLIST_INIT( &consumer_subentry );
{
fprintf( stderr, "%s: database doesn't support necessary operations.\n",
progname );
- exit( EXIT_FAILURE );
+ if ( dryrun ) {
+ fprintf( stderr, "\t(dry) continuing...\n" );
+
+ } else {
+ exit( EXIT_FAILURE );
+ }
}
lmax = 0;
lineno = 0;
- if( be->be_entry_open( be, 1 ) != 0 ) {
+ if( !dryrun && be->be_entry_open( be, 1 ) != 0 ) {
fprintf( stderr, "%s: could not open database.\n",
progname );
exit( EXIT_FAILURE );
timestamp.bv_val = timebuf;
timestamp.bv_len = strlen(timebuf);
- if ( be->be_rootndn.bv_len == 0 ) {
- name.bv_val = SLAPD_ANONYMOUS;
- name.bv_len = sizeof(SLAPD_ANONYMOUS) - 1;
- nname.bv_val = SLAPD_ANONYMOUS;
- nname.bv_len = sizeof(SLAPD_ANONYMOUS) - 1;
+ if ( BER_BVISEMPTY( &be->be_rootndn ) ) {
+ BER_BVSTR( &name, SLAPD_ANONYMOUS );
+ nname = name;
} else {
name = be->be_rootdn;
nname = be->be_rootndn;
}
}
- if ( update_ctxcsn == SLAP_TOOL_CTXCSN_KEEP ) {
+ if ( dryrun ) {
+ if ( verbose ) {
+ fprintf( stderr, "(dry) added: \"%s\"\n", e->e_dn );
+ }
+ goto done;
+ }
+
+ if ( update_ctxcsn == SLAP_TOOL_CTXCSN_KEEP &&
+ ( replica_promotion || replica_demotion )) {
if ( is_entry_syncProviderSubentry( e )) {
if ( !LDAP_SLIST_EMPTY( &consumer_subentry )) {
fprintf( stderr, "%s: consumer and provider subentries "
}
}
- if ( !is_entry_syncProviderSubentry( e ) &&
- !is_entry_syncConsumerSubentry( e )) {
+ if (( !is_entry_syncProviderSubentry( e ) &&
+ !is_entry_syncConsumerSubentry( e )) ||
+ ( !replica_promotion && !replica_demotion ))
+ {
+ /* dryrun moved earlier */
+ assert( !dryrun );
+
if (!dryrun) {
ID id = be->be_entry_put( be, e, &bvtext );
if( id == NOID ) {
}
}
+done:;
entry_free( e );
}
if ( ctxcsn_id == NOID ) {
ctxcsn_e = slap_create_context_csn_entry( be, &maxcsn );
+
+ /* dryrun moved earlier */
+ assert( !dryrun );
+
if ( !dryrun ) {
ctxcsn_id = be->be_entry_put( be, ctxcsn_e, &bvtext );
if( ctxcsn_id == NOID ) {
AC_MEMCPY( attr->a_vals[0].bv_val, maxcsn.bv_val, maxcsn.bv_len );
attr->a_vals[0].bv_val[maxcsn.bv_len] = '\0';
attr->a_vals[0].bv_len = maxcsn.bv_len;
+
+ /* dryrun moved earlier */
+ assert( !dryrun );
+
if ( !dryrun ) {
ctxcsn_id = be->be_entry_modify( be, ctxcsn_e, &bvtext );
if( ctxcsn_id == NOID ) {
for ( i = 0; replica_id_list[i] > -1 ; i++ ) {
slap_syncrepl_bv.bv_len = snprintf( slap_syncrepl_bv.bv_val,
- slap_syncrepl_bvc.bv_len,
+ slap_syncrepl_bvc.bv_len+1,
"syncrepl%d", replica_id_list[i] );
slap_syncrepl_cn_bv.bv_len = snprintf( slap_syncrepl_cn_bv.bv_val,
- slap_syncrepl_cn_bvc.bv_len,
+ slap_syncrepl_cn_bvc.bv_len+1,
"cn=syncrepl%d", replica_id_list[i] );
build_new_dn( &ctxcsn_ndn, &be->be_nsuffix[0],
(struct berval *)&slap_syncrepl_cn_bv, NULL );
if ( ctxcsn_id == NOID ) {
ctxcsn_e = slap_create_syncrepl_entry( be, &mc,
- &slap_syncrepl_cn_bv,
- &slap_syncrepl_bv );
+ &slap_syncrepl_cn_bv,
+ &slap_syncrepl_bv );
+
+ /* dryrun moved earlier */
+ assert( !dryrun );
+
if ( !dryrun ) {
ctxcsn_id = be->be_entry_put( be, ctxcsn_e, &bvtext );
if( ctxcsn_id == NOID ) {
AC_MEMCPY( attr->a_vals[0].bv_val, mc.bv_val, mc.bv_len );
attr->a_vals[0].bv_val[maxcsn.bv_len] = '\0';
attr->a_vals[0].bv_len = maxcsn.bv_len;
+
+ /* dryrun moved earlier */
+ assert( !dryrun );
+
if ( !dryrun ) {
ctxcsn_id = be->be_entry_modify( be,
ctxcsn_e, &bvtext );
if ( ctxcsn_id == NOID ) {
ctxcsn_e = slap_create_syncrepl_entry( be, &sei->cookie,
- &sei->rdn, &sei->cn );
+ &sei->rdn, &sei->cn );
+
+ /* dryrun moved earlier */
+ assert( !dryrun );
+
if ( !dryrun ) {
ctxcsn_id = be->be_entry_put( be, ctxcsn_e, &bvtext );
if( ctxcsn_id == NOID ) {
AC_MEMCPY( attr->a_vals[0].bv_val, sei->cookie.bv_val, sei->cookie.bv_len );
attr->a_vals[0].bv_val[sei->cookie.bv_len] = '\0';
attr->a_vals[0].bv_len = sei->cookie.bv_len;
+
+ /* dryrun moved earlier */
+ assert( !dryrun );
+
if ( !dryrun ) {
ctxcsn_id = be->be_entry_modify( be,
ctxcsn_e, &bvtext );
ch_free( buf );
- if( be->be_entry_close( be )) rc = EXIT_FAILURE;
+ if ( !dryrun ) {
+ if( be->be_entry_close( be ) ) {
+ rc = EXIT_FAILURE;
+ }
- if( be->be_sync ) {
- be->be_sync( be );
+ if( be->be_sync ) {
+ be->be_sync( be );
+ }
}
slap_tool_destroy();
+
return rc;
}
+