nfs-ganesha 1.4
|
00001 /* 00002 * vim:expandtab:shiftwidth=8:tabstop=8: 00003 * 00004 * Copyright CEA/DAM/DIF (2008) 00005 * contributeur : Philippe DENIEL philippe.deniel@cea.fr 00006 * Thomas LEIBOVICI thomas.leibovici@cea.fr 00007 * 00008 * 00009 * This program is free software; you can redistribute it and/or 00010 * modify it under the terms of the GNU Lesser General Public 00011 * License as published by the Free Software Foundation; either 00012 * version 3 of the License, or (at your option) any later version. 00013 * 00014 * This program is distributed in the hope that it will be useful, 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 * Lesser General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU Lesser General Public 00020 * License along with this library; if not, write to the Free Software 00021 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00022 * 00023 * --------------------------------------- 00024 */ 00025 00037 #ifdef HAVE_CONFIG_H 00038 #include "config.h" 00039 #endif 00040 00041 #ifdef _SOLARIS 00042 #include "solaris_port.h" 00043 #endif 00044 00045 #include <stdio.h> 00046 #include <string.h> 00047 #include <pthread.h> 00048 #include <fcntl.h> 00049 #include <sys/file.h> /* for having FNDELAY */ 00050 #include "HashData.h" 00051 #include "HashTable.h" 00052 #include "log.h" 00053 #include "ganesha_rpc.h" 00054 #include "nfs23.h" 00055 #include "nfs4.h" 00056 #include "mount.h" 00057 #include "nfs_core.h" 00058 #include "cache_inode.h" 00059 #include "nfs_exports.h" 00060 #include "nfs_creds.h" 00061 #include "nfs_proto_functions.h" 00062 #include "nfs_tools.h" 00063 #include "nfs_file_handle.h" 00064 #include "nfs_proto_tools.h" 00065 00078 #define arg_ACCESS4 op->nfs_argop4_u.opaccess 00079 #define res_ACCESS4 resp->nfs_resop4_u.opaccess 00080 00081 int nfs4_op_access(struct nfs_argop4 *op, compound_data_t * data, struct nfs_resop4 *resp) 00082 { 00083 char __attribute__ ((__unused__)) funcname[] = "nfs4_op_access"; 00084 00085 fsal_attrib_list_t attr; 00086 fsal_accessflags_t access_mask = 0; 00087 cache_inode_status_t cache_status; 00088 uint32_t max_access = (ACCESS4_READ | ACCESS4_LOOKUP | ACCESS4_MODIFY | 00089 ACCESS4_EXTEND | ACCESS4_DELETE | ACCESS4_EXECUTE); 00090 00091 /* initialize output */ 00092 res_ACCESS4.ACCESS4res_u.resok4.supported = 0; 00093 res_ACCESS4.ACCESS4res_u.resok4.access = 0; 00094 00095 resp->resop = NFS4_OP_ACCESS; 00096 res_ACCESS4.status = NFS4_OK; 00097 00098 /* Do basic checks on a filehandle */ 00099 res_ACCESS4.status = nfs4_sanity_check_FH(data, 0LL); 00100 if(res_ACCESS4.status != NFS4_OK) 00101 return res_ACCESS4.status; 00102 00103 /* If Filehandle points to a pseudo fs entry, manage it via pseudofs specific functions */ 00104 if(nfs4_Is_Fh_Pseudo(&(data->currentFH))) 00105 return nfs4_op_access_pseudo(op, data, resp); 00106 00107 /* If Filehandle points to a xattr object, manage it via the xattrs specific functions */ 00108 if(nfs4_Is_Fh_Xattr(&(data->currentFH))) 00109 return nfs4_op_access_xattr(op, data, resp); 00110 00111 /* Check for input parameter's sanity */ 00112 if(arg_ACCESS4.access > max_access) 00113 { 00114 res_ACCESS4.status = NFS4ERR_INVAL; 00115 return res_ACCESS4.status; 00116 } 00117 00118 /* Get the attributes for the object */ 00119 attr = data->current_entry->attributes; 00120 00121 /* determine the rights to be tested in FSAL */ 00122 00123 if(arg_ACCESS4.access & ACCESS4_READ) 00124 { 00125 res_ACCESS4.ACCESS4res_u.resok4.supported |= ACCESS4_READ; 00126 access_mask |= nfs_get_access_mask(ACCESS4_READ, &attr); 00127 } 00128 00129 if((arg_ACCESS4.access & ACCESS4_LOOKUP) && (attr.type == FSAL_TYPE_DIR)) 00130 { 00131 res_ACCESS4.ACCESS4res_u.resok4.supported |= ACCESS4_LOOKUP; 00132 access_mask |= nfs_get_access_mask(ACCESS4_LOOKUP, &attr); 00133 } 00134 00135 if(arg_ACCESS4.access & ACCESS4_MODIFY) 00136 { 00137 res_ACCESS4.ACCESS4res_u.resok4.supported |= ACCESS4_MODIFY; 00138 access_mask |= nfs_get_access_mask(ACCESS4_MODIFY, &attr); 00139 } 00140 00141 if(arg_ACCESS4.access & ACCESS4_EXTEND) 00142 { 00143 res_ACCESS4.ACCESS4res_u.resok4.supported |= ACCESS4_EXTEND; 00144 access_mask |= nfs_get_access_mask(ACCESS4_EXTEND, &attr); 00145 } 00146 00147 if((arg_ACCESS4.access & ACCESS4_DELETE) && (attr.type == FSAL_TYPE_DIR)) 00148 { 00149 res_ACCESS4.ACCESS4res_u.resok4.supported |= ACCESS4_DELETE; 00150 access_mask |= nfs_get_access_mask(ACCESS4_DELETE, &attr); 00151 } 00152 00153 if((arg_ACCESS4.access & ACCESS4_EXECUTE) && (attr.type != FSAL_TYPE_DIR)) 00154 { 00155 res_ACCESS4.ACCESS4res_u.resok4.supported |= ACCESS4_EXECUTE; 00156 access_mask |= nfs_get_access_mask(ACCESS4_EXECUTE, &attr); 00157 } 00158 00159 nfs4_access_debug("requested access", arg_ACCESS4.access, FSAL_ACE4_MASK(access_mask)); 00160 00161 /* Perform the 'access' call */ 00162 if(cache_inode_access(data->current_entry, 00163 access_mask, 00164 data->pcontext, &cache_status) == CACHE_INODE_SUCCESS) 00165 { 00166 res_ACCESS4.ACCESS4res_u.resok4.access = res_ACCESS4.ACCESS4res_u.resok4.supported; 00167 nfs4_access_debug("granted access", arg_ACCESS4.access, 0); 00168 } 00169 00170 if(cache_status == CACHE_INODE_FSAL_EACCESS) 00171 { 00172 /* 00173 * We have to determine which access bits are good one by one 00174 */ 00175 res_ACCESS4.ACCESS4res_u.resok4.access = 0; 00176 00177 access_mask = nfs_get_access_mask(ACCESS4_READ, &attr); 00178 if(cache_inode_access(data->current_entry, 00179 access_mask, 00180 data->pcontext, &cache_status) == CACHE_INODE_SUCCESS) 00181 res_ACCESS4.ACCESS4res_u.resok4.access |= ACCESS4_READ; 00182 00183 if(attr.type == FSAL_TYPE_DIR) 00184 { 00185 access_mask = nfs_get_access_mask(ACCESS4_LOOKUP, &attr); 00186 if(cache_inode_access(data->current_entry, 00187 access_mask, 00188 data->pcontext, &cache_status) == CACHE_INODE_SUCCESS) 00189 res_ACCESS4.ACCESS4res_u.resok4.access |= ACCESS4_LOOKUP; 00190 } 00191 00192 access_mask = nfs_get_access_mask(ACCESS4_MODIFY, &attr); 00193 if(cache_inode_access(data->current_entry, 00194 access_mask, 00195 data->pcontext, &cache_status) == CACHE_INODE_SUCCESS) 00196 res_ACCESS4.ACCESS4res_u.resok4.access |= ACCESS4_MODIFY; 00197 00198 access_mask = nfs_get_access_mask(ACCESS4_EXTEND, &attr); 00199 if(cache_inode_access(data->current_entry, 00200 access_mask, 00201 data->pcontext, &cache_status) == CACHE_INODE_SUCCESS) 00202 res_ACCESS4.ACCESS4res_u.resok4.access |= ACCESS4_EXTEND; 00203 00204 if(attr.type == FSAL_TYPE_DIR) 00205 { 00206 access_mask = nfs_get_access_mask(ACCESS4_DELETE, &attr); 00207 if(cache_inode_access(data->current_entry, 00208 access_mask, 00209 data->pcontext, &cache_status) == CACHE_INODE_SUCCESS) 00210 res_ACCESS4.ACCESS4res_u.resok4.access |= ACCESS4_DELETE; 00211 } 00212 00213 if(attr.type != FSAL_TYPE_DIR) 00214 { 00215 access_mask = nfs_get_access_mask(ACCESS4_EXECUTE, &attr); 00216 if(cache_inode_access(data->current_entry, 00217 access_mask, 00218 data->pcontext, &cache_status) == CACHE_INODE_SUCCESS) 00219 res_ACCESS4.ACCESS4res_u.resok4.access |= ACCESS4_EXECUTE; 00220 } 00221 00222 nfs4_access_debug("reduced access", res_ACCESS4.ACCESS4res_u.resok4.access, 0); 00223 } 00224 00225 res_ACCESS4.status = NFS4_OK; 00226 00227 return res_ACCESS4.status; 00228 } /* nfs4_op_access */ 00229 00240 void nfs4_op_access_Free(ACCESS4res * resp) 00241 { 00242 /* Nothing to be done */ 00243 return; 00244 } /* nfs4_op_access_Free */