mirror of
https://github.com/SELinuxProject/selinux
synced 2025-04-29 06:07:58 +00:00
python/restorecon: add force option
This adds 'force' keyword argument to selinux.restorecon() function using SELINUX_RESTORECON_SET_SPECFILE_CTX flag. Signed-off-by: Viktor Ashirov <vashirov@redhat.com>
This commit is contained in:
parent
ae03c821b7
commit
474a09233c
@ -20,7 +20,7 @@ DISABLED = -1
|
|||||||
PERMISSIVE = 0
|
PERMISSIVE = 0
|
||||||
ENFORCING = 1
|
ENFORCING = 1
|
||||||
|
|
||||||
def restorecon(path, recursive=False, verbose=False):
|
def restorecon(path, recursive=False, verbose=False, force=False):
|
||||||
""" Restore SELinux context on a given path
|
""" Restore SELinux context on a given path
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
@ -29,6 +29,9 @@ def restorecon(path, recursive=False, verbose=False):
|
|||||||
Keyword arguments:
|
Keyword arguments:
|
||||||
recursive -- Change files and directories file labels recursively (default False)
|
recursive -- Change files and directories file labels recursively (default False)
|
||||||
verbose -- Show changes in file labels (default False)
|
verbose -- Show changes in file labels (default False)
|
||||||
|
force -- Force reset of context to match file_context for customizable files,
|
||||||
|
and the default file context, changing the user, role, range portion as well
|
||||||
|
as the type (default False)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
restorecon_flags = SELINUX_RESTORECON_IGNORE_DIGEST | SELINUX_RESTORECON_REALPATH
|
restorecon_flags = SELINUX_RESTORECON_IGNORE_DIGEST | SELINUX_RESTORECON_REALPATH
|
||||||
@ -36,6 +39,8 @@ def restorecon(path, recursive=False, verbose=False):
|
|||||||
restorecon_flags |= SELINUX_RESTORECON_RECURSE
|
restorecon_flags |= SELINUX_RESTORECON_RECURSE
|
||||||
if verbose:
|
if verbose:
|
||||||
restorecon_flags |= SELINUX_RESTORECON_VERBOSE
|
restorecon_flags |= SELINUX_RESTORECON_VERBOSE
|
||||||
|
if force:
|
||||||
|
restorecon_flags |= SELINUX_RESTORECON_SET_SPECFILE_CTX
|
||||||
selinux_restorecon(os.path.expanduser(path), restorecon_flags)
|
selinux_restorecon(os.path.expanduser(path), restorecon_flags)
|
||||||
|
|
||||||
def chcon(path, context, recursive=False):
|
def chcon(path, context, recursive=False):
|
||||||
|
Loading…
Reference in New Issue
Block a user