diff options
author | Krzysztof Jackiewicz <k.jackiewicz@samsung.com> | 2020-09-28 14:01:51 +0200 |
---|---|---|
committer | Dariusz Michaluk <d.michaluk@samsung.com> | 2020-09-29 11:15:22 +0000 |
commit | e60b1f78757ceaf50f3b97107cb9f42dd23edb4d (patch) | |
tree | b72432dd37131e601330311305215aa3b2d8d56f | |
parent | 501a53809278409c3639be2796d30da21b3b7101 (diff) | |
download | security-manager-e60b1f78757ceaf50f3b97107cb9f42dd23edb4d.tar.gz security-manager-e60b1f78757ceaf50f3b97107cb9f42dd23edb4d.tar.bz2 security-manager-e60b1f78757ceaf50f3b97107cb9f42dd23edb4d.zip |
Remove redundant author name from db
Remove author's name from db as it's no longer needed. Make few minor changes
related to author.
Change-Id: I03f195298f6aa69d970f5d384b2ab441220f82e4
-rw-r--r-- | db/db.sql | 16 | ||||
-rw-r--r-- | db/updates/update-db-to-v15.sql | 24 | ||||
-rw-r--r-- | src/common/include/privilege_db.h | 4 | ||||
-rw-r--r-- | src/common/privilege_db.cpp | 13 | ||||
-rw-r--r-- | src/common/service_impl.cpp | 10 | ||||
-rw-r--r-- | test/privilege_db_fixture.cpp | 6 | ||||
-rw-r--r-- | test/test_privilege_db_add_app.cpp | 6 | ||||
-rw-r--r-- | test/test_privilege_db_app_pkg_getters.cpp | 4 |
8 files changed, 52 insertions, 31 deletions
@@ -4,7 +4,7 @@ PRAGMA auto_vacuum = NONE; BEGIN EXCLUSIVE TRANSACTION; -PRAGMA user_version = 14; +PRAGMA user_version = 15; CREATE TABLE IF NOT EXISTS pkg ( pkg_id INTEGER PRIMARY KEY, @@ -58,7 +58,6 @@ PRIMARY KEY (privilege_name, group_name) CREATE TABLE IF NOT EXISTS author ( author_id INTEGER PRIMARY KEY, - name VARCHAR NOT NULL, hash VARCHAR NOT NULL, UNIQUE (hash) ); @@ -96,7 +95,6 @@ SELECT app.version as version, pkg.author_id, pkg.name as pkg_name, - author.name as author_name, author.hash as author_hash, pkg.is_hybrid FROM user_app @@ -116,19 +114,19 @@ BEGIN SELECT RAISE(ABORT, 'Another application from this package is already installed with different author') WHERE EXISTS (SELECT 1 FROM user_app_pkg_view WHERE pkg_name=NEW.pkg_name - AND author_name IS NOT NULL - AND NEW.author_name IS NOT NULL - AND author_name!=NEW.author_name); + AND author_hash IS NOT NULL + AND NEW.author_hash IS NOT NULL + AND author_hash!=NEW.author_hash); - INSERT OR IGNORE INTO author(name, hash) VALUES (NEW.author_name, NEW.author_hash); + INSERT OR IGNORE INTO author(hash) VALUES (NEW.author_hash); INSERT OR IGNORE INTO pkg(name, author_id, is_hybrid) VALUES ( NEW.pkg_name, - (SELECT author_id FROM author WHERE name=NEW.author_name), + (SELECT author_id FROM author WHERE hash=NEW.author_hash), NEW.is_hybrid); -- If pkg have already existed with empty author do update it - UPDATE pkg SET author_id=(SELECT author_id FROM author WHERE name=NEW.author_name) + UPDATE pkg SET author_id=(SELECT author_id FROM author WHERE hash=NEW.author_hash) WHERE name=NEW.pkg_name AND author_id IS NULL; -- If pkg have already existed with different hybrid flag do update it diff --git a/db/updates/update-db-to-v15.sql b/db/updates/update-db-to-v15.sql new file mode 100644 index 00000000..ef2bafaf --- /dev/null +++ b/db/updates/update-db-to-v15.sql @@ -0,0 +1,24 @@ +PRAGMA foreign_keys=OFF; + +BEGIN EXCLUSIVE TRANSACTION; + +PRAGMA user_version = 15; + +CREATE TABLE author_new ( + author_id INTEGER PRIMARY KEY, + hash VARCHAR NOT NULL, + UNIQUE (hash) +); + +INSERT INTO author_new +SELECT author_id, hash +FROM author; + +DROP TABLE author; +ALTER TABLE author_new RENAME TO author; + +PRAGMA foreign_key_check; + +COMMIT TRANSACTION; + +PRAGMA foreign_keys=ON; diff --git a/src/common/include/privilege_db.h b/src/common/include/privilege_db.h index 812bacfc..9478b869 100644 --- a/src/common/include/privilege_db.h +++ b/src/common/include/privilege_db.h @@ -460,7 +460,7 @@ public: */ void GetAllPackages(std::vector<std::string> &packages); - /* Retrive hash of author_name from database + /* Retrieve hash of author_name from database * * @param pkgName[in] package identifier * @param authorHash[out] hash of author_name associated with the package, or empty string if no @@ -468,7 +468,7 @@ public: * @exception PrivilegeDb::Exception::InternalError on internal error * @exception PrivilegeDb::Exception::ConstraintError on constraint violation */ - void GetPkgAuthor(const std::string &pkgName, std::string &authorHash); + void GetPkgAuthorHash(const std::string &pkgName, std::string &authorHash); /** * Retrieve vector of pairs with group_name (1st value) and privilege_name (2nd value) diff --git a/src/common/privilege_db.cpp b/src/common/privilege_db.cpp index 3fe93588..33ffbc00 100644 --- a/src/common/privilege_db.cpp +++ b/src/common/privilege_db.cpp @@ -48,8 +48,8 @@ namespace SecurityManager { namespace { constexpr const char *g_queries[StmtTypeCount] = { - [underlying(StmtType::EAddApplication)] = "INSERT INTO user_app_pkg_view (app_name, pkg_name, uid, version, author_name, author_hash, is_hybrid)" - " VALUES (?, ?, ?, ?, ?, ?, ?)", + [underlying(StmtType::EAddApplication)] = "INSERT INTO user_app_pkg_view (app_name, pkg_name, uid, version, author_hash, is_hybrid)" + " VALUES (?, ?, ?, ?, ?, ?)", [underlying(StmtType::ERemoveApplication)] = "DELETE FROM user_app_pkg_view WHERE app_name=? AND uid=?", [underlying(StmtType::EPkgNameExists)] = "SELECT count(*) FROM pkg WHERE name=?", [underlying(StmtType::EAppNameExists)] = "SELECT count(*) FROM app WHERE name=?", @@ -319,9 +319,8 @@ void PrivilegeDb::AddApplication( command->BindString(2, pkgName); command->BindInteger(3, static_cast<unsigned int>(uid)); command->BindString(4, targetTizenVer); - authorName.empty() ? command->BindNull(5) : command->BindString(5, authorName); - authorName.empty() ? command->BindNull(6) : command->BindString(6, getAuthorHash(authorName)); - command->BindInteger(7, isHybrid ? 1 : 0); + authorName.empty() ? command->BindNull(5) : command->BindString(5, getAuthorHash(authorName)); + command->BindInteger(6, isHybrid ? 1 : 0); if (command->Step()) { LogDebug("Unexpected SQLITE_ROW answer to query: " << @@ -347,7 +346,7 @@ void PrivilegeDb::RemoveApplication( GetAppPkgName(appName, pkgName); std::string authorHash; - GetPkgAuthor(pkgName, authorHash); + GetPkgAuthorHash(pkgName, authorHash); auto command = getStatement(StmtType::ERemoveApplication); command->BindString(1, appName); @@ -569,7 +568,7 @@ void PrivilegeDb::GetPkgApps(const std::string &pkgName, }); } -void PrivilegeDb::GetPkgAuthor(const std::string &pkgName, std::string &authorHash) +void PrivilegeDb::GetPkgAuthorHash(const std::string &pkgName, std::string &authorHash) { try_catch<void>([&] { auto command = getStatement(StmtType::EGetPkgAuthor); diff --git a/src/common/service_impl.cpp b/src/common/service_impl.cpp index 70bf9f9a..43de45fa 100644 --- a/src/common/service_impl.cpp +++ b/src/common/service_impl.cpp @@ -348,7 +348,7 @@ int ServiceImpl::labelPaths(const pkg_paths &paths, } std::string authorHash; - m_privilegeDb.GetPkgAuthor(pkgName, authorHash); + m_privilegeDb.GetPkgAuthorHash(pkgName, authorHash); std::string homePath; std::vector<std::string> pkgLegalBaseDirs; @@ -530,7 +530,7 @@ int ServiceImpl::appInstallSmackRules(app_inst_req &req, InstallHelper &ih) Smack::Labels pkgLabels; try { - m_privilegeDb.GetPkgAuthor(req.pkgName, authorHash); + m_privilegeDb.GetPkgAuthorHash(req.pkgName, authorHash); // Check if hybridity is changed if the package is installed if (ih.isUserPkgInstalled && ih.isOldPkgHybrid != req.isHybrid) { @@ -942,7 +942,7 @@ int ServiceImpl::appUninstall(const Credentials &creds, app_inst_req &req) // that this app belongs to, this will allow us to remove all rules within the // package that the app appears in UninstallHelper uh; - m_privilegeDb.GetPkgAuthor(req.pkgName, uh.authorHash); + m_privilegeDb.GetPkgAuthorHash(req.pkgName, uh.authorHash); getPkgLabels(req.pkgName, uh.pkgLabels); uh.isPkgHybrid = m_privilegeDb.IsPackageHybrid(req.pkgName); @@ -1139,7 +1139,7 @@ void ServiceImpl::updateRunningAppSmackPolicy( SmackLabels::generateAppPkgNameFromLabel(appContext.appProcessLabel, appName, pkgName); std::string authorHash; - m_privilegeDb.GetPkgAuthor(pkgName, authorHash); + m_privilegeDb.GetPkgAuthorHash(pkgName, authorHash); m_smackRules.disablePrivilegeRules(appContext.appProcessLabel, pkgName, authorHash, denied); m_smackRules.enablePrivilegeRules(appContext.appProcessLabel, pkgName, authorHash, allowed); @@ -2270,7 +2270,7 @@ int ServiceImpl::prepareApp(const Credentials &creds, const std::string &appName } std::string authorHash; - m_privilegeDb.GetPkgAuthor(pkgName, authorHash); + m_privilegeDb.GetPkgAuthorHash(pkgName, authorHash); std::vector<std::string> pkgLabels; getPkgLabels(pkgName, pkgLabels); diff --git a/test/privilege_db_fixture.cpp b/test/privilege_db_fixture.cpp index 2f447fa0..62557b73 100644 --- a/test/privilege_db_fixture.cpp +++ b/test/privilege_db_fixture.cpp @@ -145,7 +145,7 @@ void PrivilegeDBFixture::addAppSuccess(const std::string &appName, "PkgNameExists wrongly not reported " << pkgName << " as existing package name"); if (authorName.length() > 0) { - BOOST_REQUIRE_NO_THROW(testPrivDb->GetPkgAuthor(pkgName, authorHash)); + BOOST_REQUIRE_NO_THROW(testPrivDb->GetPkgAuthorHash(pkgName, authorHash)); BOOST_REQUIRE_MESSAGE(testPrivDb->AuthorExists(authorHash), "AuthorExists wrongly not reported " << uid << " as existing author"); } @@ -161,7 +161,7 @@ void PrivilegeDBFixture::addAppFail(const std::string &appName, std::string authorHash; if (authorName.length() > 0) { - BOOST_REQUIRE_NO_THROW(testPrivDb->GetPkgAuthor(pkgName, authorHash)); + BOOST_REQUIRE_NO_THROW(testPrivDb->GetPkgAuthorHash(pkgName, authorHash)); BOOST_REQUIRE_NO_THROW(authorNameExists = testPrivDb->AuthorExists(authorHash)); } @@ -177,7 +177,7 @@ void PrivilegeDBFixture::addAppFail(const std::string &appName, "PkgNameExists wrongly changed value after unsuccessful installation."); if (authorName.length() > 0) { - BOOST_REQUIRE_NO_THROW(testPrivDb->GetPkgAuthor(pkgName, authorHash)); + BOOST_REQUIRE_NO_THROW(testPrivDb->GetPkgAuthorHash(pkgName, authorHash)); BOOST_REQUIRE_MESSAGE(authorNameExists == testPrivDb->AuthorExists(authorHash), "AuthorExists wrongly changed value after unsuccessful installation."); } diff --git a/test/test_privilege_db_add_app.cpp b/test/test_privilege_db_add_app.cpp index cd4965f0..63a6bdce 100644 --- a/test/test_privilege_db_add_app.cpp +++ b/test/test_privilege_db_add_app.cpp @@ -167,16 +167,16 @@ POSITIVE_TEST_CASE(T590_add_applications_with_empty_noempty_author) std::string authorHash; addAppSuccess(app(1), pkg(1), uid(1), tizenVer(1), "", NotHybrid); - BOOST_REQUIRE_NO_THROW(getPrivDb()->GetPkgAuthor(pkg(1), authorHash)); + BOOST_REQUIRE_NO_THROW(getPrivDb()->GetPkgAuthorHash(pkg(1), authorHash)); BOOST_REQUIRE_MESSAGE(authorHash.empty(), "Wrong author returned: " << authorHash << " expected: empty"); addAppSuccess(app(2), pkg(1), uid(1), tizenVer(1), author(1), NotHybrid); - BOOST_REQUIRE_NO_THROW(getPrivDb()->GetPkgAuthor(pkg(1), authorHash)); + BOOST_REQUIRE_NO_THROW(getPrivDb()->GetPkgAuthorHash(pkg(1), authorHash)); BOOST_REQUIRE_MESSAGE(!authorHash.empty(), "Wrong author returned: empty"); addAppSuccess(app(3), pkg(1), uid(1), tizenVer(1), "", NotHybrid); - BOOST_REQUIRE_NO_THROW(getPrivDb()->GetPkgAuthor(pkg(2), authorHash)); + BOOST_REQUIRE_NO_THROW(getPrivDb()->GetPkgAuthorHash(pkg(2), authorHash)); BOOST_REQUIRE_MESSAGE(authorHash.empty(), "Wrong author returned: " << authorHash << " expected: empty"); } diff --git a/test/test_privilege_db_app_pkg_getters.cpp b/test/test_privilege_db_app_pkg_getters.cpp index 8a7c9596..6e747358 100644 --- a/test/test_privilege_db_app_pkg_getters.cpp +++ b/test/test_privilege_db_app_pkg_getters.cpp @@ -90,7 +90,7 @@ void PrivilegeDBGettersFixture::checkGetPkgAuthor(const std::string &pkgName, const std::string &expectedAuthorHash) { std::string authorHash; - BOOST_REQUIRE_NO_THROW(getPrivDb()->GetPkgAuthor(pkgName, authorHash)); + BOOST_REQUIRE_NO_THROW(getPrivDb()->GetPkgAuthorHash(pkgName, authorHash)); BOOST_CHECK_MESSAGE(expectedAuthorHash == authorHash, "GetPkgAuthor for package: " << pkgName << " returned author: " << authorHash << " expected: " << expectedAuthorHash); }; @@ -184,7 +184,7 @@ POSITIVE_TEST_CASE(T325_app_name_pkg_author_exists) "AppNameExists wrongly not reported " << app(1) << " as existing application name"); BOOST_REQUIRE_MESSAGE(getPrivDb()->PkgNameExists(pkg(1)), "PkgNameExists wrongly not reported " << pkg(1) << " as existing package name"); - BOOST_REQUIRE_NO_THROW(getPrivDb()->GetPkgAuthor(pkg(1), authorHash)); + BOOST_REQUIRE_NO_THROW(getPrivDb()->GetPkgAuthorHash(pkg(1), authorHash)); BOOST_REQUIRE_MESSAGE(getPrivDb()->AuthorExists(authorHash), "AuthorExists wrongly not found " << author(1) << " as existing author"); } |