4 * Copyright (c) International Business Machines Corp., 2003, 2007
5 * Author(s): Steve French (sfrench@us.ibm.com)
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.
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.
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
23 #include <linux/posix_acl_xattr.h>
27 #include "cifsproto.h"
28 #include "cifs_debug.h"
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 */
43 int cifs_removexattr(struct dentry *direntry, const char *ea_name)
46 #ifdef CONFIG_CIFS_XATTR
48 struct cifs_sb_info *cifs_sb;
49 struct cifsTconInfo *pTcon;
50 struct super_block *sb;
55 if (direntry->d_inode == NULL)
57 sb = direntry->d_inode->i_sb;
62 cifs_sb = CIFS_SB(sb);
63 pTcon = cifs_sb->tcon;
65 full_path = build_path_from_dentry(direntry);
66 if (full_path == NULL) {
71 if (ea_name == NULL) {
72 cFYI(1, ("Null xattr names not supported"));
73 } else if (strncmp(ea_name, CIFS_XATTR_USER_PREFIX, 5)
74 && (strncmp(ea_name, CIFS_XATTR_OS2_PREFIX, 4))) {
76 ("illegal xattr request %s (only user namespace supported)",
78 /* BB what if no namespace prefix? */
79 /* Should we just pass them to server, except for
80 system and perhaps security prefixes? */
82 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
85 ea_name += 5; /* skip past user. prefix */
86 rc = CIFSSMBSetEA(xid, pTcon, full_path, ea_name, NULL,
87 (__u16)0, cifs_sb->local_nls,
88 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
97 int cifs_setxattr(struct dentry *direntry, const char *ea_name,
98 const void *ea_value, size_t value_size, int flags)
100 int rc = -EOPNOTSUPP;
101 #ifdef CONFIG_CIFS_XATTR
103 struct cifs_sb_info *cifs_sb;
104 struct cifsTconInfo *pTcon;
105 struct super_block *sb;
108 if (direntry == NULL)
110 if (direntry->d_inode == NULL)
112 sb = direntry->d_inode->i_sb;
117 cifs_sb = CIFS_SB(sb);
118 pTcon = cifs_sb->tcon;
120 full_path = build_path_from_dentry(direntry);
121 if (full_path == NULL) {
126 /* return dos attributes as pseudo xattr */
127 /* return alt name if available as pseudo attr */
129 /* if proc/fs/cifs/streamstoxattr is set then
130 search server for EAs or streams to
132 if (value_size > MAX_EA_VALUE_SIZE) {
133 cFYI(1, ("size of EA value too large"));
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)
144 if (strncmp(ea_name, CIFS_XATTR_DOS_ATTRIB, 14) == 0)
145 cFYI(1, ("attempt to set cifs inode metadata"));
147 ea_name += 5; /* skip past user. prefix */
148 rc = CIFSSMBSetEA(xid, pTcon, full_path, ea_name, ea_value,
149 (__u16)value_size, cifs_sb->local_nls,
150 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
151 } else if (strncmp(ea_name, CIFS_XATTR_OS2_PREFIX, 4) == 0) {
152 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
155 ea_name += 4; /* skip past os2. prefix */
156 rc = CIFSSMBSetEA(xid, pTcon, full_path, ea_name, ea_value,
157 (__u16)value_size, cifs_sb->local_nls,
158 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
161 temp = strncmp(ea_name, POSIX_ACL_XATTR_ACCESS,
162 strlen(POSIX_ACL_XATTR_ACCESS));
164 #ifdef CONFIG_CIFS_POSIX
165 if (sb->s_flags & MS_POSIXACL)
166 rc = CIFSSMBSetPosixACL(xid, pTcon, full_path,
167 ea_value, (const int)value_size,
168 ACL_TYPE_ACCESS, cifs_sb->local_nls,
169 cifs_sb->mnt_cifs_flags &
170 CIFS_MOUNT_MAP_SPECIAL_CHR);
171 cFYI(1, ("set POSIX ACL rc %d", rc));
173 cFYI(1, ("set POSIX ACL not supported"));
175 } else if (strncmp(ea_name, POSIX_ACL_XATTR_DEFAULT,
176 strlen(POSIX_ACL_XATTR_DEFAULT)) == 0) {
177 #ifdef CONFIG_CIFS_POSIX
178 if (sb->s_flags & MS_POSIXACL)
179 rc = CIFSSMBSetPosixACL(xid, pTcon, full_path,
180 ea_value, (const int)value_size,
181 ACL_TYPE_DEFAULT, cifs_sb->local_nls,
182 cifs_sb->mnt_cifs_flags &
183 CIFS_MOUNT_MAP_SPECIAL_CHR);
184 cFYI(1, ("set POSIX default ACL rc %d", rc));
186 cFYI(1, ("set default POSIX ACL not supported"));
189 cFYI(1, ("illegal xattr request %s (only user namespace"
190 " supported)", ea_name));
191 /* BB what if no namespace prefix? */
192 /* Should we just pass them to server, except for
193 system and perhaps security prefixes? */
204 ssize_t cifs_getxattr(struct dentry *direntry, const char *ea_name,
205 void *ea_value, size_t buf_size)
207 ssize_t rc = -EOPNOTSUPP;
208 #ifdef CONFIG_CIFS_XATTR
210 struct cifs_sb_info *cifs_sb;
211 struct cifsTconInfo *pTcon;
212 struct super_block *sb;
215 if (direntry == NULL)
217 if (direntry->d_inode == NULL)
219 sb = direntry->d_inode->i_sb;
225 cifs_sb = CIFS_SB(sb);
226 pTcon = cifs_sb->tcon;
228 full_path = build_path_from_dentry(direntry);
229 if (full_path == NULL) {
234 /* return dos attributes as pseudo xattr */
235 /* return alt name if available as pseudo attr */
236 if (ea_name == NULL) {
237 cFYI(1, ("Null xattr names not supported"));
238 } else if (strncmp(ea_name, CIFS_XATTR_USER_PREFIX, 5) == 0) {
239 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
242 if (strncmp(ea_name, CIFS_XATTR_DOS_ATTRIB, 14) == 0) {
243 cFYI(1, ("attempt to query cifs inode metadata"));
244 /* revalidate/getattr then populate from inode */
245 } /* BB add else when above is implemented */
246 ea_name += 5; /* skip past user. prefix */
247 rc = CIFSSMBQueryEA(xid, pTcon, full_path, ea_name, ea_value,
248 buf_size, cifs_sb->local_nls,
249 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
250 } else if (strncmp(ea_name, CIFS_XATTR_OS2_PREFIX, 4) == 0) {
251 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
254 ea_name += 4; /* skip past os2. prefix */
255 rc = CIFSSMBQueryEA(xid, pTcon, full_path, ea_name, ea_value,
256 buf_size, cifs_sb->local_nls,
257 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
258 } else if (strncmp(ea_name, POSIX_ACL_XATTR_ACCESS,
259 strlen(POSIX_ACL_XATTR_ACCESS)) == 0) {
260 #ifdef CONFIG_CIFS_POSIX
261 if (sb->s_flags & MS_POSIXACL)
262 rc = CIFSSMBGetPosixACL(xid, pTcon, full_path,
263 ea_value, buf_size, ACL_TYPE_ACCESS,
265 cifs_sb->mnt_cifs_flags &
266 CIFS_MOUNT_MAP_SPECIAL_CHR);
267 #ifdef CONFIG_CIFS_EXPERIMENTAL
268 else if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL) {
271 struct cifs_ntsd *pacl = NULL;
274 rc = CIFSSMBOpen(xid, pTcon, full_path,
275 FILE_OPEN, GENERIC_READ, 0, &fid,
276 &oplock, NULL, cifs_sb->local_nls,
277 cifs_sb->mnt_cifs_flags &
278 CIFS_MOUNT_MAP_SPECIAL_CHR);
279 /* else rc is EOPNOTSUPP from above */
282 rc = CIFSSMBGetCIFSACL(xid, pTcon, fid, &pacl,
284 CIFSSMBClose(xid, pTcon, fid);
287 #endif /* EXPERIMENTAL */
289 cFYI(1, ("query POSIX ACL not supported yet"));
290 #endif /* CONFIG_CIFS_POSIX */
291 } else if (strncmp(ea_name, POSIX_ACL_XATTR_DEFAULT,
292 strlen(POSIX_ACL_XATTR_DEFAULT)) == 0) {
293 #ifdef CONFIG_CIFS_POSIX
294 if (sb->s_flags & MS_POSIXACL)
295 rc = CIFSSMBGetPosixACL(xid, pTcon, full_path,
296 ea_value, buf_size, ACL_TYPE_DEFAULT,
298 cifs_sb->mnt_cifs_flags &
299 CIFS_MOUNT_MAP_SPECIAL_CHR);
301 cFYI(1, ("query POSIX default ACL not supported yet"));
303 } else if (strncmp(ea_name,
304 CIFS_XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN) == 0) {
305 cFYI(1, ("Trusted xattr namespace not supported yet"));
306 } else if (strncmp(ea_name,
307 CIFS_XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN) == 0) {
308 cFYI(1, ("Security xattr namespace not supported yet"));
311 ("illegal xattr request %s (only user namespace supported)",
314 /* We could add an additional check for streams ie
315 if proc/fs/cifs/streamstoxattr is set then
316 search server for EAs or streams to
329 ssize_t cifs_listxattr(struct dentry *direntry, char *data, size_t buf_size)
331 ssize_t rc = -EOPNOTSUPP;
332 #ifdef CONFIG_CIFS_XATTR
334 struct cifs_sb_info *cifs_sb;
335 struct cifsTconInfo *pTcon;
336 struct super_block *sb;
339 if (direntry == NULL)
341 if (direntry->d_inode == NULL)
343 sb = direntry->d_inode->i_sb;
347 cifs_sb = CIFS_SB(sb);
348 pTcon = cifs_sb->tcon;
350 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
355 full_path = build_path_from_dentry(direntry);
356 if (full_path == NULL) {
361 /* return dos attributes as pseudo xattr */
362 /* return alt name if available as pseudo attr */
364 /* if proc/fs/cifs/streamstoxattr is set then
365 search server for EAs or streams to
367 rc = CIFSSMBQAllEAs(xid, pTcon, full_path, data, buf_size,
369 cifs_sb->mnt_cifs_flags &
370 CIFS_MOUNT_MAP_SPECIAL_CHR);