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>
24 #include <linux/slab.h>
28 #include "cifsproto.h"
29 #include "cifs_debug.h"
31 #define MAX_EA_VALUE_SIZE 65535
32 #define CIFS_XATTR_DOS_ATTRIB "user.DosAttrib"
33 #define CIFS_XATTR_CIFS_ACL "system.cifs_acl"
34 #define CIFS_XATTR_USER_PREFIX "user."
35 #define CIFS_XATTR_SYSTEM_PREFIX "system."
36 #define CIFS_XATTR_OS2_PREFIX "os2."
37 #define CIFS_XATTR_SECURITY_PREFIX "security."
38 #define CIFS_XATTR_TRUSTED_PREFIX "trusted."
39 #define XATTR_TRUSTED_PREFIX_LEN 8
40 #define XATTR_SECURITY_PREFIX_LEN 9
41 /* BB need to add server (Samba e.g) support for security and trusted prefix */
45 int cifs_removexattr(struct dentry
*direntry
, const char *ea_name
)
48 #ifdef CONFIG_CIFS_XATTR
50 struct cifs_sb_info
*cifs_sb
;
51 struct tcon_link
*tlink
;
52 struct cifsTconInfo
*pTcon
;
53 struct super_block
*sb
;
54 char *full_path
= NULL
;
58 if (direntry
->d_inode
== NULL
)
60 sb
= direntry
->d_inode
->i_sb
;
64 cifs_sb
= CIFS_SB(sb
);
65 tlink
= cifs_sb_tlink(cifs_sb
);
67 return PTR_ERR(tlink
);
68 pTcon
= tlink_tcon(tlink
);
72 full_path
= build_path_from_dentry(direntry
);
73 if (full_path
== NULL
) {
77 if (ea_name
== NULL
) {
78 cFYI(1, "Null xattr names not supported");
79 } else if (strncmp(ea_name
, CIFS_XATTR_USER_PREFIX
, 5)
80 && (strncmp(ea_name
, CIFS_XATTR_OS2_PREFIX
, 4))) {
82 "illegal xattr request %s (only user namespace supported)",
84 /* BB what if no namespace prefix? */
85 /* Should we just pass them to server, except for
86 system and perhaps security prefixes? */
88 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_NO_XATTR
)
91 ea_name
+= 5; /* skip past user. prefix */
92 rc
= CIFSSMBSetEA(xid
, pTcon
, full_path
, ea_name
, NULL
,
93 (__u16
)0, cifs_sb
->local_nls
,
94 cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_MAP_SPECIAL_CHR
);
99 cifs_put_tlink(tlink
);
104 int cifs_setxattr(struct dentry
*direntry
, const char *ea_name
,
105 const void *ea_value
, size_t value_size
, int flags
)
107 int rc
= -EOPNOTSUPP
;
108 #ifdef CONFIG_CIFS_XATTR
110 struct cifs_sb_info
*cifs_sb
;
111 struct tcon_link
*tlink
;
112 struct cifsTconInfo
*pTcon
;
113 struct super_block
*sb
;
115 struct cifs_ntsd
*pacl
;
117 if (direntry
== NULL
)
119 if (direntry
->d_inode
== NULL
)
121 sb
= direntry
->d_inode
->i_sb
;
125 cifs_sb
= CIFS_SB(sb
);
126 tlink
= cifs_sb_tlink(cifs_sb
);
128 return PTR_ERR(tlink
);
129 pTcon
= tlink_tcon(tlink
);
133 full_path
= build_path_from_dentry(direntry
);
134 if (full_path
== NULL
) {
138 /* return dos attributes as pseudo xattr */
139 /* return alt name if available as pseudo attr */
141 /* if proc/fs/cifs/streamstoxattr is set then
142 search server for EAs or streams to
144 if (value_size
> MAX_EA_VALUE_SIZE
) {
145 cFYI(1, "size of EA value too large");
150 if (ea_name
== NULL
) {
151 cFYI(1, "Null xattr names not supported");
152 } else if (strncmp(ea_name
, CIFS_XATTR_USER_PREFIX
, 5) == 0) {
153 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_NO_XATTR
)
155 if (strncmp(ea_name
, CIFS_XATTR_DOS_ATTRIB
, 14) == 0)
156 cFYI(1, "attempt to set cifs inode metadata");
158 ea_name
+= 5; /* skip past user. prefix */
159 rc
= CIFSSMBSetEA(xid
, pTcon
, full_path
, ea_name
, ea_value
,
160 (__u16
)value_size
, cifs_sb
->local_nls
,
161 cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_MAP_SPECIAL_CHR
);
162 } else if (strncmp(ea_name
, CIFS_XATTR_OS2_PREFIX
, 4) == 0) {
163 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_NO_XATTR
)
166 ea_name
+= 4; /* skip past os2. prefix */
167 rc
= CIFSSMBSetEA(xid
, pTcon
, full_path
, ea_name
, ea_value
,
168 (__u16
)value_size
, cifs_sb
->local_nls
,
169 cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_MAP_SPECIAL_CHR
);
170 } else if (strncmp(ea_name
, CIFS_XATTR_CIFS_ACL
,
171 strlen(CIFS_XATTR_CIFS_ACL
)) == 0) {
172 pacl
= kmalloc(value_size
, GFP_KERNEL
);
174 cFYI(1, "%s: Can't allocate memory for ACL",
178 #ifdef CONFIG_CIFS_ACL
179 memcpy(pacl
, ea_value
, value_size
);
180 rc
= set_cifs_acl(pacl
, value_size
,
181 direntry
->d_inode
, full_path
);
182 if (rc
== 0) /* force revalidate of the inode */
183 CIFS_I(direntry
->d_inode
)->time
= 0;
186 cFYI(1, "Set CIFS ACL not supported yet");
187 #endif /* CONFIG_CIFS_ACL */
191 temp
= strncmp(ea_name
, POSIX_ACL_XATTR_ACCESS
,
192 strlen(POSIX_ACL_XATTR_ACCESS
));
194 #ifdef CONFIG_CIFS_POSIX
195 if (sb
->s_flags
& MS_POSIXACL
)
196 rc
= CIFSSMBSetPosixACL(xid
, pTcon
, full_path
,
197 ea_value
, (const int)value_size
,
198 ACL_TYPE_ACCESS
, cifs_sb
->local_nls
,
199 cifs_sb
->mnt_cifs_flags
&
200 CIFS_MOUNT_MAP_SPECIAL_CHR
);
201 cFYI(1, "set POSIX ACL rc %d", rc
);
203 cFYI(1, "set POSIX ACL not supported");
205 } else if (strncmp(ea_name
, POSIX_ACL_XATTR_DEFAULT
,
206 strlen(POSIX_ACL_XATTR_DEFAULT
)) == 0) {
207 #ifdef CONFIG_CIFS_POSIX
208 if (sb
->s_flags
& MS_POSIXACL
)
209 rc
= CIFSSMBSetPosixACL(xid
, pTcon
, full_path
,
210 ea_value
, (const int)value_size
,
211 ACL_TYPE_DEFAULT
, cifs_sb
->local_nls
,
212 cifs_sb
->mnt_cifs_flags
&
213 CIFS_MOUNT_MAP_SPECIAL_CHR
);
214 cFYI(1, "set POSIX default ACL rc %d", rc
);
216 cFYI(1, "set default POSIX ACL not supported");
219 cFYI(1, "illegal xattr request %s (only user namespace"
220 " supported)", ea_name
);
221 /* BB what if no namespace prefix? */
222 /* Should we just pass them to server, except for
223 system and perhaps security prefixes? */
230 cifs_put_tlink(tlink
);
235 ssize_t
cifs_getxattr(struct dentry
*direntry
, const char *ea_name
,
236 void *ea_value
, size_t buf_size
)
238 ssize_t rc
= -EOPNOTSUPP
;
239 #ifdef CONFIG_CIFS_XATTR
241 struct cifs_sb_info
*cifs_sb
;
242 struct tcon_link
*tlink
;
243 struct cifsTconInfo
*pTcon
;
244 struct super_block
*sb
;
247 if (direntry
== NULL
)
249 if (direntry
->d_inode
== NULL
)
251 sb
= direntry
->d_inode
->i_sb
;
255 cifs_sb
= CIFS_SB(sb
);
256 tlink
= cifs_sb_tlink(cifs_sb
);
258 return PTR_ERR(tlink
);
259 pTcon
= tlink_tcon(tlink
);
263 full_path
= build_path_from_dentry(direntry
);
264 if (full_path
== NULL
) {
268 /* return dos attributes as pseudo xattr */
269 /* return alt name if available as pseudo attr */
270 if (ea_name
== NULL
) {
271 cFYI(1, "Null xattr names not supported");
272 } else if (strncmp(ea_name
, CIFS_XATTR_USER_PREFIX
, 5) == 0) {
273 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_NO_XATTR
)
276 if (strncmp(ea_name
, CIFS_XATTR_DOS_ATTRIB
, 14) == 0) {
277 cFYI(1, "attempt to query cifs inode metadata");
278 /* revalidate/getattr then populate from inode */
279 } /* BB add else when above is implemented */
280 ea_name
+= 5; /* skip past user. prefix */
281 rc
= CIFSSMBQAllEAs(xid
, pTcon
, full_path
, ea_name
, ea_value
,
282 buf_size
, cifs_sb
->local_nls
,
283 cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_MAP_SPECIAL_CHR
);
284 } else if (strncmp(ea_name
, CIFS_XATTR_OS2_PREFIX
, 4) == 0) {
285 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_NO_XATTR
)
288 ea_name
+= 4; /* skip past os2. prefix */
289 rc
= CIFSSMBQAllEAs(xid
, pTcon
, full_path
, ea_name
, ea_value
,
290 buf_size
, cifs_sb
->local_nls
,
291 cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_MAP_SPECIAL_CHR
);
292 } else if (strncmp(ea_name
, POSIX_ACL_XATTR_ACCESS
,
293 strlen(POSIX_ACL_XATTR_ACCESS
)) == 0) {
294 #ifdef CONFIG_CIFS_POSIX
295 if (sb
->s_flags
& MS_POSIXACL
)
296 rc
= CIFSSMBGetPosixACL(xid
, pTcon
, full_path
,
297 ea_value
, buf_size
, ACL_TYPE_ACCESS
,
299 cifs_sb
->mnt_cifs_flags
&
300 CIFS_MOUNT_MAP_SPECIAL_CHR
);
302 cFYI(1, "Query POSIX ACL not supported yet");
303 #endif /* CONFIG_CIFS_POSIX */
304 } else if (strncmp(ea_name
, POSIX_ACL_XATTR_DEFAULT
,
305 strlen(POSIX_ACL_XATTR_DEFAULT
)) == 0) {
306 #ifdef CONFIG_CIFS_POSIX
307 if (sb
->s_flags
& MS_POSIXACL
)
308 rc
= CIFSSMBGetPosixACL(xid
, pTcon
, full_path
,
309 ea_value
, buf_size
, ACL_TYPE_DEFAULT
,
311 cifs_sb
->mnt_cifs_flags
&
312 CIFS_MOUNT_MAP_SPECIAL_CHR
);
314 cFYI(1, "Query POSIX default ACL not supported yet");
315 #endif /* CONFIG_CIFS_POSIX */
316 } else if (strncmp(ea_name
, CIFS_XATTR_CIFS_ACL
,
317 strlen(CIFS_XATTR_CIFS_ACL
)) == 0) {
318 #ifdef CONFIG_CIFS_ACL
320 struct cifs_ntsd
*pacl
;
322 pacl
= get_cifs_acl(cifs_sb
, direntry
->d_inode
,
326 cERROR(1, "%s: error %zd getting sec desc",
330 if (acllen
> buf_size
)
333 memcpy(ea_value
, pacl
, acllen
);
339 cFYI(1, "Query CIFS ACL not supported yet");
340 #endif /* CONFIG_CIFS_ACL */
341 } else if (strncmp(ea_name
,
342 CIFS_XATTR_TRUSTED_PREFIX
, XATTR_TRUSTED_PREFIX_LEN
) == 0) {
343 cFYI(1, "Trusted xattr namespace not supported yet");
344 } else if (strncmp(ea_name
,
345 CIFS_XATTR_SECURITY_PREFIX
, XATTR_SECURITY_PREFIX_LEN
) == 0) {
346 cFYI(1, "Security xattr namespace not supported yet");
349 "illegal xattr request %s (only user namespace supported)",
352 /* We could add an additional check for streams ie
353 if proc/fs/cifs/streamstoxattr is set then
354 search server for EAs or streams to
363 cifs_put_tlink(tlink
);
368 ssize_t
cifs_listxattr(struct dentry
*direntry
, char *data
, size_t buf_size
)
370 ssize_t rc
= -EOPNOTSUPP
;
371 #ifdef CONFIG_CIFS_XATTR
373 struct cifs_sb_info
*cifs_sb
;
374 struct tcon_link
*tlink
;
375 struct cifsTconInfo
*pTcon
;
376 struct super_block
*sb
;
379 if (direntry
== NULL
)
381 if (direntry
->d_inode
== NULL
)
383 sb
= direntry
->d_inode
->i_sb
;
387 cifs_sb
= CIFS_SB(sb
);
388 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_NO_XATTR
)
391 tlink
= cifs_sb_tlink(cifs_sb
);
393 return PTR_ERR(tlink
);
394 pTcon
= tlink_tcon(tlink
);
398 full_path
= build_path_from_dentry(direntry
);
399 if (full_path
== NULL
) {
403 /* return dos attributes as pseudo xattr */
404 /* return alt name if available as pseudo attr */
406 /* if proc/fs/cifs/streamstoxattr is set then
407 search server for EAs or streams to
409 rc
= CIFSSMBQAllEAs(xid
, pTcon
, full_path
, NULL
, data
,
410 buf_size
, cifs_sb
->local_nls
,
411 cifs_sb
->mnt_cifs_flags
&
412 CIFS_MOUNT_MAP_SPECIAL_CHR
);
417 cifs_put_tlink(tlink
);