Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[wrt350n-kernel.git] / fs / cifs / xattr.c
blob443c09fe812fef73b37fcdfb3d2ed9056049e17f
1 /*
2 * fs/cifs/xattr.c
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
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"
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)
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;
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();
62 cifs_sb = CIFS_SB(sb);
63 pTcon = cifs_sb->tcon;
65 full_path = build_path_from_dentry(direntry);
66 if (full_path == NULL) {
67 FreeXid(xid);
68 return -ENOMEM;
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));
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;
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);
89 remove_ea_exit:
90 kfree(full_path);
91 FreeXid(xid);
92 #endif
93 return rc;
96 int cifs_setxattr(struct dentry *direntry, const char *ea_name,
97 const void *ea_value, size_t value_size, int flags)
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;
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();
116 cifs_sb = CIFS_SB(sb);
117 pTcon = cifs_sb->tcon;
119 full_path = build_path_from_dentry(direntry);
120 if (full_path == NULL) {
121 FreeXid(xid);
122 return -ENOMEM;
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
129 returns as xattrs */
130 if (value_size > MAX_EA_VALUE_SIZE) {
131 cFYI(1, ("size of EA value too large"));
132 kfree(full_path);
133 FreeXid(xid);
134 return -EOPNOTSUPP;
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)
141 goto set_ea_exit;
142 <<<<<<< HEAD:fs/cifs/xattr.c
143 if (strncmp(ea_name, CIFS_XATTR_DOS_ATTRIB, 14) == 0) {
144 =======
145 if (strncmp(ea_name, CIFS_XATTR_DOS_ATTRIB, 14) == 0)
146 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:fs/cifs/xattr.c
147 cFYI(1, ("attempt to set cifs inode metadata"));
148 <<<<<<< HEAD:fs/cifs/xattr.c
150 =======
152 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:fs/cifs/xattr.c
153 ea_name += 5; /* skip past user. 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);
157 } else if (strncmp(ea_name, CIFS_XATTR_OS2_PREFIX, 4) == 0) {
158 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
159 goto set_ea_exit;
161 ea_name += 4; /* skip past os2. prefix */
162 rc = CIFSSMBSetEA(xid, pTcon, full_path, ea_name, ea_value,
163 (__u16)value_size, cifs_sb->local_nls,
164 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
165 } else {
166 int temp;
167 temp = strncmp(ea_name, POSIX_ACL_XATTR_ACCESS,
168 strlen(POSIX_ACL_XATTR_ACCESS));
169 if (temp == 0) {
170 #ifdef CONFIG_CIFS_POSIX
171 if (sb->s_flags & MS_POSIXACL)
172 rc = CIFSSMBSetPosixACL(xid, pTcon, full_path,
173 ea_value, (const int)value_size,
174 ACL_TYPE_ACCESS, cifs_sb->local_nls,
175 cifs_sb->mnt_cifs_flags &
176 CIFS_MOUNT_MAP_SPECIAL_CHR);
177 cFYI(1, ("set POSIX ACL rc %d", rc));
178 #else
179 cFYI(1, ("set POSIX ACL not supported"));
180 #endif
181 } else if (strncmp(ea_name, POSIX_ACL_XATTR_DEFAULT,
182 strlen(POSIX_ACL_XATTR_DEFAULT)) == 0) {
183 #ifdef CONFIG_CIFS_POSIX
184 if (sb->s_flags & MS_POSIXACL)
185 rc = CIFSSMBSetPosixACL(xid, pTcon, full_path,
186 ea_value, (const int)value_size,
187 ACL_TYPE_DEFAULT, cifs_sb->local_nls,
188 cifs_sb->mnt_cifs_flags &
189 CIFS_MOUNT_MAP_SPECIAL_CHR);
190 cFYI(1, ("set POSIX default ACL rc %d", rc));
191 #else
192 cFYI(1, ("set default POSIX ACL not supported"));
193 #endif
194 } else {
195 cFYI(1, ("illegal xattr request %s (only user namespace"
196 " supported)", ea_name));
197 /* BB what if no namespace prefix? */
198 /* Should we just pass them to server, except for
199 system and perhaps security prefixes? */
203 set_ea_exit:
204 kfree(full_path);
205 FreeXid(xid);
206 #endif
207 return rc;
210 ssize_t cifs_getxattr(struct dentry *direntry, const char *ea_name,
211 void *ea_value, size_t buf_size)
213 ssize_t rc = -EOPNOTSUPP;
214 #ifdef CONFIG_CIFS_XATTR
215 int xid;
216 struct cifs_sb_info *cifs_sb;
217 struct cifsTconInfo *pTcon;
218 struct super_block *sb;
219 char *full_path;
221 if (direntry == NULL)
222 return -EIO;
223 if (direntry->d_inode == NULL)
224 return -EIO;
225 sb = direntry->d_inode->i_sb;
226 if (sb == NULL)
227 return -EIO;
229 xid = GetXid();
231 cifs_sb = CIFS_SB(sb);
232 pTcon = cifs_sb->tcon;
234 full_path = build_path_from_dentry(direntry);
235 if (full_path == NULL) {
236 FreeXid(xid);
237 return -ENOMEM;
239 /* return dos attributes as pseudo xattr */
240 /* return alt name if available as pseudo attr */
241 if (ea_name == NULL) {
242 cFYI(1, ("Null xattr names not supported"));
243 } else if (strncmp(ea_name, CIFS_XATTR_USER_PREFIX, 5) == 0) {
244 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
245 goto get_ea_exit;
247 if (strncmp(ea_name, CIFS_XATTR_DOS_ATTRIB, 14) == 0) {
248 cFYI(1, ("attempt to query cifs inode metadata"));
249 /* revalidate/getattr then populate from inode */
250 } /* BB add else when above is implemented */
251 ea_name += 5; /* skip past user. prefix */
252 rc = CIFSSMBQueryEA(xid, pTcon, full_path, ea_name, ea_value,
253 buf_size, cifs_sb->local_nls,
254 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
255 } else if (strncmp(ea_name, CIFS_XATTR_OS2_PREFIX, 4) == 0) {
256 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
257 goto get_ea_exit;
259 ea_name += 4; /* skip past os2. prefix */
260 rc = CIFSSMBQueryEA(xid, pTcon, full_path, ea_name, ea_value,
261 buf_size, cifs_sb->local_nls,
262 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
263 } else if (strncmp(ea_name, POSIX_ACL_XATTR_ACCESS,
264 strlen(POSIX_ACL_XATTR_ACCESS)) == 0) {
265 #ifdef CONFIG_CIFS_POSIX
266 if (sb->s_flags & MS_POSIXACL)
267 rc = CIFSSMBGetPosixACL(xid, pTcon, full_path,
268 ea_value, buf_size, ACL_TYPE_ACCESS,
269 cifs_sb->local_nls,
270 cifs_sb->mnt_cifs_flags &
271 CIFS_MOUNT_MAP_SPECIAL_CHR);
272 #ifdef CONFIG_CIFS_EXPERIMENTAL
273 <<<<<<< HEAD:fs/cifs/xattr.c
274 else if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL) {
275 =======
276 else if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL) {
277 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:fs/cifs/xattr.c
278 __u16 fid;
279 int oplock = FALSE;
280 struct cifs_ntsd *pacl = NULL;
281 __u32 buflen = 0;
282 if (experimEnabled)
283 rc = CIFSSMBOpen(xid, pTcon, full_path,
284 FILE_OPEN, GENERIC_READ, 0, &fid,
285 &oplock, NULL, cifs_sb->local_nls,
286 cifs_sb->mnt_cifs_flags &
287 CIFS_MOUNT_MAP_SPECIAL_CHR);
288 /* else rc is EOPNOTSUPP from above */
290 if (rc == 0) {
291 rc = CIFSSMBGetCIFSACL(xid, pTcon, fid, &pacl,
292 &buflen);
293 CIFSSMBClose(xid, pTcon, fid);
296 #endif /* EXPERIMENTAL */
297 #else
298 cFYI(1, ("query POSIX ACL not supported yet"));
299 #endif /* CONFIG_CIFS_POSIX */
300 } else if (strncmp(ea_name, POSIX_ACL_XATTR_DEFAULT,
301 strlen(POSIX_ACL_XATTR_DEFAULT)) == 0) {
302 #ifdef CONFIG_CIFS_POSIX
303 if (sb->s_flags & MS_POSIXACL)
304 rc = CIFSSMBGetPosixACL(xid, pTcon, full_path,
305 ea_value, buf_size, ACL_TYPE_DEFAULT,
306 cifs_sb->local_nls,
307 cifs_sb->mnt_cifs_flags &
308 CIFS_MOUNT_MAP_SPECIAL_CHR);
309 #else
310 cFYI(1, ("query POSIX default ACL not supported yet"));
311 #endif
312 } else if (strncmp(ea_name,
313 CIFS_XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN) == 0) {
314 cFYI(1, ("Trusted xattr namespace not supported yet"));
315 } else if (strncmp(ea_name,
316 CIFS_XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN) == 0) {
317 cFYI(1, ("Security xattr namespace not supported yet"));
318 <<<<<<< HEAD:fs/cifs/xattr.c
319 } else {
320 =======
321 } else
322 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:fs/cifs/xattr.c
323 cFYI(1,
324 ("illegal xattr request %s (only user namespace supported)",
325 ea_name));
326 <<<<<<< HEAD:fs/cifs/xattr.c
328 =======
329 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:fs/cifs/xattr.c
331 /* We could add an additional check for streams ie
332 if proc/fs/cifs/streamstoxattr is set then
333 search server for EAs or streams to
334 returns as xattrs */
336 if (rc == -EINVAL)
337 rc = -EOPNOTSUPP;
339 get_ea_exit:
340 kfree(full_path);
341 FreeXid(xid);
342 #endif
343 return rc;
346 ssize_t cifs_listxattr(struct dentry *direntry, char *data, size_t buf_size)
348 ssize_t rc = -EOPNOTSUPP;
349 #ifdef CONFIG_CIFS_XATTR
350 int xid;
351 struct cifs_sb_info *cifs_sb;
352 struct cifsTconInfo *pTcon;
353 struct super_block *sb;
354 char *full_path;
356 if (direntry == NULL)
357 return -EIO;
358 if (direntry->d_inode == NULL)
359 return -EIO;
360 sb = direntry->d_inode->i_sb;
361 if (sb == NULL)
362 return -EIO;
364 cifs_sb = CIFS_SB(sb);
365 pTcon = cifs_sb->tcon;
367 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
368 return -EOPNOTSUPP;
370 xid = GetXid();
372 full_path = build_path_from_dentry(direntry);
373 if (full_path == NULL) {
374 FreeXid(xid);
375 return -ENOMEM;
377 /* return dos attributes as pseudo xattr */
378 /* return alt name if available as pseudo attr */
380 /* if proc/fs/cifs/streamstoxattr is set then
381 search server for EAs or streams to
382 returns as xattrs */
383 rc = CIFSSMBQAllEAs(xid, pTcon, full_path, data, buf_size,
384 cifs_sb->local_nls,
385 cifs_sb->mnt_cifs_flags &
386 CIFS_MOUNT_MAP_SPECIAL_CHR);
388 kfree(full_path);
389 FreeXid(xid);
390 #endif
391 return rc;