summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Steinert <[email protected]>2023-11-29 21:17:23 -0600
committerGitHub <[email protected]>2023-11-29 21:17:23 -0600
commit6bce85f6ba604fd89514f24e5f2364ee587588ec (patch)
treeb1374cfe56abad32cefc69b480902d3aa536b442
parent4ce1d8a7e0b557e7092b3e759037d5cbcb3f9380 (diff)
parent4537bb55839bf7bb28facb2117f723308c750451 (diff)
Merge pull request #17 from msteinert/update-examplev2.0.0
Update example code to call Transaction.End
-rw-r--r--example_test.go13
1 files changed, 10 insertions, 3 deletions
diff --git a/example_test.go b/example_test.go
index 8a347a6..3ab0882 100644
--- a/example_test.go
+++ b/example_test.go
@@ -14,7 +14,7 @@ import (
// 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) {
+ t, err := pam.StartFunc("passwd", "", func(s pam.Style, msg string) (string, error) {
switch s {
case pam.PromptEchoOff:
fmt.Print(msg)
@@ -40,12 +40,19 @@ func Example() {
}
})
if err != nil {
- fmt.Fprintf(os.Stderr, "start: %s\n", err.Error())
+ fmt.Fprintf(os.Stderr, "start: %v\n", err)
os.Exit(1)
}
+ defer func() {
+ err := t.End()
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "end: %v\n", err)
+ os.Exit(1)
+ }
+ }()
err = t.Authenticate(0)
if err != nil {
- fmt.Fprintf(os.Stderr, "authenticate: %s\n", err.Error())
+ fmt.Fprintf(os.Stderr, "authenticate: %v\n", err)
os.Exit(1)
}
fmt.Println("authentication succeeded!")