From: Kurt Spanier Date: Tue, 29 Dec 1998 17:28:45 +0000 (+0000) Subject: Patch for Berkeley DB 2.6.4 (beta) (DB)->cursor() call. X-Git-Tag: OPENLDAP_SLAPD_BACK_LDAP~835 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=bfb27120bed1c76a190a07295a835523942776dc;p=openldap Patch for Berkeley DB 2.6.4 (beta) (DB)->cursor() call. Introduction of ldbm_datum_init(). Patch for non-NULL pointer test befor call to ldbm_datum_free(). --- diff --git a/include/ldbm.h b/include/ldbm.h index d1b93fb4a3..0a7edcdf13 100644 --- a/include/ldbm.h +++ b/include/ldbm.h @@ -201,4 +201,16 @@ int ldbm_delete( LDBM ldbm, Datum key ); Datum ldbm_nextkey( LDBM ldbm, Datum key ); #endif + +/* initialization of Datum structures */ +#ifdef HAVE_BERKELEY_DB2 + +# define ldbm_datum_init(d) ((void)memset(&(d), 0, sizeof(Datum))) + +#else + +# define ldbm_datum_init(d) ((void)0) + +#endif /* HAVE_BERKELEY_DB2 */ + #endif /* _ldbm_h_ */ diff --git a/libraries/libldbm/ldbm.c b/libraries/libldbm/ldbm.c index 7a49e6b31c..72a212f8ca 100644 --- a/libraries/libldbm/ldbm.c +++ b/libraries/libldbm/ldbm.c @@ -54,7 +54,7 @@ ldbm_open( char *name, int rw, int mode, int dbcachesize ) dbinfo.db_pagesize = DEFAULT_DB_PAGE_SIZE; dbinfo.db_malloc = ldbm_malloc; - db_open( name, DB_TYPE, rw, mode, NULL, &dbinfo, &ret ); + (void) db_open( name, DB_TYPE, rw, mode, NULL, &dbinfo, &ret ); #else void *info; @@ -107,14 +107,9 @@ ldbm_datum_dup( LDBM ldbm, Datum data ) { Datum dup; -#ifdef HAVE_BERKELEY_DB2 - memset( &dup, 0, sizeof( dup )); -#endif + ldbm_datum_init( dup ); if ( data.dsize == 0 ) { - dup.dsize = 0; - dup.dptr = NULL; - return( dup ); } dup.dsize = data.dsize; @@ -131,7 +126,7 @@ ldbm_fetch( LDBM ldbm, Datum key ) int rc; #ifdef HAVE_BERKELEY_DB2 - memset( &data, 0, sizeof( data )); + ldbm_datum_init( data ); data.flags = DB_DBT_MALLOC; @@ -160,6 +155,7 @@ ldbm_store( LDBM ldbm, Datum key, Datum data, int flags ) #else rc = (*ldbm->put)( ldbm, &key, &data, flags & ~LDBM_SYNC ); #endif + if ( flags & LDBM_SYNC ) (*ldbm->sync)( ldbm, 0 ); return( rc ); @@ -193,13 +189,24 @@ ldbm_firstkey( LDBM ldbm ) #ifdef HAVE_BERKELEY_DB2 DBC *dbci; - memset( &key, 0, sizeof( key )); - memset( &data, 0, sizeof( data )); + ldbm_datum_init( key ); + ldbm_datum_init( data ); key.flags = data.flags = DB_DBT_MALLOC; /* acquire a cursor for the DB */ + +# if defined( DB_VERSION_MAJOR ) && defined( DB_VERSION_MINOR ) && \ + DB_VERSION_MAJOR == 2 && DB_VERSION_MINOR < 6 + if ( (*ldbm->cursor)( ldbm, NULL, &dbci )) { + +# else + + if ( (*ldbm->cursor)( ldbm, NULL, &dbci, 0 )) { + +# endif + return( key ); } else { *dbch = dbci; @@ -234,7 +241,7 @@ ldbm_nextkey( LDBM ldbm, Datum key ) #ifdef HAVE_BERKELEY_DB2 void *oldKey = key.dptr; - memset( &data, 0, sizeof( data )); + ldbm_datum_init( data ); data.flags = DB_DBT_MALLOC; @@ -267,7 +274,7 @@ ldbm_errno( LDBM ldbm ) /***************************************************************** * * - * use gdbm * + * use gdbm * * * *****************************************************************/ diff --git a/servers/slapd/back-ldbm/dbcache.c b/servers/slapd/back-ldbm/dbcache.c index 4beef6dd6e..143ed07e3e 100644 --- a/servers/slapd/back-ldbm/dbcache.c +++ b/servers/slapd/back-ldbm/dbcache.c @@ -175,9 +175,8 @@ ldbm_cache_fetch( ) { Datum data; -#ifdef HAVE_BERKELEY_DB2 - memset( &data, 0, sizeof( data ) ); -#endif + + ldbm_datum_init( data ); pthread_mutex_lock( &db->dbc_mutex ); #ifdef reentrant_database diff --git a/servers/slapd/back-ldbm/dn2id.c b/servers/slapd/back-ldbm/dn2id.c index ca8c209b6f..92336d1ce0 100644 --- a/servers/slapd/back-ldbm/dn2id.c +++ b/servers/slapd/back-ldbm/dn2id.c @@ -23,10 +23,8 @@ dn2id_add( Datum key, data; struct ldbminfo *li = (struct ldbminfo *) be->be_private; -#ifdef HAVE_BERKELEY_DB2 - memset( &key, 0, sizeof( key ) ); - memset( &data, 0, sizeof( data ) ); -#endif + ldbm_datum_init( key ); + ldbm_datum_init( data ); Debug( LDAP_DEBUG_TRACE, "=> dn2id_add( \"%s\", %ld )\n", dn, id, 0 ); @@ -68,10 +66,8 @@ dn2id( ID id; Datum key, data; -#ifdef HAVE_BERKELEY_DB2 - memset( &key, 0, sizeof( key ) ); - memset( &data, 0, sizeof( data ) ); -#endif + ldbm_datum_init( key ); + ldbm_datum_init( data ); dn = ch_strdup( dn ); Debug( LDAP_DEBUG_TRACE, "=> dn2id( \"%s\" )\n", dn, 0, 0 ); @@ -125,9 +121,7 @@ dn2id_delete( Datum key; int rc; -#ifdef HAVE_BERKELEY_DB2 - memset( &key, 0, sizeof( key ) ); -#endif + ldbm_datum_init( key ); Debug( LDAP_DEBUG_TRACE, "=> dn2id_delete( \"%s\" )\n", dn, 0, 0 ); diff --git a/servers/slapd/back-ldbm/id2children.c b/servers/slapd/back-ldbm/id2children.c index 23e64f7559..171e6c2618 100644 --- a/servers/slapd/back-ldbm/id2children.c +++ b/servers/slapd/back-ldbm/id2children.c @@ -25,8 +25,9 @@ id2children_add( #ifdef HAVE_BERKELEY_DB2 Datum data; - memset( &key, 0, sizeof( key ) ); - memset( &data, 0, sizeof( data ) ); + + ldbm_datum_init( key ); + ldbm_datum_init( data ); #endif Debug( LDAP_DEBUG_TRACE, "=> id2children_add( %lu, %lu )\n", @@ -82,7 +83,7 @@ id2children_remove( return( -1 ); } - memset( &key, 0, sizeof(key) ); + ldbm_datum_init( key ); sprintf( buf, "%c%ld", EQ_PREFIX, p ? p->e_id : 0 ); key.dptr = buf; key.dsize = strlen( buf ) + 1; @@ -112,9 +113,7 @@ has_children( IDList *idl; char buf[20]; -#ifdef HAVE_BERKELEY_DB2 - memset( &key, 0, sizeof( key ) ); -#endif + ldbm_datum_init( key ); Debug( LDAP_DEBUG_TRACE, "=> has_children( %lu )\n", p->e_id , 0, 0 ); diff --git a/servers/slapd/back-ldbm/id2entry.c b/servers/slapd/back-ldbm/id2entry.c index ab8ff238f1..e42c1f0e51 100644 --- a/servers/slapd/back-ldbm/id2entry.c +++ b/servers/slapd/back-ldbm/id2entry.c @@ -17,10 +17,8 @@ id2entry_add( Backend *be, Entry *e ) Datum key, data; int len, rc, flags; -#ifdef HAVE_BERKELEY_DB2 - memset( &key, 0, sizeof( key ) ); - memset( &data, 0, sizeof( data ) ); -#endif + ldbm_datum_init( key ); + ldbm_datum_init( data ); Debug( LDAP_DEBUG_TRACE, "=> id2entry_add( %lu, \"%s\" )\n", e->e_id, e->e_dn, 0 ); @@ -71,9 +69,7 @@ id2entry_delete( Backend *be, Entry *e ) assert(pthread_rdwr_wchk_np(&e->e_rdwr)); #endif -#ifdef HAVE_BERKELEY_DB2 - memset( &key, 0, sizeof( key ) ); -#endif + ldbm_datum_init( key ); /* XXX - check for writer lock - should also check no reader pending */ Debug (LDAP_DEBUG_TRACE, @@ -112,10 +108,8 @@ id2entry( Backend *be, ID id, int rw ) Datum key, data; Entry *e; -#ifdef HAVE_BERKELEY_DB2 - memset( &key, 0, sizeof( key ) ); - memset( &data, 0, sizeof( data ) ); -#endif + ldbm_datum_init( key ); + ldbm_datum_init( data ); Debug( LDAP_DEBUG_TRACE, "=> id2entry_%s( %ld )\n", rw ? "w" : "r", id, 0 ); diff --git a/servers/slapd/back-ldbm/idl.c b/servers/slapd/back-ldbm/idl.c index 4e47e78ada..ee5e316071 100644 --- a/servers/slapd/back-ldbm/idl.c +++ b/servers/slapd/back-ldbm/idl.c @@ -58,8 +58,9 @@ idl_fetch_one( #ifdef HAVE_BERKELEY_DB2 Datum k2; - memset( &k2, 0, sizeof( k2 ) ); - memset( &data, 0, sizeof( data ) ); + + ldbm_datum_init( data ); + ldbm_datum_init( k2 ); #endif /* Debug( LDAP_DEBUG_TRACE, "=> idl_fetch_one\n", 0, 0, 0 ); */ @@ -84,10 +85,8 @@ idl_fetch( char *kstr; int i, nids; -#ifdef HAVE_BERKELEY_DB2 - memset( &k2, 0, sizeof( k2 ) ); - memset( &data, 0, sizeof( data ) ); -#endif + ldbm_datum_init( k2 ); + ldbm_datum_init( data ); /* Debug( LDAP_DEBUG_TRACE, "=> idl_fetch\n", 0, 0, 0 ); */ @@ -178,9 +177,7 @@ idl_store( Datum data; struct ldbminfo *li = (struct ldbminfo *) be->be_private; -#ifdef HAVE_BERKELEY_DB2 - memset( &data, 0, sizeof( data ) ); -#endif + ldbm_datum_init( data ); /* Debug( LDAP_DEBUG_TRACE, "=> idl_store\n", 0, 0, 0 ); */ @@ -300,9 +297,7 @@ idl_insert_key( char *kstr; Datum k2; -#ifdef HAVE_BERKELEY_DB2 - memset( &k2, 0, sizeof( k2 ) ); -#endif + ldbm_datum_init( k2 ); if ( (idl = idl_fetch_one( be, db, key )) == NULL ) { #ifdef LDBM_DEBUG @@ -664,7 +659,7 @@ idl_delete_key ( kstr = (char *) ch_malloc( key.dsize + 20 ); for ( j = 0; idl->b_ids[j] != NOID; j++ ) { - memset( &k2, 0, sizeof(k2) ); + ldbm_datum_init( k2 ); sprintf( kstr, "%c%s%ld", CONT_PREFIX, key.dptr, idl->b_ids[j] ); k2.dptr = kstr; k2.dsize = strlen( kstr ) + 1; diff --git a/servers/slapd/back-ldbm/index.c b/servers/slapd/back-ldbm/index.c index 819aa21bd4..6ccfbc38fd 100644 --- a/servers/slapd/back-ldbm/index.c +++ b/servers/slapd/back-ldbm/index.c @@ -101,9 +101,7 @@ index_read( char *realval, *tmpval; char buf[BUFSIZ]; -#ifdef HAVE_BERKELEY_DB2 - memset( &key, 0, sizeof( key ) ); -#endif + ldbm_datum_init( key ); prefix = index2prefix( indextype ); Debug( LDAP_DEBUG_TRACE, "=> index_read( \"%s\" \"%c\" \"%s\" )\n", @@ -175,9 +173,7 @@ add_value( char *realval, *tmpval, *s; char buf[BUFSIZ]; -#ifdef HAVE_BERKELEY_DB2 - memset( &key, 0, sizeof( key ) ); -#endif + ldbm_datum_init( key ); prefix = index2prefix( indextype ); Debug( LDAP_DEBUG_TRACE, "=> add_value( \"%c%s\" )\n", prefix, val, 0 ); diff --git a/servers/slapd/tools/centipede.c b/servers/slapd/tools/centipede.c index 48738aa074..d8943a9201 100644 --- a/servers/slapd/tools/centipede.c +++ b/servers/slapd/tools/centipede.c @@ -473,7 +473,7 @@ generate_new_centroids( char **val; char last; - memset( &data, 0 , sizeof( data )); + ldbm_datum_init( data ); if ( verbose ) { printf( "Generating new centroids for..." ); @@ -498,7 +498,7 @@ generate_new_centroids( /* for each value */ for ( j = 0; val[j] != NULL; j++ ) { - memset( &key, 0 , sizeof( key )); + ldbm_datum_init( key ); /* normalize the value */ for ( s = val[j]; *s; s++ ) { @@ -575,13 +575,13 @@ diff_centroids( fflush( stdout ); } - memset( &okey, 0, sizeof( okey )); - memset( &nkey, 0, sizeof( nkey )); - memset( &olast, 0, sizeof( olast )); - memset( &nlast, 0, sizeof( nlast )); - memset( &lastkey, 0, sizeof( lastkey )); - memset( &key, 0, sizeof( key )); - memset( &data, 0, sizeof( data )); + ldbm_datum_init( okey ); + ldbm_datum_init( nkey ); + ldbm_datum_init( olast ); + ldbm_datum_init( nlast ); + ldbm_datum_init( lastkey ); + ldbm_datum_init( key ); + ldbm_datum_init( data ); if ( (mods = (LDAPMod **) malloc( sizeof(LDAPMod *) * 4 )) == NULL || (mods[0] = (LDAPMod *) malloc( sizeof(LDAPMod) )) == NULL || @@ -845,8 +845,8 @@ full_centroid( fflush( stdout ); } - memset( &key, 0, sizeof( key )); - memset( &lastkey, 0, sizeof( lastkey )); + ldbm_datum_init( key ); + ldbm_datum_init( lastkey ); if ( (mods = (LDAPMod **) malloc( sizeof(LDAPMod *) * 3 )) == NULL || (mods[0] = (LDAPMod *) malloc( sizeof(LDAPMod) )) == NULL || diff --git a/servers/slapd/tools/ldbmcat.c b/servers/slapd/tools/ldbmcat.c index 658bf98906..6f2ea10340 100644 --- a/servers/slapd/tools/ldbmcat.c +++ b/servers/slapd/tools/ldbmcat.c @@ -12,43 +12,43 @@ static void usage( char *name ) { - fprintf( stderr, "usage: %s [-n] \n", name ); - exit( 1 ); + fprintf( stderr, "usage: %s [-n] \n", name ); + exit( 1 ); } int main( int argc, char **argv ) { - Datum key, last, data; - LDBM dbp; - int rc, type; - long id; - char *file, *s; - int printid = 1; + Datum key, last, data; + LDBM dbp; + int rc, type; + long id; + char *file, *s; + int printid = 1; #ifdef HAVE_BERKELEY_DB2 - DBC *cursorp; + DBC *cursorp; - memset( &key, 0, sizeof( key )); - memset( &last, 0, sizeof( last )); - memset( &data, 0, sizeof( data )); + ldbm_datum_init( key ); + ldbm_datum_init( last ); + ldbm_datum_init( data ); #endif - if ( argc < 2 || argc > 3 || ( argc == 3 && strcmp( argv[1], "-n" ) - != 0 )) { - usage( argv[0] ); - } - if ( argc == 3 && strcmp( argv[1], "-n" ) == 0 ) { - printid = 0; - file = argv[2]; - } else { - file = argv[1]; - } - - if ( (dbp = ldbm_open( file, LDBM_READER, 0, 0 )) == NULL ) { - perror( file ); - exit ( 1 ); - } + if ( argc < 2 || argc > 3 || ( argc == 3 && strcmp( argv[1], "-n" ) + != 0 )) { + usage( argv[0] ); + } + if ( argc == 3 && strcmp( argv[1], "-n" ) == 0 ) { + printid = 0; + file = argv[2]; + } else { + file = argv[1]; + } + + if ( (dbp = ldbm_open( file, LDBM_READER, 0, 0 )) == NULL ) { + perror( file ); + exit ( 1 ); + } last.dptr = NULL; @@ -59,25 +59,33 @@ main( int argc, char **argv ) for ( key = ldbm_firstkey( dbp ); key.dptr != NULL; key = ldbm_nextkey( dbp, last ) ) #endif - { + { if ( last.dptr != NULL ) ldbm_datum_free( dbp, last ); data = ldbm_fetch( dbp, key ); - s = data.dptr; - if ( !printid && isdigit( *s )) { - if (( s = strchr( s, '\n' )) != NULL ) { - ++s; - } - } - if ( s != NULL ) { - puts( s ); - } - ldbm_datum_free( dbp, data ); + + if (( s = data.dptr ) != NULL ) { + + if ( !printid && isdigit( *s )) { + if (( s = strchr( s, '\n' )) != NULL ) { + ++s; + } + } + if ( s != NULL ) { + puts( s ); + } + + if ( data.dptr != NULL ) { + ldbm_datum_free( dbp, data ); + } + + } + last = key; } if ( last.dptr != NULL ) ldbm_datum_free( dbp, last ); - ldbm_close( dbp ); + ldbm_close( dbp ); - exit( 0 ); + exit( 0 ); } diff --git a/servers/slapd/tools/ldbmtest.c b/servers/slapd/tools/ldbmtest.c index c3bc60153e..ddda1aae12 100644 --- a/servers/slapd/tools/ldbmtest.c +++ b/servers/slapd/tools/ldbmtest.c @@ -67,10 +67,10 @@ main( int argc, char **argv ) #ifdef HAVE_BERKELEY_DB2 DBC *cursorp; - memset( &savekey, 0, sizeof( savekey )); - memset( &key, 0, sizeof( key )); - memset( &data, 0, sizeof( data )); - memset( &last, 0, sizeof( last )); + ldbm_datum_init( savekey ); + ldbm_datum_init( key ); + ldbm_datum_init( data ); + ldbm_datum_init( last ); #endif tailorfile = SLAPD_DEFAULT_CONFIGFILE; @@ -184,7 +184,9 @@ main( int argc, char **argv ) "key: ", NULL, NULL ); } - ldbm_datum_free( dbc->dbc_db, data ); + if ( data.dptr != NULL ) { + ldbm_datum_free( dbc->dbc_db, data ); + } } if ( savekey.dptr != NULL ) ldbm_datum_free( dbc->dbc_db, savekey ); @@ -562,7 +564,9 @@ edit_entry( char c, Datum *data ) perror( tmpname ); return; } - ldbm_datum_free( NULL, *data ); + if ( data->dptr != NULL ) { + ldbm_datum_free( NULL, *data ); + } get_keydata( fp, c, NULL, data ); fclose( fp ); unlink( tmpname ); diff --git a/servers/slapd/tools/ldif2id2children.c b/servers/slapd/tools/ldif2id2children.c index d95442b96c..ded23471aa 100644 --- a/servers/slapd/tools/ldif2id2children.c +++ b/servers/slapd/tools/ldif2id2children.c @@ -152,8 +152,8 @@ main( int argc, char **argv ) int vlen; Datum key, data; - memset( &key, 0, sizeof( key )); - memset( &data, 0, sizeof( data )); + ldbm_datum_init( key ); + ldbm_datum_init( data ); if ( fgets( line, sizeof(line), stdin ) != NULL ) { int len; @@ -240,8 +240,8 @@ main( int argc, char **argv ) char buf2[20]; Datum key, data; - memset( &key, 0, sizeof( key )); - memset( &data, 0, sizeof( data )); + ldbm_datum_init( key ); + ldbm_datum_init( data ); if ( fgets( line, sizeof(line), stdin ) != NULL ) { int len; diff --git a/servers/slapd/tools/ldif2id2entry.c b/servers/slapd/tools/ldif2id2entry.c index 70653f0edb..4f923656ae 100644 --- a/servers/slapd/tools/ldif2id2entry.c +++ b/servers/slapd/tools/ldif2id2entry.c @@ -144,8 +144,8 @@ main( int argc, char **argv ) int vlen; Datum key, data; - memset( &key, 0, sizeof( key )); - memset( &data, 0, sizeof( data )); + ldbm_datum_init( key ); + ldbm_datum_init( data ); if ( fgets( line, sizeof(line), stdin ) != NULL ) { int len, idlen; diff --git a/servers/slapd/tools/ldif2ldbm.c b/servers/slapd/tools/ldif2ldbm.c index 841ad133ee..c25c763189 100644 --- a/servers/slapd/tools/ldif2ldbm.c +++ b/servers/slapd/tools/ldif2ldbm.c @@ -227,8 +227,8 @@ main( int argc, char **argv ) int vlen, indexmask, syntaxmask; Datum key, data; - memset( &key, 0, sizeof( key )); - memset( &data, 0, sizeof( data )); + ldbm_datum_init( key ); + ldbm_datum_init( data ); if ( fgets( line, sizeof(line), stdin ) != NULL ) { int len; diff --git a/servers/slapd/tools/sizecount.c b/servers/slapd/tools/sizecount.c index f4ed1f4a66..fa1765da80 100644 --- a/servers/slapd/tools/sizecount.c +++ b/servers/slapd/tools/sizecount.c @@ -94,8 +94,8 @@ main( int argc, char **argv ) Datum key, data; char *w; - memset( &key, 0, sizeof( key )); - memset( &data, 0, sizeof( data )); + ldbm_datum_init( key ); + ldbm_datum_init( data ); /* update value count */ vcount++; @@ -179,8 +179,8 @@ add( { Datum key, data; - memset( &key, 0, sizeof( key )); - memset( &data, 0, sizeof( data )); + ldbm_datum_init( key ); + ldbm_datum_init( data ); key.dptr = s; key.dsize = strlen( key.dptr ) + 1; @@ -190,6 +190,6 @@ add( (*count)++; (*size) += strlen( key.dptr ); } - if ( freeit ) + if ( freeit && ( key.dptr != NULL ) ) ldbm_datum_free( ldbm, key ); }