From 3be39979ea439466781fd216e97d2113951ca704 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Wed, 15 Oct 2008 08:13:56 +0000 Subject: [PATCH] Add checksum keyword to enable DB checksum validation --- servers/slapd/back-bdb/back-bdb.h | 1 + servers/slapd/back-bdb/config.c | 22 +++++++++++++++++++++- servers/slapd/back-bdb/dbcache.c | 13 +++++++++++++ servers/slapd/back-bdb/init.c | 14 ++++++++++++++ 4 files changed, 49 insertions(+), 1 deletion(-) diff --git a/servers/slapd/back-bdb/back-bdb.h b/servers/slapd/back-bdb/back-bdb.h index 7ef6fd3761..e230af1bb3 100644 --- a/servers/slapd/back-bdb/back-bdb.h +++ b/servers/slapd/back-bdb/back-bdb.h @@ -233,6 +233,7 @@ struct bdb_info { #define BDB_UPD_CONFIG 0x04 #define BDB_DEL_INDEX 0x08 #define BDB_RE_OPEN 0x10 +#define BDB_CHKSUM 0x20 #ifdef BDB_HIER int bi_modrdns; /* number of modrdns completed */ ldap_pvt_thread_mutex_t bi_modrdns_mutex; diff --git a/servers/slapd/back-bdb/config.c b/servers/slapd/back-bdb/config.c index 5c7c1bac20..74331beb9e 100644 --- a/servers/slapd/back-bdb/config.c +++ b/servers/slapd/back-bdb/config.c @@ -51,7 +51,8 @@ enum { BDB_LOCKD, BDB_SSTACK, BDB_MODE, - BDB_PGSIZE + BDB_PGSIZE, + BDB_CHECKSUM }; static ConfigTable bdbcfg[] = { @@ -74,6 +75,10 @@ static ConfigTable bdbcfg[] = { bdb_cf_gen, "( OLcfgDbAt:1.2 NAME 'olcDbCheckpoint' " "DESC 'Database checkpoint interval in kbytes and minutes' " "SYNTAX OMsDirectoryString SINGLE-VALUE )",NULL, NULL }, + { "checksum", NULL, 1, 2, 0, ARG_ON_OFF|ARG_MAGIC|BDB_CHECKSUM, + bdb_cf_gen, "( OLcfgDbAt:1.16 NAME 'olcDbChecksum' " + "DESC 'Enable database checksum validation' " + "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL }, { "cryptfile", "file", 2, 2, 0, ARG_STRING|ARG_MAGIC|BDB_CRYPTFILE, bdb_cf_gen, "( OLcfgDbAt:1.13 NAME 'olcDbCryptFile' " "DESC 'Pathname of file containing the DB encryption key' " @@ -467,6 +472,11 @@ bdb_cf_gen( ConfigArgs *c ) c->value_int = 1; break; + case BDB_CHECKSUM: + if ( bdb->bi_flags & BDB_CHKSUM ) + c->value_int = 1; + break; + case BDB_INDEX: bdb_attr_index_unparse( bdb, &c->rvalue_vals ); if ( !c->rvalue_vals ) rc = 1; @@ -577,6 +587,9 @@ bdb_cf_gen( ConfigArgs *c ) case BDB_NOSYNC: bdb->bi_dbenv->set_flags( bdb->bi_dbenv, DB_TXN_NOSYNC, 0 ); break; + case BDB_CHECKSUM: + bdb->bi_flags &= ~BDB_CHKSUM; + break; case BDB_INDEX: if ( c->valx == -1 ) { int i; @@ -839,6 +852,13 @@ bdb_cf_gen( ConfigArgs *c ) } break; + case BDB_CHECKSUM: + if ( c->value_int ) + bdb->bi_flags |= BDB_CHKSUM; + else + bdb->bi_flags &= ~BDB_CHKSUM; + break; + case BDB_INDEX: rc = bdb_attr_index_config( bdb, c->fname, c->lineno, c->argc - 1, &c->argv[1], &c->reply); diff --git a/servers/slapd/back-bdb/dbcache.c b/servers/slapd/back-bdb/dbcache.c index 8de7a9c63b..7af43edd52 100644 --- a/servers/slapd/back-bdb/dbcache.c +++ b/servers/slapd/back-bdb/dbcache.c @@ -144,6 +144,19 @@ bdb_db_cache( } } + if( bdb->bi_flags & BDB_CHKSUM ) { + rc = db->bdi_db->set_flags( db->bdi_db, DB_CHKSUM ); + if ( rc ) { + Debug( LDAP_DEBUG_ANY, + "bdb_db_cache: db set_flags(DB_CHKSUM)(%s) failed: %s (%d)\n", + bdb->bi_dbenv_home, db_strerror(rc), rc ); + ldap_pvt_thread_mutex_unlock( &bdb->bi_database_mutex ); + db->bdi_db->close( db->bdi_db, 0 ); + ch_free( db ); + return rc; + } + } + /* If no explicit size set, use the default */ flags = bdb_db_findsize( bdb, name ); if ( !flags ) flags = BDB_PAGESIZE; diff --git a/servers/slapd/back-bdb/init.c b/servers/slapd/back-bdb/init.c index 79dfee9c51..8da08d9506 100644 --- a/servers/slapd/back-bdb/init.c +++ b/servers/slapd/back-bdb/init.c @@ -416,6 +416,20 @@ shm_retry: } } + if( bdb->bi_flags & BDB_CHKSUM ) { + rc = db->bdi_db->set_flags( db->bdi_db, DB_CHKSUM ); + if ( rc ) { + snprintf(cr->msg, sizeof(cr->msg), + "database \"%s\": db set_flags(DB_CHKSUM)(%s) failed: %s (%d).", + be->be_suffix[0].bv_val, + bdb->bi_dbenv_home, db_strerror(rc), rc ); + Debug( LDAP_DEBUG_ANY, + LDAP_XSTRING(bdb_db_open) ": %s\n", + cr->msg, 0, 0 ); + goto fail; + } + } + rc = bdb_db_findsize( bdb, (struct berval *)&bdbi_databases[i].name ); if( i == BDB_ID2ENTRY ) { -- 2.39.5