-
Notifications
You must be signed in to change notification settings - Fork 0
/
pam.go
44 lines (40 loc) · 857 Bytes
/
pam.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main
import (
"errors"
"fmt"
"log"
"github.com/msteinert/pam"
)
func PAMAuth(username, password string) bool {
t, err := pam.StartFunc("", "", func(s pam.Style, msg string) (string, error) {
switch s {
case pam.PromptEchoOff:
return password, nil
case pam.PromptEchoOn:
return username, nil
case pam.ErrorMsg:
log.Print(msg)
return "", nil
case pam.TextInfo:
fmt.Println(msg)
return "", nil
}
return "", errors.New("unrecognized message style")
})
if err != nil {
log.Fatalf("Start: %s", err.Error())
return false
}
err = t.Authenticate(0)
if err != nil {
log.Printf("authenticate: %s", err.Error())
return false
}
err = t.AcctMgmt(0)
if err != nil {
log.Printf("pam acct_mgmt: %s", err.Error())
return false
}
log.Printf("authentication for {%s} succeeded\n", username)
return true
}