diff options
author | HimbeerserverDE <himbeerserverde@gmail.com> | 2023-07-16 14:38:12 +0200 |
---|---|---|
committer | HimbeerserverDE <himbeerserverde@gmail.com> | 2023-07-16 14:38:29 +0200 |
commit | d0c2d2b735e67d79d1adb7bd8c08cabcea7e9c66 (patch) | |
tree | cf12003be6d80127935a8784ec6b1ac4007a73d5 | |
parent | 646324d22ef74fdc8117640084c9bdfdc9cf9016 (diff) |
handle errors while importing auth information
-rw-r--r-- | auth.go | 4 | ||||
-rw-r--r-- | auth_files.go | 23 |
2 files changed, 20 insertions, 7 deletions
@@ -28,13 +28,13 @@ type authBackend interface { LastSrv(name string) (string, error) SetLastSrv(name, srv string) error Timestamp(name string) (time.Time, error) - Import(in []user) + Import(in []user) error Export() ([]user, error) Ban(addr, name string) error Unban(id string) error Banned(addr *net.UDPAddr) bool - ImportBans(in []ban) + ImportBans(in []ban) error ExportBans() ([]ban, error) } diff --git a/auth_files.go b/auth_files.go index e05cff3..3e185e2 100644 --- a/auth_files.go +++ b/auth_files.go @@ -9,6 +9,7 @@ import ( type authFiles struct{} // Exists reports whether a user is registered. +// Error cases count as inexistent. func (a authFiles) Exists(name string) bool { os.Mkdir(Path("auth"), 0700) @@ -83,13 +84,20 @@ func (a authFiles) Timestamp(name string) (time.Time, error) { } // Import deletes all users and adds the passed users. -func (a authFiles) Import(in []user) { +func (a authFiles) Import(in []user) error { os.Mkdir(Path("auth"), 0700) for _, u := range in { - a.SetPasswd(u.name, u.salt, u.verifier) - os.Chtimes(Path("auth/", u.name, "/timestamp"), u.timestamp, u.timestamp) + if err := a.SetPasswd(u.name, u.salt, u.verifier); err != nil { + return err + } + + if err := os.Chtimes(Path("auth/", u.name, "/timestamp"), u.timestamp, u.timestamp); err != nil { + return err + } } + + return nil } // Export returns data that can be processed by Import @@ -155,6 +163,7 @@ func (a authFiles) Unban(id string) error { } // Banned reports whether a network address is banned. +// Error cases count as banned. func (a authFiles) Banned(addr *net.UDPAddr) bool { os.Mkdir(Path("ban"), 0700) @@ -167,12 +176,16 @@ func (a authFiles) Banned(addr *net.UDPAddr) bool { } // ImportBans deletes all ban entries and adds the passed entries. -func (a authFiles) ImportBans(in []ban) { +func (a authFiles) ImportBans(in []ban) error { os.Mkdir(Path("ban"), 0700) for _, b := range in { - a.Ban(b.addr, b.name) + if err := a.Ban(b.addr, b.name); err != nil { + return err + } } + + return nil } // ExportBans returns data that can be processed by ImportBans |