Optimization. If the attributes passed to can_rename() include both FILE_ATTRIBUTE_HI...
authorJeremy Allison <jra@samba.org>
Thu, 19 May 2011 23:38:11 +0000 (16:38 -0700)
committerKarolin Seeger <kseeger@samba.org>
Tue, 7 Jun 2011 18:00:38 +0000 (20:00 +0200)
(cherry picked from commit e66e505db8e3e6c7938eb09dc55e080f7754ddd1)

source3/smbd/reply.c

index 9c66ddee029b1af1aaa1120b11c86fc426e632f6..099a36e828ff6a465c20597d6cc6037fc2ead7f4 100644 (file)
@@ -2381,15 +2381,18 @@ void reply_ctemp(struct smb_request *req)
 static NTSTATUS can_rename(connection_struct *conn, files_struct *fsp,
                        uint16 dirtype)
 {
-       uint32 fmode;
-
        if (!CAN_WRITE(conn)) {
                return NT_STATUS_MEDIA_WRITE_PROTECTED;
        }
 
-       fmode = dos_mode(conn, fsp->fsp_name);
-       if ((fmode & ~dirtype) & (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM)) {
-               return NT_STATUS_NO_SUCH_FILE;
+       if ((dirtype & (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM)) !=
+                       (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM)) {
+               /* Only bother to read the DOS attribute if we might deny the
+                  rename on the grounds of attribute missmatch. */
+               uint32_t fmode = dos_mode(conn, fsp->fsp_name);
+               if ((fmode & ~dirtype) & (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM)) {
+                       return NT_STATUS_NO_SUCH_FILE;
+               }
        }
 
        if (S_ISDIR(fsp->fsp_name->st.st_ex_mode)) {