mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Setting the mode with setuid or setgid bits in addition to setting the owner and group will force the setuid & setgid bits to reset. This change ensures that we set the mode after setting the owner & group.
This commit is contained in:
parent
2fd63d66dc
commit
2b25d8c95b
2 changed files with 48 additions and 21 deletions
|
@ -4463,27 +4463,6 @@ def check_perms(name, ret, user, group, mode, attrs=None, follow_symlinks=False)
|
|||
if perms['lattrs']:
|
||||
chattr(name, operator='remove', attributes=perms['lattrs'])
|
||||
|
||||
# Mode changes if needed
|
||||
if mode is not None:
|
||||
# File is a symlink, ignore the mode setting
|
||||
# if follow_symlinks is False
|
||||
if os.path.islink(name) and not follow_symlinks:
|
||||
pass
|
||||
else:
|
||||
mode = salt.utils.files.normalize_mode(mode)
|
||||
if mode != perms['lmode']:
|
||||
if __opts__['test'] is True:
|
||||
ret['changes']['mode'] = mode
|
||||
else:
|
||||
set_mode(name, mode)
|
||||
if mode != salt.utils.files.normalize_mode(get_mode(name)):
|
||||
ret['result'] = False
|
||||
ret['comment'].append(
|
||||
'Failed to change mode to {0}'.format(mode)
|
||||
)
|
||||
else:
|
||||
ret['changes']['mode'] = mode
|
||||
|
||||
# user/group changes if needed, then check if it worked
|
||||
if user:
|
||||
if isinstance(user, int):
|
||||
|
@ -4572,6 +4551,27 @@ def check_perms(name, ret, user, group, mode, attrs=None, follow_symlinks=False)
|
|||
if perms.get('lattrs', ''):
|
||||
chattr(name, operator='add', attributes=perms['lattrs'])
|
||||
|
||||
# Mode changes if needed
|
||||
if mode is not None:
|
||||
# File is a symlink, ignore the mode setting
|
||||
# if follow_symlinks is False
|
||||
if os.path.islink(name) and not follow_symlinks:
|
||||
pass
|
||||
else:
|
||||
mode = salt.utils.files.normalize_mode(mode)
|
||||
if mode != perms['lmode']:
|
||||
if __opts__['test'] is True:
|
||||
ret['changes']['mode'] = mode
|
||||
else:
|
||||
set_mode(name, mode)
|
||||
if mode != salt.utils.files.normalize_mode(get_mode(name)):
|
||||
ret['result'] = False
|
||||
ret['comment'].append(
|
||||
'Failed to change mode to {0}'.format(mode)
|
||||
)
|
||||
else:
|
||||
ret['changes']['mode'] = mode
|
||||
|
||||
# Modify attributes of file if needed
|
||||
if attrs is not None and not is_dir:
|
||||
# File is a symlink, ignore the mode setting
|
||||
|
|
|
@ -2271,6 +2271,33 @@ class FileTest(ModuleCase, SaltReturnAssertsMixin):
|
|||
except OSError:
|
||||
pass
|
||||
|
||||
@skip_if_not_root
|
||||
@skipIf(not HAS_PWD, "pwd not available. Skipping test")
|
||||
@skipIf(not HAS_GRP, "grp not available. Skipping test")
|
||||
@with_system_user_and_group('user12209', 'group12209',
|
||||
on_existing='delete', delete=True)
|
||||
@with_tempdir()
|
||||
def test_issue_48336_file_managed_mode_setuid(self, tempdir, user, group):
|
||||
'''
|
||||
Ensure that mode is correct with changing of ownership and group
|
||||
symlinks)
|
||||
'''
|
||||
tempfile = os.path.join(tempdir, 'temp_file_issue_48336')
|
||||
|
||||
# Run the state
|
||||
ret = self.run_state(
|
||||
'file.managed', name=tempfile,
|
||||
user=user, group=group, mode='4750',
|
||||
)
|
||||
self.assertSaltTrueReturn(ret)
|
||||
|
||||
# Check that the owner and group are correct, and
|
||||
# the mode is what we expect
|
||||
temp_file_stats = os.stat(tempfile)
|
||||
self.assertEqual(six.text_type(oct(stat.S_IMODE(temp_file_stats.st_mode))), '04750')
|
||||
self.assertEqual(pwd.getpwuid(temp_file_stats.st_uid).pw_name, user)
|
||||
self.assertEqual(grp.getgrgid(temp_file_stats.st_gid).gr_name, group)
|
||||
|
||||
|
||||
class BlockreplaceTest(ModuleCase, SaltReturnAssertsMixin):
|
||||
marker_start = '# start'
|
||||
|
|
Loading…
Add table
Reference in a new issue