#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
{
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"),
::fclose(fp);
});
+ ::umask(old_mask);
+
if (fp_tmp_pwd.get() == NULL) {
throw runtime::Exception("Tmp file for shadow create error");
}
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");
#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)
try {
//create a directory for zone setup
- TEMPORARY_UMASK(0000);
provisionDir.makeDirectory(true);
runtime::Smack::setAccess(provisionDir, APP_SMACKLABEL + 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();
{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++) {
//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);
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);