Home | History | Annotate | Download | only in src
      1 /*
      2  * Copyright (C) 2014 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 /*==================================================================================================
     18 
     19     Source Name: dmACLManager.cc
     20 
     21     General Description: Implementation of the DMAclManager class
     22 
     23 ==================================================================================================*/
     24 
     25 #include "dm_uri_utils.h"
     26 #include "dm_tree_class.H"
     27 #include "xpl_Logger.h"
     28 #include "dmACLManager.h"
     29 
     30 SYNCML_DM_RET_STATUS_T
     31 DMAclManager::Init(CEnv* env,
     32                           DMTree* tree)
     33 {
     34     return DMConfigManager::Init(env,tree,SYNCML_DM_FILE_ACL);
     35 }
     36 
     37 void DMAclManager::GetFileName(DMString & strFileName)
     38 {
     39      m_pEnv->GetWFSFullPath(DM_DEFAULT_ACL_FILENAME,strFileName);
     40 }
     41 
     42 
     43 DMConfigItem * DMAclManager::AllocateConfigItem()
     44 {
     45     return (new DMAclItem());
     46 
     47 }
     48 
     49 
     50 
     51 
     52 BOOLEAN
     53 DMAclManager::IsPermitted( CPCHAR szPath,
     54                                           CPCHAR szServerID,
     55                                           SYNCML_DM_ACL_PERMISSIONS_T nPermissions ) const
     56 {
     57     DMURI oURI(FALSE,szPath);
     58     CPCHAR pParent = szPath;
     59 
     60     if ( !m_aConfig.size() )
     61        return TRUE;
     62 
     63     do
     64     {
     65         PDMConfigItem pItem;
     66         if ( Find(pParent,pItem) != -1 )
     67         {
     68             if ( ((DMAclItem*)(pItem.GetPtr()))->IsPermitted( "*", nPermissions ) ||
     69                   ((DMAclItem*)(pItem.GetPtr()))->IsPermitted( szServerID, nPermissions ) )
     70                 return TRUE;
     71             XPL_LOG_DM_TMN_Debug(("DMAclManager::IsPermitted(,,): check permission failed... \n"));
     72             return FALSE;
     73         }
     74     } while ( (pParent = oURI.getParentURI()) != NULL ) ;
     75 
     76   XPL_LOG_DM_TMN_Debug(("DMAclManager::IsPermitted(,,): check . node, permission not allowed \n"));
     77   return FALSE; // not . node
     78 }
     79 
     80 BOOLEAN
     81 DMAclManager::IsPermitted( CPCHAR szPath,
     82                                       CPCHAR szServerID,
     83                                       SYNCML_DM_ACL_PERMISSIONS_T nPermissions,
     84                                       BOOLEAN bIsCheckLocal )
     85 {
     86 
     87     DMMetaDataManager & m_oMDFObj =  m_pTree->GetMetaDataManager();
     88 
     89     if ( bIsCheckLocal && m_oMDFObj.IsLocal(szPath) )
     90     {
     91          XPL_LOG_DM_TMN_Debug(("DMAclManager::IsPermitted(,,,): check local but path is not local\n"));
     92          return FALSE;
     93     }
     94 
     95     // Deserialize() make expensive XPL_FS_GetModTime call
     96     // we just trying to minimize them
     97     if (!m_bLoaded)
     98 		Deserialize();
     99 
    100     if ( IsPermitted(szPath, szServerID, nPermissions) == FALSE )
    101     {
    102          XPL_LOG_DM_TMN_Debug(("DMAclManager::IsPermitted(,,,): permission for node %s is not granted to the server %s\n", szPath,szServerID));
    103          return FALSE;
    104     }
    105 
    106     DMString szMDF;
    107     m_oMDFObj.GetPath(szPath, szMDF);
    108 
    109     if (szMDF != szPath )
    110     {
    111         XPL_LOG_DM_TMN_Debug(("DMAclManager::IsPermitted(,,,): permission mdf check, szMDF:%s, szPath:%s",szMDF.c_str(), szPath));
    112         return IsPermitted(szMDF, szServerID, nPermissions);
    113     }
    114 
    115     return TRUE;
    116 }
    117 
    118 
    119 SYNCML_DM_RET_STATUS_T DMAclManager::SetACL( CPCHAR szPath, CPCHAR szACL )
    120 {
    121 
    122     CheckLocking();
    123     Delete(szPath);
    124 
    125     DMAclItem *pItem = new DMAclItem(szPath, szACL);
    126     if ( pItem == NULL )
    127         return SYNCML_DM_DEVICE_FULL;
    128 
    129     m_aConfig.push_back(PDMConfigItem(pItem));
    130     m_bChanged = true;
    131     return SYNCML_DM_SUCCESS;
    132 }
    133 
    134 SYNCML_DM_RET_STATUS_T
    135 DMAclManager::GetACL(CPCHAR szPath,
    136                                      DMString& strACL)
    137 {
    138     strACL = NULL;
    139 
    140     PDMConfigItem pItem;
    141     SYNCML_DM_RET_STATUS_T dm_stat = SYNCML_DM_SUCCESS;
    142 
    143     // Deserialize() make expensive XPL_FS_GetModTime call
    144     // we just trying to minimize them
    145     if (!m_bLoaded)
    146     	Deserialize();
    147 
    148     dm_stat = Get(szPath,pItem);
    149     if ( dm_stat != SYNCML_DM_SUCCESS )
    150         return dm_stat;
    151 
    152     strACL = ((DMAclItem*)(pItem.GetPtr()))->toString();
    153     return SYNCML_DM_SUCCESS;
    154 }
    155