1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
|
/*
* Unix SMB/CIFS implementation.
* Provide a connection to GPFS specific features
* Copyright (C) Volker Lendecke 2005
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#include "includes.h"
#ifdef HAVE_GPFS
#include "gpfs_gpl.h"
#include "vfs_gpfs.h"
static void *libgpfs_handle = NULL;
static bool gpfs_share_modes;
static bool gpfs_leases;
static int (*gpfs_set_share_fn)(int fd, unsigned int allow, unsigned int deny);
static int (*gpfs_set_lease_fn)(int fd, unsigned int leaseType);
static int (*gpfs_getacl_fn)(char *pathname, int flags, void *acl);
static int (*gpfs_putacl_fn)(char *pathname, int flags, void *acl);
bool set_gpfs_sharemode(files_struct *fsp, uint32 access_mask,
uint32 share_access)
{
unsigned int allow = GPFS_SHARE_NONE;
unsigned int deny = GPFS_DENY_NONE;
int result;
if (!gpfs_share_modes) {
return True;
}
if (gpfs_set_share_fn == NULL) {
return False;
}
if ((fsp == NULL) || (fsp->fh == NULL) || (fsp->fh->fd < 0)) {
/* No real file, don't disturb */
return True;
}
allow |= (access_mask & (FILE_WRITE_DATA|FILE_APPEND_DATA|
DELETE_ACCESS)) ? GPFS_SHARE_WRITE : 0;
allow |= (access_mask & (FILE_READ_DATA|FILE_EXECUTE)) ?
GPFS_SHARE_READ : 0;
if (allow == GPFS_SHARE_NONE) {
DEBUG(10, ("special case am=no_access:%x\n",access_mask));
}
else {
deny |= (share_access & FILE_SHARE_WRITE) ?
0 : GPFS_DENY_WRITE;
deny |= (share_access & (FILE_SHARE_READ)) ?
0 : GPFS_DENY_READ;
}
DEBUG(10, ("am=%x, allow=%d, sa=%x, deny=%d\n",
access_mask, allow, share_access, deny));
result = gpfs_set_share_fn(fsp->fh->fd, allow, deny);
if (result != 0) {
if (errno == ENOSYS) {
DEBUG(5, ("VFS module vfs_gpfs loaded, but no gpfs "
"support has been compiled into Samba. Allowing access\n"));
return True;
} else {
DEBUG(10, ("gpfs_set_share failed: %s\n",
strerror(errno)));
}
}
return (result == 0);
}
int set_gpfs_lease(int fd, int leasetype)
{
int gpfs_type = GPFS_LEASE_NONE;
if (!gpfs_leases) {
return True;
}
if (gpfs_set_lease_fn == NULL) {
errno = EINVAL;
return -1;
}
if (leasetype == F_RDLCK) {
gpfs_type = GPFS_LEASE_READ;
}
if (leasetype == F_WRLCK) {
gpfs_type = GPFS_LEASE_WRITE;
}
/* we unconditionally set CAP_LEASE, rather than looking for
-1/EACCES as there is a bug in some versions of
libgpfs_gpl.so which results in a leaked fd on /dev/ss0
each time we try this with the wrong capabilities set
*/
linux_set_lease_capability();
return gpfs_set_lease_fn(fd, gpfs_type);
}
int smbd_gpfs_getacl(char *pathname, int flags, void *acl)
{
if (gpfs_getacl_fn == NULL) {
errno = ENOSYS;
return -1;
}
return gpfs_getacl_fn(pathname, flags, acl);
}
int smbd_gpfs_putacl(char *pathname, int flags, void *acl)
{
if (gpfs_putacl_fn == NULL) {
errno = ENOSYS;
return -1;
}
return gpfs_putacl_fn(pathname, flags, acl);
}
void init_gpfs(void)
{
if (libgpfs_handle != NULL) {
return;
}
libgpfs_handle = dlopen("libgpfs_gpl.so", RTLD_LAZY);
if (libgpfs_handle == NULL) {
DEBUG(10, ("dlopen for libgpfs_gpl failed: %s\n",
strerror(errno)));
return;
}
DEBUG(10, ("libgpfs_gpl.so loaded\n"));
gpfs_set_share_fn = dlsym(libgpfs_handle, "gpfs_set_share");
if (gpfs_set_share_fn == NULL) {
DEBUG(3, ("libgpfs_gpl.so does not contain the symbol "
"'gpfs_set_share'\n"));
goto failed;
}
gpfs_set_lease_fn = dlsym(libgpfs_handle, "gpfs_set_lease");
if (gpfs_set_lease_fn == NULL) {
DEBUG(3, ("libgpfs_gpl.so does not contain the symbol "
"'gpfs_set_lease'\n"));
dlclose(libgpfs_handle);
goto failed;
}
gpfs_getacl_fn = dlsym(libgpfs_handle, "gpfs_getacl");
if (gpfs_getacl_fn == NULL) {
DEBUG(3, ("libgpfs_gpl.so does not contain the symbol "
"'gpfs_getacl'\n"));
goto failed;
}
gpfs_putacl_fn = dlsym(libgpfs_handle, "gpfs_putacl");
if (gpfs_putacl_fn == NULL) {
DEBUG(3, ("libgpfs_gpl.so does not contain the symbol "
"'gpfs_putacl'\n"));
goto failed;
}
gpfs_share_modes = lp_parm_bool(-1, "gpfs", "sharemodes", True);
gpfs_leases = lp_parm_bool(-1, "gpfs", "leases", True);
return;
failed:
dlclose(libgpfs_handle);
/* leave libgpfs_handle != NULL around, no point
in trying twice */
gpfs_set_share_fn = NULL;
gpfs_set_lease_fn = NULL;
gpfs_getacl_fn = NULL;
gpfs_putacl_fn = NULL;
}
#else
int set_gpfs_lease(int snum, int leasetype)
{
DEBUG(0, ("'VFS module smbgpfs loaded, without gpfs support compiled\n"));
/* We need to indicate that no GPFS is around by returning ENOSYS, so
* that the normal linux kernel oplock code is called. */
errno = ENOSYS;
return -1;
}
bool set_gpfs_sharemode(files_struct *fsp, uint32 access_mask,
uint32 share_access)
{
DEBUG(0, ("VFS module - smbgpfs.so loaded, without gpfs support compiled\n"));
/* Don't disturb but complain */
return True;
}
int smbd_gpfs_getacl(char *pathname, int flags, void *acl)
{
errno = ENOSYS;
return -1;
}
int smbd_gpfs_putacl(char *pathname, int flags, void *acl)
{
errno = ENOSYS;
return -1;
}
void init_gpfs(void)
{
return;
}
#endif /* HAVE_GPFS */
|