SM: Use TzPlatformConfig for global app dir
[platform/core/test/security-tests.git] / src / security-manager-tests / common / sm_commons.h
1 /*
2  * Copyright (c) 2016 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 #pragma once
18
19 #include <ftw.h>
20 #include <string>
21 #include <sys/capability.h>
22 #include <sys/stat.h>
23 #include <sys/types.h>
24 #include <vector>
25
26 #include <security-manager-types.h>
27
28 #include <app_install_helper.h>
29 #include <memory.h>
30 #include <sm_db.h>
31 #include <temp_test_user.h>
32 #include <tzplatform.h>
33
34 DEFINE_SMARTPTR(cap_free, _cap_struct, CapsSetsUniquePtr);
35
36 struct app_attributes {
37     std::string package;
38     std::string Tizen_ver;
39 };
40
41 const int FTW_MAX_FDS = 16;
42
43 extern const privileges_t SM_ALLOWED_PRIVILEGES;
44 extern const privileges_t SM_DENIED_PRIVILEGES;
45 extern const privileges_t SM_NO_PRIVILEGES;
46 extern const std::vector<std::string> SM_ALLOWED_GROUPS;
47 const std::string SM_RW_PATH =
48         TzPlatformConfig::globalAppDir() + "/sm_test_02_pkg_id_full/app_dir";
49
50 const std::string uidToStr(const uid_t uid);
51
52 std::string generateAppLabel(const std::string &appId);
53 std::string generatePkgLabel(const std::string &pkgId);
54 std::string genRWPath(int app_num);
55 std::string genROPath(int app_num);
56 std::string genPublicROPath(int app_num);
57 std::string genOwnerRWOthersROPath(int app_num);
58
59 int nftw_remove_labels(const char *fpath, const struct stat* /*sb*/,
60                        int /*typeflag*/, struct FTW* /*ftwbuf*/);
61 void check_app_permissions(const char *const app_id, const char *const pkg_id,
62                            const char *const user, const privileges_t &allowed_privs,
63                            const privileges_t &denied_privs);
64 void check_app_after_install(const char *const app_id, const char *const pkg_id);
65 void check_app_after_install(const char *const app_id, const char *const pkg_id,
66                              const privileges_t &allowed_privs,
67                              const privileges_t &denied_privs,
68                              const std::vector<std::string> &allowed_groups);
69 void check_path(const std::string &path, const std::string &label);
70 void check_app_path_after_install(int app_num, const char *pkgId, bool others_enabled=false);
71 void check_app_after_uninstall(const char *const app_id, const char *const pkg_id,
72                                const bool is_pkg_removed);
73 void check_app_after_uninstall(const char *const app_id, const char *const pkg_id,
74                                const privileges_t &privileges, const bool is_pkg_removed);
75
76 std::string access_opposite(std::string &access);
77 void check_exact_smack_accesses(const std::string &subject,
78                                 const std::string &object,
79                                 const std::string &access);
80
81 CapsSetsUniquePtr setCaps(const char *cap_string);
82 void prepare_app_env(int app_num, bool others_enabled = false);
83 void install_app(const char *app_id, const char *pkg_id, uid_t uid = 0,
84                  app_install_type type = SM_APP_INSTALL_NONE, bool check_after = true);
85 void uninstall_app(const char *app_id, const char *pkg_id,
86                    bool expect_pkg_removed = false, app_install_type type = SM_APP_INSTALL_NONE,
87                    bool check_after = true);
88
89 void createTestDirs(const TemporaryTestUser &user,
90                     const std::string &appId, const std::string &pkgId);
91 void removeTestDirs(const TemporaryTestUser &user,
92                     const std::string &appId, const std::string &pkgId);