@@ -16,53 +16,10 @@ package sqlite3
16
16
#else
17
17
#include <sqlite3.h>
18
18
#endif
19
- #include <stdlib.h>
20
-
21
- static int
22
- _sqlite3_user_authenticate(sqlite3* db, const char* zUsername, const char* aPW, int nPW)
23
- {
24
- return sqlite3_user_authenticate(db, zUsername, aPW, nPW);
25
- }
26
-
27
- static int
28
- _sqlite3_user_add(sqlite3* db, const char* zUsername, const char* aPW, int nPW, int isAdmin)
29
- {
30
- return sqlite3_user_add(db, zUsername, aPW, nPW, isAdmin);
31
- }
32
-
33
- static int
34
- _sqlite3_user_change(sqlite3* db, const char* zUsername, const char* aPW, int nPW, int isAdmin)
35
- {
36
- return sqlite3_user_change(db, zUsername, aPW, nPW, isAdmin);
37
- }
38
-
39
- static int
40
- _sqlite3_user_delete(sqlite3* db, const char* zUsername)
41
- {
42
- return sqlite3_user_delete(db, zUsername);
43
- }
44
-
45
- static int
46
- _sqlite3_auth_enabled(sqlite3* db)
47
- {
48
- int exists = -1;
49
-
50
- sqlite3_stmt *stmt;
51
- sqlite3_prepare_v2(db, "select count(type) from sqlite_master WHERE type='table' and name='sqlite_user';", -1, &stmt, NULL);
52
-
53
- while ( sqlite3_step(stmt) == SQLITE_ROW) {
54
- exists = sqlite3_column_int(stmt, 0);
55
- }
56
-
57
- sqlite3_finalize(stmt);
58
-
59
- return exists;
60
- }
61
19
*/
62
20
import "C"
63
21
import (
64
22
"errors"
65
- "unsafe"
66
23
)
67
24
68
25
const (
88
45
// If the SQLITE_USER table is not present in the database file, then
89
46
// this interface is a harmless no-op returning SQLITE_OK.
90
47
func (c * SQLiteConn ) Authenticate (username , password string ) error {
91
- rv := c .authenticate (username , password )
92
- switch rv {
93
- case C .SQLITE_ERROR , C .SQLITE_AUTH :
94
- return ErrUnauthorized
95
- case C .SQLITE_OK :
96
- return nil
97
- default :
98
- return c .lastError ()
99
- }
48
+ return ErrUnauthorized
100
49
}
101
50
102
51
// authenticate provides the actual authentication to SQLite.
@@ -109,17 +58,7 @@ func (c *SQLiteConn) Authenticate(username, password string) error {
109
58
// C.SQLITE_ERROR (1)
110
59
// C.SQLITE_AUTH (23)
111
60
func (c * SQLiteConn ) authenticate (username , password string ) int {
112
- // Allocate C Variables
113
- cuser := C .CString (username )
114
- cpass := C .CString (password )
115
-
116
- // Free C Variables
117
- defer func () {
118
- C .free (unsafe .Pointer (cuser ))
119
- C .free (unsafe .Pointer (cpass ))
120
- }()
121
-
122
- return int (C ._sqlite3_user_authenticate (c .db , cuser , cpass , C .int (len (password ))))
61
+ return 1
123
62
}
124
63
125
64
// AuthUserAdd can be used (by an admin user only)
@@ -131,20 +70,7 @@ func (c *SQLiteConn) authenticate(username, password string) int {
131
70
// for any ATTACH-ed databases. Any call to AuthUserAdd by a
132
71
// non-admin user results in an error.
133
72
func (c * SQLiteConn ) AuthUserAdd (username , password string , admin bool ) error {
134
- isAdmin := 0
135
- if admin {
136
- isAdmin = 1
137
- }
138
-
139
- rv := c .authUserAdd (username , password , isAdmin )
140
- switch rv {
141
- case C .SQLITE_ERROR , C .SQLITE_AUTH :
142
- return ErrAdminRequired
143
- case C .SQLITE_OK :
144
- return nil
145
- default :
146
- return c .lastError ()
147
- }
73
+ return ErrUnauthorized
148
74
}
149
75
150
76
// authUserAdd enables the User Authentication if not enabled.
@@ -162,17 +88,7 @@ func (c *SQLiteConn) AuthUserAdd(username, password string, admin bool) error {
162
88
// C.SQLITE_ERROR (1)
163
89
// C.SQLITE_AUTH (23)
164
90
func (c * SQLiteConn ) authUserAdd (username , password string , admin int ) int {
165
- // Allocate C Variables
166
- cuser := C .CString (username )
167
- cpass := C .CString (password )
168
-
169
- // Free C Variables
170
- defer func () {
171
- C .free (unsafe .Pointer (cuser ))
172
- C .free (unsafe .Pointer (cpass ))
173
- }()
174
-
175
- return int (C ._sqlite3_user_add (c .db , cuser , cpass , C .int (len (password )), C .int (admin )))
91
+ return 1
176
92
}
177
93
178
94
// AuthUserChange can be used to change a users
@@ -181,20 +97,7 @@ func (c *SQLiteConn) authUserAdd(username, password string, admin int) int {
181
97
// credentials or admin privilege setting. No user may change their own
182
98
// admin privilege setting.
183
99
func (c * SQLiteConn ) AuthUserChange (username , password string , admin bool ) error {
184
- isAdmin := 0
185
- if admin {
186
- isAdmin = 1
187
- }
188
-
189
- rv := c .authUserChange (username , password , isAdmin )
190
- switch rv {
191
- case C .SQLITE_ERROR , C .SQLITE_AUTH :
192
- return ErrAdminRequired
193
- case C .SQLITE_OK :
194
- return nil
195
- default :
196
- return c .lastError ()
197
- }
100
+ return ErrUnauthorized
198
101
}
199
102
200
103
// authUserChange allows to modify a user.
@@ -215,17 +118,7 @@ func (c *SQLiteConn) AuthUserChange(username, password string, admin bool) error
215
118
// C.SQLITE_ERROR (1)
216
119
// C.SQLITE_AUTH (23)
217
120
func (c * SQLiteConn ) authUserChange (username , password string , admin int ) int {
218
- // Allocate C Variables
219
- cuser := C .CString (username )
220
- cpass := C .CString (password )
221
-
222
- // Free C Variables
223
- defer func () {
224
- C .free (unsafe .Pointer (cuser ))
225
- C .free (unsafe .Pointer (cpass ))
226
- }()
227
-
228
- return int (C ._sqlite3_user_change (c .db , cuser , cpass , C .int (len (password )), C .int (admin )))
121
+ return 1
229
122
}
230
123
231
124
// AuthUserDelete can be used (by an admin user only)
@@ -234,15 +127,7 @@ func (c *SQLiteConn) authUserChange(username, password string, admin int) int {
234
127
// the database cannot be converted into a no-authentication-required
235
128
// database.
236
129
func (c * SQLiteConn ) AuthUserDelete (username string ) error {
237
- rv := c .authUserDelete (username )
238
- switch rv {
239
- case C .SQLITE_ERROR , C .SQLITE_AUTH :
240
- return ErrAdminRequired
241
- case C .SQLITE_OK :
242
- return nil
243
- default :
244
- return c .lastError ()
245
- }
130
+ return ErrUnauthorized
246
131
}
247
132
248
133
// authUserDelete can be used to delete a user.
@@ -258,25 +143,12 @@ func (c *SQLiteConn) AuthUserDelete(username string) error {
258
143
// C.SQLITE_ERROR (1)
259
144
// C.SQLITE_AUTH (23)
260
145
func (c * SQLiteConn ) authUserDelete (username string ) int {
261
- // Allocate C Variables
262
- cuser := C .CString (username )
263
-
264
- // Free C Variables
265
- defer func () {
266
- C .free (unsafe .Pointer (cuser ))
267
- }()
268
-
269
- return int (C ._sqlite3_user_delete (c .db , cuser ))
146
+ return 1
270
147
}
271
148
272
149
// AuthEnabled checks if the database is protected by user authentication
273
150
func (c * SQLiteConn ) AuthEnabled () (exists bool ) {
274
- rv := c .authEnabled ()
275
- if rv == 1 {
276
- exists = true
277
- }
278
-
279
- return
151
+ return false
280
152
}
281
153
282
154
// authEnabled perform the actual check for user authentication.
@@ -289,7 +161,7 @@ func (c *SQLiteConn) AuthEnabled() (exists bool) {
289
161
// 0 - Disabled
290
162
// 1 - Enabled
291
163
func (c * SQLiteConn ) authEnabled () int {
292
- return int ( C . _sqlite3_auth_enabled ( c . db ))
164
+ return 1
293
165
}
294
166
295
167
// EOF
0 commit comments