From 2311ecab4c8aa4026d2ac609f439b90834ff96e2 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 11 Apr 2000 21:38:45 +0000 Subject: The latest open() code changes broke the NT directory opens. Detect if a 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/smbd/open.c | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) (limited to 'source3/smbd/open.c') diff --git a/source3/smbd/open.c b/source3/smbd/open.c index 4c5605fb3b..02832308c6 100644 --- a/source3/smbd/open.c +++ b/source3/smbd/open.c @@ -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; -- cgit