Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ looseversion
tornado>=6.3.3
aiohttp>=3.9.0
croniter>=0.3.0,!=0.3.22; sys_platform != 'win32'
passlib

# We need contextvars for salt-ssh.
# Even on python versions which ships with contextvars in the standard library!
Expand Down
29 changes: 20 additions & 9 deletions salt/modules/linux_shadow.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<module-provider-override>`.
"""

import collections
import datetime
import functools
import logging
Expand All @@ -17,11 +18,6 @@
import salt.utils.files
from salt.exceptions import CommandExecutionError

try:
import spwd
except ImportError:
pass


try:
import salt.utils.pycrypto
Expand All @@ -34,6 +30,21 @@

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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand All @@ -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


Expand All @@ -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)
Loading