View | Details | Raw Unified | Return to bug 1661
Collapse All | Expand All

(-)a/channels.c (-7 / +36 lines)
Lines 1314-1329 port_open_helper(Channel *c, char *rtype) Link Here
1314
{
1314
{
1315
	int direct;
1315
	int direct;
1316
	char buf[1024];
1316
	char buf[1024];
1317
	char *remote_ipaddr = get_peer_ipaddr(c->sock);
1317
	char *remote_ipaddr;
1318
	int remote_port = get_peer_port(c->sock);
1318
	int remote_port;
1319
1319
1320
	direct = (strcmp(rtype, "direct-tcpip") == 0);
1320
	direct = (strcmp(rtype, "direct-tcpip") == 0);
1321
1321
1322
	snprintf(buf, sizeof buf,
1322
	if (c->sock != -1) {
1323
	    "%s: listening port %d for %.100s port %d, "
1323
		remote_ipaddr = get_peer_ipaddr(c->sock);
1324
	    "connect from %.200s port %d",
1324
		remote_port = get_peer_port(c->sock);
1325
	    rtype, c->listening_port, c->path, c->host_port,
1325
		snprintf(buf, sizeof buf,
1326
	    remote_ipaddr, remote_port);
1326
		    "%s: listening port %d for %.100s port %d, "
1327
		    "connect from %.200s port %d",
1328
		    rtype, c->listening_port, c->path, c->host_port,
1329
		    remote_ipaddr, remote_port);
1330
1331
	} else {
1332
		remote_ipaddr = xstrdup("-");
1333
		remote_port = 0;
1334
		snprintf(buf, sizeof buf,
1335
		    "%s: to %.100s port %d, from stdio",
1336
		    rtype, c->path, c->host_port);
1337
	}
1327
1338
1328
	xfree(c->remote_name);
1339
	xfree(c->remote_name);
1329
	c->remote_name = xstrdup(buf);
1340
	c->remote_name = xstrdup(buf);
Lines 2712-2717 channel_request_remote_forwarding(const char *listen_host, u_short listen_port, Link Here
2712
}
2723
}
2713
2724
2714
/*
2725
/*
2726
 * Forward stdio to remote TCP port
2727
 */
2728
int
2729
channel_setup_netcat(const char *host, u_short port, int rfd, int wfd) {
2730
	char *rtype = "direct-tcpip";
2731
	Channel *c;
2732
    	c = channel_new(rtype, SSH_CHANNEL_OPENING, rfd, wfd, -1,
2733
			CHAN_TCP_WINDOW_DEFAULT, CHAN_TCP_PACKET_DEFAULT,
2734
			0, rtype, 0);
2735
	c->listening_port = 0;
2736
	c->host_port = port;
2737
	c->path = xstrdup(host);
2738
	c->force_drain = 1;
2739
	port_open_helper(c, rtype);
2740
	return c->self;
2741
}
2742
2743
/*
2715
 * Request cancellation of remote forwarding of connection host:port from
2744
 * Request cancellation of remote forwarding of connection host:port from
2716
 * local side.
2745
 * local side.
2717
 */
2746
 */
(-)a/channels.h (+1 lines)
Lines 246-251 int channel_setup_local_fwd_listener(const char *, u_short, Link Here
246
void	 channel_request_rforward_cancel(const char *host, u_short port);
246
void	 channel_request_rforward_cancel(const char *host, u_short port);
247
int	 channel_setup_remote_fwd_listener(const char *, u_short, int *, int);
247
int	 channel_setup_remote_fwd_listener(const char *, u_short, int *, int);
248
int	 channel_cancel_rport_listener(const char *, u_short);
248
int	 channel_cancel_rport_listener(const char *, u_short);
249
int      channel_setup_netcat(const char *, u_short, int, int);
249
250
250
/* x11 forwarding */
251
/* x11 forwarding */
251
252
(-)a/ssh.c (-1 / +48 lines)
Lines 165-170 pid_t proxy_command_pid = 0; Link Here
165
extern int muxserver_sock;
165
extern int muxserver_sock;
166
extern u_int muxclient_command;
166
extern u_int muxclient_command;
167
167
168
/* netcat */
169
static char *netcat_host;
170
static int netcat_port;
168
171
169
/* Prints a help message to the user.  This function never returns. */
172
/* Prints a help message to the user.  This function never returns. */
170
173
Lines 261-267 main(int ac, char **av) Link Here
261
	argv0 = av[0];
264
	argv0 = av[0];
262
265
263
 again:
266
 again:
264
	while ((opt = getopt(ac, av, "1246ab:c:e:fgi:kl:m:no:p:qstvx"
267
	while ((opt = getopt(ac, av, "1246ab:c:e:fgG:i:kl:m:no:p:qstvx"
265
	    "ACD:F:I:KL:MNO:PR:S:TVw:XYy")) != -1) {
268
	    "ACD:F:I:KL:MNO:PR:S:TVw:XYy")) != -1) {
266
		switch (opt) {
269
		switch (opt) {
267
		case '1':
270
		case '1':
Lines 299-304 main(int ac, char **av) Link Here
299
		case 'g':
302
		case 'g':
300
			options.gateway_ports = 1;
303
			options.gateway_ports = 1;
301
			break;
304
			break;
305
		case 'G':
306
			if (parse_forward(&fwd, optarg, 1, 0)) {
307
				no_shell_flag = 1;
308
				no_tty_flag = 1;
309
				
310
				netcat_port = fwd.listen_port;
311
				netcat_host = fwd.listen_host;
312
				if (!netcat_host)
313
					netcat_host = "localhost";
314
			}
315
			else {
316
				fprintf(stderr,
317
					"Bad remote address specification "
318
					"'%s'\n", optarg);
319
				exit(255);
320
			}
321
			break;
302
		case 'O':
322
		case 'O':
303
			if (strcmp(optarg, "check") == 0)
323
			if (strcmp(optarg, "check") == 0)
304
				muxclient_command = SSHMUX_COMMAND_ALIVE_CHECK;
324
				muxclient_command = SSHMUX_COMMAND_ALIVE_CHECK;
Lines 799-804 main(int ac, char **av) Link Here
799
		}
819
		}
800
	}
820
	}
801
821
822
	if (netcat_host && !compat20)
823
		fatal("netcat feature not available for SSH1 connections");
824
802
	exit_status = compat20 ? ssh_session2() : ssh_session();
825
	exit_status = compat20 ? ssh_session2() : ssh_session();
803
	packet_close();
826
	packet_close();
804
827
Lines 1168-1173 ssh_session2_open(void) Link Here
1168
}
1191
}
1169
1192
1170
static int
1193
static int
1194
ssh_netcat_open(void) {
1195
	int in, out, id;
1196
1197
	in = (stdin_null_flag ? open(_PATH_DEVNULL, O_RDONLY) : dup(STDIN_FILENO));
1198
	out = dup(STDOUT_FILENO);
1199
1200
	if (in < 0 || out < 0)
1201
		fatal("dup() in/out failed");
1202
1203
	if (!isatty(in))
1204
		set_nonblock(in);
1205
	if (!isatty(out))
1206
		set_nonblock(out);
1207
1208
	id = channel_setup_netcat(netcat_host, netcat_port, in, out);
1209
1210
	debug3("ssh_netcat_open: channel_new: %d", id);
1211
1212
	return id;
1213
}
1214
1215
static int
1171
ssh_session2(void)
1216
ssh_session2(void)
1172
{
1217
{
1173
	int id = -1;
1218
	int id = -1;
Lines 1177-1182 ssh_session2(void) Link Here
1177
1222
1178
	if (!no_shell_flag || (datafellows & SSH_BUG_DUMMYCHAN))
1223
	if (!no_shell_flag || (datafellows & SSH_BUG_DUMMYCHAN))
1179
		id = ssh_session2_open();
1224
		id = ssh_session2_open();
1225
	if (netcat_host)
1226
		id = ssh_netcat_open();
1180
1227
1181
	/* If we don't expect to open a new session, then disallow it */
1228
	/* If we don't expect to open a new session, then disallow it */
1182
	if (options.control_master == SSHCTL_MASTER_NO &&
1229
	if (options.control_master == SSHCTL_MASTER_NO &&

Return to bug 1661