2 * Copyright (c) 2016-2020 Samsung Electronics Co., Ltd. All rights reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #ifndef _SECURITY_MANAGER_TEST_POLICY_CONFIGURATION_
17 #define _SECURITY_MANAGER_TEST_POLICY_CONFIGURATION_
23 #include <sys/types.h>
25 namespace SecurityManagerTest {
27 gid_t nameToGid(const char *name);
29 class PolicyConfiguration {
31 typedef std::vector<gid_t> GidVector;
32 typedef std::vector<std::string> GroupVector;
33 typedef std::vector<std::string> PrivVector;
34 typedef std::map<std::string, std::string> PrivGroupMap;
36 struct UserDescription {
37 PrivVector privVector;
38 GroupVector groupVector;
42 enum UserType { GUEST, NORMAL, ADMIN, SYSTEM };
44 std::string getConfigFilePath(UserType userType);
45 PrivVector getUserPriv(UserType userType);
46 GroupVector getUserGroup(UserType userType);
47 GidVector getUserGid(UserType userType);
49 GroupVector getGroup();
50 UserDescription& getUserDescription(UserType userType);
51 gid_t groupToGid(const std::string &gname);
52 PrivGroupMap getPrivGroupMap();
53 PrivVector getSystemdManagedPrivs();
56 GroupVector privToGroup(const T &privVector);
57 GidVector groupToGid(const GroupVector &groupVector);
59 static bool getIsAskuserEnabled();
60 static std::string getPkgRulesFilePath();
61 static std::string getAppRulesFilePath();
64 UserDescription loadUserDescription(UserType userType);
65 PrivVector loadPrivFile(const std::string &path);
66 void loadPrivGroupMap(void);
68 PrivGroupMap m_privGroupMap;
69 std::map<std::string, gid_t> m_groupGidMap;
70 std::map<UserType, UserDescription> m_userDescriptionMap;
74 PolicyConfiguration::GroupVector PolicyConfiguration::privToGroup(const T &privVector) {
76 if (m_privGroupMap.empty())
78 for (auto &e : privVector) {
79 auto it = m_privGroupMap.find(e);
80 if (it == m_privGroupMap.end())
82 result.push_back(it->second);
88 } // namespace SecurityManagerTest