summaryrefslogtreecommitdiff
path: root/session.c
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2018-07-03 10:59:35 +0000
committerDamien Miller <djm@mindrot.org>2018-07-03 21:01:30 +1000
commit95344c257412b51199ead18d54eaed5bafb75617 (patch)
tree320a21db8781ca4f6a363db928ca04b3b0d1dd70 /session.c
parent6f56fe4b9578b0627667f8bce69d4d938a88324c (diff)
downloadopenssh-git-95344c257412b51199ead18d54eaed5bafb75617.tar.gz
upstream: allow sshd_config PermitUserEnvironment to accept a
pattern-list of whitelisted environment variable names in addition to yes|no. bz#1800, feedback and ok markus@ OpenBSD-Commit-ID: 77dc2b468e0bf04b53f333434ba257008a1fdf24
Diffstat (limited to 'session.c')
-rw-r--r--session.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/session.c b/session.c
index 85df6a27..3c4e9c44 100644
--- a/session.c
+++ b/session.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: session.c,v 1.300 2018/06/09 03:03:10 djm Exp $ */
+/* $OpenBSD: session.c,v 1.301 2018/07/03 10:59:35 djm Exp $ */
/*
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
* All rights reserved
@@ -867,10 +867,12 @@ check_quietlogin(Session *s, const char *command)
* into the environment. If the file does not exist, this does nothing.
* Otherwise, it must consist of empty lines, comments (line starts with '#')
* and assignments of the form name=value. No other forms are allowed.
+ * If whitelist is not NULL, then it is interpreted as a pattern list and
+ * only variable names that match it will be accepted.
*/
static void
read_environment_file(char ***env, u_int *envsize,
- const char *filename)
+ const char *filename, const char *whitelist)
{
FILE *f;
char *line = NULL, *cp, *value;
@@ -903,6 +905,9 @@ read_environment_file(char ***env, u_int *envsize,
*/
*value = '\0';
value++;
+ if (whitelist != NULL &&
+ match_pattern_list(cp, whitelist, 0) != 1)
+ continue;
child_set_env(env, envsize, cp, value);
}
free(line);
@@ -1121,7 +1126,12 @@ do_setup_env(struct ssh *ssh, Session *s, const char *shell)
cp = strchr(ocp, '=');
if (*cp == '=') {
*cp = '\0';
- child_set_env(&env, &envsize, ocp, cp + 1);
+ /* Apply PermitUserEnvironment whitelist */
+ if (options.permit_user_env_whitelist == NULL ||
+ match_pattern_list(ocp,
+ options.permit_user_env_whitelist, 0) == 1)
+ child_set_env(&env, &envsize,
+ ocp, cp + 1);
}
free(ocp);
}
@@ -1131,7 +1141,8 @@ do_setup_env(struct ssh *ssh, Session *s, const char *shell)
if (options.permit_user_env) {
snprintf(buf, sizeof buf, "%.200s/.ssh/environment",
pw->pw_dir);
- read_environment_file(&env, &envsize, buf);
+ read_environment_file(&env, &envsize, buf,
+ options.permit_user_env_whitelist);
}
#ifdef USE_PAM