nfs-ganesha 1.4

fsal_access.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 
00035 #ifdef HAVE_CONFIG_H
00036 #include "config.h"
00037 #endif
00038 
00039 #include "fsal.h"
00040 #include "fsal_internal.h"
00041 #include "fsal_convert.h"
00042 #include "FSAL/access_check.h"
00043 
00075 fsal_status_t XFSFSAL_access(fsal_handle_t * p_object_handle,        /* IN */
00076                              fsal_op_context_t * p_context,  /* IN */
00077                              fsal_accessflags_t access_type,    /* IN */
00078                              fsal_attrib_list_t * p_object_attributes   /* [ IN/OUT ] */
00079     )
00080 {
00081 
00082   fsal_status_t status;
00083 
00084   /* sanity checks.
00085    * note : object_attributes is optionnal in FSAL_getattrs.
00086    */
00087   if(!p_object_handle || !p_context)
00088     Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_access);
00089 
00090   /* 
00091    * If an error occures during getattr operation,
00092    * it is returned, even though the access operation succeeded.
00093    */
00094 
00095   if(p_object_attributes)
00096     {
00097 
00098       FSAL_SET_MASK(p_object_attributes->asked_attributes,
00099                     FSAL_ATTR_OWNER | FSAL_ATTR_GROUP | FSAL_ATTR_ACL | FSAL_ATTR_MODE);
00100       status = FSAL_getattrs(p_object_handle, p_context, p_object_attributes);
00101 
00102       /* on error, we set a special bit in the mask. */
00103       if(FSAL_IS_ERROR(status))
00104         {
00105           FSAL_CLEAR_MASK(p_object_attributes->asked_attributes);
00106           FSAL_SET_MASK(p_object_attributes->asked_attributes, FSAL_ATTR_RDATTR_ERR);
00107           Return(status.major, status.minor, INDEX_FSAL_access);
00108         }
00109 
00110       status =
00111           fsal_check_access(p_context, access_type, NULL, p_object_attributes);
00112 
00113     }
00114   else
00115     {                           /* p_object_attributes is NULL */
00116       fsal_attrib_list_t attrs;
00117 
00118       FSAL_CLEAR_MASK(attrs.asked_attributes);
00119       FSAL_SET_MASK(attrs.asked_attributes,
00120                     FSAL_ATTR_OWNER | FSAL_ATTR_GROUP | FSAL_ATTR_ACL | FSAL_ATTR_MODE);
00121 
00122       status = FSAL_getattrs(p_object_handle, p_context, &attrs);
00123 
00124       /* on error, we set a special bit in the mask. */
00125       if(FSAL_IS_ERROR(status))
00126         Return(status.major, status.minor, INDEX_FSAL_access);
00127 
00128       status = fsal_check_access(p_context, access_type, NULL, &attrs);
00129     }
00130 
00131   Return(status.major, status.minor, INDEX_FSAL_access);
00132 
00133 }