ssh: quote cmd arguments with unix shell single quotes, request tty even with TERM=dumb

This commit is contained in:
cinap_lenrek 2017-05-03 20:55:32 +02:00
parent 38d421ec00
commit 710d4982b7

View file

@ -1070,13 +1070,7 @@ static struct {
int ypixels; int ypixels;
int lines; int lines;
int cols; int cols;
} tty = { } tty;
"dumb",
0,
0,
0,
0,
};
void void
rawon(void) rawon(void)
@ -1093,8 +1087,6 @@ rawon(void)
dup(1, 2); dup(1, 2);
if((ctl = open("/dev/consctl", OWRITE)) >= 0) if((ctl = open("/dev/consctl", OWRITE)) >= 0)
write(ctl, "rawon", 5); write(ctl, "rawon", 5);
if(s = getenv("TERM")){
tty.term = s;
if(s = getenv("XPIXELS")){ if(s = getenv("XPIXELS")){
tty.xpixels = atoi(s); tty.xpixels = atoi(s);
free(s); free(s);
@ -1111,13 +1103,33 @@ rawon(void)
tty.cols = atoi(s); tty.cols = atoi(s);
free(s); free(s);
} }
}
#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 void
usage(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] [user@]host [cmd args...]\n", argv0);
exits("usage"); exits("usage");
} }
@ -1132,10 +1144,10 @@ main(int argc, char *argv[])
fmtinstall('B', mpfmt); fmtinstall('B', mpfmt);
fmtinstall('H', encodefmt); fmtinstall('H', encodefmt);
fmtinstall('[', encodefmt); fmtinstall('[', encodefmt);
fmtinstall('k', kfmt);
s = getenv("TERM"); tty.term = getenv("TERM");
raw = s != nil && strcmp(s, "dumb") != 0; raw = tty.term != nil && *tty.term != 0;
free(s);
ARGBEGIN { ARGBEGIN {
case 'd': case 'd':
@ -1168,17 +1180,17 @@ main(int argc, char *argv[])
host = s; host = s;
} }
} }
for(cmd = nil; *argv != nil; argv++){ for(cmd = nil; *argv != nil; argv++){
if(cmd == nil) if(cmd == nil){
cmd = strdup(*argv); cmd = strdup(*argv);
else { raw = 0;
s = smprint("%s %q", cmd, *argv); }else {
s = smprint("%s %k", cmd, *argv);
free(cmd); free(cmd);
cmd = s; cmd = s;
} }
} }
if(cmd != nil)
raw = 0;
if((fd = dial(netmkaddr(host, nil, "ssh"), nil, nil, nil)) < 0) if((fd = dial(netmkaddr(host, nil, "ssh"), nil, nil, nil)) < 0)
sysfatal("dial: %r"); sysfatal("dial: %r");
@ -1201,9 +1213,6 @@ main(int argc, char *argv[])
kex(0); kex(0);
service = "ssh-connection";
sendpkt("bs", MSG_SERVICE_REQUEST, "ssh-userauth", 12); sendpkt("bs", MSG_SERVICE_REQUEST, "ssh-userauth", 12);
Next0: switch(recvpkt()){ Next0: switch(recvpkt()){
default: default:
@ -1213,6 +1222,7 @@ Next0: switch(recvpkt()){
break; break;
} }
service = "ssh-connection";
if(noneauth() < 0 && pubkeyauth() < 0 && passauth() < 0 && kbintauth() < 0) if(noneauth() < 0 && pubkeyauth() < 0 && passauth() < 0 && kbintauth() < 0)
sysfatal("auth: %r"); sysfatal("auth: %r");