Fix bug with stat mode open being done on read-only open with
authorJeremy Allison <jra@samba.org>
Fri, 30 Aug 2002 19:29:59 +0000 (19:29 +0000)
committerJeremy Allison <jra@samba.org>
Fri, 30 Aug 2002 19:29:59 +0000 (19:29 +0000)
truncate.
Jeremy.
(This used to be commit 18b9cbd857177a911ef95c9322bdf0709161cd84)

source3/smbd/open.c

index 47e859d04b3b91c3e0a89acd65a172aa20d1e14e..8cc73a681d1a0b6d68f189b638efea2adf794439 100644 (file)
@@ -139,18 +139,20 @@ static BOOL open_file(files_struct *fsp,connection_struct *conn,
         * as we always opened files read-write in that release. JRA.
         */
 
-       if ((accmode == O_RDONLY) && ((flags & O_TRUNC) == O_TRUNC))
+       if ((accmode == O_RDONLY) && ((flags & O_TRUNC) == O_TRUNC)) {
+               DEBUG(10,("open_file: truncate requested on read-only open for file %s\n",fname ));
                local_flags = (flags & ~O_ACCMODE)|O_RDWR;
+       }
 
-       /*
-        * We can't actually truncate here as the file may be locked.
-        * open_file_shared will take care of the truncate later. JRA.
-        */
+       if ((desired_access & (FILE_READ_DATA|FILE_WRITE_DATA|FILE_APPEND_DATA|FILE_EXECUTE)) ||
+                       (local_flags & O_CREAT) || ((local_flags & O_TRUNC) == O_TRUNC) ) {
 
-       local_flags &= ~O_TRUNC;
+               /*
+                * We can't actually truncate here as the file may be locked.
+                * open_file_shared will take care of the truncate later. JRA.
+                */
 
-       if ((desired_access & (FILE_READ_DATA|FILE_WRITE_DATA|FILE_APPEND_DATA|FILE_EXECUTE)) ||
-                       (local_flags & O_CREAT)) {
+               local_flags &= ~O_TRUNC;
 
                /* actually do the open */
                fsp->fd = fd_open(conn, fname, local_flags, mode);