kcc: Add corresponding methods for repsTo
[Samba.git] / source3 / modules / lib_vxfs.c
blob0d5ea607f2738d7a58b55838c28dcb8b27781fd4
1 /*
2 Unix SMB/CIFS implementation.
3 Wrap VxFS xattr calls.
5 Copyright (C) Veritas Technologies LLC <www.veritas.com> 2016
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program 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 the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "includes.h"
22 #include "smbd/smbd.h"
23 #include "system/filesys.h"
24 #include "string.h"
27 * Available under GPL at
28 * http://www.veritas.com/community/downloads/vxfsmisc-library
30 #define LIBVXFS "/usr/lib64/vxfsmisc.so"
33 static int (*vxfs_setxattr_fd_func) (int fd, const char *name,
34 const void *value, size_t len, int flags);
35 static int (*vxfs_getxattr_fd_func) (int fd, const char *name, void *value,
36 size_t *len);
37 static int (*vxfs_removexattr_fd_func) (int fd, const char *name);
38 static int (*vxfs_listxattr_fd_func) (int fd, void *value, size_t *len);
40 int vxfs_setxattr_fd(int fd, const char *name, const void *value,
41 size_t len, int flags)
43 int ret = -1;
45 if (vxfs_setxattr_fd_func == NULL) {
46 errno = ENOSYS;
47 return ret;
50 DEBUG(10, ("Calling vxfs_setxattr_fd\n"));
51 ret = vxfs_setxattr_fd_func(fd, name, value, len, flags);
52 if (ret) {
53 errno = ret;
54 ret = -1;
57 return ret;
60 int vxfs_setxattr_path(const char *path, const char *name, const void *value,
61 size_t len, int flags, bool is_dir)
63 int ret, fd = -1;
65 if (is_dir) {
66 fd = open(path, O_RDONLY|O_DIRECTORY);
67 } else {
68 fd = open(path, O_WRONLY);
71 if (fd == -1) {
72 DEBUG(10, ("error in vxfs_setxattr_path: %s\n",
73 strerror(errno)));
74 return -1;
77 ret = vxfs_setxattr_fd(fd, name, value, len, flags);
79 close(fd);
81 return ret;
84 int vxfs_getxattr_fd(int fd, const char *name, void *value, size_t len)
86 int ret;
87 size_t size = len;
89 if (vxfs_getxattr_fd_func == NULL) {
90 errno = ENOSYS;
91 return -1;
94 DEBUG(10, ("Calling vxfs_getxattr_fd with %s\n", name));
95 ret = vxfs_getxattr_fd_func(fd, name, value, &size);
96 if (ret) {
97 errno = ret;
98 if (ret == EFBIG) {
99 errno = ERANGE;
101 return -1;
104 return size;
107 int vxfs_getxattr_path(const char *path, const char *name, void *value,
108 size_t len)
110 int ret, fd = -1;
112 fd = open(path, O_RDONLY);
113 if (fd == -1) {
114 DEBUG(10, ("file not opened: vxfs_getxattr_path for %s\n",
115 path));
116 return -1;
119 ret = vxfs_getxattr_fd(fd, name, value, len);
120 close(fd);
122 return ret;
125 int vxfs_removexattr_fd(int fd, const char *name)
127 int ret = 0;
129 if (vxfs_removexattr_fd_func == NULL) {
130 errno = ENOSYS;
131 return -1;
134 DEBUG(10, ("Calling vxfs_removexattr_fd with %s\n", name));
135 ret = vxfs_removexattr_fd_func(fd, name);
136 if (ret) {
137 errno = ret;
138 ret = -1;
141 return ret;
144 int vxfs_removexattr_path(const char *path, const char *name, bool is_dir)
146 int ret, fd = -1;
148 if (is_dir) {
149 fd = open(path, O_RDONLY|O_DIRECTORY);
150 } else {
151 fd = open(path, O_WRONLY);
153 if (fd == -1) {
154 DEBUG(10, ("file not opened: vxfs_removexattr_path for %s\n",
155 path));
156 return -1;
159 ret = vxfs_removexattr_fd(fd, name);
160 close(fd);
162 return ret;
165 int vxfs_listxattr_fd(int fd, char *list, size_t size)
167 int ret;
168 size_t len = size;
170 if (vxfs_listxattr_fd_func == NULL) {
171 errno = ENOSYS;
172 return -1;
175 ret = vxfs_listxattr_fd_func(fd, list, &len);
176 DEBUG(10, ("vxfs_listxattr_fd: returned ret = %d\n", ret));
177 if (ret) {
178 errno = ret;
179 if (ret == EFBIG) {
180 errno = ERANGE;
182 return -1;
185 return len;
188 int vxfs_listxattr_path(const char *path, char *list, size_t size)
190 int ret, fd = -1;
192 fd = open(path, O_RDONLY);
193 if (fd == -1) {
194 DEBUG(10, ("file not opened: vxfs_listxattr_path for %s\n",
195 path));
196 return -1;
199 ret = vxfs_listxattr_fd(fd, list, size);
200 close(fd);
202 return ret;
205 static bool load_lib_vxfs_function(void *lib_handle, void *fn_ptr,
206 const char *fnc_name)
208 void **vlib_handle = (void **)lib_handle;
209 void **fn_pointer = (void **)fn_ptr;
211 *fn_pointer = dlsym(*vlib_handle, fnc_name);
212 if (*fn_pointer == NULL) {
213 DEBUG(10, ("Cannot find symbol for %s\n", fnc_name));
214 return true;
217 return false;
220 void vxfs_init()
222 static void *lib_handle = NULL;
224 if (lib_handle != NULL ) {
225 return;
228 lib_handle = dlopen(LIBVXFS, RTLD_LAZY);
229 if (lib_handle == NULL) {
230 DEBUG(10, ("Cannot get lib handle\n"));
231 return;
234 DEBUG(10, ("Calling vxfs_init\n"));
235 load_lib_vxfs_function(&lib_handle, &vxfs_setxattr_fd_func,
236 "vxfs_nxattr_set");
237 load_lib_vxfs_function(&lib_handle, &vxfs_getxattr_fd_func,
238 "vxfs_nxattr_get");
239 load_lib_vxfs_function(&lib_handle, &vxfs_removexattr_fd_func,
240 "vxfs_nxattr_remove");
241 load_lib_vxfs_function(&lib_handle, &vxfs_listxattr_fd_func,
242 "vxfs_nxattr_list");