From e237f4cc4346bb9ed5fc14b7daea32f133272856 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Thu, 6 Dec 2007 15:58:47 +0000 Subject: [PATCH] Re-introduce hdb dup_compare function, default compares too much --- servers/slapd/back-bdb/dn2id.c | 25 +++++++++++++++++++++++++ servers/slapd/back-bdb/init.c | 2 ++ servers/slapd/back-bdb/proto-bdb.h | 6 ++++++ 3 files changed, 33 insertions(+) diff --git a/servers/slapd/back-bdb/dn2id.c b/servers/slapd/back-bdb/dn2id.c index c360e4cb8f..1f5f75cef0 100644 --- a/servers/slapd/back-bdb/dn2id.c +++ b/servers/slapd/back-bdb/dn2id.c @@ -451,6 +451,31 @@ typedef struct diskNode { unsigned char entryID[sizeof(ID)]; /* variable placement */ } diskNode; +/* Sort function for the sorted duplicate data items of a dn2id key. + * Sorts based on normalized RDN, in length order. + */ +int +hdb_dup_compare( + DB *db, + const DBT *usrkey, + const DBT *curkey +) +{ + diskNode *un, *cn; + int rc, ul, cl; + + un = (diskNode *)usrkey->data; + cn = (diskNode *)curkey->data; + + /* data is not aligned, cannot compare directly */ + ul = un->nrdnlen[0] << 8 | un->nrdnlen[1]; + cl = cn->nrdnlen[0] << 8 | cn->nrdnlen[1]; + + rc = ul - cl; + if( rc ) return rc; + return strcmp( un->nrdn, cn->nrdn ); +} + /* This function constructs a full DN for a given entry. */ int hdb_fix_dn( diff --git a/servers/slapd/back-bdb/init.c b/servers/slapd/back-bdb/init.c index 3d9d89d95d..552540112f 100644 --- a/servers/slapd/back-bdb/init.c +++ b/servers/slapd/back-bdb/init.c @@ -412,6 +412,8 @@ shm_retry: flags |= DB_CREATE; } #else + rc = db->bdi_db->set_dup_compare( db->bdi_db, + bdb_dup_compare ); if ( slapMode & (SLAP_TOOL_READONLY|SLAP_TOOL_READMAIN) ) { flags |= DB_RDONLY; } else { diff --git a/servers/slapd/back-bdb/proto-bdb.h b/servers/slapd/back-bdb/proto-bdb.h index d1691b0808..8e39be0cec 100644 --- a/servers/slapd/back-bdb/proto-bdb.h +++ b/servers/slapd/back-bdb/proto-bdb.h @@ -129,6 +129,7 @@ int bdb_dn2idl( #ifdef BDB_HIER #define bdb_dn2id_parent BDB_SYMBOL(dn2id_parent) +#define bdb_dup_compare BDB_SYMBOL(dup_compare) #define bdb_fix_dn BDB_SYMBOL(fix_dn) int bdb_dn2id_parent( @@ -137,6 +138,11 @@ int bdb_dn2id_parent( EntryInfo *ei, ID *idp ); +int bdb_dup_compare( + DB *db, + const DBT *usrkey, + const DBT *curkey ); + int bdb_fix_dn( Entry *e, int checkit ); #endif -- 2.39.5