]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
ask-password-agent: optionally read pw to reply from env var
authorLennart Poettering <lennart@poettering.net>
Wed, 6 Nov 2024 22:38:01 +0000 (23:38 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 2 Jan 2025 15:37:54 +0000 (16:37 +0100)
src/tty-ask-password-agent/tty-ask-password-agent.c

index 8b83212755083535e8edbaced605b7b6a5a86c76..4544ee8fa7d72675e3656255440cb294508bf617 100644 (file)
@@ -243,20 +243,28 @@ static int process_one_password_file(const char *filename, FILE *f) {
                 SET_FLAG(flags, ASK_PASSWORD_ECHO, echo);
                 SET_FLAG(flags, ASK_PASSWORD_SILENT, silent);
 
-                if (arg_plymouth) {
-                        AskPasswordRequest req = {
-                                .message = message,
-                        };
-
-                        r = ask_password_plymouth(&req, not_after, flags, filename, &passwords);
-                } else
-                        r = agent_ask_password_tty(message, not_after, flags, filename, &passwords);
-                if (r < 0) {
-                        /* If the query went away, that's OK */
-                        if (IN_SET(r, -ETIME, -ENOENT))
-                                return 0;
-
-                        return log_error_errno(r, "Failed to query password: %m");
+                /* Allow providing a password via env var, for debugging purposes */
+                const char *e = secure_getenv("SYSTEMD_ASK_PASSWORD_AGENT_PASSWORD");
+                if (e) {
+                        passwords = strv_new(e);
+                        if (!passwords)
+                                return log_oom();
+                } else {
+                        if (arg_plymouth) {
+                                AskPasswordRequest req = {
+                                        .message = message,
+                                };
+
+                                r = ask_password_plymouth(&req, not_after, flags, filename, &passwords);
+                        } else
+                                r = agent_ask_password_tty(message, not_after, flags, filename, &passwords);
+                        if (r < 0) {
+                                /* If the query went away, that's OK */
+                                if (IN_SET(r, -ETIME, -ENOENT))
+                                        return 0;
+
+                                return log_error_errno(r, "Failed to query password: %m");
+                        }
                 }
 
                 assert(!strv_isempty(passwords));