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 1005B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. package pam
  6. import (
  7. "errors"
  8. "github.com/msteinert/pam"
  9. )
  10. // Supported is true when built with PAM
  11. var Supported = true
  12. // Auth pam auth service
  13. func Auth(serviceName, userName, passwd string) (string, error) {
  14. t, err := pam.StartFunc(serviceName, userName, func(s pam.Style, msg string) (string, error) {
  15. switch s {
  16. case pam.PromptEchoOff:
  17. return passwd, nil
  18. case pam.PromptEchoOn, pam.ErrorMsg, pam.TextInfo:
  19. return "", nil
  20. }
  21. return "", errors.New("Unrecognized PAM message style")
  22. })
  23. if err != nil {
  24. return "", err
  25. }
  26. if err = t.Authenticate(0); err != nil {
  27. return "", err
  28. }
  29. if err = t.AcctMgmt(0); err != nil {
  30. return "", err
  31. }
  32. // PAM login names might suffer transformations in the PAM stack.
  33. // We should take whatever the PAM stack returns for it.
  34. return t.GetItem(pam.User)
  35. }