Skip to contentSkip to conversation

Add chcon method to libselinux python bindings

PATCH In review Steve Lawrence 3 participants 3 messages Jun 7, 2010 – Jun 10, 2010 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add chcon method to libselinux python bindings

Adds a chcon method to the libselinux python bindings to change the context of a file/directory tree.

---
 libselinux/src/selinuxswig_python.i |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
libselinux/src/selinuxswig_python.i +8 -0
index 8b34c99..dea0e80 100644
@@ -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)
Signature · 7 lines
1.6.2.5


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#1 lore raw

I like it, I have basically the same code in sandbox. and would move to this implementation if it is added to libselinux.

Quoted 15 lines · Steve Lawrence

Adds a chcon method to the libselinux python bindings to change the context of a file/directory tree.

---
  libselinux/src/selinuxswig_python.i |    8 ++++++++
  1 files changed, 8 insertions(+), 0 deletions(-)
libselinux/src/selinuxswig_python.i +1 -0
index 8b34c99..dea0e80 100644
@@ -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):

libselinux/src/selinuxswig_python.i def restorecon(path, recursive=False): · line 34

Quoted 10 lines
libselinux/src/selinuxswig_python.i +7 -0
+    """ 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)

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

Acked-by on v1 1/1
#2 lore raw
In reply to Steve Lawrence
Quoted 16 lines · Steve Lawrence

Adds a chcon method to the libselinux python bindings to change the context of a file/directory tree.

---
 libselinux/src/selinuxswig_python.i |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
libselinux/src/selinuxswig_python.i +1 -0
index 8b34c99..dea0e80 100644
@@ -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):

libselinux/src/selinuxswig_python.i def restorecon(path, recursive=False): · line 34

Quoted 10 lines
libselinux/src/selinuxswig_python.i +7 -0
+    """ 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)

Merged as of libselinux 2.0.95

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.