tty-ask-password-agent.c revision cb90460e04743dd66dea37534af601786c428206
e2c5185af3c50d9510e5df68aa37abdc6c0d3aacChristopher Kiick/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
e2c5185af3c50d9510e5df68aa37abdc6c0d3aacChristopher Kiick This file is part of systemd.
e2c5185af3c50d9510e5df68aa37abdc6c0d3aacChristopher Kiick Copyright 2010 Lennart Poettering
e2c5185af3c50d9510e5df68aa37abdc6c0d3aacChristopher Kiick systemd is free software; you can redistribute it and/or modify it
e2c5185af3c50d9510e5df68aa37abdc6c0d3aacChristopher Kiick under the terms of the GNU Lesser General Public License as published by
e2c5185af3c50d9510e5df68aa37abdc6c0d3aacChristopher Kiick the Free Software Foundation; either version 2.1 of the License, or
e2c5185af3c50d9510e5df68aa37abdc6c0d3aacChristopher Kiick (at your option) any later version.
e2c5185af3c50d9510e5df68aa37abdc6c0d3aacChristopher Kiick systemd is distributed in the hope that it will be useful, but
e2c5185af3c50d9510e5df68aa37abdc6c0d3aacChristopher Kiick WITHOUT ANY WARRANTY; without even the implied warranty of
e2c5185af3c50d9510e5df68aa37abdc6c0d3aacChristopher Kiick MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
e2c5185af3c50d9510e5df68aa37abdc6c0d3aacChristopher Kiick Lesser General Public License for more details.
e2c5185af3c50d9510e5df68aa37abdc6c0d3aacChristopher Kiick You should have received a copy of the GNU Lesser General Public License
e2c5185af3c50d9510e5df68aa37abdc6c0d3aacChristopher Kiick along with systemd; If not, see <http://www.gnu.org/licenses/>.
e2c5185af3c50d9510e5df68aa37abdc6c0d3aacChristopher Kiickstatic bool arg_plymouth = false;
e2c5185af3c50d9510e5df68aa37abdc6c0d3aacChristopher Kiickstatic bool arg_console = false;
const char *message,
const char *flag_file,
bool accept_cached,
char ***_passphrases) {
ssize_t k;
size_t p = 0;
if (flag_file) {
r = -errno;
goto finish;
r = -errno;
goto finish;
r = -errno;
goto finish;
if (connect(fd, &sa.sa, offsetof(struct sockaddr_un, sun_path) + 1 + strlen(sa.un.sun_path+1)) < 0) {
r = -errno;
goto finish;
if (accept_cached) {
if (!packet) {
r = -ENOMEM;
goto finish;
r = k < 0 ? (int) k : -EIO;
goto finish;
if (until > 0) {
usec_t y;
if (y > until) {
r = -ETIME;
goto finish;
if (flag_file)
r = -errno;
goto finish;
r = -errno;
goto finish;
r = -ETIME;
goto finish;
goto finish;
if (accept_cached) {
r = -ENOMEM;
goto finish;
r = k < 0 ? (int) k : -EIO;
goto finish;
accept_cached = false;
r = -ENOENT;
goto finish;
r = -EIO;
goto finish;
r = -ENOMEM;
goto finish;
*_passphrases = l;
r = -EIO;
goto finish;
if (notify >= 0)
if (fd >= 0)
unsigned pid = 0;
bool accept_cached = false;
FILE *f;
return -errno;
goto finish;
if (!socket_name) {
r = -EBADMSG;
goto finish;
if (not_after > 0) {
goto finish;
if (pid > 0 &&
goto finish;
char *_wall;
pid) < 0) {
r = log_oom();
goto finish;
} sa = {};
goto finish;
if (arg_plymouth) {
r = -ENOMEM;
char *password;
if (arg_console)
r = tty_fd;
goto finish;
if (arg_console) {
r = -ENOMEM;
goto finish;
goto finish;
r = -errno;
goto finish;
if (sendto(socket_fd, packet, packet_length, MSG_NOSIGNAL, &sa.sa, offsetof(struct sockaddr_un, sun_path) + strlen(socket_name)) < 0) {
r = -errno;
goto finish;
fclose(f);
if (socket_fd >= 0)
static int wall_tty_block(void) {
int fd, r;
return -ENOMEM;
free(p);
if (fd < 0)
return -errno;
return fd;
int fd, k;
free(p);
if (asprintf(&p, "/run/systemd/ask-password-block/%u:%u", major(st.st_rdev), minor(st.st_rdev)) < 0)
free(p);
if (fd < 0)
static int show_passwords(void) {
DIR *d;
return -errno;
char *wall;
r = log_oom();
goto finish;
free(p);
if (wall) {
closedir(d);
static int watch_passwords(void) {
r = -errno;
goto finish;
r = -errno;
goto finish;
r = -errno;
goto finish;
if ((r = show_passwords()) < 0)
r = -errno;
goto finish;
if (notify >= 0)
if (signal_fd >= 0)
if (tty_block_fd >= 0)
static int help(void) {
help();
case ARG_VERSION:
case ARG_LIST:
case ARG_QUERY:
case ARG_WATCH:
case ARG_WALL:
case ARG_PLYMOUTH:
arg_plymouth = true;
case ARG_CONSOLE:
arg_console = true;
return -EINVAL;
return -EINVAL;
help();
return -EINVAL;
log_open();
goto finish;
if (arg_console) {
setsid();
r = watch_passwords();
r = show_passwords();