From: Howard Chu Date: Thu, 4 Dec 2003 22:38:54 +0000 (+0000) Subject: Moved ldbm into back-ldbm. No more libldbm. X-Git-Tag: OPENLDAP_REL_ENG_2_1_MP~278 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=3152932e96dd938201e8ac3c5ece7c2a2f73d3f7;p=openldap Moved ldbm into back-ldbm. No more libldbm. --- diff --git a/build/top.mk b/build/top.mk index 0afde43323..40dc1da706 100644 --- a/build/top.mk +++ b/build/top.mk @@ -152,10 +152,6 @@ 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_LIBLDBM_A = $(LDAP_LIBLDBM_A_@BUILD_LDBM@) LDAP_LIBREWRITE_A = $(LDAP_LIBDIR)/librewrite/librewrite.a LDAP_LIBLUNICODE_A = $(LDAP_LIBDIR)/liblunicode/liblunicode.a LDAP_LIBLUTIL_A = $(LDAP_LIBDIR)/liblutil/liblutil.a @@ -164,8 +160,7 @@ LDAP_L = $(LDAP_LIBLUTIL_A) \ $(LDAP_LIBLDAP_LA) $(LDAP_LIBLBER_LA) SLURPD_L = $(LDAP_LIBLUTIL_A) \ $(LDAP_LIBLDAP_R_LA) $(LDAP_LIBLBER_LA) -SLAPD_L = $(LDAP_LIBLDBM_A) \ - $(LDAP_LIBLUNICODE_A) $(LDAP_LIBREWRITE_A) \ +SLAPD_L = $(LDAP_LIBLUNICODE_A) $(LDAP_LIBREWRITE_A) \ $(SLURPD_L) WRAP_LIBS = @WRAP_LIBS@ diff --git a/include/ldbm.h b/include/ldbm.h deleted file mode 100644 index 0d6e6ffe5d..0000000000 --- a/include/ldbm.h +++ /dev/null @@ -1,278 +0,0 @@ -/* ldbm.h - ldap dbm compatibility routine header file */ -/* $OpenLDAP$ */ -/* This work is part of OpenLDAP Software . - * - * Copyright 1998-2003 The OpenLDAP Foundation. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted only as authorized by the OpenLDAP - * Public License. - * - * A copy of this license is available in file LICENSE in the - * top-level directory of the distribution or, alternatively, at - * . - */ - -#ifndef _LDBM_H_ -#define _LDBM_H_ - -#include -#include - -/* dummy DB_ENV for non Berkeley DB */ -#if !defined( LDBM_USE_DBBTREE ) && !defined( LDBM_USE_DBHASH ) -# define DB_ENV void -#endif - -#if defined( LDBM_USE_DBBTREE ) || defined( LDBM_USE_DBHASH ) - -/***************************************************************** - * * - * use berkeley db btree or hash package * - * * - *****************************************************************/ -#include -#include -#include - -#ifdef HAVE_DB_185_H -# include -#else -# ifdef HAVE_DB1_DB_H -# include -# else -# include -# endif -#endif - -#ifndef DB_VERSION_MAJOR -# define DB_VERSION_MAJOR 1 -#endif -#ifndef DB_VERSION_MINOR -# define DB_VERSION_MINOR 85 -#endif - -#if DB_VERSION_MAJOR >= 2 -# define R_NOOVERWRITE DB_NOOVERWRITE -# ifndef DEFAULT_DB_PAGE_SIZE -# define DEFAULT_DB_PAGE_SIZE 4096 -# endif -#else -# define DB_ENV void -#endif - - -LDAP_BEGIN_DECL - -typedef DBT Datum; -#define dsize size -#define dptr data - -typedef DB *LDBM; - - -/* for ldbm_open */ -#if DB_VERSION_MAJOR >= 2 -typedef DBC LDBMCursor; - -# define LDBM_READER DB_RDONLY -# define LDBM_WRITER 0x00000 /* hopefully */ -# if defined( HAVE_BERKELEY_DB_THREAD ) -# define LDBM_WRCREAT (DB_NOMMAP|DB_CREATE|DB_THREAD) -# define LDBM_NEWDB (DB_TRUNCATE|DB_CREATE|DB_THREAD) -# else -# define LDBM_WRCREAT (DB_NOMMAP|DB_CREATE) -# define LDBM_NEWDB (DB_TRUNCATE|DB_CREATE) -# endif - -#else -typedef void LDBMCursor; -# define LDBM_READER O_RDONLY -# define LDBM_WRITER O_RDWR -# define LDBM_WRCREAT (O_RDWR|O_CREAT) -# define LDBM_NEWDB (O_RDWR|O_TRUNC|O_CREAT) -#endif - -LDAP_END_DECL - -/* for ldbm_open */ -#define LDBM_NOSYNC 0 -#define LDBM_SYNC 0 -#define LDBM_LOCKING 0 -#define LDBM_NOLOCKING 0 - -/* for ldbm_insert */ -#define LDBM_INSERT R_NOOVERWRITE -#define LDBM_REPLACE 0 - -#ifdef LDBM_USE_DBBTREE -# define LDBM_ORDERED 1 -# define LDBM_SUFFIX ".dbb" -# define DB_TYPE DB_BTREE -#else -# define LDBM_SUFFIX ".dbh" -# define DB_TYPE DB_HASH -#endif - -#elif defined( HAVE_GDBM ) - -/***************************************************************** - * * - * use gdbm if possible * - * * - *****************************************************************/ - -#include - -LDAP_BEGIN_DECL - -typedef datum Datum; -typedef Datum LDBMCursor; -typedef GDBM_FILE LDBM; - -LDAP_END_DECL - -/* for ldbm_open */ -#define LDBM_READER GDBM_READER -#define LDBM_WRITER GDBM_WRITER -#define LDBM_WRCREAT GDBM_WRCREAT -#define LDBM_NEWDB GDBM_NEWDB - -#ifdef GDBM_FAST -#define LDBM_NOSYNC GDBM_FAST -#else -#define LDBM_NOSYNC 0 -#endif - -#ifdef GDBM_SYNC -#define LDBM_SYNC GDBM_SYNC -#else -#define LDBM_SYNC 0 -#endif - -#define LDBM_LOCKING 0 -#ifdef GDBM_NOLOCK -#define LDBM_NOLOCKING GDBM_NOLOCK -#else -#define LDBM_NOLOCKING 0 -#endif - -#define LDBM_SUFFIX ".gdbm" - -/* for ldbm_insert */ -#define LDBM_INSERT GDBM_INSERT -#define LDBM_REPLACE GDBM_REPLACE - -#elif defined( HAVE_MDBM ) - -/***************************************************************** - * * - * use mdbm if possible * - * * - *****************************************************************/ - -#include - -LDAP_BEGIN_DECL - -typedef datum Datum; -typedef int LDBMCursor; -typedef MDBM *LDBM; - -LDAP_END_DECL - -#include -#include -#include - -/* for ldbm_open */ -#define LDBM_READER O_RDONLY -#define LDBM_WRITER O_RDWR -#define LDBM_WRCREAT (O_RDWR|O_CREAT) -#define LDBM_NEWDB (O_RDWR|O_TRUNC|O_CREAT) - -#define LDBM_SYNC 0 -#define LDBM_NOSYNC 0 -#define LDBM_LOCKING 0 -#define LDBM_NOLOCKING 0 - -#define LDBM_SUFFIX ".mdbm" - -/* for ldbm_insert */ -#define LDBM_INSERT MDBM_INSERT -#define LDBM_REPLACE MDBM_REPLACE - -#elif defined( HAVE_NDBM ) - -/***************************************************************** - * * - * if none of the above use ndbm, the standard unix thing * - * * - *****************************************************************/ - -#include - -#ifdef HAVE_FCNTL_H -#include -#endif - -LDAP_BEGIN_DECL - -typedef datum Datum; -typedef int LDBMCursor; -typedef DBM *LDBM; - -LDAP_END_DECL - -/* for ldbm_open */ -#define LDBM_READER O_RDONLY -#define LDBM_WRITER O_WRONLY -#define LDBM_WRCREAT (O_RDWR|O_CREAT) -#define LDBM_NEWDB (O_RDWR|O_TRUNC|O_CREAT) - -#define LDBM_NOSYNC 0 -#define LDBM_SYNC 0 -#define LDBM_NOLOCK 0 -#define LDBM_SYNC 0 - -#define LDBM_SUFFIX ".ndbm" - -/* for ldbm_insert */ -#define LDBM_INSERT DBM_INSERT -#define LDBM_REPLACE DBM_REPLACE - -#endif - -LDAP_BEGIN_DECL - -LDAP_LDBM_F (int) ldbm_initialize( const char * ); -LDAP_LDBM_F (int) ldbm_shutdown( void ); - -LDAP_LDBM_F (DB_ENV*) ldbm_initialize_env(const char *, int dbcachesize, int *envdirok); -LDAP_LDBM_F (void) ldbm_shutdown_env(DB_ENV *); - -LDAP_LDBM_F (int) ldbm_errno( LDBM ldbm ); -LDAP_LDBM_F (LDBM) ldbm_open( DB_ENV *env, char *name, int rw, int mode, int dbcachesize ); -LDAP_LDBM_F (void) ldbm_close( LDBM ldbm ); -LDAP_LDBM_F (void) ldbm_sync( LDBM ldbm ); -LDAP_LDBM_F (void) ldbm_datum_free( LDBM ldbm, Datum data ); -LDAP_LDBM_F (Datum) ldbm_datum_dup( LDBM ldbm, Datum data ); -LDAP_LDBM_F (Datum) ldbm_fetch( LDBM ldbm, Datum key ); -LDAP_LDBM_F (int) ldbm_store( LDBM ldbm, Datum key, Datum data, int flags ); -LDAP_LDBM_F (int) ldbm_delete( LDBM ldbm, Datum key ); - -LDAP_LDBM_F (Datum) ldbm_firstkey( LDBM ldbm, LDBMCursor **cursor ); -LDAP_LDBM_F (Datum) ldbm_nextkey( LDBM ldbm, Datum key, LDBMCursor *cursor ); - -/* initialization of Datum structures */ -#if defined( HAVE_BERKELEY_DB ) && (DB_VERSION_MAJOR >= 2) - LDAP_LDBM_F (void *) ldbm_malloc( size_t size ); -# define ldbm_datum_init(d) ((void)memset(&(d), '\0', sizeof(Datum))) -#else -# define ldbm_datum_init(d) ((void)0) -#endif /* HAVE_BERKELEY_DB */ - -LDAP_END_DECL - -#endif /* _ldbm_h_ */ diff --git a/libraries/libldbm/Makefile.in b/libraries/libldbm/Makefile.in deleted file mode 100644 index 11ecd5de1c..0000000000 --- a/libraries/libldbm/Makefile.in +++ /dev/null @@ -1,25 +0,0 @@ -# Makefile for -lldbm -# $OpenLDAP$ -## This work is part of OpenLDAP Software . -## -## Copyright 1998-2003 The OpenLDAP Foundation. -## All rights reserved. -## -## Redistribution and use in source and binary forms, with or without -## modification, are permitted only as authorized by the OpenLDAP -## Public License. -## -## A copy of this license is available in the file LICENSE in the -## top-level directory of the distribution or, alternatively, at -## . - -LIBRARY = libldbm.a -SRCS = ldbm.c -OBJS = ldbm.o - -LDAP_INCDIR= ../../include -LDAP_LIBDIR= ../../libraries - -XLIBS = $(LIBRARY) -XXLIBS = $(LDBM_LIBS) - diff --git a/libraries/libldbm/ldbm.c b/libraries/libldbm/ldbm.c deleted file mode 100644 index 11e7ea0cc5..0000000000 --- a/libraries/libldbm/ldbm.c +++ /dev/null @@ -1,1199 +0,0 @@ -/* ldbm.c - ldap dbm compatibility routines */ -/* $OpenLDAP$ */ -/* This work is part of OpenLDAP Software . - * - * Copyright 1998-2003 The OpenLDAP Foundation. - * Portions Copyright 1998-2003 Kurt D. Zeilenga. - * Portions Copyright 1998-2001 Net Boolean Incorporated. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted only as authorized by the OpenLDAP - * Public License. - * - * A copy of this license is available in the file LICENSE in the - * top-level directory of the distribution or, alternatively, at - * . - */ -/* ACKNOWLEDGEMENTS: - * This work was originally developed by the University of Michigan - * (as part of U-MICH LDAP). Additional significant contributors - * include: - * Gary Williams - * Howard Chu - * Juan Gomez - * Kurt D. Zeilenga - * Kurt Spanier - * Mark Whitehouse - * Randy Kundee - */ - -#include "portable.h" - -#ifdef SLAPD_LDBM - -#include - -#include -#include -#include - -#include "ldbm.h" -#include "ldap_pvt_thread.h" - -void -ldbm_datum_free( LDBM ldbm, Datum data ) -{ - if ( data.dptr ) { - free( data.dptr ); - memset( &data, '\0', sizeof( Datum )); - data.dptr = NULL; - } -} - -Datum -ldbm_datum_dup( LDBM ldbm, Datum data ) -{ - Datum dup; - - ldbm_datum_init( dup ); - - if ( data.dsize == 0 ) { - dup.dsize = 0; - dup.dptr = NULL; - - return( dup ); - } - dup.dsize = data.dsize; - - if ( (dup.dptr = (char *) malloc( data.dsize )) != NULL ) { - AC_MEMCPY( dup.dptr, data.dptr, data.dsize ); - } - - return( dup ); -} - -static int ldbm_initialized = 0; - -#if defined( USE_BERKELEY_CDB ) - /* not currently supported */ -#define LDBM_RWLOCK_INIT ((void) 0) -#define LDBM_RWLOCK_DESTROY ((void) 0) -#define LDBM_WLOCK ((void) 0) -#define LDBM_WUNLOCK ((void) 0) -#define LDBM_RLOCK ((void) 0) -#define LDBM_RUNLOCK ((void) 0) - -#elif defined( HAVE_BERKELEY_DB_THREAD ) -static ldap_pvt_thread_rdwr_t ldbm_big_rdwr; -#define LDBM_RWLOCK_INIT (ldap_pvt_thread_rdwr_init( &ldbm_big_rdwr )) -#define LDBM_RWLOCK_DESTROY (ldap_pvt_thread_rdwr_destroy( &ldbm_big_rdwr )) -#define LDBM_WLOCK (ldap_pvt_thread_rdwr_wlock(&ldbm_big_rdwr)) -#define LDBM_WUNLOCK (ldap_pvt_thread_rdwr_wunlock(&ldbm_big_rdwr)) -#define LDBM_RLOCK (ldap_pvt_thread_rdwr_rlock(&ldbm_big_rdwr)) -#define LDBM_RUNLOCK (ldap_pvt_thread_rdwr_runlock(&ldbm_big_rdwr)) - -#else -static ldap_pvt_thread_mutex_t ldbm_big_mutex; -#define LDBM_RWLOCK_INIT (ldap_pvt_thread_mutex_init( &ldbm_big_mutex )) -#define LDBM_RWLOCK_DESTROY (ldap_pvt_thread_mutex_destroy( &ldbm_big_mutex )) -#define LDBM_WLOCK (ldap_pvt_thread_mutex_lock(&ldbm_big_mutex)) -#define LDBM_WUNLOCK (ldap_pvt_thread_mutex_unlock(&ldbm_big_mutex)) -#define LDBM_RLOCK LDBM_WLOCK -#define LDBM_RUNLOCK LDBM_WUNLOCK -#endif - -#if !defined( HAVE_BERKELEY_DB ) || (DB_VERSION_MAJOR < 3) - /* a dbEnv for BERKELEYv2 */ -DB_ENV *ldbm_Env = NULL; /* real or fake, depending on db and version */ -#endif - -/* Let's make the version comparisons a little easier... */ -#undef DB_VERSION_X -#ifdef HAVE_BERKELEY_DB -#define DB_VERSION_X ((DB_VERSION_MAJOR<<16)|(DB_VERSION_MINOR<<8)|DB_VERSION_PATCH) -#endif - -/******************************************************************* - * * - * Create some special functions to initialize Berkeley DB for * - * versions greater than 2. * - * * - *******************************************************************/ -#if defined( HAVE_BERKELEY_DB ) && (DB_VERSION_MAJOR >= 2) - -void * -ldbm_malloc( size_t size ) -{ - /* likely should use ber_mem* routines */ - return( calloc( 1, size ) ); -} - -#ifdef LDAP_SYSLOG -#include -#endif - -static void -ldbm_db_errcall( const char *prefix, char *message ) -{ -#ifdef LDAP_SYSLOG - syslog( LOG_INFO, "ldbm: %s %s", prefix, message ); -#endif -} - -int ldbm_initialize( const char* home ) -{ -#if DB_VERSION_MAJOR < 3 - int err; - u_int32_t envFlags; -#endif - - if(ldbm_initialized++) return 1; - - { - char *version; - int major, minor, patch; - version = db_version( &major, &minor, &patch ); - - if( major != DB_VERSION_MAJOR || - minor < DB_VERSION_MINOR ) - { -#ifdef LDAP_SYSLOG - syslog( LOG_INFO, - "ldbm_initialize(): version mismatch\nexpected: %s\ngot: %s\n", - DB_VERSION_STRING, version ); -#endif - return 1; - } - } - -#if DB_VERSION_MAJOR < 3 - ldbm_Env = calloc( 1, sizeof( DB_ENV )); - - if( ldbm_Env == NULL ) return 1; - - ldbm_Env->db_errcall = ldbm_db_errcall; - ldbm_Env->db_errpfx = "==>"; - - envFlags = DB_CREATE | DB_USE_ENVIRON; - - /* add optional flags */ -#ifdef DB_PRIVATE - envFlags |= DB_PRIVATE; -#endif -#ifdef HAVE_BERKELEY_DB_THREAD - envFlags |= DB_THREAD; -#endif - - err = db_appinit( home, NULL, ldbm_Env, envFlags ); - - if ( err ) { -#ifdef LDAP_SYSLOG - syslog( LOG_INFO, "ldbm_initialize(): " - "FATAL error (%d) in db_appinit()\n", err ); -#endif - return( 1 ); - } -#endif - - LDBM_RWLOCK_INIT; - - return 0; -} - -int ldbm_shutdown( void ) -{ - if( !ldbm_initialized ) return 1; - -#if DB_VERSION_MAJOR < 3 - db_appexit( ldbm_Env ); -#endif - - LDBM_RWLOCK_DESTROY; - return 0; -} - -#else /* some DB other than Berkeley V2 or greater */ - -int ldbm_initialize( const char * home ) -{ - if(ldbm_initialized++) return 1; - - LDBM_RWLOCK_INIT; - - return 0; -} - -int ldbm_shutdown( void ) -{ - if( !ldbm_initialized ) return 1; - - LDBM_RWLOCK_DESTROY; - - return 0; -} - -#endif /* HAVE_BERKELEY_DB */ - -#if defined( HAVE_BERKELEY_DB ) && (DB_VERSION_MAJOR >= 3) - -DB_ENV *ldbm_initialize_env(const char *home, int dbcachesize, int *envdirok) -{ - DB_ENV *env = NULL; - int err; - u_int32_t envFlags; -#ifdef HAVE_EBCDIC - char n2[2048]; -#endif - - err = db_env_create( &env, 0 ); - - if ( err ) { -#ifdef LDAP_SYSLOG - syslog( LOG_INFO, "ldbm_initialize_env(): " - "FATAL error in db_env_create() : %s (%d)\n", - db_strerror( err ), err ); -#endif - return NULL; - } - -#if DB_VERSION_X >= 0x030300 - /* This interface appeared in 3.3 */ - env->set_alloc( env, ldbm_malloc, NULL, NULL ); -#endif - - env->set_errcall( env, ldbm_db_errcall ); - env->set_errpfx( env, "==>" ); - if (dbcachesize) { - env->set_cachesize( env, 0, dbcachesize, 0 ); - } - - envFlags = DB_CREATE | DB_INIT_MPOOL | DB_USE_ENVIRON; -#ifdef DB_PRIVATE - envFlags |= DB_PRIVATE; -#endif -#ifdef DB_MPOOL_PRIVATE - envFlags |= DB_MPOOL_PRIVATE; -#endif -#ifdef HAVE_BERKELEY_DB_THREAD - envFlags |= DB_THREAD; -#endif - -#ifdef HAVE_EBCDIC - strncpy(n2, home, sizeof(n2)-1); - n2[sizeof(n2)-1] = '\0'; - __atoe(n2); - home = n2; -#endif -#if DB_VERSION_X >= 0x030100 - err = env->open( env, home, envFlags, 0 ); -#else - /* 3.0.x requires an extra argument */ - err = env->open( env, home, NULL, envFlags, 0 ); -#endif - - if ( err != 0 ) { -#ifdef LDAP_SYSLOG - syslog( LOG_INFO, "ldbm_initialize_env(): " - "FATAL error in dbEnv->open() : %s (%d)\n", - db_strerror( err ), err ); -#endif - env->close( env, 0 ); - return NULL; - } - - *envdirok = 1; - return env; -} - -void ldbm_shutdown_env(DB_ENV *env) -{ - env->close( env, 0 ); -} - -#else - -DB_ENV *ldbm_initialize_env(const char *home, int dbcachesize, int *envdirok) -{ - return ldbm_Env; -} - -void ldbm_shutdown_env(DB_ENV *env) -{ -} - -#endif - -#if defined( LDBM_USE_DBHASH ) || defined( LDBM_USE_DBBTREE ) - -/***************************************************************** - * * - * use berkeley db hash or btree package * - * * - *****************************************************************/ - -LDBM -ldbm_open( DB_ENV *env, char *name, int rw, int mode, int dbcachesize ) -{ - LDBM ret = NULL; -#ifdef HAVE_EBCDIC - char n2[2048]; -#endif - -#if DB_VERSION_MAJOR >= 3 - int err; - - LDBM_WLOCK; - - err = db_create( &ret, env, 0 ); - if ( err != 0 ) { - (void)ret->close(ret, 0); - LDBM_WUNLOCK; - - return NULL; - } - -#if DB_VERSION_X < 0x030300 - ret->set_malloc( ret, ldbm_malloc ); -#endif - - ret->set_pagesize( ret, DEFAULT_DB_PAGE_SIZE ); - - /* likely should use ber_mem* routines */ - -#ifdef HAVE_EBCDIC - strncpy(n2, name, sizeof(n2)-1); - n2[sizeof(n2)-1] = '\0'; - __atoe(n2); - name = n2; -#endif -#if DB_VERSION_X >= 0x040111 - err = ret->open( ret, NULL, name, NULL, DB_TYPE, rw, mode); -#else - err = ret->open( ret, name, NULL, DB_TYPE, rw, mode); -#endif - - if ( err != 0 ) { - int tmp = errno; - (void)ret->close(ret, 0); - errno = tmp; - - LDBM_WUNLOCK; - return NULL; - } - - LDBM_WUNLOCK; - -#elif DB_VERSION_MAJOR >= 2 - DB_INFO dbinfo; - - memset( &dbinfo, '\0', sizeof( dbinfo )); - -#if DB_VERSION_MAJOR == 2 && DB_VERSION_MINOR == 4 - /* - * BerkeleyDB 2.4 do not allow db_cachesize - * to be specified if an DB_ENV is. - */ -#else - /* set db_cachesize of MPOOL is NOT being used. */ - if (( ldbm_Env == NULL ) || ( ldbm_Env->mp_info == NULL )) { - dbinfo.db_cachesize = dbcachesize; - } -#endif - - dbinfo.db_pagesize = DEFAULT_DB_PAGE_SIZE; - dbinfo.db_malloc = ldbm_malloc; - - LDBM_WLOCK; - (void) db_open( name, DB_TYPE, rw, mode, ldbm_Env, &dbinfo, &ret ); - LDBM_WUNLOCK; - -#else - void *info; - BTREEINFO binfo; - HASHINFO hinfo; - - if ( DB_TYPE == DB_HASH ) { - memset( (char *) &hinfo, '\0', sizeof(hinfo) ); - hinfo.cachesize = dbcachesize; - info = &hinfo; - } else if ( DB_TYPE == DB_BTREE ) { - memset( (char *) &binfo, '\0', sizeof(binfo) ); - binfo.cachesize = dbcachesize; - info = &binfo; - } else { - info = NULL; - } - - LDBM_WLOCK; - ret = dbopen( name, rw, mode, DB_TYPE, info ); - LDBM_WUNLOCK; -#endif - - return ret; -} - -void -ldbm_close( LDBM ldbm ) -{ - LDBM_WLOCK; -#if DB_VERSION_MAJOR >= 2 - ldbm->close( ldbm, 0 ); -#else - ldbm->close( ldbm ); -#endif - LDBM_WUNLOCK; -} - -void -ldbm_sync( LDBM ldbm ) -{ - LDBM_WLOCK; - (*ldbm->sync)( ldbm, 0 ); - LDBM_WUNLOCK; -} - -Datum -ldbm_fetch( LDBM ldbm, Datum key ) -{ - Datum data; - int rc; - - LDBM_RLOCK; - -#if DB_VERSION_MAJOR >= 2 - ldbm_datum_init( data ); - - data.flags = DB_DBT_MALLOC; - - if ( (rc = ldbm->get( ldbm, NULL, &key, &data, 0 )) != 0 ) { - ldbm_datum_free( ldbm, data ); - data.dptr = NULL; - data.dsize = 0; - } -#else - if ( (rc = ldbm->get( ldbm, &key, &data, 0 )) == 0 ) { - /* Berkeley DB 1.85 don't malloc the data for us */ - /* duplicate it for to ensure reentrancy */ - data = ldbm_datum_dup( ldbm, data ); - } else { - data.dptr = NULL; - data.dsize = 0; - } -#endif - - LDBM_RUNLOCK; - - return( data ); -} - -int -ldbm_store( LDBM ldbm, Datum key, Datum data, int flags ) -{ - int rc; - - LDBM_WLOCK; - -#if DB_VERSION_MAJOR >= 2 - rc = ldbm->put( ldbm, NULL, &key, &data, flags & ~LDBM_SYNC ); - rc = (-1) * rc; -#else - rc = ldbm->put( ldbm, &key, &data, flags & ~LDBM_SYNC ); -#endif - - if ( flags & LDBM_SYNC ) - ldbm->sync( ldbm, 0 ); - - LDBM_WUNLOCK; - - return( rc ); -} - -int -ldbm_delete( LDBM ldbm, Datum key ) -{ - int rc; - - LDBM_WLOCK; - -#if DB_VERSION_MAJOR >= 2 - rc = ldbm->del( ldbm, NULL, &key, 0 ); - rc = (-1) * rc; -#else - rc = ldbm->del( ldbm, &key, 0 ); -#endif - ldbm->sync( ldbm, 0 ); - - LDBM_WUNLOCK; - - return( rc ); -} - -Datum -ldbm_firstkey( LDBM ldbm, LDBMCursor **dbch ) -{ - Datum key, data; - int rc; - -#if DB_VERSION_MAJOR >= 2 - LDBMCursor *dbci; - - ldbm_datum_init( key ); - ldbm_datum_init( data ); - - key.flags = data.flags = DB_DBT_MALLOC; - - LDBM_RLOCK; - - /* acquire a cursor for the DB */ -# if DB_VERSION_X >= 0x020600 - rc = ldbm->cursor( ldbm, NULL, &dbci, 0 ); -# else - rc = ldbm->cursor( ldbm, NULL, &dbci ); -# endif - - if( rc ) { - key.dptr = NULL; - } else { - *dbch = dbci; - if ( dbci->c_get( dbci, &key, &data, DB_NEXT ) == 0 ) { - ldbm_datum_free( ldbm, data ); - } else { - key.dptr = NULL; - key.dsize = 0; - } - } - - LDBM_RUNLOCK; - -#else - LDBM_RLOCK; - - rc = ldbm->seq( ldbm, &key, &data, R_FIRST ); - - if ( rc == 0 ) { - key = ldbm_datum_dup( ldbm, key ); - } else { - key.dptr = NULL; - key.dsize = 0; - } - - LDBM_RUNLOCK; -#endif - - return( key ); -} - -Datum -ldbm_nextkey( LDBM ldbm, Datum key, LDBMCursor *dbcp ) -{ - int rc; - Datum data; - - LDBM_RLOCK; - -#if DB_VERSION_MAJOR >= 2 - ldbm_datum_init( data ); - - ldbm_datum_free( ldbm, key ); - key.flags = data.flags = DB_DBT_MALLOC; - - rc = dbcp->c_get( dbcp, &key, &data, DB_NEXT ); - if ( rc == 0 ) { - ldbm_datum_free( ldbm, data ); - } else -#else - rc = ldbm->seq( ldbm, &key, &data, R_NEXT ); - - if ( rc == 0 ) { - key = ldbm_datum_dup( ldbm, key ); - } else -#endif - { - key.dptr = NULL; - key.dsize = 0; - } - - LDBM_RUNLOCK; - return( key ); -} - -int -ldbm_errno( LDBM ldbm ) -{ - return( errno ); -} - -/****************************************************************** - * * - * END Berkeley section * - * * - ******************************************************************/ - -#elif defined( HAVE_GDBM ) - -#ifdef HAVE_ST_BLKSIZE -#include -#endif - -/***************************************************************** - * * - * use gdbm * - * * - *****************************************************************/ - -LDBM -ldbm_open( DB_ENV *env, char *name, int rw, int mode, int dbcachesize ) -{ - LDBM db; -#ifdef HAVE_ST_BLKSIZE - struct stat st; -#endif -#ifdef HAVE_EBCDIC - char n2[2048]; - - strncpy(n2, name, sizeof(n2)-1); - n2[sizeof(n2)-1] = '\0'; - __atoe(n2); - name = n2; -#endif - - LDBM_WLOCK; - - if ( (db = gdbm_open( name, 0, rw | GDBM_FAST, mode, 0 )) == NULL ) { - LDBM_WUNLOCK; - return( NULL ); - } - -#ifdef HAVE_ST_BLKSIZE - if ( dbcachesize > 0 && stat( name, &st ) == 0 ) { - dbcachesize /= st.st_blksize; - if( dbcachesize == 0 ) dbcachesize = 1; - gdbm_setopt( db, GDBM_CACHESIZE, &dbcachesize, sizeof(int) ); - } -#else - if ( dbcachesize > 0 ) { - dbcachesize /= 4096; - if( dbcachesize == 0 ) dbcachesize = 1; - gdbm_setopt( db, GDBM_CACHESIZE, &dbcachesize, sizeof(int) ); - } -#endif - - LDBM_WUNLOCK; - - return( db ); -} - -void -ldbm_close( LDBM ldbm ) -{ - LDBM_WLOCK; - gdbm_close( ldbm ); - LDBM_WUNLOCK; -} - -void -ldbm_sync( LDBM ldbm ) -{ - LDBM_WLOCK; - gdbm_sync( ldbm ); - LDBM_WUNLOCK; -} - -Datum -ldbm_fetch( LDBM ldbm, Datum key ) -{ - Datum d; - - LDBM_RLOCK; - d = gdbm_fetch( ldbm, key ); - LDBM_RUNLOCK; - - return d; -} - -int -ldbm_store( LDBM ldbm, Datum key, Datum data, int flags ) -{ - int rc; - - LDBM_WLOCK; - rc = gdbm_store( ldbm, key, data, flags & ~LDBM_SYNC ); - if ( flags & LDBM_SYNC ) - gdbm_sync( ldbm ); - LDBM_WUNLOCK; - - return( rc ); -} - -int -ldbm_delete( LDBM ldbm, Datum key ) -{ - int rc; - - LDBM_WLOCK; - rc = gdbm_delete( ldbm, key ); - gdbm_sync( ldbm ); - LDBM_WUNLOCK; - - return( rc ); -} - -Datum -ldbm_firstkey( LDBM ldbm, LDBMCursor **dbcp ) -{ - Datum d; - - LDBM_RLOCK; - d = gdbm_firstkey( ldbm ); - LDBM_RUNLOCK; - - if ( d.dptr != NULL ) { - *dbcp = (Datum *) malloc( sizeof( Datum ) ); - **dbcp = ldbm_datum_dup( ldbm, d ); - } - - return d; -} - -Datum -ldbm_nextkey( LDBM ldbm, Datum key, LDBMCursor *dbcp ) -{ - Datum d; - - LDBM_RLOCK; - d = gdbm_nextkey( ldbm, *dbcp ); - LDBM_RUNLOCK; - - ldbm_datum_free( ldbm, *dbcp ); - - if ( d.dptr != NULL ) { - *dbcp = ldbm_datum_dup( ldbm, d ); - } else { - free( dbcp ); - } - - return d; -} - -int -ldbm_errno( LDBM ldbm ) -{ - int err; - - LDBM_WLOCK; - err = gdbm_errno; - LDBM_WUNLOCK; - - return( err ); -} - -#elif HAVE_MDBM - -/* MMAPED DBM HASHING DATABASE */ - -#include - -/* #define MDBM_DEBUG */ - -#ifdef MDBM_DEBUG -#include -#endif - -#define NO_NULL_KEY -/* #define MDBM_CHAIN */ - -#ifdef MDBM_CHAIN - -/* Use chaining */ - -#define mdbm_store mdbm_chain_store -#define mdbm_fetch mdbm_chain_fetch -#define mdbm_delete mdbm_chain_delete -#define mdbm_first mdbm_chain_first -#define mdbm_next mdbm_chain_next - -#endif - -#define MDBM_PG_SZ (4*1024) - -/***************************************************************** - * * - * use mdbm * - * * - *****************************************************************/ - -LDBM -ldbm_open( DB_ENV *env, char *name, int rw, int mode, int dbcachesize ) -{ - LDBM db; - -#ifdef MDBM_DEBUG - fprintf( stdout, - "==>(mdbm)ldbm_open(name=%s,rw=%x,mode=%x,cachesize=%d)\n", - name ? name : "NULL", rw, mode, dbcachesize ); - fflush( stdout ); -#endif - - LDBM_WLOCK; /* We need locking here, this is the only non-thread - * safe function we have. */ - - if ( (db = mdbm_open( name, rw, mode, MDBM_PG_SZ )) == NULL ) { - LDBM_WUNLOCK; -#ifdef MDBM_DEBUG - fprintf( stdout, "<==(mdbm)ldbm_open(db=NULL)\n" ); - fflush( stdout ); -#endif - return( NULL ); - } - -#ifdef MDBM_CHAIN - (void)mdbm_set_chain(db); -#endif - - LDBM_WUNLOCK; - -#ifdef MDBM_DEBUG - fprintf( stdout, "<==(mdbm)ldbm_open(db=%p)\n", db ); - fflush( stdout ); -#endif - - return( db ); -} - -void -ldbm_close( LDBM ldbm ) -{ - /* Open and close are not reentrant so we need to use locks here */ - -#ifdef MDBM_DEBUG - fprintf( stdout, - "==>(mdbm)ldbm_close(db=%p)\n", ldbm ); - fflush( stdout ); -#endif - - LDBM_WLOCK; - mdbm_close( ldbm ); - LDBM_WUNLOCK; - -#ifdef MDBM_DEBUG - fprintf( stdout, "<==(mdbm)ldbm_close()\n" ); - fflush( stdout ); -#endif -} - -void -ldbm_sync( LDBM ldbm ) -{ - /* XXX: Not sure if this is re-entrant need to check code, if so - * you can leave LOCKS out. - */ - - LDBM_WLOCK; - mdbm_sync( ldbm ); - LDBM_WUNLOCK; -} - -#define MAX_MDBM_RETRY 5 - -Datum -ldbm_fetch( LDBM ldbm, Datum key ) -{ - Datum d; - kvpair k; - int retry = 0; - - /* This hack is needed because MDBM does not take keys - * which begin with NULL when working in the chaining - * mode. - */ - -#ifdef NO_NULL_KEY - k.key.dsize = key.dsize + 1; - k.key.dptr = malloc(k.key.dsize); - *(k.key.dptr) = 'l'; - AC_MEMCPY( (void *)(k.key.dptr + 1), key.dptr, key.dsize ); -#else - k.key = key; -#endif - - k.val.dptr = NULL; - k.val.dsize = 0; - - /* LDBM_RLOCK; */ - do { - d = mdbm_fetch( ldbm, k ); - - if ( d.dsize > 0 ) { - if ( k.val.dptr != NULL ) { - free( k.val.dptr ); - } - - if ( (k.val.dptr = malloc( d.dsize )) != NULL ) { - k.val.dsize = d.dsize; - d = mdbm_fetch( ldbm, k ); - - } else { - d.dsize = 0; - break; - } - }/* if ( d.dsize > 0 ) */ - } while ((d.dsize > k.val.dsize) && (++retry < MAX_MDBM_RETRY)); - /* LDBM_RUNLOCK; */ - -#ifdef NO_NULL_KEY - free(k.key.dptr); -#endif - - return d; -} - -int -ldbm_store( LDBM ldbm, Datum key, Datum data, int flags ) -{ - int rc; - Datum int_key; /* Internal key */ - -#ifdef MDBM_DEBUG - fprintf( stdout, - "==>(mdbm)ldbm_store(db=%p, key(dptr=%p,sz=%d), data(dptr=%p,sz=%d), flags=%x)\n", - ldbm, key.dptr, key.dsize, data.dptr, data.dsize, flags ); - fflush( stdout ); -#endif - - /* LDBM_WLOCK; */ - -#ifdef NO_NULL_KEY - int_key.dsize = key.dsize + 1; - int_key.dptr = malloc( int_key.dsize ); - *(int_key.dptr) = 'l'; /* Must not be NULL !*/ - AC_MEMCPY( (void *)(int_key.dptr + 1), key.dptr, key.dsize ); -#else - int_key = key; -#endif - - rc = mdbm_store( ldbm, int_key, data, flags ); - if ( flags & LDBM_SYNC ) { - mdbm_sync( ldbm ); - } - - /* LDBM_WUNLOCK; */ - -#ifdef MDBM_DEBUG - fprintf( stdout, "<==(mdbm)ldbm_store(rc=%d)\n", rc ); - fflush( stdout ); -#endif - -#ifdef NO_NULL_KEY - free(int_key.dptr); -#endif - - return( rc ); -} - -int -ldbm_delete( LDBM ldbm, Datum key ) -{ - int rc; - Datum int_key; - - /* LDBM_WLOCK; */ - -#ifdef NO_NULL_KEY - int_key.dsize = key.dsize + 1; - int_key.dptr = malloc(int_key.dsize); - *(int_key.dptr) = 'l'; - AC_MEMCPY( (void *)(int_key.dptr + 1), key.dptr, key.dsize ); -#else - int_key = key; -#endif - - rc = mdbm_delete( ldbm, int_key ); - - /* LDBM_WUNLOCK; */ -#ifdef NO_NULL_KEY - free(int_key.dptr); -#endif - - return( rc ); -} - -static Datum -ldbm_get_next( LDBM ldbm, kvpair (*fptr)(MDBM *, kvpair) ) -{ - kvpair out; - kvpair in; - Datum ret; - size_t sz = MDBM_PAGE_SIZE(ldbm); -#ifdef NO_NULL_KEY - int delta = 1; -#else - int delta = 0; -#endif - - /* LDBM_RLOCK; */ - - in.key.dsize = sz; /* Assume first key in one pg */ - in.key.dptr = malloc(sz); - - in.val.dptr = NULL; /* Don't need data just key */ - in.val.dsize = 0; - - ret.dptr = NULL; - ret.dsize = NULL; - - out = fptr( ldbm, in ); - - if (out.key.dsize > 0) { - ret.dsize = out.key.dsize - delta; - - if ((ret.dptr = (char *)malloc(ret.dsize)) == NULL) { - ret.dsize = 0; - ret.dptr = NULL; - - } else { - AC_MEMCPY(ret.dptr, (void *)(out.key.dptr + delta), - ret.dsize ); - } - } - - /* LDBM_RUNLOCK; */ - - free(in.key.dptr); - return ret; -} - -Datum -ldbm_firstkey( LDBM ldbm, LDBMCursor **dbcp ) -{ - return ldbm_get_next( ldbm, mdbm_first ); -} - -Datum -ldbm_nextkey( LDBM ldbm, Datum key, LDBMCursor *dbcp ) -{ - /* XXX: - * don't know if this will affect the LDAP server operation - * but mdbm cannot take and input key. - */ - - return ldbm_get_next( ldbm, mdbm_next ); -} - -int -ldbm_errno( LDBM ldbm ) -{ - /* XXX: best we can do with current mdbm interface */ - return( errno ); -} - -#elif defined( HAVE_NDBM ) - -/***************************************************************** - * * - * if no gdbm or mdbm, fall back to using ndbm, the standard unix thing * - * * - *****************************************************************/ - -/* ARGSUSED */ -LDBM -ldbm_open( DB_ENV *env, char *name, int rw, int mode, int dbcachesize ) -{ - LDBM ldbm; - - LDBM_WLOCK; - ldbm = dbm_open( name, rw, mode ); - LDBM_WUNLOCK; - - return( ldbm ); -} - -void -ldbm_close( LDBM ldbm ) -{ - LDBM_WLOCK; - dbm_close( ldbm ); - LDBM_WUNLOCK; -} - -/* ARGSUSED */ -void -ldbm_sync( LDBM ldbm ) -{ - return; -} - -Datum -ldbm_fetch( LDBM ldbm, Datum key ) -{ - Datum d; - - LDBM_RLOCK; - d = ldbm_datum_dup( ldbm, dbm_fetch( ldbm, key ) ); - LDBM_RUNLOCK; - - return d; -} - -int -ldbm_store( LDBM ldbm, Datum key, Datum data, int flags ) -{ - int rc; - - LDBM_WLOCK; - rc = dbm_store( ldbm, key, data, flags ); - LDBM_WUNLOCK; - - return rc; -} - -int -ldbm_delete( LDBM ldbm, Datum key ) -{ - int rc; - - LDBM_WLOCK; - rc = dbm_delete( ldbm, key ); - LDBM_WUNLOCK; - - return rc; -} - -Datum -ldbm_firstkey( LDBM ldbm, LDBMCursor **dbcp ) -{ - Datum d; - - LDBM_RLOCK; - d = dbm_firstkey( ldbm ); - LDBM_RUNLOCK; - - return d; -} - -Datum -ldbm_nextkey( LDBM ldbm, Datum key, LDBMCursor *dbcp ) -{ - Datum d; - - LDBM_RLOCK; - d = dbm_nextkey( ldbm ); - LDBM_RUNLOCK; - - return d; -} - -int -ldbm_errno( LDBM ldbm ) -{ - int err; - - LDBM_WLOCK; - err = dbm_error( ldbm ); - LDBM_WUNLOCK; - - return err; -} - -#endif /* ndbm */ -#endif /* ldbm */ diff --git a/libraries/libldbm/libldbm.dsp b/libraries/libldbm/libldbm.dsp deleted file mode 100644 index 5c2a9e94d2..0000000000 --- a/libraries/libldbm/libldbm.dsp +++ /dev/null @@ -1,137 +0,0 @@ -# Microsoft Developer Studio Project File - Name="libldbm" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 5.00 -# ** DO NOT EDIT ** - -# TARGTYPE "Win32 (x86) Static Library" 0x0104 - -CFG=libldbm - Win32 Single Debug -!MESSAGE This is not a valid makefile. To build this project using NMAKE, -!MESSAGE use the Export Makefile command and run -!MESSAGE -!MESSAGE NMAKE /f "libldbm.mak". -!MESSAGE -!MESSAGE You can specify a configuration when running NMAKE -!MESSAGE by defining the macro CFG on the command line. For example: -!MESSAGE -!MESSAGE NMAKE /f "libldbm.mak" CFG="libldbm - Win32 Single Debug" -!MESSAGE -!MESSAGE Possible choices for configuration are: -!MESSAGE -!MESSAGE "libldbm - Win32 Release" (based on "Win32 (x86) Static Library") -!MESSAGE "libldbm - Win32 Debug" (based on "Win32 (x86) Static Library") -!MESSAGE "libldbm - Win32 Single Debug" (based on "Win32 (x86) Static Library") -!MESSAGE "libldbm - Win32 Single Release" (based on\ - "Win32 (x86) Static Library") -!MESSAGE - -# Begin Project -# PROP Scc_ProjName "" -# PROP Scc_LocalPath "" -CPP=cl.exe - -!IF "$(CFG)" == "libldbm - Win32 Release" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "Release" -# PROP BASE Intermediate_Dir "Release" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "..\..\Release" -# PROP Intermediate_Dir "..\..\Release\libldbm" -# PROP Target_Dir "" -RSC=rc.exe -# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c -# ADD CPP /nologo /MT /W3 /GX /O2 /I "..\..\include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LIB32=link.exe -lib -# ADD BASE LIB32 /nologo -# ADD LIB32 /nologo /out:"..\..\Release\oldbm32.lib" - -!ELSEIF "$(CFG)" == "libldbm - Win32 Debug" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "Debug" -# PROP BASE Intermediate_Dir "Debug" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir "..\..\Debug" -# PROP Intermediate_Dir "..\..\Debug\libldbm" -# PROP Target_Dir "" -RSC=rc.exe -# ADD BASE CPP /nologo /W3 /GX /Z7 /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c -# ADD CPP /nologo /MTd /W3 /GX /Z7 /Od /I "..\..\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /FR /YX /FD /c -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LIB32=link.exe -lib -# ADD BASE LIB32 /nologo -# ADD LIB32 /nologo /out:"..\..\Debug\oldbm32.lib" - -!ELSEIF "$(CFG)" == "libldbm - Win32 Single Debug" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "libldbm_" -# PROP BASE Intermediate_Dir "libldbm_" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir "..\..\SDebug" -# PROP Intermediate_Dir "..\..\SDebug\libldbm" -# PROP Target_Dir "" -RSC=rc.exe -# ADD BASE CPP /nologo /MTd /W3 /GX /Z7 /Od /I "..\..\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c -# ADD CPP /nologo /W3 /GX /Z7 /Od /I "..\..\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /FR /YX /FD /c -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LIB32=link.exe -lib -# ADD BASE LIB32 /nologo /out:"..\Debug\oldbm32.lib" -# ADD LIB32 /nologo /out:"..\..\SDebug\oldbm32.lib" - -!ELSEIF "$(CFG)" == "libldbm - Win32 Single Release" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "libldbm0" -# PROP BASE Intermediate_Dir "libldbm0" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "..\..\SRelease" -# PROP Intermediate_Dir "..\..\SRelease\libldbm" -# PROP Target_Dir "" -RSC=rc.exe -# ADD BASE CPP /nologo /MT /W3 /GX /O2 /I "..\..\include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c -# ADD CPP /nologo /W3 /GX /O2 /I "..\..\include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LIB32=link.exe -lib -# ADD BASE LIB32 /nologo /out:"..\Release\oldbm32.lib" -# ADD LIB32 /nologo /out:"..\..\SRelease\oldbm32.lib" - -!ENDIF - -# Begin Target - -# Name "libldbm - Win32 Release" -# Name "libldbm - Win32 Debug" -# Name "libldbm - Win32 Single Debug" -# Name "libldbm - Win32 Single Release" -# Begin Source File - -SOURCE=.\ldbm.c -# End Source File -# Begin Source File - -SOURCE=..\..\include\ldbm.h -# End Source File -# End Target -# End Project diff --git a/servers/slapd/back-ldbm/Makefile.in b/servers/slapd/back-ldbm/Makefile.in index 686f87d8b5..f0f8dff23b 100644 --- a/servers/slapd/back-ldbm/Makefile.in +++ b/servers/slapd/back-ldbm/Makefile.in @@ -18,13 +18,13 @@ SRCS = idl.c add.c search.c cache.c dbcache.c dn2id.c entry.c \ compare.c modify.c modrdn.c delete.c init.c \ config.c bind.c attr.c filterindex.c close.c \ alias.c tools.c key.c extended.c \ - referral.c operational.c + referral.c operational.c ldbm.c OBJS = idl.lo add.lo search.lo cache.lo dbcache.lo dn2id.lo entry.lo \ id2entry.lo index.lo id2children.lo nextid.lo \ compare.lo modify.lo modrdn.lo delete.lo init.lo \ config.lo bind.lo attr.lo filterindex.lo close.lo \ alias.lo tools.lo key.lo extended.lo \ - referral.lo operational.lo $(@BUILD_LDBM@_OBJS) + referral.lo operational.lo ldbm.lo LDAP_INCDIR= ../../../include LDAP_LIBDIR= ../../../libraries @@ -33,15 +33,12 @@ BUILD_OPT = "--enable-ldbm" BUILD_MOD = @BUILD_LDBM@ BUILD_MOD_DYNAMIC = @BUILD_LDBM_DYNAMIC@ -mod_SRCS = ldbm.c -mod_OBJS = ldbm.lo - mod_DEFS = -DSLAPD_IMPORT MOD_DEFS = $(@BUILD_LDBM@_DEFS) shared_LDAP_LIBS = $(LDAP_LIBLDAP_R_LA) $(LDAP_LIBLBER_LA) -NT_LINK_LIBS = -L.. -lslapd $(@BUILD_LIBS_DYNAMIC@_LDAP_LIBS) $(LDBM_LIBS) -UNIX_LINK_LIBS = $(@BUILD_LIBS_DYNAMIC@_LDAP_LIBS) $(LDBM_LIBS) +NT_LINK_LIBS = -L.. -lslapd $(@BUILD_LIBS_DYNAMIC@_LDAP_LIBS) +UNIX_LINK_LIBS = $(@BUILD_LIBS_DYNAMIC@_LDAP_LIBS) LIBBASE = back_ldbm @@ -54,7 +51,4 @@ all-local-lib: ../.backend ../.backend: lib$(LIBBASE).a @touch $@ -ldbm.c : $(srcdir)/../../../libraries/libldbm/ldbm.c - $(RM) $@; $(LN_S) $(srcdir)/../../../libraries/libldbm/ldbm.c $@ - depend-common: $(XXSRCS) diff --git a/servers/slapd/back-ldbm/ldbm.c b/servers/slapd/back-ldbm/ldbm.c new file mode 100644 index 0000000000..11e7ea0cc5 --- /dev/null +++ b/servers/slapd/back-ldbm/ldbm.c @@ -0,0 +1,1199 @@ +/* ldbm.c - ldap dbm compatibility routines */ +/* $OpenLDAP$ */ +/* This work is part of OpenLDAP Software . + * + * Copyright 1998-2003 The OpenLDAP Foundation. + * Portions Copyright 1998-2003 Kurt D. Zeilenga. + * Portions Copyright 1998-2001 Net Boolean Incorporated. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted only as authorized by the OpenLDAP + * Public License. + * + * A copy of this license is available in the file LICENSE in the + * top-level directory of the distribution or, alternatively, at + * . + */ +/* ACKNOWLEDGEMENTS: + * This work was originally developed by the University of Michigan + * (as part of U-MICH LDAP). Additional significant contributors + * include: + * Gary Williams + * Howard Chu + * Juan Gomez + * Kurt D. Zeilenga + * Kurt Spanier + * Mark Whitehouse + * Randy Kundee + */ + +#include "portable.h" + +#ifdef SLAPD_LDBM + +#include + +#include +#include +#include + +#include "ldbm.h" +#include "ldap_pvt_thread.h" + +void +ldbm_datum_free( LDBM ldbm, Datum data ) +{ + if ( data.dptr ) { + free( data.dptr ); + memset( &data, '\0', sizeof( Datum )); + data.dptr = NULL; + } +} + +Datum +ldbm_datum_dup( LDBM ldbm, Datum data ) +{ + Datum dup; + + ldbm_datum_init( dup ); + + if ( data.dsize == 0 ) { + dup.dsize = 0; + dup.dptr = NULL; + + return( dup ); + } + dup.dsize = data.dsize; + + if ( (dup.dptr = (char *) malloc( data.dsize )) != NULL ) { + AC_MEMCPY( dup.dptr, data.dptr, data.dsize ); + } + + return( dup ); +} + +static int ldbm_initialized = 0; + +#if defined( USE_BERKELEY_CDB ) + /* not currently supported */ +#define LDBM_RWLOCK_INIT ((void) 0) +#define LDBM_RWLOCK_DESTROY ((void) 0) +#define LDBM_WLOCK ((void) 0) +#define LDBM_WUNLOCK ((void) 0) +#define LDBM_RLOCK ((void) 0) +#define LDBM_RUNLOCK ((void) 0) + +#elif defined( HAVE_BERKELEY_DB_THREAD ) +static ldap_pvt_thread_rdwr_t ldbm_big_rdwr; +#define LDBM_RWLOCK_INIT (ldap_pvt_thread_rdwr_init( &ldbm_big_rdwr )) +#define LDBM_RWLOCK_DESTROY (ldap_pvt_thread_rdwr_destroy( &ldbm_big_rdwr )) +#define LDBM_WLOCK (ldap_pvt_thread_rdwr_wlock(&ldbm_big_rdwr)) +#define LDBM_WUNLOCK (ldap_pvt_thread_rdwr_wunlock(&ldbm_big_rdwr)) +#define LDBM_RLOCK (ldap_pvt_thread_rdwr_rlock(&ldbm_big_rdwr)) +#define LDBM_RUNLOCK (ldap_pvt_thread_rdwr_runlock(&ldbm_big_rdwr)) + +#else +static ldap_pvt_thread_mutex_t ldbm_big_mutex; +#define LDBM_RWLOCK_INIT (ldap_pvt_thread_mutex_init( &ldbm_big_mutex )) +#define LDBM_RWLOCK_DESTROY (ldap_pvt_thread_mutex_destroy( &ldbm_big_mutex )) +#define LDBM_WLOCK (ldap_pvt_thread_mutex_lock(&ldbm_big_mutex)) +#define LDBM_WUNLOCK (ldap_pvt_thread_mutex_unlock(&ldbm_big_mutex)) +#define LDBM_RLOCK LDBM_WLOCK +#define LDBM_RUNLOCK LDBM_WUNLOCK +#endif + +#if !defined( HAVE_BERKELEY_DB ) || (DB_VERSION_MAJOR < 3) + /* a dbEnv for BERKELEYv2 */ +DB_ENV *ldbm_Env = NULL; /* real or fake, depending on db and version */ +#endif + +/* Let's make the version comparisons a little easier... */ +#undef DB_VERSION_X +#ifdef HAVE_BERKELEY_DB +#define DB_VERSION_X ((DB_VERSION_MAJOR<<16)|(DB_VERSION_MINOR<<8)|DB_VERSION_PATCH) +#endif + +/******************************************************************* + * * + * Create some special functions to initialize Berkeley DB for * + * versions greater than 2. * + * * + *******************************************************************/ +#if defined( HAVE_BERKELEY_DB ) && (DB_VERSION_MAJOR >= 2) + +void * +ldbm_malloc( size_t size ) +{ + /* likely should use ber_mem* routines */ + return( calloc( 1, size ) ); +} + +#ifdef LDAP_SYSLOG +#include +#endif + +static void +ldbm_db_errcall( const char *prefix, char *message ) +{ +#ifdef LDAP_SYSLOG + syslog( LOG_INFO, "ldbm: %s %s", prefix, message ); +#endif +} + +int ldbm_initialize( const char* home ) +{ +#if DB_VERSION_MAJOR < 3 + int err; + u_int32_t envFlags; +#endif + + if(ldbm_initialized++) return 1; + + { + char *version; + int major, minor, patch; + version = db_version( &major, &minor, &patch ); + + if( major != DB_VERSION_MAJOR || + minor < DB_VERSION_MINOR ) + { +#ifdef LDAP_SYSLOG + syslog( LOG_INFO, + "ldbm_initialize(): version mismatch\nexpected: %s\ngot: %s\n", + DB_VERSION_STRING, version ); +#endif + return 1; + } + } + +#if DB_VERSION_MAJOR < 3 + ldbm_Env = calloc( 1, sizeof( DB_ENV )); + + if( ldbm_Env == NULL ) return 1; + + ldbm_Env->db_errcall = ldbm_db_errcall; + ldbm_Env->db_errpfx = "==>"; + + envFlags = DB_CREATE | DB_USE_ENVIRON; + + /* add optional flags */ +#ifdef DB_PRIVATE + envFlags |= DB_PRIVATE; +#endif +#ifdef HAVE_BERKELEY_DB_THREAD + envFlags |= DB_THREAD; +#endif + + err = db_appinit( home, NULL, ldbm_Env, envFlags ); + + if ( err ) { +#ifdef LDAP_SYSLOG + syslog( LOG_INFO, "ldbm_initialize(): " + "FATAL error (%d) in db_appinit()\n", err ); +#endif + return( 1 ); + } +#endif + + LDBM_RWLOCK_INIT; + + return 0; +} + +int ldbm_shutdown( void ) +{ + if( !ldbm_initialized ) return 1; + +#if DB_VERSION_MAJOR < 3 + db_appexit( ldbm_Env ); +#endif + + LDBM_RWLOCK_DESTROY; + return 0; +} + +#else /* some DB other than Berkeley V2 or greater */ + +int ldbm_initialize( const char * home ) +{ + if(ldbm_initialized++) return 1; + + LDBM_RWLOCK_INIT; + + return 0; +} + +int ldbm_shutdown( void ) +{ + if( !ldbm_initialized ) return 1; + + LDBM_RWLOCK_DESTROY; + + return 0; +} + +#endif /* HAVE_BERKELEY_DB */ + +#if defined( HAVE_BERKELEY_DB ) && (DB_VERSION_MAJOR >= 3) + +DB_ENV *ldbm_initialize_env(const char *home, int dbcachesize, int *envdirok) +{ + DB_ENV *env = NULL; + int err; + u_int32_t envFlags; +#ifdef HAVE_EBCDIC + char n2[2048]; +#endif + + err = db_env_create( &env, 0 ); + + if ( err ) { +#ifdef LDAP_SYSLOG + syslog( LOG_INFO, "ldbm_initialize_env(): " + "FATAL error in db_env_create() : %s (%d)\n", + db_strerror( err ), err ); +#endif + return NULL; + } + +#if DB_VERSION_X >= 0x030300 + /* This interface appeared in 3.3 */ + env->set_alloc( env, ldbm_malloc, NULL, NULL ); +#endif + + env->set_errcall( env, ldbm_db_errcall ); + env->set_errpfx( env, "==>" ); + if (dbcachesize) { + env->set_cachesize( env, 0, dbcachesize, 0 ); + } + + envFlags = DB_CREATE | DB_INIT_MPOOL | DB_USE_ENVIRON; +#ifdef DB_PRIVATE + envFlags |= DB_PRIVATE; +#endif +#ifdef DB_MPOOL_PRIVATE + envFlags |= DB_MPOOL_PRIVATE; +#endif +#ifdef HAVE_BERKELEY_DB_THREAD + envFlags |= DB_THREAD; +#endif + +#ifdef HAVE_EBCDIC + strncpy(n2, home, sizeof(n2)-1); + n2[sizeof(n2)-1] = '\0'; + __atoe(n2); + home = n2; +#endif +#if DB_VERSION_X >= 0x030100 + err = env->open( env, home, envFlags, 0 ); +#else + /* 3.0.x requires an extra argument */ + err = env->open( env, home, NULL, envFlags, 0 ); +#endif + + if ( err != 0 ) { +#ifdef LDAP_SYSLOG + syslog( LOG_INFO, "ldbm_initialize_env(): " + "FATAL error in dbEnv->open() : %s (%d)\n", + db_strerror( err ), err ); +#endif + env->close( env, 0 ); + return NULL; + } + + *envdirok = 1; + return env; +} + +void ldbm_shutdown_env(DB_ENV *env) +{ + env->close( env, 0 ); +} + +#else + +DB_ENV *ldbm_initialize_env(const char *home, int dbcachesize, int *envdirok) +{ + return ldbm_Env; +} + +void ldbm_shutdown_env(DB_ENV *env) +{ +} + +#endif + +#if defined( LDBM_USE_DBHASH ) || defined( LDBM_USE_DBBTREE ) + +/***************************************************************** + * * + * use berkeley db hash or btree package * + * * + *****************************************************************/ + +LDBM +ldbm_open( DB_ENV *env, char *name, int rw, int mode, int dbcachesize ) +{ + LDBM ret = NULL; +#ifdef HAVE_EBCDIC + char n2[2048]; +#endif + +#if DB_VERSION_MAJOR >= 3 + int err; + + LDBM_WLOCK; + + err = db_create( &ret, env, 0 ); + if ( err != 0 ) { + (void)ret->close(ret, 0); + LDBM_WUNLOCK; + + return NULL; + } + +#if DB_VERSION_X < 0x030300 + ret->set_malloc( ret, ldbm_malloc ); +#endif + + ret->set_pagesize( ret, DEFAULT_DB_PAGE_SIZE ); + + /* likely should use ber_mem* routines */ + +#ifdef HAVE_EBCDIC + strncpy(n2, name, sizeof(n2)-1); + n2[sizeof(n2)-1] = '\0'; + __atoe(n2); + name = n2; +#endif +#if DB_VERSION_X >= 0x040111 + err = ret->open( ret, NULL, name, NULL, DB_TYPE, rw, mode); +#else + err = ret->open( ret, name, NULL, DB_TYPE, rw, mode); +#endif + + if ( err != 0 ) { + int tmp = errno; + (void)ret->close(ret, 0); + errno = tmp; + + LDBM_WUNLOCK; + return NULL; + } + + LDBM_WUNLOCK; + +#elif DB_VERSION_MAJOR >= 2 + DB_INFO dbinfo; + + memset( &dbinfo, '\0', sizeof( dbinfo )); + +#if DB_VERSION_MAJOR == 2 && DB_VERSION_MINOR == 4 + /* + * BerkeleyDB 2.4 do not allow db_cachesize + * to be specified if an DB_ENV is. + */ +#else + /* set db_cachesize of MPOOL is NOT being used. */ + if (( ldbm_Env == NULL ) || ( ldbm_Env->mp_info == NULL )) { + dbinfo.db_cachesize = dbcachesize; + } +#endif + + dbinfo.db_pagesize = DEFAULT_DB_PAGE_SIZE; + dbinfo.db_malloc = ldbm_malloc; + + LDBM_WLOCK; + (void) db_open( name, DB_TYPE, rw, mode, ldbm_Env, &dbinfo, &ret ); + LDBM_WUNLOCK; + +#else + void *info; + BTREEINFO binfo; + HASHINFO hinfo; + + if ( DB_TYPE == DB_HASH ) { + memset( (char *) &hinfo, '\0', sizeof(hinfo) ); + hinfo.cachesize = dbcachesize; + info = &hinfo; + } else if ( DB_TYPE == DB_BTREE ) { + memset( (char *) &binfo, '\0', sizeof(binfo) ); + binfo.cachesize = dbcachesize; + info = &binfo; + } else { + info = NULL; + } + + LDBM_WLOCK; + ret = dbopen( name, rw, mode, DB_TYPE, info ); + LDBM_WUNLOCK; +#endif + + return ret; +} + +void +ldbm_close( LDBM ldbm ) +{ + LDBM_WLOCK; +#if DB_VERSION_MAJOR >= 2 + ldbm->close( ldbm, 0 ); +#else + ldbm->close( ldbm ); +#endif + LDBM_WUNLOCK; +} + +void +ldbm_sync( LDBM ldbm ) +{ + LDBM_WLOCK; + (*ldbm->sync)( ldbm, 0 ); + LDBM_WUNLOCK; +} + +Datum +ldbm_fetch( LDBM ldbm, Datum key ) +{ + Datum data; + int rc; + + LDBM_RLOCK; + +#if DB_VERSION_MAJOR >= 2 + ldbm_datum_init( data ); + + data.flags = DB_DBT_MALLOC; + + if ( (rc = ldbm->get( ldbm, NULL, &key, &data, 0 )) != 0 ) { + ldbm_datum_free( ldbm, data ); + data.dptr = NULL; + data.dsize = 0; + } +#else + if ( (rc = ldbm->get( ldbm, &key, &data, 0 )) == 0 ) { + /* Berkeley DB 1.85 don't malloc the data for us */ + /* duplicate it for to ensure reentrancy */ + data = ldbm_datum_dup( ldbm, data ); + } else { + data.dptr = NULL; + data.dsize = 0; + } +#endif + + LDBM_RUNLOCK; + + return( data ); +} + +int +ldbm_store( LDBM ldbm, Datum key, Datum data, int flags ) +{ + int rc; + + LDBM_WLOCK; + +#if DB_VERSION_MAJOR >= 2 + rc = ldbm->put( ldbm, NULL, &key, &data, flags & ~LDBM_SYNC ); + rc = (-1) * rc; +#else + rc = ldbm->put( ldbm, &key, &data, flags & ~LDBM_SYNC ); +#endif + + if ( flags & LDBM_SYNC ) + ldbm->sync( ldbm, 0 ); + + LDBM_WUNLOCK; + + return( rc ); +} + +int +ldbm_delete( LDBM ldbm, Datum key ) +{ + int rc; + + LDBM_WLOCK; + +#if DB_VERSION_MAJOR >= 2 + rc = ldbm->del( ldbm, NULL, &key, 0 ); + rc = (-1) * rc; +#else + rc = ldbm->del( ldbm, &key, 0 ); +#endif + ldbm->sync( ldbm, 0 ); + + LDBM_WUNLOCK; + + return( rc ); +} + +Datum +ldbm_firstkey( LDBM ldbm, LDBMCursor **dbch ) +{ + Datum key, data; + int rc; + +#if DB_VERSION_MAJOR >= 2 + LDBMCursor *dbci; + + ldbm_datum_init( key ); + ldbm_datum_init( data ); + + key.flags = data.flags = DB_DBT_MALLOC; + + LDBM_RLOCK; + + /* acquire a cursor for the DB */ +# if DB_VERSION_X >= 0x020600 + rc = ldbm->cursor( ldbm, NULL, &dbci, 0 ); +# else + rc = ldbm->cursor( ldbm, NULL, &dbci ); +# endif + + if( rc ) { + key.dptr = NULL; + } else { + *dbch = dbci; + if ( dbci->c_get( dbci, &key, &data, DB_NEXT ) == 0 ) { + ldbm_datum_free( ldbm, data ); + } else { + key.dptr = NULL; + key.dsize = 0; + } + } + + LDBM_RUNLOCK; + +#else + LDBM_RLOCK; + + rc = ldbm->seq( ldbm, &key, &data, R_FIRST ); + + if ( rc == 0 ) { + key = ldbm_datum_dup( ldbm, key ); + } else { + key.dptr = NULL; + key.dsize = 0; + } + + LDBM_RUNLOCK; +#endif + + return( key ); +} + +Datum +ldbm_nextkey( LDBM ldbm, Datum key, LDBMCursor *dbcp ) +{ + int rc; + Datum data; + + LDBM_RLOCK; + +#if DB_VERSION_MAJOR >= 2 + ldbm_datum_init( data ); + + ldbm_datum_free( ldbm, key ); + key.flags = data.flags = DB_DBT_MALLOC; + + rc = dbcp->c_get( dbcp, &key, &data, DB_NEXT ); + if ( rc == 0 ) { + ldbm_datum_free( ldbm, data ); + } else +#else + rc = ldbm->seq( ldbm, &key, &data, R_NEXT ); + + if ( rc == 0 ) { + key = ldbm_datum_dup( ldbm, key ); + } else +#endif + { + key.dptr = NULL; + key.dsize = 0; + } + + LDBM_RUNLOCK; + return( key ); +} + +int +ldbm_errno( LDBM ldbm ) +{ + return( errno ); +} + +/****************************************************************** + * * + * END Berkeley section * + * * + ******************************************************************/ + +#elif defined( HAVE_GDBM ) + +#ifdef HAVE_ST_BLKSIZE +#include +#endif + +/***************************************************************** + * * + * use gdbm * + * * + *****************************************************************/ + +LDBM +ldbm_open( DB_ENV *env, char *name, int rw, int mode, int dbcachesize ) +{ + LDBM db; +#ifdef HAVE_ST_BLKSIZE + struct stat st; +#endif +#ifdef HAVE_EBCDIC + char n2[2048]; + + strncpy(n2, name, sizeof(n2)-1); + n2[sizeof(n2)-1] = '\0'; + __atoe(n2); + name = n2; +#endif + + LDBM_WLOCK; + + if ( (db = gdbm_open( name, 0, rw | GDBM_FAST, mode, 0 )) == NULL ) { + LDBM_WUNLOCK; + return( NULL ); + } + +#ifdef HAVE_ST_BLKSIZE + if ( dbcachesize > 0 && stat( name, &st ) == 0 ) { + dbcachesize /= st.st_blksize; + if( dbcachesize == 0 ) dbcachesize = 1; + gdbm_setopt( db, GDBM_CACHESIZE, &dbcachesize, sizeof(int) ); + } +#else + if ( dbcachesize > 0 ) { + dbcachesize /= 4096; + if( dbcachesize == 0 ) dbcachesize = 1; + gdbm_setopt( db, GDBM_CACHESIZE, &dbcachesize, sizeof(int) ); + } +#endif + + LDBM_WUNLOCK; + + return( db ); +} + +void +ldbm_close( LDBM ldbm ) +{ + LDBM_WLOCK; + gdbm_close( ldbm ); + LDBM_WUNLOCK; +} + +void +ldbm_sync( LDBM ldbm ) +{ + LDBM_WLOCK; + gdbm_sync( ldbm ); + LDBM_WUNLOCK; +} + +Datum +ldbm_fetch( LDBM ldbm, Datum key ) +{ + Datum d; + + LDBM_RLOCK; + d = gdbm_fetch( ldbm, key ); + LDBM_RUNLOCK; + + return d; +} + +int +ldbm_store( LDBM ldbm, Datum key, Datum data, int flags ) +{ + int rc; + + LDBM_WLOCK; + rc = gdbm_store( ldbm, key, data, flags & ~LDBM_SYNC ); + if ( flags & LDBM_SYNC ) + gdbm_sync( ldbm ); + LDBM_WUNLOCK; + + return( rc ); +} + +int +ldbm_delete( LDBM ldbm, Datum key ) +{ + int rc; + + LDBM_WLOCK; + rc = gdbm_delete( ldbm, key ); + gdbm_sync( ldbm ); + LDBM_WUNLOCK; + + return( rc ); +} + +Datum +ldbm_firstkey( LDBM ldbm, LDBMCursor **dbcp ) +{ + Datum d; + + LDBM_RLOCK; + d = gdbm_firstkey( ldbm ); + LDBM_RUNLOCK; + + if ( d.dptr != NULL ) { + *dbcp = (Datum *) malloc( sizeof( Datum ) ); + **dbcp = ldbm_datum_dup( ldbm, d ); + } + + return d; +} + +Datum +ldbm_nextkey( LDBM ldbm, Datum key, LDBMCursor *dbcp ) +{ + Datum d; + + LDBM_RLOCK; + d = gdbm_nextkey( ldbm, *dbcp ); + LDBM_RUNLOCK; + + ldbm_datum_free( ldbm, *dbcp ); + + if ( d.dptr != NULL ) { + *dbcp = ldbm_datum_dup( ldbm, d ); + } else { + free( dbcp ); + } + + return d; +} + +int +ldbm_errno( LDBM ldbm ) +{ + int err; + + LDBM_WLOCK; + err = gdbm_errno; + LDBM_WUNLOCK; + + return( err ); +} + +#elif HAVE_MDBM + +/* MMAPED DBM HASHING DATABASE */ + +#include + +/* #define MDBM_DEBUG */ + +#ifdef MDBM_DEBUG +#include +#endif + +#define NO_NULL_KEY +/* #define MDBM_CHAIN */ + +#ifdef MDBM_CHAIN + +/* Use chaining */ + +#define mdbm_store mdbm_chain_store +#define mdbm_fetch mdbm_chain_fetch +#define mdbm_delete mdbm_chain_delete +#define mdbm_first mdbm_chain_first +#define mdbm_next mdbm_chain_next + +#endif + +#define MDBM_PG_SZ (4*1024) + +/***************************************************************** + * * + * use mdbm * + * * + *****************************************************************/ + +LDBM +ldbm_open( DB_ENV *env, char *name, int rw, int mode, int dbcachesize ) +{ + LDBM db; + +#ifdef MDBM_DEBUG + fprintf( stdout, + "==>(mdbm)ldbm_open(name=%s,rw=%x,mode=%x,cachesize=%d)\n", + name ? name : "NULL", rw, mode, dbcachesize ); + fflush( stdout ); +#endif + + LDBM_WLOCK; /* We need locking here, this is the only non-thread + * safe function we have. */ + + if ( (db = mdbm_open( name, rw, mode, MDBM_PG_SZ )) == NULL ) { + LDBM_WUNLOCK; +#ifdef MDBM_DEBUG + fprintf( stdout, "<==(mdbm)ldbm_open(db=NULL)\n" ); + fflush( stdout ); +#endif + return( NULL ); + } + +#ifdef MDBM_CHAIN + (void)mdbm_set_chain(db); +#endif + + LDBM_WUNLOCK; + +#ifdef MDBM_DEBUG + fprintf( stdout, "<==(mdbm)ldbm_open(db=%p)\n", db ); + fflush( stdout ); +#endif + + return( db ); +} + +void +ldbm_close( LDBM ldbm ) +{ + /* Open and close are not reentrant so we need to use locks here */ + +#ifdef MDBM_DEBUG + fprintf( stdout, + "==>(mdbm)ldbm_close(db=%p)\n", ldbm ); + fflush( stdout ); +#endif + + LDBM_WLOCK; + mdbm_close( ldbm ); + LDBM_WUNLOCK; + +#ifdef MDBM_DEBUG + fprintf( stdout, "<==(mdbm)ldbm_close()\n" ); + fflush( stdout ); +#endif +} + +void +ldbm_sync( LDBM ldbm ) +{ + /* XXX: Not sure if this is re-entrant need to check code, if so + * you can leave LOCKS out. + */ + + LDBM_WLOCK; + mdbm_sync( ldbm ); + LDBM_WUNLOCK; +} + +#define MAX_MDBM_RETRY 5 + +Datum +ldbm_fetch( LDBM ldbm, Datum key ) +{ + Datum d; + kvpair k; + int retry = 0; + + /* This hack is needed because MDBM does not take keys + * which begin with NULL when working in the chaining + * mode. + */ + +#ifdef NO_NULL_KEY + k.key.dsize = key.dsize + 1; + k.key.dptr = malloc(k.key.dsize); + *(k.key.dptr) = 'l'; + AC_MEMCPY( (void *)(k.key.dptr + 1), key.dptr, key.dsize ); +#else + k.key = key; +#endif + + k.val.dptr = NULL; + k.val.dsize = 0; + + /* LDBM_RLOCK; */ + do { + d = mdbm_fetch( ldbm, k ); + + if ( d.dsize > 0 ) { + if ( k.val.dptr != NULL ) { + free( k.val.dptr ); + } + + if ( (k.val.dptr = malloc( d.dsize )) != NULL ) { + k.val.dsize = d.dsize; + d = mdbm_fetch( ldbm, k ); + + } else { + d.dsize = 0; + break; + } + }/* if ( d.dsize > 0 ) */ + } while ((d.dsize > k.val.dsize) && (++retry < MAX_MDBM_RETRY)); + /* LDBM_RUNLOCK; */ + +#ifdef NO_NULL_KEY + free(k.key.dptr); +#endif + + return d; +} + +int +ldbm_store( LDBM ldbm, Datum key, Datum data, int flags ) +{ + int rc; + Datum int_key; /* Internal key */ + +#ifdef MDBM_DEBUG + fprintf( stdout, + "==>(mdbm)ldbm_store(db=%p, key(dptr=%p,sz=%d), data(dptr=%p,sz=%d), flags=%x)\n", + ldbm, key.dptr, key.dsize, data.dptr, data.dsize, flags ); + fflush( stdout ); +#endif + + /* LDBM_WLOCK; */ + +#ifdef NO_NULL_KEY + int_key.dsize = key.dsize + 1; + int_key.dptr = malloc( int_key.dsize ); + *(int_key.dptr) = 'l'; /* Must not be NULL !*/ + AC_MEMCPY( (void *)(int_key.dptr + 1), key.dptr, key.dsize ); +#else + int_key = key; +#endif + + rc = mdbm_store( ldbm, int_key, data, flags ); + if ( flags & LDBM_SYNC ) { + mdbm_sync( ldbm ); + } + + /* LDBM_WUNLOCK; */ + +#ifdef MDBM_DEBUG + fprintf( stdout, "<==(mdbm)ldbm_store(rc=%d)\n", rc ); + fflush( stdout ); +#endif + +#ifdef NO_NULL_KEY + free(int_key.dptr); +#endif + + return( rc ); +} + +int +ldbm_delete( LDBM ldbm, Datum key ) +{ + int rc; + Datum int_key; + + /* LDBM_WLOCK; */ + +#ifdef NO_NULL_KEY + int_key.dsize = key.dsize + 1; + int_key.dptr = malloc(int_key.dsize); + *(int_key.dptr) = 'l'; + AC_MEMCPY( (void *)(int_key.dptr + 1), key.dptr, key.dsize ); +#else + int_key = key; +#endif + + rc = mdbm_delete( ldbm, int_key ); + + /* LDBM_WUNLOCK; */ +#ifdef NO_NULL_KEY + free(int_key.dptr); +#endif + + return( rc ); +} + +static Datum +ldbm_get_next( LDBM ldbm, kvpair (*fptr)(MDBM *, kvpair) ) +{ + kvpair out; + kvpair in; + Datum ret; + size_t sz = MDBM_PAGE_SIZE(ldbm); +#ifdef NO_NULL_KEY + int delta = 1; +#else + int delta = 0; +#endif + + /* LDBM_RLOCK; */ + + in.key.dsize = sz; /* Assume first key in one pg */ + in.key.dptr = malloc(sz); + + in.val.dptr = NULL; /* Don't need data just key */ + in.val.dsize = 0; + + ret.dptr = NULL; + ret.dsize = NULL; + + out = fptr( ldbm, in ); + + if (out.key.dsize > 0) { + ret.dsize = out.key.dsize - delta; + + if ((ret.dptr = (char *)malloc(ret.dsize)) == NULL) { + ret.dsize = 0; + ret.dptr = NULL; + + } else { + AC_MEMCPY(ret.dptr, (void *)(out.key.dptr + delta), + ret.dsize ); + } + } + + /* LDBM_RUNLOCK; */ + + free(in.key.dptr); + return ret; +} + +Datum +ldbm_firstkey( LDBM ldbm, LDBMCursor **dbcp ) +{ + return ldbm_get_next( ldbm, mdbm_first ); +} + +Datum +ldbm_nextkey( LDBM ldbm, Datum key, LDBMCursor *dbcp ) +{ + /* XXX: + * don't know if this will affect the LDAP server operation + * but mdbm cannot take and input key. + */ + + return ldbm_get_next( ldbm, mdbm_next ); +} + +int +ldbm_errno( LDBM ldbm ) +{ + /* XXX: best we can do with current mdbm interface */ + return( errno ); +} + +#elif defined( HAVE_NDBM ) + +/***************************************************************** + * * + * if no gdbm or mdbm, fall back to using ndbm, the standard unix thing * + * * + *****************************************************************/ + +/* ARGSUSED */ +LDBM +ldbm_open( DB_ENV *env, char *name, int rw, int mode, int dbcachesize ) +{ + LDBM ldbm; + + LDBM_WLOCK; + ldbm = dbm_open( name, rw, mode ); + LDBM_WUNLOCK; + + return( ldbm ); +} + +void +ldbm_close( LDBM ldbm ) +{ + LDBM_WLOCK; + dbm_close( ldbm ); + LDBM_WUNLOCK; +} + +/* ARGSUSED */ +void +ldbm_sync( LDBM ldbm ) +{ + return; +} + +Datum +ldbm_fetch( LDBM ldbm, Datum key ) +{ + Datum d; + + LDBM_RLOCK; + d = ldbm_datum_dup( ldbm, dbm_fetch( ldbm, key ) ); + LDBM_RUNLOCK; + + return d; +} + +int +ldbm_store( LDBM ldbm, Datum key, Datum data, int flags ) +{ + int rc; + + LDBM_WLOCK; + rc = dbm_store( ldbm, key, data, flags ); + LDBM_WUNLOCK; + + return rc; +} + +int +ldbm_delete( LDBM ldbm, Datum key ) +{ + int rc; + + LDBM_WLOCK; + rc = dbm_delete( ldbm, key ); + LDBM_WUNLOCK; + + return rc; +} + +Datum +ldbm_firstkey( LDBM ldbm, LDBMCursor **dbcp ) +{ + Datum d; + + LDBM_RLOCK; + d = dbm_firstkey( ldbm ); + LDBM_RUNLOCK; + + return d; +} + +Datum +ldbm_nextkey( LDBM ldbm, Datum key, LDBMCursor *dbcp ) +{ + Datum d; + + LDBM_RLOCK; + d = dbm_nextkey( ldbm ); + LDBM_RUNLOCK; + + return d; +} + +int +ldbm_errno( LDBM ldbm ) +{ + int err; + + LDBM_WLOCK; + err = dbm_error( ldbm ); + LDBM_WUNLOCK; + + return err; +} + +#endif /* ndbm */ +#endif /* ldbm */ diff --git a/servers/slapd/back-ldbm/ldbm.h b/servers/slapd/back-ldbm/ldbm.h new file mode 100644 index 0000000000..0d6e6ffe5d --- /dev/null +++ b/servers/slapd/back-ldbm/ldbm.h @@ -0,0 +1,278 @@ +/* ldbm.h - ldap dbm compatibility routine header file */ +/* $OpenLDAP$ */ +/* This work is part of OpenLDAP Software . + * + * Copyright 1998-2003 The OpenLDAP Foundation. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted only as authorized by the OpenLDAP + * Public License. + * + * A copy of this license is available in file LICENSE in the + * top-level directory of the distribution or, alternatively, at + * . + */ + +#ifndef _LDBM_H_ +#define _LDBM_H_ + +#include +#include + +/* dummy DB_ENV for non Berkeley DB */ +#if !defined( LDBM_USE_DBBTREE ) && !defined( LDBM_USE_DBHASH ) +# define DB_ENV void +#endif + +#if defined( LDBM_USE_DBBTREE ) || defined( LDBM_USE_DBHASH ) + +/***************************************************************** + * * + * use berkeley db btree or hash package * + * * + *****************************************************************/ +#include +#include +#include + +#ifdef HAVE_DB_185_H +# include +#else +# ifdef HAVE_DB1_DB_H +# include +# else +# include +# endif +#endif + +#ifndef DB_VERSION_MAJOR +# define DB_VERSION_MAJOR 1 +#endif +#ifndef DB_VERSION_MINOR +# define DB_VERSION_MINOR 85 +#endif + +#if DB_VERSION_MAJOR >= 2 +# define R_NOOVERWRITE DB_NOOVERWRITE +# ifndef DEFAULT_DB_PAGE_SIZE +# define DEFAULT_DB_PAGE_SIZE 4096 +# endif +#else +# define DB_ENV void +#endif + + +LDAP_BEGIN_DECL + +typedef DBT Datum; +#define dsize size +#define dptr data + +typedef DB *LDBM; + + +/* for ldbm_open */ +#if DB_VERSION_MAJOR >= 2 +typedef DBC LDBMCursor; + +# define LDBM_READER DB_RDONLY +# define LDBM_WRITER 0x00000 /* hopefully */ +# if defined( HAVE_BERKELEY_DB_THREAD ) +# define LDBM_WRCREAT (DB_NOMMAP|DB_CREATE|DB_THREAD) +# define LDBM_NEWDB (DB_TRUNCATE|DB_CREATE|DB_THREAD) +# else +# define LDBM_WRCREAT (DB_NOMMAP|DB_CREATE) +# define LDBM_NEWDB (DB_TRUNCATE|DB_CREATE) +# endif + +#else +typedef void LDBMCursor; +# define LDBM_READER O_RDONLY +# define LDBM_WRITER O_RDWR +# define LDBM_WRCREAT (O_RDWR|O_CREAT) +# define LDBM_NEWDB (O_RDWR|O_TRUNC|O_CREAT) +#endif + +LDAP_END_DECL + +/* for ldbm_open */ +#define LDBM_NOSYNC 0 +#define LDBM_SYNC 0 +#define LDBM_LOCKING 0 +#define LDBM_NOLOCKING 0 + +/* for ldbm_insert */ +#define LDBM_INSERT R_NOOVERWRITE +#define LDBM_REPLACE 0 + +#ifdef LDBM_USE_DBBTREE +# define LDBM_ORDERED 1 +# define LDBM_SUFFIX ".dbb" +# define DB_TYPE DB_BTREE +#else +# define LDBM_SUFFIX ".dbh" +# define DB_TYPE DB_HASH +#endif + +#elif defined( HAVE_GDBM ) + +/***************************************************************** + * * + * use gdbm if possible * + * * + *****************************************************************/ + +#include + +LDAP_BEGIN_DECL + +typedef datum Datum; +typedef Datum LDBMCursor; +typedef GDBM_FILE LDBM; + +LDAP_END_DECL + +/* for ldbm_open */ +#define LDBM_READER GDBM_READER +#define LDBM_WRITER GDBM_WRITER +#define LDBM_WRCREAT GDBM_WRCREAT +#define LDBM_NEWDB GDBM_NEWDB + +#ifdef GDBM_FAST +#define LDBM_NOSYNC GDBM_FAST +#else +#define LDBM_NOSYNC 0 +#endif + +#ifdef GDBM_SYNC +#define LDBM_SYNC GDBM_SYNC +#else +#define LDBM_SYNC 0 +#endif + +#define LDBM_LOCKING 0 +#ifdef GDBM_NOLOCK +#define LDBM_NOLOCKING GDBM_NOLOCK +#else +#define LDBM_NOLOCKING 0 +#endif + +#define LDBM_SUFFIX ".gdbm" + +/* for ldbm_insert */ +#define LDBM_INSERT GDBM_INSERT +#define LDBM_REPLACE GDBM_REPLACE + +#elif defined( HAVE_MDBM ) + +/***************************************************************** + * * + * use mdbm if possible * + * * + *****************************************************************/ + +#include + +LDAP_BEGIN_DECL + +typedef datum Datum; +typedef int LDBMCursor; +typedef MDBM *LDBM; + +LDAP_END_DECL + +#include +#include +#include + +/* for ldbm_open */ +#define LDBM_READER O_RDONLY +#define LDBM_WRITER O_RDWR +#define LDBM_WRCREAT (O_RDWR|O_CREAT) +#define LDBM_NEWDB (O_RDWR|O_TRUNC|O_CREAT) + +#define LDBM_SYNC 0 +#define LDBM_NOSYNC 0 +#define LDBM_LOCKING 0 +#define LDBM_NOLOCKING 0 + +#define LDBM_SUFFIX ".mdbm" + +/* for ldbm_insert */ +#define LDBM_INSERT MDBM_INSERT +#define LDBM_REPLACE MDBM_REPLACE + +#elif defined( HAVE_NDBM ) + +/***************************************************************** + * * + * if none of the above use ndbm, the standard unix thing * + * * + *****************************************************************/ + +#include + +#ifdef HAVE_FCNTL_H +#include +#endif + +LDAP_BEGIN_DECL + +typedef datum Datum; +typedef int LDBMCursor; +typedef DBM *LDBM; + +LDAP_END_DECL + +/* for ldbm_open */ +#define LDBM_READER O_RDONLY +#define LDBM_WRITER O_WRONLY +#define LDBM_WRCREAT (O_RDWR|O_CREAT) +#define LDBM_NEWDB (O_RDWR|O_TRUNC|O_CREAT) + +#define LDBM_NOSYNC 0 +#define LDBM_SYNC 0 +#define LDBM_NOLOCK 0 +#define LDBM_SYNC 0 + +#define LDBM_SUFFIX ".ndbm" + +/* for ldbm_insert */ +#define LDBM_INSERT DBM_INSERT +#define LDBM_REPLACE DBM_REPLACE + +#endif + +LDAP_BEGIN_DECL + +LDAP_LDBM_F (int) ldbm_initialize( const char * ); +LDAP_LDBM_F (int) ldbm_shutdown( void ); + +LDAP_LDBM_F (DB_ENV*) ldbm_initialize_env(const char *, int dbcachesize, int *envdirok); +LDAP_LDBM_F (void) ldbm_shutdown_env(DB_ENV *); + +LDAP_LDBM_F (int) ldbm_errno( LDBM ldbm ); +LDAP_LDBM_F (LDBM) ldbm_open( DB_ENV *env, char *name, int rw, int mode, int dbcachesize ); +LDAP_LDBM_F (void) ldbm_close( LDBM ldbm ); +LDAP_LDBM_F (void) ldbm_sync( LDBM ldbm ); +LDAP_LDBM_F (void) ldbm_datum_free( LDBM ldbm, Datum data ); +LDAP_LDBM_F (Datum) ldbm_datum_dup( LDBM ldbm, Datum data ); +LDAP_LDBM_F (Datum) ldbm_fetch( LDBM ldbm, Datum key ); +LDAP_LDBM_F (int) ldbm_store( LDBM ldbm, Datum key, Datum data, int flags ); +LDAP_LDBM_F (int) ldbm_delete( LDBM ldbm, Datum key ); + +LDAP_LDBM_F (Datum) ldbm_firstkey( LDBM ldbm, LDBMCursor **cursor ); +LDAP_LDBM_F (Datum) ldbm_nextkey( LDBM ldbm, Datum key, LDBMCursor *cursor ); + +/* initialization of Datum structures */ +#if defined( HAVE_BERKELEY_DB ) && (DB_VERSION_MAJOR >= 2) + LDAP_LDBM_F (void *) ldbm_malloc( size_t size ); +# define ldbm_datum_init(d) ((void)memset(&(d), '\0', sizeof(Datum))) +#else +# define ldbm_datum_init(d) ((void)0) +#endif /* HAVE_BERKELEY_DB */ + +LDAP_END_DECL + +#endif /* _ldbm_h_ */