]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared: invoke agents only when we have a controlling TTY
authorLennart Poettering <lennart@poettering.net>
Tue, 20 Aug 2024 08:52:20 +0000 (10:52 +0200)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 20 Aug 2024 11:37:50 +0000 (20:37 +0900)
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

src/shared/ask-password-agent.c
src/shared/polkit-agent.c

index e425f825db805fe58ab754860963e68257834681..62b73503cae8349ea6d0a8737773a7853d64e6fc 100644 (file)
@@ -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;
 
index 92e576c9d259d0048196338cbc44a16d3f6a02fd..842e41e8dbf3285283b06c0f108b13d063ee3ec7 100644 (file)
@@ -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;