From 376f5ac518ee0261d4bd958e15fce03a8dc30fd7 Mon Sep 17 00:00:00 2001 From: Radek Vykydal Date: Fri, 14 Jun 2024 17:59:22 +0200 Subject: [PATCH] Use installer root to call crypt_r --- rootpw-basic.ks.in | 16 ++++++++-------- rootpw-lock.ks.in | 16 ++++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/rootpw-basic.ks.in b/rootpw-basic.ks.in index a7b0626f..d4552f8a 100644 --- a/rootpw-basic.ks.in +++ b/rootpw-basic.ks.in @@ -18,15 +18,12 @@ rootpw qweqwe shutdown -# make sure Python 3 is available for the %post scriptlet -%packages -python3 -python3-crypt-r -%end +%ksappend payload/default_packages.ks -%post --interpreter=/usr/bin/python3 +%post --nochroot --interpreter=/usr/bin/python3 import sys +import os try: # Use the standalone (not deprecated) package when available import crypt_r @@ -34,9 +31,12 @@ except ImportError: # Fallback to the deprecated standard library module import crypt as crypt_r # pylint: disable=deprecated-module -with open("/root/RESULT", "wt") as result: +SYSROOT="/mnt/sysroot" +RESULT_FILE=os.path.join(SYSROOT, "root/RESULT") + +with open(RESULT_FILE, "wt") as result: # Test that the root password is what we expect it to be - with open("/etc/shadow", "r") as f: + with open(os.path.join(SYSROOT, "etc/shadow"), "r") as f: for line in f: if line.startswith("root:"): shadow_fields = line.strip().split(":") diff --git a/rootpw-lock.ks.in b/rootpw-lock.ks.in index 619c5b3e..4b7bade8 100644 --- a/rootpw-lock.ks.in +++ b/rootpw-lock.ks.in @@ -23,15 +23,12 @@ rootpw --lock qweqwe shutdown -# make sure Python 3 is available for the %post scriptlet -%packages -python3 -python3-crypt-r -%end +%ksappend payload/default_packages.ks -%post --interpreter=/usr/bin/python3 +%post --nochroot --interpreter=/usr/bin/python3 import sys +import os try: # Use the standalone (not deprecated) package when available import crypt_r @@ -39,9 +36,12 @@ except ImportError: # Fallback to the deprecated standard library module import crypt as crypt_r # pylint: disable=deprecated-module -with open("/root/RESULT", "wt") as result: +SYSROOT="/mnt/sysroot" +RESULT_FILE=os.path.join(SYSROOT, "root/RESULT") + +with open(RESULT_FILE, "wt") as result: # Test that the root password is what we expect it to be - with open("/etc/shadow", "r") as f: + with open(os.path.join(SYSROOT, "etc/shadow"), "r") as f: for line in f: if line.startswith("root:"): shadow_fields = line.strip().split(":")