ask-password-api.c revision 9c4615fb09f559642742d3698ecb5a430c698230
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk This file is part of systemd.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk Copyright 2010 Lennart Poettering
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk systemd is free software; you can redistribute it and/or modify it
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk under the terms of the GNU Lesser General Public License as published by
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk the Free Software Foundation; either version 2.1 of the License, or
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk (at your option) any later version.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk systemd is distributed in the hope that it will be useful, but
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk WITHOUT ANY WARRANTY; without even the implied warranty of
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk Lesser General Public License for more details.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk You should have received a copy of the GNU Lesser General Public License
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk along with systemd; If not, see <http://www.gnu.org/licenses/>.
dff2cc5646d4437ab9e0cb1dcb59da65462a5938jeff.schenk#define KEYRING_TIMEOUT_USEC ((5 * USEC_PER_MINUTE) / 2)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkstatic int lookup_key(const char *keyname, key_serial_t *ret) {
return negative_errno();
p = new(char, m);
return -ENOMEM;
return -errno;
memory_erase(p, n);
free(p);
l = strv_parse_nulstr(p, n);
return -ENOMEM;
memory_erase(p, n);
*ret = l;
size_t n;
} else if (r != -ENOKEY)
r = strv_make_nulstr(l, &p, &n);
assert(n > 0);
memory_erase(p, n);
return -errno;
(unsigned long) serial,
return -EUNATCH;
return -ENOKEY;
if (ttyfd < 0)
int ask_password_tty(
const char *message,
const char *keyname,
const char *flag_file,
char **ret) {
size_t p = 0;
bool reset_tty = false;
bool dirty = false;
return -EUNATCH;
if (!message)
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 (ttyfd >= 0)
} else if (ttyfd >= 0)
if (ttyfd >= 0)
passphrase[p++] = c;
dirty = true;
r = -ENOMEM;
goto finish;
if (keyname)
*ret = x;
if (fd < 0)
return -errno;
snprintf(sa.un.sun_path, sizeof(sa.un.sun_path)-1, "/run/systemd/ask-password/sck.%" PRIx64, random_u64());
return -errno;
return -errno;
return -ENOMEM;
*name = c;
r = fd;
int ask_password_agent(
const char *message,
const char *icon,
const char *id,
const char *keyname,
char ***ret) {
return -EUNATCH;
if (fd < 0) {
r = fd;
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)
r = fflush_and_check(f);
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) {
l = strv_free(l);
r = -ECANCELED;
goto finish;
if (keyname)
*ret = l;
l = NULL;
if (socket_name)
if (final[0])
int ask_password_auto(
const char *message,
const char *icon,
const char *id,
const char *keyname,
char ***ret) {
if (r != -ENOKEY)
r = strv_push(&l, s);
string_erase(s);
free(s);
return -ENOMEM;
*ret = l;
return -EUNATCH;