aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Olheiser <john.olheiser@gmail.com>2020-10-23 05:10:29 -0500
committerGitHub <noreply@github.com>2020-10-23 11:10:29 +0100
commit21d621301ef6862ebf59a6ef84fb34028832be4f (patch)
tree2102851a9dbddbf9ef11b389b3b2c2517e7b2959
parent9912a11b333950bebb90318183ad9ceb505301c4 (diff)
downloadgitea-21d621301ef6862ebf59a6ef84fb34028832be4f.tar.gz
gitea-21d621301ef6862ebf59a6ef84fb34028832be4f.zip
Remove PAM from auth dropdown when unavailable (#13276)
Signed-off-by: jolheiser <john.olheiser@gmail.com>
-rw-r--r--modules/auth/pam/pam.go3
-rw-r--r--modules/auth/pam/pam_stub.go3
-rw-r--r--routers/admin/auths.go23
3 files changed, 21 insertions, 8 deletions
diff --git a/modules/auth/pam/pam.go b/modules/auth/pam/pam.go
index ca299b08ba..f21602c6b5 100644
--- a/modules/auth/pam/pam.go
+++ b/modules/auth/pam/pam.go
@@ -12,6 +12,9 @@ import (
"github.com/msteinert/pam"
)
+// Supported is true when built with PAM
+var Supported = true
+
// Auth pam auth service
func Auth(serviceName, userName, passwd string) (string, error) {
t, err := pam.StartFunc(serviceName, userName, func(s pam.Style, msg string) (string, error) {
diff --git a/modules/auth/pam/pam_stub.go b/modules/auth/pam/pam_stub.go
index 604799ca97..02d8da3c57 100644
--- a/modules/auth/pam/pam_stub.go
+++ b/modules/auth/pam/pam_stub.go
@@ -10,6 +10,9 @@ import (
"errors"
)
+// Supported is false when built without PAM
+var Supported = false
+
// Auth not supported lack of pam tag
func Auth(serviceName, userName, passwd string) (string, error) {
return "", errors.New("PAM not supported")
diff --git a/routers/admin/auths.go b/routers/admin/auths.go
index 98f6e25b1f..bae1c863e9 100644
--- a/routers/admin/auths.go
+++ b/routers/admin/auths.go
@@ -13,6 +13,7 @@ import (
"code.gitea.io/gitea/modules/auth"
"code.gitea.io/gitea/modules/auth/ldap"
"code.gitea.io/gitea/modules/auth/oauth2"
+ "code.gitea.io/gitea/modules/auth/pam"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/log"
@@ -57,14 +58,20 @@ type dropdownItem struct {
}
var (
- authSources = []dropdownItem{
- {models.LoginNames[models.LoginLDAP], models.LoginLDAP},
- {models.LoginNames[models.LoginDLDAP], models.LoginDLDAP},
- {models.LoginNames[models.LoginSMTP], models.LoginSMTP},
- {models.LoginNames[models.LoginPAM], models.LoginPAM},
- {models.LoginNames[models.LoginOAuth2], models.LoginOAuth2},
- {models.LoginNames[models.LoginSSPI], models.LoginSSPI},
- }
+ authSources = func() []dropdownItem {
+ items := []dropdownItem{
+ {models.LoginNames[models.LoginLDAP], models.LoginLDAP},
+ {models.LoginNames[models.LoginDLDAP], models.LoginDLDAP},
+ {models.LoginNames[models.LoginSMTP], models.LoginSMTP},
+ {models.LoginNames[models.LoginOAuth2], models.LoginOAuth2},
+ {models.LoginNames[models.LoginSSPI], models.LoginSSPI},
+ }
+ if pam.Supported {
+ items = append(items, dropdownItem{models.LoginNames[models.LoginPAM], models.LoginPAM})
+ }
+ return items
+ }()
+
securityProtocols = []dropdownItem{
{models.SecurityProtocolNames[ldap.SecurityProtocolUnencrypted], ldap.SecurityProtocolUnencrypted},
{models.SecurityProtocolNames[ldap.SecurityProtocolLDAPS], ldap.SecurityProtocolLDAPS},