From 0c91ed54db29d1d5628b6473ef4387dde1b3c116 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Thu, 15 Jul 2021 13:04:24 +0200 Subject: Improve sshpass code --- rtty.c | 13 +++++++++---- 1 file 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; -- cgit v1.2.3