diff options
author | John Ankarström <john@ankarstrom.se> | 2021-07-15 13:04:24 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2021-07-15 13:04:24 +0200 |
commit | 0c91ed54db29d1d5628b6473ef4387dde1b3c116 (patch) | |
tree | b95d200da41b3043a42f87740de28f15003260a0 | |
parent | 83e1639c12c5a38e1164e9f2d5a4f259b6efd1f6 (diff) | |
download | rtty-0c91ed54db29d1d5628b6473ef4387dde1b3c116.tar.gz |
Improve sshpass code
-rw-r--r-- | rtty.c | 13 |
1 files changed, 9 insertions, 4 deletions
@@ -21,7 +21,7 @@ main(int argc, char *argv[]) { char bufin[MAXBUF], bufout[MAXBUF], *bi, *bo, in[30], **nargv, out[30]; fd_set rfds0, rfds1; - int fdin, fdout, i, n, offset; + int fdin, fdout, i, n, offset, sshpass; struct timeval tv; signal(SIGCHLD, sigchld); @@ -34,9 +34,13 @@ main(int argc, char *argv[]) err(1, "mkfifo"); /* Ask for password on -P. */ + sshpass = 0; if(strcmp(argv[1], "-P") == 0){ - printf("password: "); + sshpass = 1; setenv("SSHPASS", getpw(), 1); + + /* Remove -P from argv. */ + argv[1] = argv[0]; argv++; argc--; } @@ -53,13 +57,13 @@ main(int argc, char *argv[]) if(!(nargv = malloc(sizeof(char *)*(argc+10)))) err(1, "malloc"); offset = -1; - if(strcmp(argv[0], "-P") == 0){ + if(sshpass){ nargv[++offset] = "sshpass"; nargv[++offset] = "-ePass"; } nargv[++offset] = "ssh"; nargv[++offset] = "-tt"; - if(strcmp(argv[0], "-P") != 0) + if(!sshpass) nargv[++offset] = "-oBatchMode=yes"; for(i = 1; i < argc; i++) nargv[i+offset] = argv[i]; @@ -161,6 +165,7 @@ getpw() term.c_lflag &= ~ECHO; tcsetattr(0, TCSANOW, &term); + printf("password: "); fgets(pw, 255, stdin); pw[strcspn(pw, "\n")] = 0; |