Initial commit
This commit is contained in:
31
internal/auth/repositories/pam_repository.go
Normal file
31
internal/auth/repositories/pam_repository.go
Normal file
@ -0,0 +1,31 @@
|
||||
package repositories
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/msteinert/pam"
|
||||
)
|
||||
|
||||
type PamRepository struct{}
|
||||
|
||||
func NewPamRepository() *PamRepository {
|
||||
return &PamRepository{}
|
||||
}
|
||||
|
||||
func (pr *PamRepository) IsValidUser(user, password string) bool {
|
||||
tx, err := pam.StartFunc("virteen", user, func(s pam.Style, msg string) (string, error) {
|
||||
return password, nil
|
||||
})
|
||||
if err != nil {
|
||||
panic("failed to start PAM transaction")
|
||||
}
|
||||
|
||||
err = tx.Authenticate(pam.Silent)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "authenticate: %s\n", err.Error())
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
Reference in New Issue
Block a user