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
, bool is_dir
)
232 fd
= open(path
, O_RDONLY
|O_DIRECTORY
);
234 fd
= open(path
, O_WRONLY
);
237 DBG_DEBUG("file %s not opened, errno:%s\n",
238 path
, strerror(errno
));
242 ret
= vxfs_setwxattr_fd(fd
);
243 DBG_DEBUG("ret = %d\n", ret
);
249 int vxfs_clearwxattr_fd(int fd
)
252 if (vxfs_clearwxattr_fd_func
== NULL
) {
256 ret
= vxfs_clearwxattr_fd_func(fd
);
257 DBG_DEBUG("ret = %d\n", ret
);
266 int vxfs_clearwxattr_path(const char *path
, bool is_dir
)
271 fd
= open(path
, O_RDONLY
|O_DIRECTORY
);
273 fd
= open(path
, O_WRONLY
);
277 DBG_DEBUG("file %s not opened, errno:%s\n",
278 path
, strerror(errno
));
281 ret
= vxfs_clearwxattr_fd(fd
);
282 DBG_DEBUG("ret = %d\n", ret
);
288 int vxfs_checkwxattr_fd(int fd
)
292 if (vxfs_checkwxattr_fd_func
== NULL
) {
296 ret
= vxfs_checkwxattr_fd_func(fd
);
297 DBG_DEBUG("ret = %d\n", ret
);
305 int vxfs_checkwxattr_path(const char *path
)
309 fd
= open(path
, O_RDONLY
);
312 DBG_DEBUG("file %s not opened, errno:%s\n",
313 path
, strerror(errno
));
316 ret
= vxfs_checkwxattr_fd(fd
);
322 static bool load_lib_vxfs_function(void *lib_handle
, void *fn_ptr
,
323 const char *fnc_name
)
325 void **vlib_handle
= (void **)lib_handle
;
326 void **fn_pointer
= (void **)fn_ptr
;
328 *fn_pointer
= dlsym(*vlib_handle
, fnc_name
);
329 if (*fn_pointer
== NULL
) {
330 DEBUG(10, ("Cannot find symbol for %s\n", fnc_name
));
339 static void *lib_handle
= NULL
;
341 if (lib_handle
!= NULL
) {
345 lib_handle
= dlopen(LIBVXFS
, RTLD_LAZY
);
346 if (lib_handle
== NULL
) {
347 DEBUG(10, ("Cannot get lib handle\n"));
351 DEBUG(10, ("Calling vxfs_init\n"));
352 load_lib_vxfs_function(&lib_handle
, &vxfs_setxattr_fd_func
,
354 load_lib_vxfs_function(&lib_handle
, &vxfs_getxattr_fd_func
,
356 load_lib_vxfs_function(&lib_handle
, &vxfs_removexattr_fd_func
,
357 "vxfs_nxattr_remove");
358 load_lib_vxfs_function(&lib_handle
, &vxfs_listxattr_fd_func
,
360 load_lib_vxfs_function(&lib_handle
, &vxfs_setwxattr_fd_func
,
362 load_lib_vxfs_function(&lib_handle
, &vxfs_clearwxattr_fd_func
,
364 load_lib_vxfs_function(&lib_handle
, &vxfs_checkwxattr_fd_func
,