blob: eae2a14916080160c4723868dd69d9c3496c99fa [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include "cifsfs.h"
26#include "cifspdu.h"
27#include "cifsglob.h"
28#include "cifsproto.h"
29#include "cifs_debug.h"
30
31#define MAX_EA_VALUE_SIZE 65535
32#define CIFS_XATTR_DOS_ATTRIB "user.DosAttrib"
Shirish Pargaonkarfbeba8b2010-11-27 11:37:54 -060033#define CIFS_XATTR_CIFS_ACL "system.cifs_acl"
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#define CIFS_XATTR_USER_PREFIX "user."
35#define CIFS_XATTR_SYSTEM_PREFIX "system."
36#define CIFS_XATTR_OS2_PREFIX "os2."
Shirish Pargaonkarfbeba8b2010-11-27 11:37:54 -060037#define CIFS_XATTR_SECURITY_PREFIX "security."
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#define CIFS_XATTR_TRUSTED_PREFIX "trusted."
39#define XATTR_TRUSTED_PREFIX_LEN 8
40#define XATTR_SECURITY_PREFIX_LEN 9
41/* BB need to add server (Samba e.g) support for security and trusted prefix */
Steve French50c2f752007-07-13 00:33:32 +000042
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
44
Steve French79a58d12007-07-06 22:44:50 +000045int cifs_removexattr(struct dentry *direntry, const char *ea_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -070046{
47 int rc = -EOPNOTSUPP;
48#ifdef CONFIG_CIFS_XATTR
49 int xid;
50 struct cifs_sb_info *cifs_sb;
Jeff Layton7ffec372010-09-29 19:51:11 -040051 struct tcon_link *tlink;
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 struct cifsTconInfo *pTcon;
Steve French79a58d12007-07-06 22:44:50 +000053 struct super_block *sb;
Jeff Layton7ffec372010-09-29 19:51:11 -040054 char *full_path = NULL;
Steve French79a58d12007-07-06 22:44:50 +000055
56 if (direntry == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 return -EIO;
Steve French79a58d12007-07-06 22:44:50 +000058 if (direntry->d_inode == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 return -EIO;
60 sb = direntry->d_inode->i_sb;
Steve French79a58d12007-07-06 22:44:50 +000061 if (sb == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 return -EIO;
Steve French79a58d12007-07-06 22:44:50 +000063
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 cifs_sb = CIFS_SB(sb);
Jeff Layton7ffec372010-09-29 19:51:11 -040065 tlink = cifs_sb_tlink(cifs_sb);
66 if (IS_ERR(tlink))
67 return PTR_ERR(tlink);
68 pTcon = tlink_tcon(tlink);
69
70 xid = GetXid();
Steve French79a58d12007-07-06 22:44:50 +000071
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 full_path = build_path_from_dentry(direntry);
Steve French79a58d12007-07-06 22:44:50 +000073 if (full_path == NULL) {
Suresh Jayaraman0f3bc092009-06-25 18:12:34 +053074 rc = -ENOMEM;
Jeff Layton7ffec372010-09-29 19:51:11 -040075 goto remove_ea_exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 }
Steve French79a58d12007-07-06 22:44:50 +000077 if (ea_name == NULL) {
Joe Perchesb6b38f72010-04-21 03:50:45 +000078 cFYI(1, "Null xattr names not supported");
Steve French79a58d12007-07-06 22:44:50 +000079 } else if (strncmp(ea_name, CIFS_XATTR_USER_PREFIX, 5)
80 && (strncmp(ea_name, CIFS_XATTR_OS2_PREFIX, 4))) {
81 cFYI(1,
Joe Perchesb6b38f72010-04-21 03:50:45 +000082 "illegal xattr request %s (only user namespace supported)",
83 ea_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 /* BB what if no namespace prefix? */
85 /* Should we just pass them to server, except for
86 system and perhaps security prefixes? */
87 } else {
Steve French79a58d12007-07-06 22:44:50 +000088 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 goto remove_ea_exit;
90
Steve French79a58d12007-07-06 22:44:50 +000091 ea_name += 5; /* skip past user. prefix */
92 rc = CIFSSMBSetEA(xid, pTcon, full_path, ea_name, NULL,
Steve French737b7582005-04-28 22:41:06 -070093 (__u16)0, cifs_sb->local_nls,
94 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 }
96remove_ea_exit:
Jesper Juhlf99d49a2005-11-07 01:01:34 -080097 kfree(full_path);
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 FreeXid(xid);
Jeff Layton7ffec372010-09-29 19:51:11 -040099 cifs_put_tlink(tlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100#endif
101 return rc;
102}
103
Steve French79a58d12007-07-06 22:44:50 +0000104int cifs_setxattr(struct dentry *direntry, const char *ea_name,
105 const void *ea_value, size_t value_size, int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106{
107 int rc = -EOPNOTSUPP;
108#ifdef CONFIG_CIFS_XATTR
109 int xid;
110 struct cifs_sb_info *cifs_sb;
Jeff Layton7ffec372010-09-29 19:51:11 -0400111 struct tcon_link *tlink;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 struct cifsTconInfo *pTcon;
Steve French79a58d12007-07-06 22:44:50 +0000113 struct super_block *sb;
114 char *full_path;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
Steve French79a58d12007-07-06 22:44:50 +0000116 if (direntry == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 return -EIO;
Steve French79a58d12007-07-06 22:44:50 +0000118 if (direntry->d_inode == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 return -EIO;
120 sb = direntry->d_inode->i_sb;
Steve French79a58d12007-07-06 22:44:50 +0000121 if (sb == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
124 cifs_sb = CIFS_SB(sb);
Jeff Layton7ffec372010-09-29 19:51:11 -0400125 tlink = cifs_sb_tlink(cifs_sb);
126 if (IS_ERR(tlink))
127 return PTR_ERR(tlink);
128 pTcon = tlink_tcon(tlink);
129
130 xid = GetXid();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 full_path = build_path_from_dentry(direntry);
Steve French79a58d12007-07-06 22:44:50 +0000133 if (full_path == NULL) {
Suresh Jayaraman0f3bc092009-06-25 18:12:34 +0530134 rc = -ENOMEM;
Jeff Layton7ffec372010-09-29 19:51:11 -0400135 goto set_ea_exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 }
137 /* return dos attributes as pseudo xattr */
138 /* return alt name if available as pseudo attr */
139
140 /* if proc/fs/cifs/streamstoxattr is set then
Steve French79a58d12007-07-06 22:44:50 +0000141 search server for EAs or streams to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 returns as xattrs */
Steve French79a58d12007-07-06 22:44:50 +0000143 if (value_size > MAX_EA_VALUE_SIZE) {
Joe Perchesb6b38f72010-04-21 03:50:45 +0000144 cFYI(1, "size of EA value too large");
Jeff Layton7ffec372010-09-29 19:51:11 -0400145 rc = -EOPNOTSUPP;
146 goto set_ea_exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 }
148
Steve French79a58d12007-07-06 22:44:50 +0000149 if (ea_name == NULL) {
Joe Perchesb6b38f72010-04-21 03:50:45 +0000150 cFYI(1, "Null xattr names not supported");
Steve French79a58d12007-07-06 22:44:50 +0000151 } else if (strncmp(ea_name, CIFS_XATTR_USER_PREFIX, 5) == 0) {
152 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 goto set_ea_exit;
Steve Frenchad7a2922008-02-07 23:25:02 +0000154 if (strncmp(ea_name, CIFS_XATTR_DOS_ATTRIB, 14) == 0)
Joe Perchesb6b38f72010-04-21 03:50:45 +0000155 cFYI(1, "attempt to set cifs inode metadata");
Steve Frenchad7a2922008-02-07 23:25:02 +0000156
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 ea_name += 5; /* skip past user. prefix */
Steve French79a58d12007-07-06 22:44:50 +0000158 rc = CIFSSMBSetEA(xid, pTcon, full_path, ea_name, ea_value,
Steve French737b7582005-04-28 22:41:06 -0700159 (__u16)value_size, cifs_sb->local_nls,
160 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
Steve French79a58d12007-07-06 22:44:50 +0000161 } else if (strncmp(ea_name, CIFS_XATTR_OS2_PREFIX, 4) == 0) {
162 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 goto set_ea_exit;
164
165 ea_name += 4; /* skip past os2. prefix */
Steve French79a58d12007-07-06 22:44:50 +0000166 rc = CIFSSMBSetEA(xid, pTcon, full_path, ea_name, ea_value,
Steve French737b7582005-04-28 22:41:06 -0700167 (__u16)value_size, cifs_sb->local_nls,
168 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 } else {
Steve French79a58d12007-07-06 22:44:50 +0000170 int temp;
171 temp = strncmp(ea_name, POSIX_ACL_XATTR_ACCESS,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 strlen(POSIX_ACL_XATTR_ACCESS));
173 if (temp == 0) {
174#ifdef CONFIG_CIFS_POSIX
Steve French79a58d12007-07-06 22:44:50 +0000175 if (sb->s_flags & MS_POSIXACL)
176 rc = CIFSSMBSetPosixACL(xid, pTcon, full_path,
177 ea_value, (const int)value_size,
178 ACL_TYPE_ACCESS, cifs_sb->local_nls,
179 cifs_sb->mnt_cifs_flags &
Steve French737b7582005-04-28 22:41:06 -0700180 CIFS_MOUNT_MAP_SPECIAL_CHR);
Joe Perchesb6b38f72010-04-21 03:50:45 +0000181 cFYI(1, "set POSIX ACL rc %d", rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182#else
Joe Perchesb6b38f72010-04-21 03:50:45 +0000183 cFYI(1, "set POSIX ACL not supported");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184#endif
Steve French79a58d12007-07-06 22:44:50 +0000185 } else if (strncmp(ea_name, POSIX_ACL_XATTR_DEFAULT,
186 strlen(POSIX_ACL_XATTR_DEFAULT)) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187#ifdef CONFIG_CIFS_POSIX
Steve French79a58d12007-07-06 22:44:50 +0000188 if (sb->s_flags & MS_POSIXACL)
189 rc = CIFSSMBSetPosixACL(xid, pTcon, full_path,
190 ea_value, (const int)value_size,
Steve French737b7582005-04-28 22:41:06 -0700191 ACL_TYPE_DEFAULT, cifs_sb->local_nls,
Steve French79a58d12007-07-06 22:44:50 +0000192 cifs_sb->mnt_cifs_flags &
Steve French737b7582005-04-28 22:41:06 -0700193 CIFS_MOUNT_MAP_SPECIAL_CHR);
Joe Perchesb6b38f72010-04-21 03:50:45 +0000194 cFYI(1, "set POSIX default ACL rc %d", rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195#else
Joe Perchesb6b38f72010-04-21 03:50:45 +0000196 cFYI(1, "set default POSIX ACL not supported");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197#endif
198 } else {
Joe Perchesb6b38f72010-04-21 03:50:45 +0000199 cFYI(1, "illegal xattr request %s (only user namespace"
200 " supported)", ea_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 /* BB what if no namespace prefix? */
Steve French79a58d12007-07-06 22:44:50 +0000202 /* Should we just pass them to server, except for
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 system and perhaps security prefixes? */
204 }
205 }
206
207set_ea_exit:
Jesper Juhlf99d49a2005-11-07 01:01:34 -0800208 kfree(full_path);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 FreeXid(xid);
Jeff Layton7ffec372010-09-29 19:51:11 -0400210 cifs_put_tlink(tlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211#endif
212 return rc;
213}
214
Steve French79a58d12007-07-06 22:44:50 +0000215ssize_t cifs_getxattr(struct dentry *direntry, const char *ea_name,
216 void *ea_value, size_t buf_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217{
218 ssize_t rc = -EOPNOTSUPP;
219#ifdef CONFIG_CIFS_XATTR
220 int xid;
221 struct cifs_sb_info *cifs_sb;
Jeff Layton7ffec372010-09-29 19:51:11 -0400222 struct tcon_link *tlink;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 struct cifsTconInfo *pTcon;
Steve French79a58d12007-07-06 22:44:50 +0000224 struct super_block *sb;
225 char *full_path;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226
Steve French79a58d12007-07-06 22:44:50 +0000227 if (direntry == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 return -EIO;
Steve French79a58d12007-07-06 22:44:50 +0000229 if (direntry->d_inode == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 return -EIO;
231 sb = direntry->d_inode->i_sb;
Steve French79a58d12007-07-06 22:44:50 +0000232 if (sb == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 return -EIO;
234
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 cifs_sb = CIFS_SB(sb);
Jeff Layton7ffec372010-09-29 19:51:11 -0400236 tlink = cifs_sb_tlink(cifs_sb);
237 if (IS_ERR(tlink))
238 return PTR_ERR(tlink);
239 pTcon = tlink_tcon(tlink);
240
241 xid = GetXid();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 full_path = build_path_from_dentry(direntry);
Steve French79a58d12007-07-06 22:44:50 +0000244 if (full_path == NULL) {
Suresh Jayaraman0f3bc092009-06-25 18:12:34 +0530245 rc = -ENOMEM;
Jeff Layton7ffec372010-09-29 19:51:11 -0400246 goto get_ea_exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 }
248 /* return dos attributes as pseudo xattr */
249 /* return alt name if available as pseudo attr */
Steve French79a58d12007-07-06 22:44:50 +0000250 if (ea_name == NULL) {
Joe Perchesb6b38f72010-04-21 03:50:45 +0000251 cFYI(1, "Null xattr names not supported");
Steve French79a58d12007-07-06 22:44:50 +0000252 } else if (strncmp(ea_name, CIFS_XATTR_USER_PREFIX, 5) == 0) {
253 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 goto get_ea_exit;
255
Steve French79a58d12007-07-06 22:44:50 +0000256 if (strncmp(ea_name, CIFS_XATTR_DOS_ATTRIB, 14) == 0) {
Joe Perchesb6b38f72010-04-21 03:50:45 +0000257 cFYI(1, "attempt to query cifs inode metadata");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 /* revalidate/getattr then populate from inode */
259 } /* BB add else when above is implemented */
260 ea_name += 5; /* skip past user. prefix */
Jeff Layton31c05192010-02-10 16:18:26 -0500261 rc = CIFSSMBQAllEAs(xid, pTcon, full_path, ea_name, ea_value,
Steve French737b7582005-04-28 22:41:06 -0700262 buf_size, cifs_sb->local_nls,
263 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
Steve French79a58d12007-07-06 22:44:50 +0000264 } else if (strncmp(ea_name, CIFS_XATTR_OS2_PREFIX, 4) == 0) {
265 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 goto get_ea_exit;
267
268 ea_name += 4; /* skip past os2. prefix */
Jeff Layton31c05192010-02-10 16:18:26 -0500269 rc = CIFSSMBQAllEAs(xid, pTcon, full_path, ea_name, ea_value,
Steve French737b7582005-04-28 22:41:06 -0700270 buf_size, cifs_sb->local_nls,
271 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
Steve French79a58d12007-07-06 22:44:50 +0000272 } else if (strncmp(ea_name, POSIX_ACL_XATTR_ACCESS,
Steve French0a4b92c2006-01-12 15:44:21 -0800273 strlen(POSIX_ACL_XATTR_ACCESS)) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274#ifdef CONFIG_CIFS_POSIX
Steve French79a58d12007-07-06 22:44:50 +0000275 if (sb->s_flags & MS_POSIXACL)
Steve French1da0c782005-04-28 22:41:04 -0700276 rc = CIFSSMBGetPosixACL(xid, pTcon, full_path,
Steve French79a58d12007-07-06 22:44:50 +0000277 ea_value, buf_size, ACL_TYPE_ACCESS,
Steve French737b7582005-04-28 22:41:06 -0700278 cifs_sb->local_nls,
Steve French79a58d12007-07-06 22:44:50 +0000279 cifs_sb->mnt_cifs_flags &
Steve French737b7582005-04-28 22:41:06 -0700280 CIFS_MOUNT_MAP_SPECIAL_CHR);
Steve French79a58d12007-07-06 22:44:50 +0000281#else
Shirish Pargaonkarfbeba8b2010-11-27 11:37:54 -0600282 cFYI(1, "Query POSIX ACL not supported yet");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283#endif /* CONFIG_CIFS_POSIX */
Steve French79a58d12007-07-06 22:44:50 +0000284 } else if (strncmp(ea_name, POSIX_ACL_XATTR_DEFAULT,
Steve French0a4b92c2006-01-12 15:44:21 -0800285 strlen(POSIX_ACL_XATTR_DEFAULT)) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286#ifdef CONFIG_CIFS_POSIX
Steve French79a58d12007-07-06 22:44:50 +0000287 if (sb->s_flags & MS_POSIXACL)
Steve French1da0c782005-04-28 22:41:04 -0700288 rc = CIFSSMBGetPosixACL(xid, pTcon, full_path,
Steve French79a58d12007-07-06 22:44:50 +0000289 ea_value, buf_size, ACL_TYPE_DEFAULT,
Steve French737b7582005-04-28 22:41:06 -0700290 cifs_sb->local_nls,
Steve French79a58d12007-07-06 22:44:50 +0000291 cifs_sb->mnt_cifs_flags &
Steve French737b7582005-04-28 22:41:06 -0700292 CIFS_MOUNT_MAP_SPECIAL_CHR);
Steve French79a58d12007-07-06 22:44:50 +0000293#else
Shirish Pargaonkarfbeba8b2010-11-27 11:37:54 -0600294 cFYI(1, "Query POSIX default ACL not supported yet");
295#endif /* CONFIG_CIFS_POSIX */
296 } else if (strncmp(ea_name, CIFS_XATTR_CIFS_ACL,
297 strlen(CIFS_XATTR_CIFS_ACL)) == 0) {
298#ifdef CONFIG_CIFS_ACL
299 u32 acllen;
300 struct cifs_ntsd *pacl;
301
302 pacl = get_cifs_acl(cifs_sb, direntry->d_inode,
303 full_path, &acllen);
304 if (IS_ERR(pacl)) {
305 rc = PTR_ERR(pacl);
306 cERROR(1, "%s: error %zd getting sec desc",
307 __func__, rc);
308 } else {
309 if (ea_value) {
310 if (acllen > buf_size)
311 acllen = -ERANGE;
312 else
313 memcpy(ea_value, pacl, acllen);
314 }
315 rc = acllen;
316 kfree(pacl);
317 }
318#else
319 cFYI(1, "Query CIFS ACL not supported yet");
320#endif /* CONFIG_CIFS_ACL */
Steve French79a58d12007-07-06 22:44:50 +0000321 } else if (strncmp(ea_name,
322 CIFS_XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN) == 0) {
Joe Perchesb6b38f72010-04-21 03:50:45 +0000323 cFYI(1, "Trusted xattr namespace not supported yet");
Steve French79a58d12007-07-06 22:44:50 +0000324 } else if (strncmp(ea_name,
325 CIFS_XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN) == 0) {
Joe Perchesb6b38f72010-04-21 03:50:45 +0000326 cFYI(1, "Security xattr namespace not supported yet");
Steve Frenchad7a2922008-02-07 23:25:02 +0000327 } else
Steve French79a58d12007-07-06 22:44:50 +0000328 cFYI(1,
Joe Perchesb6b38f72010-04-21 03:50:45 +0000329 "illegal xattr request %s (only user namespace supported)",
330 ea_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331
Steve French79a58d12007-07-06 22:44:50 +0000332 /* We could add an additional check for streams ie
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 if proc/fs/cifs/streamstoxattr is set then
Steve French79a58d12007-07-06 22:44:50 +0000334 search server for EAs or streams to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 returns as xattrs */
336
Steve French79a58d12007-07-06 22:44:50 +0000337 if (rc == -EINVAL)
338 rc = -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339
340get_ea_exit:
Jesper Juhlf99d49a2005-11-07 01:01:34 -0800341 kfree(full_path);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 FreeXid(xid);
Jeff Layton7ffec372010-09-29 19:51:11 -0400343 cifs_put_tlink(tlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344#endif
345 return rc;
346}
347
Steve French79a58d12007-07-06 22:44:50 +0000348ssize_t cifs_listxattr(struct dentry *direntry, char *data, size_t buf_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349{
350 ssize_t rc = -EOPNOTSUPP;
351#ifdef CONFIG_CIFS_XATTR
352 int xid;
353 struct cifs_sb_info *cifs_sb;
Jeff Layton7ffec372010-09-29 19:51:11 -0400354 struct tcon_link *tlink;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 struct cifsTconInfo *pTcon;
Steve French79a58d12007-07-06 22:44:50 +0000356 struct super_block *sb;
357 char *full_path;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358
Steve French79a58d12007-07-06 22:44:50 +0000359 if (direntry == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 return -EIO;
Steve French79a58d12007-07-06 22:44:50 +0000361 if (direntry->d_inode == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 return -EIO;
363 sb = direntry->d_inode->i_sb;
Steve French79a58d12007-07-06 22:44:50 +0000364 if (sb == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
367 cifs_sb = CIFS_SB(sb);
Steve French79a58d12007-07-06 22:44:50 +0000368 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
Steve Frenchea4c07d2006-08-16 19:44:25 +0000369 return -EOPNOTSUPP;
370
Jeff Layton7ffec372010-09-29 19:51:11 -0400371 tlink = cifs_sb_tlink(cifs_sb);
372 if (IS_ERR(tlink))
373 return PTR_ERR(tlink);
374 pTcon = tlink_tcon(tlink);
375
Steve Frenchea4c07d2006-08-16 19:44:25 +0000376 xid = GetXid();
377
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 full_path = build_path_from_dentry(direntry);
Steve French79a58d12007-07-06 22:44:50 +0000379 if (full_path == NULL) {
Suresh Jayaraman0f3bc092009-06-25 18:12:34 +0530380 rc = -ENOMEM;
Jeff Layton7ffec372010-09-29 19:51:11 -0400381 goto list_ea_exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 }
383 /* return dos attributes as pseudo xattr */
384 /* return alt name if available as pseudo attr */
385
386 /* if proc/fs/cifs/streamstoxattr is set then
Steve French79a58d12007-07-06 22:44:50 +0000387 search server for EAs or streams to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 returns as xattrs */
Jeff Layton31c05192010-02-10 16:18:26 -0500389 rc = CIFSSMBQAllEAs(xid, pTcon, full_path, NULL, data,
390 buf_size, cifs_sb->local_nls,
Steve French79a58d12007-07-06 22:44:50 +0000391 cifs_sb->mnt_cifs_flags &
Steve French737b7582005-04-28 22:41:06 -0700392 CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393
Jeff Layton7ffec372010-09-29 19:51:11 -0400394list_ea_exit:
Jesper Juhlf99d49a2005-11-07 01:01:34 -0800395 kfree(full_path);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 FreeXid(xid);
Jeff Layton7ffec372010-09-29 19:51:11 -0400397 cifs_put_tlink(tlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398#endif
399 return rc;
400}