namespace {
const mode_t PRIVATE_STORAGE_MODE = 0700;
+const mode_t SHARE_MODE = 0705;
}
using namespace WrtDB;
{
AddStep(&TaskFileManipulation::StepCreateDirs);
AddStep(&TaskFileManipulation::StepCreatePrivateStorageDir);
+ AddStep(&TaskFileManipulation::StepCreateShareDir);
AddStep(&TaskFileManipulation::StepRenamePath);
AddAbortStep(&TaskFileManipulation::StepAbortRenamePath);
}
}
+void TaskFileManipulation::StepCreateShareDir()
+{
+ std::string sharePath = m_context.locations->getShareDir();
+
+ if (euidaccess(sharePath.c_str(), F_OK) != 0) {
+ if(!WrtUtilMakeDir(sharePath, SHARE_MODE)){
+ LogError("Failed to create directory for share");
+ ThrowMsg(Exceptions::InternalError,
+ "Failed to create directory for share");
+ }
+ // '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(sharePath.c_str(),
+ WEBAPP_DEFAULT_UID,
+ WEBAPP_DEFAULT_GID) != 0)
+ {
+ ThrowMsg(Exceptions::InternalError,
+ "Chown to invaild user");
+ }
+ } else if (euidaccess(sharePath.c_str(), W_OK | R_OK | X_OK) == 0) {
+ LogInfo("Share directory already exists.");
+ // Even if share directory already is created, share dircetory
+ // should change owner.
+ if(chown(sharePath.c_str(),
+ WEBAPP_DEFAULT_UID,
+ WEBAPP_DEFAULT_GID) != 0)
+ {
+ ThrowMsg(Exceptions::InternalError,
+ "Chown to invaild user");
+ }
+ if(chmod(sharePath.c_str(), SHARE_MODE) != 0) {
+ ThrowMsg(Exceptions::InternalError,
+ "chmod to 0700");
+ }
+
+ } else {
+ ThrowMsg(Exceptions::InternalError,
+ "No access to private storage.");
+ }
+
+}
+
void TaskFileManipulation::StepRenamePath()
{
std::string instDir;
*
* /opt/apps/[package_name]
* \_____________ /data
- * \_____________ /data/share
+ * \_____________ /share
* \_____________ /bin
* \_____________ /bin/[id_of_installed_package]
* \_____________ /res/wgt/
std::string getBackupExecFile() const; // /opt/apps/[package]/backup/bin/[package]
std::string getUserDataRootDir() const; // /opt/usr/apps/[package]
std::string getPrivateStorageDir() const; // /opt/usr/apps/[package]/data
+ std::string getShareDir() const; // /opt/usr/apps/[package]/share
// Temporary paths
/**