diff options
author | Unknwon <u@gogs.io> | 2015-07-09 11:15:08 +0800 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2015-07-09 11:15:08 +0800 |
commit | b60fd3aaadc3e6ad227b663d599e073f1436fd1f (patch) | |
tree | 3aa7a1e26cd878c09a52078d5aa202489122f27c /modules/auth | |
parent | 3be3b8faa7b1fa8fcac0bec49f2a37e861b4353d (diff) | |
parent | 4fca548ed11cefedcaa595be1c08625a9ae9f878 (diff) |
Merge branch 'master' of github.com:gogits/gogs
Diffstat (limited to 'modules/auth')
-rw-r--r-- | modules/auth/auth_form.go | 1 | ||||
-rw-r--r-- | modules/auth/pam/pam.go | 35 | ||||
-rw-r--r-- | modules/auth/pam/pam_stub.go | 15 |
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") +} |