changelog shortlog tags branches files raw gz bz2 help

Mercurial > hg > plan9front / changeset: ssh: print usage for unknown flags, cleanup

changeset 7124: 48d6c96711d8
parent 7123: 61c77ecfdb10
child 7125: b2188aa5a2af
author: cinap_lenrek@felloff.net
date: Tue, 02 Apr 2019 19:22:19 +0200
files: sys/src/cmd/ssh.c
description: ssh: print usage for unknown flags, cleanup
     1.1--- a/sys/src/cmd/ssh.c
     1.2+++ b/sys/src/cmd/ssh.c
     1.3@@ -1157,7 +1157,7 @@ kfmt(Fmt *f)
     1.4 void
     1.5 usage(void)
     1.6 {
     1.7-	fprint(2, "usage: %s [-dRX] [-t thumbfile] [-T tries] [-u user] [-h] [user@]host [-W remote!port] [cmd args...]\n", argv0);
     1.8+	fprint(2, "usage: %s [-dR] [-t thumbfile] [-T tries] [-u user] [-h] [user@]host [-W remote!port] [cmd args...]\n", argv0);
     1.9 	exits("usage");
    1.10 }
    1.11 
    1.12@@ -1217,6 +1217,8 @@ main(int argc, char *argv[])
    1.13 		mux = 1;
    1.14 		raw = 0;
    1.15 		break;
    1.16+	default:
    1.17+		usage();
    1.18 	} ARGEND;
    1.19 
    1.20 	if(host == nil){
    1.21@@ -1287,47 +1289,84 @@ Next0:	switch(recvpkt()){
    1.22 	recv.win = send.win =  WinPackets*recv.pkt;
    1.23 	recv.chan = send.win = 0;
    1.24 
    1.25-	if(!mux){
    1.26-		/* open hailing frequencies */
    1.27-		if(remote != nil){
    1.28-			NetConnInfo *nci = getnetconninfo(nil, fd);
    1.29-			if(nci == nil)
    1.30-				sysfatal("can't get netconninfo: %r");
    1.31-			sendpkt("bsuuususu", MSG_CHANNEL_OPEN,
    1.32-				"direct-tcpip", 12,
    1.33-				recv.chan,
    1.34-				recv.win,
    1.35-				recv.pkt,
    1.36-				remote, strlen(remote),
    1.37-				port,
    1.38-				nci->laddr, strlen(nci->laddr),
    1.39-				atoi(nci->lserv));
    1.40-			free(nci);
    1.41-		} else {
    1.42-			sendpkt("bsuuu", MSG_CHANNEL_OPEN,
    1.43-				"session", 7,
    1.44-				recv.chan,
    1.45-				recv.win,
    1.46-				recv.pkt);
    1.47-		}
    1.48-Next1:		switch(recvpkt()){
    1.49-		default:
    1.50-			dispatch();
    1.51-			goto Next1;
    1.52-		case MSG_CHANNEL_OPEN_FAILURE:
    1.53-			if(unpack(recv.r, recv.w-recv.r, "_uus", &c, &b, &s, &n) < 0)
    1.54-				n = strlen(s = "???");
    1.55-			sysfatal("channel open failure: (%d) %.*s", b, utfnlen(s, n), s);
    1.56-		case MSG_CHANNEL_OPEN_CONFIRMATION:
    1.57-			break;
    1.58-		}
    1.59+	if(mux)
    1.60+		goto Mux;
    1.61 
    1.62-		if(unpack(recv.r, recv.w-recv.r, "_uuuu", &recv.chan, &send.chan, &send.win, &send.pkt) < 0)
    1.63-			sysfatal("bad channel open confirmation");
    1.64-		if(send.pkt <= 0 || send.pkt > MaxPacket)
    1.65-			send.pkt = MaxPacket;
    1.66+	/* open hailing frequencies */
    1.67+	if(remote != nil){
    1.68+		NetConnInfo *nci = getnetconninfo(nil, fd);
    1.69+		if(nci == nil)
    1.70+			sysfatal("can't get netconninfo: %r");
    1.71+		sendpkt("bsuuususu", MSG_CHANNEL_OPEN,
    1.72+			"direct-tcpip", 12,
    1.73+			recv.chan,
    1.74+			recv.win,
    1.75+			recv.pkt,
    1.76+			remote, strlen(remote),
    1.77+			port,
    1.78+			nci->laddr, strlen(nci->laddr),
    1.79+			atoi(nci->lserv));
    1.80+		free(nci);
    1.81+	} else {
    1.82+		sendpkt("bsuuu", MSG_CHANNEL_OPEN,
    1.83+			"session", 7,
    1.84+			recv.chan,
    1.85+			recv.win,
    1.86+			recv.pkt);
    1.87+	}
    1.88+Next1:	switch(recvpkt()){
    1.89+	default:
    1.90+		dispatch();
    1.91+		goto Next1;
    1.92+	case MSG_CHANNEL_OPEN_FAILURE:
    1.93+		if(unpack(recv.r, recv.w-recv.r, "_uus", &c, &b, &s, &n) < 0)
    1.94+			n = strlen(s = "???");
    1.95+		sysfatal("channel open failure: (%d) %.*s", b, utfnlen(s, n), s);
    1.96+	case MSG_CHANNEL_OPEN_CONFIRMATION:
    1.97+		break;
    1.98 	}
    1.99 
   1.100+	if(unpack(recv.r, recv.w-recv.r, "_uuuu", &recv.chan, &send.chan, &send.win, &send.pkt) < 0)
   1.101+		sysfatal("bad channel open confirmation");
   1.102+	if(send.pkt <= 0 || send.pkt > MaxPacket)
   1.103+		send.pkt = MaxPacket;
   1.104+
   1.105+	if(remote != nil)
   1.106+		goto Mux;
   1.107+
   1.108+	if(raw) {
   1.109+		rawon();
   1.110+		sendpkt("busbsuuuus", MSG_CHANNEL_REQUEST,
   1.111+			send.chan,
   1.112+			"pty-req", 7,
   1.113+			0,
   1.114+			tty.term, strlen(tty.term),
   1.115+			tty.cols,
   1.116+			tty.lines,
   1.117+			tty.xpixels,
   1.118+			tty.ypixels,
   1.119+			"", 0);
   1.120+	}
   1.121+	if(cmd == nil){
   1.122+		sendpkt("busb", MSG_CHANNEL_REQUEST,
   1.123+			send.chan,
   1.124+			"shell", 5,
   1.125+			0);
   1.126+	} else if(*cmd == '#') {
   1.127+		sendpkt("busbs", MSG_CHANNEL_REQUEST,
   1.128+			send.chan,
   1.129+			"subsystem", 9,
   1.130+			0,
   1.131+			cmd+1, strlen(cmd)-1);
   1.132+	} else {
   1.133+		sendpkt("busbs", MSG_CHANNEL_REQUEST,
   1.134+			send.chan,
   1.135+			"exec", 4,
   1.136+			0,
   1.137+			cmd, strlen(cmd));
   1.138+	}
   1.139+
   1.140+Mux:
   1.141 	notify(catch);
   1.142 	atexit(shutdown);
   1.143 
   1.144@@ -1352,39 +1391,6 @@ Next1:		switch(recvpkt()){
   1.145 
   1.146 	/* child reads input and sends packets */
   1.147 	qlock(&sl);
   1.148-	if(remote == nil && !mux){
   1.149-		if(raw) {
   1.150-			rawon();
   1.151-			sendpkt("busbsuuuus", MSG_CHANNEL_REQUEST,
   1.152-				send.chan,
   1.153-				"pty-req", 7,
   1.154-				0,
   1.155-				tty.term, strlen(tty.term),
   1.156-				tty.cols,
   1.157-				tty.lines,
   1.158-				tty.xpixels,
   1.159-				tty.ypixels,
   1.160-				"", 0);
   1.161-		}
   1.162-		if(cmd == nil){
   1.163-			sendpkt("busb", MSG_CHANNEL_REQUEST,
   1.164-				send.chan,
   1.165-				"shell", 5,
   1.166-				0);
   1.167-		} else if(*cmd == '#') {
   1.168-			sendpkt("busbs", MSG_CHANNEL_REQUEST,
   1.169-				send.chan,
   1.170-				"subsystem", 9,
   1.171-				0,
   1.172-				cmd+1, strlen(cmd)-1);
   1.173-		} else {
   1.174-			sendpkt("busbs", MSG_CHANNEL_REQUEST,
   1.175-				send.chan,
   1.176-				"exec", 4,
   1.177-				0,
   1.178-				cmd, strlen(cmd));
   1.179-		}
   1.180-	}
   1.181 	for(;;){
   1.182 		static uchar buf[MaxPacket];
   1.183 		qunlock(&sl);