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

Last change on this file was 414, checked in by Herwig Bauernfeind, 15 years ago

Samba 3.5.0: Initial import

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