chiark / gitweb /
ask-password: Add --echo to enable echoing the user input
[elogind.git] / src / ask-password / ask-password.c
index 5c37cff..1ce8776 100644 (file)
@@ -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) {