/ Check-in [694662f7]
Login

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

Overview
Comment:Work toward cleaning up the authorizer interface. Work is on-going. This is an incremental check-in. (CVS 6598)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:694662f7860179403e0cc55b45ae8afa45aa7dfb
User & Date: drh 2009-05-04 01:58:31
Context
2009-05-04
11:42
Speed up INSERT operations that add data to UNIQUE or PRIMARY KEY indexes by rationalizing duplicate seek operations. (CVS 6599) check-in: cac4f3d8 user: danielk1977 tags: trunk
01:58
Work toward cleaning up the authorizer interface. Work is on-going. This is an incremental check-in. (CVS 6598) check-in: 694662f7 user: drh tags: trunk
2009-05-03
20:23
Changes to facility full coverage testing of util.c. (CVS 6597) check-in: a6122990 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/auth.c.

    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains code used to implement the sqlite3_set_authorizer()
    13     13   ** API.  This facility is an optional feature of the library.  Embedded
    14     14   ** systems that do not need this facility may omit it by recompiling
    15     15   ** the library with -DSQLITE_OMIT_AUTHORIZATION=1
    16     16   **
    17         -** $Id: auth.c,v 1.29 2007/09/18 15:55:07 drh Exp $
           17  +** $Id: auth.c,v 1.30 2009/05/04 01:58:31 drh Exp $
    18     18   */
    19     19   #include "sqliteInt.h"
    20     20   
    21     21   /*
    22     22   ** All of the code in this file may be omitted by defining a single
    23     23   ** macro.
    24     24   */
................................................................................
    82     82     return SQLITE_OK;
    83     83   }
    84     84   
    85     85   /*
    86     86   ** Write an error message into pParse->zErrMsg that explains that the
    87     87   ** user-supplied authorization function returned an illegal value.
    88     88   */
    89         -static void sqliteAuthBadReturnCode(Parse *pParse, int rc){
    90         -  sqlite3ErrorMsg(pParse, "illegal return value (%d) from the "
    91         -    "authorization function - should be SQLITE_OK, SQLITE_IGNORE, "
    92         -    "or SQLITE_DENY", rc);
           89  +static void sqliteAuthBadReturnCode(Parse *pParse){
           90  +  sqlite3ErrorMsg(pParse, "authorizer malfunction");
    93     91     pParse->rc = SQLITE_ERROR;
    94     92   }
    95     93   
    96     94   /*
    97     95   ** The pExpr should be a TK_COLUMN expression.  The table referred to
    98     96   ** is in pTabList or else it is the NEW or OLD table of a trigger.  
    99     97   ** Check to see if it is OK to read this particular column.
................................................................................
   114    112     const char *zCol;     /* Name of the column of the table */
   115    113     int iSrc;             /* Index in pTabList->a[] of table being read */
   116    114     const char *zDBase;   /* Name of database being accessed */
   117    115     TriggerStack *pStack; /* The stack of current triggers */
   118    116     int iDb;              /* The index of the database the expression refers to */
   119    117   
   120    118     if( db->xAuth==0 ) return;
   121         -  if( pExpr->op!=TK_COLUMN ) return;
          119  +  assert( pExpr->op==TK_COLUMN );
   122    120     iDb = sqlite3SchemaToIndex(pParse->db, pSchema);
   123    121     if( iDb<0 ){
   124    122       /* An attempt to read a column out of a subquery or other
   125    123       ** temporary table. */
   126    124       return;
   127    125     }
   128    126     for(iSrc=0; pTabList && iSrc<pTabList->nSrc; iSrc++){
   129    127       if( pExpr->iTable==pTabList->a[iSrc].iCursor ) break;
   130    128     }
   131         -  if( iSrc>=0 && pTabList && iSrc<pTabList->nSrc ){
          129  +  if( pTabList && iSrc<pTabList->nSrc ){
   132    130       pTab = pTabList->a[iSrc].pTab;
   133    131     }else if( (pStack = pParse->trigStack)!=0 ){
   134    132       /* This must be an attempt to read the NEW or OLD pseudo-tables
   135    133       ** of a trigger.
   136    134       */
   137    135       assert( pExpr->iTable==pStack->newIdx || pExpr->iTable==pStack->oldIdx );
   138    136       pTab = pStack->pTab;
................................................................................
   158    156         sqlite3ErrorMsg(pParse, "access to %s.%s.%s is prohibited", 
   159    157            zDBase, pTab->zName, zCol);
   160    158       }else{
   161    159         sqlite3ErrorMsg(pParse, "access to %s.%s is prohibited",pTab->zName,zCol);
   162    160       }
   163    161       pParse->rc = SQLITE_AUTH;
   164    162     }else if( rc!=SQLITE_OK ){
   165         -    sqliteAuthBadReturnCode(pParse, rc);
          163  +    sqliteAuthBadReturnCode(pParse);
   166    164     }
   167    165   }
   168    166   
   169    167   /*
   170    168   ** Do an authorization check using the code and arguments given.  Return
   171    169   ** either SQLITE_OK (zero) or SQLITE_IGNORE or SQLITE_DENY.  If SQLITE_DENY
   172    170   ** is returned, then the error count and error message in pParse are
................................................................................
   194    192     }
   195    193     rc = db->xAuth(db->pAuthArg, code, zArg1, zArg2, zArg3, pParse->zAuthContext);
   196    194     if( rc==SQLITE_DENY ){
   197    195       sqlite3ErrorMsg(pParse, "not authorized");
   198    196       pParse->rc = SQLITE_AUTH;
   199    197     }else if( rc!=SQLITE_OK && rc!=SQLITE_IGNORE ){
   200    198       rc = SQLITE_DENY;
   201         -    sqliteAuthBadReturnCode(pParse, rc);
          199  +    sqliteAuthBadReturnCode(pParse);
   202    200     }
   203    201     return rc;
   204    202   }
   205    203   
   206    204   /*
   207    205   ** Push an authorization context.  After this routine is called, the
   208    206   ** zArg3 argument to authorization callbacks will be zContext until

Changes to test/auth.test.

     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.  The
    12     12   # focus of this script is testing the sqlite3_set_authorizer() API
    13     13   # and related functionality.
    14     14   #
    15         -# $Id: auth.test,v 1.44 2008/10/27 15:34:33 danielk1977 Exp $
           15  +# $Id: auth.test,v 1.45 2009/05/04 01:58:31 drh Exp $
    16     16   #
    17     17   
    18     18   set testdir [file dirname $argv0]
    19     19   source $testdir/tester.tcl
    20     20   
    21     21   # disable this test if the SQLITE_OMIT_AUTHORIZATION macro is
    22     22   # defined during compilation.
................................................................................
  2137   2137     proc auth {code arg1 arg2 arg3 arg4} {
  2138   2138       if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="ROWID"} {
  2139   2139         return bogus
  2140   2140       }
  2141   2141       return SQLITE_OK
  2142   2142     }
  2143   2143     catchsql {SELECT ROWID,b,c FROM t2}
  2144         -} {1 {illegal return value (999) from the authorization function - should be SQLITE_OK, SQLITE_IGNORE, or SQLITE_DENY}}
         2144  +} {1 {authorizer malfunction}}
  2145   2145   do_test auth-2.9.2 {
  2146   2146     db errorcode
  2147   2147   } {1}
  2148   2148   do_test auth-2.10 {
  2149   2149     proc auth {code arg1 arg2 arg3 arg4} {
  2150   2150       if {$code=="SQLITE_SELECT"} {
  2151   2151         return bogus
  2152   2152       }
  2153   2153       return SQLITE_OK
  2154   2154     }
  2155   2155     catchsql {SELECT ROWID,b,c FROM t2}
  2156         -} {1 {illegal return value (1) from the authorization function - should be SQLITE_OK, SQLITE_IGNORE, or SQLITE_DENY}}
         2156  +} {1 {authorizer malfunction}}
  2157   2157   do_test auth-2.11.1 {
  2158   2158     proc auth {code arg1 arg2 arg3 arg4} {
  2159   2159       if {$code=="SQLITE_READ" && $arg2=="a"} {
  2160   2160         return SQLITE_IGNORE
  2161   2161       }
  2162   2162       return SQLITE_OK
  2163   2163     }

Changes to test/auth3.test.

     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   #
    12     12   # Test that the truncate optimization is disabled if the SQLITE_DELETE
    13     13   # authorization callback returns SQLITE_IGNORE.
    14     14   #
    15         -# $Id: auth3.test,v 1.1 2008/10/27 15:34:33 danielk1977 Exp $
           15  +# $Id: auth3.test,v 1.2 2009/05/04 01:58:31 drh Exp $
    16     16   #
    17     17   
    18     18   set testdir [file dirname $argv0]
    19     19   source $testdir/tester.tcl
    20     20   
    21     21   # disable this test if the SQLITE_OMIT_AUTHORIZATION macro is
    22     22   # defined during compilation.
................................................................................
    53     53   do_test auth3.1.2 {
    54     54     set ::authcode SQLITE_DENY
    55     55     catchsql { DELETE FROM t1 }
    56     56   } {1 {not authorized}}
    57     57   do_test auth3.1.3 {
    58     58     set ::authcode SQLITE_INVALID
    59     59     catchsql { DELETE FROM t1 }
    60         -} {1 {illegal return value (1) from the authorization function - should be SQLITE_OK, SQLITE_IGNORE, or SQLITE_DENY}}
           60  +} {1 {authorizer malfunction}}
    61     61   do_test auth3.1.4 {
    62     62     execsql { SELECT * FROM t1 }
    63     63   } {1 2 3 4 5 6}
    64     64   do_test auth3-1.5 {
    65     65     set ::authcode SQLITE_IGNORE
    66     66     execsql { 
    67     67       DELETE FROM t1;