2 Unix SMB/CIFS implementation.
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/>.
22 #include "smbd/smbd.h"
23 #include "system/filesys.h"
28 * Available under GPL at
29 * http://www.veritas.com/community/downloads/vxfsmisc-library
31 #define LIBVXFS "/usr/lib64/vxfsmisc.so"
34 static int (*vxfs_setxattr_fd_func) (int fd, const char *name,
35 const void *value, size_t len, int flags);
36 static int (*vxfs_getxattr_fd_func) (int fd, const char *name, void *value,
38 static int (*vxfs_removexattr_fd_func) (int fd, const char *name);
39 static int (*vxfs_listxattr_fd_func) (int fd, void *value, size_t *len);
40 static int (*vxfs_setwxattr_fd_func) (int fd);
41 static int (*vxfs_clearwxattr_fd_func) (int fd);
42 static int (*vxfs_checkwxattr_fd_func) (int fd);
44 int vxfs_setxattr_fd(int fd, const char *name, const void *value,
45 size_t len, int flags)
49 if (vxfs_setxattr_fd_func == NULL) {
54 DEBUG(10, ("Calling vxfs_setxattr_fd\n"));
55 ret = vxfs_setxattr_fd_func(fd, name, value, len, flags);
64 int vxfs_setxattr_path(const char *path, const char *name, const void *value,
65 size_t len, int flags, bool is_dir)
70 fd = open(path, O_RDONLY|O_DIRECTORY);
72 fd = open(path, O_WRONLY);
76 DEBUG(10, ("error in vxfs_setxattr_path: %s\n",
81 ret = vxfs_setxattr_fd(fd, name, value, len, flags);
88 int vxfs_getxattr_fd(int fd, const char *name, void *value, size_t len)
93 if (vxfs_getxattr_fd_func == NULL) {
98 DEBUG(10, ("Calling vxfs_getxattr_fd with %s\n", name));
99 ret = vxfs_getxattr_fd_func(fd, name, value, &size);
111 int vxfs_getxattr_path(const char *path, const char *name, void *value,
116 fd = open(path, O_RDONLY);
118 DEBUG(10, ("file not opened: vxfs_getxattr_path for %s\n",
123 ret = vxfs_getxattr_fd(fd, name, value, len);
129 int vxfs_removexattr_fd(int fd, const char *name)
133 if (vxfs_removexattr_fd_func == NULL) {
138 DEBUG(10, ("Calling vxfs_removexattr_fd with %s\n", name));
139 ret = vxfs_removexattr_fd_func(fd, name);
148 int vxfs_removexattr_path(const char *path, const char *name, bool is_dir)
153 fd = open(path, O_RDONLY|O_DIRECTORY);
155 fd = open(path, O_WRONLY);
158 DEBUG(10, ("file not opened: vxfs_removexattr_path for %s\n",
163 ret = vxfs_removexattr_fd(fd, name);
169 int vxfs_listxattr_fd(int fd, char *list, size_t size)
174 if (vxfs_listxattr_fd_func == NULL) {
179 ret = vxfs_listxattr_fd_func(fd, list, &len);
180 DEBUG(10, ("vxfs_listxattr_fd: returned ret = %d\n", ret));
192 int vxfs_listxattr_path(const char *path, char *list, size_t size)
196 fd = open(path, O_RDONLY);
198 DEBUG(10, ("file not opened: vxfs_listxattr_path for %s\n",
203 ret = vxfs_listxattr_fd(fd, list, size);
209 int vxfs_setwxattr_fd(int fd)
213 if (vxfs_setwxattr_fd_func == NULL) {
217 ret = vxfs_setwxattr_fd_func(fd);
218 DBG_DEBUG("ret = %d\n", ret);
227 int vxfs_setwxattr_path(const char *path)
231 fd = open(path, O_WRONLY);
233 DBG_DEBUG("file %s not opened, errno:%s\n",
234 path, strerror(errno));
238 ret = vxfs_setwxattr_fd(fd);
239 DBG_DEBUG("ret = %d\n", ret);
245 int vxfs_clearwxattr_fd(int fd)
248 if (vxfs_clearwxattr_fd_func == NULL) {
252 ret = vxfs_clearwxattr_fd_func(fd);
253 DBG_DEBUG("ret = %d\n", ret);
262 int vxfs_clearwxattr_path(const char *path)
266 fd = open(path, O_WRONLY);
268 DBG_DEBUG("file %s not opened, errno:%s\n",
269 path, strerror(errno));
272 ret = vxfs_clearwxattr_fd(fd);
273 DBG_DEBUG("ret = %d\n", ret);
279 int vxfs_checkwxattr_fd(int fd)
283 if (vxfs_checkwxattr_fd_func == NULL) {
287 ret = vxfs_checkwxattr_fd_func(fd);
288 DBG_DEBUG("ret = %d\n", ret);
296 int vxfs_checkwxattr_path(const char *path)
300 fd = open(path, O_WRONLY);
302 DBG_DEBUG("file %s not opened, errno:%s\n",
303 path, strerror(errno));
306 ret = vxfs_checkwxattr_fd(fd);
312 static bool load_lib_vxfs_function(void *lib_handle, void *fn_ptr,
313 const char *fnc_name)
315 void **vlib_handle = (void **)lib_handle;
316 void **fn_pointer = (void **)fn_ptr;
318 *fn_pointer = dlsym(*vlib_handle, fnc_name);
319 if (*fn_pointer == NULL) {
320 DEBUG(10, ("Cannot find symbol for %s\n", fnc_name));
329 static void *lib_handle = NULL;
331 if (lib_handle != NULL ) {
335 lib_handle = dlopen(LIBVXFS, RTLD_LAZY);
336 if (lib_handle == NULL) {
337 DEBUG(10, ("Cannot get lib handle\n"));
341 DEBUG(10, ("Calling vxfs_init\n"));
342 load_lib_vxfs_function(&lib_handle, &vxfs_setxattr_fd_func,
344 load_lib_vxfs_function(&lib_handle, &vxfs_getxattr_fd_func,
346 load_lib_vxfs_function(&lib_handle, &vxfs_removexattr_fd_func,
347 "vxfs_nxattr_remove");
348 load_lib_vxfs_function(&lib_handle, &vxfs_listxattr_fd_func,
350 load_lib_vxfs_function(&lib_handle, &vxfs_setwxattr_fd_func,
352 load_lib_vxfs_function(&lib_handle, &vxfs_clearwxattr_fd_func,
354 load_lib_vxfs_function(&lib_handle, &vxfs_checkwxattr_fd_func,