firstboot: allow provisioning of firstboot params via creds too
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user