2 * Copyright (c) 2014-2019 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.
20 #include <sys/types.h>
28 #include <security-manager-types.h>
29 #include <app_def_privilege.h>
31 struct AppInstallHelper {
33 using TypePathsMap = std::map<app_install_path_type, std::vector<std::string>>;
34 using TypePathMap = std::map<app_install_path_type, std::string>;
36 AppInstallHelper(const std::string &appNamePrefix,
37 const std::string &pkgNamePrefix,
40 std::string version = std::string())
41 : m_appName(appNamePrefix + "_app_id"), m_pkgName(pkgNamePrefix + "_pkg_id"), m_isLocal(isLocal), m_uidGid(uid), m_version(version),
42 m_installType(SM_APP_INSTALL_NONE), m_isHybrid(false), m_creatorPid(getpid())
45 AppInstallHelper(const std::string &appNamePrefix,
46 const std::string &pkgNamePrefix,
48 : AppInstallHelper(appNamePrefix, pkgNamePrefix, false, uid)
51 AppInstallHelper(const std::string &namePrefix)
52 : AppInstallHelper(namePrefix, namePrefix, false, geteuid())
55 AppInstallHelper(const std::string &appNamePrefix, const std::string &pkgNamePrefix)
56 : AppInstallHelper(appNamePrefix, pkgNamePrefix, false, geteuid())
59 AppInstallHelper(const std::string &namePrefix, uid_t uid)
60 : AppInstallHelper(namePrefix, namePrefix, true, uid)
63 AppInstallHelper(const std::string &appNamePrefix, const std::string &pkgNamePrefix, uid_t uid,
64 const std::string &version)
65 : AppInstallHelper(appNamePrefix, pkgNamePrefix, true, uid, version)
68 AppInstallHelper(const std::string &namePrefix, uid_t uid, const std::string &version)
69 : AppInstallHelper(namePrefix, namePrefix, true, uid, version)
72 AppInstallHelper(const AppInstallHelper &other) = default;
73 AppInstallHelper& operator=(const AppInstallHelper &other) = delete;
74 AppInstallHelper(AppInstallHelper &&other);
76 // App info getters and setters
77 const std::string& getAppId() const;
78 const std::string& getPkgId() const;
81 void setVersion(const std::string &version);
82 std::string getVersion() const;
83 void setAuthor(const std::string &author);
84 std::string getAuthor() const;
85 void setInstallType(app_install_type type);
86 app_install_type getInstallType() const;
88 bool getIsHybrid() const;
103 // Path types creation and removal on file system
104 void createPath(app_install_path_type smType, PathType pType, int i = 0, RootType rType = RootType::BASE);
106 // below methods are deprecated
107 void createTrustedDir(int i = 0, RootType type = RootType::BASE);
108 void createPrivateDir(int i = 0, RootType type = RootType::BASE);
109 void createPublicDir(RootType type = RootType::BASE);
110 void createPrivateFile(int i = 0, RootType type = RootType::BASE);
111 void createSharedRODir(int i = 0, RootType type = RootType::BASE);
112 void createSharedROFile(int i = 0, RootType type = RootType::BASE);
113 void createPrivateRODir(int i = 0, RootType type = RootType::BASE);
117 std::string getPath(app_install_path_type smType, PathType pType, int i = 0, RootType rType = RootType::BASE) const;
119 // below methods are deprecated
120 std::string getInstallDir(RootType type) const;
121 std::string getTrustedDir(int i = 0, RootType type = RootType::BASE) const;
122 std::string getPrivateDir(int i = 0, RootType type = RootType::BASE) const;
123 std::string getPrivateRODir(int i = 0, RootType type = RootType::BASE) const;
124 std::string getPublicDir(RootType type = RootType::BASE) const;
125 std::string getPrivatePath(int i = 0, RootType type = RootType::BASE) const;
126 std::string getSharedRODir(int i = 0, RootType type = RootType::BASE) const;
127 std::string getSharedROPath(int i = 0, RootType type = RootType::BASE) const;
128 const TypePathsMap& getDirsMap() const;
129 const TypePathsMap& getFilesMap() const;
132 std::vector<std::string> getPrivilegesNames() const; // deprecated
133 void addPrivileges(const std::vector<std::string> &privileges); // deprecated
134 void addPrivilege(Privilege privilege);
135 void addPrivileges(const PrivilegeVector &privileges);
136 const PrivilegeVector& getPrivileges() const;
138 void addAppDefinedPrivilege(Privilege privilege);
139 const PrivilegeVector& getAppDefinedPrivileges() const;
142 std::string generateAppLabel() const;
143 std::string generatePkgLabel() const;
144 void revokeRules() const;
145 virtual ~AppInstallHelper() {
146 if (m_creatorPid == getpid())
152 RootInfo() : isCreated(false) {}
156 using RootTypeInfoMap = std::map<RootType, RootInfo>;
158 void setInstallPath(RootType type) const;
160 bool createFile(app_install_path_type smType, const std::string &path);
161 bool createDir(app_install_path_type smType, const std::string &path, bool isBasePath = false);
162 void createDirLink(app_install_path_type smType, const std::string &dest, int i = 0,
163 RootType rType = RootType::BASE);
164 void createInstallDir(RootType type);
166 const std::string m_appName;
167 const std::string m_pkgName;
170 std::string m_version;
171 app_install_type m_installType;
174 mutable RootTypeInfoMap m_rootPaths;
175 TypePathsMap m_dirTypeMap;
176 TypePathsMap m_fileTypeMap;
178 PrivilegeVector m_privileges;
179 PrivilegeVector m_appDefinedPrivileges;
181 std::string m_author;