本站源代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

153 lines
4.3KB

  1. // Copyright (C) 2018 G.J.R. Timmer <gjr.timmer@gmail.com>.
  2. //
  3. // Use of this source code is governed by an MIT-style
  4. // license that can be found in the LICENSE file.
  5. // +build !sqlite_userauth
  6. package sqlite3
  7. import (
  8. "C"
  9. )
  10. // Authenticate will perform an authentication of the provided username
  11. // and password against the database.
  12. //
  13. // If a database contains the SQLITE_USER table, then the
  14. // call to Authenticate must be invoked with an
  15. // appropriate username and password prior to enable read and write
  16. //access to the database.
  17. //
  18. // Return SQLITE_OK on success or SQLITE_ERROR if the username/password
  19. // combination is incorrect or unknown.
  20. //
  21. // If the SQLITE_USER table is not present in the database file, then
  22. // this interface is a harmless no-op returnning SQLITE_OK.
  23. func (c *SQLiteConn) Authenticate(username, password string) error {
  24. // NOOP
  25. return nil
  26. }
  27. // authenticate provides the actual authentication to SQLite.
  28. // This is not exported for usage in Go.
  29. // It is however exported for usage within SQL by the user.
  30. //
  31. // Returns:
  32. // C.SQLITE_OK (0)
  33. // C.SQLITE_ERROR (1)
  34. // C.SQLITE_AUTH (23)
  35. func (c *SQLiteConn) authenticate(username, password string) int {
  36. // NOOP
  37. return 0
  38. }
  39. // AuthUserAdd can be used (by an admin user only)
  40. // to create a new user. When called on a no-authentication-required
  41. // database, this routine converts the database into an authentication-
  42. // required database, automatically makes the added user an
  43. // administrator, and logs in the current connection as that user.
  44. // The AuthUserAdd only works for the "main" database, not
  45. // for any ATTACH-ed databases. Any call to AuthUserAdd by a
  46. // non-admin user results in an error.
  47. func (c *SQLiteConn) AuthUserAdd(username, password string, admin bool) error {
  48. // NOOP
  49. return nil
  50. }
  51. // authUserAdd enables the User Authentication if not enabled.
  52. // Otherwise it will add a user.
  53. //
  54. // When user authentication is already enabled then this function
  55. // can only be called by an admin.
  56. //
  57. // This is not exported for usage in Go.
  58. // It is however exported for usage within SQL by the user.
  59. //
  60. // Returns:
  61. // C.SQLITE_OK (0)
  62. // C.SQLITE_ERROR (1)
  63. // C.SQLITE_AUTH (23)
  64. func (c *SQLiteConn) authUserAdd(username, password string, admin int) int {
  65. // NOOP
  66. return 0
  67. }
  68. // AuthUserChange can be used to change a users
  69. // login credentials or admin privilege. Any user can change their own
  70. // login credentials. Only an admin user can change another users login
  71. // credentials or admin privilege setting. No user may change their own
  72. // admin privilege setting.
  73. func (c *SQLiteConn) AuthUserChange(username, password string, admin bool) error {
  74. // NOOP
  75. return nil
  76. }
  77. // authUserChange allows to modify a user.
  78. // Users can change their own password.
  79. //
  80. // Only admins can change passwords for other users
  81. // and modify the admin flag.
  82. //
  83. // The admin flag of the current logged in user cannot be changed.
  84. // THis ensures that their is always an admin.
  85. //
  86. // This is not exported for usage in Go.
  87. // It is however exported for usage within SQL by the user.
  88. //
  89. // Returns:
  90. // C.SQLITE_OK (0)
  91. // C.SQLITE_ERROR (1)
  92. // C.SQLITE_AUTH (23)
  93. func (c *SQLiteConn) authUserChange(username, password string, admin int) int {
  94. // NOOP
  95. return 0
  96. }
  97. // AuthUserDelete can be used (by an admin user only)
  98. // to delete a user. The currently logged-in user cannot be deleted,
  99. // which guarantees that there is always an admin user and hence that
  100. // the database cannot be converted into a no-authentication-required
  101. // database.
  102. func (c *SQLiteConn) AuthUserDelete(username string) error {
  103. // NOOP
  104. return nil
  105. }
  106. // authUserDelete can be used to delete a user.
  107. //
  108. // This function can only be executed by an admin.
  109. //
  110. // This is not exported for usage in Go.
  111. // It is however exported for usage within SQL by the user.
  112. //
  113. // Returns:
  114. // C.SQLITE_OK (0)
  115. // C.SQLITE_ERROR (1)
  116. // C.SQLITE_AUTH (23)
  117. func (c *SQLiteConn) authUserDelete(username string) int {
  118. // NOOP
  119. return 0
  120. }
  121. // AuthEnabled checks if the database is protected by user authentication
  122. func (c *SQLiteConn) AuthEnabled() (exists bool) {
  123. // NOOP
  124. return false
  125. }
  126. // authEnabled perform the actual check for user authentication.
  127. //
  128. // This is not exported for usage in Go.
  129. // It is however exported for usage within SQL by the user.
  130. //
  131. // Returns:
  132. // 0 - Disabled
  133. // 1 - Enabled
  134. func (c *SQLiteConn) authEnabled() int {
  135. // NOOP
  136. return 0
  137. }
  138. // EOF
上海开阖软件有限公司 沪ICP备12045867号-1