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

(-)clientloop.c (-5 / +28 lines)
Lines 140-145 int session_ident = -1; Link Here
140
struct confirm_ctx {
140
struct confirm_ctx {
141
	int want_tty;
141
	int want_tty;
142
	int want_subsys;
142
	int want_subsys;
143
	int want_x_fwd;
144
	int want_agent_fwd;
143
	Buffer cmd;
145
	Buffer cmd;
144
	char *term;
146
	char *term;
145
	struct termios tio;
147
	struct termios tio;
Lines 631-636 static void Link Here
631
client_extra_session2_setup(int id, void *arg)
633
client_extra_session2_setup(int id, void *arg)
632
{
634
{
633
	struct confirm_ctx *cctx = arg;
635
	struct confirm_ctx *cctx = arg;
636
	const char *display;
634
	Channel *c;
637
	Channel *c;
635
	int i;
638
	int i;
636
639
Lines 639-644 client_extra_session2_setup(int id, void Link Here
639
	if ((c = channel_lookup(id)) == NULL)
642
	if ((c = channel_lookup(id)) == NULL)
640
		fatal("%s: no channel for id %d", __func__, id);
643
		fatal("%s: no channel for id %d", __func__, id);
641
644
645
	display = getenv("DISPLAY");	
646
	if (cctx->want_x_fwd && options.forward_x11 && display != NULL) {
647
		char *proto, *data;
648
		/* Get reasonable local authentication information. */
649
		client_x11_get_proto(display, options.xauth_location,
650
		    options.forward_x11_trusted, &proto, &data);
651
		/* Request forwarding with authentication spoofing. */
652
		debug("Requesting X11 forwarding with authentication spoofing.");
653
		x11_request_forwarding_with_spoofing(id, display, proto, data);
654
		/* XXX wait for reply */
655
	}
656
657
	if (cctx->want_agent_fwd && options.forward_agent) {
658
		debug("Requesting authentication agent forwarding.");
659
		channel_request_start(id, "auth-agent-req@openssh.com", 0);
660
		packet_send();
661
	}
662
642
	client_session2_setup(id, cctx->want_tty, cctx->want_subsys,
663
	client_session2_setup(id, cctx->want_tty, cctx->want_subsys,
643
	    cctx->term, &cctx->tio, c->rfd, &cctx->cmd, cctx->env,
664
	    cctx->term, &cctx->tio, c->rfd, &cctx->cmd, cctx->env,
644
	    client_subsystem_reply);
665
	    client_subsystem_reply);
Lines 704-710 client_process_control(fd_set * readset) Link Here
704
		buffer_free(&m);
725
		buffer_free(&m);
705
		return;
726
		return;
706
	}
727
	}
707
	if ((ver = buffer_get_char(&m)) != 1) {
728
	if ((ver = buffer_get_char(&m)) != SSHMUX_VER) {
708
		error("%s: wrong client version %d", __func__, ver);
729
		error("%s: wrong client version %d", __func__, ver);
709
		buffer_free(&m);
730
		buffer_free(&m);
710
		close(client_fd);
731
		close(client_fd);
Lines 738-744 client_process_control(fd_set * readset) Link Here
738
		buffer_clear(&m);
759
		buffer_clear(&m);
739
		buffer_put_int(&m, allowed);
760
		buffer_put_int(&m, allowed);
740
		buffer_put_int(&m, getpid());
761
		buffer_put_int(&m, getpid());
741
		if (ssh_msg_send(client_fd, /* version */1, &m) == -1) {
762
		if (ssh_msg_send(client_fd, SSHMUX_VER, &m) == -1) {
742
			error("%s: client msg_send failed", __func__);
763
			error("%s: client msg_send failed", __func__);
743
			close(client_fd);
764
			close(client_fd);
744
			buffer_free(&m);
765
			buffer_free(&m);
Lines 758-764 client_process_control(fd_set * readset) Link Here
758
	buffer_clear(&m);
779
	buffer_clear(&m);
759
	buffer_put_int(&m, allowed);
780
	buffer_put_int(&m, allowed);
760
	buffer_put_int(&m, getpid());
781
	buffer_put_int(&m, getpid());
761
	if (ssh_msg_send(client_fd, /* version */1, &m) == -1) {
782
	if (ssh_msg_send(client_fd, SSHMUX_VER, &m) == -1) {
762
		error("%s: client msg_send failed", __func__);
783
		error("%s: client msg_send failed", __func__);
763
		close(client_fd);
784
		close(client_fd);
764
		buffer_free(&m);
785
		buffer_free(&m);
Lines 779-785 client_process_control(fd_set * readset) Link Here
779
		buffer_free(&m);
800
		buffer_free(&m);
780
		return;
801
		return;
781
	}
802
	}
782
	if ((ver = buffer_get_char(&m)) != 1) {
803
	if ((ver = buffer_get_char(&m)) != SSHMUX_VER) {
783
		error("%s: wrong client version %d", __func__, ver);
804
		error("%s: wrong client version %d", __func__, ver);
784
		buffer_free(&m);
805
		buffer_free(&m);
785
		close(client_fd);
806
		close(client_fd);
Lines 790-795 client_process_control(fd_set * readset) Link Here
790
	memset(cctx, 0, sizeof(*cctx));
811
	memset(cctx, 0, sizeof(*cctx));
791
	cctx->want_tty = (flags & SSHMUX_FLAG_TTY) != 0;
812
	cctx->want_tty = (flags & SSHMUX_FLAG_TTY) != 0;
792
	cctx->want_subsys = (flags & SSHMUX_FLAG_SUBSYS) != 0;
813
	cctx->want_subsys = (flags & SSHMUX_FLAG_SUBSYS) != 0;
814
	cctx->want_x_fwd = (flags & SSHMUX_FLAG_X11_FWD) != 0;
815
	cctx->want_agent_fwd = (flags & SSHMUX_FLAG_AGENT_FWD) != 0;
793
	cctx->term = buffer_get_string(&m, &len);
816
	cctx->term = buffer_get_string(&m, &len);
794
817
795
	cmd = buffer_get_string(&m, &len);
818
	cmd = buffer_get_string(&m, &len);
Lines 823-829 client_process_control(fd_set * readset) Link Here
823
846
824
	/* This roundtrip is just for synchronisation of ttymodes */
847
	/* This roundtrip is just for synchronisation of ttymodes */
825
	buffer_clear(&m);
848
	buffer_clear(&m);
826
	if (ssh_msg_send(client_fd, /* version */1, &m) == -1) {
849
	if (ssh_msg_send(client_fd, SSHMUX_VER, &m) == -1) {
827
		error("%s: client msg_send failed", __func__);
850
		error("%s: client msg_send failed", __func__);
828
		close(client_fd);
851
		close(client_fd);
829
		close(new_fd[0]);
852
		close(new_fd[0]);
(-)clientloop.h (+5 lines)
Lines 43-48 void client_global_request_reply_fwd(in Link Here
43
void	 client_session2_setup(int, int, int, const char *, struct termios *,
43
void	 client_session2_setup(int, int, int, const char *, struct termios *,
44
	    int, Buffer *, char **, dispatch_fn *);
44
	    int, Buffer *, char **, dispatch_fn *);
45
45
46
/* Multiplexing protocol version */
47
#define SSHMUX_VER			1
48
46
/* Multiplexing control protocol flags */
49
/* Multiplexing control protocol flags */
47
#define SSHMUX_COMMAND_OPEN		1	/* Open new connection */
50
#define SSHMUX_COMMAND_OPEN		1	/* Open new connection */
48
#define SSHMUX_COMMAND_ALIVE_CHECK	2	/* Check master is alive */
51
#define SSHMUX_COMMAND_ALIVE_CHECK	2	/* Check master is alive */
Lines 50-52 void client_session2_setup(int, int, in Link Here
50
53
51
#define SSHMUX_FLAG_TTY			(1)	/* Request tty on open */
54
#define SSHMUX_FLAG_TTY			(1)	/* Request tty on open */
52
#define SSHMUX_FLAG_SUBSYS		(1<<1)	/* Subsystem request on open */
55
#define SSHMUX_FLAG_SUBSYS		(1<<1)	/* Subsystem request on open */
56
#define SSHMUX_FLAG_X11_FWD		(1<<2)	/* Request X11 forwarding */
57
#define SSHMUX_FLAG_AGENT_FWD		(1<<3)	/* Request agent forwarding */
(-)ssh.c (-7 / +10 lines)
Lines 1251-1278 control_client(const char *path) Link Here
1251
 			close(fd);
1251
 			close(fd);
1252
 	}
1252
 	}
1253
  
1253
  
1254
	if ((term = getenv("TERM")) == NULL)
1254
	term = getenv("TERM");
1255
		term = "";
1256
1255
1257
	flags = 0;
1256
	flags = 0;
1258
	if (tty_flag)
1257
	if (tty_flag)
1259
		flags |= SSHMUX_FLAG_TTY;
1258
		flags |= SSHMUX_FLAG_TTY;
1260
	if (subsystem_flag)
1259
	if (subsystem_flag)
1261
		flags |= SSHMUX_FLAG_SUBSYS;
1260
		flags |= SSHMUX_FLAG_SUBSYS;
1261
	if (options.forward_x11)
1262
		flags |= SSHMUX_FLAG_X11_FWD;
1263
	if (options.forward_agent)
1264
		flags |= SSHMUX_FLAG_AGENT_FWD;
1262
1265
1263
	buffer_init(&m);
1266
	buffer_init(&m);
1264
1267
1265
	/* Send our command to server */
1268
	/* Send our command to server */
1266
	buffer_put_int(&m, mux_command);
1269
	buffer_put_int(&m, mux_command);
1267
	buffer_put_int(&m, flags);
1270
	buffer_put_int(&m, flags);
1268
	if (ssh_msg_send(sock, /* version */1, &m) == -1)
1271
	if (ssh_msg_send(sock, SSHMUX_VER, &m) == -1)
1269
		fatal("%s: msg_send", __func__);
1272
		fatal("%s: msg_send", __func__);
1270
	buffer_clear(&m);
1273
	buffer_clear(&m);
1271
1274
1272
	/* Get authorisation status and PID of controlee */
1275
	/* Get authorisation status and PID of controlee */
1273
	if (ssh_msg_recv(sock, &m) == -1)
1276
	if (ssh_msg_recv(sock, &m) == -1)
1274
		fatal("%s: msg_recv", __func__);
1277
		fatal("%s: msg_recv", __func__);
1275
	if (buffer_get_char(&m) != 1)
1278
	if (buffer_get_char(&m) != SSHMUX_VER)
1276
		fatal("%s: wrong version", __func__);
1279
		fatal("%s: wrong version", __func__);
1277
	if (buffer_get_int(&m) != 1)
1280
	if (buffer_get_int(&m) != 1)
1278
		fatal("Connection to master denied");
1281
		fatal("Connection to master denied");
Lines 1296-1302 control_client(const char *path) Link Here
1296
	}
1299
	}
1297
1300
1298
	/* SSHMUX_COMMAND_OPEN */
1301
	/* SSHMUX_COMMAND_OPEN */
1299
	buffer_put_cstring(&m, term);
1302
	buffer_put_cstring(&m, term ? term : "");
1300
	buffer_append(&command, "\0", 1);
1303
	buffer_append(&command, "\0", 1);
1301
	buffer_put_cstring(&m, buffer_ptr(&command));
1304
	buffer_put_cstring(&m, buffer_ptr(&command));
1302
1305
Lines 1318-1324 control_client(const char *path) Link Here
1318
			}
1321
			}
1319
	}
1322
	}
1320
1323
1321
	if (ssh_msg_send(sock, /* version */1, &m) == -1)
1324
	if (ssh_msg_send(sock, SSHMUX_VER, &m) == -1)
1322
		fatal("%s: msg_send", __func__);
1325
		fatal("%s: msg_send", __func__);
1323
1326
1324
	mm_send_fd(sock, STDIN_FILENO);
1327
	mm_send_fd(sock, STDIN_FILENO);
Lines 1329-1335 control_client(const char *path) Link Here
1329
	buffer_clear(&m);
1332
	buffer_clear(&m);
1330
	if (ssh_msg_recv(sock, &m) == -1)
1333
	if (ssh_msg_recv(sock, &m) == -1)
1331
		fatal("%s: msg_recv", __func__);
1334
		fatal("%s: msg_recv", __func__);
1332
	if (buffer_get_char(&m) != 1)
1335
	if (buffer_get_char(&m) != SSHMUX_VER)
1333
		fatal("%s: wrong version", __func__);
1336
		fatal("%s: wrong version", __func__);
1334
	buffer_free(&m);
1337
	buffer_free(&m);
1335
1338
(-)ssh_config.5 (+6 lines)
Lines 279-284 can not be opened, Link Here
279
.Nm ssh
279
.Nm ssh
280
will continue without connecting to a master instance.
280
will continue without connecting to a master instance.
281
.Pp
281
.Pp
282
X11 and
283
.Xr ssh-agent 4
284
forwarding is supported over these multiplexed connections, however the
285
display and agent fowarded will be the one belonging to the master
286
connection. I.e. it is not possible to forward multiple displays or agents.
287
.Pp
282
Two additional options allow for opportunistic multiplexing: try to use a
288
Two additional options allow for opportunistic multiplexing: try to use a
283
master connection but fall back to creating a new one if one does not already
289
master connection but fall back to creating a new one if one does not already
284
exist.
290
exist.

Return to bug 1016