]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/syncrepl.c
also log cookie parsing
[openldap] / servers / slapd / syncrepl.c
index d0893a31446f6348e8ec647e372e6467d4e5076a..3e6a62753e4fffbd0fdbc4874e57729e26860391 100644 (file)
@@ -63,7 +63,7 @@ typedef struct syncinfo_s {
        BackendDB               *si_wbe;
        struct re_s             *si_re;
        int                     si_rid;
-       char                    si_ridtxt[ STRLENOF("rid=4095") + 1 ];
+       char                    si_ridtxt[ STRLENOF("rid=999") + 1 ];
        slap_bindconf           si_bindconf;
        struct berval           si_base;
        struct berval           si_logbase;
@@ -562,9 +562,7 @@ do_syncrep1(
                ldap_pvt_thread_mutex_lock( &si->si_cookieState->cs_mutex );
                rc = backend_operational( op, &rs );
                if ( rc == LDAP_SUCCESS && a.a_vals ) {
-                       int num;
-                       for (i=0; !BER_BVISNULL( &a.a_vals[i] ); i++) ;
-                       num = i;
+                       int num = a.a_numvals;
                        /* check for differences */
                        if ( num != si->si_cookieState->cs_num ) {
                                changed = 1;
@@ -798,6 +796,10 @@ do_syncrep2(
                                }
                                if ( ber_peek_tag( ber, &len ) == LDAP_TAG_SYNC_COOKIE ) {
                                        ber_scanf( ber, /*"{"*/ "m}", &cookie );
+
+                                       Debug( LDAP_DEBUG_SYNC, "do_syncrep2: cookie=%s\n",
+                                               BER_BVISNULL( &cookie ) ? "" : cookie.bv_val, 0, 0 );
+
                                        if ( !BER_BVISNULL( &cookie ) ) {
                                                ch_free( syncCookie.octet_str.bv_val );
                                                ber_dupbv( &syncCookie.octet_str, &cookie );
@@ -865,6 +867,10 @@ do_syncrep2(
                                        ber_scanf( ber, "{" /*"}"*/);
                                        if ( ber_peek_tag( ber, &len ) == LDAP_TAG_SYNC_COOKIE ) {
                                                ber_scanf( ber, "m", &cookie );
+
+                                               Debug( LDAP_DEBUG_SYNC, "do_syncrep2: cookie=%s\n",
+                                                       BER_BVISNULL( &cookie ) ? "" : cookie.bv_val, 0, 0 );
+
                                                if ( !BER_BVISNULL( &cookie ) ) {
                                                        ch_free( syncCookie.octet_str.bv_val );
                                                        ber_dupbv( &syncCookie.octet_str, &cookie);
@@ -953,6 +959,10 @@ do_syncrep2(
                                                if ( ber_peek_tag( ber, &len ) == LDAP_TAG_SYNC_COOKIE )
                                                {
                                                        ber_scanf( ber, "m", &cookie );
+
+                                                       Debug( LDAP_DEBUG_SYNC, "do_syncrep2: cookie=%s\n",
+                                                               BER_BVISNULL( &cookie ) ? "" : cookie.bv_val, 0, 0 );
+
                                                        if ( !BER_BVISNULL( &cookie ) ) {
                                                                ch_free( syncCookie.octet_str.bv_val );
                                                                ber_dupbv( &syncCookie.octet_str, &cookie );
@@ -980,6 +990,10 @@ do_syncrep2(
                                                        LDAP_TAG_SYNC_COOKIE )
                                                {
                                                        ber_scanf( ber, "m", &cookie );
+
+                                                       Debug( LDAP_DEBUG_SYNC, "do_syncrep2: cookie=%s\n",
+                                                               BER_BVISNULL( &cookie ) ? "" : cookie.bv_val, 0, 0 );
+
                                                        if ( !BER_BVISNULL( &cookie ) ) {
                                                                ch_free( syncCookie.octet_str.bv_val );
                                                                ber_dupbv( &syncCookie.octet_str, &cookie );
@@ -1064,7 +1078,9 @@ do_syncrep2(
 
                        default:
                                Debug( LDAP_DEBUG_ANY, "do_syncrep2: %s "
-                                       "unknown message\n", si->si_ridtxt, 0, 0 );
+                                       "unknown message (0x%02lx)\n",
+                                       si->si_ridtxt,
+                                       (unsigned long)ldap_msgtype( msg ), 0 );
                                break;
 
                        }
@@ -1277,16 +1293,16 @@ reload:
        if ( rc ) {
                if ( fail == RETRYNUM_TAIL ) {
                        Debug( LDAP_DEBUG_ANY,
-                               "do_syncrepl: rid %03d quitting\n",
-                               si->si_rid, 0, 0 );
+                               "do_syncrepl: %s quitting\n",
+                               si->si_ridtxt, 0, 0 );
                } else if ( fail > 0 ) {
                        Debug( LDAP_DEBUG_ANY,
-                               "do_syncrepl: rid %03d retrying (%d retries left)\n",
-                               si->si_rid, fail, 0 );
+                               "do_syncrepl: %s retrying (%d retries left)\n",
+                               si->si_ridtxt, fail, 0 );
                } else {
                        Debug( LDAP_DEBUG_ANY,
-                               "do_syncrepl: rid %03d retrying\n",
-                               si->si_rid, 0, 0 );
+                               "do_syncrepl: %s retrying\n",
+                               si->si_ridtxt, 0, 0 );
                }
        }
 
@@ -1381,6 +1397,7 @@ syncrepl_accesslog_mods(
                        mod->sml_type = ad->ad_cname;
                        mod->sml_values = NULL;
                        mod->sml_nvalues = NULL;
+                       mod->sml_numvals = 0;
 
                        *modtail = mod;
                        modtail = &mod->sml_next;
@@ -1390,6 +1407,7 @@ syncrepl_accesslog_mods(
                        bv.bv_len = vals[i].bv_len - ( bv.bv_val - vals[i].bv_val );
                        ber_dupbv( &bv2, &bv );
                        ber_bvarray_add( &mod->sml_values, &bv2 );
+                       mod->sml_numvals++;
                }
        }
        return modlist;
@@ -1722,6 +1740,7 @@ syncrepl_message_to_entry(
                mod->sml_type = tmp.sml_type;
                mod->sml_values = tmp.sml_values;
                mod->sml_nvalues = NULL;
+               mod->sml_numvals = 0;   /* slap_mods_check will set this */
 
                *modtail = mod;
                modtail = &mod->sml_next;
@@ -1838,16 +1857,13 @@ syncrepl_entry(
        SlapReply       rs_add = {REP_RESULT};
        SlapReply       rs_modify = {REP_RESULT};
        Filter f = {0};
-#ifdef LDAP_COMP_MATCH
-       AttributeAssertion ava = { NULL, BER_BVNULL, NULL };
-#else
-       AttributeAssertion ava = { NULL, BER_BVNULL };
-#endif
+       AttributeAssertion ava = ATTRIBUTEASSERTION_INIT;
        int rc = LDAP_SUCCESS;
 
        struct berval pdn = BER_BVNULL;
        dninfo dni = {0};
        int     retry = 1;
+       int     freecsn = 1;
 
        Debug( LDAP_DEBUG_SYNC,
                "syncrepl_entry: %s LDAP_RES_SEARCH_ENTRY(LDAP_SYNC_%s)\n",
@@ -1959,6 +1975,8 @@ syncrepl_entry(
                                si->si_ridtxt, dni.dn.bv_val ? dni.dn.bv_val : "(null)", 0 );
        }
 
+       assert( BER_BVISNULL( &op->o_csn ) );
+
        slap_op_time( &op->o_time, &op->o_tincr );
        switch ( syncstate ) {
        case LDAP_SYNC_ADD:
@@ -1973,6 +1991,7 @@ syncrepl_entry(
                                 */
                                assert( BER_BVISNULL( &op->o_csn ) );
                                op->o_csn = a->a_vals[0];
+                               freecsn = 0;
                        }
                }
 retry_add:;
@@ -2205,8 +2224,12 @@ done:
        if ( !BER_BVISNULL( &dni.dn ) ) {
                op->o_tmpfree( dni.dn.bv_val, op->o_tmpmemctx );
        }
-       if ( entry )
+       if ( entry ) {
                entry_free( entry );
+       }
+       if ( !BER_BVISNULL( &op->o_csn ) && freecsn ) {
+               op->o_tmpfree( op->o_csn.bv_val, op->o_tmpmemctx );
+       }
        BER_BVZERO( &op->o_csn );
        return rc;
 }
@@ -2254,11 +2277,7 @@ syncrepl_del_nonpresent(
 
        if ( uuids ) {
                Filter uf;
-#ifdef LDAP_COMP_MATCH
-               AttributeAssertion eq = { NULL, BER_BVNULL, NULL };
-#else
-               AttributeAssertion eq = { NULL, BER_BVNULL };
-#endif
+               AttributeAssertion eq = ATTRIBUTEASSERTION_INIT;
                int i;
 
                op->ors_attrsonly = 1;
@@ -2335,6 +2354,7 @@ syncrepl_del_nonpresent(
                                mod1.sml_flags = 0;
                                mod1.sml_desc = slap_schema.si_ad_objectClass;
                                mod1.sml_type = mod1.sml_desc->ad_cname;
+                               mod1.sml_numvals = 2;
                                mod1.sml_values = &gcbva[0];
                                mod1.sml_nvalues = NULL;
                                mod1.sml_next = &mod2;
@@ -2343,6 +2363,7 @@ syncrepl_del_nonpresent(
                                mod2.sml_flags = 0;
                                mod2.sml_desc = slap_schema.si_ad_structuralObjectClass;
                                mod2.sml_type = mod2.sml_desc->ad_cname;
+                               mod1.sml_numvals = 1;
                                mod2.sml_values = &gcbva[1];
                                mod2.sml_nvalues = NULL;
                                mod2.sml_next = NULL;
@@ -2376,6 +2397,10 @@ syncrepl_del_nonpresent(
                        ber_bvfree( np_prev->npe_name );
                        ber_bvfree( np_prev->npe_nname );
                        ch_free( np_prev );
+
+                       if ( slapd_shutdown ) {
+                               break;
+                       }
                }
 
                slap_graduate_commit_csn( op );
@@ -2466,6 +2491,7 @@ syncrepl_add_glue(
 
                a = attr_alloc( slap_schema.si_ad_objectClass );
 
+               a->a_numvals = 2;
                a->a_vals = ch_calloc( 3, sizeof( struct berval ) );
                ber_dupbv( &a->a_vals[0], &gcbva[0] );
                ber_dupbv( &a->a_vals[1], &gcbva[1] );
@@ -2478,6 +2504,7 @@ syncrepl_add_glue(
 
                a = attr_alloc( slap_schema.si_ad_structuralObjectClass );
 
+               a->a_numvals = 1;
                a->a_vals = ch_calloc( 2, sizeof( struct berval ) );
                ber_dupbv( &a->a_vals[0], &gcbva[1] );
                ber_dupbv( &a->a_vals[1], &gcbva[2] );
@@ -2556,6 +2583,7 @@ syncrepl_updateCookie(
        mod[0].sml_type = mod[0].sml_desc->ad_cname;
        mod[0].sml_values = NULL;
        mod[0].sml_nvalues = NULL;
+       mod[0].sml_numvals = 0;
        mod[0].sml_next = &mod[1];
 
        mod[1].sml_op = LDAP_MOD_ADD;
@@ -2563,6 +2591,7 @@ syncrepl_updateCookie(
        mod[1].sml_type = mod[0].sml_desc->ad_cname;
        mod[1].sml_values = NULL;
        mod[1].sml_nvalues = NULL;
+       mod[1].sml_numvals = 0;
        mod[1].sml_next = NULL;
 
        ldap_pvt_thread_mutex_lock( &si->si_cookieState->cs_mutex );
@@ -2578,8 +2607,10 @@ syncrepl_updateCookie(
                                si->si_cookieState->cs_vals[j].bv_val, len ) > 0 ) {
                                ber_bvarray_add_x( &mod[0].sml_values,
                                        &si->si_cookieState->cs_vals[j], op->o_tmpmemctx );
+                               mod[0].sml_numvals++;
                                ber_bvarray_add_x( &mod[1].sml_values,
                                        &syncCookie->ctxcsn[i], op->o_tmpmemctx );
+                               mod[1].sml_numvals++;
                                if ( BER_BVISNULL( &first ))
                                        first = syncCookie->ctxcsn[i];
                        }
@@ -2589,6 +2620,7 @@ syncrepl_updateCookie(
                if ( j == si->si_cookieState->cs_num ) {
                        ber_bvarray_add_x( &mod[1].sml_values,
                                &syncCookie->ctxcsn[i], op->o_tmpmemctx );
+                       mod[1].sml_numvals++;
                        if ( BER_BVISNULL( &first ))
                                first = syncCookie->ctxcsn[i];
                }
@@ -2683,6 +2715,11 @@ attr_cmp( Operation *op, Attribute *old, Attribute *new,
                for ( o=0; old->a_vals[o].bv_val; o++ ) ;
                for ( n=0; new->a_vals[n].bv_val; n++ ) ;
 
+               /* there MUST be both old and new values */
+               assert( o != 0 );
+               assert( n != 0 );
+               j = 0;
+
                adds = op->o_tmpalloc( sizeof(struct berval *) * n, op->o_tmpmemctx );
                dels = op->o_tmpalloc( sizeof(struct berval *) * o, op->o_tmpmemctx );
 
@@ -2716,6 +2753,7 @@ attr_cmp( Operation *op, Attribute *old, Attribute *new,
                        mod->sml_flags = 0;
                        mod->sml_desc = old->a_desc;
                        mod->sml_type = mod->sml_desc->ad_cname;
+                       mod->sml_numvals = no;
                        mod->sml_values = ch_malloc( ( no + 1 ) * sizeof(struct berval) );
                        if ( old->a_vals != old->a_nvals ) {
                                mod->sml_nvalues = ch_malloc( ( no + 1 ) * sizeof(struct berval) );
@@ -2747,6 +2785,7 @@ attr_cmp( Operation *op, Attribute *old, Attribute *new,
                        mod->sml_flags = 0;
                        mod->sml_desc = old->a_desc;
                        mod->sml_type = mod->sml_desc->ad_cname;
+                       mod->sml_numvals = nn;
                        mod->sml_values = ch_malloc( ( nn + 1 ) * sizeof(struct berval) );
                        if ( old->a_vals != old->a_nvals ) {
                                mod->sml_nvalues = ch_malloc( ( nn + 1 ) * sizeof(struct berval) );
@@ -2835,11 +2874,11 @@ dn_callback(
                                        oldRDN.bv_len -= oldVal.bv_len + 2;
                                        slap_bv2ad( &oldRDN, &ad, &rs->sr_text );
                                        a = attr_find( dni->new_entry->e_attrs, ad );
-                                       if ( !a || value_find_ex( ad,
+                                       if ( !a || attr_valfind( a,
                                                SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH |
                                                SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
-                                               SLAP_MR_VALUE_OF_SYNTAX, a->a_nvals,
-                                               &oldVal, op->o_tmpmemctx ) != LDAP_SUCCESS )
+                                               SLAP_MR_VALUE_OF_SYNTAX,
+                                               &oldVal, NULL, op->o_tmpmemctx ) != LDAP_SUCCESS )
                                        {
                                                dni->delOldRDN = 1;
                                        }
@@ -2926,6 +2965,7 @@ dn_callback(
                                                        mod->sml_flags = 0;
                                                        mod->sml_desc = old->a_desc;
                                                        mod->sml_type = mod->sml_desc->ad_cname;
+                                                       mod->sml_numvals = 0;
                                                        mod->sml_values = NULL;
                                                        mod->sml_nvalues = NULL;
                                                        *modtail = mod;
@@ -2978,8 +3018,6 @@ nonpresent_callback(
 
        } else if ( rs->sr_type == REP_SEARCH ) {
                if ( !( si->si_refreshDelete & NP_DELETE_ONE ) ) {
-                       char buf[sizeof("rid=000 not")];
-
                        a = attr_find( rs->sr_entry->e_attrs, slap_schema.si_ad_entryUUID );
 
                        if ( a ) {
@@ -2987,13 +3025,15 @@ nonpresent_callback(
                                        syncuuid_cmp );
                        }
 
-                       if ( slap_debug & LDAP_DEBUG_SYNC ) {
-                               sprintf( buf, "%s %s", si->si_ridtxt,
+                       if ( LogTest( LDAP_DEBUG_SYNC ) ) {
+                               char buf[sizeof("rid=999 not")];
+
+                               snprintf( buf, sizeof(buf), "%s %s", si->si_ridtxt,
                                        present_uuid ? "got" : "not" );
-                       }
 
-                       Debug( LDAP_DEBUG_SYNC, "nonpresent_callback: %s UUID %s, dn %s\n",
-                               buf, a ? a->a_vals[0].bv_val : "<missing>", rs->sr_entry->e_name.bv_val );
+                               Debug( LDAP_DEBUG_SYNC, "nonpresent_callback: %s UUID %s, dn %s\n",
+                                       buf, a ? a->a_vals[0].bv_val : "<missing>", rs->sr_entry->e_name.bv_val );
+                       }
 
                        if ( a == NULL ) return 0;
                }
@@ -3359,7 +3399,7 @@ parse_syncrepl_line(
                                return -1;
                        }
                        si->si_rid = tmp;
-                       sprintf( si->si_ridtxt, IDSTR "=%d", si->si_rid );
+                       sprintf( si->si_ridtxt, IDSTR "=%03d", si->si_rid );
                        gots |= GOT_ID;
                } else if ( !strncasecmp( c->argv[ i ], PROVIDERSTR "=",
                                        STRLENOF( PROVIDERSTR "=" ) ) )
@@ -3906,7 +3946,7 @@ syncrepl_unparse( syncinfo_t *si, struct berval *bv )
 
        ptr = buf;
        assert( si->si_rid >= 0 && si->si_rid <= SLAP_SYNC_SID_MAX );
-       ptr += snprintf( ptr, WHATSLEFT, IDSTR "=%d " PROVIDERSTR "=%s",
+       ptr += snprintf( ptr, WHATSLEFT, IDSTR "=%03d " PROVIDERSTR "=%s",
                si->si_rid, si->si_bindconf.sb_uri.bv_val );
        if ( ptr - buf >= sizeof( buf ) ) return;
        if ( !BER_BVISNULL( &bc ) ) {