aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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;