modules/gpfs.c

説明を見る。
00001 /* 
00002  *  Unix SMB/CIFS implementation.
00003  *  Provide a connection to GPFS specific features
00004  *  Copyright (C) Volker Lendecke 2005
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *  
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *  
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019  */
00020 
00021 #include "includes.h"
00022 
00023 #ifdef HAVE_GPFS
00024 
00025 #include "gpfs_gpl.h"
00026 
00027 static void *libgpfs_handle = NULL;
00028 
00029 static int (*gpfs_set_share_fn)(int fd, unsigned int allow, unsigned int deny);
00030 static int (*gpfs_set_lease_fn)(int fd, unsigned int leaseType);
00031 static int (*gpfs_getacl_fn)(char *pathname, int flags, void *acl);
00032 static int (*gpfs_putacl_fn)(char *pathname, int flags, void *acl);
00033 
00034 
00035 BOOL set_gpfs_sharemode(files_struct *fsp, uint32 access_mask,
00036                         uint32 share_access)
00037 {
00038         unsigned int allow = GPFS_SHARE_NONE;
00039         unsigned int deny = GPFS_DENY_NONE;
00040         int result;
00041 
00042         if (gpfs_set_share_fn == NULL) {
00043                 return False;
00044         }
00045 
00046         if ((fsp == NULL) || (fsp->fh == NULL) || (fsp->fh->fd < 0)) {
00047                 /* No real file, don't disturb */
00048                 return True;
00049         }
00050 
00051         allow |= (access_mask & (FILE_WRITE_DATA|FILE_APPEND_DATA|
00052                                  DELETE_ACCESS)) ? GPFS_SHARE_WRITE : 0;
00053         allow |= (access_mask & (FILE_READ_DATA|FILE_EXECUTE)) ?
00054                 GPFS_SHARE_READ : 0;
00055 
00056         if (allow == GPFS_SHARE_NONE) {
00057                 DEBUG(10, ("special case am=no_access:%x\n",access_mask));
00058         }
00059         else {  
00060                 deny |= (share_access & FILE_SHARE_WRITE) ?
00061                         0 : GPFS_DENY_WRITE;
00062                 deny |= (share_access & (FILE_SHARE_READ)) ?
00063                         0 : GPFS_DENY_READ;
00064         }
00065         DEBUG(10, ("am=%x, allow=%d, sa=%x, deny=%d\n",
00066                    access_mask, allow, share_access, deny));
00067 
00068         result = gpfs_set_share_fn(fsp->fh->fd, allow, deny);
00069         if (result != 0) {
00070                 if (errno == ENOSYS) {
00071                         DEBUG(5, ("VFS module vfs_gpfs loaded, but no gpfs "
00072                                   "support has been compiled into Samba. Allowing access\n"));
00073                         return True;
00074                 } else {
00075                         DEBUG(10, ("gpfs_set_share failed: %s\n",
00076                                    strerror(errno)));
00077                 }
00078         }
00079 
00080         return (result == 0);
00081 }
00082 
00083 int set_gpfs_lease(int fd, int leasetype)
00084 {
00085         int gpfs_type = GPFS_LEASE_NONE;
00086 
00087         if (gpfs_set_lease_fn == NULL) {
00088                 errno = EINVAL;
00089                 return -1;
00090         }
00091 
00092         if (leasetype == F_RDLCK) {
00093                 gpfs_type = GPFS_LEASE_READ;
00094         }
00095         if (leasetype == F_WRLCK) {
00096                 gpfs_type = GPFS_LEASE_WRITE;
00097         }
00098         return gpfs_set_lease_fn(fd, gpfs_type);
00099 }
00100 
00101 int smbd_gpfs_getacl(char *pathname, int flags, void *acl)
00102 {
00103         if (gpfs_getacl_fn == NULL) {
00104                 errno = ENOSYS;
00105                 return -1;
00106         }
00107 
00108         return gpfs_getacl_fn(pathname, flags, acl);
00109 }
00110 
00111 int smbd_gpfs_putacl(char *pathname, int flags, void *acl)
00112 {
00113         if (gpfs_putacl_fn == NULL) {
00114                 errno = ENOSYS;
00115                 return -1;
00116         }
00117 
00118         return gpfs_putacl_fn(pathname, flags, acl);
00119 }
00120 
00121 void init_gpfs(void)
00122 {
00123         if (libgpfs_handle != NULL) {
00124                 return;
00125         }
00126 
00127         libgpfs_handle = sys_dlopen("libgpfs_gpl.so", RTLD_LAZY);
00128 
00129         if (libgpfs_handle == NULL) {
00130                 DEBUG(10, ("sys_dlopen for libgpfs_gpl failed: %s\n",
00131                            strerror(errno)));
00132                 return;
00133         }
00134 
00135         DEBUG(10, ("libgpfs_gpl.so loaded\n"));
00136 
00137         gpfs_set_share_fn = sys_dlsym(libgpfs_handle, "gpfs_set_share");
00138         if (gpfs_set_share_fn == NULL) {
00139                 DEBUG(3, ("libgpfs_gpl.so does not contain the symbol "
00140                           "'gpfs_set_share'\n"));
00141                 sys_dlclose(libgpfs_handle);
00142 
00143                 /* leave libgpfs_handle != NULL around, no point
00144                    in trying twice */
00145                 gpfs_set_share_fn = NULL;
00146                 gpfs_set_lease_fn = NULL;
00147                 gpfs_getacl_fn = NULL;
00148                 gpfs_putacl_fn = NULL;
00149                 return;
00150         }
00151 
00152         gpfs_set_lease_fn = sys_dlsym(libgpfs_handle, "gpfs_set_lease");
00153         if (gpfs_set_lease_fn == NULL) {
00154                 DEBUG(3, ("libgpfs_gpl.so does not contain the symbol "
00155                           "'gpfs_set_lease'\n"));
00156                 sys_dlclose(libgpfs_handle);
00157 
00158                 /* leave libgpfs_handle != NULL around, no point
00159                    in trying twice */
00160                 gpfs_set_share_fn = NULL;
00161                 gpfs_set_lease_fn = NULL;
00162                 gpfs_getacl_fn = NULL;
00163                 gpfs_putacl_fn = NULL;
00164                 return;
00165         }
00166 
00167         gpfs_getacl_fn = sys_dlsym(libgpfs_handle, "gpfs_getacl");
00168         if (gpfs_getacl_fn == NULL) {
00169                 DEBUG(3, ("libgpfs_gpl.so does not contain the symbol "
00170                           "'gpfs_getacl'\n"));
00171                 sys_dlclose(libgpfs_handle);
00172 
00173                 /* leave libgpfs_handle != NULL around, no point
00174                    in trying twice */
00175                 gpfs_set_share_fn = NULL;
00176                 gpfs_set_lease_fn = NULL;
00177                 gpfs_getacl_fn = NULL;
00178                 gpfs_putacl_fn = NULL;
00179                 return;
00180         }
00181 
00182         gpfs_putacl_fn = sys_dlsym(libgpfs_handle, "gpfs_putacl");
00183         if (gpfs_putacl_fn == NULL) {
00184                 DEBUG(3, ("libgpfs_gpl.so does not contain the symbol "
00185                           "'gpfs_putacl'\n"));
00186                 sys_dlclose(libgpfs_handle);
00187 
00188                 /* leave libgpfs_handle != NULL around, no point
00189                    in trying twice */
00190                 gpfs_set_share_fn = NULL;
00191                 gpfs_set_lease_fn = NULL;
00192                 gpfs_getacl_fn = NULL;
00193                 gpfs_putacl_fn = NULL;
00194                 return;
00195         }
00196 
00197 }
00198 
00199 #else
00200 
00201 int set_gpfs_lease(int snum, int leasetype)
00202 {
00203         DEBUG(0, ("'VFS module smbgpfs loaded, without gpfs support compiled\n"));
00204 
00205         /* We need to indicate that no GPFS is around by returning ENOSYS, so
00206          * that the normal linux kernel oplock code is called. */
00207         errno = ENOSYS;
00208         return -1;
00209 }
00210 
00211 BOOL set_gpfs_sharemode(files_struct *fsp, uint32 access_mask,
00212                         uint32 share_access)
00213 {
00214         DEBUG(0, ("VFS module - smbgpfs.so loaded, without gpfs support compiled\n"));
00215         /* Don't disturb but complain */
00216         return True;
00217 }
00218 
00219 int smbd_gpfs_getacl(char *pathname, int flags, void *acl)
00220 {
00221         errno = ENOSYS;
00222         return -1;
00223 }
00224 
00225 int smbd_gpfs_putacl(char *pathname, int flags, void *acl)
00226 {
00227         errno = ENOSYS;
00228         return -1;
00229 }
00230 
00231 void init_gpfs(void)
00232 {
00233         return;
00234 }
00235 
00236 #endif /* HAVE_GPFS */

Sambaに対してSat Aug 29 21:23:06 2009に生成されました。  doxygen 1.4.7