Fix nss tests
[platform/core/test/security-tests.git] / src / security-manager-tests / common / policy_configuration.h
1 /*
2  * Copyright (c) 2016-2020 Samsung Electronics Co., Ltd. All rights reserved
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 #ifndef _SECURITY_MANAGER_TEST_POLICY_CONFIGURATION_
17 #define _SECURITY_MANAGER_TEST_POLICY_CONFIGURATION_
18
19 #include <map>
20 #include <string>
21 #include <vector>
22
23 #include <sys/types.h>
24
25 namespace SecurityManagerTest {
26
27 gid_t nameToGid(const char *name);
28
29 class PolicyConfiguration {
30 public:
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;
35
36     struct UserDescription {
37         PrivVector privVector;
38         GroupVector groupVector;
39         GidVector gidVector;
40     };
41
42     enum UserType { GUEST, NORMAL, ADMIN, SYSTEM };
43
44     std::string getConfigFilePath(UserType userType);
45     PrivVector getUserPriv(UserType userType);
46     GroupVector getUserGroup(UserType userType);
47     GidVector getUserGid(UserType userType);
48     GidVector getGid();
49     GroupVector getGroup();
50     UserDescription& getUserDescription(UserType userType);
51     gid_t groupToGid(const std::string &gname);
52     PrivGroupMap getPrivGroupMap();
53     PrivVector getSystemdManagedPrivs();
54     GroupVector privToGroup(const PrivVector &privVector);
55     GidVector groupToGid(const GroupVector &groupVector);
56
57 static bool getIsAskuserEnabled();
58
59 private:
60     UserDescription loadUserDescription(UserType userType);
61     PrivVector loadPrivFile(const std::string &path);
62     void loadPrivGroupMap(void);
63
64     PrivGroupMap m_privGroupMap;
65     std::map<std::string, gid_t> m_groupGidMap;
66     std::map<UserType, UserDescription> m_userDescriptionMap;
67 };
68
69 } // namespace SecurityManagerTest
70
71 #endif