cpu: -c command quoting, various cleanups

This commit is contained in:
cinap_lenrek 2012-06-25 06:44:23 +02:00
parent f4480d1517
commit 1cd5d74d4d

View file

@ -136,7 +136,7 @@ procsetname(char *fmt, ...)
void void
main(int argc, char **argv) main(int argc, char **argv)
{ {
char dat[MaxStr], buf[MaxStr], cmd[MaxStr], *p, *err; char dat[MaxStr], buf[MaxStr], cmd[MaxStr], *p, *s, *err;
int ac, fd, ms, data; int ac, fd, ms, data;
char *av[10]; char *av[10];
@ -183,12 +183,11 @@ main(int argc, char **argv)
break; break;
case 'c': case 'c':
cflag++; cflag++;
cmd[0] = '!'; s = cmd;
cmd[1] = '\0'; *s++ = '!';
while(p = ARGF()) { *s = 0;
strcat(cmd, " "); while(p = ARGF())
strcat(cmd, p); s = seprint(s, cmd+sizeof(cmd), " %q", p);
}
break; break;
case 'k': case 'k':
keyspec = smprint("%s %s", keyspec, EARGF(usage())); keyspec = smprint("%s %s", keyspec, EARGF(usage()));
@ -343,7 +342,7 @@ remoteside(int old)
/* Set environment values for the user */ /* Set environment values for the user */
putenv("user", user); putenv("user", user);
sprint(home, "/usr/%s", user); snprint(home, sizeof(home), "/usr/%s", user);
putenv("home", home); putenv("home", home);
/* Now collect invoking cpu's current directory or possibly a command */ /* Now collect invoking cpu's current directory or possibly a command */
@ -532,7 +531,7 @@ netkeysrvauth(int fd, char *user)
int tries; int tries;
AuthInfo *ai; AuthInfo *ai;
if(readstr(fd, user, 32) < 0) if(readstr(fd, user, MaxStr) < 0)
return -1; return -1;
ai = nil; ai = nil;
@ -571,21 +570,24 @@ mksecret(char *t, uchar *f)
static int static int
p9auth(int fd) p9auth(int fd)
{ {
uchar key[16]; uchar key[16], digest[SHA1dlen];
uchar digest[SHA1dlen];
char fromclientsecret[21]; char fromclientsecret[21];
char fromserversecret[21]; char fromserversecret[21];
int i;
AuthInfo *ai; AuthInfo *ai;
int i;
procsetname("%s: auth_proxy proto=%q role=client %s", procsetname("%s: auth_proxy proto=%q role=client %s",
origargs, p9authproto, keyspec); origargs, p9authproto, keyspec);
ai = auth_proxy(fd, auth_getkey, "proto=%q role=client %s", p9authproto, keyspec); ai = auth_proxy(fd, auth_getkey, "proto=%q role=client %s", p9authproto, keyspec);
if(ai == nil) if(ai == nil)
return -1; return -1;
memmove(key+4, ai->secret, ai->nsecret); if(ealgs == nil){
if(ealgs == nil) auth_freeAI(ai);
return fd; return fd;
}
assert(ai->nsecret <= sizeof(key)-4);
memmove(key+4, ai->secret, ai->nsecret);
auth_freeAI(ai);
/* exchange random numbers */ /* exchange random numbers */
srand(truerand()); srand(truerand());
@ -641,23 +643,25 @@ loghex(uchar *p, int n)
static int static int
srvp9auth(int fd, char *user) srvp9auth(int fd, char *user)
{ {
uchar key[16]; uchar key[16], digest[SHA1dlen];
uchar digest[SHA1dlen];
char fromclientsecret[21]; char fromclientsecret[21];
char fromserversecret[21]; char fromserversecret[21];
int i;
AuthInfo *ai; AuthInfo *ai;
int i;
ai = auth_proxy(0, nil, "proto=%q role=server %s", p9authproto, keyspec); ai = auth_proxy(fd, nil, "proto=%q role=server %s", p9authproto, keyspec);
if(ai == nil) if(ai == nil)
return -1; return -1;
if(auth_chuid(ai, nil) < 0) if(auth_chuid(ai, nil) < 0)
return -1; fatal("newns: %r");
strecpy(user, user+MaxStr, ai->cuid); snprint(user, MaxStr, "%s", ai->cuid);
memmove(key+4, ai->secret, ai->nsecret); if(ealgs == nil){
auth_freeAI(ai);
if(ealgs == nil)
return fd; return fd;
}
assert(ai->nsecret <= sizeof(key)-4);
memmove(key+4, ai->secret, ai->nsecret);
auth_freeAI(ai);
/* exchange random numbers */ /* exchange random numbers */
srand(truerand()); srand(truerand());