Move checks inside file_set_sparse() to allow it to be called from anywhere.
authorJeremy Allison <jra@samba.org>
Fri, 17 Dec 2010 00:50:31 +0000 (16:50 -0800)
committerJeremy Allison <jra@samba.org>
Fri, 17 Dec 2010 20:56:38 +0000 (21:56 +0100)
Autobuild-User: Jeremy Allison <jra@samba.org>
Autobuild-Date: Fri Dec 17 21:56:38 CET 2010 on sn-devel-104

source3/smbd/dosmode.c
source3/smbd/nttrans.c

index 86f78075062d4bf9926ca0e5d12b33233a7e2ac7..628f8871873c55ca9092b4fe911d658ab9fe0a0b 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "includes.h"
 #include "librpc/gen_ndr/ndr_xattr.h"
+#include "../libcli/security/security.h"
 
 static uint32_t filter_mode_by_protocol(uint32_t mode)
 {
@@ -855,6 +856,25 @@ NTSTATUS file_set_sparse(connection_struct *conn,
        uint32_t new_dosmode;
        NTSTATUS status;
 
+       if (!CAN_WRITE(conn)) {
+               DEBUG(9,("file_set_sparse: fname[%s] set[%u] "
+                       "on readonly share[%s]\n",
+                       smb_fname_str_dbg(fsp->fsp_name),
+                       sparse,
+                       lp_servicename(SNUM(conn))));
+               return NT_STATUS_MEDIA_WRITE_PROTECTED;
+       }
+
+       if (!(fsp->access_mask & FILE_WRITE_DATA) &&
+                       !(fsp->access_mask & FILE_WRITE_ATTRIBUTES)) {
+               DEBUG(9,("file_set_sparse: fname[%s] set[%u] "
+                       "access_mask[0x%08X] - access denied\n",
+                       smb_fname_str_dbg(fsp->fsp_name),
+                       sparse,
+                       fsp->access_mask));
+               return NT_STATUS_ACCESS_DENIED;
+       }
+
        DEBUG(10,("file_set_sparse: setting sparse bit %u on file %s\n",
                  sparse, smb_fname_str_dbg(fsp->fsp_name)));
 
@@ -888,7 +908,7 @@ NTSTATUS file_set_sparse(connection_struct *conn,
 
        notify_fname(conn, NOTIFY_ACTION_MODIFIED,
                     FILE_NOTIFY_CHANGE_ATTRIBUTES,
-                    smb_fname->base_name);
+                    fsp->fsp_name->base_name);
 
        return NT_STATUS_OK;
 }
index 55804b90355e5ee139791fba2acee5708951dc70..cccb47a97fcdf43318b6aa0c8975453572135b3e 100644 (file)
@@ -2122,24 +2122,6 @@ static void call_nt_transact_ioctl(connection_struct *conn,
                        return;
                }
 
-               if (!CAN_WRITE(conn)) {
-                       DEBUG(9,("FSCTL_SET_SPARSE: fname[%s] set[%u] "
-                                "on readonly share[%s]\n",
-                                smb_fname_str_dbg(fsp->fsp_name), set_sparse,
-                                lp_servicename(SNUM(conn))));
-                       reply_nterror(req, NT_STATUS_MEDIA_WRITE_PROTECTED);
-                       return;
-               }
-
-               if (!(fsp->access_mask & FILE_WRITE_DATA) &&
-                   !(fsp->access_mask & FILE_WRITE_ATTRIBUTES)) {
-                       DEBUG(9,("FSCTL_SET_SPARSE: fname[%s] set[%u] "
-                                "access_mask[0x%08X] - access denied\n",
-                                smb_fname_str_dbg(fsp->fsp_name), set_sparse, fsp->access_mask));
-                       reply_nterror(req, NT_STATUS_ACCESS_DENIED);
-                       return;
-               }
-
                status = file_set_sparse(conn, fsp, set_sparse);
                if (!NT_STATUS_IS_OK(status)) {
                        DEBUG(9,("FSCTL_SET_SPARSE: fname[%s] set[%u] - %s\n",