The latest open() code changes broke the NT directory opens. Detect if a
authorJeremy Allison <jra@samba.org>
Tue, 11 Apr 2000 21:38:45 +0000 (21:38 +0000)
committerJeremy Allison <jra@samba.org>
Tue, 11 Apr 2000 21:38:45 +0000 (21:38 +0000)
read-only open on a directory was done and return an EISDIR from open_file().
Changed interface to fd_close to return error.
Jeremy.
(This used to be commit df4302f3911447fcebe9342f6cbf3b89bd3bafba)

source3/include/proto.h
source3/smbd/close.c
source3/smbd/open.c

index f6d387d19e3d00e1539d9cfe09d40fa29476b859..b7cfb83501a5b62066b8a5a7063f468f603af9cd 100644 (file)
@@ -3055,7 +3055,7 @@ int reply_nttrans(connection_struct *conn,
 
 /*The following definitions come from  smbd/open.c  */
 
-void fd_close(files_struct *fsp, int *err_ret);
+int fd_close(struct connection_struct *conn, files_struct *fsp);
 void open_file_shared(files_struct *fsp,connection_struct *conn,char *fname,int share_mode,int ofun,
                      mode_t mode,int oplock_request, int *Access,int *action);
 int open_file_stat(files_struct *fsp,connection_struct *conn,
index 61e82641591d09ea77d56e4f7ad1e5eabbbd6d4c..4358f8fc2ffe01d5a88ea7319554f9e2d3b1378e 100644 (file)
@@ -113,7 +113,7 @@ static int close_normal_file(files_struct *fsp, BOOL normal_close)
        if (lp_share_modes(SNUM(conn)))
                unlock_share_entry_fsp(fsp);
 
-       fd_close(fsp, &err);
+       err = fd_close(conn, fsp);
 
        /* NT uses smbclose to start a print - weird */
        if (normal_close && fsp->print_file)
index 4c5605fb3be900518a0b228884db9f2bf70fb469..02832308c64d3502c9e24a38794d9f61bc5a91ba 100644 (file)
@@ -28,8 +28,9 @@ extern uint16 global_oplock_port;
 extern BOOL global_client_failed_oplock_break;
 
 /****************************************************************************
-fd support routines - attempt to do a dos_open
+ fd support routines - attempt to do a dos_open.
 ****************************************************************************/
+
 static int fd_open(struct connection_struct *conn, char *fname, 
                   int flags, mode_t mode)
 {
@@ -42,21 +43,26 @@ static int fd_open(struct connection_struct *conn, char *fname,
                fd = conn->vfs_ops.open(dos_to_unix(fname,False),flags,mode);
        }
 
+       DEBUG(10,("fd_open: name %s, mode = %d, fd = %d. %s\n", fname, (int)mode, fd,
+               (fd == -1) ? strerror(errno) : "" ));
+
        return fd;
 }
 
 /****************************************************************************
-close the file associated with a fsp
+ Close the file associated with a fsp.
 ****************************************************************************/
-void fd_close(files_struct *fsp, int *err_ret)
+
+int fd_close(struct connection_struct *conn, files_struct *fsp)
 {
-       fsp->conn->vfs_ops.close(fsp->fd);
+       int ret = conn->vfs_ops.close(fsp->fd);
        fsp->fd = -1;
+       return ret;
 }
 
 
 /****************************************************************************
-check a filename for the pipe string
+ Check a filename for the pipe string.
 ****************************************************************************/
 
 static void check_for_pipe(char *fname)
@@ -73,7 +79,7 @@ static void check_for_pipe(char *fname)
 }
 
 /****************************************************************************
-open a file
+ Open a file.
 ****************************************************************************/
 
 static void open_file(files_struct *fsp,connection_struct *conn,
@@ -91,7 +97,7 @@ static void open_file(files_struct *fsp,connection_struct *conn,
 
        pstrcpy(fname,fname1);
 
-       /* check permissions */
+       /* Check permissions */
 
        /*
         * This code was changed after seeing a client open request 
@@ -121,7 +127,7 @@ static void open_file(files_struct *fsp,connection_struct *conn,
        /* actually do the open */
        fsp->fd = fd_open(conn, fname, flags, mode);
 
-       if (fsp->fd == -1)  {
+       if (fsp->fd == -1)  {
                DEBUG(3,("Error opening file %s (%s) (flags=%d)\n",
                         fname,strerror(errno),flags));
                check_for_pipe(fname);
@@ -130,6 +136,18 @@ static void open_file(files_struct *fsp,connection_struct *conn,
 
        conn->vfs_ops.fstat(fsp->fd, &sbuf);
 
+       /*
+        * POSIX allows read-only opens of directories. We don't
+        * want to do this (we use a different code path for this)
+        * so catch a directory open and return an EISDIR. JRA.
+        */
+
+       if(S_ISDIR(sbuf.st_mode)) {
+               fd_close(conn, fsp);
+               errno = EISDIR;
+               return;
+       }
+
        conn->num_files_open++;
        fsp->mode = sbuf.st_mode;
        fsp->inode = sbuf.st_ino;