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 <<<<<<< HEAD
:fs
/cifs
/xattr
.c
143 if (strncmp(ea_name
, CIFS_XATTR_DOS_ATTRIB
, 14) == 0) {
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
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
)
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
);
167 temp
= strncmp(ea_name
, POSIX_ACL_XATTR_ACCESS
,
168 strlen(POSIX_ACL_XATTR_ACCESS
));
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
));
179 cFYI(1, ("set POSIX ACL not supported"));
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
));
192 cFYI(1, ("set default POSIX ACL not supported"));
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? */
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
216 struct cifs_sb_info
*cifs_sb
;
217 struct cifsTconInfo
*pTcon
;
218 struct super_block
*sb
;
221 if (direntry
== NULL
)
223 if (direntry
->d_inode
== NULL
)
225 sb
= direntry
->d_inode
->i_sb
;
231 cifs_sb
= CIFS_SB(sb
);
232 pTcon
= cifs_sb
->tcon
;
234 full_path
= build_path_from_dentry(direntry
);
235 if (full_path
== NULL
) {
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
)
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
)
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
,
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
) {
276 else if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_CIFS_ACL
) {
277 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:fs
/cifs
/xattr
.c
280 struct cifs_ntsd
*pacl
= NULL
;
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 */
291 rc
= CIFSSMBGetCIFSACL(xid
, pTcon
, fid
, &pacl
,
293 CIFSSMBClose(xid
, pTcon
, fid
);
296 #endif /* EXPERIMENTAL */
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
,
307 cifs_sb
->mnt_cifs_flags
&
308 CIFS_MOUNT_MAP_SPECIAL_CHR
);
310 cFYI(1, ("query POSIX default ACL not supported yet"));
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
322 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:fs
/cifs
/xattr
.c
324 ("illegal xattr request %s (only user namespace supported)",
326 <<<<<<< HEAD
:fs
/cifs
/xattr
.c
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
346 ssize_t
cifs_listxattr(struct dentry
*direntry
, char *data
, size_t buf_size
)
348 ssize_t rc
= -EOPNOTSUPP
;
349 #ifdef CONFIG_CIFS_XATTR
351 struct cifs_sb_info
*cifs_sb
;
352 struct cifsTconInfo
*pTcon
;
353 struct super_block
*sb
;
356 if (direntry
== NULL
)
358 if (direntry
->d_inode
== NULL
)
360 sb
= direntry
->d_inode
->i_sb
;
364 cifs_sb
= CIFS_SB(sb
);
365 pTcon
= cifs_sb
->tcon
;
367 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_NO_XATTR
)
372 full_path
= build_path_from_dentry(direntry
);
373 if (full_path
== NULL
) {
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
383 rc
= CIFSSMBQAllEAs(xid
, pTcon
, full_path
, data
, buf_size
,
385 cifs_sb
->mnt_cifs_flags
&
386 CIFS_MOUNT_MAP_SPECIAL_CHR
);