aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2021-07-15 13:04:24 +0200
committerJohn Ankarström <john@ankarstrom.se>2021-07-15 13:04:24 +0200
commit0c91ed54db29d1d5628b6473ef4387dde1b3c116 (patch)
treeb95d200da41b3043a42f87740de28f15003260a0
parent83e1639c12c5a38e1164e9f2d5a4f259b6efd1f6 (diff)
downloadrtty-0c91ed54db29d1d5628b6473ef4387dde1b3c116.tar.gz
Improve sshpass code
-rw-r--r--rtty.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/rtty.c b/rtty.c
index c7a616d..6a69e56 100644
--- a/rtty.c
+++ b/rtty.c
@@ -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;