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:
Eric Paris 2011-06-29 00:32:30 -04:00
parent 2ea80c28a5
commit c7ed95f449

View File

@ -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: