[patches] [PATCH V2 8/9] sql: remove sqlite authorization
Bulat Niatshin
niatshin at tarantool.org
Tue Feb 27 16:54:53 MSK 2018
Remove all sqlite code related to SQLite embedded authorization.
It is completely unnecessary right now, because in the near
future authorization will be handled by Tarantool grants.
For #3119
---
src/box/sql/CMakeLists.txt | 1 -
src/box/sql/alter.c | 14 ----
src/box/sql/build.c | 140 +-----------------------------------
src/box/sql/delete.c | 19 +----
src/box/sql/fkey.c | 16 -----
src/box/sql/func.c | 3 -
src/box/sql/insert.c | 3 -
src/box/sql/main.c | 4 --
src/box/sql/prepare.c | 11 ---
src/box/sql/resolve.c | 24 -------
src/box/sql/select.c | 13 ----
src/box/sql/sqlite3.h | 174 +++------------------------------------------
src/box/sql/sqliteInt.h | 73 -------------------
src/box/sql/trigger.c | 28 --------
src/box/sql/update.c | 23 ------
15 files changed, 10 insertions(+), 536 deletions(-)
diff --git a/src/box/sql/CMakeLists.txt b/src/box/sql/CMakeLists.txt
index 9a2556df5..238e18578 100644
--- a/src/box/sql/CMakeLists.txt
+++ b/src/box/sql/CMakeLists.txt
@@ -13,7 +13,6 @@ set(SRCDIR ${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${SRCDIR})
-add_definitions(-DSQLITE_OMIT_AUTHORIZATION=1)
add_definitions(-DSQLITE_MAX_WORKER_THREADS=0)
add_definitions(-DTHREADSAFE=0)
add_definitions(-DSQLITE_DEFAULT_FOREIGN_KEYS=1)
diff --git a/src/box/sql/alter.c b/src/box/sql/alter.c
index 33194c98e..c8dda9633 100644
--- a/src/box/sql/alter.c
+++ b/src/box/sql/alter.c
@@ -114,13 +114,6 @@ sqlite3AlterRenameTable(Parse * pParse, /* Parser context. */
}
#endif
-#ifndef SQLITE_OMIT_AUTHORIZATION
- /* Invoke the authorization callback. */
- if (sqlite3AuthCheck(pParse, SQLITE_ALTER_TABLE, zDb, pTab->zName, 0)) {
- goto exit_rename_table;
- }
-#endif
-
/* Begin a transaction for database.
* Then modify the schema cookie (since the ALTER TABLE modifies the
* schema).
@@ -173,13 +166,6 @@ sqlite3AlterFinishAddColumn(Parse * pParse, Token * pColDef)
pTab = sqlite3FindTable(db, zTab);
assert(pTab);
-#ifndef SQLITE_OMIT_AUTHORIZATION
- /* Invoke the authorization callback. */
- if (sqlite3AuthCheck(pParse, SQLITE_ALTER_TABLE, zDb, pTab->zName, 0)) {
- return;
- }
-#endif
-
/* If the default value for the new column was specified with a
* literal NULL, then set pDflt to 0. This simplifies checking
* for an SQL NULL default below.
diff --git a/src/box/sql/build.c b/src/box/sql/build.c
index a32e67ddd..593a365da 100644
--- a/src/box/sql/build.c
+++ b/src/box/sql/build.c
@@ -84,18 +84,6 @@ sqlite3FinishCoding(Parse * pParse)
if (v) {
sqlite3VdbeAddOp0(v, OP_Halt);
-#if SQLITE_USER_AUTHENTICATION
- if (pParse->nTableLock > 0 && db->init.busy == 0) {
- sqlite3UserAuthInit(db);
- if (db->auth.authLevel < UAUTH_User) {
- sqlite3ErrorMsg(pParse,
- "user not authenticated");
- pParse->rc = SQLITE_AUTH_USER;
- return;
- }
- }
-#endif
-
/* The cookie mask contains one bit for each database file open.
* (Bit 0 is for main, bit 1 is for temp, and so forth.) Bits are
* set for each database that is used. Generate code to start a
@@ -198,18 +186,6 @@ sqlite3NestedParse(Parse * pParse, const char *zFormat, ...)
pParse->nested--;
}
-#if SQLITE_USER_AUTHENTICATION
-/*
- * Return TRUE if zTable is the name of the system table that stores the
- * list of users and their access credentials.
- */
-int
-sqlite3UserAuthTable(const char *zTable)
-{
- return sqlite3_stricmp(zTable, "sqlite_user") == 0;
-}
-#endif
-
/*
* Locate the in-memory structure that describes a particular database
* table given the name of that table and (optionally) the name of the
@@ -225,16 +201,6 @@ sqlite3UserAuthTable(const char *zTable)
Table *
sqlite3FindTable(sqlite3 * db, const char *zName)
{
-#if SQLITE_USER_AUTHENTICATION
- /* Only the admin user is allowed to know that the sqlite_user table
- * exists
- */
- if (db->auth.authLevel < UAUTH_Admin
- && sqlite3UserAuthTable(zName) != 0) {
- return 0;
- }
-#endif
-
return sqlite3HashFind(&db->pSchema->tblHash, zName);
}
@@ -663,26 +629,6 @@ sqlite3StartTable(Parse *pParse, Token *pName, int noErr)
pParse->sNameToken = *pName;
if (zName == 0)
return;
-#ifndef SQLITE_OMIT_AUTHORIZATION
- assert(isTemp == 0 || isTemp == 1);
- assert(isView == 0 || (isView == 1 && isTemp == 0));
- {
- static const u8 aCode[] = {
- SQLITE_CREATE_TABLE,
- SQLITE_CREATE_TEMP_TABLE,
- SQLITE_CREATE_VIEW
- };
- char *zDb = db->mdb.zDbSName;
- if (sqlite3AuthCheck
- (pParse, SQLITE_INSERT, MASTER_NAME, 0, zDb)) {
- goto begin_table_error;
- }
- if (sqlite3AuthCheck(pParse, (int)aCode[isTemp + 2 * isView],
- zName, 0, zDb)) {
- goto begin_table_error;
- }
- }
-#endif
/*
* Make sure the new table name does not collide with an
@@ -2133,9 +2079,6 @@ sqlite3ViewGetColumnNames(Parse * pParse, Table * pTable)
int nErr = 0; /* Number of errors encountered */
int n; /* Temporarily holds the number of cursors assigned */
sqlite3 *db = pParse->db; /* Database connection for malloc errors */
-#ifndef SQLITE_OMIT_AUTHORIZATION
- sqlite3_xauth xAuth; /* Saved xAuth pointer */
-#endif
assert(pTable);
@@ -2182,14 +2125,7 @@ sqlite3ViewGetColumnNames(Parse * pParse, Table * pTable)
sqlite3SrcListAssignCursors(pParse, pSel->pSrc);
pTable->nCol = -1;
db->lookaside.bDisable++;
-#ifndef SQLITE_OMIT_AUTHORIZATION
- xAuth = db->xAuth;
- db->xAuth = 0;
pSelTab = sqlite3ResultSetOfSelect(pParse, pSel);
- db->xAuth = xAuth;
-#else
- pSelTab = sqlite3ResultSetOfSelect(pParse, pSel);
-#endif
pParse->nTab = n;
if (pTable->pCheck) {
/* CREATE VIEW name(arglist) AS ...
@@ -2401,27 +2337,6 @@ sqlite3DropTable(Parse * pParse, SrcList * pName, int isView, int noErr)
sqlite3CodeVerifySchema(pParse);
goto exit_drop_table;
}
-#ifndef SQLITE_OMIT_AUTHORIZATION
- {
- int code;
- const char *zTab = MASTER_NAME;
- char *zDb = db->mdb.zDbSName;
- if (sqlite3AuthCheck(pParse, SQLITE_DELETE, zTab, 0, zDb)) {
- goto exit_drop_table;
- }
- if (isView)
- code = SQLITE_DROP_VIEW;
- else
- code = SQLITE_DROP_TABLE;
- if (sqlite3AuthCheck(pParse, code, pTab->zName, NULL, zDb)) {
- goto exit_drop_table;
- }
- if (sqlite3AuthCheck
- (pParse, SQLITE_DELETE, pTab->zName, 0, zDb)) {
- goto exit_drop_table;
- }
- }
-#endif
#ifndef SQLITE_OMIT_VIEW
/* Ensure DROP TABLE is not used on a view, and DROP VIEW is not used
* on a table.
@@ -2640,12 +2555,6 @@ sqlite3RefillIndex(Parse * pParse, Index * pIndex, int memRootPage)
KeyInfo *pKey; /* KeyInfo for index */
int regRecord; /* Register holding assembled index record */
sqlite3 *db = pParse->db; /* The database connection */
-#ifndef SQLITE_OMIT_AUTHORIZATION
- if (sqlite3AuthCheck(pParse, SQLITE_REINDEX, pIndex->zName, 0,
- db->mdb.zDbSName)) {
- return;
- }
-#endif
v = sqlite3GetVdbe(pParse);
if (v == 0)
return;
@@ -2986,22 +2895,6 @@ sqlite3CreateIndex(Parse * pParse, /* All information about this parse */
}
}
- /* Check for authorization to create an index.
- */
-#ifndef SQLITE_OMIT_AUTHORIZATION
- {
- const char *zDb = pDb->zDbSName;
- if (sqlite3AuthCheck
- (pParse, SQLITE_INSERT, MASTER_NAME, 0, zDb)) {
- goto exit_create_index;
- }
- i = SQLITE_CREATE_INDEX;
- if (sqlite3AuthCheck(pParse, i, zName, pTab->zName, zDb)) {
- goto exit_create_index;
- }
- }
-#endif
-
/* If pList==0, it means this routine was called to make a primary
* key out of the last column added to the table under construction.
* So create a fake list to simulate this.
@@ -3409,20 +3302,6 @@ sqlite3DropIndex(Parse * pParse, SrcList * pName, Token * pName2, int ifExists)
0);
goto exit_drop_index;
}
-#ifndef SQLITE_OMIT_AUTHORIZATION
- {
- int code = SQLITE_DROP_INDEX;
- const char *zDb = db->mdb.zDbSName;
- const char *zTab = MASTER_NAME;
- if (sqlite3AuthCheck(pParse, SQLITE_DELETE, zTab, 0, zDb)) {
- goto exit_drop_index;
- }
- if (sqlite3AuthCheck(pParse, code, pIndex->zName,
- pIndex->pTable->zName, zDb)) {
- goto exit_drop_index;
- }
- }
-#endif
/* Generate code to remove the index and from the master table */
sqlite3BeginWriteOperation(pParse, 1);
@@ -3880,9 +3759,6 @@ sqlite3BeginTransaction(Parse * pParse, int MAYBE_UNUSED type)
assert(pParse != 0);
db = pParse->db;
assert(db != 0);
- if (sqlite3AuthCheck(pParse, SQLITE_TRANSACTION, "BEGIN", 0, 0)) {
- return;
- }
v = sqlite3GetVdbe(pParse);
if (!v)
return;
@@ -3899,9 +3775,6 @@ sqlite3CommitTransaction(Parse * pParse)
assert(pParse != 0);
assert(pParse->db != 0);
- if (sqlite3AuthCheck(pParse, SQLITE_TRANSACTION, "COMMIT", 0, 0)) {
- return;
- }
v = sqlite3GetVdbe(pParse);
if (v) {
sqlite3VdbeAddOp1(v, OP_AutoCommit, 1);
@@ -3918,9 +3791,6 @@ sqlite3RollbackTransaction(Parse * pParse)
assert(pParse != 0);
assert(pParse->db != 0);
- if (sqlite3AuthCheck(pParse, SQLITE_TRANSACTION, "ROLLBACK", 0, 0)) {
- return;
- }
v = sqlite3GetVdbe(pParse);
if (v) {
sqlite3VdbeAddOp2(v, OP_AutoCommit, 1, 1);
@@ -3937,15 +3807,7 @@ sqlite3Savepoint(Parse * pParse, int op, Token * pName)
char *zName = sqlite3NameFromToken(pParse->db, pName);
if (zName) {
Vdbe *v = sqlite3GetVdbe(pParse);
- static const char *const az[] =
- { "BEGIN", "RELEASE", "ROLLBACK" };
-#ifndef SQLITE_OMIT_AUTHORIZATION
- assert(!SAVEPOINT_BEGIN && SAVEPOINT_RELEASE == 1
- && SAVEPOINT_ROLLBACK == 2);
-#endif
- if (!v
- || sqlite3AuthCheck(pParse, SQLITE_SAVEPOINT, az[op], zName,
- 0)) {
+ if (!v) {
sqlite3DbFree(pParse->db, zName);
return;
}
diff --git a/src/box/sql/delete.c b/src/box/sql/delete.c
index d87b75436..63ae57b4d 100644
--- a/src/box/sql/delete.c
+++ b/src/box/sql/delete.c
@@ -243,10 +243,8 @@ sqlite3DeleteFrom(Parse * pParse, /* The parser context */
int iIdxCur = 0; /* Cursor number of the first index */
int nIdx; /* Number of indices */
sqlite3 *db; /* Main database structure */
- AuthContext sContext; /* Authorization context */
NameContext sNC; /* Name context to resolve expressions in */
int memCnt = -1; /* Memory cell used for change counting */
- int rcauth; /* Value returned by authorization callback */
int eOnePass; /* ONEPASS_OFF or _SINGLE or _MULTI */
int aiCurOnePass[2]; /* The write cursors opened by WHERE_ONEPASS */
u8 *aToOpen = 0; /* Open cursor iTabCur+j if aToOpen[j] is true */
@@ -269,7 +267,6 @@ sqlite3DeleteFrom(Parse * pParse, /* The parser context */
Trigger *pTrigger; /* List of table triggers, if required */
#endif
- memset(&sContext, 0, sizeof(sContext));
db = pParse->db;
if (pParse->nErr || db->mallocFailed) {
goto delete_from_cleanup;
@@ -310,13 +307,6 @@ sqlite3DeleteFrom(Parse * pParse, /* The parser context */
if (sqlite3IsReadOnly(pParse, pTab, (pTrigger ? 1 : 0))) {
goto delete_from_cleanup;
}
- rcauth = sqlite3AuthCheck(pParse, SQLITE_DELETE, pTab->zName, 0,
- "main");
- assert(rcauth == SQLITE_OK || rcauth == SQLITE_DENY
- || rcauth == SQLITE_IGNORE);
- if (rcauth == SQLITE_DENY) {
- goto delete_from_cleanup;
- }
assert(!isView || pTrigger);
/* Assign cursor numbers to the table and all its indices.
@@ -327,12 +317,6 @@ sqlite3DeleteFrom(Parse * pParse, /* The parser context */
pParse->nTab++;
}
- /* Start the view context
- */
- if (isView) {
- sqlite3AuthContextPush(pParse, &sContext, pTab->zName);
- }
-
/* Begin generating code.
*/
v = sqlite3GetVdbe(pParse);
@@ -375,7 +359,7 @@ sqlite3DeleteFrom(Parse * pParse, /* The parser context */
* this optimization caused the row change count (the value returned by
* API function sqlite3_count_changes) to be set incorrectly.
*/
- if (rcauth == SQLITE_OK && pWhere == 0 && !bComplex
+ if (pWhere == 0 && !bComplex
#ifdef SQLITE_ENABLE_PREUPDATE_HOOK
&& db->xPreUpdateCallback == 0
#endif
@@ -586,7 +570,6 @@ sqlite3DeleteFrom(Parse * pParse, /* The parser context */
}
delete_from_cleanup:
- sqlite3AuthContextPop(&sContext);
sqlite3SrcListDelete(db, pTabList);
sqlite3ExprDelete(db, pWhere);
sqlite3DbFree(db, aToOpen);
diff --git a/src/box/sql/fkey.c b/src/box/sql/fkey.c
index 088d84e27..0a5efd67e 100644
--- a/src/box/sql/fkey.c
+++ b/src/box/sql/fkey.c
@@ -1008,22 +1008,6 @@ sqlite3FkCheck(Parse * pParse, /* Parse context */
aiCol[i] = -1;
}
assert(pIdx == 0 || pIdx->aiColumn[i] >= 0);
-#ifndef SQLITE_OMIT_AUTHORIZATION
- /* Request permission to read the parent key columns. If the
- * authorization callback returns SQLITE_IGNORE, behave as if any
- * values read from the parent table are NULL.
- */
- if (db->xAuth) {
- int rcauth;
- char *zCol =
- pTo->aCol[pIdx ? pIdx->aiColumn[i] : pTo->
- iPKey].zName;
- rcauth =
- sqlite3AuthReadCol(pParse, pTo->zName,
- zCol);
- bIgnore = (rcauth == SQLITE_IGNORE);
- }
-#endif
}
pParse->nTab++;
diff --git a/src/box/sql/func.c b/src/box/sql/func.c
index f60cbee31..d8d39a225 100644
--- a/src/box/sql/func.c
+++ b/src/box/sql/func.c
@@ -1843,9 +1843,6 @@ sqlite3RegisterBuiltinFunctions(void)
static FuncDef aBuiltinFunc[] = {
#ifdef SQLITE_SOUNDEX
FUNCTION(soundex, 1, 0, 0, soundexFunc),
-#endif
-#if SQLITE_USER_AUTHENTICATION
- FUNCTION(sqlite_crypt, 2, 0, 0, sqlite3CryptFunc),
#endif
FUNCTION2(unlikely, 1, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY),
FUNCTION2(likelihood, 2, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY),
diff --git a/src/box/sql/insert.c b/src/box/sql/insert.c
index b20a47970..2844b5e6a 100644
--- a/src/box/sql/insert.c
+++ b/src/box/sql/insert.c
@@ -375,9 +375,6 @@ sqlite3Insert(Parse * pParse, /* Parser context */
if (pTab == 0) {
goto insert_cleanup;
}
- if (sqlite3AuthCheck(pParse, SQLITE_INSERT, pTab->zName, 0, "")) {
- goto insert_cleanup;
- }
/* Figure out if we have any triggers and if the table being
* inserted into is a view
diff --git a/src/box/sql/main.c b/src/box/sql/main.c
index 4150acb6a..eb36e2d32 100644
--- a/src/box/sql/main.c
+++ b/src/box/sql/main.c
@@ -1210,9 +1210,6 @@ sqlite3ErrName(int rc)
case SQLITE_NOLFS:
zName = "SQLITE_NOLFS";
break;
- case SQLITE_AUTH:
- zName = "SQLITE_AUTH";
- break;
case SQLITE_FORMAT:
zName = "SQLITE_FORMAT";
break;
@@ -1290,7 +1287,6 @@ sqlite3ErrStr(int rc)
/* SQLITE_MISUSE */
"library routine called out of sequence",
/* SQLITE_NOLFS */ "large file support is disabled",
- /* SQLITE_AUTH */ "authorization denied",
/* SQLITE_FORMAT */ "auxiliary database format error",
/* SQLITE_RANGE */ "bind or column index out of range",
/* SQLITE_NOTADB */
diff --git a/src/box/sql/prepare.c b/src/box/sql/prepare.c
index 2889f0f5e..0bba6b215 100644
--- a/src/box/sql/prepare.c
+++ b/src/box/sql/prepare.c
@@ -190,17 +190,6 @@ sqlite3InitDatabase(sqlite3 * db)
*/
assert(db->init.busy);
{
-#ifndef SQLITE_OMIT_AUTHORIZATION
- {
- sqlite3_xauth xAuth;
- xAuth = db->xAuth;
- db->xAuth = 0;
-#endif
- rc = SQLITE_OK;
-#ifndef SQLITE_OMIT_AUTHORIZATION
- db->xAuth = xAuth;
- }
-#endif
rc = initData.rc;
#ifndef SQLITE_OMIT_ANALYZE
if (rc == SQLITE_OK) {
diff --git a/src/box/sql/resolve.c b/src/box/sql/resolve.c
index 5548def3b..18e25cfcf 100644
--- a/src/box/sql/resolve.c
+++ b/src/box/sql/resolve.c
@@ -696,25 +696,6 @@ resolveExprStep(Walker * pWalker, Expr * pExpr)
'u' ? 8388608 : 125829120;
}
}
-#ifndef SQLITE_OMIT_AUTHORIZATION
- {
- int auth =
- sqlite3AuthCheck(pParse,
- SQLITE_FUNCTION, 0,
- pDef->zName, 0);
- if (auth != SQLITE_OK) {
- if (auth == SQLITE_DENY) {
- sqlite3ErrorMsg(pParse,
- "not authorized to use function: %s",
- pDef->
- zName);
- pNC->nErr++;
- }
- pExpr->op = TK_NULL;
- return WRC_Prune;
- }
- }
-#endif
if (pDef->
funcFlags & (SQLITE_FUNC_CONSTANT |
SQLITE_FUNC_SLOCHNG)) {
@@ -1295,8 +1276,6 @@ resolveSelectStep(Walker * pWalker, Select * p)
if (pItem->pSelect) {
NameContext *pNC; /* Used to iterate name contexts */
int nRef = 0; /* Refcount for pOuterNC and outer contexts */
- const char *zSavedContext =
- pParse->zAuthContext;
/* Count the total number of references to pOuterNC and all of its
* parent contexts. After resolving references to expressions in
@@ -1307,12 +1286,9 @@ resolveSelectStep(Walker * pWalker, Select * p)
for (pNC = pOuterNC; pNC; pNC = pNC->pNext)
nRef += pNC->nRef;
- if (pItem->zName)
- pParse->zAuthContext = pItem->zName;
sqlite3ResolveSelectNames(pParse,
pItem->pSelect,
pOuterNC);
- pParse->zAuthContext = zSavedContext;
if (pParse->nErr || db->mallocFailed)
return WRC_Abort;
diff --git a/src/box/sql/select.c b/src/box/sql/select.c
index 041e6ca87..57a5c4999 100644
--- a/src/box/sql/select.c
+++ b/src/box/sql/select.c
@@ -2306,10 +2306,6 @@ generateWithRecursiveQuery(Parse * pParse, /* Parsing context */
Expr *pLimit, *pOffset; /* Saved LIMIT and OFFSET */
int regLimit, regOffset; /* Registers used by LIMIT and OFFSET */
- /* Obtain authorization to do a recursive query */
- if (sqlite3AuthCheck(pParse, SQLITE_RECURSIVE, 0, 0, 0))
- return;
-
/* Process the LIMIT and OFFSET clauses, if they exist */
addrBreak = sqlite3VdbeMakeLabel(v);
p->nSelectRow = 320; /* 4 billion rows */
@@ -3782,7 +3778,6 @@ flattenSubquery(Parse * pParse, /* Parsing context */
int isAgg, /* True if outer SELECT uses aggregate functions */
int subqueryIsAgg) /* True if the subquery uses aggregate functions */
{
- const char *zSavedAuthContext = pParse->zAuthContext;
Select *pParent; /* Current UNION ALL term of the other query */
Select *pSub; /* The inner query or "subquery" */
Select *pSub1; /* Pointer to the rightmost select in sub-query */
@@ -3943,12 +3938,6 @@ flattenSubquery(Parse * pParse, /* Parsing context */
SELECTTRACE(1, pParse, p, ("flatten %s.%p from term %d\n",
pSub->zSelName, pSub, iFrom));
- /* Authorize the subquery */
- pParse->zAuthContext = pSubitem->zName;
- TESTONLY(i =) sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0);
- testcase(i == SQLITE_DENY);
- pParse->zAuthContext = zSavedAuthContext;
-
/* If the sub-query is a compound SELECT statement, then (by restrictions
* 17 and 18 above) it must be a UNION ALL and the parent query must
* be of the form:
@@ -5447,8 +5436,6 @@ sqlite3Select(Parse * pParse, /* The parser context */
if (p == 0 || db->mallocFailed || pParse->nErr) {
return 1;
}
- if (sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0))
- return 1;
memset(&sAggInfo, 0, sizeof(sAggInfo));
#ifdef SELECTTRACE_ENABLED
pParse->nSelectIndent++;
diff --git a/src/box/sql/sqlite3.h b/src/box/sql/sqlite3.h
index f8c6c7706..d771bddd2 100644
--- a/src/box/sql/sqlite3.h
+++ b/src/box/sql/sqlite3.h
@@ -437,14 +437,13 @@ sqlite3_exec(sqlite3 *, /* An open database */
#define SQLITE_MISMATCH 20 /* Data type mismatch */
#define SQLITE_MISUSE 21 /* Library used incorrectly */
#define SQLITE_NOLFS 22 /* Uses OS features not supported on host */
-#define SQLITE_AUTH 23 /* Authorization denied */
-#define SQLITE_FORMAT 24 /* Auxiliary database format error */
-#define SQLITE_RANGE 25 /* 2nd parameter to sqlite3_bind out of range */
-#define SQLITE_NOTADB 26 /* File opened that is not a database file */
-#define SQL_TARANTOOL_ITERATOR_FAIL 27
-#define SQL_TARANTOOL_INSERT_FAIL 28
-#define SQL_TARANTOOL_DELETE_FAIL 29
-#define SQL_TARANTOOL_ERROR 30
+#define SQLITE_FORMAT 23 /* Auxiliary database format error */
+#define SQLITE_RANGE 24 /* 2nd parameter to sqlite3_bind out of range */
+#define SQLITE_NOTADB 25 /* File opened that is not a database file */
+#define SQL_TARANTOOL_ITERATOR_FAIL 26
+#define SQL_TARANTOOL_INSERT_FAIL 27
+#define SQL_TARANTOOL_DELETE_FAIL 28
+#define SQL_TARANTOOL_ERROR 29
#define SQLITE_NOTICE 31 /* Notifications from sqlite3_log() */
#define SQLITE_WARNING 32 /* Warnings from sqlite3_log() */
#define SQLITE_ROW 100 /* sqlite3_step() has another row ready */
@@ -495,7 +494,6 @@ sqlite3_exec(sqlite3 *, /* An open database */
#define SQLITE_IOERR_GETTEMPPATH (SQLITE_IOERR | (25<<8))
#define SQLITE_IOERR_CONVPATH (SQLITE_IOERR | (26<<8))
#define SQLITE_IOERR_VNODE (SQLITE_IOERR | (27<<8))
-#define SQLITE_IOERR_AUTH (SQLITE_IOERR | (28<<8))
#define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8))
#define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8))
#define SQLITE_BUSY_SNAPSHOT (SQLITE_BUSY | (2<<8))
@@ -519,7 +517,6 @@ sqlite3_exec(sqlite3 *, /* An open database */
#define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8))
#define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
#define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8))
-#define SQLITE_AUTH_USER (SQLITE_AUTH | (1<<8))
#define SQLITE_OK_LOAD_PERMANENTLY (SQLITE_OK | (1<<8))
/*
@@ -2533,160 +2530,6 @@ sqlite3_memory_highwater(int resetFlag);
SQLITE_API void
sqlite3_randomness(int N, void *P);
-/*
- * CAPI3REF: Compile-Time Authorization Callbacks
- * METHOD: sqlite3
- *
- * ^This routine registers an authorizer callback with a particular
- * [database connection], supplied in the first argument.
- * ^The authorizer callback is invoked as SQL statements are being compiled
- * by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()],
- * [sqlite3_prepare16()] At various
- * points during the compilation process, as logic is being created
- * to perform various actions, the authorizer callback is invoked to
- * see if those actions are allowed. ^The authorizer callback should
- * return [SQLITE_OK] to allow the action, [SQLITE_IGNORE] to disallow the
- * specific action but allow the SQL statement to continue to be
- * compiled, or [SQLITE_DENY] to cause the entire SQL statement to be
- * rejected with an error. ^If the authorizer callback returns
- * any value other than [SQLITE_IGNORE], [SQLITE_OK], or [SQLITE_DENY]
- * then the [sqlite3_prepare_v2()] or equivalent call that triggered
- * the authorizer will fail with an error message.
- *
- * When the callback returns [SQLITE_OK], that means the operation
- * requested is ok. ^When the callback returns [SQLITE_DENY], the
- * [sqlite3_prepare_v2()] or equivalent call that triggered the
- * authorizer will fail with an error message explaining that
- * access is denied.
- *
- * ^The first parameter to the authorizer callback is a copy of the third
- * parameter to the sqlite3_set_authorizer() interface. ^The second parameter
- * to the callback is an integer [SQLITE_COPY | action code] that specifies
- * the particular action to be authorized. ^The third through sixth parameters
- * to the callback are zero-terminated strings that contain additional
- * details about the action to be authorized.
- *
- * ^If the action code is [SQLITE_READ]
- * and the callback returns [SQLITE_IGNORE] then the
- * [prepared statement] statement is constructed to substitute
- * a NULL value in place of the table column that would have
- * been read if [SQLITE_OK] had been returned. The [SQLITE_IGNORE]
- * return can be used to deny an untrusted user access to individual
- * columns of a table.
- * ^If the action code is [SQLITE_DELETE] and the callback returns
- * [SQLITE_IGNORE] then the [DELETE] operation proceeds but the
- * [truncate optimization] is disabled and all rows are deleted individually.
- *
- * An authorizer is used when [sqlite3_prepare | preparing]
- * SQL statements from an untrusted source, to ensure that the SQL statements
- * do not try to access data they are not allowed to see, or that they do not
- * try to execute malicious statements that damage the database. For
- * example, an application may allow a user to enter arbitrary
- * SQL queries for evaluation by a database. But the application does
- * not want the user to be able to make arbitrary changes to the
- * database. An authorizer could then be put in place while the
- * user-entered SQL is being [sqlite3_prepare | prepared] that
- * disallows everything except [SELECT] statements.
- *
- * Applications that need to process SQL from untrusted sources
- * might also consider lowering resource limits using [sqlite3_limit()]
- * and limiting database size using the [max_page_count] [PRAGMA]
- * in addition to using an authorizer.
- *
- * ^(Only a single authorizer can be in place on a database connection
- * at a time. Each call to sqlite3_set_authorizer overrides the
- * previous call.)^ ^Disable the authorizer by installing a NULL callback.
- * The authorizer is disabled by default.
- *
- * The authorizer callback must not do anything that will modify
- * the database connection that invoked the authorizer callback.
- * Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
- * database connections for the meaning of "modify" in this paragraph.
- *
- * ^When [sqlite3_prepare_v2()] is used to prepare a statement, the
- * statement might be re-prepared during [sqlite3_step()] due to a
- * schema change. Hence, the application should ensure that the
- * correct authorizer callback remains in place during the [sqlite3_step()].
- *
- * ^Note that the authorizer callback is invoked only during
- * [sqlite3_prepare()] or its variants. Authorization is not
- * performed during statement evaluation in [sqlite3_step()], unless
- * as stated in the previous paragraph, sqlite3_step() invokes
- * sqlite3_prepare_v2() to reprepare a statement after a schema change.
-*/
-SQLITE_API int
-sqlite3_set_authorizer(sqlite3 *,
- int (*xAuth) (void *, int,
- const char *,
- const char *,
- const char *,
- const char *),
- void *pUserData);
-
-/*
- * CAPI3REF: Authorizer Return Codes
- *
- * The [sqlite3_set_authorizer | authorizer callback function] must
- * return either [SQLITE_OK] or one of these two constants in order
- * to signal SQLite whether or not the action is permitted. See the
- * [sqlite3_set_authorizer | authorizer documentation] for additional
- * information.
-*/
-#define SQLITE_DENY 1 /* Abort the SQL statement with an error */
-#define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */
-
-/*
- * CAPI3REF: Authorizer Action Codes
- *
- * The [sqlite3_set_authorizer()] interface registers a callback function
- * that is invoked to authorize certain SQL statement actions. The
- * second parameter to the callback is an integer code that specifies
- * what action is being authorized. These are the integer action codes that
- * the authorizer callback may be passed.
- *
- * These action code values signify what kind of operation is to be
- * authorized. The 3rd and 4th parameters to the authorization
- * callback function will be parameters or NULL depending on which of these
- * codes is used as the second parameter. ^(The 5th parameter to the
- * authorizer callback is the name of the database ("main", "temp",
- * etc.) if applicable.)^ ^The 6th parameter to the authorizer callback
- * is the name of the inner-most trigger or view that is responsible for
- * the access attempt or NULL if this access attempt is directly from
- * top-level SQL code.
-*/
-/******************************************* 3rd ************ 4th ***********/
-#define SQLITE_CREATE_INDEX 1 /* Index Name Table Name */
-#define SQLITE_CREATE_TABLE 2 /* Table Name NULL */
-#define SQLITE_CREATE_TEMP_INDEX 3 /* Index Name Table Name */
-#define SQLITE_CREATE_TEMP_TABLE 4 /* Table Name NULL */
-#define SQLITE_CREATE_TEMP_TRIGGER 5 /* Trigger Name Table Name */
-#define SQLITE_CREATE_TEMP_VIEW 6 /* View Name NULL */
-#define SQLITE_CREATE_TRIGGER 7 /* Trigger Name Table Name */
-#define SQLITE_CREATE_VIEW 8 /* View Name NULL */
-#define SQLITE_DELETE 9 /* Table Name NULL */
-#define SQLITE_DROP_INDEX 10 /* Index Name Table Name */
-#define SQLITE_DROP_TABLE 11 /* Table Name NULL */
-#define SQLITE_DROP_TEMP_INDEX 12 /* Index Name Table Name */
-#define SQLITE_DROP_TEMP_TABLE 13 /* Table Name NULL */
-#define SQLITE_DROP_TEMP_TRIGGER 14 /* Trigger Name Table Name */
-#define SQLITE_DROP_TEMP_VIEW 15 /* View Name NULL */
-#define SQLITE_DROP_TRIGGER 16 /* Trigger Name Table Name */
-#define SQLITE_DROP_VIEW 17 /* View Name NULL */
-#define SQLITE_INSERT 18 /* Table Name NULL */
-#define SQLITE_PRAGMA 19 /* Pragma Name 1st arg or NULL */
-#define SQLITE_READ 20 /* Table Name Column Name */
-#define SQLITE_SELECT 21 /* NULL NULL */
-#define SQLITE_TRANSACTION 22 /* Operation NULL */
-#define SQLITE_UPDATE 23 /* Table Name Column Name */
-#define SQLITE_ATTACH 24 /* Filename NULL */
-#define SQLITE_DETACH 25 /* Database Name NULL */
-#define SQLITE_ALTER_TABLE 26 /* Database Name Table Name */
-#define SQLITE_REINDEX 27 /* Index Name NULL */
-#define SQLITE_ANALYZE 28 /* Table Name NULL */
-#define SQLITE_FUNCTION 31 /* NULL Function Name */
-#define SQLITE_SAVEPOINT 32 /* Operation Savepoint Name */
-#define SQLITE_COPY 0 /* No longer used */
-#define SQLITE_RECURSIVE 33 /* NULL NULL */
/*
* CAPI3REF: SQL Trace Event Codes
@@ -3206,8 +3049,7 @@ typedef struct sqlite3_stmt sqlite3_stmt;
* off the Internet. The internal databases can be given the
* large, default limits. Databases managed by external sources can
* be given much smaller limits designed to prevent a denial of service
- * attack. Developers might also want to use the [sqlite3_set_authorizer()]
- * interface to further control untrusted SQL. The size of the database
+ * attack.. The size of the database
* created by an untrusted script can be contained using the
* [max_page_count] [PRAGMA].
*
diff --git a/src/box/sql/sqliteInt.h b/src/box/sql/sqliteInt.h
index 3d7164c32..6c7337375 100644
--- a/src/box/sql/sqliteInt.h
+++ b/src/box/sql/sqliteInt.h
@@ -829,7 +829,6 @@ void *sqlite3_wsd_find(void *K, int L);
* Forward references to structures
*/
typedef struct AggInfo AggInfo;
-typedef struct AuthContext AuthContext;
typedef struct AutoincInfo AutoincInfo;
typedef struct Bitvec Bitvec;
typedef struct Column Column;
@@ -951,44 +950,6 @@ struct FuncDefHash {
FuncDef *a[SQLITE_FUNC_HASH_SZ]; /* Hash table for functions */
};
-#ifdef SQLITE_USER_AUTHENTICATION
-/*
- * Information held in the "sqlite3" database connection object and used
- * to manage user authentication.
- */
-typedef struct sqlite3_userauth sqlite3_userauth;
-struct sqlite3_userauth {
- u8 authLevel; /* Current authentication level */
- int nAuthPW; /* Size of the zAuthPW in bytes */
- char *zAuthPW; /* Password used to authenticate */
- char *zAuthUser; /* User name used to authenticate */
-};
-
-/* Allowed values for sqlite3_userauth.authLevel */
-#define UAUTH_Unknown 0 /* Authentication not yet checked */
-#define UAUTH_Fail 1 /* User authentication failed */
-#define UAUTH_User 2 /* Authenticated as a normal user */
-#define UAUTH_Admin 3 /* Authenticated as an administrator */
-
-/* Functions used only by user authorization logic */
-int sqlite3UserAuthTable(const char *);
-int sqlite3UserAuthCheckLogin(sqlite3 *, const char *, u8 *);
-void sqlite3UserAuthInit(sqlite3 *);
-void sqlite3CryptFunc(sqlite3_context *, int, sqlite3_value **);
-
-#endif /* SQLITE_USER_AUTHENTICATION */
-
-/*
- * typedef for the authorization callback function.
- */
-#ifdef SQLITE_USER_AUTHENTICATION
-typedef int (*sqlite3_xauth) (void *, int, const char *, const char *,
- const char *, const char *, const char *);
-#else
-typedef int (*sqlite3_xauth) (void *, int, const char *, const char *,
- const char *, const char *);
-#endif
-
/*
* Each database connection is an instance of the following structure.
*/
@@ -1053,10 +1014,6 @@ struct sqlite3 {
double notUsed1; /* Spacer */
} u1;
Lookaside lookaside; /* Lookaside malloc configuration */
-#ifndef SQLITE_OMIT_AUTHORIZATION
- sqlite3_xauth xAuth; /* Access authorization function */
- void *pAuthArg; /* 1st argument to the access auth function */
-#endif
#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
int (*xProgress) (void *); /* The progress callback */
void *pProgressArg; /* Argument to the progress callback */
@@ -1066,9 +1023,6 @@ struct sqlite3 {
BusyHandler busyHandler; /* Busy callback */
int busyTimeout; /* Busy handler timeout, in msec */
int *pnBytesFreed; /* If not NULL, increment this in DbFree() */
-#ifdef SQLITE_USER_AUTHENTICATION
- sqlite3_userauth auth; /* User authentication information */
-#endif
};
/*
@@ -2473,7 +2427,6 @@ struct Parse {
const char *zTail; /* All SQL text past the last semicolon parsed */
Table *pNewTable; /* A table being constructed by CREATE TABLE */
Trigger *pNewTrigger; /* Trigger under construct by a CREATE TRIGGER */
- const char *zAuthContext; /* The 6th parameter to db->xAuth callbacks */
Table *pZombieTab; /* List of Table objects to delete after code gen */
TriggerPrg *pTriggerPrg; /* Linked list of coded triggers */
With *pWith; /* Current WITH clause, or NULL */
@@ -2490,15 +2443,6 @@ struct Parse {
#define PARSE_TAIL_SZ (sizeof(Parse)-PARSE_RECURSE_SZ) /* Non-recursive part */
#define PARSE_TAIL(X) (((char*)(X))+PARSE_RECURSE_SZ) /* Pointer to tail */
-/*
- * An instance of the following structure can be declared on a stack and used
- * to save the Parse.zAuthContext value so that it can be restored later.
- */
-struct AuthContext {
- const char *zAuthContext; /* Put saved Parse.zAuthContext here */
- Parse *pParse; /* The Parse structure */
-};
-
/*
* Bitfield flags for P5 value in various opcodes.
*
@@ -3287,23 +3231,6 @@ u32 sqlite3TriggerColmask(Parse *, Trigger *, ExprList *, int, int, Table *,
int sqlite3JoinType(Parse *, Token *, Token *, Token *);
void sqlite3CreateForeignKey(Parse *, ExprList *, Token *, ExprList *, int);
void sqlite3DeferForeignKey(Parse *, int);
-#ifndef SQLITE_OMIT_AUTHORIZATION
-void sqlite3AuthRead(Parse *, Expr *, Schema *, SrcList *);
-int sqlite3AuthCheck(Parse *, int, const char *, const char *, const char *);
-void sqlite3AuthContextPush(Parse *, AuthContext *, const char *);
-void sqlite3AuthContextPop(AuthContext *);
-int sqlite3AuthReadCol(Parse *, const char *, const char *);
-#else
-#define sqlite3AuthRead(a,b,c,d)
-static inline
-int sqlite3AuthCheck(MAYBE_UNUSED Parse *a,
- MAYBE_UNUSED int b,
- MAYBE_UNUSED const char *c,
- MAYBE_UNUSED const char *d,
- MAYBE_UNUSED const char *e) { return SQLITE_OK; }
-#define sqlite3AuthContextPush(a,b,c)
-#define sqlite3AuthContextPop(a) ((void)(a))
-#endif
void sqlite3Detach(Parse *, Expr *);
void sqlite3FixInit(DbFixer *, Parse *, const char *, const Token *);
int sqlite3FixSrcList(DbFixer *, SrcList *);
diff --git a/src/box/sql/trigger.c b/src/box/sql/trigger.c
index def724ae6..a2827c882 100644
--- a/src/box/sql/trigger.c
+++ b/src/box/sql/trigger.c
@@ -155,21 +155,6 @@ sqlite3BeginTrigger(Parse * pParse, /* The parse context of the CREATE TRIGGER s
" trigger on table: %S", pTableName, 0);
goto trigger_cleanup;
}
-#ifndef SQLITE_OMIT_AUTHORIZATION
- {
- assert(sqlite3SchemaToIndex(db, pTab->pSchema) == 0);
- int code = SQLITE_CREATE_TRIGGER;
- const char *zDb = db->mdb.zDbSName;
- const char *zDbTrig = zDb;
- if (sqlite3AuthCheck(pParse, code, zName, pTab->zName, zDbTrig)) {
- goto trigger_cleanup;
- }
- if (sqlite3AuthCheck
- (pParse, SQLITE_INSERT, MASTER_NAME, 0, zDb)) {
- goto trigger_cleanup;
- }
- }
-#endif
/* INSTEAD OF triggers can only appear on views and BEFORE triggers
* cannot appear on views. So we might as well translate every
@@ -580,18 +565,6 @@ sqlite3DropTriggerPtr(Parse * pParse, Trigger * pTrigger)
pTable = tableOfTrigger(pTrigger);
assert(pTable);
assert(pTable->pSchema == pTrigger->pSchema);
-#ifndef SQLITE_OMIT_AUTHORIZATION
- {
- int code = SQLITE_DROP_TRIGGER;
- const char *zDb = db->mdb.zDbSName;
- const char *zTab = MASTER_NAME;
- if (sqlite3AuthCheck
- (pParse, code, pTrigger->zName, pTable->zName, zDb)
- || sqlite3AuthCheck(pParse, SQLITE_DELETE, zTab, 0, zDb)) {
- return;
- }
- }
-#endif
/* Generate code to destroy the database record of the trigger.
*/
@@ -906,7 +879,6 @@ codeRowTrigger(Parse * pParse, /* Current parse context */
pSubParse->db = db;
pSubParse->pTriggerTab = pTab;
pSubParse->pToplevel = pTop;
- pSubParse->zAuthContext = pTrigger->zName;
pSubParse->eTriggerOp = pTrigger->op;
pSubParse->nQueryLoop = pParse->nQueryLoop;
diff --git a/src/box/sql/update.c b/src/box/sql/update.c
index 9a86589ac..75baf1f51 100644
--- a/src/box/sql/update.c
+++ b/src/box/sql/update.c
@@ -121,7 +121,6 @@ sqlite3Update(Parse * pParse, /* The parser context */
*/
u8 *aToOpen; /* 1 for tables and indices to be opened */
u8 chngPk; /* PRIMARY KEY changed */
- AuthContext sContext; /* The authorization context */
NameContext sNC; /* The name-context to resolve expressions in */
int okOnePass; /* True for one-pass algorithm without the FIFO */
int hasFK; /* True if foreign key processing is required */
@@ -147,7 +146,6 @@ sqlite3Update(Parse * pParse, /* The parser context */
int regOld = 0; /* Content of OLD.* table in triggers */
int regKey = 0; /* composite PRIMARY KEY value */
- memset(&sContext, 0, sizeof(sContext));
db = pParse->db;
if (pParse->nErr || db->mallocFailed) {
goto update_cleanup;
@@ -250,21 +248,6 @@ sqlite3Update(Parse * pParse, /* The parser context */
pParse->checkSchema = 1;
goto update_cleanup;
}
-#ifndef SQLITE_OMIT_AUTHORIZATION
- {
- int rc;
- rc = sqlite3AuthCheck(pParse, SQLITE_UPDATE,
- pTab->zName,
- j <
- 0 ? "ROWID" : pTab->aCol[j].zName,
- db->mdb.zDbSName);
- if (rc == SQLITE_DENY) {
- goto update_cleanup;
- } else if (rc == SQLITE_IGNORE) {
- aXRef[j] = -1;
- }
- }
-#endif
}
assert(chngPk == 0 || chngPk == 1);
@@ -324,11 +307,6 @@ sqlite3Update(Parse * pParse, /* The parser context */
regNew = pParse->nMem + 1;
pParse->nMem += pTab->nCol;
- /* Start the view context. */
- if (isView) {
- sqlite3AuthContextPush(pParse, &sContext, pTab->zName);
- }
-
/* If we are trying to update a view, realize that view into
* an ephemeral table.
*/
@@ -690,7 +668,6 @@ sqlite3Update(Parse * pParse, /* The parser context */
}
update_cleanup:
- sqlite3AuthContextPop(&sContext);
sqlite3DbFree(db, aXRef); /* Also frees aRegIdx[] and aToOpen[] */
sqlite3SrcListDelete(db, pTabList);
sqlite3ExprListDelete(db, pChanges);
--
2.14.1
More information about the Tarantool-patches
mailing list