Skip to content

Commit 93b6405

Browse files
authored
Merge pull request #65457 from s0undt3ch/hotfix/merge-forward
[master] Merge 3006.x into master
2 parents 0cf0214 + 90666c8 commit 93b6405

File tree

20 files changed

+528
-249
lines changed

20 files changed

+528
-249
lines changed

changelog/65411.fixed.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fixes an issue setting user or machine policy on Windows when the Group Policy
2+
directory is missing

salt/_compat.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
# pylint: disable=unused-import
55
import sys
66

7+
# pragma: no cover
8+
79
# The ipaddress module included in Salt is from Python 3.9.5.
810
# When running from Py3.9.5+ use the standard library module, use ours otherwise
911
if sys.version_info >= (3, 9, 5):

salt/modules/win_file.py

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616
import sys
1717
import tempfile
1818

19+
import salt.utils.files
1920
import salt.utils.path
2021
import salt.utils.platform
22+
import salt.utils.user
2123
from salt.exceptions import CommandExecutionError, SaltInvocationError
2224
from salt.modules.file import (
2325
__clean_tmp,
@@ -107,6 +109,15 @@
107109
except ImportError:
108110
HAS_WINDOWS_MODULES = False
109111

112+
HAS_WIN_DACL = False
113+
try:
114+
if salt.utils.platform.is_windows():
115+
import salt.utils.win_dacl
116+
117+
HAS_WIN_DACL = True
118+
except ImportError:
119+
HAS_WIN_DACL = False
120+
110121
if salt.utils.platform.is_windows():
111122
if HAS_WINDOWS_MODULES:
112123
# namespace functions from file.py
@@ -194,6 +205,8 @@ def __virtual__():
194205
"""
195206
if not salt.utils.platform.is_windows() or not HAS_WINDOWS_MODULES:
196207
return False, "Module win_file: Missing Win32 modules"
208+
if not HAS_WIN_DACL:
209+
return False, "Module win_file: Unable to load salt.utils.win_dacl"
197210
return __virtualname__
198211

199212

@@ -305,7 +318,7 @@ def group_to_gid(group):
305318
if group is None:
306319
return ""
307320

308-
return __utils__["dacl.get_sid_string"](group)
321+
return salt.utils.win_dacl.get_sid_string(group)
309322

310323

311324
def get_pgid(path, follow_symlinks=True):
@@ -346,8 +359,8 @@ def get_pgid(path, follow_symlinks=True):
346359
if follow_symlinks and sys.getwindowsversion().major >= 6:
347360
path = _resolve_symlink(path)
348361

349-
group_name = __utils__["dacl.get_primary_group"](path)
350-
return __utils__["dacl.get_sid_string"](group_name)
362+
group_name = salt.utils.win_dacl.get_primary_group(path)
363+
return salt.utils.win_dacl.get_sid_string(group_name)
351364

352365

353366
def get_pgroup(path, follow_symlinks=True):
@@ -498,7 +511,7 @@ def uid_to_user(uid):
498511
if uid is None or uid == "":
499512
return ""
500513

501-
return __utils__["dacl.get_name"](uid)
514+
return salt.utils.win_dacl.get_name(uid)
502515

503516

504517
def user_to_uid(user):
@@ -518,9 +531,9 @@ def user_to_uid(user):
518531
salt '*' file.user_to_uid myusername
519532
"""
520533
if user is None:
521-
user = __utils__["user.get_user"]()
534+
user = salt.utils.user.get_user()
522535

523-
return __utils__["dacl.get_sid_string"](user)
536+
return salt.utils.win_dacl.get_sid_string(user)
524537

525538

526539
def get_uid(path, follow_symlinks=True):
@@ -558,8 +571,8 @@ def get_uid(path, follow_symlinks=True):
558571
if follow_symlinks and sys.getwindowsversion().major >= 6:
559572
path = _resolve_symlink(path)
560573

561-
owner_sid = __utils__["dacl.get_owner"](path)
562-
return __utils__["dacl.get_sid_string"](owner_sid)
574+
owner_sid = salt.utils.win_dacl.get_owner(path)
575+
return salt.utils.win_dacl.get_sid_string(owner_sid)
563576

564577

565578
def get_user(path, follow_symlinks=True):
@@ -597,7 +610,7 @@ def get_user(path, follow_symlinks=True):
597610
if follow_symlinks and sys.getwindowsversion().major >= 6:
598611
path = _resolve_symlink(path)
599612

600-
return __utils__["dacl.get_owner"](path)
613+
return salt.utils.win_dacl.get_owner(path)
601614

602615

603616
def get_mode(path):
@@ -735,9 +748,9 @@ def chown(path, user, group=None, pgroup=None, follow_symlinks=True):
735748
if not os.path.exists(path):
736749
raise CommandExecutionError(f"Path not found: {path}")
737750

738-
__utils__["dacl.set_owner"](path, user)
751+
salt.utils.win_dacl.set_owner(path, user)
739752
if pgroup:
740-
__utils__["dacl.set_primary_group"](path, pgroup)
753+
salt.utils.win_dacl.set_primary_group(path, pgroup)
741754

742755
return True
743756

@@ -767,7 +780,7 @@ def chpgrp(path, group):
767780
salt '*' file.chpgrp c:\\temp\\test.txt Administrators
768781
salt '*' file.chpgrp c:\\temp\\test.txt "'None'"
769782
"""
770-
return __utils__["dacl.set_primary_group"](path, group)
783+
return salt.utils.win_dacl.set_primary_group(path, group)
771784

772785

773786
def chgrp(path, group):
@@ -802,7 +815,7 @@ def chgrp(path, group):
802815
803816
.. code-block:: bash
804817
805-
salt '*' file.chpgrp c:\\temp\\test.txt administrators
818+
salt '*' file.chgrp c:\\temp\\test.txt administrators
806819
"""
807820
func_name = f"{__virtualname__}.chgrp"
808821
if __opts__.get("fun", "") == func_name:
@@ -871,7 +884,7 @@ def stats(path, hash_type="sha256", follow_symlinks=True):
871884
ret["mtime"] = pstat.st_mtime
872885
ret["ctime"] = pstat.st_ctime
873886
ret["size"] = pstat.st_size
874-
ret["mode"] = __utils__["files.normalize_mode"](oct(stat.S_IMODE(pstat.st_mode)))
887+
ret["mode"] = salt.utils.files.normalize_mode(oct(stat.S_IMODE(pstat.st_mode)))
875888
if hash_type:
876889
ret["sum"] = get_sum(path, hash_type)
877890
ret["type"] = "file"
@@ -1513,7 +1526,7 @@ def is_link(path):
15131526
)
15141527

15151528
try:
1516-
return __utils__["path.islink"](path)
1529+
return salt.utils.path.islink(path)
15171530
except Exception as exc: # pylint: disable=broad-except
15181531
raise CommandExecutionError(exc)
15191532

@@ -1604,10 +1617,10 @@ def mkdir(
16041617

16051618
# Set owner
16061619
if owner:
1607-
__utils__["dacl.set_owner"](obj_name=path, principal=owner)
1620+
salt.utils.win_dacl.set_owner(obj_name=path, principal=owner)
16081621

16091622
# Set permissions
1610-
__utils__["dacl.set_perms"](
1623+
salt.utils.win_dacl.set_perms(
16111624
obj_name=path,
16121625
obj_type="file",
16131626
grant_perms=grant_perms,
@@ -1926,7 +1939,7 @@ def check_perms(
19261939

19271940
path = os.path.expanduser(path)
19281941

1929-
return __utils__["dacl.check_perms"](
1942+
return salt.utils.win_dacl.check_perms(
19301943
obj_name=path,
19311944
obj_type="file",
19321945
ret=ret,
@@ -1935,6 +1948,7 @@ def check_perms(
19351948
deny_perms=deny_perms,
19361949
inheritance=inheritance,
19371950
reset=reset,
1951+
test_mode=__opts__["test"],
19381952
)
19391953

19401954

@@ -2012,7 +2026,7 @@ def set_perms(path, grant_perms=None, deny_perms=None, inheritance=True, reset=F
20122026
# Specify advanced attributes with a list
20132027
salt '*' file.set_perms C:\\Temp\\ "{'jsnuffy': {'perms': ['read_attributes', 'read_ea'], 'applies_to': 'this_folder_only'}}"
20142028
"""
2015-
return __utils__["dacl.set_perms"](
2029+
return salt.utils.win_dacl.set_perms(
20162030
obj_name=path,
20172031
obj_type="file",
20182032
grant_perms=grant_perms,

0 commit comments

Comments
 (0)