]> git.sur5r.net Git - openldap/commitdiff
Import ITS#2889 fix from HEAD
authorHoward Chu <hyc@openldap.org>
Fri, 9 Jan 2004 22:21:06 +0000 (22:21 +0000)
committerHoward Chu <hyc@openldap.org>
Fri, 9 Jan 2004 22:21:06 +0000 (22:21 +0000)
servers/slapd/repl.c

index 25fe030e797d022c3c20bf8ccf111f67b2c6a33d..03630be9498d0ddc56df8680da939d4810ddd191 100644 (file)
@@ -100,7 +100,7 @@ add_replica_attrs(
 static void
 print_vals( FILE *fp, struct berval *type, struct berval *bv );
 static void
-replog1( struct slap_replica_info *ri, Operation *op, void *change, FILE *fp, void *first);
+replog1( struct slap_replica_info *ri, Operation *op, void *change, FILE *fp, struct berval *dn, long now);
 
 void
 replog(
@@ -177,13 +177,9 @@ replog(
        }
 #endif
 
-       fprintf( fp, "time: %ld\n", now );
-       fprintf( fp, "dn: %s\n", dn->bv_val );
-
-       replog1( NULL, op, change, fp, NULL );
+       replog1( NULL, op, change, fp, dn, now );
 
        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 */
@@ -206,60 +202,19 @@ replog(
                                        continue;
                                }
                        }
-                       subsets = 0;
-                       first = NULL;
                        switch( op->o_tag ) {
                        case LDAP_REQ_EXTENDED:
                                /* quick hack for extended operations */
-                               /* assume change parameter is a Modfications* */
+                               /* assume change parameter is a Modifications* */
                                /* 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 );
+                       replog1( be->be_replica[i], op, change, fp, dn, now );
                }
        }
 
@@ -267,20 +222,42 @@ replog(
        ldap_pvt_thread_mutex_unlock( &replog_mutex );
 }
 
+static void
+rephdr(
+       struct slap_replica_info *ri,
+       Operation *op,
+       FILE *fp,
+       struct berval *dn,
+       long now
+)
+{
+       if ( ri ) {
+               fprintf( fp, "replica: %s\n", ri->ri_host );
+       }
+       fprintf( fp, "time: %ld\n", now );
+       fprintf( fp, "dn: %s\n", dn->bv_val );
+}
 
 static void
 replog1(
-    struct slap_replica_info *ri,
-    Operation *op,
-    void       *change,
-    FILE       *fp,
-       void    *first
+       struct slap_replica_info *ri,
+       Operation *op,
+       void    *change,
+       FILE    *fp,
+       struct berval *dn,
+       long    now
 )
 {
        Modifications   *ml;
        Attribute       *a;
+       AttributeName   *an;
        Entry           *e;
        struct slap_replog_moddn *moddn;
+       int             dohdr = 1, ocs = -1;
+       struct berval vals[2];
+
+       vals[1].bv_val = NULL;
+       vals[1].bv_len = 0;
 
        switch ( op->o_tag ) {
        case LDAP_REQ_EXTENDED:
@@ -289,31 +266,83 @@ replog1(
                /* fall thru */
 
        case LDAP_REQ_MODIFY:
-               fprintf( fp, "changetype: modify\n" );
-               ml = first ? first : change;
-               for ( ; ml != NULL; ml = ml->sml_next ) {
-                       char *type;
+               for ( ml = change; ml != NULL; ml = ml->sml_next ) {
+                       char *did, *type = ml->sml_desc->ad_cname.bv_val;
+                       switch ( ml->sml_op ) {
+                       case LDAP_MOD_ADD:
+                               did = "add"; break;
+
+                       case LDAP_MOD_DELETE:
+                               did = "delete"; break;
+
+                       case LDAP_MOD_REPLACE:
+                               did = "replace"; break;
+                       }
                        if ( ri && ri->ri_attrs ) {
                                int is_in = ad_inlist( ml->sml_desc, ri->ri_attrs );
 
                                if ( ( !is_in && !ri->ri_exclude ) || ( is_in && ri->ri_exclude ) ) {
                                        continue;
                                }
+                               /* If this is objectClass, see if the value is included
+                                * in any subset, otherwise drop it.
+                                */
+                               if ( ocs && ml->sml_desc == slap_schema.si_ad_objectClass
+                                       && ml->sml_bvalues ) {
+                                       int i, first = 1;
+
+                                       if ( ocs == -1 ) ocs = 0;
+
+                                       for ( i=0; ml->sml_bvalues[i].bv_val; i++ ) {
+                                               int match = 0;
+                                               for ( an = ri->ri_attrs; an->an_name.bv_val; an++ ) {
+                                                       if ( an->an_oc ) {
+                                                               ocs = 1;
+                                                               if ( ml->sml_bvalues[i].bv_len == an->an_name.bv_len
+                                                                       && !strcasecmp(ml->sml_bvalues[i].bv_val,
+                                                                               an->an_name.bv_val ) ) {
+                                                                       match = 1;
+                                                                       break;
+                                                               }
+                                                       }
+                                               }
+                                               /* Objectclasses need no special treatment, drop into
+                                                * regular processing
+                                                */
+                                               if ( !ocs ) break;
+
+                                               match ^= ri->ri_exclude;
+                                               /* Found a match, log it */
+                                               if ( match ) {
+                                                       if ( dohdr ) {
+                                                               rephdr( ri, op, fp, dn, now );
+                                                               fprintf( fp, "changetype: modify\n" );
+                                                               dohdr = 0;
+                                                       }
+                                                       if ( first ) {
+                                                               fprintf( fp, "%s: %s\n", did, type );
+                                                               first = 0;
+                                                       }
+                                                       vals[0] = an->an_name;
+                                                       print_vals( fp, &ml->sml_desc->ad_cname, vals );
+                                                       ocs = 2;
+                                               }
+                                       }
+                                       /* Explicit objectclasses have been handled already */
+                                       if ( ocs ) {
+                                               if ( ocs == 2 ) {
+                                                       fprintf( fp, "-\n" );
+                                               }
+                                               continue;
+                                       }
+                               }
                        }
-                       type = ml->sml_desc->ad_cname.bv_val;
-                       switch ( ml->sml_op ) {
-                       case LDAP_MOD_ADD:
-                               fprintf( fp, "add: %s\n", type );
-                               break;
-
-                       case LDAP_MOD_DELETE:
-                               fprintf( fp, "delete: %s\n", type );
-                               break;
-
-                       case LDAP_MOD_REPLACE:
-                               fprintf( fp, "replace: %s\n", type );
-                               break;
+                       if ( dohdr ) {
+                               rephdr( ri, op, fp, dn, now );
+                               fprintf( fp, "changetype: modify\n" );
+                               dohdr = 0;
                        }
+                       fprintf( fp, "%s: %s\n", did, type );
                        if ( ml->sml_bvalues )
                                print_vals( fp, &ml->sml_desc->ad_cname, ml->sml_bvalues );
                        fprintf( fp, "-\n" );
@@ -321,10 +350,7 @@ replog1(
                break;
 
        case LDAP_REQ_ADD:
-               e = change;
-               fprintf( fp, "changetype: add\n" );
-               a = first ? first : e->e_attrs;
-               for ( ; a != NULL; a=a->a_next ) {
+               for ( a = e->e_attrs; a != NULL; a=a->a_next ) {
                        if ( ri && ri->ri_attrs ) {
                                int is_in = ad_inlist( a->a_desc, ri->ri_attrs );
                                if ( ( !is_in && !ri->ri_exclude ) || ( is_in && ri->ri_exclude ) ) {
@@ -334,39 +360,56 @@ replog1(
                                 * only include those classes in the
                                 * objectClass attribute
                                 */
-                               if ( a->a_desc == slap_schema.si_ad_objectClass ) {
-                                       int ocs = 0;
-                                       AttributeName *an;
-                                       struct berval vals[2];
-                                       vals[1].bv_val = NULL;
-                                       vals[1].bv_len = 0;
-                                       for ( an = ri->ri_attrs; an->an_name.bv_val; an++ ) {
-                                               if ( an->an_oc ) {
-                                                       int i;
-                                                       for ( i=0; a->a_vals[i].bv_val; i++ ) {
+                               if ( ocs && a->a_desc == slap_schema.si_ad_objectClass ) {
+                                       int i;
+
+                                       if ( ocs == -1 ) ocs = 0;
+
+                                       for ( i=0; a->a_vals[i].bv_val; i++ ) {
+                                               int match = 0;
+                                               for ( an = ri->ri_attrs; an->an_name.bv_val; an++ ) {
+                                                       if ( an->an_oc ) {
+                                                               ocs = 1;
                                                                if ( a->a_vals[i].bv_len == an->an_name.bv_len
                                                                        && !strcasecmp(a->a_vals[i].bv_val,
                                                                                an->an_name.bv_val ) ) {
-                                                                       ocs = 1;
-                                                                       vals[0] = an->an_name;
-                                                                       print_vals( fp, &a->a_desc->ad_cname, vals );
+                                                                       match = 1;
                                                                        break;
                                                                }
                                                        }
                                                }
+                                               if ( !ocs ) break;
+
+                                               match ^= ri->ri_exclude;
+                                               if ( match ) {
+                                                       if ( dohdr ) {
+                                                               rephdr( ri, op, fp, dn, now );
+                                                               fprintf( fp, "changetype: add\n" );
+                                                               dohdr = 0;
+                                                       }
+                                                       vals[0] = an->an_name;
+                                                       print_vals( fp, &a->a_desc->ad_cname, vals );
+                                               }
                                        }
                                        if ( ocs ) continue;
                                }
                        }
+                       if ( dohdr ) {
+                               rephdr( ri, op, fp, dn, now );
+                               fprintf( fp, "changetype: add\n" );
+                               dohdr = 0;
+                       }
                        print_vals( fp, &a->a_desc->ad_cname, a->a_vals );
                }
                break;
 
        case LDAP_REQ_DELETE:
+               rephdr( ri, op, fp, dn, now );
                fprintf( fp, "changetype: delete\n" );
                break;
 
        case LDAP_REQ_MODRDN:
+               rephdr( ri, op, fp, dn, now );
                moddn = change;
                fprintf( fp, "changetype: modrdn\n" );
                fprintf( fp, "newrdn: %s\n", moddn->newrdn->bv_val );