source: vendor/3.6.0/source3/modules/gpfs.c

Last change on this file was 740, checked in by Silvan Scherrer, 13 years ago

Samba Server: update vendor to 3.6.0

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