+ for ( i = 0; op->o_bd->be_replica != NULL && op->o_bd->be_replica[i] != NULL; i++ ) {
+ /* check if dn's suffix matches legal suffixes, if any */
+ if ( op->o_bd->be_replica[i]->ri_nsuffix != NULL ) {
+ int j;
+
+ for ( j = 0; op->o_bd->be_replica[i]->ri_nsuffix[j].bv_val; j++ ) {
+ if ( dnIsSuffix( &op->o_req_ndn, &op->o_bd->be_replica[i]->ri_nsuffix[j] ) ) {
+ break;
+ }
+ }
+
+ if ( !op->o_bd->be_replica[i]->ri_nsuffix[j].bv_val ) {
+ /* do not add "replica:" line */
+ continue;
+ }
+ }
+ /* See if we only want a subset of attributes */
+ if ( op->o_bd->be_replica[i]->ri_attrs != NULL &&
+ ( op->o_tag == LDAP_REQ_MODIFY || op->o_tag == LDAP_REQ_ADD || op->o_tag == LDAP_REQ_EXTENDED ) ) {
+ if ( !subsets ) {
+ subsets = i + 1;
+ }
+ /* Do attribute subsets by themselves in a second pass */
+ continue;
+ }
+
+ fprintf( fp, "replica: %s\n", op->o_bd->be_replica[i]->ri_host );
+#ifdef NO_LOG_WHEN_NO_REPLICAS
+ ++count;
+#endif
+ }
+
+#ifdef NO_LOG_WHEN_NO_REPLICAS
+ if ( count == 0 && subsets == 0 ) {
+ /* if no replicas matched, drop the log
+ * (should we log it anyway?) */
+ lock_fclose( fp, lfp );
+ ldap_pvt_thread_mutex_unlock( &replog_mutex );
+
+ return;
+ }
+#endif
+
+ replog1( NULL, op, fp, now );
+
+ if ( subsets > 0 ) {
+ for ( i = subsets - 1; op->o_bd->be_replica[i] != NULL; i++ ) {
+
+ /* If no attrs, we already did this above */
+ if ( op->o_bd->be_replica[i]->ri_attrs == NULL ) {
+ continue;
+ }
+
+ /* check if dn's suffix matches legal suffixes, if any */
+ if ( op->o_bd->be_replica[i]->ri_nsuffix != NULL ) {
+ int j;
+
+ for ( j = 0; op->o_bd->be_replica[i]->ri_nsuffix[j].bv_val; j++ ) {
+ if ( dnIsSuffix( &op->o_req_ndn, &op->o_bd->be_replica[i]->ri_nsuffix[j] ) ) {
+ break;
+ }
+ }
+
+ if ( !op->o_bd->be_replica[i]->ri_nsuffix[j].bv_val ) {
+ /* no matching suffix found, skip it */
+ continue;
+ }
+ }
+ switch( op->o_tag ) {
+ case LDAP_REQ_EXTENDED:
+ /* quick hack for extended operations */
+ /* assume change parameter is a Modifications* */
+ /* fall thru */
+ case LDAP_REQ_MODIFY:
+ case LDAP_REQ_ADD:
+ break;
+ default:
+ /* Other operations were logged in the first pass */
+ continue;
+ }
+ replog1( op->o_bd->be_replica[i], op, fp, now );
+ }
+ }
+
+ lock_fclose( fp, lfp );
+ ldap_pvt_thread_mutex_unlock( &replog_mutex );
+}
+
+static void
+rephdr(
+ struct slap_replica_info *ri,
+ Operation *op,
+ FILE *fp,
+ long now
+)
+{
+ if ( ri ) {
+ fprintf( fp, "replica: %s\n", ri->ri_host );