2 * Copyright (c) 2012 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.
18 * @file test_cases.cpp
19 * @author Zofia Abramowska (z.abramowska@samsung.com)
21 * @brief libprivilege-control tests commons
24 #ifndef LIBPRIVILEGE_CONTROL_TEST_COMMON_H_
25 #define LIBPRIVILEGE_CONTROL_TEST_COMMON_H_
32 // How many open file descriptors should ftw() function use?
33 #define FTW_MAX_FDS 16
35 #define SOCK_PATH "/tmp/test-smack-socket"
37 #define SMACK_RULES_DIR "/opt/etc/smack-app/accesses.d/"
39 #define TEST_APP_DIR "/etc/smack/test_privilege_control_DIR/app_dir"
40 #define TEST_NON_APP_DIR "/etc/smack/test_privilege_control_DIR/non_app_dir"
42 #define APP_ID "test_APP"
43 #define APPID_DIR "test_APP_ID_dir"
44 #define APPID_SHARED_DIR "test_APP_ID_shared_dir"
46 #define APP_FRIEND_1 "app_friend_1"
47 #define APP_FRIEND_2 "app_friend_2"
49 #define LIBPRIVILEGE_APP_GROUP_LIST "/usr/share/privilege-control/app_group_list"
50 #define LIBPRIVILEGE_TEST_DAC_FILE "/usr/share/privilege-control/test_privilege_control_rules.dac"
51 #define LIBPRIVILEGE_TEST_DAC_FILE_WGT "/usr/share/privilege-control/WRT_test_privilege_control_rules_wgt.dac"
52 #define LIBPRIVILEGE_TEST_DAC_FILE_OSP "/usr/share/privilege-control/OSP_test_privilege_control_rules_osp.dac"
54 #define APP_TEST_APP_1 "test-application1"
55 #define APP_TEST_APP_2 "test-application_2"
56 #define APP_TEST_APP_3 "test-app-3"
57 #define APP_TEST_AV_1 "test-antivirus1"
58 #define APP_TEST_AV_2 "test-antivirus_2"
59 #define APP_TEST_AV_3 "test-av-3"
61 #define WGT_APP_ID "QwCqJ0ttyS"
62 #define WGT_PARTNER_APP_ID "7btsV1Y0sX"
63 #define WGT_PLATFORM_APP_ID "G4DE3U2vmW"
65 #define OSP_APP_ID "uqNfgEjqc7"
66 #define OSP_PARTNER_APP_ID "j4RuPsZrNt"
67 #define OSP_PLATFORM_APP_ID "V5LKqDFBXm"
69 #define WGT_APP_PATH "/opt/usr/apps/QwCqJ0ttyS/bin/QwCqJ0ttyS.TestMisiuPysiu123"
70 #define WGT_PARTNER_APP_PATH "/opt/usr/apps/7btsV1Y0sX/bin/7btsV1Y0sX.MisiuPysiu123Partner"
71 #define WGT_PLATFORM_APP_PATH "/opt/usr/apps/G4DE3U2vmW/bin/G4DE3U2vmW.MisiuPysiu123Platform"
73 #define OSP_APP_PATH "/opt/usr/apps/uqNfgEjqc7/bin/PysiuMisiu123Osp"
74 #define OSP_PARTNER_APP_PATH "/opt/usr/apps/j4RuPsZrNt/bin/PysiuMisiu123OspPartner"
75 #define OSP_PLATFORM_APP_PATH "/opt/usr/apps/V5LKqDFBXm/bin/PysiuMisiu123OspPlatform"
77 #define APP_SET_PRIV_PATH "/etc/smack/test_privilege_control_DIR/test_set_app_privilege/test_APP"
79 //correct and incorrect PID used in incorrect params test
80 const pid_t PID_CORRECT = 0;
81 const pid_t PID_INCORRECT = -1;
83 extern const char *PRIVS[];
84 extern const char *PRIVS2[];
86 extern const char *PRIVS_WGT[];
87 extern const char *PRIVS_OSP[];
89 extern const char* PRIV_APPSETTING[];
91 // Rules from test_privilege_control_rules.smack
92 const std::vector< std::vector<std::string> > rules = {
93 { APP_ID, "test_book_1", "r" },
94 { APP_ID, "test_book_2", "w" },
95 { APP_ID, "test_book_3", "x" },
96 { APP_ID, "test_book_4", "rw" },
97 { APP_ID, "test_book_5", "rx" },
98 { APP_ID, "test_book_6", "wx" },
99 { APP_ID, "test_book_7", "rwx" },
100 { "test_subject_1", APP_ID, "r" },
101 { "test_subject_2", APP_ID, "w" },
102 { "test_subject_3", APP_ID, "x" },
103 { "test_subject_4", APP_ID, "rw" },
104 { "test_subject_5", APP_ID, "rx" },
105 { "test_subject_6", APP_ID, "wx" },
106 { "test_subject_7", APP_ID, "rwx" },
107 { APP_ID, APPID_SHARED_DIR, "rwxat"}
110 // Rules from WRT_test_privilege_control_rules2.smack
111 const std::vector< std::vector<std::string> > rules2 = {
112 { WGT_APP_ID, "test_book_8", "r" },
113 { WGT_APP_ID, "test_book_9", "w" },
114 { WGT_APP_ID, "test_book_10", "x" },
115 { WGT_APP_ID, "test_book_11", "rw" },
116 { WGT_APP_ID, "test_book_12", "rx" },
117 { WGT_APP_ID, "test_book_13", "wx" },
118 { WGT_APP_ID, "test_book_14", "rwx" },
119 { WGT_APP_ID, "test_book_15", "rwxat" },
120 { "test_subject_8", WGT_APP_ID, "r" },
121 { "test_subject_9", WGT_APP_ID, "w" },
122 { "test_subject_10", WGT_APP_ID, "x" },
123 { "test_subject_11", WGT_APP_ID, "rw" },
124 { "test_subject_12", WGT_APP_ID, "rx" },
125 { "test_subject_13", WGT_APP_ID, "wx" },
126 { "test_subject_14", WGT_APP_ID, "rwx" },
127 { "test_subject_15", WGT_APP_ID, "rwxat" }
130 // Rules from WRT_test_privilege_control_rules_no_r.smack
131 const std::vector< std::vector<std::string> > rules2_no_r = {
132 { WGT_APP_ID, "test_book_9", "w" },
133 { WGT_APP_ID, "test_book_10", "x" },
134 { WGT_APP_ID, "test_book_11", "w" },
135 { WGT_APP_ID, "test_book_12", "x" },
136 { WGT_APP_ID, "test_book_13", "x" },
137 { WGT_APP_ID, "test_book_14", "wx" },
138 { WGT_APP_ID, "test_book_15", "wxat" },
139 { "test_subject_9", WGT_APP_ID, "w" },
140 { "test_subject_10", WGT_APP_ID, "x" },
141 { "test_subject_11", WGT_APP_ID, "w" },
142 { "test_subject_12", WGT_APP_ID, "x" },
143 { "test_subject_13", WGT_APP_ID, "x" },
144 { "test_subject_14", WGT_APP_ID, "wx" },
145 { "test_subject_15", WGT_APP_ID, "wxat" }
148 // Rules from test_privilege_control_rules.smack
149 // minus WRT_test_privilege_control_rules_no_r.smack
150 const std::vector< std::vector<std::string> > rules2_r = {
151 { WGT_APP_ID, "test_book_8", "r" },
152 { WGT_APP_ID, "test_book_11", "r" },
153 { WGT_APP_ID, "test_book_12", "r" },
154 { WGT_APP_ID, "test_book_14", "r" },
155 { WGT_APP_ID, "test_book_15", "r" },
156 { "test_subject_8", WGT_APP_ID, "r" },
157 { "test_subject_11", WGT_APP_ID, "r" },
158 { "test_subject_12", WGT_APP_ID, "r" },
159 { "test_subject_14", WGT_APP_ID, "r" },
160 { "test_subject_15", WGT_APP_ID, "r" }
163 // Rules from EFL_test_privilege_control_rules_osp.smack for osp_platform
164 const std::vector< std::vector<std::string> > rules_efl = {
165 { APP_ID, "test_book_efl", "r" }
168 // Rules from WRT_test_privilege_control_rules_wgt.smack for wgt
169 const std::vector< std::vector<std::string> > rules_wgt = {
170 { WGT_APP_ID, "test_book_8", "r" },
171 { WGT_APP_ID, "test_book_9", "w" },
172 { WGT_APP_ID, "test_book_10", "x" },
173 { WGT_APP_ID, "test_book_11", "rw" },
174 { WGT_APP_ID, "test_book_12", "rx" },
175 { WGT_APP_ID, "test_book_13", "wx" },
176 { WGT_APP_ID, "test_book_14", "rwx" },
177 { WGT_APP_ID, "test_book_15", "rwxat" },
178 { "test_subject_8", WGT_APP_ID, "r" },
179 { "test_subject_9", WGT_APP_ID, "w" },
180 { "test_subject_10", WGT_APP_ID, "x" },
181 { "test_subject_11", WGT_APP_ID, "rw" },
182 { "test_subject_12", WGT_APP_ID, "rx" },
183 { "test_subject_13", WGT_APP_ID, "wx" },
184 { "test_subject_14", WGT_APP_ID, "rwx" },
185 { "test_subject_15", WGT_APP_ID, "rwxat" }
188 // Rules from WRT_test_privilege_control_rules.smack for wgt
189 const std::vector< std::vector<std::string> > rules_wgt2 = {
190 { WGT_APP_ID, "test_book_1", "r" },
191 { WGT_APP_ID, "test_book_2", "w" },
192 { WGT_APP_ID, "test_book_3", "x" },
193 { WGT_APP_ID, "test_book_4", "rw" },
194 { WGT_APP_ID, "test_book_5", "rx" },
195 { WGT_APP_ID, "test_book_6", "wx" },
196 { WGT_APP_ID, "test_book_7", "rwx" },
197 { "test_subject_1", WGT_APP_ID, "r" },
198 { "test_subject_2", WGT_APP_ID, "w" },
199 { "test_subject_3", WGT_APP_ID, "x" },
200 { "test_subject_4", WGT_APP_ID, "rw" },
201 { "test_subject_5", WGT_APP_ID, "rx" },
202 { "test_subject_6", WGT_APP_ID, "wx" },
203 { "test_subject_7", WGT_APP_ID, "rwx" }
206 // Rules from WRT_test_privilege_control_rules_wgt.smack for wgt_partner
207 const std::vector< std::vector<std::string> > rules_wgt_partner = {
208 { WGT_PARTNER_APP_ID, "test_book_8", "r" },
209 { WGT_PARTNER_APP_ID, "test_book_9", "w" },
210 { WGT_PARTNER_APP_ID, "test_book_10", "x" },
211 { WGT_PARTNER_APP_ID, "test_book_11", "rw" },
212 { WGT_PARTNER_APP_ID, "test_book_12", "rx" },
213 { WGT_PARTNER_APP_ID, "test_book_13", "wx" },
214 { WGT_PARTNER_APP_ID, "test_book_14", "rwx" },
215 { WGT_PARTNER_APP_ID, "test_book_15", "rwxat" },
216 { "test_subject_8", WGT_PARTNER_APP_ID, "r" },
217 { "test_subject_9", WGT_PARTNER_APP_ID, "w" },
218 { "test_subject_10", WGT_PARTNER_APP_ID, "x" },
219 { "test_subject_11", WGT_PARTNER_APP_ID, "rw" },
220 { "test_subject_12", WGT_PARTNER_APP_ID, "rx" },
221 { "test_subject_13", WGT_PARTNER_APP_ID, "wx" },
222 { "test_subject_14", WGT_PARTNER_APP_ID, "rwx" },
223 { "test_subject_15", WGT_PARTNER_APP_ID, "rwxat" }
226 // Rules from WRT_test_privilege_control_rules_wgt.smack for wgt_platform
227 const std::vector< std::vector<std::string> > rules_wgt_platform = {
228 { WGT_PLATFORM_APP_ID, "test_book_8", "r" },
229 { WGT_PLATFORM_APP_ID, "test_book_9", "w" },
230 { WGT_PLATFORM_APP_ID, "test_book_10", "x" },
231 { WGT_PLATFORM_APP_ID, "test_book_11", "rw" },
232 { WGT_PLATFORM_APP_ID, "test_book_12", "rx" },
233 { WGT_PLATFORM_APP_ID, "test_book_13", "wx" },
234 { WGT_PLATFORM_APP_ID, "test_book_14", "rwx" },
235 { WGT_PLATFORM_APP_ID, "test_book_15", "rwxat" },
236 { "test_subject_8", WGT_PLATFORM_APP_ID, "r" },
237 { "test_subject_9", WGT_PLATFORM_APP_ID, "w" },
238 { "test_subject_10", WGT_PLATFORM_APP_ID, "x" },
239 { "test_subject_11", WGT_PLATFORM_APP_ID, "rw" },
240 { "test_subject_12", WGT_PLATFORM_APP_ID, "rx" },
241 { "test_subject_13", WGT_PLATFORM_APP_ID, "wx" },
242 { "test_subject_14", WGT_PLATFORM_APP_ID, "rwx" },
243 { "test_subject_15", WGT_PLATFORM_APP_ID, "rwxat" }
246 // Rules from OSP_test_privilege_control_rules_osp.smack for osp
247 const std::vector< std::vector<std::string> > rules_osp = {
248 { OSP_APP_ID, "test_book_8", "r" },
249 { OSP_APP_ID, "test_book_9", "w" },
250 { OSP_APP_ID, "test_book_10", "x" },
251 { OSP_APP_ID, "test_book_11", "rw" },
252 { OSP_APP_ID, "test_book_12", "rx" },
253 { OSP_APP_ID, "test_book_13", "wx" },
254 { OSP_APP_ID, "test_book_14", "rwx" },
255 { OSP_APP_ID, "test_book_15", "rwxat" },
256 { "test_subject_8", OSP_APP_ID, "r" },
257 { "test_subject_9", OSP_APP_ID, "w" },
258 { "test_subject_10", OSP_APP_ID, "x" },
259 { "test_subject_11", OSP_APP_ID, "rw" },
260 { "test_subject_12", OSP_APP_ID, "rx" },
261 { "test_subject_13", OSP_APP_ID, "wx" },
262 { "test_subject_14", OSP_APP_ID, "rwx" },
263 { "test_subject_15", OSP_APP_ID, "rwxat" }
266 // Rules from OSP_test_privilege_control_rules_osp.smack for osp_partner
267 const std::vector< std::vector<std::string> > rules_osp_partner = {
268 { OSP_PARTNER_APP_ID, "test_book_8", "r" },
269 { OSP_PARTNER_APP_ID, "test_book_9", "w" },
270 { OSP_PARTNER_APP_ID, "test_book_10", "x" },
271 { OSP_PARTNER_APP_ID, "test_book_11", "rw" },
272 { OSP_PARTNER_APP_ID, "test_book_12", "rx" },
273 { OSP_PARTNER_APP_ID, "test_book_13", "wx" },
274 { OSP_PARTNER_APP_ID, "test_book_14", "rwx" },
275 { OSP_PARTNER_APP_ID, "test_book_15", "rwxat" },
276 { "test_subject_8", OSP_PARTNER_APP_ID, "r" },
277 { "test_subject_9", OSP_PARTNER_APP_ID, "w" },
278 { "test_subject_10", OSP_PARTNER_APP_ID, "x" },
279 { "test_subject_11", OSP_PARTNER_APP_ID, "rw" },
280 { "test_subject_12", OSP_PARTNER_APP_ID, "rx" },
281 { "test_subject_13", OSP_PARTNER_APP_ID, "wx" },
282 { "test_subject_14", OSP_PARTNER_APP_ID, "rwx" },
283 { "test_subject_15", OSP_PARTNER_APP_ID, "rwxat" }
286 // Rules from OSP_test_privilege_control_rules_osp.smack for osp_platform
287 const std::vector< std::vector<std::string> > rules_osp_platform = {
288 { OSP_PLATFORM_APP_ID, "test_book_8", "r" },
289 { OSP_PLATFORM_APP_ID, "test_book_9", "w" },
290 { OSP_PLATFORM_APP_ID, "test_book_10", "x" },
291 { OSP_PLATFORM_APP_ID, "test_book_11", "rw" },
292 { OSP_PLATFORM_APP_ID, "test_book_12", "rx" },
293 { OSP_PLATFORM_APP_ID, "test_book_13", "wx" },
294 { OSP_PLATFORM_APP_ID, "test_book_14", "rwx" },
295 { OSP_PLATFORM_APP_ID, "test_book_15", "rwxat" },
296 { "test_subject_8", OSP_PLATFORM_APP_ID, "r" },
297 { "test_subject_9", OSP_PLATFORM_APP_ID, "w" },
298 { "test_subject_10", OSP_PLATFORM_APP_ID, "x" },
299 { "test_subject_11", OSP_PLATFORM_APP_ID, "rw" },
300 { "test_subject_12", OSP_PLATFORM_APP_ID, "rx" },
301 { "test_subject_13", OSP_PLATFORM_APP_ID, "wx" },
302 { "test_subject_14", OSP_PLATFORM_APP_ID, "rwx" },
303 { "test_subject_15", OSP_PLATFORM_APP_ID, "rwxat" }
306 int test_have_all_accesses(const std::vector< std::vector<std::string> > &rules);
307 int test_have_any_accesses(const std::vector< std::vector<std::string> > &rules);
309 void cleaning_smack_app_files (void);
311 void read_gids(std::set<unsigned> &set, const char *file_path);
312 void check_groups(const char *dac_file);
314 int nftw_remove_labels(const char *fpath, const struct stat* /*sb*/,
315 int /*typeflag*/, struct FTW* /*ftwbuf*/);
316 int nftw_check_labels_app_dir(const char *fpath, const struct stat *sb,
317 int /*typeflag*/, struct FTW* /*ftwbuf*/);
318 int nftw_set_labels_non_app_dir(const char *fpath, const struct stat* /*sb*/,
319 int /*typeflag*/, struct FTW* /*ftwbuf*/);
320 int nftw_check_labels_non_app_dir(const char *fpath, const struct stat* /*sb*/,
321 int /*typeflag*/, struct FTW* /*ftwbuf*/);
324 #endif /* LIBPRIVILEGE_CONTROL_TEST_COMMON_H_ */