From: Howard Chu Date: Sat, 6 Mar 2004 12:41:29 +0000 (+0000) Subject: Store IDs in BeigEndian format on disk X-Git-Tag: OPENLDAP_REL_ENG_2_2_BP~358 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=ea0d619daeb8f2c5427287e71fd5fc904b00e805;p=openldap Store IDs in BeigEndian format on disk --- diff --git a/servers/slapd/back-bdb/dbcache.c b/servers/slapd/back-bdb/dbcache.c index 23d964deaa..3ce25895a7 100644 --- a/servers/slapd/back-bdb/dbcache.c +++ b/servers/slapd/back-bdb/dbcache.c @@ -118,7 +118,6 @@ bdb_db_cache( rc = db->bdi_db->set_h_hash( db->bdi_db, bdb_db_hash ); #endif rc = db->bdi_db->set_flags( db->bdi_db, DB_DUP | DB_DUPSORT ); - rc = db->bdi_db->set_dup_compare( db->bdi_db, bdb_bt_compare ); file = ch_malloc( strlen( name ) + sizeof(BDB_SUFFIX) ); sprintf( file, "%s" BDB_SUFFIX, name ); diff --git a/servers/slapd/back-bdb/id2entry.c b/servers/slapd/back-bdb/id2entry.c index fce1fcdc63..13f958dd46 100644 --- a/servers/slapd/back-bdb/id2entry.c +++ b/servers/slapd/back-bdb/id2entry.c @@ -32,7 +32,9 @@ static int bdb_id2entry_put( DB *db = bdb->bi_id2entry->bdi_db; DBT key, data; struct berval bv; - int rc; + char buf[sizeof(ID)]; + ID tmp; + int i, rc; #ifdef BDB_HIER struct berval odn, ondn; @@ -44,9 +46,16 @@ static int bdb_id2entry_put( e->e_nname = slap_empty_bv; #endif DBTzero( &key ); - key.data = (char *) &e->e_id; + key.data = buf; key.size = sizeof(ID); + /* Set key in BigEndian order */ + tmp = e->e_id; + for ( i=sizeof(ID)-1; i>=0; i-- ) { + buf[i] = tmp & 0xff; + tmp >>= 8; + } + rc = entry_encode( e, &bv ); #ifdef BDB_HIER e->e_name = odn; e->e_nname = ondn; @@ -96,13 +105,20 @@ int bdb_id2entry( DB *db = bdb->bi_id2entry->bdi_db; DBT key, data; struct berval bv; - int rc = 0, ret = 0; + char buf[sizeof(ID)]; + ID tmp; + int i, rc = 0, ret = 0; *e = NULL; DBTzero( &key ); - key.data = (char *) &id; + key.data = buf; key.size = sizeof(ID); + tmp = id; + for ( i=sizeof(ID)-1; i>=0; i-- ) { + buf[i] = tmp & 0xff; + tmp >>= 8; + } DBTzero( &data ); data.flags = DB_DBT_MALLOC; @@ -138,11 +154,18 @@ int bdb_id2entry_delete( struct bdb_info *bdb = (struct bdb_info *) be->be_private; DB *db = bdb->bi_id2entry->bdi_db; DBT key; - int rc; + char buf[sizeof(ID)]; + ID tmp; + int i, rc; DBTzero( &key ); - key.data = (char *) &e->e_id; + key.data = buf; key.size = sizeof(ID); + tmp = e->e_id; + for ( i=sizeof(ID)-1; i>=0; i-- ) { + buf[i] = tmp & 0xff; + tmp >>= 8; + } /* delete from database */ rc = db->del( db, tid, &key, 0 ); diff --git a/servers/slapd/back-bdb/init.c b/servers/slapd/back-bdb/init.c index 7be4e2d954..f037eaf6ee 100644 --- a/servers/slapd/back-bdb/init.c +++ b/servers/slapd/back-bdb/init.c @@ -114,32 +114,6 @@ bdb_db_init( BackendDB *be ) return 0; } -int -bdb_bt_compare( - DB *db, - const DBT *usrkey, - const DBT *curkey -) -{ - unsigned char *u, *c; - int i, x; - - u = usrkey->data; - c = curkey->data; - -#ifdef WORDS_BIGENDIAN - for( i = 0; i < (int)sizeof(ID); i++) -#else - for( i = sizeof(ID)-1; i >= 0; i--) -#endif - { - x = u[i] - c[i]; - if( x ) return x; - } - - return 0; -} - static int bdb_db_open( BackendDB *be ) { @@ -372,8 +346,6 @@ bdb_db_open( BackendDB *be ) } if( i == BDB_ID2ENTRY ) { - rc = db->bdi_db->set_bt_compare( db->bdi_db, - bdb_bt_compare ); rc = db->bdi_db->set_pagesize( db->bdi_db, BDB_ID2ENTRY_PAGESIZE ); if ( slapMode & SLAP_TOOL_READMAIN ) { @@ -385,8 +357,6 @@ bdb_db_open( BackendDB *be ) rc = db->bdi_db->set_flags( db->bdi_db, DB_DUP | DB_DUPSORT ); #ifndef BDB_HIER - rc = db->bdi_db->set_dup_compare( db->bdi_db, - bdb_bt_compare ); if ( slapMode & SLAP_TOOL_READONLY ) { flags |= DB_RDONLY; } else { @@ -395,8 +365,6 @@ bdb_db_open( BackendDB *be ) #else rc = db->bdi_db->set_dup_compare( db->bdi_db, bdb_dup_compare ); - rc = db->bdi_db->set_bt_compare( db->bdi_db, - bdb_bt_compare ); if ( slapMode & (SLAP_TOOL_READONLY|SLAP_TOOL_READMAIN) ) { flags |= DB_RDONLY; } else {