You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

pam.go 961B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. //go:build pam
  5. // +build pam
  6. package pam
  7. import (
  8. "errors"
  9. "github.com/msteinert/pam"
  10. )
  11. // Supported is true when built with PAM
  12. var Supported = true
  13. // Auth pam auth service
  14. func Auth(serviceName, userName, passwd string) (string, error) {
  15. t, err := pam.StartFunc(serviceName, userName, func(s pam.Style, msg string) (string, error) {
  16. switch s {
  17. case pam.PromptEchoOff:
  18. return passwd, nil
  19. case pam.PromptEchoOn, pam.ErrorMsg, pam.TextInfo:
  20. return "", nil
  21. }
  22. return "", errors.New("Unrecognized PAM message style")
  23. })
  24. if err != nil {
  25. return "", err
  26. }
  27. if err = t.Authenticate(0); err != nil {
  28. return "", err
  29. }
  30. // PAM login names might suffer transformations in the PAM stack.
  31. // We should take whatever the PAM stack returns for it.
  32. return t.GetItem(pam.User)
  33. }