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