Bug 189967

Summary: cp -Z doesn't set the SE Linux context if a file exists
Product: [Fedora] Fedora Reporter: Russell Coker <rcoker>
Component: coreutilsAssignee: Tim Waugh <twaugh>
Status: CLOSED RAWHIDE QA Contact:
Severity: medium Docs Contact:
Priority: medium    
Version: rawhideCC: meyering
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Fixed In Version: 5.94-4 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2006-04-26 06:59:36 EDT Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---
Description Flags
patch to fix this bug none

Description Russell Coker 2006-04-26 06:47:02 EDT
Description of problem:

The command "cp -Z root:object_r:tmp_t file-a file-b" does not set the context 
of file-b if it already exists.  If the file does not exist then it operates 

This is because the "-Z" option of cp sets the default context for new files 
that are created.  If a file exists then cp does not unlink and recreate it, 
but instead just truncates it.

One potential solution would be to unlink and recreate the file.  My solution 
has been to apply the create context when truncating the file (patch 
attached).  If you don't like my patch then let me know what you would like 
and I'll re-write it.
Comment 1 Russell Coker 2006-04-26 06:47:02 EDT
Created attachment 128246 [details]
patch to fix this bug
Comment 2 Tim Waugh 2006-04-26 06:59:36 EDT
Thanks.  Applied in 5.94-4.
Comment 3 Tim Waugh 2006-10-04 09:33:45 EDT
This got broken again in rawhide.  Fixed in 5.97-12.