Skip to contentSkip to conversation

python/restorecon: add force option

PATCH In review Viktor Ashirov 2 participants 3 messages Jan 30, 2019 – Feb 5, 2019 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 python/restorecon: add force option

This adds 'force' keyword argument to selinux.restorecon() function using SELINUX_RESTORECON_SET_SPECFILE_CTX flag.

---
 libselinux/src/selinuxswig_python.i | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
libselinux/src/selinuxswig_python.i +6 -1
index 2af7c7e0..4c73bf92 100644
@@ -20,7 +20,7 @@ DISABLED = -1
 PERMISSIVE = 0
 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
 
     Arguments:
@@ -29,6 +29,9 @@ def restorecon(path, recursive=False, verbose=False):
     Keyword arguments:
     recursive -- Change files and directories file labels recursively (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
@@ -36,6 +39,8 @@ def restorecon(path, recursive=False, verbose=False):
         restorecon_flags |= SELINUX_RESTORECON_RECURSE
     if verbose:
         restorecon_flags |= SELINUX_RESTORECON_VERBOSE
+    if force:
+        restorecon_flags |= SELINUX_RESTORECON_SET_SPECFILE_CTX
     selinux_restorecon(os.path.expanduser(path), restorecon_flags)
 
 def chcon(path, context, recursive=False):
Signature · 1 line
2.20.1
Acked-by on v1 1/1
#1 lore raw
Quoted 5 lines · Viktor Ashirov

This adds 'force' keyword argument to selinux.restorecon() function using SELINUX_RESTORECON_SET_SPECFILE_CTX flag.

Quoted 39 lines
---
 libselinux/src/selinuxswig_python.i | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
libselinux/src/selinuxswig_python.i +6 -2
index 2af7c7e0..4c73bf92 100644
@@ -20,7 +20,7 @@ DISABLED = -1
 PERMISSIVE = 0
 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
 
     Arguments:
@@ -29,6 +29,9 @@ def restorecon(path, recursive=False, verbose=False):
     Keyword arguments:
     recursive -- Change files and directories file labels recursively (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
@@ -36,6 +39,8 @@ def restorecon(path, recursive=False, verbose=False):
         restorecon_flags |= SELINUX_RESTORECON_RECURSE
     if verbose:
         restorecon_flags |= SELINUX_RESTORECON_VERBOSE
+    if force:
+        restorecon_flags |= SELINUX_RESTORECON_SET_SPECFILE_CTX
     selinux_restorecon(os.path.expanduser(path), restorecon_flags)
 
 def chcon(path, context, recursive=False):
--

2.20.1

#2 lore raw
Quoted 9 lines · Nicolas Iooss
Quoted 5 lines · Viktor Ashirov

This adds 'force' keyword argument to selinux.restorecon() function using SELINUX_RESTORECON_SET_SPECFILE_CTX flag.

Merged. Thanks!
Nicolas

Quoted 39 lines
Quoted 39 lines
---
 libselinux/src/selinuxswig_python.i | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
libselinux/src/selinuxswig_python.i +6 -2
index 2af7c7e0..4c73bf92 100644
@@ -20,7 +20,7 @@ DISABLED = -1
 PERMISSIVE = 0
 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
 
     Arguments:
@@ -29,6 +29,9 @@ def restorecon(path, recursive=False, verbose=False):
     Keyword arguments:
     recursive -- Change files and directories file labels recursively (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
@@ -36,6 +39,8 @@ def restorecon(path, recursive=False, verbose=False):
         restorecon_flags |= SELINUX_RESTORECON_RECURSE
     if verbose:
         restorecon_flags |= SELINUX_RESTORECON_VERBOSE
+    if force:
+        restorecon_flags |= SELINUX_RESTORECON_SET_SPECFILE_CTX
     selinux_restorecon(os.path.expanduser(path), restorecon_flags)
 
 def chcon(path, context, recursive=False):
--

2.20.1