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