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) {
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))) {
75 ("illegal xattr request %s (only user namespace supported)",
77 /* BB what if no namespace prefix? */
78 /* Should we just pass them to server, except for
79 system and perhaps security prefixes? */
81 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
84 ea_name += 5; /* skip past user. prefix */
85 rc = CIFSSMBSetEA(xid, pTcon, full_path, ea_name, NULL,
86 (__u16)0, cifs_sb->local_nls,
87 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
96 int cifs_setxattr(struct dentry *direntry, const char *ea_name,
97 const void *ea_value, size_t value_size, int flags)
100 #ifdef CONFIG_CIFS_XATTR
102 struct cifs_sb_info *cifs_sb;
103 struct cifsTconInfo *pTcon;
104 struct super_block *sb;
107 if (direntry == NULL)
109 if (direntry->d_inode == NULL)
111 sb = direntry->d_inode->i_sb;
116 cifs_sb = CIFS_SB(sb);
117 pTcon = cifs_sb->tcon;
119 full_path = build_path_from_dentry(direntry);
120 if (full_path == NULL) {
124 /* return dos attributes as pseudo xattr */
125 /* return alt name if available as pseudo attr */
127 /* if proc/fs/cifs/streamstoxattr is set then
128 search server for EAs or streams to
130 if (value_size > MAX_EA_VALUE_SIZE) {
131 cFYI(1, ("size of EA value too large"));
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)
142 if (strncmp(ea_name, CIFS_XATTR_DOS_ATTRIB, 14) == 0) {
143 cFYI(1, ("attempt to set cifs inode metadata"));
145 ea_name += 5; /* skip past user. prefix */
146 rc = CIFSSMBSetEA(xid, pTcon, full_path, ea_name, ea_value,
147 (__u16)value_size, cifs_sb->local_nls,
148 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
149 } else if (strncmp(ea_name, CIFS_XATTR_OS2_PREFIX, 4) == 0) {
150 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
153 ea_name += 4; /* skip past os2. prefix */
154 rc = CIFSSMBSetEA(xid, pTcon, full_path, ea_name, ea_value,
155 (__u16)value_size, cifs_sb->local_nls,
156 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
159 temp = strncmp(ea_name, POSIX_ACL_XATTR_ACCESS,
160 strlen(POSIX_ACL_XATTR_ACCESS));
162 #ifdef CONFIG_CIFS_POSIX
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 &
168 CIFS_MOUNT_MAP_SPECIAL_CHR);
169 cFYI(1, ("set POSIX ACL rc %d", rc));
171 cFYI(1, ("set POSIX ACL not supported"));
173 } else if (strncmp(ea_name, POSIX_ACL_XATTR_DEFAULT,
174 strlen(POSIX_ACL_XATTR_DEFAULT)) == 0) {
175 #ifdef CONFIG_CIFS_POSIX
176 if (sb->s_flags & MS_POSIXACL)
177 rc = CIFSSMBSetPosixACL(xid, pTcon, full_path,
178 ea_value, (const int)value_size,
179 ACL_TYPE_DEFAULT, cifs_sb->local_nls,
180 cifs_sb->mnt_cifs_flags &
181 CIFS_MOUNT_MAP_SPECIAL_CHR);
182 cFYI(1, ("set POSIX default ACL rc %d", rc));
184 cFYI(1, ("set default POSIX ACL not supported"));
187 cFYI(1, ("illegal xattr request %s (only user namespace supported)", ea_name));
188 /* BB what if no namespace prefix? */
189 /* Should we just pass them to server, except for
190 system and perhaps security prefixes? */
201 ssize_t cifs_getxattr(struct dentry *direntry, const char *ea_name,
202 void *ea_value, size_t buf_size)
204 ssize_t rc = -EOPNOTSUPP;
205 #ifdef CONFIG_CIFS_XATTR
207 struct cifs_sb_info *cifs_sb;
208 struct cifsTconInfo *pTcon;
209 struct super_block *sb;
212 if (direntry == NULL)
214 if (direntry->d_inode == NULL)
216 sb = direntry->d_inode->i_sb;
222 cifs_sb = CIFS_SB(sb);
223 pTcon = cifs_sb->tcon;
225 full_path = build_path_from_dentry(direntry);
226 if (full_path == NULL) {
230 /* return dos attributes as pseudo xattr */
231 /* return alt name if available as pseudo attr */
232 if (ea_name == NULL) {
233 cFYI(1, ("Null xattr names not supported"));
234 } else if (strncmp(ea_name, CIFS_XATTR_USER_PREFIX, 5) == 0) {
235 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
238 if (strncmp(ea_name, CIFS_XATTR_DOS_ATTRIB, 14) == 0) {
239 cFYI(1, ("attempt to query cifs inode metadata"));
240 /* revalidate/getattr then populate from inode */
241 } /* BB add else when above is implemented */
242 ea_name += 5; /* skip past user. prefix */
243 rc = CIFSSMBQueryEA(xid, pTcon, full_path, ea_name, ea_value,
244 buf_size, cifs_sb->local_nls,
245 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
246 } else if (strncmp(ea_name, CIFS_XATTR_OS2_PREFIX, 4) == 0) {
247 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
250 ea_name += 4; /* skip past os2. prefix */
251 rc = CIFSSMBQueryEA(xid, pTcon, full_path, ea_name, ea_value,
252 buf_size, cifs_sb->local_nls,
253 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
254 } else if (strncmp(ea_name, POSIX_ACL_XATTR_ACCESS,
255 strlen(POSIX_ACL_XATTR_ACCESS)) == 0) {
256 #ifdef CONFIG_CIFS_POSIX
257 if (sb->s_flags & MS_POSIXACL)
258 rc = CIFSSMBGetPosixACL(xid, pTcon, full_path,
259 ea_value, buf_size, ACL_TYPE_ACCESS,
261 cifs_sb->mnt_cifs_flags &
262 CIFS_MOUNT_MAP_SPECIAL_CHR);
263 /* else if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL) {
266 rc = CIFSSMBOpen(xid, pTcon, full_path,
267 FILE_OPEN, GENERIC_READ, 0, &fid,
268 &oplock, NULL, cifs_sb->local_nls,
269 cifs_sb->mnt_cifs_flags &
270 CIFS_MOUNT_MAP_SPECIAL_CHR);
272 rc = CIFSSMBGetCIFSACL(xid, pTcon, fid,
275 CIFSSMBClose(xid, pTcon, fid);
277 } */ /* BB enable after fixing up return data */
279 cFYI(1, ("query POSIX ACL not supported yet"));
280 #endif /* CONFIG_CIFS_POSIX */
281 } else if (strncmp(ea_name, POSIX_ACL_XATTR_DEFAULT,
282 strlen(POSIX_ACL_XATTR_DEFAULT)) == 0) {
283 #ifdef CONFIG_CIFS_POSIX
284 if (sb->s_flags & MS_POSIXACL)
285 rc = CIFSSMBGetPosixACL(xid, pTcon, full_path,
286 ea_value, buf_size, ACL_TYPE_DEFAULT,
288 cifs_sb->mnt_cifs_flags &
289 CIFS_MOUNT_MAP_SPECIAL_CHR);
291 cFYI(1, ("query POSIX default ACL not supported yet"));
293 } else if (strncmp(ea_name,
294 CIFS_XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN) == 0) {
295 cFYI(1, ("Trusted xattr namespace not supported yet"));
296 } else if (strncmp(ea_name,
297 CIFS_XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN) == 0) {
298 cFYI(1, ("Security xattr namespace not supported yet"));
301 ("illegal xattr request %s (only user namespace supported)",
305 /* We could add an additional check for streams ie
306 if proc/fs/cifs/streamstoxattr is set then
307 search server for EAs or streams to
320 ssize_t cifs_listxattr(struct dentry *direntry, char *data, size_t buf_size)
322 ssize_t rc = -EOPNOTSUPP;
323 #ifdef CONFIG_CIFS_XATTR
325 struct cifs_sb_info *cifs_sb;
326 struct cifsTconInfo *pTcon;
327 struct super_block *sb;
330 if (direntry == NULL)
332 if (direntry->d_inode == NULL)
334 sb = direntry->d_inode->i_sb;
338 cifs_sb = CIFS_SB(sb);
339 pTcon = cifs_sb->tcon;
341 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
346 full_path = build_path_from_dentry(direntry);
347 if (full_path == NULL) {
351 /* return dos attributes as pseudo xattr */
352 /* return alt name if available as pseudo attr */
354 /* if proc/fs/cifs/streamstoxattr is set then
355 search server for EAs or streams to
357 rc = CIFSSMBQAllEAs(xid, pTcon, full_path, data, buf_size,
359 cifs_sb->mnt_cifs_flags &
360 CIFS_MOUNT_MAP_SPECIAL_CHR);