Extend AppInstallHelper with checker methods
[platform/core/test/security-tests.git] / src / security-manager-tests / common / sm_commons.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
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 <app_install_helper.h>
27 #include <memory.h>
28 #include <temp_test_user.h>
29
30 DEFINE_SMARTPTR(cap_free, _cap_struct, CapsSetsUniquePtr);
31
32 const int FTW_MAX_FDS = 16;
33
34 int nftw_remove_labels(const char *fpath, const struct stat* /*sb*/,
35                        int /*typeflag*/, struct FTW* /*ftwbuf*/);
36 void check_path(const std::string &path, const std::string &label,
37                 bool transmute = true, bool execute = false);
38
39 CapsSetsUniquePtr setCaps(const char *cap_string);
40
41 void accessTest(const std::string &id, const std::string &testPath, int accessType);
42 void runAccessTest(const std::string &label, uid_t uid, gid_t gid,
43                    const std::string &testPath, int accessType);
44 void runAccessTest(const AppInstallHelper &app, const std::string &testPath, int accessType);
45 void runSystemAccessTest(uid_t uid, gid_t gid, const std::string &testPath, int accessType);
46
47 bool isAskuserDisabled();
48 bool isPrivilegePrivacy(const std::string &priv);
49 int countPrivacyPrivileges(const PrivilegeVector &privs);
50 int countPrivacyPrivileges(const std::vector<std::string> &privs);
51
52 int setLauncherSecurityAttributes(uid_t uid, gid_t gid);
53 int setLauncherSecurityAttributes(TemporaryTestUser &user);