aboutsummaryrefslogtreecommitdiff
path: root/modules/auth
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
parent7a7c096fd09035f759168800402389457648f47e (diff)
parentf92bdf875b4ccb2a8eadaa571d112ebf653986d6 (diff)
Merge branch 'develop' of github.com:gogits/gogs into develop
Diffstat (limited to 'modules/auth')
-rw-r--r--modules/auth/auth_form.go1
-rw-r--r--modules/auth/pam/pam.go35
-rw-r--r--modules/auth/pam/pam_stub.go15
3 files changed, 51 insertions, 0 deletions
diff --git a/modules/auth/auth_form.go b/modules/auth/auth_form.go
index 7d459999..1102dc34 100644
--- a/modules/auth/auth_form.go
+++ b/modules/auth/auth_form.go
@@ -30,6 +30,7 @@ type AuthenticationForm struct {
SMTPPort int `form:"smtp_port"`
TLS bool `form:"tls"`
AllowAutoRegister bool `form:"allowautoregister"`
+ PAMServiceName string
}
func (f *AuthenticationForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
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
+}
diff --git a/modules/auth/pam/pam_stub.go b/modules/auth/pam/pam_stub.go
new file mode 100644
index 00000000..2f210bf6
--- /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")
+}