/ Check-in [2bb38bb9]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Enhancements to the secure_delete pragma to make it easier to use.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 2bb38bb96ff6b9fb91dd1cf214041cf113ac5508
User & Date: drh 2010-02-12 19:46:27
Context
2010-02-13
02:31
Merged tracing and initialization changes from mutex_unix.c into mutex_w32.c. check-in: 942aa1f6 user: shaneh tags: trunk
2010-02-12
19:46
Enhancements to the secure_delete pragma to make it easier to use. check-in: 2bb38bb9 user: drh tags: trunk
18:18
Allow the secure-delete setting to be changed at run-time using a pragma. The SQLITE_SECURE_DELETE compile-time option determines the default setting. check-in: f72f8a87 user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/attach.c.

140
141
142
143
144
145
146


147
148
149
150
151
152
153
      zErrDyn = sqlite3MPrintf(db, 
        "attached databases must use the same text encoding as main database");
      rc = SQLITE_ERROR;
    }
    pPager = sqlite3BtreePager(aNew->pBt);
    sqlite3PagerLockingMode(pPager, db->dfltLockMode);
    sqlite3PagerJournalMode(pPager, db->dfltJournalMode);


  }
  aNew->zName = sqlite3DbStrDup(db, zName);
  aNew->safety_level = 3;

#if SQLITE_HAS_CODEC
  if( rc==SQLITE_OK ){
    extern int sqlite3CodecAttach(sqlite3*, int, const void*, int);







>
>







140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
      zErrDyn = sqlite3MPrintf(db, 
        "attached databases must use the same text encoding as main database");
      rc = SQLITE_ERROR;
    }
    pPager = sqlite3BtreePager(aNew->pBt);
    sqlite3PagerLockingMode(pPager, db->dfltLockMode);
    sqlite3PagerJournalMode(pPager, db->dfltJournalMode);
    sqlite3BtreeSecureDelete(aNew->pBt,
                             sqlite3BtreeSecureDelete(db->aDb[0].pBt,-1) );
  }
  aNew->zName = sqlite3DbStrDup(db, zName);
  aNew->safety_level = 3;

#if SQLITE_HAS_CODEC
  if( rc==SQLITE_OK ){
    extern int sqlite3CodecAttach(sqlite3*, int, const void*, int);

Changes to src/btree.c.

2168
2169
2170
2171
2172
2173
2174

2175
2176
2177
2178
2179
2180
2181
/*
** Set the secureDelete flag if newFlag is 0 or 1.  If newFlag is -1,
** then make no changes.  Always return the value of the secureDelete
** setting after the change.
*/
int sqlite3BtreeSecureDelete(Btree *p, int newFlag){
  int b;

  sqlite3BtreeEnter(p);
  if( newFlag>=0 ){
    p->pBt->secureDelete = (newFlag!=0) ? 1 : 0;
  } 
  b = p->pBt->secureDelete;
  sqlite3BtreeLeave(p);
  return b;







>







2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
/*
** Set the secureDelete flag if newFlag is 0 or 1.  If newFlag is -1,
** then make no changes.  Always return the value of the secureDelete
** setting after the change.
*/
int sqlite3BtreeSecureDelete(Btree *p, int newFlag){
  int b;
  if( p==0 ) return 0;
  sqlite3BtreeEnter(p);
  if( newFlag>=0 ){
    p->pBt->secureDelete = (newFlag!=0) ? 1 : 0;
  } 
  b = p->pBt->secureDelete;
  sqlite3BtreeLeave(p);
  return b;

Changes to src/pragma.c.

426
427
428
429
430
431
432






433
434
435
436
437
438
439
  */
  if( sqlite3StrICmp(zLeft,"secure_delete")==0 ){
    Btree *pBt = pDb->pBt;
    int b = -1;
    assert( pBt!=0 );
    if( zRight ){
      b = getBoolean(zRight);






    }
    b = sqlite3BtreeSecureDelete(pBt, b);
    returnSingleInt(pParse, "secure_delete", b);
  }else

  /*
  **  PRAGMA [database.]page_count







>
>
>
>
>
>







426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
  */
  if( sqlite3StrICmp(zLeft,"secure_delete")==0 ){
    Btree *pBt = pDb->pBt;
    int b = -1;
    assert( pBt!=0 );
    if( zRight ){
      b = getBoolean(zRight);
    }
    if( pId2->n==0 && b>=0 ){
      int ii;
      for(ii=0; ii<db->nDb; ii++){
        sqlite3BtreeSecureDelete(db->aDb[ii].pBt, b);
      }
    }
    b = sqlite3BtreeSecureDelete(pBt, b);
    returnSingleInt(pParse, "secure_delete", b);
  }else

  /*
  **  PRAGMA [database.]page_count

Added test/securedel.test.



















































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# 2010 January 12
#
# The author disclaims copyright to this source code.  In place of
# a legal notice, here is a blessing:
#
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#*************************************************************************
#
# Tests for the secure_delete pragma.
#

set testdir [file dirname $argv0]
source $testdir/tester.tcl

unset -nocomplain DEFAULT_SECDEL
set DEFAULT_SECDEL 0
ifcapable secure_delete {
  set DEFAULT_SECDEL 1
}


do_test securedel-1.0 {
  db eval {PRAGMA secure_delete;}
} $DEFAULT_SECDEL

file delete -force test2.db test2.db-journal
do_test securedel-1.1 {
  db eval {
    ATTACH 'test2.db' AS db2;
    PRAGMA main.secure_delete=ON;
    PRAGMA db2.secure_delete;
  }
} [list 1 $DEFAULT_SECDEL]
do_test securedel-1.2 {
  db eval {
    PRAGMA main.secure_delete=OFF;
    PRAGMA db2.secure_delete;
  }
} [list 0 $DEFAULT_SECDEL]
do_test securedel-1.3 {
  db eval {
    PRAGMA secure_delete=OFF;
    PRAGMA db2.secure_delete;
  }
} {0 0}
do_test securedel-1.4 {
breakpoint
  db eval {
    PRAGMA secure_delete=ON;
    PRAGMA db2.secure_delete;
  }
} {1 1}

do_test securedel-2.1 {
  db eval {
    DETACH db2;
    ATTACH 'test2.db' AS db2;
    PRAGMA db2.secure_delete;
  }
} 1
do_test securedel-2.2 {
  db eval {
    DETACH db2;
    PRAGMA main.secure_delete=OFF;
    ATTACH 'test2.db' AS db2;
    PRAGMA db2.secure_delete;
  }
} {0 0}

finish_test