| OLD | NEW |
| 1 /* | 1 /* |
| 2 ** 2003 January 11 | 2 ** 2003 January 11 |
| 3 ** | 3 ** |
| 4 ** The author disclaims copyright to this source code. In place of | 4 ** The author disclaims copyright to this source code. In place of |
| 5 ** a legal notice, here is a blessing: | 5 ** a legal notice, here is a blessing: |
| 6 ** | 6 ** |
| 7 ** May you do good and not evil. | 7 ** May you do good and not evil. |
| 8 ** May you find forgiveness for yourself and forgive others. | 8 ** May you find forgiveness for yourself and forgive others. |
| 9 ** May you share freely, never taking more than you give. | 9 ** May you share freely, never taking more than you give. |
| 10 ** | 10 ** |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 ** | 66 ** |
| 67 ** Setting the auth function to NULL disables this hook. The default | 67 ** Setting the auth function to NULL disables this hook. The default |
| 68 ** setting of the auth function is NULL. | 68 ** setting of the auth function is NULL. |
| 69 */ | 69 */ |
| 70 int sqlite3_set_authorizer( | 70 int sqlite3_set_authorizer( |
| 71 sqlite3 *db, | 71 sqlite3 *db, |
| 72 int (*xAuth)(void*,int,const char*,const char*,const char*,const char*), | 72 int (*xAuth)(void*,int,const char*,const char*,const char*,const char*), |
| 73 void *pArg | 73 void *pArg |
| 74 ){ | 74 ){ |
| 75 sqlite3_mutex_enter(db->mutex); | 75 sqlite3_mutex_enter(db->mutex); |
| 76 db->xAuth = xAuth; | 76 db->xAuth = (sqlite3_xauth)xAuth; |
| 77 db->pAuthArg = pArg; | 77 db->pAuthArg = pArg; |
| 78 sqlite3ExpirePreparedStatements(db); | 78 sqlite3ExpirePreparedStatements(db); |
| 79 sqlite3_mutex_leave(db->mutex); | 79 sqlite3_mutex_leave(db->mutex); |
| 80 return SQLITE_OK; | 80 return SQLITE_OK; |
| 81 } | 81 } |
| 82 | 82 |
| 83 /* | 83 /* |
| 84 ** Write an error message into pParse->zErrMsg that explains that the | 84 ** Write an error message into pParse->zErrMsg that explains that the |
| 85 ** user-supplied authorization function returned an illegal value. | 85 ** user-supplied authorization function returned an illegal value. |
| 86 */ | 86 */ |
| (...skipping 14 matching lines...) Expand all Loading... |
| 101 int sqlite3AuthReadCol( | 101 int sqlite3AuthReadCol( |
| 102 Parse *pParse, /* The parser context */ | 102 Parse *pParse, /* The parser context */ |
| 103 const char *zTab, /* Table name */ | 103 const char *zTab, /* Table name */ |
| 104 const char *zCol, /* Column name */ | 104 const char *zCol, /* Column name */ |
| 105 int iDb /* Index of containing database. */ | 105 int iDb /* Index of containing database. */ |
| 106 ){ | 106 ){ |
| 107 sqlite3 *db = pParse->db; /* Database handle */ | 107 sqlite3 *db = pParse->db; /* Database handle */ |
| 108 char *zDb = db->aDb[iDb].zName; /* Name of attached database */ | 108 char *zDb = db->aDb[iDb].zName; /* Name of attached database */ |
| 109 int rc; /* Auth callback return code */ | 109 int rc; /* Auth callback return code */ |
| 110 | 110 |
| 111 rc = db->xAuth(db->pAuthArg, SQLITE_READ, zTab,zCol,zDb,pParse->zAuthContext); | 111 rc = db->xAuth(db->pAuthArg, SQLITE_READ, zTab,zCol,zDb,pParse->zAuthContext |
| 112 #ifdef SQLITE_USER_AUTHENTICATION |
| 113 ,db->auth.zAuthUser |
| 114 #endif |
| 115 ); |
| 112 if( rc==SQLITE_DENY ){ | 116 if( rc==SQLITE_DENY ){ |
| 113 if( db->nDb>2 || iDb!=0 ){ | 117 if( db->nDb>2 || iDb!=0 ){ |
| 114 sqlite3ErrorMsg(pParse, "access to %s.%s.%s is prohibited",zDb,zTab,zCol); | 118 sqlite3ErrorMsg(pParse, "access to %s.%s.%s is prohibited",zDb,zTab,zCol); |
| 115 }else{ | 119 }else{ |
| 116 sqlite3ErrorMsg(pParse, "access to %s.%s is prohibited", zTab, zCol); | 120 sqlite3ErrorMsg(pParse, "access to %s.%s is prohibited", zTab, zCol); |
| 117 } | 121 } |
| 118 pParse->rc = SQLITE_AUTH; | 122 pParse->rc = SQLITE_AUTH; |
| 119 }else if( rc!=SQLITE_IGNORE && rc!=SQLITE_OK ){ | 123 }else if( rc!=SQLITE_IGNORE && rc!=SQLITE_OK ){ |
| 120 sqliteAuthBadReturnCode(pParse); | 124 sqliteAuthBadReturnCode(pParse); |
| 121 } | 125 } |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 /* Don't do any authorization checks if the database is initialising | 205 /* Don't do any authorization checks if the database is initialising |
| 202 ** or if the parser is being invoked from within sqlite3_declare_vtab. | 206 ** or if the parser is being invoked from within sqlite3_declare_vtab. |
| 203 */ | 207 */ |
| 204 if( db->init.busy || IN_DECLARE_VTAB ){ | 208 if( db->init.busy || IN_DECLARE_VTAB ){ |
| 205 return SQLITE_OK; | 209 return SQLITE_OK; |
| 206 } | 210 } |
| 207 | 211 |
| 208 if( db->xAuth==0 ){ | 212 if( db->xAuth==0 ){ |
| 209 return SQLITE_OK; | 213 return SQLITE_OK; |
| 210 } | 214 } |
| 211 rc = db->xAuth(db->pAuthArg, code, zArg1, zArg2, zArg3, pParse->zAuthContext); | 215 rc = db->xAuth(db->pAuthArg, code, zArg1, zArg2, zArg3, pParse->zAuthContext |
| 216 #ifdef SQLITE_USER_AUTHENTICATION |
| 217 ,db->auth.zAuthUser |
| 218 #endif |
| 219 ); |
| 212 if( rc==SQLITE_DENY ){ | 220 if( rc==SQLITE_DENY ){ |
| 213 sqlite3ErrorMsg(pParse, "not authorized"); | 221 sqlite3ErrorMsg(pParse, "not authorized"); |
| 214 pParse->rc = SQLITE_AUTH; | 222 pParse->rc = SQLITE_AUTH; |
| 215 }else if( rc!=SQLITE_OK && rc!=SQLITE_IGNORE ){ | 223 }else if( rc!=SQLITE_OK && rc!=SQLITE_IGNORE ){ |
| 216 rc = SQLITE_DENY; | 224 rc = SQLITE_DENY; |
| 217 sqliteAuthBadReturnCode(pParse); | 225 sqliteAuthBadReturnCode(pParse); |
| 218 } | 226 } |
| 219 return rc; | 227 return rc; |
| 220 } | 228 } |
| 221 | 229 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 240 ** by sqlite3AuthContextPush | 248 ** by sqlite3AuthContextPush |
| 241 */ | 249 */ |
| 242 void sqlite3AuthContextPop(AuthContext *pContext){ | 250 void sqlite3AuthContextPop(AuthContext *pContext){ |
| 243 if( pContext->pParse ){ | 251 if( pContext->pParse ){ |
| 244 pContext->pParse->zAuthContext = pContext->zAuthContext; | 252 pContext->pParse->zAuthContext = pContext->zAuthContext; |
| 245 pContext->pParse = 0; | 253 pContext->pParse = 0; |
| 246 } | 254 } |
| 247 } | 255 } |
| 248 | 256 |
| 249 #endif /* SQLITE_OMIT_AUTHORIZATION */ | 257 #endif /* SQLITE_OMIT_AUTHORIZATION */ |
| OLD | NEW |