the changes to the main smb code
[tprouty/samba.git] / source / smbd / open.c
index 4c5605fb3be900518a0b228884db9f2bf70fb469..bd8e860a17e5e6a141d1935c1e95e360c2f0c565 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;
@@ -147,6 +165,7 @@ static void open_file(files_struct *fsp,connection_struct *conn,
        fsp->modified = False;
        fsp->oplock_type = NO_OPLOCK;
        fsp->sent_oplock_break = NO_BREAK_SENT;
+       fsp->num_posix_locks = 0;
        fsp->is_directory = False;
        fsp->stat_open = False;
        fsp->directory_delete_on_close = False;
@@ -394,7 +413,7 @@ void open_file_shared(files_struct *fsp,connection_struct *conn,char *fname,int
             ignored */
          *Access = DOS_OPEN_WRONLY;
          *action = FILE_WAS_CREATED;
-         print_open_file(fsp, conn, fname);
+         print_fsp_open(fsp, conn, fname);
          return;
   }
 
@@ -720,6 +739,7 @@ int open_file_stat(files_struct *fsp,connection_struct *conn,
        fsp->modified = False;
        fsp->oplock_type = NO_OPLOCK;
        fsp->sent_oplock_break = NO_BREAK_SENT;
+       fsp->num_posix_locks = 0;
        fsp->is_directory = False;
        fsp->stat_open = True;
        fsp->directory_delete_on_close = False;
@@ -833,6 +853,7 @@ int open_directory(files_struct *fsp,connection_struct *conn,
        fsp->modified = False;
        fsp->oplock_type = NO_OPLOCK;
        fsp->sent_oplock_break = NO_BREAK_SENT;
+       fsp->num_posix_locks = 0;
        fsp->is_directory = True;
        fsp->directory_delete_on_close = False;
        fsp->conn = conn;