Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * fs/cifs/xattr.c |
| 3 | * |
| 4 | * Copyright (c) International Business Machines Corp., 2003 |
| 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 */ |
| 40 | |
| 41 | |
| 42 | |
| 43 | int cifs_removexattr(struct dentry * direntry, const char * ea_name) |
| 44 | { |
| 45 | int rc = -EOPNOTSUPP; |
| 46 | #ifdef CONFIG_CIFS_XATTR |
| 47 | int xid; |
| 48 | struct cifs_sb_info *cifs_sb; |
| 49 | struct cifsTconInfo *pTcon; |
| 50 | struct super_block * sb; |
| 51 | char * full_path; |
| 52 | |
| 53 | if(direntry == NULL) |
| 54 | return -EIO; |
| 55 | if(direntry->d_inode == NULL) |
| 56 | return -EIO; |
| 57 | sb = direntry->d_inode->i_sb; |
| 58 | if(sb == NULL) |
| 59 | return -EIO; |
| 60 | xid = GetXid(); |
| 61 | |
| 62 | cifs_sb = CIFS_SB(sb); |
| 63 | pTcon = cifs_sb->tcon; |
| 64 | |
| 65 | down(&sb->s_vfs_rename_sem); |
| 66 | full_path = build_path_from_dentry(direntry); |
| 67 | up(&sb->s_vfs_rename_sem); |
| 68 | if(full_path == NULL) { |
| 69 | FreeXid(xid); |
| 70 | return -ENOMEM; |
| 71 | } |
| 72 | if(ea_name == NULL) { |
| 73 | cFYI(1,("Null xattr names not supported")); |
| 74 | } else if(strncmp(ea_name,CIFS_XATTR_USER_PREFIX,5) |
| 75 | && (strncmp(ea_name,CIFS_XATTR_OS2_PREFIX,4))) { |
| 76 | cFYI(1,("illegal xattr namespace %s (only user namespace supported)",ea_name)); |
| 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 { |
| 81 | if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR) |
| 82 | goto remove_ea_exit; |
| 83 | |
| 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 | |
| 96 | int cifs_setxattr(struct dentry * direntry, const char * ea_name, |
| 97 | const void * ea_value, size_t value_size, int flags) |
| 98 | { |
| 99 | int rc = -EOPNOTSUPP; |
| 100 | #ifdef CONFIG_CIFS_XATTR |
| 101 | int xid; |
| 102 | struct cifs_sb_info *cifs_sb; |
| 103 | struct cifsTconInfo *pTcon; |
| 104 | struct super_block * sb; |
| 105 | char * full_path; |
| 106 | |
| 107 | if(direntry == NULL) |
| 108 | return -EIO; |
| 109 | if(direntry->d_inode == NULL) |
| 110 | return -EIO; |
| 111 | sb = direntry->d_inode->i_sb; |
| 112 | if(sb == NULL) |
| 113 | return -EIO; |
| 114 | xid = GetXid(); |
| 115 | |
| 116 | cifs_sb = CIFS_SB(sb); |
| 117 | pTcon = cifs_sb->tcon; |
| 118 | |
| 119 | down(&sb->s_vfs_rename_sem); |
| 120 | full_path = build_path_from_dentry(direntry); |
| 121 | up(&sb->s_vfs_rename_sem); |
| 122 | if(full_path == NULL) { |
| 123 | FreeXid(xid); |
| 124 | return -ENOMEM; |
| 125 | } |
| 126 | /* return dos attributes as pseudo xattr */ |
| 127 | /* return alt name if available as pseudo attr */ |
| 128 | |
| 129 | /* if proc/fs/cifs/streamstoxattr is set then |
| 130 | search server for EAs or streams to |
| 131 | returns as xattrs */ |
| 132 | if(value_size > MAX_EA_VALUE_SIZE) { |
| 133 | cFYI(1,("size of EA value too large")); |
Jesper Juhl | f99d49a | 2005-11-07 01:01:34 -0800 | [diff] [blame^] | 134 | kfree(full_path); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | FreeXid(xid); |
| 136 | return -EOPNOTSUPP; |
| 137 | } |
| 138 | |
| 139 | if(ea_name == NULL) { |
| 140 | cFYI(1,("Null xattr names not supported")); |
| 141 | } else if(strncmp(ea_name,CIFS_XATTR_USER_PREFIX,5) == 0) { |
| 142 | if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR) |
| 143 | goto set_ea_exit; |
| 144 | if(strncmp(ea_name,CIFS_XATTR_DOS_ATTRIB,14) == 0) { |
| 145 | cFYI(1,("attempt to set cifs inode metadata")); |
| 146 | } |
| 147 | ea_name += 5; /* skip past user. prefix */ |
| 148 | rc = CIFSSMBSetEA(xid,pTcon,full_path,ea_name,ea_value, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 149 | (__u16)value_size, cifs_sb->local_nls, |
| 150 | cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | } else if(strncmp(ea_name, CIFS_XATTR_OS2_PREFIX,4) == 0) { |
| 152 | if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR) |
| 153 | goto set_ea_exit; |
| 154 | |
| 155 | ea_name += 4; /* skip past os2. prefix */ |
| 156 | rc = CIFSSMBSetEA(xid,pTcon,full_path,ea_name,ea_value, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 157 | (__u16)value_size, cifs_sb->local_nls, |
| 158 | cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | } else { |
| 160 | int temp; |
| 161 | temp = strncmp(ea_name,POSIX_ACL_XATTR_ACCESS, |
| 162 | strlen(POSIX_ACL_XATTR_ACCESS)); |
| 163 | if (temp == 0) { |
| 164 | #ifdef CONFIG_CIFS_POSIX |
Steve French | 1da0c78 | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 165 | if(sb->s_flags & MS_POSIXACL) |
| 166 | rc = CIFSSMBSetPosixACL(xid, pTcon,full_path, |
| 167 | ea_value, (const int)value_size, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 168 | ACL_TYPE_ACCESS,cifs_sb->local_nls, |
| 169 | cifs_sb->mnt_cifs_flags & |
| 170 | CIFS_MOUNT_MAP_SPECIAL_CHR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | cFYI(1,("set POSIX ACL rc %d",rc)); |
| 172 | #else |
| 173 | cFYI(1,("set POSIX ACL not supported")); |
| 174 | #endif |
| 175 | } else if(strncmp(ea_name,POSIX_ACL_XATTR_DEFAULT,strlen(POSIX_ACL_XATTR_DEFAULT)) == 0) { |
| 176 | #ifdef CONFIG_CIFS_POSIX |
Steve French | 1da0c78 | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 177 | if(sb->s_flags & MS_POSIXACL) |
| 178 | rc = CIFSSMBSetPosixACL(xid, pTcon,full_path, |
| 179 | ea_value, (const int)value_size, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 180 | ACL_TYPE_DEFAULT, cifs_sb->local_nls, |
| 181 | cifs_sb->mnt_cifs_flags & |
| 182 | CIFS_MOUNT_MAP_SPECIAL_CHR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | cFYI(1,("set POSIX default ACL rc %d",rc)); |
| 184 | #else |
| 185 | cFYI(1,("set default POSIX ACL not supported")); |
| 186 | #endif |
| 187 | } else { |
| 188 | cFYI(1,("illegal xattr request %s (only user namespace supported)",ea_name)); |
| 189 | /* BB what if no namespace prefix? */ |
| 190 | /* Should we just pass them to server, except for |
| 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 | |
| 202 | ssize_t cifs_getxattr(struct dentry * direntry, const char * ea_name, |
| 203 | void * ea_value, size_t buf_size) |
| 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; |
| 210 | struct super_block * sb; |
| 211 | char * full_path; |
| 212 | |
| 213 | if(direntry == NULL) |
| 214 | return -EIO; |
| 215 | if(direntry->d_inode == NULL) |
| 216 | return -EIO; |
| 217 | sb = direntry->d_inode->i_sb; |
| 218 | if(sb == NULL) |
| 219 | return -EIO; |
| 220 | |
| 221 | xid = GetXid(); |
| 222 | |
| 223 | cifs_sb = CIFS_SB(sb); |
| 224 | pTcon = cifs_sb->tcon; |
| 225 | |
| 226 | down(&sb->s_vfs_rename_sem); |
| 227 | full_path = build_path_from_dentry(direntry); |
| 228 | up(&sb->s_vfs_rename_sem); |
| 229 | if(full_path == NULL) { |
| 230 | FreeXid(xid); |
| 231 | return -ENOMEM; |
| 232 | } |
| 233 | /* return dos attributes as pseudo xattr */ |
| 234 | /* return alt name if available as pseudo attr */ |
| 235 | if(ea_name == NULL) { |
| 236 | cFYI(1,("Null xattr names not supported")); |
| 237 | } else if(strncmp(ea_name,CIFS_XATTR_USER_PREFIX,5) == 0) { |
| 238 | if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR) |
| 239 | goto get_ea_exit; |
| 240 | |
| 241 | if(strncmp(ea_name,CIFS_XATTR_DOS_ATTRIB,14) == 0) { |
| 242 | cFYI(1,("attempt to query cifs inode metadata")); |
| 243 | /* revalidate/getattr then populate from inode */ |
| 244 | } /* BB add else when above is implemented */ |
| 245 | ea_name += 5; /* skip past user. prefix */ |
| 246 | rc = CIFSSMBQueryEA(xid,pTcon,full_path,ea_name,ea_value, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 247 | buf_size, cifs_sb->local_nls, |
| 248 | cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | } else if(strncmp(ea_name, CIFS_XATTR_OS2_PREFIX,4) == 0) { |
| 250 | if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR) |
| 251 | goto get_ea_exit; |
| 252 | |
| 253 | ea_name += 4; /* skip past os2. prefix */ |
| 254 | rc = CIFSSMBQueryEA(xid,pTcon,full_path,ea_name,ea_value, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 255 | buf_size, cifs_sb->local_nls, |
| 256 | cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | } else if(strncmp(ea_name,POSIX_ACL_XATTR_ACCESS,strlen(POSIX_ACL_XATTR_ACCESS)) == 0) { |
| 258 | #ifdef CONFIG_CIFS_POSIX |
Steve French | 1da0c78 | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 259 | if(sb->s_flags & MS_POSIXACL) |
| 260 | rc = CIFSSMBGetPosixACL(xid, pTcon, full_path, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | ea_value, buf_size, ACL_TYPE_ACCESS, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 262 | cifs_sb->local_nls, |
| 263 | cifs_sb->mnt_cifs_flags & |
| 264 | CIFS_MOUNT_MAP_SPECIAL_CHR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | #else |
| 266 | cFYI(1,("query POSIX ACL not supported yet")); |
| 267 | #endif /* CONFIG_CIFS_POSIX */ |
| 268 | } else if(strncmp(ea_name,POSIX_ACL_XATTR_DEFAULT,strlen(POSIX_ACL_XATTR_DEFAULT)) == 0) { |
| 269 | #ifdef CONFIG_CIFS_POSIX |
Steve French | 1da0c78 | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 270 | if(sb->s_flags & MS_POSIXACL) |
| 271 | rc = CIFSSMBGetPosixACL(xid, pTcon, full_path, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | ea_value, buf_size, ACL_TYPE_DEFAULT, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 273 | cifs_sb->local_nls, |
| 274 | cifs_sb->mnt_cifs_flags & |
| 275 | CIFS_MOUNT_MAP_SPECIAL_CHR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | #else |
| 277 | cFYI(1,("query POSIX default ACL not supported yet")); |
| 278 | #endif |
| 279 | } else if(strncmp(ea_name, |
| 280 | CIFS_XATTR_TRUSTED_PREFIX,XATTR_TRUSTED_PREFIX_LEN) == 0) { |
| 281 | cFYI(1,("Trusted xattr namespace not supported yet")); |
| 282 | } else if(strncmp(ea_name, |
| 283 | CIFS_XATTR_SECURITY_PREFIX,XATTR_SECURITY_PREFIX_LEN) == 0) { |
| 284 | cFYI(1,("Security xattr namespace not supported yet")); |
| 285 | } else { |
| 286 | cFYI(1,("illegal xattr name request %s (only user namespace supported)",ea_name)); |
| 287 | } |
| 288 | |
| 289 | /* We could add an additional check for streams ie |
| 290 | if proc/fs/cifs/streamstoxattr is set then |
| 291 | search server for EAs or streams to |
| 292 | returns as xattrs */ |
| 293 | |
| 294 | if(rc == -EINVAL) |
| 295 | rc = -EOPNOTSUPP; |
| 296 | |
| 297 | get_ea_exit: |
Jesper Juhl | f99d49a | 2005-11-07 01:01:34 -0800 | [diff] [blame^] | 298 | kfree(full_path); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | FreeXid(xid); |
| 300 | #endif |
| 301 | return rc; |
| 302 | } |
| 303 | |
| 304 | ssize_t cifs_listxattr(struct dentry * direntry, char * data, size_t buf_size) |
| 305 | { |
| 306 | ssize_t rc = -EOPNOTSUPP; |
| 307 | #ifdef CONFIG_CIFS_XATTR |
| 308 | int xid; |
| 309 | struct cifs_sb_info *cifs_sb; |
| 310 | struct cifsTconInfo *pTcon; |
| 311 | struct super_block * sb; |
| 312 | char * full_path; |
| 313 | |
| 314 | if(direntry == NULL) |
| 315 | return -EIO; |
| 316 | if(direntry->d_inode == NULL) |
| 317 | return -EIO; |
| 318 | sb = direntry->d_inode->i_sb; |
| 319 | if(sb == NULL) |
| 320 | return -EIO; |
| 321 | xid = GetXid(); |
| 322 | |
| 323 | cifs_sb = CIFS_SB(sb); |
| 324 | pTcon = cifs_sb->tcon; |
| 325 | |
| 326 | down(&sb->s_vfs_rename_sem); |
| 327 | full_path = build_path_from_dentry(direntry); |
| 328 | up(&sb->s_vfs_rename_sem); |
| 329 | if(full_path == NULL) { |
| 330 | FreeXid(xid); |
| 331 | return -ENOMEM; |
| 332 | } |
| 333 | /* return dos attributes as pseudo xattr */ |
| 334 | /* return alt name if available as pseudo attr */ |
| 335 | |
| 336 | /* if proc/fs/cifs/streamstoxattr is set then |
| 337 | search server for EAs or streams to |
| 338 | returns as xattrs */ |
| 339 | rc = CIFSSMBQAllEAs(xid,pTcon,full_path,data,buf_size, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 340 | cifs_sb->local_nls, |
| 341 | cifs_sb->mnt_cifs_flags & |
| 342 | CIFS_MOUNT_MAP_SPECIAL_CHR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | |
Jesper Juhl | f99d49a | 2005-11-07 01:01:34 -0800 | [diff] [blame^] | 344 | kfree(full_path); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | FreeXid(xid); |
| 346 | #endif |
| 347 | return rc; |
| 348 | } |