BEGIN EXCLUSIVE TRANSACTION;
-PRAGMA user_version = 14;
+PRAGMA user_version = 15;
CREATE TABLE IF NOT EXISTS pkg (
pkg_id INTEGER PRIMARY KEY,
CREATE TABLE IF NOT EXISTS author (
author_id INTEGER PRIMARY KEY,
- name VARCHAR NOT NULL,
hash VARCHAR NOT NULL,
UNIQUE (hash)
);
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
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
--- /dev/null
+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;
*/
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
* @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)
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=?",
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: " <<
GetAppPkgName(appName, pkgName);
std::string authorHash;
- GetPkgAuthor(pkgName, authorHash);
+ GetPkgAuthorHash(pkgName, authorHash);
auto command = getStatement(StmtType::ERemoveApplication);
command->BindString(1, appName);
});
}
-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);
}
std::string authorHash;
- m_privilegeDb.GetPkgAuthor(pkgName, authorHash);
+ m_privilegeDb.GetPkgAuthorHash(pkgName, authorHash);
std::string homePath;
std::vector<std::string> pkgLegalBaseDirs;
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) {
// 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);
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);
}
std::string authorHash;
- m_privilegeDb.GetPkgAuthor(pkgName, authorHash);
+ m_privilegeDb.GetPkgAuthorHash(pkgName, authorHash);
std::vector<std::string> pkgLabels;
getPkgLabels(pkgName, pkgLabels);
"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");
}
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));
}
"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.");
}
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");
}
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);
};
"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");
}