Attempt to modernize the repo

This commit is contained in:
Michael Steinert
2021-12-03 11:48:12 -06:00
parent e613721261
commit 39406aafe4
8 changed files with 56 additions and 55 deletions

22
.github/workflows/test.yaml vendored Normal file
View File

@@ -0,0 +1,22 @@
on: [push, pull_request]
name: Test
jobs:
test:
strategy:
matrix:
go-version: [1.16.x, 1.17.x]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
- name: Install PAM
run: sudo apt install -y libpam-dev
- name: Add a test user
run: sudo useradd -d /tmp/test -p '$1$Qd8H95T5$RYSZQeoFbEB.gS19zS99A0' -s /bin/false test
- name: Checkout code
uses: actions/checkout@v2
- name: Test
run: sudo go test -v ./...

1
.gitignore vendored
View File

@@ -1 +0,0 @@
coverage.out

View File

@@ -1,18 +0,0 @@
language: go
go:
- 1.14.x
- 1.15.x
- tip
before_install:
- sudo apt-get update -qq
- sudo apt-get install -qq --no-install-recommends libpam0g-dev
- sudo useradd -d /tmp/test -p '$1$Qd8H95T5$RYSZQeoFbEB.gS19zS99A0' -s /bin/false test
- go get github.com/axw/gocov/gocov
- go get github.com/mattn/goveralls
- go get golang.org/x/tools/cmd/cover
script:
- sudo GOROOT=$GOROOT GOPATH=$GOPATH $(which go) test -v -covermode=count -coverprofile=coverage.out .
- if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then goveralls -coverprofile=coverage.out -service travis-ci -repotoken $REPO_TOKEN; fi

View File

@@ -1,7 +1,5 @@
[![Build Status](https://travis-ci.org/msteinert/pam.svg?branch=master)](https://travis-ci.org/msteinert/pam)
[![GoDoc](https://godoc.org/github.com/msteinert/pam?status.svg)](http://godoc.org/github.com/msteinert/pam) [![GoDoc](https://godoc.org/github.com/msteinert/pam?status.svg)](http://godoc.org/github.com/msteinert/pam)
[![Coverage Status](https://coveralls.io/repos/msteinert/pam/badge.svg?branch=master)](https://coveralls.io/r/msteinert/pam?branch=master) [![Go Report Card](https://goreportcard.com/badge/github.com/msteinert/pam)](https://goreportcard.com/report/github.com/msteinert/pam)
[![Go Report Card](http://goreportcard.com/badge/msteinert/pam)](http://goreportcard.com/report/msteinert/pam)
# Go PAM # Go PAM

View File

@@ -4,50 +4,49 @@ import (
"bufio" "bufio"
"errors" "errors"
"fmt" "fmt"
"log"
"os" "os"
"github.com/bgentry/speakeasy"
"github.com/msteinert/pam" "github.com/msteinert/pam"
"golang.org/x/term"
) )
// This example uses whatever default PAM service configuration is available // This example uses the default PAM service to authenticate any users. This
// on the system, and tries to authenticate any user. This should cause PAM // should cause PAM to ask its conversation handler for a username and password
// to ask its conversation handler for a username and password, in sequence. // in sequence.
// func Example() {
// This application will handle those requests by displaying the
// PAM-provided prompt and sending back the first line of stdin input
// it can read for each.
//
// Keep in mind that unless run as root (or setuid root), the only
// user's authentication that can succeed is that of the process owner.
func Example_authenticate() {
t, err := pam.StartFunc("", "", func(s pam.Style, msg string) (string, error) { t, err := pam.StartFunc("", "", func(s pam.Style, msg string) (string, error) {
switch s { switch s {
case pam.PromptEchoOff: case pam.PromptEchoOff:
return speakeasy.Ask(msg) fmt.Print(msg)
case pam.PromptEchoOn: pw, err := term.ReadPassword(int(os.Stdin.Fd()))
fmt.Print(msg + " ")
input, err := bufio.NewReader(os.Stdin).ReadString('\n')
if err != nil { if err != nil {
return "", err return "", err
} }
return input[:len(input)-1], nil fmt.Println()
return string(pw), nil
case pam.PromptEchoOn:
fmt.Print(msg)
s := bufio.NewScanner(os.Stdin)
s.Scan()
return s.Text(), nil
case pam.ErrorMsg: case pam.ErrorMsg:
log.Print(msg) fmt.Fprintf(os.Stderr, "%s\n", msg)
return "", nil return "", nil
case pam.TextInfo: case pam.TextInfo:
fmt.Println(msg) fmt.Println(msg)
return "", nil return "", nil
default:
return "", errors.New("unrecognized message style")
} }
return "", errors.New("Unrecognized message style")
}) })
if err != nil { if err != nil {
log.Fatalf("Start: %s", err.Error()) fmt.Fprintf(os.Stderr, "start: %s\n", err.Error())
os.Exit(1)
} }
err = t.Authenticate(0) err = t.Authenticate(0)
if err != nil { if err != nil {
log.Fatalf("Authenticate: %s", err.Error()) fmt.Fprintf(os.Stderr, "authenticate: %s\n", err.Error())
os.Exit(1)
} }
fmt.Println("Authentication succeeded!") fmt.Println("authentication succeeded!")
} }

7
go.mod Normal file
View File

@@ -0,0 +1,7 @@
module github.com/msteinert/pam
go 1.17
require golang.org/x/term v0.0.0-20210927222741-03fcf44c2211
require golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 // indirect

4
go.sum Normal file
View File

@@ -0,0 +1,4 @@
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 h1:SrN+KX8Art/Sf4HNj6Zcz06G7VEz+7w9tdXTPOZ7+l4=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=

View File

@@ -3,7 +3,6 @@ package pam
import ( import (
"errors" "errors"
"os/user" "os/user"
"runtime"
"testing" "testing"
) )
@@ -31,7 +30,6 @@ func TestPAM_001(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("setcred #error: %v", err) t.Fatalf("setcred #error: %v", err)
} }
runtime.GC()
} }
func TestPAM_002(t *testing.T) { func TestPAM_002(t *testing.T) {
@@ -55,7 +53,6 @@ func TestPAM_002(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("authenticate #error: %v", err) t.Fatalf("authenticate #error: %v", err)
} }
runtime.GC()
} }
type Credentials struct { type Credentials struct {
@@ -90,7 +87,6 @@ func TestPAM_003(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("authenticate #error: %v", err) t.Fatalf("authenticate #error: %v", err)
} }
runtime.GC()
} }
func TestPAM_004(t *testing.T) { func TestPAM_004(t *testing.T) {
@@ -109,7 +105,6 @@ func TestPAM_004(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("authenticate #error: %v", err) t.Fatalf("authenticate #error: %v", err)
} }
runtime.GC()
} }
func TestPAM_005(t *testing.T) { func TestPAM_005(t *testing.T) {
@@ -127,7 +122,6 @@ func TestPAM_005(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("chauthtok #error: %v", err) t.Fatalf("chauthtok #error: %v", err)
} }
runtime.GC()
} }
func TestPAM_006(t *testing.T) { func TestPAM_006(t *testing.T) {
@@ -149,7 +143,6 @@ func TestPAM_006(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("close_session #error: %v", err) t.Fatalf("close_session #error: %v", err)
} }
runtime.GC()
} }
func TestPAM_007(t *testing.T) { func TestPAM_007(t *testing.T) {
@@ -171,7 +164,6 @@ func TestPAM_007(t *testing.T) {
if len(s) == 0 { if len(s) == 0 {
t.Fatalf("error #expected an error message") t.Fatalf("error #expected an error message")
} }
runtime.GC()
} }
func TestItem(t *testing.T) { func TestItem(t *testing.T) {
@@ -206,7 +198,6 @@ func TestItem(t *testing.T) {
if s != "root" { if s != "root" {
t.Fatalf("getitem #error: expected root, got %v", s) t.Fatalf("getitem #error: expected root, got %v", s)
} }
runtime.GC()
} }
func TestEnv(t *testing.T) { func TestEnv(t *testing.T) {
@@ -273,7 +264,6 @@ func TestEnv(t *testing.T) {
if m["VAL3"] != "3" { if m["VAL3"] != "3" {
t.Fatalf("getenvlist #error: expected 3, got %v", m["VAL1"]) t.Fatalf("getenvlist #error: expected 3, got %v", m["VAL1"])
} }
runtime.GC()
} }
func TestFailure_001(t *testing.T) { func TestFailure_001(t *testing.T) {