Commit abbcc737 authored by Kurt Zeilenga's avatar Kurt Zeilenga
Browse files

Import ksp's changes to support newer versions of DB2 (ITS#27).

parent 14741c26
......@@ -8,6 +8,7 @@ Changes included in OpenLDAP 1.1.2
Fixed slapd/nonauthorized add bug (ITS#26)
Fixed misc. overlapping strcpy bugs
Fixed misc. memory leaks
Update DB2 support for newer SleepyCat releases (ITS#27)
Update slapd/slurpd to workaround FreeBSD pthread_exit bug (ITS#28)
Build environment
Fixed --disable-crypt/-disable-cleartext options
......
......@@ -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_ */
......@@ -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 *
* *
*****************************************************************/
......
......@@ -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
......
......@@ -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 );
......
......@@ -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 );
......
......@@ -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 );
......
......@@ -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;
......
......@@ -99,9 +99,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",
......@@ -173,9 +171,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 );
......
......@@ -474,7 +474,7 @@ generate_new_centroids(
char **val;
char last;
memset( &data, 0 , sizeof( data ));
ldbm_datum_init( data );
if ( verbose ) {
printf( "Generating new centroids for..." );
......@@ -499,7 +499,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++ ) {
......@@ -576,13 +576,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 ||
......@@ -846,8 +846,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 ||
......
......@@ -12,43 +12,43 @@
static void
usage( char *name )
{
fprintf( stderr, "usage: %s [-n] <filename>\n", name );
exit( 1 );
fprintf( stderr, "usage: %s [-n] <filename>\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 );
}
......@@ -70,10 +70,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;
......@@ -187,7 +187,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 );
......@@ -565,7 +567,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 );
......
......@@ -155,8 +155,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;
......@@ -243,8 +243,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;
......
......@@ -147,8 +147,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;
......
......@@ -230,8 +230,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;
......
......@@ -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 );
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment