blob: 159547c8a40bc073ce1fb4ccaf847662b9de0954 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * fs/cifs/xattr.c
3 *
Steve French79a58d12007-07-06 22:44:50 +00004 * Copyright (c) International Business Machines Corp., 2003, 2007
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * Author(s): Steve French (sfrench@us.ibm.com)
6 *
7 * This library is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published
9 * by the Free Software Foundation; either version 2.1 of the License, or
10 * (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
15 * the GNU Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22#include <linux/fs.h>
23#include <linux/posix_acl_xattr.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090024#include <linux/slab.h>
Mimi Zoharf995e742011-08-11 16:00:47 -040025#include <linux/xattr.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include "cifsfs.h"
27#include "cifspdu.h"
28#include "cifsglob.h"
29#include "cifsproto.h"
30#include "cifs_debug.h"
Steve French2baa2682014-09-27 02:19:01 -050031#include "cifs_fs_sb.h"
32#include "cifs_unicode.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
34#define MAX_EA_VALUE_SIZE 65535
35#define CIFS_XATTR_DOS_ATTRIB "user.DosAttrib"
Shirish Pargaonkarfbeba8b2010-11-27 11:37:54 -060036#define CIFS_XATTR_CIFS_ACL "system.cifs_acl"
Mimi Zoharf995e742011-08-11 16:00:47 -040037
Linus Torvalds1da177e2005-04-16 15:20:36 -070038/* BB need to add server (Samba e.g) support for security and trusted prefix */
Steve French50c2f752007-07-13 00:33:32 +000039
Steve French79a58d12007-07-06 22:44:50 +000040int cifs_removexattr(struct dentry *direntry, const char *ea_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -070041{
42 int rc = -EOPNOTSUPP;
43#ifdef CONFIG_CIFS_XATTR
Pavel Shilovsky6d5786a2012-06-20 11:21:16 +040044 unsigned int xid;
Al Viro5fdccfe2016-04-10 17:07:33 -040045 struct cifs_sb_info *cifs_sb = CIFS_SB(direntry->d_sb);
Jeff Layton7ffec372010-09-29 19:51:11 -040046 struct tcon_link *tlink;
Steve French96daf2b2011-05-27 04:34:02 +000047 struct cifs_tcon *pTcon;
Jeff Layton7ffec372010-09-29 19:51:11 -040048 char *full_path = NULL;
Steve French79a58d12007-07-06 22:44:50 +000049
Jeff Layton7ffec372010-09-29 19:51:11 -040050 tlink = cifs_sb_tlink(cifs_sb);
51 if (IS_ERR(tlink))
52 return PTR_ERR(tlink);
53 pTcon = tlink_tcon(tlink);
54
Pavel Shilovsky6d5786a2012-06-20 11:21:16 +040055 xid = get_xid();
Steve French79a58d12007-07-06 22:44:50 +000056
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 full_path = build_path_from_dentry(direntry);
Steve French79a58d12007-07-06 22:44:50 +000058 if (full_path == NULL) {
Suresh Jayaraman0f3bc092009-06-25 18:12:34 +053059 rc = -ENOMEM;
Jeff Layton7ffec372010-09-29 19:51:11 -040060 goto remove_ea_exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 }
Steve French79a58d12007-07-06 22:44:50 +000062 if (ea_name == NULL) {
Joe Perchesf96637b2013-05-04 22:12:25 -050063 cifs_dbg(FYI, "Null xattr names not supported\n");
Mimi Zoharf995e742011-08-11 16:00:47 -040064 } else if (strncmp(ea_name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)
65 && (strncmp(ea_name, XATTR_OS2_PREFIX, XATTR_OS2_PREFIX_LEN))) {
Joe Perchesf96637b2013-05-04 22:12:25 -050066 cifs_dbg(FYI,
67 "illegal xattr request %s (only user namespace supported)\n",
68 ea_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 /* BB what if no namespace prefix? */
70 /* Should we just pass them to server, except for
71 system and perhaps security prefixes? */
72 } else {
Steve French79a58d12007-07-06 22:44:50 +000073 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 goto remove_ea_exit;
75
Mimi Zoharf995e742011-08-11 16:00:47 -040076 ea_name += XATTR_USER_PREFIX_LEN; /* skip past user. prefix */
Steve French666753c2014-01-26 23:53:43 -060077 if (pTcon->ses->server->ops->set_EA)
78 rc = pTcon->ses->server->ops->set_EA(xid, pTcon,
79 full_path, ea_name, NULL, (__u16)0,
Steve French2baa2682014-09-27 02:19:01 -050080 cifs_sb->local_nls, cifs_remap(cifs_sb));
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 }
82remove_ea_exit:
Jesper Juhlf99d49a2005-11-07 01:01:34 -080083 kfree(full_path);
Pavel Shilovsky6d5786a2012-06-20 11:21:16 +040084 free_xid(xid);
Jeff Layton7ffec372010-09-29 19:51:11 -040085 cifs_put_tlink(tlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -070086#endif
87 return rc;
88}
89
Steve French79a58d12007-07-06 22:44:50 +000090int cifs_setxattr(struct dentry *direntry, const char *ea_name,
91 const void *ea_value, size_t value_size, int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -070092{
93 int rc = -EOPNOTSUPP;
94#ifdef CONFIG_CIFS_XATTR
Pavel Shilovsky6d5786a2012-06-20 11:21:16 +040095 unsigned int xid;
Al Viro5fdccfe2016-04-10 17:07:33 -040096 struct super_block *sb = direntry->d_sb;
97 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
Jeff Layton7ffec372010-09-29 19:51:11 -040098 struct tcon_link *tlink;
Steve French96daf2b2011-05-27 04:34:02 +000099 struct cifs_tcon *pTcon;
Steve French79a58d12007-07-06 22:44:50 +0000100 char *full_path;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
Jeff Layton7ffec372010-09-29 19:51:11 -0400102 tlink = cifs_sb_tlink(cifs_sb);
103 if (IS_ERR(tlink))
104 return PTR_ERR(tlink);
105 pTcon = tlink_tcon(tlink);
106
Pavel Shilovsky6d5786a2012-06-20 11:21:16 +0400107 xid = get_xid();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 full_path = build_path_from_dentry(direntry);
Steve French79a58d12007-07-06 22:44:50 +0000110 if (full_path == NULL) {
Suresh Jayaraman0f3bc092009-06-25 18:12:34 +0530111 rc = -ENOMEM;
Jeff Layton7ffec372010-09-29 19:51:11 -0400112 goto set_ea_exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 }
114 /* return dos attributes as pseudo xattr */
115 /* return alt name if available as pseudo attr */
116
117 /* if proc/fs/cifs/streamstoxattr is set then
Steve French79a58d12007-07-06 22:44:50 +0000118 search server for EAs or streams to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 returns as xattrs */
Steve French79a58d12007-07-06 22:44:50 +0000120 if (value_size > MAX_EA_VALUE_SIZE) {
Joe Perchesf96637b2013-05-04 22:12:25 -0500121 cifs_dbg(FYI, "size of EA value too large\n");
Jeff Layton7ffec372010-09-29 19:51:11 -0400122 rc = -EOPNOTSUPP;
123 goto set_ea_exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 }
125
Steve French79a58d12007-07-06 22:44:50 +0000126 if (ea_name == NULL) {
Joe Perchesf96637b2013-05-04 22:12:25 -0500127 cifs_dbg(FYI, "Null xattr names not supported\n");
Mimi Zoharf995e742011-08-11 16:00:47 -0400128 } else if (strncmp(ea_name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)
129 == 0) {
Steve French79a58d12007-07-06 22:44:50 +0000130 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 goto set_ea_exit;
Steve Frenchad7a2922008-02-07 23:25:02 +0000132 if (strncmp(ea_name, CIFS_XATTR_DOS_ATTRIB, 14) == 0)
Joe Perchesf96637b2013-05-04 22:12:25 -0500133 cifs_dbg(FYI, "attempt to set cifs inode metadata\n");
Steve Frenchad7a2922008-02-07 23:25:02 +0000134
Mimi Zoharf995e742011-08-11 16:00:47 -0400135 ea_name += XATTR_USER_PREFIX_LEN; /* skip past user. prefix */
Steve French666753c2014-01-26 23:53:43 -0600136 if (pTcon->ses->server->ops->set_EA)
137 rc = pTcon->ses->server->ops->set_EA(xid, pTcon,
138 full_path, ea_name, ea_value, (__u16)value_size,
Steve French2baa2682014-09-27 02:19:01 -0500139 cifs_sb->local_nls, cifs_remap(cifs_sb));
Mimi Zoharf995e742011-08-11 16:00:47 -0400140 } else if (strncmp(ea_name, XATTR_OS2_PREFIX, XATTR_OS2_PREFIX_LEN)
141 == 0) {
Steve French79a58d12007-07-06 22:44:50 +0000142 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 goto set_ea_exit;
144
Mimi Zoharf995e742011-08-11 16:00:47 -0400145 ea_name += XATTR_OS2_PREFIX_LEN; /* skip past os2. prefix */
Steve French666753c2014-01-26 23:53:43 -0600146 if (pTcon->ses->server->ops->set_EA)
147 rc = pTcon->ses->server->ops->set_EA(xid, pTcon,
148 full_path, ea_name, ea_value, (__u16)value_size,
Steve French2baa2682014-09-27 02:19:01 -0500149 cifs_sb->local_nls, cifs_remap(cifs_sb));
Steve Frenchb73b9a42011-04-19 18:27:10 +0000150 } else if (strncmp(ea_name, CIFS_XATTR_CIFS_ACL,
151 strlen(CIFS_XATTR_CIFS_ACL)) == 0) {
Santosh Nayakb0f8ef22012-03-02 11:47:26 +0530152#ifdef CONFIG_CIFS_ACL
153 struct cifs_ntsd *pacl;
Steve Frenchb73b9a42011-04-19 18:27:10 +0000154 pacl = kmalloc(value_size, GFP_KERNEL);
155 if (!pacl) {
Steve Frenchb73b9a42011-04-19 18:27:10 +0000156 rc = -ENOMEM;
157 } else {
Steve Frenchb73b9a42011-04-19 18:27:10 +0000158 memcpy(pacl, ea_value, value_size);
Steve French83e3bc22014-02-02 23:31:47 -0600159 if (pTcon->ses->server->ops->set_acl)
160 rc = pTcon->ses->server->ops->set_acl(pacl,
David Howells2b0143b2015-03-17 22:25:59 +0000161 value_size, d_inode(direntry),
Steve French83e3bc22014-02-02 23:31:47 -0600162 full_path, CIFS_ACL_DACL);
163 else
164 rc = -EOPNOTSUPP;
Steve Frenchb73b9a42011-04-19 18:27:10 +0000165 if (rc == 0) /* force revalidate of the inode */
David Howells2b0143b2015-03-17 22:25:59 +0000166 CIFS_I(d_inode(direntry))->time = 0;
Steve Frenchb73b9a42011-04-19 18:27:10 +0000167 kfree(pacl);
Santosh Nayakb0f8ef22012-03-02 11:47:26 +0530168 }
Steve Frenchb73b9a42011-04-19 18:27:10 +0000169#else
Joe Perchesf96637b2013-05-04 22:12:25 -0500170 cifs_dbg(FYI, "Set CIFS ACL not supported yet\n");
Steve Frenchb73b9a42011-04-19 18:27:10 +0000171#endif /* CONFIG_CIFS_ACL */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 } else {
Steve French79a58d12007-07-06 22:44:50 +0000173 int temp;
Andreas Gruenbacher97d79292015-12-02 14:44:35 +0100174 temp = strncmp(ea_name, XATTR_NAME_POSIX_ACL_ACCESS,
175 strlen(XATTR_NAME_POSIX_ACL_ACCESS));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 if (temp == 0) {
177#ifdef CONFIG_CIFS_POSIX
Steve French79a58d12007-07-06 22:44:50 +0000178 if (sb->s_flags & MS_POSIXACL)
179 rc = CIFSSMBSetPosixACL(xid, pTcon, full_path,
180 ea_value, (const int)value_size,
181 ACL_TYPE_ACCESS, cifs_sb->local_nls,
Steve French2baa2682014-09-27 02:19:01 -0500182 cifs_remap(cifs_sb));
Joe Perchesf96637b2013-05-04 22:12:25 -0500183 cifs_dbg(FYI, "set POSIX ACL rc %d\n", rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184#else
Joe Perchesf96637b2013-05-04 22:12:25 -0500185 cifs_dbg(FYI, "set POSIX ACL not supported\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186#endif
Andreas Gruenbacher97d79292015-12-02 14:44:35 +0100187 } else if (strncmp(ea_name, XATTR_NAME_POSIX_ACL_DEFAULT,
188 strlen(XATTR_NAME_POSIX_ACL_DEFAULT)) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189#ifdef CONFIG_CIFS_POSIX
Steve French79a58d12007-07-06 22:44:50 +0000190 if (sb->s_flags & MS_POSIXACL)
191 rc = CIFSSMBSetPosixACL(xid, pTcon, full_path,
192 ea_value, (const int)value_size,
Steve French737b7582005-04-28 22:41:06 -0700193 ACL_TYPE_DEFAULT, cifs_sb->local_nls,
Steve French2baa2682014-09-27 02:19:01 -0500194 cifs_remap(cifs_sb));
Joe Perchesf96637b2013-05-04 22:12:25 -0500195 cifs_dbg(FYI, "set POSIX default ACL rc %d\n", rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196#else
Joe Perchesf96637b2013-05-04 22:12:25 -0500197 cifs_dbg(FYI, "set default POSIX ACL not supported\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198#endif
199 } else {
Joe Perchesf96637b2013-05-04 22:12:25 -0500200 cifs_dbg(FYI, "illegal xattr request %s (only user namespace supported)\n",
201 ea_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 /* BB what if no namespace prefix? */
Steve French79a58d12007-07-06 22:44:50 +0000203 /* Should we just pass them to server, except for
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 system and perhaps security prefixes? */
205 }
206 }
207
208set_ea_exit:
Jesper Juhlf99d49a2005-11-07 01:01:34 -0800209 kfree(full_path);
Pavel Shilovsky6d5786a2012-06-20 11:21:16 +0400210 free_xid(xid);
Jeff Layton7ffec372010-09-29 19:51:11 -0400211 cifs_put_tlink(tlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212#endif
213 return rc;
214}
215
Steve French79a58d12007-07-06 22:44:50 +0000216ssize_t cifs_getxattr(struct dentry *direntry, const char *ea_name,
217 void *ea_value, size_t buf_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218{
219 ssize_t rc = -EOPNOTSUPP;
220#ifdef CONFIG_CIFS_XATTR
Pavel Shilovsky6d5786a2012-06-20 11:21:16 +0400221 unsigned int xid;
Al Viro5fdccfe2016-04-10 17:07:33 -0400222 struct super_block *sb = direntry->d_sb;
223 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
Jeff Layton7ffec372010-09-29 19:51:11 -0400224 struct tcon_link *tlink;
Steve French96daf2b2011-05-27 04:34:02 +0000225 struct cifs_tcon *pTcon;
Steve French79a58d12007-07-06 22:44:50 +0000226 char *full_path;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227
Jeff Layton7ffec372010-09-29 19:51:11 -0400228 tlink = cifs_sb_tlink(cifs_sb);
229 if (IS_ERR(tlink))
230 return PTR_ERR(tlink);
231 pTcon = tlink_tcon(tlink);
232
Pavel Shilovsky6d5786a2012-06-20 11:21:16 +0400233 xid = get_xid();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 full_path = build_path_from_dentry(direntry);
Steve French79a58d12007-07-06 22:44:50 +0000236 if (full_path == NULL) {
Suresh Jayaraman0f3bc092009-06-25 18:12:34 +0530237 rc = -ENOMEM;
Jeff Layton7ffec372010-09-29 19:51:11 -0400238 goto get_ea_exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 }
240 /* return dos attributes as pseudo xattr */
241 /* return alt name if available as pseudo attr */
Steve French79a58d12007-07-06 22:44:50 +0000242 if (ea_name == NULL) {
Joe Perchesf96637b2013-05-04 22:12:25 -0500243 cifs_dbg(FYI, "Null xattr names not supported\n");
Mimi Zoharf995e742011-08-11 16:00:47 -0400244 } else if (strncmp(ea_name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)
245 == 0) {
Steve French79a58d12007-07-06 22:44:50 +0000246 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 goto get_ea_exit;
248
Steve French79a58d12007-07-06 22:44:50 +0000249 if (strncmp(ea_name, CIFS_XATTR_DOS_ATTRIB, 14) == 0) {
Joe Perchesf96637b2013-05-04 22:12:25 -0500250 cifs_dbg(FYI, "attempt to query cifs inode metadata\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 /* revalidate/getattr then populate from inode */
252 } /* BB add else when above is implemented */
Mimi Zoharf995e742011-08-11 16:00:47 -0400253 ea_name += XATTR_USER_PREFIX_LEN; /* skip past user. prefix */
Steve French666753c2014-01-26 23:53:43 -0600254 if (pTcon->ses->server->ops->query_all_EAs)
255 rc = pTcon->ses->server->ops->query_all_EAs(xid, pTcon,
256 full_path, ea_name, ea_value, buf_size,
Steve French2baa2682014-09-27 02:19:01 -0500257 cifs_sb->local_nls, cifs_remap(cifs_sb));
Mimi Zoharf995e742011-08-11 16:00:47 -0400258 } else if (strncmp(ea_name, XATTR_OS2_PREFIX, XATTR_OS2_PREFIX_LEN) == 0) {
Steve French79a58d12007-07-06 22:44:50 +0000259 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 goto get_ea_exit;
261
Mimi Zoharf995e742011-08-11 16:00:47 -0400262 ea_name += XATTR_OS2_PREFIX_LEN; /* skip past os2. prefix */
Steve French666753c2014-01-26 23:53:43 -0600263 if (pTcon->ses->server->ops->query_all_EAs)
264 rc = pTcon->ses->server->ops->query_all_EAs(xid, pTcon,
265 full_path, ea_name, ea_value, buf_size,
Steve French2baa2682014-09-27 02:19:01 -0500266 cifs_sb->local_nls, cifs_remap(cifs_sb));
Andreas Gruenbacher97d79292015-12-02 14:44:35 +0100267 } else if (strncmp(ea_name, XATTR_NAME_POSIX_ACL_ACCESS,
268 strlen(XATTR_NAME_POSIX_ACL_ACCESS)) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269#ifdef CONFIG_CIFS_POSIX
Steve French79a58d12007-07-06 22:44:50 +0000270 if (sb->s_flags & MS_POSIXACL)
Steve French1da0c782005-04-28 22:41:04 -0700271 rc = CIFSSMBGetPosixACL(xid, pTcon, full_path,
Steve French79a58d12007-07-06 22:44:50 +0000272 ea_value, buf_size, ACL_TYPE_ACCESS,
Steve French737b7582005-04-28 22:41:06 -0700273 cifs_sb->local_nls,
Steve French2baa2682014-09-27 02:19:01 -0500274 cifs_remap(cifs_sb));
Steve French79a58d12007-07-06 22:44:50 +0000275#else
Joe Perchesf96637b2013-05-04 22:12:25 -0500276 cifs_dbg(FYI, "Query POSIX ACL not supported yet\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277#endif /* CONFIG_CIFS_POSIX */
Andreas Gruenbacher97d79292015-12-02 14:44:35 +0100278 } else if (strncmp(ea_name, XATTR_NAME_POSIX_ACL_DEFAULT,
279 strlen(XATTR_NAME_POSIX_ACL_DEFAULT)) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280#ifdef CONFIG_CIFS_POSIX
Steve French79a58d12007-07-06 22:44:50 +0000281 if (sb->s_flags & MS_POSIXACL)
Steve French1da0c782005-04-28 22:41:04 -0700282 rc = CIFSSMBGetPosixACL(xid, pTcon, full_path,
Steve French79a58d12007-07-06 22:44:50 +0000283 ea_value, buf_size, ACL_TYPE_DEFAULT,
Steve French737b7582005-04-28 22:41:06 -0700284 cifs_sb->local_nls,
Steve French2baa2682014-09-27 02:19:01 -0500285 cifs_remap(cifs_sb));
Steve French79a58d12007-07-06 22:44:50 +0000286#else
Joe Perchesf96637b2013-05-04 22:12:25 -0500287 cifs_dbg(FYI, "Query POSIX default ACL not supported yet\n");
Shirish Pargaonkarfbeba8b2010-11-27 11:37:54 -0600288#endif /* CONFIG_CIFS_POSIX */
289 } else if (strncmp(ea_name, CIFS_XATTR_CIFS_ACL,
290 strlen(CIFS_XATTR_CIFS_ACL)) == 0) {
291#ifdef CONFIG_CIFS_ACL
292 u32 acllen;
293 struct cifs_ntsd *pacl;
294
Steve French83e3bc22014-02-02 23:31:47 -0600295 if (pTcon->ses->server->ops->get_acl == NULL)
296 goto get_ea_exit; /* rc already EOPNOTSUPP */
297
298 pacl = pTcon->ses->server->ops->get_acl(cifs_sb,
David Howells2b0143b2015-03-17 22:25:59 +0000299 d_inode(direntry), full_path, &acllen);
Shirish Pargaonkarfbeba8b2010-11-27 11:37:54 -0600300 if (IS_ERR(pacl)) {
301 rc = PTR_ERR(pacl);
Joe Perchesf96637b2013-05-04 22:12:25 -0500302 cifs_dbg(VFS, "%s: error %zd getting sec desc\n",
303 __func__, rc);
Shirish Pargaonkarfbeba8b2010-11-27 11:37:54 -0600304 } else {
305 if (ea_value) {
306 if (acllen > buf_size)
307 acllen = -ERANGE;
308 else
309 memcpy(ea_value, pacl, acllen);
310 }
311 rc = acllen;
312 kfree(pacl);
313 }
314#else
Joe Perchesf96637b2013-05-04 22:12:25 -0500315 cifs_dbg(FYI, "Query CIFS ACL not supported yet\n");
Shirish Pargaonkarfbeba8b2010-11-27 11:37:54 -0600316#endif /* CONFIG_CIFS_ACL */
Steve French79a58d12007-07-06 22:44:50 +0000317 } else if (strncmp(ea_name,
Mimi Zoharf995e742011-08-11 16:00:47 -0400318 XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN) == 0) {
Joe Perchesf96637b2013-05-04 22:12:25 -0500319 cifs_dbg(FYI, "Trusted xattr namespace not supported yet\n");
Steve French79a58d12007-07-06 22:44:50 +0000320 } else if (strncmp(ea_name,
Mimi Zoharf995e742011-08-11 16:00:47 -0400321 XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN) == 0) {
Joe Perchesf96637b2013-05-04 22:12:25 -0500322 cifs_dbg(FYI, "Security xattr namespace not supported yet\n");
Steve Frenchad7a2922008-02-07 23:25:02 +0000323 } else
Joe Perchesf96637b2013-05-04 22:12:25 -0500324 cifs_dbg(FYI,
325 "illegal xattr request %s (only user namespace supported)\n",
326 ea_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327
Steve French79a58d12007-07-06 22:44:50 +0000328 /* We could add an additional check for streams ie
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 if proc/fs/cifs/streamstoxattr is set then
Steve French79a58d12007-07-06 22:44:50 +0000330 search server for EAs or streams to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 returns as xattrs */
332
Steve French79a58d12007-07-06 22:44:50 +0000333 if (rc == -EINVAL)
334 rc = -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335
336get_ea_exit:
Jesper Juhlf99d49a2005-11-07 01:01:34 -0800337 kfree(full_path);
Pavel Shilovsky6d5786a2012-06-20 11:21:16 +0400338 free_xid(xid);
Jeff Layton7ffec372010-09-29 19:51:11 -0400339 cifs_put_tlink(tlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340#endif
341 return rc;
342}
343
Steve French79a58d12007-07-06 22:44:50 +0000344ssize_t cifs_listxattr(struct dentry *direntry, char *data, size_t buf_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345{
346 ssize_t rc = -EOPNOTSUPP;
347#ifdef CONFIG_CIFS_XATTR
Pavel Shilovsky6d5786a2012-06-20 11:21:16 +0400348 unsigned int xid;
Al Viro5fdccfe2016-04-10 17:07:33 -0400349 struct cifs_sb_info *cifs_sb = CIFS_SB(direntry->d_sb);
Jeff Layton7ffec372010-09-29 19:51:11 -0400350 struct tcon_link *tlink;
Steve French96daf2b2011-05-27 04:34:02 +0000351 struct cifs_tcon *pTcon;
Steve French79a58d12007-07-06 22:44:50 +0000352 char *full_path;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353
Steve French79a58d12007-07-06 22:44:50 +0000354 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
Steve Frenchea4c07d2006-08-16 19:44:25 +0000355 return -EOPNOTSUPP;
356
Jeff Layton7ffec372010-09-29 19:51:11 -0400357 tlink = cifs_sb_tlink(cifs_sb);
358 if (IS_ERR(tlink))
359 return PTR_ERR(tlink);
360 pTcon = tlink_tcon(tlink);
361
Pavel Shilovsky6d5786a2012-06-20 11:21:16 +0400362 xid = get_xid();
Steve Frenchea4c07d2006-08-16 19:44:25 +0000363
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 full_path = build_path_from_dentry(direntry);
Steve French79a58d12007-07-06 22:44:50 +0000365 if (full_path == NULL) {
Suresh Jayaraman0f3bc092009-06-25 18:12:34 +0530366 rc = -ENOMEM;
Jeff Layton7ffec372010-09-29 19:51:11 -0400367 goto list_ea_exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 }
369 /* return dos attributes as pseudo xattr */
370 /* return alt name if available as pseudo attr */
371
372 /* if proc/fs/cifs/streamstoxattr is set then
Steve French79a58d12007-07-06 22:44:50 +0000373 search server for EAs or streams to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 returns as xattrs */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375
Steve French666753c2014-01-26 23:53:43 -0600376 if (pTcon->ses->server->ops->query_all_EAs)
377 rc = pTcon->ses->server->ops->query_all_EAs(xid, pTcon,
378 full_path, NULL, data, buf_size,
Steve French2baa2682014-09-27 02:19:01 -0500379 cifs_sb->local_nls, cifs_remap(cifs_sb));
Jeff Layton7ffec372010-09-29 19:51:11 -0400380list_ea_exit:
Jesper Juhlf99d49a2005-11-07 01:01:34 -0800381 kfree(full_path);
Pavel Shilovsky6d5786a2012-06-20 11:21:16 +0400382 free_xid(xid);
Jeff Layton7ffec372010-09-29 19:51:11 -0400383 cifs_put_tlink(tlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384#endif
385 return rc;
386}