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"
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
,
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
)
45 if (vxfs_setxattr_fd_func
== NULL
) {
50 DEBUG(10, ("Calling vxfs_setxattr_fd\n"));
51 ret
= vxfs_setxattr_fd_func(fd
, name
, value
, len
, flags
);
60 int vxfs_setxattr_path(const char *path
, const char *name
, const void *value
,
61 size_t len
, int flags
, bool is_dir
)
66 fd
= open(path
, O_RDONLY
|O_DIRECTORY
);
68 fd
= open(path
, O_WRONLY
);
72 DEBUG(10, ("error in vxfs_setxattr_path: %s\n",
77 ret
= vxfs_setxattr_fd(fd
, name
, value
, len
, flags
);
84 int vxfs_getxattr_fd(int fd
, const char *name
, void *value
, size_t len
)
89 if (vxfs_getxattr_fd_func
== NULL
) {
94 DEBUG(10, ("Calling vxfs_getxattr_fd with %s\n", name
));
95 ret
= vxfs_getxattr_fd_func(fd
, name
, value
, &size
);
107 int vxfs_getxattr_path(const char *path
, const char *name
, void *value
,
112 fd
= open(path
, O_RDONLY
);
114 DEBUG(10, ("file not opened: vxfs_getxattr_path for %s\n",
119 ret
= vxfs_getxattr_fd(fd
, name
, value
, len
);
125 int vxfs_removexattr_fd(int fd
, const char *name
)
129 if (vxfs_removexattr_fd_func
== NULL
) {
134 DEBUG(10, ("Calling vxfs_removexattr_fd with %s\n", name
));
135 ret
= vxfs_removexattr_fd_func(fd
, name
);
144 int vxfs_removexattr_path(const char *path
, const char *name
, bool is_dir
)
149 fd
= open(path
, O_RDONLY
|O_DIRECTORY
);
151 fd
= open(path
, O_WRONLY
);
154 DEBUG(10, ("file not opened: vxfs_removexattr_path for %s\n",
159 ret
= vxfs_removexattr_fd(fd
, name
);
165 int vxfs_listxattr_fd(int fd
, char *list
, size_t size
)
170 if (vxfs_listxattr_fd_func
== NULL
) {
175 ret
= vxfs_listxattr_fd_func(fd
, list
, &len
);
176 DEBUG(10, ("vxfs_listxattr_fd: returned ret = %d\n", ret
));
188 int vxfs_listxattr_path(const char *path
, char *list
, size_t size
)
192 fd
= open(path
, O_RDONLY
);
194 DEBUG(10, ("file not opened: vxfs_listxattr_path for %s\n",
199 ret
= vxfs_listxattr_fd(fd
, list
, size
);
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
));
222 static void *lib_handle
= NULL
;
224 if (lib_handle
!= NULL
) {
228 lib_handle
= dlopen(LIBVXFS
, RTLD_LAZY
);
229 if (lib_handle
== NULL
) {
230 DEBUG(10, ("Cannot get lib handle\n"));
234 DEBUG(10, ("Calling vxfs_init\n"));
235 load_lib_vxfs_function(&lib_handle
, &vxfs_setxattr_fd_func
,
237 load_lib_vxfs_function(&lib_handle
, &vxfs_getxattr_fd_func
,
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
,