summaryrefslogtreecommitdiff
path: root/session.c
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2018-06-09 03:03:10 +0000
committerDamien Miller <djm@mindrot.org>2018-06-09 13:11:00 +1000
commit28013759f09ed3ebf7e8335e83a62936bd7a7f47 (patch)
tree11704fdf59dbe3ebfe0151cbe82eb0847e12b420 /session.c
parent7082bb58a2eb878d23ec674587c742e5e9673c36 (diff)
upstream: add a SetEnv directive for sshd_config to allow an
administrator to explicitly specify environment variables set in sessions started by sshd. These override the default environment and any variables set by user configuration (PermitUserEnvironment, etc), but not the SSH_* variables set by sshd itself. ok markus@ OpenBSD-Commit-ID: b6a96c0001ccd7dd211df6cae9e961c20fd718c0
Diffstat (limited to 'session.c')
-rw-r--r--session.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/session.c b/session.c
index 7b15e32cc..85df6a272 100644
--- a/session.c
+++ b/session.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: session.c,v 1.299 2018/06/09 02:58:02 djm Exp $ */ 1/* $OpenBSD: session.c,v 1.300 2018/06/09 03:03:10 djm Exp $ */
2/* 2/*
3 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 3 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
4 * All rights reserved 4 * All rights reserved
@@ -1004,7 +1004,7 @@ do_setup_env(struct ssh *ssh, Session *s, const char *shell)
1004 char buf[256]; 1004 char buf[256];
1005 size_t n; 1005 size_t n;
1006 u_int i, envsize; 1006 u_int i, envsize;
1007 char *ocp, *cp, **env, *laddr; 1007 char *ocp, *cp, *value, **env, *laddr;
1008 struct passwd *pw = s->pw; 1008 struct passwd *pw = s->pw;
1009#if !defined (HAVE_LOGIN_CAP) && !defined (HAVE_CYGWIN) 1009#if !defined (HAVE_LOGIN_CAP) && !defined (HAVE_CYGWIN)
1010 char *path = NULL; 1010 char *path = NULL;
@@ -1156,6 +1156,17 @@ do_setup_env(struct ssh *ssh, Session *s, const char *shell)
1156 } 1156 }
1157#endif /* USE_PAM */ 1157#endif /* USE_PAM */
1158 1158
1159 /* Environment specified by admin */
1160 for (i = 0; i < options.num_setenv; i++) {
1161 cp = xstrdup(options.setenv[i]);
1162 if ((value = strchr(cp, '=')) == NULL) {
1163 /* shouldn't happen; vars are checked in servconf.c */
1164 fatal("Invalid config SetEnv: %s", options.setenv[i]);
1165 }
1166 *value++ = '\0';
1167 child_set_env(&env, &envsize, cp, value);
1168 }
1169
1159 /* SSH_CLIENT deprecated */ 1170 /* SSH_CLIENT deprecated */
1160 snprintf(buf, sizeof buf, "%.50s %d %d", 1171 snprintf(buf, sizeof buf, "%.50s %d %d",
1161 ssh_remote_ipaddr(ssh), ssh_remote_port(ssh), 1172 ssh_remote_ipaddr(ssh), ssh_remote_port(ssh),