Set the umask prior to file creation (#315)

* Set the umask prior to file creation

* Set umask prior to file creation
This commit is contained in:
edneville
2016-07-20 18:35:22 +01:00
committed by Ahmet Alp Balkan
parent 29fb42a8f8
commit e8c641f726
2 changed files with 4 additions and 5 deletions

View File

@@ -200,13 +200,13 @@ class ResourceDiskHandler(object):
# fallocate command
fn_sh = shellutil.quote((filename,))
ret = shellutil.run(u"fallocate -l {0} {1}".format(nbytes, fn_sh))
ret = shellutil.run(u"umask 0077 && fallocate -l {0} {1}".format(nbytes, fn_sh))
if ret != 127: # 127 = command not found
return ret
# dd fallback
dd_maxbs = 64 * 1024 ** 2
dd_cmd = "dd if=/dev/zero bs={0} count={1} conv=notrunc of={2}"
dd_cmd = "umask 0077 && dd if=/dev/zero bs={0} count={1} conv=notrunc of={2}"
blocks = int(nbytes / dd_maxbs)
if blocks > 0:

View File

@@ -561,9 +561,8 @@ class AbstractDistro(object):
if os.path.isfile(mountpoint + "/swapfile") and os.path.getsize(mountpoint + "/swapfile") != (sizeKB * 1024):
os.remove(mountpoint + "/swapfile")
if not os.path.isfile(mountpoint + "/swapfile"):
Run("dd if=/dev/zero of=" + mountpoint + "/swapfile bs=1024 count=" + str(sizeKB))
Run("umask 0077 && dd if=/dev/zero of=" + mountpoint + "/swapfile bs=1024 count=" + str(sizeKB))
Run("mkswap " + mountpoint + "/swapfile")
Run("chmod 600 " + mountpoint + "/swapfile")
if not Run("swapon " + mountpoint + "/swapfile"):
Log("Enabled " + str(sizeKB) + " KB of swap at " + mountpoint + "/swapfile")
else:
@@ -1769,7 +1768,7 @@ sizeKB = int(Config.get("ResourceDisk.SwapSizeMB")) * 1024
if os.path.isfile(mountpoint + "/swapfile") and os.path.getsize(mountpoint + "/swapfile") != (sizeKB * 1024):
os.remove(mountpoint + "/swapfile")
if not os.path.isfile(mountpoint + "/swapfile"):
Run("dd if=/dev/zero of=" + mountpoint + "/swapfile bs=1024 count=" + str(sizeKB))
Run("umask 0077 && dd if=/dev/zero of=" + mountpoint + "/swapfile bs=1024 count=" + str(sizeKB))
if Run("mdconfig -a -t vnode -f " + mountpoint + "/swapfile -u 0"):
waagent.Error("ActivateResourceDisk: Configuring swap - Failed to create md0")
if not Run("swapon /dev/md0"):