[228] | 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 |
|
---|
| 27 | static bool gpfs_share_modes;
|
---|
| 28 | static bool gpfs_leases;
|
---|
| 29 |
|
---|
| 30 | static int (*gpfs_set_share_fn)(int fd, unsigned int allow, unsigned int deny);
|
---|
| 31 | static int (*gpfs_set_lease_fn)(int fd, unsigned int leaseType);
|
---|
| 32 | static int (*gpfs_getacl_fn)(char *pathname, int flags, void *acl);
|
---|
| 33 | static int (*gpfs_putacl_fn)(char *pathname, int flags, void *acl);
|
---|
| 34 |
|
---|
| 35 |
|
---|
| 36 | bool set_gpfs_sharemode(files_struct *fsp, uint32 access_mask,
|
---|
| 37 | uint32 share_access)
|
---|
| 38 | {
|
---|
| 39 | unsigned int allow = GPFS_SHARE_NONE;
|
---|
| 40 | unsigned int deny = GPFS_DENY_NONE;
|
---|
| 41 | int result;
|
---|
| 42 |
|
---|
| 43 | if (!gpfs_share_modes) {
|
---|
| 44 | return True;
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | if (gpfs_set_share_fn == NULL) {
|
---|
| 48 | return False;
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | if ((fsp == NULL) || (fsp->fh == NULL) || (fsp->fh->fd < 0)) {
|
---|
| 52 | /* No real file, don't disturb */
|
---|
| 53 | return True;
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | allow |= (access_mask & (FILE_WRITE_DATA|FILE_APPEND_DATA|
|
---|
| 57 | DELETE_ACCESS)) ? GPFS_SHARE_WRITE : 0;
|
---|
| 58 | allow |= (access_mask & (FILE_READ_DATA|FILE_EXECUTE)) ?
|
---|
| 59 | GPFS_SHARE_READ : 0;
|
---|
| 60 |
|
---|
| 61 | if (allow == GPFS_SHARE_NONE) {
|
---|
| 62 | DEBUG(10, ("special case am=no_access:%x\n",access_mask));
|
---|
| 63 | }
|
---|
| 64 | else {
|
---|
| 65 | deny |= (share_access & FILE_SHARE_WRITE) ?
|
---|
| 66 | 0 : GPFS_DENY_WRITE;
|
---|
| 67 | deny |= (share_access & (FILE_SHARE_READ)) ?
|
---|
| 68 | 0 : GPFS_DENY_READ;
|
---|
| 69 | }
|
---|
| 70 | DEBUG(10, ("am=%x, allow=%d, sa=%x, deny=%d\n",
|
---|
| 71 | access_mask, allow, share_access, deny));
|
---|
| 72 |
|
---|
| 73 | result = gpfs_set_share_fn(fsp->fh->fd, allow, deny);
|
---|
| 74 | if (result != 0) {
|
---|
| 75 | if (errno == ENOSYS) {
|
---|
| 76 | DEBUG(5, ("VFS module vfs_gpfs loaded, but no gpfs "
|
---|
| 77 | "support has been compiled into Samba. Allowing access\n"));
|
---|
| 78 | return True;
|
---|
| 79 | } else {
|
---|
| 80 | DEBUG(10, ("gpfs_set_share failed: %s\n",
|
---|
| 81 | strerror(errno)));
|
---|
| 82 | }
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | return (result == 0);
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | int set_gpfs_lease(int fd, int leasetype)
|
---|
| 89 | {
|
---|
| 90 | int gpfs_type = GPFS_LEASE_NONE;
|
---|
| 91 |
|
---|
| 92 | if (!gpfs_leases) {
|
---|
| 93 | return True;
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | if (gpfs_set_lease_fn == NULL) {
|
---|
| 97 | errno = EINVAL;
|
---|
| 98 | return -1;
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | if (leasetype == F_RDLCK) {
|
---|
| 102 | gpfs_type = GPFS_LEASE_READ;
|
---|
| 103 | }
|
---|
| 104 | if (leasetype == F_WRLCK) {
|
---|
| 105 | gpfs_type = GPFS_LEASE_WRITE;
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | /* we unconditionally set CAP_LEASE, rather than looking for
|
---|
| 109 | -1/EACCES as there is a bug in some versions of
|
---|
| 110 | libgpfs_gpl.so which results in a leaked fd on /dev/ss0
|
---|
| 111 | each time we try this with the wrong capabilities set
|
---|
| 112 | */
|
---|
| 113 | linux_set_lease_capability();
|
---|
| 114 | return gpfs_set_lease_fn(fd, gpfs_type);
|
---|
| 115 | }
|
---|
| 116 |
|
---|
| 117 | int smbd_gpfs_getacl(char *pathname, int flags, void *acl)
|
---|
| 118 | {
|
---|
| 119 | if (gpfs_getacl_fn == NULL) {
|
---|
| 120 | errno = ENOSYS;
|
---|
| 121 | return -1;
|
---|
| 122 | }
|
---|
| 123 |
|
---|
| 124 | return gpfs_getacl_fn(pathname, flags, acl);
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 | int smbd_gpfs_putacl(char *pathname, int flags, void *acl)
|
---|
| 128 | {
|
---|
| 129 | if (gpfs_putacl_fn == NULL) {
|
---|
| 130 | errno = ENOSYS;
|
---|
| 131 | return -1;
|
---|
| 132 | }
|
---|
| 133 |
|
---|
| 134 | return gpfs_putacl_fn(pathname, flags, acl);
|
---|
| 135 | }
|
---|
| 136 |
|
---|
| 137 | static bool init_gpfs_function_lib(void *plibhandle_pointer,
|
---|
| 138 | const char *libname,
|
---|
| 139 | void *pfn_pointer, const char *fn_name)
|
---|
| 140 | {
|
---|
| 141 | bool did_open_here = false;
|
---|
| 142 | void **libhandle_pointer = (void **)plibhandle_pointer;
|
---|
| 143 | void **fn_pointer = (void **)pfn_pointer;
|
---|
| 144 |
|
---|
| 145 | if (*libhandle_pointer == NULL) {
|
---|
| 146 | *libhandle_pointer = sys_dlopen(libname, RTLD_LAZY);
|
---|
| 147 | did_open_here = true;
|
---|
| 148 | }
|
---|
| 149 | if (*libhandle_pointer == NULL) {
|
---|
| 150 | DEBUG(10, ("Could not open lib %s\n", libname));
|
---|
| 151 | return false;
|
---|
| 152 | }
|
---|
| 153 |
|
---|
| 154 | *fn_pointer = sys_dlsym(*libhandle_pointer, fn_name);
|
---|
| 155 | if (*fn_pointer == NULL) {
|
---|
| 156 | DEBUG(10, ("Did not find symbol %s in lib %s\n",
|
---|
| 157 | fn_name, libname));
|
---|
| 158 | if (did_open_here) {
|
---|
| 159 | sys_dlclose(*libhandle_pointer);
|
---|
| 160 | *libhandle_pointer = NULL;
|
---|
| 161 | }
|
---|
| 162 | return false;
|
---|
| 163 | }
|
---|
| 164 |
|
---|
| 165 | return true;
|
---|
| 166 | }
|
---|
| 167 |
|
---|
| 168 | static bool init_gpfs_function(void *fn_pointer, const char *fn_name)
|
---|
| 169 | {
|
---|
| 170 | static void *libgpfs_handle = NULL;
|
---|
| 171 | static void *libgpfs_gpl_handle = NULL;
|
---|
| 172 |
|
---|
| 173 | if (init_gpfs_function_lib(&libgpfs_handle, "libgpfs.so",
|
---|
| 174 | fn_pointer, fn_name)) {
|
---|
| 175 | return true;
|
---|
| 176 | }
|
---|
| 177 | if (init_gpfs_function_lib(&libgpfs_gpl_handle, "libgpfs_gpl.so",
|
---|
| 178 | fn_pointer, fn_name)) {
|
---|
| 179 | return true;
|
---|
| 180 | }
|
---|
| 181 | return false;
|
---|
| 182 | }
|
---|
| 183 |
|
---|
| 184 | void init_gpfs(void)
|
---|
| 185 | {
|
---|
| 186 | init_gpfs_function(&gpfs_set_share_fn, "gpfs_set_share");
|
---|
| 187 | init_gpfs_function(&gpfs_set_lease_fn, "gpfs_set_lease");
|
---|
| 188 | init_gpfs_function(&gpfs_getacl_fn, "gpfs_getacl");
|
---|
| 189 | init_gpfs_function(&gpfs_putacl_fn, "gpfs_putacl");
|
---|
| 190 |
|
---|
| 191 | gpfs_share_modes = lp_parm_bool(-1, "gpfs", "sharemodes", True);
|
---|
| 192 | gpfs_leases = lp_parm_bool(-1, "gpfs", "leases", True);
|
---|
| 193 |
|
---|
| 194 | return;
|
---|
| 195 | }
|
---|
| 196 |
|
---|
| 197 | #else
|
---|
| 198 |
|
---|
| 199 | int set_gpfs_lease(int snum, int leasetype)
|
---|
| 200 | {
|
---|
| 201 | DEBUG(0, ("'VFS module smbgpfs loaded, without gpfs support compiled\n"));
|
---|
| 202 |
|
---|
| 203 | /* We need to indicate that no GPFS is around by returning ENOSYS, so
|
---|
| 204 | * that the normal linux kernel oplock code is called. */
|
---|
| 205 | errno = ENOSYS;
|
---|
| 206 | return -1;
|
---|
| 207 | }
|
---|
| 208 |
|
---|
| 209 | bool set_gpfs_sharemode(files_struct *fsp, uint32 access_mask,
|
---|
| 210 | uint32 share_access)
|
---|
| 211 | {
|
---|
| 212 | DEBUG(0, ("VFS module - smbgpfs.so loaded, without gpfs support compiled\n"));
|
---|
| 213 | /* Don't disturb but complain */
|
---|
| 214 | return True;
|
---|
| 215 | }
|
---|
| 216 |
|
---|
| 217 | int smbd_gpfs_getacl(char *pathname, int flags, void *acl)
|
---|
| 218 | {
|
---|
| 219 | errno = ENOSYS;
|
---|
| 220 | return -1;
|
---|
| 221 | }
|
---|
| 222 |
|
---|
| 223 | int smbd_gpfs_putacl(char *pathname, int flags, void *acl)
|
---|
| 224 | {
|
---|
| 225 | errno = ENOSYS;
|
---|
| 226 | return -1;
|
---|
| 227 | }
|
---|
| 228 |
|
---|
| 229 | void init_gpfs(void)
|
---|
| 230 | {
|
---|
| 231 | return;
|
---|
| 232 | }
|
---|
| 233 |
|
---|
| 234 | #endif /* HAVE_GPFS */
|
---|