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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #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 Pargaonkar | fbeba8b | 2010-11-27 11:37:54 -0600 | [diff] [blame] | 33 | #define CIFS_XATTR_CIFS_ACL "system.cifs_acl" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #define CIFS_XATTR_USER_PREFIX "user." |
| 35 | #define CIFS_XATTR_SYSTEM_PREFIX "system." |
| 36 | #define CIFS_XATTR_OS2_PREFIX "os2." |
Shirish Pargaonkar | fbeba8b | 2010-11-27 11:37:54 -0600 | [diff] [blame] | 37 | #define CIFS_XATTR_SECURITY_PREFIX "security." |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | #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 French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 42 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
| 44 | |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 45 | int cifs_removexattr(struct dentry *direntry, const char *ea_name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | { |
| 47 | int rc = -EOPNOTSUPP; |
| 48 | #ifdef CONFIG_CIFS_XATTR |
| 49 | int xid; |
| 50 | struct cifs_sb_info *cifs_sb; |
Jeff Layton | 7ffec37 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 51 | struct tcon_link *tlink; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | struct cifsTconInfo *pTcon; |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 53 | struct super_block *sb; |
Jeff Layton | 7ffec37 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 54 | char *full_path = NULL; |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 55 | |
| 56 | if (direntry == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | return -EIO; |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 58 | if (direntry->d_inode == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | return -EIO; |
| 60 | sb = direntry->d_inode->i_sb; |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 61 | if (sb == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | return -EIO; |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 63 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | cifs_sb = CIFS_SB(sb); |
Jeff Layton | 7ffec37 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 65 | 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 French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 71 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | full_path = build_path_from_dentry(direntry); |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 73 | if (full_path == NULL) { |
Suresh Jayaraman | 0f3bc09 | 2009-06-25 18:12:34 +0530 | [diff] [blame] | 74 | rc = -ENOMEM; |
Jeff Layton | 7ffec37 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 75 | goto remove_ea_exit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | } |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 77 | if (ea_name == NULL) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 78 | cFYI(1, "Null xattr names not supported"); |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 79 | } else if (strncmp(ea_name, CIFS_XATTR_USER_PREFIX, 5) |
| 80 | && (strncmp(ea_name, CIFS_XATTR_OS2_PREFIX, 4))) { |
| 81 | cFYI(1, |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 82 | "illegal xattr request %s (only user namespace supported)", |
| 83 | ea_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | /* 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 French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 88 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | goto remove_ea_exit; |
| 90 | |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 91 | ea_name += 5; /* skip past user. prefix */ |
| 92 | rc = CIFSSMBSetEA(xid, pTcon, full_path, ea_name, NULL, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 93 | (__u16)0, cifs_sb->local_nls, |
| 94 | cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | } |
| 96 | remove_ea_exit: |
Jesper Juhl | f99d49a | 2005-11-07 01:01:34 -0800 | [diff] [blame] | 97 | kfree(full_path); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | FreeXid(xid); |
Jeff Layton | 7ffec37 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 99 | cifs_put_tlink(tlink); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | #endif |
| 101 | return rc; |
| 102 | } |
| 103 | |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 104 | int cifs_setxattr(struct dentry *direntry, const char *ea_name, |
| 105 | const void *ea_value, size_t value_size, int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | { |
| 107 | int rc = -EOPNOTSUPP; |
| 108 | #ifdef CONFIG_CIFS_XATTR |
| 109 | int xid; |
| 110 | struct cifs_sb_info *cifs_sb; |
Jeff Layton | 7ffec37 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 111 | struct tcon_link *tlink; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | struct cifsTconInfo *pTcon; |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 113 | struct super_block *sb; |
| 114 | char *full_path; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 116 | if (direntry == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | return -EIO; |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 118 | if (direntry->d_inode == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | return -EIO; |
| 120 | sb = direntry->d_inode->i_sb; |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 121 | if (sb == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | |
| 124 | cifs_sb = CIFS_SB(sb); |
Jeff Layton | 7ffec37 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 125 | tlink = cifs_sb_tlink(cifs_sb); |
| 126 | if (IS_ERR(tlink)) |
| 127 | return PTR_ERR(tlink); |
| 128 | pTcon = tlink_tcon(tlink); |
| 129 | |
| 130 | xid = GetXid(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | full_path = build_path_from_dentry(direntry); |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 133 | if (full_path == NULL) { |
Suresh Jayaraman | 0f3bc09 | 2009-06-25 18:12:34 +0530 | [diff] [blame] | 134 | rc = -ENOMEM; |
Jeff Layton | 7ffec37 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 135 | goto set_ea_exit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | } |
| 137 | /* return dos attributes as pseudo xattr */ |
| 138 | /* return alt name if available as pseudo attr */ |
| 139 | |
| 140 | /* if proc/fs/cifs/streamstoxattr is set then |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 141 | search server for EAs or streams to |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | returns as xattrs */ |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 143 | if (value_size > MAX_EA_VALUE_SIZE) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 144 | cFYI(1, "size of EA value too large"); |
Jeff Layton | 7ffec37 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 145 | rc = -EOPNOTSUPP; |
| 146 | goto set_ea_exit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | } |
| 148 | |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 149 | if (ea_name == NULL) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 150 | cFYI(1, "Null xattr names not supported"); |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 151 | } else if (strncmp(ea_name, CIFS_XATTR_USER_PREFIX, 5) == 0) { |
| 152 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | goto set_ea_exit; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 154 | if (strncmp(ea_name, CIFS_XATTR_DOS_ATTRIB, 14) == 0) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 155 | cFYI(1, "attempt to set cifs inode metadata"); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 156 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | ea_name += 5; /* skip past user. prefix */ |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 158 | rc = CIFSSMBSetEA(xid, pTcon, full_path, ea_name, ea_value, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 159 | (__u16)value_size, cifs_sb->local_nls, |
| 160 | cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 161 | } else if (strncmp(ea_name, CIFS_XATTR_OS2_PREFIX, 4) == 0) { |
| 162 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | goto set_ea_exit; |
| 164 | |
| 165 | ea_name += 4; /* skip past os2. prefix */ |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 166 | rc = CIFSSMBSetEA(xid, pTcon, full_path, ea_name, ea_value, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 167 | (__u16)value_size, cifs_sb->local_nls, |
| 168 | cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | } else { |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 170 | int temp; |
| 171 | temp = strncmp(ea_name, POSIX_ACL_XATTR_ACCESS, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | strlen(POSIX_ACL_XATTR_ACCESS)); |
| 173 | if (temp == 0) { |
| 174 | #ifdef CONFIG_CIFS_POSIX |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 175 | if (sb->s_flags & MS_POSIXACL) |
| 176 | rc = CIFSSMBSetPosixACL(xid, pTcon, full_path, |
| 177 | ea_value, (const int)value_size, |
| 178 | ACL_TYPE_ACCESS, cifs_sb->local_nls, |
| 179 | cifs_sb->mnt_cifs_flags & |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 180 | CIFS_MOUNT_MAP_SPECIAL_CHR); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 181 | cFYI(1, "set POSIX ACL rc %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | #else |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 183 | cFYI(1, "set POSIX ACL not supported"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | #endif |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 185 | } else if (strncmp(ea_name, POSIX_ACL_XATTR_DEFAULT, |
| 186 | strlen(POSIX_ACL_XATTR_DEFAULT)) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | #ifdef CONFIG_CIFS_POSIX |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 188 | if (sb->s_flags & MS_POSIXACL) |
| 189 | rc = CIFSSMBSetPosixACL(xid, pTcon, full_path, |
| 190 | ea_value, (const int)value_size, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 191 | ACL_TYPE_DEFAULT, cifs_sb->local_nls, |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 192 | cifs_sb->mnt_cifs_flags & |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 193 | CIFS_MOUNT_MAP_SPECIAL_CHR); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 194 | cFYI(1, "set POSIX default ACL rc %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | #else |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 196 | cFYI(1, "set default POSIX ACL not supported"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | #endif |
| 198 | } else { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 199 | cFYI(1, "illegal xattr request %s (only user namespace" |
| 200 | " supported)", ea_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | /* BB what if no namespace prefix? */ |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 202 | /* Should we just pass them to server, except for |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | system and perhaps security prefixes? */ |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | set_ea_exit: |
Jesper Juhl | f99d49a | 2005-11-07 01:01:34 -0800 | [diff] [blame] | 208 | kfree(full_path); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | FreeXid(xid); |
Jeff Layton | 7ffec37 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 210 | cifs_put_tlink(tlink); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | #endif |
| 212 | return rc; |
| 213 | } |
| 214 | |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 215 | ssize_t cifs_getxattr(struct dentry *direntry, const char *ea_name, |
| 216 | void *ea_value, size_t buf_size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | { |
| 218 | ssize_t rc = -EOPNOTSUPP; |
| 219 | #ifdef CONFIG_CIFS_XATTR |
| 220 | int xid; |
| 221 | struct cifs_sb_info *cifs_sb; |
Jeff Layton | 7ffec37 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 222 | struct tcon_link *tlink; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | struct cifsTconInfo *pTcon; |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 224 | struct super_block *sb; |
| 225 | char *full_path; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 227 | if (direntry == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | return -EIO; |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 229 | if (direntry->d_inode == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | return -EIO; |
| 231 | sb = direntry->d_inode->i_sb; |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 232 | if (sb == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | return -EIO; |
| 234 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | cifs_sb = CIFS_SB(sb); |
Jeff Layton | 7ffec37 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 236 | tlink = cifs_sb_tlink(cifs_sb); |
| 237 | if (IS_ERR(tlink)) |
| 238 | return PTR_ERR(tlink); |
| 239 | pTcon = tlink_tcon(tlink); |
| 240 | |
| 241 | xid = GetXid(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | full_path = build_path_from_dentry(direntry); |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 244 | if (full_path == NULL) { |
Suresh Jayaraman | 0f3bc09 | 2009-06-25 18:12:34 +0530 | [diff] [blame] | 245 | rc = -ENOMEM; |
Jeff Layton | 7ffec37 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 246 | goto get_ea_exit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | } |
| 248 | /* return dos attributes as pseudo xattr */ |
| 249 | /* return alt name if available as pseudo attr */ |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 250 | if (ea_name == NULL) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 251 | cFYI(1, "Null xattr names not supported"); |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 252 | } else if (strncmp(ea_name, CIFS_XATTR_USER_PREFIX, 5) == 0) { |
| 253 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | goto get_ea_exit; |
| 255 | |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 256 | if (strncmp(ea_name, CIFS_XATTR_DOS_ATTRIB, 14) == 0) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 257 | cFYI(1, "attempt to query cifs inode metadata"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | /* revalidate/getattr then populate from inode */ |
| 259 | } /* BB add else when above is implemented */ |
| 260 | ea_name += 5; /* skip past user. prefix */ |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 261 | rc = CIFSSMBQAllEAs(xid, pTcon, full_path, ea_name, ea_value, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 262 | buf_size, cifs_sb->local_nls, |
| 263 | cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 264 | } else if (strncmp(ea_name, CIFS_XATTR_OS2_PREFIX, 4) == 0) { |
| 265 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | goto get_ea_exit; |
| 267 | |
| 268 | ea_name += 4; /* skip past os2. prefix */ |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 269 | rc = CIFSSMBQAllEAs(xid, pTcon, full_path, ea_name, ea_value, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 270 | buf_size, cifs_sb->local_nls, |
| 271 | cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 272 | } else if (strncmp(ea_name, POSIX_ACL_XATTR_ACCESS, |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 273 | strlen(POSIX_ACL_XATTR_ACCESS)) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | #ifdef CONFIG_CIFS_POSIX |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 275 | if (sb->s_flags & MS_POSIXACL) |
Steve French | 1da0c78 | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 276 | rc = CIFSSMBGetPosixACL(xid, pTcon, full_path, |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 277 | ea_value, buf_size, ACL_TYPE_ACCESS, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 278 | cifs_sb->local_nls, |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 279 | cifs_sb->mnt_cifs_flags & |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 280 | CIFS_MOUNT_MAP_SPECIAL_CHR); |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 281 | #else |
Shirish Pargaonkar | fbeba8b | 2010-11-27 11:37:54 -0600 | [diff] [blame] | 282 | cFYI(1, "Query POSIX ACL not supported yet"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | #endif /* CONFIG_CIFS_POSIX */ |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 284 | } else if (strncmp(ea_name, POSIX_ACL_XATTR_DEFAULT, |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 285 | strlen(POSIX_ACL_XATTR_DEFAULT)) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | #ifdef CONFIG_CIFS_POSIX |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 287 | if (sb->s_flags & MS_POSIXACL) |
Steve French | 1da0c78 | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 288 | rc = CIFSSMBGetPosixACL(xid, pTcon, full_path, |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 289 | ea_value, buf_size, ACL_TYPE_DEFAULT, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 290 | cifs_sb->local_nls, |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 291 | cifs_sb->mnt_cifs_flags & |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 292 | CIFS_MOUNT_MAP_SPECIAL_CHR); |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 293 | #else |
Shirish Pargaonkar | fbeba8b | 2010-11-27 11:37:54 -0600 | [diff] [blame] | 294 | cFYI(1, "Query POSIX default ACL not supported yet"); |
| 295 | #endif /* CONFIG_CIFS_POSIX */ |
| 296 | } else if (strncmp(ea_name, CIFS_XATTR_CIFS_ACL, |
| 297 | strlen(CIFS_XATTR_CIFS_ACL)) == 0) { |
| 298 | #ifdef CONFIG_CIFS_ACL |
| 299 | u32 acllen; |
| 300 | struct cifs_ntsd *pacl; |
| 301 | |
| 302 | pacl = get_cifs_acl(cifs_sb, direntry->d_inode, |
| 303 | full_path, &acllen); |
| 304 | if (IS_ERR(pacl)) { |
| 305 | rc = PTR_ERR(pacl); |
| 306 | cERROR(1, "%s: error %zd getting sec desc", |
| 307 | __func__, rc); |
| 308 | } else { |
| 309 | if (ea_value) { |
| 310 | if (acllen > buf_size) |
| 311 | acllen = -ERANGE; |
| 312 | else |
| 313 | memcpy(ea_value, pacl, acllen); |
| 314 | } |
| 315 | rc = acllen; |
| 316 | kfree(pacl); |
| 317 | } |
| 318 | #else |
| 319 | cFYI(1, "Query CIFS ACL not supported yet"); |
| 320 | #endif /* CONFIG_CIFS_ACL */ |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 321 | } else if (strncmp(ea_name, |
| 322 | CIFS_XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN) == 0) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 323 | cFYI(1, "Trusted xattr namespace not supported yet"); |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 324 | } else if (strncmp(ea_name, |
| 325 | CIFS_XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN) == 0) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 326 | cFYI(1, "Security xattr namespace not supported yet"); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 327 | } else |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 328 | cFYI(1, |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 329 | "illegal xattr request %s (only user namespace supported)", |
| 330 | ea_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 332 | /* We could add an additional check for streams ie |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | if proc/fs/cifs/streamstoxattr is set then |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 334 | search server for EAs or streams to |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | returns as xattrs */ |
| 336 | |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 337 | if (rc == -EINVAL) |
| 338 | rc = -EOPNOTSUPP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | |
| 340 | get_ea_exit: |
Jesper Juhl | f99d49a | 2005-11-07 01:01:34 -0800 | [diff] [blame] | 341 | kfree(full_path); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | FreeXid(xid); |
Jeff Layton | 7ffec37 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 343 | cifs_put_tlink(tlink); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | #endif |
| 345 | return rc; |
| 346 | } |
| 347 | |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 348 | 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] | 349 | { |
| 350 | ssize_t rc = -EOPNOTSUPP; |
| 351 | #ifdef CONFIG_CIFS_XATTR |
| 352 | int xid; |
| 353 | struct cifs_sb_info *cifs_sb; |
Jeff Layton | 7ffec37 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 354 | struct tcon_link *tlink; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | struct cifsTconInfo *pTcon; |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 356 | struct super_block *sb; |
| 357 | char *full_path; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 359 | if (direntry == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | return -EIO; |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 361 | if (direntry->d_inode == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | return -EIO; |
| 363 | sb = direntry->d_inode->i_sb; |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 364 | if (sb == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | |
| 367 | cifs_sb = CIFS_SB(sb); |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 368 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR) |
Steve French | ea4c07d | 2006-08-16 19:44:25 +0000 | [diff] [blame] | 369 | return -EOPNOTSUPP; |
| 370 | |
Jeff Layton | 7ffec37 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 371 | tlink = cifs_sb_tlink(cifs_sb); |
| 372 | if (IS_ERR(tlink)) |
| 373 | return PTR_ERR(tlink); |
| 374 | pTcon = tlink_tcon(tlink); |
| 375 | |
Steve French | ea4c07d | 2006-08-16 19:44:25 +0000 | [diff] [blame] | 376 | xid = GetXid(); |
| 377 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | full_path = build_path_from_dentry(direntry); |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 379 | if (full_path == NULL) { |
Suresh Jayaraman | 0f3bc09 | 2009-06-25 18:12:34 +0530 | [diff] [blame] | 380 | rc = -ENOMEM; |
Jeff Layton | 7ffec37 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 381 | goto list_ea_exit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | } |
| 383 | /* return dos attributes as pseudo xattr */ |
| 384 | /* return alt name if available as pseudo attr */ |
| 385 | |
| 386 | /* if proc/fs/cifs/streamstoxattr is set then |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 387 | search server for EAs or streams to |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | returns as xattrs */ |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 389 | rc = CIFSSMBQAllEAs(xid, pTcon, full_path, NULL, data, |
| 390 | buf_size, cifs_sb->local_nls, |
Steve French | 79a58d1 | 2007-07-06 22:44:50 +0000 | [diff] [blame] | 391 | cifs_sb->mnt_cifs_flags & |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 392 | CIFS_MOUNT_MAP_SPECIAL_CHR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | |
Jeff Layton | 7ffec37 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 394 | list_ea_exit: |
Jesper Juhl | f99d49a | 2005-11-07 01:01:34 -0800 | [diff] [blame] | 395 | kfree(full_path); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | FreeXid(xid); |
Jeff Layton | 7ffec37 | 2010-09-29 19:51:11 -0400 | [diff] [blame] | 397 | cifs_put_tlink(tlink); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | #endif |
| 399 | return rc; |
| 400 | } |