diff options
author | Paolo Borelli <pborelli@gnome.org> | 2015-04-23 13:58:57 +0200 |
---|---|---|
committer | Ignacio Casal Quinteiro <icq@gnome.org> | 2015-04-24 10:13:01 +0200 |
commit | 182003aa417ba67661c6743e0fabe6e1f67efd1c (patch) | |
tree | cff0efe4adedd4bc52b3c852e254a7c4fe0dad99 /modules/auth/pam | |
parent | 2c4fb6e6469f756dfaeb276302bac87e4dac3e1e (diff) | |
download | gitea-182003aa417ba67661c6743e0fabe6e1f67efd1c.tar.gz gitea-182003aa417ba67661c6743e0fabe6e1f67efd1c.zip |
Add PAM authentication
Diffstat (limited to 'modules/auth/pam')
-rw-r--r-- | modules/auth/pam/pam.go | 35 | ||||
-rw-r--r-- | modules/auth/pam/pam_stub.go | 15 |
2 files changed, 50 insertions, 0 deletions
diff --git a/modules/auth/pam/pam.go b/modules/auth/pam/pam.go new file mode 100644 index 0000000000..7d150b1c0b --- /dev/null +++ b/modules/auth/pam/pam.go @@ -0,0 +1,35 @@ +// +build !windows + +// Copyright 2014 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package pam + +import ( + "errors" + + "github.com/msteinert/pam" +) + +func PAMAuth(serviceName, userName, passwd string) error { + t, err := pam.StartFunc(serviceName, userName, func(s pam.Style, msg string) (string, error) { + switch s { + case pam.PromptEchoOff: + return passwd, nil + case pam.PromptEchoOn, pam.ErrorMsg, pam.TextInfo: + return "", nil + } + return "", errors.New("Unrecognized PAM message style") + }) + + if err != nil { + return err + } + + if err = t.Authenticate(0); err != nil { + return err + } + + return nil +} diff --git a/modules/auth/pam/pam_stub.go b/modules/auth/pam/pam_stub.go new file mode 100644 index 0000000000..2f210bf6e7 --- /dev/null +++ b/modules/auth/pam/pam_stub.go @@ -0,0 +1,15 @@ +// +build windows + +// Copyright 2014 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package pam + +import ( + "errors" +) + +func PAMAuth(serviceName, userName, passwd string) error { + return errors.New("PAM not supported") +} |