Skip to content

Commit

Permalink
Use installer root to call crypt_r
Browse files Browse the repository at this point in the history
  • Loading branch information
rvykydal committed Jun 14, 2024
1 parent d42263d commit 376f5ac
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
16 changes: 8 additions & 8 deletions rootpw-basic.ks.in
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,25 @@ 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
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(":")
Expand Down
16 changes: 8 additions & 8 deletions rootpw-lock.ks.in
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,25 @@ 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
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(":")
Expand Down

0 comments on commit 376f5ac

Please sign in to comment.