From: Lennart Poettering Date: Thu, 7 Nov 2024 09:00:53 +0000 (+0100) Subject: ask-password-api: move 'flag_file' from function parameter into AskPasswordRequest... X-Git-Tag: v258-rc1~1751^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4ff3689ad2ea7aad4aa5e5428238b447baea807e;p=thirdparty%2Fsystemd.git ask-password-api: move 'flag_file' from function parameter into AskPasswordRequest structure --- diff --git a/src/firstboot/firstboot.c b/src/firstboot/firstboot.c index 9be62b8df3d..bf9b840a23c 100644 --- a/src/firstboot/firstboot.c +++ b/src/firstboot/firstboot.c @@ -738,7 +738,7 @@ static int prompt_root_password(int rfd) { .message = msg1, }; - r = ask_password_tty(-EBADF, &req, /* until= */ 0, /* flags= */ 0, /* flag_file= */ NULL, &a); + r = ask_password_tty(-EBADF, &req, /* until= */ 0, /* flags= */ 0, &a); if (r < 0) return log_error_errno(r, "Failed to query root password: %m"); if (strv_length(a) != 1) @@ -760,7 +760,7 @@ static int prompt_root_password(int rfd) { req.message = msg2; - r = ask_password_tty(-EBADF, &req, /* until= */ 0, /* flags= */ 0, /* flag_file= */ NULL, &b); + r = ask_password_tty(-EBADF, &req, /* until= */ 0, /* flags= */ 0, &b); if (r < 0) return log_error_errno(r, "Failed to query root password: %m"); if (strv_length(b) != 1) diff --git a/src/shared/ask-password-api.c b/src/shared/ask-password-api.c index 2e49096f820..e8ba9a2c361 100644 --- a/src/shared/ask-password-api.c +++ b/src/shared/ask-password-api.c @@ -311,7 +311,6 @@ int ask_password_plymouth( const AskPasswordRequest *req, usec_t until, AskPasswordFlags flags, - const char *flag_file, char ***ret) { _cleanup_close_ int fd = -EBADF, inotify_fd = -EBADF; @@ -328,12 +327,12 @@ int ask_password_plymouth( const char *message = req && req->message ? req->message : "Password:"; - if (flag_file) { + if (req->flag_file) { inotify_fd = inotify_init1(IN_CLOEXEC|IN_NONBLOCK); if (inotify_fd < 0) return -errno; - if (inotify_add_watch(inotify_fd, flag_file, IN_ATTRIB) < 0) /* for the link count */ + if (inotify_add_watch(inotify_fd, req->flag_file, IN_ATTRIB) < 0) /* for the link count */ return -errno; } @@ -375,7 +374,7 @@ int ask_password_plymouth( else timeout = USEC_INFINITY; - if (flag_file && access(flag_file, F_OK) < 0) + if (req->flag_file && access(req->flag_file, F_OK) < 0) return -errno; r = ppoll_usec(pollfd, n_pollfd, timeout); @@ -468,7 +467,6 @@ int ask_password_tty( const AskPasswordRequest *req, usec_t until, AskPasswordFlags flags, - const char *flag_file, char ***ret) { bool reset_tty = false, dirty = false, use_color = false, press_tab_visible = false; @@ -493,15 +491,14 @@ int ask_password_tty( if (!FLAGS_SET(flags, ASK_PASSWORD_HIDE_EMOJI) && emoji_enabled()) message = strjoina(special_glyph(SPECIAL_GLYPH_LOCK_AND_KEY), " ", message); - if (flag_file || (FLAGS_SET(flags, ASK_PASSWORD_ACCEPT_CACHED) && keyring)) { + if (req->flag_file || (FLAGS_SET(flags, ASK_PASSWORD_ACCEPT_CACHED) && keyring)) { inotify_fd = inotify_init1(IN_CLOEXEC|IN_NONBLOCK); if (inotify_fd < 0) return -errno; } - if (flag_file) { - if (inotify_add_watch(inotify_fd, flag_file, IN_ATTRIB /* for the link count */) < 0) + if (req->flag_file) + if (inotify_add_watch(inotify_fd, req->flag_file, IN_ATTRIB /* for the link count */) < 0) return -errno; - } if (FLAGS_SET(flags, ASK_PASSWORD_ACCEPT_CACHED) && req && keyring) { r = ask_password_keyring(req, flags, ret); if (r >= 0) @@ -590,8 +587,8 @@ int ask_password_tty( else timeout = USEC_INFINITY; - if (flag_file) { - r = RET_NERRNO(access(flag_file, F_OK)); + if (req->flag_file) { + r = RET_NERRNO(access(req->flag_file, F_OK)); if (r < 0) goto finish; } @@ -820,6 +817,10 @@ int ask_password_agent( if (FLAGS_SET(flags, ASK_PASSWORD_NO_AGENT)) return -EUNATCH; + /* We don't support the flag file concept for now when querying via the agent logic */ + if (req->flag_file) + return -EOPNOTSUPP; + assert_se(sigemptyset(&mask) >= 0); assert_se(sigset_add_many(&mask, SIGINT, SIGTERM) >= 0); assert_se(sigprocmask(SIG_BLOCK, &mask, &oldmask) >= 0); @@ -1127,7 +1128,7 @@ int ask_password_auto( } if (!FLAGS_SET(flags, ASK_PASSWORD_NO_TTY) && isatty_safe(STDIN_FILENO)) - return ask_password_tty(-EBADF, req, until, flags, NULL, ret); + return ask_password_tty(-EBADF, req, until, flags, ret); if (!FLAGS_SET(flags, ASK_PASSWORD_NO_AGENT)) return ask_password_agent(req, until, flags, ret); diff --git a/src/shared/ask-password-api.h b/src/shared/ask-password-api.h index b3cb407e51c..c8763700c8c 100644 --- a/src/shared/ask-password-api.h +++ b/src/shared/ask-password-api.h @@ -26,10 +26,11 @@ typedef struct AskPasswordRequest { const char *icon; /* freedesktop icon spec name */ const char *id; /* some identifier used for this prompt for the "ask-password" protocol */ const char *credential; /* $CREDENTIALS_DIRECTORY credential name */ + const char *flag_file; /* Once this flag file disappears abort the query */ } AskPasswordRequest; -int ask_password_tty(int tty_fd, const AskPasswordRequest *req, usec_t until, AskPasswordFlags flags, const char *flag_file, char ***ret); -int ask_password_plymouth(const AskPasswordRequest *req, usec_t until, AskPasswordFlags flags, const char *flag_file, char ***ret); +int ask_password_tty(int tty_fd, const AskPasswordRequest *req, usec_t until, AskPasswordFlags flags, char ***ret); +int ask_password_plymouth(const AskPasswordRequest *req, usec_t until, AskPasswordFlags flags, char ***ret); int ask_password_agent(const AskPasswordRequest *req, usec_t until, AskPasswordFlags flag, char ***ret); int ask_password_auto(const AskPasswordRequest *req, usec_t until, AskPasswordFlags flag, char ***ret); diff --git a/src/test/test-ask-password-api.c b/src/test/test-ask-password-api.c index e58e86870b3..efd19696c89 100644 --- a/src/test/test-ask-password-api.c +++ b/src/test/test-ask-password-api.c @@ -13,7 +13,7 @@ TEST(ask_password) { .keyring = "da key", }; - r = ask_password_tty(-EBADF, &req, /* until= */ 0, /* flags= */ ASK_PASSWORD_CONSOLE_COLOR, /* flag_file= */ NULL, &ret); + r = ask_password_tty(-EBADF, &req, /* until= */ 0, /* flags= */ ASK_PASSWORD_CONSOLE_COLOR, &ret); if (r == -ECANCELED) ASSERT_NULL(ret); else { diff --git a/src/tty-ask-password-agent/tty-ask-password-agent.c b/src/tty-ask-password-agent/tty-ask-password-agent.c index 214687673f8..3c38fbbd41e 100644 --- a/src/tty-ask-password-agent/tty-ask-password-agent.c +++ b/src/tty-ask-password-agent/tty-ask-password-agent.c @@ -149,9 +149,10 @@ static int agent_ask_password_tty( AskPasswordRequest req = { .message = message, + .flag_file = flag_file, }; - r = ask_password_tty(tty_fd, &req, until, flags, flag_file, ret); + r = ask_password_tty(tty_fd, &req, until, flags, ret); if (arg_console) { assert(tty_fd >= 0); @@ -254,9 +255,10 @@ static int process_one_password_file(const char *filename, FILE *f) { if (arg_plymouth) { AskPasswordRequest req = { .message = message, + .flag_file = filename, }; - r = ask_password_plymouth(&req, not_after, flags, filename, &passwords); + r = ask_password_plymouth(&req, not_after, flags, &passwords); } else r = agent_ask_password_tty(message, not_after, flags, filename, &passwords); if (r < 0) {