Allow actual call to set file offline
authorAlexander Bokovoy <ab@samba.org>
Wed, 6 Feb 2008 06:09:23 +0000 (09:09 +0300)
committerAlexander Bokovoy <ab@samba.org>
Wed, 6 Feb 2008 06:09:23 +0000 (09:09 +0300)
Dos mode calculation was masking out FILE_ATTRIBUTE_OFFLINE so that code to set file offline
was never called before. Merge from Tridge's v3-0-ctdb git tree.
(This used to be commit 9827d5ff416479408b19a8964c2321ea2517aa74)

source3/smbd/dosmode.c

index eb18f65fca9dc4541925294778c758d9e361ad24..f068f1f65533d57ceca40db9e04bafdcf222a4bf 100644 (file)
@@ -419,9 +419,10 @@ int file_set_dosmode(connection_struct *conn, const char *fname,
        mode_t tmp;
        mode_t unixmode;
        int ret = -1, lret = -1;
+       uint32_t old_mode;
 
        /* We only allow READONLY|HIDDEN|SYSTEM|DIRECTORY|ARCHIVE here. */
-       dosmode &= SAMBA_ATTRIBUTES_MASK;
+       dosmode &= SAMBA_ATTRIBUTES_MASK | FILE_ATTRIBUTE_OFFLINE;
 
        DEBUG(10,("file_set_dosmode: setting dos mode 0x%x on file %s\n", dosmode, fname));
 
@@ -444,7 +445,24 @@ int file_set_dosmode(connection_struct *conn, const char *fname,
        else
                dosmode &= ~aDIR;
 
-       if (dos_mode(conn,fname,st) == dosmode) {
+       old_mode = dos_mode(conn,fname,st);
+       
+       if (dosmode & FILE_ATTRIBUTE_OFFLINE) {
+               if (!(old_mode & FILE_ATTRIBUTE_OFFLINE)) {
+                       lret = SMB_VFS_SET_OFFLINE(conn, fname);
+                       if (lret == -1) {
+                               DEBUG(0, ("set_dos_mode: client has asked to set "
+                                         "FILE_ATTRIBUTE_OFFLINE to %s/%s but there was "
+                                         "an error while setting it or it is not supported.\n",
+                                         parent_dir, fname));
+                       }
+               }
+       }
+
+       dosmode  &= ~FILE_ATTRIBUTE_OFFLINE;
+       old_mode &= ~FILE_ATTRIBUTE_OFFLINE;
+
+       if (old_mode == dosmode) {
                st->st_mode = unixmode;
                return(0);
        }
@@ -491,16 +509,6 @@ int file_set_dosmode(connection_struct *conn, const char *fname,
                unixmode |= (st->st_mode & (S_IWUSR|S_IWGRP|S_IWOTH));
        }
 
-       if (dosmode & FILE_ATTRIBUTE_OFFLINE) {
-               lret = SMB_VFS_SET_OFFLINE(conn, fname);
-               if (lret == -1) {
-                       DEBUG(0, ("set_dos_mode: client has asked to set "
-                                 "FILE_ATTRIBUTE_OFFLINE to %s/%s but there was "
-                                 "an error while setting it or it is not supported.\n", 
-                                 parent_dir, fname));
-               }
-       }
-
        ret = SMB_VFS_CHMOD(conn, fname, unixmode);
        if (ret == 0) {
                if(!newfile || (lret != -1)) {