From 64845bdc829d6a6179d0762b7e97ef23828562a3 Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Fri, 3 Oct 2014 15:53:45 +0200 Subject: ask-password: Add --echo to enable echoing the user input Programs such as OpenVPN may use ask-password for not only retrieving passwords, but also usernames. Masking usernames with * seems just silly. v2 - Don't mess with termios flags, instead print the input instead of an asterix. Resolves issues with backspace and TAB input. v3 - Renamed 'do_echo' variables and argument to 'echo'. Also modified the ask_password_{tty,agent,auto} API instead of additional wrapper functions. [zj: undo changes to ask_password_auto, since no callers were using the new argument.] --- src/ask-password/ask-password.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/ask-password') diff --git a/src/ask-password/ask-password.c b/src/ask-password/ask-password.c index 5c37cffc22..1ce8776d8a 100644 --- a/src/ask-password/ask-password.c +++ b/src/ask-password/ask-password.c @@ -45,6 +45,7 @@ static const char *arg_icon = NULL; static const char *arg_id = NULL; static const char *arg_message = NULL; +static bool arg_echo = false; static bool arg_use_tty = true; static usec_t arg_timeout = DEFAULT_TIMEOUT_USEC; static bool arg_accept_cached = false; @@ -56,6 +57,7 @@ static void help(void) { " -h --help Show this help\n" " --icon=NAME Icon name\n" " --timeout=SEC Timeout in sec\n" + " --echo Do not mask input (useful for usernames)\n" " --no-tty Ask question via agent even on TTY\n" " --accept-cached Accept cached passwords\n" " --multiple List multiple passwords if available\n" @@ -68,6 +70,7 @@ static int parse_argv(int argc, char *argv[]) { enum { ARG_ICON = 0x100, ARG_TIMEOUT, + ARG_ECHO, ARG_NO_TTY, ARG_ACCEPT_CACHED, ARG_MULTIPLE, @@ -78,6 +81,7 @@ static int parse_argv(int argc, char *argv[]) { { "help", no_argument, NULL, 'h' }, { "icon", required_argument, NULL, ARG_ICON }, { "timeout", required_argument, NULL, ARG_TIMEOUT }, + { "echo", no_argument, NULL, ARG_ECHO }, { "no-tty", no_argument, NULL, ARG_NO_TTY }, { "accept-cached", no_argument, NULL, ARG_ACCEPT_CACHED }, { "multiple", no_argument, NULL, ARG_MULTIPLE }, @@ -109,6 +113,10 @@ static int parse_argv(int argc, char *argv[]) { } break; + case ARG_ECHO: + arg_echo = true; + break; + case ARG_NO_TTY: arg_use_tty = false; break; @@ -160,7 +168,7 @@ int main(int argc, char *argv[]) { if (arg_use_tty && isatty(STDIN_FILENO)) { char *password = NULL; - if ((r = ask_password_tty(arg_message, timeout, NULL, &password)) >= 0) { + if ((r = ask_password_tty(arg_message, timeout, arg_echo, NULL, &password)) >= 0) { puts(password); free(password); } @@ -168,7 +176,7 @@ int main(int argc, char *argv[]) { } else { char **l; - if ((r = ask_password_agent(arg_message, arg_icon, arg_id, timeout, arg_accept_cached, &l)) >= 0) { + if ((r = ask_password_agent(arg_message, arg_icon, arg_id, timeout, arg_echo, arg_accept_cached, &l)) >= 0) { char **p; STRV_FOREACH(p, l) { -- cgit v1.2.3-54-g00ecf