Correctly return access denied on share mode deny when we can't open the
authorJeremy Allison <jra@samba.org>
Wed, 12 Feb 2003 01:13:35 +0000 (01:13 +0000)
committerJeremy Allison <jra@samba.org>
Wed, 12 Feb 2003 01:13:35 +0000 (01:13 +0000)
file. This is a regression that was damaged by other code.
Jeremy.
(This used to be commit 7844a53df72af8fd2f70d51b784352aeb1298ed2)

source3/smbd/open.c

index 657074581660f641844848bf4f0333fab88fe27e..6b3dcbe71b4b287523f288b6e5c1f0e317ef4fb1 100644 (file)
@@ -79,6 +79,7 @@ static void check_for_pipe(char *fname)
                DEBUG(3,("Rejecting named pipe open for %s\n",fname));
                unix_ERR_class = ERRSRV;
                unix_ERR_code = ERRaccess;
+               unix_ERR_ntstatus = NT_STATUS_ACCESS_DENIED;
        }
 }
 
@@ -255,6 +256,7 @@ static int truncate_unless_locked(struct connection_struct *conn, files_struct *
                errno = EACCES;
                unix_ERR_class = ERRDOS;
                unix_ERR_code = ERRlock;
+               unix_ERR_ntstatus = dos_to_ntstatus(ERRDOS, ERRlock);
                return -1;
        } else {
                return conn->vfs_ops.ftruncate(fsp,fsp->fd,0); 
@@ -399,9 +401,10 @@ static BOOL check_share_mode(connection_struct *conn, share_mode_entry *share, i
        if (GET_DELETE_ON_CLOSE_FLAG(share->share_mode)) {
                DEBUG(5,("check_share_mode: Failing open on file %s as delete on close flag is set.\n",
                        fname ));
-               unix_ERR_class = ERRDOS;
-               unix_ERR_code = ERRnoaccess;
-               unix_ERR_ntstatus = NT_STATUS_DELETE_PENDING;
+               /* Use errno to map to correct error. */
+               unix_ERR_class = SMB_SUCCESS;
+               unix_ERR_code = 0;
+               unix_ERR_ntstatus = NT_STATUS_OK;
                return False;
        }
 
@@ -444,6 +447,7 @@ static BOOL check_share_mode(connection_struct *conn, share_mode_entry *share, i
                                fname ));
                        unix_ERR_class = ERRDOS;
                        unix_ERR_code = ERRbadshare;
+                       unix_ERR_ntstatus = NT_STATUS_SHARING_VIOLATION;
 
                        return False;
                }
@@ -464,6 +468,7 @@ and existing desired access (0x%x) are non-data opens\n",
                        fname ));
                unix_ERR_class = ERRDOS;
                unix_ERR_code = ERRbadshare;
+               unix_ERR_ntstatus = NT_STATUS_SHARING_VIOLATION;
 
                return False;
        }
@@ -479,6 +484,7 @@ and existing desired access (0x%x) are non-data opens\n",
                        fname ));
                unix_ERR_class = ERRDOS;
                unix_ERR_code = ERRbadshare;
+               unix_ERR_ntstatus = NT_STATUS_SHARING_VIOLATION;
 
                return False;
        }
@@ -510,6 +516,7 @@ existing desired access (0x%x).\n", fname, (unsigned int)desired_access, (unsign
 
                        unix_ERR_class = ERRDOS;
                        unix_ERR_code = ERRbadshare;
+                       unix_ERR_ntstatus = NT_STATUS_SHARING_VIOLATION;
 
                        return False;
                }
@@ -596,6 +603,7 @@ dev = %x, inode = %.0f\n", old_shares[i].op_type, fname, (unsigned int)dev, (dou
                                        errno = EACCES;
                                        unix_ERR_class = ERRDOS;
                                        unix_ERR_code = ERRbadshare;
+                                       unix_ERR_ntstatus = NT_STATUS_SHARING_VIOLATION;
                                        return -1;
                                }
                                
@@ -646,6 +654,7 @@ dev = %x, inode = %.0f. Deleting it to continue...\n", (int)broken_entry.pid, fn
                                                errno = EACCES;
                                                unix_ERR_class = ERRDOS;
                                                unix_ERR_code = ERRbadshare;
+                                               unix_ERR_ntstatus = NT_STATUS_SHARING_VIOLATION;
                                                return -1;
                                        }
                                        
@@ -922,6 +931,7 @@ files_struct *open_file_shared1(connection_struct *conn,char *fname, SMB_STRUCT_
                         * we can do. We also ensure we're not going to create or tuncate
                         * the file as we only want an access decision at this stage. JRA.
                         */
+                       errno = 0;
                        fsp_open = open_file(fsp,conn,fname,psbuf,
                                                flags|(flags2&~(O_TRUNC|O_CREAT)),mode,desired_access);
 
@@ -929,6 +939,12 @@ files_struct *open_file_shared1(connection_struct *conn,char *fname, SMB_STRUCT_
 flags=0x%X flags2=0x%X mode=0%o returned %d\n",
                                flags,(flags2&~(O_TRUNC|O_CREAT)),(int)mode,(int)fsp_open ));
 
+                       if (!fsp_open && errno) {
+                               unix_ERR_class = ERRDOS;
+                               unix_ERR_code = ERRnoaccess;
+                               unix_ERR_ntstatus = NT_STATUS_ACCESS_DENIED;
+                       }
+
                        unlock_share_entry(conn, dev, inode);
                        if (fsp_open)
                                fd_close(conn, fsp);