~sircmpwn/tokidoki

a115c5003769b5df14bd6a64e6c6a122baf65f1b — Conrad Hoffmann 10 months ago 96e33a0
auth/*: more consistent logging
2 files changed, 6 insertions(+), 6 deletions(-)

M auth/imap.go
M auth/pam.go
M auth/imap.go => auth/imap.go +2 -2
@@ 44,7 44,7 @@ func (prov *IMAPProvider) doAuth(next http.Handler,

	conn, err := prov.dial()
	if err != nil {
		log.Debug().Err(err).Msg("auth dial error")
		log.Warn().Err(err).Msg("auth dial error")
		http.Error(w, "Temporary authentication error, try again later", http.StatusServiceUnavailable)
		return
	}


@@ 52,7 52,7 @@ func (prov *IMAPProvider) doAuth(next http.Handler,

	auth := sasl.NewPlainClient("", user, pass)
	if err := conn.Authenticate(auth); err != nil {
		log.Debug().Err(err).Msg("auth error")
		log.Debug().Str("user", user).Err(err).Msg("auth error")
		http.Error(w, "Invalid username or password", http.StatusUnauthorized)
		return
	}

M auth/pam.go => auth/pam.go +4 -4
@@ 44,26 44,26 @@ func pamAuth(next http.Handler, w http.ResponseWriter, r *http.Request) {
		}
	})
	if err != nil {
		log.Debug().Err(err).Msg("failed to start PAM conversation")
		log.Warn().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 {
		log.Debug().Err(err).Msg("auth error")
		log.Debug().Str("user", user).Err(err).Msg("auth error")
		http.Error(w, "Invalid username or password", http.StatusUnauthorized)
		return
	}

	if err := t.AcctMgmt(0); err != nil {
		log.Debug().Err(err).Msg("account unavailable")
		log.Debug().Str("user", user).Err(err).Msg("account unavailable")
		http.Error(w, "Account unavailable", http.StatusUnauthorized)
		return
	}

	user, err = t.GetItem(pam.User)
	if err != nil {
		log.Debug().Err(err).Msg("failed to get PAM username")
		log.Warn().Str("user", user).Err(err).Msg("failed to get PAM username")
		http.Error(w, "Temporary authentication error, try again later", http.StatusServiceUnavailable)
		return
	}