Remove boost dependency
[platform/core/appfw/app-installers.git] / src / common / security_registration.cc
index 56447e8..1204e3d 100644 (file)
@@ -4,9 +4,6 @@
 
 #include "common/security_registration.h"
 
-#include <boost/filesystem/operations.hpp>
-#include <boost/format.hpp>
-
 #include <unistd.h>
 #include <sys/types.h>
 #include <manifest_parser/utils/logging.h>
@@ -23,7 +20,7 @@
 #include "common/utils/file_util.h"
 #include "common/utils/glist_range.h"
 
-namespace bf = boost::filesystem;
+namespace fs = std::filesystem;
 namespace ci = common_installer;
 
 namespace {
@@ -32,7 +29,7 @@ using AppDefinedPrivInfo = std::vector<std::pair<std::string, std::string>>;
 
 const std::vector<std::pair<const char*,
                             app_install_path_type>> kSecurityPolicies = {
-  {"/", SECURITY_MANAGER_PATH_PUBLIC_RO},
+  {".", SECURITY_MANAGER_PATH_PUBLIC_RO},
   {"bin", SECURITY_MANAGER_PATH_RO},
   {"data", SECURITY_MANAGER_PATH_RW},
   {"cache", SECURITY_MANAGER_PATH_RW},
@@ -123,7 +120,7 @@ class SecurityContextRequest {
 
   bool PrepareAdditional(const std::string& author_id,
       const std::string& api_version,
-      const boost::filesystem::path& path,
+      const std::filesystem::path& path,
       bool cross_app_rules) {
     if (cross_app_rules) {
       int error = security_manager_app_inst_req_set_hybrid(req_);
@@ -151,7 +148,7 @@ class SecurityContextRequest {
     if (!path.empty()) {
       app_install_type type = SM_APP_INSTALL_NONE;
       for (auto& policy : kPathPolicies) {
-        bf::path root = bf::path(policy.first);
+        fs::path root = fs::path(policy.first);
         if (ci::IsSubDir(path, root)) {
           type = policy.second;
           break;
@@ -325,7 +322,7 @@ class SecurityContextPathRequest {
   }
 
   bool PreparePath(const std::string& pkg_type,
-      const boost::filesystem::path& path, bool is_readonly_pkg,
+      const std::filesystem::path& path, bool is_readonly_pkg,
       bool is_extonly) {
     if (path.empty()) {
       LOG(ERROR) << "Path is empty. This value must be set";
@@ -333,7 +330,7 @@ class SecurityContextPathRequest {
     }
     app_install_type type = SM_APP_INSTALL_NONE;
     for (auto& policy : kPathPolicies) {
-      bf::path root = bf::path(policy.first);
+      fs::path root = fs::path(policy.first);
       if (ci::IsSubDir(path, root)) {
         type = policy.second;
         break;
@@ -358,7 +355,7 @@ class SecurityContextPathRequest {
     else
       policies = kSecurityPolicies;
     for (auto& policy : policies) {
-      bf::path subpath = path / policy.first;
+      fs::path subpath = path / policy.first;
       if (is_extonly) {
         // Now, this is for legacy migraton.
         // do not try to access any file before changing label,
@@ -367,9 +364,9 @@ class SecurityContextPathRequest {
         if (pkg_type == "wgt" && (subdir == "bin" || subdir == "lib"))
           continue;
       } else {
-        if (!bf::exists(subpath))
+        if (!fs::exists(subpath))
           continue;
-        if (bf::is_symlink(symlink_status(subpath)) &&
+        if (fs::is_symlink(symlink_status(subpath)) &&
             policy.second != SECURITY_MANAGER_PATH_OWNER_RW_OTHER_RO) {
           LOG(DEBUG) << "Path " << subpath << " is a symlink."
                      << "Path will not be registered";
@@ -385,8 +382,8 @@ class SecurityContextPathRequest {
 
       // this is for lib rpk installation. set public RO for contents only.
       if (pkg_type == "rpk" && std::string(policy.first) == "lib") {
-        for (bf::directory_iterator iter(subpath);
-            iter != bf::directory_iterator(); ++iter) {
+        for (fs::directory_iterator iter(subpath);
+            iter != fs::directory_iterator(); ++iter) {
           error = security_manager_path_req_add_path(req_,
               iter->path().string().c_str(), SECURITY_MANAGER_PATH_PUBLIC_RO);
           if (error!= SECURITY_MANAGER_SUCCESS) {
@@ -440,7 +437,7 @@ bool RegisterSecurityContextForManifest(const ci::InstallerContext* context,
     std::string* error_message) {
   std::string pkg_id = context->pkgid.get();
   std::string pkg_type = context->pkg_type.get();
-  bf::path path = context->GetPkgPath();
+  fs::path path = context->GetPkgPath();
   uid_t uid = context->uid.get();
   const ci::CertificateInfo* cert_info = &(context->certificate_info.get());
   manifest_x* manifest = context->manifest_data.get();
@@ -562,7 +559,7 @@ bool UnregisterSecurityContextForPkgId(const std::string &pkg_id,
 }
 
 bool RegisterSecurityContextForPath(const std::string &pkg_id,
-    const std::string& pkg_type, const boost::filesystem::path& path,
+    const std::string& pkg_type, const std::filesystem::path& path,
     uid_t uid, bool is_readonly_pkg, std::string* error_message) {
   SecurityContextPathRequest req;
   if (!req.IsValid()) {
@@ -583,7 +580,7 @@ bool RegisterSecurityContextForPath(const std::string &pkg_id,
 }
 
 bool RegisterSecurityContextForPathExternalOnly(const std::string &pkg_id,
-    const std::string &pkg_type, const boost::filesystem::path& path,
+    const std::string &pkg_type, const std::filesystem::path& path,
     uid_t uid, std::string* error_message) {
   SecurityContextPathRequest req;
   if (!req.IsValid()) {
@@ -603,14 +600,14 @@ bool RegisterSecurityContextForPathExternalOnly(const std::string &pkg_id,
   return result;
 }
 
-bool HasOwnerRwOtherRoPaths(const boost::filesystem::path& path) {
+bool HasOwnerRwOtherRoPaths(const std::filesystem::path& path) {
   for (auto& policy : kSecurityPolicies) {
     if (policy.second != SECURITY_MANAGER_PATH_OWNER_RW_OTHER_RO)
       continue;
 
-    bf::path subpath = path / policy.first;
+    fs::path subpath = path / policy.first;
     LOG(ERROR) << "subpath : " << subpath;
-    if (bf::exists(subpath))
+    if (fs::exists(subpath))
       return true;
   }