From: Kurt Zeilenga Date: Mon, 6 Oct 2003 16:57:28 +0000 (+0000) Subject: Merge in latest changes from HEAD X-Git-Tag: OPENLDAP_REL_ENG_2_2_2BETA~3 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=5766ca91e0e8e484e6bf824b47865dd7b541c422;p=openldap Merge in latest changes from HEAD --- diff --git a/build/top.mk b/build/top.mk index bcfb0d6088..5495b79b00 100644 --- a/build/top.mk +++ b/build/top.mk @@ -148,8 +148,11 @@ LDAP_LIBLBER_LA = $(LDAP_LIBDIR)/liblber/liblber.la LDAP_LIBLDAP_LA = $(LDAP_LIBDIR)/libldap/libldap.la LDAP_LIBLDAP_R_LA = $(LDAP_LIBDIR)/libldap_r/libldap_r.la +LDAP_LIBLDBM_A_no = +LDAP_LIBLDBM_A_yes = $(LDAP_LIBDIR)/libldbm/libldbm.a + LDAP_LIBAVL_A = $(LDAP_LIBDIR)/libavl/libavl.a -LDAP_LIBLDBM_A = $(LDAP_LIBDIR)/libldbm/libldbm.a +LDAP_LIBLDBM_A = $(LDAP_LIBLDBM_A_@BUILD_LDBM@) LDAP_LIBLDIF_A = $(LDAP_LIBDIR)/libldif/libldif.a LDAP_LIBREWRITE_A = $(LDAP_LIBDIR)/librewrite/librewrite.a LDAP_LIBLUNICODE_A = $(LDAP_LIBDIR)/liblunicode/liblunicode.a diff --git a/clients/tools/ldapsearch.c b/clients/tools/ldapsearch.c index 31be49d5f0..047f055cf5 100644 --- a/clients/tools/ldapsearch.c +++ b/clients/tools/ldapsearch.c @@ -995,7 +995,7 @@ done: return( rc ); } -#if 1 +#ifdef OLD_WAY /* This is the original version, the old way of doing things. */ static void print_entry( @@ -1161,10 +1161,10 @@ print_entry( { if (bv.bv_val == NULL) break; - if ( attrsonly || !bvals ) { + if ( attrsonly ) { write_ldif( LDIF_PUT_NOVALUE, bv.bv_val, NULL, 0 ); - } else { + } else if ( bvals ) { for ( i = 0; bvals[i].bv_val != NULL; i++ ) { if ( vals2tmp > 1 || ( vals2tmp && ldif_is_not_printable( bvals[i].bv_val, bvals[i].bv_len ) )) diff --git a/doc/man/man5/slapd-bdb.5 b/doc/man/man5/slapd-bdb.5 index 99f8afede3..caed18a197 100644 --- a/doc/man/man5/slapd-bdb.5 +++ b/doc/man/man5/slapd-bdb.5 @@ -70,6 +70,11 @@ results if the data comes from a transaction that is later aborted. In this case, the modified data is discarded and a subsequent search will return a different result. .TP +.B idlcachesize +Specify the size of the in-memory index cache, in index slots. The +default is zero. A larger value will speed up frequent searches of +indexed entries. +.TP .B index {|default} [pres,eq,approx,sub,] Specify the indexes to maintain for the given attribute (or @@ -119,6 +124,12 @@ allocations can have a major negative impact on server performance, but specifying too much stack will also consume a great deal of memory. Each search stack uses 512K bytes per level. The default stack depth is 16, thus 8MB per thread is used. +.TP +.B shm_key +Specify a key for a shared memory BDB environment. By default the +BDB environment uses memory mapped files. If a non-zero value is +specified, it will be used as the key to identify a shared memory +region that will house the environment. .SH FILES .TP ETCDIR/slapd.conf diff --git a/include/lber.h b/include/lber.h index 728f575090..77a32fa891 100644 --- a/include/lber.h +++ b/include/lber.h @@ -25,6 +25,7 @@ #define _LBER_H #include +#include LDAP_BEGIN_DECL diff --git a/include/ldbm.h b/include/ldbm.h index 9c92ac6e96..5a86a5fa70 100644 --- a/include/ldbm.h +++ b/include/ldbm.h @@ -15,6 +15,7 @@ #define _LDBM_H_ #include +#include /* dummy DB_ENV for non Berkeley DB */ #if !defined( LDBM_USE_DBBTREE ) && !defined( LDBM_USE_DBHASH ) diff --git a/include/slapi-plugin.h b/include/slapi-plugin.h index 3f763428b2..fc6ac13ad2 100644 --- a/include/slapi-plugin.h +++ b/include/slapi-plugin.h @@ -49,6 +49,9 @@ int slapi_attr_get_values( Slapi_Attr *attr, struct berval ***vals ); char *slapi_dn_normalize( char *dn ); char *slapi_dn_normalize_case( char *dn ); int slapi_dn_issuffix( char *dn, char *suffix ); +char *slapi_dn_beparent( Slapi_PBlock *pb, const char *dn ); +char *slapi_dn_parent( const char *dn ); +int slapi_dn_isparent( const char *parentdn, const char *childdn ); char *slapi_dn_ignore_case( char *dn ); /* DS 5.x SLAPI */ @@ -181,6 +184,8 @@ void slapi_send_ldap_result( Slapi_PBlock *pb, int err, char *matched, char *text, int nentries, struct berval **urls ); int slapi_send_ldap_search_entry( Slapi_PBlock *pb, Slapi_Entry *e, LDAPControl **ectrls, char **attrs, int attrsonly ); +int slapi_send_ldap_search_reference( Slapi_PBlock *pb, Slapi_Entry *e, + struct berval **urls, LDAPControl **ectrls, struct berval **v2refs ); /* filter routines */ Slapi_Filter *slapi_str2filter( char *str ); diff --git a/libraries/liblber/Makefile.in b/libraries/liblber/Makefile.in index 440c370953..feae38b363 100644 --- a/libraries/liblber/Makefile.in +++ b/libraries/liblber/Makefile.in @@ -40,5 +40,5 @@ idtest: $(XLIBS) idtest.o install-local: FORCE -$(MKDIR) $(DESTDIR)$(libdir) $(LTINSTALL) $(INSTALLFLAGS) -m 644 $(LIBRARY) $(DESTDIR)$(libdir) - $(LTFINISH) $(DESTDIR)$libdir + $(LTFINISH) $(DESTDIR)$(libdir) diff --git a/libraries/libldap/cyrus.c b/libraries/libldap/cyrus.c index d687c4cec6..1816d8d7c3 100644 --- a/libraries/libldap/cyrus.c +++ b/libraries/libldap/cyrus.c @@ -14,6 +14,7 @@ #include #include #include +#include #include "ldap-int.h" diff --git a/libraries/libldap/sasl.c b/libraries/libldap/sasl.c index 1509ccd3b1..bd59ff58b2 100644 --- a/libraries/libldap/sasl.c +++ b/libraries/libldap/sasl.c @@ -433,6 +433,7 @@ ldap_sasl_interactive_bind_s( void *defaults ) { int rc; + char *smechs = NULL; #if defined( LDAP_R_COMPILE ) && defined( HAVE_CYRUS_SASL ) ldap_pvt_thread_mutex_lock( &ldap_int_sasl_mutex ); @@ -448,9 +449,14 @@ ldap_sasl_interactive_bind_s( goto done; } else #endif - if( mechs == NULL || *mechs == '\0' ) { - char *smechs; +#ifdef HAVE_CYRUS_SASL + if( mechs == NULL || *mechs == '\0' ) { + mechs = ld->ld_options.ldo_def_sasl_mech; + } +#endif + + if( mechs == NULL || *mechs == '\0' ) { rc = ldap_pvt_sasl_getmechs( ld, &smechs ); if( rc != LDAP_SUCCESS ) { goto done; @@ -488,6 +494,7 @@ done: #if defined( LDAP_R_COMPILE ) && defined( HAVE_CYRUS_SASL ) ldap_pvt_thread_mutex_unlock( &ldap_int_sasl_mutex ); #endif + if ( smechs ) LDAP_FREE( smechs ); return rc; } diff --git a/libraries/libldap_r/rq.c b/libraries/libldap_r/rq.c index 29153ccc72..88851efeb7 100644 --- a/libraries/libldap_r/rq.c +++ b/libraries/libldap_r/rq.c @@ -9,9 +9,10 @@ #include #include +#include +#include #include #include -#include #include "ldap-int.h" #include "ldap_pvt_thread.h" diff --git a/servers/slapd/Makefile.in b/servers/slapd/Makefile.in index c571c12f04..b5b76a2ef1 100644 --- a/servers/slapd/Makefile.in +++ b/servers/slapd/Makefile.in @@ -47,12 +47,14 @@ SLAPD_STATIC_DEPENDS=@SLAPD_NO_STATIC@ libbackends.a SLAPD_STATIC_BACKENDS=@SLAPD_STATIC_BACKENDS@ SLAPD_DYNAMIC_BACKENDS=@SLAPD_DYNAMIC_BACKENDS@ +SLAPI_LIBS=@LIBSLAPI@ @SLAPI_LIBS@ + XDEFS = $(MODULES_CPPFLAGS) XLDFLAGS = $(MODULES_LDFLAGS) XLIBS = $(SLAPD_STATIC_DEPENDS) $(SLAPD_L) XXLIBS = $(LDBM_LIBS) $(SLAPD_LIBS) $(SECURITY_LIBS) $(LDIF_LIBS) $(LUTIL_LIBS) -XXXLIBS = $(LTHREAD_LIBS) $(SLAPI_LIBS) @LIBSLAPI@ $(MODULES_LIBS) +XXXLIBS = $(LTHREAD_LIBS) $(SLAPI_LIBS) $(MODULES_LIBS) BUILD_OPT = "--enable-slapd" BUILD_SRV = @BUILD_SLAPD@ @@ -228,13 +230,11 @@ slapd.exp: libslapd.a dlltool --dllname slapd.exe --input-def slapd.def \ --base-file slapd.base --output-exp $@ -libslapi.a: .slapi +slapi/.libs/libslapi.a: FORCE (cd slapi; $(MAKE) $(MFLAGS) all) - cp slapi/.libs/libslapi.a . -.slapi: FORCE - $(AR) ruv slapi/libtmpslapd.a $(OBJS) - (cd slapi; $(MAKE) $(MFLAGS) all) +libslapi.a: slapi/.libs/libslapi.a + cp slapi/.libs/libslapi.a . slapd: $(SLAPD_DEPENDS) @LIBSLAPI@ $(LTLINK) -o $@ $(SLAPD_OBJECTS) $(LIBS) \ diff --git a/servers/slapd/back-bdb/add.c b/servers/slapd/back-bdb/add.c index 6260b8164e..551a8813c1 100644 --- a/servers/slapd/back-bdb/add.c +++ b/servers/slapd/back-bdb/add.c @@ -37,7 +37,7 @@ bdb_add(Operation *op, SlapReply *rs ) Operation* ps_list; int rc; - EntryInfo *suffix_ei; + EntryInfo *suffix_ei = NULL; Entry *ctxcsn_e; int ctxcsn_added = 0; @@ -102,8 +102,8 @@ retry: /* transaction retry */ rs->sr_text = "internal error"; goto return_results; } - bdb_trans_backoff( ++num_retries ); ldap_pvt_thread_yield(); + bdb_trans_backoff( ++num_retries ); } /* begin transaction */ @@ -506,6 +506,7 @@ retry: /* transaction retry */ } else { char gid[DB_XIDDATASIZE]; + memset( gid, 0, sizeof(gid) ); snprintf( gid, sizeof( gid ), "%s-%08lx-%08lx", bdb_uuid.bv_val, (long) op->o_connid, (long) op->o_opid ); diff --git a/servers/slapd/back-bdb/back-bdb.h b/servers/slapd/back-bdb/back-bdb.h index b5dc2fe033..1a249f41e6 100644 --- a/servers/slapd/back-bdb/back-bdb.h +++ b/servers/slapd/back-bdb/back-bdb.h @@ -87,6 +87,7 @@ typedef struct bdb_entry_info { #define CACHE_ENTRY_DELETED 1 #define CACHE_ENTRY_NO_KIDS 2 #define CACHE_ENTRY_NOT_LINKED 4 +#define CACHE_ENTRY_NO_GRANDKIDS 8 /* * remaining fields require backend cache lock to access @@ -113,6 +114,7 @@ typedef struct bdb_cache { int c_maxsize; int c_cursize; EntryInfo c_dntree; + EntryInfo *c_eifree; /* free list */ Avlnode *c_idtree; EntryInfo *c_lruhead; /* lru - add accessed entries here */ EntryInfo *c_lrutail; /* lru - rem lru entries from here */ @@ -141,6 +143,7 @@ struct bdb_info { int bi_ndatabases; struct bdb_db_info **bi_databases; + ldap_pvt_thread_mutex_t bi_database_mutex; int bi_db_opflags; /* db-specific flags */ slap_mask_t bi_defaultmask; @@ -182,7 +185,7 @@ struct bdb_op_info { int boi_acl_cache; }; -#define DB_OPEN(db, txn, file, name, type, flags, mode) \ +#define DB_OPEN(db, file, name, type, flags, mode) \ (db)->open(db, file, name, type, flags, mode) #if DB_VERSION_MAJOR < 4 @@ -213,8 +216,8 @@ struct bdb_op_info { /* BDB 4.1.17 adds txn arg to db->open */ #if DB_VERSION_MINOR > 1 || DB_VERSION_PATCH >= 17 #undef DB_OPEN -#define DB_OPEN(db, txn, file, name, type, flags, mode) \ - (db)->open(db, txn, file, name, type, flags, mode) +#define DB_OPEN(db, file, name, type, flags, mode) \ + (db)->open(db, NULL, file, name, type, (flags)|DB_AUTO_COMMIT, mode) #endif #endif diff --git a/servers/slapd/back-bdb/cache.c b/servers/slapd/back-bdb/cache.c index 02db20c8c5..f18e21ce20 100644 --- a/servers/slapd/back-bdb/cache.c +++ b/servers/slapd/back-bdb/cache.c @@ -23,12 +23,25 @@ static void bdb_lru_print(Cache *cache); #endif static EntryInfo * -bdb_cache_entryinfo_new( ) +bdb_cache_entryinfo_new( Cache *cache ) { - EntryInfo *ei; + EntryInfo *ei = NULL; - ei = ch_calloc(1, sizeof(struct bdb_entry_info)); - ldap_pvt_thread_mutex_init( &ei->bei_kids_mutex ); + if ( cache->c_eifree ) { + ldap_pvt_thread_rdwr_wlock( &cache->c_rwlock ); + if ( cache->c_eifree ) { + ei = cache->c_eifree; + cache->c_eifree = ei->bei_lrunext; + } + ldap_pvt_thread_rdwr_wunlock( &cache->c_rwlock ); + } + if ( ei ) { + ei->bei_lrunext = NULL; + ei->bei_state = 0; + } else { + ei = ch_calloc(1, sizeof(struct bdb_entry_info)); + ldap_pvt_thread_mutex_init( &ei->bei_kids_mutex ); + } return ei; } @@ -200,7 +213,7 @@ bdb_entryinfo_add_internal( *res = NULL; - ei2 = bdb_cache_entryinfo_new(); + ei2 = bdb_cache_entryinfo_new( &bdb->bi_cache ); ldap_pvt_thread_rdwr_wlock( &bdb->bi_cache.c_rwlock ); bdb_cache_entryinfo_lock( ei->bei_parent ); @@ -356,7 +369,7 @@ hdb_cache_find_parent( ei2 = ein; /* Create a new node for the current ID */ - ein = bdb_cache_entryinfo_new(); + ein = bdb_cache_entryinfo_new( &bdb->bi_cache ); ein->bei_id = ei.bei_id; ein->bei_kids = ei.bei_kids; ein->bei_nrdn = ei.bei_nrdn; @@ -518,6 +531,23 @@ bdb_cache_lru_add( ldap_pvt_thread_mutex_unlock( &bdb->bi_cache.lru_mutex ); } +EntryInfo * +bdb_cache_find_info( + struct bdb_info *bdb, + ID id +) +{ + EntryInfo ei, *ei2; + + ei.bei_id = id; + + ldap_pvt_thread_rdwr_rlock( &bdb->bi_cache.c_rwlock ); + ei2 = (EntryInfo *) avl_find( bdb->bi_cache.c_idtree, + (caddr_t) &ei, bdb_id_cmp ); + ldap_pvt_thread_rdwr_runlock( &bdb->bi_cache.c_rwlock ); + return ei2; +} + /* * cache_find_id - find an entry in the cache, given id. * The entry is locked for Read upon return. Call with islocked TRUE if @@ -683,7 +713,7 @@ bdb_cache_children( } rc = bdb_dn2id_children( op, txn, e ); if ( rc == DB_NOTFOUND ) { - BEI(e)->bei_state |= CACHE_ENTRY_NO_KIDS; + BEI(e)->bei_state |= CACHE_ENTRY_NO_KIDS | CACHE_ENTRY_NO_GRANDKIDS; } return rc; } @@ -716,8 +746,9 @@ bdb_cache_add( rc = bdb_entryinfo_add_internal( bdb, &ei, &new ); new->bei_e = e; e->e_private = new; - new->bei_state = CACHE_ENTRY_NO_KIDS; + new->bei_state = CACHE_ENTRY_NO_KIDS | CACHE_ENTRY_NO_GRANDKIDS; eip->bei_state &= ~CACHE_ENTRY_NO_KIDS; + if (eip->bei_parent) eip->bei_parent->bei_state &= ~CACHE_ENTRY_NO_GRANDKIDS; /* set lru mutex */ ldap_pvt_thread_mutex_lock( &bdb->bi_cache.lru_mutex ); @@ -890,15 +921,36 @@ bdb_cache_delete( void bdb_cache_delete_cleanup( + Cache *cache, Entry *e ) { - bdb_cache_entryinfo_unlock( BEI(e) ); - bdb_cache_entryinfo_destroy( e->e_private ); + EntryInfo *ei = BEI(e); + + ei->bei_e = NULL; e->e_private = NULL; bdb_entry_return( e ); + + free( ei->bei_nrdn.bv_val ); + ei->bei_nrdn.bv_val = NULL; +#ifdef BDB_HIER + free( ei->bei_rdn.bv_val ); + ei->bei_rdn.bv_val = NULL; + ei->bei_modrdns = 0; + ei->bei_ckids = 0; + ei->bei_dkids = 0; +#endif + ei->bei_parent = NULL; + ei->bei_kids = NULL; + ei->bei_lruprev = NULL; + + ldap_pvt_thread_rdwr_wlock( &cache->c_rwlock ); + ei->bei_lrunext = cache->c_eifree; + cache->c_eifree = ei; + ldap_pvt_thread_rdwr_wunlock( &cache->c_rwlock ); + bdb_cache_entryinfo_unlock( ei ); } - + static int bdb_cache_delete_internal( Cache *cache, @@ -1078,3 +1130,24 @@ bdb_locker_id( Operation *op, DB_ENV *env, int *locker ) return 0; } #endif + +void +bdb_cache_delete_entry( + struct bdb_info *bdb, + EntryInfo *ei, + u_int32_t locker, + DB_LOCK *lock ) +{ + ldap_pvt_thread_rdwr_wlock( &bdb->bi_cache.c_rwlock ); + if ( bdb_cache_entry_db_lock( bdb->bi_dbenv, locker, ei, 1, 1, lock ) == 0 ) { + if ( ei->bei_e && !(ei->bei_state & CACHE_ENTRY_NOT_LINKED )) { + LRU_DELETE( &bdb->bi_cache, ei ); + ei->bei_e->e_private = NULL; + bdb_entry_return( ei->bei_e ); + ei->bei_e = NULL; + --bdb->bi_cache.c_cursize; + } + bdb_cache_entry_db_unlock( bdb->bi_dbenv, lock ); + } + ldap_pvt_thread_rdwr_wunlock( &bdb->bi_cache.c_rwlock ); +} diff --git a/servers/slapd/back-bdb/ctxcsn.c b/servers/slapd/back-bdb/ctxcsn.c index c6655c11f1..3f9dfc1f61 100644 --- a/servers/slapd/back-bdb/ctxcsn.c +++ b/servers/slapd/back-bdb/ctxcsn.c @@ -47,7 +47,7 @@ bdb_csn_commit( struct berval ctxcsn_ndn = { 0, NULL }; EntryInfo *ctxcsn_ei = NULL; DB_LOCK ctxcsn_lock; - struct berval *max_committed_csn = NULL; + struct berval max_committed_csn; DB_LOCK suffix_lock; int rc, ret; ID ctxcsn_id; @@ -61,16 +61,18 @@ bdb_csn_commit( } build_new_dn( &ctxcsn_ndn, &op->o_bd->be_nsuffix[0], - (struct berval *)&slap_ldapsync_cn_bv ); - - rc = bdb_dn2entry( op, tid, &ctxcsn_ndn, &ctxcsn_ei, - 1, locker, &ctxcsn_lock ); + (struct berval *)&slap_ldapsync_cn_bv, op->o_tmpmemctx ); + rc = bdb_dn2entry( op, tid, &ctxcsn_ndn, &ctxcsn_ei, + 1, locker, &ctxcsn_lock ); + *ctxcsn_e = ctxcsn_ei->bei_e; - max_committed_csn = slap_get_commit_csn( op ); + op->o_tmpfree( ctxcsn_ndn.bv_val, op->o_tmpmemctx ); + + slap_get_commit_csn( op, &max_committed_csn ); - if ( max_committed_csn == NULL ) { + if ( max_committed_csn.bv_val == NULL ) { return BDB_CSN_COMMIT; } @@ -81,13 +83,14 @@ bdb_csn_commit( if ( !*ctxcsn_e ) { rs->sr_err = LDAP_OTHER; rs->sr_text = "context csn not present"; - ber_bvfree( max_committed_csn ); + ch_free( max_committed_csn.bv_val ); return BDB_CSN_ABORT; } else { Modifications mod; struct berval modvals[2]; + Entry dummy; - modvals[0] = *max_committed_csn; + modvals[0] = max_committed_csn; modvals[1].bv_val = NULL; modvals[1].bv_len = 0; @@ -98,11 +101,10 @@ bdb_csn_commit( mod.sml_type = mod.sml_desc->ad_cname; mod.sml_next = NULL; - bdb_cache_entry_db_relock( bdb->bi_dbenv, locker, ctxcsn_ei, 1, 0, &ctxcsn_lock ); - - ret = bdb_modify_internal( op, tid, &mod, *ctxcsn_e, - &rs->sr_text, textbuf, textlen ); - ber_bvfree( max_committed_csn ); + dummy = **ctxcsn_e; + ret = bdb_modify_internal( op, tid, &mod, &dummy, + &rs->sr_text, textbuf, textlen ); + ch_free( max_committed_csn.bv_val ); if ( ret != LDAP_SUCCESS ) { #ifdef NEW_LOGGING LDAP_LOG ( OPERATION, ERR, @@ -120,7 +122,7 @@ bdb_csn_commit( } } - ret = bdb_id2entry_update( op->o_bd, tid, *ctxcsn_e ); + ret = bdb_id2entry_update( op->o_bd, tid, &dummy ); switch ( ret ) { case 0 : break; @@ -132,6 +134,7 @@ bdb_csn_commit( rs->sr_text = "context csn update failed"; return BDB_CSN_ABORT; } + bdb_cache_modify( *ctxcsn_e, dummy.e_attrs, bdb->bi_dbenv, locker, &ctxcsn_lock ); } break; case DB_NOTFOUND: @@ -159,8 +162,8 @@ bdb_csn_commit( return BDB_CSN_ABORT; } - *ctxcsn_e = slap_create_context_csn_entry( op->o_bd, max_committed_csn ); - ber_bvfree( max_committed_csn ); + *ctxcsn_e = slap_create_context_csn_entry( op->o_bd, &max_committed_csn ); + ch_free( max_committed_csn.bv_val ); (*ctxcsn_e)->e_id = ctxcsn_id; *ctxcsn_added = 1; @@ -266,9 +269,9 @@ bdb_get_commit_csn( struct berval bv; sprintf( substr, "cn=syncrepl%d", op->o_bd->syncinfo->id ); ber_str2bv( substr, 0, 0, &bv ); - build_new_dn( &ctxcsn_ndn, &op->o_bd->be_nsuffix[0], &bv ); + build_new_dn( &ctxcsn_ndn, &op->o_bd->be_nsuffix[0], &bv, NULL ); } else { - build_new_dn( &ctxcsn_ndn, &op->o_bd->be_nsuffix[0], (struct berval *)&slap_ldapsync_cn_bv ); + build_new_dn( &ctxcsn_ndn, &op->o_bd->be_nsuffix[0], (struct berval *)&slap_ldapsync_cn_bv, NULL ); } ctxcsn_retry : @@ -302,9 +305,8 @@ txn_retry: rs->sr_err = LDAP_OTHER; return rs->sr_err; } - - bdb_trans_backoff( ++num_retries ); ldap_pvt_thread_yield(); + bdb_trans_backoff( ++num_retries ); } rs->sr_err = TXN_BEGIN( bdb->bi_dbenv, NULL, <id, bdb->bi_db_opflags ); if ( rs->sr_err != 0 ) { diff --git a/servers/slapd/back-bdb/dbcache.c b/servers/slapd/back-bdb/dbcache.c index 7c99c19196..de55018803 100644 --- a/servers/slapd/back-bdb/dbcache.c +++ b/servers/slapd/back-bdb/dbcache.c @@ -46,19 +46,14 @@ bdb_db_hash( int bdb_db_cache( Backend *be, - DB_TXN *tid, const char *name, DB **dbout ) { int i; int rc; - int flags; struct bdb_info *bdb = (struct bdb_info *) be->be_private; struct bdb_db_info *db; char *file; - DBT lockobj; - DB_LOCK lock; - u_int32_t locker = 0; *dbout = NULL; @@ -69,33 +64,19 @@ bdb_db_cache( } } - lockobj.data = "bdb_db_cache"; - lockobj.size = sizeof("bdb_db_cache"); - - if (tid) { - locker = TXN_ID( tid ); - } else { -#ifdef BDB_REUSE_LOCKERS -#define op NULL /* implicit arg in LOCK_ID */ -#endif - rc = LOCK_ID( bdb->bi_dbenv, &locker ); - if (rc) return rc; - } - rc = LOCK_GET( bdb->bi_dbenv, locker, 0, &lockobj, - DB_LOCK_WRITE, &lock ); - if (rc) return rc; + ldap_pvt_thread_mutex_lock( &bdb->bi_database_mutex ); /* check again! may have been added by another thread */ for( i=BDB_NDB; i < bdb->bi_ndatabases; i++ ) { if( !strcmp( bdb->bi_databases[i]->bdi_name, name) ) { *dbout = bdb->bi_databases[i]->bdi_db; - LOCK_PUT( bdb->bi_dbenv, &lock); + ldap_pvt_thread_mutex_unlock( &bdb->bi_database_mutex ); return 0; } } if( i >= BDB_INDICES ) { - LOCK_PUT( bdb->bi_dbenv, &lock); + ldap_pvt_thread_mutex_unlock( &bdb->bi_database_mutex ); return -1; } @@ -114,7 +95,7 @@ bdb_db_cache( "bdb_db_cache: db_create(%s) failed: %s (%d)\n", bdb->bi_dbenv_home, db_strerror(rc), rc ); #endif - LOCK_PUT( bdb->bi_dbenv, &lock); + ldap_pvt_thread_mutex_unlock( &bdb->bi_database_mutex ); return rc; } @@ -129,11 +110,9 @@ bdb_db_cache( #ifdef HAVE_EBCDIC __atoe( file ); #endif - flags = bdb->bi_db_opflags | DB_CREATE | DB_THREAD; - if ( !tid ) flags |= DB_AUTO_COMMIT; - rc = DB_OPEN( db->bdi_db, tid, + rc = DB_OPEN( db->bdi_db, file, NULL /* name */, - DB_HASH, flags, + DB_HASH, bdb->bi_db_opflags | DB_CREATE | DB_THREAD, bdb->bi_dbenv_mode ); ch_free( file ); @@ -148,7 +127,7 @@ bdb_db_cache( "bdb_db_cache: db_open(%s) failed: %s (%d)\n", name, db_strerror(rc), rc ); #endif - LOCK_PUT( bdb->bi_dbenv, &lock); + ldap_pvt_thread_mutex_unlock( &bdb->bi_database_mutex ); return rc; } @@ -157,6 +136,6 @@ bdb_db_cache( *dbout = db->bdi_db; - LOCK_PUT( bdb->bi_dbenv, &lock ); + ldap_pvt_thread_mutex_unlock( &bdb->bi_database_mutex ); return 0; } diff --git a/servers/slapd/back-bdb/delete.c b/servers/slapd/back-bdb/delete.c index 945099b5ce..9acab3aa18 100644 --- a/servers/slapd/back-bdb/delete.c +++ b/servers/slapd/back-bdb/delete.c @@ -73,8 +73,8 @@ retry: /* transaction retry */ rs->sr_text = "internal error"; goto return_results; } - bdb_trans_backoff( ++num_retries ); ldap_pvt_thread_yield(); + bdb_trans_backoff( ++num_retries ); } /* begin transaction */ @@ -554,7 +554,7 @@ done: if( e != NULL ) { if ( rs->sr_err == LDAP_SUCCESS ) { /* Free the EntryInfo and the Entry */ - bdb_cache_delete_cleanup( e ); + bdb_cache_delete_cleanup( &bdb->bi_cache, e ); } else { bdb_unlocked_cache_return_entry_w(&bdb->bi_cache, e); } diff --git a/servers/slapd/back-bdb/dn2id.c b/servers/slapd/back-bdb/dn2id.c index c3cef02e80..1ea506b676 100644 --- a/servers/slapd/back-bdb/dn2id.c +++ b/servers/slapd/back-bdb/dn2id.c @@ -899,26 +899,15 @@ struct dn2id_cookie { Operation *op; }; -/* Stuff for iterating over a bei_kids AVL tree and adding the - * IDs to an IDL - */ -struct apply_arg { - ID *idl; - EntryInfo **ei; -}; - static int apply_func( void *data, void *arg ) { EntryInfo *ei = data; - struct apply_arg *ap = arg; + ID *idl = arg; - bdb_idl_insert( ap->idl, ei->bei_id ); - if ( ap->ei ) { - *(ap->ei)++ = ei; - } + bdb_idl_insert( idl, ei->bei_id ); return 0; } @@ -927,7 +916,6 @@ hdb_dn2idl_internal( struct dn2id_cookie *cx ) { - EntryInfo **eilist = NULL, **ptr; #ifdef SLAP_IDL_CACHE if ( cx->bdb->bi_idl_cache_size ) { cx->rc = bdb_idl_cache_get(cx->bdb, cx->db, &cx->key, cx->tmp); @@ -941,13 +929,26 @@ hdb_dn2idl_internal( #endif BDB_IDL_ZERO( cx->tmp ); + if ( !cx->ei ) { + cx->ei = bdb_cache_find_info( cx->bdb, cx->id ); + if ( !cx->ei ) { + cx->rc = DB_NOTFOUND; + goto saveit; + } + } + + bdb_cache_entryinfo_lock( cx->ei ); + /* If number of kids in the cache differs from on-disk, load * up all the kids from the database */ if ( cx->ei->bei_ckids+1 != cx->ei->bei_dkids ) { EntryInfo ei; + db_recno_t dkids = cx->ei->bei_dkids; ei.bei_parent = cx->ei; + bdb_cache_entryinfo_unlock( cx->ei ); + cx->rc = cx->db->cursor( cx->db, NULL, &cx->dbc, cx->bdb->bi_db_opflags ); if ( cx->rc ) return cx->rc; @@ -959,27 +960,20 @@ hdb_dn2idl_internal( /* The first item holds the parent ID. Ignore it. */ cx->rc = cx->dbc->c_get( cx->dbc, &cx->key, &cx->data, DB_SET ); - if ( cx->rc == DB_NOTFOUND ) goto saveit; - if ( cx->rc ) return cx->rc; + if ( cx->rc ) { + cx->dbc->c_close( cx->dbc ); + if ( cx->rc == DB_NOTFOUND ) goto saveit; + return cx->rc; + } /* If the on-disk count is zero we've never checked it. * Count it now. */ - if ( !cx->ei->bei_dkids ) { - db_recno_t dkids; + if ( !dkids ) { cx->dbc->c_count( cx->dbc, &dkids, 0 ); cx->ei->bei_dkids = dkids; } - /* If there are kids and this is a subtree search, allocate - * temp storage for the list of kids. - */ - if ( cx->prefix == DN_SUBTREE_PREFIX && cx->ei->bei_dkids > 1 ) { - eilist = cx->op->o_tmpalloc( sizeof(EntryInfo *) * cx->ei->bei_dkids, cx->op->o_tmpmemctx ); - eilist[cx->ei->bei_dkids-1] = NULL; - ptr = eilist; - } - cx->data.data = cx->buf; cx->data.ulen = BDB_IDL_UM_SIZE * sizeof(ID); cx->data.flags = DB_DBT_USERMEM; @@ -995,9 +989,11 @@ hdb_dn2idl_internal( if (j) { EntryInfo *ei2; diskNode *d = (diskNode *)j; + short nrlen; AC_MEMCPY( &ei.bei_id, &d->entryID, sizeof(ID) ); - AC_MEMCPY( &ei.bei_nrdn.bv_len, &d->nrdnlen, sizeof(d->nrdnlen) ); + AC_MEMCPY( &nrlen, &d->nrdnlen, sizeof(d->nrdnlen) ); + ei.bei_nrdn.bv_len = nrlen; /* nrdn/rdn are set in-place. * hdb_cache_load will copy them as needed */ @@ -1006,39 +1002,23 @@ hdb_dn2idl_internal( ei.bei_rdn.bv_val = d->nrdn + ei.bei_nrdn.bv_len + 1; bdb_idl_insert( cx->tmp, ei.bei_id ); hdb_cache_load( cx->bdb, &ei, &ei2 ); - if ( eilist ) - *ptr++ = ei2; } } } - cx->dbc->c_close( cx->dbc ); + cx->rc = cx->dbc->c_close( cx->dbc ); } else { /* The in-memory cache is in sync with the on-disk data. * do we have any kids? */ + cx->rc = 0; if ( cx->ei->bei_ckids > 0 ) { - struct apply_arg ap; - - /* Temp storage for subtree search */ - if ( cx->prefix == DN_SUBTREE_PREFIX ) { - eilist = cx->op->o_tmpalloc( sizeof(EntryInfo *) * cx->ei->bei_dkids, cx->op->o_tmpmemctx ); - eilist[cx->ei->bei_dkids-1] = NULL; - } /* Walk the kids tree; order is irrelevant since bdb_idl_insert * will insert in sorted order. */ - ap.idl = cx->tmp; - ap.ei = eilist; - bdb_cache_entryinfo_lock( cx->ei ); - avl_apply( cx->ei->bei_kids, apply_func, &ap, -1, AVL_POSTORDER ); - bdb_cache_entryinfo_unlock( cx->ei ); + avl_apply( cx->ei->bei_kids, apply_func, cx->tmp, -1, AVL_POSTORDER ); } - } - - /* If we got some records, treat as success */ - if (!BDB_IDL_IS_ZERO(cx->tmp)) { - cx->rc = 0; + bdb_cache_entryinfo_unlock( cx->ei ); } saveit: @@ -1049,17 +1029,33 @@ saveit: #endif ; gotit: - if ( cx->rc == 0 ) { - /* If eilist is NULL, cx->tmp is empty... */ - if ( cx->prefix == DN_SUBTREE_PREFIX && eilist ) { - bdb_idl_union( cx->ids, cx->tmp ); - for (ptr = eilist; *ptr; ptr++) { - cx->ei = *ptr; - cx->id = cx->ei->bei_id; - hdb_dn2idl_internal( cx ); + if ( !BDB_IDL_IS_ZERO( cx->tmp )) { + if ( cx->prefix == DN_SUBTREE_PREFIX ) { + if (cx->ei->bei_state & CACHE_ENTRY_NO_GRANDKIDS) { + bdb_idl_union( cx->ids, cx->tmp ); + } else { + ID *save, idcurs; + EntryInfo *ei = cx->ei; + int nokids = 1; + save = cx->op->o_tmpalloc( BDB_IDL_SIZEOF( cx->tmp ), + cx->op->o_tmpmemctx ); + BDB_IDL_CPY( save, cx->tmp ); + bdb_idl_union( cx->ids, cx->tmp ); + + idcurs = 0; + for ( cx->id = bdb_idl_first( save, &idcurs ); + cx->id != NOID; + cx->id = bdb_idl_next( save, &idcurs )) { + cx->ei = NULL; + hdb_dn2idl_internal( cx ); + if ( !BDB_IDL_IS_ZERO( cx->tmp )) + nokids = 0; + } + cx->op->o_tmpfree( save, cx->op->o_tmpmemctx ); + if ( nokids ) ei->bei_state |= CACHE_ENTRY_NO_GRANDKIDS; } - cx->op->o_tmpfree( eilist, cx->op->o_tmpmemctx ); cx->rc = 0; + } else { BDB_IDL_CPY( cx->ids, cx->tmp ); } diff --git a/servers/slapd/back-bdb/index.c b/servers/slapd/back-bdb/index.c index c4196495cb..7916d98442 100644 --- a/servers/slapd/back-bdb/index.c +++ b/servers/slapd/back-bdb/index.c @@ -97,7 +97,7 @@ int bdb_index_param( return LDAP_INAPPROPRIATE_MATCHING; } - rc = bdb_db_cache( be, NULL, prefixp->bv_val, &db ); + rc = bdb_db_cache( be, prefixp->bv_val, &db ); if( rc != LDAP_SUCCESS ) { return rc; @@ -159,7 +159,7 @@ static int indexer( assert( mask ); - rc = bdb_db_cache( op->o_bd, txn, atname->bv_val, &db ); + rc = bdb_db_cache( op->o_bd, atname->bv_val, &db ); if ( rc != LDAP_SUCCESS ) { #ifdef NEW_LOGGING diff --git a/servers/slapd/back-bdb/init.c b/servers/slapd/back-bdb/init.c index 8a5a468af1..77bb9e91cb 100644 --- a/servers/slapd/back-bdb/init.c +++ b/servers/slapd/back-bdb/init.c @@ -93,6 +93,7 @@ bdb_db_init( BackendDB *be ) LDAP_LIST_INIT (&bdb->bi_psearch_list); + ldap_pvt_thread_mutex_init( &bdb->bi_database_mutex ); ldap_pvt_thread_mutex_init( &bdb->bi_lastid_mutex ); ldap_pvt_thread_mutex_init( &bdb->bi_cache.lru_mutex ); ldap_pvt_thread_mutex_init( &bdb->bi_cache.c_dntree.bei_kids_mutex ); @@ -397,14 +398,14 @@ bdb_db_open( BackendDB *be ) #ifdef HAVE_EBCDIC strcpy( path, bdbi_databases[i].file ); __atoe( path ); - rc = DB_OPEN( db->bdi_db, NULL, + rc = DB_OPEN( db->bdi_db, path, /* bdbi_databases[i].name, */ NULL, bdbi_databases[i].type, bdbi_databases[i].flags | flags | DB_AUTO_COMMIT, bdb->bi_dbenv_mode ); #else - rc = DB_OPEN( db->bdi_db, NULL, + rc = DB_OPEN( db->bdi_db, bdbi_databases[i].file, /* bdbi_databases[i].name, */ NULL, bdbi_databases[i].type, @@ -539,6 +540,7 @@ bdb_db_destroy( BackendDB *be ) ldap_pvt_thread_mutex_destroy( &bdb->bi_cache.lru_mutex ); ldap_pvt_thread_mutex_destroy( &bdb->bi_cache.c_dntree.bei_kids_mutex ); ldap_pvt_thread_mutex_destroy( &bdb->bi_lastid_mutex ); + ldap_pvt_thread_mutex_destroy( &bdb->bi_database_mutex ); #ifdef SLAP_IDL_CACHE if ( bdb->bi_idl_cache_max_size ) { ldap_pvt_thread_rdwr_destroy( &bdb->bi_idl_tree_rwlock ); diff --git a/servers/slapd/back-bdb/modify.c b/servers/slapd/back-bdb/modify.c index 61cb5f7908..71c80ec798 100644 --- a/servers/slapd/back-bdb/modify.c +++ b/servers/slapd/back-bdb/modify.c @@ -348,8 +348,8 @@ retry: /* transaction retry */ rs->sr_text = "internal error"; goto return_results; } - bdb_trans_backoff( ++num_retries ); ldap_pvt_thread_yield(); + bdb_trans_backoff( ++num_retries ); } /* begin transaction */ diff --git a/servers/slapd/back-bdb/modrdn.c b/servers/slapd/back-bdb/modrdn.c index fe4d2d3ffa..ff4dab5a72 100644 --- a/servers/slapd/back-bdb/modrdn.c +++ b/servers/slapd/back-bdb/modrdn.c @@ -92,7 +92,6 @@ retry: /* transaction retry */ #else Debug( LDAP_DEBUG_TRACE, "==>bdb_modrdn: retrying...\n", 0, 0, 0 ); #endif - pm_list = LDAP_LIST_FIRST(&op->o_pm_list); while ( pm_list != NULL ) { LDAP_LIST_REMOVE ( pm_list, ps_link ); @@ -110,8 +109,8 @@ retry: /* transaction retry */ rs->sr_text = "internal error"; goto return_results; } - bdb_trans_backoff( ++num_retries ); ldap_pvt_thread_yield(); + bdb_trans_backoff( ++num_retries ); } /* begin transaction */ @@ -665,7 +664,7 @@ retry: /* transaction retry */ } /* Build target dn and make sure target entry doesn't exist already. */ - if (!new_dn.bv_val) build_new_dn( &new_dn, new_parent_dn, &op->oq_modrdn.rs_newrdn ); + if (!new_dn.bv_val) build_new_dn( &new_dn, new_parent_dn, &op->oq_modrdn.rs_newrdn, NULL ); if (!new_ndn.bv_val) { struct berval bv = {0, NULL}; @@ -961,6 +960,7 @@ retry: /* transaction retry */ } else { char gid[DB_XIDDATASIZE]; + memset( gid, 0, sizeof(gid) ); snprintf( gid, sizeof( gid ), "%s-%08lx-%08lx", bdb_uuid.bv_val, (long) op->o_connid, (long) op->o_opid ); @@ -1052,9 +1052,15 @@ done: Modifications *tmp; for (; mod; mod=tmp ) { tmp = mod->sml_next; + /* slap_modrdn2mods does things one way, + * slap_mods_opattrs does it differently + */ + if ( mod->sml_op != SLAP_MOD_SOFTADD && + mod->sml_op != LDAP_MOD_DELETE ) break; if ( mod->sml_nvalues ) free( mod->sml_nvalues[0].bv_val ); free( mod ); } + slap_mods_free( mod ); } /* LDAP v3 Support */ diff --git a/servers/slapd/back-bdb/passwd.c b/servers/slapd/back-bdb/passwd.c index e8ca8f70f7..890481c123 100644 --- a/servers/slapd/back-bdb/passwd.c +++ b/servers/slapd/back-bdb/passwd.c @@ -120,8 +120,8 @@ retry: /* transaction retry */ rs->sr_text = "internal error"; goto done; } - bdb_trans_backoff( ++num_retries ); ldap_pvt_thread_yield(); + bdb_trans_backoff( ++num_retries ); } /* begin transaction */ diff --git a/servers/slapd/back-bdb/proto-bdb.h b/servers/slapd/back-bdb/proto-bdb.h index c791c028c9..f9e14ee560 100644 --- a/servers/slapd/back-bdb/proto-bdb.h +++ b/servers/slapd/back-bdb/proto-bdb.h @@ -55,7 +55,6 @@ int bdb_get_commit_csn LDAP_P(( Operation *op, SlapReply *rs, int bdb_db_cache( Backend *be, - DB_TXN *tid, const char *name, DB **db ); @@ -420,10 +419,12 @@ void bdb_unlocked_cache_return_entry_rw( Cache *cache, Entry *e, int rw ); #define bdb_cache_delete BDB_SYMBOL(cache_delete) #define bdb_cache_delete_cleanup BDB_SYMBOL(cache_delete_cleanup) #define bdb_cache_find_id BDB_SYMBOL(cache_find_id) +#define bdb_cache_find_info BDB_SYMBOL(cache_find_info) #define bdb_cache_find_ndn BDB_SYMBOL(cache_find_ndn) #define bdb_cache_modify BDB_SYMBOL(cache_modify) #define bdb_cache_modrdn BDB_SYMBOL(cache_modrdn) #define bdb_cache_release_all BDB_SYMBOL(cache_release_all) +#define bdb_cache_delete_entry BDB_SYMBOL(cache_delete_entry) int bdb_cache_children( Operation *op, @@ -459,6 +460,10 @@ int bdb_cache_find_ndn( struct berval *ndn, EntryInfo **res ); +EntryInfo * bdb_cache_find_info( + struct bdb_info *bdb, + ID id +); int bdb_cache_find_id( Operation *op, DB_TXN *tid, @@ -476,9 +481,16 @@ int bdb_cache_delete( DB_LOCK *lock ); void bdb_cache_delete_cleanup( + Cache *cache, Entry *e ); void bdb_cache_release_all( Cache *cache ); +void bdb_cache_delete_entry( + struct bdb_info *bdb, + EntryInfo *ei, + u_int32_t locker, + DB_LOCK *lock +); #ifdef BDB_HIER int hdb_cache_load( @@ -497,6 +509,10 @@ int bdb_cache_entry_db_relock( int tryOnly, DB_LOCK *lock ); +int bdb_cache_entry_db_unlock( + DB_ENV *env, + DB_LOCK *lock ); + #ifdef BDB_REUSE_LOCKERS #define bdb_locker_id BDB_SYMBOL(locker_id) diff --git a/servers/slapd/back-bdb/search.c b/servers/slapd/back-bdb/search.c index 93a8714d33..2d3f245c50 100644 --- a/servers/slapd/back-bdb/search.c +++ b/servers/slapd/back-bdb/search.c @@ -1218,7 +1218,10 @@ loop_continue: /* free reader lock */ if (!IS_PSEARCH) { bdb_cache_return_entry_r( bdb->bi_dbenv, - &bdb->bi_cache, e , &lock); + &bdb->bi_cache, e , &lock ); + if ( sop->o_nocaching ) { + bdb_cache_delete_entry( bdb, ei, locker, &lock ); + } } e = NULL; rs->sr_entry = NULL; diff --git a/servers/slapd/back-bdb/trans.c b/servers/slapd/back-bdb/trans.c index 51fecf418b..e84bd5242f 100644 --- a/servers/slapd/back-bdb/trans.c +++ b/servers/slapd/back-bdb/trans.c @@ -9,6 +9,7 @@ #include "back-bdb.h" #include "external.h" #include "lber_pvt.h" +#include "lutil.h" /* Congestion avoidance code @@ -25,7 +26,7 @@ bdb_trans_backoff( int num_retries ) unsigned long max_key = -1; struct timeval timeout; - lutil_entropy( &key, sizeof( unsigned long )); + lutil_entropy( (unsigned char *) &key, sizeof( unsigned long )); for ( i = 0; i < num_retries; i++ ) { if ( i >= 5 ) break; diff --git a/servers/slapd/back-ldbm/add.c b/servers/slapd/back-ldbm/add.c index 7406a93d7e..e4a5130b77 100644 --- a/servers/slapd/back-ldbm/add.c +++ b/servers/slapd/back-ldbm/add.c @@ -134,7 +134,8 @@ ldbm_back_add( ber_bvarray_free( rs->sr_ref ); free( (char *)rs->sr_matched ); - + rs->sr_ref = NULL; + rs->sr_matched = NULL; return rs->sr_err; } @@ -220,6 +221,8 @@ ldbm_back_add( ber_bvarray_free( rs->sr_ref ); free( (char *)rs->sr_matched ); + rs->sr_ref = NULL; + rs->sr_matched = NULL; return rs->sr_err; } @@ -408,6 +411,7 @@ ldbm_back_add( } rs->sr_err = LDAP_SUCCESS; + rs->sr_text = NULL; send_ldap_result( op, rs ); /* marks the entry as committed, so it is added to the cache; diff --git a/servers/slapd/back-ldbm/bind.c b/servers/slapd/back-ldbm/bind.c index 73ab8217d1..e84935af0e 100644 --- a/servers/slapd/back-ldbm/bind.c +++ b/servers/slapd/back-ldbm/bind.c @@ -81,6 +81,8 @@ ldbm_back_bind( if ( rs->sr_ref ) ber_bvarray_free( rs->sr_ref ); if ( rs->sr_matched ) free( (char *)rs->sr_matched ); + rs->sr_ref = NULL; + rs->sr_matched = NULL; return rs->sr_err; } @@ -145,7 +147,8 @@ ldbm_back_bind( send_ldap_result( op, rs ); ber_bvarray_free( rs->sr_ref ); - + rs->sr_matched = NULL; + rs->sr_ref = NULL; rc = rs->sr_err; goto return_results; } diff --git a/servers/slapd/back-ldbm/compare.c b/servers/slapd/back-ldbm/compare.c index 0f560e59d1..0c41f24477 100644 --- a/servers/slapd/back-ldbm/compare.c +++ b/servers/slapd/back-ldbm/compare.c @@ -50,7 +50,8 @@ ldbm_back_compare( if ( rs->sr_ref ) ber_bvarray_free( rs->sr_ref ); free( (char *)rs->sr_matched ); - + rs->sr_ref = NULL; + rs->sr_matched = NULL; return( 1 ); } @@ -72,7 +73,8 @@ ldbm_back_compare( send_ldap_result( op, rs ); if ( rs->sr_ref ) ber_bvarray_free( rs->sr_ref ); - + rs->sr_ref = NULL; + rs->sr_matched = NULL; rs->sr_err = 1; goto return_results; } diff --git a/servers/slapd/back-ldbm/delete.c b/servers/slapd/back-ldbm/delete.c index 73ce466683..edcfbf5be4 100644 --- a/servers/slapd/back-ldbm/delete.c +++ b/servers/slapd/back-ldbm/delete.c @@ -72,7 +72,8 @@ ldbm_back_delete( if ( rs->sr_ref ) ber_bvarray_free( rs->sr_ref ); free( (char *)rs->sr_matched ); - + rs->sr_ref = NULL; + rs->sr_matched = NULL; return( -1 ); } @@ -115,7 +116,8 @@ ldbm_back_delete( send_ldap_result( op, rs ); if ( rs->sr_ref ) ber_bvarray_free( rs->sr_ref ); - + rs->sr_ref = NULL; + rs->sr_matched = NULL; rc = LDAP_REFERRAL; goto return_results; } diff --git a/servers/slapd/back-ldbm/modify.c b/servers/slapd/back-ldbm/modify.c index 1e78935a79..5679f2dadc 100644 --- a/servers/slapd/back-ldbm/modify.c +++ b/servers/slapd/back-ldbm/modify.c @@ -153,6 +153,7 @@ int ldbm_modify_internal( rc = modify_add_values( e, mod, get_permissiveModify( op ), text, textbuf, textlen ); + mod->sm_op = SLAP_MOD_SOFTADD; if ( rc == LDAP_TYPE_OR_VALUE_EXISTS ) { rc = LDAP_SUCCESS; } @@ -335,6 +336,8 @@ ldbm_back_modify( if ( rs->sr_ref ) ber_bvarray_free( rs->sr_ref ); free( (char *)rs->sr_matched ); + rs->sr_ref = NULL; + rs->sr_matched = NULL; return rs->sr_err; } @@ -357,7 +360,8 @@ ldbm_back_modify( send_ldap_result( op, rs ); if ( rs->sr_ref ) ber_bvarray_free( rs->sr_ref ); - + rs->sr_ref = NULL; + rs->sr_matched = NULL; goto error_return; } @@ -381,6 +385,7 @@ ldbm_back_modify( goto error_return; } + rs->sr_text = NULL; send_ldap_error( op, rs, LDAP_SUCCESS, NULL ); @@ -392,5 +397,6 @@ ldbm_back_modify( error_return:; cache_return_entry_w( &li->li_cache, e ); ldap_pvt_thread_rdwr_wunlock(&li->li_giant_rwlock); + rs->sr_text = NULL; return rs->sr_err; } diff --git a/servers/slapd/back-ldbm/modrdn.c b/servers/slapd/back-ldbm/modrdn.c index 7200a7bc48..99440e9d45 100644 --- a/servers/slapd/back-ldbm/modrdn.c +++ b/servers/slapd/back-ldbm/modrdn.c @@ -104,7 +104,8 @@ ldbm_back_modrdn( if ( rs->sr_ref ) ber_bvarray_free( rs->sr_ref ); free( (char *)rs->sr_matched ); - + rs->sr_ref = NULL; + rs->sr_matched = NULL; return rs->sr_err; } @@ -146,6 +147,8 @@ ldbm_back_modrdn( send_ldap_result( op, rs ); if ( rs->sr_ref ) ber_bvarray_free( rs->sr_ref ); + rs->sr_ref = NULL; + rs->sr_matched = NULL; goto return_results; } @@ -469,7 +472,7 @@ ldbm_back_modrdn( } /* Build target dn and make sure target entry doesn't exist already. */ - build_new_dn( &new_dn, new_parent_dn, &op->oq_modrdn.rs_newrdn ); + build_new_dn( &new_dn, new_parent_dn, &op->oq_modrdn.rs_newrdn, NULL ); dnNormalize( 0, NULL, NULL, &new_dn, &new_ndn, NULL ); #ifdef NEW_LOGGING @@ -633,6 +636,7 @@ ldbm_back_modrdn( } rs->sr_err = LDAP_SUCCESS; + rs->sr_text = NULL; send_ldap_result( op, rs ); rc = 0; cache_entry_commit( e ); @@ -651,10 +655,16 @@ return_results: if ( mod != NULL ) { Modifications *tmp; for (; mod; mod = tmp ) { + /* slap_modrdn2mods does things one way, + * slap_mods_opattrs does it differently + */ + if ( mod->sml_op != SLAP_MOD_SOFTADD && + mod->sml_op != LDAP_MOD_DELETE ) break; if ( mod->sml_nvalues ) free( mod->sml_nvalues[0].bv_val ); tmp = mod->sml_next; free( mod ); } + slap_mods_free( mod ); } /* LDAP v3 Support */ @@ -677,5 +687,6 @@ return_results: entry_free( e ); } ldap_pvt_thread_rdwr_wunlock(&li->li_giant_rwlock); + rs->sr_text = NULL; return( rc ); } diff --git a/servers/slapd/back-ldbm/referral.c b/servers/slapd/back-ldbm/referral.c index 6aedb91e5f..fc14eb993c 100644 --- a/servers/slapd/back-ldbm/referral.c +++ b/servers/slapd/back-ldbm/referral.c @@ -79,6 +79,8 @@ ldbm_back_referrals( } if ( rs->sr_matched ) free( (char *)rs->sr_matched ); + rs->sr_ref = NULL; + rs->sr_matched = NULL; return rs->sr_err; } @@ -111,6 +113,8 @@ ldbm_back_referrals( } if( refs != NULL ) ber_bvarray_free( refs ); + rs->sr_ref = NULL; + rs->sr_matched = NULL; } cache_return_entry_r( &li->li_cache, e ); diff --git a/servers/slapd/back-ldbm/search.c b/servers/slapd/back-ldbm/search.c index 4a46352208..8d3949cc67 100644 --- a/servers/slapd/back-ldbm/search.c +++ b/servers/slapd/back-ldbm/search.c @@ -111,6 +111,8 @@ ldbm_back_search( ber_bvarray_free( rs->sr_ref ); ber_memfree( matched_dn.bv_val ); + rs->sr_ref = NULL; + rs->sr_matched = NULL; return LDAP_REFERRAL; } @@ -155,6 +157,8 @@ ldbm_back_search( } ber_memfree( matched_dn.bv_val ); + rs->sr_ref = NULL; + rs->sr_matched = NULL; return LDAP_OTHER; } diff --git a/servers/slapd/back-meta/search.c b/servers/slapd/back-meta/search.c index 940ce702cc..2409e54a40 100644 --- a/servers/slapd/back-meta/search.c +++ b/servers/slapd/back-meta/search.c @@ -673,6 +673,8 @@ meta_send_entry( dc.ctx = "searchAttrDN"; while ( ber_scanf( &ber, "{m", &a ) != LBER_ERROR ) { + int last = 0; + ldap_back_map( &li->targets[ target ]->rwmap.rwm_at, &a, &mapped, BACKLDAP_REMAP ); if ( mapped.bv_val == NULL || mapped.bv_val[0] == '\0' ) { @@ -724,7 +726,6 @@ meta_send_entry( } else if ( attr->a_desc == slap_schema.si_ad_objectClass || attr->a_desc == slap_schema.si_ad_structuralObjectClass ) { - int last; for ( last = 0; attr->a_vals[ last ].bv_val; ++last ); @@ -762,6 +763,25 @@ meta_send_entry( ldap_dnattr_result_rewrite( &dc, attr->a_vals ); } + if ( last && attr->a_desc->ad_type->sat_equality && + attr->a_desc->ad_type->sat_equality->smr_normalize ) { + int i; + + attr->a_nvals = ch_malloc((last + 1)*sizeof(struct berval)); + for ( i = 0; ia_desc->ad_type->sat_equality->smr_normalize( + SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX, + attr->a_desc->ad_type->sat_syntax, + attr->a_desc->ad_type->sat_equality, + &attr->a_vals[i], &attr->a_nvals[i], + op->o_tmpmemctx ); + } + attr->a_nvals[i].bv_val = NULL; + attr->a_nvals[i].bv_len = 0; + } else { + attr->a_nvals = attr->a_vals; + } + *attrp = attr; attrp = &attr->a_next; } diff --git a/servers/slapd/back-perl/add.c b/servers/slapd/back-perl/add.c index b17e7cdfb5..88aaf6e79e 100644 --- a/servers/slapd/back-perl/add.c +++ b/servers/slapd/back-perl/add.c @@ -15,7 +15,7 @@ #include #include -#undef _ /* #defined used by both Perl and ac/localize.h */ +#undef _ /* #defined by both Perl and ac/localize.h */ #ifdef HAVE_WIN32_ASPERL #include "asperl_undefs.h" diff --git a/servers/slapd/back-perl/bind.c b/servers/slapd/back-perl/bind.c index a09825de7f..b495b7ceb9 100644 --- a/servers/slapd/back-perl/bind.c +++ b/servers/slapd/back-perl/bind.c @@ -15,7 +15,7 @@ #include #include -#undef _ /* #defined used by both Perl and ac/localize.h */ +#undef _ /* #defined by both Perl and ac/localize.h */ #ifdef HAVE_WIN32_ASPERL #include "asperl_undefs.h" diff --git a/servers/slapd/back-perl/close.c b/servers/slapd/back-perl/close.c index 2e3252c3c1..30afe22994 100644 --- a/servers/slapd/back-perl/close.c +++ b/servers/slapd/back-perl/close.c @@ -15,7 +15,7 @@ #include #include -#undef _ /* #defined used by both Perl and ac/localize.h */ +#undef _ /* #defined by both Perl and ac/localize.h */ #ifdef HAVE_WIN32_ASPERL #include "asperl_undefs.h" diff --git a/servers/slapd/back-perl/compare.c b/servers/slapd/back-perl/compare.c index 1dfcb125f5..4cb871461a 100644 --- a/servers/slapd/back-perl/compare.c +++ b/servers/slapd/back-perl/compare.c @@ -15,7 +15,7 @@ #include #include -#undef _ /* #defined used by both Perl and ac/localize.h */ +#undef _ /* #defined by both Perl and ac/localize.h */ #ifdef HAVE_WIN32_ASPERL #include "asperl_undefs.h" diff --git a/servers/slapd/back-perl/config.c b/servers/slapd/back-perl/config.c index ed9b961711..63878e1d9b 100644 --- a/servers/slapd/back-perl/config.c +++ b/servers/slapd/back-perl/config.c @@ -15,7 +15,7 @@ #include #include -#undef _ /* #defined used by both Perl and ac/localize.h */ +#undef _ /* #defined by both Perl and ac/localize.h */ #ifdef HAVE_WIN32_ASPERL #include "asperl_undefs.h" diff --git a/servers/slapd/back-perl/delete.c b/servers/slapd/back-perl/delete.c index 9bc5126468..9a812f479e 100644 --- a/servers/slapd/back-perl/delete.c +++ b/servers/slapd/back-perl/delete.c @@ -15,7 +15,7 @@ #include #include -#undef _ /* #defined used by both Perl and ac/localize.h */ +#undef _ /* #defined by both Perl and ac/localize.h */ #ifdef HAVE_WIN32_ASPERL #include "asperl_undefs.h" diff --git a/servers/slapd/back-perl/init.c b/servers/slapd/back-perl/init.c index 5f4bec4375..1c8a2616eb 100644 --- a/servers/slapd/back-perl/init.c +++ b/servers/slapd/back-perl/init.c @@ -15,7 +15,7 @@ #include #include -#undef _ /* #defined used by both Perl and ac/localize.h */ +#undef _ /* #defined by both Perl and ac/localize.h */ #ifdef HAVE_WIN32_ASPERL #include "asperl_undefs.h" diff --git a/servers/slapd/back-perl/modify.c b/servers/slapd/back-perl/modify.c index f77f308752..fa6a89f21b 100644 --- a/servers/slapd/back-perl/modify.c +++ b/servers/slapd/back-perl/modify.c @@ -15,7 +15,7 @@ #include #include -#undef _ /* #defined used by both Perl and ac/localize.h */ +#undef _ /* #defined by both Perl and ac/localize.h */ #ifdef HAVE_WIN32_ASPERL #include "asperl_undefs.h" diff --git a/servers/slapd/back-perl/modrdn.c b/servers/slapd/back-perl/modrdn.c index 2befbb6ee7..704d25b3f0 100644 --- a/servers/slapd/back-perl/modrdn.c +++ b/servers/slapd/back-perl/modrdn.c @@ -28,7 +28,7 @@ #include #include -#undef _ /* #defined used by both Perl and ac/localize.h */ +#undef _ /* #defined by both Perl and ac/localize.h */ #ifdef HAVE_WIN32_ASPERL #include "asperl_undefs.h" diff --git a/servers/slapd/back-perl/search.c b/servers/slapd/back-perl/search.c index 50230e6efc..2cf30dcd4b 100644 --- a/servers/slapd/back-perl/search.c +++ b/servers/slapd/back-perl/search.c @@ -15,7 +15,7 @@ #include #include -#undef _ /* #defined used by both Perl and ac/localize.h */ +#undef _ /* #defined by both Perl and ac/localize.h */ #ifdef HAVE_WIN32_ASPERL #include "asperl_undefs.h" diff --git a/servers/slapd/back-sql/modify.c b/servers/slapd/back-sql/modify.c index 152165fa87..ce587646a9 100644 --- a/servers/slapd/back-sql/modify.c +++ b/servers/slapd/back-sql/modify.c @@ -679,7 +679,7 @@ backsql_modrdn( Operation *op, SlapReply *rs ) goto modrdn_return; } - build_new_dn( &new_dn, new_pdn, &op->oq_modrdn.rs_newrdn ); + build_new_dn( &new_dn, new_pdn, &op->oq_modrdn.rs_newrdn, NULL ); rs->sr_err = dnNormalize( 0, NULL, NULL, &new_dn, &new_ndn, op->o_tmpmemctx ); if ( rs->sr_err != LDAP_SUCCESS ) { diff --git a/servers/slapd/backend.c b/servers/slapd/backend.c index f0adee39b0..7458a2b910 100644 --- a/servers/slapd/backend.c +++ b/servers/slapd/backend.c @@ -336,6 +336,23 @@ int backend_startup(Backend *be) /* open each backend database */ for( i = 0; i < nBackendDB; i++ ) { + if ( backendDB[i].be_update_ndn.bv_val && ( + !backendDB[i].be_update_refs && + !backendDB[i].syncinfo && + !default_referral ) ) { +#ifdef NEW_LOGGING + LDAP_LOG( BACKEND, CRIT, + "backend_startup: slave \"%s\" updateref missing\n", + backendDB[i].be_suffix[0].bv_val, 0, 0 ); + +#else + Debug( LDAP_DEBUG_ANY, + "backend_startup: slave \"%s\" updateref missing\n", + backendDB[i].be_suffix[0].bv_val, 0, 0 ); +#endif + return -1; + } + /* append global access controls */ acl_append( &backendDB[i].be_acl, global_acl ); @@ -607,7 +624,8 @@ select_backend( if( be == NULL ) { be = &backends[i]; - if( manageDSAit && len == dnlen ) { + if( manageDSAit && len == dnlen && + !SLAP_GLUE_SUBORDINATE( be ) ) { continue; } } else { @@ -1177,6 +1195,7 @@ backend_group( if ( target && dn_match( &target->e_nname, gr_ndn ) ) { e = target; + rc = 0; } else { rc = be_entry_get_rw(op, gr_ndn, group_oc, group_at, 0, &e ); } diff --git a/servers/slapd/backover.c b/servers/slapd/backover.c index 29edb8470c..bb13448a46 100644 --- a/servers/slapd/backover.c +++ b/servers/slapd/backover.c @@ -165,7 +165,7 @@ over_op_func( BI_op_bind **func; BackendDB *be = op->o_bd, db = *op->o_bd; slap_callback cb = {over_back_response, NULL}; - int rc = 0; + int rc = SLAP_CB_CONTINUE; op->o_bd = &db; cb.sc_private = op->o_callback; @@ -176,15 +176,18 @@ over_op_func( if ( func[which] ) { db.bd_info = (BackendInfo *)on; rc = func[which]( op, rs ); - if ( rc ) break; + if ( rc != SLAP_CB_CONTINUE ) break; } } func = &oi->oi_bd.bd_info->bi_op_bind; - if ( func[which] ) { + if ( func[which] && rc == SLAP_CB_CONTINUE ) { rc = func[which]( op, rs ); } - + /* should not fall thru this far without anything happening... */ + if ( rc == SLAP_CB_CONTINUE ) { + rc = LDAP_UNWILLING_TO_PERFORM; + } op->o_bd = be; return rc; } @@ -321,7 +324,7 @@ overlay_config( BackendDB *be, const char *ov ) */ oi = (slap_overinfo *) be->bd_info; for ( prev=NULL, on2 = oi->oi_list; on2; prev=on2, on2=on2->on_next ); - on2 = ch_malloc( sizeof(slap_overinst) ); + on2 = ch_calloc( 1, sizeof(slap_overinst) ); if ( !prev ) { oi->oi_list = on2; } else { @@ -329,6 +332,7 @@ overlay_config( BackendDB *be, const char *ov ) } *on2 = *on; on2->on_next = NULL; + on2->on_info = oi; /* Any initialization needed? */ if ( on->on_bi.bi_db_init ) { diff --git a/servers/slapd/bind.c b/servers/slapd/bind.c index 0d87e303ed..b4095cf56b 100644 --- a/servers/slapd/bind.c +++ b/servers/slapd/bind.c @@ -47,6 +47,7 @@ do_bind( #ifdef LDAP_SLAPI Slapi_PBlock *pb = op->o_pb; + int rc; #endif #ifdef NEW_LOGGING @@ -526,8 +527,9 @@ do_bind( slapi_pblock_set( pb, SLAPI_BIND_METHOD, (void *)method ); slapi_pblock_set( pb, SLAPI_BIND_CREDENTIALS, (void *)&op->orb_cred ); slapi_pblock_set( pb, SLAPI_MANAGEDSAIT, (void *)(0) ); + slapi_pblock_set( pb, SLAPI_CONN_DN, (void *)(0) ); - rs->sr_err = doPluginFNs( op->o_bd, SLAPI_PLUGIN_PRE_BIND_FN, pb ); + rc = doPluginFNs( op->o_bd, SLAPI_PLUGIN_PRE_BIND_FN, pb ); #ifdef NEW_LOGGING LDAP_LOG( OPERATION, INFO, @@ -539,7 +541,7 @@ do_bind( rs->sr_err, 0, 0); #endif - switch ( rs->sr_err ) { + switch ( rc ) { case SLAPI_BIND_SUCCESS: /* Continue with backend processing */ break; @@ -552,7 +554,7 @@ do_bind( case SLAPI_BIND_ANONYMOUS: /* SLAPI_BIND_ANONYMOUS is undocumented XXX */ default: - /* Authoritative, plugin sent result */ + /* Authoritative, plugin sent result, or no plugins called. */ if ( slapi_pblock_get( op->o_pb, SLAPI_RESULT_CODE, (void *)&rs->sr_err) != 0 ) { @@ -564,7 +566,12 @@ do_bind( if ( rs->sr_err == LDAP_SUCCESS ) { slapi_pblock_get( pb, SLAPI_CONN_DN, (void *)&op->orb_edn.bv_val ); - if ( op->orb_edn.bv_val != NULL ) { + if ( op->orb_edn.bv_val == NULL ) { + if ( rc == 1 ) { + /* No plugins were called; continue. */ + break; + } + } else { op->orb_edn.bv_len = strlen( op->orb_edn.bv_val ); } rs->sr_err = dnPrettyNormal( NULL, &op->orb_edn, diff --git a/servers/slapd/connection.c b/servers/slapd/connection.c index e7effae346..731f46bc8c 100644 --- a/servers/slapd/connection.c +++ b/servers/slapd/connection.c @@ -193,6 +193,9 @@ int connections_timeout_idle(time_t now) c != NULL; c = connection_next( c, &connindex ) ) { + /* Don't timeout a slow-running request */ + if( c->c_n_ops_executing ) continue; + if( difftime( c->c_activitytime+global_idletimeout, now) < 0 ) { /* close it */ connection_closing( c ); @@ -1079,9 +1082,6 @@ operations_error: ldap_pvt_thread_mutex_lock( &conn->c_mutex ); - conn->c_n_ops_executing--; - conn->c_n_ops_completed++; - LDAP_STAILQ_REMOVE( &conn->c_ops, op, slap_op, o_next); LDAP_STAILQ_NEXT(op, o_next) = NULL; @@ -1094,6 +1094,8 @@ operations_error: co_op_free: + conn->c_n_ops_executing--; + conn->c_n_ops_completed++; memctx = NULL; ber_set_option( op->o_ber, LBER_OPT_BER_MEMCTX, &memctx ); slap_op_free( op ); diff --git a/servers/slapd/ctxcsn.c b/servers/slapd/ctxcsn.c index bcf7a4f687..459fc35583 100644 --- a/servers/slapd/ctxcsn.c +++ b/servers/slapd/ctxcsn.c @@ -33,13 +33,18 @@ #include "slap.h" #include "lutil_ldap.h" -struct berval * -slap_get_commit_csn( Operation *op ) +const struct berval slap_ldapsync_bv = BER_BVC("ldapsync"); +const struct berval slap_ldapsync_cn_bv = BER_BVC("cn=ldapsync"); + +void +slap_get_commit_csn( Operation *op, struct berval *csn ) { - struct berval *max_committed_csn = NULL; struct slap_csn_entry *csne = NULL, *committed_csne = NULL; int i = 0; + csn->bv_val = NULL; + csn->bv_len = 0; + ldap_pvt_thread_mutex_lock( &op->o_bd->be_pcl_mutex ); LDAP_TAILQ_FOREACH( csne, &op->o_bd->be_pending_csn_list, csn_link ) { @@ -61,10 +66,8 @@ slap_get_commit_csn( Operation *op ) ldap_pvt_thread_mutex_unlock( &op->o_bd->be_pcl_mutex ); if ( committed_csne ) { - max_committed_csn = ber_dupbv( NULL, committed_csne->csn ); + ber_dupbv( csn, committed_csne->csn ); } - - return max_committed_csn; } void @@ -91,6 +94,12 @@ slap_graduate_commit_csn( Operation *op ) { struct slap_csn_entry *csne = NULL; + if ( op == NULL ) + return; + + if ( op->o_bd == NULL ) + return; + ldap_pvt_thread_mutex_lock( &op->o_bd->be_pcl_mutex ); LDAP_TAILQ_FOREACH( csne, &op->o_bd->be_pending_csn_list, csn_link ) { @@ -132,12 +141,9 @@ slap_create_context_csn_entry( attr_merge( e, slap_schema.si_ad_objectClass, ocbva, NULL ); - bv.bv_val = "subentry"; - bv.bv_len = sizeof("subentry")-1; - - attr_merge_one( e, slap_schema.si_ad_structuralObjectClass, &bv, NULL ); + attr_merge_one( e, slap_schema.si_ad_structuralObjectClass, &ocbva[1], NULL ); - attr_merge_one( e, slap_schema.si_ad_cn, &slap_ldapsync_bv, NULL ); + attr_merge_one( e, slap_schema.si_ad_cn, (struct berval *)&slap_ldapsync_bv, NULL ); if ( context_csn ) { attr_merge_one( e, slap_schema.si_ad_contextCSN, @@ -148,7 +154,7 @@ slap_create_context_csn_entry( bv.bv_len = sizeof("{}")-1; attr_merge_one( e, slap_schema.si_ad_subtreeSpecification, &bv, NULL ); - build_new_dn( &e->e_name, &be->be_nsuffix[0], &slap_ldapsync_cn_bv ); + build_new_dn( &e->e_name, &be->be_nsuffix[0], (struct berval *)&slap_ldapsync_cn_bv, NULL ); ber_dupbv( &e->e_nname, &e->e_name ); return e; @@ -179,13 +185,13 @@ slap_get_csn( { struct slap_csn_entry *pending; + if ( csn == NULL ) + return LDAP_OTHER; + if ( manage_ctxcsn ) { pending = (struct slap_csn_entry *) ch_calloc( 1, sizeof( struct slap_csn_entry )); } - if ( csn == NULL ) - return LDAP_OTHER; - csn->bv_len = lutil_csnstr( csnbuf, len, 0, 0 ); csn->bv_val = csnbuf; diff --git a/servers/slapd/dn.c b/servers/slapd/dn.c index be518eec58..5696dbf837 100644 --- a/servers/slapd/dn.c +++ b/servers/slapd/dn.c @@ -14,10 +14,8 @@ #include #include -#include "ldap_pvt.h" - #include "slap.h" - +#include "ldap_pvt.h" /* must be after slap.h, to get ldap_bv2dn_x() & co */ #include "lutil.h" /* @@ -819,7 +817,8 @@ rdnValidate( struct berval *rdn ) void build_new_dn( struct berval * new_dn, struct berval * parent_dn, - struct berval * newrdn ) + struct berval * newrdn, + void *memctx ) { char *ptr; @@ -829,7 +828,7 @@ build_new_dn( struct berval * new_dn, } new_dn->bv_len = parent_dn->bv_len + newrdn->bv_len + 1; - new_dn->bv_val = (char *) ch_malloc( new_dn->bv_len + 1 ); + new_dn->bv_val = (char *) sl_malloc( new_dn->bv_len + 1, memctx ); ptr = lutil_strcopy( new_dn->bv_val, newrdn->bv_val ); *ptr++ = ','; diff --git a/servers/slapd/filter.c b/servers/slapd/filter.c index d634b6850d..c998615157 100644 --- a/servers/slapd/filter.c +++ b/servers/slapd/filter.c @@ -26,6 +26,11 @@ static int get_ssa( SubstringsAssertion **s, const char **text ); +static int filter_escape_value_x( + struct berval *in, + struct berval *out, + void *ctx ); + static void simple_vrFilter2bv( Operation *op, ValuesReturnFilter *f, @@ -854,7 +859,7 @@ filter2bv( Filter *f, struct berval *fstr ) filter2bv_x( &op, f, fstr ); } -int +static int filter_escape_value_x( struct berval *in, struct berval *out, diff --git a/servers/slapd/globals.c b/servers/slapd/globals.c index f21065908f..fdc4c823a2 100644 --- a/servers/slapd/globals.c +++ b/servers/slapd/globals.c @@ -25,7 +25,3 @@ const struct berval slap_unknown_bv = BER_BVC("unknown"); /* normalized boolean values */ const struct berval slap_true_bv = BER_BVC("TRUE"); const struct berval slap_false_bv = BER_BVC("FALSE"); - -/* ldapsync items */ -const struct berval slap_ldapsync_bv = BER_BVC("ldapsync"); -const struct berval slap_ldapsync_cn_bv = BER_BVC("cn=ldapsync"); diff --git a/servers/slapd/overlays/README b/servers/slapd/overlays/README new file mode 100644 index 0000000000..b76594cbfd --- /dev/null +++ b/servers/slapd/overlays/README @@ -0,0 +1,23 @@ +# $OpenLDAP$ + +This directory is still a work in progress. As such, no explicit makefile +is provided. + +The overlays are meant to be built as dynamically loaded modules. +To build a particular overlay, use commands of this form: + + libtool --mode=compile cc -I../../../include -I.. -c dyngroup.c + libtool --mode=link cc -rpath /module/executable/path \ + -module -o dyngroup.la dyngroup.lo + +To use the dyngroup overlay on a backend, set slapd.conf as follows: + + moduleload /module/executable/path/dyngroup.la + + database bdb + ... (BDB configuration) + overlay dyngroup + attrpair member memberurl + +Replace "/module/executable/path" with the full pathname of the directory +where the module will be installed. diff --git a/servers/slapd/overlays/dyngroup.c b/servers/slapd/overlays/dyngroup.c new file mode 100644 index 0000000000..c351065c65 --- /dev/null +++ b/servers/slapd/overlays/dyngroup.c @@ -0,0 +1,156 @@ +/* dyngroup.c - Demonstration of overlay code */ +/* $OpenLDAP$ */ +/* + * Copyright 2003 The OpenLDAP Foundation, All Rights Reserved. + * COPYING RESTRICTIONS APPLY, see COPYRIGHT file + */ +/* + * Copyright 2003, Howard Chu, All rights reserved. + * + * Permission is granted to anyone to use this software for any purpose + * on any computer system, and to alter it and redistribute it, subject + * to the following restrictions: + * + * 1. The author is not responsible for the consequences of use of this + * software, no matter how awful, even if they arise from flaws in it. + * + * 2. The origin of this software must not be misrepresented, either by + * explicit claim or by omission. Since few users ever read sources, + * credits should appear in the documentation. + * + * 3. Altered versions must be plainly marked as such, and must not be + * misrepresented as being the original software. Since few users + * ever read sources, credits should appear in the documentation. + * + * 4. This notice may not be removed or altered. + */ + +#include "portable.h" + +#include + +#include +#include + +#include "slap.h" + +/* This overlay extends the Compare operation to detect members of a + * dynamic group. It has no effect on any other operations. It must + * be configured with a pair of attributes to trigger on, e.g. + * attrpair member memberURL + * will cause compares on "member" to trigger a compare on "memberURL". + */ + +typedef struct adpair { + struct adpair *ap_next; + AttributeDescription *ap_mem; + AttributeDescription *ap_uri; +} adpair; + +static int +dyngroup_response( Operation *op, SlapReply *rs ) +{ + slap_overinst *on = (slap_overinst *) op->o_bd->bd_info; + adpair *ap = on->on_bi.bi_private; + + /* If we've been configured and the current response is + * what we're looking for... + */ + if ( ap && op->o_tag == LDAP_REQ_COMPARE && + rs->sr_err == LDAP_NO_SUCH_ATTRIBUTE ) { + + for (;ap;ap=ap->ap_next) { + if ( op->oq_compare.rs_ava->aa_desc == ap->ap_mem ) { + /* This compare is for one of the attributes we're + * interested in. We'll use slapd's existing dyngroup + * evaluator to get the answer we want. + */ + int cache = op->o_do_not_cache; + + op->o_do_not_cache = 1; + if ( backend_group( op, NULL, &op->o_req_ndn, + &op->oq_compare.rs_ava->aa_value, NULL, ap->ap_uri ) == 0 ) + rs->sr_err = LDAP_COMPARE_TRUE; + op->o_do_not_cache = cache; + break; + } + } + } + /* Default is to just fall through to the normal processing */ + return SLAP_CB_CONTINUE; +} + +static int dyngroup_config( + BackendDB *be, + const char *fname, + int lineno, + int argc, + char **argv +) +{ + slap_overinst *on = (slap_overinst *) be->bd_info; + adpair ap = { NULL, NULL, NULL }, *a2; + + if ( strcasecmp( argv[0], "attrpair" ) == 0 ) { + const char *text; + if ( argc != 3 ) { + Debug( LDAP_DEBUG_ANY, + "%s: line %d: attribute description missing in \"attrpair \" line.\n", + fname, lineno, 0 ); + return( 1 ); + } + if ( slap_str2ad( argv[1], &ap.ap_mem, &text ) ) { + Debug( LDAP_DEBUG_ANY, + "%s: line %d: attribute description unknown \"attrpair\" line: %s.\n", + fname, lineno, text ); + return( 1 ); + } + if ( slap_str2ad( argv[2], &ap.ap_uri, &text ) ) { + Debug( LDAP_DEBUG_ANY, + "%s: line %d: attribute description unknown \"attrpair\" line: %s.\n", + fname, lineno, text ); + return( 1 ); + } + /* The on->on_bi.bi_private pointer can be used for + * anything this instance of the overlay needs. + */ + + a2 = ch_malloc( sizeof(adpair) ); + a2->ap_next = on->on_bi.bi_private; + a2->ap_mem = ap.ap_mem; + a2->ap_uri = ap.ap_uri; + on->on_bi.bi_private = a2; + } + return 0; +} + +static int +dyngroup_close( + BackendDB *be +) +{ + slap_overinst *on = (slap_overinst *) be->bd_info; + adpair *ap, *a2; + + for ( ap = on->on_bi.bi_private; ap; ap = a2 ) { + a2 = ap->ap_next; + ch_free( ap ); + } + return 0; +} + +static slap_overinst dyngroup; + +/* This overlay is set up for dynamic loading via moduleload. For static + * configuration, you'll need to arrange for the slap_overinst to be + * initialized and registered by some other function inside slapd. + */ + +int init_module(int argc, char *argv[]) { + dyngroup.on_bi.bi_type = "dyngroup"; + dyngroup.on_bi.bi_db_config = dyngroup_config; + dyngroup.on_bi.bi_db_close = dyngroup_close; + dyngroup.on_response = dyngroup_response; + + return overlay_register( &dyngroup ); +} diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index 47803caa77..ed3762dd6f 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -358,7 +358,7 @@ LDAP_SLAPD_F (ContentRule *) cr_bvfind LDAP_P(( * ctxcsn.c */ -LDAP_SLAPD_F (struct berval *) slap_get_commit_csn LDAP_P(( Operation * )); +LDAP_SLAPD_F (void) slap_get_commit_csn LDAP_P(( Operation *, struct berval * )); LDAP_SLAPD_F (void) slap_rewind_commit_csn LDAP_P(( Operation * )); LDAP_SLAPD_F (void) slap_graduate_commit_csn LDAP_P(( Operation * )); LDAP_SLAPD_F (Entry *) slap_create_context_csn_entry LDAP_P(( Backend *, struct berval *)); @@ -427,7 +427,8 @@ LDAP_SLAPD_F (int) dn_rdnlen LDAP_P(( Backend *be, struct berval *dn )); LDAP_SLAPD_F (void) build_new_dn LDAP_P(( struct berval * new_dn, struct berval * parent_dn, - struct berval * newrdn )); + struct berval * newrdn, + void *memctx )); LDAP_SLAPD_F (void) dnParent LDAP_P(( struct berval *dn, struct berval *pdn )); diff --git a/servers/slapd/result.c b/servers/slapd/result.c index c4311df736..08ddfda50f 100644 --- a/servers/slapd/result.c +++ b/servers/slapd/result.c @@ -372,8 +372,8 @@ send_ldap_response( #ifdef LDAP_SLAPI slapi_pblock_set( op->o_pb, SLAPI_RESULT_CODE, (void *)rs->sr_err ); - slapi_pblock_set( op->o_pb, SLAPI_RESULT_MATCHED, ( rs->sr_matched != NULL ) ? (void *)ch_strdup( rs->sr_matched ) : NULL ); - slapi_pblock_set( op->o_pb, SLAPI_RESULT_TEXT, ( rs->sr_text != NULL ) ? (void *)ch_strdup( rs->sr_text ) : NULL ); + slapi_pblock_set( op->o_pb, SLAPI_RESULT_MATCHED, (void *)rs->sr_matched ); + slapi_pblock_set( op->o_pb, SLAPI_RESULT_TEXT, (void *)rs->sr_text ); #endif /* LDAP_SLAPI */ ldap_pvt_thread_mutex_lock( &num_sent_mutex ); @@ -487,6 +487,20 @@ slap_send_ldap_result( Operation *op, SlapReply *rs ) } } +#ifdef LDAP_SLAPI + /* + * Call pre-result plugins. To avoid infinite recursion plugins + * should just set SLAPI_RESULT_CODE rather than sending a + * result if they wish to change the result. + */ + slapi_x_pblock_set_operation( op->o_pb, op ); + slapi_pblock_set( op->o_pb, SLAPI_RESULT_CODE, (void *)rs->sr_err ); + slapi_pblock_set( op->o_pb, SLAPI_RESULT_TEXT, (void *)rs->sr_text ); + slapi_pblock_set( op->o_pb, SLAPI_RESULT_MATCHED, (void *)rs->sr_matched ); + + (void) doPluginFNs( op->o_bd, SLAPI_PLUGIN_PRE_RESULT_FN, op->o_pb ); +#endif /* LDAP_SLAPI */ + if ( op->o_protocol < LDAP_VERSION3 ) { tmp = v2ref( rs->sr_ref, rs->sr_text ); rs->sr_text = tmp; diff --git a/servers/slapd/slap.h b/servers/slapd/slap.h index 0cee21b3dd..30465dffdd 100644 --- a/servers/slapd/slap.h +++ b/servers/slapd/slap.h @@ -1981,6 +1981,7 @@ typedef struct slap_op { ValuesReturnFilter *o_vrFilter; /* ValuesReturnFilter */ syncinfo_t* o_si; + int o_nocaching; #ifdef LDAP_SLAPI void *o_pb; /* NS-SLAPI plugin */ diff --git a/servers/slapd/slapi/Makefile.in b/servers/slapd/slapi/Makefile.in index d93f9d9fd2..d803f02f80 100644 --- a/servers/slapd/slapi/Makefile.in +++ b/servers/slapd/slapi/Makefile.in @@ -9,7 +9,6 @@ ## written consent of IBM LIBRARY = libslapi.la -#XLIBRARY = libtmpslapd.a #all-common: $(LIBRARY) $(PROGRAMS) # @touch plugin.c slapi_pblock.c slapi_utils.c slapi_ops.c slapi_ext.c @@ -36,8 +35,6 @@ NT_LINK_LIBS = $(AC_LIBS) XINCPATH = -I$(srcdir)/.. -I$(srcdir) XDEFS = $(MODULES_CPPFLAGS) -#UNIX_LINK_LIBS = ./libtmpslapd.a ../libbackends.a ../../../libraries/libavl/libavl.a ../../../libraries/liblber/.libs/liblber.a ../../../libraries/libldbm/libldbm.a ../../../libraries/libldif/libldif.a ../../../libraries/liblutil/liblutil.a ../../../libraries/liblunicode/liblunicode.a ../../../libraries/libldap_r/.libs/libldap_r.a ./libtmpslapd.a - BUILD_MOD = @BUILD_SLAPI@ install-local: FORCE diff --git a/servers/slapd/slapi/plugin.c b/servers/slapd/slapi/plugin.c index b4e99b9884..1814498ef6 100644 --- a/servers/slapd/slapi/plugin.c +++ b/servers/slapd/slapi/plugin.c @@ -60,6 +60,7 @@ newPlugin( char *argv[] ) { Slapi_PBlock *pPlugin = NULL; + Slapi_PluginDesc *pPluginDesc = NULL; lt_dlhandle hdLoadHandle; int rc; @@ -70,28 +71,37 @@ newPlugin( } rc = slapi_pblock_set( pPlugin, SLAPI_PLUGIN_TYPE, (void *)type ); - if ( rc != LDAP_SUCCESS ) { + if ( rc != 0 ) { goto done; } rc = slapi_pblock_set( pPlugin, SLAPI_PLUGIN_ARGC, (void *)argc ); - if ( rc != LDAP_SUCCESS ) { + if ( rc != 0 ) { goto done; } rc = slapi_pblock_set( pPlugin, SLAPI_PLUGIN_ARGV, (void *)argv ); - if ( rc != LDAP_SUCCESS ) { + if ( rc != 0 ) { goto done; } rc = loadPlugin( pPlugin, path, initfunc, TRUE, NULL, &hdLoadHandle ); if ( rc != 0 ) { - rc = LDAP_OTHER; goto done; } + if ( slapi_pblock_get( pPlugin, SLAPI_PLUGIN_DESCRIPTION, (void **)&pPluginDesc ) == 0 && + pPluginDesc != NULL ) { + slapi_log_error(SLAPI_LOG_TRACE, "newPlugin", + "Registered plugin %s %s [%s] (%s)\n", + pPluginDesc->spd_id, + pPluginDesc->spd_version, + pPluginDesc->spd_vendor, + pPluginDesc->spd_description); + } + done: - if ( rc != LDAP_SUCCESS && pPlugin != NULL ) { + if ( rc != 0 && pPlugin != NULL ) { slapi_pblock_destroy( pPlugin ); pPlugin = NULL; } diff --git a/servers/slapd/slapi/proto-slapi.h b/servers/slapd/slapi/proto-slapi.h index f607a17d63..8fc2edd62c 100644 --- a/servers/slapd/slapi/proto-slapi.h +++ b/servers/slapd/slapi/proto-slapi.h @@ -156,6 +156,9 @@ extern char * slapi_esc_dn_normalize( char *dn ); extern char * slapi_esc_dn_normalize_case( char *dn ); extern int slapi_dn_isroot( Slapi_PBlock *pb, char *dn ); extern int slapi_dn_issuffix( char *dn, char *suffix ); +char *slapi_dn_beparent( Slapi_PBlock *pb, const char *dn ); +char *slapi_dn_parent( const char *dn ); +int slapi_dn_isparent( const char *parentdn, const char *childdn ); extern char *slapi_dn_ignore_case( char *dn ); extern char *slapi_get_hostname(); extern void slapi_register_supported_saslmechanism( char *mechanism ); @@ -165,6 +168,9 @@ extern int slapi_send_ldap_extended_response(Connection *conn, Operation *op, int errornum, char *respName, struct berval *response); extern int slapi_send_ldap_search_entry( Slapi_PBlock *pb, Slapi_Entry *e, LDAPControl **ectrls, char **attrs, int attrsonly ); +extern int slapi_send_ldap_search_reference( Slapi_PBlock *pb, Slapi_Entry *e, + struct berval **references, LDAPControl **ectrls, struct berval **v2refs ); + extern void slapi_register_supported_control(char *controloid, unsigned long controlops); extern int slapi_get_supported_controls(char ***ctrloidsp, unsigned long **ctrlopsp); diff --git a/servers/slapd/slapi/slapi_pblock.c b/servers/slapd/slapi/slapi_pblock.c index 546a241581..000f801167 100644 --- a/servers/slapd/slapi/slapi_pblock.c +++ b/servers/slapd/slapi/slapi_pblock.c @@ -268,7 +268,7 @@ static int set( Slapi_PBlock *pb, int param, void *val ) { #if defined(LDAP_SLAPI) - int i; + int i, freeit; if ( isValidParam( pb, param ) == INVALID_PARAM ) { return PBLOCK_ERROR; @@ -281,6 +281,17 @@ set( Slapi_PBlock *pb, int param, void *val ) return PBLOCK_ERROR; } + switch ( param ) { + case SLAPI_CONN_DN: + case SLAPI_CONN_AUTHMETHOD: + case SLAPI_IBM_CONN_DN_ALT: + case SLAPI_IBM_CONN_DN_ORIG: + case SLAPI_RESULT_TEXT: + case SLAPI_RESULT_MATCHED: + freeit = 1; break; + default: + freeit = 0; break; + } for( i = 0; i < pb->numParams; i++ ) { if ( pb->curParams[i] == param ) { break; @@ -291,6 +302,7 @@ set( Slapi_PBlock *pb, int param, void *val ) pb->curParams[i] = param; pb->numParams++; } + if ( freeit ) ch_free( pb->curVals[i] ); pb->curVals[i] = val; unLock( pb ); diff --git a/servers/slapd/slapi/slapi_utils.c b/servers/slapd/slapi/slapi_utils.c index 1bc7311292..4ed0816fd4 100644 --- a/servers/slapd/slapi/slapi_utils.c +++ b/servers/slapd/slapi/slapi_utils.c @@ -29,10 +29,6 @@ #include #include -#ifdef _SPARC -#include -#endif - #include /* @@ -922,6 +918,139 @@ slapi_dn_issuffix( #endif /* LDAP_SLAPI */ } +int +slapi_dn_isparent( + const char *parentdn, + const char *childdn ) +{ +#ifdef LDAP_SLAPI + struct berval assertedParentDN, normalizedAssertedParentDN; + struct berval childDN, normalizedChildDN; + struct berval normalizedParentDN; + int match; + + assert( parentdn != NULL ); + assert( childdn != NULL ); + + assertedParentDN.bv_val = (char *)parentdn; + assertedParentDN.bv_len = strlen( parentdn ); + + if ( dnNormalize( 0, NULL, NULL, &assertedParentDN, + &normalizedAssertedParentDN, NULL ) != LDAP_SUCCESS ) + { + return 0; + } + + childDN.bv_val = (char *)childdn; + childDN.bv_len = strlen( childdn ); + + if ( dnNormalize( 0, NULL, NULL, &childDN, + &normalizedChildDN, NULL ) != LDAP_SUCCESS ) + { + slapi_ch_free( (void **)&normalizedAssertedParentDN.bv_val ); + return 0; + } + + dnParent( &normalizedChildDN, &normalizedParentDN ); + + if ( dnMatch( &match, 0, slap_schema.si_syn_distinguishedName, NULL, + &normalizedParentDN, (void *)&normalizedAssertedParentDN ) != LDAP_SUCCESS ) + { + match = -1; + } + + slapi_ch_free( (void **)&normalizedAssertedParentDN.bv_val ); + slapi_ch_free( (void **)&normalizedChildDN.bv_val ); + + return ( match == 0 ); +#else + return 0; +#endif /* LDAP_SLAPI */ +} + +/* + * Returns DN of the parent entry, or NULL if the DN is + * an empty string or NULL, or has no parent. + */ +char * +slapi_dn_parent( const char *_dn ) +{ +#ifdef LDAP_SLAPI + struct berval dn, prettyDN; + struct berval parentDN; + + if ( _dn == NULL ) { + return NULL; + } + + dn.bv_val = (char *)_dn; + dn.bv_len = strlen( _dn ); + + if ( dn.bv_len == 0 ) { + return NULL; + } + + if ( dnPretty( NULL, &dn, &prettyDN, NULL ) != LDAP_SUCCESS ) { + return NULL; + } + + dnParent( &prettyDN, &parentDN ); /* in-place */ + + slapi_ch_free( (void **)&prettyDN.bv_val ); + + if ( parentDN.bv_len == 0 ) { + return NULL; + } + + return slapi_ch_strdup( parentDN.bv_val ); +#else + return NULL; +#endif /* LDAP_SLAPI */ +} + +/* + * Returns DN of the parent entry; or NULL if the DN is + * an empty string, if the DN has no parent, or if the + * DN is the suffix of the backend database + */ +char *slapi_dn_beparent( Slapi_PBlock *pb, const char *_dn ) +{ +#ifdef LDAP_SLAPI + Backend *be; + struct berval dn, prettyDN; + struct berval normalizedDN, parentDN; + + if ( slapi_pblock_get( pb, SLAPI_BACKEND, (void **)&be ) != 0 ) + be = NULL; + + dn.bv_val = (char *)_dn; + dn.bv_len = strlen( _dn ); + + if ( dnPrettyNormal( NULL, &dn, &prettyDN, &normalizedDN, NULL ) != LDAP_SUCCESS ) { + return NULL; + } + + if ( be != NULL && be_issuffix( be, &normalizedDN ) ) { + slapi_ch_free( (void **)&prettyDN.bv_val ); + slapi_ch_free( (void **)&normalizedDN.bv_val ); + return NULL; + } + + dnParent( &prettyDN, &parentDN ); + + slapi_ch_free( (void **)&prettyDN.bv_val ); + slapi_ch_free( (void **)&normalizedDN.bv_val ); + + if ( parentDN.bv_len == 0 ) { + return NULL; + } + + return slapi_ch_strdup( parentDN.bv_val ); +#else + return NULL; +#endif /* LDAP_SLAPI */ +} + char * slapi_dn_ignore_case( char *dn ) { @@ -1273,7 +1402,7 @@ slapi_register_supported_saslmechanism( char *mechanism ) { #ifdef LDAP_SLAPI /* FIXME -- can not add saslmechanism to OpenLDAP dynamically */ - slapi_log_error( SLAPI_LOG_FATAL, "SLAPI_SASL", + slapi_log_error( SLAPI_LOG_FATAL, "slapi_register_supported_saslmechanism", "OpenLDAP does not support dynamic registration of SASL mechanisms\n" ); #endif /* LDAP_SLAPI */ } @@ -1283,7 +1412,7 @@ slapi_get_supported_saslmechanisms( void ) { #ifdef LDAP_SLAPI /* FIXME -- can not get the saslmechanism without a connection. */ - slapi_log_error( SLAPI_LOG_FATAL, "SLAPI_SASL", + slapi_log_error( SLAPI_LOG_FATAL, "slapi_get_supported_saslmechanisms", "can not get the SASL mechanism list " "without a connection\n" ); return NULL; @@ -1442,6 +1571,60 @@ slapi_send_ldap_search_entry( #endif /* LDAP_SLAPI */ } +int +slapi_send_ldap_search_reference( + Slapi_PBlock *pb, + Slapi_Entry *e, + struct berval **references, + LDAPControl **ectrls, + struct berval **v2refs + ) +{ +#ifdef LDAP_SLAPI + Operation *pOp; + SlapReply rs = { REP_SEARCHREF }; + int rc; + + rs.sr_err = LDAP_SUCCESS; + rs.sr_matched = NULL; + rs.sr_text = NULL; + + rc = bvptr2obj( references, &rs.sr_ref ); + if ( rc != LDAP_SUCCESS ) { + return rc; + } + + rs.sr_ctrls = ectrls; + rs.sr_attrs = NULL; + rs.sr_entry = e; + + if ( v2refs != NULL ) { + rc = bvptr2obj( v2refs, &rs.sr_v2ref ); + if ( rc != LDAP_SUCCESS ) { + slapi_ch_free( (void **)&rs.sr_ref ); + return rc; + } + } else { + rs.sr_v2ref = NULL; + } + + if ( slapi_pblock_get( pb, SLAPI_OPERATION, (void *)&pOp ) != 0 ) { + return LDAP_OTHER; + } + + rc = send_search_reference( pOp, &rs ); + + if ( rs.sr_ref != NULL ) + slapi_ch_free( (void **)&rs.sr_ref ); + + if ( rs.sr_v2ref != NULL ) + slapi_ch_free( (void **)&rs.sr_v2ref ); + + return rc; +#else + return -1; +#endif /* LDAP_SLAPI */ +} Slapi_Filter * slapi_str2filter( char *str ) @@ -1930,24 +2113,6 @@ slapi_get_hostname( void ) { #ifdef LDAP_SLAPI char *hn = NULL; - - /* - * FIXME: I'd prefer a different check ... - */ -#if defined _SPARC - hn = (char *)slapi_ch_malloc( MAX_HOSTNAME ); - if ( hn == NULL) { - slapi_log_error( SLAPI_LOG_FATAL, "SLAPI_SYSINFO", - "can't malloc memory for hostname\n" ); - hn = NULL; - - } else if ( sysinfo( SI_HOSTNAME, hn, MAX_HOSTNAME ) < 0 ) { - slapi_log_error( SLAPI_LOG_FATAL, "SLAPI_SYSINFO", - "can't get hostname\n" ); - slapi_ch_free( (void **)&hn ); - hn = NULL; - } -#else /* !_SPARC */ static int been_here = 0; static char *static_hn = NULL; @@ -1955,8 +2120,8 @@ slapi_get_hostname( void ) if ( !been_here ) { static_hn = (char *)slapi_ch_malloc( MAX_HOSTNAME ); if ( static_hn == NULL) { - slapi_log_error( SLAPI_LOG_FATAL, "SLAPI_SYSINFO", - "can't malloc memory for hostname\n" ); + slapi_log_error( SLAPI_LOG_FATAL, "slapi_get_hostname", + "Cannot allocate memory for hostname\n" ); static_hn = NULL; ldap_pvt_thread_mutex_unlock( &slapi_hn_mutex ); @@ -1965,7 +2130,7 @@ slapi_get_hostname( void ) } else { if ( gethostname( static_hn, MAX_HOSTNAME ) != 0 ) { slapi_log_error( SLAPI_LOG_FATAL, - "SLAPI_SYSINFO", + "SLAPI", "can't get hostname\n" ); slapi_ch_free( (void **)&static_hn ); static_hn = NULL; @@ -1981,7 +2146,6 @@ slapi_get_hostname( void ) ldap_pvt_thread_mutex_unlock( &slapi_hn_mutex ); hn = ch_strdup( static_hn ); -#endif /* !_SPARC */ return hn; #else /* LDAP_SLAPI */ @@ -2244,13 +2408,15 @@ static int initConnectionPB( Slapi_PBlock *pb, Connection *conn ) 0 ); if ( connAuthType != NULL ) { rc = slapi_pblock_set(pb, SLAPI_CONN_AUTHMETHOD, (void *)connAuthType); + /* slapi_pblock_set dups this itself */ + slapi_ch_free( (void **)&connAuthType ); if ( rc != LDAP_SUCCESS ) return rc; } if ( conn->c_authz.sai_dn.bv_val != NULL ) { - char *connDn = slapi_ch_strdup(conn->c_authz.sai_dn.bv_val); - rc = slapi_pblock_set(pb, SLAPI_CONN_DN, (void *)connDn); + /* slapi_pblock_set dups this itself */ + rc = slapi_pblock_set(pb, SLAPI_CONN_DN, (void *)conn->c_authz.sai_dn.bv_val); if ( rc != LDAP_SUCCESS ) return rc; } @@ -3405,7 +3571,7 @@ int slapi_x_compute_output_ber(computed_attr_context *c, Slapi_Attr *a, Slapi_En } if ( !access_allowed( op, e, desc, NULL, ACL_READ, &c->cac_acl_state) ) { - slapi_log_error( SLAPI_LOG_ACL, "SLAPI_COMPUTE", + slapi_log_error( SLAPI_LOG_ACL, "slapi_x_compute_output_ber", "acl: access to attribute %s not allowed\n", desc->ad_cname.bv_val ); return 0; @@ -3413,7 +3579,7 @@ int slapi_x_compute_output_ber(computed_attr_context *c, Slapi_Attr *a, Slapi_En rc = ber_printf( ber, "{O[" /*]}*/ , &desc->ad_cname ); if (rc == -1 ) { - slapi_log_error( SLAPI_LOG_BER, "SLAPI_COMPUTE", + slapi_log_error( SLAPI_LOG_BER, "slapi_x_compute_output_ber", "ber_printf failed\n"); return 1; } @@ -3422,15 +3588,15 @@ int slapi_x_compute_output_ber(computed_attr_context *c, Slapi_Attr *a, Slapi_En for ( i = 0; a->a_vals[i].bv_val != NULL; i++ ) { if ( !access_allowed( op, e, desc, &a->a_vals[i], ACL_READ, &c->cac_acl_state)) { - slapi_log_error( SLAPI_LOG_ACL, "SLAPI_COMPUTE", - "slapi_x_compute_output_ber: conn %lu " + slapi_log_error( SLAPI_LOG_ACL, "slapi_x_compute_output_ber", + "conn %lu " "acl: access to %s, value %d not allowed\n", op->o_connid, desc->ad_cname.bv_val, i ); continue; } if (( rc = ber_printf( ber, "O", &a->a_vals[i] )) == -1 ) { - slapi_log_error( SLAPI_LOG_BER, "SLAPI_COMPUTE", + slapi_log_error( SLAPI_LOG_BER, "slapi_x_compute_output_ber", "ber_printf failed\n"); return 1; } @@ -3438,7 +3604,7 @@ int slapi_x_compute_output_ber(computed_attr_context *c, Slapi_Attr *a, Slapi_En } if (( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) { - slapi_log_error( SLAPI_LOG_BER, "SLAPI_COMPUTE", + slapi_log_error( SLAPI_LOG_BER, "slapi_x_compute_output_ber", "ber_printf failed\n" ); return 1; } @@ -3741,8 +3907,6 @@ int slapi_x_access_allowed( Operation *op, return 1; } - slapi_x_pblock_set_operation( op->o_pb, op ); - switch ( access ) { case ACL_WRITE: slap_access |= SLAPI_ACL_ADD | SLAPI_ACL_DELETE | SLAPI_ACL_WRITE; @@ -3766,6 +3930,8 @@ int slapi_x_access_allowed( Operation *op, return 1; } + slapi_x_pblock_set_operation( op->o_pb, op ); + rc = 1; /* default allow policy */ for ( pGetPlugin = tmpPlugin; *pGetPlugin != NULL; pGetPlugin++ ) { diff --git a/servers/slapd/syncrepl.c b/servers/slapd/syncrepl.c index 120c0aad06..360d574087 100644 --- a/servers/slapd/syncrepl.c +++ b/servers/slapd/syncrepl.c @@ -364,9 +364,8 @@ do_syncrepl( op.ors_tlimit = 0; op.ors_attrsonly = 0; op.ors_attrs = NULL; - op.ors_filter = str2filter( def_filter_str = "(objectClass=*)" ); - ber_str2bv( def_filter_str, strlen( def_filter_str ), 1, - &op.ors_filterstr ); + op.ors_filter = str2filter_x( &op, def_filter_str = "(objectClass=*)" ); + ber_str2bv( def_filter_str, 0, 0, &op.ors_filterstr ); si->conn = &conn; conn.c_send_ldap_result = slap_send_ldap_result; @@ -374,22 +373,15 @@ do_syncrepl( conn.c_send_search_reference = slap_send_search_reference; /* get syncrepl cookie of shadow replica from subentry */ - ber_str2bv( si->base, strlen(si->base), 1, &base_bv ); + ber_str2bv( si->base, 0, 0, &base_bv ); dnPrettyNormal( 0, &base_bv, &pbase, &nbase, op.o_tmpmemctx ); sprintf( substr, "cn=syncrepl%d", si->id ); - ber_str2bv( substr, strlen(substr), 1, &sub_bv ); + ber_str2bv( substr, 0, 0, &sub_bv ); dnPrettyNormal( 0, &sub_bv, &psubrdn, &nsubrdn, op.o_tmpmemctx ); - build_new_dn( &op.o_req_dn, &pbase, &psubrdn ); - build_new_dn( &op.o_req_ndn, &nbase, &nsubrdn ); - - ch_free( base_bv.bv_val ); - ch_free( pbase.bv_val ); - ch_free( nbase.bv_val ); - ch_free( sub_bv.bv_val ); - ch_free( psubrdn.bv_val ); - ch_free( nsubrdn.bv_val ); + build_new_dn( &op.o_req_dn, &pbase, &psubrdn, op.o_tmpmemctx ); + build_new_dn( &op.o_req_ndn, &nbase, &nsubrdn, op.o_tmpmemctx ); /* set callback function */ cb.sc_response = cookie_callback; @@ -401,11 +393,6 @@ do_syncrepl( ber_dupbv( &syncCookie_req, si->syncCookie ); - ch_free( op.o_req_dn.bv_val ); - ch_free( op.o_req_ndn.bv_val ); - filter_free( op.ors_filter ); - ch_free( op.ors_filterstr.bv_val ); - psub = be->be_nsuffix[0]; for ( n = 0; si->attrs[ n ] != NULL; n++ ) ; @@ -491,11 +478,11 @@ do_syncrepl( if ( syncCookie.bv_len ) { syncrepl_updateCookie( si, ld, &op, &psub, &syncCookie ); } - if ( rc_efree ) + if ( modlist ) { + slap_mods_free( modlist ); + } + if ( rc_efree ) { entry_free( entry ); - for ( ml = modlist; ml != NULL; ml = mlnext ) { - mlnext = ml->sml_next; - ber_memfree( ml ); } break; @@ -638,17 +625,27 @@ do_syncrepl( break; } + if ( syncCookie.bv_val ) + ch_free( syncCookie.bv_val ); + if ( syncUUID.bv_val ) + ch_free( syncUUID.bv_val ); } ldap_msgfree( res ); } if ( rc == -1 ) { + int errno; + const char *errstr; + + ldap_get_option( ld, LDAP_OPT_ERROR_NUMBER, &errno ); + errstr = ldap_err2string( errno ); + #ifdef NEW_LOGGING LDAP_LOG( OPERATION, ERR, - "do_syncrepl : unknown result\n", 0, 0, 0 ); + "do_syncrepl : %s\n", errstr, 0, 0 ); #else Debug( LDAP_DEBUG_ANY, - "do_syncrepl : unknown result\n", 0, 0, 0 ); + "do_syncrepl : %s\n", errstr, 0, 0 ); #endif } @@ -814,6 +811,7 @@ syncrepl_message_to_entry( ber_scanf( ctrl_ber, "o}", syncCookie ); } ber_free( ctrl_ber, 1 ); + ldap_controls_free( rctrls ); } else { #ifdef NEW_LOGGING LDAP_LOG( OPERATION, ERR,"syncrepl_message_to_entry : " @@ -824,10 +822,7 @@ syncrepl_message_to_entry( #endif } - if ( *syncstate == LDAP_SYNC_PRESENT ) { - e = NULL; - goto done; - } else if ( *syncstate == LDAP_SYNC_DELETE ) { + if ( *syncstate == LDAP_SYNC_PRESENT || *syncstate == LDAP_SYNC_DELETE ) { goto done; } @@ -934,10 +929,11 @@ syncrepl_entry( } if ( syncstate == LDAP_SYNC_PRESENT ) { - if ( e ) + if ( e ) { return 1; - else + } else { return 0; + } } filterstr = (char *) sl_malloc( strlen("entryUUID=") + syncUUID->bv_len + 1, @@ -946,7 +942,6 @@ syncrepl_entry( strcat( filterstr, syncUUID->bv_val ); si->e = e; - si->syncUUID = syncUUID; si->syncUUID_ndn = NULL; filter = str2filter( filterstr ); @@ -1023,9 +1018,8 @@ syncrepl_entry( "syncrepl_entry : be_modify failed (%d)\n", rc, 0, 0 ); #endif - return 1; } - return 0; + return 1; } else if ( rc == LDAP_REFERRAL || rc == LDAP_NO_SUCH_OBJECT ) { syncrepl_add_glue( si, ld, op, e, @@ -1120,7 +1114,9 @@ syncrepl_del_nonpresent( op->ors_filter = filter; ber_str2bv( si->filterstr, strlen( si->filterstr ), 1, &op->ors_filterstr ); + op->o_nocaching = 1; be->be_search( op, &rs ); + op->o_nocaching = 0; if ( !LDAP_LIST_EMPTY( &si->nonpresentlist ) ) { np_list = LDAP_LIST_FIRST( &si->nonpresentlist ); @@ -1293,7 +1289,7 @@ syncrepl_updateCookie( Modifications *ml; Modifications *mlnext; Modifications *mod; - Modifications *modlist; + Modifications *modlist = NULL; Modifications **modtail = &modlist; struct berval* ocbva = NULL; @@ -1307,7 +1303,7 @@ syncrepl_updateCookie( char txtbuf[SLAP_TEXT_BUFLEN]; size_t textlen = sizeof txtbuf; - Entry* e; + Entry* e = NULL; int rc; struct berval sub_bv = { 0, NULL }; @@ -1399,7 +1395,7 @@ syncrepl_updateCookie( e = ( Entry * ) ch_calloc( 1, sizeof( Entry )); - build_new_dn( &sub_bv, pdn, &psubrdn ); + build_new_dn( &sub_bv, pdn, &psubrdn, NULL ); dnPrettyNormal( NULL, &sub_bv, &e->e_name, &e->e_nname, NULL ); ch_free( sub_bv.bv_val ); ch_free( psubrdn.bv_val ); @@ -1477,14 +1473,14 @@ update_cookie_retry: } } - if ( e != NULL ) + if ( e != NULL ) { entry_free( e ); + } done : - for ( ml = modlist; ml != NULL; ml = mlnext ) { - mlnext = ml->sml_next; - free( ml ); + if ( modlist ) { + slap_mods_free( modlist ); } return; @@ -1497,9 +1493,9 @@ avl_ber_bvfree( void *bv ) return; } if ( ((struct berval *)bv)->bv_val != NULL ) { - ber_memfree ( ((struct berval *)bv)->bv_val ); + ch_free ( ((struct berval *)bv)->bv_val ); } - ber_memfree ( (char *) bv ); + ch_free ( (char *) bv ); } static int @@ -1587,6 +1583,8 @@ nonpresent_callback( } else { avl_delete( &si->presentlist, &a->a_vals[0], syncuuid_cmp ); + ch_free( present_uuid->bv_val ); + ch_free( present_uuid ); } return LDAP_SUCCESS; } else { diff --git a/servers/slapd/tools/Makefile.in b/servers/slapd/tools/Makefile.in index dbddeb02c0..081e9aea56 100644 --- a/servers/slapd/tools/Makefile.in +++ b/servers/slapd/tools/Makefile.in @@ -28,7 +28,7 @@ XXLIBS = $(SLAPD_LIBS) \ $(LDBM_LIBS) $(SECURITY_LIBS) \ $(LDIF_LIBS) $(LUTIL_LIBS) XXXLIBS = $(LTHREAD_LIBS) -SLAPI_DEP_LIBS = $(LIBS) $(SLAPI_LIBS) @LIBSLAPITOOLS@ $(MODULES_LIBS) +SLAPI_DEP_LIBS = $(LIBS) @LIBSLAPITOOLS@ @SLAPI_LIBS@ $(MODULES_LIBS) STATIC_DEPENDS=@SLAPD_NO_STATIC@ ../libbackends.a diff --git a/servers/slapd/tools/slapadd.c b/servers/slapd/tools/slapadd.c index 87059a57b5..da006c28ea 100644 --- a/servers/slapd/tools/slapadd.c +++ b/servers/slapd/tools/slapadd.c @@ -268,7 +268,6 @@ main( int argc, char **argv ) if ( SLAP_LASTMOD(be) && update_ctxcsn == SLAP_TOOL_CTXCSN_BATCH && csn.bv_len > 0 ) { Entry *ctxcsn_e; ID ctxcsn_id; - struct berval ctxcsn_rdn = { 0, NULL }; struct berval ctxcsn_ndn = { 0, NULL }; int ret; struct berval bvtext; @@ -278,8 +277,7 @@ main( int argc, char **argv ) bvtext.bv_val = textbuf; bvtext.bv_val[0] = '\0'; - ber_str2bv( "cn=ldapsync", strlen( "cn=ldapsync" ), 0, &ctxcsn_rdn ); - build_new_dn( &ctxcsn_ndn, &be->be_nsuffix[0], &ctxcsn_rdn ); + build_new_dn( &ctxcsn_ndn, &be->be_nsuffix[0], (struct berval *)&slap_ldapsync_cn_bv, NULL ); ctxcsn_id = be->be_dn2id_get( be, &ctxcsn_ndn ); if ( ctxcsn_id == NOID ) { diff --git a/servers/slurpd/config.c b/servers/slurpd/config.c index 6f3df19a0f..3f7a8f8b65 100644 --- a/servers/slurpd/config.c +++ b/servers/slurpd/config.c @@ -64,8 +64,10 @@ slurpd_read_config( FILE *fp; char *line; + if ( cargv == NULL ) { cargv = ch_calloc( ARGS_STEP + 1, sizeof(*cargv) ); cargv_size = ARGS_STEP + 1; + } #ifdef NEW_LOGGING LDAP_LOG ( CONFIG, ARGS, diff --git a/tests/Makefile.in b/tests/Makefile.in index 17eb1592ca..3184786344 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -27,7 +27,7 @@ test-bdb: FORCE @if test "$(BUILD_BDB)" != "no"; then \ echo "Initiating LDAP tests for BDB..." ; \ $(MKDIR) test-db test-repl || true; \ - $(srcdir)/scripts/all $(srcdir) bdb $(BUILD_BDB) $(BUILD_MONITOR) $(BUILD_CACHE) ; \ + $(srcdir)/scripts/all $(srcdir) bdb $(BUILD_BDB) $(BUILD_MONITOR) $(BUILD_CACHE) bdb ; \ else \ echo "run configure with --enable-bdb" ; \ fi @@ -40,7 +40,7 @@ test-hdb: FORCE @if test "$(BUILD_HDB)" != "no" ; then \ echo "Initiating LDAP tests for HDB..." ; \ $(MKDIR) test-db test-repl || true; \ - $(srcdir)/scripts/all $(srcdir) hdb $(BUILD_HDB) $(BUILD_MONITOR) $(BUILD_CACHE) ; \ + $(srcdir)/scripts/all $(srcdir) hdb $(BUILD_HDB) $(BUILD_MONITOR) $(BUILD_CACHE) hdb ; \ else \ echo "run configure with --enable-hdb" ; \ fi @@ -50,10 +50,18 @@ test-ldbm: FORCE @-$(LN_S) $(srcdir)/data . @-$(LN_S) $(top_srcdir)/servers/slapd/schema . @-$(LN_S) ../libraries/liblunicode ucdata - @if test "$(BUILD_LDBM)" != "no"; then \ + @if test "$(BUILD_LDBM)" != "no" ; then \ echo "Initiating LDAP tests for LDBM..." ; \ $(MKDIR) test-db test-repl || true; \ - $(srcdir)/scripts/all $(srcdir) ldbm $(BUILD_LDBM) $(BUILD_MONITOR) $(BUILD_CACHE); \ + if test "$(BUILD_BDB)" != "no"; then \ + $(srcdir)/scripts/all $(srcdir) ldbm $(BUILD_LDBM) $(BUILD_MONITOR) $(BUILD_CACHE) bdb ; \ + else \ + if test "$(BUILD_HDB)" != "no"; then \ + $(srcdir)/scripts/all $(srcdir) ldbm $(BUILD_LDBM) $(BUILD_MONITOR) $(BUILD_CACHE) hdb ; \ + else \ + $(srcdir)/scripts/all $(srcdir) ldbm $(BUILD_LDBM) $(BUILD_MONITOR) $(BUILD_CACHE) no ; \ + fi ; \ + fi ; \ else \ echo "run configure with --enable-ldbm" ; \ fi diff --git a/tests/data/do_search.0 b/tests/data/do_search.0 index 6e9cd1f3fa..ea0e29b643 100644 --- a/tests/data/do_search.0 +++ b/tests/data/do_search.0 @@ -1,5 +1,10 @@ +o=university of michigan,c=us cn=Barbara Jensen +ou=people,o=university of michigan,c=us cn=Bjorn Jensen +ou=people,o=university of michigan,c=us cn=James A Jones 1 +o=university of michigan,c=us cn=Bjorn Jensen +o=university of michigan,c=us cn=Alumni Assoc Staff diff --git a/tests/progs/slapd-tester.c b/tests/progs/slapd-tester.c index a2a96f415a..4c5c9e2374 100644 --- a/tests/progs/slapd-tester.c +++ b/tests/progs/slapd-tester.c @@ -35,7 +35,7 @@ #define TMODRDNFILE "do_modrdn.0" static char *get_file_name( char *dirname, char *filename ); -static int get_search_filters( char *filename, char *filters[] ); +static int get_search_filters( char *filename, char *filters[], char *bases[] ); static int get_read_entries( char *filename, char *entries[] ); static void fork_child( char *prog, char **args ); static void wait4kids( int nkidval ); @@ -54,7 +54,7 @@ static char argbuf[BUFSIZ]; static void usage( char *name ) { - fprintf( stderr, "usage: %s [-h ] -p -D -w -d -b [-j ] [-l ] -P \n", name ); + fprintf( stderr, "usage: %s -H | ([-h ] -p ) -D -w -d [-j ] [-l ] -P \n", name ); exit( EXIT_FAILURE ); } @@ -68,13 +68,13 @@ main( int argc, char **argv ) char *manager = NULL; char *passwd = NULL; char *dirname = NULL; - char *sbase = NULL; char *progdir = NULL; char *loops = LOOPS; DIR *datadir; struct dirent *file; char *sfile = NULL; char *sreqs[MAXREQS]; + char *sbase[MAXREQS]; int snum = 0; char *rfile = NULL; char *rreqs[MAXREQS]; @@ -119,10 +119,6 @@ main( int argc, char **argv ) passwd = ArgDup( optarg ); break; - case 'b': /* the base DN */ - sbase = ArgDup( optarg ); - break; - case 'd': /* data directory */ dirname = strdup( optarg ); break; @@ -145,7 +141,7 @@ main( int argc, char **argv ) } } - if (( dirname == NULL ) || ( sbase == NULL ) || ( port == NULL && uri == NULL ) || + if (( dirname == NULL ) || ( port == NULL && uri == NULL ) || ( manager == NULL ) || ( passwd == NULL ) || ( progdir == NULL )) usage( argv[0] ); @@ -184,7 +180,7 @@ main( int argc, char **argv ) /* look for search requests */ if ( sfile ) { - snum = get_search_filters( sfile, sreqs ); + snum = get_search_filters( sfile, sreqs, sbase ); } /* look for read requests */ @@ -214,10 +210,10 @@ main( int argc, char **argv ) sargs[sanum++] = "-p"; sargs[sanum++] = port; } - sargs[sanum++] = "-b"; - sargs[sanum++] = sbase; sargs[sanum++] = "-l"; sargs[sanum++] = loops; + sargs[sanum++] = "-b"; + sargs[sanum++] = NULL; /* will hold the search base */ sargs[sanum++] = "-f"; sargs[sanum++] = NULL; /* will hold the search request */ sargs[sanum++] = NULL; @@ -304,6 +300,7 @@ main( int argc, char **argv ) if ( j < snum ) { sargs[sanum - 2] = sreqs[j]; + sargs[sanum - 4] = sbase[j]; fork_child( scmd, sargs ); } @@ -348,7 +345,7 @@ get_file_name( char *dirname, char *filename ) static int -get_search_filters( char *filename, char *filters[] ) +get_search_filters( char *filename, char *filters[], char *bases[] ) { FILE *fp; int filter = 0; @@ -361,6 +358,11 @@ get_search_filters( char *filename, char *filters[] ) if (( nl = strchr( line, '\r' )) || ( nl = strchr( line, '\n' ))) *nl = '\0'; + bases[filter] = ArgDup( line ); + fgets( line, BUFSIZ, fp ); + if (( nl = strchr( line, '\r' )) || ( nl = strchr( line, '\n' ))) + *nl = '\0'; + filters[filter++] = ArgDup( line ); } diff --git a/tests/scripts/all b/tests/scripts/all index b0b9a94f99..46257d3690 100755 --- a/tests/scripts/all +++ b/tests/scripts/all @@ -44,12 +44,18 @@ else PROXYCACHE=$1; shift fi +if test $# -eq 0 ; then + SYNCREPL=no +else + SYNCREPL=$1; shift +fi + TB=`$SHTOOL echo -e "%B"` TN=`$SHTOOL echo -e "%b"` for CMD in $SRCDIR/scripts/test*; do echo ">>>>> Starting ${TB}`basename $CMD`${TN} ..." - $CMD $SRCDIR $BACKEND $BACKENDTYPE $MONITOR $PROXYCACHE + $CMD $SRCDIR $BACKEND $BACKENDTYPE $MONITOR $PROXYCACHE $SYNCREPL RC=$? if test $RC -eq 0 ; then echo ">>>>> $CMD completed ${TB}OK${TN}." diff --git a/tests/scripts/args.sh b/tests/scripts/args.sh index bef77b0666..b13e8af097 100755 --- a/tests/scripts/args.sh +++ b/tests/scripts/args.sh @@ -20,6 +20,11 @@ if test $# -ge 1 ; then PROXYCACHE=$1; shift fi +SYNCREPL=no +if test $# -ge 1 ; then + SYNCREPL=$1; shift +fi + WAIT=0 if test $# -ge 1 ; then WAIT=1; shift diff --git a/tests/scripts/test008-concurrency b/tests/scripts/test008-concurrency index 4e0c7af7d2..23f67993a3 100755 --- a/tests/scripts/test008-concurrency +++ b/tests/scripts/test008-concurrency @@ -50,7 +50,7 @@ for i in 0 1 2 3 4 5; do done echo "Using tester for concurrent server access..." -$SLAPDTESTER -b "$BASEDN" -P "$PROGDIR" -d "$DATADIR" -h $LOCALHOST -p $PORT -D "$MANAGERDN" -w $PASSWD -l 50 +$SLAPDTESTER -P "$PROGDIR" -d "$DATADIR" -h $LOCALHOST -p $PORT -D "$MANAGERDN" -w $PASSWD -l 50 RC=$? if test $RC != 0 ; then diff --git a/tests/scripts/test017-syncreplication-refresh b/tests/scripts/test017-syncreplication-refresh index be59b12298..aed3a98050 100755 --- a/tests/scripts/test017-syncreplication-refresh +++ b/tests/scripts/test017-syncreplication-refresh @@ -28,7 +28,11 @@ mkdir $R1REPLDIR SAVE=$BACKEND if test $BACKEND = ldbm; then - BACKEND=bdb + if test $SYNCREPL = no; then + echo "Sync replication requires back-bdb or back-hdb" + exit 0 + fi + BACKEND=$SYNCREPL fi echo "Starting master slapd on TCP/IP port $PORT..." . $CONFFILTER $BACKEND $MONITORDB < $SRMASTERCONF > $DBCONF diff --git a/tests/scripts/test018-syncreplication-persist b/tests/scripts/test018-syncreplication-persist index 66f5637673..0a62c9dcec 100755 --- a/tests/scripts/test018-syncreplication-persist +++ b/tests/scripts/test018-syncreplication-persist @@ -28,7 +28,11 @@ mkdir $P1REPLDIR SAVE=$BACKEND if test $BACKEND = ldbm; then - BACKEND=bdb + if test $SYNCREPL = no; then + echo "Sync replication requires back-bdb or back-hdb" + exit 0 + fi + BACKEND=$SYNCREPL fi echo "Starting master slapd on TCP/IP port $PORT..." . $CONFFILTER $BACKEND $MONITORDB < $SRMASTERCONF > $DBCONF diff --git a/tests/scripts/test020-syncreplication-cascading b/tests/scripts/test020-syncreplication-cascading index 7fff42ec59..bae0f71bfa 100755 --- a/tests/scripts/test020-syncreplication-cascading +++ b/tests/scripts/test020-syncreplication-cascading @@ -40,7 +40,11 @@ mkdir $P3REPLDIR SAVE=$BACKEND if test $BACKEND = ldbm; then - BACKEND=bdb + if test $SYNCREPL = no; then + echo "Sync replication requires back-bdb or back-hdb" + exit 0 + fi + BACKEND=$SYNCREPL fi echo "Starting master slapd on TCP/IP port $PORT..." . $CONFFILTER $BACKEND $MONITORDB < $SRMASTERCONF > $DBCONF @@ -78,7 +82,13 @@ if test $RC != 0 ; then fi SAVE=$BACKEND -BACKEND=bdb +if test $BACKEND = ldbm; then + if test $SYNCREPL = no; then + echo "Sync replication requires back-bdb or back-hdb" + exit 0 + fi + BACKEND=$SYNCREPL +fi echo "Starting R1 slave slapd on TCP/IP port $R1SLAVEPORT..." . $CONFFILTER $BACKEND $MONITORDB < $R1SRSLAVECONF > $R1REPLCONF $SLAPD -f $R1REPLCONF -h $R1SLAVEURI -d $LVL $TIMING > $R1SLAVELOG 2>&1 & @@ -129,7 +139,13 @@ echo "Waiting for the R2 slave to replicate..." sleep 10 SAVE=$BACKEND -BACKEND=bdb +if test $BACKEND = ldbm; then + if test $SYNCREPL = no; then + echo "Sync replication requires back-bdb or back-hdb" + exit 0 + fi + BACKEND=$SYNCREPL +fi echo "Starting P1 slave slapd on TCP/IP port $P1SLAVEPORT..." . $CONFFILTER $BACKEND $MONITORDB < $P1SRSLAVECONF > $P1REPLCONF $SLAPD -f $P1REPLCONF -h $P1SLAVEURI -d $LVL $TIMING > $P1SLAVELOG 2>&1 &