Add a missing include file to two VFS modules
[Samba/gebeck_regimport.git] / source3 / modules / gpfs.c
blob52a93310eb7867640083bdaa29b19609a48d65d3
1 /*
2 * Unix SMB/CIFS implementation.
3 * Provide a connection to GPFS specific features
4 * Copyright (C) Volker Lendecke 2005
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
20 #include "includes.h"
21 #include "system/filesys.h"
22 #include "smbd/smbd.h"
23 #include "system/filesys.h"
25 #ifdef HAVE_GPFS
27 #include "libcli/security/security.h"
28 #include "gpfs_gpl.h"
29 #include "vfs_gpfs.h"
31 static bool gpfs_getrealfilename;
32 static bool gpfs_winattr;
33 static bool gpfs_do_ftruncate;
35 static int (*gpfs_set_share_fn)(int fd, unsigned int allow, unsigned int deny);
36 static int (*gpfs_set_lease_fn)(int fd, unsigned int leaseType);
37 static int (*gpfs_getacl_fn)(char *pathname, int flags, void *acl);
38 static int (*gpfs_putacl_fn)(char *pathname, int flags, void *acl);
39 static int (*gpfs_get_realfilename_path_fn)(char *pathname, char *filenamep,
40 int *buflen);
41 static int (*gpfs_set_winattrs_path_fn)(char *pathname, int flags, struct gpfs_winattr *attrs);
42 static int (*gpfs_get_winattrs_path_fn)(char *pathname, struct gpfs_winattr *attrs);
43 static int (*gpfs_get_winattrs_fn)(int fd, struct gpfs_winattr *attrs);
44 static int (*gpfs_ftruncate_fn)(int fd, gpfs_off64_t length);
45 static int (*gpfs_lib_init_fn)(int flags);
47 bool set_gpfs_sharemode(files_struct *fsp, uint32 access_mask,
48 uint32 share_access)
50 unsigned int allow = GPFS_SHARE_NONE;
51 unsigned int deny = GPFS_DENY_NONE;
52 int result;
54 if (gpfs_set_share_fn == NULL) {
55 return False;
58 if ((fsp == NULL) || (fsp->fh == NULL) || (fsp->fh->fd < 0)) {
59 /* No real file, don't disturb */
60 return True;
63 allow |= (access_mask & (FILE_WRITE_DATA|FILE_APPEND_DATA|
64 DELETE_ACCESS)) ? GPFS_SHARE_WRITE : 0;
65 allow |= (access_mask & (FILE_READ_DATA|FILE_EXECUTE)) ?
66 GPFS_SHARE_READ : 0;
68 if (allow == GPFS_SHARE_NONE) {
69 DEBUG(10, ("special case am=no_access:%x\n",access_mask));
71 else {
72 deny |= (share_access & FILE_SHARE_WRITE) ?
73 0 : GPFS_DENY_WRITE;
74 deny |= (share_access & (FILE_SHARE_READ)) ?
75 0 : GPFS_DENY_READ;
77 DEBUG(10, ("am=%x, allow=%d, sa=%x, deny=%d\n",
78 access_mask, allow, share_access, deny));
80 result = gpfs_set_share_fn(fsp->fh->fd, allow, deny);
81 if (result != 0) {
82 if (errno == ENOSYS) {
83 DEBUG(5, ("VFS module vfs_gpfs loaded, but no gpfs "
84 "support has been compiled into Samba. Allowing access\n"));
85 return True;
86 } else {
87 DEBUG(10, ("gpfs_set_share failed: %s\n",
88 strerror(errno)));
92 return (result == 0);
95 int set_gpfs_lease(int fd, int leasetype)
97 int gpfs_type = GPFS_LEASE_NONE;
99 if (gpfs_set_lease_fn == NULL) {
100 errno = EINVAL;
101 return -1;
104 if (leasetype == F_RDLCK) {
105 gpfs_type = GPFS_LEASE_READ;
107 if (leasetype == F_WRLCK) {
108 gpfs_type = GPFS_LEASE_WRITE;
111 /* we unconditionally set CAP_LEASE, rather than looking for
112 -1/EACCES as there is a bug in some versions of
113 libgpfs_gpl.so which results in a leaked fd on /dev/ss0
114 each time we try this with the wrong capabilities set
116 linux_set_lease_capability();
117 return gpfs_set_lease_fn(fd, gpfs_type);
120 int smbd_gpfs_getacl(char *pathname, int flags, void *acl)
122 if (gpfs_getacl_fn == NULL) {
123 errno = ENOSYS;
124 return -1;
127 return gpfs_getacl_fn(pathname, flags, acl);
130 int smbd_gpfs_putacl(char *pathname, int flags, void *acl)
132 if (gpfs_putacl_fn == NULL) {
133 errno = ENOSYS;
134 return -1;
137 return gpfs_putacl_fn(pathname, flags, acl);
140 int smbd_gpfs_ftruncate(int fd, gpfs_off64_t length)
142 if (!gpfs_do_ftruncate || (gpfs_ftruncate_fn == NULL)) {
143 errno = ENOSYS;
144 return -1;
147 return gpfs_ftruncate_fn(fd, length);
150 int smbd_gpfs_get_realfilename_path(char *pathname, char *filenamep,
151 int *buflen)
153 if ((!gpfs_getrealfilename)
154 || (gpfs_get_realfilename_path_fn == NULL)) {
155 errno = ENOSYS;
156 return -1;
159 return gpfs_get_realfilename_path_fn(pathname, filenamep, buflen);
162 int get_gpfs_winattrs(char *pathname,struct gpfs_winattr *attrs)
165 if ((!gpfs_winattr) || (gpfs_get_winattrs_path_fn == NULL)) {
166 errno = ENOSYS;
167 return -1;
169 DEBUG(10, ("gpfs_get_winattrs_path:open call %s\n",pathname));
170 return gpfs_get_winattrs_path_fn(pathname, attrs);
173 int smbd_fget_gpfs_winattrs(int fd, struct gpfs_winattr *attrs)
176 if ((!gpfs_winattr) || (gpfs_get_winattrs_fn == NULL)) {
177 errno = ENOSYS;
178 return -1;
180 DEBUG(10, ("gpfs_get_winattrs_path:open call %d\n", fd));
181 return gpfs_get_winattrs_fn(fd, attrs);
184 int set_gpfs_winattrs(char *pathname,int flags,struct gpfs_winattr *attrs)
186 if ((!gpfs_winattr) || (gpfs_set_winattrs_path_fn == NULL)) {
187 errno = ENOSYS;
188 return -1;
191 DEBUG(10, ("gpfs_set_winattrs_path:open call %s\n",pathname));
192 return gpfs_set_winattrs_path_fn(pathname,flags, attrs);
195 void smbd_gpfs_lib_init()
197 if (gpfs_lib_init_fn) {
198 int rc = gpfs_lib_init_fn(0);
199 DEBUG(10, ("gpfs_lib_init() finished with rc %d "
200 "and errno %d\n", rc, errno));
201 } else {
202 DEBUG(10, ("libgpfs lacks gpfs_lib_init\n"));
206 static bool init_gpfs_function_lib(void *plibhandle_pointer,
207 const char *libname,
208 void *pfn_pointer, const char *fn_name)
210 bool did_open_here = false;
211 void **libhandle_pointer = (void **)plibhandle_pointer;
212 void **fn_pointer = (void **)pfn_pointer;
214 DEBUG(10, ("trying to load name %s from %s\n",
215 fn_name, libname));
217 if (*libhandle_pointer == NULL) {
218 *libhandle_pointer = dlopen(libname, RTLD_LAZY);
219 did_open_here = true;
221 if (*libhandle_pointer == NULL) {
222 DEBUG(10, ("Could not open lib %s\n", libname));
223 return false;
226 *fn_pointer = dlsym(*libhandle_pointer, fn_name);
227 if (*fn_pointer == NULL) {
228 DEBUG(10, ("Did not find symbol %s in lib %s\n",
229 fn_name, libname));
230 if (did_open_here) {
231 dlclose(*libhandle_pointer);
232 *libhandle_pointer = NULL;
234 return false;
237 return true;
240 static bool init_gpfs_function(void *fn_pointer, const char *fn_name)
242 static void *libgpfs_handle = NULL;
243 static void *libgpfs_gpl_handle = NULL;
245 if (init_gpfs_function_lib(&libgpfs_handle, "libgpfs.so",
246 fn_pointer, fn_name)) {
247 return true;
249 if (init_gpfs_function_lib(&libgpfs_gpl_handle, "libgpfs_gpl.so",
250 fn_pointer, fn_name)) {
251 return true;
253 return false;
256 void init_gpfs(void)
258 init_gpfs_function(&gpfs_set_share_fn, "gpfs_set_share");
259 init_gpfs_function(&gpfs_set_lease_fn, "gpfs_set_lease");
260 init_gpfs_function(&gpfs_getacl_fn, "gpfs_getacl");
261 init_gpfs_function(&gpfs_putacl_fn, "gpfs_putacl");
262 init_gpfs_function(&gpfs_get_realfilename_path_fn,
263 "gpfs_get_realfilename_path");
264 init_gpfs_function(&gpfs_get_winattrs_path_fn,"gpfs_get_winattrs_path");
265 init_gpfs_function(&gpfs_set_winattrs_path_fn,"gpfs_set_winattrs_path");
266 init_gpfs_function(&gpfs_get_winattrs_fn,"gpfs_get_winattrs");
267 init_gpfs_function(&gpfs_ftruncate_fn, "gpfs_ftruncate");
268 init_gpfs_function(&gpfs_lib_init_fn,"gpfs_lib_init");
270 gpfs_getrealfilename = lp_parm_bool(-1, "gpfs", "getrealfilename",
271 True);
272 gpfs_winattr = lp_parm_bool(-1, "gpfs", "winattr", False);
273 gpfs_do_ftruncate = lp_parm_bool(-1, "gpfs", "ftruncate", True);
275 return;
278 #else
280 int set_gpfs_lease(int snum, int leasetype)
282 DEBUG(0, ("'VFS module smbgpfs loaded, without gpfs support compiled\n"));
284 /* We need to indicate that no GPFS is around by returning ENOSYS, so
285 * that the normal linux kernel oplock code is called. */
286 errno = ENOSYS;
287 return -1;
290 bool set_gpfs_sharemode(files_struct *fsp, uint32 access_mask,
291 uint32 share_access)
293 DEBUG(0, ("VFS module - smbgpfs.so loaded, without gpfs support compiled\n"));
294 /* Don't disturb but complain */
295 return True;
298 int smbd_gpfs_getacl(char *pathname, int flags, void *acl)
300 errno = ENOSYS;
301 return -1;
304 int smbd_gpfs_putacl(char *pathname, int flags, void *acl)
306 errno = ENOSYS;
307 return -1;
310 int smbd_gpfs_get_realfilename_path(char *pathname, char *fileamep,
311 int *buflen)
313 errno = ENOSYS;
314 return -1;
317 int set_gpfs_winattrs(char *pathname,int flags,struct gpfs_winattr *attrs)
319 errno = ENOSYS;
320 return -1;
323 int get_gpfs_winattrs(char *pathname,struct gpfs_winattr *attrs)
325 errno = ENOSYS;
326 return -1;
329 void smbd_gpfs_lib_init()
331 return;
334 void init_gpfs(void)
336 return;
339 #endif /* HAVE_GPFS */