pam.go 758 B

12345678910111213141516171819202122232425262728293031323334
  1. //go:build pam
  2. // +build pam
  3. // Copyright 2014 The Gogs Authors. All rights reserved.
  4. // Use of this source code is governed by a MIT-style
  5. // license that can be found in the LICENSE file.
  6. package pam
  7. import (
  8. "github.com/msteinert/pam"
  9. "github.com/pkg/errors"
  10. )
  11. func (c *Config) doAuth(login, password string) error {
  12. t, err := pam.StartFunc(c.ServiceName, login, func(s pam.Style, msg string) (string, error) {
  13. switch s {
  14. case pam.PromptEchoOff:
  15. return password, nil
  16. case pam.PromptEchoOn, pam.ErrorMsg, pam.TextInfo:
  17. return "", nil
  18. }
  19. return "", errors.Errorf("unrecognized PAM message style: %v - %s", s, msg)
  20. })
  21. if err != nil {
  22. return err
  23. }
  24. err = t.Authenticate(0)
  25. if err != nil {
  26. return err
  27. }
  28. return t.AcctMgmt(0)
  29. }