Skip to content

Commit

Permalink
groups->ldapgroups
Browse files Browse the repository at this point in the history
  • Loading branch information
Fusion committed Oct 2, 2023
1 parent 1eac56d commit 6baa605
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,19 @@ so, let's say you built the 'sqlite' plugin, you would now specify its library:
### SQLite, MySQL, Postgres

Tables:
- users, groups are self-explanatory
- users, ldapgroups are self-explanatory
- includegroups store the 'includegroups' relationships
- othergroups, on the other hand, are a comma-separated list found in the users table (performance)

Here is how to insert example data using your database's REPL (more detailed information can be found in pkg/plugins/sample-database.cfg)

```sql
INSERT INTO groups(name, gidnumber) VALUES('superheros', 5501);
INSERT INTO groups(name, gidnumber) VALUES('svcaccts', 5502);
INSERT INTO groups(name, gidnumber) VALUES('civilians', 5503);
INSERT INTO groups(name, gidnumber) VALUES('caped', 5504);
INSERT INTO groups(name, gidnumber) VALUES('lovesailing', 5505);
INSERT INTO groups(name, gidnumber) VALUES('smoker', 5506);
INSERT INTO ldapgroups(name, gidnumber) VALUES('superheros', 5501);
INSERT INTO ldapgroups(name, gidnumber) VALUES('svcaccts', 5502);
INSERT INTO ldapgroups(name, gidnumber) VALUES('civilians', 5503);
INSERT INTO ldapgroups(name, gidnumber) VALUES('caped', 5504);
INSERT INTO ldapgroups(name, gidnumber) VALUES('lovesailing', 5505);
INSERT INTO ldapgroups(name, gidnumber) VALUES('smoker', 5506);
INSERT INTO includegroups(parentgroupid, includegroupid) VALUES(5503, 5501);
INSERT INTO includegroups(parentgroupid, includegroupid) VALUES(5504, 5502);
INSERT INTO includegroups(parentgroupid, includegroupid) VALUES(5504, 5501);
Expand Down
16 changes: 11 additions & 5 deletions sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (

_ "github.com/mattn/go-sqlite3"

"github.com/glauth/glauth/v2/pkg/plugins"
"github.com/glauth/glauth/v2/pkg/handler"
"github.com/glauth/glauth/v2/pkg/plugins"
)

type SqliteBackend struct {
Expand Down Expand Up @@ -50,9 +50,9 @@ CREATE TABLE IF NOT EXISTS users (
statement.Exec()
statement, _ = db.Prepare("CREATE UNIQUE INDEX IF NOT EXISTS idx_user_name on users(name)")
statement.Exec()
statement, _ = db.Prepare("CREATE TABLE IF NOT EXISTS groups (id INTEGER PRIMARY KEY, name TEXT NOT NULL, gidnumber INTEGER NOT NULL)")
statement, _ = db.Prepare("CREATE TABLE IF NOT EXISTS ldapgroups (id INTEGER PRIMARY KEY, name TEXT NOT NULL, gidnumber INTEGER NOT NULL)")
statement.Exec()
statement, _ = db.Prepare("CREATE UNIQUE INDEX IF NOT EXISTS idx_group_name on groups(name)")
statement, _ = db.Prepare("CREATE UNIQUE INDEX IF NOT EXISTS idx_group_name on ldapgroups(name)")
statement.Exec()
statement, _ = db.Prepare("CREATE TABLE IF NOT EXISTS includegroups (id INTEGER PRIMARY KEY, parentgroupid INTEGER NOT NULL, includegroupid INTEGER NOT NULL)")
statement.Exec()
Expand All @@ -61,11 +61,17 @@ CREATE TABLE IF NOT EXISTS users (
}

// Migrate schema if necessary
func (b SqliteBackend) MigrateSchema(db *sql.DB, checker func(*sql.DB, string) bool) {
if !checker(db, "sshkeys") {
func (b SqliteBackend) MigrateSchema(db *sql.DB, checker func(*sql.DB, string, string) bool) {
if !checker(db, "users", "sshkeys") {
statement, _ := db.Prepare("ALTER TABLE users ADD COLUMN sshkeys TEXT DEFAULT ''")
statement.Exec()
}
if checker(db, "groups", "name") {
statement, _ := db.Prepare("DROP TABLE ldapgroups")
statement.Exec()
statement, _ = db.Prepare("ALTER TABLE groups RENAME TO ldapgroups")
statement.Exec()
}
}

func main() {}

0 comments on commit 6baa605

Please sign in to comment.