summaryrefslogtreecommitdiff
path: root/sys/src/cmd/ssh.c
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2019-04-02 19:22:19 +0200
committercinap_lenrek <cinap_lenrek@felloff.net>2019-04-02 19:22:19 +0200
commit6d429cf9e8418ec69d2516ccba370860e20afd63 (patch)
tree31f1402ced61d44c350023e24ee924f243d09045 /sys/src/cmd/ssh.c
parent009b624fe69ab396babae0ecc9bc7a6bb5bf7405 (diff)
ssh: print usage for unknown flags, cleanup
Diffstat (limited to 'sys/src/cmd/ssh.c')
-rw-r--r--sys/src/cmd/ssh.c150
1 files changed, 78 insertions, 72 deletions
diff --git a/sys/src/cmd/ssh.c b/sys/src/cmd/ssh.c
index cce0c0fae..2d23be1d3 100644
--- a/sys/src/cmd/ssh.c
+++ b/sys/src/cmd/ssh.c
@@ -1157,7 +1157,7 @@ kfmt(Fmt *f)
void
usage(void)
{
- fprint(2, "usage: %s [-dRX] [-t thumbfile] [-T tries] [-u user] [-h] [user@]host [-W remote!port] [cmd args...]\n", argv0);
+ fprint(2, "usage: %s [-dR] [-t thumbfile] [-T tries] [-u user] [-h] [user@]host [-W remote!port] [cmd args...]\n", argv0);
exits("usage");
}
@@ -1217,6 +1217,8 @@ main(int argc, char *argv[])
mux = 1;
raw = 0;
break;
+ default:
+ usage();
} ARGEND;
if(host == nil){
@@ -1287,47 +1289,84 @@ Next0: switch(recvpkt()){
recv.win = send.win = WinPackets*recv.pkt;
recv.chan = send.win = 0;
- if(!mux){
- /* open hailing frequencies */
- if(remote != nil){
- NetConnInfo *nci = getnetconninfo(nil, fd);
- if(nci == nil)
- sysfatal("can't get netconninfo: %r");
- sendpkt("bsuuususu", MSG_CHANNEL_OPEN,
- "direct-tcpip", 12,
- recv.chan,
- recv.win,
- recv.pkt,
- remote, strlen(remote),
- port,
- nci->laddr, strlen(nci->laddr),
- atoi(nci->lserv));
- free(nci);
- } else {
- sendpkt("bsuuu", MSG_CHANNEL_OPEN,
- "session", 7,
- recv.chan,
- recv.win,
- recv.pkt);
- }
-Next1: switch(recvpkt()){
- default:
- dispatch();
- goto Next1;
- case MSG_CHANNEL_OPEN_FAILURE:
- if(unpack(recv.r, recv.w-recv.r, "_uus", &c, &b, &s, &n) < 0)
- n = strlen(s = "???");
- sysfatal("channel open failure: (%d) %.*s", b, utfnlen(s, n), s);
- case MSG_CHANNEL_OPEN_CONFIRMATION:
- break;
- }
+ if(mux)
+ goto Mux;
+
+ /* open hailing frequencies */
+ if(remote != nil){
+ NetConnInfo *nci = getnetconninfo(nil, fd);
+ if(nci == nil)
+ sysfatal("can't get netconninfo: %r");
+ sendpkt("bsuuususu", MSG_CHANNEL_OPEN,
+ "direct-tcpip", 12,
+ recv.chan,
+ recv.win,
+ recv.pkt,
+ remote, strlen(remote),
+ port,
+ nci->laddr, strlen(nci->laddr),
+ atoi(nci->lserv));
+ free(nci);
+ } else {
+ sendpkt("bsuuu", MSG_CHANNEL_OPEN,
+ "session", 7,
+ recv.chan,
+ recv.win,
+ recv.pkt);
+ }
+Next1: switch(recvpkt()){
+ default:
+ dispatch();
+ goto Next1;
+ case MSG_CHANNEL_OPEN_FAILURE:
+ if(unpack(recv.r, recv.w-recv.r, "_uus", &c, &b, &s, &n) < 0)
+ n = strlen(s = "???");
+ sysfatal("channel open failure: (%d) %.*s", b, utfnlen(s, n), s);
+ case MSG_CHANNEL_OPEN_CONFIRMATION:
+ break;
+ }
+
+ if(unpack(recv.r, recv.w-recv.r, "_uuuu", &recv.chan, &send.chan, &send.win, &send.pkt) < 0)
+ sysfatal("bad channel open confirmation");
+ if(send.pkt <= 0 || send.pkt > MaxPacket)
+ send.pkt = MaxPacket;
+
+ if(remote != nil)
+ goto Mux;
- if(unpack(recv.r, recv.w-recv.r, "_uuuu", &recv.chan, &send.chan, &send.win, &send.pkt) < 0)
- sysfatal("bad channel open confirmation");
- if(send.pkt <= 0 || send.pkt > MaxPacket)
- send.pkt = MaxPacket;
+ if(raw) {
+ rawon();
+ sendpkt("busbsuuuus", MSG_CHANNEL_REQUEST,
+ send.chan,
+ "pty-req", 7,
+ 0,
+ tty.term, strlen(tty.term),
+ tty.cols,
+ tty.lines,
+ tty.xpixels,
+ tty.ypixels,
+ "", 0);
+ }
+ if(cmd == nil){
+ sendpkt("busb", MSG_CHANNEL_REQUEST,
+ send.chan,
+ "shell", 5,
+ 0);
+ } else if(*cmd == '#') {
+ sendpkt("busbs", MSG_CHANNEL_REQUEST,
+ send.chan,
+ "subsystem", 9,
+ 0,
+ cmd+1, strlen(cmd)-1);
+ } else {
+ sendpkt("busbs", MSG_CHANNEL_REQUEST,
+ send.chan,
+ "exec", 4,
+ 0,
+ cmd, strlen(cmd));
}
+Mux:
notify(catch);
atexit(shutdown);
@@ -1352,39 +1391,6 @@ Next1: switch(recvpkt()){
/* child reads input and sends packets */
qlock(&sl);
- if(remote == nil && !mux){
- if(raw) {
- rawon();
- sendpkt("busbsuuuus", MSG_CHANNEL_REQUEST,
- send.chan,
- "pty-req", 7,
- 0,
- tty.term, strlen(tty.term),
- tty.cols,
- tty.lines,
- tty.xpixels,
- tty.ypixels,
- "", 0);
- }
- if(cmd == nil){
- sendpkt("busb", MSG_CHANNEL_REQUEST,
- send.chan,
- "shell", 5,
- 0);
- } else if(*cmd == '#') {
- sendpkt("busbs", MSG_CHANNEL_REQUEST,
- send.chan,
- "subsystem", 9,
- 0,
- cmd+1, strlen(cmd)-1);
- } else {
- sendpkt("busbs", MSG_CHANNEL_REQUEST,
- send.chan,
- "exec", 4,
- 0,
- cmd, strlen(cmd));
- }
- }
for(;;){
static uchar buf[MaxPacket];
qunlock(&sl);