mirror of
https://git.sr.ht/~sircmpwn/tokidoki
synced 2025-12-12 22:17:22 +01:00
Switch to a proper logging library
Structured logs can be enabled with `-log.json`.
This commit is contained in:
parent
03fce79e57
commit
40bae8dc31
9 changed files with 75 additions and 64 deletions
13
auth/pam.go
13
auth/pam.go
|
|
@ -7,8 +7,7 @@ import (
|
|||
"net/http"
|
||||
|
||||
"github.com/msteinert/pam"
|
||||
|
||||
"git.sr.ht/~sircmpwn/tokidoki/debug"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
type pamProvider struct{}
|
||||
|
|
@ -34,7 +33,7 @@ func pamAuth(next http.Handler, w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
t, err := pam.StartFunc("login", user, func(s pam.Style, msg string) (string, error) {
|
||||
debug.Printf("%v %v", s, msg)
|
||||
log.Debug().Str("style", fmt.Sprintf("%v", s)).Msg(msg)
|
||||
switch s {
|
||||
case pam.PromptEchoOff:
|
||||
return pass, nil
|
||||
|
|
@ -45,26 +44,26 @@ func pamAuth(next http.Handler, w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
})
|
||||
if err != nil {
|
||||
debug.Printf("Failed to start PAM conversation: %v", err)
|
||||
log.Debug().Err(err).Msg("failed to start PAM conversation")
|
||||
http.Error(w, "Temporary authentication error, try again later", http.StatusServiceUnavailable)
|
||||
return
|
||||
}
|
||||
|
||||
if err := t.Authenticate(0); err != nil {
|
||||
debug.Printf("Auth error: %v", err)
|
||||
log.Debug().Err(err).Msg("auth error")
|
||||
http.Error(w, "Invalid username or password", http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
if err := t.AcctMgmt(0); err != nil {
|
||||
debug.Printf("Account unavailable: %v", err)
|
||||
log.Debug().Err(err).Msg("account unavailable")
|
||||
http.Error(w, "Account unavailable", http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
user, err = t.GetItem(pam.User)
|
||||
if err != nil {
|
||||
debug.Printf("Failed to get PAM username: %v", err)
|
||||
log.Debug().Err(err).Msg("failed to get PAM username")
|
||||
http.Error(w, "Temporary authentication error, try again later", http.StatusServiceUnavailable)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue