2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
18 * @file PermissionManager.cpp
19 * @brief This is the implementation file for %PermissionManager class.
25 #include <unique_ptr.h>
27 #include <FBaseUtilStringUtil.h>
29 #include <FIoDirectory.h>
30 #include <FBase_StringConverter.h>
31 #include <FIo_FileImpl.h>
33 #include "PermissionManager.h"
34 #include "InstallerUtil.h"
35 #include "SmackManager.h"
37 using namespace Tizen::Base;
38 using namespace Tizen::Base::Collection;
39 using namespace Tizen::Base::Utility;
40 using namespace Tizen::Io;
41 using namespace Tizen::App;
43 PermissionManager::PermissionManager(void)
47 PermissionManager::~PermissionManager(void)
52 PermissionManager::SetDirectory(InstallationContext* pContext)
58 SmackManager smackManager;
59 smackManager.Construct(pContext);
61 appRootPath = pContext->__rootPath;
62 PackageId packageId = pContext->__packageId;
65 // InstallerUtil::ChangeOwner(appRootPath);
66 InstallerUtil::ChangeMode(appRootPath, PERM_BASE | PERM_EXECUTE);
67 smackManager.AddLabelDir(packageId, appRootPath, true);
70 destPath = appRootPath + DIR_BIN;
71 InstallerUtil::ChangeDirectoryPermission(destPath, PERM_BASE | PERM_EXECUTE, false);
72 smackManager.AddLabelDir(packageId, destPath);
75 destPath = appRootPath + DIR_INFO;
76 InstallerUtil::ChangeDirectoryPermission(destPath, PERM_BASE, false);
77 smackManager.AddLabelDir(packageId, destPath);
80 destPath = appRootPath + DIR_RES;
81 InstallerUtil::ChangeDirectoryPermission(destPath, PERM_BASE, false);
82 smackManager.AddLabelDir(packageId, destPath);
85 destPath = appRootPath + DIR_LIB;
86 InstallerUtil::ChangeDirectoryPermission(destPath, PERM_BASE | PERM_EXECUTE, false);
87 smackManager.AddLabelDir(packageId, destPath);
90 destPath = appRootPath + DIR_SHARED;
91 if (File::IsFileExist(destPath) == false)
93 r = Directory::Create(destPath, false);
94 TryReturn(!IsFailed(r), INSTALLER_ERROR_INTERNAL_STATE, "Directory::Create() failed");
96 InstallerUtil::ChangeDirectoryPermission(destPath, PERM_BASE, false);
97 smackManager.AddLabelDir(packageId, destPath);
100 destPath = appRootPath + DIR_SHARED_RES;
101 if (File::IsFileExist(destPath) == false)
103 String iconPath = appRootPath + DIR_ICONS;
104 InstallerUtil::CreateSymlink(iconPath, destPath);
106 InstallerUtil::ChangeDirectoryPermission(destPath, PERM_BASE, false);
107 smackManager.AddLabelSharedDir(packageId, destPath);
109 // appRoot/shared/data
110 destPath = appRootPath + DIR_SHARED_DATA;
111 InstallerUtil::ChangeDirectoryPermission(destPath, PERM_BASE, true);
112 smackManager.AddLabelSharedDir(packageId, destPath);
114 // appRoot/shared/trusted
115 destPath = appRootPath + DIR_SHARED_TRUSTED;
116 InstallerUtil::ChangeDirectoryPermission(destPath, PERM_BASE, true);
117 smackManager.AddLabelSharedDir(packageId, destPath);
120 destPath = appRootPath + DIR_CONTENTS;
121 InstallerUtil::ChangeDirectoryPermission(destPath, PERM_BASE, false);
122 smackManager.AddLabelDir(packageId, destPath);
125 destPath = appRootPath + DIR_SETTING;
126 if (pContext->__isAppSetting == true)
128 String appVersion = pContext->__version;
130 String settingXmlPath;
132 srcPath = destPath + L"/setting." + appVersion + L".xml";
133 settingXmlPath = destPath + L"/setting.xml";
135 InstallerUtil::Remove(settingXmlPath);
136 InstallerUtil::CreateSymlink(srcPath, settingXmlPath);
138 InstallerUtil::ChangeDirectoryPermission(destPath, PERM_BASE | PERM_WRITE, false);
139 smackManager.AddLabelDir(packageId, destPath);
143 destPath = appRootPath + DIR_DATA;
144 if (File::IsFileExist(destPath) == false)
146 r = Directory::Create(destPath, false);
147 TryReturn(!IsFailed(r), INSTALLER_ERROR_INTERNAL_STATE, "Directory::Create() failed");
149 InstallerUtil::ChangeDirectoryPermission(destPath, PERM_BASE, true);
150 smackManager.AddLabelDir(packageId, destPath);
152 String apiVersion = pContext->__apiVersion;
154 AppLog("------------------------------------------");
155 AppLog("[Tizen::Io] # path = [%ls]", appRootPath.GetPointer());
156 AppLog("[Tizen::Io] # packageId = [%ls]", packageId.GetPointer());
157 AppLog("[Tizen::Io] # apiVersion = [%ls]", apiVersion.GetPointer());
159 if (pContext->__isOspCompat == true)
161 AppLog("[Tizen::Io] OSP 2.0 application");
163 if (_FileImpl::PrepareDataCaging(appRootPath, packageId) == false)
165 AppLog("[Tizen::Io] _FileImpl::PrepareDataCaging() failed");
169 SetSymLink(pContext);
173 AppLog("[Tizen::Io] apiVersion is equal to or greater than Tizen 2.0");
175 if (_FileImpl::CreateOspApplicationDirectories(appRootPath, packageId) == false)
177 AppLog("[Tizen::Io] _FileImpl::CreateOspApplicationDirectories() failed");
181 AppLog("------------------------------------------");
187 PermissionManager::SetFile(InstallationContext* pContext)
190 String appRootPath = pContext->__rootPath;
192 IListT<AppData*>* pAppDataList = pContext->__pAppDataList;
193 TryReturn(pAppDataList, false, "pAppDataList is null");
195 for (int i = 0 ; i < pAppDataList->GetCount(); i++)
197 AppData* pAppData = null;
198 pAppDataList->GetAt(i, pAppData);
199 TryReturn(pAppData, false, "pAppData is null");
201 // set permission(755) to bin file.
202 destPath = appRootPath + DIR_BIN + L"/" + pAppData->__name + L".exe";
203 if (File::IsFileExist(destPath) == true)
205 InstallerUtil::ChangeMode(destPath, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
213 PermissionManager::SetSymLink(InstallationContext* pContext)
217 String appRootPath = pContext->__rootPath;
220 oldPath = appRootPath + DIR_RES;
221 newPath = appRootPath + L"/Res";
222 InstallerUtil::CreateSymlink(oldPath, newPath);
224 newPath = appRootPath + L"/Res";
225 std::unique_ptr< char[] > pResPath(_StringConverter::CopyToCharArrayN(newPath));
226 int ret = symlink("./res", pResPath.get());
230 oldPath = appRootPath + DIR_DATA;
231 newPath = appRootPath + L"/Home";
232 InstallerUtil::CreateSymlink(oldPath, newPath);
234 newPath = appRootPath + L"/Home";
235 std::unique_ptr< char[] > pHomePath(_StringConverter::CopyToCharArrayN(newPath));
236 ret = symlink("./data", pHomePath.get());
239 oldPath = appRootPath + DIR_RES + L"/screen-size-normal";
240 newPath = appRootPath + L"/Res/ScreenSize-Normal";
241 InstallerUtil::CreateSymlink(oldPath, newPath);
243 oldPath = appRootPath + DIR_RES + L"/screen-density-high";
244 newPath = appRootPath + L"/Res/ScreenDensity-High";
245 InstallerUtil::CreateSymlink(oldPath, newPath);
247 oldPath = appRootPath + DIR_RES + L"/screen-density-middle";
248 newPath = appRootPath + L"/Res/ScreenDensity-Middle";
249 InstallerUtil::CreateSymlink(oldPath, newPath);
251 oldPath = appRootPath + DIR_RES + L"/screen-density-low";
252 newPath = appRootPath + L"/Res/ScreenDensity-Low";
253 InstallerUtil::CreateSymlink(oldPath, newPath);