to allow selective replication of subtrees of a single database.
Multiple occurrences allow the same replica to handle different
subtrees
#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;
}
}
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 );
+ }
+ }
}
}
/*
* 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 ));
/*
#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(
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;
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 );
#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
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 */
assert(0);
}
+int add_replica_info( Backend *be, const char *host )
+{
+ assert(0);
+}
+
}
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 ) ) {
/* Config file keywords */
#define HOSTSTR "host"
+#define SUFFIXSTR "suffix"
#define BINDDNSTR "binddn"
#define BINDMETHSTR "bindmethod"
#define KERBEROSSTR "kerberos"