aboutsummaryrefslogtreecommitdiff
path: root/modules/auth/pam/pam.go
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2015-04-24 05:21:10 -0400
committerUnknwon <u@gogs.io>2015-04-24 05:21:10 -0400
commitc08baee0855807d24a1b86adfcea86d0731e2a3a (patch)
treec033d0fd4a4c4104b0b6304ec9f2a26c6047ce10 /modules/auth/pam/pam.go
parent7a7c096fd09035f759168800402389457648f47e (diff)
parentf92bdf875b4ccb2a8eadaa571d112ebf653986d6 (diff)
Merge branch 'develop' of github.com:gogits/gogs into develop
Diffstat (limited to 'modules/auth/pam/pam.go')
-rw-r--r--modules/auth/pam/pam.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/modules/auth/pam/pam.go b/modules/auth/pam/pam.go
new file mode 100644
index 00000000..7d150b1c
--- /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
+}