Installer Util and DRM wrapper api added.
authorDongeup Ham <dongeup.ham@samsung.com>
Thu, 18 Oct 2012 12:25:18 +0000 (21:25 +0900)
committerDongeup Ham <dongeup.ham@samsung.com>
Thu, 18 Oct 2012 12:25:18 +0000 (21:25 +0900)
Change-Id: I2e2ba54cf25ca7ebde6e1fd4d9e92542355f35e6

.cproject
inc/InstallerDefs.h
src/Manager/ConfigurationManager.cpp
src/Manager/PermissionManager.cpp
src/Manager/PermissionManager.h [changed mode: 0644->0755]
src/Step/PackageCheckStep.cpp
src/Util/InstallerUtil.cpp
src/Util/InstallerUtil.h

index afce116..bb9cd9e 100755 (executable)
--- a/.cproject
+++ b/.cproject
                                                                        <listOptionValue builtIn="false" value="&quot;../../../src/system/inc&quot;"/>
                                                                        <listOptionValue builtIn="false" value="&quot;../../../src/security/inc&quot;"/>
                                                                        <listOptionValue builtIn="false" value="&quot;${SBI_SYSROOT}/usr/include/pkgmgr&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="&quot;${SBI_SYSROOT}/usr/include/dlog&quot;"/>
                                                                        <listOptionValue builtIn="false" value="&quot;${SBI_SYSROOT}/usr/include/system&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="../../osp-foundation/src/base/inc"/>
+                                                                       <listOptionValue builtIn="false" value="../../osp-foundation/src/app/inc"/>
+                                                                       <listOptionValue builtIn="false" value="&quot;../../osp-foundation/src/system/inc&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="&quot;../../osp-foundation/src/security/inc&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="&quot;../../osp-foundation/src/io/inc&quot;"/>
                                                                </option>
                                                                <option id="sbi.gnu.cpp.compiler.option.frameworks_inc.cpp.1460003629" name="Tizen-Frameworks-Include-Path" superClass="sbi.gnu.cpp.compiler.option.frameworks_inc.cpp" valueType="includePath">
                                                                        <listOptionValue builtIn="false" value="&quot;${SBI_SYSROOT}/usr/include&quot;"/>
index 5fb3d9a..49bd167 100755 (executable)
@@ -75,7 +75,7 @@
 #define DIR_MEMORYCARD_OSP_APPLICATIONS_TEMP   L"/opt/storage/sdcard/apps/__@@osp_tmp@@__"
 
 #define OSP_INSTALLER "osp-installer"
-#define OSP_INSTALLER_VERSION "osp-installer version = 2012/10/18"
+#define OSP_INSTALLER_VERSION "osp-installer version = 2012/10/18(10)"
 
 enum InstallationSetStep
 {
@@ -97,10 +97,10 @@ enum InstallationStep
        INSTALLER_STEP_INIT,
        INSTALLER_STEP_CHECK_SYSTEM,
        INSTALLER_STEP_CHECK_PACKAGE,
+       INSTALLER_STEP_DRM,
        INSTALLER_STEP_PARSE_MANIFEST,
        INSTALLER_STEP_UNPACK,
        INSTALLER_STEP_LICENSE,
-       INSTALLER_STEP_DRM,
        INSTALLER_STEP_PARSE_SIGNATURE,
 
        INSTALLER_STEP_INIT_UNINSTALL,
@@ -153,7 +153,7 @@ enum InstallerError
        INSTALLER_ERROR_CERT_CHAIN,
        INSTALLER_ERROR_CERT_REVOKED,
        INSTALLER_ERROR_CERT_ROOT,
-       INSTALLER_ERROR_DRM_LICENSE,
+       INSTALLER_ERROR_DRM,
        INSTALLER_ERROR_INTEGRITY_FAILED,
 
 };
index 4f44f05..65dbccb 100755 (executable)
@@ -106,6 +106,9 @@ ConfigurationManager::CreateFile(InstallationContext* pContext)
                        String binaryPath;
                        binaryPath.Format(1024, L"%ls%ls/%ls", rootPath.GetPointer(), DIR_BIN, appName.GetPointer());
 
+                       String tempBinaryPath;
+                       tempBinaryPath.Format(1024, L"%ls%ls/.%ls", rootPath.GetPointer(), DIR_BIN, appName.GetPointer());
+
                        pBinaryPath = _StringConverter::CopyToCharArrayN(binaryPath);
                        TryCatch(pBinaryPath, res = false, "[osp-installer] pBinaryPath is null");
 
@@ -121,6 +124,8 @@ ConfigurationManager::CreateFile(InstallationContext* pContext)
                                r = File::Copy(UIAPP_LOADER_PATH, pBinaryPath, false);
                                TryCatch(!IsFailed(r), res = false, "[osp-installer] File::Copy() failed, filePath=[%s]", pBinaryPath);
 
+                               InstallerUtil::Copy(UIAPP_LOADER_PATH, tempBinaryPath);
+
                                ArrayList* pFeatureList = pAppInfoImpl->GetAppFeatureList();
                                TryCatch(pFeatureList, res = false, "[osp-installer] pFeatureList is null");
 
@@ -186,12 +191,18 @@ ConfigurationManager::CreateFile(InstallationContext* pContext)
                                if (pContext->IsPreloaded() == false)
                                {
                                        //err = symlink(SERVICEAPP_LOADER_PATH, pBinaryPath);
+
+                                       InstallerUtil::Copy(SERVICEAPP_LOADER_PATH, tempBinaryPath);
+
                                        r = File::Copy(SERVICEAPP_LOADER_PATH, pBinaryPath, false);
                                        TryCatch(!IsFailed(r), res = false, "[osp-installer] File::Copy() failed, filePath=[%s]", pBinaryPath);
                                }
                                else
                                {
                                        //err = symlink(SYSTEMAPP_LOADER_PATH, pBinaryPath);
+
+                                       InstallerUtil::Copy(SYSTEMAPP_LOADER_PATH, tempBinaryPath);
+
                                        r = File::Copy(SYSTEMAPP_LOADER_PATH, pBinaryPath, false);
                                        TryCatch(!IsFailed(r), res = false, "[osp-installer] File::Copy() failed, filePath=[%s]", pBinaryPath);
                                }
index 8f25f68..5a2835c 100755 (executable)
@@ -49,25 +49,25 @@ PermissionManager::~PermissionManager(void)
 {
 }
 
-bool
-PermissionManager::ChangeOwner(const Osp::Base::String& filePath)
-{
-       int res = -1;
-       char* pFilePath = null;
-
-       pFilePath = _StringConverter::CopyToCharArrayN(filePath);
-       TryReturn(pFilePath, false, "[osp-installer] pFilePath is null");
-
-       res = chown(pFilePath, APP_OWNER_ID, APP_GROUP_ID);
-       if (res != 0)
-       {
-               AppLogTag(OSP_INSTALLER, "Fail to change owner[%s], res=[%d]", pFilePath, res);
-       }
-
-       delete[] pFilePath;
-
-       return true;
-}
+//bool
+//PermissionManager::ChangeOwner(const Osp::Base::String& filePath)
+//{
+//     int res = -1;
+//     char* pFilePath = null;
+//
+//     pFilePath = _StringConverter::CopyToCharArrayN(filePath);
+//     TryReturn(pFilePath, false, "[osp-installer] pFilePath is null");
+//
+//     res = chown(pFilePath, APP_OWNER_ID, APP_GROUP_ID);
+//     if (res != 0)
+//     {
+//             AppLogTag(OSP_INSTALLER, "Fail to change owner[%s], res=[%d]", pFilePath, res);
+//     }
+//
+//     delete[] pFilePath;
+//
+//     return true;
+//}
 
 bool
 PermissionManager::ChangeHomeDirectoryOwner(const String& rootPath, int depth)
@@ -97,8 +97,8 @@ PermissionManager::ChangeHomeDirectoryOwner(const String& rootPath, int depth)
 
                if (entryName == L".")
                {
-                       ChangeOwner(entryDir);
-                       ChangeMode(entryDir, S_IRUSR | S_IWUSR | S_IXUSR);
+                       InstallerUtil::ChangeOwner(entryDir);
+                       InstallerUtil::ChangeMode(entryDir, S_IRUSR | S_IWUSR | S_IXUSR);
                        continue;
                }
                else if (entryName == L"..")
@@ -113,13 +113,13 @@ PermissionManager::ChangeHomeDirectoryOwner(const String& rootPath, int depth)
 
                if (entry.IsDirectory() == false)
                {
-                       ChangeOwner(entryDir);
-                       ChangeMode(entryDir, S_IRUSR | S_IWUSR | S_IXUSR);
+                       InstallerUtil::ChangeOwner(entryDir);
+                       InstallerUtil::ChangeMode(entryDir, S_IRUSR | S_IWUSR | S_IXUSR);
                }
                else
                {
                        ChangeHomeDirectoryOwner(entryDir, depth+1);
-                       ChangeMode(entryDir, S_IRUSR | S_IWUSR | S_IXUSR);
+                       InstallerUtil::ChangeMode(entryDir, S_IRUSR | S_IWUSR | S_IXUSR);
                }
        }
 
@@ -164,30 +164,30 @@ PermissionManager::ApplyHomeDirectoryPolicy(const String& rootPath)
 //     }
 
        ChangeHomeDirectoryOwner(dataPath, 0);
-       ChangeMode(dataPath, S_IRUSR | S_IWUSR | S_IXUSR);
+       InstallerUtil::ChangeMode(dataPath, S_IRUSR | S_IWUSR | S_IXUSR);
 
        return true;
 }
 
-bool
-PermissionManager::ChangeMode(const String& filePath, int mode)
-{
-       int res = -1;
-       char* pFilePath = null;
-
-       pFilePath = _StringConverter::CopyToCharArrayN(filePath);
-       TryReturn(pFilePath, false, "[osp-installer] pFilePath is null");
-
-       res = chmod(pFilePath, mode);
-       if (res != 0)
-       {
-               AppLogTag(OSP_INSTALLER, "Fail to change mode, path=[%s], mode=[%o], res=[%d]", pFilePath, mode, res);
-       }
-
-       delete[] pFilePath;
-
-       return true;
-}
+//bool
+//PermissionManager::ChangeMode(const String& filePath, int mode)
+//{
+//     int res = -1;
+//     char* pFilePath = null;
+//
+//     pFilePath = _StringConverter::CopyToCharArrayN(filePath);
+//     TryReturn(pFilePath, false, "[osp-installer] pFilePath is null");
+//
+//     res = chmod(pFilePath, mode);
+//     if (res != 0)
+//     {
+//             AppLogTag(OSP_INSTALLER, "Fail to change mode, path=[%s], mode=[%o], res=[%d]", pFilePath, mode, res);
+//     }
+//
+//     delete[] pFilePath;
+//
+//     return true;
+//}
 
 bool
 PermissionManager::SetDirectory(InstallationContext* pContext)
@@ -255,7 +255,7 @@ PermissionManager::SetDirectory(InstallationContext* pContext)
        if (r == E_SUCCESS)
        {
                ChangeHomeDirectoryOwner(destPath, 0);
-               ChangeMode(destPath, S_IRUSR | S_IXUSR);
+               InstallerUtil::ChangeMode(destPath, S_IRUSR | S_IXUSR);
        }
 
        sprintf(destPath, "%ls%ls", appRootPath.GetPointer(), DIR_DATA);
@@ -293,7 +293,7 @@ PermissionManager::SetDirectory(InstallationContext* pContext)
        if (r == E_SUCCESS)
        {
                ChangeHomeDirectoryOwner(destPath, 0);
-               ChangeMode(destPath, S_IRUSR | S_IWUSR | S_IXUSR);
+               InstallerUtil::ChangeMode(destPath, S_IRUSR | S_IWUSR | S_IXUSR);
        }
 
        sprintf(destPath, "%ls%ls", appRootPath.GetPointer(), DIR_SETTING);
@@ -320,7 +320,7 @@ PermissionManager::SetDirectory(InstallationContext* pContext)
                }
 
                ChangeHomeDirectoryOwner(destPath, 0);
-               ChangeMode(destPath, S_IRUSR | S_IWUSR | S_IXUSR);
+               InstallerUtil::ChangeMode(destPath, S_IRUSR | S_IWUSR | S_IXUSR);
        }
 
        ApplyHomeDirectoryPolicy(appRootPath);
old mode 100644 (file)
new mode 100755 (executable)
index 7bdd7a5..e47e728
@@ -43,10 +43,10 @@ public:
        static bool SetFile(InstallationContext* pContext);
 
 private:
-       static bool ChangeOwner(const Osp::Base::String& filePath);
+       // static bool ChangeOwner(const Osp::Base::String& filePath);
        static bool ChangeHomeDirectoryOwner(const Osp::Base::String&, int depth);
        static bool ApplyHomeDirectoryPolicy(const Osp::Base::String& rootpath);
-       static bool ChangeMode(const Osp::Base::String& filePath, int mode);
+       // static bool ChangeMode(const Osp::Base::String& filePath, int mode);
        static bool CreateSystemDirectory(InstallationContext* pContext, const Osp::Base::String& rootpath);
        static bool SetSymLink(InstallationContext* pContext);
     static bool PrepareDataCaging(InstallationContext* pContext);
index 5a3d8df..acdd6aa 100755 (executable)
@@ -24,6 +24,7 @@
 
 #include "InstallationContext.h"
 #include "PackageCheckStep.h"
+#include "InstallerUtil.h"
 
 using namespace Osp::Base;
 using namespace Osp::Base::Utility;
@@ -91,7 +92,7 @@ InstallerError
 PackageCheckStep::OnStatePackageCheck(void)
 {
        InstallerError error = INSTALLER_ERROR_NONE;
-       AppLogTag(OSP_INSTALLER, "SignatureStep::OnStatePackageCheck()");
+       AppLogTag(OSP_INSTALLER, "PackageCheckStep::OnStatePackageCheck()");
 
        String tempDir;
 
@@ -114,8 +115,16 @@ PackageCheckStep::OnStatePackageCheck(void)
                TryReturn(!IsFailed(r), INSTALLER_ERROR_INTERNAL_STATE, "[osp-installer] Directory::Create() failed");
        }
 
+       String packagePath = __pContext->GetPackagePath();
+       if (InstallerUtil::IsDrmFile(packagePath) == true)
+       {
+               bool res = false;
+               res = InstallerUtil::DecryptPackage(packagePath);
+               TryReturn(res == true, INSTALLER_ERROR_DRM, "[osp-installer] InstallerUtil::DecryptPackage() failed");
+       }
+
        FileUnzipper unzipper;
-       unzipper.Construct(__pContext->GetPackagePath());
+       unzipper.Construct(packagePath);
 
        AppLogTag(OSP_INSTALLER, "UnzipTo(manifest.xml) - START");
        unzipper.UnzipTo(tempDir, L"info/manifest.xml");
index 0f69c61..c1b4163 100755 (executable)
@@ -22,6 +22,7 @@
 #include <sys/stat.h>
 #include <dirent.h>
 #include <unistd.h>
+#include <unique_ptr.h>
 
 #include <FBaseErrorDefine.h>
 #include <FIoFile.h>
@@ -59,6 +60,7 @@ InstallerUtil::Remove(const Osp::Base::String& filePath)
        err = lstat(pFilePath, &fileinfo);
        TryCatch(err >= 0, res = false, "[osp-installer] lstat() failed, pFilePath=%s", pFilePath);
 
+
        if (S_ISLNK(fileinfo.st_mode))
        {
                AppLogTag(OSP_INSTALLER, "remove symlink, pFilePath=%s", pFilePath);
@@ -85,6 +87,98 @@ CATCH:
        return res;
 }
 
+bool
+InstallerUtil::Copy(const String& srcFilePath, const String& destFilePath)
+{
+       const int bufSize = 4096;
+       int readBytes = 0;
+       result r = E_SUCCESS;
+
+       File srcFile;
+       File destFile;
+
+       std::unique_ptr<char[]> pBuf(new char[bufSize]);
+       TryReturn(pBuf, false, "[osp-installer] pBuf is null");
+
+       r = srcFile.Construct(srcFilePath, L"r");
+       TryReturn(!IsFailed(r), false, "[osp-installer] srcFile.Construct is failed");
+
+       r = destFile.Construct(destFilePath, L"w");
+       TryReturn(!IsFailed(r), false, "[osp-installer] destFile.Construct is failed");
+
+       do
+       {
+               readBytes = srcFile.Read(pBuf.get(), bufSize);
+               if (readBytes > 0)
+               {
+                       r = destFile.Write(pBuf.get(), readBytes);
+                       TryReturn(!IsFailed(r), false, "[osp-installer] destFile.Write is failed");
+               }
+       }
+       while (readBytes > 0);
+
+       return true;
+}
+
+bool
+InstallerUtil::CreateSymlink(const String& oldPath, const String& newPath)
+{
+       int err = -1;
+
+       std::unique_ptr<char[]> pOldPath(_StringConverter::CopyToCharArrayN(oldPath));
+       TryReturn(pOldPath, false, "[osp-installer] pOldPath is null");
+
+       std::unique_ptr<char[]> pNewPath(_StringConverter::CopyToCharArrayN(newPath));
+       TryReturn(pNewPath, false, "[osp-installer] pNewPath is null");
+
+       err = symlink(pOldPath.get(), pNewPath.get());
+       TryReturn(err == 0, false, "[osp-installer] symlink() is failed, oldpath=(%s), newpath=(%s)", pOldPath.get(), pNewPath.get());
+
+       return true;
+}
+
+bool
+InstallerUtil::ChangeMode(const String& filePath, int mode)
+{
+       int err = -1;
+
+       std::unique_ptr<char[]> pFilePath(_StringConverter::CopyToCharArrayN(filePath));
+       TryReturn(pFilePath, false, "[osp-installer] pFilePath is null");
+
+       err = chmod(pFilePath.get(), mode);
+       TryReturn(err == 0, false, "[osp-installer] chmod() is failed, filepath=[%s], mode=[%o]", pFilePath.get(), mode);
+
+       return true;
+}
+
+bool
+InstallerUtil::ChangeOwner(const String& filePath)
+{
+       int err = -1;
+
+       std::unique_ptr<char[]> pFilePath(_StringConverter::CopyToCharArrayN(filePath));
+       TryReturn(pFilePath, false, "[osp-installer] pFilePath is null");
+
+       err = chown(pFilePath.get(), APP_OWNER_ID, APP_GROUP_ID);
+       TryReturn(err == 0, false, "[osp-installer] chown() is failed, filepath=[%s]", pFilePath.get());
+
+       return true;
+}
+
+bool
+InstallerUtil::IsDrmFile(const Osp::Base::String& packagePath)
+{
+       AppLogTag(OSP_INSTALLER, "IsDrmFile() called, packagePath=%ls", packagePath.GetPointer());
+       return false;
+}
+
+bool
+InstallerUtil::DecryptPackage(const Osp::Base::String& packagePath)
+{
+       AppLogTag(OSP_INSTALLER, "DecryptPackage() called, packagePath=%ls", packagePath.GetPointer());
+       return true;
+}
+
 String
 InstallerUtil::GetCategory(int categoryType)
 {
index c553c28..a01cae1 100755 (executable)
@@ -43,6 +43,14 @@ public:
        virtual ~InstallerUtil(void);
 
        static bool Remove(const Osp::Base::String& filePath);
+       static bool Copy(const Osp::Base::String& srcFilePath, const Osp::Base::String& destFilePath);
+
+       static bool CreateSymlink(const Osp::Base::String& oldPath, const Osp::Base::String& newPath);
+       static bool ChangeMode(const Osp::Base::String& filePath, int mode);
+       static bool     ChangeOwner(const Osp::Base::String& filePath);
+
+       static bool IsDrmFile(const Osp::Base::String& packagePath);
+       static bool DecryptPackage(const Osp::Base::String& packagePath);
 
        static Osp::Base::String GetCategory(int categoryType);
        static CategoryType GetCategoryType(char* pCategory);