1f442e33eSdrh /* 2f442e33eSdrh ** 2014-09-08 3f442e33eSdrh ** 4f442e33eSdrh ** The author disclaims copyright to this source code. In place of 5f442e33eSdrh ** a legal notice, here is a blessing: 6f442e33eSdrh ** 7f442e33eSdrh ** May you do good and not evil. 8f442e33eSdrh ** May you find forgiveness for yourself and forgive others. 9f442e33eSdrh ** May you share freely, never taking more than you give. 10f442e33eSdrh ** 11f442e33eSdrh ************************************************************************* 12f442e33eSdrh ** 13f442e33eSdrh ** This file contains the application interface definitions for the 14f442e33eSdrh ** user-authentication extension feature. 15f442e33eSdrh ** 16f442e33eSdrh ** To compile with the user-authentication feature, append this file to 17f442e33eSdrh ** end of an SQLite amalgamation header file ("sqlite3.h"), then add 18f442e33eSdrh ** the SQLITE_USER_AUTHENTICATION compile-time option. See the 19f442e33eSdrh ** user-auth.txt file in the same source directory as this file for 20f442e33eSdrh ** additional information. 21f442e33eSdrh */ 22f442e33eSdrh #ifdef SQLITE_USER_AUTHENTICATION 23f442e33eSdrh 24*70cdf382Sdan #ifdef __cplusplus 25*70cdf382Sdan extern "C" { 26*70cdf382Sdan #endif 27*70cdf382Sdan 28f442e33eSdrh /* 29f442e33eSdrh ** If a database contains the SQLITE_USER table, then the 30f442e33eSdrh ** sqlite3_user_authenticate() interface must be invoked with an 31f442e33eSdrh ** appropriate username and password prior to enable read and write 32f442e33eSdrh ** access to the database. 33f442e33eSdrh ** 34f442e33eSdrh ** Return SQLITE_OK on success or SQLITE_ERROR if the username/password 35f442e33eSdrh ** combination is incorrect or unknown. 36f442e33eSdrh ** 37f442e33eSdrh ** If the SQLITE_USER table is not present in the database file, then 38f442e33eSdrh ** this interface is a harmless no-op returnning SQLITE_OK. 39f442e33eSdrh */ 40f442e33eSdrh int sqlite3_user_authenticate( 41f442e33eSdrh sqlite3 *db, /* The database connection */ 42f442e33eSdrh const char *zUsername, /* Username */ 43d39c40ffSdrh const char *aPW, /* Password or credentials */ 44d39c40ffSdrh int nPW /* Number of bytes in aPW[] */ 45f442e33eSdrh ); 46f442e33eSdrh 47f442e33eSdrh /* 48f442e33eSdrh ** The sqlite3_user_add() interface can be used (by an admin user only) 49f442e33eSdrh ** to create a new user. When called on a no-authentication-required 50f442e33eSdrh ** database, this routine converts the database into an authentication- 51f442e33eSdrh ** required database, automatically makes the added user an 52f442e33eSdrh ** administrator, and logs in the current connection as that user. 53f442e33eSdrh ** The sqlite3_user_add() interface only works for the "main" database, not 54f442e33eSdrh ** for any ATTACH-ed databases. Any call to sqlite3_user_add() by a 55f442e33eSdrh ** non-admin user results in an error. 56f442e33eSdrh */ 57f442e33eSdrh int sqlite3_user_add( 58f442e33eSdrh sqlite3 *db, /* Database connection */ 59f442e33eSdrh const char *zUsername, /* Username to be added */ 60d39c40ffSdrh const char *aPW, /* Password or credentials */ 61f442e33eSdrh int nPW, /* Number of bytes in aPW[] */ 62d39c40ffSdrh int isAdmin /* True to give new user admin privilege */ 63f442e33eSdrh ); 64f442e33eSdrh 65f442e33eSdrh /* 66f442e33eSdrh ** The sqlite3_user_change() interface can be used to change a users 67f442e33eSdrh ** login credentials or admin privilege. Any user can change their own 68f442e33eSdrh ** login credentials. Only an admin user can change another users login 69f442e33eSdrh ** credentials or admin privilege setting. No user may change their own 70f442e33eSdrh ** admin privilege setting. 71f442e33eSdrh */ 72f442e33eSdrh int sqlite3_user_change( 73f442e33eSdrh sqlite3 *db, /* Database connection */ 74f442e33eSdrh const char *zUsername, /* Username to change */ 75d39c40ffSdrh const char *aPW, /* New password or credentials */ 76f442e33eSdrh int nPW, /* Number of bytes in aPW[] */ 77d39c40ffSdrh int isAdmin /* Modified admin privilege for the user */ 78f442e33eSdrh ); 79f442e33eSdrh 80f442e33eSdrh /* 81f442e33eSdrh ** The sqlite3_user_delete() interface can be used (by an admin user only) 82f442e33eSdrh ** to delete a user. The currently logged-in user cannot be deleted, 83f442e33eSdrh ** which guarantees that there is always an admin user and hence that 84f442e33eSdrh ** the database cannot be converted into a no-authentication-required 85f442e33eSdrh ** database. 86f442e33eSdrh */ 87f442e33eSdrh int sqlite3_user_delete( 88f442e33eSdrh sqlite3 *db, /* Database connection */ 89f442e33eSdrh const char *zUsername /* Username to remove */ 90f442e33eSdrh ); 91f442e33eSdrh 92*70cdf382Sdan #ifdef __cplusplus 93*70cdf382Sdan } /* end of the 'extern "C"' block */ 94*70cdf382Sdan #endif 95*70cdf382Sdan 96f442e33eSdrh #endif /* SQLITE_USER_AUTHENTICATION */ 97