</para></listitem>
</varlistentry>
+ <varlistentry>
+ <term><option>--echo</option></term>
+
+ <listitem><para>Echo the user input
+ instead of masking it. This is useful
+ when using
+ <filename>systemd-ask-password</filename>
+ to query for usernames.
+ </para></listitem>
+ </varlistentry>
+
<varlistentry>
<term><option>--no-tty</option></term>
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;
" -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"
enum {
ARG_ICON = 0x100,
ARG_TIMEOUT,
+ ARG_ECHO,
ARG_NO_TTY,
ARG_ACCEPT_CACHED,
ARG_MULTIPLE,
{ "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 },
}
break;
+ case ARG_ECHO:
+ arg_echo = true;
+ break;
+
case ARG_NO_TTY:
arg_use_tty = false;
break;
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);
}
} 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) {
for (;;) {
_cleanup_free_ char *a = NULL, *b = NULL;
- r = ask_password_tty(msg1, 0, NULL, &a);
+ r = ask_password_tty(msg1, 0, false, NULL, &a);
if (r < 0) {
log_error("Failed to query root password: %s", strerror(-r));
return r;
break;
}
- r = ask_password_tty(msg2, 0, NULL, &b);
+ r = ask_password_tty(msg2, 0, false, NULL, &b);
if (r < 0) {
log_error("Failed to query root password: %s", strerror(-r));
clear_string(a);
int ask_password_tty(
const char *message,
usec_t until,
+ bool echo,
const char *flag_file,
char **_passphrase) {
passphrase[p++] = c;
if (!silent_mode && ttyfd >= 0)
- loop_write(ttyfd, "*", 1, false);
+ loop_write(ttyfd, echo ? &c : "*", 1, false);
dirty = true;
}
const char *icon,
const char *id,
usec_t until,
+ bool echo,
bool accept_cached,
char ***_passphrases) {
"PID="PID_FMT"\n"
"Socket=%s\n"
"AcceptCached=%i\n"
+ "Echo=%i\n"
"NotAfter="USEC_FMT"\n",
getpid(),
socket_name,
accept_cached ? 1 : 0,
+ echo ? 1 : 0,
until);
if (message)
int r;
char *s = NULL, **l = NULL;
- r = ask_password_tty(message, until, NULL, &s);
+ r = ask_password_tty(message, until, false, NULL, &s);
if (r < 0)
return r;
*_passphrases = l;
return r;
} else
- return ask_password_agent(message, icon, id, until, accept_cached, _passphrases);
+ return ask_password_agent(message, icon, id, until, false, accept_cached, _passphrases);
}
#include "util.h"
-int ask_password_tty(const char *message, usec_t until, const char *flag_file, char **_passphrase);
+int ask_password_tty(const char *message, usec_t until, bool echo, const char *flag_file, char **_passphrase);
int ask_password_agent(const char *message, const char *icon, const char *id,
- usec_t until, bool accept_cached, char ***_passphrases);
+ usec_t until, bool echo, bool accept_cached, char ***_passphrases);
int ask_password_auto(const char *message, const char *icon, const char *id,
usec_t until, bool accept_cached, char ***_passphrases);
_cleanup_free_ char *socket_name = NULL, *message = NULL, *packet = NULL;
uint64_t not_after = 0;
unsigned pid = 0;
- bool accept_cached = false;
+ bool accept_cached = false, echo = false;
const ConfigTableItem items[] = {
{ "Ask", "Socket", config_parse_string, 0, &socket_name },
{ "Ask", "Message", config_parse_string, 0, &message },
{ "Ask", "PID", config_parse_unsigned, 0, &pid },
{ "Ask", "AcceptCached", config_parse_bool, 0, &accept_cached },
+ { "Ask", "Echo", config_parse_bool, 0, &echo },
{}
};
return tty_fd;
}
- r = ask_password_tty(message, not_after, filename, &password);
+ r = ask_password_tty(message, not_after, echo, filename, &password);
if (arg_console) {
safe_close(tty_fd);