16
16
import sys
17
17
import tempfile
18
18
19
+ import salt .utils .files
19
20
import salt .utils .path
20
21
import salt .utils .platform
22
+ import salt .utils .user
21
23
from salt .exceptions import CommandExecutionError , SaltInvocationError
22
24
from salt .modules .file import (
23
25
__clean_tmp ,
107
109
except ImportError :
108
110
HAS_WINDOWS_MODULES = False
109
111
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
+
110
121
if salt .utils .platform .is_windows ():
111
122
if HAS_WINDOWS_MODULES :
112
123
# namespace functions from file.py
@@ -194,6 +205,8 @@ def __virtual__():
194
205
"""
195
206
if not salt .utils .platform .is_windows () or not HAS_WINDOWS_MODULES :
196
207
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"
197
210
return __virtualname__
198
211
199
212
@@ -305,7 +318,7 @@ def group_to_gid(group):
305
318
if group is None :
306
319
return ""
307
320
308
- return __utils__ [ "dacl. get_sid_string" ] (group )
321
+ return salt . utils . win_dacl . get_sid_string (group )
309
322
310
323
311
324
def get_pgid (path , follow_symlinks = True ):
@@ -346,8 +359,8 @@ def get_pgid(path, follow_symlinks=True):
346
359
if follow_symlinks and sys .getwindowsversion ().major >= 6 :
347
360
path = _resolve_symlink (path )
348
361
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 )
351
364
352
365
353
366
def get_pgroup (path , follow_symlinks = True ):
@@ -498,7 +511,7 @@ def uid_to_user(uid):
498
511
if uid is None or uid == "" :
499
512
return ""
500
513
501
- return __utils__ [ "dacl. get_name" ] (uid )
514
+ return salt . utils . win_dacl . get_name (uid )
502
515
503
516
504
517
def user_to_uid (user ):
@@ -518,9 +531,9 @@ def user_to_uid(user):
518
531
salt '*' file.user_to_uid myusername
519
532
"""
520
533
if user is None :
521
- user = __utils__ [ " user.get_user" ] ()
534
+ user = salt . utils . user .get_user ()
522
535
523
- return __utils__ [ "dacl. get_sid_string" ] (user )
536
+ return salt . utils . win_dacl . get_sid_string (user )
524
537
525
538
526
539
def get_uid (path , follow_symlinks = True ):
@@ -558,8 +571,8 @@ def get_uid(path, follow_symlinks=True):
558
571
if follow_symlinks and sys .getwindowsversion ().major >= 6 :
559
572
path = _resolve_symlink (path )
560
573
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 )
563
576
564
577
565
578
def get_user (path , follow_symlinks = True ):
@@ -597,7 +610,7 @@ def get_user(path, follow_symlinks=True):
597
610
if follow_symlinks and sys .getwindowsversion ().major >= 6 :
598
611
path = _resolve_symlink (path )
599
612
600
- return __utils__ [ "dacl. get_owner" ] (path )
613
+ return salt . utils . win_dacl . get_owner (path )
601
614
602
615
603
616
def get_mode (path ):
@@ -735,9 +748,9 @@ def chown(path, user, group=None, pgroup=None, follow_symlinks=True):
735
748
if not os .path .exists (path ):
736
749
raise CommandExecutionError (f"Path not found: { path } " )
737
750
738
- __utils__ [ "dacl. set_owner" ] (path , user )
751
+ salt . utils . win_dacl . set_owner (path , user )
739
752
if pgroup :
740
- __utils__ [ "dacl. set_primary_group" ] (path , pgroup )
753
+ salt . utils . win_dacl . set_primary_group (path , pgroup )
741
754
742
755
return True
743
756
@@ -767,7 +780,7 @@ def chpgrp(path, group):
767
780
salt '*' file.chpgrp c:\\ temp\\ test.txt Administrators
768
781
salt '*' file.chpgrp c:\\ temp\\ test.txt "'None'"
769
782
"""
770
- return __utils__ [ "dacl. set_primary_group" ] (path , group )
783
+ return salt . utils . win_dacl . set_primary_group (path , group )
771
784
772
785
773
786
def chgrp (path , group ):
@@ -802,7 +815,7 @@ def chgrp(path, group):
802
815
803
816
.. code-block:: bash
804
817
805
- salt '*' file.chpgrp c:\\ temp\\ test.txt administrators
818
+ salt '*' file.chgrp c:\\ temp\\ test.txt administrators
806
819
"""
807
820
func_name = f"{ __virtualname__ } .chgrp"
808
821
if __opts__ .get ("fun" , "" ) == func_name :
@@ -871,7 +884,7 @@ def stats(path, hash_type="sha256", follow_symlinks=True):
871
884
ret ["mtime" ] = pstat .st_mtime
872
885
ret ["ctime" ] = pstat .st_ctime
873
886
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 )))
875
888
if hash_type :
876
889
ret ["sum" ] = get_sum (path , hash_type )
877
890
ret ["type" ] = "file"
@@ -1513,7 +1526,7 @@ def is_link(path):
1513
1526
)
1514
1527
1515
1528
try :
1516
- return __utils__ [ " path.islink" ] (path )
1529
+ return salt . utils . path .islink (path )
1517
1530
except Exception as exc : # pylint: disable=broad-except
1518
1531
raise CommandExecutionError (exc )
1519
1532
@@ -1604,10 +1617,10 @@ def mkdir(
1604
1617
1605
1618
# Set owner
1606
1619
if owner :
1607
- __utils__ [ "dacl. set_owner" ] (obj_name = path , principal = owner )
1620
+ salt . utils . win_dacl . set_owner (obj_name = path , principal = owner )
1608
1621
1609
1622
# Set permissions
1610
- __utils__ [ "dacl. set_perms" ] (
1623
+ salt . utils . win_dacl . set_perms (
1611
1624
obj_name = path ,
1612
1625
obj_type = "file" ,
1613
1626
grant_perms = grant_perms ,
@@ -1926,7 +1939,7 @@ def check_perms(
1926
1939
1927
1940
path = os .path .expanduser (path )
1928
1941
1929
- return __utils__ [ "dacl. check_perms" ] (
1942
+ return salt . utils . win_dacl . check_perms (
1930
1943
obj_name = path ,
1931
1944
obj_type = "file" ,
1932
1945
ret = ret ,
@@ -1935,6 +1948,7 @@ def check_perms(
1935
1948
deny_perms = deny_perms ,
1936
1949
inheritance = inheritance ,
1937
1950
reset = reset ,
1951
+ test_mode = __opts__ ["test" ],
1938
1952
)
1939
1953
1940
1954
@@ -2012,7 +2026,7 @@ def set_perms(path, grant_perms=None, deny_perms=None, inheritance=True, reset=F
2012
2026
# Specify advanced attributes with a list
2013
2027
salt '*' file.set_perms C:\\ Temp\\ "{'jsnuffy': {'perms': ['read_attributes', 'read_ea'], 'applies_to': 'this_folder_only'}}"
2014
2028
"""
2015
- return __utils__ [ "dacl. set_perms" ] (
2029
+ return salt . utils . win_dacl . set_perms (
2016
2030
obj_name = path ,
2017
2031
obj_type = "file" ,
2018
2032
grant_perms = grant_perms ,
0 commit comments