dsdb-schema: make schema_subclasses_order_recurse() static
[Samba/gebeck_regimport.git] / source4 / ntvfs / posix / xattr_system.c
blobebb2010e381f10ca5d234783757fbb5fe3370287
1 /*
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/>.
22 #include "includes.h"
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,
29 TALLOC_CTX *mem_ctx,
30 const char *attr_name,
31 const char *fname,
32 int fd,
33 size_t estimated_size,
34 DATA_BLOB *blob)
36 int ret;
38 *blob = data_blob_talloc(mem_ctx, NULL, estimated_size+16);
39 if (blob->data == NULL) {
40 return NT_STATUS_NO_MEMORY;
43 again:
44 if (fd != -1) {
45 ret = fgetxattr(fd, attr_name, blob->data, estimated_size);
46 } else {
47 ret = getxattr(fname, attr_name, blob->data, estimated_size);
49 if (ret == -1 && errno == ERANGE) {
50 estimated_size *= 2;
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;
57 goto again;
59 if (ret == -1 && errno == EPERM) {
60 struct stat statbuf;
62 if (fd != -1) {
63 ret = fstat(fd, &statbuf);
64 } else {
65 ret = stat(fname, &statbuf);
67 if (ret == 0) {
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 */
72 data_blob_free(blob);
73 return NT_STATUS_NOT_FOUND;
75 } else {
76 /* if not this was probably a legitimate error
77 * reset ret and errno to the correct values */
78 errno = EPERM;
79 ret = -1;
84 if (ret == -1) {
85 data_blob_free(blob);
86 return pvfs_map_errno(pvfs, errno);
89 blob->length = ret;
91 return NT_STATUS_OK;
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,
99 const char *fname,
100 int fd,
101 const DATA_BLOB *blob)
103 int ret;
105 if (fd != -1) {
106 ret = fsetxattr(fd, attr_name, blob->data, blob->length, 0);
107 } else {
108 ret = setxattr(fname, attr_name, blob->data, blob->length, 0);
110 if (ret == -1) {
111 return pvfs_map_errno(pvfs, errno);
114 return NT_STATUS_OK;
119 delete a xattr
121 NTSTATUS delete_xattr_system(struct pvfs_state *pvfs, const char *attr_name,
122 const char *fname, int fd)
124 int ret;
126 if (fd != -1) {
127 ret = fremovexattr(fd, attr_name);
128 } else {
129 ret = removexattr(fname, attr_name);
131 if (ret == -1) {
132 return pvfs_map_errno(pvfs, errno);
135 return NT_STATUS_OK;
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 */
144 return NT_STATUS_OK;