From eb4d860255ea9e0aa9c2a758ba074ac224c029e5 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 22 Nov 2013 10:37:49 +0100 Subject: optionally do not hide the input MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- Makefile | 5 ++++- src/passphrase.c | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 7618511..5dc054f 100644 --- a/Makefile +++ b/Makefile @@ -2,8 +2,11 @@ PREFIX = /usr LIB = /lib INCLUDE = /include +OPTIONS = +# PASSPHRASE_ECHO: Do not hide the passphrase + OPTIMISE = -Os -CPPFLAGS = +CPPFLAGS = $(foreach D, $(OPTIONS), -D'$(D)=1') CFLAGS = -std=c90 -Wall -Wextra -fPIC LDFLAGS = -shared diff --git a/src/passphrase.c b/src/passphrase.c index 724ff09..43f1431 100644 --- a/src/passphrase.c +++ b/src/passphrase.c @@ -27,10 +27,12 @@ #define START_PASSPHRASE_LIMIT 32 +#ifndef PASSPHRASE_ECHO /** * The original TTY settings */ static struct termios saved_stty; +#endif /** @@ -72,7 +74,9 @@ char* passphrase_read(void) /* NUL-terminate passphrase */ *(rc + len) = 0; +#ifndef PASSPHRASE_ECHO printf("\n"); +#endif return rc; } @@ -82,12 +86,14 @@ char* passphrase_read(void) */ void passphrase_disable_echo(void) { +#ifndef PASSPHRASE_ECHO struct termios stty; tcgetattr(STDIN_FILENO, &stty); saved_stty = stty; stty.c_lflag &= ~ECHO; tcsetattr(STDIN_FILENO, TCSAFLUSH, &stty); +#endif } @@ -96,6 +102,8 @@ void passphrase_disable_echo(void) */ void passphrase_reenable_echo(void) { +#ifndef PASSPHRASE_ECHO tcsetattr(STDIN_FILENO, TCSAFLUSH, &saved_stty); +#endif } -- cgit v1.2.3-70-g09d2