blob: 95c43bb203353a65974a6cf5b24a0fe02c3c5c86 [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"
31
32#define MAX_EA_VALUE_SIZE 65535
33#define CIFS_XATTR_DOS_ATTRIB "user.DosAttrib"
Shirish Pargaonkarfbeba8b2010-11-27 11:37:54 -060034#define CIFS_XATTR_CIFS_ACL "system.cifs_acl"
Mimi Zoharf995e742011-08-11 16:00:47 -040035
Linus Torvalds1da177e2005-04-16 15:20:36 -070036/* BB need to add server (Samba e.g) support for security and trusted prefix */
Steve French50c2f752007-07-13 00:33:32 +000037
Steve French79a58d12007-07-06 22:44:50 +000038int cifs_removexattr(struct dentry *direntry, const char *ea_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -070039{
40 int rc = -EOPNOTSUPP;
41#ifdef CONFIG_CIFS_XATTR
Pavel Shilovsky6d5786a2012-06-20 11:21:16 +040042 unsigned int xid;
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 struct cifs_sb_info *cifs_sb;
Jeff Layton7ffec372010-09-29 19:51:11 -040044 struct tcon_link *tlink;
Steve French96daf2b2011-05-27 04:34:02 +000045 struct cifs_tcon *pTcon;
Steve French79a58d12007-07-06 22:44:50 +000046 struct super_block *sb;
Jeff Layton7ffec372010-09-29 19:51:11 -040047 char *full_path = NULL;
Steve French79a58d12007-07-06 22:44:50 +000048
49 if (direntry == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 return -EIO;
Steve French79a58d12007-07-06 22:44:50 +000051 if (direntry->d_inode == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 return -EIO;
53 sb = direntry->d_inode->i_sb;
Steve French79a58d12007-07-06 22:44:50 +000054 if (sb == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 return -EIO;
Steve French79a58d12007-07-06 22:44:50 +000056
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 cifs_sb = CIFS_SB(sb);
Jeff Layton7ffec372010-09-29 19:51:11 -040058 tlink = cifs_sb_tlink(cifs_sb);
59 if (IS_ERR(tlink))
60 return PTR_ERR(tlink);
61 pTcon = tlink_tcon(tlink);
62
Pavel Shilovsky6d5786a2012-06-20 11:21:16 +040063 xid = get_xid();
Steve French79a58d12007-07-06 22:44:50 +000064
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 full_path = build_path_from_dentry(direntry);
Steve French79a58d12007-07-06 22:44:50 +000066 if (full_path == NULL) {
Suresh Jayaraman0f3bc092009-06-25 18:12:34 +053067 rc = -ENOMEM;
Jeff Layton7ffec372010-09-29 19:51:11 -040068 goto remove_ea_exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 }
Steve French79a58d12007-07-06 22:44:50 +000070 if (ea_name == NULL) {
Joe Perchesf96637b2013-05-04 22:12:25 -050071 cifs_dbg(FYI, "Null xattr names not supported\n");
Mimi Zoharf995e742011-08-11 16:00:47 -040072 } else if (strncmp(ea_name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)
73 && (strncmp(ea_name, XATTR_OS2_PREFIX, XATTR_OS2_PREFIX_LEN))) {
Joe Perchesf96637b2013-05-04 22:12:25 -050074 cifs_dbg(FYI,
75 "illegal xattr request %s (only user namespace supported)\n",
76 ea_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 /* BB what if no namespace prefix? */
78 /* Should we just pass them to server, except for
79 system and perhaps security prefixes? */
80 } else {
Steve French79a58d12007-07-06 22:44:50 +000081 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 goto remove_ea_exit;
83
Mimi Zoharf995e742011-08-11 16:00:47 -040084 ea_name += XATTR_USER_PREFIX_LEN; /* skip past user. prefix */
Steve French666753c2014-01-26 23:53:43 -060085 if (pTcon->ses->server->ops->set_EA)
86 rc = pTcon->ses->server->ops->set_EA(xid, pTcon,
87 full_path, ea_name, NULL, (__u16)0,
88 cifs_sb->local_nls, cifs_sb->mnt_cifs_flags &
89 CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 }
91remove_ea_exit:
Jesper Juhlf99d49a2005-11-07 01:01:34 -080092 kfree(full_path);
Pavel Shilovsky6d5786a2012-06-20 11:21:16 +040093 free_xid(xid);
Jeff Layton7ffec372010-09-29 19:51:11 -040094 cifs_put_tlink(tlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -070095#endif
96 return rc;
97}
98
Steve French79a58d12007-07-06 22:44:50 +000099int cifs_setxattr(struct dentry *direntry, const char *ea_name,
100 const void *ea_value, size_t value_size, int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101{
102 int rc = -EOPNOTSUPP;
103#ifdef CONFIG_CIFS_XATTR
Pavel Shilovsky6d5786a2012-06-20 11:21:16 +0400104 unsigned int xid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 struct cifs_sb_info *cifs_sb;
Jeff Layton7ffec372010-09-29 19:51:11 -0400106 struct tcon_link *tlink;
Steve French96daf2b2011-05-27 04:34:02 +0000107 struct cifs_tcon *pTcon;
Steve French79a58d12007-07-06 22:44:50 +0000108 struct super_block *sb;
109 char *full_path;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
Steve French79a58d12007-07-06 22:44:50 +0000111 if (direntry == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 return -EIO;
Steve French79a58d12007-07-06 22:44:50 +0000113 if (direntry->d_inode == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 return -EIO;
115 sb = direntry->d_inode->i_sb;
Steve French79a58d12007-07-06 22:44:50 +0000116 if (sb == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
119 cifs_sb = CIFS_SB(sb);
Jeff Layton7ffec372010-09-29 19:51:11 -0400120 tlink = cifs_sb_tlink(cifs_sb);
121 if (IS_ERR(tlink))
122 return PTR_ERR(tlink);
123 pTcon = tlink_tcon(tlink);
124
Pavel Shilovsky6d5786a2012-06-20 11:21:16 +0400125 xid = get_xid();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 full_path = build_path_from_dentry(direntry);
Steve French79a58d12007-07-06 22:44:50 +0000128 if (full_path == NULL) {
Suresh Jayaraman0f3bc092009-06-25 18:12:34 +0530129 rc = -ENOMEM;
Jeff Layton7ffec372010-09-29 19:51:11 -0400130 goto set_ea_exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 }
132 /* return dos attributes as pseudo xattr */
133 /* return alt name if available as pseudo attr */
134
135 /* if proc/fs/cifs/streamstoxattr is set then
Steve French79a58d12007-07-06 22:44:50 +0000136 search server for EAs or streams to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 returns as xattrs */
Steve French79a58d12007-07-06 22:44:50 +0000138 if (value_size > MAX_EA_VALUE_SIZE) {
Joe Perchesf96637b2013-05-04 22:12:25 -0500139 cifs_dbg(FYI, "size of EA value too large\n");
Jeff Layton7ffec372010-09-29 19:51:11 -0400140 rc = -EOPNOTSUPP;
141 goto set_ea_exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 }
143
Steve French79a58d12007-07-06 22:44:50 +0000144 if (ea_name == NULL) {
Joe Perchesf96637b2013-05-04 22:12:25 -0500145 cifs_dbg(FYI, "Null xattr names not supported\n");
Mimi Zoharf995e742011-08-11 16:00:47 -0400146 } else if (strncmp(ea_name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)
147 == 0) {
Steve French79a58d12007-07-06 22:44:50 +0000148 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 goto set_ea_exit;
Steve Frenchad7a2922008-02-07 23:25:02 +0000150 if (strncmp(ea_name, CIFS_XATTR_DOS_ATTRIB, 14) == 0)
Joe Perchesf96637b2013-05-04 22:12:25 -0500151 cifs_dbg(FYI, "attempt to set cifs inode metadata\n");
Steve Frenchad7a2922008-02-07 23:25:02 +0000152
Mimi Zoharf995e742011-08-11 16:00:47 -0400153 ea_name += XATTR_USER_PREFIX_LEN; /* skip past user. prefix */
Steve French666753c2014-01-26 23:53:43 -0600154 if (pTcon->ses->server->ops->set_EA)
155 rc = pTcon->ses->server->ops->set_EA(xid, pTcon,
156 full_path, ea_name, ea_value, (__u16)value_size,
157 cifs_sb->local_nls, cifs_sb->mnt_cifs_flags &
158 CIFS_MOUNT_MAP_SPECIAL_CHR);
Mimi Zoharf995e742011-08-11 16:00:47 -0400159 } else if (strncmp(ea_name, XATTR_OS2_PREFIX, XATTR_OS2_PREFIX_LEN)
160 == 0) {
Steve French79a58d12007-07-06 22:44:50 +0000161 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 goto set_ea_exit;
163
Mimi Zoharf995e742011-08-11 16:00:47 -0400164 ea_name += XATTR_OS2_PREFIX_LEN; /* skip past os2. prefix */
Steve French666753c2014-01-26 23:53:43 -0600165 if (pTcon->ses->server->ops->set_EA)
166 rc = pTcon->ses->server->ops->set_EA(xid, pTcon,
167 full_path, ea_name, ea_value, (__u16)value_size,
168 cifs_sb->local_nls, cifs_sb->mnt_cifs_flags &
169 CIFS_MOUNT_MAP_SPECIAL_CHR);
Steve Frenchb73b9a42011-04-19 18:27:10 +0000170 } else if (strncmp(ea_name, CIFS_XATTR_CIFS_ACL,
171 strlen(CIFS_XATTR_CIFS_ACL)) == 0) {
Santosh Nayakb0f8ef22012-03-02 11:47:26 +0530172#ifdef CONFIG_CIFS_ACL
173 struct cifs_ntsd *pacl;
Steve Frenchb73b9a42011-04-19 18:27:10 +0000174 pacl = kmalloc(value_size, GFP_KERNEL);
175 if (!pacl) {
Steve Frenchb73b9a42011-04-19 18:27:10 +0000176 rc = -ENOMEM;
177 } else {
Steve Frenchb73b9a42011-04-19 18:27:10 +0000178 memcpy(pacl, ea_value, value_size);
179 rc = set_cifs_acl(pacl, value_size,
Shirish Pargaonkara5ff3762011-10-13 10:26:03 -0500180 direntry->d_inode, full_path, CIFS_ACL_DACL);
Steve Frenchb73b9a42011-04-19 18:27:10 +0000181 if (rc == 0) /* force revalidate of the inode */
182 CIFS_I(direntry->d_inode)->time = 0;
183 kfree(pacl);
Santosh Nayakb0f8ef22012-03-02 11:47:26 +0530184 }
Steve Frenchb73b9a42011-04-19 18:27:10 +0000185#else
Joe Perchesf96637b2013-05-04 22:12:25 -0500186 cifs_dbg(FYI, "Set CIFS ACL not supported yet\n");
Steve Frenchb73b9a42011-04-19 18:27:10 +0000187#endif /* CONFIG_CIFS_ACL */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 } else {
Steve French79a58d12007-07-06 22:44:50 +0000189 int temp;
190 temp = strncmp(ea_name, POSIX_ACL_XATTR_ACCESS,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 strlen(POSIX_ACL_XATTR_ACCESS));
192 if (temp == 0) {
193#ifdef CONFIG_CIFS_POSIX
Steve French79a58d12007-07-06 22:44:50 +0000194 if (sb->s_flags & MS_POSIXACL)
195 rc = CIFSSMBSetPosixACL(xid, pTcon, full_path,
196 ea_value, (const int)value_size,
197 ACL_TYPE_ACCESS, cifs_sb->local_nls,
198 cifs_sb->mnt_cifs_flags &
Steve French737b7582005-04-28 22:41:06 -0700199 CIFS_MOUNT_MAP_SPECIAL_CHR);
Joe Perchesf96637b2013-05-04 22:12:25 -0500200 cifs_dbg(FYI, "set POSIX ACL rc %d\n", rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201#else
Joe Perchesf96637b2013-05-04 22:12:25 -0500202 cifs_dbg(FYI, "set POSIX ACL not supported\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203#endif
Steve French79a58d12007-07-06 22:44:50 +0000204 } else if (strncmp(ea_name, POSIX_ACL_XATTR_DEFAULT,
205 strlen(POSIX_ACL_XATTR_DEFAULT)) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206#ifdef CONFIG_CIFS_POSIX
Steve French79a58d12007-07-06 22:44:50 +0000207 if (sb->s_flags & MS_POSIXACL)
208 rc = CIFSSMBSetPosixACL(xid, pTcon, full_path,
209 ea_value, (const int)value_size,
Steve French737b7582005-04-28 22:41:06 -0700210 ACL_TYPE_DEFAULT, cifs_sb->local_nls,
Steve French79a58d12007-07-06 22:44:50 +0000211 cifs_sb->mnt_cifs_flags &
Steve French737b7582005-04-28 22:41:06 -0700212 CIFS_MOUNT_MAP_SPECIAL_CHR);
Joe Perchesf96637b2013-05-04 22:12:25 -0500213 cifs_dbg(FYI, "set POSIX default ACL rc %d\n", rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214#else
Joe Perchesf96637b2013-05-04 22:12:25 -0500215 cifs_dbg(FYI, "set default POSIX ACL not supported\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216#endif
217 } else {
Joe Perchesf96637b2013-05-04 22:12:25 -0500218 cifs_dbg(FYI, "illegal xattr request %s (only user namespace supported)\n",
219 ea_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 /* BB what if no namespace prefix? */
Steve French79a58d12007-07-06 22:44:50 +0000221 /* Should we just pass them to server, except for
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 system and perhaps security prefixes? */
223 }
224 }
225
226set_ea_exit:
Jesper Juhlf99d49a2005-11-07 01:01:34 -0800227 kfree(full_path);
Pavel Shilovsky6d5786a2012-06-20 11:21:16 +0400228 free_xid(xid);
Jeff Layton7ffec372010-09-29 19:51:11 -0400229 cifs_put_tlink(tlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230#endif
231 return rc;
232}
233
Steve French79a58d12007-07-06 22:44:50 +0000234ssize_t cifs_getxattr(struct dentry *direntry, const char *ea_name,
235 void *ea_value, size_t buf_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236{
237 ssize_t rc = -EOPNOTSUPP;
238#ifdef CONFIG_CIFS_XATTR
Pavel Shilovsky6d5786a2012-06-20 11:21:16 +0400239 unsigned int xid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 struct cifs_sb_info *cifs_sb;
Jeff Layton7ffec372010-09-29 19:51:11 -0400241 struct tcon_link *tlink;
Steve French96daf2b2011-05-27 04:34:02 +0000242 struct cifs_tcon *pTcon;
Steve French79a58d12007-07-06 22:44:50 +0000243 struct super_block *sb;
244 char *full_path;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245
Steve French79a58d12007-07-06 22:44:50 +0000246 if (direntry == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 return -EIO;
Steve French79a58d12007-07-06 22:44:50 +0000248 if (direntry->d_inode == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 return -EIO;
250 sb = direntry->d_inode->i_sb;
Steve French79a58d12007-07-06 22:44:50 +0000251 if (sb == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 return -EIO;
253
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 cifs_sb = CIFS_SB(sb);
Jeff Layton7ffec372010-09-29 19:51:11 -0400255 tlink = cifs_sb_tlink(cifs_sb);
256 if (IS_ERR(tlink))
257 return PTR_ERR(tlink);
258 pTcon = tlink_tcon(tlink);
259
Pavel Shilovsky6d5786a2012-06-20 11:21:16 +0400260 xid = get_xid();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 full_path = build_path_from_dentry(direntry);
Steve French79a58d12007-07-06 22:44:50 +0000263 if (full_path == NULL) {
Suresh Jayaraman0f3bc092009-06-25 18:12:34 +0530264 rc = -ENOMEM;
Jeff Layton7ffec372010-09-29 19:51:11 -0400265 goto get_ea_exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 }
267 /* return dos attributes as pseudo xattr */
268 /* return alt name if available as pseudo attr */
Steve French79a58d12007-07-06 22:44:50 +0000269 if (ea_name == NULL) {
Joe Perchesf96637b2013-05-04 22:12:25 -0500270 cifs_dbg(FYI, "Null xattr names not supported\n");
Mimi Zoharf995e742011-08-11 16:00:47 -0400271 } else if (strncmp(ea_name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)
272 == 0) {
Steve French79a58d12007-07-06 22:44:50 +0000273 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 goto get_ea_exit;
275
Steve French79a58d12007-07-06 22:44:50 +0000276 if (strncmp(ea_name, CIFS_XATTR_DOS_ATTRIB, 14) == 0) {
Joe Perchesf96637b2013-05-04 22:12:25 -0500277 cifs_dbg(FYI, "attempt to query cifs inode metadata\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 /* revalidate/getattr then populate from inode */
279 } /* BB add else when above is implemented */
Mimi Zoharf995e742011-08-11 16:00:47 -0400280 ea_name += XATTR_USER_PREFIX_LEN; /* skip past user. prefix */
Steve French666753c2014-01-26 23:53:43 -0600281 if (pTcon->ses->server->ops->query_all_EAs)
282 rc = pTcon->ses->server->ops->query_all_EAs(xid, pTcon,
283 full_path, ea_name, ea_value, buf_size,
284 cifs_sb->local_nls, cifs_sb->mnt_cifs_flags &
285 CIFS_MOUNT_MAP_SPECIAL_CHR);
Mimi Zoharf995e742011-08-11 16:00:47 -0400286 } else if (strncmp(ea_name, XATTR_OS2_PREFIX, XATTR_OS2_PREFIX_LEN) == 0) {
Steve French79a58d12007-07-06 22:44:50 +0000287 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 goto get_ea_exit;
289
Mimi Zoharf995e742011-08-11 16:00:47 -0400290 ea_name += XATTR_OS2_PREFIX_LEN; /* skip past os2. prefix */
Steve French666753c2014-01-26 23:53:43 -0600291 if (pTcon->ses->server->ops->query_all_EAs)
292 rc = pTcon->ses->server->ops->query_all_EAs(xid, pTcon,
293 full_path, ea_name, ea_value, buf_size,
294 cifs_sb->local_nls, cifs_sb->mnt_cifs_flags &
295 CIFS_MOUNT_MAP_SPECIAL_CHR);
Steve French79a58d12007-07-06 22:44:50 +0000296 } else if (strncmp(ea_name, POSIX_ACL_XATTR_ACCESS,
Steve French0a4b92c2006-01-12 15:44:21 -0800297 strlen(POSIX_ACL_XATTR_ACCESS)) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298#ifdef CONFIG_CIFS_POSIX
Steve French79a58d12007-07-06 22:44:50 +0000299 if (sb->s_flags & MS_POSIXACL)
Steve French1da0c782005-04-28 22:41:04 -0700300 rc = CIFSSMBGetPosixACL(xid, pTcon, full_path,
Steve French79a58d12007-07-06 22:44:50 +0000301 ea_value, buf_size, ACL_TYPE_ACCESS,
Steve French737b7582005-04-28 22:41:06 -0700302 cifs_sb->local_nls,
Steve French79a58d12007-07-06 22:44:50 +0000303 cifs_sb->mnt_cifs_flags &
Steve French737b7582005-04-28 22:41:06 -0700304 CIFS_MOUNT_MAP_SPECIAL_CHR);
Steve French79a58d12007-07-06 22:44:50 +0000305#else
Joe Perchesf96637b2013-05-04 22:12:25 -0500306 cifs_dbg(FYI, "Query POSIX ACL not supported yet\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307#endif /* CONFIG_CIFS_POSIX */
Steve French79a58d12007-07-06 22:44:50 +0000308 } else if (strncmp(ea_name, POSIX_ACL_XATTR_DEFAULT,
Steve French0a4b92c2006-01-12 15:44:21 -0800309 strlen(POSIX_ACL_XATTR_DEFAULT)) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310#ifdef CONFIG_CIFS_POSIX
Steve French79a58d12007-07-06 22:44:50 +0000311 if (sb->s_flags & MS_POSIXACL)
Steve French1da0c782005-04-28 22:41:04 -0700312 rc = CIFSSMBGetPosixACL(xid, pTcon, full_path,
Steve French79a58d12007-07-06 22:44:50 +0000313 ea_value, buf_size, ACL_TYPE_DEFAULT,
Steve French737b7582005-04-28 22:41:06 -0700314 cifs_sb->local_nls,
Steve French79a58d12007-07-06 22:44:50 +0000315 cifs_sb->mnt_cifs_flags &
Steve French737b7582005-04-28 22:41:06 -0700316 CIFS_MOUNT_MAP_SPECIAL_CHR);
Steve French79a58d12007-07-06 22:44:50 +0000317#else
Joe Perchesf96637b2013-05-04 22:12:25 -0500318 cifs_dbg(FYI, "Query POSIX default ACL not supported yet\n");
Shirish Pargaonkarfbeba8b2010-11-27 11:37:54 -0600319#endif /* CONFIG_CIFS_POSIX */
320 } else if (strncmp(ea_name, CIFS_XATTR_CIFS_ACL,
321 strlen(CIFS_XATTR_CIFS_ACL)) == 0) {
322#ifdef CONFIG_CIFS_ACL
323 u32 acllen;
324 struct cifs_ntsd *pacl;
325
326 pacl = get_cifs_acl(cifs_sb, direntry->d_inode,
327 full_path, &acllen);
328 if (IS_ERR(pacl)) {
329 rc = PTR_ERR(pacl);
Joe Perchesf96637b2013-05-04 22:12:25 -0500330 cifs_dbg(VFS, "%s: error %zd getting sec desc\n",
331 __func__, rc);
Shirish Pargaonkarfbeba8b2010-11-27 11:37:54 -0600332 } else {
333 if (ea_value) {
334 if (acllen > buf_size)
335 acllen = -ERANGE;
336 else
337 memcpy(ea_value, pacl, acllen);
338 }
339 rc = acllen;
340 kfree(pacl);
341 }
342#else
Joe Perchesf96637b2013-05-04 22:12:25 -0500343 cifs_dbg(FYI, "Query CIFS ACL not supported yet\n");
Shirish Pargaonkarfbeba8b2010-11-27 11:37:54 -0600344#endif /* CONFIG_CIFS_ACL */
Steve French79a58d12007-07-06 22:44:50 +0000345 } else if (strncmp(ea_name,
Mimi Zoharf995e742011-08-11 16:00:47 -0400346 XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN) == 0) {
Joe Perchesf96637b2013-05-04 22:12:25 -0500347 cifs_dbg(FYI, "Trusted xattr namespace not supported yet\n");
Steve French79a58d12007-07-06 22:44:50 +0000348 } else if (strncmp(ea_name,
Mimi Zoharf995e742011-08-11 16:00:47 -0400349 XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN) == 0) {
Joe Perchesf96637b2013-05-04 22:12:25 -0500350 cifs_dbg(FYI, "Security xattr namespace not supported yet\n");
Steve Frenchad7a2922008-02-07 23:25:02 +0000351 } else
Joe Perchesf96637b2013-05-04 22:12:25 -0500352 cifs_dbg(FYI,
353 "illegal xattr request %s (only user namespace supported)\n",
354 ea_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355
Steve French79a58d12007-07-06 22:44:50 +0000356 /* We could add an additional check for streams ie
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 if proc/fs/cifs/streamstoxattr is set then
Steve French79a58d12007-07-06 22:44:50 +0000358 search server for EAs or streams to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 returns as xattrs */
360
Steve French79a58d12007-07-06 22:44:50 +0000361 if (rc == -EINVAL)
362 rc = -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363
364get_ea_exit:
Jesper Juhlf99d49a2005-11-07 01:01:34 -0800365 kfree(full_path);
Pavel Shilovsky6d5786a2012-06-20 11:21:16 +0400366 free_xid(xid);
Jeff Layton7ffec372010-09-29 19:51:11 -0400367 cifs_put_tlink(tlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368#endif
369 return rc;
370}
371
Steve French79a58d12007-07-06 22:44:50 +0000372ssize_t cifs_listxattr(struct dentry *direntry, char *data, size_t buf_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373{
374 ssize_t rc = -EOPNOTSUPP;
375#ifdef CONFIG_CIFS_XATTR
Pavel Shilovsky6d5786a2012-06-20 11:21:16 +0400376 unsigned int xid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 struct cifs_sb_info *cifs_sb;
Jeff Layton7ffec372010-09-29 19:51:11 -0400378 struct tcon_link *tlink;
Steve French96daf2b2011-05-27 04:34:02 +0000379 struct cifs_tcon *pTcon;
Steve French79a58d12007-07-06 22:44:50 +0000380 struct super_block *sb;
381 char *full_path;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382
Steve French79a58d12007-07-06 22:44:50 +0000383 if (direntry == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 return -EIO;
Steve French79a58d12007-07-06 22:44:50 +0000385 if (direntry->d_inode == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 return -EIO;
387 sb = direntry->d_inode->i_sb;
Steve French79a58d12007-07-06 22:44:50 +0000388 if (sb == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390
391 cifs_sb = CIFS_SB(sb);
Steve French79a58d12007-07-06 22:44:50 +0000392 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
Steve Frenchea4c07d2006-08-16 19:44:25 +0000393 return -EOPNOTSUPP;
394
Jeff Layton7ffec372010-09-29 19:51:11 -0400395 tlink = cifs_sb_tlink(cifs_sb);
396 if (IS_ERR(tlink))
397 return PTR_ERR(tlink);
398 pTcon = tlink_tcon(tlink);
399
Pavel Shilovsky6d5786a2012-06-20 11:21:16 +0400400 xid = get_xid();
Steve Frenchea4c07d2006-08-16 19:44:25 +0000401
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 full_path = build_path_from_dentry(direntry);
Steve French79a58d12007-07-06 22:44:50 +0000403 if (full_path == NULL) {
Suresh Jayaraman0f3bc092009-06-25 18:12:34 +0530404 rc = -ENOMEM;
Jeff Layton7ffec372010-09-29 19:51:11 -0400405 goto list_ea_exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 }
407 /* return dos attributes as pseudo xattr */
408 /* return alt name if available as pseudo attr */
409
410 /* if proc/fs/cifs/streamstoxattr is set then
Steve French79a58d12007-07-06 22:44:50 +0000411 search server for EAs or streams to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 returns as xattrs */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413
Steve French666753c2014-01-26 23:53:43 -0600414 if (pTcon->ses->server->ops->query_all_EAs)
415 rc = pTcon->ses->server->ops->query_all_EAs(xid, pTcon,
416 full_path, NULL, data, buf_size,
417 cifs_sb->local_nls, cifs_sb->mnt_cifs_flags &
418 CIFS_MOUNT_MAP_SPECIAL_CHR);
Jeff Layton7ffec372010-09-29 19:51:11 -0400419list_ea_exit:
Jesper Juhlf99d49a2005-11-07 01:01:34 -0800420 kfree(full_path);
Pavel Shilovsky6d5786a2012-06-20 11:21:16 +0400421 free_xid(xid);
Jeff Layton7ffec372010-09-29 19:51:11 -0400422 cifs_put_tlink(tlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423#endif
424 return rc;
425}