summaryrefslogtreecommitdiff
path: root/src/firstboot
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2021-03-11 11:47:57 +0100
committerLennart Poettering <lennart@poettering.net>2021-03-26 12:21:18 +0100
commit416f7b3a11e00d1a43da950fb4a00bc6c2707013 (patch)
tree0dd0d39b17eeb1857f6ad4a0c1bf94fabad0fa90 /src/firstboot
parentf8fd093001ac6bf90e0a7c96c0cd451d8031f669 (diff)
downloadsystemd-416f7b3a11e00d1a43da950fb4a00bc6c2707013.tar.gz
firstboot: allow provisioning of firstboot params via creds too
Diffstat (limited to 'src/firstboot')
-rw-r--r--src/firstboot/firstboot.c64
1 files changed, 63 insertions, 1 deletions
diff --git a/src/firstboot/firstboot.c b/src/firstboot/firstboot.c
index 42b9ca776f..01af1033e5 100644
--- a/src/firstboot/firstboot.c
+++ b/src/firstboot/firstboot.c
@@ -10,6 +10,7 @@
#include "alloc-util.h"
#include "ask-password-api.h"
#include "copy.h"
+#include "creds-util.h"
#include "dissect-image.h"
#include "env-file.h"
#include "fd-util.h"
@@ -232,11 +233,29 @@ static bool locale_is_ok(const char *name) {
static int prompt_locale(void) {
_cleanup_strv_free_ char **locales = NULL;
+ bool acquired_from_creds = false;
int r;
if (arg_locale || arg_locale_messages)
return 0;
+ r = read_credential("firstboot.locale", (void**) &arg_locale, NULL);
+ if (r < 0)
+ log_debug_errno(r, "Failed to read credential firstboot.locale, ignoring: %m");
+ else
+ acquired_from_creds = true;
+
+ r = read_credential("firstboot.locale-messages", (void**) &arg_locale_messages, NULL);
+ if (r < 0)
+ log_debug_errno(r, "Failed to read credential firstboot.locale-message, ignoring: %m");
+ else
+ acquired_from_creds = true;
+
+ if (acquired_from_creds) {
+ log_debug("Acquired locale from credentials.");
+ return 0;
+ }
+
if (!arg_prompt_locale)
return 0;
@@ -336,6 +355,14 @@ static int prompt_keymap(void) {
if (arg_keymap)
return 0;
+ r = read_credential("firstboot.keymap", (void**) &arg_keymap, NULL);
+ if (r < 0)
+ log_debug_errno(r, "Failed to read credential firstboot.keymap, ignoring: %m");
+ else {
+ log_debug("Acquired keymap from credential.");
+ return 0;
+ }
+
if (!arg_prompt_keymap)
return 0;
@@ -407,6 +434,14 @@ static int prompt_timezone(void) {
if (arg_timezone)
return 0;
+ r = read_credential("firstboot.timezone", (void**) &arg_timezone, NULL);
+ if (r < 0)
+ log_debug_errno(r, "Failed to read credential firstboot.timezone, ignoring: %m");
+ else {
+ log_debug("Acquired timezone from credential.");
+ return 0;
+ }
+
if (!arg_prompt_timezone)
return 0;
@@ -558,6 +593,22 @@ static int prompt_root_password(void) {
if (arg_root_password)
return 0;
+ r = read_credential("passwd.hashed-password.root", (void**) &arg_root_password, NULL);
+ if (r == -ENOENT) {
+ r = read_credential("passwd.plaintext-password.root", (void**) &arg_root_password, NULL);
+ if (r < 0)
+ log_debug_errno(r, "Couldn't read credential 'passwd.{hashed|plaintext}-password.root', ignoring: %m");
+ else {
+ arg_root_password_is_hashed = false;
+ return 0;
+ }
+ } else if (r < 0)
+ log_debug_errno(r, "Couldn't read credential 'passwd.hashed-password.root', ignoring: %m");
+ else {
+ arg_root_password_is_hashed = true;
+ return 0;
+ }
+
if (!arg_prompt_root_password)
return 0;
@@ -631,7 +682,18 @@ static int find_shell(const char *path, const char *root) {
static int prompt_root_shell(void) {
int r;
- if (arg_root_shell || !arg_prompt_root_shell)
+ if (arg_root_shell)
+ return 0;
+
+ r = read_credential("passwd.shell.root", (void**) &arg_root_shell, NULL);
+ if (r < 0)
+ log_debug_errno(r, "Failed to read credential passwd.shell.root, ignoring: %m");
+ else {
+ log_debug("Acquired root shell from credential.");
+ return 0;
+ }
+
+ if (!arg_prompt_root_shell)
return 0;
print_welcome();