s4:kdc: let samba_kdc_trust_message2entry() return all keys with SDB_F_ADMIN_DATA
[Samba.git] / source3 / modules / lib_vxfs.c
blobe030cc368181d76b87959549bb05a8446282fa4c
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"
25 #include "vfs_vxfs.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,
37 size_t *len);
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)
46 int ret = -1;
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) {
51 errno = ENOSYS;
52 return ret;
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);
58 if (ret) {
59 errno = ret;
60 ret = -1;
63 return ret;
66 int vxfs_getxattr_fd(int fd, const char *name, void *value, size_t len)
68 int ret;
69 size_t size = len;
70 DBG_DEBUG("In vxfs_getxattr_fd fd %d name %s len %zu\n",
71 fd, name, len);
73 if (vxfs_getxattr_fd_func == NULL) {
74 errno = ENOSYS;
75 return -1;
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);
81 if (ret) {
82 errno = ret;
83 if (ret == EFBIG) {
84 errno = ERANGE;
86 return -1;
88 DBG_DEBUG("vxfs_getxattr_fd done with size %zu\n", size);
90 return size;
93 int vxfs_getxattr_path(const char *path, const char *name, void *value,
94 size_t len)
96 int ret, fd = -1;
97 DBG_DEBUG("In vxfs_getxattr_path path %s name %s len %zu\n",
98 path, name, len);
100 fd = open(path, O_RDONLY);
101 if (fd == -1) {
102 DBG_DEBUG("file not opened: vxfs_getxattr_path for %s\n",
103 path);
104 return -1;
107 ret = vxfs_getxattr_fd(fd, name, value, len);
108 close(fd);
110 return ret;
113 int vxfs_removexattr_fd(int fd, const char *name)
115 int ret = 0;
116 DBG_DEBUG("In vxfs_removexattr_fd fd %d name %s\n", fd, name);
118 if (vxfs_removexattr_fd_func == NULL) {
119 errno = ENOSYS;
120 return -1;
123 DBG_DEBUG("Calling vxfs_removexattr_fd with %s\n", name);
124 ret = vxfs_removexattr_fd_func(fd, name);
125 if (ret) {
126 errno = ret;
127 ret = -1;
130 return ret;
133 int vxfs_listxattr_fd(int fd, char *list, size_t size)
135 int ret;
136 size_t len = 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) {
140 errno = ENOSYS;
141 return -1;
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);
147 if (ret) {
148 errno = ret;
149 if (ret == EFBIG) {
150 errno = ERANGE;
152 return -1;
155 return len;
158 int vxfs_setwxattr_fd(int fd)
160 int ret = 0;
161 DBG_DEBUG("In vxfs_setwxattr_fd fd %d\n", fd);
163 if (vxfs_setwxattr_fd_func == NULL) {
164 errno = ENOSYS;
165 return -1;
167 ret = vxfs_setwxattr_fd_func(fd);
168 DBG_DEBUG("ret = %d\n", ret);
169 if (ret != 0) {
170 errno = ret;
171 ret = -1;
174 return ret;
177 int vxfs_setwxattr_path(const char *path, bool is_dir)
179 int ret, fd = -1;
180 DBG_DEBUG("In vxfs_setwxattr_path path %s is_dir %d\n", path, is_dir);
182 if (is_dir) {
183 fd = open(path, O_RDONLY|O_DIRECTORY);
184 } else {
185 fd = open(path, O_WRONLY);
187 if (fd == -1) {
188 DBG_DEBUG("file %s not opened, errno:%s\n",
189 path, strerror(errno));
190 return -1;
193 ret = vxfs_setwxattr_fd(fd);
194 DBG_DEBUG("ret = %d\n", ret);
195 close(fd);
197 return ret;
200 int vxfs_checkwxattr_fd(int fd)
202 int ret;
203 DBG_DEBUG("In vxfs_checkwxattr_fd fd %d\n", fd);
205 if (vxfs_checkwxattr_fd_func == NULL) {
206 errno = ENOSYS;
207 return -1;
209 ret = vxfs_checkwxattr_fd_func(fd);
210 DBG_DEBUG("ret = %d\n", ret);
211 if (ret != 0) {
212 errno = ret;
213 ret = -1;
215 return ret;
218 int vxfs_checkwxattr_path(const char *path)
220 int ret, fd = -1;
221 DBG_DEBUG("In vxfs_checkwxattr_path path %s\n", path);
223 fd = open(path, O_RDONLY);
225 if (fd == -1) {
226 DBG_DEBUG("file %s not opened, errno:%s\n",
227 path, strerror(errno));
228 return -1;
230 ret = vxfs_checkwxattr_fd(fd);
231 close(fd);
233 return ret;
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));
245 return true;
248 return false;
251 void vxfs_init()
253 static void *lib_handle = NULL;
255 if (lib_handle != NULL ) {
256 return;
259 lib_handle = dlopen(LIBVXFS, RTLD_LAZY);
260 if (lib_handle == NULL) {
261 DEBUG(10, ("Cannot get lib handle\n"));
262 return;
265 DEBUG(10, ("Calling vxfs_init\n"));
266 load_lib_vxfs_function(&lib_handle, &vxfs_setxattr_fd_func,
267 "vxfs_nxattr_set");
268 load_lib_vxfs_function(&lib_handle, &vxfs_getxattr_fd_func,
269 "vxfs_nxattr_get");
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,
273 "vxfs_nxattr_list");
274 load_lib_vxfs_function(&lib_handle, &vxfs_setwxattr_fd_func,
275 "vxfs_wattr_set");
276 load_lib_vxfs_function(&lib_handle, &vxfs_checkwxattr_fd_func,
277 "vxfs_wattr_check");