From: Lennart Poettering Date: Tue, 20 Aug 2024 08:52:20 +0000 (+0200) Subject: shared: invoke agents only when we have a controlling TTY X-Git-Tag: v257-rc1~673 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=61242b1f0f9cac399deb67c88c3b62d38218dba3;p=thirdparty%2Fsystemd.git shared: invoke agents only when we have a controlling TTY being connected to a TTY is not really enough to determine interactivity in many cases. Let's also check if we have a controlling TTY. Inspired by #34016 --- diff --git a/src/shared/ask-password-agent.c b/src/shared/ask-password-agent.c index e425f825db8..62b73503cae 100644 --- a/src/shared/ask-password-agent.c +++ b/src/shared/ask-password-agent.c @@ -22,6 +22,14 @@ int ask_password_agent_open(void) { if (!isatty_safe(STDIN_FILENO)) return 0; + /* Also check if we have a controlling terminal. If not (ENXIO here), we aren't actually invoked + * interactively on a terminal, hence fail */ + r = get_ctty_devnr(0, NULL); + if (r == -ENXIO) + return 0; + if (r < 0) + return r; + if (!is_main_thread()) return -EPERM; diff --git a/src/shared/polkit-agent.c b/src/shared/polkit-agent.c index 92e576c9d25..842e41e8dbf 100644 --- a/src/shared/polkit-agent.c +++ b/src/shared/polkit-agent.c @@ -35,6 +35,14 @@ int polkit_agent_open(void) { if (!isatty_safe(STDIN_FILENO)) return 0; + /* Also check if we have a controlling terminal. If not (ENXIO here), we aren't actually invoked + * interactively on a terminal, hence fail */ + r = get_ctty_devnr(0, NULL); + if (r == -ENXIO) + return 0; + if (r < 0) + return r; + if (!is_main_thread()) return -EPERM;