diff options
| author | Mikhail Osipov <mike.osipov@gmail.com> | 2021-09-22 14:08:50 +0300 |
|---|---|---|
| committer | Mikhail Osipov <mike.osipov@gmail.com> | 2021-09-22 14:10:24 +0300 |
| commit | bb5930cfc1852de96296c3a8b19b1e202e5c504c (patch) | |
| tree | e66aad2b93762e88889ce7052cb2e9b1a50e32e6 /pkg/server/hook/auth.go | |
| parent | 8f869ec31d249732e22c609e8dff0a492a47af5a (diff) | |
aes: get secret from file
Diffstat (limited to 'pkg/server/hook/auth.go')
| -rw-r--r-- | pkg/server/hook/auth.go | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/pkg/server/hook/auth.go b/pkg/server/hook/auth.go index 0f70d88..9c8ca35 100644 --- a/pkg/server/hook/auth.go +++ b/pkg/server/hook/auth.go @@ -68,19 +68,18 @@ func hashsum(args ...string) string { func getpass(f *os.File, salt string, user string) string { f.Seek(0, 0) + match := func(s, t string) bool { + if salt == "" { + return s == t + } + return hashsum(salt, s) == t + } + for scanner := bufio.NewScanner(f); scanner.Scan(); { splitted := strings.SplitN(scanner.Text(), "#", 2) tokens := strings.Fields(splitted[0]) - if len(tokens) > 1 { - if salt == "" { - if tokens[0] == user { - return tokens[1] - } - } else { - if hashsum(salt, tokens[0]) == user { - return tokens[1] - } - } + if len(tokens) > 1 && match(tokens[0], user) { + return tokens[1] } } @@ -226,7 +225,6 @@ func (a *auth) Close() { func (h *authHook) New(env env.Env) (interface{}, error) { file := env.Value("authfile") - if file == "" { return nil, errors.New("no authfile configured") } |
