[PATCH v2 3/4] server: Fix up executable permissions when renaming files.

Zebediah Figura z.figura12 at gmail.com
Mon Mar 9 19:27:04 CDT 2020


Same as MoveFileWithProgressW().

Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
---
 server/fd.c   | 10 ++++++++++
 server/file.c |  9 +++++++--
 server/file.h |  1 +
 3 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/server/fd.c b/server/fd.c
index 9a3f68b10c9..7fe13e0f854 100644
--- a/server/fd.c
+++ b/server/fd.c
@@ -2426,6 +2426,16 @@ static void set_fd_name( struct fd *fd, struct fd *root, const char *nameptr,
         goto failed;
     }
 
+    if (is_file_executable( fd->unix_name ) != is_file_executable( name ) && !fstat( fd->unix_fd, &st ))
+    {
+        if (is_file_executable( fd->unix_name ))
+            /* set executable bit where read bit is set */
+            st.st_mode |= (st.st_mode & 0444) >> 2;
+        else
+            st.st_mode &= ~0111;
+        fchmod( fd->unix_fd, st.st_mode );
+    }
+
     free( fd->unix_name );
     fd->unix_name = name;
     fd->closed->unix_name = name;
diff --git a/server/file.c b/server/file.c
index 71b84486b0f..bce202138e0 100644
--- a/server/file.c
+++ b/server/file.c
@@ -191,6 +191,12 @@ static struct object *create_file_obj( struct fd *fd, unsigned int access, mode_
     return &file->obj;
 }
 
+int is_file_executable( const char *name )
+{
+    int len = strlen( name );
+    return len >= 4 && (!strcasecmp( name + len - 4, ".exe") || !strcasecmp( name + len - 4, ".com" ));
+}
+
 static struct object *create_file( struct fd *root, const char *nameptr, data_size_t len,
                                    unsigned int access, unsigned int sharing, int create,
                                    unsigned int options, unsigned int attrs,
@@ -236,8 +242,7 @@ static struct object *create_file( struct fd *root, const char *nameptr, data_si
     else
         mode = (attrs & FILE_ATTRIBUTE_READONLY) ? 0444 : 0666;
 
-    if (len >= 4 &&
-        (!strcasecmp( name + len - 4, ".exe" ) || !strcasecmp( name + len - 4, ".com" )))
+    if (is_file_executable( name ))
     {
         if (mode & S_IRUSR)
             mode |= S_IXUSR;
diff --git a/server/file.h b/server/file.h
index 4341ad3b040..0df4c177162 100644
--- a/server/file.h
+++ b/server/file.h
@@ -149,6 +149,7 @@ extern void file_set_error(void);
 extern struct object_type *file_get_type( struct object *obj );
 extern struct security_descriptor *mode_to_sd( mode_t mode, const SID *user, const SID *group );
 extern mode_t sd_to_mode( const struct security_descriptor *sd, const SID *owner );
+extern int is_file_executable( const char *name );
 
 /* file mapping functions */
 
-- 
2.25.1




More information about the wine-devel mailing list