Skip to content

Commit

Permalink
Merge pull request saltstack#56408 from lorengordon/lockoutduration
Browse files Browse the repository at this point in the history
Uses correct zero value for lgpo LockoutDuration
  • Loading branch information
dwoz authored Apr 22, 2020
2 parents 4d21cb5 + 8f79096 commit 569426f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
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 @@ -555,6 +555,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

0 comments on commit 569426f

Please sign in to comment.