summaryrefslogtreecommitdiff
path: root/cloudinit/util.py
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2011-10-30 17:17:03 -0400
committerScott Moser <smoser@ubuntu.com>2011-10-30 17:17:03 -0400
commit25824d2007e062f32a7bf3c502eaf9b8f2bf4c15 (patch)
tree9a70da85e6faf0265386dac0ce7ea08d01ece44c /cloudinit/util.py
parent6d9f6dfcf7e28f398b426c18ca36adeec24f8061 (diff)
downloadvyos-cloud-init-25824d2007e062f32a7bf3c502eaf9b8f2bf4c15.tar.gz
vyos-cloud-init-25824d2007e062f32a7bf3c502eaf9b8f2bf4c15.zip
Restore created files' selinux contexts
This adds a restorecon_if_possible method which uses selinux python module, and uses that for files modified in /etc. taken from git://pkgs.fedoraproject.org/cloud-init.git commit 87f33190f43d2b26cced4597e7298835024466c2 Author: Garrett Holmstrom <gholms@fedoraproject.org> Patch3: cloud-init-0.6.2-filecontext.patch
Diffstat (limited to 'cloudinit/util.py')
-rw-r--r--cloudinit/util.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/cloudinit/util.py b/cloudinit/util.py
index 68ce674e..744fb71e 100644
--- a/cloudinit/util.py
+++ b/cloudinit/util.py
@@ -28,6 +28,12 @@ import time
import traceback
import re
+try:
+ import selinux
+ HAVE_LIBSELINUX = True
+except ImportError:
+ HAVE_LIBSELINUX = False
+
def read_conf(fname):
try:
stream = open(fname,"r")
@@ -113,6 +119,11 @@ def write_file(file,content,mode=0644,omode="wb"):
os.chmod(file,mode)
f.write(content)
f.close()
+ restorecon_if_possible(file)
+
+def restorecon_if_possible(path, recursive=False):
+ if HAVE_LIBSELINUX and selinux.is_selinux_enabled():
+ selinux.restorecon(path, recursive=recursive)
# get keyid from keyserver
def getkeybyid(keyid,keyserver):