]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/repl.c
Support subtree rename, refuse subtree delete
[openldap] / servers / slapd / repl.c
index c04a44247b9e9f2e1a17f7437180776cafa6ef6b..529416023c97fc1cd7afa356f144c50c9a4c807a 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1998-2003 The OpenLDAP Foundation.
+ * Copyright 1998-2005 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -42,6 +42,7 @@
 int
 add_replica_info(
     Backend     *be,
+    const char  *uri, 
     const char  *host 
 )
 {
@@ -59,7 +60,8 @@ add_replica_info(
 
        be->be_replica[ i ] 
                = ch_calloc( sizeof( struct slap_replica_info ), 1 );
-       be->be_replica[ i ]->ri_host = ch_strdup( host );
+       be->be_replica[ i ]->ri_uri = uri;
+       be->be_replica[ i ]->ri_host = host;
        be->be_replica[ i ]->ri_nsuffix = NULL;
        be->be_replica[ i ]->ri_attrs = NULL;
        be->be_replica[ i + 1 ] = NULL;
@@ -134,14 +136,16 @@ replog( Operation *op )
 #endif
        int     subsets = 0;
        long now = slap_get_time();
+       char    *replogfile;
 
-       if ( op->o_bd->be_replogfile == NULL && replogfile == NULL ) {
+       replogfile = op->o_bd->be_replogfile ? op->o_bd->be_replogfile :
+               frontendDB->be_replogfile;
+       if ( !replogfile ) {
                return;
        }
 
        ldap_pvt_thread_mutex_lock( &replog_mutex );
-       if ( (fp = lock_fopen( op->o_bd->be_replogfile ? op->o_bd->be_replogfile :
-           replogfile, "a", &lfp )) == NULL ) {
+       if ( (fp = lock_fopen( replogfile, "a", &lfp )) == NULL ) {
                ldap_pvt_thread_mutex_unlock( &replog_mutex );
                return;
        }
@@ -260,8 +264,9 @@ replog1(
        Modifications   *ml;
        Attribute       *a;
        AttributeName   *an;
-       int             dohdr = 1;
+       int             dohdr = 1, ocs = -1;
        struct berval vals[2];
+
        vals[1].bv_val = NULL;
        vals[1].bv_len = 0;
 
@@ -298,40 +303,49 @@ replog1(
                                /* If this is objectClass, see if the value is included
                                 * in any subset, otherwise drop it.
                                 */
-                               if ( ml->sml_desc == slap_schema.si_ad_objectClass
-                                       && ml->sml_bvalues ) {
-                                       int i, ocs = 0, first = 1;
-                                       for ( i=0; ml->sml_bvalues[i].bv_val; i++ ) {
+                               if ( ocs && ml->sml_desc == slap_schema.si_ad_objectClass
+                                       && ml->sml_values )
+                               {
+                                       int i, first = 1;
+
+                                       if ( ocs == -1 ) ocs = 0;
+
+                                       for ( i=0; ml->sml_values[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,
+                                                               match |= an->an_oc_exclude;
+                                                               if ( ml->sml_values[i].bv_len == an->an_name.bv_len
+                                                                       && !strcasecmp(ml->sml_values[i].bv_val,
                                                                                an->an_name.bv_val ) ) {
-                                                                       match = 1 ^ an->an_oc_exclude;
+                                                                       match = !an->an_oc_exclude;
                                                                        break;
                                                                }
                                                        }
                                                }
-                                               if ( ocs ) {
-                                                       match ^= ri->ri_exclude;
-                                                       /* Found a match, log it */
-                                                       if ( match ) {
-                                                               if ( dohdr ) {
-                                                                       rephdr( ri, op, fp, 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;
+                                               /* 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, 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 ) {
@@ -348,8 +362,8 @@ replog1(
                                dohdr = 0;
                        }
                        fprintf( fp, "%s: %s\n", did, type );
-                       if ( ml->sml_bvalues ) {
-                               print_vals( fp, &ml->sml_desc->ad_cname, ml->sml_bvalues );
+                       if ( ml->sml_values ) {
+                               print_vals( fp, &ml->sml_desc->ad_cname, ml->sml_values );
                        }
                        fprintf( fp, "-\n" );
                }
@@ -367,23 +381,29 @@ replog1(
                                 * only include those classes in the
                                 * objectClass attribute
                                 */
-                               if ( a->a_desc == slap_schema.si_ad_objectClass ) {
-                                       int i, ocs = 0;
+                               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;
+                                                               match |= an->an_oc_exclude;
                                                                if ( a->a_vals[i].bv_len == an->an_name.bv_len
                                                                        && !strcasecmp(a->a_vals[i].bv_val,
                                                                                an->an_name.bv_val ) ) {
-                                                                       match = 1 ^ an->an_oc_exclude;
+                                                                       match = !an->an_oc_exclude;
                                                                        break;
                                                                }
                                                        }
                                                }
+                                               if ( !ocs ) break;
+
                                                match ^= ri->ri_exclude;
-                                               if ( ocs && match ) {
+                                               if ( match ) {
                                                        if ( dohdr ) {
                                                                rephdr( ri, op, fp, now );
                                                                fprintf( fp, "changetype: add\n" );