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_checkwxattr_fd_func) (int fd);
43 int vxfs_setxattr_fd(int fd, const char *name, const void *value,
44 size_t len, int flags)
48 DBG_DEBUG("In vxfs_setxattr_fd fd %d name %s len %zu flags %d\n",
49 fd, name, len, flags);
50 if (vxfs_setxattr_fd_func == NULL) {
55 DBG_DEBUG("Calling vxfs_setxattr_fd\n");
56 ret = vxfs_setxattr_fd_func(fd, name, value, len, flags);
57 DBG_DEBUG("vxfs_setxattr_fd ret = %d \n", ret);
66 int vxfs_getxattr_fd(int fd, const char *name, void *value, size_t len)
70 DBG_DEBUG("In vxfs_getxattr_fd fd %d name %s len %zu\n",
73 if (vxfs_getxattr_fd_func == NULL) {
78 DBG_DEBUG("Calling vxfs_getxattr_fd with %s\n", name);
79 ret = vxfs_getxattr_fd_func(fd, name, value, &size);
80 DBG_DEBUG("vxfs_getxattr_fd ret = %d\n", ret);
88 DBG_DEBUG("vxfs_getxattr_fd done with size %zu\n", size);
93 int vxfs_getxattr_path(const char *path, const char *name, void *value,
97 DBG_DEBUG("In vxfs_getxattr_path path %s name %s len %zu\n",
100 fd = open(path, O_RDONLY);
102 DBG_DEBUG("file not opened: vxfs_getxattr_path for %s\n",
107 ret = vxfs_getxattr_fd(fd, name, value, len);
113 int vxfs_removexattr_fd(int fd, const char *name)
116 DBG_DEBUG("In vxfs_removexattr_fd fd %d name %s\n", fd, name);
118 if (vxfs_removexattr_fd_func == NULL) {
123 DBG_DEBUG("Calling vxfs_removexattr_fd with %s\n", name);
124 ret = vxfs_removexattr_fd_func(fd, name);
133 int vxfs_listxattr_fd(int fd, char *list, size_t size)
137 DBG_DEBUG("In vxfs_listxattr_fd fd %d list %s size %zu\n", fd, list, size);
139 if (vxfs_listxattr_fd_func == NULL) {
144 ret = vxfs_listxattr_fd_func(fd, list, &len);
145 DBG_DEBUG("vxfs_listxattr_fd: returned ret = %d\n", ret);
146 DBG_DEBUG("In vxfs_listxattr_fd done with len %zu\n", len);
158 int vxfs_setwxattr_fd(int fd)
161 DBG_DEBUG("In vxfs_setwxattr_fd fd %d\n", fd);
163 if (vxfs_setwxattr_fd_func == NULL) {
167 ret = vxfs_setwxattr_fd_func(fd);
168 DBG_DEBUG("ret = %d\n", ret);
177 int vxfs_setwxattr_path(const char *path, bool is_dir)
180 DBG_DEBUG("In vxfs_setwxattr_path path %s is_dir %d\n", path, is_dir);
183 fd = open(path, O_RDONLY|O_DIRECTORY);
185 fd = open(path, O_WRONLY);
188 DBG_DEBUG("file %s not opened, errno:%s\n",
189 path, strerror(errno));
193 ret = vxfs_setwxattr_fd(fd);
194 DBG_DEBUG("ret = %d\n", ret);
200 int vxfs_checkwxattr_fd(int fd)
203 DBG_DEBUG("In vxfs_checkwxattr_fd fd %d\n", fd);
205 if (vxfs_checkwxattr_fd_func == NULL) {
209 ret = vxfs_checkwxattr_fd_func(fd);
210 DBG_DEBUG("ret = %d\n", ret);
218 int vxfs_checkwxattr_path(const char *path)
221 DBG_DEBUG("In vxfs_checkwxattr_path path %s\n", path);
223 fd = open(path, O_RDONLY);
226 DBG_DEBUG("file %s not opened, errno:%s\n",
227 path, strerror(errno));
230 ret = vxfs_checkwxattr_fd(fd);
236 static bool load_lib_vxfs_function(void *lib_handle, void *fn_ptr,
237 const char *fnc_name)
239 void **vlib_handle = (void **)lib_handle;
240 void **fn_pointer = (void **)fn_ptr;
242 *fn_pointer = dlsym(*vlib_handle, fnc_name);
243 if (*fn_pointer == NULL) {
244 DEBUG(10, ("Cannot find symbol for %s\n", fnc_name));
253 static void *lib_handle = NULL;
255 if (lib_handle != NULL ) {
259 lib_handle = dlopen(LIBVXFS, RTLD_LAZY);
260 if (lib_handle == NULL) {
261 DEBUG(10, ("Cannot get lib handle\n"));
265 DEBUG(10, ("Calling vxfs_init\n"));
266 load_lib_vxfs_function(&lib_handle, &vxfs_setxattr_fd_func,
268 load_lib_vxfs_function(&lib_handle, &vxfs_getxattr_fd_func,
270 load_lib_vxfs_function(&lib_handle, &vxfs_removexattr_fd_func,
271 "vxfs_nxattr_remove");
272 load_lib_vxfs_function(&lib_handle, &vxfs_listxattr_fd_func,
274 load_lib_vxfs_function(&lib_handle, &vxfs_setwxattr_fd_func,
276 load_lib_vxfs_function(&lib_handle, &vxfs_checkwxattr_fd_func,