From 537721089af4466962e1520a571e4478d040edb3 Mon Sep 17 00:00:00 2001 From: Steve Lawrence Date: Thu, 10 Jun 2010 13:56:57 -0400 Subject: [PATCH] Author: Steve Lawrence Email: slawrence@tresys.com Subject: Add chcon method to libselinux python bindings Date: Mon, 7 Jun 2010 17:40:05 -0400 Adds a chcon method to the libselinux python bindings to change the context of a file/directory tree. Signed-off-by: Chad Sellers --- libselinux/src/selinuxswig_python.i | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libselinux/src/selinuxswig_python.i b/libselinux/src/selinuxswig_python.i index 8b34c995..dea0e80c 100644 --- a/libselinux/src/selinuxswig_python.i +++ b/libselinux/src/selinuxswig_python.i @@ -21,6 +21,14 @@ def restorecon(path, recursive=False): map(restorecon, [os.path.join(dirname, fname) for fname in fnames]), None) +def chcon(path, context, recursive=False): + """ Set the SELinux context on a given path """ + lsetfilecon(path, context) + if recursive: + for root, dirs, files in os.walk(path): + for name in files + dirs: + lsetfilecon(os.path.join(root,name), context) + def copytree(src, dest): """ An SELinux-friendly shutil.copytree method """ shutil.copytree(src, dest)