From ece9bdb0ebee4682ac52b147de9b3f36bb38fa46 Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Sat, 21 Jul 2001 14:15:23 +0000 Subject: [PATCH] Added the suffix= parameter to replica config directive to allow selective replication of subtrees of a single database. Multiple occurrences allow the same replica to handle different subtrees --- servers/slapd/config.c | 39 +++++++++++++++++++-- servers/slapd/proto-slap.h | 2 +- servers/slapd/repl.c | 67 +++++++++++++++++++++++++++++++++++-- servers/slapd/slap.h | 7 +++- servers/slapd/tools/mimic.c | 5 +++ servers/slurpd/config.c | 2 ++ servers/slurpd/slurp.h | 1 + 7 files changed, 117 insertions(+), 6 deletions(-) diff --git a/servers/slapd/config.c b/servers/slapd/config.c index 78303f5ce0..ce3c49c27d 100644 --- a/servers/slapd/config.c +++ b/servers/slapd/config.c @@ -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 ); + } + } } } diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index e70eff0d7e..cb68e287c5 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -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 )); /* diff --git a/servers/slapd/repl.c b/servers/slapd/repl.c index dc85c33a57..e5eddcfb8b 100644 --- a/servers/slapd/repl.c +++ b/servers/slapd/repl.c @@ -19,6 +19,31 @@ #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 ); diff --git a/servers/slapd/slap.h b/servers/slapd/slap.h index 1a0d72bfe6..baf78bf9ab 100644 --- a/servers/slapd/slap.h +++ b/servers/slapd/slap.h @@ -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 */ diff --git a/servers/slapd/tools/mimic.c b/servers/slapd/tools/mimic.c index 4c499c3327..3038bf6b69 100644 --- a/servers/slapd/tools/mimic.c +++ b/servers/slapd/tools/mimic.c @@ -196,3 +196,8 @@ void slap_mods_free( Modifications *ml ) assert(0); } +int add_replica_info( Backend *be, const char *host ) +{ + assert(0); +} + diff --git a/servers/slurpd/config.c b/servers/slurpd/config.c index e7a5627f59..308a4edd42 100644 --- a/servers/slurpd/config.c +++ b/servers/slurpd/config.c @@ -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 ) ) { diff --git a/servers/slurpd/slurp.h b/servers/slurpd/slurp.h index 9a8c8f3bb8..6dcd42554f 100644 --- a/servers/slurpd/slurp.h +++ b/servers/slurpd/slurp.h @@ -119,6 +119,7 @@ /* Config file keywords */ #define HOSTSTR "host" +#define SUFFIXSTR "suffix" #define BINDDNSTR "binddn" #define BINDMETHSTR "bindmethod" #define KERBEROSSTR "kerberos" -- 2.39.5