Remove TEMPORARY_UMASK 03/65303/5
authorSungbae Yoo <sungbae.yoo@samsung.com>
Fri, 8 Apr 2016 08:20:48 +0000 (17:20 +0900)
committerSungbae Yoo <sungbae.yoo@samsung.com>
Mon, 11 Apr 2016 06:30:49 +0000 (15:30 +0900)
Change-Id: I964e4fe960f1e7e40b5ec5a4fcf8c60ee9b0eeee
Signed-off-by: Sungbae Yoo <sungbae.yoo@samsung.com>
common/auth/shadow.cpp
server/zone.cpp

index 09139d3..01cbdc4 100644 (file)
 #include "filesystem.h"
 #include "audit/logger.h"
 
-#define TEMPORARY_UMASK(mode)   \
-        std::unique_ptr<mode_t, void(*)(mode_t *)> umask_##mode(new mode_t, \
-        [](mode_t *prev) {umask(*prev);}); \
-        *umask_##mode = mode;
-
 namespace runtime {
 
 //PwdFileLock
@@ -99,9 +94,10 @@ void Shadow::remove(const std::string& filename, const element& value,
 {
     std::string tmpfilename = filename + ".tmp";
     pwdStruct* ppwd;
+    mode_t old_mask;
     struct stat st;
 
-    TEMPORARY_UMASK(0777);
+    old_mask = ::umask(0777);
 
     std::unique_ptr<FILE, void(*)(FILE*)> fp_tmp_pwd(
         ::fopen(tmpfilename.c_str(), "w"),
@@ -112,6 +108,8 @@ void Shadow::remove(const std::string& filename, const element& value,
         ::fclose(fp);
     });
 
+    ::umask(old_mask);
+
     if (fp_tmp_pwd.get() == NULL) {
         throw runtime::Exception("Tmp file for shadow create error");
     }
@@ -122,8 +120,14 @@ void Shadow::remove(const std::string& filename, const element& value,
 
     PwdFileLock pwdLock;
 
-    std::unique_ptr<FILE, decltype(&::fclose)> fp_pwd
-    (::fopen(filename.c_str(), "r"), &::fclose);
+    std::unique_ptr<FILE, void(*)(FILE*)> fp_pwd(
+        ::fopen(filename.c_str(), "r"),
+    [](FILE * fp) {
+        if (fp == NULL) {
+            return;
+        }
+        ::fclose(fp);
+    });
 
     if (fp_pwd.get() == NULL) {
         throw runtime::Exception("shadow file open error");
index 21ad3ee..7f333cf 100644 (file)
 #define SHARED_SMACKLABEL   "User::App::Shared"
 #define APP_SMACKLABEL   "User::Pkg::"
 
-#define TEMPORARY_UMASK(mode)   \
-        std::unique_ptr<mode_t, void(*)(mode_t *)> umask_##mode(new mode_t, \
-        [](mode_t *prev) {umask(*prev);}); \
-        *umask_##mode = mode;
-
 namespace DevicePolicyManager {
 
 static int setZoneState(uid_t id, int state)
@@ -138,7 +133,6 @@ int Zone::createZone(const std::string& name, const std::string& setupWizAppid)
 
     try {
         //create a directory for zone setup
-        TEMPORARY_UMASK(0000);
         provisionDir.makeDirectory(true);
         runtime::Smack::setAccess(provisionDir, APP_SMACKLABEL + setupWizAppid);
 
@@ -158,8 +152,10 @@ int Zone::createZone(const std::string& name, const std::string& setupWizAppid)
     auto create = [&manager, name, setupWizAppid, provisionDirPath] {
         std::unique_ptr<xml::Document> bundleXml;
         xml::Node::NodeList nodes;
+        mode_t old_mask;
         int ret;
 
+        old_mask = ::umask(0);
         try {
             //attach a directory for inotify
             int fd = inotify_init();
@@ -218,7 +214,7 @@ int Zone::createZone(const std::string& name, const std::string& setupWizAppid)
                 {TZ_SYS_HOME, NULL},
             };
 
-            TEMPORARY_UMASK(0022);
+            ::umask(0022);
 
             ::tzplatform_set_user(user.getUid());
             for (int i = 0; dirs[i].dir != TZ_SYS_HOME; i++) {
@@ -269,15 +265,17 @@ int Zone::createZone(const std::string& name, const std::string& setupWizAppid)
             //TODO: write container owner info
 
             //write manifest file
+            ::umask(0077);
             bundleXml->write(ZONE_MANIFEST_DIR + name + ".xml", "UTF-8", true);
 
             //unlock the user
             setZoneState(user.getUid(), 1);
+
+            manager.notify("Zone::created", name, std::string());
         } catch (runtime::Exception& e) {
             ERROR(e.what());
         }
-
-        manager.notify("Zone::created", name, std::string());
+        ::umask(old_mask);
     };
 
     std::thread asyncWork(create);
@@ -335,11 +333,12 @@ int Zone::removeZone(const std::string& name)
             user.remove();
 
             bundle.remove();
+
+            manager.notify("Zone::removed", name, std::string());
         } catch (runtime::Exception& e) {
             ERROR(e.what());
             return;
         }
-        manager.notify("Zone::removed", name, std::string());
     };
 
     std::thread asyncWork(remove);