nfs-ganesha 1.4

nfs4_op_verify.c

Go to the documentation of this file.
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 
00036 #ifdef HAVE_CONFIG_H
00037 #include "config.h"
00038 #endif
00039 
00040 #ifdef _SOLARIS
00041 #include "solaris_port.h"
00042 #endif
00043 
00044 #include <stdio.h>
00045 #include <string.h>
00046 #include <pthread.h>
00047 #include <fcntl.h>
00048 #include <sys/file.h>           /* for having FNDELAY */
00049 #include "HashData.h"
00050 #include "HashTable.h"
00051 #include "log.h"
00052 #include "ganesha_rpc.h"
00053 #include "nfs23.h"
00054 #include "nfs4.h"
00055 #include "mount.h"
00056 #include "nfs_core.h"
00057 #include "cache_inode.h"
00058 #include "nfs_exports.h"
00059 #include "nfs_creds.h"
00060 #include "nfs_proto_functions.h"
00061 #include "nfs_proto_tools.h"
00062 #include "nfs_tools.h"
00063 #include "nfs_file_handle.h"
00064 
00079 #define arg_VERIFY4 op->nfs_argop4_u.opverify
00080 #define res_VERIFY4 resp->nfs_resop4_u.opverify
00081 
00082 int nfs4_op_verify(struct nfs_argop4 *op, compound_data_t * data, struct nfs_resop4 *resp)
00083 {
00084   char __attribute__ ((__unused__)) funcname[] = "nfs4_op_verify";
00085 
00086   fsal_attrib_list_t   file_attr;
00087   cache_inode_status_t cache_status;
00088   fattr4               file_attr4;
00089   int                  rc = 0;
00090 
00091   resp->resop = NFS4_OP_VERIFY;
00092   res_VERIFY4.status = NFS4_OK;
00093 
00094   /* Do basic checks on a filehandle */
00095   res_VERIFY4.status = nfs4_sanity_check_FH(data, 0LL);
00096   if(res_VERIFY4.status != NFS4_OK)
00097     return res_VERIFY4.status;
00098 
00099   /* operation is always permitted on pseudofs */
00100   if(nfs4_Is_Fh_Pseudo(&(data->currentFH)))
00101     {
00102       res_VERIFY4.status = NFS4_OK;
00103       return res_VERIFY4.status;
00104     }
00105 
00106   /* Get only attributes that are allowed to be read */
00107   if(!nfs4_Fattr_Check_Access(&arg_VERIFY4.obj_attributes, FATTR4_ATTR_READ))
00108     {
00109       res_VERIFY4.status = NFS4ERR_INVAL;
00110       return res_VERIFY4.status;
00111     }
00112 
00113   /* Ask only for supported attributes */
00114   if(!nfs4_Fattr_Supported(&arg_VERIFY4.obj_attributes))
00115     {
00116       res_VERIFY4.status = NFS4ERR_ATTRNOTSUPP;
00117       return res_VERIFY4.status;
00118     }
00119 
00120   /* Get the cache inode attribute */
00121   if((cache_status = cache_inode_getattr(data->current_entry,
00122                                          &file_attr,
00123                                          data->pcontext,
00124                                          &cache_status)) != CACHE_INODE_SUCCESS)
00125     {
00126       res_VERIFY4.status = NFS4ERR_INVAL;
00127       return res_VERIFY4.status;
00128     }
00129 
00130   if(nfs4_FSALattr_To_Fattr(data->pexport,
00131                             &file_attr,
00132                             &file_attr4,
00133                             data,
00134                             &(data->currentFH),
00135                             &(arg_VERIFY4.obj_attributes.attrmask)) != 0)
00136     {
00137       res_VERIFY4.status = NFS4ERR_SERVERFAULT;
00138       return res_VERIFY4.status;
00139     }
00140 
00141   if((rc = nfs4_Fattr_cmp(&(arg_VERIFY4.obj_attributes), &file_attr4)) == TRUE)
00142     res_VERIFY4.status = NFS4_OK;
00143   else
00144     {
00145       if(rc == -1)
00146         res_VERIFY4.status = NFS4ERR_INVAL;
00147       else
00148         res_VERIFY4.status = NFS4ERR_NOT_SAME;
00149     }
00150 
00151   nfs4_Fattr_Free(&file_attr4);
00152   return res_VERIFY4.status;
00153 }                               /* nfs4_op_verify */
00154 
00165 void nfs4_op_verify_Free(VERIFY4res * resp)
00166 {
00167   /* Nothing to be done */
00168   return;
00169 }                               /* nfs4_op_verify_Free */