Skip to content

Commit

Permalink
Convert lib/pam to use slog (#50310)
Browse files Browse the repository at this point in the history
  • Loading branch information
rosstimothy authored Dec 17, 2024
1 parent e3a6af3 commit 4dd5276
Showing 1 changed file with 7 additions and 8 deletions.
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

0 comments on commit 4dd5276

Please sign in to comment.