Zebediah Figura : ntdll: Check for an existing file on the server side.

Alexandre Julliard julliard at winehq.org
Thu Mar 12 17:09:06 CDT 2020


Module: wine
Branch: master
Commit: ee136f98322179006e434197f17016af2fbff140
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=ee136f98322179006e434197f17016af2fbff140

Author: Zebediah Figura <z.figura12 at gmail.com>
Date:   Tue Mar 10 22:38:23 2020 -0500

ntdll: Check for an existing file on the server side.

Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/ntdll/file.c              | 16 ++--------------
 include/wine/server_protocol.h |  4 +++-
 server/fd.c                    | 10 ++++++++--
 server/protocol.def            |  1 +
 server/request.h               |  3 ++-
 server/trace.c                 |  1 +
 6 files changed, 17 insertions(+), 18 deletions(-)

diff --git a/dlls/ntdll/file.c b/dlls/ntdll/file.c
index 96f8cb38fc..5175e9d5ce 100644
--- a/dlls/ntdll/file.c
+++ b/dlls/ntdll/file.c
@@ -2778,18 +2778,12 @@ NTSTATUS WINAPI NtSetInformationFile(HANDLE handle, PIO_STATUS_BLOCK io,
             if (io->u.Status != STATUS_SUCCESS && io->u.Status != STATUS_NO_SUCH_FILE)
                 break;
 
-            if (!info->ReplaceIfExists && io->u.Status == STATUS_SUCCESS)
-            {
-                RtlFreeAnsiString( &unix_name );
-                io->u.Status = STATUS_OBJECT_NAME_COLLISION;
-                break;
-            }
-
             SERVER_START_REQ( set_fd_name_info )
             {
                 req->handle   = wine_server_obj_handle( handle );
                 req->rootdir  = wine_server_obj_handle( attr.RootDirectory );
                 req->link     = FALSE;
+                req->replace  = info->ReplaceIfExists;
                 wine_server_add_data( req, unix_name.Buffer, unix_name.Length );
                 io->u.Status = wine_server_call( req );
             }
@@ -2821,18 +2815,12 @@ NTSTATUS WINAPI NtSetInformationFile(HANDLE handle, PIO_STATUS_BLOCK io,
             if (io->u.Status != STATUS_SUCCESS && io->u.Status != STATUS_NO_SUCH_FILE)
                 break;
 
-            if (!info->ReplaceIfExists && io->u.Status == STATUS_SUCCESS)
-            {
-                RtlFreeAnsiString( &unix_name );
-                io->u.Status = STATUS_OBJECT_NAME_COLLISION;
-                break;
-            }
-
             SERVER_START_REQ( set_fd_name_info )
             {
                 req->handle   = wine_server_obj_handle( handle );
                 req->rootdir  = wine_server_obj_handle( attr.RootDirectory );
                 req->link     = TRUE;
+                req->replace  = info->ReplaceIfExists;
                 wine_server_add_data( req, unix_name.Buffer, unix_name.Length );
                 io->u.Status  = wine_server_call( req );
             }
diff --git a/include/wine/server_protocol.h b/include/wine/server_protocol.h
index 3b457df8b0..af4507b5d1 100644
--- a/include/wine/server_protocol.h
+++ b/include/wine/server_protocol.h
@@ -5532,7 +5532,9 @@ struct set_fd_name_info_request
     obj_handle_t handle;
     obj_handle_t rootdir;
     int          link;
+    int          replace;
     /* VARARG(filename,string); */
+    char __pad_28[4];
 };
 struct set_fd_name_info_reply
 {
@@ -6704,6 +6706,6 @@ union generic_reply
     struct resume_process_reply resume_process_reply;
 };
 
-#define SERVER_PROTOCOL_VERSION 595
+#define SERVER_PROTOCOL_VERSION 596
 
 #endif /* __WINE_WINE_SERVER_PROTOCOL_H */
diff --git a/server/fd.c b/server/fd.c
index 5d80e218b9..c2cb3c96ac 100644
--- a/server/fd.c
+++ b/server/fd.c
@@ -2325,7 +2325,7 @@ static void set_fd_disposition( struct fd *fd, int unlink )
 
 /* set new name for the fd */
 static void set_fd_name( struct fd *fd, struct fd *root, const char *nameptr,
-                         data_size_t len, int create_link )
+                         data_size_t len, int create_link, int replace )
 {
     struct inode *inode;
     struct stat st;
@@ -2367,6 +2367,12 @@ static void set_fd_name( struct fd *fd, struct fd *root, const char *nameptr,
 
     if (!stat( name, &st ))
     {
+        if (!replace)
+        {
+            set_error( STATUS_OBJECT_NAME_COLLISION );
+            goto failed;
+        }
+
         /* can't replace directories or special files */
         if (!S_ISREG( st.st_mode ))
         {
@@ -2695,7 +2701,7 @@ DECL_HANDLER(set_fd_name_info)
 
     if ((fd = get_handle_fd_obj( current->process, req->handle, 0 )))
     {
-        set_fd_name( fd, root_fd, get_req_data(), get_req_data_size(), req->link );
+        set_fd_name( fd, root_fd, get_req_data(), get_req_data_size(), req->link, req->replace );
         release_object( fd );
     }
     if (root_fd) release_object( root_fd );
diff --git a/server/protocol.def b/server/protocol.def
index 6c44b2b43f..722993e59c 100644
--- a/server/protocol.def
+++ b/server/protocol.def
@@ -3809,6 +3809,7 @@ struct handle_info
     obj_handle_t handle;          /* handle to a file or directory */
     obj_handle_t rootdir;         /* root directory */
     int          link;            /* link instead of renaming */
+    int          replace;         /* replace an existing file? */
     VARARG(filename,string);      /* new file name */
 @END
 
diff --git a/server/request.h b/server/request.h
index 15fcb671bb..a5472dd1c2 100644
--- a/server/request.h
+++ b/server/request.h
@@ -2377,7 +2377,8 @@ C_ASSERT( sizeof(struct set_fd_disp_info_request) == 24 );
 C_ASSERT( FIELD_OFFSET(struct set_fd_name_info_request, handle) == 12 );
 C_ASSERT( FIELD_OFFSET(struct set_fd_name_info_request, rootdir) == 16 );
 C_ASSERT( FIELD_OFFSET(struct set_fd_name_info_request, link) == 20 );
-C_ASSERT( sizeof(struct set_fd_name_info_request) == 24 );
+C_ASSERT( FIELD_OFFSET(struct set_fd_name_info_request, replace) == 24 );
+C_ASSERT( sizeof(struct set_fd_name_info_request) == 32 );
 C_ASSERT( FIELD_OFFSET(struct get_window_layered_info_request, handle) == 12 );
 C_ASSERT( sizeof(struct get_window_layered_info_request) == 16 );
 C_ASSERT( FIELD_OFFSET(struct get_window_layered_info_reply, color_key) == 8 );
diff --git a/server/trace.c b/server/trace.c
index 79e3f22ee5..95db31b4cb 100644
--- a/server/trace.c
+++ b/server/trace.c
@@ -4464,6 +4464,7 @@ static void dump_set_fd_name_info_request( const struct set_fd_name_info_request
     fprintf( stderr, " handle=%04x", req->handle );
     fprintf( stderr, ", rootdir=%04x", req->rootdir );
     fprintf( stderr, ", link=%d", req->link );
+    fprintf( stderr, ", replace=%d", req->replace );
     dump_varargs_string( ", filename=", cur_size );
 }
 




More information about the wine-cvs mailing list