ask-password-api.c revision 24882e06c135584f16f31ba8a00fecde8b7f6fad
260672bd3f54ac0cf5bfc2032c7f5a51991c9f4aChad Kienle/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
260672bd3f54ac0cf5bfc2032c7f5a51991c9f4aChad Kienle This file is part of systemd.
12215e8cf03be7141191f455a58ff6abb9129c98Andi Egloff Copyright 2010 Lennart Poettering
260672bd3f54ac0cf5bfc2032c7f5a51991c9f4aChad Kienle systemd is free software; you can redistribute it and/or modify it
260672bd3f54ac0cf5bfc2032c7f5a51991c9f4aChad Kienle under the terms of the GNU Lesser General Public License as published by
260672bd3f54ac0cf5bfc2032c7f5a51991c9f4aChad Kienle the Free Software Foundation; either version 2.1 of the License, or
260672bd3f54ac0cf5bfc2032c7f5a51991c9f4aChad Kienle (at your option) any later version.
along with systemd; If not, see <http://www.gnu.org/licenses/>.
#include <stdbool.h>
#include <termios.h>
#include <unistd.h>
#include <poll.h>
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <stddef.h>
#include "util.h"
#include "formats-util.h"
#include "mkdir.h"
#include "strv.h"
#include "random-util.h"
#include "terminal-util.h"
#include "signal-util.h"
#include "ask-password-api.h"
if (ttyfd < 0)
int ask_password_tty(
const char *message,
bool echo,
const char *flag_file,
char **_passphrase) {
size_t p = 0;
bool reset_tty = false;
bool silent_mode = false;
bool dirty = false;
if (flag_file) {
if (notify < 0) {
r = -errno;
goto finish;
r = -errno;
goto finish;
if (ttyfd >= 0) {
r = -errno;
goto finish;
r = -errno;
goto finish;
reset_tty = true;
ssize_t n;
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;
r = -errno;
goto finish;
if (!silent_mode)
if (!silent_mode)
silent_mode = true;
if (ttyfd >= 0)
} else if (ttyfd >= 0)
silent_mode = true;
if (ttyfd >= 0)
passphrase[p++] = c;
dirty = true;
r = -ENOMEM;
goto finish;
*_passphrase = x;
int fd;
} sa = {
if (fd < 0)
snprintf(sa.un.sun_path, sizeof(sa.un.sun_path)-1, "/run/systemd/ask-password/sck.%" PRIx64, random_u64());
r = -errno;
goto fail;
r = -errno;
goto fail;
r = log_oom();
goto fail;
*name = c;
return fd;
fail:
int ask_password_agent(
const char *message,
const char *icon,
const char *id,
bool echo,
bool accept_cached,
char ***_passphrases) {
if (fd < 0) {
r = -errno;
goto finish;
r = -errno;
goto finish;
if (signal_fd < 0) {
r = -errno;
goto finish;
if (socket_fd < 0) {
r = socket_fd;
goto finish;
fprintf(f,
getpid(),
until);
if (message)
if (icon)
if (id)
fflush(f);
if (ferror(f)) {
r = -errno;
goto finish;
r = -errno;
goto finish;
} control;
ssize_t n;
usec_t t;
r = -ETIME;
goto finish;
r = -errno;
goto finish;
r = -ETIME;
goto finish;
r = -EINTR;
goto finish;
r = -EIO;
goto finish;
r = -errno;
goto finish;
r = -ENOMEM;
goto finish;
if (strv_length(l) <= 0) {
strv_free(l);
*_passphrases = l;
r = -ECANCELED;
goto finish;
if (socket_name)
if (final[0])
r = strv_consume(&l, s);
*_passphrases = l;