From 107d3890e7609b9a849162be947324f828c1aa9b Mon Sep 17 00:00:00 2001 From: Tomas Mraz Date: Jan 24 2014 17:48:29 +0000 Subject: Call restorecon when we could not obtain correct context via cp. --- diff --git a/authinfo.py b/authinfo.py index 97526e1..f01dc0a 100644 --- a/authinfo.py +++ b/authinfo.py @@ -1009,10 +1009,12 @@ class SaveGroup: class SafeFile: def __init__(self, filename, default_mode): (base, name) = os.path.split(filename) + self.missing = False self.file = tempfile.NamedTemporaryFile(dir=base, prefix=name, delete=True) # overwrite the inode attributes and contents if call(["/bin/cp", "-af", filename, self.file.name], stderr=os.open('/dev/null', os.O_WRONLY)) == 1: + self.missing = True # the mode was not copied, use the default os.fchmod(self.file.fileno(), default_mode) self.filename = filename @@ -1021,6 +1023,9 @@ class SafeFile: self.file.flush() os.fsync(self.file.fileno()) os.rename(self.file.name, self.filename) + if self.missing: + call(["/usr/sbin/restorecon", self.filename], + stderr=os.open('/dev/null', os.O_WRONLY)) def close(self): # we may have renamed the temp file, need to catch OSError