blob: 2a22fb2989e4780fd977c683b27ddf23e78e7d8e [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;
Steve French96daf2b2011-05-27 04:34:02 +000052 struct cifs_tcon *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;
Steve French96daf2b2011-05-27 04:34:02 +0000112 struct cifs_tcon *pTcon;
Steve French79a58d12007-07-06 22:44:50 +0000113 struct super_block *sb;
114 char *full_path;
Steve Frenchb73b9a42011-04-19 18:27:10 +0000115 struct cifs_ntsd *pacl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
Steve French79a58d12007-07-06 22:44:50 +0000117 if (direntry == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 return -EIO;
Steve French79a58d12007-07-06 22:44:50 +0000119 if (direntry->d_inode == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 return -EIO;
121 sb = direntry->d_inode->i_sb;
Steve French79a58d12007-07-06 22:44:50 +0000122 if (sb == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
125 cifs_sb = CIFS_SB(sb);
Jeff Layton7ffec372010-09-29 19:51:11 -0400126 tlink = cifs_sb_tlink(cifs_sb);
127 if (IS_ERR(tlink))
128 return PTR_ERR(tlink);
129 pTcon = tlink_tcon(tlink);
130
131 xid = GetXid();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 full_path = build_path_from_dentry(direntry);
Steve French79a58d12007-07-06 22:44:50 +0000134 if (full_path == NULL) {
Suresh Jayaraman0f3bc092009-06-25 18:12:34 +0530135 rc = -ENOMEM;
Jeff Layton7ffec372010-09-29 19:51:11 -0400136 goto set_ea_exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 }
138 /* return dos attributes as pseudo xattr */
139 /* return alt name if available as pseudo attr */
140
141 /* if proc/fs/cifs/streamstoxattr is set then
Steve French79a58d12007-07-06 22:44:50 +0000142 search server for EAs or streams to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 returns as xattrs */
Steve French79a58d12007-07-06 22:44:50 +0000144 if (value_size > MAX_EA_VALUE_SIZE) {
Joe Perchesb6b38f72010-04-21 03:50:45 +0000145 cFYI(1, "size of EA value too large");
Jeff Layton7ffec372010-09-29 19:51:11 -0400146 rc = -EOPNOTSUPP;
147 goto set_ea_exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 }
149
Steve French79a58d12007-07-06 22:44:50 +0000150 if (ea_name == NULL) {
Joe Perchesb6b38f72010-04-21 03:50:45 +0000151 cFYI(1, "Null xattr names not supported");
Steve French79a58d12007-07-06 22:44:50 +0000152 } else if (strncmp(ea_name, CIFS_XATTR_USER_PREFIX, 5) == 0) {
153 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 goto set_ea_exit;
Steve Frenchad7a2922008-02-07 23:25:02 +0000155 if (strncmp(ea_name, CIFS_XATTR_DOS_ATTRIB, 14) == 0)
Joe Perchesb6b38f72010-04-21 03:50:45 +0000156 cFYI(1, "attempt to set cifs inode metadata");
Steve Frenchad7a2922008-02-07 23:25:02 +0000157
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 ea_name += 5; /* skip past user. prefix */
Steve French79a58d12007-07-06 22:44:50 +0000159 rc = CIFSSMBSetEA(xid, pTcon, full_path, ea_name, ea_value,
Steve French737b7582005-04-28 22:41:06 -0700160 (__u16)value_size, cifs_sb->local_nls,
161 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
Steve French79a58d12007-07-06 22:44:50 +0000162 } else if (strncmp(ea_name, CIFS_XATTR_OS2_PREFIX, 4) == 0) {
163 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 goto set_ea_exit;
165
166 ea_name += 4; /* skip past os2. prefix */
Steve French79a58d12007-07-06 22:44:50 +0000167 rc = CIFSSMBSetEA(xid, pTcon, full_path, ea_name, ea_value,
Steve French737b7582005-04-28 22:41:06 -0700168 (__u16)value_size, cifs_sb->local_nls,
169 cifs_sb->mnt_cifs_flags & 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) {
172 pacl = kmalloc(value_size, GFP_KERNEL);
173 if (!pacl) {
174 cFYI(1, "%s: Can't allocate memory for ACL",
175 __func__);
176 rc = -ENOMEM;
177 } else {
178#ifdef CONFIG_CIFS_ACL
179 memcpy(pacl, ea_value, value_size);
180 rc = set_cifs_acl(pacl, value_size,
181 direntry->d_inode, full_path);
182 if (rc == 0) /* force revalidate of the inode */
183 CIFS_I(direntry->d_inode)->time = 0;
184 kfree(pacl);
185#else
186 cFYI(1, "Set CIFS ACL not supported yet");
187#endif /* CONFIG_CIFS_ACL */
188 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 } else {
Steve French79a58d12007-07-06 22:44:50 +0000190 int temp;
191 temp = strncmp(ea_name, POSIX_ACL_XATTR_ACCESS,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 strlen(POSIX_ACL_XATTR_ACCESS));
193 if (temp == 0) {
194#ifdef CONFIG_CIFS_POSIX
Steve French79a58d12007-07-06 22:44:50 +0000195 if (sb->s_flags & MS_POSIXACL)
196 rc = CIFSSMBSetPosixACL(xid, pTcon, full_path,
197 ea_value, (const int)value_size,
198 ACL_TYPE_ACCESS, cifs_sb->local_nls,
199 cifs_sb->mnt_cifs_flags &
Steve French737b7582005-04-28 22:41:06 -0700200 CIFS_MOUNT_MAP_SPECIAL_CHR);
Joe Perchesb6b38f72010-04-21 03:50:45 +0000201 cFYI(1, "set POSIX ACL rc %d", rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202#else
Joe Perchesb6b38f72010-04-21 03:50:45 +0000203 cFYI(1, "set POSIX ACL not supported");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204#endif
Steve French79a58d12007-07-06 22:44:50 +0000205 } else if (strncmp(ea_name, POSIX_ACL_XATTR_DEFAULT,
206 strlen(POSIX_ACL_XATTR_DEFAULT)) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207#ifdef CONFIG_CIFS_POSIX
Steve French79a58d12007-07-06 22:44:50 +0000208 if (sb->s_flags & MS_POSIXACL)
209 rc = CIFSSMBSetPosixACL(xid, pTcon, full_path,
210 ea_value, (const int)value_size,
Steve French737b7582005-04-28 22:41:06 -0700211 ACL_TYPE_DEFAULT, cifs_sb->local_nls,
Steve French79a58d12007-07-06 22:44:50 +0000212 cifs_sb->mnt_cifs_flags &
Steve French737b7582005-04-28 22:41:06 -0700213 CIFS_MOUNT_MAP_SPECIAL_CHR);
Joe Perchesb6b38f72010-04-21 03:50:45 +0000214 cFYI(1, "set POSIX default ACL rc %d", rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215#else
Joe Perchesb6b38f72010-04-21 03:50:45 +0000216 cFYI(1, "set default POSIX ACL not supported");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217#endif
218 } else {
Joe Perchesb6b38f72010-04-21 03:50:45 +0000219 cFYI(1, "illegal xattr request %s (only user namespace"
220 " supported)", ea_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 /* BB what if no namespace prefix? */
Steve French79a58d12007-07-06 22:44:50 +0000222 /* Should we just pass them to server, except for
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 system and perhaps security prefixes? */
224 }
225 }
226
227set_ea_exit:
Jesper Juhlf99d49a2005-11-07 01:01:34 -0800228 kfree(full_path);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 FreeXid(xid);
Jeff Layton7ffec372010-09-29 19:51:11 -0400230 cifs_put_tlink(tlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231#endif
232 return rc;
233}
234
Steve French79a58d12007-07-06 22:44:50 +0000235ssize_t cifs_getxattr(struct dentry *direntry, const char *ea_name,
236 void *ea_value, size_t buf_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237{
238 ssize_t rc = -EOPNOTSUPP;
239#ifdef CONFIG_CIFS_XATTR
240 int xid;
241 struct cifs_sb_info *cifs_sb;
Jeff Layton7ffec372010-09-29 19:51:11 -0400242 struct tcon_link *tlink;
Steve French96daf2b2011-05-27 04:34:02 +0000243 struct cifs_tcon *pTcon;
Steve French79a58d12007-07-06 22:44:50 +0000244 struct super_block *sb;
245 char *full_path;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246
Steve French79a58d12007-07-06 22:44:50 +0000247 if (direntry == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 return -EIO;
Steve French79a58d12007-07-06 22:44:50 +0000249 if (direntry->d_inode == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 return -EIO;
251 sb = direntry->d_inode->i_sb;
Steve French79a58d12007-07-06 22:44:50 +0000252 if (sb == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 return -EIO;
254
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 cifs_sb = CIFS_SB(sb);
Jeff Layton7ffec372010-09-29 19:51:11 -0400256 tlink = cifs_sb_tlink(cifs_sb);
257 if (IS_ERR(tlink))
258 return PTR_ERR(tlink);
259 pTcon = tlink_tcon(tlink);
260
261 xid = GetXid();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 full_path = build_path_from_dentry(direntry);
Steve French79a58d12007-07-06 22:44:50 +0000264 if (full_path == NULL) {
Suresh Jayaraman0f3bc092009-06-25 18:12:34 +0530265 rc = -ENOMEM;
Jeff Layton7ffec372010-09-29 19:51:11 -0400266 goto get_ea_exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 }
268 /* return dos attributes as pseudo xattr */
269 /* return alt name if available as pseudo attr */
Steve French79a58d12007-07-06 22:44:50 +0000270 if (ea_name == NULL) {
Joe Perchesb6b38f72010-04-21 03:50:45 +0000271 cFYI(1, "Null xattr names not supported");
Steve French79a58d12007-07-06 22:44:50 +0000272 } else if (strncmp(ea_name, CIFS_XATTR_USER_PREFIX, 5) == 0) {
273 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 Perchesb6b38f72010-04-21 03:50:45 +0000277 cFYI(1, "attempt to query cifs inode metadata");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 /* revalidate/getattr then populate from inode */
279 } /* BB add else when above is implemented */
280 ea_name += 5; /* skip past user. prefix */
Jeff Layton31c05192010-02-10 16:18:26 -0500281 rc = CIFSSMBQAllEAs(xid, pTcon, full_path, ea_name, ea_value,
Steve French737b7582005-04-28 22:41:06 -0700282 buf_size, cifs_sb->local_nls,
283 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
Steve French79a58d12007-07-06 22:44:50 +0000284 } else if (strncmp(ea_name, CIFS_XATTR_OS2_PREFIX, 4) == 0) {
285 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 goto get_ea_exit;
287
288 ea_name += 4; /* skip past os2. prefix */
Jeff Layton31c05192010-02-10 16:18:26 -0500289 rc = CIFSSMBQAllEAs(xid, pTcon, full_path, ea_name, ea_value,
Steve French737b7582005-04-28 22:41:06 -0700290 buf_size, cifs_sb->local_nls,
291 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
Steve French79a58d12007-07-06 22:44:50 +0000292 } else if (strncmp(ea_name, POSIX_ACL_XATTR_ACCESS,
Steve French0a4b92c2006-01-12 15:44:21 -0800293 strlen(POSIX_ACL_XATTR_ACCESS)) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294#ifdef CONFIG_CIFS_POSIX
Steve French79a58d12007-07-06 22:44:50 +0000295 if (sb->s_flags & MS_POSIXACL)
Steve French1da0c782005-04-28 22:41:04 -0700296 rc = CIFSSMBGetPosixACL(xid, pTcon, full_path,
Steve French79a58d12007-07-06 22:44:50 +0000297 ea_value, buf_size, ACL_TYPE_ACCESS,
Steve French737b7582005-04-28 22:41:06 -0700298 cifs_sb->local_nls,
Steve French79a58d12007-07-06 22:44:50 +0000299 cifs_sb->mnt_cifs_flags &
Steve French737b7582005-04-28 22:41:06 -0700300 CIFS_MOUNT_MAP_SPECIAL_CHR);
Steve French79a58d12007-07-06 22:44:50 +0000301#else
Shirish Pargaonkarfbeba8b2010-11-27 11:37:54 -0600302 cFYI(1, "Query POSIX ACL not supported yet");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303#endif /* CONFIG_CIFS_POSIX */
Steve French79a58d12007-07-06 22:44:50 +0000304 } else if (strncmp(ea_name, POSIX_ACL_XATTR_DEFAULT,
Steve French0a4b92c2006-01-12 15:44:21 -0800305 strlen(POSIX_ACL_XATTR_DEFAULT)) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306#ifdef CONFIG_CIFS_POSIX
Steve French79a58d12007-07-06 22:44:50 +0000307 if (sb->s_flags & MS_POSIXACL)
Steve French1da0c782005-04-28 22:41:04 -0700308 rc = CIFSSMBGetPosixACL(xid, pTcon, full_path,
Steve French79a58d12007-07-06 22:44:50 +0000309 ea_value, buf_size, ACL_TYPE_DEFAULT,
Steve French737b7582005-04-28 22:41:06 -0700310 cifs_sb->local_nls,
Steve French79a58d12007-07-06 22:44:50 +0000311 cifs_sb->mnt_cifs_flags &
Steve French737b7582005-04-28 22:41:06 -0700312 CIFS_MOUNT_MAP_SPECIAL_CHR);
Steve French79a58d12007-07-06 22:44:50 +0000313#else
Shirish Pargaonkarfbeba8b2010-11-27 11:37:54 -0600314 cFYI(1, "Query POSIX default ACL not supported yet");
315#endif /* CONFIG_CIFS_POSIX */
316 } else if (strncmp(ea_name, CIFS_XATTR_CIFS_ACL,
317 strlen(CIFS_XATTR_CIFS_ACL)) == 0) {
318#ifdef CONFIG_CIFS_ACL
319 u32 acllen;
320 struct cifs_ntsd *pacl;
321
322 pacl = get_cifs_acl(cifs_sb, direntry->d_inode,
323 full_path, &acllen);
324 if (IS_ERR(pacl)) {
325 rc = PTR_ERR(pacl);
326 cERROR(1, "%s: error %zd getting sec desc",
327 __func__, rc);
328 } else {
329 if (ea_value) {
330 if (acllen > buf_size)
331 acllen = -ERANGE;
332 else
333 memcpy(ea_value, pacl, acllen);
334 }
335 rc = acllen;
336 kfree(pacl);
337 }
338#else
339 cFYI(1, "Query CIFS ACL not supported yet");
340#endif /* CONFIG_CIFS_ACL */
Steve French79a58d12007-07-06 22:44:50 +0000341 } else if (strncmp(ea_name,
342 CIFS_XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN) == 0) {
Joe Perchesb6b38f72010-04-21 03:50:45 +0000343 cFYI(1, "Trusted xattr namespace not supported yet");
Steve French79a58d12007-07-06 22:44:50 +0000344 } else if (strncmp(ea_name,
345 CIFS_XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN) == 0) {
Joe Perchesb6b38f72010-04-21 03:50:45 +0000346 cFYI(1, "Security xattr namespace not supported yet");
Steve Frenchad7a2922008-02-07 23:25:02 +0000347 } else
Steve French79a58d12007-07-06 22:44:50 +0000348 cFYI(1,
Joe Perchesb6b38f72010-04-21 03:50:45 +0000349 "illegal xattr request %s (only user namespace supported)",
350 ea_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351
Steve French79a58d12007-07-06 22:44:50 +0000352 /* We could add an additional check for streams ie
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 if proc/fs/cifs/streamstoxattr is set then
Steve French79a58d12007-07-06 22:44:50 +0000354 search server for EAs or streams to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 returns as xattrs */
356
Steve French79a58d12007-07-06 22:44:50 +0000357 if (rc == -EINVAL)
358 rc = -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359
360get_ea_exit:
Jesper Juhlf99d49a2005-11-07 01:01:34 -0800361 kfree(full_path);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 FreeXid(xid);
Jeff Layton7ffec372010-09-29 19:51:11 -0400363 cifs_put_tlink(tlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364#endif
365 return rc;
366}
367
Steve French79a58d12007-07-06 22:44:50 +0000368ssize_t cifs_listxattr(struct dentry *direntry, char *data, size_t buf_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369{
370 ssize_t rc = -EOPNOTSUPP;
371#ifdef CONFIG_CIFS_XATTR
372 int xid;
373 struct cifs_sb_info *cifs_sb;
Jeff Layton7ffec372010-09-29 19:51:11 -0400374 struct tcon_link *tlink;
Steve French96daf2b2011-05-27 04:34:02 +0000375 struct cifs_tcon *pTcon;
Steve French79a58d12007-07-06 22:44:50 +0000376 struct super_block *sb;
377 char *full_path;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378
Steve French79a58d12007-07-06 22:44:50 +0000379 if (direntry == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 return -EIO;
Steve French79a58d12007-07-06 22:44:50 +0000381 if (direntry->d_inode == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 return -EIO;
383 sb = direntry->d_inode->i_sb;
Steve French79a58d12007-07-06 22:44:50 +0000384 if (sb == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386
387 cifs_sb = CIFS_SB(sb);
Steve French79a58d12007-07-06 22:44:50 +0000388 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
Steve Frenchea4c07d2006-08-16 19:44:25 +0000389 return -EOPNOTSUPP;
390
Jeff Layton7ffec372010-09-29 19:51:11 -0400391 tlink = cifs_sb_tlink(cifs_sb);
392 if (IS_ERR(tlink))
393 return PTR_ERR(tlink);
394 pTcon = tlink_tcon(tlink);
395
Steve Frenchea4c07d2006-08-16 19:44:25 +0000396 xid = GetXid();
397
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 full_path = build_path_from_dentry(direntry);
Steve French79a58d12007-07-06 22:44:50 +0000399 if (full_path == NULL) {
Suresh Jayaraman0f3bc092009-06-25 18:12:34 +0530400 rc = -ENOMEM;
Jeff Layton7ffec372010-09-29 19:51:11 -0400401 goto list_ea_exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 }
403 /* return dos attributes as pseudo xattr */
404 /* return alt name if available as pseudo attr */
405
406 /* if proc/fs/cifs/streamstoxattr is set then
Steve French79a58d12007-07-06 22:44:50 +0000407 search server for EAs or streams to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 returns as xattrs */
Jeff Layton31c05192010-02-10 16:18:26 -0500409 rc = CIFSSMBQAllEAs(xid, pTcon, full_path, NULL, data,
410 buf_size, cifs_sb->local_nls,
Steve French79a58d12007-07-06 22:44:50 +0000411 cifs_sb->mnt_cifs_flags &
Steve French737b7582005-04-28 22:41:06 -0700412 CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413
Jeff Layton7ffec372010-09-29 19:51:11 -0400414list_ea_exit:
Jesper Juhlf99d49a2005-11-07 01:01:34 -0800415 kfree(full_path);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 FreeXid(xid);
Jeff Layton7ffec372010-09-29 19:51:11 -0400417 cifs_put_tlink(tlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418#endif
419 return rc;
420}