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 <csellers@tresys.com>
This commit is contained in:
Steve Lawrence 2010-06-10 13:56:57 -04:00 committed by Chad Sellers
parent 8f007923dd
commit 537721089a
1 changed files with 8 additions and 0 deletions

View File

@ -21,6 +21,14 @@ def restorecon(path, recursive=False):
map(restorecon, [os.path.join(dirname, fname) map(restorecon, [os.path.join(dirname, fname)
for fname in fnames]), None) 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): def copytree(src, dest):
""" An SELinux-friendly shutil.copytree method """ """ An SELinux-friendly shutil.copytree method """
shutil.copytree(src, dest) shutil.copytree(src, dest)