UPD: User Authentication
Implemented table check; only activate User Authentication on a database which has no UA enabled. Closes #582
This commit is contained in:
parent
2d9b52a482
commit
183e7d61d1
10
sqlite3.go
10
sqlite3.go
|
@ -1368,14 +1368,8 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
|
||||||
return nil, fmt.Errorf("Missing '_auth_pass' while user authentication was requested with '_auth'")
|
return nil, fmt.Errorf("Missing '_auth_pass' while user authentication was requested with '_auth'")
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Table exists check for table 'sqlite_user'
|
// Check if User Authentication is Enabled
|
||||||
// replace 'authExists := false' with return value of table exists check
|
authExists := conn.AuthIsEnabled()
|
||||||
//
|
|
||||||
// REPLACE BY RESULT FROM TABLE EXISTS
|
|
||||||
// SELECT count(type) as exists FROM sqlite_master WHERE type='table' AND name='sqlite_user';
|
|
||||||
// Scan result 'exists' and use it instead of boolean below.
|
|
||||||
authExists := false
|
|
||||||
|
|
||||||
if !authExists {
|
if !authExists {
|
||||||
if err := conn.AuthUserAdd(authUser, authPass, true); err != nil {
|
if err := conn.AuthUserAdd(authUser, authPass, true); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -40,6 +40,23 @@ _sqlite3_user_delete(sqlite3* db, const char* zUsername)
|
||||||
{
|
{
|
||||||
return sqlite3_user_delete(db, zUsername);
|
return sqlite3_user_delete(db, zUsername);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
_sqlite3_auth_is_enabled(sqlite3* db)
|
||||||
|
{
|
||||||
|
int exists = -1;
|
||||||
|
|
||||||
|
sqlite3_stmt *stmt;
|
||||||
|
sqlite3_prepare_v2(db, "select count(type) from sqlite_master WHERE type='table' and name='sqlite_user';", -1, &stmt, NULL);
|
||||||
|
|
||||||
|
while ( sqlite3_step(stmt) == SQLITE_ROW) {
|
||||||
|
exists = sqlite3_column_int(stmt, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
sqlite3_finalize(stmt);
|
||||||
|
|
||||||
|
return exists;
|
||||||
|
}
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
import (
|
import (
|
||||||
|
@ -165,4 +182,14 @@ func (c *SQLiteConn) AuthUserDelete(username string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check is database is protected by user authentication
|
||||||
|
func (c *SQLiteConn) AuthIsEnabled() (exists bool) {
|
||||||
|
rv := C._sqlite3_auth_is_enabled(c.db)
|
||||||
|
if rv == 1 {
|
||||||
|
exists = true
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// EOF
|
// EOF
|
||||||
|
|
Loading…
Reference in New Issue