Bug 698583

Summary: restorecon from libselinux-python fails on relative paths
Product: Red Hat Enterprise Linux 6 Reporter: Milos Malik <mmalik>
Component: libselinuxAssignee: Daniel Walsh <dwalsh>
Status: CLOSED ERRATA QA Contact: Milos Malik <mmalik>
Severity: medium Docs Contact:
Priority: medium    
Version: 6.1CC: dwalsh, mgrepl, syeghiay, twoerner
Target Milestone: rc   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: libselinux-2.0.94-5.1.el6 Doc Type: Bug Fix
Doc Text:
Prior to this update, Python bindings for the restorecon command required a user to specify the entire path. Consequent to this, an attempt to use the selinux.restorecon() function with a relative path failed with the following error message: OSError: [Errno 2] No such file or directory This update corrects the Python bindings to allow the use of the selinux.restorecon() function with a relative path or just a file name.
Story Points: ---
Clone Of: 695760 Environment:
Last Closed: 2011-12-06 10:02:16 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Bug Depends On: 695760    
Bug Blocks:    

Description Milos Malik 2011-04-21 10:06:47 UTC
+++ This bug was initially created as a clone of Bug #695760 +++

Created attachment 491521 [details]
python test case

Description of problem:
restorecon from libselinux-python fails on relative paths.

Version-Release number of selected component (if applicable):
libselinux-2.0.94-5.el6
libselinux-python-2.0.94-5
libselinux-utils-2.0.94-5

How reproducible:
Always

Steps to Reproduce:
1. run the attached reproducer
2.
3.
  
Actual results:
Traceback (most recent call last):
  File "/tmp/s.py", line 11, in <module>
    selinux.restorecon(path, True)
  File "/usr/lib64/python2.7/site-packages/selinux/__init__.py", line 74, in restorecon
    status, context = matchpathcon(path, mode)
OSError: [Errno 2] No such file or directory

Expected results:
restored context

Comment 1 Milos Malik 2011-04-21 10:13:12 UTC
I forgot to update the "Actual results" section.

# python s.py 
Traceback (most recent call last):
  File "s.py", line 11, in <module>
    selinux.restorecon(path, True)
  File "/usr/lib/python2.6/site-packages/selinux/__init__.py", line 74, in restorecon
    status, context = matchpathcon(path, mode)
OSError: [Errno 2] No such file or directory
# echo $?
1

Comment 2 Daniel Walsh 2011-05-25 17:24:24 UTC
Fixed in libselinux-2.0.94-5.1.el6

Comment 7 Milos Malik 2011-07-29 13:25:05 UTC
# matchpathcon /mnt/testarea/tests/libselinux/Regression/bz698583-relative-paths/
/mnt/testarea/tests/libselinux/Regression/bz698583-relative-paths	<<none>>
# 

OK, I will modify the automated test.

Comment 9 Jaromir Hradilek 2011-10-26 15:12:55 UTC
    Technical note added. If any revisions are required, please edit the "Technical Notes" field
    accordingly. All revisions will be proofread by the Engineering Content Services team.
    
    New Contents:
Prior to this update, Python bindings for the restorecon command required a user to specify the entire path. Consequent to this, an attempt to use the selinux.restorecon() function with a relative path failed with the following error message:

    OSError: [Errno 2] No such file or directory

This update corrects the Python bindings to allow the use of the selinux.restorecon() function with a relative path or just a file name.

Comment 10 errata-xmlrpc 2011-12-06 10:02:16 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

http://rhn.redhat.com/errata/RHBA-2011-1559.html