Fix GRUB2 password handling and GRUB1 kickstart password handling.
This also changes GRUB2 to continue with installation even if we
fail to set up the password authentication.
---
pyanaconda/bootloader.py | 78 +++++++++++++++++++++++++++++++++-------------
pyanaconda/kickstart.py | 6 ++-
2 files changed, 60 insertions(+), 24 deletions(-)
diff --git a/pyanaconda/bootloader.py b/pyanaconda/bootloader.py
index 6cdb4e4..418e0fd 100644
--- a/pyanaconda/bootloader.py
+++ b/pyanaconda/bootloader.py
@@ -965,7 +965,7 @@ class GRUB(BootLoader):
def write_config_header(self, config, install_root=""):
"""Write global configuration information. """
@@ -1488,32 +1492,62 @@ class GRUB2(GRUB):
if self.console and self.console.startswith("ttyS"):
defaults.write("GRUB_TERMINAL="serial console"
")
defaults.write("GRUB_SERIAL_COMMAND="%s"
" % self.serial_command)
+
+ # this is going to cause problems for systems containing multiple
+ # linux installations or even multiple boot entries with different
+ # boot arguments
defaults.write("GRUB_CMDLINE_LINUX="%s"
" % self.boot_args)
defaults.close()
- def write_password_config(self, install_root=""):
+ def _encrypt_password(self, install_root=""):
+ """ Make sure self.encrypted_password is set up properly. """
+ if self.encrypted_password:
+ return
+
if not self.password:
+ raise RuntimeError("cannot encrypt empty password")
+
+ (pread, pwrite) = os.pipe()
+ os.write(pwrite, "%s
%s
" % (self.password, self.password))
+ os.close(pwrite)
+ buf = iutil.execWithCapture("grub2-mkpasswd-pbkdf2", [],
+ stdin=pread,
+ stderr="/dev/tty5",
+ root=install_root)
+ os.close(pread)
+ self.encrypted_password = buf.split()[-1].strip()
+ if not self.encrypted_password.startswith("grub.pbkdf2.") :
+ raise BootLoaderError("failed to encrypt bootloader password")
+
+ def write_password_config(self, install_root=""):
+ if not self.password and not self.encrypted_password:
return
- # FIXME: this is useless since we currently have no way to propagate
- # --users="" to each menu entry
- header = open(install_root + "/etc/grub.d/01_users", "w")
+ users_file = install_root + "/etc/grub.d/01_users"
+ header = open(users_file, "w")
header.write("#!/bin/sh -e
def write_config(self, install_root=""):
self.write_device_map(install_root=install_root)
self.write_defaults(install_root=install_root)
- self.write_password_config(install_root=install_ro ot)
+
+ # if we fail to setup password auth we should complete the
+ # installation so the system is at least bootable
+ try:
+ self.write_password_config(install_root=install_ro ot)
+ except (BootLoaderError, OSError, RuntimeError) as e:
+ log.error("bootloader password setup failed: %s" % e)
+
+ # now tell grub2 to generate the main configuration file
rc = iutil.execWithRedirect("grub2-mkconfig",
["-o", self.config_file],
root=install_root,
diff --git a/pyanaconda/kickstart.py b/pyanaconda/kickstart.py
index bbbf772..0308055 100644
--- a/pyanaconda/kickstart.py
+++ b/pyanaconda/kickstart.py
@@ -277,8 +277,10 @@ class Bootloader(commands.bootloader.F15_Bootloader):
self.anaconda.bootloader.boot_args.update(args)