]>
Commit | Line | Data |
---|---|---|
db9ecf05 | 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
00843602 | 2 | |
7f4e0805 LP |
3 | #include <errno.h> |
4 | #include <fcntl.h> | |
a8fbdf54 TA |
5 | #include <inttypes.h> |
6 | #include <limits.h> | |
00843602 | 7 | #include <stdbool.h> |
7f4e0805 | 8 | #include <stddef.h> |
a8fbdf54 TA |
9 | #include <stdint.h> |
10 | #include <stdio.h> | |
11 | #include <stdlib.h> | |
00843602 | 12 | #include <sys/inotify.h> |
7f4e0805 | 13 | #include <sys/signalfd.h> |
a8fbdf54 TA |
14 | #include <sys/stat.h> |
15 | #include <sys/time.h> | |
16 | #include <sys/uio.h> | |
00843602 LP |
17 | #include <sys/un.h> |
18 | #include <termios.h> | |
19 | #include <unistd.h> | |
7f4e0805 | 20 | |
b5efdb8a | 21 | #include "alloc-util.h" |
3ffd4af2 | 22 | #include "ask-password-api.h" |
28db6fbf | 23 | #include "constants.h" |
8806bb4b | 24 | #include "creds-util.h" |
3ffd4af2 | 25 | #include "fd-util.h" |
0d39fa9c | 26 | #include "fileio.h" |
f97b34a6 | 27 | #include "format-util.h" |
c7b7d74e | 28 | #include "fs-util.h" |
d8e32c47 | 29 | #include "glyph-util.h" |
c004493c | 30 | #include "io-util.h" |
cbae575e | 31 | #include "keyring-util.h" |
a8fbdf54 TA |
32 | #include "log.h" |
33 | #include "macro.h" | |
0a970718 | 34 | #include "memory-util.h" |
f5947a5e | 35 | #include "missing_syscall.h" |
35cd0ba5 | 36 | #include "mkdir-label.h" |
08af3cc5 | 37 | #include "nulstr-util.h" |
df0ff127 | 38 | #include "process-util.h" |
3df3e884 | 39 | #include "random-util.h" |
24882e06 | 40 | #include "signal-util.h" |
00843602 | 41 | #include "socket-util.h" |
07630cea | 42 | #include "string-util.h" |
00843602 LP |
43 | #include "strv.h" |
44 | #include "terminal-util.h" | |
a8fbdf54 | 45 | #include "time-util.h" |
e4de7287 | 46 | #include "tmpfile-util.h" |
affb60b1 | 47 | #include "umask-util.h" |
f3149d57 | 48 | #include "utf8.h" |
7f4e0805 | 49 | |
e287086b LP |
50 | #define KEYRING_TIMEOUT_USEC ((5 * USEC_PER_MINUTE) / 2) |
51 | ||
52 | static int lookup_key(const char *keyname, key_serial_t *ret) { | |
53 | key_serial_t serial; | |
54 | ||
55 | assert(keyname); | |
56 | assert(ret); | |
57 | ||
58 | serial = request_key("user", keyname, NULL, 0); | |
59 | if (serial == -1) | |
9c4615fb | 60 | return negative_errno(); |
e287086b LP |
61 | |
62 | *ret = serial; | |
63 | return 0; | |
64 | } | |
65 | ||
66 | static int retrieve_key(key_serial_t serial, char ***ret) { | |
cbae575e | 67 | _cleanup_(erase_and_freep) void *p = NULL; |
e287086b | 68 | char **l; |
cbae575e LP |
69 | size_t n; |
70 | int r; | |
e287086b LP |
71 | |
72 | assert(ret); | |
73 | ||
cbae575e LP |
74 | r = keyring_read(serial, &p, &n); |
75 | if (r < 0) | |
76 | return r; | |
77 | ||
78 | l = strv_parse_nulstr(p, n); | |
e287086b LP |
79 | if (!l) |
80 | return -ENOMEM; | |
81 | ||
82 | *ret = l; | |
83 | return 0; | |
84 | } | |
85 | ||
86 | static int add_to_keyring(const char *keyname, AskPasswordFlags flags, char **passwords) { | |
ab84f5b9 | 87 | _cleanup_strv_free_erase_ char **l = NULL; |
e693a932 | 88 | _cleanup_(erase_and_freep) char *p = NULL; |
e287086b LP |
89 | key_serial_t serial; |
90 | size_t n; | |
91 | int r; | |
92 | ||
93 | assert(keyname); | |
e287086b | 94 | |
9cb5bf91 | 95 | if (!FLAGS_SET(flags, ASK_PASSWORD_PUSH_CACHE)) |
e287086b | 96 | return 0; |
e013e10d LP |
97 | if (strv_isempty(passwords)) |
98 | return 0; | |
e287086b LP |
99 | |
100 | r = lookup_key(keyname, &serial); | |
101 | if (r >= 0) { | |
102 | r = retrieve_key(serial, &l); | |
103 | if (r < 0) | |
104 | return r; | |
105 | } else if (r != -ENOKEY) | |
106 | return r; | |
107 | ||
108 | r = strv_extend_strv(&l, passwords, true); | |
109 | if (r <= 0) | |
110 | return r; | |
111 | ||
112 | r = strv_make_nulstr(l, &p, &n); | |
113 | if (r < 0) | |
114 | return r; | |
115 | ||
76078ad8 LP |
116 | /* chop off the final NUL byte. We do this because we want to use the separator NUL bytes only if we |
117 | * have multiple passwords. */ | |
118 | n = LESS_BY(n, (size_t) 1); | |
119 | ||
b60df13b | 120 | serial = add_key("user", keyname, p, n, KEY_SPEC_USER_KEYRING); |
e287086b LP |
121 | if (serial == -1) |
122 | return -errno; | |
123 | ||
124 | if (keyctl(KEYCTL_SET_TIMEOUT, | |
125 | (unsigned long) serial, | |
126 | (unsigned long) DIV_ROUND_UP(KEYRING_TIMEOUT_USEC, USEC_PER_SEC), 0, 0) < 0) | |
e3ac53a2 | 127 | log_debug_errno(errno, "Failed to adjust kernel keyring key timeout: %m"); |
e287086b | 128 | |
c7b7d74e XF |
129 | /* Tell everyone to check the keyring */ |
130 | (void) touch("/run/systemd/ask-password"); | |
131 | ||
e3ac53a2 | 132 | log_debug("Added key to kernel keyring as %" PRIi32 ".", serial); |
e287086b LP |
133 | |
134 | return 1; | |
135 | } | |
136 | ||
137 | static int add_to_keyring_and_log(const char *keyname, AskPasswordFlags flags, char **passwords) { | |
138 | int r; | |
139 | ||
140 | assert(keyname); | |
e287086b LP |
141 | |
142 | r = add_to_keyring(keyname, flags, passwords); | |
143 | if (r < 0) | |
e3ac53a2 | 144 | return log_debug_errno(r, "Failed to add password to kernel keyring: %m"); |
e287086b LP |
145 | |
146 | return 0; | |
147 | } | |
148 | ||
8a111277 | 149 | static int ask_password_keyring(const char *keyname, AskPasswordFlags flags, char ***ret) { |
e287086b LP |
150 | |
151 | key_serial_t serial; | |
152 | int r; | |
153 | ||
154 | assert(keyname); | |
155 | assert(ret); | |
156 | ||
9cb5bf91 | 157 | if (!FLAGS_SET(flags, ASK_PASSWORD_ACCEPT_CACHED)) |
e287086b LP |
158 | return -EUNATCH; |
159 | ||
160 | r = lookup_key(keyname, &serial); | |
16edfadc YW |
161 | if (r < 0) { |
162 | /* when retrieving the distinction between "kernel or container manager don't support | |
163 | * or allow this" and "no matching key known" doesn't matter. Note that we propagate | |
164 | * EACCESS here (even if EPERM not) since that is used if the keyring is available but | |
165 | * we lack access to the key. */ | |
166 | if (ERRNO_IS_NOT_SUPPORTED(r) || r == -EPERM) | |
167 | return -ENOKEY; | |
168 | ||
e287086b | 169 | return r; |
16edfadc | 170 | } |
e287086b LP |
171 | |
172 | return retrieve_key(serial, ret); | |
173 | } | |
174 | ||
8e9d1eec | 175 | static int backspace_chars(int ttyfd, size_t p) { |
58fc840b | 176 | if (ttyfd < 0) |
8e9d1eec | 177 | return 0; |
58fc840b | 178 | |
8e9d1eec ZJS |
179 | _cleanup_free_ char *buf = malloc_multiply(3, p); |
180 | if (!buf) | |
181 | return log_oom(); | |
58fc840b | 182 | |
8e9d1eec ZJS |
183 | for (size_t i = 0; i < p; i++) |
184 | memcpy(buf + 3 * i, "\b \b", 3); | |
58fc840b | 185 | |
8e9d1eec ZJS |
186 | return loop_write(ttyfd, buf, 3*p, false); |
187 | } | |
fd6ac62c | 188 | |
8e9d1eec | 189 | static int backspace_string(int ttyfd, const char *str) { |
fd6ac62c LP |
190 | assert(str); |
191 | ||
f95dbcc2 | 192 | /* Backspaces through enough characters to entirely undo printing of the specified string. */ |
fd6ac62c | 193 | |
8e9d1eec ZJS |
194 | if (ttyfd < 0) |
195 | return 0; | |
196 | ||
197 | size_t m = utf8_n_codepoints(str); | |
f5fbe71d | 198 | if (m == SIZE_MAX) |
8e9d1eec ZJS |
199 | m = strlen(str); /* Not a valid UTF-8 string? If so, let's backspace the number of bytes |
200 | * output. Most likely this happened because we are not in an UTF-8 locale, | |
201 | * and in that case that is the correct thing to do. And even if it's not, | |
202 | * terminals tend to stop backspacing at the leftmost column, hence | |
203 | * backspacing too much should be mostly OK. */ | |
fd6ac62c | 204 | |
8e9d1eec | 205 | return backspace_chars(ttyfd, m); |
fd6ac62c LP |
206 | } |
207 | ||
6b2faba7 FB |
208 | int ask_password_plymouth( |
209 | const char *message, | |
210 | usec_t until, | |
211 | AskPasswordFlags flags, | |
212 | const char *flag_file, | |
213 | char ***ret) { | |
214 | ||
215 | static const union sockaddr_union sa = PLYMOUTH_SOCKET; | |
254d1313 | 216 | _cleanup_close_ int fd = -EBADF, notify = -EBADF; |
6b2faba7 FB |
217 | _cleanup_free_ char *packet = NULL; |
218 | ssize_t k; | |
219 | int r, n; | |
220 | struct pollfd pollfd[2] = {}; | |
221 | char buffer[LINE_MAX]; | |
222 | size_t p = 0; | |
223 | enum { | |
224 | POLL_SOCKET, | |
225 | POLL_INOTIFY | |
226 | }; | |
227 | ||
228 | assert(ret); | |
229 | ||
66bff73b LP |
230 | if (!message) |
231 | message = "Password:"; | |
232 | ||
6b2faba7 FB |
233 | if (flag_file) { |
234 | notify = inotify_init1(IN_CLOEXEC|IN_NONBLOCK); | |
235 | if (notify < 0) | |
236 | return -errno; | |
237 | ||
108dfff2 | 238 | if (inotify_add_watch(notify, flag_file, IN_ATTRIB) < 0) /* for the link count */ |
6b2faba7 FB |
239 | return -errno; |
240 | } | |
241 | ||
242 | fd = socket(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0); | |
243 | if (fd < 0) | |
244 | return -errno; | |
245 | ||
108dfff2 | 246 | if (connect(fd, &sa.sa, SOCKADDR_UN_LEN(sa.un)) < 0) |
6b2faba7 FB |
247 | return -errno; |
248 | ||
9cb5bf91 | 249 | if (FLAGS_SET(flags, ASK_PASSWORD_ACCEPT_CACHED)) { |
6b2faba7 FB |
250 | packet = strdup("c"); |
251 | n = 1; | |
252 | } else if (asprintf(&packet, "*\002%c%s%n", (int) (strlen(message) + 1), message, &n) < 0) | |
253 | packet = NULL; | |
254 | if (!packet) | |
255 | return -ENOMEM; | |
256 | ||
257 | r = loop_write(fd, packet, n + 1, true); | |
258 | if (r < 0) | |
259 | return r; | |
260 | ||
261 | pollfd[POLL_SOCKET].fd = fd; | |
262 | pollfd[POLL_SOCKET].events = POLLIN; | |
263 | pollfd[POLL_INOTIFY].fd = notify; | |
264 | pollfd[POLL_INOTIFY].events = POLLIN; | |
265 | ||
266 | for (;;) { | |
d9e2af0a | 267 | usec_t timeout; |
6b2faba7 | 268 | |
d9e2af0a YW |
269 | if (until > 0) |
270 | timeout = usec_sub_unsigned(until, now(CLOCK_MONOTONIC)); | |
271 | else | |
272 | timeout = USEC_INFINITY; | |
6b2faba7 FB |
273 | |
274 | if (flag_file && access(flag_file, F_OK) < 0) { | |
275 | r = -errno; | |
276 | goto finish; | |
277 | } | |
278 | ||
d9e2af0a YW |
279 | r = ppoll_usec(pollfd, notify >= 0 ? 2 : 1, timeout); |
280 | if (r == -EINTR) | |
281 | continue; | |
282 | if (r < 0) | |
6b2faba7 | 283 | goto finish; |
d9e2af0a | 284 | if (r == 0) { |
6b2faba7 FB |
285 | r = -ETIME; |
286 | goto finish; | |
287 | } | |
288 | ||
289 | if (notify >= 0 && pollfd[POLL_INOTIFY].revents != 0) | |
290 | (void) flush_fd(notify); | |
291 | ||
292 | if (pollfd[POLL_SOCKET].revents == 0) | |
293 | continue; | |
294 | ||
295 | k = read(fd, buffer + p, sizeof(buffer) - p); | |
296 | if (k < 0) { | |
8add30a0 | 297 | if (ERRNO_IS_TRANSIENT(errno)) |
6b2faba7 FB |
298 | continue; |
299 | ||
300 | r = -errno; | |
301 | goto finish; | |
8add30a0 YW |
302 | } |
303 | if (k == 0) { | |
6b2faba7 FB |
304 | r = -EIO; |
305 | goto finish; | |
306 | } | |
307 | ||
308 | p += k; | |
309 | ||
6b2faba7 FB |
310 | if (buffer[0] == 5) { |
311 | ||
9cb5bf91 | 312 | if (FLAGS_SET(flags, ASK_PASSWORD_ACCEPT_CACHED)) { |
6b2faba7 FB |
313 | /* Hmm, first try with cached |
314 | * passwords failed, so let's retry | |
315 | * with a normal password request */ | |
316 | packet = mfree(packet); | |
317 | ||
318 | if (asprintf(&packet, "*\002%c%s%n", (int) (strlen(message) + 1), message, &n) < 0) { | |
319 | r = -ENOMEM; | |
320 | goto finish; | |
321 | } | |
322 | ||
323 | r = loop_write(fd, packet, n+1, true); | |
324 | if (r < 0) | |
325 | goto finish; | |
326 | ||
327 | flags &= ~ASK_PASSWORD_ACCEPT_CACHED; | |
328 | p = 0; | |
329 | continue; | |
330 | } | |
331 | ||
332 | /* No password, because UI not shown */ | |
333 | r = -ENOENT; | |
334 | goto finish; | |
335 | ||
336 | } else if (IN_SET(buffer[0], 2, 9)) { | |
337 | uint32_t size; | |
338 | char **l; | |
339 | ||
340 | /* One or more answers */ | |
341 | if (p < 5) | |
342 | continue; | |
343 | ||
344 | memcpy(&size, buffer+1, sizeof(size)); | |
345 | size = le32toh(size); | |
346 | if (size + 5 > sizeof(buffer)) { | |
347 | r = -EIO; | |
348 | goto finish; | |
349 | } | |
350 | ||
351 | if (p-5 < size) | |
352 | continue; | |
353 | ||
354 | l = strv_parse_nulstr(buffer + 5, size); | |
355 | if (!l) { | |
356 | r = -ENOMEM; | |
357 | goto finish; | |
358 | } | |
359 | ||
360 | *ret = l; | |
361 | break; | |
362 | ||
363 | } else { | |
364 | /* Unknown packet */ | |
365 | r = -EIO; | |
366 | goto finish; | |
367 | } | |
368 | } | |
369 | ||
370 | r = 0; | |
371 | ||
372 | finish: | |
373 | explicit_bzero_safe(buffer, sizeof(buffer)); | |
374 | return r; | |
375 | } | |
376 | ||
8aaf18e0 ZJS |
377 | #define NO_ECHO "(no echo) " |
378 | #define PRESS_TAB "(press TAB for no echo) " | |
379 | #define SKIPPED "(skipped)" | |
380 | ||
7f4e0805 | 381 | int ask_password_tty( |
daa55720 | 382 | int ttyfd, |
7f4e0805 | 383 | const char *message, |
e287086b | 384 | const char *keyname, |
7f4e0805 | 385 | usec_t until, |
e287086b | 386 | AskPasswordFlags flags, |
7f4e0805 | 387 | const char *flag_file, |
c7b7d74e | 388 | char ***ret) { |
7f4e0805 | 389 | |
088dcd8e LP |
390 | enum { |
391 | POLL_TTY, | |
392 | POLL_INOTIFY, | |
393 | _POLL_MAX, | |
394 | }; | |
395 | ||
8aaf18e0 | 396 | bool reset_tty = false, dirty = false, use_color = false, press_tab_visible = false; |
254d1313 | 397 | _cleanup_close_ int cttyfd = -EBADF, notify = -EBADF; |
7f4e0805 | 398 | struct termios old_termios, new_termios; |
f3149d57 | 399 | char passphrase[LINE_MAX + 1] = {}, *x; |
c7b7d74e | 400 | _cleanup_strv_free_erase_ char **l = NULL; |
088dcd8e | 401 | struct pollfd pollfd[_POLL_MAX]; |
f3149d57 | 402 | size_t p = 0, codepoint = 0; |
088dcd8e | 403 | int r; |
7f4e0805 | 404 | |
e287086b LP |
405 | assert(ret); |
406 | ||
9cb5bf91 | 407 | if (FLAGS_SET(flags, ASK_PASSWORD_NO_TTY)) |
e287086b LP |
408 | return -EUNATCH; |
409 | ||
410 | if (!message) | |
411 | message = "Password:"; | |
7f4e0805 | 412 | |
e390c34d | 413 | if (!FLAGS_SET(flags, ASK_PASSWORD_HIDE_EMOJI) && emoji_enabled()) |
52d199e3 LP |
414 | message = strjoina(special_glyph(SPECIAL_GLYPH_LOCK_AND_KEY), " ", message); |
415 | ||
9cb5bf91 | 416 | if (flag_file || (FLAGS_SET(flags, ASK_PASSWORD_ACCEPT_CACHED) && keyname)) { |
981e4cd3 | 417 | notify = inotify_init1(IN_CLOEXEC|IN_NONBLOCK); |
a497a296 LP |
418 | if (notify < 0) |
419 | return -errno; | |
c7b7d74e XF |
420 | } |
421 | if (flag_file) { | |
a497a296 LP |
422 | if (inotify_add_watch(notify, flag_file, IN_ATTRIB /* for the link count */) < 0) |
423 | return -errno; | |
7f4e0805 | 424 | } |
9cb5bf91 | 425 | if (FLAGS_SET(flags, ASK_PASSWORD_ACCEPT_CACHED) && keyname) { |
c7b7d74e XF |
426 | r = ask_password_keyring(keyname, flags, ret); |
427 | if (r >= 0) | |
428 | return 0; | |
429 | else if (r != -ENOKEY) | |
430 | return r; | |
431 | ||
432 | if (inotify_add_watch(notify, "/run/systemd/ask-password", IN_ATTRIB /* for mtime */) < 0) | |
433 | return -errno; | |
434 | } | |
7f4e0805 | 435 | |
daa55720 LP |
436 | /* If the caller didn't specify a TTY, then use the controlling tty, if we can. */ |
437 | if (ttyfd < 0) | |
438 | ttyfd = cttyfd = open("/dev/tty", O_RDWR|O_NOCTTY|O_CLOEXEC); | |
7f4e0805 | 439 | |
daa55720 | 440 | if (ttyfd >= 0) { |
a497a296 LP |
441 | if (tcgetattr(ttyfd, &old_termios) < 0) |
442 | return -errno; | |
7f4e0805 | 443 | |
9cb5bf91 | 444 | if (FLAGS_SET(flags, ASK_PASSWORD_CONSOLE_COLOR)) |
c2b32159 LP |
445 | use_color = dev_console_colors_enabled(); |
446 | else | |
447 | use_color = colors_enabled(); | |
448 | ||
449 | if (use_color) | |
ac7a9674 LP |
450 | (void) loop_write(ttyfd, ANSI_HIGHLIGHT, STRLEN(ANSI_HIGHLIGHT), false); |
451 | ||
452 | (void) loop_write(ttyfd, message, strlen(message), false); | |
453 | (void) loop_write(ttyfd, " ", 1, false); | |
454 | ||
9cb5bf91 | 455 | if (!FLAGS_SET(flags, ASK_PASSWORD_SILENT) && !FLAGS_SET(flags, ASK_PASSWORD_ECHO)) { |
8aaf18e0 | 456 | if (use_color) |
25e4608b | 457 | (void) loop_write(ttyfd, ansi_grey(), strlen(ansi_grey()), false); |
8aaf18e0 ZJS |
458 | (void) loop_write(ttyfd, PRESS_TAB, strlen(PRESS_TAB), false); |
459 | press_tab_visible = true; | |
460 | } | |
461 | ||
c2b32159 | 462 | if (use_color) |
ac7a9674 | 463 | (void) loop_write(ttyfd, ANSI_NORMAL, STRLEN(ANSI_NORMAL), false); |
7f4e0805 LP |
464 | |
465 | new_termios = old_termios; | |
466 | new_termios.c_lflag &= ~(ICANON|ECHO); | |
467 | new_termios.c_cc[VMIN] = 1; | |
468 | new_termios.c_cc[VTIME] = 0; | |
469 | ||
108dfff2 LP |
470 | r = RET_NERRNO(tcsetattr(ttyfd, TCSADRAIN, &new_termios)); |
471 | if (r < 0) | |
7f4e0805 | 472 | goto finish; |
7f4e0805 LP |
473 | |
474 | reset_tty = true; | |
475 | } | |
476 | ||
70dee475 LP |
477 | pollfd[POLL_TTY] = (struct pollfd) { |
478 | .fd = ttyfd >= 0 ? ttyfd : STDIN_FILENO, | |
479 | .events = POLLIN, | |
480 | }; | |
481 | pollfd[POLL_INOTIFY] = (struct pollfd) { | |
482 | .fd = notify, | |
483 | .events = POLLIN, | |
484 | }; | |
7f4e0805 LP |
485 | |
486 | for (;;) { | |
e1ed99c8 | 487 | _cleanup_(erase_char) char c; |
d9e2af0a | 488 | usec_t timeout; |
7f4e0805 LP |
489 | ssize_t n; |
490 | ||
d9e2af0a YW |
491 | if (until > 0) |
492 | timeout = usec_sub_unsigned(until, now(CLOCK_MONOTONIC)); | |
493 | else | |
494 | timeout = USEC_INFINITY; | |
7f4e0805 | 495 | |
108dfff2 LP |
496 | if (flag_file) { |
497 | r = RET_NERRNO(access(flag_file, F_OK)); | |
498 | if (r < 0) | |
7f4e0805 | 499 | goto finish; |
108dfff2 | 500 | } |
7f4e0805 | 501 | |
d9e2af0a YW |
502 | r = ppoll_usec(pollfd, notify >= 0 ? 2 : 1, timeout); |
503 | if (r == -EINTR) | |
504 | continue; | |
505 | if (r < 0) | |
7f4e0805 | 506 | goto finish; |
d9e2af0a | 507 | if (r == 0) { |
ccc80078 | 508 | r = -ETIME; |
7f4e0805 LP |
509 | goto finish; |
510 | } | |
511 | ||
1f00998c | 512 | if (notify >= 0 && pollfd[POLL_INOTIFY].revents != 0 && keyname) { |
665dfe93 | 513 | (void) flush_fd(notify); |
7f4e0805 | 514 | |
c7b7d74e XF |
515 | r = ask_password_keyring(keyname, flags, ret); |
516 | if (r >= 0) { | |
517 | r = 0; | |
518 | goto finish; | |
519 | } else if (r != -ENOKEY) | |
520 | goto finish; | |
521 | } | |
522 | ||
7f4e0805 LP |
523 | if (pollfd[POLL_TTY].revents == 0) |
524 | continue; | |
525 | ||
981e4cd3 LP |
526 | n = read(ttyfd >= 0 ? ttyfd : STDIN_FILENO, &c, 1); |
527 | if (n < 0) { | |
8add30a0 | 528 | if (ERRNO_IS_TRANSIENT(errno)) |
7f4e0805 LP |
529 | continue; |
530 | ||
531 | r = -errno; | |
532 | goto finish; | |
533 | ||
fd6ac62c | 534 | } |
7f4e0805 | 535 | |
8aaf18e0 ZJS |
536 | if (press_tab_visible) { |
537 | assert(ttyfd >= 0); | |
538 | backspace_chars(ttyfd, strlen(PRESS_TAB)); | |
539 | press_tab_visible = false; | |
540 | } | |
541 | ||
fd6ac62c LP |
542 | /* We treat EOF, newline and NUL byte all as valid end markers */ |
543 | if (n == 0 || c == '\n' || c == 0) | |
7f4e0805 | 544 | break; |
fd6ac62c | 545 | |
d325f244 FB |
546 | if (c == 4) { /* C-d also known as EOT */ |
547 | if (ttyfd >= 0) | |
8aaf18e0 | 548 | (void) loop_write(ttyfd, SKIPPED, strlen(SKIPPED), false); |
d325f244 FB |
549 | |
550 | goto skipped; | |
551 | } | |
552 | ||
fd6ac62c | 553 | if (c == 21) { /* C-u */ |
7f4e0805 | 554 | |
9cb5bf91 | 555 | if (!FLAGS_SET(flags, ASK_PASSWORD_SILENT)) |
8e9d1eec | 556 | (void) backspace_string(ttyfd, passphrase); |
fd6ac62c | 557 | |
87f54463 | 558 | explicit_bzero_safe(passphrase, sizeof(passphrase)); |
fd6ac62c | 559 | p = codepoint = 0; |
7f4e0805 | 560 | |
4c701096 | 561 | } else if (IN_SET(c, '\b', 127)) { |
58fc840b LP |
562 | |
563 | if (p > 0) { | |
fd6ac62c | 564 | size_t q; |
58fc840b | 565 | |
9cb5bf91 | 566 | if (!FLAGS_SET(flags, ASK_PASSWORD_SILENT)) |
8e9d1eec | 567 | (void) backspace_chars(ttyfd, 1); |
58fc840b | 568 | |
92e068b4 ZJS |
569 | /* Remove a full UTF-8 codepoint from the end. For that, figure out where the |
570 | * last one begins */ | |
fd6ac62c LP |
571 | q = 0; |
572 | for (;;) { | |
37ca78a3 | 573 | int z; |
fd6ac62c | 574 | |
f5fbe71d | 575 | z = utf8_encoded_valid_unichar(passphrase + q, SIZE_MAX); |
37ca78a3 | 576 | if (z <= 0) { |
f5fbe71d | 577 | q = SIZE_MAX; /* Invalid UTF8! */ |
fd6ac62c LP |
578 | break; |
579 | } | |
580 | ||
581 | if (q + z >= p) /* This one brings us over the edge */ | |
582 | break; | |
583 | ||
584 | q += z; | |
585 | } | |
586 | ||
f5fbe71d | 587 | p = codepoint = q == SIZE_MAX ? p - 1 : q; |
87f54463 | 588 | explicit_bzero_safe(passphrase + p, sizeof(passphrase) - p); |
fd6ac62c | 589 | |
9cb5bf91 | 590 | } else if (!dirty && !FLAGS_SET(flags, ASK_PASSWORD_SILENT)) { |
441dfe09 | 591 | |
e287086b | 592 | flags |= ASK_PASSWORD_SILENT; |
441dfe09 | 593 | |
92e068b4 ZJS |
594 | /* There are two ways to enter silent mode. Either by pressing backspace as |
595 | * first key (and only as first key), or ... */ | |
fd6ac62c | 596 | |
441dfe09 | 597 | if (ttyfd >= 0) |
8aaf18e0 | 598 | (void) loop_write(ttyfd, NO_ECHO, strlen(NO_ECHO), false); |
441dfe09 | 599 | |
58fc840b | 600 | } else if (ttyfd >= 0) |
ac7a9674 | 601 | (void) loop_write(ttyfd, "\a", 1, false); |
7f4e0805 | 602 | |
9cb5bf91 | 603 | } else if (c == '\t' && !FLAGS_SET(flags, ASK_PASSWORD_SILENT)) { |
58fc840b | 604 | |
8e9d1eec | 605 | (void) backspace_string(ttyfd, passphrase); |
e287086b | 606 | flags |= ASK_PASSWORD_SILENT; |
58fc840b | 607 | |
441dfe09 LP |
608 | /* ... or by pressing TAB at any time. */ |
609 | ||
58fc840b | 610 | if (ttyfd >= 0) |
8aaf18e0 | 611 | (void) loop_write(ttyfd, NO_ECHO, strlen(NO_ECHO), false); |
036eeac5 | 612 | |
fd6ac62c LP |
613 | } else if (p >= sizeof(passphrase)-1) { |
614 | ||
615 | /* Reached the size limit */ | |
616 | if (ttyfd >= 0) | |
617 | (void) loop_write(ttyfd, "\a", 1, false); | |
618 | ||
619 | } else { | |
7f4e0805 LP |
620 | passphrase[p++] = c; |
621 | ||
9cb5bf91 | 622 | if (!FLAGS_SET(flags, ASK_PASSWORD_SILENT) && ttyfd >= 0) { |
fd6ac62c | 623 | /* Check if we got a complete UTF-8 character now. If so, let's output one '*'. */ |
f5fbe71d | 624 | n = utf8_encoded_valid_unichar(passphrase + codepoint, SIZE_MAX); |
f3149d57 | 625 | if (n >= 0) { |
9cb5bf91 | 626 | if (FLAGS_SET(flags, ASK_PASSWORD_ECHO)) |
d26eef92 ZJS |
627 | (void) loop_write(ttyfd, passphrase + codepoint, n, false); |
628 | else | |
629 | (void) loop_write(ttyfd, "*", 1, false); | |
f3149d57 | 630 | codepoint = p; |
f3149d57 ZJS |
631 | } |
632 | } | |
441dfe09 LP |
633 | |
634 | dirty = true; | |
7f4e0805 LP |
635 | } |
636 | } | |
637 | ||
981e4cd3 | 638 | x = strndup(passphrase, p); |
87f54463 | 639 | explicit_bzero_safe(passphrase, sizeof(passphrase)); |
981e4cd3 | 640 | if (!x) { |
7f4e0805 LP |
641 | r = -ENOMEM; |
642 | goto finish; | |
643 | } | |
644 | ||
0e28c86f LP |
645 | r = strv_consume(&l, x); |
646 | if (r < 0) | |
c7b7d74e | 647 | goto finish; |
c7b7d74e | 648 | |
d325f244 | 649 | skipped: |
72c08a47 ZJS |
650 | if (strv_isempty(l)) |
651 | r = log_debug_errno(SYNTHETIC_ERRNO(ECANCELED), "Password query was cancelled."); | |
652 | else { | |
653 | if (keyname) | |
654 | (void) add_to_keyring_and_log(keyname, flags, l); | |
655 | ||
656 | *ret = TAKE_PTR(l); | |
657 | r = 0; | |
658 | } | |
7f4e0805 LP |
659 | |
660 | finish: | |
981e4cd3 | 661 | if (ttyfd >= 0 && reset_tty) { |
ac7a9674 LP |
662 | (void) loop_write(ttyfd, "\n", 1, false); |
663 | (void) tcsetattr(ttyfd, TCSADRAIN, &old_termios); | |
7f4e0805 LP |
664 | } |
665 | ||
666 | return r; | |
667 | } | |
668 | ||
15a3e96f LP |
669 | static int create_socket(char **ret) { |
670 | _cleanup_free_ char *path = NULL; | |
f36a9d59 ZJS |
671 | union sockaddr_union sa; |
672 | socklen_t sa_len; | |
254d1313 | 673 | _cleanup_close_ int fd = -EBADF; |
f36a9d59 | 674 | int r; |
7f4e0805 | 675 | |
15a3e96f | 676 | assert(ret); |
7f4e0805 | 677 | |
e62d8c39 | 678 | fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0); |
4a62c710 | 679 | if (fd < 0) |
00843602 | 680 | return -errno; |
7f4e0805 | 681 | |
15a3e96f LP |
682 | if (asprintf(&path, "/run/systemd/ask-password/sck.%" PRIx64, random_u64()) < 0) |
683 | return -ENOMEM; | |
684 | ||
f36a9d59 ZJS |
685 | r = sockaddr_un_set_path(&sa.un, path); |
686 | if (r < 0) | |
687 | return r; | |
688 | sa_len = r; | |
7f4e0805 | 689 | |
2053593f | 690 | WITH_UMASK(0177) |
f36a9d59 | 691 | if (bind(fd, &sa.sa, sa_len) < 0) |
00843602 | 692 | return -errno; |
1d6702e8 | 693 | |
2ff48e98 LP |
694 | r = setsockopt_int(fd, SOL_SOCKET, SO_PASSCRED, true); |
695 | if (r < 0) | |
696 | return r; | |
7f4e0805 | 697 | |
15a3e96f LP |
698 | *ret = TAKE_PTR(path); |
699 | return TAKE_FD(fd); | |
7f4e0805 LP |
700 | } |
701 | ||
7f4e0805 LP |
702 | int ask_password_agent( |
703 | const char *message, | |
704 | const char *icon, | |
9fa1de96 | 705 | const char *id, |
e287086b | 706 | const char *keyname, |
7f4e0805 | 707 | usec_t until, |
e287086b LP |
708 | AskPasswordFlags flags, |
709 | char ***ret) { | |
7f4e0805 LP |
710 | |
711 | enum { | |
712 | FD_SOCKET, | |
713 | FD_SIGNAL, | |
c7b7d74e | 714 | FD_INOTIFY, |
7f4e0805 LP |
715 | _FD_MAX |
716 | }; | |
717 | ||
254d1313 | 718 | _cleanup_close_ int socket_fd = -EBADF, signal_fd = -EBADF, notify = -EBADF, fd = -EBADF; |
2b583ce6 | 719 | char temp[] = "/run/systemd/ask-password/tmp.XXXXXX"; |
7f4e0805 | 720 | char final[sizeof(temp)] = ""; |
981e4cd3 | 721 | _cleanup_free_ char *socket_name = NULL; |
c7b7d74e | 722 | _cleanup_strv_free_erase_ char **l = NULL; |
e287086b | 723 | _cleanup_fclose_ FILE *f = NULL; |
7f4e0805 | 724 | struct pollfd pollfd[_FD_MAX]; |
e287086b | 725 | sigset_t mask, oldmask; |
981e4cd3 | 726 | int r; |
7f4e0805 | 727 | |
e287086b | 728 | assert(ret); |
21bc923a | 729 | |
9cb5bf91 | 730 | if (FLAGS_SET(flags, ASK_PASSWORD_NO_AGENT)) |
e287086b | 731 | return -EUNATCH; |
00843602 | 732 | |
72c0a2c2 LP |
733 | assert_se(sigemptyset(&mask) >= 0); |
734 | assert_se(sigset_add_many(&mask, SIGINT, SIGTERM, -1) >= 0); | |
735 | assert_se(sigprocmask(SIG_BLOCK, &mask, &oldmask) >= 0); | |
f9b72cd8 | 736 | |
00843602 | 737 | (void) mkdir_p_label("/run/systemd/ask-password", 0755); |
7f4e0805 | 738 | |
9cb5bf91 | 739 | if (FLAGS_SET(flags, ASK_PASSWORD_ACCEPT_CACHED) && keyname) { |
c7b7d74e XF |
740 | r = ask_password_keyring(keyname, flags, ret); |
741 | if (r >= 0) { | |
742 | r = 0; | |
743 | goto finish; | |
744 | } else if (r != -ENOKEY) | |
745 | goto finish; | |
746 | ||
747 | notify = inotify_init1(IN_CLOEXEC | IN_NONBLOCK); | |
748 | if (notify < 0) { | |
749 | r = -errno; | |
750 | goto finish; | |
751 | } | |
108dfff2 LP |
752 | |
753 | r = RET_NERRNO(inotify_add_watch(notify, "/run/systemd/ask-password", IN_ATTRIB /* for mtime */)); | |
754 | if (r < 0) | |
c7b7d74e | 755 | goto finish; |
c7b7d74e XF |
756 | } |
757 | ||
646853bd | 758 | fd = mkostemp_safe(temp); |
1d6702e8 | 759 | if (fd < 0) { |
709f6e46 | 760 | r = fd; |
7f4e0805 LP |
761 | goto finish; |
762 | } | |
763 | ||
00843602 | 764 | (void) fchmod(fd, 0644); |
7f4e0805 | 765 | |
4fa744a3 | 766 | f = take_fdopen(&fd, "w"); |
981e4cd3 | 767 | if (!f) { |
00843602 | 768 | r = -errno; |
7f4e0805 LP |
769 | goto finish; |
770 | } | |
771 | ||
981e4cd3 LP |
772 | signal_fd = signalfd(-1, &mask, SFD_NONBLOCK|SFD_CLOEXEC); |
773 | if (signal_fd < 0) { | |
00843602 | 774 | r = -errno; |
7f4e0805 LP |
775 | goto finish; |
776 | } | |
777 | ||
981e4cd3 LP |
778 | socket_fd = create_socket(&socket_name); |
779 | if (socket_fd < 0) { | |
7f4e0805 LP |
780 | r = socket_fd; |
781 | goto finish; | |
782 | } | |
783 | ||
784 | fprintf(f, | |
785 | "[Ask]\n" | |
de0671ee | 786 | "PID="PID_FMT"\n" |
7f4e0805 | 787 | "Socket=%s\n" |
21bc923a | 788 | "AcceptCached=%i\n" |
64845bdc | 789 | "Echo=%i\n" |
1fa94a31 SB |
790 | "NotAfter="USEC_FMT"\n" |
791 | "Silent=%i\n", | |
df0ff127 | 792 | getpid_cached(), |
7f4e0805 | 793 | socket_name, |
9cb5bf91 CH |
794 | FLAGS_SET(flags, ASK_PASSWORD_ACCEPT_CACHED), |
795 | FLAGS_SET(flags, ASK_PASSWORD_ECHO), | |
1fa94a31 | 796 | until, |
9cb5bf91 | 797 | FLAGS_SET(flags, ASK_PASSWORD_SILENT)); |
7f4e0805 LP |
798 | |
799 | if (message) | |
800 | fprintf(f, "Message=%s\n", message); | |
801 | ||
802 | if (icon) | |
803 | fprintf(f, "Icon=%s\n", icon); | |
804 | ||
9fa1de96 DH |
805 | if (id) |
806 | fprintf(f, "Id=%s\n", id); | |
807 | ||
dacd6cee | 808 | r = fflush_and_check(f); |
00843602 | 809 | if (r < 0) |
7f4e0805 | 810 | goto finish; |
7f4e0805 LP |
811 | |
812 | memcpy(final, temp, sizeof(temp)); | |
813 | ||
814 | final[sizeof(final)-11] = 'a'; | |
815 | final[sizeof(final)-10] = 's'; | |
816 | final[sizeof(final)-9] = 'k'; | |
817 | ||
108dfff2 LP |
818 | r = RET_NERRNO(rename(temp, final)); |
819 | if (r < 0) | |
7f4e0805 | 820 | goto finish; |
7f4e0805 LP |
821 | |
822 | zero(pollfd); | |
823 | pollfd[FD_SOCKET].fd = socket_fd; | |
824 | pollfd[FD_SOCKET].events = POLLIN; | |
825 | pollfd[FD_SIGNAL].fd = signal_fd; | |
826 | pollfd[FD_SIGNAL].events = POLLIN; | |
c7b7d74e XF |
827 | pollfd[FD_INOTIFY].fd = notify; |
828 | pollfd[FD_INOTIFY].events = POLLIN; | |
7f4e0805 LP |
829 | |
830 | for (;;) { | |
fb29cdbe | 831 | CMSG_BUFFER_TYPE(CMSG_SPACE(sizeof(struct ucred))) control; |
7f4e0805 | 832 | char passphrase[LINE_MAX+1]; |
7f4e0805 LP |
833 | struct iovec iovec; |
834 | struct ucred *ucred; | |
d9e2af0a | 835 | usec_t timeout; |
7f4e0805 | 836 | ssize_t n; |
7f4e0805 | 837 | |
d9e2af0a YW |
838 | if (until > 0) |
839 | timeout = usec_sub_unsigned(until, now(CLOCK_MONOTONIC)); | |
840 | else | |
841 | timeout = USEC_INFINITY; | |
7f4e0805 | 842 | |
d9e2af0a YW |
843 | r = ppoll_usec(pollfd, notify >= 0 ? _FD_MAX : _FD_MAX - 1, timeout); |
844 | if (r == -EINTR) | |
845 | continue; | |
846 | if (r < 0) | |
7f4e0805 | 847 | goto finish; |
d9e2af0a | 848 | if (r == 0) { |
7f4e0805 LP |
849 | r = -ETIME; |
850 | goto finish; | |
851 | } | |
852 | ||
21bc923a LP |
853 | if (pollfd[FD_SIGNAL].revents & POLLIN) { |
854 | r = -EINTR; | |
855 | goto finish; | |
856 | } | |
7f4e0805 | 857 | |
c7b7d74e XF |
858 | if (notify >= 0 && pollfd[FD_INOTIFY].revents != 0) { |
859 | (void) flush_fd(notify); | |
860 | ||
861 | r = ask_password_keyring(keyname, flags, ret); | |
862 | if (r >= 0) { | |
863 | r = 0; | |
864 | goto finish; | |
865 | } else if (r != -ENOKEY) | |
866 | goto finish; | |
867 | } | |
868 | ||
869 | if (pollfd[FD_SOCKET].revents == 0) | |
870 | continue; | |
871 | ||
7f4e0805 | 872 | if (pollfd[FD_SOCKET].revents != POLLIN) { |
7f4e0805 LP |
873 | r = -EIO; |
874 | goto finish; | |
875 | } | |
876 | ||
5cfa2c3d | 877 | iovec = IOVEC_MAKE(passphrase, sizeof(passphrase)); |
7f4e0805 | 878 | |
41ab8c67 LP |
879 | struct msghdr msghdr = { |
880 | .msg_iov = &iovec, | |
881 | .msg_iovlen = 1, | |
882 | .msg_control = &control, | |
883 | .msg_controllen = sizeof(control), | |
884 | }; | |
7f4e0805 | 885 | |
3691bcf3 | 886 | n = recvmsg_safe(socket_fd, &msghdr, 0); |
981e4cd3 | 887 | if (n < 0) { |
8add30a0 YW |
888 | if (ERRNO_IS_TRANSIENT(n)) |
889 | continue; | |
890 | if (n == -EXFULL) { | |
891 | log_debug("Got message with truncated control data, ignoring."); | |
892 | continue; | |
893 | } | |
894 | ||
3691bcf3 | 895 | r = (int) n; |
7f4e0805 LP |
896 | goto finish; |
897 | } | |
898 | ||
1c8da044 LP |
899 | cmsg_close_all(&msghdr); |
900 | ||
8add30a0 | 901 | if (n == 0) { |
00843602 | 902 | log_debug("Message too short"); |
7f4e0805 LP |
903 | continue; |
904 | } | |
905 | ||
371d72e0 LP |
906 | ucred = CMSG_FIND_DATA(&msghdr, SOL_SOCKET, SCM_CREDENTIALS, struct ucred); |
907 | if (!ucred) { | |
00843602 | 908 | log_debug("Received message without credentials. Ignoring."); |
7f4e0805 LP |
909 | continue; |
910 | } | |
911 | ||
7f4e0805 | 912 | if (ucred->uid != 0) { |
00843602 | 913 | log_debug("Got request from unprivileged user. Ignoring."); |
7f4e0805 LP |
914 | continue; |
915 | } | |
916 | ||
917 | if (passphrase[0] == '+') { | |
e287086b | 918 | /* An empty message refers to the empty password */ |
8254a475 | 919 | if (n == 1) |
bea1a013 | 920 | l = strv_new(""); |
8254a475 LP |
921 | else |
922 | l = strv_parse_nulstr(passphrase+1, n-1); | |
87f54463 | 923 | explicit_bzero_safe(passphrase, n); |
8254a475 | 924 | if (!l) { |
7f4e0805 LP |
925 | r = -ENOMEM; |
926 | goto finish; | |
927 | } | |
928 | ||
58629001 | 929 | if (strv_isempty(l)) { |
e287086b | 930 | l = strv_free(l); |
00843602 | 931 | log_debug("Invalid packet"); |
21bc923a LP |
932 | continue; |
933 | } | |
934 | ||
e287086b LP |
935 | break; |
936 | } | |
21bc923a | 937 | |
e287086b | 938 | if (passphrase[0] == '-') { |
7f4e0805 LP |
939 | r = -ECANCELED; |
940 | goto finish; | |
7f4e0805 LP |
941 | } |
942 | ||
e287086b | 943 | log_debug("Invalid packet"); |
7f4e0805 LP |
944 | } |
945 | ||
e287086b LP |
946 | if (keyname) |
947 | (void) add_to_keyring_and_log(keyname, flags, l); | |
948 | ||
ae2a15bc | 949 | *ret = TAKE_PTR(l); |
7f4e0805 LP |
950 | r = 0; |
951 | ||
952 | finish: | |
981e4cd3 | 953 | if (socket_name) |
00843602 | 954 | (void) unlink(socket_name); |
7f4e0805 | 955 | |
00843602 | 956 | (void) unlink(temp); |
7f4e0805 LP |
957 | |
958 | if (final[0]) | |
00843602 | 959 | (void) unlink(final); |
7f4e0805 | 960 | |
f9b72cd8 | 961 | assert_se(sigprocmask(SIG_SETMASK, &oldmask, NULL) == 0); |
7f4e0805 LP |
962 | return r; |
963 | } | |
260ab287 | 964 | |
8806bb4b LP |
965 | static int ask_password_credential(const char *credential_name, AskPasswordFlags flags, char ***ret) { |
966 | _cleanup_(erase_and_freep) char *buffer = NULL; | |
967 | size_t size; | |
968 | char **l; | |
969 | int r; | |
970 | ||
971 | assert(credential_name); | |
972 | assert(ret); | |
973 | ||
974 | r = read_credential(credential_name, (void**) &buffer, &size); | |
975 | if (IN_SET(r, -ENXIO, -ENOENT)) /* No credentials passed or this credential not defined? */ | |
976 | return -ENOKEY; | |
977 | ||
978 | l = strv_parse_nulstr(buffer, size); | |
979 | if (!l) | |
980 | return -ENOMEM; | |
981 | ||
982 | *ret = l; | |
983 | return 0; | |
984 | } | |
985 | ||
00843602 LP |
986 | int ask_password_auto( |
987 | const char *message, | |
988 | const char *icon, | |
8806bb4b LP |
989 | const char *id, /* id in "ask-password" protocol */ |
990 | const char *key_name, /* name in kernel keyring */ | |
991 | const char *credential_name, /* name in $CREDENTIALS_DIRECTORY directory */ | |
00843602 | 992 | usec_t until, |
e287086b LP |
993 | AskPasswordFlags flags, |
994 | char ***ret) { | |
00843602 LP |
995 | |
996 | int r; | |
997 | ||
e287086b | 998 | assert(ret); |
21bc923a | 999 | |
9cb5bf91 | 1000 | if (!FLAGS_SET(flags, ASK_PASSWORD_NO_CREDENTIAL) && credential_name) { |
8806bb4b LP |
1001 | r = ask_password_credential(credential_name, flags, ret); |
1002 | if (r != -ENOKEY) | |
1003 | return r; | |
1004 | } | |
1005 | ||
9cb5bf91 | 1006 | if (FLAGS_SET(flags, ASK_PASSWORD_ACCEPT_CACHED) && |
8806bb4b | 1007 | key_name && |
9cb5bf91 CH |
1008 | (FLAGS_SET(flags, ASK_PASSWORD_NO_TTY) || !isatty(STDIN_FILENO)) && |
1009 | FLAGS_SET(flags, ASK_PASSWORD_NO_AGENT)) { | |
8806bb4b | 1010 | r = ask_password_keyring(key_name, flags, ret); |
e287086b LP |
1011 | if (r != -ENOKEY) |
1012 | return r; | |
1013 | } | |
1014 | ||
9cb5bf91 | 1015 | if (!FLAGS_SET(flags, ASK_PASSWORD_NO_TTY) && isatty(STDIN_FILENO)) |
8806bb4b | 1016 | return ask_password_tty(-1, message, key_name, until, flags, NULL, ret); |
00843602 | 1017 | |
9cb5bf91 | 1018 | if (!FLAGS_SET(flags, ASK_PASSWORD_NO_AGENT)) |
8806bb4b | 1019 | return ask_password_agent(message, icon, id, key_name, until, flags, ret); |
e287086b LP |
1020 | |
1021 | return -EUNATCH; | |
260ab287 | 1022 | } |