sqlite3userauth.h 3.4 KB

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