summaryrefslogtreecommitdiff
path: root/src/ask-password
diff options
context:
space:
mode:
authorChristian Hesse <mail@eworm.de>2021-05-26 22:38:30 +0200
committerChristian Hesse <mail@eworm.de>2021-05-31 21:13:31 +0200
commite390c34d001187b8c18760e6ce33b72117c59ff1 (patch)
tree258c5b2e6f4b9910d5392bdc9e435d5820c94a17 /src/ask-password
parent4858bc0d8453bfbadf46aecd291e886d2a8a2f20 (diff)
downloadsystemd-e390c34d001187b8c18760e6ce33b72117c59ff1.tar.gz
ask-password: allow to control lock and key emoji
Giving --echo to systemd-ask-password allows to echo the user input. There's nothing secret, so do not show a lock and key emoji by default. The behavior can be controlled with --emoji=yes|no|auto. The default is auto, which defaults to yes, unless --echo is given.
Diffstat (limited to 'src/ask-password')
-rw-r--r--src/ask-password/ask-password.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/ask-password/ask-password.c b/src/ask-password/ask-password.c
index 09bcefbe66..26cf012f01 100644
--- a/src/ask-password/ask-password.c
+++ b/src/ask-password/ask-password.c
@@ -10,6 +10,7 @@
#include "log.h"
#include "macro.h"
#include "main-func.h"
+#include "parse-argument.h"
#include "pretty-print.h"
#include "strv.h"
#include "terminal-util.h"
@@ -45,6 +46,8 @@ static int help(void) {
" credentials\n"
" --timeout=SEC Timeout in seconds\n"
" --echo Do not mask input (useful for usernames)\n"
+ " --emoji=yes|no|auto\n"
+ " Show a lock and key emoji\n"
" --no-tty Ask question via agent even on TTY\n"
" --accept-cached Accept cached passwords\n"
" --multiple List multiple passwords if available\n"
@@ -64,6 +67,7 @@ static int parse_argv(int argc, char *argv[]) {
ARG_ICON = 0x100,
ARG_TIMEOUT,
ARG_ECHO,
+ ARG_EMOJI,
ARG_NO_TTY,
ARG_ACCEPT_CACHED,
ARG_MULTIPLE,
@@ -80,6 +84,7 @@ static int parse_argv(int argc, char *argv[]) {
{ "icon", required_argument, NULL, ARG_ICON },
{ "timeout", required_argument, NULL, ARG_TIMEOUT },
{ "echo", no_argument, NULL, ARG_ECHO },
+ { "emoji", required_argument, NULL, ARG_EMOJI },
{ "no-tty", no_argument, NULL, ARG_NO_TTY },
{ "accept-cached", no_argument, NULL, ARG_ACCEPT_CACHED },
{ "multiple", no_argument, NULL, ARG_MULTIPLE },
@@ -90,6 +95,7 @@ static int parse_argv(int argc, char *argv[]) {
{}
};
+ const char *emoji = NULL;
int c;
assert(argc >= 0);
@@ -120,6 +126,10 @@ static int parse_argv(int argc, char *argv[]) {
arg_flags |= ASK_PASSWORD_ECHO;
break;
+ case ARG_EMOJI:
+ emoji = optarg;
+ break;
+
case ARG_NO_TTY:
arg_flags |= ASK_PASSWORD_NO_TTY;
break;
@@ -155,6 +165,18 @@ static int parse_argv(int argc, char *argv[]) {
assert_not_reached("Unhandled option");
}
+ if (isempty(emoji) || streq(emoji, "auto"))
+ SET_FLAG(arg_flags, ASK_PASSWORD_HIDE_EMOJI, FLAGS_SET(arg_flags, ASK_PASSWORD_ECHO));
+ else {
+ int r;
+ bool b;
+
+ r = parse_boolean_argument("--emoji=", emoji, &b);
+ if (r < 0)
+ return r;
+ SET_FLAG(arg_flags, ASK_PASSWORD_HIDE_EMOJI, !b);
+ }
+
if (argc > optind) {
arg_message = strv_join(argv + optind, " ");
if (!arg_message)