2 * Copyright (c) 2014-2017 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 AppInstallHelper(const std::string &appNamePrefix,
35 const std::string &pkgNamePrefix,
38 std::string version = std::string())
39 : m_appName(appNamePrefix), m_pkgName(pkgNamePrefix), m_isLocal(isLocal), m_uidGid(uid), m_version(version),
40 m_installType(SM_APP_INSTALL_NONE), m_isHybrid(false), m_isInstallDirCreated(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 std::string getAppId() const;
78 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;
90 // Path types creation and removal on file system
91 void createInstallDir();
92 void createTrustedDir(int i = 0);
93 void createPrivateDir(int i = 0);
94 void createPublicDir();
95 void createPrivateFile(int i = 0);
96 void createSharedRODir(int i = 0);
97 void createPrivateRODir(int i = 0);
101 std::string getInstallDir() const;
102 std::string getTrustedDir(int i = 0) const;
103 std::string getPrivateDir(int i = 0) const;
104 std::string getPrivateRODir(int i = 0) const;
105 std::string getPublicDir() const;
106 std::string getPrivatePath(int i = 0) const;
107 std::string getSharedRODir(int i = 0) const;
108 const TypePathsMap& getDirsMap() const;
109 const TypePathsMap& getFilesMap() const;
112 void addPrivilege(const std::string &privilege);
113 void addPrivileges(const std::vector<std::string> &privileges);
114 std::vector<std::string> getPrivileges() const;
116 void addClientPrivilege(const std::pair<std::string, std::string> &privilege);
117 std::vector<std::pair<std::string, std::string>> getClientPrivileges() const;
119 void addAppDefinedPrivilege(const AppDefinedPrivilege &privilege);
120 AppDefinedPrivilegesVector getAppDefinedPrivileges() const;
123 std::string generateAppLabel() const;
124 std::string generatePkgLabel() const;
125 void revokeRules() const;
126 virtual ~AppInstallHelper() {
127 if (m_creatorPid == getpid())
132 void setInstallPath();
133 bool create(std::function<int(const char*, mode_t)> &&creatFun, const std::string &path);
134 std::string m_appName;
135 std::string m_pkgName;
138 std::string m_version;
139 app_install_type m_installType;
141 std::string m_installDir;
142 bool m_isInstallDirCreated;
143 TypePathsMap m_dirTypeMap;
144 TypePathsMap m_fileTypeMap;
145 std::vector<std::pair<std::string, std::string>> m_privileges;
146 AppDefinedPrivilegesVector m_appDefinedPrivileges;
147 std::string m_author;