+ for ( i = 0; be->be_replica != NULL && be->be_replica[i] != NULL; i++ ) {
+ /* check if dn's suffix matches legal suffixes, if any */
+ if ( be->be_replica[i]->ri_nsuffix != NULL ) {
+ int j;
+
+ for ( j = 0; be->be_replica[i]->ri_nsuffix[j].bv_val; j++ ) {
+ if ( dnIsSuffix( ndn, &be->be_replica[i]->ri_nsuffix[j] ) ) {
+ break;
+ }
+ }
+
+ if ( !be->be_replica[i]->ri_nsuffix[j].bv_val ) {
+ /* do not add "replica:" line */
+ continue;
+ }
+ }
+ /* See if we only want a subset of attributes */
+ if ( be->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", be->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
+
+ fprintf( fp, "time: %ld\n", now );
+ fprintf( fp, "dn: %s\n", dn->bv_val );
+
+ replog1( NULL, op, change, fp, NULL );
+
+ if ( subsets > 0 ) {
+ void *first;
+ for ( i = subsets - 1; be->be_replica != NULL && be->be_replica[i] != NULL; i++ ) {
+
+ /* If no attrs, we already did this above */
+ if ( be->be_replica[i]->ri_attrs == NULL ) {
+ continue;
+ }
+
+ /* check if dn's suffix matches legal suffixes, if any */
+ if ( be->be_replica[i]->ri_nsuffix != NULL ) {
+ int j;
+
+ for ( j = 0; be->be_replica[i]->ri_nsuffix[j].bv_val; j++ ) {
+ if ( dnIsSuffix( ndn, &be->be_replica[i]->ri_nsuffix[j] ) ) {
+ break;
+ }
+ }
+
+ if ( !be->be_replica[i]->ri_nsuffix[j].bv_val ) {
+ /* do not add "replica:" line */
+ continue;
+ }
+ }
+ subsets = 0;
+ first = NULL;
+ switch( op->o_tag ) {
+ case LDAP_REQ_EXTENDED:
+ /* quick hack for extended operations */
+ /* assume change parameter is a Modfications* */
+ /* fall thru */
+ case LDAP_REQ_MODIFY:
+ for ( ml = change; ml != NULL; ml = ml->sml_next ) {
+ int is_in, exclude;
+
+ is_in = ad_inlist( ml->sml_desc, be->be_replica[i]->ri_attrs );
+ exclude = be->be_replica[i]->ri_exclude;
+
+ /*
+ * there might be a more clever way to do this test,
+ * but this way, at least, is comprehensible :)
+ */
+ if ( ( is_in && !exclude ) || ( !is_in && exclude ) ) {
+ subsets = 1;
+ first = ml;
+ break;
+ }
+ }
+ if ( !subsets ) {
+ continue;
+ }
+ break;
+ case LDAP_REQ_ADD:
+ e = change;
+ for ( a = e->e_attrs; a != NULL; a = a->a_next ) {
+ int is_in, exclude;
+
+ is_in = ad_inlist( a->a_desc, be->be_replica[i]->ri_attrs );
+ exclude = be->be_replica[i]->ri_exclude;
+
+ if ( ( is_in && !exclude ) || ( !is_in && exclude ) ) {
+ subsets = 1;
+ first = a;
+ break;
+ }
+ }
+ if ( !subsets ) {
+ continue;
+ }
+ break;
+ default:
+ /* Other operations were logged in the first pass */
+ continue;
+ }
+ fprintf( fp, "replica: %s\n", be->be_replica[i]->ri_host );
+ fprintf( fp, "time: %ld\n", now );
+ fprintf( fp, "dn: %s\n", dn->bv_val );
+ replog1( be->be_replica[i], op, change, fp, first );
+ }