Bug 716391 - slip.util.files.overwrite_safely fails when SELinux is disabled
Summary: slip.util.files.overwrite_safely fails when SELinux is disabled
Keywords:
Status: CLOSED DUPLICATE of bug 720848
Alias: None
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: python-slip
Version: 6.1
Hardware: All
OS: Linux
low
medium
Target Milestone: rc
: ---
Assignee: Nils Philippsen
QA Contact: Desktop QE
URL:
Whiteboard:
Depends On: 627788
Blocks:
TreeView+ depends on / blocked
 
Reported: 2011-06-24 09:32 UTC by J.H.M. Dassen (Ray)
Modified: 2013-07-03 04:17 UTC (History)
3 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of: 627788
Environment:
Last Closed: 2011-11-22 11:20:37 UTC
Target Upstream Version:


Attachments (Terms of Use)

Description J.H.M. Dassen (Ray) 2011-06-24 09:32:09 UTC
+++ This bug was initially created as a clone of Bug #627788 +++

Description of problem:
If SELinux is disabled, when slip.util.files.overwrite_safely is called with
the default preserve_context=True, it fails because it cannot read the
"security.selinux" xattr of the destination file.  This makes it impossible
to save the configuration in system-config-date.

Version-Release number of selected component (if applicable):
python-slip-0.2.12-1.fc13.noarch

How reproducible:
Always

Steps to Reproduce:
touch foo
python <<SCRIPT
from slip.util.files import overwrite_safely
overwrite_safely("foo", "content")
SCRIPT
  
Actual results:
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "/usr/lib/python2.6/site-packages/slip/util/files.py", line 179, in overwrite_safely
    ret, ctx = selinux.getfilecon(path)
OSError: [Errno 61] No data available

Expected results:
The file is successfully written.

--- Additional comment from nphilipp on 2010-08-31 09:47:57 EDT ---

I seem to have misunderstood the possible return values of selinux.is_selinux_enabled():

commit 6502bebb6b94d613e84e2cc517a299e2cb9028c9
Author: Nils Philippsen <nils>
Date:   Tue Aug 31 15:43:30 2010 +0200

    fix overwrite_safely() if SELinux is disabled (#627788)

diff --git a/slip/util/files.py b/slip/util/files.py
index b248d17..1b2887d 100644
--- a/slip/util/files.py
+++ b/slip/util/files.py
@@ -165,7 +165,7 @@ def overwrite_safely(path, content, preserve_mode=True, preserve_context=True):
 
     exists = os.path.exists(path)
 
-    if preserve_context and selinux.is_selinux_enabled() < 0:
+    if preserve_context and selinux.is_selinux_enabled() <= 0:
         preserve_context = False
 
     try:

Comment 1 J.H.M. Dassen (Ray) 2011-06-24 09:33:10 UTC
Code inspection showed this issue to be present in RHEL6.

Comment 5 Nils Philippsen 2011-11-22 11:20:37 UTC

*** This bug has been marked as a duplicate of bug 720848 ***


Note You need to log in before you can comment on or make changes to this bug.