summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>2018-10-05 17:24:01 +0200
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>2018-10-08 15:15:46 +0200
commita792540f2eb10dfef526c4deb91b583e6bbeb176 (patch)
treed59ca162bcb9fba2f468928063adc5ba0bd24d3d /src
parent7d81f2d157e4f2f2d1aae5f1e327a1bb073da82b (diff)
downloadkey-manager-a792540f2eb10dfef526c4deb91b583e6bbeb176.tar.gz
key-manager-a792540f2eb10dfef526c4deb91b583e6bbeb176.tar.bz2
key-manager-a792540f2eb10dfef526c4deb91b583e6bbeb176.zip
Add RO location for initial values
RO location will be processed before RW if a flag file is present. After import the flag will be removed but xml files will be left untouched. Change-Id: Id11c982ee4a055871e4af6841c23a11cbf139239
Diffstat (limited to 'src')
-rw-r--r--src/manager/initial-values/initial-value-loader.cpp30
1 files changed, 24 insertions, 6 deletions
diff --git a/src/manager/initial-values/initial-value-loader.cpp b/src/manager/initial-values/initial-value-loader.cpp
index d2c94082..9f203d87 100644
--- a/src/manager/initial-values/initial-value-loader.cpp
+++ b/src/manager/initial-values/initial-value-loader.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2015 - 2018 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,6 +23,8 @@
#include <unistd.h>
+#include <fstream>
+
#include <ckm-logic.h>
#include <for-each-file.h>
#include <InitialValuesFile.h>
@@ -31,6 +33,7 @@
namespace {
const char *const INIT_VALUES_XSD = RO_DATA_DIR "/initial_values.xsd";
const char *const INIT_VALUES_FILE_SUFFIX = ".xml";
+const char *const INIT_VALUES_RO_IMPORT_FLAG = INITIAL_VALUES_DIR_RW "/ro_import";
} // namespace anonymous
namespace CKM {
@@ -40,8 +43,9 @@ void LoadFiles(CKMLogic &logic)
{
try {
std::vector<std::string> filesToParse;
+ std::string currentDir;
- forEachFile(INITIAL_VALUES_DIR, [&filesToParse](const std::string & filename) {
+ auto addXmlFiles = [&](const std::string & filename) {
std::string lowercaseFilename = filename;
std::transform(lowercaseFilename.begin(), lowercaseFilename.end(),
lowercaseFilename.begin(), ::tolower);
@@ -49,8 +53,20 @@ void LoadFiles(CKMLogic &logic)
if (lowercaseFilename.find(INIT_VALUES_FILE_SUFFIX) == std::string::npos)
return;
- filesToParse.emplace_back(std::string(INITIAL_VALUES_DIR) + "/" + filename);
- });
+ filesToParse.emplace_back(currentDir + "/" + filename);
+ };
+
+ std::ifstream ro_flag(INIT_VALUES_RO_IMPORT_FLAG);
+ if (ro_flag) {
+ currentDir = INITIAL_VALUES_DIR_RO;
+ forEachFile(INITIAL_VALUES_DIR_RO, addXmlFiles);
+ if (-1 == unlink(INIT_VALUES_RO_IMPORT_FLAG))
+ LogError("Unlink() failed for " << INIT_VALUES_RO_IMPORT_FLAG << ":" <<
+ CKM::GetErrnoString(errno));
+ }
+
+ currentDir = INITIAL_VALUES_DIR_RW;
+ forEachFile(INITIAL_VALUES_DIR_RW, addXmlFiles);
// parse
for (const auto &file : filesToParse) {
@@ -67,8 +83,10 @@ void LoadFiles(CKMLogic &logic)
rc);
}
- if (-1 == unlink(file.c_str()))
- LogError("Unlink() failed for " << file << ":" << CKM::GetErrnoString(errno));
+ if (file.compare(0, sizeof(INITIAL_VALUES_DIR_RW) - 1, INITIAL_VALUES_DIR_RW) == 0) {
+ if (-1 == unlink(file.c_str()))
+ LogError("Unlink() failed for " << file << ":" << CKM::GetErrnoString(errno));
+ }
}
} catch (...) {
LogError("The implementation of exception handling in xml parser is broken!");