From 8ff8aef19d523691647a42a76076c197f5ba7184 Mon Sep 17 00:00:00 2001 From: Garet Halliday <me@garet.holiday> Date: Thu, 7 Sep 2023 19:21:54 -0500 Subject: [PATCH] make linter slightly happier --- lib/bouncer/backends/v0/accept.go | 112 ++++++++++++------------ lib/rob/schedulers/v2/scheduler_test.go | 3 +- lib/rob/schedulers/v2/sink/sink.go | 2 +- 3 files changed, 60 insertions(+), 57 deletions(-) diff --git a/lib/bouncer/backends/v0/accept.go b/lib/bouncer/backends/v0/accept.go index e3e96df2..ec4dbb3c 100644 --- a/lib/bouncer/backends/v0/accept.go +++ b/lib/bouncer/backends/v0/accept.go @@ -107,6 +107,63 @@ func authenticationCleartext(server fed.Conn, creds auth.Cleartext) error { return nil } +func authentication(server fed.Conn, creds auth.Credentials, packet fed.Packet) (done bool, err error) { + var method int32 + packet.ReadInt32(&method) + // they have more authentication methods than there are pokemon + switch method { + case 0: + // we're good to go, that was easy + return true, nil + case 2: + err = errors.New("kerberos v5 is not supported") + return + case 3: + c, ok := creds.(auth.Cleartext) + if !ok { + return false, auth.ErrMethodNotSupported + } + return false, authenticationCleartext(server, c) + case 5: + var md5 packets.AuthenticationMD5 + if !md5.ReadFromPacket(packet) { + err = ErrBadFormat + return + } + + c, ok := creds.(auth.MD5) + if !ok { + return false, auth.ErrMethodNotSupported + } + return false, authenticationMD5(server, md5.Salt, c) + case 6: + err = errors.New("scm credential is not supported") + return + case 7: + err = errors.New("gss is not supported") + return + case 9: + err = errors.New("sspi is not supported") + return + case 10: + // read list of mechanisms + var sasl packets.AuthenticationSASL + if !sasl.ReadFromPacket(packet) { + err = ErrBadFormat + return + } + + c, ok := creds.(auth.SASL) + if !ok { + return false, auth.ErrMethodNotSupported + } + return false, authenticationSASL(server, sasl.Mechanisms, c) + default: + err = errors.New("unknown authentication method") + return + } +} + func startup0(server fed.Conn, creds auth.Credentials) (done bool, err error) { var packet fed.Packet packet, err = server.ReadPacket(true) @@ -124,60 +181,7 @@ func startup0(server fed.Conn, creds auth.Credentials) (done bool, err error) { } return case packets.TypeAuthentication: - var method int32 - packet.ReadInt32(&method) - // they have more authentication methods than there are pokemon - switch method { - case 0: - // we're good to go, that was easy - return true, nil - case 2: - err = errors.New("kerberos v5 is not supported") - return - case 3: - c, ok := creds.(auth.Cleartext) - if !ok { - return false, auth.ErrMethodNotSupported - } - return false, authenticationCleartext(server, c) - case 5: - var md5 packets.AuthenticationMD5 - if !md5.ReadFromPacket(packet) { - err = ErrBadFormat - return - } - - c, ok := creds.(auth.MD5) - if !ok { - return false, auth.ErrMethodNotSupported - } - return false, authenticationMD5(server, md5.Salt, c) - case 6: - err = errors.New("scm credential is not supported") - return - case 7: - err = errors.New("gss is not supported") - return - case 9: - err = errors.New("sspi is not supported") - return - case 10: - // read list of mechanisms - var sasl packets.AuthenticationSASL - if !sasl.ReadFromPacket(packet) { - err = ErrBadFormat - return - } - - c, ok := creds.(auth.SASL) - if !ok { - return false, auth.ErrMethodNotSupported - } - return false, authenticationSASL(server, sasl.Mechanisms, c) - default: - err = errors.New("unknown authentication method") - return - } + return authentication(server, creds, packet) case packets.TypeNegotiateProtocolVersion: // we only support protocol 3.0 for now err = errors.New("server wanted to negotiate protocol version") diff --git a/lib/rob/schedulers/v2/scheduler_test.go b/lib/rob/schedulers/v2/scheduler_test.go index 2ba0039d..76b75150 100644 --- a/lib/rob/schedulers/v2/scheduler_test.go +++ b/lib/rob/schedulers/v2/scheduler_test.go @@ -30,8 +30,7 @@ func (T *ShareTable) Get(user int) int { T.mu.RLock() defer T.mu.RUnlock() - v, _ := T.table[user] - return v + return T.table[user] } func testSink(sched *Scheduler) uuid.UUID { diff --git a/lib/rob/schedulers/v2/sink/sink.go b/lib/rob/schedulers/v2/sink/sink.go index 8bfd2c03..c8e3519b 100644 --- a/lib/rob/schedulers/v2/sink/sink.go +++ b/lib/rob/schedulers/v2/sink/sink.go @@ -224,7 +224,7 @@ func (T *Sink) StealFor(rhs *Sink) uuid.UUID { user := j.User - pending, _ := T.pending[user] + pending := T.pending[user] delete(T.pending, user) T.mu.Unlock() -- GitLab