Skip to content

Commit

Permalink
Adapt rootpw tests to crypt module removal in Python 3.13
Browse files Browse the repository at this point in the history
Anaconda code is adapted in commit 1c4d063d4c530e5f76c7ee0ff33d95752b842f52
  • Loading branch information
rvykydal committed Jun 14, 2024
1 parent b73e900 commit db62da7
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 14 deletions.
3 changes: 3 additions & 0 deletions fragments/platform/rhel10/payload/python_crypt_packages.ks
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
%packages
python3
%end
3 changes: 3 additions & 0 deletions fragments/platform/rhel8/payload/python_crypt_packages.ks
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
%packages
python3
%end
3 changes: 3 additions & 0 deletions fragments/platform/rhel9/payload/python_crypt_packages.ks
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
%packages
python3
%end
4 changes: 4 additions & 0 deletions fragments/shared/payload/python_crypt_packages.ks
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
%packages
python3
python3-crypt-r
%end
14 changes: 8 additions & 6 deletions rootpw-basic.ks.in
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@ rootpw qweqwe

shutdown

# make sure Python 3 is available for the %post scriptlet
%packages
python3
%end
%ksappend payload/python_crypt_packages.ks

%post --interpreter=/usr/bin/python3

import sys
import crypt
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:
# Test that the root password is what we expect it to be
Expand All @@ -39,7 +41,7 @@ with open("/root/RESULT", "wt") as result:
print("Unable to find root password", file=result)
sys.exit(0)

if crypt.crypt("qweqwe", shadow_fields[1]) != shadow_fields[1]:
if crypt_r.crypt("qweqwe", shadow_fields[1]) != shadow_fields[1]:
print("Root password is not correct: %s" % shadow_fields[1], file=result)
sys.exit(0)

Expand Down
1 change: 0 additions & 1 deletion rootpw-crypted.ks.in
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ python3
%post --interpreter=/usr/bin/python3

import sys
import crypt

with open("/root/RESULT", "wt") as result:
# Test that the root password is what we expect it to be
Expand Down
1 change: 0 additions & 1 deletion rootpw-lock-no-password.ks.in
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ python3
%post --interpreter=/usr/bin/python3

import sys
import crypt

with open("/root/RESULT", "wt") as result:
# Test that the root password is what we expect it to be
Expand Down
14 changes: 8 additions & 6 deletions rootpw-lock.ks.in
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@ rootpw --lock qweqwe

shutdown

# make sure Python 3 is available for the %post scriptlet
%packages
python3
%end
%ksappend payload/python_crypt_packages.ks

%post --interpreter=/usr/bin/python3

import sys
import crypt
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:
# Test that the root password is what we expect it to be
Expand All @@ -48,7 +50,7 @@ with open("/root/RESULT", "wt") as result:
print("Root password is not locked: %s" % shadow_fields[1], file=result)
sys.exit(0)

if crypt.crypt("qweqwe", shadow_fields[1][1:]) != shadow_fields[1][1:]:
if crypt_r.crypt("qweqwe", shadow_fields[1][1:]) != shadow_fields[1][1:]:
print("Root password is not correct: %s" % shadow_fields[1], file=result)
sys.exit(0)

Expand Down

0 comments on commit db62da7

Please sign in to comment.