Re: [PATCH 4/5] fs: tftp: hide files which are actually not present on the server

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Aug 30, 2018 at 12:45:26PM +0200, Sascha Hauer wrote:
> In tftp_lookup we claimed that every desired file is there. This leads
> to problems when a user only tests if a file is present and makes
> decisions upon this information. Rather than claiming that all files
> are present do a tftp_do_open() on the files and see if it is really
> there.
> 
> Signed-off-by: Sascha Hauer <s.hauer@xxxxxxxxxxxxxx>
> ---
>  fs/tftp.c | 33 +++++++++++++++++++++++++--------
>  1 file changed, 25 insertions(+), 8 deletions(-)
> 
> diff --git a/fs/tftp.c b/fs/tftp.c
> index 0baf0c2890..9274e931a2 100644
> --- a/fs/tftp.c
> +++ b/fs/tftp.c
> @@ -391,14 +391,6 @@ static struct file_priv *tftp_do_open(struct device_d *dev,
>  	case O_WRONLY:
>  		priv->push = 1;
>  		priv->state = STATE_WRQ;
> -		if (!(accmode & O_TRUNC)) {
> -			/*
> -			 * TFTP always truncates the existing file, so this
> -			 * flag is mandatory when opening a file for writing.
> -			 */
> -			ret = -ENOSYS;
> -			goto out;
> -		}
>  		break;
>  	case O_RDWR:
>  		ret = -ENOSYS;
> @@ -646,10 +638,34 @@ static struct inode *tftp_get_inode(struct super_block *sb, const struct inode *
>  	return inode;
>  }
>  
> +static int tftp_create(struct inode *dir, struct dentry *dentry, umode_t mode)
> +{
> +	struct inode *inode;
> +
> +	inode = tftp_get_inode(dir->i_sb, dir, mode);
> +	if (!inode)
> +		return -EPERM;
> +
> +	inode->i_size = 0;
> +
> +	d_instantiate(dentry, inode);
> +
> +	return 0;
> +}
> +
>  static struct dentry *tftp_lookup(struct inode *dir, struct dentry *dentry,
>  			    unsigned int flags)
>  {
> +	struct super_block *sb = dir->i_sb;
> +	struct fs_device_d *fsdev = container_of(sb, struct fs_device_d, sb);
>  	struct inode *inode;
> +	struct file_priv *priv;
> +
> +	priv = tftp_do_open(&fsdev->dev, O_RDONLY, dentry);
> +	if (IS_ERR(priv))
> +		return NULL;
> +
> +	tftp_do_close(priv);
>  
>  	inode = tftp_get_inode(dir->i_sb, dir, S_IFREG | S_IRWXUGO);
>  	if (!inode)
> @@ -663,6 +679,7 @@ static struct dentry *tftp_lookup(struct inode *dir, struct dentry *dentry,
>  static const struct inode_operations tftp_dir_inode_operations =
>  {
>  	.lookup = tftp_lookup,
> +	.create = tftp_create,
>  };
>  
>  static const struct super_operations tftp_ops;

Tested-by: Steffen Trumtrar <s.trumtrar@xxxxxxxxxxxxxx>

Thx,
Steffen

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox



[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux