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"
24 #include "../lib/util/wrap_xattr.h"
27 pull a xattr as a blob, from either a file or a file descriptor
29 NTSTATUS
pull_xattr_blob_system(struct pvfs_state
*pvfs
,
31 const char *attr_name
,
34 size_t estimated_size
,
39 *blob
= data_blob_talloc(mem_ctx
, NULL
, estimated_size
+16);
40 if (blob
->data
== NULL
) {
41 return NT_STATUS_NO_MEMORY
;
46 ret
= wrap_fgetxattr(fd
, attr_name
, blob
->data
, estimated_size
);
48 ret
= wrap_getxattr(fname
, attr_name
, blob
->data
, estimated_size
);
50 if (ret
== -1 && errno
== ERANGE
) {
52 blob
->data
= talloc_realloc(mem_ctx
, blob
->data
,
53 uint8_t, estimated_size
);
54 if (blob
->data
== NULL
) {
55 return NT_STATUS_NO_MEMORY
;
57 blob
->length
= estimated_size
;
60 if (ret
== -1 && errno
== EPERM
) {
64 ret
= fstat(fd
, &statbuf
);
66 ret
= stat(fname
, &statbuf
);
69 /* check if this is a directory and the sticky bit is set */
70 if (S_ISDIR(statbuf
.st_mode
) && (statbuf
.st_mode
& S_ISVTX
)) {
71 /* pretend we could not find the xattr */
74 return NT_STATUS_NOT_FOUND
;
77 /* if not this was probably a legitimate error
78 * reset ret and errno to the correct values */
87 return pvfs_map_errno(pvfs
, errno
);
96 push a xattr as a blob, from either a file or a file descriptor
98 NTSTATUS
push_xattr_blob_system(struct pvfs_state
*pvfs
,
99 const char *attr_name
,
102 const DATA_BLOB
*blob
)
107 ret
= wrap_fsetxattr(fd
, attr_name
, blob
->data
, blob
->length
, 0);
109 ret
= wrap_setxattr(fname
, attr_name
, blob
->data
, blob
->length
, 0);
112 return pvfs_map_errno(pvfs
, errno
);
122 NTSTATUS
delete_xattr_system(struct pvfs_state
*pvfs
, const char *attr_name
,
123 const char *fname
, int fd
)
128 ret
= wrap_fremovexattr(fd
, attr_name
);
130 ret
= wrap_removexattr(fname
, attr_name
);
133 return pvfs_map_errno(pvfs
, errno
);
140 unlink a file - cleanup any xattrs
142 NTSTATUS
unlink_xattr_system(struct pvfs_state
*pvfs
, const char *fname
)
144 /* nothing needs to be done for filesystem based xattrs */