/* * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * @file installer_task_private_storage.cpp * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com) * @version 1.0 * @brief Implementation file for installer task private storage. */ #include "task_private_storage.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define WEBAPP_DEFAULT_UID 5000 #define WEBAPP_DEFAULT_GID 5000 namespace { const mode_t PRIVATE_STORAGE_MODE = 0700; } namespace Jobs { namespace WidgetInstall { TaskPrivateStorage::TaskPrivateStorage(InstallerContext& context) : DPL::TaskDecl(this), m_context(context) { AddStep(&TaskPrivateStorage::StepCreateDirectory); } void TaskPrivateStorage::StepCreateDirectory() { using namespace WrtDB; LogInfo("Step: Creating private storage directory."); m_context.installStep = InstallerContext::INSTALL_CREATE_PRIVATE_STORAGE; std::ostringstream widgetPath; DPL::OptionalString pkgname = m_context.widgetConfig.pkgname; if(!pkgname.IsNull()) { widgetPath << m_context.locations->getPackageInstallationDir() << "/"; } else { ThrowMsg(Exceptions::InternalError, "No Package name exists."); } if (access(widgetPath.str().c_str(), W_OK | X_OK) != 0) { ThrowMsg(Exceptions::InternalError, DPL::GetErrnoString()); } std::ostringstream storagePath; storagePath << widgetPath.str().c_str() << GlobalConfig::GetWidgetPrivateStoragePath(); if (access(storagePath.str().c_str(), F_OK) != 0) { FileUtils::MakePath(storagePath.str(), PRIVATE_STORAGE_MODE); // '5000' is default uid, gid for applications. // So installed applications should be launched as process of uid '5000'. // the process can access private directory 'data' of itself. if(chown(storagePath.str().c_str(), WEBAPP_DEFAULT_UID, WEBAPP_DEFAULT_GID) != 0) { ThrowMsg(Exceptions::InternalError, "Chown to invaild user"); } } else if (access(storagePath.str().c_str(), W_OK | R_OK | X_OK) == 0) { LogInfo("Private storage already exists."); // Even if private directory already is created, private dircetory // should change owner. if(chown(storagePath.str().c_str(), WEBAPP_DEFAULT_UID, WEBAPP_DEFAULT_GID) != 0) { ThrowMsg(Exceptions::InternalError, "Chown to invaild user"); } if(chmod(storagePath.str().c_str(), PRIVATE_STORAGE_MODE) != 0) { ThrowMsg(Exceptions::InternalError, "chmod to 0700"); } } else { ThrowMsg(Exceptions::InternalError, "No access to private storage."); } m_context.job->UpdateProgress( InstallerContext::INSTALL_CREATE_PRIVATE_STORAGE, "Private storage created." ); } } //namespace WidgetInstall } //namespace Jobs