mirror of
https://gogs.blitter.com/RLabs/xs
synced 2024-08-14 10:26:42 +00:00
Oops. Forgot to add hexkauth.go to last few commits.
This commit is contained in:
parent
4d9ea3cbe1
commit
3ca98d364c
1 changed files with 43 additions and 0 deletions
43
hkexauth.go
Normal file
43
hkexauth.go
Normal file
|
@ -0,0 +1,43 @@
|
|||
// Authentication routines for the HKExSh
|
||||
|
||||
package herradurakex
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/csv"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
func AuthUser(username string, authcookie string, fname string) (valid bool, allowedCmds string) {
|
||||
b, _ := ioutil.ReadFile(fname)
|
||||
r := csv.NewReader(bytes.NewReader(b))
|
||||
|
||||
b = nil
|
||||
runtime.GC() // Paranoia and prob. not effective; kill authFile in b[]
|
||||
|
||||
r.Comma = ':'
|
||||
r.Comment = '#'
|
||||
r.FieldsPerRecord = 3 // username:authCookie:disallowedCmdList (a,b,...)
|
||||
for {
|
||||
record, err := r.Read()
|
||||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if username == record[0] &&
|
||||
authcookie == record[1] {
|
||||
valid = true
|
||||
break
|
||||
}
|
||||
|
||||
fmt.Println(record)
|
||||
}
|
||||
return
|
||||
}
|
Loading…
Reference in a new issue