summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>2019-02-20 12:40:21 +0100
committerTomasz Swierczek <t.swierczek@samsung.com>2019-05-17 10:48:15 +0200
commit39795557d02a1e2ae0dd5ea2fa7a2085bed329c2 (patch)
tree9f5009aa1ca10704606a20676857f35d6731dbab
parente7fc5083eeec26de78c7ff9a4dc3e51b18b59958 (diff)
downloadkey-manager-39795557d02a1e2ae0dd5ea2fa7a2085bed329c2.tar.gz
key-manager-39795557d02a1e2ae0dd5ea2fa7a2085bed329c2.tar.bz2
key-manager-39795557d02a1e2ae0dd5ea2fa7a2085bed329c2.zip
Get rid of misleading SCHEMA_INFO error
During startup the key-manager attempts to read a table SCHEMA_INFO to get the information about the database version. In older versions of the database that table is missing. Key-manager properly handles that case but produces 3 lines of error log which may suggest that something went wrong. This commit checks the existence of the table before attempting to use it. Whole operation is enclosed in a transaction. Change-Id: Ie7f1fbe1182c2add5965f8e5ddada262ffcb42fe
-rw-r--r--src/manager/service/db-crypto.cpp64
-rw-r--r--src/manager/service/db-crypto.h6
2 files changed, 31 insertions, 39 deletions
diff --git a/src/manager/service/db-crypto.cpp b/src/manager/service/db-crypto.cpp
index 2bc2a92..d7acb0f 100644
--- a/src/manager/service/db-crypto.cpp
+++ b/src/manager/service/db-crypto.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2014 - 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.
@@ -229,25 +229,28 @@ void Crypto::createView(const char *create_cmd)
bool Crypto::getDBVersion(int &schemaVersion)
{
- SchemaInfo SchemaInfo(this);
-
- if (SchemaInfo.getVersionInfo(schemaVersion)) {
- LogDebug("Current DB version: " << schemaVersion);
- return true;
- } else {
- LogDebug("No DB version known or DB not present");
+ Transaction transaction(this);
- if (m_connection->CheckTableExist("CKM_TABLE")) {
- // special case: old CKM_TABLE exists
- schemaVersion = DB_VERSION_1;
- return true;
- } else if (m_connection->CheckTableExist("NAME_TABLE")) {
- // special case: new scheme exists, but no SCHEMA_INFO table present
- schemaVersion = DB_VERSION_2;
+ if (m_connection->CheckTableExist("SCHEMA_INFO")) {
+ SchemaInfo SchemaInfo(m_connection);
+ if (SchemaInfo.getVersionInfo(schemaVersion)) {
+ LogDebug("Current DB version: " << schemaVersion);
return true;
}
}
+ LogDebug("No DB version known or DB not present");
+
+ if (m_connection->CheckTableExist("CKM_TABLE")) {
+ // special case: old CKM_TABLE exists
+ schemaVersion = DB_VERSION_1;
+ return true;
+ } else if (m_connection->CheckTableExist("NAME_TABLE")) {
+ // special case: new scheme exists, but no SCHEMA_INFO table present
+ schemaVersion = DB_VERSION_2;
+ return true;
+ }
+
// not recognized - proceed with an empty DBs
return false;
}
@@ -282,7 +285,7 @@ void Crypto::initDatabase()
}
// update DB version info
- SchemaInfo SchemaInfo(this);
+ SchemaInfo SchemaInfo(m_connection);
SchemaInfo.setVersionInfo();
transaction.commit();
}
@@ -320,7 +323,7 @@ void Crypto::createDBSchema()
"Can not create the database schema: no initialization script");
m_connection->ExecCommand((*script).c_str());
- SchemaInfo SchemaInfo(this);
+ SchemaInfo SchemaInfo(m_connection);
SchemaInfo.setVersionInfo();
transaction.commit();
}
@@ -712,34 +715,23 @@ void Crypto::setPermission(
void Crypto::SchemaInfo::setVersionInfo()
{
SqlConnection::DataCommandUniquePtr insertContextCommand =
- m_db->m_connection->PrepareDataCommand(DB_CMD_SCHEMA_SET);
+ m_connection->PrepareDataCommand(DB_CMD_SCHEMA_SET);
insertContextCommand->BindString(101, DB_SCHEMA_VERSION_FIELD);
insertContextCommand->BindString(103,
std::to_string(DB_VERSION_CURRENT).c_str());
insertContextCommand->Step();
}
-bool Crypto::SchemaInfo::getVersionInfo(int &version) const
+bool Crypto::SchemaInfo::getVersionInfo(int &version)
{
- // Try..Catch mandatory here - we don't need to escalate the error
- // if it happens - we just won't return the version, allowing CKM to work
- try {
- SqlConnection::DataCommandUniquePtr selectCommand =
- m_db->m_connection->PrepareDataCommand(DB_CMD_SCHEMA_GET);
- selectCommand->BindString(101, DB_SCHEMA_VERSION_FIELD);
+ SqlConnection::DataCommandUniquePtr selectCommand =
+ m_connection->PrepareDataCommand(DB_CMD_SCHEMA_GET);
+ selectCommand->BindString(101, DB_SCHEMA_VERSION_FIELD);
- if (selectCommand->Step()) {
- version = static_cast<int>(atoi(selectCommand->GetColumnString(1).c_str()));
- return true;
- }
- } 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");
+ if (selectCommand->Step()) {
+ version = static_cast<int>(atoi(selectCommand->GetColumnString(1).c_str()));
+ return true;
}
-
return false;
}
diff --git a/src/manager/service/db-crypto.h b/src/manager/service/db-crypto.h
index 65ef3a3..ad0ef12 100644
--- a/src/manager/service/db-crypto.h
+++ b/src/manager/service/db-crypto.h
@@ -231,13 +231,13 @@ private:
class SchemaInfo {
public:
- explicit SchemaInfo(const Crypto *db) : m_db(db) {}
+ explicit SchemaInfo(SqlConnection *connection) : m_connection(connection) {}
void setVersionInfo();
- bool getVersionInfo(int &version) const;
+ bool getVersionInfo(int &version);
private:
- const Crypto *m_db;
+ SqlConnection *m_connection;
};
public: