2 * Copyright (c) 2016 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.
21 #include <sys/capability.h>
23 #include <sys/types.h>
28 #include <security-manager-types.h>
32 #include <temp_test_user.h>
33 #include <tzplatform.h>
35 DEFINE_SMARTPTR(cap_free, _cap_struct, CapsSetsUniquePtr);
37 struct app_attributes {
39 std::string Tizen_ver;
42 const int FTW_MAX_FDS = 16;
44 extern const privileges_t SM_ALLOWED_PRIVILEGES;
45 extern const privileges_t SM_DENIED_PRIVILEGES;
46 extern const privileges_t SM_NO_PRIVILEGES;
47 extern const std::vector<std::string> SM_ALLOWED_GROUPS;
48 const std::string SM_RW_PATH =
49 TzPlatformConfig::globalAppDir() + "/sm_test_02_pkg_id_full/app_dir";
51 const std::string uidToStr(const uid_t uid);
53 std::string generateProcessLabel(const std::string &appId, const std::string &pkgId, bool isHybrid = false);
54 std::string generatePathRWLabel(const std::string &pkgId);
55 std::string generatePathROLabel(const std::string &pkgId);
56 std::string getPublicPathLabel();
57 std::string genRWPath(int app_num);
58 std::string genROPath(int app_num);
59 std::string genPublicROPath(int app_num);
60 std::string genOwnerRWOthersROPath(int app_num);
62 int nftw_remove_labels(const char *fpath, const struct stat* /*sb*/,
63 int /*typeflag*/, struct FTW* /*ftwbuf*/);
64 void check_app_permissions(const std::string &app_id, const std::string &pkg_id,
65 const std::string &user, const privileges_t &allowed_privs,
66 const privileges_t &denied_privs, bool isHybrid = false);
67 void check_app_after_install(const std::string &app_id, const std::string &pkg_id);
68 void check_app_after_install(const std::string &app_id, const std::string &pkg_id,
69 const privileges_t &allowed_privs,
70 const privileges_t &denied_privs,
71 const std::vector<std::string> &allowed_groups,
72 bool isHybrid = false);
73 void check_path(const std::string &path, const std::string &label,
74 bool transmute = true, bool execute = false);
75 void check_app_path_after_install(int app_num, const char *pkgId, bool others_enabled=false);
76 void check_app_after_uninstall(const std::string &app_id, const std::string &pkg_id,
77 const bool is_pkg_removed);
78 void check_app_after_uninstall(const std::string &app_id, const std::string &pkg_id,
79 const privileges_t &privileges, const bool is_pkg_removed,
80 bool isHybrid = false);
82 std::string access_opposite(std::string &access);
83 void check_exact_smack_accesses(const std::string &subject,
84 const std::string &object,
85 const std::string &access);
87 CapsSetsUniquePtr setCaps(const char *cap_string);
88 void prepare_app_env(int app_num, bool others_enabled = false);
89 void install_app(const std::string &app_id, const std::string &pkg_id, uid_t uid = 0,
90 app_install_type type = SM_APP_INSTALL_NONE, bool check_after = true);
91 void uninstall_app(const std::string &app_id, const std::string &pkg_id,
92 bool expect_pkg_removed = false, app_install_type type = SM_APP_INSTALL_NONE,
93 bool check_after = true);
95 void createTestDirs(const TemporaryTestUser &user,
96 const std::string &appId, const std::string &pkgId);
97 void removeTestDirs(const TemporaryTestUser &user,
98 const std::string &appId, const std::string &pkgId);
100 pid_t runInChild(const std::function<void(void)> &process);
102 void runInChildParentWait(const std::function<void(void)> &process);