#include <sqlite3.h>
#include <glib.h>
-#include <db-util.h>
-
#include "pkgmgr-info.h"
#include "pkgmgrinfo_debug.h"
#include "pkgmgrinfo_private.h"
pkgmgrinfo_cert_compare_result_type_e *result)
{
static const char query[] =
- "SELECT author_signer_cert FROM package_cert_info "
+ "SELECT COALESCE(author_signer_cert, -1) FROM package_cert_info "
"WHERE package=?";
int ret;
sqlite3_stmt *stmt;
const char *pkgid[2];
- int certid[2] = {-1, };
+ int certid[2] = {-1, -1};
int i;
+ pkgid[0] = l_pkgid;
+ pkgid[1] = r_pkgid;
+
ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
if (ret != SQLITE_OK) {
_LOGE("prepare error: %s", sqlite3_errmsg(db));
return PMINFO_R_ERROR;
}
- pkgid[0] = l_pkgid;
- pkgid[1] = r_pkgid;
for (i = 0; i < 2; i++) {
ret = sqlite3_bind_text(stmt, 1, pkgid[i], -1, SQLITE_STATIC);
if (ret != SQLITE_OK) {
*result = PMINFO_CERT_COMPARE_MISMATCH;
sqlite3_finalize(stmt);
-
return PMINFO_R_OK;
}
{
int ret;
sqlite3 *db;
- const char *dbpath;
+ char *dbpath;
if (lhs_package_id == NULL || rhs_package_id == NULL ||
compare_result == NULL) {
}
/* open unified global cert db */
- dbpath = getUserPkgCertDBPathUID(GLOBAL_USER);
+ dbpath = getUserPkgCertDBPath();
if (dbpath == NULL)
return PMINFO_R_ERROR;
- ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
+ ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
if (ret != SQLITE_OK) {
_LOGE("failed to open db: %d", ret);
+ free(dbpath);
return PMINFO_R_ERROR;
}
+ free(dbpath);
if (_pkginfo_compare_certinfo(db, lhs_package_id, rhs_package_id,
compare_result)) {
"SELECT package FROM package_app_info WHERE app_id=?";
int ret;
sqlite3 *db;
- const char *dbpath;
+ char *dbpath;
sqlite3_stmt *stmt;
dbpath = getUserPkgParserDBPathUID(uid);
if (dbpath == NULL)
return PMINFO_R_ERROR;
- ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
+ ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
if (ret != SQLITE_OK) {
_LOGE("failed to open db: %d", ret);
+ free(dbpath);
return PMINFO_R_ERROR;
}
+ free(dbpath);
ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
if (ret != SQLITE_OK) {
_save_column_str(stmt, 0, pkgid);
ret = PMINFO_R_OK;
} else if (ret == SQLITE_DONE) {
- _LOGI("cannot find pkgid of app %s for uid %d", appid);
+ _LOGI("cannot find pkgid of app %s for uid %d", appid, (int)uid);
ret = PMINFO_R_ENOENT;
} else {
_LOGE("step error: %s", sqlite3_errmsg(db));
{
int ret;
sqlite3 *db;
- const char *dbpath;
+ char *dbpath;
/* open unified global cert db */
- dbpath = getUserPkgCertDBPathUID(GLOBAL_USER);
+ dbpath = getUserPkgCertDBPath();
if (dbpath == NULL)
return PMINFO_R_ERROR;
- ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
+ ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
if (ret != SQLITE_OK) {
_LOGE("failed to open db: %d", ret);
+ free(dbpath);
return PMINFO_R_ERROR;
}
+ free(dbpath);
ret = _pkginfo_get_certid(db, pkgid, info->cert_id);
if (ret != PMINFO_R_OK) {
return ret;
}
+ sqlite3_close_v2(db);
+
return PMINFO_R_OK;
}
retvm_if(cert_type > PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
pkgmgr_instcertinfo_x *certinfo = NULL;
certinfo = (pkgmgr_instcertinfo_x *)handle;
+ if (certinfo->cert_info[cert_type])
+ free(certinfo->cert_info[cert_type]);
(certinfo->cert_info)[cert_type] = strdup(cert_value);
return PMINFO_R_OK;
}
char *cert_info[])
{
static const char query_insert[] =
- "INSERT INTO package_cert_info (package,"
+ "INSERT INTO package_cert_info (package, package_count,"
" author_root_cert, author_im_cert, author_signer_cert,"
" dist_root_cert, dist_im_cert, dist_signer_cert,"
" dist2_root_cert, dist2_im_cert, dist2_signer_cert) "
- "VALUES(?, "
+ "VALUES(?, 1,"
" (SELECT cert_id FROM package_cert_index_info"
" WHERE cert_info=?),"
" (SELECT cert_id FROM package_cert_index_info"
" (SELECT cert_id FROM package_cert_index_info"
" WHERE cert_info=?))";
static const char query_update[] =
- "UPDATE package_cert_info SET "
- " author_root_cert= "
- " (SELECT cert_id FROM package_cert_index_info"
- " WHERE cert_info=?),"
- " author_im_cert= "
- " (SELECT cert_id FROM package_cert_index_info"
- " WHERE cert_info=?),"
- " author_signer_cert= "
- " (SELECT cert_id FROM package_cert_index_info"
- " WHERE cert_info=?),"
- " dist_root_cert= "
- " (SELECT cert_id FROM package_cert_index_info"
- " WHERE cert_info=?),"
- " dist_im_cert= "
- " (SELECT cert_id FROM package_cert_index_info"
- " WHERE cert_info=?),"
- " dist_signer_cert= "
- " (SELECT cert_id FROM package_cert_index_info"
- " WHERE cert_info=?),"
- " dist2_root_cert= "
- " (SELECT cert_id FROM package_cert_index_info"
- " WHERE cert_info=?),"
- "dist2_im_cert= "
- " (SELECT cert_id FROM package_cert_index_info"
- " WHERE cert_info=?),"
- "dist2_signer_cert= "
- " (SELECT cert_id FROM package_cert_index_info"
- " WHERE cert_info=?) "
+ "UPDATE package_cert_info "
+ "SET package_count = package_count + 1 "
"WHERE package=?";
int ret;
sqlite3_stmt *stmt;
}
idx = 1;
- sqlite3_bind_text(stmt, idx++, pkgid, -1, SQLITE_STATIC);
+ ret = sqlite3_bind_text(stmt, idx++, pkgid, -1, SQLITE_STATIC);
+ if (ret != SQLITE_OK) {
+ _LOGE("bind failed: %s", sqlite3_errmsg(db));
+ sqlite3_finalize(stmt);
+ return PMINFO_R_ERROR;
+ }
+
for (i = 0; i < MAX_CERT_TYPE; i++) {
if (sqlite3_bind_text(stmt, idx++, cert_info[i], -1,
SQLITE_STATIC)) {
_LOGE("prepare error: %s", sqlite3_errmsg(db));
return PMINFO_R_ERROR;
}
- idx = 1;
- for (i = 0; i < MAX_CERT_TYPE; i++) {
- if (sqlite3_bind_text(stmt, idx++, cert_info[i], -1,
- SQLITE_STATIC)) {
- _LOGE("bind error: %s", sqlite3_errmsg(db));
- sqlite3_finalize(stmt);
- return PMINFO_R_ERROR;
- }
+
+ if (sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_STATIC)) {
+ _LOGE("bind error: %s", sqlite3_errmsg(db));
+ sqlite3_finalize(stmt);
+ return PMINFO_R_ERROR;
}
- sqlite3_bind_text(stmt, idx++, pkgid, -1, SQLITE_STATIC);
+
ret = sqlite3_step(stmt);
sqlite3_finalize(stmt);
}
if (cert_info[i] == NULL)
continue;
idx = 1;
- sqlite3_bind_text(stmt, idx++, cert_info[i], -1, SQLITE_STATIC);
- sqlite3_bind_text(stmt, idx++, cert_info[i], -1, SQLITE_STATIC);
- sqlite3_bind_text(stmt, idx++, cert_info[i], -1, SQLITE_STATIC);
+ ret = sqlite3_bind_text(stmt, idx++, cert_info[i], -1, SQLITE_STATIC);
+ if (ret != SQLITE_OK) {
+ _LOGE("bind failed: %s", sqlite3_errmsg(db));
+ sqlite3_finalize(stmt);
+ return PMINFO_R_ERROR;
+ }
+ ret = sqlite3_bind_text(stmt, idx++, cert_info[i], -1, SQLITE_STATIC);
+ if (ret != SQLITE_OK) {
+ _LOGE("bind failed: %s", sqlite3_errmsg(db));
+ sqlite3_finalize(stmt);
+ return PMINFO_R_ERROR;
+ }
+ ret = sqlite3_bind_text(stmt, idx++, cert_info[i], -1, SQLITE_STATIC);
+ if (ret != SQLITE_OK) {
+ _LOGE("bind failed: %s", sqlite3_errmsg(db));
+ sqlite3_finalize(stmt);
+ return PMINFO_R_ERROR;
+ }
ret = sqlite3_step(stmt);
if (ret != SQLITE_DONE) {
{
int ret;
sqlite3 *db;
- const char *dbpath;
+ char *dbpath;
pkgmgr_instcertinfo_x *info = (pkgmgr_instcertinfo_x *)handle;
if (pkgid == NULL || handle == NULL) {
return PMINFO_R_EINVAL;
}
+ _check_create_cert_db();
+
/* open unified global cert db */
- dbpath = getUserPkgCertDBPathUID(GLOBAL_USER);
+ dbpath = getUserPkgCertDBPath();
if (dbpath == NULL)
return PMINFO_R_ERROR;
- ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READWRITE, NULL);
+ ret = __open_db(dbpath, &db, SQLITE_OPEN_READWRITE);
if (ret != SQLITE_OK) {
_LOGE("failed to open db: %d", ret);
+ free(dbpath);
return PMINFO_R_ERROR;
}
+ free(dbpath);
- ret = sqlite3_exec(db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
+ ret = sqlite3_exec(db, "BEGIN DEFERRED", NULL, NULL, NULL);
if (ret != SQLITE_OK) {
_LOGE("failed to begin transaction");
sqlite3_close_v2(db);
return PMINFO_R_ERROR;
}
- _check_create_cert_db(db);
-
if (_pkginfo_save_cert_index_info(db, info->cert_info)) {
_LOGE("failed to save cert index info, rollback now");
- sqlite3_exec(GET_DB(cert_db), "ROLLBACK", NULL, NULL, NULL);
+ ret = sqlite3_exec(db, "ROLLBACK", NULL, NULL, NULL);
+ if (ret != SQLITE_OK)
+ LOGE("Rollback is failed. error(%s)", sqlite3_errmsg(db));
sqlite3_close_v2(db);
return PMINFO_R_ERROR;
}
+
if (_pkginfo_save_cert_info(db, pkgid, info->cert_info)) {
_LOGE("failed to save cert info, rollback now");
- sqlite3_exec(GET_DB(cert_db), "ROLLBACK", NULL, NULL, NULL);
+ ret = sqlite3_exec(db, "ROLLBACK", NULL, NULL, NULL);
+ if (ret != SQLITE_OK)
+ LOGE("Rollback is failed. error(%s)", sqlite3_errmsg(db));
sqlite3_close_v2(db);
return PMINFO_R_ERROR;
}
ret = sqlite3_exec(db, "COMMIT", NULL, NULL, NULL);
if (ret != SQLITE_OK) {
_LOGE("failed to commit transaction, rollback now");
- sqlite3_exec(GET_DB(cert_db), "ROLLBACK", NULL, NULL, NULL);
+ ret = sqlite3_exec(db, "ROLLBACK", NULL, NULL, NULL);
+ if (ret != SQLITE_OK)
+ LOGE("Rollback is failed. error(%s)", sqlite3_errmsg(db));
sqlite3_close_v2(db);
return PMINFO_R_ERROR;
}
static int _pkginfo_delete_certinfo(sqlite3 *db, const char *pkgid)
{
static const char query[] =
- "DELETE FROM package_cert_info WHERE package=?";
+ "UPDATE package_cert_info "
+ "SET package_count = package_count - 1 "
+ "WHERE package=?";
int ret;
sqlite3_stmt *stmt;
{
int ret;
sqlite3 *db;
- const char *dbpath;
+ char *dbpath;
if (pkgid == NULL) {
_LOGE("invalid parameter");
}
/* open unified global cert db */
- dbpath = getUserPkgCertDBPathUID(GLOBAL_USER);
+ dbpath = getUserPkgCertDBPath();
if (dbpath == NULL)
return PMINFO_R_ERROR;
- ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READWRITE, NULL);
+ ret = __open_db(dbpath, &db, SQLITE_OPEN_READWRITE);
if (ret != SQLITE_OK) {
_LOGE("failed to open db: %d", ret);
+ free(dbpath);
return PMINFO_R_ERROR;
}
+ free(dbpath);
- ret = sqlite3_exec(db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
+ ret = sqlite3_exec(db, "BEGIN DEFERRED", NULL, NULL, NULL);
if (ret != SQLITE_OK) {
_LOGE("failed to begin transaction");
sqlite3_close_v2(db);
if (_pkginfo_delete_certinfo(db, pkgid)) {
_LOGE("failed to delete certinfo of %s, rollback now", pkgid);
- sqlite3_exec(GET_DB(cert_db), "ROLLBACK", NULL, NULL, NULL);
+ ret = sqlite3_exec(db, "ROLLBACK", NULL, NULL, NULL);
+ if (ret != SQLITE_OK)
+ LOGE("Rollback is failed. error(%s)", sqlite3_errmsg(db));
sqlite3_close_v2(db);
return PMINFO_R_ERROR;
}
ret = sqlite3_exec(db, "COMMIT", NULL, NULL, NULL);
if (ret != SQLITE_OK) {
_LOGE("failed to commit transaction, rollback now");
- sqlite3_exec(GET_DB(cert_db), "ROLLBACK", NULL, NULL, NULL);
+ ret = sqlite3_exec(db, "ROLLBACK", NULL, NULL, NULL);
+ if (ret != SQLITE_OK)
+ LOGE("Rollback is failed. error(%s)", sqlite3_errmsg(db));
sqlite3_close_v2(db);
return PMINFO_R_ERROR;
}