mirror of
https://github.com/SELinuxProject/selinux
synced 2025-01-19 03:40:50 +00:00
libselinux: make python bindings for restorecon work on relative path
This patch just makes python bindings for restorecon work on relative paths. $ cd /etc $ python > import selinux > selinux.restorecon("resolv.conf") Signed-off-by: Eric Paris <eparis@redhat.com> Acked-by: Dan Walsh <dwalsh@redhat.com>
This commit is contained in:
parent
2ea80c28a5
commit
c7ed95f449
@ -12,8 +12,15 @@ import shutil, os, stat
|
||||
|
||||
def restorecon(path, recursive=False):
|
||||
""" Restore SELinux context on a given path """
|
||||
mode = os.lstat(path)[stat.ST_MODE]
|
||||
status, context = matchpathcon(path, mode)
|
||||
|
||||
try:
|
||||
mode = os.lstat(path)[stat.ST_MODE]
|
||||
status, context = matchpathcon(path, mode)
|
||||
except OSError:
|
||||
path = os.path.realpath(os.path.expanduser(path))
|
||||
mode = os.lstat(path)[stat.ST_MODE]
|
||||
status, context = matchpathcon(path, mode)
|
||||
|
||||
if status == 0:
|
||||
lsetfilecon(path, context)
|
||||
if recursive:
|
||||
|
Loading…
Reference in New Issue
Block a user