~ubuntu-branches/ubuntu/maverick/sqlite3/maverick-updates

« back to all changes in this revision

Viewing changes to src/auth.c

  • Committer: Bazaar Package Importer
  • Author(s): Laszlo Boszormenyi (GCS)
  • Date: 2009-05-31 16:28:06 UTC
  • mfrom: (9.1.1 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090531162806-583oaj2nn948jxkc
Tags: 3.6.14.2-1
* New upstream release. Disable ICU support, it causes more trouble than
  good.
* Add 20-hurd-locking-style.patch for proper locking on Hurd
  (closes: #529734).

Show diffs side-by-side

added added

removed removed

Lines of Context:
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.31 2009/05/04 18:01:40 drh Exp $
18
18
*/
19
19
#include "sqliteInt.h"
20
20
 
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
 
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
 
  for(iSrc=0; pTabList && iSrc<pTabList->nSrc; iSrc++){
129
 
    if( pExpr->iTable==pTabList->a[iSrc].iCursor ) break;
130
 
  }
131
 
  if( iSrc>=0 && pTabList && iSrc<pTabList->nSrc ){
 
126
  if( pTabList ){
 
127
    for(iSrc=0; ALWAYS(iSrc<pTabList->nSrc); iSrc++){
 
128
      if( pExpr->iTable==pTabList->a[iSrc].iCursor ) break;
 
129
    }
 
130
    assert( iSrc<pTabList->nSrc );
132
131
    pTab = pTabList->a[iSrc].pTab;
133
 
  }else if( (pStack = pParse->trigStack)!=0 ){
134
 
    /* This must be an attempt to read the NEW or OLD pseudo-tables
135
 
    ** of a trigger.
136
 
    */
137
 
    assert( pExpr->iTable==pStack->newIdx || pExpr->iTable==pStack->oldIdx );
138
 
    pTab = pStack->pTab;
 
132
  }else{
 
133
    pStack = pParse->trigStack;
 
134
    if( ALWAYS(pStack) ){
 
135
      /* This must be an attempt to read the NEW or OLD pseudo-tables
 
136
      ** of a trigger.
 
137
      */
 
138
      assert( pExpr->iTable==pStack->newIdx || pExpr->iTable==pStack->oldIdx );
 
139
      pTab = pStack->pTab;
 
140
    }
139
141
  }
140
 
  if( pTab==0 ) return;
 
142
  if( NEVER(pTab==0) ) return;
141
143
  if( pExpr->iColumn>=0 ){
142
144
    assert( pExpr->iColumn<pTab->nCol );
143
145
    zCol = pTab->aCol[pExpr->iColumn].zName;
162
164
    }
163
165
    pParse->rc = SQLITE_AUTH;
164
166
  }else if( rc!=SQLITE_OK ){
165
 
    sqliteAuthBadReturnCode(pParse, rc);
 
167
    sqliteAuthBadReturnCode(pParse);
166
168
  }
167
169
}
168
170
 
198
200
    pParse->rc = SQLITE_AUTH;
199
201
  }else if( rc!=SQLITE_OK && rc!=SQLITE_IGNORE ){
200
202
    rc = SQLITE_DENY;
201
 
    sqliteAuthBadReturnCode(pParse, rc);
 
203
    sqliteAuthBadReturnCode(pParse);
202
204
  }
203
205
  return rc;
204
206
}
213
215
  AuthContext *pContext, 
214
216
  const char *zContext
215
217
){
 
218
  assert( pParse );
216
219
  pContext->pParse = pParse;
217
 
  if( pParse ){
218
 
    pContext->zAuthContext = pParse->zAuthContext;
219
 
    pParse->zAuthContext = zContext;
220
 
  }
 
220
  pContext->zAuthContext = pParse->zAuthContext;
 
221
  pParse->zAuthContext = zContext;
221
222
}
222
223
 
223
224
/*