ask-password.c revision 1602b008531ba6e0c704588cb2643daef26b71d9
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2010 Lennart Poettering
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <errno.h>
#include <getopt.h>
#include <stddef.h>
#include <unistd.h>
#include "ask-password-api.h"
#include "def.h"
#include "log.h"
#include "macro.h"
#include "strv.h"
static const char *arg_keyname = NULL;
static char *arg_message = NULL;
static bool arg_multiple = false;
static void help(void) {
printf("%s [OPTIONS...] MESSAGE\n\n"
"Query the user for a system passphrase, via the TTY or an UI agent.\n\n"
" -h --help Show this help\n"
" --icon=NAME Icon name\n"
" --keyname=NAME Kernel key name for caching passwords (e.g. \"cryptsetup\")\n"
" --timeout=SEC Timeout in seconds\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,
};
{}
};
int c;
switch (c) {
case 'h':
help();
return 0;
case ARG_ICON:
break;
case ARG_TIMEOUT:
return -EINVAL;
}
break;
case ARG_ECHO:
break;
case ARG_NO_TTY:
break;
case ARG_ACCEPT_CACHED:
break;
case ARG_MULTIPLE:
arg_multiple = true;
break;
case ARG_ID:
break;
case ARG_KEYNAME:
break;
case '?':
return -EINVAL;
default:
assert_not_reached("Unhandled option");
}
if (!arg_message)
return log_oom();
}
return 1;
}
_cleanup_strv_free_ char **l = NULL;
char **p;
int r;
log_open();
if (r <= 0)
goto finish;
if (arg_timeout > 0)
else
timeout = 0;
if (r < 0) {
log_error_errno(r, "Failed to query password: %m");
goto finish;
}
STRV_FOREACH(p, l) {
puts(*p);
if (!arg_multiple)
break;
}
strv_erase(l);
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}