blob: 5ac836a86b1885d4e1766e831a1b56d3a263e277 [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);
Steve French83e3bc22014-02-02 23:31:47 -0600179 if (pTcon->ses->server->ops->set_acl)
180 rc = pTcon->ses->server->ops->set_acl(pacl,
181 value_size, direntry->d_inode,
182 full_path, CIFS_ACL_DACL);
183 else
184 rc = -EOPNOTSUPP;
Steve Frenchb73b9a42011-04-19 18:27:10 +0000185 if (rc == 0) /* force revalidate of the inode */
186 CIFS_I(direntry->d_inode)->time = 0;
187 kfree(pacl);
Santosh Nayakb0f8ef22012-03-02 11:47:26 +0530188 }
Steve Frenchb73b9a42011-04-19 18:27:10 +0000189#else
Joe Perchesf96637b2013-05-04 22:12:25 -0500190 cifs_dbg(FYI, "Set CIFS ACL not supported yet\n");
Steve Frenchb73b9a42011-04-19 18:27:10 +0000191#endif /* CONFIG_CIFS_ACL */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 } else {
Steve French79a58d12007-07-06 22:44:50 +0000193 int temp;
194 temp = strncmp(ea_name, POSIX_ACL_XATTR_ACCESS,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 strlen(POSIX_ACL_XATTR_ACCESS));
196 if (temp == 0) {
197#ifdef CONFIG_CIFS_POSIX
Steve French79a58d12007-07-06 22:44:50 +0000198 if (sb->s_flags & MS_POSIXACL)
199 rc = CIFSSMBSetPosixACL(xid, pTcon, full_path,
200 ea_value, (const int)value_size,
201 ACL_TYPE_ACCESS, cifs_sb->local_nls,
202 cifs_sb->mnt_cifs_flags &
Steve French737b7582005-04-28 22:41:06 -0700203 CIFS_MOUNT_MAP_SPECIAL_CHR);
Joe Perchesf96637b2013-05-04 22:12:25 -0500204 cifs_dbg(FYI, "set POSIX ACL rc %d\n", rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205#else
Joe Perchesf96637b2013-05-04 22:12:25 -0500206 cifs_dbg(FYI, "set POSIX ACL not supported\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207#endif
Steve French79a58d12007-07-06 22:44:50 +0000208 } else if (strncmp(ea_name, POSIX_ACL_XATTR_DEFAULT,
209 strlen(POSIX_ACL_XATTR_DEFAULT)) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210#ifdef CONFIG_CIFS_POSIX
Steve French79a58d12007-07-06 22:44:50 +0000211 if (sb->s_flags & MS_POSIXACL)
212 rc = CIFSSMBSetPosixACL(xid, pTcon, full_path,
213 ea_value, (const int)value_size,
Steve French737b7582005-04-28 22:41:06 -0700214 ACL_TYPE_DEFAULT, cifs_sb->local_nls,
Steve French79a58d12007-07-06 22:44:50 +0000215 cifs_sb->mnt_cifs_flags &
Steve French737b7582005-04-28 22:41:06 -0700216 CIFS_MOUNT_MAP_SPECIAL_CHR);
Joe Perchesf96637b2013-05-04 22:12:25 -0500217 cifs_dbg(FYI, "set POSIX default ACL rc %d\n", rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218#else
Joe Perchesf96637b2013-05-04 22:12:25 -0500219 cifs_dbg(FYI, "set default POSIX ACL not supported\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220#endif
221 } else {
Joe Perchesf96637b2013-05-04 22:12:25 -0500222 cifs_dbg(FYI, "illegal xattr request %s (only user namespace supported)\n",
223 ea_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 /* BB what if no namespace prefix? */
Steve French79a58d12007-07-06 22:44:50 +0000225 /* Should we just pass them to server, except for
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 system and perhaps security prefixes? */
227 }
228 }
229
230set_ea_exit:
Jesper Juhlf99d49a2005-11-07 01:01:34 -0800231 kfree(full_path);
Pavel Shilovsky6d5786a2012-06-20 11:21:16 +0400232 free_xid(xid);
Jeff Layton7ffec372010-09-29 19:51:11 -0400233 cifs_put_tlink(tlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234#endif
235 return rc;
236}
237
Steve French79a58d12007-07-06 22:44:50 +0000238ssize_t cifs_getxattr(struct dentry *direntry, const char *ea_name,
239 void *ea_value, size_t buf_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240{
241 ssize_t rc = -EOPNOTSUPP;
242#ifdef CONFIG_CIFS_XATTR
Pavel Shilovsky6d5786a2012-06-20 11:21:16 +0400243 unsigned int xid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 struct cifs_sb_info *cifs_sb;
Jeff Layton7ffec372010-09-29 19:51:11 -0400245 struct tcon_link *tlink;
Steve French96daf2b2011-05-27 04:34:02 +0000246 struct cifs_tcon *pTcon;
Steve French79a58d12007-07-06 22:44:50 +0000247 struct super_block *sb;
248 char *full_path;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249
Steve French79a58d12007-07-06 22:44:50 +0000250 if (direntry == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 return -EIO;
Steve French79a58d12007-07-06 22:44:50 +0000252 if (direntry->d_inode == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 return -EIO;
254 sb = direntry->d_inode->i_sb;
Steve French79a58d12007-07-06 22:44:50 +0000255 if (sb == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 return -EIO;
257
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 cifs_sb = CIFS_SB(sb);
Jeff Layton7ffec372010-09-29 19:51:11 -0400259 tlink = cifs_sb_tlink(cifs_sb);
260 if (IS_ERR(tlink))
261 return PTR_ERR(tlink);
262 pTcon = tlink_tcon(tlink);
263
Pavel Shilovsky6d5786a2012-06-20 11:21:16 +0400264 xid = get_xid();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 full_path = build_path_from_dentry(direntry);
Steve French79a58d12007-07-06 22:44:50 +0000267 if (full_path == NULL) {
Suresh Jayaraman0f3bc092009-06-25 18:12:34 +0530268 rc = -ENOMEM;
Jeff Layton7ffec372010-09-29 19:51:11 -0400269 goto get_ea_exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 }
271 /* return dos attributes as pseudo xattr */
272 /* return alt name if available as pseudo attr */
Steve French79a58d12007-07-06 22:44:50 +0000273 if (ea_name == NULL) {
Joe Perchesf96637b2013-05-04 22:12:25 -0500274 cifs_dbg(FYI, "Null xattr names not supported\n");
Mimi Zoharf995e742011-08-11 16:00:47 -0400275 } else if (strncmp(ea_name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)
276 == 0) {
Steve French79a58d12007-07-06 22:44:50 +0000277 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 goto get_ea_exit;
279
Steve French79a58d12007-07-06 22:44:50 +0000280 if (strncmp(ea_name, CIFS_XATTR_DOS_ATTRIB, 14) == 0) {
Joe Perchesf96637b2013-05-04 22:12:25 -0500281 cifs_dbg(FYI, "attempt to query cifs inode metadata\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 /* revalidate/getattr then populate from inode */
283 } /* BB add else when above is implemented */
Mimi Zoharf995e742011-08-11 16:00:47 -0400284 ea_name += XATTR_USER_PREFIX_LEN; /* skip past user. prefix */
Steve French666753c2014-01-26 23:53:43 -0600285 if (pTcon->ses->server->ops->query_all_EAs)
286 rc = pTcon->ses->server->ops->query_all_EAs(xid, pTcon,
287 full_path, ea_name, ea_value, buf_size,
288 cifs_sb->local_nls, cifs_sb->mnt_cifs_flags &
289 CIFS_MOUNT_MAP_SPECIAL_CHR);
Mimi Zoharf995e742011-08-11 16:00:47 -0400290 } else if (strncmp(ea_name, XATTR_OS2_PREFIX, XATTR_OS2_PREFIX_LEN) == 0) {
Steve French79a58d12007-07-06 22:44:50 +0000291 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 goto get_ea_exit;
293
Mimi Zoharf995e742011-08-11 16:00:47 -0400294 ea_name += XATTR_OS2_PREFIX_LEN; /* skip past os2. prefix */
Steve French666753c2014-01-26 23:53:43 -0600295 if (pTcon->ses->server->ops->query_all_EAs)
296 rc = pTcon->ses->server->ops->query_all_EAs(xid, pTcon,
297 full_path, ea_name, ea_value, buf_size,
298 cifs_sb->local_nls, cifs_sb->mnt_cifs_flags &
299 CIFS_MOUNT_MAP_SPECIAL_CHR);
Steve French79a58d12007-07-06 22:44:50 +0000300 } else if (strncmp(ea_name, POSIX_ACL_XATTR_ACCESS,
Steve French0a4b92c2006-01-12 15:44:21 -0800301 strlen(POSIX_ACL_XATTR_ACCESS)) == 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_ACCESS,
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
Joe Perchesf96637b2013-05-04 22:12:25 -0500310 cifs_dbg(FYI, "Query POSIX ACL not supported yet\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311#endif /* CONFIG_CIFS_POSIX */
Steve French79a58d12007-07-06 22:44:50 +0000312 } else if (strncmp(ea_name, POSIX_ACL_XATTR_DEFAULT,
Steve French0a4b92c2006-01-12 15:44:21 -0800313 strlen(POSIX_ACL_XATTR_DEFAULT)) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314#ifdef CONFIG_CIFS_POSIX
Steve French79a58d12007-07-06 22:44:50 +0000315 if (sb->s_flags & MS_POSIXACL)
Steve French1da0c782005-04-28 22:41:04 -0700316 rc = CIFSSMBGetPosixACL(xid, pTcon, full_path,
Steve French79a58d12007-07-06 22:44:50 +0000317 ea_value, buf_size, ACL_TYPE_DEFAULT,
Steve French737b7582005-04-28 22:41:06 -0700318 cifs_sb->local_nls,
Steve French79a58d12007-07-06 22:44:50 +0000319 cifs_sb->mnt_cifs_flags &
Steve French737b7582005-04-28 22:41:06 -0700320 CIFS_MOUNT_MAP_SPECIAL_CHR);
Steve French79a58d12007-07-06 22:44:50 +0000321#else
Joe Perchesf96637b2013-05-04 22:12:25 -0500322 cifs_dbg(FYI, "Query POSIX default ACL not supported yet\n");
Shirish Pargaonkarfbeba8b2010-11-27 11:37:54 -0600323#endif /* CONFIG_CIFS_POSIX */
324 } else if (strncmp(ea_name, CIFS_XATTR_CIFS_ACL,
325 strlen(CIFS_XATTR_CIFS_ACL)) == 0) {
326#ifdef CONFIG_CIFS_ACL
327 u32 acllen;
328 struct cifs_ntsd *pacl;
329
Steve French83e3bc22014-02-02 23:31:47 -0600330 if (pTcon->ses->server->ops->get_acl == NULL)
331 goto get_ea_exit; /* rc already EOPNOTSUPP */
332
333 pacl = pTcon->ses->server->ops->get_acl(cifs_sb,
334 direntry->d_inode, full_path, &acllen);
Shirish Pargaonkarfbeba8b2010-11-27 11:37:54 -0600335 if (IS_ERR(pacl)) {
336 rc = PTR_ERR(pacl);
Joe Perchesf96637b2013-05-04 22:12:25 -0500337 cifs_dbg(VFS, "%s: error %zd getting sec desc\n",
338 __func__, rc);
Shirish Pargaonkarfbeba8b2010-11-27 11:37:54 -0600339 } else {
340 if (ea_value) {
341 if (acllen > buf_size)
342 acllen = -ERANGE;
343 else
344 memcpy(ea_value, pacl, acllen);
345 }
346 rc = acllen;
347 kfree(pacl);
348 }
349#else
Joe Perchesf96637b2013-05-04 22:12:25 -0500350 cifs_dbg(FYI, "Query CIFS ACL not supported yet\n");
Shirish Pargaonkarfbeba8b2010-11-27 11:37:54 -0600351#endif /* CONFIG_CIFS_ACL */
Steve French79a58d12007-07-06 22:44:50 +0000352 } else if (strncmp(ea_name,
Mimi Zoharf995e742011-08-11 16:00:47 -0400353 XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN) == 0) {
Joe Perchesf96637b2013-05-04 22:12:25 -0500354 cifs_dbg(FYI, "Trusted xattr namespace not supported yet\n");
Steve French79a58d12007-07-06 22:44:50 +0000355 } else if (strncmp(ea_name,
Mimi Zoharf995e742011-08-11 16:00:47 -0400356 XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN) == 0) {
Joe Perchesf96637b2013-05-04 22:12:25 -0500357 cifs_dbg(FYI, "Security xattr namespace not supported yet\n");
Steve Frenchad7a2922008-02-07 23:25:02 +0000358 } else
Joe Perchesf96637b2013-05-04 22:12:25 -0500359 cifs_dbg(FYI,
360 "illegal xattr request %s (only user namespace supported)\n",
361 ea_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362
Steve French79a58d12007-07-06 22:44:50 +0000363 /* We could add an additional check for streams ie
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 if proc/fs/cifs/streamstoxattr is set then
Steve French79a58d12007-07-06 22:44:50 +0000365 search server for EAs or streams to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 returns as xattrs */
367
Steve French79a58d12007-07-06 22:44:50 +0000368 if (rc == -EINVAL)
369 rc = -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370
371get_ea_exit:
Jesper Juhlf99d49a2005-11-07 01:01:34 -0800372 kfree(full_path);
Pavel Shilovsky6d5786a2012-06-20 11:21:16 +0400373 free_xid(xid);
Jeff Layton7ffec372010-09-29 19:51:11 -0400374 cifs_put_tlink(tlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375#endif
376 return rc;
377}
378
Steve French79a58d12007-07-06 22:44:50 +0000379ssize_t cifs_listxattr(struct dentry *direntry, char *data, size_t buf_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380{
381 ssize_t rc = -EOPNOTSUPP;
382#ifdef CONFIG_CIFS_XATTR
Pavel Shilovsky6d5786a2012-06-20 11:21:16 +0400383 unsigned int xid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 struct cifs_sb_info *cifs_sb;
Jeff Layton7ffec372010-09-29 19:51:11 -0400385 struct tcon_link *tlink;
Steve French96daf2b2011-05-27 04:34:02 +0000386 struct cifs_tcon *pTcon;
Steve French79a58d12007-07-06 22:44:50 +0000387 struct super_block *sb;
388 char *full_path;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389
Steve French79a58d12007-07-06 22:44:50 +0000390 if (direntry == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 return -EIO;
Steve French79a58d12007-07-06 22:44:50 +0000392 if (direntry->d_inode == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 return -EIO;
394 sb = direntry->d_inode->i_sb;
Steve French79a58d12007-07-06 22:44:50 +0000395 if (sb == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397
398 cifs_sb = CIFS_SB(sb);
Steve French79a58d12007-07-06 22:44:50 +0000399 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
Steve Frenchea4c07d2006-08-16 19:44:25 +0000400 return -EOPNOTSUPP;
401
Jeff Layton7ffec372010-09-29 19:51:11 -0400402 tlink = cifs_sb_tlink(cifs_sb);
403 if (IS_ERR(tlink))
404 return PTR_ERR(tlink);
405 pTcon = tlink_tcon(tlink);
406
Pavel Shilovsky6d5786a2012-06-20 11:21:16 +0400407 xid = get_xid();
Steve Frenchea4c07d2006-08-16 19:44:25 +0000408
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 full_path = build_path_from_dentry(direntry);
Steve French79a58d12007-07-06 22:44:50 +0000410 if (full_path == NULL) {
Suresh Jayaraman0f3bc092009-06-25 18:12:34 +0530411 rc = -ENOMEM;
Jeff Layton7ffec372010-09-29 19:51:11 -0400412 goto list_ea_exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 }
414 /* return dos attributes as pseudo xattr */
415 /* return alt name if available as pseudo attr */
416
417 /* if proc/fs/cifs/streamstoxattr is set then
Steve French79a58d12007-07-06 22:44:50 +0000418 search server for EAs or streams to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 returns as xattrs */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420
Steve French666753c2014-01-26 23:53:43 -0600421 if (pTcon->ses->server->ops->query_all_EAs)
422 rc = pTcon->ses->server->ops->query_all_EAs(xid, pTcon,
423 full_path, NULL, data, buf_size,
424 cifs_sb->local_nls, cifs_sb->mnt_cifs_flags &
425 CIFS_MOUNT_MAP_SPECIAL_CHR);
Jeff Layton7ffec372010-09-29 19:51:11 -0400426list_ea_exit:
Jesper Juhlf99d49a2005-11-07 01:01:34 -0800427 kfree(full_path);
Pavel Shilovsky6d5786a2012-06-20 11:21:16 +0400428 free_xid(xid);
Jeff Layton7ffec372010-09-29 19:51:11 -0400429 cifs_put_tlink(tlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430#endif
431 return rc;
432}