976134
From 3f6f906c7c7b28dc30edb98200b6e13e1a513bb4 Mon Sep 17 00:00:00 2001
976134
From: Ondrej Holy <oholy@redhat.com>
976134
Date: Wed, 9 May 2018 12:54:59 +0200
976134
Subject: [PATCH] smb: Use O_RDWR to fix fstat when writing
976134
976134
fstat fails with EINVAL on Windows servers if O_WRONLY is used to open
976134
(though it works properly on SAMBA servers). O_RDWR is needed to make
976134
it work. This causes issues when copying files over gvfsd-fuse among
976134
others.
976134
976134
https://bugzilla.gnome.org/show_bug.cgi?id=795805
976134
---
976134
 daemon/gvfsbackendsmb.c | 10 +++++-----
976134
 1 file changed, 5 insertions(+), 5 deletions(-)
976134
976134
diff --git a/daemon/gvfsbackendsmb.c b/daemon/gvfsbackendsmb.c
976134
index d4944197..9571fa0d 100644
976134
--- a/daemon/gvfsbackendsmb.c
976134
+++ b/daemon/gvfsbackendsmb.c
976134
@@ -808,7 +808,7 @@ do_create (GVfsBackend *backend,
976134
   smbc_open = smbc_getFunctionOpen (op_backend->smb_context);
976134
   errno = 0;
976134
   file = smbc_open (op_backend->smb_context, uri,
976134
-		    O_CREAT|O_WRONLY|O_EXCL, 0666);
976134
+                    O_CREAT|O_RDWR|O_EXCL, 0666);
976134
   g_free (uri);
976134
 
976134
   if (file == NULL)
976134
@@ -850,7 +850,7 @@ do_append_to (GVfsBackend *backend,
976134
   smbc_open = smbc_getFunctionOpen (op_backend->smb_context);
976134
   errno = 0;
976134
   file = smbc_open (op_backend->smb_context, uri,
976134
-					O_CREAT|O_WRONLY|O_APPEND, 0666);
976134
+                    O_CREAT|O_RDWR|O_APPEND, 0666);
976134
   g_free (uri);
976134
 
976134
   if (file == NULL)
976134
@@ -916,7 +916,7 @@ open_tmpfile (GVfsBackendSmb *backend,
976134
     smbc_open = smbc_getFunctionOpen (backend->smb_context);
976134
     errno = 0;
976134
     file = smbc_open (backend->smb_context, tmp_uri,
976134
-		      O_CREAT|O_WRONLY|O_EXCL, 0666);
976134
+                      O_CREAT|O_RDWR|O_EXCL, 0666);
976134
   } while (file == NULL && errno == EEXIST);
976134
 
976134
   g_free (dir_uri);
976134
@@ -1040,7 +1040,7 @@ do_replace (GVfsBackend *backend,
976134
   
976134
   errno = 0;
976134
   file = smbc_open (op_backend->smb_context, uri,
976134
-		    O_CREAT|O_WRONLY|O_EXCL, 0);
976134
+                    O_CREAT|O_RDWR|O_EXCL, 0);
976134
   if (file == NULL && errno != EEXIST)
976134
     {
976134
       int errsv = fixup_open_errno (errno);
976134
@@ -1110,7 +1110,7 @@ do_replace (GVfsBackend *backend,
976134
 	  
976134
 	  errno = 0;
976134
 	  file = smbc_open (op_backend->smb_context, uri,
976134
-			    O_CREAT|O_WRONLY|O_TRUNC, 0);
976134
+                            O_CREAT|O_RDWR|O_TRUNC, 0);
976134
 	  if (file == NULL)
976134
 	    {
976134
               int errsv = fixup_open_errno (errno);
976134
-- 
976134
2.35.3
976134