Debian Codegraph @

sqlite3_opt_userauth.go

raw
1 // Copyright (C) 2018 G.J.R. Timmer <[email protected]>.
2 //
3 // Use of this source code is governed by an MIT-style
4 // license that can be found in the LICENSE file.
5
6 //go:build sqlite_userauth
7
8 package sqlite3
9
10 /*
11 #cgo CFLAGS: -DSQLITE_USER_AUTHENTICATION
12 #cgo LDFLAGS: -lm
13 #ifndef USE_LIBSQLITE3
14 #include "sqlite3-binding.h"
15 #else
16 #include <sqlite3.h>
17 #endif
18 */
19 import "C"
20 import (
21 "errors"
22 )
23
24 const (
25 SQLITE_AUTH = C.SQLITE_AUTH
26 )
27
28 var (
29 ErrUnauthorized = errors.New("SQLITE_AUTH: Unauthorized")
30 ErrAdminRequired = errors.New("SQLITE_AUTH: Unauthorized; Admin Privileges Required")
31 errUserAuthNoLongerSupported = errors.New("sqlite3: the sqlite_userauth tag is no longer supported as the userauth extension is no longer supported by the SQLite authors, see https://github.com/mattn/go-sqlite3/issues/1341")
32 )
33
34 // Authenticate will perform an authentication of the provided username
35 // and password against the database.
36 //
37 // If a database contains the SQLITE_USER table, then the
38 // call to Authenticate must be invoked with an
39 // appropriate username and password prior to enable read and write
40 // access to the database.
41 //
42 // Return SQLITE_OK on success or SQLITE_ERROR if the username/password
43 // combination is incorrect or unknown.
44 //
45 // If the SQLITE_USER table is not present in the database file, then
46 // this interface is a harmless no-op returning SQLITE_OK.
47 func (c *SQLiteConn) Authenticate(username, password string) error {
48 return errUserAuthNoLongerSupported
49 }
50
51 // authenticate provides the actual authentication to SQLite.
52 // This is not exported for usage in Go.
53 // It is however exported for usage within SQL by the user.
54 //
55 // Returns:
56 //
57 // C.SQLITE_OK (0)
58 // C.SQLITE_ERROR (1)
59 // C.SQLITE_AUTH (23)
60 func (c *SQLiteConn) authenticate(username, password string) int {
61 return 1
62 }
63
64 // AuthUserAdd can be used (by an admin user only)
65 // to create a new user. When called on a no-authentication-required
66 // database, this routine converts the database into an authentication-
67 // required database, automatically makes the added user an
68 // administrator, and logs in the current connection as that user.
69 // The AuthUserAdd only works for the "main" database, not
70 // for any ATTACH-ed databases. Any call to AuthUserAdd by a
71 // non-admin user results in an error.
72 func (c *SQLiteConn) AuthUserAdd(username, password string, admin bool) error {
73 return errUserAuthNoLongerSupported
74 }
75
76 // authUserAdd enables the User Authentication if not enabled.
77 // Otherwise it will add a user.
78 //
79 // When user authentication is already enabled then this function
80 // can only be called by an admin.
81 //
82 // This is not exported for usage in Go.
83 // It is however exported for usage within SQL by the user.
84 //
85 // Returns:
86 //
87 // C.SQLITE_OK (0)
88 // C.SQLITE_ERROR (1)
89 // C.SQLITE_AUTH (23)
90 func (c *SQLiteConn) authUserAdd(username, password string, admin int) int {
91 return 1
92 }
93
94 // AuthUserChange can be used to change a users
95 // login credentials or admin privilege. Any user can change their own
96 // login credentials. Only an admin user can change another users login
97 // credentials or admin privilege setting. No user may change their own
98 // admin privilege setting.
99 func (c *SQLiteConn) AuthUserChange(username, password string, admin bool) error {
100 return errUserAuthNoLongerSupported
101 }
102
103 // authUserChange allows to modify a user.
104 // Users can change their own password.
105 //
106 // Only admins can change passwords for other users
107 // and modify the admin flag.
108 //
109 // The admin flag of the current logged in user cannot be changed.
110 // THis ensures that their is always an admin.
111 //
112 // This is not exported for usage in Go.
113 // It is however exported for usage within SQL by the user.
114 //
115 // Returns:
116 //
117 // C.SQLITE_OK (0)
118 // C.SQLITE_ERROR (1)
119 // C.SQLITE_AUTH (23)
120 func (c *SQLiteConn) authUserChange(username, password string, admin int) int {
121 return 1
122 }
123
124 // AuthUserDelete can be used (by an admin user only)
125 // to delete a user. The currently logged-in user cannot be deleted,
126 // which guarantees that there is always an admin user and hence that
127 // the database cannot be converted into a no-authentication-required
128 // database.
129 func (c *SQLiteConn) AuthUserDelete(username string) error {
130 return errUserAuthNoLongerSupported
131 }
132
133 // authUserDelete can be used to delete a user.
134 //
135 // This function can only be executed by an admin.
136 //
137 // This is not exported for usage in Go.
138 // It is however exported for usage within SQL by the user.
139 //
140 // Returns:
141 //
142 // C.SQLITE_OK (0)
143 // C.SQLITE_ERROR (1)
144 // C.SQLITE_AUTH (23)
145 func (c *SQLiteConn) authUserDelete(username string) int {
146 return 1
147 }
148
149 // AuthEnabled checks if the database is protected by user authentication
150 func (c *SQLiteConn) AuthEnabled() (exists bool) {
151 return false
152 }
153
154 // authEnabled perform the actual check for user authentication.
155 //
156 // This is not exported for usage in Go.
157 // It is however exported for usage within SQL by the user.
158 //
159 // Returns:
160 //
161 // 0 - Disabled
162 // 1 - Enabled
163 func (c *SQLiteConn) authEnabled() int {
164 return 0
165 }
166
167 // EOF