aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2021-07-15 13:39:10 +0200
committerJohn Ankarström <john@ankarstrom.se>2021-07-15 13:39:22 +0200
commit668bd8418f5886b1e449381057e4f2849b200562 (patch)
tree0b97a8a1d5cadda1d21fe95f1873b5d2eb9cc044
parent0c91ed54db29d1d5628b6473ef4387dde1b3c116 (diff)
downloadrtty-668bd8418f5886b1e449381057e4f2849b200562.tar.gz
Add +d (detect password prompt) flag
Also, rename -P flag to +p.
-rw-r--r--rtty.134
-rw-r--r--rtty.c61
2 files changed, 63 insertions, 32 deletions
diff --git a/rtty.1 b/rtty.1
index c6ee571..7fc2fee 100644
--- a/rtty.1
+++ b/rtty.1
@@ -6,7 +6,7 @@
.Nd limited but responsive remote shell
.Sh SYNOPSIS
.Nm
-.Op Fl P
+.Op Sy +dp
.Op Ar ...
.Sh DESCRIPTION
.Pp
@@ -15,7 +15,7 @@ is a wrapper around
.Xr ssh 1
that provides a remote shell as responsive as
.Xr mosh 1
-and as limited as a traditional teletypewriter.
+and as limited as a hard-copy teletypewriter.
It is a very useful tool on slow connections.
As
.Nm
@@ -23,21 +23,31 @@ uses the default line-editing capabilities of the terminal,
user input is only sent to the remote server
once a full line has been input.
.Pp
+Flags specific to
+.Nm
+are prefixed with a plus sign.
If the
-.Fl P
+.Sy +d
flag is provided,
.Nm
-will manually ask the user for a password and run
-.Xr ssh 1
-using
-.Xr sshpass 1 .
-Otherwise,
+tries to detect password prompts from the remote server
+and hide the user's input.
+If the
+.Sy +p
+flag is provided,
+.Nm
+manually asks the user for a password
+before connecting to the server.
+This requires
+.Xr sshpass 1
+to be installed.
+Without the
+.Sy +p
+flag,
.Xr ssh 1
-is launched in batch mode,
-without the possibility of interactive password entry.
+is launched in batch mode.
.Pp
-All arguments except
-.Fl P
+All other arguments
are passed to
.Xr ssh 1 .
.Sh AUTHORS
diff --git a/rtty.c b/rtty.c
index 6a69e56..18eeae6 100644
--- a/rtty.c
+++ b/rtty.c
@@ -13,16 +13,17 @@
#define INIT "export TERM=tty43 EDITOR=ed PAGER='pr -ptl23'\n"
#define MAXBUF 2048
-char *getpw(void);
+char *getpw(char *);
void sigchld();
int
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, sshpass;
- struct timeval tv;
+ char bufin[MAXBUF], bufout[MAXBUF], *bi, *bo, in[30], **nargv,
+ out[30], pw[255];
+ fd_set rfds0, rfds1;
+ int detect, fdin, fdout, i, n, offset, sshpass;
+ struct timeval tv;
signal(SIGCHLD, sigchld);
@@ -33,17 +34,25 @@ main(int argc, char *argv[])
if(errno != EEXIST)
err(1, "mkfifo");
- /* Ask for password on -P. */
- sshpass = 0;
- if(strcmp(argv[1], "-P") == 0){
- sshpass = 1;
- setenv("SSHPASS", getpw(), 1);
+ /* Process rtty-specific flags. */
+ detect = sshpass = 0;
+ for(;argv[1][0] == '+';){
+ if(strchr(argv[1], 'd')) detect = 1;
+ if(strchr(argv[1], 'p')) sshpass = 1;
- /* Remove -P from argv. */
+ /* Remove flag argument from argv. */
argv[1] = argv[0];
argv++; argc--;
}
+ /* Ask for password on +p. */
+ if(sshpass){
+ printf("password: ");
+ getpw(pw);
+ setenv("SSHPASS", pw, 1);
+ sshpass = 1;
+ }
+
if(fork() == 0){
/* Redirect standard in, out. */
if(!(fdin = open(in, O_RDONLY)))
@@ -143,29 +152,41 @@ main(int argc, char *argv[])
printf("%s", bo);
fflush(stdout);
bufin[0] = 0;
+
+ if(!detect)
+ continue;
+
+ /*
+ * As the +d flag is given, rtty tries to detect
+ * password prompts and hide the user's input.
+ */
+ if(bo[strlen(bo)-1] == ':'
+ || strcmp(bo+strlen(bo)-2, ": ") == 0){
+ if(!(bo = strrchr(bufout, '\n')))
+ bo = bufout;
+ if(strstr(bo, "password")
+ || strstr(bo, "Password")
+ || strstr(bo, "passphrase")
+ || strstr(bo, "Passphrase")){
+ getpw(pw);
+ dprintf(fdin, "%s\n", pw);
+ }
+ }
}
}
}
char *
-getpw()
+getpw(char *pw)
{
- char *pw;
struct termios orig, term;
- /*
- * This pointer will never be freed, but eh... whatever.
- */
- if(!(pw = malloc(255)))
- err(1, "malloc");
-
tcgetattr(0, &orig);
tcgetattr(0, &term);
term.c_lflag &= ~ECHO;
tcsetattr(0, TCSANOW, &term);
- printf("password: ");
fgets(pw, 255, stdin);
pw[strcspn(pw, "\n")] = 0;