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.

36 lines
724 B

  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) 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. return nil
  28. }