cifs: fix inode leak in cifs_get_inode_info_unix
[pandora-kernel.git] / fs / cifs / inode.c
index ae6b725..2e904bd 100644 (file)
@@ -219,15 +219,15 @@ int cifs_get_inode_info_unix(struct inode **pinode,
        rc = CIFSSMBUnixQPathInfo(xid, pTcon, full_path, &find_data,
                                  cifs_sb->local_nls, cifs_sb->mnt_cifs_flags &
                                        CIFS_MOUNT_MAP_SPECIAL_CHR);
-       if (rc) {
-               if (rc == -EREMOTE && !is_dfs_referral) {
-                       is_dfs_referral = true;
-                       cFYI(DBG2, ("DFS ref"));
-                       /* for DFS, server does not give us real inode data */
-                       fill_fake_finddataunix(&find_data, sb);
-                       rc = 0;
-               }
-       }
+       if (rc == -EREMOTE && !is_dfs_referral) {
+               is_dfs_referral = true;
+               cFYI(DBG2, ("DFS ref"));
+               /* for DFS, server does not give us real inode data */
+               fill_fake_finddataunix(&find_data, sb);
+               rc = 0;
+       } else if (rc)
+               goto cgiiu_exit;
+
        num_of_bytes = le64_to_cpu(find_data.NumOfBytes);
        end_of_file = le64_to_cpu(find_data.EndOfFile);
 
@@ -236,7 +236,7 @@ int cifs_get_inode_info_unix(struct inode **pinode,
                *pinode = new_inode(sb);
                if (*pinode == NULL) {
                        rc = -ENOMEM;
-               goto cgiiu_exit;
+                       goto cgiiu_exit;
                }
                /* Is an i_ino of zero legal? */
                /* note ino incremented to unique num in new_inode */
@@ -1546,13 +1546,26 @@ int cifs_setattr(struct dentry *direntry, struct iattr *attrs)
                } else
                        goto cifs_setattr_exit;
        }
-       if (attrs->ia_valid & ATTR_UID) {
-               cFYI(1, ("UID changed to %d", attrs->ia_uid));
-               uid = attrs->ia_uid;
-       }
-       if (attrs->ia_valid & ATTR_GID) {
-               cFYI(1, ("GID changed to %d", attrs->ia_gid));
-               gid = attrs->ia_gid;
+
+       /*
+        * Without unix extensions we can't send ownership changes to the
+        * server, so silently ignore them. This is consistent with how
+        * local DOS/Windows filesystems behave (VFAT, NTFS, etc). With
+        * CIFSACL support + proper Windows to Unix idmapping, we may be
+        * able to support this in the future.
+        */
+       if (!pTcon->unix_ext &&
+           !(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID)) {
+               attrs->ia_valid &= ~(ATTR_UID | ATTR_GID);
+       } else {
+               if (attrs->ia_valid & ATTR_UID) {
+                       cFYI(1, ("UID changed to %d", attrs->ia_uid));
+                       uid = attrs->ia_uid;
+               }
+               if (attrs->ia_valid & ATTR_GID) {
+                       cFYI(1, ("GID changed to %d", attrs->ia_gid));
+                       gid = attrs->ia_gid;
+               }
        }
 
        time_buf.Attributes = 0;
@@ -1562,7 +1575,7 @@ int cifs_setattr(struct dentry *direntry, struct iattr *attrs)
                attrs->ia_valid &= ~ATTR_MODE;
 
        if (attrs->ia_valid & ATTR_MODE) {
-               cFYI(1, ("Mode changed to 0x%x", attrs->ia_mode));
+               cFYI(1, ("Mode changed to 0%o", attrs->ia_mode));
                mode = attrs->ia_mode;
        }
 
@@ -1577,18 +1590,18 @@ int cifs_setattr(struct dentry *direntry, struct iattr *attrs)
 #ifdef CONFIG_CIFS_EXPERIMENTAL
                if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL)
                        rc = mode_to_acl(inode, full_path, mode);
-               else if ((mode & S_IWUGO) == 0) {
-#else
-               if ((mode & S_IWUGO) == 0) {
+               else
 #endif
-                       /* not writeable */
-                       if ((cifsInode->cifsAttrs & ATTR_READONLY) == 0) {
-                               set_dosattr = true;
-                               time_buf.Attributes =
-                                       cpu_to_le32(cifsInode->cifsAttrs |
-                                                   ATTR_READONLY);
-                       }
-               } else if (cifsInode->cifsAttrs & ATTR_READONLY) {
+               if (((mode & S_IWUGO) == 0) &&
+                   (cifsInode->cifsAttrs & ATTR_READONLY) == 0) {
+                       set_dosattr = true;
+                       time_buf.Attributes = cpu_to_le32(cifsInode->cifsAttrs |
+                                                         ATTR_READONLY);
+                       /* fix up mode if we're not using dynperm */
+                       if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DYNPERM) == 0)
+                               attrs->ia_mode = inode->i_mode & ~S_IWUGO;
+               } else if ((mode & S_IWUGO) &&
+                          (cifsInode->cifsAttrs & ATTR_READONLY)) {
                        /* If file is readonly on server, we would
                        not be able to write to it - so if any write
                        bit is enabled for user or group or other we
@@ -1599,6 +1612,20 @@ int cifs_setattr(struct dentry *direntry, struct iattr *attrs)
                        /* Windows ignores set to zero */
                        if (time_buf.Attributes == 0)
                                time_buf.Attributes |= cpu_to_le32(ATTR_NORMAL);
+
+                       /* reset local inode permissions to normal */
+                       if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DYNPERM)) {
+                               attrs->ia_mode &= ~(S_IALLUGO);
+                               if (S_ISDIR(inode->i_mode))
+                                       attrs->ia_mode |=
+                                               cifs_sb->mnt_dir_mode;
+                               else
+                                       attrs->ia_mode |=
+                                               cifs_sb->mnt_file_mode;
+                       }
+               } else if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DYNPERM)) {
+                       /* ignore mode change - ATTR_READONLY hasn't changed */
+                       attrs->ia_valid &= ~ATTR_MODE;
                }
        }