1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: Apache-2.0
7 // This file is compiled by docker_test.go to build a test client.
8 // It's not part of the pam module itself.
17 "github.com/msteinert/pam"
18 "github.com/sirupsen/logrus"
22 if len(os.Args) != 4 || os.Args[1] != "try" {
23 logrus.Print("usage: testclient try 'username' 'password'")
26 username := os.Args[2]
27 password := os.Args[3]
29 // Configure PAM to use arvados token auth by default.
30 cmd := exec.Command("pam-auth-update", "--force", "arvados", "--remove", "unix")
31 cmd.Env = append([]string{"DEBIAN_FRONTEND=noninteractive"}, os.Environ()...)
33 cmd.Stdout = os.Stdout
34 cmd.Stderr = os.Stderr
37 logrus.WithError(err).Error("pam-auth-update failed")
41 // Check that pam-auth-update actually added arvados config.
42 cmd = exec.Command("grep", "-Hn", "arvados", "/etc/pam.d/common-auth")
43 cmd.Stdout = os.Stderr
44 cmd.Stderr = os.Stderr
50 logrus.Debugf("starting pam: username=%q password=%q", username, password)
54 tx, err := pam.StartFunc("default", username, func(style pam.Style, message string) (string, error) {
55 logrus.Debugf("pam conversation: style=%v message=%q", style, message)
58 logrus.WithField("Message", message).Info("pam.ErrorMsg")
59 errorMessage = message
62 logrus.WithField("Message", message).Info("pam.TextInfo")
63 errorMessage = message
65 case pam.PromptEchoOn, pam.PromptEchoOff:
69 return "", fmt.Errorf("unrecognized message style %d", style)
73 logrus.WithError(err).Print("StartFunc failed")
76 err = tx.Authenticate(pam.DisallowNullAuthtok)
78 err = fmt.Errorf("PAM: %s (message = %q)", err, errorMessage)
79 logrus.WithError(err).Print("authentication failed")
82 logrus.Print("authentication succeeded")