Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * fs/cifs/xattr.c |
| 3 | * |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 4 | * Copyright (c) International Business Machines Corp., 2003, 2007 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * 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 Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 24 | #include <linux/slab.h> |
Mimi Zohar | f995e74 | 2011-08-11 16:00:47 -0400 | [diff] [blame] | 25 | #include <linux/xattr.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include "cifsfs.h" |
| 27 | #include "cifspdu.h" |
| 28 | #include "cifsglob.h" |
| 29 | #include "cifsproto.h" |
| 30 | #include "cifs_debug.h" |
Steve French | 2baa268 | 2014-09-27 02:19:01 -0500 | [diff] [blame] | 31 | #include "cifs_fs_sb.h" |
| 32 | #include "cifs_unicode.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
| 34 | #define MAX_EA_VALUE_SIZE 65535 |
Shirish Pargaonkar | fbeba8b | 2010-11-27 11:37:54 -0600 | [diff] [blame] | 35 | #define CIFS_XATTR_CIFS_ACL "system.cifs_acl" |
Mimi Zohar | f995e74 | 2011-08-11 16:00:47 -0400 | [diff] [blame] | 36 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | /* BB need to add server (Samba e.g) support for security and trusted prefix */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 38 | |
Andreas Gruenbacher | a9ae008 | 2016-04-22 12:11:38 +0200 | [diff] [blame] | 39 | enum { XATTR_USER, XATTR_CIFS_ACL, XATTR_ACL_ACCESS, XATTR_ACL_DEFAULT }; |
| 40 | |
| 41 | static int cifs_xattr_set(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 42 | struct dentry *dentry, struct inode *inode, |
| 43 | const char *name, const void *value, |
| 44 | size_t size, int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | { |
| 46 | int rc = -EOPNOTSUPP; |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 47 | unsigned int xid; |
Andreas Gruenbacher | a9ae008 | 2016-04-22 12:11:38 +0200 | [diff] [blame] | 48 | struct super_block *sb = dentry->d_sb; |
Al Viro | 5fdccfe | 2016-04-10 17:07:33 -0400 | [diff] [blame] | 49 | struct cifs_sb_info *cifs_sb = CIFS_SB(sb); |
Jeff Layton | 7ffec37 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 50 | struct tcon_link *tlink; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 51 | struct cifs_tcon *pTcon; |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 52 | char *full_path; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
Jeff Layton | 7ffec37 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 54 | tlink = cifs_sb_tlink(cifs_sb); |
| 55 | if (IS_ERR(tlink)) |
| 56 | return PTR_ERR(tlink); |
| 57 | pTcon = tlink_tcon(tlink); |
| 58 | |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 59 | xid = get_xid(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | |
Andreas Gruenbacher | a9ae008 | 2016-04-22 12:11:38 +0200 | [diff] [blame] | 61 | full_path = build_path_from_dentry(dentry); |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 62 | if (full_path == NULL) { |
Suresh Jayaraman | 0f3bc09 | 2009-06-25 18:12:34 +0530 | [diff] [blame] | 63 | rc = -ENOMEM; |
Andreas Gruenbacher | a9ae008 | 2016-04-22 12:11:38 +0200 | [diff] [blame] | 64 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | } |
| 66 | /* return dos attributes as pseudo xattr */ |
| 67 | /* return alt name if available as pseudo attr */ |
| 68 | |
| 69 | /* if proc/fs/cifs/streamstoxattr is set then |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 70 | search server for EAs or streams to |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | returns as xattrs */ |
Andreas Gruenbacher | a9ae008 | 2016-04-22 12:11:38 +0200 | [diff] [blame] | 72 | if (size > MAX_EA_VALUE_SIZE) { |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 73 | cifs_dbg(FYI, "size of EA value too large\n"); |
Jeff Layton | 7ffec37 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 74 | rc = -EOPNOTSUPP; |
Andreas Gruenbacher | a9ae008 | 2016-04-22 12:11:38 +0200 | [diff] [blame] | 75 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | } |
| 77 | |
Andreas Gruenbacher | a9ae008 | 2016-04-22 12:11:38 +0200 | [diff] [blame] | 78 | switch (handler->flags) { |
| 79 | case XATTR_USER: |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 80 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR) |
Andreas Gruenbacher | a9ae008 | 2016-04-22 12:11:38 +0200 | [diff] [blame] | 81 | goto out; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 82 | |
Steve French | 666753c | 2014-01-26 23:53:43 -0600 | [diff] [blame] | 83 | if (pTcon->ses->server->ops->set_EA) |
| 84 | rc = pTcon->ses->server->ops->set_EA(xid, pTcon, |
Andreas Gruenbacher | a9ae008 | 2016-04-22 12:11:38 +0200 | [diff] [blame] | 85 | full_path, name, value, (__u16)size, |
Steve French | 2baa268 | 2014-09-27 02:19:01 -0500 | [diff] [blame] | 86 | cifs_sb->local_nls, cifs_remap(cifs_sb)); |
Andreas Gruenbacher | a9ae008 | 2016-04-22 12:11:38 +0200 | [diff] [blame] | 87 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
Andreas Gruenbacher | a9ae008 | 2016-04-22 12:11:38 +0200 | [diff] [blame] | 89 | case XATTR_CIFS_ACL: { |
Santosh Nayak | b0f8ef2 | 2012-03-02 11:47:26 +0530 | [diff] [blame] | 90 | #ifdef CONFIG_CIFS_ACL |
| 91 | struct cifs_ntsd *pacl; |
Andreas Gruenbacher | a9ae008 | 2016-04-22 12:11:38 +0200 | [diff] [blame] | 92 | |
| 93 | if (!value) |
| 94 | goto out; |
| 95 | pacl = kmalloc(size, GFP_KERNEL); |
Steve French | b73b9a4 | 2011-04-19 18:27:10 +0000 | [diff] [blame] | 96 | if (!pacl) { |
Steve French | b73b9a4 | 2011-04-19 18:27:10 +0000 | [diff] [blame] | 97 | rc = -ENOMEM; |
| 98 | } else { |
Andreas Gruenbacher | a9ae008 | 2016-04-22 12:11:38 +0200 | [diff] [blame] | 99 | memcpy(pacl, value, size); |
| 100 | if (value && |
| 101 | pTcon->ses->server->ops->set_acl) |
Steve French | 83e3bc2 | 2014-02-02 23:31:47 -0600 | [diff] [blame] | 102 | rc = pTcon->ses->server->ops->set_acl(pacl, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 103 | size, inode, |
Steve French | 83e3bc2 | 2014-02-02 23:31:47 -0600 | [diff] [blame] | 104 | full_path, CIFS_ACL_DACL); |
| 105 | else |
| 106 | rc = -EOPNOTSUPP; |
Steve French | b73b9a4 | 2011-04-19 18:27:10 +0000 | [diff] [blame] | 107 | if (rc == 0) /* force revalidate of the inode */ |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 108 | CIFS_I(inode)->time = 0; |
Steve French | b73b9a4 | 2011-04-19 18:27:10 +0000 | [diff] [blame] | 109 | kfree(pacl); |
Santosh Nayak | b0f8ef2 | 2012-03-02 11:47:26 +0530 | [diff] [blame] | 110 | } |
Steve French | b73b9a4 | 2011-04-19 18:27:10 +0000 | [diff] [blame] | 111 | #endif /* CONFIG_CIFS_ACL */ |
Andreas Gruenbacher | a9ae008 | 2016-04-22 12:11:38 +0200 | [diff] [blame] | 112 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | } |
| 114 | |
Andreas Gruenbacher | a9ae008 | 2016-04-22 12:11:38 +0200 | [diff] [blame] | 115 | case XATTR_ACL_ACCESS: |
| 116 | #ifdef CONFIG_CIFS_POSIX |
| 117 | if (!value) |
| 118 | goto out; |
| 119 | if (sb->s_flags & MS_POSIXACL) |
| 120 | rc = CIFSSMBSetPosixACL(xid, pTcon, full_path, |
| 121 | value, (const int)size, |
| 122 | ACL_TYPE_ACCESS, cifs_sb->local_nls, |
| 123 | cifs_remap(cifs_sb)); |
| 124 | #endif /* CONFIG_CIFS_POSIX */ |
| 125 | break; |
| 126 | |
| 127 | case XATTR_ACL_DEFAULT: |
| 128 | #ifdef CONFIG_CIFS_POSIX |
| 129 | if (!value) |
| 130 | goto out; |
| 131 | if (sb->s_flags & MS_POSIXACL) |
| 132 | rc = CIFSSMBSetPosixACL(xid, pTcon, full_path, |
| 133 | value, (const int)size, |
| 134 | ACL_TYPE_DEFAULT, cifs_sb->local_nls, |
| 135 | cifs_remap(cifs_sb)); |
| 136 | #endif /* CONFIG_CIFS_POSIX */ |
| 137 | break; |
| 138 | } |
| 139 | |
| 140 | out: |
Jesper Juhl | f99d49a | 2005-11-07 01:01:34 -0800 | [diff] [blame] | 141 | kfree(full_path); |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 142 | free_xid(xid); |
Jeff Layton | 7ffec37 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 143 | cifs_put_tlink(tlink); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | return rc; |
| 145 | } |
| 146 | |
Andreas Gruenbacher | a9ae008 | 2016-04-22 12:11:38 +0200 | [diff] [blame] | 147 | static int cifs_xattr_get(const struct xattr_handler *handler, |
| 148 | struct dentry *dentry, struct inode *inode, |
| 149 | const char *name, void *value, size_t size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | { |
| 151 | ssize_t rc = -EOPNOTSUPP; |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 152 | unsigned int xid; |
Andreas Gruenbacher | a9ae008 | 2016-04-22 12:11:38 +0200 | [diff] [blame] | 153 | struct super_block *sb = dentry->d_sb; |
Al Viro | 5fdccfe | 2016-04-10 17:07:33 -0400 | [diff] [blame] | 154 | struct cifs_sb_info *cifs_sb = CIFS_SB(sb); |
Jeff Layton | 7ffec37 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 155 | struct tcon_link *tlink; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 156 | struct cifs_tcon *pTcon; |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 157 | char *full_path; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | |
Jeff Layton | 7ffec37 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 159 | tlink = cifs_sb_tlink(cifs_sb); |
| 160 | if (IS_ERR(tlink)) |
| 161 | return PTR_ERR(tlink); |
| 162 | pTcon = tlink_tcon(tlink); |
| 163 | |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 164 | xid = get_xid(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | |
Andreas Gruenbacher | a9ae008 | 2016-04-22 12:11:38 +0200 | [diff] [blame] | 166 | full_path = build_path_from_dentry(dentry); |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 167 | if (full_path == NULL) { |
Suresh Jayaraman | 0f3bc09 | 2009-06-25 18:12:34 +0530 | [diff] [blame] | 168 | rc = -ENOMEM; |
Andreas Gruenbacher | a9ae008 | 2016-04-22 12:11:38 +0200 | [diff] [blame] | 169 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | } |
| 171 | /* return dos attributes as pseudo xattr */ |
| 172 | /* return alt name if available as pseudo attr */ |
Andreas Gruenbacher | a9ae008 | 2016-04-22 12:11:38 +0200 | [diff] [blame] | 173 | switch (handler->flags) { |
| 174 | case XATTR_USER: |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 175 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR) |
Andreas Gruenbacher | a9ae008 | 2016-04-22 12:11:38 +0200 | [diff] [blame] | 176 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | |
Steve French | 666753c | 2014-01-26 23:53:43 -0600 | [diff] [blame] | 178 | if (pTcon->ses->server->ops->query_all_EAs) |
| 179 | rc = pTcon->ses->server->ops->query_all_EAs(xid, pTcon, |
Andreas Gruenbacher | a9ae008 | 2016-04-22 12:11:38 +0200 | [diff] [blame] | 180 | full_path, name, value, size, |
Steve French | 2baa268 | 2014-09-27 02:19:01 -0500 | [diff] [blame] | 181 | cifs_sb->local_nls, cifs_remap(cifs_sb)); |
Andreas Gruenbacher | a9ae008 | 2016-04-22 12:11:38 +0200 | [diff] [blame] | 182 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | |
Andreas Gruenbacher | a9ae008 | 2016-04-22 12:11:38 +0200 | [diff] [blame] | 184 | case XATTR_CIFS_ACL: { |
Shirish Pargaonkar | fbeba8b | 2010-11-27 11:37:54 -0600 | [diff] [blame] | 185 | #ifdef CONFIG_CIFS_ACL |
Andreas Gruenbacher | a9ae008 | 2016-04-22 12:11:38 +0200 | [diff] [blame] | 186 | u32 acllen; |
| 187 | struct cifs_ntsd *pacl; |
Shirish Pargaonkar | fbeba8b | 2010-11-27 11:37:54 -0600 | [diff] [blame] | 188 | |
Andreas Gruenbacher | a9ae008 | 2016-04-22 12:11:38 +0200 | [diff] [blame] | 189 | if (pTcon->ses->server->ops->get_acl == NULL) |
| 190 | goto out; /* rc already EOPNOTSUPP */ |
Steve French | 83e3bc2 | 2014-02-02 23:31:47 -0600 | [diff] [blame] | 191 | |
Andreas Gruenbacher | a9ae008 | 2016-04-22 12:11:38 +0200 | [diff] [blame] | 192 | pacl = pTcon->ses->server->ops->get_acl(cifs_sb, |
| 193 | inode, full_path, &acllen); |
| 194 | if (IS_ERR(pacl)) { |
| 195 | rc = PTR_ERR(pacl); |
| 196 | cifs_dbg(VFS, "%s: error %zd getting sec desc\n", |
| 197 | __func__, rc); |
| 198 | } else { |
| 199 | if (value) { |
| 200 | if (acllen > size) |
| 201 | acllen = -ERANGE; |
| 202 | else |
| 203 | memcpy(value, pacl, acllen); |
Shirish Pargaonkar | fbeba8b | 2010-11-27 11:37:54 -0600 | [diff] [blame] | 204 | } |
Andreas Gruenbacher | a9ae008 | 2016-04-22 12:11:38 +0200 | [diff] [blame] | 205 | rc = acllen; |
| 206 | kfree(pacl); |
| 207 | } |
| 208 | #endif /* CONFIG_CIFS_ACL */ |
| 209 | break; |
| 210 | } |
| 211 | |
| 212 | case XATTR_ACL_ACCESS: |
| 213 | #ifdef CONFIG_CIFS_POSIX |
| 214 | if (sb->s_flags & MS_POSIXACL) |
| 215 | rc = CIFSSMBGetPosixACL(xid, pTcon, full_path, |
| 216 | value, size, ACL_TYPE_ACCESS, |
| 217 | cifs_sb->local_nls, |
| 218 | cifs_remap(cifs_sb)); |
| 219 | #endif /* CONFIG_CIFS_POSIX */ |
| 220 | break; |
| 221 | |
| 222 | case XATTR_ACL_DEFAULT: |
| 223 | #ifdef CONFIG_CIFS_POSIX |
| 224 | if (sb->s_flags & MS_POSIXACL) |
| 225 | rc = CIFSSMBGetPosixACL(xid, pTcon, full_path, |
| 226 | value, size, ACL_TYPE_DEFAULT, |
| 227 | cifs_sb->local_nls, |
| 228 | cifs_remap(cifs_sb)); |
| 229 | #endif /* CONFIG_CIFS_POSIX */ |
| 230 | break; |
| 231 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 233 | /* We could add an additional check for streams ie |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | if proc/fs/cifs/streamstoxattr is set then |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 235 | search server for EAs or streams to |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | returns as xattrs */ |
| 237 | |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 238 | if (rc == -EINVAL) |
| 239 | rc = -EOPNOTSUPP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | |
Andreas Gruenbacher | a9ae008 | 2016-04-22 12:11:38 +0200 | [diff] [blame] | 241 | out: |
Jesper Juhl | f99d49a | 2005-11-07 01:01:34 -0800 | [diff] [blame] | 242 | kfree(full_path); |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 243 | free_xid(xid); |
Jeff Layton | 7ffec37 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 244 | cifs_put_tlink(tlink); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | return rc; |
| 246 | } |
| 247 | |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 248 | ssize_t cifs_listxattr(struct dentry *direntry, char *data, size_t buf_size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | { |
| 250 | ssize_t rc = -EOPNOTSUPP; |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 251 | unsigned int xid; |
Al Viro | 5fdccfe | 2016-04-10 17:07:33 -0400 | [diff] [blame] | 252 | struct cifs_sb_info *cifs_sb = CIFS_SB(direntry->d_sb); |
Jeff Layton | 7ffec37 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 253 | struct tcon_link *tlink; |
Steve French | 96daf2b | 2011-05-27 04:34:02 +0000 | [diff] [blame] | 254 | struct cifs_tcon *pTcon; |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 255 | char *full_path; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 257 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR) |
Steve French | ea4c07d | 2006-08-16 19:44:25 +0000 | [diff] [blame] | 258 | return -EOPNOTSUPP; |
| 259 | |
Jeff Layton | 7ffec37 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 260 | tlink = cifs_sb_tlink(cifs_sb); |
| 261 | if (IS_ERR(tlink)) |
| 262 | return PTR_ERR(tlink); |
| 263 | pTcon = tlink_tcon(tlink); |
| 264 | |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 265 | xid = get_xid(); |
Steve French | ea4c07d | 2006-08-16 19:44:25 +0000 | [diff] [blame] | 266 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | full_path = build_path_from_dentry(direntry); |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 268 | if (full_path == NULL) { |
Suresh Jayaraman | 0f3bc09 | 2009-06-25 18:12:34 +0530 | [diff] [blame] | 269 | rc = -ENOMEM; |
Jeff Layton | 7ffec37 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 270 | goto list_ea_exit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | } |
| 272 | /* return dos attributes as pseudo xattr */ |
| 273 | /* return alt name if available as pseudo attr */ |
| 274 | |
| 275 | /* if proc/fs/cifs/streamstoxattr is set then |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 276 | search server for EAs or streams to |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | returns as xattrs */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | |
Steve French | 666753c | 2014-01-26 23:53:43 -0600 | [diff] [blame] | 279 | if (pTcon->ses->server->ops->query_all_EAs) |
| 280 | rc = pTcon->ses->server->ops->query_all_EAs(xid, pTcon, |
| 281 | full_path, NULL, data, buf_size, |
Steve French | 2baa268 | 2014-09-27 02:19:01 -0500 | [diff] [blame] | 282 | cifs_sb->local_nls, cifs_remap(cifs_sb)); |
Jeff Layton | 7ffec37 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 283 | list_ea_exit: |
Jesper Juhl | f99d49a | 2005-11-07 01:01:34 -0800 | [diff] [blame] | 284 | kfree(full_path); |
Pavel Shilovsky | 6d5786a | 2012-06-20 11:21:16 +0400 | [diff] [blame] | 285 | free_xid(xid); |
Jeff Layton | 7ffec37 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 286 | cifs_put_tlink(tlink); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | return rc; |
| 288 | } |
Andreas Gruenbacher | a9ae008 | 2016-04-22 12:11:38 +0200 | [diff] [blame] | 289 | |
| 290 | static const struct xattr_handler cifs_user_xattr_handler = { |
| 291 | .prefix = XATTR_USER_PREFIX, |
| 292 | .flags = XATTR_USER, |
| 293 | .get = cifs_xattr_get, |
| 294 | .set = cifs_xattr_set, |
| 295 | }; |
| 296 | |
| 297 | /* os2.* attributes are treated like user.* attributes */ |
| 298 | static const struct xattr_handler cifs_os2_xattr_handler = { |
| 299 | .prefix = XATTR_OS2_PREFIX, |
| 300 | .flags = XATTR_USER, |
| 301 | .get = cifs_xattr_get, |
| 302 | .set = cifs_xattr_set, |
| 303 | }; |
| 304 | |
| 305 | static const struct xattr_handler cifs_cifs_acl_xattr_handler = { |
| 306 | .name = CIFS_XATTR_CIFS_ACL, |
| 307 | .flags = XATTR_CIFS_ACL, |
| 308 | .get = cifs_xattr_get, |
| 309 | .set = cifs_xattr_set, |
| 310 | }; |
| 311 | |
| 312 | static const struct xattr_handler cifs_posix_acl_access_xattr_handler = { |
| 313 | .name = XATTR_NAME_POSIX_ACL_ACCESS, |
| 314 | .flags = XATTR_ACL_ACCESS, |
| 315 | .get = cifs_xattr_get, |
| 316 | .set = cifs_xattr_set, |
| 317 | }; |
| 318 | |
| 319 | static const struct xattr_handler cifs_posix_acl_default_xattr_handler = { |
| 320 | .name = XATTR_NAME_POSIX_ACL_DEFAULT, |
| 321 | .flags = XATTR_ACL_DEFAULT, |
| 322 | .get = cifs_xattr_get, |
| 323 | .set = cifs_xattr_set, |
| 324 | }; |
| 325 | |
| 326 | const struct xattr_handler *cifs_xattr_handlers[] = { |
| 327 | &cifs_user_xattr_handler, |
| 328 | &cifs_os2_xattr_handler, |
| 329 | &cifs_cifs_acl_xattr_handler, |
| 330 | &cifs_posix_acl_access_xattr_handler, |
| 331 | &cifs_posix_acl_default_xattr_handler, |
| 332 | NULL |
| 333 | }; |