View | Details | Raw Unified | Return to bug 815 | Differences between
and this patch

Collapse All | Expand All

(-)usr.bin/ssh/readconf.c (+16 lines)
Lines 106-111 Link Here
106
	oEnableSSHKeysign, oRekeyLimit, oVerifyHostKeyDNS, oConnectTimeout,
106
	oEnableSSHKeysign, oRekeyLimit, oVerifyHostKeyDNS, oConnectTimeout,
107
	oAddressFamily, oGssAuthentication, oGssDelegateCreds,
107
	oAddressFamily, oGssAuthentication, oGssDelegateCreds,
108
	oServerAliveInterval, oServerAliveCountMax, oIdentitiesOnly,
108
	oServerAliveInterval, oServerAliveCountMax, oIdentitiesOnly,
109
	oSendEnv,
109
	oDeprecated, oUnsupported
110
	oDeprecated, oUnsupported
110
} OpCodes;
111
} OpCodes;
111
112
Lines 193-198 Link Here
193
	{ "addressfamily", oAddressFamily },
194
	{ "addressfamily", oAddressFamily },
194
	{ "serveraliveinterval", oServerAliveInterval },
195
	{ "serveraliveinterval", oServerAliveInterval },
195
	{ "serveralivecountmax", oServerAliveCountMax },
196
	{ "serveralivecountmax", oServerAliveCountMax },
197
	{ "sendenv", oSendEnv },
196
	{ NULL, oBadOption }
198
	{ NULL, oBadOption }
197
};
199
};
198
200
Lines 747-752 Link Here
747
		intptr = &options->server_alive_count_max;
749
		intptr = &options->server_alive_count_max;
748
		goto parse_int;
750
		goto parse_int;
749
751
752
	case oSendEnv:
753
		while ((arg = strdelim(&s)) != NULL && *arg != '\0') {
754
			if (strchr(arg, '=') != NULL)
755
				fatal("%s line %d: Invalid environment name.",
756
				    filename, linenum);
757
			if (options->num_send_env >= MAX_SEND_ENV)
758
				fatal("%s line %d: too many send env.",
759
				    filename, linenum);
760
			options->send_env[options->num_send_env++] =
761
			    xstrdup(arg);
762
		}
763
		break;
764
750
	case oDeprecated:
765
	case oDeprecated:
751
		debug("%s line %d: Deprecated option \"%s\"",
766
		debug("%s line %d: Deprecated option \"%s\"",
752
		    filename, linenum, keyword);
767
		    filename, linenum, keyword);
Lines 892-897 Link Here
892
	options->verify_host_key_dns = -1;
907
	options->verify_host_key_dns = -1;
893
	options->server_alive_interval = -1;
908
	options->server_alive_interval = -1;
894
	options->server_alive_count_max = -1;
909
	options->server_alive_count_max = -1;
910
	options->num_send_env = 0;
895
}
911
}
896
912
897
/*
913
/*
(-)usr.bin/ssh/readconf.h (+5 lines)
Lines 27-32 Link Here
27
}       Forward;
27
}       Forward;
28
/* Data structure for representing option data. */
28
/* Data structure for representing option data. */
29
29
30
#define MAX_SEND_ENV	256
31
30
typedef struct {
32
typedef struct {
31
	int     forward_agent;	/* Forward authentication agent. */
33
	int     forward_agent;	/* Forward authentication agent. */
32
	int     forward_x11;	/* Forward X11 display. */
34
	int     forward_x11;	/* Forward X11 display. */
Lines 103-108 Link Here
103
	int	identities_only;
105
	int	identities_only;
104
	int	server_alive_interval; 
106
	int	server_alive_interval; 
105
	int	server_alive_count_max;
107
	int	server_alive_count_max;
108
109
	int     num_send_env;
110
	char   *send_env[MAX_SEND_ENV];
106
}       Options;
111
}       Options;
107
112
108
113
(-)usr.bin/ssh/servconf.c (-1 / +16 lines)
Lines 96-101 Link Here
96
	options->client_alive_count_max = -1;
96
	options->client_alive_count_max = -1;
97
	options->authorized_keys_file = NULL;
97
	options->authorized_keys_file = NULL;
98
	options->authorized_keys_file2 = NULL;
98
	options->authorized_keys_file2 = NULL;
99
	options->num_accept_env = 0;
99
100
100
	/* Needs to be accessable in many places */
101
	/* Needs to be accessable in many places */
101
	use_privsep = -1;
102
	use_privsep = -1;
Lines 243-249 Link Here
243
	sBanner, sUseDNS, sHostbasedAuthentication,
244
	sBanner, sUseDNS, sHostbasedAuthentication,
244
	sHostbasedUsesNameFromPacketOnly, sClientAliveInterval,
245
	sHostbasedUsesNameFromPacketOnly, sClientAliveInterval,
245
	sClientAliveCountMax, sAuthorizedKeysFile, sAuthorizedKeysFile2,
246
	sClientAliveCountMax, sAuthorizedKeysFile, sAuthorizedKeysFile2,
246
	sGssAuthentication, sGssCleanupCreds,
247
	sGssAuthentication, sGssCleanupCreds, sAcceptEnv,
247
	sUsePrivilegeSeparation,
248
	sUsePrivilegeSeparation,
248
	sDeprecated, sUnsupported
249
	sDeprecated, sUnsupported
249
} ServerOpCodes;
250
} ServerOpCodes;
Lines 331-336 Link Here
331
	{ "authorizedkeysfile", sAuthorizedKeysFile },
332
	{ "authorizedkeysfile", sAuthorizedKeysFile },
332
	{ "authorizedkeysfile2", sAuthorizedKeysFile2 },
333
	{ "authorizedkeysfile2", sAuthorizedKeysFile2 },
333
	{ "useprivilegeseparation", sUsePrivilegeSeparation},
334
	{ "useprivilegeseparation", sUsePrivilegeSeparation},
335
	{ "acceptenv", sAcceptEnv },
334
	{ NULL, sBadOption }
336
	{ NULL, sBadOption }
335
};
337
};
336
338
Lines 850-855 Link Here
850
	case sClientAliveCountMax:
852
	case sClientAliveCountMax:
851
		intptr = &options->client_alive_count_max;
853
		intptr = &options->client_alive_count_max;
852
		goto parse_int;
854
		goto parse_int;
855
856
	case sAcceptEnv:
857
		while ((arg = strdelim(&cp)) && *arg != '\0') {
858
			if (strchr(arg, '=') != NULL)
859
				fatal("%s line %d: Invalid environment name.",
860
				    filename, linenum);
861
			if (options->num_accept_env >= MAX_ACCEPT_ENV)
862
				fatal("%s line %d: too many allow env.",
863
				    filename, linenum);
864
			options->accept_env[options->num_accept_env++] =
865
			    xstrdup(arg);
866
		}
867
		break;
853
868
854
	case sDeprecated:
869
	case sDeprecated:
855
		logit("%s line %d: Deprecated option %s",
870
		logit("%s line %d: Deprecated option %s",
(-)usr.bin/ssh/servconf.h (+4 lines)
Lines 24-29 Link Here
24
#define MAX_DENY_GROUPS		256	/* Max # groups on deny list. */
24
#define MAX_DENY_GROUPS		256	/* Max # groups on deny list. */
25
#define MAX_SUBSYSTEMS		256	/* Max # subsystems. */
25
#define MAX_SUBSYSTEMS		256	/* Max # subsystems. */
26
#define MAX_HOSTKEYS		256	/* Max # hostkeys. */
26
#define MAX_HOSTKEYS		256	/* Max # hostkeys. */
27
#define MAX_ACCEPT_ENV		256	/* Max # of env vars. */
27
28
28
/* permit_root_login */
29
/* permit_root_login */
29
#define	PERMIT_NOT_SET		-1
30
#define	PERMIT_NOT_SET		-1
Lines 106-111 Link Here
106
	u_int num_subsystems;
107
	u_int num_subsystems;
107
	char   *subsystem_name[MAX_SUBSYSTEMS];
108
	char   *subsystem_name[MAX_SUBSYSTEMS];
108
	char   *subsystem_command[MAX_SUBSYSTEMS];
109
	char   *subsystem_command[MAX_SUBSYSTEMS];
110
111
	u_int num_accept_env;
112
	char   *accept_env[MAX_ACCEPT_ENV];
109
113
110
	int	max_startups_begin;
114
	int	max_startups_begin;
111
	int	max_startups_rate;
115
	int	max_startups_rate;
(-)usr.bin/ssh/session.c (+50 lines)
Lines 42-47 Link Here
42
#include "sshpty.h"
42
#include "sshpty.h"
43
#include "packet.h"
43
#include "packet.h"
44
#include "buffer.h"
44
#include "buffer.h"
45
#include "match.h"
45
#include "mpaux.h"
46
#include "mpaux.h"
46
#include "uidswap.h"
47
#include "uidswap.h"
47
#include "compat.h"
48
#include "compat.h"
Lines 793-798 Link Here
793
794
794
	if (!options.use_login) {
795
	if (!options.use_login) {
795
		/* Set basic environment. */
796
		/* Set basic environment. */
797
		for (i = 0; i < s->num_env; i++)
798
			child_set_env(&env, &envsize, s->env[i].name, 
799
			    s->env[i].val);
800
796
		child_set_env(&env, &envsize, "USER", pw->pw_name);
801
		child_set_env(&env, &envsize, "USER", pw->pw_name);
797
		child_set_env(&env, &envsize, "LOGNAME", pw->pw_name);
802
		child_set_env(&env, &envsize, "LOGNAME", pw->pw_name);
798
		child_set_env(&env, &envsize, "HOME", pw->pw_dir);
803
		child_set_env(&env, &envsize, "HOME", pw->pw_dir);
Lines 1514-1519 Link Here
1514
}
1519
}
1515
1520
1516
static int
1521
static int
1522
session_env_req(Session *s)
1523
{
1524
	char *name, *val;
1525
	u_int name_len, val_len, i;
1526
1527
	name = packet_get_string(&name_len);
1528
	val = packet_get_string(&val_len);
1529
	packet_check_eom();
1530
1531
	/* Don't set too many environment variables */
1532
	if (s->num_env > 128) {
1533
		debug2("Ignoring env request %s: too many env vars", name);
1534
		goto fail;
1535
	}
1536
1537
	for (i = 0; i < options.num_accept_env; i++) {
1538
		if (match_pattern(name, options.accept_env[i])) {
1539
			debug2("Setting env %d: %s=%s", s->num_env, name, val);
1540
			s->env = xrealloc(s->env, sizeof(*s->env) *
1541
			    (s->num_env + 1));
1542
			s->env[s->num_env].name = name;
1543
			s->env[s->num_env].val = val;
1544
			s->num_env++;
1545
			return (1);
1546
		}
1547
	}
1548
	debug2("Ignoring env request %s: disallowed name", name);
1549
1550
 fail:
1551
	xfree(name);
1552
	xfree(val);
1553
	return (0);
1554
}
1555
1556
static int
1517
session_auth_agent_req(Session *s)
1557
session_auth_agent_req(Session *s)
1518
{
1558
{
1519
	static int called = 0;
1559
	static int called = 0;
Lines 1562-1567 Link Here
1562
			success = session_subsystem_req(s);
1602
			success = session_subsystem_req(s);
1563
		} else if (strcmp(rtype, "break") == 0) {
1603
		} else if (strcmp(rtype, "break") == 0) {
1564
			success = session_break_req(s);
1604
			success = session_break_req(s);
1605
		} else if (strcmp(rtype, "env") == 0) {
1606
			success = session_env_req(s);
1565
		}
1607
		}
1566
	}
1608
	}
1567
	if (strcmp(rtype, "window-change") == 0) {
1609
	if (strcmp(rtype, "window-change") == 0) {
Lines 1695-1700 Link Here
1695
void
1737
void
1696
session_close(Session *s)
1738
session_close(Session *s)
1697
{
1739
{
1740
	int i;
1741
1698
	debug("session_close: session %d pid %ld", s->self, (long)s->pid);
1742
	debug("session_close: session %d pid %ld", s->self, (long)s->pid);
1699
	if (s->ttyfd != -1)
1743
	if (s->ttyfd != -1)
1700
		session_pty_cleanup(s);
1744
		session_pty_cleanup(s);
Lines 1709-1714 Link Here
1709
	if (s->auth_proto)
1753
	if (s->auth_proto)
1710
		xfree(s->auth_proto);
1754
		xfree(s->auth_proto);
1711
	s->used = 0;
1755
	s->used = 0;
1756
	for (i = 0; i < s->num_env; i++) {
1757
		xfree(s->env[i].name);
1758
		xfree(s->env[i].val);
1759
	}
1760
	if (s->env != NULL)
1761
		xfree(s->env);
1712
	session_proctitle(s);
1762
	session_proctitle(s);
1713
}
1763
}
1714
1764
(-)usr.bin/ssh/session.h (+5 lines)
Lines 53-58 Link Here
53
	/* proto 2 */
53
	/* proto 2 */
54
	int	chanid;
54
	int	chanid;
55
	int	is_subsystem;
55
	int	is_subsystem;
56
	int	num_env;
57
	struct {
58
		char	*name;
59
		char	*val;
60
	}	*env;
56
};
61
};
57
62
58
void	 do_authenticated(Authctxt *);
63
void	 do_authenticated(Authctxt *);
(-)usr.bin/ssh/ssh.c (+39 lines)
Lines 68-73 Link Here
68
#include "kex.h"
68
#include "kex.h"
69
#include "mac.h"
69
#include "mac.h"
70
#include "sshtty.h"
70
#include "sshtty.h"
71
#include "match.h"
71
72
72
#ifdef SMARTCARD
73
#ifdef SMARTCARD
73
#include "scard.h"
74
#include "scard.h"
Lines 1040-1045 Link Here
1040
		debug("Requesting authentication agent forwarding.");
1041
		debug("Requesting authentication agent forwarding.");
1041
		channel_request_start(id, "auth-agent-req@openssh.com", 0);
1042
		channel_request_start(id, "auth-agent-req@openssh.com", 0);
1042
		packet_send();
1043
		packet_send();
1044
	}
1045
1046
	/* Transfer any environment variables from client to server */
1047
	if (options.num_send_env != 0) {
1048
		int i, j, matched;
1049
		extern char **environ;
1050
		char *name, *val;
1051
1052
		debug("Sending environment.");
1053
		for (i = 0; environ && environ[i] != NULL; i++) {
1054
			/* Split */
1055
			name = xstrdup(environ[i]);
1056
			if ((val = strchr(name, '=')) == NULL) {
1057
				free(name);
1058
				continue;
1059
			}
1060
			*val++ = '\0';
1061
1062
			matched = 0;
1063
			for (j = 0; j < options.num_send_env; j++) {
1064
				if (match_pattern(name, options.send_env[j])) {
1065
					matched = 1;
1066
					break;
1067
				}
1068
			}
1069
			if (!matched) {
1070
				debug3("Ignored env %s", name);
1071
				free(name);
1072
				continue;
1073
			}
1074
1075
			debug("Sending env %s = %s", name, val);
1076
			channel_request_start(id, "env", 0);
1077
			packet_put_cstring(name);
1078
			packet_put_cstring(val);
1079
			packet_send();
1080
			free(name);
1081
		}
1043
	}
1082
	}
1044
1083
1045
	len = buffer_len(&command);
1084
	len = buffer_len(&command);
(-)usr.bin/ssh/ssh_config.5 (+21 lines)
Lines 570-575 Link Here
570
The default is
570
The default is
571
.Dq yes .
571
.Dq yes .
572
Note that this option applies to protocol version 1 only.
572
Note that this option applies to protocol version 1 only.
573
.It Cm SendEnv
574
Specifies what variables from the local
575
.Xr environ 7
576
should be sent to the server.
577
Note that environment passing is only supported for protocol 2, the 
578
server must also support it and must be configured to accept these 
579
enviornment variables.
580
Refer to
581
.Cm AcceptEnv
582
in
583
.Xr sshd_config 5
584
for how to configure the server.
585
Variables are specified by name, which may contain the wildcard characters
586
.Ql \&*
587
and
588
.Ql \&? .
589
Multiple environment variables may be seperated by whitespace or spread
590
across multiple
591
.Cm SendEnv
592
directives.
593
The default is not to send any environment variables.
573
.It Cm ServerAliveInterval
594
.It Cm ServerAliveInterval
574
Sets a timeout interval in seconds after which if no data has been received
595
Sets a timeout interval in seconds after which if no data has been received
575
from the server,
596
from the server,
(-)usr.bin/ssh/sshd_config.5 (+23 lines)
Lines 61-66 Link Here
61
keywords and their meanings are as follows (note that
61
keywords and their meanings are as follows (note that
62
keywords are case-insensitive and arguments are case-sensitive):
62
keywords are case-insensitive and arguments are case-sensitive):
63
.Bl -tag -width Ds
63
.Bl -tag -width Ds
64
.It Cm AcceptEnv
65
Specifies what environment variables sent by the client will be copied into
66
the session's
67
.Xr environ 7 .
68
See
69
.Cm SendEnv
70
in
71
.Xr ssh_config 5
72
for how to configure the client.
73
Note that environment passingis only supported for protocol 2.
74
Variables are specified by name, which may contain the wildcard characters
75
.Ql \&*
76
and
77
.Ql \&? .
78
Multiple environment variables may be seperated by whitespace or spread
79
across multiple
80
.Cm AcceptEnv
81
directives.
82
Be warned that some enviornment variables could be used to bypass restricted
83
user environments.
84
For this reason, care should be taken in the use of this directive.
85
The default is not to accept any environment variables.
86
.Pp
64
.It Cm AllowGroups
87
.It Cm AllowGroups
65
This keyword can be followed by a list of group name patterns, separated
88
This keyword can be followed by a list of group name patterns, separated
66
by spaces.
89
by spaces.
(-)regress/usr.bin/ssh/Makefile (+1 lines)
Lines 10-15 Link Here
10
		proto-version \
10
		proto-version \
11
		proto-mismatch \
11
		proto-mismatch \
12
		exit-status \
12
		exit-status \
13
		envpass \
13
		transfer \
14
		transfer \
14
		banner \
15
		banner \
15
		rekey \
16
		rekey \
(-)regress/usr.bin/ssh/envpass.sh (+44 lines)
Added Link Here
1
#	$OpenBSD$
2
#	Placed in the Public Domain.
3
4
tid="environment passing"
5
6
# NB accepted env vars are in test-exec.sh (_XXX_TEST_* and _XXX_TEST)
7
8
trace "pass env, don't accept"
9
verbose "test $tid: pass env, don't accept"
10
_TEST_ENV=blah ${SSH} -oSendEnv="*" -F $OBJ/ssh_proxy otherhost \
11
	'[ -z "$_TEST_ENV" ]'
12
r=$?
13
if [ $r -ne 0 ]; then
14
	fail "environment found"
15
fi
16
17
trace "don't pass env, accept"
18
verbose "test $tid: don't pass env, accept"
19
${SSH} -F $OBJ/ssh_proxy otherhost \
20
	'[ -z "$_XXX_TEST_A" -a -z "$_XXX_TEST_B" ]'
21
r=$?
22
if [ $r -ne 0 ]; then
23
	fail "environment found"
24
fi
25
26
trace "pass single env, accept single env"
27
verbose "test $tid: pass single env, accept single env"
28
_XXX_TEST=blah ${SSH} -oSendEnv="_XXX_TEST" -F $OBJ/ssh_proxy otherhost \
29
	'[ "x$_XXX_TEST" = "xblah" ]'
30
r=$?
31
if [ $r -ne 0 ]; then
32
	fail "environment not found"
33
fi
34
35
trace "pass multiple env, accept multiple env"
36
verbose "test $tid: pass multiple env, accept multiple env"
37
_XXX_TEST_A=1 _XXX_TEST_B=2 ${SSH} -oSendEnv="_XXX_TEST_*" \
38
    -F $OBJ/ssh_proxy otherhost \
39
	'[ "x$_XXX_TEST_A" = "x1" -a "x$_XXX_TEST_B" = "x2" ]'
40
r=$?
41
if [ $r -ne 0 ]; then
42
	fail "environment not found"
43
fi
44
(-)regress/usr.bin/ssh/test-exec.sh (+2 lines)
Lines 130-135 Link Here
130
	PidFile			$PIDFILE
130
	PidFile			$PIDFILE
131
	AuthorizedKeysFile	$OBJ/authorized_keys_%u
131
	AuthorizedKeysFile	$OBJ/authorized_keys_%u
132
	LogLevel		QUIET
132
	LogLevel		QUIET
133
	AcceptEnv		_XXX_TEST_*
134
	AcceptEnv		_XXX_TEST
133
EOF
135
EOF
134
136
135
# server config for proxy connects
137
# server config for proxy connects

Return to bug 815