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

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