Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert lib/pam to use slog #50310

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions lib/pam/pam.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import "C"

import (
"bufio"
"context"
"fmt"
"io"
"os"
Expand All @@ -57,10 +58,10 @@ import (
"unsafe"

"github.com/gravitational/trace"
"github.com/sirupsen/logrus"

"github.com/gravitational/teleport"
"github.com/gravitational/teleport/lib/service/servicecfg"
logutils "github.com/gravitational/teleport/lib/utils/log"
)

func init() {
Expand Down Expand Up @@ -101,9 +102,7 @@ func init() {
runtime.LockOSThread()
}

var log = logrus.WithFields(logrus.Fields{
teleport.ComponentKey: teleport.ComponentPAM,
})
var logger = logutils.NewPackageLogger(teleport.ComponentKey, teleport.ComponentPAM)

const (
// maxMessageSize is the maximum size of a message to accept from PAM. In
Expand Down Expand Up @@ -148,7 +147,7 @@ var handlers map[int]handler = make(map[int]handler)
func writeCallback(index C.int, stream C.int, s *C.char) {
handle, err := lookupHandler(int(index))
if err != nil {
log.Errorf("Unable to write to output stream: %v", err)
logger.ErrorContext(context.Background(), "Unable to write to output stream", "error", err)
return
}

Expand All @@ -164,7 +163,7 @@ func writeCallback(index C.int, stream C.int, s *C.char) {
func readCallback(index C.int, e C.int) *C.char {
handle, err := lookupHandler(int(index))
if err != nil {
log.Errorf("Unable to read from input stream: %v", err)
logger.ErrorContext(context.Background(), "Unable to read from input stream", "error", err)
return nil
}

Expand All @@ -176,7 +175,7 @@ func readCallback(index C.int, e C.int) *C.char {
// Read from the stream (typically stdin or equivalent).
s, err := handle.readStream(echo)
if err != nil {
log.Errorf("Unable to read from input stream: %v", err)
logger.ErrorContext(context.Background(), "Unable to read from input stream", "error", err)
return nil
}

Expand Down Expand Up @@ -438,7 +437,7 @@ func (p *PAM) free() {
// Terminate the PAM transaction.
retval := C._pam_end(pamHandle, p.pamh, p.retval)
if retval != C.PAM_SUCCESS {
log.Warnf("Failed to end PAM transaction: %v.\n", p.codeToError(retval))
logger.WarnContext(context.Background(), "Failed to end PAM transaction", "error", p.codeToError(retval))
}

// Release the memory allocated for the conversation function.
Expand Down
Loading