]> git.sur5r.net Git - openldap/commitdiff
Add checksum keyword to enable DB checksum validation
authorHoward Chu <hyc@openldap.org>
Wed, 15 Oct 2008 08:13:56 +0000 (08:13 +0000)
committerHoward Chu <hyc@openldap.org>
Wed, 15 Oct 2008 08:13:56 +0000 (08:13 +0000)
servers/slapd/back-bdb/back-bdb.h
servers/slapd/back-bdb/config.c
servers/slapd/back-bdb/dbcache.c
servers/slapd/back-bdb/init.c

index 7ef6fd376126f17725dfd11ecc2d2c0b14056541..e230af1bb3f719b832ae61bace3809d5f9d57b60 100644 (file)
@@ -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;
index 5c7c1bac2072a9c108d8f6b043116c282bde8651..74331beb9ed6ee6a0357128835848fb32f892284 100644 (file)
@@ -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);
index 8de7a9c63bcee7d90fd14f98f3660a25345d693f..7af43edd521ef88118c70a107b545348250d34ca 100644 (file)
@@ -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;
index 79dfee9c517562681e069207bfcb2c05c8550502..8da08d9506d1bad4d817e88c221583c5b7038a7f 100644 (file)
@@ -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 ) {