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