blob: 09afda4cc58e67aa0627bc3ba7c70167cd4ae73f [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 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);
Pavel Shilovsky6d5786a2012-06-20 11:21:16 +040091 free_xid(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
Pavel Shilovsky6d5786a2012-06-20 11:21:16 +0400102 unsigned int xid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
Steve French79a58d12007-07-06 22:44:50 +0000109 if (direntry == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 return -EIO;
Steve French79a58d12007-07-06 22:44:50 +0000111 if (direntry->d_inode == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 return -EIO;
113 sb = direntry->d_inode->i_sb;
Steve French79a58d12007-07-06 22:44:50 +0000114 if (sb == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
117 cifs_sb = CIFS_SB(sb);
Jeff Layton7ffec372010-09-29 19:51:11 -0400118 tlink = cifs_sb_tlink(cifs_sb);
119 if (IS_ERR(tlink))
120 return PTR_ERR(tlink);
121 pTcon = tlink_tcon(tlink);
122
Pavel Shilovsky6d5786a2012-06-20 11:21:16 +0400123 xid = get_xid();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 full_path = build_path_from_dentry(direntry);
Steve French79a58d12007-07-06 22:44:50 +0000126 if (full_path == NULL) {
Suresh Jayaraman0f3bc092009-06-25 18:12:34 +0530127 rc = -ENOMEM;
Jeff Layton7ffec372010-09-29 19:51:11 -0400128 goto set_ea_exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 }
130 /* return dos attributes as pseudo xattr */
131 /* return alt name if available as pseudo attr */
132
133 /* if proc/fs/cifs/streamstoxattr is set then
Steve French79a58d12007-07-06 22:44:50 +0000134 search server for EAs or streams to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 returns as xattrs */
Steve French79a58d12007-07-06 22:44:50 +0000136 if (value_size > MAX_EA_VALUE_SIZE) {
Joe Perchesf96637b2013-05-04 22:12:25 -0500137 cifs_dbg(FYI, "size of EA value too large\n");
Jeff Layton7ffec372010-09-29 19:51:11 -0400138 rc = -EOPNOTSUPP;
139 goto set_ea_exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 }
141
Steve French79a58d12007-07-06 22:44:50 +0000142 if (ea_name == NULL) {
Joe Perchesf96637b2013-05-04 22:12:25 -0500143 cifs_dbg(FYI, "Null xattr names not supported\n");
Mimi Zoharf995e742011-08-11 16:00:47 -0400144 } else if (strncmp(ea_name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)
145 == 0) {
Steve French79a58d12007-07-06 22:44:50 +0000146 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 goto set_ea_exit;
Steve Frenchad7a2922008-02-07 23:25:02 +0000148 if (strncmp(ea_name, CIFS_XATTR_DOS_ATTRIB, 14) == 0)
Joe Perchesf96637b2013-05-04 22:12:25 -0500149 cifs_dbg(FYI, "attempt to set cifs inode metadata\n");
Steve Frenchad7a2922008-02-07 23:25:02 +0000150
Mimi Zoharf995e742011-08-11 16:00:47 -0400151 ea_name += XATTR_USER_PREFIX_LEN; /* skip past user. prefix */
Steve French79a58d12007-07-06 22:44:50 +0000152 rc = CIFSSMBSetEA(xid, pTcon, full_path, ea_name, ea_value,
Steve French737b7582005-04-28 22:41:06 -0700153 (__u16)value_size, cifs_sb->local_nls,
154 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
Mimi Zoharf995e742011-08-11 16:00:47 -0400155 } else if (strncmp(ea_name, XATTR_OS2_PREFIX, XATTR_OS2_PREFIX_LEN)
156 == 0) {
Steve French79a58d12007-07-06 22:44:50 +0000157 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 goto set_ea_exit;
159
Mimi Zoharf995e742011-08-11 16:00:47 -0400160 ea_name += XATTR_OS2_PREFIX_LEN; /* skip past os2. prefix */
Steve French79a58d12007-07-06 22:44:50 +0000161 rc = CIFSSMBSetEA(xid, pTcon, full_path, ea_name, ea_value,
Steve French737b7582005-04-28 22:41:06 -0700162 (__u16)value_size, cifs_sb->local_nls,
163 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
Steve Frenchb73b9a42011-04-19 18:27:10 +0000164 } else if (strncmp(ea_name, CIFS_XATTR_CIFS_ACL,
165 strlen(CIFS_XATTR_CIFS_ACL)) == 0) {
Santosh Nayakb0f8ef22012-03-02 11:47:26 +0530166#ifdef CONFIG_CIFS_ACL
167 struct cifs_ntsd *pacl;
Steve Frenchb73b9a42011-04-19 18:27:10 +0000168 pacl = kmalloc(value_size, GFP_KERNEL);
169 if (!pacl) {
Steve Frenchb73b9a42011-04-19 18:27:10 +0000170 rc = -ENOMEM;
171 } else {
Steve Frenchb73b9a42011-04-19 18:27:10 +0000172 memcpy(pacl, ea_value, value_size);
173 rc = set_cifs_acl(pacl, value_size,
Shirish Pargaonkara5ff3762011-10-13 10:26:03 -0500174 direntry->d_inode, full_path, CIFS_ACL_DACL);
Steve Frenchb73b9a42011-04-19 18:27:10 +0000175 if (rc == 0) /* force revalidate of the inode */
176 CIFS_I(direntry->d_inode)->time = 0;
177 kfree(pacl);
Santosh Nayakb0f8ef22012-03-02 11:47:26 +0530178 }
Steve Frenchb73b9a42011-04-19 18:27:10 +0000179#else
Joe Perchesf96637b2013-05-04 22:12:25 -0500180 cifs_dbg(FYI, "Set CIFS ACL not supported yet\n");
Steve Frenchb73b9a42011-04-19 18:27:10 +0000181#endif /* CONFIG_CIFS_ACL */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 } else {
Steve French79a58d12007-07-06 22:44:50 +0000183 int temp;
184 temp = strncmp(ea_name, POSIX_ACL_XATTR_ACCESS,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 strlen(POSIX_ACL_XATTR_ACCESS));
186 if (temp == 0) {
187#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,
191 ACL_TYPE_ACCESS, cifs_sb->local_nls,
192 cifs_sb->mnt_cifs_flags &
Steve French737b7582005-04-28 22:41:06 -0700193 CIFS_MOUNT_MAP_SPECIAL_CHR);
Joe Perchesf96637b2013-05-04 22:12:25 -0500194 cifs_dbg(FYI, "set POSIX ACL rc %d\n", rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195#else
Joe Perchesf96637b2013-05-04 22:12:25 -0500196 cifs_dbg(FYI, "set POSIX ACL not supported\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197#endif
Steve French79a58d12007-07-06 22:44:50 +0000198 } else if (strncmp(ea_name, POSIX_ACL_XATTR_DEFAULT,
199 strlen(POSIX_ACL_XATTR_DEFAULT)) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200#ifdef CONFIG_CIFS_POSIX
Steve French79a58d12007-07-06 22:44:50 +0000201 if (sb->s_flags & MS_POSIXACL)
202 rc = CIFSSMBSetPosixACL(xid, pTcon, full_path,
203 ea_value, (const int)value_size,
Steve French737b7582005-04-28 22:41:06 -0700204 ACL_TYPE_DEFAULT, cifs_sb->local_nls,
Steve French79a58d12007-07-06 22:44:50 +0000205 cifs_sb->mnt_cifs_flags &
Steve French737b7582005-04-28 22:41:06 -0700206 CIFS_MOUNT_MAP_SPECIAL_CHR);
Joe Perchesf96637b2013-05-04 22:12:25 -0500207 cifs_dbg(FYI, "set POSIX default ACL rc %d\n", rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208#else
Joe Perchesf96637b2013-05-04 22:12:25 -0500209 cifs_dbg(FYI, "set default POSIX ACL not supported\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210#endif
211 } else {
Joe Perchesf96637b2013-05-04 22:12:25 -0500212 cifs_dbg(FYI, "illegal xattr request %s (only user namespace supported)\n",
213 ea_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 /* BB what if no namespace prefix? */
Steve French79a58d12007-07-06 22:44:50 +0000215 /* Should we just pass them to server, except for
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 system and perhaps security prefixes? */
217 }
218 }
219
220set_ea_exit:
Jesper Juhlf99d49a2005-11-07 01:01:34 -0800221 kfree(full_path);
Pavel Shilovsky6d5786a2012-06-20 11:21:16 +0400222 free_xid(xid);
Jeff Layton7ffec372010-09-29 19:51:11 -0400223 cifs_put_tlink(tlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224#endif
225 return rc;
226}
227
Steve French79a58d12007-07-06 22:44:50 +0000228ssize_t cifs_getxattr(struct dentry *direntry, const char *ea_name,
229 void *ea_value, size_t buf_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230{
231 ssize_t rc = -EOPNOTSUPP;
232#ifdef CONFIG_CIFS_XATTR
Pavel Shilovsky6d5786a2012-06-20 11:21:16 +0400233 unsigned int xid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 struct cifs_sb_info *cifs_sb;
Jeff Layton7ffec372010-09-29 19:51:11 -0400235 struct tcon_link *tlink;
Steve French96daf2b2011-05-27 04:34:02 +0000236 struct cifs_tcon *pTcon;
Steve French79a58d12007-07-06 22:44:50 +0000237 struct super_block *sb;
238 char *full_path;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239
Steve French79a58d12007-07-06 22:44:50 +0000240 if (direntry == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 return -EIO;
Steve French79a58d12007-07-06 22:44:50 +0000242 if (direntry->d_inode == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 return -EIO;
244 sb = direntry->d_inode->i_sb;
Steve French79a58d12007-07-06 22:44:50 +0000245 if (sb == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 return -EIO;
247
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 cifs_sb = CIFS_SB(sb);
Jeff Layton7ffec372010-09-29 19:51:11 -0400249 tlink = cifs_sb_tlink(cifs_sb);
250 if (IS_ERR(tlink))
251 return PTR_ERR(tlink);
252 pTcon = tlink_tcon(tlink);
253
Pavel Shilovsky6d5786a2012-06-20 11:21:16 +0400254 xid = get_xid();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 full_path = build_path_from_dentry(direntry);
Steve French79a58d12007-07-06 22:44:50 +0000257 if (full_path == NULL) {
Suresh Jayaraman0f3bc092009-06-25 18:12:34 +0530258 rc = -ENOMEM;
Jeff Layton7ffec372010-09-29 19:51:11 -0400259 goto get_ea_exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 }
261 /* return dos attributes as pseudo xattr */
262 /* return alt name if available as pseudo attr */
Steve French79a58d12007-07-06 22:44:50 +0000263 if (ea_name == NULL) {
Joe Perchesf96637b2013-05-04 22:12:25 -0500264 cifs_dbg(FYI, "Null xattr names not supported\n");
Mimi Zoharf995e742011-08-11 16:00:47 -0400265 } else if (strncmp(ea_name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)
266 == 0) {
Steve French79a58d12007-07-06 22:44:50 +0000267 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 goto get_ea_exit;
269
Steve French79a58d12007-07-06 22:44:50 +0000270 if (strncmp(ea_name, CIFS_XATTR_DOS_ATTRIB, 14) == 0) {
Joe Perchesf96637b2013-05-04 22:12:25 -0500271 cifs_dbg(FYI, "attempt to query cifs inode metadata\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 /* revalidate/getattr then populate from inode */
273 } /* BB add else when above is implemented */
Mimi Zoharf995e742011-08-11 16:00:47 -0400274 ea_name += XATTR_USER_PREFIX_LEN; /* skip past user. prefix */
Jeff Layton31c05192010-02-10 16:18:26 -0500275 rc = CIFSSMBQAllEAs(xid, pTcon, full_path, ea_name, ea_value,
Steve French737b7582005-04-28 22:41:06 -0700276 buf_size, cifs_sb->local_nls,
277 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
Mimi Zoharf995e742011-08-11 16:00:47 -0400278 } else if (strncmp(ea_name, XATTR_OS2_PREFIX, XATTR_OS2_PREFIX_LEN) == 0) {
Steve French79a58d12007-07-06 22:44:50 +0000279 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 goto get_ea_exit;
281
Mimi Zoharf995e742011-08-11 16:00:47 -0400282 ea_name += XATTR_OS2_PREFIX_LEN; /* skip past os2. prefix */
Jeff Layton31c05192010-02-10 16:18:26 -0500283 rc = CIFSSMBQAllEAs(xid, pTcon, full_path, ea_name, ea_value,
Steve French737b7582005-04-28 22:41:06 -0700284 buf_size, cifs_sb->local_nls,
285 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
Steve French79a58d12007-07-06 22:44:50 +0000286 } else if (strncmp(ea_name, POSIX_ACL_XATTR_ACCESS,
Steve French0a4b92c2006-01-12 15:44:21 -0800287 strlen(POSIX_ACL_XATTR_ACCESS)) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288#ifdef CONFIG_CIFS_POSIX
Steve French79a58d12007-07-06 22:44:50 +0000289 if (sb->s_flags & MS_POSIXACL)
Steve French1da0c782005-04-28 22:41:04 -0700290 rc = CIFSSMBGetPosixACL(xid, pTcon, full_path,
Steve French79a58d12007-07-06 22:44:50 +0000291 ea_value, buf_size, ACL_TYPE_ACCESS,
Steve French737b7582005-04-28 22:41:06 -0700292 cifs_sb->local_nls,
Steve French79a58d12007-07-06 22:44:50 +0000293 cifs_sb->mnt_cifs_flags &
Steve French737b7582005-04-28 22:41:06 -0700294 CIFS_MOUNT_MAP_SPECIAL_CHR);
Steve French79a58d12007-07-06 22:44:50 +0000295#else
Joe Perchesf96637b2013-05-04 22:12:25 -0500296 cifs_dbg(FYI, "Query POSIX ACL not supported yet\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297#endif /* CONFIG_CIFS_POSIX */
Steve French79a58d12007-07-06 22:44:50 +0000298 } else if (strncmp(ea_name, POSIX_ACL_XATTR_DEFAULT,
Steve French0a4b92c2006-01-12 15:44:21 -0800299 strlen(POSIX_ACL_XATTR_DEFAULT)) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300#ifdef CONFIG_CIFS_POSIX
Steve French79a58d12007-07-06 22:44:50 +0000301 if (sb->s_flags & MS_POSIXACL)
Steve French1da0c782005-04-28 22:41:04 -0700302 rc = CIFSSMBGetPosixACL(xid, pTcon, full_path,
Steve French79a58d12007-07-06 22:44:50 +0000303 ea_value, buf_size, ACL_TYPE_DEFAULT,
Steve French737b7582005-04-28 22:41:06 -0700304 cifs_sb->local_nls,
Steve French79a58d12007-07-06 22:44:50 +0000305 cifs_sb->mnt_cifs_flags &
Steve French737b7582005-04-28 22:41:06 -0700306 CIFS_MOUNT_MAP_SPECIAL_CHR);
Steve French79a58d12007-07-06 22:44:50 +0000307#else
Joe Perchesf96637b2013-05-04 22:12:25 -0500308 cifs_dbg(FYI, "Query POSIX default ACL not supported yet\n");
Shirish Pargaonkarfbeba8b2010-11-27 11:37:54 -0600309#endif /* CONFIG_CIFS_POSIX */
310 } else if (strncmp(ea_name, CIFS_XATTR_CIFS_ACL,
311 strlen(CIFS_XATTR_CIFS_ACL)) == 0) {
312#ifdef CONFIG_CIFS_ACL
313 u32 acllen;
314 struct cifs_ntsd *pacl;
315
316 pacl = get_cifs_acl(cifs_sb, direntry->d_inode,
317 full_path, &acllen);
318 if (IS_ERR(pacl)) {
319 rc = PTR_ERR(pacl);
Joe Perchesf96637b2013-05-04 22:12:25 -0500320 cifs_dbg(VFS, "%s: error %zd getting sec desc\n",
321 __func__, rc);
Shirish Pargaonkarfbeba8b2010-11-27 11:37:54 -0600322 } else {
323 if (ea_value) {
324 if (acllen > buf_size)
325 acllen = -ERANGE;
326 else
327 memcpy(ea_value, pacl, acllen);
328 }
329 rc = acllen;
330 kfree(pacl);
331 }
332#else
Joe Perchesf96637b2013-05-04 22:12:25 -0500333 cifs_dbg(FYI, "Query CIFS ACL not supported yet\n");
Shirish Pargaonkarfbeba8b2010-11-27 11:37:54 -0600334#endif /* CONFIG_CIFS_ACL */
Steve French79a58d12007-07-06 22:44:50 +0000335 } else if (strncmp(ea_name,
Mimi Zoharf995e742011-08-11 16:00:47 -0400336 XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN) == 0) {
Joe Perchesf96637b2013-05-04 22:12:25 -0500337 cifs_dbg(FYI, "Trusted xattr namespace not supported yet\n");
Steve French79a58d12007-07-06 22:44:50 +0000338 } else if (strncmp(ea_name,
Mimi Zoharf995e742011-08-11 16:00:47 -0400339 XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN) == 0) {
Joe Perchesf96637b2013-05-04 22:12:25 -0500340 cifs_dbg(FYI, "Security xattr namespace not supported yet\n");
Steve Frenchad7a2922008-02-07 23:25:02 +0000341 } else
Joe Perchesf96637b2013-05-04 22:12:25 -0500342 cifs_dbg(FYI,
343 "illegal xattr request %s (only user namespace supported)\n",
344 ea_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345
Steve French79a58d12007-07-06 22:44:50 +0000346 /* We could add an additional check for streams ie
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 if proc/fs/cifs/streamstoxattr is set then
Steve French79a58d12007-07-06 22:44:50 +0000348 search server for EAs or streams to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 returns as xattrs */
350
Steve French79a58d12007-07-06 22:44:50 +0000351 if (rc == -EINVAL)
352 rc = -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353
354get_ea_exit:
Jesper Juhlf99d49a2005-11-07 01:01:34 -0800355 kfree(full_path);
Pavel Shilovsky6d5786a2012-06-20 11:21:16 +0400356 free_xid(xid);
Jeff Layton7ffec372010-09-29 19:51:11 -0400357 cifs_put_tlink(tlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358#endif
359 return rc;
360}
361
Steve French79a58d12007-07-06 22:44:50 +0000362ssize_t cifs_listxattr(struct dentry *direntry, char *data, size_t buf_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363{
364 ssize_t rc = -EOPNOTSUPP;
365#ifdef CONFIG_CIFS_XATTR
Pavel Shilovsky6d5786a2012-06-20 11:21:16 +0400366 unsigned int xid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 struct cifs_sb_info *cifs_sb;
Jeff Layton7ffec372010-09-29 19:51:11 -0400368 struct tcon_link *tlink;
Steve French96daf2b2011-05-27 04:34:02 +0000369 struct cifs_tcon *pTcon;
Steve French79a58d12007-07-06 22:44:50 +0000370 struct super_block *sb;
371 char *full_path;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372
Steve French79a58d12007-07-06 22:44:50 +0000373 if (direntry == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 return -EIO;
Steve French79a58d12007-07-06 22:44:50 +0000375 if (direntry->d_inode == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 return -EIO;
377 sb = direntry->d_inode->i_sb;
Steve French79a58d12007-07-06 22:44:50 +0000378 if (sb == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380
381 cifs_sb = CIFS_SB(sb);
Steve French79a58d12007-07-06 22:44:50 +0000382 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
Steve Frenchea4c07d2006-08-16 19:44:25 +0000383 return -EOPNOTSUPP;
384
Jeff Layton7ffec372010-09-29 19:51:11 -0400385 tlink = cifs_sb_tlink(cifs_sb);
386 if (IS_ERR(tlink))
387 return PTR_ERR(tlink);
388 pTcon = tlink_tcon(tlink);
389
Pavel Shilovsky6d5786a2012-06-20 11:21:16 +0400390 xid = get_xid();
Steve Frenchea4c07d2006-08-16 19:44:25 +0000391
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 full_path = build_path_from_dentry(direntry);
Steve French79a58d12007-07-06 22:44:50 +0000393 if (full_path == NULL) {
Suresh Jayaraman0f3bc092009-06-25 18:12:34 +0530394 rc = -ENOMEM;
Jeff Layton7ffec372010-09-29 19:51:11 -0400395 goto list_ea_exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 }
397 /* return dos attributes as pseudo xattr */
398 /* return alt name if available as pseudo attr */
399
400 /* if proc/fs/cifs/streamstoxattr is set then
Steve French79a58d12007-07-06 22:44:50 +0000401 search server for EAs or streams to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 returns as xattrs */
Jeff Layton31c05192010-02-10 16:18:26 -0500403 rc = CIFSSMBQAllEAs(xid, pTcon, full_path, NULL, data,
404 buf_size, cifs_sb->local_nls,
Steve French79a58d12007-07-06 22:44:50 +0000405 cifs_sb->mnt_cifs_flags &
Steve French737b7582005-04-28 22:41:06 -0700406 CIFS_MOUNT_MAP_SPECIAL_CHR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407
Jeff Layton7ffec372010-09-29 19:51:11 -0400408list_ea_exit:
Jesper Juhlf99d49a2005-11-07 01:01:34 -0800409 kfree(full_path);
Pavel Shilovsky6d5786a2012-06-20 11:21:16 +0400410 free_xid(xid);
Jeff Layton7ffec372010-09-29 19:51:11 -0400411 cifs_put_tlink(tlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412#endif
413 return rc;
414}