- op.o_si = si;
- op.o_tag = LDAP_REQ_SEARCH;
- op.o_dn = si->updatedn;
- op.o_ndn = si->updatedn;
- op.o_callback = &cb;
- op.o_time = slap_get_time();
- op.o_managedsait = 1;
- op.o_threadctx = si->ctx;
- op.o_bd = be;
- op.o_conn = &conn;
- op.o_connid = op.o_conn->c_connid;
- op.ors_scope = LDAP_SCOPE_BASE;
- op.ors_deref = LDAP_DEREF_NEVER;
- op.ors_slimit = 0;
- op.ors_tlimit = 0;
- op.ors_attrsonly = 0;
- op.ors_attrs = NULL;
- op.ors_filter = str2filter( def_filter_str = "(objectClass=*)" );
- ber_str2bv( def_filter_str, strlen( def_filter_str ), 1,
- &op.ors_filterstr );
-
- si->conn = &conn;
- conn.c_send_ldap_result = slap_send_ldap_result;
- conn.c_send_search_entry = slap_send_search_entry;
- conn.c_send_search_reference = slap_send_search_reference;
+ if ( cmdline_cookie_found ) {
+ /* cookie is supplied in the command line */
+ BerVarray cookie = NULL;
+ struct berval cookie_bv;
+
+ LDAP_STAILQ_REMOVE( &slap_sync_cookie, sc, sync_cookie, sc_next );
+ slap_sync_cookie_free( &si->si_syncCookie, 0 );
+
+ /* read stored cookie if it exists */
+ backend_attribute( op, NULL, &op->o_req_ndn,
+ slap_schema.si_ad_syncreplCookie, &cookie );
+
+ if ( !cookie ) {
+ /* no stored cookie */
+ if ( sc->ctxcsn == NULL ||
+ sc->ctxcsn->bv_val == NULL ) {
+ /* if cmdline cookie does not have ctxcsn */
+ /* component, set it to an initial value */
+ slap_init_sync_cookie_ctxcsn( sc );
+ }
+ slap_dup_sync_cookie( &si->si_syncCookie, sc );
+ slap_sync_cookie_free( sc, 1 );
+ sc = NULL;
+ } else {
+ /* stored cookie */
+ struct berval newcookie = { 0, NULL };
+ 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( si->si_syncCookie.octet_str );
+ si->si_syncCookie.octet_str = NULL;
+ ber_bvarray_free_x( cookie, op->o_tmpmemctx );
+ 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 );
+ }
+ }
+ }