Blame SOURCES/libvirt-storage_file-create-Create-new-images-with-write-permission-bit.patch

fbe740
From 1624090a014019ac1b61dc62557b829426068835 Mon Sep 17 00:00:00 2001
fbe740
Message-Id: <1624090a014019ac1b61dc62557b829426068835@dist-git>
fbe740
From: Peter Krempa <pkrempa@redhat.com>
fbe740
Date: Tue, 12 May 2020 17:24:08 +0200
fbe740
Subject: [PATCH] storage_file: create: Create new images with write permission
fbe740
 bit
fbe740
MIME-Version: 1.0
fbe740
Content-Type: text/plain; charset=UTF-8
fbe740
Content-Transfer-Encoding: 8bit
fbe740
fbe740
The 'Create' API of the two storage file backends is used only on
fbe740
code-paths where we need to format the image after creating an empty
fbe740
file. Since the DAC security driver only modifies the owner of the file
fbe740
and not the mode we need to create all files which are going to be
fbe740
formatted with the write bit set for the user.
fbe740
fbe740
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
fbe740
Reviewed-by: Ján Tomko <jtomko@redhat.com>
fbe740
(cherry picked from commit 20939b037c37789ddca54c18862fb45b4b41740f)
fbe740
fbe740
https://bugzilla.redhat.com/show_bug.cgi?id=1832204
fbe740
Message-Id: <647821632e4b2822eceb81590459aafa2f88b6fb.1589296861.git.pkrempa@redhat.com>
fbe740
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
fbe740
---
fbe740
 src/storage/storage_file_fs.c      | 6 +-----
fbe740
 src/storage/storage_file_gluster.c | 6 +-----
fbe740
 2 files changed, 2 insertions(+), 10 deletions(-)
fbe740
fbe740
diff --git a/src/storage/storage_file_fs.c b/src/storage/storage_file_fs.c
fbe740
index 8817970f44..1629c3d877 100644
fbe740
--- a/src/storage/storage_file_fs.c
fbe740
+++ b/src/storage/storage_file_fs.c
fbe740
@@ -83,13 +83,9 @@ virStorageFileBackendFileInit(virStorageSourcePtr src)
fbe740
 static int
fbe740
 virStorageFileBackendFileCreate(virStorageSourcePtr src)
fbe740
 {
fbe740
-    mode_t mode = S_IRUSR;
fbe740
     VIR_AUTOCLOSE fd = -1;
fbe740
 
fbe740
-    if (!src->readonly)
fbe740
-        mode |= S_IWUSR;
fbe740
-
fbe740
-    if ((fd = virFileOpenAs(src->path, O_WRONLY | O_TRUNC | O_CREAT, mode,
fbe740
+    if ((fd = virFileOpenAs(src->path, O_WRONLY | O_TRUNC | O_CREAT, S_IRUSR | S_IWUSR,
fbe740
                             src->drv->uid, src->drv->gid, 0)) < 0) {
fbe740
         errno = -fd;
fbe740
         return -1;
fbe740
diff --git a/src/storage/storage_file_gluster.c b/src/storage/storage_file_gluster.c
fbe740
index f389a94437..608f93d2f6 100644
fbe740
--- a/src/storage/storage_file_gluster.c
fbe740
+++ b/src/storage/storage_file_gluster.c
fbe740
@@ -152,13 +152,9 @@ virStorageFileBackendGlusterCreate(virStorageSourcePtr src)
fbe740
 {
fbe740
     virStorageFileBackendGlusterPrivPtr priv = src->drv->priv;
fbe740
     glfs_fd_t *fd = NULL;
fbe740
-    mode_t mode = S_IRUSR;
fbe740
-
fbe740
-    if (!src->readonly)
fbe740
-        mode |= S_IWUSR;
fbe740
 
fbe740
     if (!(fd = glfs_creat(priv->vol, src->path,
fbe740
-                          O_CREAT | O_TRUNC | O_WRONLY, mode)))
fbe740
+                          O_CREAT | O_TRUNC | O_WRONLY, S_IRUSR | S_IWUSR)))
fbe740
         return -1;
fbe740
 
fbe740
     ignore_value(glfs_close(fd));
fbe740
-- 
fbe740
2.26.2
fbe740