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>
25 #include <linux/xattr.h>
29 #include "cifsproto.h"
30 #include "cifs_debug.h"
31 #include "cifs_fs_sb.h"
32 #include "cifs_unicode.h"
34 #define MAX_EA_VALUE_SIZE 65535
35 #define CIFS_XATTR_DOS_ATTRIB "user.DosAttrib"
36 #define CIFS_XATTR_CIFS_ACL "system.cifs_acl"
38 /* BB need to add server (Samba e.g) support for security and trusted prefix */
40 int cifs_removexattr(struct dentry *direntry, const char *ea_name)
43 #ifdef CONFIG_CIFS_XATTR
45 struct cifs_sb_info *cifs_sb = CIFS_SB(direntry->d_sb);
46 struct tcon_link *tlink;
47 struct cifs_tcon *pTcon;
48 char *full_path = NULL;
50 tlink = cifs_sb_tlink(cifs_sb);
52 return PTR_ERR(tlink);
53 pTcon = tlink_tcon(tlink);
57 full_path = build_path_from_dentry(direntry);
58 if (full_path == NULL) {
62 if (ea_name == NULL) {
63 cifs_dbg(FYI, "Null xattr names not supported\n");
64 } else if (strncmp(ea_name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)
65 && (strncmp(ea_name, XATTR_OS2_PREFIX, XATTR_OS2_PREFIX_LEN))) {
67 "illegal xattr request %s (only user namespace supported)\n",
69 /* BB what if no namespace prefix? */
70 /* Should we just pass them to server, except for
71 system and perhaps security prefixes? */
73 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
76 ea_name += XATTR_USER_PREFIX_LEN; /* skip past user. prefix */
77 if (pTcon->ses->server->ops->set_EA)
78 rc = pTcon->ses->server->ops->set_EA(xid, pTcon,
79 full_path, ea_name, NULL, (__u16)0,
80 cifs_sb->local_nls, cifs_remap(cifs_sb));
85 cifs_put_tlink(tlink);
90 int cifs_setxattr(struct dentry *direntry, const char *ea_name,
91 const void *ea_value, size_t value_size, int flags)
94 #ifdef CONFIG_CIFS_XATTR
96 struct super_block *sb = direntry->d_sb;
97 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
98 struct tcon_link *tlink;
99 struct cifs_tcon *pTcon;
102 tlink = cifs_sb_tlink(cifs_sb);
104 return PTR_ERR(tlink);
105 pTcon = tlink_tcon(tlink);
109 full_path = build_path_from_dentry(direntry);
110 if (full_path == NULL) {
114 /* return dos attributes as pseudo xattr */
115 /* return alt name if available as pseudo attr */
117 /* if proc/fs/cifs/streamstoxattr is set then
118 search server for EAs or streams to
120 if (value_size > MAX_EA_VALUE_SIZE) {
121 cifs_dbg(FYI, "size of EA value too large\n");
126 if (ea_name == NULL) {
127 cifs_dbg(FYI, "Null xattr names not supported\n");
128 } else if (strncmp(ea_name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)
130 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
132 if (strncmp(ea_name, CIFS_XATTR_DOS_ATTRIB, 14) == 0)
133 cifs_dbg(FYI, "attempt to set cifs inode metadata\n");
135 ea_name += XATTR_USER_PREFIX_LEN; /* skip past user. prefix */
136 if (pTcon->ses->server->ops->set_EA)
137 rc = pTcon->ses->server->ops->set_EA(xid, pTcon,
138 full_path, ea_name, ea_value, (__u16)value_size,
139 cifs_sb->local_nls, cifs_remap(cifs_sb));
140 } else if (strncmp(ea_name, XATTR_OS2_PREFIX, XATTR_OS2_PREFIX_LEN)
142 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
145 ea_name += XATTR_OS2_PREFIX_LEN; /* skip past os2. prefix */
146 if (pTcon->ses->server->ops->set_EA)
147 rc = pTcon->ses->server->ops->set_EA(xid, pTcon,
148 full_path, ea_name, ea_value, (__u16)value_size,
149 cifs_sb->local_nls, cifs_remap(cifs_sb));
150 } else if (strncmp(ea_name, CIFS_XATTR_CIFS_ACL,
151 strlen(CIFS_XATTR_CIFS_ACL)) == 0) {
152 #ifdef CONFIG_CIFS_ACL
153 struct cifs_ntsd *pacl;
154 pacl = kmalloc(value_size, GFP_KERNEL);
158 memcpy(pacl, ea_value, value_size);
159 if (pTcon->ses->server->ops->set_acl)
160 rc = pTcon->ses->server->ops->set_acl(pacl,
161 value_size, d_inode(direntry),
162 full_path, CIFS_ACL_DACL);
165 if (rc == 0) /* force revalidate of the inode */
166 CIFS_I(d_inode(direntry))->time = 0;
170 cifs_dbg(FYI, "Set CIFS ACL not supported yet\n");
171 #endif /* CONFIG_CIFS_ACL */
174 temp = strncmp(ea_name, XATTR_NAME_POSIX_ACL_ACCESS,
175 strlen(XATTR_NAME_POSIX_ACL_ACCESS));
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_ACCESS, cifs_sb->local_nls,
182 cifs_remap(cifs_sb));
183 cifs_dbg(FYI, "set POSIX ACL rc %d\n", rc);
185 cifs_dbg(FYI, "set POSIX ACL not supported\n");
187 } else if (strncmp(ea_name, XATTR_NAME_POSIX_ACL_DEFAULT,
188 strlen(XATTR_NAME_POSIX_ACL_DEFAULT)) == 0) {
189 #ifdef CONFIG_CIFS_POSIX
190 if (sb->s_flags & MS_POSIXACL)
191 rc = CIFSSMBSetPosixACL(xid, pTcon, full_path,
192 ea_value, (const int)value_size,
193 ACL_TYPE_DEFAULT, cifs_sb->local_nls,
194 cifs_remap(cifs_sb));
195 cifs_dbg(FYI, "set POSIX default ACL rc %d\n", rc);
197 cifs_dbg(FYI, "set default POSIX ACL not supported\n");
200 cifs_dbg(FYI, "illegal xattr request %s (only user namespace supported)\n",
202 /* BB what if no namespace prefix? */
203 /* Should we just pass them to server, except for
204 system and perhaps security prefixes? */
211 cifs_put_tlink(tlink);
216 ssize_t cifs_getxattr(struct dentry *direntry, const char *ea_name,
217 void *ea_value, size_t buf_size)
219 ssize_t rc = -EOPNOTSUPP;
220 #ifdef CONFIG_CIFS_XATTR
222 struct super_block *sb = direntry->d_sb;
223 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
224 struct tcon_link *tlink;
225 struct cifs_tcon *pTcon;
228 tlink = cifs_sb_tlink(cifs_sb);
230 return PTR_ERR(tlink);
231 pTcon = tlink_tcon(tlink);
235 full_path = build_path_from_dentry(direntry);
236 if (full_path == NULL) {
240 /* return dos attributes as pseudo xattr */
241 /* return alt name if available as pseudo attr */
242 if (ea_name == NULL) {
243 cifs_dbg(FYI, "Null xattr names not supported\n");
244 } else if (strncmp(ea_name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)
246 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
249 if (strncmp(ea_name, CIFS_XATTR_DOS_ATTRIB, 14) == 0) {
250 cifs_dbg(FYI, "attempt to query cifs inode metadata\n");
251 /* revalidate/getattr then populate from inode */
252 } /* BB add else when above is implemented */
253 ea_name += XATTR_USER_PREFIX_LEN; /* skip past user. prefix */
254 if (pTcon->ses->server->ops->query_all_EAs)
255 rc = pTcon->ses->server->ops->query_all_EAs(xid, pTcon,
256 full_path, ea_name, ea_value, buf_size,
257 cifs_sb->local_nls, cifs_remap(cifs_sb));
258 } else if (strncmp(ea_name, XATTR_OS2_PREFIX, XATTR_OS2_PREFIX_LEN) == 0) {
259 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
262 ea_name += XATTR_OS2_PREFIX_LEN; /* skip past os2. prefix */
263 if (pTcon->ses->server->ops->query_all_EAs)
264 rc = pTcon->ses->server->ops->query_all_EAs(xid, pTcon,
265 full_path, ea_name, ea_value, buf_size,
266 cifs_sb->local_nls, cifs_remap(cifs_sb));
267 } else if (strncmp(ea_name, XATTR_NAME_POSIX_ACL_ACCESS,
268 strlen(XATTR_NAME_POSIX_ACL_ACCESS)) == 0) {
269 #ifdef CONFIG_CIFS_POSIX
270 if (sb->s_flags & MS_POSIXACL)
271 rc = CIFSSMBGetPosixACL(xid, pTcon, full_path,
272 ea_value, buf_size, ACL_TYPE_ACCESS,
274 cifs_remap(cifs_sb));
276 cifs_dbg(FYI, "Query POSIX ACL not supported yet\n");
277 #endif /* CONFIG_CIFS_POSIX */
278 } else if (strncmp(ea_name, XATTR_NAME_POSIX_ACL_DEFAULT,
279 strlen(XATTR_NAME_POSIX_ACL_DEFAULT)) == 0) {
280 #ifdef CONFIG_CIFS_POSIX
281 if (sb->s_flags & MS_POSIXACL)
282 rc = CIFSSMBGetPosixACL(xid, pTcon, full_path,
283 ea_value, buf_size, ACL_TYPE_DEFAULT,
285 cifs_remap(cifs_sb));
287 cifs_dbg(FYI, "Query POSIX default ACL not supported yet\n");
288 #endif /* CONFIG_CIFS_POSIX */
289 } else if (strncmp(ea_name, CIFS_XATTR_CIFS_ACL,
290 strlen(CIFS_XATTR_CIFS_ACL)) == 0) {
291 #ifdef CONFIG_CIFS_ACL
293 struct cifs_ntsd *pacl;
295 if (pTcon->ses->server->ops->get_acl == NULL)
296 goto get_ea_exit; /* rc already EOPNOTSUPP */
298 pacl = pTcon->ses->server->ops->get_acl(cifs_sb,
299 d_inode(direntry), full_path, &acllen);
302 cifs_dbg(VFS, "%s: error %zd getting sec desc\n",
306 if (acllen > buf_size)
309 memcpy(ea_value, pacl, acllen);
315 cifs_dbg(FYI, "Query CIFS ACL not supported yet\n");
316 #endif /* CONFIG_CIFS_ACL */
317 } else if (strncmp(ea_name,
318 XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN) == 0) {
319 cifs_dbg(FYI, "Trusted xattr namespace not supported yet\n");
320 } else if (strncmp(ea_name,
321 XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN) == 0) {
322 cifs_dbg(FYI, "Security xattr namespace not supported yet\n");
325 "illegal xattr request %s (only user namespace supported)\n",
328 /* We could add an additional check for streams ie
329 if proc/fs/cifs/streamstoxattr is set then
330 search server for EAs or streams to
339 cifs_put_tlink(tlink);
344 ssize_t cifs_listxattr(struct dentry *direntry, char *data, size_t buf_size)
346 ssize_t rc = -EOPNOTSUPP;
347 #ifdef CONFIG_CIFS_XATTR
349 struct cifs_sb_info *cifs_sb = CIFS_SB(direntry->d_sb);
350 struct tcon_link *tlink;
351 struct cifs_tcon *pTcon;
354 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
357 tlink = cifs_sb_tlink(cifs_sb);
359 return PTR_ERR(tlink);
360 pTcon = tlink_tcon(tlink);
364 full_path = build_path_from_dentry(direntry);
365 if (full_path == NULL) {
369 /* return dos attributes as pseudo xattr */
370 /* return alt name if available as pseudo attr */
372 /* if proc/fs/cifs/streamstoxattr is set then
373 search server for EAs or streams to
376 if (pTcon->ses->server->ops->query_all_EAs)
377 rc = pTcon->ses->server->ops->query_all_EAs(xid, pTcon,
378 full_path, NULL, data, buf_size,
379 cifs_sb->local_nls, cifs_remap(cifs_sb));
383 cifs_put_tlink(tlink);