aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2015-12-05 13:46:41 +0100
committerMattias Andrée <maandree@operamail.com>2015-12-05 13:46:41 +0100
commitdd2c176e769c4763db2e2432aabf8b433b89f138 (patch)
tree3ab8293d32b282a9b5b8154f45fe33d7baf1cbba
parentread input from passcheck (diff)
downloadlibpassphrase-dd2c176e769c4763db2e2432aabf8b433b89f138.tar.gz
libpassphrase-dd2c176e769c4763db2e2432aabf8b433b89f138.tar.bz2
libpassphrase-dd2c176e769c4763db2e2432aabf8b433b89f138.tar.xz
issue #2 on github solved, but not yet perfect
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r--src/echoes.c16
-rw-r--r--src/passphrase.c30
-rw-r--r--src/test.c2
3 files changed, 36 insertions, 12 deletions
diff --git a/src/echoes.c b/src/echoes.c
index e1a0e63..e0a18f4 100644
--- a/src/echoes.c
+++ b/src/echoes.c
@@ -58,19 +58,19 @@ void passphrase_reenable_echo(void)
*/
void passphrase_disable_echo1(int fdin)
{
-#if !defined(PASSPHRASE_ECHO) || defined(PASSPHRASE_MOVE)
+#if !defined(PASSPHRASE_ECHO) || defined(PASSPHRASE_MOVE) || defined(PASSPHRASE_METER)
struct termios stty;
tcgetattr(fdin, &stty);
saved_stty = stty;
stty.c_lflag &= (tcflag_t)~ECHO;
-# if defined(PASSPHRASE_STAR) || defined(PASSPHRASE_TEXT) || defined(PASSPHRASE_MOVE)
+# if defined(PASSPHRASE_STAR) || defined(PASSPHRASE_TEXT) || defined(PASSPHRASE_MOVE) || defined(PASSPHRASE_METER)
stty.c_lflag &= (tcflag_t)~ICANON;
-# endif /* PASSPHRASE_STAR || PASSPHRASE_TEXT || PASSPHRASE_MOVE */
+# endif /* PASSPHRASE_STAR || PASSPHRASE_TEXT || PASSPHRASE_MOVE || PASSPHRASE_METER */
tcsetattr(fdin, TCSAFLUSH, &stty);
-#else /* !PASSPHRASE_ECHO || PASSPHRASE_MOVE */
+#else /* !PASSPHRASE_ECHO || PASSPHRASE_MOVE || PASSPHRASE_METER */
(void) fdin;
-#endif /* !PASSPHRASE_ECHO || PASSPHRASE_MOVE */
+#endif /* !PASSPHRASE_ECHO || PASSPHRASE_MOVE || PASSPHRASE_METER */
}
@@ -81,10 +81,10 @@ void passphrase_disable_echo1(int fdin)
*/
void passphrase_reenable_echo1(int fdin)
{
-#if !defined(PASSPHRASE_ECHO) || defined(PASSPHRASE_MOVE)
+#if !defined(PASSPHRASE_ECHO) || defined(PASSPHRASE_MOVE) || defined(PASSPHRASE_METER)
tcsetattr(fdin, TCSAFLUSH, &saved_stty);
-#else /* !PASSPHRASE_ECHO || !PASSPHRASE_MOVE */
+#else /* !PASSPHRASE_ECHO || !PASSPHRASE_MOVE || PASSPHRASE_METER */
(void) fdin;
-#endif /* !PASSPHRASE_ECHO || !PASSPHRASE_MOVE */
+#endif /* !PASSPHRASE_ECHO || !PASSPHRASE_MOVE || PASSPHRASE_METER */
}
diff --git a/src/passphrase.c b/src/passphrase.c
index 032111b..2978c80 100644
--- a/src/passphrase.c
+++ b/src/passphrase.c
@@ -23,6 +23,7 @@
#include <fcntl.h>
#include <errno.h>
#include <limits.h>
+#include <termios.h>
#include <sys/wait.h>
#define PASSPHRASE_USE_DEPRECATED
@@ -85,6 +86,9 @@ static void passcheck_start(struct passcheck_state* state, int flags)
if (state->flags == 0)
return;
+ if (state->flags & PASSPHRASE_READ_BELOW_FREE)
+ state->flags &= ~PASSPHRASE_READ_SCREEN_FREE;
+
command = getenv("LIBPASSPHRASE_METER");
if (!command || !*command)
command = DEFAULT_PASSPHRASE_METER;
@@ -163,6 +167,19 @@ static void passcheck_start(struct passcheck_state* state, int flags)
goto fail;
}
+ if (state->flags & PASSPHRASE_READ_SCREEN_FREE)
+ {
+ struct termios stty;
+ struct termios saved_stty;
+ tcgetattr(STDERR_FILENO, &stty);
+ saved_stty = stty;
+ stty.c_oflag &= (tcflag_t)~ONLCR;
+ tcsetattr(STDERR_FILENO, TCSAFLUSH, &stty);
+ fprintf(stderr, "\n\033[A");
+ fflush(stderr);
+ tcsetattr(STDERR_FILENO, TCSAFLUSH, &saved_stty);
+ }
+
close(exec_rw[0]);
state->pid = pid;
return;
@@ -195,7 +212,11 @@ rereap:
if ((waitpid(state->pid, &_status, 0) == -1) && (errno == EINTR))
goto rereap;
- /* TODO cleanup */
+ if (state->flags & PASSPHRASE_READ_SCREEN_FREE)
+ fprintf(stderr, "\033[s\033[E\033[0K\033[u");
+ else
+ fprintf(stderr, "\033[B\033[0K\033[A");
+ fflush(stderr);
state->flags = 0;
}
@@ -280,7 +301,11 @@ static void passcheck_update(struct passcheck_state* state, const char* passphra
}
strength_ptr = 0;
- /* TODO */
+ if (state->flags & PASSPHRASE_READ_SCREEN_FREE)
+ fprintf(stderr, "\033[s\033[E\033[0K%s%lli\033[u", /*TODO locale*/"Strength: ", value);
+ else
+ fprintf(stderr, "\033[B\033[s\033[0K%lli\033[u\033[A", value);
+ fflush(stderr);
return;
fail:
@@ -404,7 +429,6 @@ char* passphrase_read2(int fdin, int flags)
{
#ifdef PASSPHRASE_METER
passcheck_stop(&passcheck);
- xflush();
#endif /* PASSPHRASE_METER */
break;
}
diff --git a/src/test.c b/src/test.c
index a962bd5..c7cfbac 100644
--- a/src/test.c
+++ b/src/test.c
@@ -53,7 +53,7 @@ int main(int argc, char** argv)
/* Read the passphrase */
passphrase = passphrase_read2(fd, PASSPHRASE_READ_NEW |
- PASSPHRASE_READ_SCREEN_FREE);
+ PASSPHRASE_READ_BELOW_FREE);
if (passphrase == NULL)
{
/* Something went wrong, print what and exit */