)
SET(CKM_DB_TOOLS_SOURCES
- ${CMAKE_CURRENT_SOURCE_DIR}/db-crypto-ext.cpp
${CMAKE_CURRENT_SOURCE_DIR}/ckm-logic-ext.cpp
${CMAKE_CURRENT_SOURCE_DIR}/db-wrapper.cpp
${KEY_MANAGER_PATH}/common/ckm-error.cpp
/*
- * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2000 - 2020 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.
#include "ckm-logic-ext.h"
-#include "db-crypto-ext.h"
+#include <dpl/db/sql_connection.h>
+
+namespace {
+
+const char *DB_CMD_OBJECT_SELECT = "SELECT * FROM [join_name_object_tables];";
+
+} // anonymous namespace
namespace CKM {
-DB::SqlConnection::Output CKMLogicExt::Execute(uid_t user,
- const std::string &cmd)
+DB::SqlConnection::Output CKMLogicExt::Execute(uid_t user, const std::string &cmd)
{
- /*
- * We need to access to DB::Crypto::m_connection to call Execute() on it. We don't want to mess
- * with DB::Crypto too much so adding a friend and extending public interface was not an option.
- * That's why we need a derived class DB::CryptoExt. m_userDataMap must be left unchanged after
- * this operation but DB::Crypto can't be copied. According to C++ standard static casting
- * DB::Crypto pointer to DB::CryptoExt pointer is UB. Therefore DB::Crypto is temporarily moved
- * into DB::CryptoExt and moved back to m_userDataMap after the call to Execute().
- */
- DB::CryptoExt db(std::move(m_userDataMap[user].database));
-
- try {
- DB::SqlConnection::Output output = db.Execute(cmd);
- m_userDataMap[user].database = std::move(*static_cast<DB::Crypto *>(&db));
- return output;
- } catch (const DB::SqlConnection::Exception::Base &e) {
- m_userDataMap[user].database = std::move(*static_cast<DB::Crypto *>(&db));
- throw;
- }
+ DB::SqlConnection::Output out;
+ m_userDataMap[user].database.m_connection->ExecCommand(&out, "%s", cmd.c_str());
+ return out;
}
DB::RowVector CKMLogicExt::getRows(uid_t user)
{
- DB::CryptoExt db(std::move(m_userDataMap[user].database));
-
- try {
- DB::RowVector output = db.getRows();
- m_userDataMap[user].database = std::move(*static_cast<DB::Crypto *>(&db));
- return output;
- } catch (const DB::SqlConnection::Exception::Base &e) {
- m_userDataMap[user].database = std::move(*static_cast<DB::Crypto *>(&db));
- throw;
- }
+ DB::Crypto& database = m_userDataMap[user].database;
+ DB::SqlConnection::DataCommandUniquePtr selectCommand =
+ database.m_connection->PrepareDataCommand(DB_CMD_OBJECT_SELECT);
+
+ DB::RowVector rows;
+ while (selectCommand->Step())
+ rows.push_back(database.getRow(selectCommand));
+ return rows;
}
void CKMLogicExt::saveRow(uid_t user, const DB::Row &row)
+++ /dev/null
-/*
- * Copyright (c) 2014-2017 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/*
- * @file db-crypto-ext.cpp
- * @author Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
- * @version 1.0
- * @brief Limited implementation of encrypted db access layer
- */
-
-#include "db-crypto-ext.h"
-
-#include <dpl/exception.h>
-
-namespace CKM {
-namespace DB {
-
-const char *DB_CMD_OBJECT_SELECT =
- "SELECT * FROM [join_name_object_tables];";
-
-SqlConnection::Output CryptoExt::Execute(const std::string &cmd)
-{
- SqlConnection::Output out;
-
- if (!m_connection) {
- ThrowMsg(SqlConnection::Exception::ConnectionBroken,
- "Not connected to database");
- }
-
- m_connection->ExecCommand(&out, "%s", cmd.c_str());
- return out;
-}
-
-RowVector CryptoExt::getRows()
-{
- try {
- RowVector output;
- SqlConnection::DataCommandUniquePtr selectCommand =
- m_connection->PrepareDataCommand(DB_CMD_OBJECT_SELECT);
-
- while (selectCommand->Step()) {
- // extract data
- output.push_back(getRow(selectCommand));
- }
-
- return output;
- } catch (const SqlConnection::Exception::InvalidColumn &) {
- LogError("Select statement invalid column error");
- } catch (const SqlConnection::Exception::SyntaxError &) {
- LogError("Couldn't prepare select statement");
- } catch (const SqlConnection::Exception::InternalError &) {
- LogError("Couldn't execute select statement");
- }
-
- ThrowErr(Exc::DatabaseFailed, "Couldn't get row from database");
-}
-
-} // namespace DB
-} // namespace CKM
+++ /dev/null
-/*
- * Copyright (c) 2015-2019 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/*
- * @file db-crypto-ext.h
- * @author Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
- * @version 1.0
- * @brief Header of encrypted db access layer
- */
-
-#pragma once
-
-#include <db-crypto.h>
-#include <string>
-#include <utility>
-#include <dpl/db/sql_connection.h>
-
-namespace CKM {
-namespace DB {
-struct CryptoExt : public Crypto {
- explicit CryptoExt(Crypto orig) : Crypto(std::move(orig)) {}
-
- SqlConnection::Output Execute(const std::string &cmd);
- RowVector getRows();
-};
-
-} // namespace DB
-} // namespace CKM
-
#pragma GCC diagnostic warning "-Wdeprecated-declarations"
namespace CKM {
+
+class CKMLogicExt;
+
namespace DB {
class Crypto {
public:
private:
bool m_inUserTransaction;
+ friend CKMLogicExt;
+
void resetDB();
void initDatabase();
void createDBSchema();
};
} // namespace DB
+
} // namespace CKM
#pragma GCC diagnostic pop