rc = ldap_sync_search( si, op->o_tmpmemctx );
 
        if( rc != LDAP_SUCCESS ) {
-               Debug( LDAP_DEBUG_ANY, "do_syncrep1: rid %03d "
+               Debug( LDAP_DEBUG_ANY, "do_syncrep1: rid %03ld "
                        "ldap_search_ext: %s (%d)\n",
                        si->si_rid, ldap_err2string( rc ), rc );
        }
        ber_init2( ber, NULL, LBER_USE_DER );
        ber_set_option( ber, LBER_OPT_BER_MEMCTX, &op->o_tmpmemctx );
 
-       Debug( LDAP_DEBUG_TRACE, "=>do_syncrep2 rid %03d\n", si->si_rid, 0, 0 );
+       Debug( LDAP_DEBUG_TRACE, "=>do_syncrep2 rid %03ld\n", si->si_rid, 0, 0 );
 
        psub = &si->si_be->be_nsuffix[0];
 
                                        rctrlp = ldap_find_control( LDAP_CONTROL_SYNC_STATE, rctrls );
                                }
                                if ( rctrlp == NULL ) {
-                                       Debug( LDAP_DEBUG_ANY, "do_syncrep2: rid %03d "
+                                       Debug( LDAP_DEBUG_ANY, "do_syncrep2: rid %03ld "
                                                "got search entry without "
                                                "Sync State control\n", si->si_rid, 0, 0 );
                                        rc = -1;
                                /* FIXME: what if syncUUID is NULL or empty?
                                 * (happens with back-sql...) */
                                if ( BER_BVISEMPTY( &syncUUID ) ) {
-                                       Debug( LDAP_DEBUG_ANY, "do_syncrep2: rid %03d "
+                                       Debug( LDAP_DEBUG_ANY, "do_syncrep2: rid %03ld "
                                                "got empty syncUUID\n", si->si_rid, 0, 0 );
                                        ldap_controls_free( rctrls );
                                        rc = -1;
 
                        case LDAP_RES_SEARCH_REFERENCE:
                                Debug( LDAP_DEBUG_ANY,
-                                       "do_syncrep2: rid %03d reference received error\n",
+                                       "do_syncrep2: rid %03ld reference received error\n",
                                        si->si_rid, 0, 0 );
                                break;
 
                        case LDAP_RES_SEARCH_RESULT:
                                Debug( LDAP_DEBUG_SYNC,
-                                       "do_syncrep2: rid %03d LDAP_RES_SEARCH_RESULT\n",
+                                       "do_syncrep2: rid %03ld LDAP_RES_SEARCH_RESULT\n",
                                        si->si_rid, 0, 0 );
                                ldap_parse_result( si->si_ld, msg, &err, NULL, NULL, NULL,
                                        &rctrls, 0 );
                                        ber_tag_t tag;
                                        case LDAP_TAG_SYNC_NEW_COOKIE:
                                                Debug( LDAP_DEBUG_SYNC,
-                                                       "do_syncrep2: rid %03d %s - %s\n", 
+                                                       "do_syncrep2: rid %03ld %s - %s\n", 
                                                        si->si_rid,
                                                        "LDAP_RES_INTERMEDIATE", 
                                                        "NEW_COOKIE" );
                                        case LDAP_TAG_SYNC_REFRESH_DELETE:
                                        case LDAP_TAG_SYNC_REFRESH_PRESENT:
                                                Debug( LDAP_DEBUG_SYNC,
-                                                       "do_syncrep2: rid %03d %s - %s\n", 
+                                                       "do_syncrep2: rid %03ld %s - %s\n", 
                                                        si->si_rid,
                                                        "LDAP_RES_INTERMEDIATE", 
                                                        si_tag == LDAP_TAG_SYNC_REFRESH_PRESENT ?
                                                break;
                                        case LDAP_TAG_SYNC_ID_SET:
                                                Debug( LDAP_DEBUG_SYNC,
-                                                       "do_syncrep2: rid %03d %s - %s\n", 
+                                                       "do_syncrep2: rid %03ld %s - %s\n", 
                                                        si->si_rid,
                                                        "LDAP_RES_INTERMEDIATE", 
                                                        "SYNC_ID_SET" );
                                                break;
                                        default:
                                                Debug( LDAP_DEBUG_ANY,
-                                                       "do_syncrep2: rid %03d unknown syncinfo tag (%ld)\n",
+                                                       "do_syncrep2: rid %03ld unknown syncinfo tag (%ld)\n",
                                                        si->si_rid, (long) si_tag, 0 );
                                                ldap_memfree( retoid );
                                                ber_bvfree( retdata );
                                        break;
 
                                } else {
-                                       Debug( LDAP_DEBUG_ANY, "do_syncrep2: rid %03d "
+                                       Debug( LDAP_DEBUG_ANY, "do_syncrep2: rid %03ld "
                                                "unknown intermediate response (%d)\n",
                                                si->si_rid, rc, 0 );
                                        ldap_memfree( retoid );
                                break;
 
                        default:
-                               Debug( LDAP_DEBUG_ANY, "do_syncrep2: rid %03d "
+                               Debug( LDAP_DEBUG_ANY, "do_syncrep2: rid %03ld "
                                        "unknown message\n", si->si_rid, 0, 0 );
                                break;
 
                errstr = ldap_err2string( rc );
                
                Debug( LDAP_DEBUG_ANY,
-                       "do_syncrep2: rid %03d %s\n", si->si_rid, errstr, 0 );
+                       "do_syncrep2: rid %03ld %s\n", si->si_rid, errstr, 0 );
        }
 
 done:
        int i, defer = 1;
        Backend *be;
 
-       Debug( LDAP_DEBUG_TRACE, "=>do_syncrepl rid %03d\n", si->si_rid, 0, 0 );
+       Debug( LDAP_DEBUG_TRACE, "=>do_syncrepl rid %03ld\n", si->si_rid, 0, 0 );
 
        if ( si == NULL )
                return NULL;
        int             rc, deleteOldRdn = 0, freeReqDn = 0;
 
        if ( ldap_msgtype( msg ) != LDAP_RES_SEARCH_ENTRY ) {
-               Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_op: rid %03d "
+               Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_op: rid %03ld "
                        "Message type should be entry (%d)",
                        si->si_rid, ldap_msgtype( msg ), 0 );
                return -1;
 
        if ( rc != LDAP_SUCCESS ) {
                Debug( LDAP_DEBUG_ANY,
-                       "syncrepl_message_to_op: rid %03d dn get failed (%d)",
+                       "syncrepl_message_to_op: rid %03ld dn get failed (%d)",
                        si->si_rid, rc, 0 );
                return rc;
        }
                        int i = verb_to_mask( bvals[0].bv_val, modops );
                        if ( i < 0 ) {
                                Debug( LDAP_DEBUG_ANY,
-                                       "syncrepl_message_to_op: rid %03d unknown op %s",
+                                       "syncrepl_message_to_op: rid %03ld unknown op %s",
                                        si->si_rid, bvals[0].bv_val, 0 );
                                ch_free( bvals );
                                rc = -1;
                rc = slap_mods_check( op, modlist, &text, txtbuf, textlen, NULL );
 
                if ( rc != LDAP_SUCCESS ) {
-                       Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_op: rid %03d "
+                       Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_op: rid %03ld "
                                "mods check (%s)\n",
                                si->si_rid, text, 0 );
                        goto done;
                        freeReqDn = 0;
                        rc = slap_mods2entry( modlist, &op->ora_e, 1, 0, &text, txtbuf, textlen);
                        if( rc != LDAP_SUCCESS ) {
-                               Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_op: rid %03d "
+                               Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_op: rid %03ld "
                                "mods2entry (%s)\n",
                                        si->si_rid, text, 0 );
                        } else {
                                rc = op->o_bd->be_add( op, &rs );
                                Debug( LDAP_DEBUG_SYNC,
-                                       "syncrepl_message_to_op: rid %03d be_add %s (%d)\n", 
+                                       "syncrepl_message_to_op: rid %03ld be_add %s (%d)\n", 
                                        si->si_rid, op->o_req_dn.bv_val, rc );
                        }
                        if ( e == op->ora_e )
                        op->orm_modlist = modlist;
                        rc = op->o_bd->be_modify( op, &rs );
                        Debug( LDAP_DEBUG_SYNC,
-                               "syncrepl_message_to_op: rid %03d be_modify %s (%d)\n", 
+                               "syncrepl_message_to_op: rid %03ld be_modify %s (%d)\n", 
                                si->si_rid, op->o_req_dn.bv_val, rc );
                }
                break;
                rc = op->o_bd->be_modrdn( op, &rs );
                slap_mods_free( op->orr_modlist, 1 );
                Debug( LDAP_DEBUG_SYNC,
-                       "syncrepl_message_to_op: rid %03d be_modrdn %s (%d)\n", 
+                       "syncrepl_message_to_op: rid %03ld be_modrdn %s (%d)\n", 
                        si->si_rid, op->o_req_dn.bv_val, rc );
                break;
        case LDAP_REQ_DELETE:
                rc = op->o_bd->be_delete( op, &rs );
                Debug( LDAP_DEBUG_SYNC,
-                       "syncrepl_message_to_op: rid %03d be_delete %s (%d)\n", 
+                       "syncrepl_message_to_op: rid %03ld be_delete %s (%d)\n", 
                        si->si_rid, op->o_req_dn.bv_val, rc );
                break;
        }
        *modlist = NULL;
 
        if ( ldap_msgtype( msg ) != LDAP_RES_SEARCH_ENTRY ) {
-               Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry: rid %03d "
+               Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry: rid %03ld "
                        "Message type should be entry (%d)",
                        si->si_rid, ldap_msgtype( msg ), 0 );
                return -1;
 
        if ( rc != LDAP_SUCCESS ) {
                Debug( LDAP_DEBUG_ANY,
-                       "syncrepl_message_to_entry: rid %03d dn get failed (%d)",
+                       "syncrepl_message_to_entry: rid %03ld dn get failed (%d)",
                        si->si_rid, rc, 0 );
                return rc;
        }
        }
 
        if ( *modlist == NULL ) {
-               Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry: rid %03d no attributes\n",
+               Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry: rid %03ld no attributes\n",
                        si->si_rid, 0, 0 );
                rc = -1;
                goto done;
        rc = slap_mods_check( op, *modlist, &text, txtbuf, textlen, NULL );
 
        if ( rc != LDAP_SUCCESS ) {
-               Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry: rid %03d mods check (%s)\n",
+               Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry: rid %03ld mods check (%s)\n",
                        si->si_rid, text, 0 );
                goto done;
        }
        
        rc = slap_mods2entry( *modlist, &e, 1, 1, &text, txtbuf, textlen);
        if( rc != LDAP_SUCCESS ) {
-               Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry: rid %03d mods2entry (%s)\n",
+               Debug( LDAP_DEBUG_ANY, "syncrepl_message_to_entry: rid %03ld mods2entry (%s)\n",
                        si->si_rid, text, 0 );
        }
 
 
        switch( syncstate ) {
        case LDAP_SYNC_PRESENT:
-               Debug( LDAP_DEBUG_SYNC, "syncrepl_entry: rid %03d %s\n",
+               Debug( LDAP_DEBUG_SYNC, "syncrepl_entry: rid %03ld %s\n",
                                        si->si_rid,
                                        "LDAP_RES_SEARCH_ENTRY(LDAP_SYNC_PRESENT)", 0 );
                break;
        case LDAP_SYNC_ADD:
-               Debug( LDAP_DEBUG_SYNC, "syncrepl_entry: rid %03d %s\n",
+               Debug( LDAP_DEBUG_SYNC, "syncrepl_entry: rid %03ld %s\n",
                                        si->si_rid,
                                        "LDAP_RES_SEARCH_ENTRY(LDAP_SYNC_ADD)", 0 );
                break;
        case LDAP_SYNC_DELETE:
-               Debug( LDAP_DEBUG_SYNC, "syncrepl_entry: rid %03d %s\n",
+               Debug( LDAP_DEBUG_SYNC, "syncrepl_entry: rid %03ld %s\n",
                                        si->si_rid,
                                        "LDAP_RES_SEARCH_ENTRY(LDAP_SYNC_DELETE)", 0 );
                break;
        case LDAP_SYNC_MODIFY:
-               Debug( LDAP_DEBUG_SYNC, "syncrepl_entry: rid %03d %s\n",
+               Debug( LDAP_DEBUG_SYNC, "syncrepl_entry: rid %03ld %s\n",
                                        si->si_rid,
                                        "LDAP_RES_SEARCH_ENTRY(LDAP_SYNC_MODIFY)", 0 );
                break;
        default:
-               Debug( LDAP_DEBUG_ANY, "syncrepl_entry: rid %03d %s\n",
+               Debug( LDAP_DEBUG_ANY, "syncrepl_entry: rid %03ld %s\n",
                                        si->si_rid,
                                        "LDAP_RES_SEARCH_ENTRY(UNKNOWN syncstate)", 0 );
        }
 
        (void)slap_uuidstr_from_normalized( &syncUUID_strrep, syncUUID, op->o_tmpmemctx );
        if ( syncuuid_bv ) {
-               Debug( LDAP_DEBUG_SYNC, "syncrepl_entry: rid %03d inserted UUID %s\n",
+               Debug( LDAP_DEBUG_SYNC, "syncrepl_entry: rid %03ld inserted UUID %s\n",
                        si->si_rid, syncUUID_strrep.bv_val, 0 );
        }
        op->ors_filter = &f;
        if ( limits_check( op, &rs_search ) == 0 ) {
                rc = be->be_search( op, &rs_search );
                Debug( LDAP_DEBUG_SYNC,
-                               "syncrepl_entry: rid %03d be_search (%d)\n", 
+                               "syncrepl_entry: rid %03ld be_search (%d)\n", 
                                si->si_rid, rc, 0 );
        }
 
 
        if ( entry && !BER_BVISNULL( &entry->e_name ) ) {
                Debug( LDAP_DEBUG_SYNC,
-                               "syncrepl_entry: rid %03d %s\n",
+                               "syncrepl_entry: rid %03ld %s\n",
                                si->si_rid, entry->e_name.bv_val, 0 );
        } else {
                Debug( LDAP_DEBUG_SYNC,
-                               "syncrepl_entry: rid %03d %s\n",
+                               "syncrepl_entry: rid %03ld %s\n",
                                si->si_rid, dni.dn.bv_val ? dni.dn.bv_val : "(null)", 0 );
        }
 
 
                        rc = be->be_add( op, &rs_add );
                        Debug( LDAP_DEBUG_SYNC,
-                                       "syncrepl_entry: rid %03d be_add (%d)\n", 
+                                       "syncrepl_entry: rid %03ld be_add (%d)\n", 
                                        si->si_rid, rc, 0 );
                        switch ( rs_add.sr_err ) {
                        case LDAP_SUCCESS:
 
                        default:
                                Debug( LDAP_DEBUG_ANY,
-                                       "syncrepl_entry: rid %03d be_add failed (%d)\n",
+                                       "syncrepl_entry: rid %03ld be_add failed (%d)\n",
                                        si->si_rid, rs_add.sr_err, 0 );
                                break;
                        }
 
                        slap_mods_free( op->orr_modlist, 1 );
                        Debug( LDAP_DEBUG_SYNC,
-                                       "syncrepl_entry: rid %03d be_modrdn (%d)\n", 
+                                       "syncrepl_entry: rid %03ld be_modrdn (%d)\n", 
                                        si->si_rid, rc, 0 );
                        if ( rs_modify.sr_err == LDAP_SUCCESS ) {
                                op->o_req_dn = entry->e_name;
 
                        rc = be->be_modify( op, &rs_modify );
                        Debug( LDAP_DEBUG_SYNC,
-                                       "syncrepl_entry: rid %03d be_modify (%d)\n", 
+                                       "syncrepl_entry: rid %03ld be_modify (%d)\n", 
                                        si->si_rid, rc, 0 );
                        if ( rs_modify.sr_err != LDAP_SUCCESS ) {
                                Debug( LDAP_DEBUG_ANY,
-                                       "syncrepl_entry: rid %03d be_modify failed (%d)\n",
+                                       "syncrepl_entry: rid %03ld be_modify failed (%d)\n",
                                        si->si_rid, rs_modify.sr_err, 0 );
                        }
                }
                        op->o_tag = LDAP_REQ_DELETE;
                        rc = be->be_delete( op, &rs_delete );
                        Debug( LDAP_DEBUG_SYNC,
-                                       "syncrepl_entry: rid %03d be_delete (%d)\n", 
+                                       "syncrepl_entry: rid %03ld be_delete (%d)\n", 
                                        si->si_rid, rc, 0 );
 
                        while ( rs_delete.sr_err == LDAP_SUCCESS
 
        default :
                Debug( LDAP_DEBUG_ANY,
-                       "syncrepl_entry: rid %03d unknown syncstate\n", si->si_rid, 0, 0 );
+                       "syncrepl_entry: rid %03ld unknown syncstate\n", si->si_rid, 0, 0 );
                goto done;
        }
 
                        op->o_req_ndn = *np_prev->npe_nname;
                        rc = op->o_bd->be_delete( op, &rs_delete );
                        Debug( LDAP_DEBUG_SYNC,
-                               "syncrepl_del_nonpresent: rid %03d be_delete %s (%d)\n", 
+                               "syncrepl_del_nonpresent: rid %03ld be_delete %s (%d)\n", 
                                si->si_rid, op->o_req_dn.bv_val, rc );
 
                        if ( rs_delete.sr_err == LDAP_NOT_ALLOWED_ON_NONLEAF ) {
                slap_dup_sync_cookie( &si->si_syncCookie, syncCookie );
        } else {
                Debug( LDAP_DEBUG_ANY,
-                       "syncrepl_updateCookie: rid %03d be_modify failed (%d)\n",
+                       "syncrepl_updateCookie: rid %03ld be_modify failed (%d)\n",
                        si->si_rid, rs_modify.sr_err, 0 );
        }
 
                                        syncuuid_cmp );
 
                        if ( slap_debug & LDAP_DEBUG_SYNC )
-                               sprintf( buf, "%03d %s", si->si_rid,
+                               sprintf( buf, "%03ld %s", si->si_rid,
                                        present_uuid ? "got" : "not" );
 
                        Debug( LDAP_DEBUG_SYNC, "nonpresent_callback: rid %s UUID %s, dn %s\n",