]> git.sur5r.net Git - openldap/commitdiff
Added the suffix=<dn> parameter to replica config directive
authorPierangelo Masarati <ando@openldap.org>
Sat, 21 Jul 2001 14:15:23 +0000 (14:15 +0000)
committerPierangelo Masarati <ando@openldap.org>
Sat, 21 Jul 2001 14:15:23 +0000 (14:15 +0000)
to allow selective replication of subtrees of a single database.
Multiple occurrences allow the same replica to handle different
subtrees

servers/slapd/config.c
servers/slapd/proto-slap.h
servers/slapd/repl.c
servers/slapd/slap.h
servers/slapd/tools/mimic.c
servers/slurpd/config.c
servers/slurpd/slurp.h

index 78303f5ce0daf226af3d04fe8827f1dcc29c31c1..ce3c49c27d367e970132f53057e0f64e64ac85ba 100644 (file)
@@ -1560,11 +1560,13 @@ read_config( const char *fname )
 #endif
 
                        } else {
+                               int nr = -1;
+
                                for ( i = 1; i < cargc; i++ ) {
                                        if ( strncasecmp( cargv[i], "host=", 5 )
                                            == 0 ) {
-                                               charray_add( &be->be_replica,
-                                                            cargv[i] + 5 );
+                                               nr = add_replica_info( be, 
+                                                       cargv[i] + 5 );
                                                break;
                                        }
                                }
@@ -1579,6 +1581,39 @@ read_config( const char *fname )
                                            fname, lineno, 0 );
 #endif
 
+                               } else if ( nr == -1 ) {
+#ifdef NEW_LOGGING
+                                       LDAP_LOG(( "config", LDAP_LEVEL_INFO,
+                                                  "%s: line %d: unable to add"
+                                                  " replica \"%s\""
+                                                  " (ignored)\n",
+                                                  fname, lineno, 
+                                                  cargv[i] + 5 ));
+#else
+                                       Debug( LDAP_DEBUG_ANY,
+               "%s: line %d: unable to add replica \"%s\" (ignored)\n",
+                                               fname, lineno, cargv[i] + 5 );
+#endif
+                               } else {
+                                       for ( i = 1; i < cargc; i++ ) {
+                                               if ( strncasecmp( cargv[i], "suffix=", 7 ) == 0 ) {
+                                                       char *nsuffix = ch_strdup( cargv[i] + 7 );
+                                                       if ( dn_normalize( nsuffix ) != NULL ) {
+                                                               charray_add( &be->be_replica[nr]->ri_nsuffix, nsuffix );
+                                                       } else {
+#ifdef NEW_LOGGING
+                                                               LDAP_LOG(( "config", LDAP_LEVEL_INFO,
+                                                                                       "%s: line %d: unable to normalize suffix in \"replica\" line (ignored)\n",
+                                                                                       fname, lineno ));
+#else
+                                                                Debug( LDAP_DEBUG_ANY,
+                                                                                "%s: line %d: unable to normalize suffix in \"replica\" line (ignored)\n",
+                                                                                fname, lineno, 0 );
+#endif
+                                                       }
+                                                       free( nsuffix );
+                                               }
+                                       }
                                }
                        }
 
index e70eff0d7ed2f4cc6a7d211a2a8e749e9f898528..cb68e287c5d2ccafc8bd87543f998b7d0ef04554 100644 (file)
@@ -490,7 +490,7 @@ LDAP_SLAPD_F (char *) phonetic LDAP_P(( char *s ));
 /*
  * repl.c
  */
-
+LDAP_SLAPD_F (int) add_replica_info LDAP_P(( Backend *be, const char *host ));
 LDAP_SLAPD_F (void) replog LDAP_P(( Backend *be, Operation *op, char *dn, void *change ));
 
 /*
index dc85c33a572faa0dca5f9e2c61af965ea869c739..e5eddcfb8b05d437f77c5588572800578acfa5c8 100644 (file)
 
 #include "slap.h"
 
+int
+add_replica_info(
+    Backend     *be,
+    const char  *host 
+)
+{
+       int i = 0;
+
+       assert( be );
+       assert( host );
+
+       if ( be->be_replica != NULL ) {
+               for ( ; be->be_replica[ i ] != NULL; i++ );
+       }
+               
+       be->be_replica = ch_realloc( be->be_replica, 
+               sizeof( struct slap_replica_info * )*( i + 2 ) );
+
+       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 + 1 ] = NULL;
+
+       return( i );
+}
 
 void
 replog(
@@ -33,7 +58,7 @@ replog(
        struct replog_moddn *moddn;
        char *tmp;
        FILE    *fp, *lfp;
-       int     len, i;
+       int     len, i, count = 0;
 
        if ( be->be_replogfile == NULL && replogfile == NULL ) {
                return;
@@ -46,10 +71,48 @@ replog(
                return;
        }
 
+       tmp = ch_strdup( dn );
+       if ( dn_normalize( tmp ) == NULL ) {
+               /* something has gone really bad */
+               ch_free( tmp );
+
+               lock_fclose( fp, lfp );
+               ldap_pvt_thread_mutex_unlock( &replog_mutex );
+               return;
+       }
+
        for ( i = 0; be->be_replica != NULL && be->be_replica[i] != NULL;
            i++ ) {
-               fprintf( fp, "replica: %s\n", be->be_replica[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]; j++ ) {
+                               if ( dn_issuffix( tmp, be->be_replica[i]->ri_nsuffix[j] ) ) {
+                                       break;
+                               }
+                       }
+
+                       if ( !be->be_replica[i]->ri_nsuffix[j] ) {
+                               /* do not add "replica:" line */
+                               continue;
+                       }
+               }
+
+               fprintf( fp, "replica: %s\n", be->be_replica[i]->ri_host );
+               ++count;
        }
+
+       ch_free( tmp );
+       if ( count == 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;
+       }
+
        fprintf( fp, "time: %ld\n", (long) slap_get_time() );
        fprintf( fp, "dn: %s\n", dn );
 
index 1a0d72bfe65220c8b397f36b0c47761693535146..baf78bf9ab5c3c22109df5bfe420d886270252ef 100644 (file)
@@ -813,6 +813,11 @@ LDAP_SLAPD_F (int) slapMode;
 
 #define SLAP_TRUNCATE_MODE     0x0100
 
+struct slap_replica_info {
+       char   *ri_host;        /* supersedes be_replica */
+       char  **ri_nsuffix;     /* array of suffixes this replica accepts */
+};
+
 /* temporary aliases */
 typedef BackendDB Backend;
 #define nbackends nBackendDB
@@ -912,7 +917,7 @@ struct slap_backend_db {
        int     be_timelimit;   /* time limit for this backend             */
        AccessControl *be_acl;  /* access control list for this backend    */
        slap_access_t   be_dfltaccess;  /* access given if no acl matches          */
-       char    **be_replica;   /* replicas of this backend (in master)    */
+       struct slap_replica_info **be_replica;  /* replicas of this backend (in master) */
        char    *be_replogfile; /* replication log file (in master)        */
        char    *be_update_ndn; /* allowed to make changes (in replicas) */
        struct berval **be_update_refs; /* where to refer modifying clients to */
index 4c499c3327b8ef0183f6217a0c452dc8e5f58acb..3038bf6b69281898327f771c51710f41955bf37e 100644 (file)
@@ -196,3 +196,8 @@ void slap_mods_free( Modifications *ml )
        assert(0);
 }
 
+int add_replica_info( Backend *be, const char *host )
+{
+       assert(0);
+}
+       
index e7a5627f5988850cdf4a999eebdc51a62bdf7436..308a4edd42104e28eb5cf928f926cf734dec297c 100644 (file)
@@ -377,6 +377,8 @@ parse_replica_line(
            }
            ri->ri_hostname = strdup( val );
            gots |= GOT_HOST;
+       } else if ( !strncasecmp( cargv[ i ], SUFFIXSTR, strlen( HOSTSTR ))) {
+           /* ignore it */ ;
        } else if ( !strncasecmp( cargv[ i ], TLSSTR, strlen( TLSSTR ))) {
            val = cargv[ i ] + strlen( TLSSTR ) + 1;
                if( !strcasecmp( val, TLSCRITICALSTR ) ) {
index 9a8c8f3bb8030fa1b8c7a8c62cf765be8d99536e..6dcd42554f001182394137ce000cbaa1ddc49414 100644 (file)
 
 /* Config file keywords */
 #define        HOSTSTR                 "host"
+#define        SUFFIXSTR               "suffix"
 #define        BINDDNSTR               "binddn"
 #define        BINDMETHSTR             "bindmethod"
 #define        KERBEROSSTR             "kerberos"