smbd: Remove unused [push_pull]_file_id_24
[samba.git] / source3 / modules / gpfs.c
1 /* 
2  *  Unix SMB/CIFS implementation.
3  *  Provide a connection to GPFS specific features
4  *  Copyright (C) Volker Lendecke 2005
5  *
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.
10  *  
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.
15  *  
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/>.
18  */
19
20 #include "includes.h"
21
22 #ifdef HAVE_GPFS
23
24 #include "libcli/security/security.h"
25 #include "gpfs_gpl.h"
26 #include "vfs_gpfs.h"
27
28 static bool gpfs_getrealfilename;
29 static bool gpfs_winattr;
30 static bool gpfs_do_ftruncate;
31
32 static int (*gpfs_set_share_fn)(int fd, unsigned int allow, unsigned int deny);
33 static int (*gpfs_set_lease_fn)(int fd, unsigned int leaseType);
34 static int (*gpfs_getacl_fn)(char *pathname, int flags, void *acl);
35 static int (*gpfs_putacl_fn)(char *pathname, int flags, void *acl);
36 static int (*gpfs_get_realfilename_path_fn)(char *pathname, char *filenamep,
37                                             int *buflen);
38 static int (*gpfs_set_winattrs_path_fn)(char *pathname, int flags, struct gpfs_winattr *attrs);
39 static int (*gpfs_get_winattrs_path_fn)(char *pathname, struct gpfs_winattr *attrs);
40 static int (*gpfs_get_winattrs_fn)(int fd, struct gpfs_winattr *attrs);
41 static int (*gpfs_ftruncate_fn)(int fd, gpfs_off64_t length);
42
43 bool set_gpfs_sharemode(files_struct *fsp, uint32 access_mask,
44                         uint32 share_access)
45 {
46         unsigned int allow = GPFS_SHARE_NONE;
47         unsigned int deny = GPFS_DENY_NONE;
48         int result;
49
50         if (gpfs_set_share_fn == NULL) {
51                 return False;
52         }
53
54         if ((fsp == NULL) || (fsp->fh == NULL) || (fsp->fh->fd < 0)) {
55                 /* No real file, don't disturb */
56                 return True;
57         }
58
59         allow |= (access_mask & (FILE_WRITE_DATA|FILE_APPEND_DATA|
60                                  DELETE_ACCESS)) ? GPFS_SHARE_WRITE : 0;
61         allow |= (access_mask & (FILE_READ_DATA|FILE_EXECUTE)) ?
62                 GPFS_SHARE_READ : 0;
63
64         if (allow == GPFS_SHARE_NONE) {
65                 DEBUG(10, ("special case am=no_access:%x\n",access_mask));
66         }
67         else {  
68                 deny |= (share_access & FILE_SHARE_WRITE) ?
69                         0 : GPFS_DENY_WRITE;
70                 deny |= (share_access & (FILE_SHARE_READ)) ?
71                         0 : GPFS_DENY_READ;
72         }
73         DEBUG(10, ("am=%x, allow=%d, sa=%x, deny=%d\n",
74                    access_mask, allow, share_access, deny));
75
76         result = gpfs_set_share_fn(fsp->fh->fd, allow, deny);
77         if (result != 0) {
78                 if (errno == ENOSYS) {
79                         DEBUG(5, ("VFS module vfs_gpfs loaded, but no gpfs "
80                                   "support has been compiled into Samba. Allowing access\n"));
81                         return True;
82                 } else {
83                         DEBUG(10, ("gpfs_set_share failed: %s\n",
84                                    strerror(errno)));
85                 }
86         }
87
88         return (result == 0);
89 }
90
91 int set_gpfs_lease(int fd, int leasetype)
92 {
93         int gpfs_type = GPFS_LEASE_NONE;
94
95         if (gpfs_set_lease_fn == NULL) {
96                 errno = EINVAL;
97                 return -1;
98         }
99
100         if (leasetype == F_RDLCK) {
101                 gpfs_type = GPFS_LEASE_READ;
102         }
103         if (leasetype == F_WRLCK) {
104                 gpfs_type = GPFS_LEASE_WRITE;
105         }
106
107         /* we unconditionally set CAP_LEASE, rather than looking for
108            -1/EACCES as there is a bug in some versions of
109            libgpfs_gpl.so which results in a leaked fd on /dev/ss0
110            each time we try this with the wrong capabilities set
111         */
112         linux_set_lease_capability();
113         return gpfs_set_lease_fn(fd, gpfs_type);
114 }
115
116 int smbd_gpfs_getacl(char *pathname, int flags, void *acl)
117 {
118         if (gpfs_getacl_fn == NULL) {
119                 errno = ENOSYS;
120                 return -1;
121         }
122
123         return gpfs_getacl_fn(pathname, flags, acl);
124 }
125
126 int smbd_gpfs_putacl(char *pathname, int flags, void *acl)
127 {
128         if (gpfs_putacl_fn == NULL) {
129                 errno = ENOSYS;
130                 return -1;
131         }
132
133         return gpfs_putacl_fn(pathname, flags, acl);
134 }
135
136 int smbd_gpfs_ftruncate(int fd, gpfs_off64_t length)
137 {
138         if (!gpfs_do_ftruncate || (gpfs_ftruncate_fn == NULL)) {
139                 errno = ENOSYS;
140                 return -1;
141         }
142
143         return gpfs_ftruncate_fn(fd, length);
144 }
145
146 int smbd_gpfs_get_realfilename_path(char *pathname, char *filenamep,
147                                     int *buflen)
148 {
149         if ((!gpfs_getrealfilename)
150             || (gpfs_get_realfilename_path_fn == NULL)) {
151                 errno = ENOSYS;
152                 return -1;
153         }
154
155         return gpfs_get_realfilename_path_fn(pathname, filenamep, buflen);
156 }
157
158 int get_gpfs_winattrs(char *pathname,struct gpfs_winattr *attrs)
159 {
160
161         if ((!gpfs_winattr) || (gpfs_get_winattrs_path_fn == NULL)) {
162                 errno = ENOSYS;
163                 return -1;
164         }
165         DEBUG(10, ("gpfs_get_winattrs_path:open call %s\n",pathname));
166         return gpfs_get_winattrs_path_fn(pathname, attrs);
167 }
168
169 int smbd_fget_gpfs_winattrs(int fd, struct gpfs_winattr *attrs)
170 {
171
172         if ((!gpfs_winattr) || (gpfs_get_winattrs_fn == NULL)) {
173                 errno = ENOSYS;
174                 return -1;
175         }
176         DEBUG(10, ("gpfs_get_winattrs_path:open call %d\n", fd));
177         return gpfs_get_winattrs_fn(fd, attrs);
178 }
179
180 int set_gpfs_winattrs(char *pathname,int flags,struct gpfs_winattr *attrs)
181 {
182         if ((!gpfs_winattr) || (gpfs_set_winattrs_path_fn == NULL)) {
183                 errno = ENOSYS;
184                 return -1;
185         }
186
187         DEBUG(10, ("gpfs_set_winattrs_path:open call %s\n",pathname));
188         return gpfs_set_winattrs_path_fn(pathname,flags, attrs);
189 }
190
191 static bool init_gpfs_function_lib(void *plibhandle_pointer,
192                                    const char *libname,
193                                    void *pfn_pointer, const char *fn_name)
194 {
195         bool did_open_here = false;
196         void **libhandle_pointer = (void **)plibhandle_pointer;
197         void **fn_pointer = (void **)pfn_pointer;
198
199         DEBUG(10, ("trying to load name %s from %s\n",
200                    fn_name, libname));
201
202         if (*libhandle_pointer == NULL) {
203                 *libhandle_pointer = dlopen(libname, RTLD_LAZY);
204                 did_open_here = true;
205         }
206         if (*libhandle_pointer == NULL) {
207                 DEBUG(10, ("Could not open lib %s\n", libname));
208                 return false;
209         }
210
211         *fn_pointer = dlsym(*libhandle_pointer, fn_name);
212         if (*fn_pointer == NULL) {
213                 DEBUG(10, ("Did not find symbol %s in lib %s\n",
214                            fn_name, libname));
215                 if (did_open_here) {
216                         dlclose(*libhandle_pointer);
217                         *libhandle_pointer = NULL;
218                 }
219                 return false;
220         }
221
222         return true;
223 }
224
225 static bool init_gpfs_function(void *fn_pointer, const char *fn_name)
226 {
227         static void *libgpfs_handle = NULL;
228         static void *libgpfs_gpl_handle = NULL;
229
230         if (init_gpfs_function_lib(&libgpfs_handle, "libgpfs.so",
231                                    fn_pointer, fn_name)) {
232                 return true;
233         }
234         if (init_gpfs_function_lib(&libgpfs_gpl_handle, "libgpfs_gpl.so",
235                                    fn_pointer, fn_name)) {
236                 return true;
237         }
238         return false;
239 }
240
241 void init_gpfs(void)
242 {
243         init_gpfs_function(&gpfs_set_share_fn, "gpfs_set_share");
244         init_gpfs_function(&gpfs_set_lease_fn, "gpfs_set_lease");
245         init_gpfs_function(&gpfs_getacl_fn, "gpfs_getacl");
246         init_gpfs_function(&gpfs_putacl_fn, "gpfs_putacl");
247         init_gpfs_function(&gpfs_get_realfilename_path_fn,
248                            "gpfs_get_realfilename_path");
249         init_gpfs_function(&gpfs_get_winattrs_path_fn,"gpfs_get_winattrs_path");
250         init_gpfs_function(&gpfs_set_winattrs_path_fn,"gpfs_set_winattrs_path");
251         init_gpfs_function(&gpfs_get_winattrs_fn,"gpfs_get_winattrs");
252         init_gpfs_function(&gpfs_ftruncate_fn, "gpfs_ftruncate");
253
254         gpfs_getrealfilename = lp_parm_bool(-1, "gpfs", "getrealfilename",
255                                             True);
256         gpfs_winattr = lp_parm_bool(-1, "gpfs", "winattr", False);
257         gpfs_do_ftruncate = lp_parm_bool(-1, "gpfs", "ftruncate", True);
258
259         return;
260 }
261
262 #else
263
264 int set_gpfs_lease(int snum, int leasetype)
265 {
266         DEBUG(0, ("'VFS module smbgpfs loaded, without gpfs support compiled\n"));
267
268         /* We need to indicate that no GPFS is around by returning ENOSYS, so
269          * that the normal linux kernel oplock code is called. */
270         errno = ENOSYS;
271         return -1;
272 }
273
274 bool set_gpfs_sharemode(files_struct *fsp, uint32 access_mask,
275                         uint32 share_access)
276 {
277         DEBUG(0, ("VFS module - smbgpfs.so loaded, without gpfs support compiled\n"));
278         /* Don't disturb but complain */
279         return True;
280 }
281
282 int smbd_gpfs_getacl(char *pathname, int flags, void *acl)
283 {
284         errno = ENOSYS;
285         return -1;
286 }
287
288 int smbd_gpfs_putacl(char *pathname, int flags, void *acl)
289 {
290         errno = ENOSYS;
291         return -1;
292 }
293
294 int smbd_gpfs_get_realfilename_path(char *pathname, char *fileamep,
295                                     int *buflen)
296 {
297         errno = ENOSYS;
298         return -1;
299 }
300
301 int set_gpfs_winattrs(char *pathname,int flags,struct gpfs_winattr *attrs)
302 {
303         errno = ENOSYS;
304         return -1;
305 }
306
307 int get_gpfs_winattrs(char *pathname,struct gpfs_winattr *attrs)
308 {
309         errno = ENOSYS;
310         return -1;
311 }
312
313 void init_gpfs(void)
314 {
315         return;
316 }
317
318 #endif /* HAVE_GPFS */