]> git.lizzy.rs Git - plan9front.git/blobdiff - sys/src/cmd/ssh.c
usb lib: add maxpkt and ntds to Altc struct
[plan9front.git] / sys / src / cmd / ssh.c
index c0877f289c18100a7b8ce239bd6edc7a1e3d13d3..750563588d814e7ed4dbd2cb182bbf9fa5154383 100644 (file)
@@ -52,9 +52,7 @@ enum {
        WinPackets = 8,         // (1<<15) * 8 = 256K
 };
 
-enum {
-       MaxPwTries = 3 // retry this often for keyboard-interactive
-};
+int MaxPwTries = 3; // retry this often for keyboard-interactive
 
 typedef struct
 {
@@ -99,7 +97,7 @@ shutdown(void)
 void
 catch(void*, char *msg)
 {
-       if(strstr(msg, "interrupt") != nil){
+       if(strcmp(msg, "interrupt") == 0){
                intr = 1;
                noted(NCONT);
        }
@@ -116,7 +114,7 @@ wasintr(void)
                return 1;
        memset(err, 0, sizeof(err));
        errstr(err, sizeof(err));
-       r = strstr(err, "interrupt") != nil;
+       r = strcmp(err, "interrupted") == 0;
        errstr(err, sizeof(err));
        return r;
 }
@@ -428,11 +426,6 @@ ssh2rsasig(uchar *data, int len)
        return m;
 }
 
-/* libsec */
-extern mpint* pkcs1padbuf(uchar *buf, int len, mpint *modulus, int blocktype);
-extern int asn1encodedigest(DigestState* (*fun)(uchar*, ulong, uchar*, DigestState*),
-       uchar *digest, uchar *buf, int len);
-
 mpint*
 pkcs1digest(uchar *data, int len, RSApub *pub)
 {
@@ -1072,19 +1065,35 @@ static struct {
        int     ypixels;
        int     lines;
        int     cols;
-} tty = {
-       "dumb",
-       0,
-       0,
-       0,
-       0,
-};
+} tty;
+
+void
+getdim(void)
+{
+       char *s;
+
+       if(s = getenv("XPIXELS")){
+               tty.xpixels = atoi(s);
+               free(s);
+       }
+       if(s = getenv("YPIXELS")){
+               tty.ypixels = atoi(s);
+               free(s);
+       }
+       if(s = getenv("LINES")){
+               tty.lines = atoi(s);
+               free(s);
+       }
+       if(s = getenv("COLS")){
+               tty.cols = atoi(s);
+               free(s);
+       }
+}
 
 void
 rawon(void)
 {
        int ctl;
-       char *s;
 
        close(0);
        if(open("/dev/cons", OREAD) != 0)
@@ -1093,33 +1102,38 @@ rawon(void)
        if(open("/dev/cons", OWRITE) != 1)
                sysfatal("open: %r");
        dup(1, 2);
-       if((ctl = open("/dev/consctl", OWRITE)) >= 0)
+       if((ctl = open("/dev/consctl", OWRITE)) >= 0){
                write(ctl, "rawon", 5);
-       if(s = getenv("TERM")){
-               tty.term = s;
-               if(s = getenv("XPIXELS")){
-                       tty.xpixels = atoi(s);
-                       free(s);
-               }
-               if(s = getenv("YPIXELS")){
-                       tty.ypixels = atoi(s);
-                       free(s);
-               }
-               if(s = getenv("LINES")){
-                       tty.lines = atoi(s);
-                       free(s);
-               }
-               if(s = getenv("COLS")){
-                       tty.cols = atoi(s);
-                       free(s);
-               }
+               write(ctl, "winchon", 7);       /* vt(1): interrupt note on window change */
        }
+       getdim();
+}
+
+#pragma           varargck    type  "k"   char*
+
+kfmt(Fmt *f)
+{
+       char *s, *p;
+       int n;
+
+       s = va_arg(f->args, char*);
+       n = fmtstrcpy(f, "'");
+       while((p = strchr(s, '\'')) != nil){
+               *p = '\0';
+               n += fmtstrcpy(f, s);
+               *p = '\'';
+               n += fmtstrcpy(f, "'\\''");
+               s = p+1;
+       }
+       n += fmtstrcpy(f, s);
+       n += fmtstrcpy(f, "'");
+       return n;
 }
 
 void
 usage(void)
 {
-       fprint(2, "usage: %s [-dR] [-t thumbfile] [-u user] [user@]host [cmd]\n", argv0);
+       fprint(2, "usage: %s [-dR] [-t thumbfile] [-T tries] [-u user] [-h] [user@]host [cmd args...]\n", argv0);
        exits("usage");
 }
 
@@ -1134,10 +1148,10 @@ main(int argc, char *argv[])
        fmtinstall('B', mpfmt);
        fmtinstall('H', encodefmt);
        fmtinstall('[', encodefmt);
+       fmtinstall('k', kfmt);
 
-       s = getenv("TERM");
-       raw = s != nil && strcmp(s, "dumb") != 0;
-       free(s);
+       tty.term = getenv("TERM");
+       raw = tty.term != nil && *tty.term != 0;
 
        ARGBEGIN {
        case 'd':
@@ -1149,15 +1163,24 @@ main(int argc, char *argv[])
        case 'u':
                user = EARGF(usage());
                break;
+       case 'h':
+               host = EARGF(usage());
+               break;
        case 't':
                thumbfile = EARGF(usage());
                break;
+       case 'T':
+               MaxPwTries = strtol(EARGF(usage()), &s, 0);
+               if(*s != 0) usage();
+               break;
        } ARGEND;
 
-       if(argc == 0)
-               usage();
+       if(host == nil){
+               if(argc == 0)
+                       usage();
+               host = *argv++;
+       }
 
-       host = *argv++;
        if(user == nil){
                s = strchr(host, '@');
                if(s != nil){
@@ -1166,17 +1189,17 @@ main(int argc, char *argv[])
                        host = s;
                }
        }
+
        for(cmd = nil; *argv != nil; argv++){
-               if(cmd == nil)
+               if(cmd == nil){
                        cmd = strdup(*argv);
-               else {
-                       s = smprint("%s %q", cmd, *argv);
+                       raw = 0;
+               }else {
+                       s = smprint("%s %k", cmd, *argv);
                        free(cmd);
                        cmd = s;
                }
        }
-       if(cmd != nil)
-               raw = 0;
 
        if((fd = dial(netmkaddr(host, nil, "ssh"), nil, nil, nil)) < 0)
                sysfatal("dial: %r");
@@ -1199,9 +1222,6 @@ main(int argc, char *argv[])
 
        kex(0);
 
-
-       service = "ssh-connection";
-
        sendpkt("bs", MSG_SERVICE_REQUEST, "ssh-userauth", 12);
 Next0: switch(recvpkt()){
        default:
@@ -1211,6 +1231,7 @@ Next0:    switch(recvpkt()){
                break;
        }
 
+       service = "ssh-connection";
        if(noneauth() < 0 && pubkeyauth() < 0 && passauth() < 0 && kbintauth() < 0)
                sysfatal("auth: %r");
 
@@ -1284,6 +1305,12 @@ Next1:   switch(recvpkt()){
                        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,
@@ -1300,12 +1327,23 @@ Next1:  switch(recvpkt()){
                        break;
                if(n < 0 && wasintr()){
                        if(!raw) break;
-                       sendpkt("busbs", MSG_CHANNEL_REQUEST,
-                               send.chan,
-                               "signal", 6,
-                               0,
-                               "INT", 3);
-                       intr = 0;
+                       if(intr){
+                               getdim();
+                               sendpkt("busbuuuu", MSG_CHANNEL_REQUEST,
+                                       send.chan,
+                                       "window-change", 13,
+                                       0,
+                                       tty.cols,
+                                       tty.lines,
+                                       tty.xpixels,
+                                       tty.ypixels);
+                               sendpkt("busbs", MSG_CHANNEL_REQUEST,
+                                       send.chan,
+                                       "signal", 6,
+                                       0,
+                                       "INT", 3);
+                               intr = 0;
+                       }
                        continue;
                }
                if(n <= 0)