2 * Copyright (c) 2011 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.
17 * @file installer_task_private_storage.cpp
18 * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
20 * @brief Implementation file for installer task private storage.
22 #include "task_private_storage.h"
27 #include <sys/types.h>
32 #include <dpl/log/log.h>
33 #include <dpl/errno_string.h>
35 #include <dpl/wrt-dao-ro/widget_config.h>
36 #include <dpl/utils/file_utils.h>
37 #include <widget_install/job_widget_install.h>
38 #include <widget_install/widget_install_context.h>
39 #include <widget_install/widget_install_errors.h>
41 #define WEBAPP_DEFAULT_UID 5000
42 #define WEBAPP_DEFAULT_GID 5000
45 const mode_t PRIVATE_STORAGE_MODE = 0700;
49 namespace WidgetInstall {
50 TaskPrivateStorage::TaskPrivateStorage(InstallerContext& context) :
51 DPL::TaskDecl<TaskPrivateStorage>(this),
54 AddStep(&TaskPrivateStorage::StepCreateDirectory);
57 void TaskPrivateStorage::StepCreateDirectory()
59 using namespace WrtDB;
61 LogInfo("Step: Creating private storage directory.");
63 m_context.installStep =
64 InstallerContext::INSTALL_CREATE_PRIVATE_STORAGE;
66 std::ostringstream widgetPath;
67 DPL::OptionalString pkgname = m_context.widgetConfig.pkgname;
68 if(!pkgname.IsNull()) {
69 widgetPath << GlobalConfig::GetUserInstalledWidgetPath() << "/";
70 widgetPath << pkgname << "/";
72 ThrowMsg(Exceptions::InternalError, "No Package name exists.");
75 if (access(widgetPath.str().c_str(), W_OK | X_OK) != 0) {
76 ThrowMsg(Exceptions::InternalError, DPL::GetErrnoString());
79 std::ostringstream storagePath;
80 storagePath << widgetPath.str().c_str()
81 << GlobalConfig::GetWidgetPrivateStoragePath();
83 if (access(storagePath.str().c_str(), F_OK) != 0) {
84 FileUtils::MakePath(storagePath.str(), PRIVATE_STORAGE_MODE);
85 // '5000' is default uid, gid for applications.
86 // So installed applications should be launched as process of uid '5000'.
87 // the process can access private directory 'data' of itself.
88 if(chown(storagePath.str().c_str(),
90 WEBAPP_DEFAULT_GID) != 0)
92 ThrowMsg(Exceptions::InternalError,
93 "Chown to invaild user");
95 } else if (access(storagePath.str().c_str(), W_OK | R_OK | X_OK) == 0) {
96 LogInfo("Private storage already exists.");
97 // Even if private directory already is created, private dircetory
98 // should change owner.
99 if(chown(storagePath.str().c_str(),
101 WEBAPP_DEFAULT_GID) != 0)
103 ThrowMsg(Exceptions::InternalError,
104 "Chown to invaild user");
106 if(chmod(storagePath.str().c_str(), PRIVATE_STORAGE_MODE) != 0) {
107 ThrowMsg(Exceptions::InternalError,
112 ThrowMsg(Exceptions::InternalError,
113 "No access to private storage.");
116 m_context.job->UpdateProgress(
117 InstallerContext::INSTALL_CREATE_PRIVATE_STORAGE,
118 "Private storage created."
121 } //namespace WidgetInstall