blob: 45f07c46f3ed5d9e4afc29ebf0337844b8acd856 [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
42 int xid;
43 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
63 xid = GetXid();
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 Perchesb6b38f72010-04-21 03:50:45 +000071 cFYI(1, "Null xattr names not supported");
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))) {
Steve French79a58d12007-07-06 22:44:50 +000074 cFYI(1,
Joe Perchesb6b38f72010-04-21 03:50:45 +000075 "illegal xattr request %s (only user namespace supported)",
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 French79a58d12007-07-06 22:44:50 +000085 rc = CIFSSMBSetEA(xid, pTcon, full_path, ea_name, NULL,
Steve French737b7582005-04-28 22:41:06 -070086 (__u16)0, cifs_sb->local_nls,
87 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 }
89remove_ea_exit:
Jesper Juhlf99d49a2005-11-07 01:01:34 -080090 kfree(full_path);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 FreeXid(xid);
Jeff Layton7ffec372010-09-29 19:51:11 -040092 cifs_put_tlink(tlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093#endif
94 return rc;
95}
96
Steve French79a58d12007-07-06 22:44:50 +000097int cifs_setxattr(struct dentry *direntry, const char *ea_name,
98 const void *ea_value, size_t value_size, int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -070099{
100 int rc = -EOPNOTSUPP;
101#ifdef CONFIG_CIFS_XATTR
102 int xid;
103 struct cifs_sb_info *cifs_sb;
Jeff Layton7ffec372010-09-29 19:51:11 -0400104 struct tcon_link *tlink;
Steve French96daf2b2011-05-27 04:34:02 +0000105 struct cifs_tcon *pTcon;
Steve French79a58d12007-07-06 22:44:50 +0000106 struct super_block *sb;
107 char *full_path;
Steve Frenchb73b9a42011-04-19 18:27:10 +0000108 struct cifs_ntsd *pacl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
Steve French79a58d12007-07-06 22:44:50 +0000110 if (direntry == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 return -EIO;
Steve French79a58d12007-07-06 22:44:50 +0000112 if (direntry->d_inode == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 return -EIO;
114 sb = direntry->d_inode->i_sb;
Steve French79a58d12007-07-06 22:44:50 +0000115 if (sb == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
118 cifs_sb = CIFS_SB(sb);
Jeff Layton7ffec372010-09-29 19:51:11 -0400119 tlink = cifs_sb_tlink(cifs_sb);
120 if (IS_ERR(tlink))
121 return PTR_ERR(tlink);
122 pTcon = tlink_tcon(tlink);
123
124 xid = GetXid();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 full_path = build_path_from_dentry(direntry);
Steve French79a58d12007-07-06 22:44:50 +0000127 if (full_path == NULL) {
Suresh Jayaraman0f3bc092009-06-25 18:12:34 +0530128 rc = -ENOMEM;
Jeff Layton7ffec372010-09-29 19:51:11 -0400129 goto set_ea_exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 }
131 /* return dos attributes as pseudo xattr */
132 /* return alt name if available as pseudo attr */
133
134 /* if proc/fs/cifs/streamstoxattr is set then
Steve French79a58d12007-07-06 22:44:50 +0000135 search server for EAs or streams to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 returns as xattrs */
Steve French79a58d12007-07-06 22:44:50 +0000137 if (value_size > MAX_EA_VALUE_SIZE) {
Joe Perchesb6b38f72010-04-21 03:50:45 +0000138 cFYI(1, "size of EA value too large");
Jeff Layton7ffec372010-09-29 19:51:11 -0400139 rc = -EOPNOTSUPP;
140 goto set_ea_exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 }
142
Steve French79a58d12007-07-06 22:44:50 +0000143 if (ea_name == NULL) {
Joe Perchesb6b38f72010-04-21 03:50:45 +0000144 cFYI(1, "Null xattr names not supported");
Mimi Zoharf995e742011-08-11 16:00:47 -0400145 } else if (strncmp(ea_name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)
146 == 0) {
Steve French79a58d12007-07-06 22:44:50 +0000147 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 goto set_ea_exit;
Steve Frenchad7a2922008-02-07 23:25:02 +0000149 if (strncmp(ea_name, CIFS_XATTR_DOS_ATTRIB, 14) == 0)
Joe Perchesb6b38f72010-04-21 03:50:45 +0000150 cFYI(1, "attempt to set cifs inode metadata");
Steve Frenchad7a2922008-02-07 23:25:02 +0000151
Mimi Zoharf995e742011-08-11 16:00:47 -0400152 ea_name += XATTR_USER_PREFIX_LEN; /* skip past user. prefix */
Steve French79a58d12007-07-06 22:44:50 +0000153 rc = CIFSSMBSetEA(xid, pTcon, full_path, ea_name, ea_value,
Steve French737b7582005-04-28 22:41:06 -0700154 (__u16)value_size, cifs_sb->local_nls,
155 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
Mimi Zoharf995e742011-08-11 16:00:47 -0400156 } else if (strncmp(ea_name, XATTR_OS2_PREFIX, XATTR_OS2_PREFIX_LEN)
157 == 0) {
Steve French79a58d12007-07-06 22:44:50 +0000158 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 goto set_ea_exit;
160
Mimi Zoharf995e742011-08-11 16:00:47 -0400161 ea_name += XATTR_OS2_PREFIX_LEN; /* skip past os2. prefix */
Steve French79a58d12007-07-06 22:44:50 +0000162 rc = CIFSSMBSetEA(xid, pTcon, full_path, ea_name, ea_value,
Steve French737b7582005-04-28 22:41:06 -0700163 (__u16)value_size, cifs_sb->local_nls,
164 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
Steve Frenchb73b9a42011-04-19 18:27:10 +0000165 } else if (strncmp(ea_name, CIFS_XATTR_CIFS_ACL,
166 strlen(CIFS_XATTR_CIFS_ACL)) == 0) {
167 pacl = kmalloc(value_size, GFP_KERNEL);
168 if (!pacl) {
169 cFYI(1, "%s: Can't allocate memory for ACL",
170 __func__);
171 rc = -ENOMEM;
172 } else {
173#ifdef CONFIG_CIFS_ACL
174 memcpy(pacl, ea_value, value_size);
175 rc = set_cifs_acl(pacl, value_size,
Shirish Pargaonkara5ff3762011-10-13 10:26:03 -0500176 direntry->d_inode, full_path, CIFS_ACL_DACL);
Steve Frenchb73b9a42011-04-19 18:27:10 +0000177 if (rc == 0) /* force revalidate of the inode */
178 CIFS_I(direntry->d_inode)->time = 0;
179 kfree(pacl);
180#else
181 cFYI(1, "Set CIFS ACL not supported yet");
182#endif /* CONFIG_CIFS_ACL */
183 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 } else {
Steve French79a58d12007-07-06 22:44:50 +0000185 int temp;
186 temp = strncmp(ea_name, POSIX_ACL_XATTR_ACCESS,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 strlen(POSIX_ACL_XATTR_ACCESS));
188 if (temp == 0) {
189#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,
193 ACL_TYPE_ACCESS, cifs_sb->local_nls,
194 cifs_sb->mnt_cifs_flags &
Steve French737b7582005-04-28 22:41:06 -0700195 CIFS_MOUNT_MAP_SPECIAL_CHR);
Joe Perchesb6b38f72010-04-21 03:50:45 +0000196 cFYI(1, "set POSIX ACL rc %d", rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197#else
Joe Perchesb6b38f72010-04-21 03:50:45 +0000198 cFYI(1, "set POSIX ACL not supported");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199#endif
Steve French79a58d12007-07-06 22:44:50 +0000200 } else if (strncmp(ea_name, POSIX_ACL_XATTR_DEFAULT,
201 strlen(POSIX_ACL_XATTR_DEFAULT)) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202#ifdef CONFIG_CIFS_POSIX
Steve French79a58d12007-07-06 22:44:50 +0000203 if (sb->s_flags & MS_POSIXACL)
204 rc = CIFSSMBSetPosixACL(xid, pTcon, full_path,
205 ea_value, (const int)value_size,
Steve French737b7582005-04-28 22:41:06 -0700206 ACL_TYPE_DEFAULT, cifs_sb->local_nls,
Steve French79a58d12007-07-06 22:44:50 +0000207 cifs_sb->mnt_cifs_flags &
Steve French737b7582005-04-28 22:41:06 -0700208 CIFS_MOUNT_MAP_SPECIAL_CHR);
Joe Perchesb6b38f72010-04-21 03:50:45 +0000209 cFYI(1, "set POSIX default ACL rc %d", rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210#else
Joe Perchesb6b38f72010-04-21 03:50:45 +0000211 cFYI(1, "set default POSIX ACL not supported");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212#endif
213 } else {
Joe Perchesb6b38f72010-04-21 03:50:45 +0000214 cFYI(1, "illegal xattr request %s (only user namespace"
215 " supported)", ea_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 /* BB what if no namespace prefix? */
Steve French79a58d12007-07-06 22:44:50 +0000217 /* Should we just pass them to server, except for
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 system and perhaps security prefixes? */
219 }
220 }
221
222set_ea_exit:
Jesper Juhlf99d49a2005-11-07 01:01:34 -0800223 kfree(full_path);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 FreeXid(xid);
Jeff Layton7ffec372010-09-29 19:51:11 -0400225 cifs_put_tlink(tlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226#endif
227 return rc;
228}
229
Steve French79a58d12007-07-06 22:44:50 +0000230ssize_t cifs_getxattr(struct dentry *direntry, const char *ea_name,
231 void *ea_value, size_t buf_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232{
233 ssize_t rc = -EOPNOTSUPP;
234#ifdef CONFIG_CIFS_XATTR
235 int xid;
236 struct cifs_sb_info *cifs_sb;
Jeff Layton7ffec372010-09-29 19:51:11 -0400237 struct tcon_link *tlink;
Steve French96daf2b2011-05-27 04:34:02 +0000238 struct cifs_tcon *pTcon;
Steve French79a58d12007-07-06 22:44:50 +0000239 struct super_block *sb;
240 char *full_path;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241
Steve French79a58d12007-07-06 22:44:50 +0000242 if (direntry == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 return -EIO;
Steve French79a58d12007-07-06 22:44:50 +0000244 if (direntry->d_inode == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 return -EIO;
246 sb = direntry->d_inode->i_sb;
Steve French79a58d12007-07-06 22:44:50 +0000247 if (sb == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 return -EIO;
249
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 cifs_sb = CIFS_SB(sb);
Jeff Layton7ffec372010-09-29 19:51:11 -0400251 tlink = cifs_sb_tlink(cifs_sb);
252 if (IS_ERR(tlink))
253 return PTR_ERR(tlink);
254 pTcon = tlink_tcon(tlink);
255
256 xid = GetXid();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 full_path = build_path_from_dentry(direntry);
Steve French79a58d12007-07-06 22:44:50 +0000259 if (full_path == NULL) {
Suresh Jayaraman0f3bc092009-06-25 18:12:34 +0530260 rc = -ENOMEM;
Jeff Layton7ffec372010-09-29 19:51:11 -0400261 goto get_ea_exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 }
263 /* return dos attributes as pseudo xattr */
264 /* return alt name if available as pseudo attr */
Steve French79a58d12007-07-06 22:44:50 +0000265 if (ea_name == NULL) {
Joe Perchesb6b38f72010-04-21 03:50:45 +0000266 cFYI(1, "Null xattr names not supported");
Mimi Zoharf995e742011-08-11 16:00:47 -0400267 } else if (strncmp(ea_name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)
268 == 0) {
Steve French79a58d12007-07-06 22:44:50 +0000269 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 goto get_ea_exit;
271
Steve French79a58d12007-07-06 22:44:50 +0000272 if (strncmp(ea_name, CIFS_XATTR_DOS_ATTRIB, 14) == 0) {
Joe Perchesb6b38f72010-04-21 03:50:45 +0000273 cFYI(1, "attempt to query cifs inode metadata");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 /* revalidate/getattr then populate from inode */
275 } /* BB add else when above is implemented */
Mimi Zoharf995e742011-08-11 16:00:47 -0400276 ea_name += XATTR_USER_PREFIX_LEN; /* skip past user. prefix */
Jeff Layton31c05192010-02-10 16:18:26 -0500277 rc = CIFSSMBQAllEAs(xid, pTcon, full_path, ea_name, ea_value,
Steve French737b7582005-04-28 22:41:06 -0700278 buf_size, cifs_sb->local_nls,
279 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
Mimi Zoharf995e742011-08-11 16:00:47 -0400280 } else if (strncmp(ea_name, XATTR_OS2_PREFIX, XATTR_OS2_PREFIX_LEN) == 0) {
Steve French79a58d12007-07-06 22:44:50 +0000281 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 goto get_ea_exit;
283
Mimi Zoharf995e742011-08-11 16:00:47 -0400284 ea_name += XATTR_OS2_PREFIX_LEN; /* skip past os2. prefix */
Jeff Layton31c05192010-02-10 16:18:26 -0500285 rc = CIFSSMBQAllEAs(xid, pTcon, full_path, ea_name, ea_value,
Steve French737b7582005-04-28 22:41:06 -0700286 buf_size, cifs_sb->local_nls,
287 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
Steve French79a58d12007-07-06 22:44:50 +0000288 } else if (strncmp(ea_name, POSIX_ACL_XATTR_ACCESS,
Steve French0a4b92c2006-01-12 15:44:21 -0800289 strlen(POSIX_ACL_XATTR_ACCESS)) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290#ifdef CONFIG_CIFS_POSIX
Steve French79a58d12007-07-06 22:44:50 +0000291 if (sb->s_flags & MS_POSIXACL)
Steve French1da0c782005-04-28 22:41:04 -0700292 rc = CIFSSMBGetPosixACL(xid, pTcon, full_path,
Steve French79a58d12007-07-06 22:44:50 +0000293 ea_value, buf_size, ACL_TYPE_ACCESS,
Steve French737b7582005-04-28 22:41:06 -0700294 cifs_sb->local_nls,
Steve French79a58d12007-07-06 22:44:50 +0000295 cifs_sb->mnt_cifs_flags &
Steve French737b7582005-04-28 22:41:06 -0700296 CIFS_MOUNT_MAP_SPECIAL_CHR);
Steve French79a58d12007-07-06 22:44:50 +0000297#else
Shirish Pargaonkarfbeba8b2010-11-27 11:37:54 -0600298 cFYI(1, "Query POSIX ACL not supported yet");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299#endif /* CONFIG_CIFS_POSIX */
Steve French79a58d12007-07-06 22:44:50 +0000300 } else if (strncmp(ea_name, POSIX_ACL_XATTR_DEFAULT,
Steve French0a4b92c2006-01-12 15:44:21 -0800301 strlen(POSIX_ACL_XATTR_DEFAULT)) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302#ifdef CONFIG_CIFS_POSIX
Steve French79a58d12007-07-06 22:44:50 +0000303 if (sb->s_flags & MS_POSIXACL)
Steve French1da0c782005-04-28 22:41:04 -0700304 rc = CIFSSMBGetPosixACL(xid, pTcon, full_path,
Steve French79a58d12007-07-06 22:44:50 +0000305 ea_value, buf_size, ACL_TYPE_DEFAULT,
Steve French737b7582005-04-28 22:41:06 -0700306 cifs_sb->local_nls,
Steve French79a58d12007-07-06 22:44:50 +0000307 cifs_sb->mnt_cifs_flags &
Steve French737b7582005-04-28 22:41:06 -0700308 CIFS_MOUNT_MAP_SPECIAL_CHR);
Steve French79a58d12007-07-06 22:44:50 +0000309#else
Shirish Pargaonkarfbeba8b2010-11-27 11:37:54 -0600310 cFYI(1, "Query POSIX default ACL not supported yet");
311#endif /* CONFIG_CIFS_POSIX */
312 } else if (strncmp(ea_name, CIFS_XATTR_CIFS_ACL,
313 strlen(CIFS_XATTR_CIFS_ACL)) == 0) {
314#ifdef CONFIG_CIFS_ACL
315 u32 acllen;
316 struct cifs_ntsd *pacl;
317
318 pacl = get_cifs_acl(cifs_sb, direntry->d_inode,
319 full_path, &acllen);
320 if (IS_ERR(pacl)) {
321 rc = PTR_ERR(pacl);
322 cERROR(1, "%s: error %zd getting sec desc",
323 __func__, rc);
324 } else {
325 if (ea_value) {
326 if (acllen > buf_size)
327 acllen = -ERANGE;
328 else
329 memcpy(ea_value, pacl, acllen);
330 }
331 rc = acllen;
332 kfree(pacl);
333 }
334#else
335 cFYI(1, "Query CIFS ACL not supported yet");
336#endif /* CONFIG_CIFS_ACL */
Steve French79a58d12007-07-06 22:44:50 +0000337 } else if (strncmp(ea_name,
Mimi Zoharf995e742011-08-11 16:00:47 -0400338 XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN) == 0) {
Joe Perchesb6b38f72010-04-21 03:50:45 +0000339 cFYI(1, "Trusted xattr namespace not supported yet");
Steve French79a58d12007-07-06 22:44:50 +0000340 } else if (strncmp(ea_name,
Mimi Zoharf995e742011-08-11 16:00:47 -0400341 XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN) == 0) {
Joe Perchesb6b38f72010-04-21 03:50:45 +0000342 cFYI(1, "Security xattr namespace not supported yet");
Steve Frenchad7a2922008-02-07 23:25:02 +0000343 } else
Steve French79a58d12007-07-06 22:44:50 +0000344 cFYI(1,
Joe Perchesb6b38f72010-04-21 03:50:45 +0000345 "illegal xattr request %s (only user namespace supported)",
346 ea_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347
Steve French79a58d12007-07-06 22:44:50 +0000348 /* We could add an additional check for streams ie
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 if proc/fs/cifs/streamstoxattr is set then
Steve French79a58d12007-07-06 22:44:50 +0000350 search server for EAs or streams to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 returns as xattrs */
352
Steve French79a58d12007-07-06 22:44:50 +0000353 if (rc == -EINVAL)
354 rc = -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355
356get_ea_exit:
Jesper Juhlf99d49a2005-11-07 01:01:34 -0800357 kfree(full_path);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 FreeXid(xid);
Jeff Layton7ffec372010-09-29 19:51:11 -0400359 cifs_put_tlink(tlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360#endif
361 return rc;
362}
363
Steve French79a58d12007-07-06 22:44:50 +0000364ssize_t cifs_listxattr(struct dentry *direntry, char *data, size_t buf_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365{
366 ssize_t rc = -EOPNOTSUPP;
367#ifdef CONFIG_CIFS_XATTR
368 int xid;
369 struct cifs_sb_info *cifs_sb;
Jeff Layton7ffec372010-09-29 19:51:11 -0400370 struct tcon_link *tlink;
Steve French96daf2b2011-05-27 04:34:02 +0000371 struct cifs_tcon *pTcon;
Steve French79a58d12007-07-06 22:44:50 +0000372 struct super_block *sb;
373 char *full_path;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374
Steve French79a58d12007-07-06 22:44:50 +0000375 if (direntry == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 return -EIO;
Steve French79a58d12007-07-06 22:44:50 +0000377 if (direntry->d_inode == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 return -EIO;
379 sb = direntry->d_inode->i_sb;
Steve French79a58d12007-07-06 22:44:50 +0000380 if (sb == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382
383 cifs_sb = CIFS_SB(sb);
Steve French79a58d12007-07-06 22:44:50 +0000384 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
Steve Frenchea4c07d2006-08-16 19:44:25 +0000385 return -EOPNOTSUPP;
386
Jeff Layton7ffec372010-09-29 19:51:11 -0400387 tlink = cifs_sb_tlink(cifs_sb);
388 if (IS_ERR(tlink))
389 return PTR_ERR(tlink);
390 pTcon = tlink_tcon(tlink);
391
Steve Frenchea4c07d2006-08-16 19:44:25 +0000392 xid = GetXid();
393
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 full_path = build_path_from_dentry(direntry);
Steve French79a58d12007-07-06 22:44:50 +0000395 if (full_path == NULL) {
Suresh Jayaraman0f3bc092009-06-25 18:12:34 +0530396 rc = -ENOMEM;
Jeff Layton7ffec372010-09-29 19:51:11 -0400397 goto list_ea_exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 }
399 /* return dos attributes as pseudo xattr */
400 /* return alt name if available as pseudo attr */
401
402 /* if proc/fs/cifs/streamstoxattr is set then
Steve French79a58d12007-07-06 22:44:50 +0000403 search server for EAs or streams to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 returns as xattrs */
Jeff Layton31c05192010-02-10 16:18:26 -0500405 rc = CIFSSMBQAllEAs(xid, pTcon, full_path, NULL, data,
406 buf_size, cifs_sb->local_nls,
Steve French79a58d12007-07-06 22:44:50 +0000407 cifs_sb->mnt_cifs_flags &
Steve French737b7582005-04-28 22:41:06 -0700408 CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409
Jeff Layton7ffec372010-09-29 19:51:11 -0400410list_ea_exit:
Jesper Juhlf99d49a2005-11-07 01:01:34 -0800411 kfree(full_path);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 FreeXid(xid);
Jeff Layton7ffec372010-09-29 19:51:11 -0400413 cifs_put_tlink(tlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414#endif
415 return rc;
416}