2 Unix SMB/CIFS implementation.
4 POSIX NTVFS backend - xattr support using filesystem xattrs
6 Copyright (C) Andrew Tridgell 2004
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "vfs_posix.h"
26 pull a xattr as a blob, from either a file or a file descriptor
28 NTSTATUS
pull_xattr_blob_system(struct pvfs_state
*pvfs
,
30 const char *attr_name
,
33 size_t estimated_size
,
38 *blob
= data_blob_talloc(mem_ctx
, NULL
, estimated_size
+16);
39 if (blob
->data
== NULL
) {
40 return NT_STATUS_NO_MEMORY
;
45 ret
= fgetxattr(fd
, attr_name
, blob
->data
, estimated_size
);
47 ret
= getxattr(fname
, attr_name
, blob
->data
, estimated_size
);
49 if (ret
== -1 && errno
== ERANGE
) {
51 blob
->data
= talloc_realloc(mem_ctx
, blob
->data
,
52 uint8_t, estimated_size
);
53 if (blob
->data
== NULL
) {
54 return NT_STATUS_NO_MEMORY
;
56 blob
->length
= estimated_size
;
59 if (ret
== -1 && errno
== EPERM
) {
63 ret
= fstat(fd
, &statbuf
);
65 ret
= stat(fname
, &statbuf
);
68 /* check if this is a directory and the sticky bit is set */
69 if (S_ISDIR(statbuf
.st_mode
) && (statbuf
.st_mode
& S_ISVTX
)) {
70 /* pretend we could not find the xattr */
73 return NT_STATUS_NOT_FOUND
;
76 /* if not this was probably a legitimate error
77 * reset ret and errno to the correct values */
86 return pvfs_map_errno(pvfs
, errno
);
95 push a xattr as a blob, from either a file or a file descriptor
97 NTSTATUS
push_xattr_blob_system(struct pvfs_state
*pvfs
,
98 const char *attr_name
,
101 const DATA_BLOB
*blob
)
106 ret
= fsetxattr(fd
, attr_name
, blob
->data
, blob
->length
, 0);
108 ret
= setxattr(fname
, attr_name
, blob
->data
, blob
->length
, 0);
111 return pvfs_map_errno(pvfs
, errno
);
121 NTSTATUS
delete_xattr_system(struct pvfs_state
*pvfs
, const char *attr_name
,
122 const char *fname
, int fd
)
127 ret
= fremovexattr(fd
, attr_name
);
129 ret
= removexattr(fname
, attr_name
);
132 return pvfs_map_errno(pvfs
, errno
);
139 unlink a file - cleanup any xattrs
141 NTSTATUS
unlink_xattr_system(struct pvfs_state
*pvfs
, const char *fname
)
143 /* nothing needs to be done for filesystem based xattrs */