r20228: Bring the calling conventions of inherit_access_acl and change_owner_to_parent
[samba.git] / source3 / smbd / open.c
index 4033243888edad1054aaea3c9b8c4cc32d3ce250..d916609769430a12e6e8274aa18d9f0a3ca4bdcd 100644 (file)
@@ -39,10 +39,10 @@ struct deferred_open_record {
 ****************************************************************************/
 
 static BOOL fd_open(struct connection_struct *conn,
-                       const char *fname, 
-                       files_struct *fsp,
-                       int flags,
-                       mode_t mode)
+                   const char *fname, 
+                   files_struct *fsp,
+                   int flags,
+                   mode_t mode)
 {
        int sav;
 
@@ -68,7 +68,7 @@ static BOOL fd_open(struct connection_struct *conn,
 ****************************************************************************/
 
 int fd_close(struct connection_struct *conn,
-               files_struct *fsp)
+            files_struct *fsp)
 {
        if (fsp->fh->fd == -1) {
                return 0; /* What we used to call a stat open. */
@@ -85,9 +85,9 @@ int fd_close(struct connection_struct *conn,
 ****************************************************************************/
 
 void change_owner_to_parent(connection_struct *conn,
-                               files_struct *fsp,
-                               const char *fname,
-                               SMB_STRUCT_STAT *psbuf)
+                           files_struct *fsp,
+                           const char *fname,
+                           SMB_STRUCT_STAT *psbuf)
 {
        const char *parent_path = parent_dirname(fname);
        SMB_STRUCT_STAT parent_st;
@@ -185,12 +185,13 @@ void change_owner_to_parent(connection_struct *conn,
 ****************************************************************************/
 
 static NTSTATUS open_file(files_struct *fsp,
-                       connection_struct *conn,
-                       const char *fname,
-                       SMB_STRUCT_STAT *psbuf,
-                       int flags,
-                       mode_t unx_mode,
-                       uint32 access_mask)
+                         connection_struct *conn,
+                         const char *fname,
+                         SMB_STRUCT_STAT *psbuf,
+                         int flags,
+                         mode_t unx_mode,
+                         uint32 access_mask, /* client requested access mask. */
+                         uint32 open_access_mask) /* what we're actually using in the open. */
 {
        int accmode = (flags & O_ACCMODE);
        int local_flags = flags;
@@ -244,7 +245,7 @@ static NTSTATUS open_file(files_struct *fsp,
                local_flags = (flags & ~O_ACCMODE)|O_RDWR;
        }
 
-       if ((access_mask & (FILE_READ_DATA|FILE_WRITE_DATA|FILE_APPEND_DATA|FILE_EXECUTE)) ||
+       if ((open_access_mask & (FILE_READ_DATA|FILE_WRITE_DATA|FILE_APPEND_DATA|FILE_EXECUTE)) ||
            (!file_existed && (local_flags & O_CREAT)) ||
            ((local_flags & O_TRUNC) == O_TRUNC) ) {
 
@@ -282,7 +283,9 @@ static NTSTATUS open_file(files_struct *fsp,
                }
 
                /* Inherit the ACL if the file was created. */
-               if ((local_flags & O_CREAT) && !file_existed) {
+               if ((local_flags & O_CREAT)
+                   && !file_existed
+                   && lp_inherit_perms(SNUM(conn))) {
                        inherit_access_acl(conn, fname, unx_mode);
                }
 
@@ -334,7 +337,8 @@ static NTSTATUS open_file(files_struct *fsp,
        if (!CAN_WRITE(conn)) {
                fsp->can_write = False;
        } else {
-               fsp->can_write = (access_mask & (FILE_WRITE_DATA | FILE_APPEND_DATA)) ? True : False;
+               fsp->can_write = (access_mask & (FILE_WRITE_DATA | FILE_APPEND_DATA)) ?
+                       True : False;
        }
        fsp->print_file = False;
        fsp->modified = False;
@@ -350,7 +354,8 @@ static NTSTATUS open_file(files_struct *fsp,
        fsp->wcp = NULL; /* Write cache pointer. */
 
        DEBUG(2,("%s opened file %s read=%s write=%s (numopen=%d)\n",
-                *current_user_info.smb_name ? current_user_info.smb_name : conn->user,fsp->fsp_name,
+                *current_user_info.smb_name ?
+                current_user_info.smb_name : conn->user,fsp->fsp_name,
                 BOOLSTR(fsp->can_read), BOOLSTR(fsp->can_write),
                 conn->num_files_open + 1));
 
@@ -472,8 +477,8 @@ static void validate_my_share_entries(int num,
        if (is_deferred_open_entry(share_entry) &&
            !open_was_deferred(share_entry->op_mid)) {
                pstring str;
-               DEBUG(0, ("Got a deferred entry without a request: "
-                         "PANIC: %s\n", share_mode_str(num, share_entry)));
+               pstr_sprintf(str, "Got a deferred entry without a request: "
+                            "PANIC: %s\n", share_mode_str(num, share_entry));
                smb_panic(str);
        }
 
@@ -613,15 +618,17 @@ static BOOL is_delete_request(files_struct *fsp) {
  */
 
 static BOOL delay_for_oplocks(struct share_mode_lock *lck,
-                               files_struct *fsp,
-                               int pass_number,
-                               int oplock_request)
+                             files_struct *fsp,
+                             int pass_number,
+                             int oplock_request)
 {
        int i;
        struct share_mode_entry *exclusive = NULL;
        BOOL valid_entry = False;
        BOOL delay_it = False;
        BOOL have_level2 = False;
+       BOOL ret;
+       char msg[MSG_SMB_SHARE_MODE_ENTRY_SIZE];
 
        if (oplock_request & INTERNAL_OPEN_ONLY) {
                fsp->oplock_type = NO_OPLOCK;
@@ -685,34 +692,36 @@ static BOOL delay_for_oplocks(struct share_mode_lock *lck,
                fsp->oplock_type = FAKE_LEVEL_II_OPLOCK;
        }
 
-       if (delay_it) {
-               BOOL ret;
-               char msg[MSG_SMB_SHARE_MODE_ENTRY_SIZE];
+       if (!delay_it) {
+               return False;
+       }
 
-               DEBUG(10, ("Sending break request to PID %s\n",
-                          procid_str_static(&exclusive->pid)));
-               exclusive->op_mid = get_current_mid();
+       /*
+        * Send a break message to the oplock holder and delay the open for
+        * our client.
+        */
 
-               /* Create the message. */
-               share_mode_entry_to_message(msg, exclusive);
+       DEBUG(10, ("Sending break request to PID %s\n",
+                  procid_str_static(&exclusive->pid)));
+       exclusive->op_mid = get_current_mid();
 
-               /* Add in the FORCE_OPLOCK_BREAK_TO_NONE bit in the message if set. We don't
-                  want this set in the share mode struct pointed to by lck. */
+       /* Create the message. */
+       share_mode_entry_to_message(msg, exclusive);
 
-               if (oplock_request & FORCE_OPLOCK_BREAK_TO_NONE) {
-                       SSVAL(msg,6,exclusive->op_type | FORCE_OPLOCK_BREAK_TO_NONE);
-               }
+       /* Add in the FORCE_OPLOCK_BREAK_TO_NONE bit in the message if set. We
+          don't want this set in the share mode struct pointed to by lck. */
 
-               become_root();
-               ret = message_send_pid(exclusive->pid, MSG_SMB_BREAK_REQUEST,
-                                      msg, MSG_SMB_SHARE_MODE_ENTRY_SIZE, True);
-               unbecome_root();
-               if (!ret) {
-                       DEBUG(3, ("Could not send oplock break message\n"));
-               }
+       if (oplock_request & FORCE_OPLOCK_BREAK_TO_NONE) {
+               SSVAL(msg,6,exclusive->op_type | FORCE_OPLOCK_BREAK_TO_NONE);
+       }
+
+       ret = message_send_pid(exclusive->pid, MSG_SMB_BREAK_REQUEST,
+                              msg, MSG_SMB_SHARE_MODE_ENTRY_SIZE, True);
+       if (!ret) {
+               DEBUG(3, ("Could not send oplock break message\n"));
        }
 
-       return delay_it;
+       return True;
 }
 
 static BOOL request_timed_out(struct timeval request_time,
@@ -776,40 +785,18 @@ static void defer_open(struct share_mode_lock *lck,
        srv_defer_sign_response(mid);
 }
 
-/****************************************************************************
- Set a kernel flock on a file for NFS interoperability.
- This requires a patch to Linux.
-****************************************************************************/
-
-static void kernel_flock(files_struct *fsp, uint32 share_mode)
-{
-#if HAVE_KERNEL_SHARE_MODES
-       int kernel_mode = 0;
-       if (share_mode == FILE_SHARE_WRITE) {
-               kernel_mode = LOCK_MAND|LOCK_WRITE;
-       } else if (share_mode == FILE_SHARE_READ) {
-               kernel_mode = LOCK_MAND|LOCK_READ;
-       } else if (share_mode == FILE_SHARE_NONE) {
-               kernel_mode = LOCK_MAND;
-       }
-       if (kernel_mode) {
-               flock(fsp->fh->fd, kernel_mode);
-       }
-#endif
-       ;
-}
 
 /****************************************************************************
  On overwrite open ensure that the attributes match.
 ****************************************************************************/
 
 static BOOL open_match_attributes(connection_struct *conn,
-                               const char *path,
-                               uint32 old_dos_attr,
-                               uint32 new_dos_attr,
-                               mode_t existing_unx_mode,
-                               mode_t new_unx_mode,
-                               mode_t *returned_unx_mode)
+                                 const char *path,
+                                 uint32 old_dos_attr,
+                                 uint32 new_dos_attr,
+                                 mode_t existing_unx_mode,
+                                 mode_t new_unx_mode,
+                                 mode_t *returned_unx_mode)
 {
        uint32 noarch_old_dos_attr, noarch_new_dos_attr;
 
@@ -914,10 +901,10 @@ static files_struct *fcb_or_dos_open(connection_struct *conn,
 ****************************************************************************/
 
 BOOL map_open_params_to_ntcreate(const char *fname, int deny_mode, int open_func,
-                               uint32 *paccess_mask,
-                               uint32 *pshare_mode,
-                               uint32 *pcreate_disposition,
-                               uint32 *pcreate_options)
+                                uint32 *paccess_mask,
+                                uint32 *pshare_mode,
+                                uint32 *pcreate_disposition,
+                                uint32 *pcreate_options)
 {
        uint32 access_mask;
        uint32 share_mode;
@@ -1089,17 +1076,17 @@ static void schedule_defer_open(struct share_mode_lock *lck, struct timeval requ
 ****************************************************************************/
 
 NTSTATUS open_file_ntcreate(connection_struct *conn,
-                                const char *fname,
-                                SMB_STRUCT_STAT *psbuf,
-                                uint32 access_mask,            /* access bits (FILE_READ_DATA etc.) */
-                                uint32 share_access,           /* share constants (FILE_SHARE_READ etc). */
-                                uint32 create_disposition,     /* FILE_OPEN_IF etc. */
-                                uint32 create_options,         /* options such as delete on close. */
-                                uint32 new_dos_attributes,     /* attributes used for new file. */
-                                int oplock_request,            /* internal Samba oplock codes. */
-                                                               /* Information (FILE_EXISTS etc.) */
-                                int *pinfo,
-                                files_struct **result)
+                           const char *fname,
+                           SMB_STRUCT_STAT *psbuf,
+                           uint32 access_mask,         /* access bits (FILE_READ_DATA etc.) */
+                           uint32 share_access,        /* share constants (FILE_SHARE_READ etc) */
+                           uint32 create_disposition,  /* FILE_OPEN_IF etc. */
+                           uint32 create_options,      /* options such as delete on close. */
+                           uint32 new_dos_attributes,  /* attributes used for new file. */
+                           int oplock_request,         /* internal Samba oplock codes. */
+                                                       /* Information (FILE_EXISTS etc.) */
+                           int *pinfo,
+                           files_struct **result)
 {
        int flags=0;
        int flags2=0;
@@ -1117,7 +1104,9 @@ NTSTATUS open_file_ntcreate(connection_struct *conn,
        uint16 mid = get_current_mid();
        struct timeval request_time = timeval_zero();
        struct share_mode_lock *lck = NULL;
+       uint32 open_access_mask = access_mask;
        NTSTATUS status;
+       int ret_flock;
 
        if (conn->printer) {
                /* 
@@ -1131,7 +1120,7 @@ NTSTATUS open_file_ntcreate(connection_struct *conn,
 
                DEBUG(10, ("open_file_ntcreate: printer open fname=%s\n", fname));
 
-               return print_fsp_open(conn, fname, &fsp);
+               return print_fsp_open(conn, fname, result);
        }
 
        /* We add aARCH to this as this mode is only used if the file is
@@ -1289,7 +1278,7 @@ NTSTATUS open_file_ntcreate(connection_struct *conn,
 
        /* This is a nasty hack - must fix... JRA. */
        if (access_mask == MAXIMUM_ALLOWED_ACCESS) {
-               access_mask = FILE_GENERIC_ALL;
+               open_access_mask = access_mask = FILE_GENERIC_ALL;
        }
 
        /*
@@ -1297,6 +1286,11 @@ NTSTATUS open_file_ntcreate(connection_struct *conn,
         */
 
        se_map_generic(&access_mask, &file_generic_mapping);
+       open_access_mask = access_mask;
+
+       if (flags2 & O_TRUNC) {
+               open_access_mask |= FILE_WRITE_DATA; /* This will cause oplock breaks. */
+       }
 
        DEBUG(10, ("open_file_ntcreate: fname=%s, after mapping "
                   "access_mask=0x%x\n", fname, access_mask ));
@@ -1307,7 +1301,15 @@ NTSTATUS open_file_ntcreate(connection_struct *conn,
         */
 
        if (access_mask & (FILE_WRITE_DATA | FILE_APPEND_DATA)) {
-               flags = O_RDWR;
+               /* DENY_DOS opens are always underlying read-write on the
+                  file handle, no matter what the requested access mask
+                   says. */
+               if ((create_options & NTCREATEX_OPTIONS_PRIVATE_DENY_DOS) ||
+                       access_mask & (FILE_READ_ATTRIBUTES|FILE_READ_DATA|FILE_READ_EA|FILE_EXECUTE)) {
+                       flags = O_RDWR;
+               } else {
+                       flags = O_WRONLY;
+               }
        } else {
                flags = O_RDONLY;
        }
@@ -1353,7 +1355,9 @@ NTSTATUS open_file_ntcreate(connection_struct *conn,
        fsp->inode = psbuf->st_ino;
        fsp->share_access = share_access;
        fsp->fh->private_options = create_options;
-       fsp->access_mask = access_mask;
+       fsp->access_mask = open_access_mask; /* We change this to the
+                                             * requested access_mask after
+                                             * the open is done. */
        /* Ensure no SAMBA_PRIVATE bits can be set. */
        fsp->oplock_type = (oplock_request & ~SAMBA_PRIVATE_OPLOCK_MASK);
 
@@ -1366,8 +1370,8 @@ NTSTATUS open_file_ntcreate(connection_struct *conn,
                inode = psbuf->st_ino;
 
                lck = get_share_mode_lock(NULL, dev, inode,
-                                       conn->connectpath,
-                                       fname);
+                                         conn->connectpath,
+                                         fname);
 
                if (lck == NULL) {
                        file_free(fsp);
@@ -1383,13 +1387,17 @@ NTSTATUS open_file_ntcreate(connection_struct *conn,
                        return NT_STATUS_SHARING_VIOLATION;
                }
 
+               /* Use the client requested access mask here, not the one we
+                * open with. */
                status = open_mode_check(conn, fname, lck,
                                         access_mask, share_access,
                                         create_options, &file_existed);
 
                if (NT_STATUS_IS_OK(status)) {
-                       /* We might be going to allow this open. Check oplock status again. */
-                       /* Second pass - send break for both batch or exclusive oplocks. */
+                       /* We might be going to allow this open. Check oplock
+                        * status again. */
+                       /* Second pass - send break for both batch or
+                        * exclusive oplocks. */
                        if (delay_for_oplocks(lck, fsp, 2, oplock_request)) {
                                schedule_defer_open(lck, request_time);
                                TALLOC_FREE(lck);
@@ -1417,6 +1425,9 @@ NTSTATUS open_file_ntcreate(connection_struct *conn,
                            (NTCREATEX_OPTIONS_PRIVATE_DENY_DOS|
                             NTCREATEX_OPTIONS_PRIVATE_DENY_FCB)) {
                                files_struct *fsp_dup;
+
+                               /* Use the client requested access mask here,
+                                * not the one we open with. */
                                fsp_dup = fcb_or_dos_open(conn, fname, dev,
                                                          inode, access_mask,
                                                          share_access,
@@ -1446,12 +1457,14 @@ NTSTATUS open_file_ntcreate(connection_struct *conn,
 
                        if (flags & O_RDWR) {
                                can_access_mask = FILE_READ_DATA|FILE_WRITE_DATA;
+                       } else if (flags & O_WRONLY) {
+                               can_access_mask = FILE_WRITE_DATA;
                        } else {
                                can_access_mask = FILE_READ_DATA;
                        }
 
-                       if (((flags & O_RDWR) && !CAN_WRITE(conn)) ||
-                                       !can_access_file(conn,fname,psbuf,can_access_mask)) {
+                       if (((can_access_mask & FILE_WRITE_DATA) && !CAN_WRITE(conn)) ||
+                           !can_access_file(conn,fname,psbuf,can_access_mask)) {
                                can_access = False;
                        }
 
@@ -1529,127 +1542,111 @@ NTSTATUS open_file_ntcreate(connection_struct *conn,
                unx_mode = 0777;
        }
 
-       DEBUG(4,("calling open_file with flags=0x%X flags2=0x%X mode=0%o\n",
+       DEBUG(4,("calling open_file with flags=0x%X flags2=0x%X mode=0%o, "
+               "access_mask = 0x%x, open_access_mask = 0x%x\n",
                 (unsigned int)flags, (unsigned int)flags2,
-                (unsigned int)unx_mode));
-
-       /* Drop the lock before doing any real file access. Allows kernel
-          oplock breaks to be processed. Handle any races after the open
-          call when we re-acquire the lock. */
-
-       if (lck) {
-               TALLOC_FREE(lck);
-       }
+                (unsigned int)unx_mode, (unsigned int)access_mask,
+                (unsigned int)open_access_mask));
 
        /*
         * open_file strips any O_TRUNC flags itself.
         */
 
        fsp_open = open_file(fsp,conn,fname,psbuf,flags|flags2,unx_mode,
-                            access_mask);
+                            access_mask, open_access_mask);
 
        if (!NT_STATUS_IS_OK(fsp_open)) {
+               if (lck != NULL) {
+                       TALLOC_FREE(lck);
+               }
                file_free(fsp);
                return fsp_open;
        }
 
-       /*
-        * Deal with the race condition where two smbd's detect the
-        * file doesn't exist and do the create at the same time. One
-        * of them will win and set a share mode, the other (ie. this
-        * one) should check if the requested share mode for this
-        * create is allowed.
-        */
-
-       /*
-        * Now the file exists and fsp is successfully opened,
-        * fsp->dev and fsp->inode are valid and should replace the
-        * dev=0,inode=0 from a non existent file. Spotted by
-        * Nadav Danieli <nadavd@exanet.com>. JRA.
-        */
-
-       dev = fsp->dev;
-       inode = fsp->inode;
-
-       lck = get_share_mode_lock(NULL, dev, inode,
-                               conn->connectpath,
-                               fname);
+       if (!file_existed) {
 
-       if (lck == NULL) {
-               DEBUG(0, ("open_file_ntcreate: Could not get share mode lock for %s\n", fname));
-               fd_close(conn, fsp);
-               file_free(fsp);
-               return NT_STATUS_SHARING_VIOLATION;
-       }
+               /*
+                * Deal with the race condition where two smbd's detect the
+                * file doesn't exist and do the create at the same time. One
+                * of them will win and set a share mode, the other (ie. this
+                * one) should check if the requested share mode for this
+                * create is allowed.
+                */
 
-       /*
-        * The share entry is again *locked*.....
-        */
+               /*
+                * Now the file exists and fsp is successfully opened,
+                * fsp->dev and fsp->inode are valid and should replace the
+                * dev=0,inode=0 from a non existent file. Spotted by
+                * Nadav Danieli <nadavd@exanet.com>. JRA.
+                */
 
-       /* First pass - send break only on batch oplocks. */
-       if (delay_for_oplocks(lck, fsp, 1, oplock_request)) {
-               schedule_defer_open(lck, request_time);
-               fd_close(conn, fsp);
-               file_free(fsp);
-               TALLOC_FREE(lck);
-               return NT_STATUS_SHARING_VIOLATION;
-       }
+               dev = fsp->dev;
+               inode = fsp->inode;
 
-       status = open_mode_check(conn, fname, lck,
-                                access_mask, share_access,
-                                create_options, &file_existed);
+               lck = get_share_mode_lock(NULL, dev, inode,
+                                         conn->connectpath,
+                                         fname);
 
-       if (NT_STATUS_IS_OK(status)) {
-               /* We might be going to allow this open. Check oplock status again. */
-               /* Second pass - send break for both batch or exclusive oplocks. */
-               if (delay_for_oplocks(lck, fsp, 2, oplock_request)) {
-                       schedule_defer_open(lck, request_time);
+               if (lck == NULL) {
+                       DEBUG(0, ("open_file_ntcreate: Could not get share "
+                                 "mode lock for %s\n", fname));
                        fd_close(conn, fsp);
                        file_free(fsp);
-                       TALLOC_FREE(lck);
                        return NT_STATUS_SHARING_VIOLATION;
                }
-       }
 
-       if (NT_STATUS_EQUAL(status, NT_STATUS_DELETE_PENDING)) {
-               /* DELETE_PENDING is not deferred for a second */
-               fd_close(conn, fsp);
-               file_free(fsp);
-               TALLOC_FREE(lck);
-               return status;
-       }
+               status = open_mode_check(conn, fname, lck,
+                                        access_mask, share_access,
+                                        create_options, &file_existed);
 
-       if (!NT_STATUS_IS_OK(status)) {
-               struct deferred_open_record state;
+               if (!NT_STATUS_IS_OK(status)) {
+                       struct deferred_open_record state;
 
-               fd_close(conn, fsp);
-               file_free(fsp);
+                       fd_close(conn, fsp);
+                       file_free(fsp);
 
-               state.delayed_for_oplocks = False;
-               state.dev = dev;
-               state.inode = inode;
+                       state.delayed_for_oplocks = False;
+                       state.dev = dev;
+                       state.inode = inode;
 
-               /* Do it all over again immediately. In the second
-                * round we will find that the file existed and handle
-                * the DELETE_PENDING and FCB cases correctly. No need
-                * to duplicate the code here. Essentially this is a
-                * "goto top of this function", but don't tell
-                * anybody... */
+                       /* Do it all over again immediately. In the second
+                        * round we will find that the file existed and handle
+                        * the DELETE_PENDING and FCB cases correctly. No need
+                        * to duplicate the code here. Essentially this is a
+                        * "goto top of this function", but don't tell
+                        * anybody... */
+
+                       defer_open(lck, request_time, timeval_zero(),
+                                  &state);
+                       TALLOC_FREE(lck);
+                       return status;
+               }
+
+               /*
+                * We exit this block with the share entry *locked*.....
+                */
 
-               defer_open(lck, request_time, timeval_zero(),
-                          &state);
-               TALLOC_FREE(lck);
-               return status;
        }
 
+       SMB_ASSERT(lck != NULL);
+
        /* note that we ignore failure for the following. It is
            basically a hack for NFS, and NFS will never set one of
            these only read them. Nobody but Samba can ever set a deny
            mode and we have already checked our more authoritative
            locking database for permission to set this deny mode. If
-           the kernel refuses the operations then the kernel is wrong */
+           the kernel refuses the operations then the kernel is wrong.
+          note that GPFS supports it as well - jmcd */
+
+       ret_flock = SMB_VFS_KERNEL_FLOCK(fsp, fsp->fh->fd, share_access);
+       if(ret_flock == -1 ){
 
-       kernel_flock(fsp, share_access);
+               talloc_free(lck);
+               fd_close(conn, fsp);
+               file_free(fsp);
+               
+               return NT_STATUS_SHARING_VIOLATION;
+       }
 
        /*
         * At this point onwards, we can guarentee that the share entry
@@ -1683,7 +1680,7 @@ NTSTATUS open_file_ntcreate(connection_struct *conn,
 
        if (file_existed) {
                /* stat opens on existing files don't get oplocks. */
-               if (is_stat_open(fsp->access_mask)) {
+               if (is_stat_open(open_access_mask)) {
                        fsp->oplock_type = NO_OPLOCK;
                }
 
@@ -1720,7 +1717,7 @@ NTSTATUS open_file_ntcreate(connection_struct *conn,
        set_share_mode(lck, fsp, current_user.ut.uid, 0, fsp->oplock_type);
 
        if (info == FILE_WAS_OVERWRITTEN || info == FILE_WAS_CREATED ||
-                               info == FILE_WAS_SUPERSEDED) {
+           info == FILE_WAS_SUPERSEDED) {
 
                /* Handle strange delete on close create semantics. */
                if (create_options & FILE_DELETE_ON_CLOSE) {
@@ -1760,8 +1757,8 @@ NTSTATUS open_file_ntcreate(connection_struct *conn,
                int saved_errno = errno; /* We might get ENOSYS in the next
                                          * call.. */
 
-               if (SMB_VFS_FCHMOD_ACL(fsp, fsp->fh->fd, unx_mode) == -1
-                   && errno == ENOSYS) {
+               if (SMB_VFS_FCHMOD_ACL(fsp, fsp->fh->fd, unx_mode) == -1 &&
+                   errno == ENOSYS) {
                        errno = saved_errno; /* Ignore ENOSYS */
                }
 
@@ -1782,7 +1779,7 @@ NTSTATUS open_file_ntcreate(connection_struct *conn,
                        } else {
                                DEBUG(5, ("open_file_ntcreate: reset "
                                          "attributes of file %s to 0%o\n",
-                                       fname, (unsigned int)new_unx_mode));
+                                         fname, (unsigned int)new_unx_mode));
                                ret = 0; /* Don't do the fchmod below. */
                        }
                }
@@ -1791,7 +1788,7 @@ NTSTATUS open_file_ntcreate(connection_struct *conn,
                    (SMB_VFS_FCHMOD(fsp, fsp->fh->fd, new_unx_mode) == -1))
                        DEBUG(5, ("open_file_ntcreate: failed to reset "
                                  "attributes of file %s to 0%o\n",
-                               fname, (unsigned int)new_unx_mode));
+                                 fname, (unsigned int)new_unx_mode));
        }
 
        /* If this is a successful open, we must remove any deferred open
@@ -1826,7 +1823,7 @@ NTSTATUS open_file_fchmod(connection_struct *conn, const char *fname,
 
        /* note! we must use a non-zero desired access or we don't get
            a real file descriptor. Oh what a twisted web we weave. */
-       status = open_file(fsp,conn,fname,psbuf,O_WRONLY,0,FILE_WRITE_DATA);
+       status = open_file(fsp,conn,fname,psbuf,O_WRONLY,0,FILE_WRITE_DATA,FILE_WRITE_DATA);
 
        /* 
         * This is not a user visible file open.
@@ -1859,14 +1856,14 @@ int close_file_fchmod(files_struct *fsp)
 ****************************************************************************/
 
 NTSTATUS open_directory(connection_struct *conn,
-                               const char *fname,
-                               SMB_STRUCT_STAT *psbuf,
-                               uint32 access_mask,
-                               uint32 share_access,
-                               uint32 create_disposition,
-                               uint32 create_options,
-                               int *pinfo,
-                               files_struct **result)
+                       const char *fname,
+                       SMB_STRUCT_STAT *psbuf,
+                       uint32 access_mask,
+                       uint32 share_access,
+                       uint32 create_disposition,
+                       uint32 create_options,
+                       int *pinfo,
+                       files_struct **result)
 {
        files_struct *fsp = NULL;
        BOOL dir_existed = VALID_STAT(*psbuf) ? True : False;
@@ -2003,8 +2000,8 @@ NTSTATUS open_directory(connection_struct *conn,
        string_set(&fsp->fsp_name,fname);
 
        lck = get_share_mode_lock(NULL, fsp->dev, fsp->inode,
-                               conn->connectpath,
-                               fname);
+                                 conn->connectpath,
+                                 fname);
 
        if (lck == NULL) {
                DEBUG(0, ("open_directory: Could not get share mode lock for %s\n", fname));
@@ -2060,7 +2057,7 @@ NTSTATUS open_directory(connection_struct *conn,
  Open a pseudo-file (no locking checks - a 'stat' open).
 ****************************************************************************/
 
-NTSTATUS open_file_stat(connection_struct *conn, char *fname,
+NTSTATUS open_file_stat(connection_struct *conn, const char *fname,
                        SMB_STRUCT_STAT *psbuf, files_struct **result)
 {
        files_struct *fsp = NULL;