changelog shortlog tags branches files raw gz bz2 help

Mercurial > hg > plan9front / changeset: merge

changeset 7114: 5502ebdaef11
parent 7112: 15f5de9bb073
parent 7113: f3850ed4100b
child 7115: ff3d2ba9517a
author: cinap_lenrek@felloff.net
date: Tue, 02 Apr 2019 09:05:01 +0200
files:
description: merge
     1.1--- a/sys/man/1/ssh
     1.2+++ b/sys/man/1/ssh
     1.3@@ -23,6 +23,9 @@ ssh - secure shell remote login client
     1.4 ] [
     1.5 .IR user @] host
     1.6 [
     1.7+.B -W
     1.8+.I remote!port
     1.9+] [
    1.10 .I cmd
    1.11 .I args
    1.12 .I ...
    1.13@@ -83,6 +86,13 @@ with the
    1.14 .B -r
    1.15 option.
    1.16 .PP
    1.17+With the
    1.18+.B -W
    1.19+option, instead of executing a command remotely, makes
    1.20+the server dial a tcp connection to
    1.21+.I remote!port
    1.22+which the client relays on standard input and output.
    1.23+.PP
    1.24 The
    1.25 .B -d
    1.26 option enables debug output.
     2.1--- a/sys/src/cmd/ssh.c
     2.2+++ b/sys/src/cmd/ssh.c
     2.3@@ -80,8 +80,8 @@ int nsid;
     2.4 uchar sid[256];
     2.5 char thumb[2*SHA2_256dlen+1], *thumbfile;
     2.6 
     2.7-int fd, intr, raw, debug;
     2.8-char *user, *service, *status, *host, *cmd;
     2.9+int fd, intr, raw, port, debug;
    2.10+char *user, *service, *status, *host, *remote, *cmd;
    2.11 
    2.12 Oneway recv, send;
    2.13 void dispatch(void);
    2.14@@ -1147,7 +1147,7 @@ kfmt(Fmt *f)
    2.15 void
    2.16 usage(void)
    2.17 {
    2.18-	fprint(2, "usage: %s [-dR] [-t thumbfile] [-T tries] [-u user] [-h] [user@]host [cmd args...]\n", argv0);
    2.19+	fprint(2, "usage: %s [-dR] [-t thumbfile] [-T tries] [-u user] [-h] [user@]host [-W remote!port] [cmd args...]\n", argv0);
    2.20 	exits("usage");
    2.21 }
    2.22 
    2.23@@ -1173,6 +1173,17 @@ main(int argc, char *argv[])
    2.24 	case 'd':
    2.25 		debug++;
    2.26 		break;
    2.27+	case 'W':
    2.28+		remote = EARGF(usage());
    2.29+		s = strrchr(remote, '!');
    2.30+		if(s == nil)
    2.31+			s = strrchr(remote, ':');
    2.32+		if(s == nil)
    2.33+			usage();
    2.34+		*s++ = 0;
    2.35+		port = atoi(s);
    2.36+		raw = 0;
    2.37+		break;
    2.38 	case 'R':
    2.39 		raw = 0;
    2.40 		break;
    2.41@@ -1221,6 +1232,9 @@ main(int argc, char *argv[])
    2.42 		}
    2.43 	}
    2.44 
    2.45+	if(remote != nil && cmd != nil)
    2.46+		usage();
    2.47+
    2.48 	if((fd = dial(netmkaddr(host, nil, "ssh"), nil, nil, nil)) < 0)
    2.49 		sysfatal("dial: %r");
    2.50 
    2.51@@ -1260,11 +1274,27 @@ Next0:	switch(recvpkt()){
    2.52 	recv.chan = 0;
    2.53 
    2.54 	/* open hailing frequencies */
    2.55-	sendpkt("bsuuu", MSG_CHANNEL_OPEN,
    2.56-		"session", 7,
    2.57-		recv.chan,
    2.58-		recv.win,
    2.59-		recv.pkt);
    2.60+	if(remote != nil){
    2.61+		NetConnInfo *nci = getnetconninfo(nil, fd);
    2.62+		if(nci == nil)
    2.63+			sysfatal("can't get netconninfo: %r");
    2.64+		sendpkt("bsuuususu", MSG_CHANNEL_OPEN,
    2.65+			"direct-tcpip", 12,
    2.66+			recv.chan,
    2.67+			recv.win,
    2.68+			recv.pkt,
    2.69+			remote, strlen(remote),
    2.70+			port,
    2.71+			nci->laddr, strlen(nci->laddr),
    2.72+			atoi(nci->lserv));
    2.73+		free(nci);
    2.74+	} else {
    2.75+		sendpkt("bsuuu", MSG_CHANNEL_OPEN,
    2.76+			"session", 7,
    2.77+			recv.chan,
    2.78+			recv.win,
    2.79+			recv.pkt);
    2.80+	}
    2.81 
    2.82 Next1:	switch(recvpkt()){
    2.83 	default:
    2.84@@ -1307,36 +1337,38 @@ Next1:	switch(recvpkt()){
    2.85 
    2.86 	/* child reads input and sends packets */
    2.87 	qlock(&sl);
    2.88-	if(raw) {
    2.89-		rawon();
    2.90-		sendpkt("busbsuuuus", MSG_CHANNEL_REQUEST,
    2.91-			send.chan,
    2.92-			"pty-req", 7,
    2.93-			0,
    2.94-			tty.term, strlen(tty.term),
    2.95-			tty.cols,
    2.96-			tty.lines,
    2.97-			tty.xpixels,
    2.98-			tty.ypixels,
    2.99-			"", 0);
   2.100-	}
   2.101-	if(cmd == nil){
   2.102-		sendpkt("busb", MSG_CHANNEL_REQUEST,
   2.103-			send.chan,
   2.104-			"shell", 5,
   2.105-			0);
   2.106-	} else if(*cmd == '#') {
   2.107-		sendpkt("busbs", MSG_CHANNEL_REQUEST,
   2.108-			send.chan,
   2.109-			"subsystem", 9,
   2.110-			0,
   2.111-			cmd+1, strlen(cmd)-1);
   2.112-	} else {
   2.113-		sendpkt("busbs", MSG_CHANNEL_REQUEST,
   2.114-			send.chan,
   2.115-			"exec", 4,
   2.116-			0,
   2.117-			cmd, strlen(cmd));
   2.118+	if(remote == nil){
   2.119+		if(raw) {
   2.120+			rawon();
   2.121+			sendpkt("busbsuuuus", MSG_CHANNEL_REQUEST,
   2.122+				send.chan,
   2.123+				"pty-req", 7,
   2.124+				0,
   2.125+				tty.term, strlen(tty.term),
   2.126+				tty.cols,
   2.127+				tty.lines,
   2.128+				tty.xpixels,
   2.129+				tty.ypixels,
   2.130+				"", 0);
   2.131+		}
   2.132+		if(cmd == nil){
   2.133+			sendpkt("busb", MSG_CHANNEL_REQUEST,
   2.134+				send.chan,
   2.135+				"shell", 5,
   2.136+				0);
   2.137+		} else if(*cmd == '#') {
   2.138+			sendpkt("busbs", MSG_CHANNEL_REQUEST,
   2.139+				send.chan,
   2.140+				"subsystem", 9,
   2.141+				0,
   2.142+				cmd+1, strlen(cmd)-1);
   2.143+		} else {
   2.144+			sendpkt("busbs", MSG_CHANNEL_REQUEST,
   2.145+				send.chan,
   2.146+				"exec", 4,
   2.147+				0,
   2.148+				cmd, strlen(cmd));
   2.149+		}
   2.150 	}
   2.151 	for(;;){
   2.152 		static uchar buf[MaxPacket];