[PATCH 010/155] libselinux: make python bindings for restorecon work

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


This patch looks good to me. acked.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk45tJoACgkQrlYvE4MpobO9DgCgyXO0eHme6svwTzTi/uF2wHpi
IJgAn3gXydwv63AXuawlBLjQZWT0Lk7Q
=REBv
-----END PGP SIGNATURE-----
>From 8c8bae801ee3e64900cae99465893cce6484a7b8 Mon Sep 17 00:00:00 2001
From: Eric Paris <eparis@xxxxxxxxxx>
Date: Wed, 29 Jun 2011 00:32:30 -0400
Subject: [PATCH 010/155] 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@xxxxxxxxxx>
---
 libselinux/src/selinuxswig_python.i |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/libselinux/src/selinuxswig_python.i b/libselinux/src/selinuxswig_python.i
index faf7ac5..daf8314 100644
--- a/libselinux/src/selinuxswig_python.i
+++ b/libselinux/src/selinuxswig_python.i
@@ -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:
-- 
1.7.6

Attachment: 0010-libselinux-make-python-bindings-for-restorecon-work-.patch.sig
Description: PGP signature


[Index of Archives]     [Selinux Refpolicy]     [Linux SGX]     [Fedora Users]     [Fedora Desktop]     [Yosemite Photos]     [Yosemite Camping]     [Yosemite Campsites]     [KDE Users]     [Gnome Users]

  Powered by Linux