render / rpms / libvirt

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