Commit f71381fc authored by Ian Kent's avatar Ian Kent Committed by akpm

autofs: use inode permission method for write access

Patch series "autofs: misc patches".

This series contains several patches that resulted mostly from comments
made by Al Viro (quite a long time ago now).


This patch (of 5):

Eliminate some code duplication from mkdir/rmdir/symlink/unlink methods by
using the inode operation .permission().

Link: https://lkml.kernel.org/r/165724445154.30914.10970894936827635879.stgit@donald.themaw.net
Link: https://lkml.kernel.org/r/165724458096.30914.13499431569758625806.stgit@donald.themaw.netSigned-off-by: default avatarIan Kent <raven@themaw.net>
Cc: Al Viro <viro@ZenIV.linux.org.uk>
Cc: David Howells <dhowells@redhat.com>
Cc: Miklos Szeredi <miklos@szeredi.hu>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent 55656016
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "autofs_i.h" #include "autofs_i.h"
static int autofs_dir_permission(struct user_namespace *, struct inode *, int);
static int autofs_dir_symlink(struct user_namespace *, struct inode *, static int autofs_dir_symlink(struct user_namespace *, struct inode *,
struct dentry *, const char *); struct dentry *, const char *);
static int autofs_dir_unlink(struct inode *, struct dentry *); static int autofs_dir_unlink(struct inode *, struct dentry *);
...@@ -50,6 +51,7 @@ const struct file_operations autofs_dir_operations = { ...@@ -50,6 +51,7 @@ const struct file_operations autofs_dir_operations = {
const struct inode_operations autofs_dir_inode_operations = { const struct inode_operations autofs_dir_inode_operations = {
.lookup = autofs_lookup, .lookup = autofs_lookup,
.permission = autofs_dir_permission,
.unlink = autofs_dir_unlink, .unlink = autofs_dir_unlink,
.symlink = autofs_dir_symlink, .symlink = autofs_dir_symlink,
.mkdir = autofs_dir_mkdir, .mkdir = autofs_dir_mkdir,
...@@ -526,18 +528,11 @@ static struct dentry *autofs_lookup(struct inode *dir, ...@@ -526,18 +528,11 @@ static struct dentry *autofs_lookup(struct inode *dir,
return NULL; return NULL;
} }
static int autofs_dir_symlink(struct user_namespace *mnt_userns, static int autofs_dir_permission(struct user_namespace *mnt_userns,
struct inode *dir, struct dentry *dentry, struct inode *inode, int mask)
const char *symname)
{ {
struct autofs_sb_info *sbi = autofs_sbi(dir->i_sb); if (mask & MAY_WRITE) {
struct autofs_info *ino = autofs_dentry_ino(dentry); struct autofs_sb_info *sbi = autofs_sbi(inode->i_sb);
struct autofs_info *p_ino;
struct inode *inode;
size_t size = strlen(symname);
char *cp;
pr_debug("%s <- %pd\n", symname, dentry);
if (!autofs_oz_mode(sbi)) if (!autofs_oz_mode(sbi))
return -EACCES; return -EACCES;
...@@ -548,6 +543,22 @@ static int autofs_dir_symlink(struct user_namespace *mnt_userns, ...@@ -548,6 +543,22 @@ static int autofs_dir_symlink(struct user_namespace *mnt_userns,
*/ */
if (sbi->flags & AUTOFS_SBI_CATATONIC) if (sbi->flags & AUTOFS_SBI_CATATONIC)
return -EACCES; return -EACCES;
}
return generic_permission(mnt_userns, inode, mask);
}
static int autofs_dir_symlink(struct user_namespace *mnt_userns,
struct inode *dir, struct dentry *dentry,
const char *symname)
{
struct autofs_info *ino = autofs_dentry_ino(dentry);
struct autofs_info *p_ino;
struct inode *inode;
size_t size = strlen(symname);
char *cp;
pr_debug("%s <- %pd\n", symname, dentry);
BUG_ON(!ino); BUG_ON(!ino);
...@@ -601,16 +612,6 @@ static int autofs_dir_unlink(struct inode *dir, struct dentry *dentry) ...@@ -601,16 +612,6 @@ static int autofs_dir_unlink(struct inode *dir, struct dentry *dentry)
struct autofs_info *ino = autofs_dentry_ino(dentry); struct autofs_info *ino = autofs_dentry_ino(dentry);
struct autofs_info *p_ino; struct autofs_info *p_ino;
if (!autofs_oz_mode(sbi))
return -EACCES;
/* autofs_oz_mode() needs to allow path walks when the
* autofs mount is catatonic but the state of an autofs
* file system needs to be preserved over restarts.
*/
if (sbi->flags & AUTOFS_SBI_CATATONIC)
return -EACCES;
ino->count--; ino->count--;
p_ino = autofs_dentry_ino(dentry->d_parent); p_ino = autofs_dentry_ino(dentry->d_parent);
p_ino->count--; p_ino->count--;
...@@ -683,16 +684,6 @@ static int autofs_dir_rmdir(struct inode *dir, struct dentry *dentry) ...@@ -683,16 +684,6 @@ static int autofs_dir_rmdir(struct inode *dir, struct dentry *dentry)
pr_debug("dentry %p, removing %pd\n", dentry, dentry); pr_debug("dentry %p, removing %pd\n", dentry, dentry);
if (!autofs_oz_mode(sbi))
return -EACCES;
/* autofs_oz_mode() needs to allow path walks when the
* autofs mount is catatonic but the state of an autofs
* file system needs to be preserved over restarts.
*/
if (sbi->flags & AUTOFS_SBI_CATATONIC)
return -EACCES;
if (ino->count != 1) if (ino->count != 1)
return -ENOTEMPTY; return -ENOTEMPTY;
...@@ -726,16 +717,6 @@ static int autofs_dir_mkdir(struct user_namespace *mnt_userns, ...@@ -726,16 +717,6 @@ static int autofs_dir_mkdir(struct user_namespace *mnt_userns,
struct autofs_info *p_ino; struct autofs_info *p_ino;
struct inode *inode; struct inode *inode;
if (!autofs_oz_mode(sbi))
return -EACCES;
/* autofs_oz_mode() needs to allow path walks when the
* autofs mount is catatonic but the state of an autofs
* file system needs to be preserved over restarts.
*/
if (sbi->flags & AUTOFS_SBI_CATATONIC)
return -EACCES;
pr_debug("dentry %p, creating %pd\n", dentry, dentry); pr_debug("dentry %p, creating %pd\n", dentry, dentry);
BUG_ON(!ino); BUG_ON(!ino);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment