From 808cffe61db046f5a22aa47432cc7b21509983d4 Mon Sep 17 00:00:00 2001 From: phga Date: Thu, 25 Nov 2021 21:19:18 +0100 Subject: [PATCH] feat: users have database privileges for their dbs (uname_%) --- cmd/bs1in/database.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/cmd/bs1in/database.go b/cmd/bs1in/database.go index 947269b..6b61524 100644 --- a/cmd/bs1in/database.go +++ b/cmd/bs1in/database.go @@ -75,7 +75,8 @@ func openMariaDBConnection() { } func createMariaDbUser(uid string, pw string) bool { - createUserStmt := `CREATE OR REPLACE USER '%s'@'%%' IDENTIFIED BY '%s';` + createUserStmt := "CREATE OR REPLACE USER '%[1]s'@'%%' IDENTIFIED BY '%[2]s';\n" + createUserStmt += "GRANT ALL ON `%[1]s\\_%%`.* TO '%[1]s'@'%%';" createUserStmt = fmt.Sprintf(createUserStmt, uid, pw) log.Println(createUserStmt) _, err := mariaDB.Exec(createUserStmt) @@ -89,11 +90,6 @@ func createMariaDbUser(uid string, pw string) bool { } func createMariaDbDatabasesForUser(uid string) bool { - // _, err := mariaDB.Exec(`DROP USER IF EXISTS '?'; - // CREATE USER '?'@'%'; - // DROP DATABASE IF EXISTS ?_W19_20; - // CREATE DATABASE ?_W19_20; - // GRANT ALL ON ?_W19_20.* TO '?'@'%' IDENTIFIED BY '?';`, uid, uid, uid, uid, uid, uid, pw) sqlFilePath := "../../sql/" files, err := ioutil.ReadDir(sqlFilePath) if err != nil {