Small, Fast, Reliable.
Choose any three.

SQLite C Interface

Compile-Time Authorization Callbacks

int sqlite3_set_authorizer(
  sqlite3*,
  int (*xAuth)(void*,int,const char*,const char*,const char*,const char*),
  void *pUserData
);

This routine registers a authorizer callback with the SQLite library. The authorizer callback is invoked as SQL statements are being compiled by sqlite3_prepare() or its variants sqlite3_prepare_v2(), sqlite3_prepare16() and sqlite3_prepare16_v2(). 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.

Depending on the action, the SQLITE_IGNORE and SQLITE_DENY return codes might mean something different or they might mean the same thing. If the action is, for example, to perform a delete opertion, then SQLITE_IGNORE and SQLITE_DENY both cause the statement compilation to fail with an error. But if the action is to read a specific column from a specific table, then SQLITE_DENY will cause the entire statement to fail but SQLITE_IGNORE will cause a NULL value to be read instead of the actual column value.

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 action code that specifies the particular action to be authorized. The available action codes are documented separately. The third through sixth parameters to the callback are strings that contain additional details about the action to be authorized.

An authorizer is used when preparing SQL statements from an untrusted source, to ensure that the SQL statements do not try to access data that 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 prepared that disallows everything except SELECT statements.

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. A NULL authorizer means that no authorization callback is invoked. The default authorizer is NULL.

Note that the authorizer callback is invoked only during sqlite3_prepare() or its variants. Authorization is not performed during statement evaluation in sqlite3_step().

See also lists of Objects, Constants, and Functions.


This page last modified 2007/11/22 00:41:31 UTC