lxcpp: fix cgroup unit tests
[platform/core/security/vasum.git] / server / proxy-call-policy.cpp
1 /*
2  *  Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *  Contact: Piotr Bartosiewicz <p.bartosiewi@partner.samsung.com>
5  *
6  *  Licensed under the Apache License, Version 2.0 (the "License");
7  *  you may not use this file except in compliance with the License.
8  *  You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *  Unless required by applicable law or agreed to in writing, software
13  *  distributed under the License is distributed on an "AS IS" BASIS,
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *  See the License for the specific language governing permissions and
16  *  limitations under the License
17  */
18
19 /**
20  * @file
21  * @author  Piotr Bartosiewicz (p.bartosiewi@partner.samsung.com)
22  * @brief   Implementation of a class for checking permissions of proxy calls
23  */
24
25
26 #include "config.hpp"
27
28 #include "proxy-call-policy.hpp"
29
30
31 namespace vasum {
32
33 namespace {
34 const std::string ANY = "*";
35
36 inline bool match(const std::string& rule, const std::string& value) {
37     // simple matching, change to regex if it turns out to be insufficient
38     return rule == ANY || rule == value;
39 }
40
41 } // namespace
42
43
44 ProxyCallPolicy::ProxyCallPolicy(const std::vector<ProxyCallRule>& proxyCallRules)
45     : mProxyCallRules(proxyCallRules)
46 {
47 }
48
49 bool ProxyCallPolicy::isProxyCallAllowed(const std::string& caller,
50                                          const std::string& target,
51                                          const std::string& targetBusName,
52                                          const std::string& targetObjectPath,
53                                          const std::string& targetInterface,
54                                          const std::string& targetMethod) const
55 {
56     for (const ProxyCallRule& rule : mProxyCallRules) {
57         if (match(rule.caller, caller)
58                 && match(rule.target, target)
59                 && match(rule.targetBusName, targetBusName)
60                 && match(rule.targetObjectPath, targetObjectPath)
61                 && match(rule.targetInterface, targetInterface)
62                 && match(rule.targetMethod, targetMethod)) {
63             return true;
64         }
65     }
66
67     return false;
68 }
69
70
71 } // namespace vasum