You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] Salt relies on spwd module, deprecated in 3.11 and removed in 3.13 #67119
This time however linux_shadow and solaris_shadow are broken by the need for spwd. The official recommendation by Python is the third party python-pam.
Even though I'm almost convinced this is a dead project and it was a huge mistake to port my Ansible stuff to Salt... since I have to maintain my systems and days only have 24 hours, I've had to make the fix myself.
So here is the patch, and I formally disclaim any ownership or licensing interest on it, and no I will not sign your CLA:
diff -up venv3007.1/lib/python3.12/site-packages/salt/modules/linux_shadow.py.old venv3007.1/lib/python3.12/site-packages/salt/modules/linux_shadow.py
--- venv3007.1/lib/python3.12/site-packages/salt/modules/linux_shadow.py.old 2025-02-10 00:08:23.401850220 +0000
+++ venv3007.1/lib/python3.12/site-packages/salt/modules/linux_shadow.py 2025-02-10 00:15:43.969807664 +0000
@@ -8,6 +8,7 @@ Manage the shadow file on Linux systems
<module-provider-override>`.
"""
+import collections
import datetime
import functools
import logging
@@ -17,11 +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 +30,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 +82,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 +520,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 +540,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 +556,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)
Creating users on Linux systems will still fail in the absence of the python3-passlib package (or equivalent PyPI module). So I'll leave it to the brain trust to figure out how to fix that in the packaging.
By the way, the whole "onedir" thing? It really screwed us salt-ssh users.
Activity
Rudd-O commentedon Feb 10, 2025
Even though I'm almost convinced this is a dead project and it was a huge mistake to port my Ansible stuff to Salt... since I have to maintain my systems and days only have 24 hours, I've had to make the fix myself.
So here is the patch, and I formally disclaim any ownership or licensing interest on it, and no I will not sign your CLA:
Creating users on Linux systems will still fail in the absence of the
python3-passlibpackage (or equivalent PyPI module). So I'll leave it to the brain trust to figure out how to fix that in the packaging.By the way, the whole "onedir" thing? It really screwed us salt-ssh users.
Vaelatern commentedon Feb 10, 2025
thank you for the patch! I will test it.
Vaelatern commentedon Feb 11, 2025
I've tested it and it works for me, so.
I'm volunteering to make this an official PR.
Rudd-O commentedon Feb 12, 2025
Let's GOOOOOOOOOOOOOOOOOOOO!
frebib commentedon Mar 5, 2025
Can you raise a PR for this?
Vaelatern commentedon Mar 6, 2025
@frebib #67788