Attempt to modernize the repo
This commit is contained in:
22
.github/workflows/test.yaml
vendored
Normal file
22
.github/workflows/test.yaml
vendored
Normal 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
1
.gitignore
vendored
@@ -1 +0,0 @@
|
||||
coverage.out
|
||||
18
.travis.yml
18
.travis.yml
@@ -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
|
||||
@@ -1,7 +1,5 @@
|
||||
[](https://travis-ci.org/msteinert/pam)
|
||||
[](http://godoc.org/github.com/msteinert/pam)
|
||||
[](https://coveralls.io/r/msteinert/pam?branch=master)
|
||||
[](http://goreportcard.com/report/msteinert/pam)
|
||||
[](https://goreportcard.com/report/github.com/msteinert/pam)
|
||||
|
||||
# Go PAM
|
||||
|
||||
|
||||
@@ -4,50 +4,49 @@ import (
|
||||
"bufio"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/bgentry/speakeasy"
|
||||
"github.com/msteinert/pam"
|
||||
"golang.org/x/term"
|
||||
)
|
||||
|
||||
// This example uses whatever default PAM service configuration is available
|
||||
// on the system, and tries to authenticate any user. This should cause PAM
|
||||
// to ask its conversation handler for a username and password, in sequence.
|
||||
//
|
||||
// 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() {
|
||||
// This example uses the default PAM service to authenticate any users. This
|
||||
// should cause PAM to ask its conversation handler for a username and password
|
||||
// in sequence.
|
||||
func Example() {
|
||||
t, err := pam.StartFunc("", "", func(s pam.Style, msg string) (string, error) {
|
||||
switch s {
|
||||
case pam.PromptEchoOff:
|
||||
return speakeasy.Ask(msg)
|
||||
case pam.PromptEchoOn:
|
||||
fmt.Print(msg + " ")
|
||||
input, err := bufio.NewReader(os.Stdin).ReadString('\n')
|
||||
fmt.Print(msg)
|
||||
pw, err := term.ReadPassword(int(os.Stdin.Fd()))
|
||||
if err != nil {
|
||||
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:
|
||||
log.Print(msg)
|
||||
fmt.Fprintf(os.Stderr, "%s\n", msg)
|
||||
return "", nil
|
||||
case pam.TextInfo:
|
||||
fmt.Println(msg)
|
||||
return "", nil
|
||||
default:
|
||||
return "", errors.New("unrecognized message style")
|
||||
}
|
||||
return "", errors.New("Unrecognized message style")
|
||||
})
|
||||
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)
|
||||
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
7
go.mod
Normal 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
4
go.sum
Normal 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=
|
||||
@@ -3,7 +3,6 @@ package pam
|
||||
import (
|
||||
"errors"
|
||||
"os/user"
|
||||
"runtime"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -31,7 +30,6 @@ func TestPAM_001(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("setcred #error: %v", err)
|
||||
}
|
||||
runtime.GC()
|
||||
}
|
||||
|
||||
func TestPAM_002(t *testing.T) {
|
||||
@@ -55,7 +53,6 @@ func TestPAM_002(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("authenticate #error: %v", err)
|
||||
}
|
||||
runtime.GC()
|
||||
}
|
||||
|
||||
type Credentials struct {
|
||||
@@ -90,7 +87,6 @@ func TestPAM_003(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("authenticate #error: %v", err)
|
||||
}
|
||||
runtime.GC()
|
||||
}
|
||||
|
||||
func TestPAM_004(t *testing.T) {
|
||||
@@ -109,7 +105,6 @@ func TestPAM_004(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("authenticate #error: %v", err)
|
||||
}
|
||||
runtime.GC()
|
||||
}
|
||||
|
||||
func TestPAM_005(t *testing.T) {
|
||||
@@ -127,7 +122,6 @@ func TestPAM_005(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("chauthtok #error: %v", err)
|
||||
}
|
||||
runtime.GC()
|
||||
}
|
||||
|
||||
func TestPAM_006(t *testing.T) {
|
||||
@@ -149,7 +143,6 @@ func TestPAM_006(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("close_session #error: %v", err)
|
||||
}
|
||||
runtime.GC()
|
||||
}
|
||||
|
||||
func TestPAM_007(t *testing.T) {
|
||||
@@ -171,7 +164,6 @@ func TestPAM_007(t *testing.T) {
|
||||
if len(s) == 0 {
|
||||
t.Fatalf("error #expected an error message")
|
||||
}
|
||||
runtime.GC()
|
||||
}
|
||||
|
||||
func TestItem(t *testing.T) {
|
||||
@@ -206,7 +198,6 @@ func TestItem(t *testing.T) {
|
||||
if s != "root" {
|
||||
t.Fatalf("getitem #error: expected root, got %v", s)
|
||||
}
|
||||
runtime.GC()
|
||||
}
|
||||
|
||||
func TestEnv(t *testing.T) {
|
||||
@@ -273,7 +264,6 @@ func TestEnv(t *testing.T) {
|
||||
if m["VAL3"] != "3" {
|
||||
t.Fatalf("getenvlist #error: expected 3, got %v", m["VAL1"])
|
||||
}
|
||||
runtime.GC()
|
||||
}
|
||||
|
||||
func TestFailure_001(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user