+ if ( sc->sid != -1 ) {
+ /* command line cookie wins */
+ si->si_syncCookie.sid = sc->sid;
+ }
+ if ( sc->ctxcsn != NULL ) {
+ /* command line cookie wins */
+ if ( si->si_syncCookie.ctxcsn ) {
+ ber_bvarray_free( si->si_syncCookie.ctxcsn );
+ si->si_syncCookie.ctxcsn = NULL;
+ }
+ ber_dupbv( &cookie_bv, &sc->ctxcsn[0] );
+ ber_bvarray_add( &si->si_syncCookie.ctxcsn, &cookie_bv );
+ }
+ if ( sc->rid != -1 ) {
+ /* command line cookie wins */
+ si->si_syncCookie.rid = sc->rid;
+ }
+ slap_sync_cookie_free( sc, 1 );
+ sc = NULL;
+ slap_compose_sync_cookie( NULL, &newcookie,
+ &si->si_syncCookie.ctxcsn[0],
+ si->si_syncCookie.sid, si->si_syncCookie.rid );
+ ber_bvarray_add( &si->si_syncCookie.octet_str, &newcookie );
+ }
+ } else {
+ /* no command line cookie is specified */
+ if ( si->si_syncCookie.octet_str == NULL ) {
+ BerVarray cookie = NULL;
+ struct berval cookie_bv;
+ /* try to read stored cookie */
+ backend_attribute( op, NULL, &op->o_req_ndn,
+ slap_schema.si_ad_syncreplCookie, &cookie );
+ if ( cookie ) {
+ ber_dupbv( &cookie_bv, &cookie[0] );
+ ber_bvarray_add( &si->si_syncCookie.octet_str, &cookie_bv );
+ slap_parse_sync_cookie( &si->si_syncCookie );
+ ber_bvarray_free_x( cookie, op->o_tmpmemctx );
+ }