Skip to content

Commit fb8f69a

Browse files
committed
default AcceptEnv to LANG and LC_* for distro compatibility #25
1 parent f792cdc commit fb8f69a

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

tsshd/sshd_config.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,14 @@ func parseSshdConfig(path, user string, groups []string) {
124124
sshdConfigMap = make(map[string]string)
125125
sshdSubsystemMap = make(map[string]string)
126126

127+
// While OpenSSH defaults AcceptEnv to empty, most Linux distributions
128+
// (e.g., Ubuntu, Debian, CentOS) include "LANG" and "LC_*" by default
129+
// to preserve locale settings across SSH sessions.
130+
// We follow this convention as our internal default. However, we also
131+
// support explicitly setting AcceptEnv to an empty value in the
132+
// configuration to override this behavior and clear all accepted variables.
133+
sshdConfigMap["AcceptEnv"] = "LANG LC_*"
134+
127135
file, err := os.Open(path)
128136
if err != nil {
129137
return
@@ -142,11 +150,8 @@ func parseSshdConfig(path, user string, groups []string) {
142150
}
143151

144152
key, value := splitKeyValue(line)
145-
if value == "" {
146-
continue
147-
}
148153

149-
if key == "match" {
154+
if key == "match" && value != "" {
150155
inMatch = true
151156
userMatch = evalMatchLine(value, user, groups)
152157
continue
@@ -156,9 +161,9 @@ func parseSshdConfig(path, user string, groups []string) {
156161
continue
157162
}
158163

159-
if key == "subsystem" {
164+
if key == "subsystem" && value != "" {
160165
name, path := splitKeyValue(value)
161-
if name != "" && path != "" {
166+
if name != "" {
162167
sshdSubsystemMap[name] = path
163168
}
164169
continue

tsshd/sshd_config_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ Match User mary
6060
6161
Match Group admin
6262
AllowTcpForwarding Yes
63-
AcceptEnv LANG LC_*
63+
AcceptEnv
6464
Subsystem Asvr /usr/bin/asvr
6565
6666
Match User bob Group=users
@@ -84,6 +84,8 @@ Match User bob Group=users
8484
assert.Equal("Yes", getSshdConfig("X11Forwarding"))
8585
assert.Equal("/usr/lib/openssh/sftp-server", getSshdSubsystem("sftp"))
8686
assert.Equal("/usr/bin/asvr", getSshdSubsystem("ASVR"))
87+
// Empty AcceptEnv inside Match should override the default/global value.
88+
assert.Equal("", getSshdConfig("AcceptEnv"))
8789
}
8890

8991
func TestSplitKeyValue(t *testing.T) {

0 commit comments

Comments
 (0)