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