Fix groups issue in tests using perm_app_set_privilege api.
[platform/core/test/security-tests.git] / tests / libprivilege-control-tests / test_cases_nosmack.cpp
1 /*
2  * Copyright (c) 2012 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
17 /*
18  * @file        test_cases.cpp
19  * @author      Jan Olszak (j.olszak@samsung.com)
20  * @author      Rafal Krypa (r.krypa@samsung.com)
21  * @author      Lukasz Wojciechowski (l.wojciechow@partner.samsung.com)
22  * @version     1.0
23  * @brief       libprivilege-control test runner
24  */
25
26 #include <memory>
27 #include <functional>
28 #include <fstream>
29 #include <set>
30
31 #include <string.h>
32 #include <errno.h>
33 #include <fcntl.h>
34 #include <unistd.h>
35 #include <sys/socket.h>
36 #include <sys/un.h>
37 #include <sys/wait.h>
38
39 #include <dpl/test/test_runner.h>
40 #include <dpl/test/test_runner_multiprocess.h>
41 #include <sys/smack.h>
42 #include <privilege-control.h>
43 #include <tests_common.h>
44 #include <libprivilege-control_test_common.h>
45 #include "common/db.h"
46
47 #define APP_USER_NAME "app"
48 #define APP_HOME_DIR  "/opt/home/app"
49
50
51 #define APP_SET_PRIV_PATH_REAL "/etc/smack/test_privilege_control_DIR/test_set_app_privilege/test_APP_REAL"
52
53
54 /////////////////////////////////////////
55 //////NOSMACK ENVIRONMENT TESTS//////////
56 /////////////////////////////////////////
57
58 /**
59  * NOSMACK version of nftw_check_labels_app_shared_dir function.
60  *
61  * This function used with nftw should expect -1 result from smack_have_access instead of 1.
62  */
63 int nftw_check_labels_app_shared_dir_nosmack(const char *fpath, const struct stat *sb,
64                                              int /*typeflag*/, struct FTW* /*ftwbuf*/)
65 {
66     int result;
67     char* label;
68
69     result = smack_lgetlabel(fpath, &label, SMACK_LABEL_ACCESS);
70     RUNNER_ASSERT_MSG_BT(result == 0, "Could not get label for the path. Result: " << result);
71     RUNNER_ASSERT_MSG_BT(label != NULL, "ACCESS label on " << fpath << " is not set");
72
73     result = strcmp(APPID_SHARED_DIR, label);
74     RUNNER_ASSERT_MSG_BT(result == 0,
75             "ACCESS label on " << fpath << " is incorrect. Result: " << result);
76
77     //The only exception in nftw_check_labels_app_shared_dir
78     //smack_have_access returns -1 because of no SMACK.
79     result = smack_have_access(APP_ID, APPID_SHARED_DIR, "rwxat");
80     RUNNER_ASSERT_MSG_BT(result == -1,
81             "smack_have_access should return error (SMACK is off). Result: " << result);
82
83     result = smack_lgetlabel(fpath, &label, SMACK_LABEL_EXEC);
84     RUNNER_ASSERT_MSG_BT(result == 0, "Could not get label for the path. Result: " << result);
85     RUNNER_ASSERT_MSG_BT(label == NULL, "EXEC label on " << fpath << " is set");
86
87     result = smack_lgetlabel(fpath, &label, SMACK_LABEL_TRANSMUTE);
88     RUNNER_ASSERT_MSG_BT(result == 0, "Could not get label for the path. Result: " << result);
89     if (S_ISDIR(sb->st_mode)) {
90         RUNNER_ASSERT_MSG_BT(label != NULL, "TRANSMUTE label on " << fpath << " is not set");
91         result = strcmp("TRUE", label);
92         RUNNER_ASSERT_MSG_BT(result == 0,
93                 "TRANSMUTE label on " << fpath << " is not set. Result: " << result);
94     } else
95         RUNNER_ASSERT_MSG_BT(label == NULL, "TRANSMUTE label on " << fpath << " is set");
96
97     return 0;
98 }
99
100 RUNNER_TEST_GROUP_INIT(libprivilegecontrol_nosmack)
101
102 /**
103  * NOSMACK version of privilege_control03 test.
104  *
105  * Uses nosmack version of nftw_check_labels_app_shared_dir (defined above).
106  */
107 RUNNER_TEST_NOSMACK(privilege_control03_app_label_shared_dir_nosmack)
108 {
109     int result;
110
111     DB_BEGIN
112
113     result = perm_app_setup_path(APP_ID, TEST_APP_DIR, APP_PATH_GROUP_RW, APP_ID);
114     RUNNER_ASSERT_MSG_BT(result != PC_OPERATION_SUCCESS,
115             "perm_app_setup_path should fail here. Result: " << result);
116
117     DB_END
118
119     result = nftw(TEST_APP_DIR, &nftw_remove_labels, FTW_MAX_FDS, FTW_PHYS);
120     RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS,
121             "Unable to clean up Smack labels in " << TEST_APP_DIR);
122
123     result = nftw(TEST_NON_APP_DIR, &nftw_set_labels_non_app_dir, FTW_MAX_FDS, FTW_PHYS);
124     RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS,
125             "Unable to clean up Smack labels in " << TEST_NON_APP_DIR);
126
127     DB_BEGIN
128
129     result = perm_app_setup_path(APP_ID, TEST_APP_DIR, APP_PATH_GROUP_RW, APPID_SHARED_DIR);
130     RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS,
131             "perm_app_setup_path() failed. Result: " << result);
132
133     DB_END
134
135     result = nftw(TEST_APP_DIR, &nftw_check_labels_app_shared_dir_nosmack, FTW_MAX_FDS, FTW_PHYS);
136     RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS,
137             "Unable to check Smack labels for shared app dir");
138
139     result = nftw(TEST_NON_APP_DIR, &nftw_check_labels_non_app_dir, FTW_MAX_FDS, FTW_PHYS);
140     RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS,
141             "Unable to check Smack labels for non-app dir");
142 }
143
144 /**
145  * NOSMACK version of privilege_control04 test.
146  *
147  * Tries to add permisions from test_privilege_control_rules template and checks if
148  * smack_have_access returns -1 on check between every rule.
149  */
150 RUNNER_TEST_NOSMACK(privilege_control04_add_permissions_nosmack)
151 {
152     int result;
153
154     DB_BEGIN
155
156     result = perm_app_uninstall(APP_ID);
157     RUNNER_ASSERT_MSG_BT(result == 0,
158             "perm_app_uninstall returned " << result << ". Errno: " << strerror(errno));
159
160     result = perm_app_install(APP_ID);
161     RUNNER_ASSERT_MSG_BT(result == 0,
162             "perm_app_install returned " << result << ". Errno: " << strerror(errno));
163
164     //Add permissions
165     result = perm_app_enable_permissions(APP_ID, APP_TYPE_EFL, PRIVS_EFL, true);
166     RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS,
167             "Error adding app permissions. Result: " << result);
168
169     DB_END
170
171     //Check if smack_have_access always fails on every rule
172     result = test_have_nosmack_accesses(rules_efl);
173     RUNNER_ASSERT_MSG_BT(result == -1,
174             "Despite SMACK being off some accesses were added. Result: " << result);
175
176     TestLibPrivilegeControlDatabase db_test;
177     db_test.test_db_after__perm_app_install(APP_ID);
178     db_test.test_db_after__perm_app_enable_permissions(APP_ID, APP_TYPE_EFL, PRIVS_EFL, true);
179
180     DB_BEGIN
181
182     result = perm_app_disable_permissions(APP_ID, APP_TYPE_EFL, PRIVS_EFL);
183     RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS,
184             "Error disabling permissions: " << perm_strerror(result));
185     DB_END
186 }
187
188 void test_set_app_privilege_nosmack(
189                                const char* app_id, app_type_t app_type,
190                                const char** privileges, const char* type,
191                                const char* app_path, const char* dac_file,
192                                const rules_t &rules)
193 {
194     check_app_installed(app_path);
195
196     int result;
197
198     DB_BEGIN
199
200     result = perm_app_uninstall(app_id);
201     RUNNER_ASSERT_MSG_BT(result == 0,
202             "perm_app_uninstall returned " << result << ". Errno: " << strerror(errno));
203
204     result = perm_app_install(app_id);
205     RUNNER_ASSERT_MSG_BT(result == 0,
206             "perm_app_install returned " << result << ". Errno: " << strerror(errno));
207
208     result = perm_app_enable_permissions(app_id, app_type, privileges, 1);
209     RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS,
210             " Error enabling app permissions. Result: " << result);
211
212     DB_END
213
214     result = test_have_nosmack_accesses(rules);
215     RUNNER_ASSERT_MSG_BT(result == -1,
216             " Permissions shouldn't be added. Result: " << result);
217
218     std::set<unsigned> groups_before;
219     read_user_gids(groups_before, APP_UID);
220
221     result = perm_app_set_privilege(app_id, type, app_path);
222     RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS,
223             " Error in perm_app_set_privilege. Error: " << result);
224
225     //Even though app privileges are set, no smack label should be extracted.
226     char* label = NULL;
227     result = smack_new_label_from_self(&label);
228     RUNNER_ASSERT_MSG_BT(result == -1,
229             " new_label_from_self should return error (SMACK is off). Result: " << result);
230     RUNNER_ASSERT_MSG_BT(label == NULL,
231             " new_label_from_self shouldn't allocate memory for label.");
232
233     check_groups(groups_before, dac_file);
234 }
235
236 /**
237  * NOSMACK version of privilege_control05_set_app_privilege test.
238  *
239  * Another very similar test to it's SMACK version, this time smack_new_label_from_self is
240  * expected to return different result.
241  */
242 RUNNER_CHILD_TEST_NOSMACK(privilege_control05_set_app_privilege_nosmack)
243 {
244     int result;
245
246     check_app_installed(APP_SET_PRIV_PATH);
247
248     //Preset exec label
249     smack_lsetlabel(APP_SET_PRIV_PATH_REAL, APP_ID, SMACK_LABEL_EXEC);
250     smack_lsetlabel(APP_SET_PRIV_PATH, APP_ID "_symlink", SMACK_LABEL_EXEC);
251
252     DB_BEGIN
253     perm_app_uninstall(APP_ID);
254     DB_END
255
256     std::set<unsigned> groups_before;
257     read_user_gids(groups_before, APP_UID);
258
259     //Set app privileges
260     result = perm_app_set_privilege(APP_ID, NULL, APP_SET_PRIV_PATH);
261     RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS,
262             "Error in perm_app_set_privilege. Error: " << result);
263
264     //Even though app privileges are set, no smack label should be extracted.
265     char* label = NULL;
266     result = smack_new_label_from_self(&label);
267     RUNNER_ASSERT_MSG_BT(result == -1,
268             "new_label_from_self should return error (SMACK is off). Result: " << result);
269     RUNNER_ASSERT_MSG_BT(label == NULL, "new_label_from_self shouldn't allocate memory for label.");
270
271     //Check if DAC privileges really set
272     RUNNER_ASSERT_MSG_BT(getuid() == APP_UID, "Wrong UID");
273     RUNNER_ASSERT_MSG_BT(getgid() == APP_GID, "Wrong GID");
274
275     result = strcmp(getenv("HOME"), APP_HOME_DIR);
276     RUNNER_ASSERT_MSG_BT(result == 0, "Wrong HOME DIR. Result: " << result);
277
278     result = strcmp(getenv("USER"), APP_USER_NAME);
279     RUNNER_ASSERT_MSG_BT(result == 0, "Wrong user USER NAME. Result: " << result);
280
281     check_groups(groups_before, NULL);
282 }
283
284 /**
285  * NOSMACK version of privilege_control05_set_app_privilege_wgt test.
286  *
287  * Same as the above, plus uses test_have_nosmack_accesses instead of test_have_all_accesses.
288  */
289 RUNNER_CHILD_TEST_NOSMACK(privilege_control05_set_app_privilege_wgt_nosmack)
290 {
291     test_set_app_privilege_nosmack(WGT_APP_ID, APP_TYPE_WGT, PRIVS_WGT, "wgt", WGT_APP_PATH,
292             LIBPRIVILEGE_TEST_DAC_FILE_WGT, rules_wgt);
293 }
294
295 /**
296  * NOSMACK version of privilege_control05_set_app_privilege_osp test.
297  *
298  * Same as the above.
299  */
300 RUNNER_CHILD_TEST_NOSMACK(privilege_control05_set_app_privilege_osp_nosmack)
301 {
302     test_set_app_privilege_nosmack(OSP_APP_ID, APP_TYPE_OSP, PRIVS_OSP, "tpk", OSP_APP_PATH,
303             LIBPRIVILEGE_TEST_DAC_FILE_OSP, rules_osp);
304 }
305
306 RUNNER_CHILD_TEST_NOSMACK(privilege_control05_set_app_privilege_efl_nosmack)
307 {
308     test_set_app_privilege_nosmack(EFL_APP_ID, APP_TYPE_EFL, PRIVS_EFL,
309             "rpm", EFL_APP_PATH,
310             LIBPRIVILEGE_TEST_DAC_FILE_EFL, rules_efl);
311 }
312
313 /**
314  * Revoke permissions from the list. Should be executed as privileged user.
315  */
316 RUNNER_CHILD_TEST_NOSMACK(privilege_control06_revoke_permissions_wgt_nosmack)
317 {
318     test_revoke_permissions(__LINE__, WGT_APP_ID, rules_wgt, false);
319 }
320
321 /**
322  * Revoke permissions from the list. Should be executed as privileged user.
323  */
324 RUNNER_CHILD_TEST_NOSMACK(privilege_control06_revoke_permissions_osp_nosmack)
325 {
326     test_revoke_permissions(__LINE__, OSP_APP_ID, rules_osp, false);
327 }
328
329 /**
330  * NOSMACK version of privilege_control11_app_enable_permissions test.
331  *
332  * Since the original test did the same thing around five times, there is no need to redo the
333  * same test for perm_app_enable_permissions. perm_app_enable_permissions will be called once,
334  * test_have_nosmack_accesses will check if smack_have_access still returns error and then
335  * we will check if SMACK file was correctly created.
336  */
337 RUNNER_TEST_NOSMACK(privilege_control11_app_enable_permissions_nosmack)
338 {
339     int result;
340
341     DB_BEGIN
342
343     result = perm_app_uninstall(WGT_APP_ID);
344     RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS,
345             "perm_app_uninstall returned " << result << ". Errno: " << strerror(errno));
346
347     result = perm_app_install(WGT_APP_ID);
348     RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS,
349             "perm_app_install returned " << result << ". Errno: " << strerror(errno));
350
351     result = perm_app_revoke_permissions(WGT_APP_ID);
352     RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS,
353             "Error revoking app permissions. Result: " << result);
354
355     result = perm_app_enable_permissions(WGT_APP_ID, APP_TYPE_WGT, PRIVS2, 1);
356     RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS,
357             "Error enabling app permissions. Result: " << result);
358
359     DB_END
360
361     //Check if accesses aren't added
362     result = test_have_nosmack_accesses(rules2);
363     RUNNER_ASSERT_MSG_BT(result == -1, "Permissions shouldn't be added. Result: " << result);
364
365     TestLibPrivilegeControlDatabase db_test;
366     db_test.test_db_after__perm_app_install(WGT_APP_ID);
367     db_test.test_db_after__perm_app_enable_permissions(WGT_APP_ID, APP_TYPE_WGT, PRIVS2, true);
368
369     DB_BEGIN
370
371     //Clean up
372     result = perm_app_revoke_permissions(WGT_APP_ID);
373     RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS,
374             "Error revoking app permissions. Result: " << result);
375
376     DB_END
377
378     db_test.test_db_after__perm_app_install(WGT_APP_ID);
379 }
380
381 RUNNER_CHILD_TEST_NOSMACK(privilege_control11_app_enable_permissions_efl_nosmack)
382 {
383     test_app_enable_permissions_efl(false);
384 }
385
386 /*
387  * Check perm_app_install function
388  */
389 RUNNER_CHILD_TEST_NOSMACK(privilege_control12_app_disable_permissions_efl_nosmack)
390 {
391     test_app_disable_permissions_efl(false);
392 }
393
394 /**
395  * Remove previously granted SMACK permissions based on permissions list.
396  */
397 RUNNER_TEST_NOSMACK(privilege_control12_app_disable_permissions_nosmack)
398 {
399     test_app_disable_permissions(false);
400 }
401
402 /**
403  * NOSMACK version of privilege_control13 test.
404  *
405  * Uses perm_app_reset_permissions and checks with test_have_nosmack_accesses if nothing has
406  * changed.
407  */
408 RUNNER_TEST_NOSMACK(privilege_control13_app_reset_permissions_nosmack)
409 {
410     int result;
411
412     DB_BEGIN
413
414     result = perm_app_uninstall(WGT_APP_ID);
415     RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS,
416             "perm_app_uninstall returned " << result << ". Errno: " << strerror(errno));
417
418     result = perm_app_install(WGT_APP_ID);
419     RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS,
420             "perm_app_install returned " << result << ". Errno: " << strerror(errno));
421
422     // Prepare permissions to reset
423     result = perm_app_enable_permissions(WGT_APP_ID, APP_TYPE_WGT, PRIVS2, 1);
424     RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS,
425             " Error adding app permissions. Result: " << result);
426
427     // Reset permissions
428     result = perm_app_reset_permissions(WGT_APP_ID);
429     RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS,
430             "Error reseting app permissions. Result: " << result);
431
432     DB_END
433
434     result = test_have_nosmack_accesses(rules2);
435     RUNNER_ASSERT_MSG_BT(result == -1, "Permissions shouldn't be changed. Result: " << result);
436
437     DB_BEGIN
438
439     // Disable permissions
440     result = perm_app_revoke_permissions(WGT_APP_ID);
441     RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS,
442             "Error disabling app permissions. Result: " << result);
443
444     DB_END
445 }
446
447 /**
448  * NOSMACK version of privilege_control15_app_id_from_socket.
449  *
450  * SMACK version of this test case utilized smack_new_label_from_self and smack_set_label_for_self.
451  * Those functions rely on /proc/self/attr/current file, which is unreadable and has no contents on
452  * NOSMACK environment. Functions mentioned above were tested during libsmack tests, so they are
453  * assumed to react correctly and are not tested in this test case.
454  *
455  * This test works similarly to libsmack test smack09_new_label_from_socket. At first server and
456  * client are created then sockets are set up and perm_app_id_from_socket is used. On NOSMACK env
457  * correct behavior for perm_app_id_from_socket would be returning NULL label.
458  */
459 RUNNER_MULTIPROCESS_TEST_NOSMACK(privilege_control15_app_id_from_socket_nosmack)
460 {
461     int pid;
462     struct sockaddr_un sockaddr = {AF_UNIX, SOCK_PATH};
463
464     //Clean up before creating socket
465     unlink(SOCK_PATH);
466
467     //Create our server and client with fork
468     pid = fork();
469     RUNNER_ASSERT_MSG_BT(pid >= 0, "Fork failed");
470
471     if (!pid) { //child (server)
472         int sock, result, fd;
473
474         //Create a socket
475         sock = socket(AF_UNIX, SOCK_STREAM, 0);
476         RUNNER_ASSERT_MSG_BT(sock >= 0, "socket failed: " << strerror(errno));
477
478         //Bind socket to address
479         result = bind(sock, (struct sockaddr*) &sockaddr, sizeof(struct sockaddr_un));
480         if (result != 0) {
481             close(sock);
482             RUNNER_ASSERT_MSG_BT(false, "bind failed: " << strerror(errno));
483         }
484
485         //Prepare for listening
486         result = listen(sock, 1);
487         if (result != 0) {
488             close(sock);
489             RUNNER_ASSERT_MSG_BT(false, "listen failed: " << strerror(errno));
490         }
491
492         //Accept connection
493         alarm(2);
494         fd = accept(sock, NULL, NULL);
495         alarm(0);
496         RUNNER_ASSERT_MSG_BT(fd >= 0, "accept failed: " << strerror(errno));
497
498         //Wait a little bit for client to use perm_app_id_from_socket
499         usleep(200);
500
501         //cleanup
502         close(sock);
503         exit(0);
504     } else { //parent (client)
505         // Give server some time to setup listening socket
506         sleep(1);
507         int sock, result;
508         char* smack_label = NULL;
509
510         //Create socket
511         sock = socket(AF_UNIX, SOCK_STREAM, 0);
512         RUNNER_ASSERT_MSG_BT(sock >= 0, "socket failed: " << strerror(errno));
513
514         //Try connecting to address
515         result = connect(sock, (struct sockaddr*) &sockaddr, sizeof(struct sockaddr_un));
516         if (result != 0) {
517             close(sock);
518             RUNNER_ASSERT_MSG_BT(0, "connect failed: " << strerror(errno));
519         }
520
521         //Use perm_app_id_from_socket. Should fail and return NULL smack_label.
522         smack_label = perm_app_id_from_socket(sock);
523         if (smack_label != NULL) {
524             close(sock);
525             RUNNER_ASSERT_MSG_BT(0, "perm_app_id_from_socket should fail.");
526         }
527
528         //cleanup
529         close(sock);
530         RUNNER_ASSERT_MSG_BT(smack_label == NULL, "perm_app_id_from_socket should fail.");
531     }
532 }
533
534 RUNNER_TEST_NOSMACK(privilege_control17_appsettings_privilege_nosmack)
535 {
536     test_appsettings_privilege(false);
537 }
538
539 /**
540  * NOSMACK version of privilege_control18 test.
541  *
542  * Uses NOSMACK version of nftw_check_labels_app_public_dir.
543  */
544 RUNNER_TEST_NOSMACK(privilege_control18_app_setup_path_public_nosmack)
545 {
546     int result;
547
548     result = nftw(TEST_APP_DIR, &nftw_remove_labels, FTW_MAX_FDS, FTW_PHYS);
549     RUNNER_ASSERT_MSG_BT(result == 0,
550             "Unable to clean up Smack labels in " << TEST_APP_DIR << ". Result: " << result);
551
552     result = nftw(TEST_NON_APP_DIR, &nftw_set_labels_non_app_dir, FTW_MAX_FDS, FTW_PHYS);
553     RUNNER_ASSERT_MSG_BT(result == 0,
554             "Unable to clean up Smack labels in " << TEST_NON_APP_DIR << ". Result: " << result);
555
556     DB_BEGIN
557
558     result = perm_app_setup_path(APP_ID, TEST_APP_DIR, APP_PATH_PUBLIC_RO);
559     RUNNER_ASSERT_MSG_BT(result == 0, "perm_app_setup_path() failed. Result: " << result);
560
561     DB_END
562
563     result = nftw(TEST_NON_APP_DIR, &nftw_check_labels_non_app_dir, FTW_MAX_FDS, FTW_PHYS);
564     RUNNER_ASSERT_MSG_BT(result == 0,
565             "Unable to check Smack labels for non-app dir. Result: " << result);
566
567 }
568
569 /**
570  * NOSMACK version of privilege_control19 test.
571  *
572  * Uses NOSMACK version of nftw_check_labels_app_settings_dir.
573  */
574 RUNNER_TEST_NOSMACK(privilege_control19_app_setup_path_settings_nosmack)
575 {
576     int result;
577
578     result = nftw(TEST_APP_DIR, &nftw_remove_labels, FTW_MAX_FDS, FTW_PHYS);
579     RUNNER_ASSERT_MSG_BT(result == 0,
580             "Unable to clean up Smack labels in " << TEST_APP_DIR << ". Result: " << result);
581
582     result = nftw(TEST_NON_APP_DIR, &nftw_set_labels_non_app_dir, FTW_MAX_FDS, FTW_PHYS);
583     RUNNER_ASSERT_MSG_BT(result == 0,
584             "Unable to clean up Smack labels in " << TEST_NON_APP_DIR << ". Result: " << result);
585
586     DB_BEGIN
587
588     result = perm_app_setup_path(APP_ID, TEST_APP_DIR, APP_PATH_SETTINGS_RW);
589     RUNNER_ASSERT_MSG_BT(result == 0, "perm_app_setup_path() failed. Result: " << result);
590
591     DB_END
592
593     result = nftw(TEST_NON_APP_DIR, &nftw_check_labels_non_app_dir, FTW_MAX_FDS, FTW_PHYS);
594     RUNNER_ASSERT_MSG_BT(result == 0,
595             "Unable to check Smack labels for non-app dir. Result: " << result);
596
597 }