- LDAP_SYNCREPL defined in include/ldap.h

- add "updatedn" to the replication specification
- return referral to update to the slave server
This commit is contained in:
Jong Hyuk Choi 2003-05-01 23:39:29 +00:00
parent 759996c6e9
commit e8cd5c2386
11 changed files with 126 additions and 36 deletions

View File

@ -200,6 +200,7 @@ typedef struct ldapcontrol {
#ifdef LDAP_DEVEL #ifdef LDAP_DEVEL
#define LDAP_CLIENT_UPDATE 1 #define LDAP_CLIENT_UPDATE 1
#define LDAP_SYNC 2 #define LDAP_SYNC 2
#define LDAP_SYNCREPL 1
#endif #endif
#ifdef LDAP_CLIENT_UPDATE #ifdef LDAP_CLIENT_UPDATE

View File

@ -18,9 +18,9 @@ SRCS = main.c globals.c config.c daemon.c \
repl.c lock.c controls.c extended.c kerberos.c passwd.c \ repl.c lock.c controls.c extended.c kerberos.c passwd.c \
schema.c schema_check.c schema_init.c schema_prep.c \ schema.c schema_check.c schema_init.c schema_prep.c \
schemaparse.c ad.c at.c mr.c syntax.c oc.c saslauthz.c \ schemaparse.c ad.c at.c mr.c syntax.c oc.c saslauthz.c \
oidm.c starttls.c index.c sets.c referral.c \ oidm.c starttls.c index.c sets.c referral.c root_dse.c \
root_dse.c sasl.c module.c mra.c mods.c sl_malloc.c \ sasl.c module.c mra.c mods.c sl_malloc.c limits.c \
limits.c backglue.c operational.c matchedValues.c cancel.c \ backglue.c operational.c matchedValues.c cancel.c syncrepl.c \
$(@PLAT@_SRCS) $(@PLAT@_SRCS)
OBJS = main.o globals.o config.o daemon.o \ OBJS = main.o globals.o config.o daemon.o \
@ -32,9 +32,9 @@ OBJS = main.o globals.o config.o daemon.o \
repl.o lock.o controls.o extended.o kerberos.o passwd.o \ repl.o lock.o controls.o extended.o kerberos.o passwd.o \
schema.o schema_check.o schema_init.o schema_prep.o \ schema.o schema_check.o schema_init.o schema_prep.o \
schemaparse.o ad.o at.o mr.o syntax.o oc.o saslauthz.o \ schemaparse.o ad.o at.o mr.o syntax.o oc.o saslauthz.o \
oidm.o starttls.o index.o sets.o referral.o \ oidm.o starttls.o index.o sets.o referral.o root_dse.o \
root_dse.o sasl.o module.o mra.o mods.o sl_malloc.o \ sasl.o module.o mra.o mods.o sl_malloc.o limits.o \
limits.o backglue.o operational.o matchedValues.o cancel.o \ backglue.o operational.o matchedValues.o cancel.o syncrepl.o \
$(@PLAT@_OBJS) $(@PLAT@_OBJS)
LDAP_INCDIR= ../../include -I$(srcdir)/slapi LDAP_INCDIR= ../../include -I$(srcdir)/slapi

View File

@ -243,7 +243,12 @@ do_add( Operation *op, SlapReply *rs )
if ( op->o_bd->be_add ) { if ( op->o_bd->be_add ) {
/* do the update here */ /* do the update here */
int repl_user = be_isupdate(op->o_bd, &op->o_ndn ); int repl_user = be_isupdate(op->o_bd, &op->o_ndn );
#ifndef SLAPD_MULTIMASTER #if defined(LDAP_SYNCREPL) && !defined(SLAPD_MULTIMASTER)
if ( !op->o_bd->syncinfo &&
( !op->o_bd->be_update_ndn.bv_len || repl_user ))
#elif defined(LDAP_SYNCREPL) && defined(SLAPD_MULTIMASTER)
if ( !op->o_bd->syncinfo ) /* LDAP_SYNCREPL overrides MM */
#elif !defined(LDAP_SYNCREPL) && !defined(SLAPD_MULTIMASTER)
if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) if ( !op->o_bd->be_update_ndn.bv_len || repl_user )
#endif #endif
{ {
@ -252,7 +257,7 @@ do_add( Operation *op, SlapReply *rs )
size_t textlen = sizeof textbuf; size_t textlen = sizeof textbuf;
rs->sr_err = slap_mods_check( modlist, update, &rs->sr_text, rs->sr_err = slap_mods_check( modlist, update, &rs->sr_text,
textbuf, textlen, NULL ); textbuf, textlen, NULL );
if( rs->sr_err != LDAP_SUCCESS ) { if( rs->sr_err != LDAP_SUCCESS ) {
send_ldap_result( op, rs ); send_ldap_result( op, rs );
@ -306,9 +311,9 @@ do_add( Operation *op, SlapReply *rs )
e = NULL; e = NULL;
} }
#ifndef SLAPD_MULTIMASTER #if defined(LDAP_SYNCREPL) || !defined(SLAPD_MULTIMASTER)
} else { } else {
BerVarray defref; BerVarray defref = NULL;
#ifdef LDAP_SLAPI #ifdef LDAP_SLAPI
/* /*
* SLAPI_ADD_ENTRY will be empty, but this may be acceptable * SLAPI_ADD_ENTRY will be empty, but this may be acceptable
@ -321,8 +326,16 @@ do_add( Operation *op, SlapReply *rs )
} }
#endif /* LDAP_SLAPI */ #endif /* LDAP_SLAPI */
defref = op->o_bd->be_update_refs #ifdef LDAP_SYNCREPL
? op->o_bd->be_update_refs : default_referral; if ( op->o_bd->syncinfo ) {
defref = op->o_bd->syncinfo->master_bv;
} else
#endif
{
defref = op->o_bd->be_update_refs
? op->o_bd->be_update_refs : default_referral;
}
if ( defref != NULL ) { if ( defref != NULL ) {
rs->sr_ref = referral_rewrite( defref, rs->sr_ref = referral_rewrite( defref,
NULL, &e->e_name, LDAP_SCOPE_DEFAULT ); NULL, &e->e_name, LDAP_SCOPE_DEFAULT );

View File

@ -14,6 +14,10 @@
LDAP_BEGIN_DECL LDAP_BEGIN_DECL
#ifdef LDAP_SYNCREPL
#define BDB_SUBENTRIES 1
#endif
#define DN_BASE_PREFIX SLAP_INDEX_EQUALITY_PREFIX #define DN_BASE_PREFIX SLAP_INDEX_EQUALITY_PREFIX
#define DN_ONE_PREFIX '%' #define DN_ONE_PREFIX '%'
#define DN_SUBTREE_PREFIX '@' #define DN_SUBTREE_PREFIX '@'

View File

@ -2727,8 +2727,9 @@ add_syncrepl(
#define GOT_TYPE 0x0200 #define GOT_TYPE 0x0200
#define GOT_INTERVAL 0x0400 #define GOT_INTERVAL 0x0400
#define GOT_LASTMOD 0x0800 #define GOT_LASTMOD 0x0800
#define GOT_UPDATEDN 0x1000
#define GOT_ALL 0x0FFF #define GOT_ALL 0x1FFF
static int static int
parse_syncrepl_line( parse_syncrepl_line(
@ -2772,6 +2773,11 @@ parse_syncrepl_line(
si->masterport = 0; si->masterport = 0;
} }
si->mastername = strdup( val ); si->mastername = strdup( val );
si->master_bv = (BerVarray) ch_calloc( 2, sizeof (struct berval ));
ber_str2bv( si->masteruri, strlen(si->masteruri), 0,
&si->master_bv[0] );
si->master_bv[1].bv_len = 0;
si->master_bv[1].bv_val = NULL;
gots |= GOT_HOST; gots |= GOT_HOST;
} else if ( !strncasecmp( cargv[ i ], TLSSTR, sizeof( TLSSTR ) - 1 ) ) { } else if ( !strncasecmp( cargv[ i ], TLSSTR, sizeof( TLSSTR ) - 1 ) ) {
val = cargv[ i ] + sizeof( TLSSTR ); val = cargv[ i ] + sizeof( TLSSTR );
@ -2781,7 +2787,18 @@ parse_syncrepl_line(
si->tls = TLS_ON; si->tls = TLS_ON;
} }
} else if ( !strncasecmp( cargv[ i ], } else if ( !strncasecmp( cargv[ i ],
"binddn", sizeof( BINDDNSTR ) - 1 ) ) { UPDATEDNSTR, sizeof( UPDATEDNSTR ) - 1 ) ) {
char *str;
struct berval updatedn = {0, NULL};
val = cargv[ i ] + sizeof( UPDATEDNSTR );
str = strdup( val );
ber_str2bv( str, strlen(str), 1, &updatedn );
dnNormalize( 0, NULL, NULL, &updatedn, &si->updatedn, NULL );
ch_free( str );
ch_free( updatedn.bv_val );
gots |= GOT_UPDATEDN;
} else if ( !strncasecmp( cargv[ i ],
BINDDNSTR, sizeof( BINDDNSTR ) - 1 ) ) {
val = cargv[ i ] + sizeof( BINDDNSTR ); val = cargv[ i ] + sizeof( BINDDNSTR );
si->binddn = strdup( val ); si->binddn = strdup( val );
gots |= GOT_DN; gots |= GOT_DN;
@ -2934,6 +2951,7 @@ parse_syncrepl_line(
} else if ( !strncasecmp( val, "refreshAndPersist", sizeof( "refreshAndPersist" ) - 1 )) { } else if ( !strncasecmp( val, "refreshAndPersist", sizeof( "refreshAndPersist" ) - 1 )) {
gots |= GOT_INTERVAL; gots |= GOT_INTERVAL;
si->type = LDAP_SYNC_REFRESH_AND_PERSIST; si->type = LDAP_SYNC_REFRESH_AND_PERSIST;
si->interval = 0;
} else { } else {
fprintf( stderr, "Error: parse_syncrepl_line: " fprintf( stderr, "Error: parse_syncrepl_line: "
"unknown sync type \"%s\"\n", val); "unknown sync type \"%s\"\n", val);
@ -2943,8 +2961,11 @@ parse_syncrepl_line(
INTERVALSTR, sizeof( INTERVALSTR ) - 1 ) ) { INTERVALSTR, sizeof( INTERVALSTR ) - 1 ) ) {
val = cargv[ i ] + sizeof( INTERVALSTR ); val = cargv[ i ] + sizeof( INTERVALSTR );
gots |= GOT_INTERVAL; gots |= GOT_INTERVAL;
si->interval = atoi( val ); if ( gots & GOT_TYPE && si->type == LDAP_SYNC_REFRESH_AND_PERSIST )
if ( si->interval <= 0 ) { si->interval = 0;
else
si->interval = atoi( val );
if ( si->interval < 0 ) {
fprintf( stderr, "Error: parse_syncrepl_line: " fprintf( stderr, "Error: parse_syncrepl_line: "
"invalid interval \"%d\"\n", si->interval); "invalid interval \"%d\"\n", si->interval);
return 1; return 1;

View File

@ -190,7 +190,11 @@ do_delete(
if ( op->o_bd->be_delete ) { if ( op->o_bd->be_delete ) {
/* do the update here */ /* do the update here */
int repl_user = be_isupdate( op->o_bd, &op->o_ndn ); int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
#ifndef SLAPD_MULTIMASTER #if defined(LDAP_SYNCREPL) && !defined(SLAPD_MULTIMASTER)
if ( !op->o_bd->syncinfo && ( !op->o_bd->be_update_ndn.bv_len || repl_user ))
#elif defined(LDAP_SYNCREPL) && defined(SLAPD_MULTIMASTER)
if ( !op->o_bd->syncinfo ) /* LDAP_SYNCREPL overrides MM */
#elif !defined(LDAP_SYNCREPL) && !defined(SLAPD_MULTIMASTER)
if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) if ( !op->o_bd->be_update_ndn.bv_len || repl_user )
#endif #endif
{ {
@ -202,12 +206,20 @@ do_delete(
replog( op ); replog( op );
} }
} }
#ifndef SLAPD_MULTIMASTER #if defined(LDAP_SYNCREPL) || !defined(SLAPD_MULTIMASTER)
} else { } else {
BerVarray defref = op->o_bd->be_update_refs BerVarray defref = NULL;
? op->o_bd->be_update_refs : default_referral; #ifdef LDAP_SYNCREPL
if ( op->o_bd->syncinfo ) {
defref = op->o_bd->syncinfo->master_bv;
} else
#endif
{
defref = op->o_bd->be_update_refs
? op->o_bd->be_update_refs : default_referral;
}
if ( defref != NULL ) { if ( defref != NULL ) {
rs->sr_ref = referral_rewrite( default_referral, rs->sr_ref = referral_rewrite( defref,
NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT ); NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
if (!rs->sr_ref) rs->sr_ref = defref; if (!rs->sr_ref) rs->sr_ref = defref;
rs->sr_err = LDAP_REFERRAL; rs->sr_err = LDAP_REFERRAL;

View File

@ -391,10 +391,16 @@ do_modify(
if ( op->o_bd->be_modify ) { if ( op->o_bd->be_modify ) {
/* do the update here */ /* do the update here */
int repl_user = be_isupdate( op->o_bd, &op->o_ndn ); int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
#ifndef SLAPD_MULTIMASTER
/* Multimaster slapd does not have to check for replicator dn /* Multimaster slapd does not have to check for replicator dn
* because it accepts each modify request * because it accepts each modify request
*/ */
#if defined(LDAP_SYNCREPL) && !defined(SLAPD_MULTIMASTER)
if ( !op->o_bd->syncinfo &&
( !op->o_bd->be_update_ndn.bv_len || repl_user ))
#elif defined(LDAP_SYNCREPL) && defined(SLAPD_MULTIMASTER)
if ( !op->o_bd->syncinfo ) /* LDAP_SYNCREPL overrides MM */
#elif !defined(LDAP_SYNCREPL) && !defined(SLAPD_MULTIMASTER)
if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) if ( !op->o_bd->be_update_ndn.bv_len || repl_user )
#endif #endif
{ {
@ -436,11 +442,19 @@ do_modify(
replog( op ); replog( op );
} }
#ifndef SLAPD_MULTIMASTER #if defined(LDAP_SYNCREPL) || !defined(SLAPD_MULTIMASTER)
/* send a referral */ /* send a referral */
} else { } else {
BerVarray defref = op->o_bd->be_update_refs BerVarray defref = NULL;
? op->o_bd->be_update_refs : default_referral; #ifdef LDAP_SYNCREPL
if ( op->o_bd->syncinfo ) {
defref = op->o_bd->syncinfo->master_bv;
} else
#endif
{
defref = op->o_bd->be_update_refs
? op->o_bd->be_update_refs : default_referral;
}
if ( defref != NULL ) { if ( defref != NULL ) {
rs->sr_ref = referral_rewrite( defref, rs->sr_ref = referral_rewrite( defref,
NULL, &op->o_req_dn, NULL, &op->o_req_dn,

View File

@ -353,7 +353,12 @@ do_modrdn(
if ( op->o_bd->be_modrdn ) { if ( op->o_bd->be_modrdn ) {
/* do the update here */ /* do the update here */
int repl_user = be_isupdate( op->o_bd, &op->o_ndn ); int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
#ifndef SLAPD_MULTIMASTER #if defined(LDAP_SYNCREPL) && !defined(SLAPD_MULTIMASTER)
if ( !op->o_bd->syncinfo &&
( !op->o_bd->be_update_ndn.bv_len || repl_user ))
#elif defined(LDAP_SYNCREPL) && defined(SLAPD_MULTIMASTER)
if ( !op->o_bd->syncinfo ) /* LDAP_SYNCREPL overrides MM */
#elif !defined(LDAP_SYNCREPL) && !defined(SLAPD_MULTIMASTER)
if ( !op->o_bd->be_update_ndn.bv_len || repl_user ) if ( !op->o_bd->be_update_ndn.bv_len || repl_user )
#endif #endif
{ {
@ -365,10 +370,18 @@ do_modrdn(
) { ) {
replog( op ); replog( op );
} }
#ifndef SLAPD_MULTIMASTER #if defined(LDAP_SYNCREPL) || !defined(SLAPD_MULTIMASTER)
} else { } else {
BerVarray defref = op->o_bd->be_update_refs BerVarray defref = NULL;
? op->o_bd->be_update_refs : default_referral; #ifdef LDAP_SYNCREPL
if ( op->o_bd->syncinfo ) {
defref = op->o_bd->syncinfo->master_bv;
} else
#endif
{
defref = op->o_bd->be_update_refs
? op->o_bd->be_update_refs : default_referral;
}
if ( defref != NULL ) { if ( defref != NULL ) {
rs->sr_ref = referral_rewrite( defref, rs->sr_ref = referral_rewrite( defref,
NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT ); NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );

View File

@ -52,13 +52,22 @@ int passwd_extop(
rs->sr_err = LDAP_OTHER; rs->sr_err = LDAP_OTHER;
#endif #endif
#ifndef SLAPD_MULTIMASTER #if defined(LDAP_SYNCREPL) || !defined(SLAPD_MULTIMASTER)
/* This does not apply to multi-master case */ /* This does not apply to multi-master case */
} else if( op->o_bd->be_update_ndn.bv_len ) { } else if( op->o_bd->be_update_ndn.bv_len ) {
/* we SHOULD return a referral in this case */ /* we SHOULD return a referral in this case */
rs->sr_ref = referral_rewrite( op->o_bd->be_update_refs, BerVarray defref = NULL;
NULL, NULL, LDAP_SCOPE_DEFAULT ); #ifdef LDAP_SYNCREPL
rs->sr_err = LDAP_REFERRAL; if ( op->o_bd->syncinfo ) {
defref = op->o_bd->syncinfo->master_bv;
} else
#endif
{
defref = referral_rewrite( op->o_bd->be_update_refs,
NULL, NULL, LDAP_SCOPE_DEFAULT );
}
rs->sr_ref = defref;
rs->sr_err = LDAP_REFERRAL;
#endif /* !SLAPD_MULTIMASTER */ #endif /* !SLAPD_MULTIMASTER */
} else { } else {

View File

@ -1286,9 +1286,11 @@ typedef struct syncinfo_s {
void *ctx; void *ctx;
int id; int id;
char *masteruri; char *masteruri;
struct berval *master_bv;
char *mastername; char *mastername;
int masterport; int masterport;
int type; int type;
struct berval updatedn;
char *binddn; char *binddn;
int bindmethod; int bindmethod;
char *passwd; char *passwd;
@ -1298,7 +1300,7 @@ typedef struct syncinfo_s {
char *authzId; char *authzId;
char *srvtab; char *srvtab;
char *saslmech; char *saslmech;
int interval; time_t interval;
char *base; char *base;
int scope; int scope;
int deref; int deref;
@ -1327,6 +1329,7 @@ typedef struct syncinfo_s {
#define IDSTR "id" #define IDSTR "id"
#define MASTERSTR "master" #define MASTERSTR "master"
#define SUFFIXSTR "suffix" #define SUFFIXSTR "suffix"
#define UPDATEDNSTR "updatedn"
#define BINDDNSTR "binddn" #define BINDDNSTR "binddn"
#define BINDMETHSTR "bindmethod" #define BINDMETHSTR "bindmethod"
#define SIMPLESTR "simple" #define SIMPLESTR "simple"

View File

@ -320,8 +320,8 @@ do_syncrepl(
op.o_tmpmemctx = NULL; /* FIXME : to use per-thread mem context */ op.o_tmpmemctx = NULL; /* FIXME : to use per-thread mem context */
op.o_tag = LDAP_REQ_SEARCH; op.o_tag = LDAP_REQ_SEARCH;
op.o_dn = be->be_rootdn; op.o_dn = si->updatedn;
op.o_ndn = be->be_rootndn; op.o_ndn = si->updatedn;
op.o_callback = &cb; op.o_callback = &cb;
op.o_time = slap_get_time(); op.o_time = slap_get_time();
op.o_managedsait = 1; op.o_managedsait = 1;