File 0001-Remove-uses-of-spwd.patch of Package salt
From a2f5d6122204208aee6f11ccc9b6e95af1eea508 Mon Sep 17 00:00:00 2001
From: Toyam Cox <Vaelatern@voidlinux.org>
Date: Wed, 5 Mar 2025 22:42:29 -0500
Subject: [PATCH 1/2] Remove uses of spwd
Module deprecated and no longer shipped with Python 3.13.
Co-authored-by: Toyam Cox <Vaelatern@voidlinux.org>
Co-authored-by: Georg Pfuetzenreuter <mail@georg-pfuetzenreuter.net>
Signed-off-by: Georg Pfuetzenreuter <mail@georg-pfuetzenreuter.net>
---
changelog/67119.fixed.md | 1 +
salt/modules/linux_shadow.py | 30 ++++++++++++++++++++----------
2 files changed, 21 insertions(+), 10 deletions(-)
create mode 100644 changelog/67119.fixed.md
diff --git a/changelog/67119.fixed.md b/changelog/67119.fixed.md
new file mode 100644
index 000000000000..34eca2d3b2a7
--- /dev/null
+++ b/changelog/67119.fixed.md
@@ -0,0 +1 @@
+Remove usage of spwd
diff --git a/salt/modules/linux_shadow.py b/salt/modules/linux_shadow.py
index aa149ac4c8e8..677dedfe4f38 100644
--- a/salt/modules/linux_shadow.py
+++ b/salt/modules/linux_shadow.py
@@ -8,6 +8,7 @@ Manage the shadow file on Linux systems
<module-provider-override>`.
"""
+import collections
import datetime
import functools
import logging
@@ -17,12 +18,6 @@ import salt.utils.data
import salt.utils.files
from salt.exceptions import CommandExecutionError
-try:
- import spwd
-except ImportError:
- pass
-
-
try:
import salt.utils.pycrypto
@@ -34,6 +29,21 @@ __virtualname__ = "shadow"
log = logging.getLogger(__name__)
+struct_spwd = collections.namedtuple(
+ "struct_spwd",
+ [
+ "sp_namp",
+ "sp_pwdp",
+ "sp_lstchg",
+ "sp_min",
+ "sp_max",
+ "sp_warn",
+ "sp_inact",
+ "sp_expire",
+ "sp_flag",
+ ],
+)
+
def __virtual__():
return __virtualname__ if __grains__.get("kernel", "") == "Linux" else False
@@ -71,7 +81,7 @@ def info(name, root=None):
if root is not None:
getspnam = functools.partial(_getspnam, root=root)
else:
- getspnam = functools.partial(spwd.getspnam)
+ getspnam = functools.partial(_getspnam, root="/")
try:
data = getspnam(name)
@@ -509,7 +519,7 @@ def list_users(root=None):
if root is not None:
getspall = functools.partial(_getspall, root=root)
else:
- getspall = functools.partial(spwd.getspall)
+ getspall = functools.partial(_getspall, root="/")
return sorted(
user.sp_namp if hasattr(user, "sp_namp") else user.sp_nam for user in getspall()
@@ -529,7 +539,7 @@ def _getspnam(name, root=None):
# Generate a getspnam compatible output
for i in range(2, 9):
comps[i] = int(comps[i]) if comps[i] else -1
- return spwd.struct_spwd(comps)
+ return struct_spwd(*comps)
raise KeyError
@@ -545,4 +555,4 @@ def _getspall(root=None):
# Generate a getspall compatible output
for i in range(2, 9):
comps[i] = int(comps[i]) if comps[i] else -1
- yield spwd.struct_spwd(comps)
+ yield struct_spwd(*comps)
--
2.50.1