Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 260722
b: refs/heads/master
c: e57712e
h: refs/heads/master
v: v3
  • Loading branch information
Al Viro committed Jul 26, 2011
1 parent 7f51350 commit 3fc99cb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 51 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 03209378b4b25775bf5e6a86e86f074a1057a439
refs/heads/master: e57712ebebbb9db7d8dcef216437b3171ddcf115
78 changes: 28 additions & 50 deletions trunk/fs/open.c
Original file line number Diff line number Diff line change
Expand Up @@ -446,74 +446,52 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
return error;
}

SYSCALL_DEFINE2(fchmod, unsigned int, fd, mode_t, mode)
static int chmod_common(struct path *path, umode_t mode)
{
struct inode * inode;
struct dentry * dentry;
struct file * file;
int err = -EBADF;
struct inode *inode = path->dentry->d_inode;
struct iattr newattrs;
int error;

file = fget(fd);
if (!file)
goto out;

dentry = file->f_path.dentry;
inode = dentry->d_inode;

audit_inode(NULL, dentry);

err = mnt_want_write_file(file);
if (err)
goto out_putf;
error = mnt_want_write(path->mnt);
if (error)
return error;
mutex_lock(&inode->i_mutex);
err = security_path_chmod(dentry, file->f_vfsmnt, mode);
if (err)
error = security_path_chmod(path->dentry, path->mnt, mode);
if (error)
goto out_unlock;
if (mode == (mode_t) -1)
mode = inode->i_mode;
newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
err = notify_change(dentry, &newattrs);
error = notify_change(path->dentry, &newattrs);
out_unlock:
mutex_unlock(&inode->i_mutex);
mnt_drop_write(file->f_path.mnt);
out_putf:
fput(file);
out:
mnt_drop_write(path->mnt);
return error;
}

SYSCALL_DEFINE2(fchmod, unsigned int, fd, mode_t, mode)
{
struct file * file;
int err = -EBADF;

file = fget(fd);
if (file) {
audit_inode(NULL, file->f_path.dentry);
err = chmod_common(&file->f_path, mode);
fput(file);
}
return err;
}

SYSCALL_DEFINE3(fchmodat, int, dfd, const char __user *, filename, mode_t, mode)
{
struct path path;
struct inode *inode;
int error;
struct iattr newattrs;

error = user_path_at(dfd, filename, LOOKUP_FOLLOW, &path);
if (error)
goto out;
inode = path.dentry->d_inode;

error = mnt_want_write(path.mnt);
if (error)
goto dput_and_out;
mutex_lock(&inode->i_mutex);
error = security_path_chmod(path.dentry, path.mnt, mode);
if (error)
goto out_unlock;
if (mode == (mode_t) -1)
mode = inode->i_mode;
newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
error = notify_change(path.dentry, &newattrs);
out_unlock:
mutex_unlock(&inode->i_mutex);
mnt_drop_write(path.mnt);
dput_and_out:
path_put(&path);
out:
if (!error) {
error = chmod_common(&path, mode);
path_put(&path);
}
return error;
}

Expand Down

0 comments on commit 3fc99cb

Please sign in to comment.