mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
commit
6e92cad2a1
1 changed files with 13 additions and 5 deletions
|
@ -4,18 +4,26 @@ Execute calls on selinux
|
|||
|
||||
import os
|
||||
|
||||
__selinux_fs_path__ = None
|
||||
|
||||
def __virtual__():
|
||||
'''
|
||||
Check if the os is Linux, and then if selinux is running in permissive or
|
||||
enforcing mode.
|
||||
'''
|
||||
global __selinux_fs_path__
|
||||
if __grains__['kernel'] == 'Linux':
|
||||
if os.path.isdir('/selinux'):
|
||||
if os.path.isfile('/selinux/enforce'):
|
||||
return 'selinux'
|
||||
# systems running systemd (e.g. Fedora 15 and newer)
|
||||
# have the selinux filesystem in a different location
|
||||
for directory in ['/sys/fs/selinux', '/selinux']:
|
||||
if os.path.isdir(directory):
|
||||
if os.path.isfile(os.path.join(directory, 'enforce')):
|
||||
__selinux_fs_path__ = directory
|
||||
return 'selinux'
|
||||
return False
|
||||
|
||||
def selinux_fs_path():
|
||||
return __selinux_fs_path__
|
||||
|
||||
def getenforce():
|
||||
'''
|
||||
|
@ -25,7 +33,7 @@ def getenforce():
|
|||
|
||||
salt '*' selinux.getenforce
|
||||
'''
|
||||
if open('/selinux/enforce', 'r').read() == '0':
|
||||
if open(os.path.join(__selinux_fs_path__, 'enforce'), 'r').read() == '0':
|
||||
return 'Permissive'
|
||||
else:
|
||||
return 'Enforcing'
|
||||
|
@ -38,7 +46,7 @@ def setenforce(mode):
|
|||
if isinstance(mode, str):
|
||||
if mode.lower() == 'enforcing':
|
||||
mode = '1'
|
||||
elif mode.lower() == 'Permissive':
|
||||
elif mode.lower() == 'permissive':
|
||||
mode = '0'
|
||||
else:
|
||||
return 'Invalid mode {0}'.format(mode)
|
||||
|
|
Loading…
Add table
Reference in a new issue