Skip to content

Uses correct zero value for lgpo LockoutDuration #56408

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 22, 2020
Merged
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
14 changes: 13 additions & 1 deletion salt/modules/win_lgpo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2615,12 +2615,18 @@ def __init__(self):
"lgpo_section": self.account_lockout_policy_gpedit_path,
"Settings": {
"Function": "_in_range_inclusive",
"Args": {"min": 0, "max": 6000000},
"Args": {
"min": 0,
"max": 6000000,
"zero_value": 0xFFFFFFFF,
},
},
"NetUserModal": {"Modal": 3, "Option": "lockout_duration"},
"Transform": {
"Get": "_seconds_to_minutes",
"Put": "_minutes_to_seconds",
"GetArgs": {"zero_value": 0xFFFFFFFF},
"PutArgs": {"zero_value": 0xFFFFFFFF},
},
},
"LockoutThreshold": {
Expand Down Expand Up @@ -4252,7 +4258,10 @@ def _seconds_to_minutes(cls, val, **kwargs):
"""
converts a number of seconds to minutes
"""
zero_value = kwargs.get("zero_value", 0)
if val is not None:
if val == zero_value:
return 0
return val / 60
else:
return "Not Defined"
Expand All @@ -4262,7 +4271,10 @@ def _minutes_to_seconds(cls, val, **kwargs):
"""
converts number of minutes to seconds
"""
zero_value = kwargs.get("zero_value", 0)
if val is not None:
if val == 0:
return zero_value
return val * 60
else:
return "Not Defined"
Expand Down
21 changes: 21 additions & 0 deletions tests/integration/modules/test_win_lgpo.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,27 @@ def test_set_computer_policy_ClipboardRedirection(self):
],
)

@destructiveTest
def test_set_computer_policy_LockoutDuration(self):
"""
Test setting LockoutDuration
"""
# For LockoutDuration to be meaningful, first configure
# LockoutThreshold
self._testSeceditPolicy("LockoutThreshold", 3, [r"^LockoutBadCount = 3"])

# Next set the LockoutDuration non-zero value, as this is required
# before setting LockoutWindow
self._testSeceditPolicy("LockoutDuration", 60, [r"^LockoutDuration = 60"])

# Now set LockoutWindow to a valid value <= LockoutDuration. If this
# is not set, then the LockoutDuration zero value is ignored by the
# Windows API (leading to a false sense of accomplishment)
self._testSeceditPolicy("LockoutWindow", 60, [r"^ResetLockoutCount = 60"])

# set LockoutDuration zero value, the secedit zero value is -1
self._testSeceditPolicy("LockoutDuration", 0, [r"^LockoutDuration = -1"])

@destructiveTest
def test_set_computer_policy_GuestAccountStatus(self):
"""
Expand Down