Implement master and slave mode
[platform/core/security/security-manager.git] / src / common / include / zone-utils.h
1 /*
2  *  Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *  Contact: Rafal Krypa <r.krypa@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  * @file        zone-utils.h
20  * @author      Lukasz Kostyra (l.kostyra@samsung.com)
21  * @version     1.0
22  * @brief       Definition of Zone utilities
23  */
24
25 #ifndef _SECURITY_MANAGER_ZONE_UTILS_H_
26 #define _SECURITY_MANAGER_ZONE_UTILS_H_
27
28 #include <string>
29
30 // FIXME This module is a replacement for Vasum functions.
31 //
32 //       When Vasum will be included into OBS, the module should be removed and vasum-client should
33 //       be used instead.
34
35 namespace SecurityManager
36 {
37
38 extern const std::string ZONE_HOST;
39
40 /**
41  * Extracts Zone ID in which runs process having provided PID.
42  *
43  * This function parses /proc/<pid>/cpuset file and tries to acquire Zone ID name from it.
44  *
45  * @param[in]  pid    PID of process to get Zone ID from.
46  * @param[out] zoneId Zone ID extracted from cpuset. If process runs in host, returns "host" string.
47  * @return            True on success, false on failure.
48  */
49 bool getZoneIdFromPid(int pid, std::string& zoneId);
50
51 /**
52  * Generates zone-specific label from given @ref label and zone's name @ref zoneName
53  *
54  * @param[in]  label    Base label, used to generate new zone-specific label
55  * @param[in]  zoneName Name of zone for which label will be generated
56  * @return              Generated label
57  */
58 std::string zoneSmackLabelGenerate(const std::string &label, const std::string &zoneName);
59
60 /**
61  * Map @ref hostLabel to @ref zoneLabel using Smack namespaces.
62  *
63  * FIXME This is a placeholder for Vasum API - implement when Smack Namespaces are implemented
64  *
65  * @param[in]  hostLabel Smack label as seen from hosts perspective
66  * @param[in]  zoneName  Zone ID to which label will be mapped
67  * @param[in]  zoneLabel Smack label seen from zone's perspective
68  * @return               True on success, false on failure
69  */
70 bool zoneSmackLabelMap(const std::string &hostLabel, const std::string &zoneName,
71                        const std::string &zoneLabel);
72
73 /**
74  * Unmap label mapped by zoneSmackLabelMap.
75  *
76  * FIXME This is a placeholder for Vasum API - implement when Smack Namespaces are implemented
77  *
78  * @param[in]  hostLabel Label to unmap
79  * @param[in]  zoneName  Zone ID for which unmapping should be done
80  * @return               True on success, false on failure
81  */
82 bool zoneSmackLabelUnmap(const std::string &hostLabel, const std::string &zoneName);
83
84 } //namespace SecurityManager
85
86 #endif //_SECURITY_MANAGER_ZONE_UTILS_H_