]> git.sur5r.net Git - openldap/commitdiff
suck in the subtree replication changes from HEAD
authorKurt Zeilenga <kurt@openldap.org>
Fri, 27 Jul 2001 01:13:27 +0000 (01:13 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Fri, 27 Jul 2001 01:13:27 +0000 (01:13 +0000)
servers/slapd/config.c
servers/slapd/proto-slap.h
servers/slapd/repl.c
servers/slapd/slap.h
servers/slapd/tools/mimic.c

index f97e28ce62a2c650561b49b497324859df2df6a2..4f3d58387da4c5c2fbeaaff00ea8f4f5c2ee1aa5 100644 (file)
@@ -931,11 +931,13 @@ read_config( const char *fname )
 "%s: line %d: replica line must appear inside a database definition (ignored)\n",
                                    fname, lineno, 0 );
                        } 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;
                                        }
                                }
@@ -943,6 +945,31 @@ read_config( const char *fname )
                                        Debug( LDAP_DEBUG_ANY,
                    "%s: line %d: missing host in \"replica\" line (ignored)\n",
                                            fname, lineno, 0 );
+
+                               } else if ( nr == -1 ) {
+                                       Debug( LDAP_DEBUG_ANY,
+               "%s: line %d: unable to add replica \"%s\" (ignored)\n",
+                                               fname, lineno, cargv[i] + 5 );
+                               } 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 ) {
+                                                               if ( be_issuffix( be, nsuffix ) ) {
+                                                                       charray_add( &be->be_replica[nr]->ri_nsuffix, nsuffix );
+                                                               } else {
+                                                                       Debug( LDAP_DEBUG_ANY,
+                                                                                       "%s: line %d: suffix \"%s\" in \"replica\" line is not valid for backend (ignored)\n",
+                                                                                       fname, lineno, cargv[i] + 7 );
+                                                               }
+                                                       } else {
+                                                               Debug( LDAP_DEBUG_ANY,
+                                                                                "%s: line %d: unable to normalize suffix in \"replica\" line (ignored)\n",
+                                                                                fname, lineno, 0 );
+                                                       }
+                                                       free( nsuffix );
+                                               }
+                                       }
                                }
                        }
 
index 64c8018925c1464f3138c3a91a4769572c8c9920..54f98354d3ff7da645b39c6a75b0a9e421c9efe7 100644 (file)
@@ -470,7 +470,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 443fe81d932f6565172d24fcdadc6970ff4cd245..f0d213bcb0f1e2f4f427045c1d392def221a02dd 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 b5d26bb1ad16a60201e885e03cca07f857f05e10..5a2c43483a1c79e6a7d4cf080e7ec9ea69d17c8f 100644 (file)
@@ -807,6 +807,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
@@ -906,7 +911,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 3f18906061f7017ffb6cf2b5d7b6d92e6dba6e4e..cf27352b754cf81f5c434d97c1e93427a3c4ab98 100644 (file)
@@ -168,3 +168,8 @@ void slap_mods_free( Modifications *ml )
 {
        assert(0);
 }
+
+int add_replica_info( Backend *be, const char *host )
+{
+       assert(0);
+}