ask-password.c revision 601185b43da638b1c74153deae01dbd518680889
/*-*- 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 <assert.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/signalfd.h>
#include <getopt.h>
#include <termios.h>
#include <limits.h>
#include <stddef.h>
#include "log.h"
#include "macro.h"
#include "util.h"
#include "strv.h"
#include "ask-password-api.h"
#include "def.h"
static const char *arg_message = NULL;
static bool arg_use_tty = true;
static bool arg_accept_cached = false;
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"
" --timeout=SEC Timeout in sec\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_NO_TTY:
arg_use_tty = false;
break;
case ARG_ACCEPT_CACHED:
arg_accept_cached = true;
break;
case ARG_MULTIPLE:
arg_multiple = true;
break;
case ARG_ID:
break;
case '?':
return -EINVAL;
default:
assert_not_reached("Unhandled option");
}
return -EINVAL;
}
return 1;
}
int r;
log_open();
if (r <= 0)
goto finish;
if (arg_timeout > 0)
else
timeout = 0;
}
} else {
char **l;
char **p;
STRV_FOREACH(p, l) {
puts(*p);
if (!arg_multiple)
break;
}
strv_free(l);
}
}
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}