2021-06-18 13:31:49 +08:00
|
|
|
// SPDX-License-Identifier: LGPL-2.1
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* fs/cifs/xattr.c
|
|
|
|
*
|
2007-07-07 06:44:50 +08:00
|
|
|
* Copyright (c) International Business Machines Corp., 2003, 2007
|
2005-04-17 06:20:36 +08:00
|
|
|
* Author(s): Steve French (sfrench@us.ibm.com)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/posix_acl_xattr.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2011-08-12 04:00:47 +08:00
|
|
|
#include <linux/xattr.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include "cifsfs.h"
|
|
|
|
#include "cifspdu.h"
|
|
|
|
#include "cifsglob.h"
|
|
|
|
#include "cifsproto.h"
|
|
|
|
#include "cifs_debug.h"
|
2014-09-27 15:19:01 +08:00
|
|
|
#include "cifs_fs_sb.h"
|
|
|
|
#include "cifs_unicode.h"
|
2021-04-29 13:18:43 +08:00
|
|
|
#include "cifs_ioctl.h"
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-09-21 19:26:00 +08:00
|
|
|
#define MAX_EA_VALUE_SIZE CIFSMaxBufSize
|
2019-12-20 00:52:50 +08:00
|
|
|
#define CIFS_XATTR_CIFS_ACL "system.cifs_acl" /* DACL only */
|
|
|
|
#define CIFS_XATTR_CIFS_NTSD "system.cifs_ntsd" /* owner plus DACL */
|
2020-12-19 01:30:12 +08:00
|
|
|
#define CIFS_XATTR_CIFS_NTSD_FULL "system.cifs_ntsd_full" /* owner/DACL/SACL */
|
2016-09-20 00:14:06 +08:00
|
|
|
#define CIFS_XATTR_ATTRIB "cifs.dosattrib" /* full name: user.cifs.dosattrib */
|
2016-09-20 16:05:57 +08:00
|
|
|
#define CIFS_XATTR_CREATETIME "cifs.creationtime" /* user.cifs.creationtime */
|
2018-08-11 07:46:58 +08:00
|
|
|
/*
|
|
|
|
* Although these three are just aliases for the above, need to move away from
|
|
|
|
* confusing users and using the 20+ year old term 'cifs' when it is no longer
|
|
|
|
* secure, replaced by SMB2 (then even more highly secure SMB3) many years ago
|
|
|
|
*/
|
2019-12-20 00:52:50 +08:00
|
|
|
#define SMB3_XATTR_CIFS_ACL "system.smb3_acl" /* DACL only */
|
|
|
|
#define SMB3_XATTR_CIFS_NTSD "system.smb3_ntsd" /* owner plus DACL */
|
2020-12-19 01:30:12 +08:00
|
|
|
#define SMB3_XATTR_CIFS_NTSD_FULL "system.smb3_ntsd_full" /* owner/DACL/SACL */
|
2018-08-11 07:46:58 +08:00
|
|
|
#define SMB3_XATTR_ATTRIB "smb3.dosattrib" /* full name: user.smb3.dosattrib */
|
|
|
|
#define SMB3_XATTR_CREATETIME "smb3.creationtime" /* user.smb3.creationtime */
|
2011-08-12 04:00:47 +08:00
|
|
|
/* BB need to add server (Samba e.g) support for security and trusted prefix */
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-12-20 00:52:50 +08:00
|
|
|
enum { XATTR_USER, XATTR_CIFS_ACL, XATTR_ACL_ACCESS, XATTR_ACL_DEFAULT,
|
2020-12-19 01:30:12 +08:00
|
|
|
XATTR_CIFS_NTSD, XATTR_CIFS_NTSD_FULL };
|
2019-12-20 00:52:50 +08:00
|
|
|
|
|
|
|
static int cifs_attrib_set(unsigned int xid, struct cifs_tcon *pTcon,
|
2021-03-19 03:44:05 +08:00
|
|
|
struct inode *inode, const char *full_path,
|
2019-12-20 00:52:50 +08:00
|
|
|
const void *value, size_t size)
|
|
|
|
{
|
|
|
|
ssize_t rc = -EOPNOTSUPP;
|
|
|
|
__u32 *pattrib = (__u32 *)value;
|
|
|
|
__u32 attrib;
|
|
|
|
FILE_BASIC_INFO info_buf;
|
|
|
|
|
|
|
|
if ((value == NULL) || (size != sizeof(__u32)))
|
|
|
|
return -ERANGE;
|
|
|
|
|
|
|
|
memset(&info_buf, 0, sizeof(info_buf));
|
|
|
|
attrib = *pattrib;
|
|
|
|
info_buf.Attributes = cpu_to_le32(attrib);
|
|
|
|
if (pTcon->ses->server->ops->set_file_info)
|
|
|
|
rc = pTcon->ses->server->ops->set_file_info(inode, full_path,
|
|
|
|
&info_buf, xid);
|
|
|
|
if (rc == 0)
|
|
|
|
CIFS_I(inode)->cifsAttrs = attrib;
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cifs_creation_time_set(unsigned int xid, struct cifs_tcon *pTcon,
|
2021-03-19 03:44:05 +08:00
|
|
|
struct inode *inode, const char *full_path,
|
2019-12-20 00:52:50 +08:00
|
|
|
const void *value, size_t size)
|
|
|
|
{
|
|
|
|
ssize_t rc = -EOPNOTSUPP;
|
|
|
|
__u64 *pcreation_time = (__u64 *)value;
|
|
|
|
__u64 creation_time;
|
|
|
|
FILE_BASIC_INFO info_buf;
|
|
|
|
|
|
|
|
if ((value == NULL) || (size != sizeof(__u64)))
|
|
|
|
return -ERANGE;
|
|
|
|
|
|
|
|
memset(&info_buf, 0, sizeof(info_buf));
|
|
|
|
creation_time = *pcreation_time;
|
|
|
|
info_buf.CreationTime = cpu_to_le64(creation_time);
|
|
|
|
if (pTcon->ses->server->ops->set_file_info)
|
|
|
|
rc = pTcon->ses->server->ops->set_file_info(inode, full_path,
|
|
|
|
&info_buf, xid);
|
|
|
|
if (rc == 0)
|
|
|
|
CIFS_I(inode)->createtime = creation_time;
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
2010-09-30 07:51:11 +08:00
|
|
|
|
2016-04-22 18:11:38 +08:00
|
|
|
static int cifs_xattr_set(const struct xattr_handler *handler,
|
2021-01-21 21:19:27 +08:00
|
|
|
struct user_namespace *mnt_userns,
|
2016-05-27 22:19:30 +08:00
|
|
|
struct dentry *dentry, struct inode *inode,
|
|
|
|
const char *name, const void *value,
|
|
|
|
size_t size, int flags)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int rc = -EOPNOTSUPP;
|
2012-06-20 15:21:16 +08:00
|
|
|
unsigned int xid;
|
2016-04-22 18:11:38 +08:00
|
|
|
struct super_block *sb = dentry->d_sb;
|
2016-04-11 05:07:33 +08:00
|
|
|
struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
|
2010-09-30 07:51:11 +08:00
|
|
|
struct tcon_link *tlink;
|
2011-05-27 12:34:02 +08:00
|
|
|
struct cifs_tcon *pTcon;
|
2021-03-19 03:47:35 +08:00
|
|
|
const char *full_path;
|
2021-03-06 06:36:04 +08:00
|
|
|
void *page;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-09-30 07:51:11 +08:00
|
|
|
tlink = cifs_sb_tlink(cifs_sb);
|
|
|
|
if (IS_ERR(tlink))
|
|
|
|
return PTR_ERR(tlink);
|
|
|
|
pTcon = tlink_tcon(tlink);
|
|
|
|
|
2012-06-20 15:21:16 +08:00
|
|
|
xid = get_xid();
|
2021-03-06 06:36:04 +08:00
|
|
|
page = alloc_dentry_path();
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2021-03-06 06:36:04 +08:00
|
|
|
full_path = build_path_from_dentry(dentry, page);
|
|
|
|
if (IS_ERR(full_path)) {
|
|
|
|
rc = PTR_ERR(full_path);
|
2016-04-22 18:11:38 +08:00
|
|
|
goto out;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
/* return dos attributes as pseudo xattr */
|
|
|
|
/* return alt name if available as pseudo attr */
|
|
|
|
|
|
|
|
/* if proc/fs/cifs/streamstoxattr is set then
|
2007-07-07 06:44:50 +08:00
|
|
|
search server for EAs or streams to
|
2005-04-17 06:20:36 +08:00
|
|
|
returns as xattrs */
|
2016-04-22 18:11:38 +08:00
|
|
|
if (size > MAX_EA_VALUE_SIZE) {
|
2013-05-05 11:12:25 +08:00
|
|
|
cifs_dbg(FYI, "size of EA value too large\n");
|
2010-09-30 07:51:11 +08:00
|
|
|
rc = -EOPNOTSUPP;
|
2016-04-22 18:11:38 +08:00
|
|
|
goto out;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2016-04-22 18:11:38 +08:00
|
|
|
switch (handler->flags) {
|
|
|
|
case XATTR_USER:
|
2019-12-20 00:52:50 +08:00
|
|
|
cifs_dbg(FYI, "%s:setting user xattr %s\n", __func__, name);
|
|
|
|
if ((strcmp(name, CIFS_XATTR_ATTRIB) == 0) ||
|
|
|
|
(strcmp(name, SMB3_XATTR_ATTRIB) == 0)) {
|
|
|
|
rc = cifs_attrib_set(xid, pTcon, inode, full_path,
|
|
|
|
value, size);
|
|
|
|
if (rc == 0) /* force revalidate of the inode */
|
|
|
|
CIFS_I(inode)->time = 0;
|
|
|
|
break;
|
|
|
|
} else if ((strcmp(name, CIFS_XATTR_CREATETIME) == 0) ||
|
|
|
|
(strcmp(name, SMB3_XATTR_CREATETIME) == 0)) {
|
|
|
|
rc = cifs_creation_time_set(xid, pTcon, inode,
|
|
|
|
full_path, value, size);
|
|
|
|
if (rc == 0) /* force revalidate of the inode */
|
|
|
|
CIFS_I(inode)->time = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-07-07 06:44:50 +08:00
|
|
|
if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
|
2016-04-22 18:11:38 +08:00
|
|
|
goto out;
|
2008-02-08 07:25:02 +08:00
|
|
|
|
2014-01-27 13:53:43 +08:00
|
|
|
if (pTcon->ses->server->ops->set_EA)
|
|
|
|
rc = pTcon->ses->server->ops->set_EA(xid, pTcon,
|
2016-04-22 18:11:38 +08:00
|
|
|
full_path, name, value, (__u16)size,
|
2017-08-24 09:24:56 +08:00
|
|
|
cifs_sb->local_nls, cifs_sb);
|
2016-04-22 18:11:38 +08:00
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-12-20 00:52:50 +08:00
|
|
|
case XATTR_CIFS_ACL:
|
2020-12-19 01:30:12 +08:00
|
|
|
case XATTR_CIFS_NTSD:
|
|
|
|
case XATTR_CIFS_NTSD_FULL: {
|
2012-03-02 14:17:26 +08:00
|
|
|
struct cifs_ntsd *pacl;
|
2016-04-22 18:11:38 +08:00
|
|
|
|
|
|
|
if (!value)
|
|
|
|
goto out;
|
|
|
|
pacl = kmalloc(size, GFP_KERNEL);
|
2011-04-20 02:27:10 +08:00
|
|
|
if (!pacl) {
|
|
|
|
rc = -ENOMEM;
|
|
|
|
} else {
|
2016-04-22 18:11:38 +08:00
|
|
|
memcpy(pacl, value, size);
|
2020-12-19 01:30:12 +08:00
|
|
|
if (pTcon->ses->server->ops->set_acl) {
|
|
|
|
int aclflags = 0;
|
2019-12-20 00:52:50 +08:00
|
|
|
rc = 0;
|
2020-12-19 01:30:12 +08:00
|
|
|
|
|
|
|
switch (handler->flags) {
|
|
|
|
case XATTR_CIFS_NTSD_FULL:
|
|
|
|
aclflags = (CIFS_ACL_OWNER |
|
|
|
|
CIFS_ACL_DACL |
|
|
|
|
CIFS_ACL_SACL);
|
|
|
|
break;
|
|
|
|
case XATTR_CIFS_NTSD:
|
|
|
|
aclflags = (CIFS_ACL_OWNER |
|
|
|
|
CIFS_ACL_DACL);
|
|
|
|
break;
|
|
|
|
case XATTR_CIFS_ACL:
|
|
|
|
default:
|
|
|
|
aclflags = CIFS_ACL_DACL;
|
2019-12-20 00:52:50 +08:00
|
|
|
}
|
2020-12-19 01:30:12 +08:00
|
|
|
|
|
|
|
rc = pTcon->ses->server->ops->set_acl(pacl,
|
|
|
|
size, inode, full_path, aclflags);
|
2019-12-20 00:52:50 +08:00
|
|
|
} else {
|
2014-02-03 13:31:47 +08:00
|
|
|
rc = -EOPNOTSUPP;
|
2019-12-20 00:52:50 +08:00
|
|
|
}
|
2011-04-20 02:27:10 +08:00
|
|
|
if (rc == 0) /* force revalidate of the inode */
|
2016-05-27 22:19:30 +08:00
|
|
|
CIFS_I(inode)->time = 0;
|
2011-04-20 02:27:10 +08:00
|
|
|
kfree(pacl);
|
2012-03-02 14:17:26 +08:00
|
|
|
}
|
2016-04-22 18:11:38 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case XATTR_ACL_ACCESS:
|
2005-04-17 06:20:36 +08:00
|
|
|
#ifdef CONFIG_CIFS_POSIX
|
2016-04-22 18:11:38 +08:00
|
|
|
if (!value)
|
|
|
|
goto out;
|
2017-11-28 05:05:09 +08:00
|
|
|
if (sb->s_flags & SB_POSIXACL)
|
2016-04-22 18:11:38 +08:00
|
|
|
rc = CIFSSMBSetPosixACL(xid, pTcon, full_path,
|
|
|
|
value, (const int)size,
|
|
|
|
ACL_TYPE_ACCESS, cifs_sb->local_nls,
|
|
|
|
cifs_remap(cifs_sb));
|
|
|
|
#endif /* CONFIG_CIFS_POSIX */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case XATTR_ACL_DEFAULT:
|
2005-04-17 06:20:36 +08:00
|
|
|
#ifdef CONFIG_CIFS_POSIX
|
2016-04-22 18:11:38 +08:00
|
|
|
if (!value)
|
|
|
|
goto out;
|
2017-11-28 05:05:09 +08:00
|
|
|
if (sb->s_flags & SB_POSIXACL)
|
2016-04-22 18:11:38 +08:00
|
|
|
rc = CIFSSMBSetPosixACL(xid, pTcon, full_path,
|
|
|
|
value, (const int)size,
|
|
|
|
ACL_TYPE_DEFAULT, cifs_sb->local_nls,
|
|
|
|
cifs_remap(cifs_sb));
|
|
|
|
#endif /* CONFIG_CIFS_POSIX */
|
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2016-04-22 18:11:38 +08:00
|
|
|
out:
|
2021-03-06 06:36:04 +08:00
|
|
|
free_dentry_path(page);
|
2012-06-20 15:21:16 +08:00
|
|
|
free_xid(xid);
|
2010-09-30 07:51:11 +08:00
|
|
|
cifs_put_tlink(tlink);
|
2005-04-17 06:20:36 +08:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2016-09-20 00:14:06 +08:00
|
|
|
static int cifs_attrib_get(struct dentry *dentry,
|
|
|
|
struct inode *inode, void *value,
|
|
|
|
size_t size)
|
|
|
|
{
|
|
|
|
ssize_t rc;
|
|
|
|
__u32 *pattribute;
|
|
|
|
|
|
|
|
rc = cifs_revalidate_dentry_attr(dentry);
|
|
|
|
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
if ((value == NULL) || (size == 0))
|
|
|
|
return sizeof(__u32);
|
|
|
|
else if (size < sizeof(__u32))
|
|
|
|
return -ERANGE;
|
|
|
|
|
|
|
|
/* return dos attributes as pseudo xattr */
|
|
|
|
pattribute = (__u32 *)value;
|
|
|
|
*pattribute = CIFS_I(inode)->cifsAttrs;
|
|
|
|
|
|
|
|
return sizeof(__u32);
|
|
|
|
}
|
|
|
|
|
2016-09-20 16:05:57 +08:00
|
|
|
static int cifs_creation_time_get(struct dentry *dentry, struct inode *inode,
|
|
|
|
void *value, size_t size)
|
|
|
|
{
|
|
|
|
ssize_t rc;
|
2019-12-20 00:52:50 +08:00
|
|
|
__u64 *pcreatetime;
|
2016-09-20 16:05:57 +08:00
|
|
|
|
|
|
|
rc = cifs_revalidate_dentry_attr(dentry);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
if ((value == NULL) || (size == 0))
|
|
|
|
return sizeof(__u64);
|
|
|
|
else if (size < sizeof(__u64))
|
|
|
|
return -ERANGE;
|
|
|
|
|
|
|
|
/* return dos attributes as pseudo xattr */
|
|
|
|
pcreatetime = (__u64 *)value;
|
|
|
|
*pcreatetime = CIFS_I(inode)->createtime;
|
|
|
|
return sizeof(__u64);
|
|
|
|
}
|
|
|
|
|
2016-09-20 00:14:06 +08:00
|
|
|
|
2016-04-22 18:11:38 +08:00
|
|
|
static int cifs_xattr_get(const struct xattr_handler *handler,
|
|
|
|
struct dentry *dentry, struct inode *inode,
|
|
|
|
const char *name, void *value, size_t size)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
ssize_t rc = -EOPNOTSUPP;
|
2012-06-20 15:21:16 +08:00
|
|
|
unsigned int xid;
|
2016-04-22 18:11:38 +08:00
|
|
|
struct super_block *sb = dentry->d_sb;
|
2016-04-11 05:07:33 +08:00
|
|
|
struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
|
2010-09-30 07:51:11 +08:00
|
|
|
struct tcon_link *tlink;
|
2011-05-27 12:34:02 +08:00
|
|
|
struct cifs_tcon *pTcon;
|
2021-03-19 03:47:35 +08:00
|
|
|
const char *full_path;
|
2021-03-06 06:36:04 +08:00
|
|
|
void *page;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-09-30 07:51:11 +08:00
|
|
|
tlink = cifs_sb_tlink(cifs_sb);
|
|
|
|
if (IS_ERR(tlink))
|
|
|
|
return PTR_ERR(tlink);
|
|
|
|
pTcon = tlink_tcon(tlink);
|
|
|
|
|
2012-06-20 15:21:16 +08:00
|
|
|
xid = get_xid();
|
2021-03-06 06:36:04 +08:00
|
|
|
page = alloc_dentry_path();
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2021-03-06 06:36:04 +08:00
|
|
|
full_path = build_path_from_dentry(dentry, page);
|
|
|
|
if (IS_ERR(full_path)) {
|
|
|
|
rc = PTR_ERR(full_path);
|
2016-04-22 18:11:38 +08:00
|
|
|
goto out;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2016-09-20 00:14:06 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* return alt name if available as pseudo attr */
|
2016-04-22 18:11:38 +08:00
|
|
|
switch (handler->flags) {
|
|
|
|
case XATTR_USER:
|
2016-09-20 00:14:06 +08:00
|
|
|
cifs_dbg(FYI, "%s:querying user xattr %s\n", __func__, name);
|
2018-08-11 07:46:58 +08:00
|
|
|
if ((strcmp(name, CIFS_XATTR_ATTRIB) == 0) ||
|
|
|
|
(strcmp(name, SMB3_XATTR_ATTRIB) == 0)) {
|
2016-09-20 00:14:06 +08:00
|
|
|
rc = cifs_attrib_get(dentry, inode, value, size);
|
|
|
|
break;
|
2018-08-11 07:46:58 +08:00
|
|
|
} else if ((strcmp(name, CIFS_XATTR_CREATETIME) == 0) ||
|
|
|
|
(strcmp(name, SMB3_XATTR_CREATETIME) == 0)) {
|
2016-09-20 16:05:57 +08:00
|
|
|
rc = cifs_creation_time_get(dentry, inode, value, size);
|
|
|
|
break;
|
2016-09-20 00:14:06 +08:00
|
|
|
}
|
|
|
|
|
2007-07-07 06:44:50 +08:00
|
|
|
if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
|
2016-04-22 18:11:38 +08:00
|
|
|
goto out;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2014-01-27 13:53:43 +08:00
|
|
|
if (pTcon->ses->server->ops->query_all_EAs)
|
|
|
|
rc = pTcon->ses->server->ops->query_all_EAs(xid, pTcon,
|
2017-05-13 09:59:10 +08:00
|
|
|
full_path, name, value, size, cifs_sb);
|
2016-04-22 18:11:38 +08:00
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-12-20 00:52:50 +08:00
|
|
|
case XATTR_CIFS_ACL:
|
2020-12-19 01:30:12 +08:00
|
|
|
case XATTR_CIFS_NTSD:
|
|
|
|
case XATTR_CIFS_NTSD_FULL: {
|
|
|
|
/*
|
|
|
|
* fetch owner, DACL, and SACL if asked for full descriptor,
|
|
|
|
* fetch owner and DACL otherwise
|
|
|
|
*/
|
2020-12-18 04:58:08 +08:00
|
|
|
u32 acllen, extra_info;
|
2016-04-22 18:11:38 +08:00
|
|
|
struct cifs_ntsd *pacl;
|
|
|
|
|
|
|
|
if (pTcon->ses->server->ops->get_acl == NULL)
|
|
|
|
goto out; /* rc already EOPNOTSUPP */
|
|
|
|
|
2020-12-19 01:30:12 +08:00
|
|
|
if (handler->flags == XATTR_CIFS_NTSD_FULL) {
|
2020-12-18 04:58:08 +08:00
|
|
|
extra_info = SACL_SECINFO;
|
2020-12-19 01:30:12 +08:00
|
|
|
} else {
|
2020-12-18 04:58:08 +08:00
|
|
|
extra_info = 0;
|
2020-12-19 01:30:12 +08:00
|
|
|
}
|
2016-04-22 18:11:38 +08:00
|
|
|
pacl = pTcon->ses->server->ops->get_acl(cifs_sb,
|
2020-12-18 04:58:08 +08:00
|
|
|
inode, full_path, &acllen, extra_info);
|
2016-04-22 18:11:38 +08:00
|
|
|
if (IS_ERR(pacl)) {
|
|
|
|
rc = PTR_ERR(pacl);
|
|
|
|
cifs_dbg(VFS, "%s: error %zd getting sec desc\n",
|
|
|
|
__func__, rc);
|
|
|
|
} else {
|
|
|
|
if (value) {
|
|
|
|
if (acllen > size)
|
|
|
|
acllen = -ERANGE;
|
|
|
|
else
|
|
|
|
memcpy(value, pacl, acllen);
|
|
|
|
}
|
|
|
|
rc = acllen;
|
|
|
|
kfree(pacl);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case XATTR_ACL_ACCESS:
|
2005-04-17 06:20:36 +08:00
|
|
|
#ifdef CONFIG_CIFS_POSIX
|
2017-11-28 05:05:09 +08:00
|
|
|
if (sb->s_flags & SB_POSIXACL)
|
2005-04-29 13:41:04 +08:00
|
|
|
rc = CIFSSMBGetPosixACL(xid, pTcon, full_path,
|
2016-04-22 18:11:38 +08:00
|
|
|
value, size, ACL_TYPE_ACCESS,
|
2005-04-29 13:41:06 +08:00
|
|
|
cifs_sb->local_nls,
|
2014-09-27 15:19:01 +08:00
|
|
|
cifs_remap(cifs_sb));
|
2016-04-22 18:11:38 +08:00
|
|
|
#endif /* CONFIG_CIFS_POSIX */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case XATTR_ACL_DEFAULT:
|
2005-04-17 06:20:36 +08:00
|
|
|
#ifdef CONFIG_CIFS_POSIX
|
2017-11-28 05:05:09 +08:00
|
|
|
if (sb->s_flags & SB_POSIXACL)
|
2005-04-29 13:41:04 +08:00
|
|
|
rc = CIFSSMBGetPosixACL(xid, pTcon, full_path,
|
2016-04-22 18:11:38 +08:00
|
|
|
value, size, ACL_TYPE_DEFAULT,
|
2005-04-29 13:41:06 +08:00
|
|
|
cifs_sb->local_nls,
|
2014-09-27 15:19:01 +08:00
|
|
|
cifs_remap(cifs_sb));
|
2016-04-22 18:11:38 +08:00
|
|
|
#endif /* CONFIG_CIFS_POSIX */
|
|
|
|
break;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-07-07 06:44:50 +08:00
|
|
|
/* We could add an additional check for streams ie
|
2005-04-17 06:20:36 +08:00
|
|
|
if proc/fs/cifs/streamstoxattr is set then
|
2007-07-07 06:44:50 +08:00
|
|
|
search server for EAs or streams to
|
2005-04-17 06:20:36 +08:00
|
|
|
returns as xattrs */
|
|
|
|
|
2007-07-07 06:44:50 +08:00
|
|
|
if (rc == -EINVAL)
|
|
|
|
rc = -EOPNOTSUPP;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2016-04-22 18:11:38 +08:00
|
|
|
out:
|
2021-03-06 06:36:04 +08:00
|
|
|
free_dentry_path(page);
|
2012-06-20 15:21:16 +08:00
|
|
|
free_xid(xid);
|
2010-09-30 07:51:11 +08:00
|
|
|
cifs_put_tlink(tlink);
|
2005-04-17 06:20:36 +08:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2007-07-07 06:44:50 +08:00
|
|
|
ssize_t cifs_listxattr(struct dentry *direntry, char *data, size_t buf_size)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
ssize_t rc = -EOPNOTSUPP;
|
2012-06-20 15:21:16 +08:00
|
|
|
unsigned int xid;
|
2016-04-11 05:07:33 +08:00
|
|
|
struct cifs_sb_info *cifs_sb = CIFS_SB(direntry->d_sb);
|
2010-09-30 07:51:11 +08:00
|
|
|
struct tcon_link *tlink;
|
2011-05-27 12:34:02 +08:00
|
|
|
struct cifs_tcon *pTcon;
|
2021-03-19 03:47:35 +08:00
|
|
|
const char *full_path;
|
2021-03-06 06:36:04 +08:00
|
|
|
void *page;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2021-04-29 13:18:43 +08:00
|
|
|
if (unlikely(cifs_forced_shutdown(cifs_sb)))
|
|
|
|
return -EIO;
|
|
|
|
|
2007-07-07 06:44:50 +08:00
|
|
|
if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
|
2006-08-17 03:44:25 +08:00
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
2010-09-30 07:51:11 +08:00
|
|
|
tlink = cifs_sb_tlink(cifs_sb);
|
|
|
|
if (IS_ERR(tlink))
|
|
|
|
return PTR_ERR(tlink);
|
|
|
|
pTcon = tlink_tcon(tlink);
|
|
|
|
|
2012-06-20 15:21:16 +08:00
|
|
|
xid = get_xid();
|
2021-03-06 06:36:04 +08:00
|
|
|
page = alloc_dentry_path();
|
2006-08-17 03:44:25 +08:00
|
|
|
|
2021-03-06 06:36:04 +08:00
|
|
|
full_path = build_path_from_dentry(direntry, page);
|
|
|
|
if (IS_ERR(full_path)) {
|
|
|
|
rc = PTR_ERR(full_path);
|
2010-09-30 07:51:11 +08:00
|
|
|
goto list_ea_exit;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
/* return dos attributes as pseudo xattr */
|
|
|
|
/* return alt name if available as pseudo attr */
|
|
|
|
|
|
|
|
/* if proc/fs/cifs/streamstoxattr is set then
|
2007-07-07 06:44:50 +08:00
|
|
|
search server for EAs or streams to
|
2005-04-17 06:20:36 +08:00
|
|
|
returns as xattrs */
|
|
|
|
|
2014-01-27 13:53:43 +08:00
|
|
|
if (pTcon->ses->server->ops->query_all_EAs)
|
|
|
|
rc = pTcon->ses->server->ops->query_all_EAs(xid, pTcon,
|
2017-05-13 09:59:10 +08:00
|
|
|
full_path, NULL, data, buf_size, cifs_sb);
|
2010-09-30 07:51:11 +08:00
|
|
|
list_ea_exit:
|
2021-03-06 06:36:04 +08:00
|
|
|
free_dentry_path(page);
|
2012-06-20 15:21:16 +08:00
|
|
|
free_xid(xid);
|
2010-09-30 07:51:11 +08:00
|
|
|
cifs_put_tlink(tlink);
|
2005-04-17 06:20:36 +08:00
|
|
|
return rc;
|
|
|
|
}
|
2016-04-22 18:11:38 +08:00
|
|
|
|
|
|
|
static const struct xattr_handler cifs_user_xattr_handler = {
|
|
|
|
.prefix = XATTR_USER_PREFIX,
|
|
|
|
.flags = XATTR_USER,
|
|
|
|
.get = cifs_xattr_get,
|
|
|
|
.set = cifs_xattr_set,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* os2.* attributes are treated like user.* attributes */
|
|
|
|
static const struct xattr_handler cifs_os2_xattr_handler = {
|
|
|
|
.prefix = XATTR_OS2_PREFIX,
|
|
|
|
.flags = XATTR_USER,
|
|
|
|
.get = cifs_xattr_get,
|
|
|
|
.set = cifs_xattr_set,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct xattr_handler cifs_cifs_acl_xattr_handler = {
|
|
|
|
.name = CIFS_XATTR_CIFS_ACL,
|
|
|
|
.flags = XATTR_CIFS_ACL,
|
|
|
|
.get = cifs_xattr_get,
|
|
|
|
.set = cifs_xattr_set,
|
|
|
|
};
|
|
|
|
|
2018-08-11 07:46:58 +08:00
|
|
|
/*
|
|
|
|
* Although this is just an alias for the above, need to move away from
|
|
|
|
* confusing users and using the 20 year old term 'cifs' when it is no
|
|
|
|
* longer secure and was replaced by SMB2/SMB3 a long time ago, and
|
|
|
|
* SMB3 and later are highly secure.
|
|
|
|
*/
|
|
|
|
static const struct xattr_handler smb3_acl_xattr_handler = {
|
|
|
|
.name = SMB3_XATTR_CIFS_ACL,
|
|
|
|
.flags = XATTR_CIFS_ACL,
|
|
|
|
.get = cifs_xattr_get,
|
|
|
|
.set = cifs_xattr_set,
|
|
|
|
};
|
|
|
|
|
2019-12-20 00:52:50 +08:00
|
|
|
static const struct xattr_handler cifs_cifs_ntsd_xattr_handler = {
|
|
|
|
.name = CIFS_XATTR_CIFS_NTSD,
|
|
|
|
.flags = XATTR_CIFS_NTSD,
|
|
|
|
.get = cifs_xattr_get,
|
|
|
|
.set = cifs_xattr_set,
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Although this is just an alias for the above, need to move away from
|
|
|
|
* confusing users and using the 20 year old term 'cifs' when it is no
|
|
|
|
* longer secure and was replaced by SMB2/SMB3 a long time ago, and
|
|
|
|
* SMB3 and later are highly secure.
|
|
|
|
*/
|
|
|
|
static const struct xattr_handler smb3_ntsd_xattr_handler = {
|
|
|
|
.name = SMB3_XATTR_CIFS_NTSD,
|
|
|
|
.flags = XATTR_CIFS_NTSD,
|
|
|
|
.get = cifs_xattr_get,
|
|
|
|
.set = cifs_xattr_set,
|
|
|
|
};
|
|
|
|
|
2020-12-19 01:30:12 +08:00
|
|
|
static const struct xattr_handler cifs_cifs_ntsd_full_xattr_handler = {
|
|
|
|
.name = CIFS_XATTR_CIFS_NTSD_FULL,
|
|
|
|
.flags = XATTR_CIFS_NTSD_FULL,
|
|
|
|
.get = cifs_xattr_get,
|
|
|
|
.set = cifs_xattr_set,
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Although this is just an alias for the above, need to move away from
|
|
|
|
* confusing users and using the 20 year old term 'cifs' when it is no
|
|
|
|
* longer secure and was replaced by SMB2/SMB3 a long time ago, and
|
|
|
|
* SMB3 and later are highly secure.
|
|
|
|
*/
|
|
|
|
static const struct xattr_handler smb3_ntsd_full_xattr_handler = {
|
|
|
|
.name = SMB3_XATTR_CIFS_NTSD_FULL,
|
|
|
|
.flags = XATTR_CIFS_NTSD_FULL,
|
|
|
|
.get = cifs_xattr_get,
|
|
|
|
.set = cifs_xattr_set,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-04-22 18:11:38 +08:00
|
|
|
static const struct xattr_handler cifs_posix_acl_access_xattr_handler = {
|
|
|
|
.name = XATTR_NAME_POSIX_ACL_ACCESS,
|
|
|
|
.flags = XATTR_ACL_ACCESS,
|
|
|
|
.get = cifs_xattr_get,
|
|
|
|
.set = cifs_xattr_set,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct xattr_handler cifs_posix_acl_default_xattr_handler = {
|
|
|
|
.name = XATTR_NAME_POSIX_ACL_DEFAULT,
|
|
|
|
.flags = XATTR_ACL_DEFAULT,
|
|
|
|
.get = cifs_xattr_get,
|
|
|
|
.set = cifs_xattr_set,
|
|
|
|
};
|
|
|
|
|
|
|
|
const struct xattr_handler *cifs_xattr_handlers[] = {
|
|
|
|
&cifs_user_xattr_handler,
|
|
|
|
&cifs_os2_xattr_handler,
|
|
|
|
&cifs_cifs_acl_xattr_handler,
|
2018-08-11 07:46:58 +08:00
|
|
|
&smb3_acl_xattr_handler, /* alias for above since avoiding "cifs" */
|
2019-12-20 00:52:50 +08:00
|
|
|
&cifs_cifs_ntsd_xattr_handler,
|
|
|
|
&smb3_ntsd_xattr_handler, /* alias for above since avoiding "cifs" */
|
2020-12-19 01:30:12 +08:00
|
|
|
&cifs_cifs_ntsd_full_xattr_handler,
|
|
|
|
&smb3_ntsd_full_xattr_handler, /* alias for above since avoiding "cifs" */
|
2016-04-22 18:11:38 +08:00
|
|
|
&cifs_posix_acl_access_xattr_handler,
|
|
|
|
&cifs_posix_acl_default_xattr_handler,
|
|
|
|
NULL
|
|
|
|
};
|