Skip to content

Commit

Permalink
Merge pull request #55780 from lukasraska/fix-54809
Browse files Browse the repository at this point in the history
Fallback to disabled LG_INCLUDE_INDIRECT when DC is unavailable
  • Loading branch information
dwoz authored Jan 3, 2020
2 parents ba07d56 + 24f71ba commit 8786e71
Showing 2 changed files with 27 additions and 2 deletions.
5 changes: 3 additions & 2 deletions salt/utils/win_functions.py
Original file line number Diff line number Diff line change
@@ -88,9 +88,10 @@ def get_user_groups(name, sid=False):
try:
groups = win32net.NetUserGetLocalGroups(None, name)
except win32net.error as exc:
if exc.winerror == 5:
# ERROR_ACCESS_DENIED, NERR_DCNotFound, RPC_S_SERVER_UNAVAILABLE
if exc.winerror in (5, 1722, 2453):
# Try without LG_INCLUDE_INDIRECT flag, because the user might
# not have permissions for it
# not have permissions for it or something is wrong with DC
groups = win32net.NetUserGetLocalGroups(None, name, 0)
else:
raise
24 changes: 24 additions & 0 deletions tests/unit/utils/test_win_functions.py
Original file line number Diff line number Diff line change
@@ -93,6 +93,30 @@ def test_get_user_groups_system(self):
ret = win_functions.get_user_groups('SYSTEM')
self.assertListEqual(groups, ret)

@skipIf(not salt.utils.platform.is_windows(),
'WinDLL only available on Windows')
@skipIf(not HAS_WIN32, 'Requires pywin32 libraries')
def test_get_user_groups_unavailable_dc(self):
groups = ['Administrators', 'Users']
win_error = WinError()
win_error.winerror = 1722
effect = [win_error, groups]
with patch('win32net.NetUserGetLocalGroups', side_effect=effect):
ret = win_functions.get_user_groups('Administrator')
self.assertListEqual(groups, ret)

@skipIf(not salt.utils.platform.is_windows(),
'WinDLL only available on Windows')
@skipIf(not HAS_WIN32, 'Requires pywin32 libraries')
def test_get_user_groups_unknown_dc(self):
groups = ['Administrators', 'Users']
win_error = WinError()
win_error.winerror = 2453
effect = [win_error, groups]
with patch('win32net.NetUserGetLocalGroups', side_effect=effect):
ret = win_functions.get_user_groups('Administrator')
self.assertListEqual(groups, ret)

@skipIf(not salt.utils.platform.is_windows(),
'WinDLL only available on Windows')
@skipIf(not HAS_WIN32, 'Requires pywin32 libraries')

0 comments on commit 8786e71

Please sign in to comment.