diff mbox

[02/23] vfs: Check for create permission during rename

Message ID 1265002505-8387-3-git-send-email-aneesh.kumar@linux.vnet.ibm.com
State Not Applicable, archived
Headers show

Commit Message

Aneesh Kumar K.V Feb. 1, 2010, 5:34 a.m. UTC
If the new dentry is already present we were just checking
for the delete permission. We also need to check after
deletion whether we are allowed to create new name. This
is needed in case of a acl model that differentiate between
delete and create permission like NFSv4acl

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
---
 fs/namei.c |   18 ++++++++++++++----
 1 files changed, 14 insertions(+), 4 deletions(-)
diff mbox

Patch

diff --git a/fs/namei.c b/fs/namei.c
index 3e842ac..2a1a1d6 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -1380,12 +1380,11 @@  static int may_delete(struct inode *dir,struct dentry *victim,int isdir)
  *  3. We should have write and exec permissions on dir
  *  4. We can't do it if dir is immutable (done in permission())
  */
-static inline int may_create(struct inode *dir, struct dentry *child, int isdir)
+static inline int _do_may_create(struct inode *dir,
+				struct dentry *child, int isdir)
 {
 	int error;
 
-	if (child->d_inode)
-		return -EEXIST;
 	if (IS_DEADDIR(dir))
 		return -ENOENT;
 	if (dir->i_op->may_create) {
@@ -1403,6 +1402,13 @@  static inline int may_create(struct inode *dir, struct dentry *child, int isdir)
 	return error;
 }
 
+static inline int may_create(struct inode *dir, struct dentry *child, int isdir)
+{
+	if (child->d_inode)
+		return -EEXIST;
+	return _do_may_create(dir, child, isdir);
+}
+
 /* 
  * O_DIRECTORY translates into forcing a directory lookup.
  */
@@ -2673,8 +2679,12 @@  int vfs_rename(struct inode *old_dir, struct dentry *old_dentry,
 
 	if (!new_dentry->d_inode)
 		error = may_create(new_dir, new_dentry, is_dir);
-	else
+	else {
 		error = may_delete(new_dir, new_dentry, is_dir);
+		if (error)
+			return error;
+		error = _do_may_create(new_dir, new_dentry, is_dir);
+	}
 	if (error)
 		return error;