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

Collapse All | Expand All

(-)channels.c (-1 lines)
Lines 1914-1920 Link Here
1914
		if (buffer_len(&c->input) == 0)
1914
		if (buffer_len(&c->input) == 0)
1915
			chan_ibuf_empty(c);
1915
			chan_ibuf_empty(c);
1916
	}
1916
	}
1917
1918
}
1917
}
1919
1918
1920
void
1919
void
(-)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 877-882 Link Here
877
	options->verify_host_key_dns = -1;
892
	options->verify_host_key_dns = -1;
878
	options->server_alive_interval = -1;
893
	options->server_alive_interval = -1;
879
	options->server_alive_count_max = -1;
894
	options->server_alive_count_max = -1;
895
	options->num_send_env = 0;
880
}
896
}
881
897
882
/*
898
/*
(-)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
(-)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_allow_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, sAllowEnv,
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
	{ "allowenv", sAllowEnv },
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 sAllowEnv:
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_allow_env >= MAX_ALLOW_ENV)
862
				fatal("%s line %d: too many allow env.",
863
				    filename, linenum);
864
			options->allow_env[options->num_allow_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",
(-)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_ALLOW_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_allow_env;
112
	char   *allow_env[MAX_ALLOW_ENV];
109
113
110
	int	max_startups_begin;
114
	int	max_startups_begin;
111
	int	max_startups_rate;
115
	int	max_startups_rate;
(-)session.c (+49 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 784-789 Link Here
784
	env = xmalloc(envsize * sizeof(char *));
785
	env = xmalloc(envsize * sizeof(char *));
785
	env[0] = NULL;
786
	env[0] = NULL;
786
787
788
	for (i = 0; i < s->num_env; i++)
789
		child_set_env(&env, &envsize, s->env[i].name, s->env[i].val);
790
787
#ifdef GSSAPI
791
#ifdef GSSAPI
788
	/* Allow any GSSAPI methods that we've used to alter
792
	/* Allow any GSSAPI methods that we've used to alter
789
	 * the childs environment as they see fit
793
	 * the childs environment as they see fit
Lines 1514-1519 Link Here
1514
}
1518
}
1515
1519
1516
static int
1520
static int
1521
session_env_req(Session *s)
1522
{
1523
	char *name, *val;
1524
	u_int name_len, val_len, i;
1525
1526
	name = packet_get_string(&name_len);
1527
	val = packet_get_string(&val_len);
1528
	packet_check_eom();
1529
1530
	/* Don't set too many environment variables */
1531
	if (s->num_env > 128) {
1532
		debug2("Ignoring env request %s: too many env vars", name);
1533
		goto fail;
1534
	}
1535
1536
	for (i = 0; i < options.num_allow_env; i++) {
1537
		if (match_pattern(name, options.allow_env[i])) {
1538
			debug2("Setting env %d: %s=%s", s->num_env, name, val);
1539
			s->env = xrealloc(s->env, sizeof(*s->env) *
1540
			    (s->num_env + 1));
1541
			s->env[s->num_env].name = name;
1542
			s->env[s->num_env].val = val;
1543
			s->num_env++;
1544
			return (1);
1545
		}
1546
	}
1547
	debug2("Ignoring env request %s: disallowed name", name);
1548
1549
 fail:
1550
	xfree(name);
1551
	xfree(val);
1552
	return (0);
1553
}
1554
1555
static int
1517
session_auth_agent_req(Session *s)
1556
session_auth_agent_req(Session *s)
1518
{
1557
{
1519
	static int called = 0;
1558
	static int called = 0;
Lines 1562-1567 Link Here
1562
			success = session_subsystem_req(s);
1601
			success = session_subsystem_req(s);
1563
		} else if (strcmp(rtype, "break") == 0) {
1602
		} else if (strcmp(rtype, "break") == 0) {
1564
			success = session_break_req(s);
1603
			success = session_break_req(s);
1604
		} else if (strcmp(rtype, "env") == 0) {
1605
			success = session_env_req(s);
1565
		}
1606
		}
1566
	}
1607
	}
1567
	if (strcmp(rtype, "window-change") == 0) {
1608
	if (strcmp(rtype, "window-change") == 0) {
Lines 1695-1700 Link Here
1695
void
1736
void
1696
session_close(Session *s)
1737
session_close(Session *s)
1697
{
1738
{
1739
	int i;
1740
1698
	debug("session_close: session %d pid %ld", s->self, (long)s->pid);
1741
	debug("session_close: session %d pid %ld", s->self, (long)s->pid);
1699
	if (s->ttyfd != -1)
1742
	if (s->ttyfd != -1)
1700
		session_pty_cleanup(s);
1743
		session_pty_cleanup(s);
Lines 1709-1714 Link Here
1709
	if (s->auth_proto)
1752
	if (s->auth_proto)
1710
		xfree(s->auth_proto);
1753
		xfree(s->auth_proto);
1711
	s->used = 0;
1754
	s->used = 0;
1755
	for (i = 0; i < s->num_env; i++) {
1756
		xfree(s->env[i].name);
1757
		xfree(s->env[i].val);
1758
	}
1759
	if (s->env != NULL)
1760
		xfree(s->env);
1712
	session_proctitle(s);
1761
	session_proctitle(s);
1713
}
1762
}
1714
1763
(-)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 *);
(-)sftp-client.c (-1 / +1 lines)
Lines 643-649 Link Here
643
643
644
	buffer_init(&msg);
644
	buffer_init(&msg);
645
645
646
	/* Send rename request */
646
	/* Send symlink request */
647
	id = conn->msg_id++;
647
	id = conn->msg_id++;
648
	buffer_put_char(&msg, SSH2_FXP_SYMLINK);
648
	buffer_put_char(&msg, SSH2_FXP_SYMLINK);
649
	buffer_put_int(&msg, id);
649
	buffer_put_int(&msg, id);
(-)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 1039-1044 Link Here
1039
		debug("Requesting authentication agent forwarding.");
1040
		debug("Requesting authentication agent forwarding.");
1040
		channel_request_start(id, "auth-agent-req@openssh.com", 0);
1041
		channel_request_start(id, "auth-agent-req@openssh.com", 0);
1041
		packet_send();
1042
		packet_send();
1043
	}
1044
1045
	/* Transfer any environment variables from client to server */
1046
	if (options.num_send_env != 0) {
1047
		int i, j, matched;
1048
		extern char **environ;
1049
		char *name, *val;
1050
1051
		debug("Sending environment.");
1052
		for (i = 0; environ && environ[i] != NULL; i++) {
1053
			/* Split */
1054
			name = xstrdup(environ[i]);
1055
			if ((val = strchr(name, '=')) == NULL) {
1056
				free(name);
1057
				continue;
1058
			}
1059
			*val++ = '\0';
1060
1061
			matched = 0;
1062
			for (j = 0; j < options.num_send_env; j++) {
1063
				if (match_pattern(name, options.send_env[j])) {
1064
					matched = 1;
1065
					break;
1066
				}
1067
			}
1068
			if (!matched) {
1069
				debug3("Ignored env %s", name);
1070
				free(name);
1071
				continue;
1072
			}
1073
1074
			debug("Sending env %s = %s", name, val);
1075
			channel_request_start(id, "env", 0);
1076
			packet_put_cstring(name);
1077
			packet_put_cstring(val);
1078
			packet_send();
1079
			free(name);
1080
		}
1042
	}
1081
	}
1043
1082
1044
	len = buffer_len(&command);
1083
	len = buffer_len(&command);

Return to bug 815