Fix create shared data directory during update 84/224184/3
authorIlho Kim <ilho159.kim@samsung.com>
Fri, 7 Feb 2020 03:32:09 +0000 (12:32 +0900)
committerSangyoon Jang <jeremy.jang@samsung.com>
Fri, 7 Feb 2020 05:51:00 +0000 (05:51 +0000)
When updating from a package without privilege to a package with
need to set owner and permission

Change-Id: Ifa7732231f147723dfbee63f4739a35467cd1545
Signed-off-by: Ilho Kim <ilho159.kim@samsung.com>
src/common/shared_dirs.cc

index 5e753e8..2aee1c7 100644 (file)
@@ -881,12 +881,26 @@ bool CreatePerUserSharedDataDir(const std::string& pkgid) {
   ci::UserList list = ci::GetUserList();
   for (auto l : list) {
     uid_t uid = std::get<0>(l);
+    uid_t gid = std::get<1>(l);
     LOG(DEBUG) << "Adding shareddata directory for uid: " << uid;
 
     bf::path apps_rw = ci::GetRootAppPath(false, uid);
     if (!CreateSharedDataDirectories(apps_rw, pkgid))
       return false;
 
+    std::vector<std::string> shared_dirs(kSharedDataEntries);
+    for (auto entry : shared_dirs) {
+      bf::path shared_dst = apps_rw / entry / pkgid;
+      if (!SetDirectoryOwnerAndPermissions(shared_dst, uid, gid))
+        return false;
+    }
+
+    for (bf::recursive_directory_iterator iter(apps_rw / pkgid);
+        iter != bf::recursive_directory_iterator(); ++iter) {
+      if (!SetSharedDirOwnerAndPermissions(iter->path(), uid))
+        return false;
+    }
+
     std::string error_message;
     if (!ci::RegisterSecurityContextForPath(pkgid, apps_rw / pkgid, uid,
         false, &error_message)) {